[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 2 | // 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 | |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 7 | #include <iterator> |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 8 | #include <map> |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 9 | #include <set> |
[email protected] | 1033acd | 2012-02-08 08:46:27 | [diff] [blame] | 10 | #include <utility> |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
brettw | f195891 | 2015-10-07 19:43:12 | [diff] [blame] | 13 | #include "base/base_switches.h" |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 14 | #include "base/bind.h" |
danakj | db9ae794 | 2020-11-11 16:01:35 | [diff] [blame] | 15 | #include "base/callback_helpers.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 16 | #include "base/command_line.h" |
Ken Rockot | 91c40da8 | 2019-08-12 20:07:11 | [diff] [blame] | 17 | #include "base/compiler_specific.h" |
Jan Wilken Dörrie | b5a41c3 | 2020-12-09 18:55:47 | [diff] [blame] | 18 | #include "base/containers/contains.h" |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 19 | #include "base/files/file_util.h" |
morrita | d95714f | 2014-10-01 02:37:24 | [diff] [blame] | 20 | #include "base/files/scoped_file.h" |
Marc Treib | ad33cf94 | 2017-08-24 11:19:00 | [diff] [blame] | 21 | #include "base/i18n/base_i18n_switches.h" |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 22 | #include "base/i18n/character_encoding.h" |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 23 | #include "base/macros.h" |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 24 | #include "base/metrics/field_trial_params.h" |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 25 | #include "base/metrics/histogram_macros.h" |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 26 | #include "base/no_destructor.h" |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 27 | #include "base/path_service.h" |
Gabriel Charette | e926fc1 | 2019-12-16 19:00:02 | [diff] [blame] | 28 | #include "base/sequenced_task_runner.h" |
Aaron Tagliaboschi | 19ad8d3 | 2020-05-12 20:10:44 | [diff] [blame] | 29 | #include "base/strings/strcat.h" |
[email protected] | e746341 | 2013-06-10 22:53:46 | [diff] [blame] | 30 | #include "base/strings/string_number_conversions.h" |
markdittmer | 67b71ea | 2016-03-03 22:40:03 | [diff] [blame] | 31 | #include "base/strings/string_split.h" |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 32 | #include "base/strings/string_util.h" |
| 33 | #include "base/strings/stringprintf.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 34 | #include "base/strings/utf_string_conversions.h" |
Sebastien Marchand | 75a7cdf | 2018-11-13 23:47:03 | [diff] [blame] | 35 | #include "base/system/sys_info.h" |
Wojciech Dzierżanowski | 4538080 | 2019-04-29 14:50:32 | [diff] [blame] | 36 | #include "base/threading/sequenced_task_runner_handle.h" |
gab | b15e1907 | 2016-05-11 20:45:41 | [diff] [blame] | 37 | #include "base/threading/thread_task_runner_handle.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 38 | #include "build/build_config.h" |
Hidehiko Abe | 7c68f58 | 2020-09-03 15:47:25 | [diff] [blame] | 39 | #include "build/chromeos_buildflags.h" |
Dominic Mazzoni | 21fb028 | 2019-02-13 18:32:47 | [diff] [blame] | 40 | #include "chrome/browser/accessibility/accessibility_labels_service.h" |
| 41 | #include "chrome/browser/accessibility/accessibility_labels_service_factory.h" |
Abigail Klein | a81f2e2 | 2020-05-04 14:32:41 | [diff] [blame] | 42 | #include "chrome/browser/accessibility/caption_util.h" |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 43 | #include "chrome/browser/after_startup_task_utils.h" |
Ovidio Henriquez | 3d729f6 | 2020-02-07 00:43:29 | [diff] [blame] | 44 | #include "chrome/browser/bluetooth/chrome_bluetooth_delegate.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 45 | #include "chrome/browser/browser_about_handler.h" |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 46 | #include "chrome/browser/browser_features.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 47 | #include "chrome/browser/browser_process.h" |
msramek | 1c2b3ca | 2017-03-14 17:57:56 | [diff] [blame] | 48 | #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
Colin Blundell | 111b61c0 | 2020-01-24 11:53:51 | [diff] [blame] | 49 | #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
Lingqi Chi | 775e6075 | 2020-12-14 06:31:16 | [diff] [blame] | 50 | #include "chrome/browser/chrome_content_browser_client_binder_policies.h" |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 51 | #include "chrome/browser/chrome_content_browser_client_parts.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 52 | #include "chrome/browser/content_settings/cookie_settings_factory.h" |
peconn | 5100d43 | 2015-09-16 12:03:08 | [diff] [blame] | 53 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
Robbie McElrath | 1294d24 | 2019-05-31 20:46:22 | [diff] [blame] | 54 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 55 | #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
Zhuoyu Qian | cb197638 | 2018-12-13 02:18:30 | [diff] [blame] | 56 | #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" |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 58 | #include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h" |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 59 | #include "chrome/browser/defaults.h" |
Anatoliy Potapchuk | 096e4d0a | 2020-12-01 16:49:21 | [diff] [blame] | 60 | #include "chrome/browser/device_api/device_service_impl.h" |
Marijn Kruisselbrink | efe0bef6 | 2020-07-21 22:44:59 | [diff] [blame] | 61 | #include "chrome/browser/download/chrome_download_manager_delegate.h" |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 62 | #include "chrome/browser/download/download_prefs.h" |
Dominique Fauteux-Chapleau | 5fd6beb | 2021-01-13 18:46:49 | [diff] [blame] | 63 | #include "chrome/browser/enterprise/connectors/connectors_service.h" |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 64 | #include "chrome/browser/extensions/chrome_extension_cookies.h" |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 65 | #include "chrome/browser/external_protocol/external_protocol_handler.h" |
Yao Xiao | c5436ad | 2021-01-12 00:22:30 | [diff] [blame] | 66 | #include "chrome/browser/federated_learning/floc_eligibility_observer.h" |
Yao Xiao | ebed8c1 | 2020-09-26 07:51:20 | [diff] [blame] | 67 | #include "chrome/browser/federated_learning/floc_id_provider.h" |
| 68 | #include "chrome/browser/federated_learning/floc_id_provider_factory.h" |
Olivier Yiptong | 935e6c4 | 2020-11-21 01:28:23 | [diff] [blame] | 69 | #include "chrome/browser/font_access/chrome_font_access_delegate.h" |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 70 | #include "chrome/browser/font_family_cache.h" |
Peng Huang | 71d398ed | 2020-02-28 01:30:53 | [diff] [blame] | 71 | #include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h" |
Matt Reynolds | 93616f9b | 2019-06-07 01:28:52 | [diff] [blame] | 72 | #include "chrome/browser/hid/chrome_hid_delegate.h" |
Colin Blundell | eaa7377bf | 2020-01-22 08:49:10 | [diff] [blame] | 73 | #include "chrome/browser/interstitials/enterprise_util.h" |
Avi Drissman | d3092734 | 2018-05-22 15:04:27 | [diff] [blame] | 74 | #include "chrome/browser/lifetime/browser_shutdown.h" |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 75 | #include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h" |
Guido Urdaneta | e02b572 | 2020-07-22 05:58:21 | [diff] [blame] | 76 | #include "chrome/browser/media/audio_service_util.h" |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 77 | #include "chrome/browser/media/router/media_router_feature.h" |
Patrik Höglund | b564859b | 2018-05-17 11:17:16 | [diff] [blame] | 78 | #include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h" |
mcasas | a2023ab | 2016-09-08 01:06:36 | [diff] [blame] | 79 | #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
Darin Fisher | 09aa722 | 2019-08-29 09:27:36 | [diff] [blame] | 80 | #include "chrome/browser/media/webrtc/webrtc_logging_controller.h" |
Sebastien Marchand | 8c008810 | 2019-10-11 16:47:56 | [diff] [blame] | 81 | #include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h" |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 82 | #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 83 | #include "chrome/browser/metrics/chrome_feature_list_creator.h" |
[email protected] | a2b4c5c | 2013-10-18 02:06:07 | [diff] [blame] | 84 | #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h" |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 85 | #include "chrome/browser/net/chrome_network_delegate.h" |
David Benjamin | f6a3409 | 2019-11-07 19:55:10 | [diff] [blame] | 86 | #include "chrome/browser/net/profile_network_context_service.h" |
| 87 | #include "chrome/browser/net/profile_network_context_service_factory.h" |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 88 | #include "chrome/browser/net/system_network_context_manager.h" |
Richard Knoll | d0eae96 | 2019-04-04 12:34:02 | [diff] [blame] | 89 | #include "chrome/browser/notifications/platform_notification_service_factory.h" |
peter | c26c6c6 | 2014-12-10 14:13:59 | [diff] [blame] | 90 | #include "chrome/browser/notifications/platform_notification_service_impl.h" |
leon.han | 952ea325 | 2016-04-13 02:44:56 | [diff] [blame] | 91 | #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 92 | #include "chrome/browser/payments/payment_request_display_manager_factory.h" |
Sigurdur Asgeirsson | 54b7270 | 2019-04-12 14:18:54 | [diff] [blame] | 93 | #include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h" |
Sigurdur Asgeirsson | 7069667 | 2019-02-08 16:14:51 | [diff] [blame] | 94 | #include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h" |
Patrick Monette | a408469 | 2021-01-18 17:51:30 | [diff] [blame] | 95 | #include "chrome/browser/performance_monitor/chrome_browser_main_extra_parts_performance_monitor.h" |
Adam Langley | 85339f6 | 2018-02-12 22:03:56 | [diff] [blame] | 96 | #include "chrome/browser/permissions/attestation_permission_request.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 97 | #include "chrome/browser/platform_util.h" |
Amber Won | 94afd811 | 2017-08-23 17:30:11 | [diff] [blame] | 98 | #include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h" |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 99 | #include "chrome/browser/plugins/plugin_utils.h" |
Liquan (Max) Gu | 4fd38d86 | 2021-01-15 02:14:51 | [diff] [blame] | 100 | #include "chrome/browser/policy/profile_policy_connector.h" |
Hiroki Nakagawa | 7230e341 | 2021-01-22 10:08:29 | [diff] [blame] | 101 | #include "chrome/browser/prefetch/no_state_prefetch/chrome_no_state_prefetch_contents_delegate.h" |
Hiroki Nakagawa | b4cd18aa | 2021-01-25 18:11:01 | [diff] [blame] | 102 | #include "chrome/browser/prefetch/no_state_prefetch/no_state_prefetch_manager_factory.h" |
Hiroki Nakagawa | 483686a9 | 2020-10-29 04:31:45 | [diff] [blame] | 103 | #include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_features.h" |
| 104 | #include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_service.h" |
| 105 | #include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_service_factory.h" |
| 106 | #include "chrome/browser/prefetch/prefetch_proxy/prefetch_proxy_url_loader_interceptor.h" |
Ryan Sturm | 8670b57 | 2020-10-21 18:45:30 | [diff] [blame] | 107 | #include "chrome/browser/prefetch/search_prefetch/field_trial_settings.h" |
| 108 | #include "chrome/browser/prefetch/search_prefetch/search_prefetch_service.h" |
| 109 | #include "chrome/browser/prefetch/search_prefetch/search_prefetch_service_factory.h" |
Ryan Sturm | 6b2f639 | 2020-12-09 21:46:00 | [diff] [blame] | 110 | #include "chrome/browser/prefetch/search_prefetch/search_prefetch_url_loader.h" |
Ryan Sturm | 8670b57 | 2020-10-21 18:45:30 | [diff] [blame] | 111 | #include "chrome/browser/prefetch/search_prefetch/search_prefetch_url_loader_interceptor.h" |
Ryan Sturm | cc5071be | 2019-02-16 02:15:19 | [diff] [blame] | 112 | #include "chrome/browser/previews/previews_content_util.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 113 | #include "chrome/browser/previews/previews_service.h" |
| 114 | #include "chrome/browser/previews/previews_service_factory.h" |
| 115 | #include "chrome/browser/previews/previews_ui_tab_helper.h" |
John Delaney | c278279 | 2021-01-15 01:29:07 | [diff] [blame] | 116 | #include "chrome/browser/privacy_sandbox/privacy_sandbox_settings.h" |
| 117 | #include "chrome/browser/privacy_sandbox/privacy_sandbox_settings_factory.h" |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 118 | #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 119 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 120 | #include "chrome/browser/profiles/profile_io_data.h" |
Ken Rockot | 4e284d3 | 2020-03-06 06:26:49 | [diff] [blame] | 121 | #include "chrome/browser/profiles/profile_manager.h" |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 122 | #include "chrome/browser/profiles/renderer_updater.h" |
| 123 | #include "chrome/browser/profiles/renderer_updater_factory.h" |
Erik Chen | 49bbfa2 | 2017-08-18 08:49:56 | [diff] [blame] | 124 | #include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h" |
| 125 | #include "chrome/browser/profiling_host/profiling_process_host.h" |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 126 | #include "chrome/browser/renderer_host/chrome_navigation_ui_data.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 127 | #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 128 | #include "chrome/browser/renderer_preferences_util.h" |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 129 | #include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h" |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 130 | #include "chrome/browser/safe_browsing/certificate_reporting_service.h" |
| 131 | #include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h" |
Dominique Fauteux-Chapleau | 5b14716 | 2020-01-17 17:08:24 | [diff] [blame] | 132 | #include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h" |
Mustafa Emre Acer | 97be475 | 2020-05-13 01:24:43 | [diff] [blame] | 133 | #include "chrome/browser/safe_browsing/delayed_warning_navigation_throttle.h" |
Carlos IL | 4ee307e | 2018-12-22 03:19:00 | [diff] [blame] | 134 | #include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h" |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 135 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 136 | #include "chrome/browser/safe_browsing/ui_manager.h" |
| 137 | #include "chrome/browser/safe_browsing/url_checker_delegate_impl.h" |
Xinghui Lu | e17b1994 | 2020-02-24 21:19:58 | [diff] [blame] | 138 | #include "chrome/browser/safe_browsing/url_lookup_service_factory.h" |
[email protected] | a7b8e43d | 2013-03-18 18:52:43 | [diff] [blame] | 139 | #include "chrome/browser/search/search.h" |
Sam Goto | 5cf068e8 | 2019-11-04 23:08:44 | [diff] [blame] | 140 | #include "chrome/browser/sharing/sms/sms_remote_fetcher.h" |
Reilly Grant | cc22e60 | 2018-09-07 15:25:20 | [diff] [blame] | 141 | #include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h" |
Reilly Grant | 3787780 | 2018-08-18 00:58:35 | [diff] [blame] | 142 | #include "chrome/browser/signin/chrome_signin_url_loader_throttle.h" |
Robbie McElrath | 38f47af | 2019-09-19 21:51:40 | [diff] [blame] | 143 | #include "chrome/browser/signin/header_modification_delegate_impl.h" |
David Roger | e8e83f3c | 2019-09-12 10:56:23 | [diff] [blame] | 144 | #include "chrome/browser/signin/identity_manager_factory.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 145 | #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" |
Colin Blundell | 13e92ec | 2020-01-27 09:47:38 | [diff] [blame] | 146 | #include "chrome/browser/ssl/chrome_security_blocking_page_factory.h" |
Chris Thompson | e2e073d4 | 2020-07-23 12:33:45 | [diff] [blame] | 147 | #include "chrome/browser/ssl/sct_reporting_service.h" |
| 148 | #include "chrome/browser/ssl/sct_reporting_service_factory.h" |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 149 | #include "chrome/browser/ssl/ssl_client_auth_metrics.h" |
[email protected] | 25af6ec | 2014-06-06 19:35:07 | [diff] [blame] | 150 | #include "chrome/browser/ssl/ssl_client_certificate_selector.h" |
Mustafa Emre Acer | 06028d79 | 2021-01-05 19:48:51 | [diff] [blame] | 151 | #include "chrome/browser/ssl/typed_navigation_upgrade_throttle.h" |
meacer | 4ef065e | 2015-01-09 03:21:35 | [diff] [blame] | 152 | #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 153 | #include "chrome/browser/tab_contents/tab_util.h" |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 154 | #include "chrome/browser/tracing/chrome_tracing_delegate.h" |
Dave Tapuska | c6627e1 | 2018-08-30 15:07:19 | [diff] [blame] | 155 | #include "chrome/browser/translate/translate_service.h" |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 156 | #include "chrome/browser/ui/blocked_content/blocked_window_params.h" |
Clark DuVall | 8a020d62 | 2020-06-04 00:45:50 | [diff] [blame] | 157 | #include "chrome/browser/ui/blocked_content/chrome_popup_navigation_delegate.h" |
Charles Harrison | 6dd11d28 | 2017-10-03 06:14:51 | [diff] [blame] | 158 | #include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h" |
thestig | e8082124 | 2015-09-30 23:46:08 | [diff] [blame] | 159 | #include "chrome/browser/ui/browser_navigator.h" |
| 160 | #include "chrome/browser/ui/browser_navigator_params.h" |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 161 | #include "chrome/browser/ui/chrome_select_file_policy.h" |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 162 | #include "chrome/browser/ui/login/login_handler.h" |
Emily Stark | d6896cd3 | 2019-08-21 04:55:54 | [diff] [blame] | 163 | #include "chrome/browser/ui/login/login_navigation_throttle.h" |
Emily Stark | 63c884f | 2020-05-12 03:55:28 | [diff] [blame] | 164 | #include "chrome/browser/ui/login/login_tab_helper.h" |
Jonathan Mengedoht | 42a19bb | 2020-07-28 14:10:16 | [diff] [blame] | 165 | #include "chrome/browser/ui/passwords/well_known_change_password_navigation_throttle.h" |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 166 | #include "chrome/browser/ui/prefs/pref_watcher.h" |
[email protected] | 329ac97 | 2013-06-21 15:24:25 | [diff] [blame] | 167 | #include "chrome/browser/ui/sync/sync_promo_ui.h" |
[email protected] | b5d7342 | 2012-06-02 23:46:44 | [diff] [blame] | 168 | #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h" |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 169 | #include "chrome/browser/ui/ui_features.h" |
Ken Buchanan | 7d68835 | 2020-12-05 05:45:57 | [diff] [blame] | 170 | #include "chrome/browser/ui/webid/identity_dialog_controller.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 171 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
dbeam | baee5bd | 2015-09-26 03:07:01 | [diff] [blame] | 172 | #include "chrome/browser/ui/webui/log_web_ui_url.h" |
[email protected] | 95ebe7c | 2020-04-08 19:12:45 | [diff] [blame] | 173 | #include "chrome/browser/usb/frame_usb_services.h" |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 174 | #include "chrome/browser/vr/vr_tab_helper.h" |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 175 | #include "chrome/browser/web_applications/components/app_registrar.h" |
Alan Cutter | 1797f46a | 2020-02-12 02:48:59 | [diff] [blame] | 176 | #include "chrome/browser/web_applications/components/web_app_provider_base.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 177 | #include "chrome/common/buildflags.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 178 | #include "chrome/common/channel_info.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 179 | #include "chrome/common/chrome_constants.h" |
Lukasz Anforowicz | 4600ea3 | 2020-01-18 02:37:48 | [diff] [blame] | 180 | #include "chrome/common/chrome_content_client.h" |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 181 | #include "chrome/common/chrome_features.h" |
[email protected] | a7944aa | 2012-10-15 10:12:14 | [diff] [blame] | 182 | #include "chrome/common/chrome_paths.h" |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 183 | #include "chrome/common/chrome_paths_internal.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 184 | #include "chrome/common/chrome_switches.h" |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 185 | #include "chrome/common/env_vars.h" |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 186 | #include "chrome/common/google_url_loader_throttle.h" |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 187 | #include "chrome/common/logging_chrome.h" |
[email protected] | 9d45049 | 2013-06-13 23:08:37 | [diff] [blame] | 188 | #include "chrome/common/pepper_permission_util.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 189 | #include "chrome/common/pref_names.h" |
Mike Wittman | 67d6311 | 2020-09-19 00:33:46 | [diff] [blame] | 190 | #include "chrome/common/profiler/thread_profiler_configuration.h" |
nigeltao | 7cd8d558 | 2016-12-12 06:05:28 | [diff] [blame] | 191 | #include "chrome/common/renderer_configuration.mojom.h" |
Ayu Ishii | fbb1fad | 2020-06-22 20:15:07 | [diff] [blame] | 192 | #include "chrome/common/secure_origin_allowlist.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 193 | #include "chrome/common/url_constants.h" |
Peter Boström | 8e9b163 | 2019-08-22 23:12:47 | [diff] [blame] | 194 | #include "chrome/common/webui_url_constants.h" |
ben | c70c0e3 | 2016-09-22 03:50:37 | [diff] [blame] | 195 | #include "chrome/grit/browser_resources.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 196 | #include "chrome/grit/generated_resources.h" |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 197 | #include "chrome/installer/util/google_update_settings.h" |
brettw | f195891 | 2015-10-07 19:43:12 | [diff] [blame] | 198 | #include "components/autofill/core/common/autofill_switches.h" |
Clark DuVall | 8a020d62 | 2020-06-04 00:45:50 | [diff] [blame] | 199 | #include "components/blocked_content/popup_blocker.h" |
Clark DuVall | f518925 | 2020-04-15 22:33:34 | [diff] [blame] | 200 | #include "components/browsing_data/content/browsing_data_helper.h" |
msramek | 1c8e19d | 2017-01-04 20:04:53 | [diff] [blame] | 201 | #include "components/browsing_data/core/browsing_data_utils.h" |
Colin Blundell | 111b61c0 | 2020-01-24 11:53:51 | [diff] [blame] | 202 | #include "components/captive_portal/content/captive_portal_service.h" |
Colin Blundell | 7cf3fe3 | 2020-01-23 09:52:49 | [diff] [blame] | 203 | #include "components/captive_portal/core/buildflags.h" |
[email protected] | 649b5727 | 2014-05-09 14:54:44 | [diff] [blame] | 204 | #include "components/cdm/browser/cdm_message_filter_android.h" |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 205 | #include "components/certificate_matching/certificate_principal_pattern.h" |
[email protected] | 09cff7878 | 2014-04-20 22:04:48 | [diff] [blame] | 206 | #include "components/cloud_devices/common/cloud_devices_switches.h" |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 207 | #include "components/content_settings/browser/page_specific_content_settings.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 208 | #include "components/content_settings/core/browser/content_settings_utils.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 209 | #include "components/content_settings/core/browser/cookie_settings.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 210 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
Titouan Rigoudy | 9c2c014 | 2020-08-19 17:57:12 | [diff] [blame] | 211 | #include "components/content_settings/core/browser/private_network_settings.h" |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 212 | #include "components/content_settings/core/common/content_settings.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 213 | #include "components/content_settings/core/common/content_settings_types.h" |
tbansal | 08a0e3e | 2017-06-30 21:30:08 | [diff] [blame] | 214 | #include "components/content_settings/core/common/content_settings_utils.h" |
Daniel Vogelheim | 976f1c2 | 2017-11-22 16:26:03 | [diff] [blame] | 215 | #include "components/content_settings/core/common/pref_names.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 216 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h" |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 217 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h" |
rajendrant | 4319407 | 2019-04-15 22:13:43 | [diff] [blame] | 218 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h" |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 219 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
wychen | e5568734 | 2015-11-13 20:17:03 | [diff] [blame] | 220 | #include "components/dom_distiller/core/dom_distiller_switches.h" |
[email protected] | 474a5a3 | 2014-07-28 18:23:24 | [diff] [blame] | 221 | #include "components/dom_distiller/core/url_constants.h" |
Clark DuVall | 3d4e89b9 | 2020-04-03 23:07:32 | [diff] [blame] | 222 | #include "components/embedder_support/switches.h" |
John Abd-El-Malek | ec1fc69e | 2021-01-28 19:14:41 | [diff] [blame^] | 223 | #include "components/embedder_support/user_agent_utils.h" |
Rakina Zata Amni | ba3eecb | 2020-11-02 10:12:28 | [diff] [blame] | 224 | #include "components/error_page/common/error.h" |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 225 | #include "components/error_page/common/error_page_switches.h" |
Rakina Zata Amni | ba3eecb | 2020-11-02 10:12:28 | [diff] [blame] | 226 | #include "components/error_page/common/localized_error.h" |
Ken Rockot | 4408a0f | 2020-07-27 19:40:54 | [diff] [blame] | 227 | #include "components/error_page/content/browser/net_error_auto_reloader.h" |
khushalsagar | c5447db2 | 2017-08-22 17:53:01 | [diff] [blame] | 228 | #include "components/feature_engagement/public/feature_constants.h" |
| 229 | #include "components/feature_engagement/public/feature_list.h" |
John Abd-El-Malek | cdb5b52 | 2020-05-26 22:41:03 | [diff] [blame] | 230 | #include "components/google/core/common/google_switches.h" |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 231 | #include "components/keep_alive_registry/keep_alive_types.h" |
| 232 | #include "components/keep_alive_registry/scoped_keep_alive.h" |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 233 | #include "components/language/core/browser/pref_names.h" |
Evan Stade | bbb9f524 | 2020-09-25 17:26:46 | [diff] [blame] | 234 | #include "components/media_router/browser/presentation/presentation_service_delegate_impl.h" |
| 235 | #include "components/media_router/browser/presentation/receiver_presentation_service_delegate_impl.h" |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 236 | #include "components/metrics/client_info.h" |
John Abd-El-Malek | dc02601 | 2020-06-15 23:28:56 | [diff] [blame] | 237 | #include "components/metrics_services_manager/metrics_services_manager.h" |
droger | c690e880 | 2015-09-21 14:29:16 | [diff] [blame] | 238 | #include "components/net_log/chrome_net_log.h" |
Hiroki Nakagawa | b4cd18aa | 2021-01-25 18:11:01 | [diff] [blame] | 239 | #include "components/no_state_prefetch/browser/no_state_prefetch_manager.h" |
Hiroki Nakagawa | 76e0fe01b | 2020-11-06 04:32:45 | [diff] [blame] | 240 | #include "components/no_state_prefetch/common/prerender_final_status.h" |
Hiroki Nakagawa | 76e0fe01b | 2020-11-06 04:32:45 | [diff] [blame] | 241 | #include "components/no_state_prefetch/common/prerender_url_loader_throttle.h" |
| 242 | #include "components/no_state_prefetch/common/prerender_util.h" |
Mustafa Emre Acer | 06028d79 | 2021-01-05 19:48:51 | [diff] [blame] | 243 | #include "components/omnibox/common/omnibox_features.h" |
Tao Bai | b827b20 | 2019-09-19 21:22:12 | [diff] [blame] | 244 | #include "components/page_load_metrics/browser/metrics_navigation_throttle.h" |
| 245 | #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" |
Liquan (Max) Gu | 4fd38d86 | 2021-01-15 02:14:51 | [diff] [blame] | 246 | #include "components/payments/content/payment_handler_navigation_throttle.h" |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 247 | #include "components/payments/content/payment_request_display_manager.h" |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 248 | #include "components/performance_manager/embedder/performance_manager_registry.h" |
Clark DuVall | a11361ad3 | 2020-02-20 22:14:27 | [diff] [blame] | 249 | #include "components/permissions/permission_context_base.h" |
Scott Violet | 9389378 | 2020-03-27 16:23:54 | [diff] [blame] | 250 | #include "components/permissions/quota_permission_context_impl.h" |
Aaron Colwell | b422622 | 2020-07-25 16:11:36 | [diff] [blame] | 251 | #include "components/policy/content/policy_blocklist_navigation_throttle.h" |
| 252 | #include "components/policy/content/policy_blocklist_service.h" |
Chris Hamilton | 65c4131 | 2020-06-10 13:14:40 | [diff] [blame] | 253 | #include "components/policy/core/common/policy_pref_names.h" |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 254 | #include "components/policy/core/common/policy_service.h" |
| 255 | #include "components/policy/policy_constants.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 256 | #include "components/pref_registry/pref_registry_syncable.h" |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 257 | #include "components/prefs/pref_registry_simple.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 258 | #include "components/prefs/pref_service.h" |
| 259 | #include "components/prefs/scoped_user_pref_update.h" |
Sophie Chang | ff1fc38 | 2019-08-21 16:30:21 | [diff] [blame] | 260 | #include "components/previews/content/previews_decider.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 261 | #include "components/previews/content/previews_decider_impl.h" |
| 262 | #include "components/previews/content/previews_ui_service.h" |
| 263 | #include "components/previews/content/previews_user_data.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 264 | #include "components/previews/core/previews_experiments.h" |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 265 | #include "components/previews/core/previews_features.h" |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 266 | #include "components/previews/core/previews_switches.h" |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 267 | #include "components/safe_browsing/buildflags.h" |
Ali Juma | fb3dc1f | 2020-01-07 17:33:47 | [diff] [blame] | 268 | #include "components/safe_browsing/content/browser/browser_url_loader_throttle.h" |
| 269 | #include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h" |
| 270 | #include "components/safe_browsing/core/browser/url_checker_delegate.h" |
| 271 | #include "components/safe_browsing/core/common/safe_browsing_prefs.h" |
| 272 | #include "components/safe_browsing/core/db/database_manager.h" |
| 273 | #include "components/safe_browsing/core/features.h" |
| 274 | #include "components/safe_browsing/core/realtime/policy_engine.h" |
Xinghui Lu | e17b1994 | 2020-02-24 21:19:58 | [diff] [blame] | 275 | #include "components/safe_browsing/core/realtime/url_lookup_service.h" |
Carlos IL | 1a5edec | 2020-06-12 17:56:57 | [diff] [blame] | 276 | #include "components/security_interstitials/content/insecure_form_navigation_throttle.h" |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 277 | #include "components/security_interstitials/content/origin_policy_ui.h" |
Evan Stade | 1e71d6dd | 2019-10-29 03:04:49 | [diff] [blame] | 278 | #include "components/security_interstitials/content/ssl_cert_reporter.h" |
Colin Blundell | 5eb994b | 2020-01-28 11:50:48 | [diff] [blame] | 279 | #include "components/security_interstitials/content/ssl_error_handler.h" |
Evan Stade | 1e71d6dd | 2019-10-29 03:04:49 | [diff] [blame] | 280 | #include "components/security_interstitials/content/ssl_error_navigation_throttle.h" |
David Roger | e8e83f3c | 2019-09-12 10:56:23 | [diff] [blame] | 281 | #include "components/signin/public/identity_manager/identity_manager.h" |
Liquan (Max) Gu | 4fd38d86 | 2021-01-15 02:14:51 | [diff] [blame] | 282 | #include "components/site_engagement/content/site_engagement_service.h" |
Clark DuVall | aadc244c | 2020-06-06 03:47:14 | [diff] [blame] | 283 | #include "components/site_isolation/pref_names.h" |
Alex Moshchuk | 51e1428b | 2020-04-22 18:00:54 | [diff] [blame] | 284 | #include "components/site_isolation/preloaded_isolated_origins.h" |
Clark DuVall | aadc244c | 2020-06-06 03:47:14 | [diff] [blame] | 285 | #include "components/site_isolation/site_isolation_policy.h" |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 286 | #include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h" |
[email protected] | eba93c9 | 2014-01-07 17:34:17 | [diff] [blame] | 287 | #include "components/translate/core/common/translate_switches.h" |
Maks Orlovich | 5408ddfc | 2020-07-28 23:07:35 | [diff] [blame] | 288 | #include "components/ukm/content/source_url_recorder.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 289 | #include "components/url_formatter/url_fixer.h" |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 290 | #include "components/variations/variations_associated_data.h" |
Ben Goldberger | 72533cd | 2020-07-21 16:11:38 | [diff] [blame] | 291 | #include "components/variations/variations_ids_provider.h" |
Kyle Milka | b5c048e | 2017-07-07 02:38:46 | [diff] [blame] | 292 | #include "components/variations/variations_switches.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 293 | #include "components/version_info/version_info.h" |
Chris Blume | f59fc628 | 2020-02-21 00:18:39 | [diff] [blame] | 294 | #include "components/viz/common/features.h" |
Chris Blume | 7f752e3 | 2020-02-14 22:22:33 | [diff] [blame] | 295 | #include "components/viz/common/viz_utils.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 296 | #include "content/public/browser/browser_child_process_host.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 297 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 298 | #include "content/public/browser/browser_ppapi_host.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 299 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 300 | #include "content/public/browser/browser_thread.h" |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 301 | #include "content/public/browser/browser_url_handler.h" |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 302 | #include "content/public/browser/browsing_data_remover.h" |
Lucas Garron | b9539b73 | 2017-10-31 00:22:09 | [diff] [blame] | 303 | #include "content/public/browser/certificate_request_result_type.h" |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 304 | #include "content/public/browser/child_process_data.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 305 | #include "content/public/browser/child_process_security_policy.h" |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 306 | #include "content/public/browser/client_certificate_delegate.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 307 | #include "content/public/browser/file_url_loader.h" |
Olivier Yiptong | 935e6c4 | 2020-11-21 01:28:23 | [diff] [blame] | 308 | #include "content/public/browser/font_access_delegate.h" |
Mohsen Izadi | 6a6476b7 | 2018-12-07 04:34:35 | [diff] [blame] | 309 | #include "content/public/browser/gpu_data_manager.h" |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 310 | #include "content/public/browser/navigation_handle.h" |
| 311 | #include "content/public/browser/navigation_throttle.h" |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 312 | #include "content/public/browser/overlay_window.h" |
[email protected] | 094c877 | 2013-12-21 17:54:50 | [diff] [blame] | 313 | #include "content/public/browser/render_frame_host.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 314 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 315 | #include "content/public/browser/render_view_host.h" |
[email protected] | ce96786 | 2012-02-09 22:47:05 | [diff] [blame] | 316 | #include "content/public/browser/resource_context.h" |
Alex Moshchuk | 51e1428b | 2020-04-22 18:00:54 | [diff] [blame] | 317 | #include "content/public/browser/site_isolation_policy.h" |
jam | 608f299 | 2016-03-31 16:35:34 | [diff] [blame] | 318 | #include "content/public/browser/storage_partition.h" |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 319 | #include "content/public/browser/tts_controller.h" |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 320 | #include "content/public/browser/tts_platform.h" |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 321 | #include "content/public/browser/url_loader_request_interceptor.h" |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 322 | #include "content/public/browser/vpn_service_proxy.h" |
[email protected] | 91ee368 | 2012-01-19 15:02:19 | [diff] [blame] | 323 | #include "content/public/browser/web_contents.h" |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 324 | #include "content/public/browser/web_contents_delegate.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 325 | #include "content/public/browser/web_ui_url_loader_factory.h" |
Anatoliy Potapchuk | 096e4d0a | 2020-12-01 16:49:21 | [diff] [blame] | 326 | #include "content/public/common/bindings_policy.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 327 | #include "content/public/common/child_process_host.h" |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 328 | #include "content/public/common/content_descriptors.h" |
juncai | 1bf9f7c | 2016-03-22 20:46:56 | [diff] [blame] | 329 | #include "content/public/common/content_features.h" |
brettw | 90e9260 | 2015-10-10 00:12:40 | [diff] [blame] | 330 | #include "content/public/common/content_switches.h" |
Hans Wennborg | 5ffd139 | 2019-10-16 11:00:02 | [diff] [blame] | 331 | #include "content/public/common/navigation_policy.h" |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 332 | #include "content/public/common/network_service_util.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 333 | #include "content/public/common/url_constants.h" |
[email protected] | 22aa4f8 | 2013-09-24 17:01:44 | [diff] [blame] | 334 | #include "content/public/common/url_utils.h" |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 335 | #include "content/public/common/user_agent.h" |
Takuto Ikuta | aa3b796c | 2019-02-06 02:54:56 | [diff] [blame] | 336 | #include "content/public/common/window_container_type.mojom-shared.h" |
Bill Orr | eb42922 | 2018-08-08 21:14:43 | [diff] [blame] | 337 | #include "device/vr/buildflags/buildflags.h" |
Karandeep Bhatia | ae5d9f3 | 2020-07-17 02:52:34 | [diff] [blame] | 338 | #include "extensions/browser/process_map.h" |
Scott Violet | c8240b0 | 2018-03-08 22:03:59 | [diff] [blame] | 339 | #include "extensions/buildflags/buildflags.h" |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 340 | #include "google_apis/gaia/gaia_urls.h" |
Andrew Moylan | 17329fc | 2017-09-25 07:43:30 | [diff] [blame] | 341 | #include "google_apis/google_api_keys.h" |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 342 | #include "gpu/config/gpu_switches.h" |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 343 | #include "ipc/ipc_message.h" |
grunell | 086a411 | 2017-03-02 09:23:04 | [diff] [blame] | 344 | #include "media/audio/audio_manager.h" |
François Beaufort | 8c08979fc | 2018-03-05 13:06:31 | [diff] [blame] | 345 | #include "media/base/media_switches.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 346 | #include "media/media_buildflags.h" |
| 347 | #include "media/mojo/buildflags.h" |
Guido Urdaneta | d06ae84 | 2019-10-10 20:04:12 | [diff] [blame] | 348 | #include "media/webrtc/webrtc_switches.h" |
Shimi Zhang | 6b72d29 | 2019-07-12 20:52:42 | [diff] [blame] | 349 | #include "mojo/public/cpp/bindings/pending_associated_receiver.h" |
Julie Jeongeun Kim | 7f8e26a2 | 2019-10-10 12:09:52 | [diff] [blame] | 350 | #include "mojo/public/cpp/bindings/receiver_set.h" |
Ken Rockot | 0adc1e4 | 2019-05-24 08:20:08 | [diff] [blame] | 351 | #include "mojo/public/cpp/bindings/remote.h" |
engedy | afef048 | 2017-07-06 15:40:53 | [diff] [blame] | 352 | #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 353 | #include "net/base/load_flags.h" |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 354 | #include "net/base/mime_util.h" |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 355 | #include "net/ssl/client_cert_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 356 | #include "net/ssl/ssl_cert_request_info.h" |
Lukasz Anforowicz | 4600ea3 | 2020-01-18 02:37:48 | [diff] [blame] | 357 | #include "pdf/buildflags.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 358 | #include "ppapi/buildflags/buildflags.h" |
Scott Violet | 318a55f | 2018-03-30 19:08:19 | [diff] [blame] | 359 | #include "printing/buildflags/buildflags.h" |
Guido Urdaneta | e02b572 | 2020-07-22 05:58:21 | [diff] [blame] | 360 | #include "sandbox/policy/features.h" |
Robert Sesek | 7d0b49b | 2020-07-08 18:31:27 | [diff] [blame] | 361 | #include "sandbox/policy/sandbox_type.h" |
| 362 | #include "sandbox/policy/switches.h" |
Yue Ru Sun | 03a6990a | 2020-10-24 18:04:31 | [diff] [blame] | 363 | #include "services/metrics/public/cpp/ukm_source_id.h" |
Takashi Toyoshima | 12844146 | 2019-10-16 04:19:17 | [diff] [blame] | 364 | #include "services/network/public/cpp/features.h" |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 365 | #include "services/network/public/cpp/is_potentially_trustworthy.h" |
Lukasz Anforowicz | 9527fd4 | 2019-03-13 19:08:50 | [diff] [blame] | 366 | #include "services/network/public/cpp/network_switches.h" |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 367 | #include "services/network/public/cpp/resource_request.h" |
Lukasz Anforowicz | 25620d3 | 2021-01-27 22:03:44 | [diff] [blame] | 368 | #include "services/network/public/cpp/self_deleting_url_loader_factory.h" |
Ken Rockot | cebdf9c8 | 2019-05-28 20:33:03 | [diff] [blame] | 369 | #include "services/strings/grit/services_strings.h" |
DongJun Kim | febb3c2 | 2019-10-21 02:08:06 | [diff] [blame] | 370 | #include "storage/browser/file_system/external_mount_points.h" |
Hans Wennborg | 5ffd139 | 2019-10-16 11:00:02 | [diff] [blame] | 371 | #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" |
John Delaney | ac24e57 | 2019-04-30 19:47:02 | [diff] [blame] | 372 | #include "third_party/blink/public/common/features.h" |
Minggang Wang | b2f8290 | 2020-08-25 16:07:09 | [diff] [blame] | 373 | #include "third_party/blink/public/common/loader/referrer_utils.h" |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 374 | #include "third_party/blink/public/common/loader/url_loader_throttle.h" |
Mario Sanchez Prada | 0bd8b8c | 2020-10-21 17:49:23 | [diff] [blame] | 375 | #include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h" |
Chris Hamilton | 65c4131 | 2020-06-10 13:14:40 | [diff] [blame] | 376 | #include "third_party/blink/public/common/switches.h" |
Lily Chen | c2c9e9f | 2019-12-05 19:55:31 | [diff] [blame] | 377 | #include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h" |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 378 | #include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h" |
Gyuyoung Kim | 1e9d3c3 | 2020-10-12 14:04:57 | [diff] [blame] | 379 | #include "third_party/blink/public/mojom/webpreferences/web_preferences.mojom.h" |
Koji Ishii | 3cbd93a | 2020-10-16 13:48:02 | [diff] [blame] | 380 | #include "third_party/blink/public/public_buildflags.h" |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 381 | #include "third_party/skia/include/core/SkColor.h" |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 382 | #include "third_party/widevine/cdm/buildflags.h" |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 383 | #include "ui/base/clipboard/clipboard_format_type.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 384 | #include "ui/base/l10n/l10n_util.h" |
Scott Violet | 5ae6c42e | 2020-10-28 02:47:37 | [diff] [blame] | 385 | #include "ui/base/page_transition_types.h" |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 386 | #include "ui/base/resource/resource_bundle.h" |
Scott Violet | 8ff9c30 | 2018-02-22 22:28:35 | [diff] [blame] | 387 | #include "ui/base/ui_base_features.h" |
Khushal | 1fc0da5 | 2019-10-09 00:38:56 | [diff] [blame] | 388 | #include "ui/display/display.h" |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 389 | #include "ui/gfx/color_utils.h" |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 390 | #include "ui/native_theme/native_theme.h" |
[email protected] | b47dc49 | 2014-08-17 07:05:57 | [diff] [blame] | 391 | #include "ui/resources/grit/ui_resources.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 392 | #include "url/gurl.h" |
| 393 | #include "url/origin.h" |
Olya Kalitova | 78ae0493 | 2020-09-21 11:26:06 | [diff] [blame] | 394 | #include "url/third_party/mozilla/url_parse.h" |
| 395 | #include "url/url_constants.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 396 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 397 | #if defined(OS_WIN) |
wfh | c91e967 | 2016-01-27 00:14:20 | [diff] [blame] | 398 | #include "base/strings/string_tokenizer.h" |
Julian Pastarmov | b4773b8 | 2020-04-21 16:34:14 | [diff] [blame] | 399 | #include "base/win/win_util.h" |
| 400 | #include "base/win/windows_version.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 401 | #include "chrome/browser/chrome_browser_main_win.h" |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 402 | #include "chrome/install_static/install_util.h" |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 403 | #include "sandbox/win/src/sandbox_policy.h" |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 404 | #elif defined(OS_MAC) |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 405 | #include "chrome/browser/chrome_browser_main_mac.h" |
Evan Liu | 054dc08 | 2020-09-30 14:09:42 | [diff] [blame] | 406 | #include "components/soda/constants.h" |
| 407 | #include "sandbox/mac/seatbelt_exec.h" |
| 408 | #include "sandbox/policy/mac/sandbox_mac.h" |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 409 | #elif BUILDFLAG(IS_CHROMEOS_ASH) |
Alice Boxhall | da265914 | 2020-05-14 06:04:37 | [diff] [blame] | 410 | #include "ash/public/cpp/ash_pref_names.h" |
Xiyuan Xia | fc9f3813 | 2019-08-02 00:51:42 | [diff] [blame] | 411 | #include "ash/public/cpp/tablet_mode.h" |
Joshua Peraza | 30d8fc7 | 2019-08-19 17:24:30 | [diff] [blame] | 412 | #include "chrome/app/chrome_crash_reporter_client.h" |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 413 | #include "chrome/browser/browser_process.h" |
Andreea Costinas | 81218bf | 2021-01-08 11:48:14 | [diff] [blame] | 414 | #include "chrome/browser/browser_process_platform_part.h" |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 415 | #include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h" |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 416 | #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 417 | #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 418 | #include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h" |
Sam McNally | d8b7d82 | 2018-08-21 03:18:18 | [diff] [blame] | 419 | #include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h" |
[email protected] | 5bc61cad | 2014-07-08 05:05:08 | [diff] [blame] | 420 | #include "chrome/browser/chromeos/file_manager/app_id.h" |
[email protected] | 43420a1 | 2014-04-21 03:20:48 | [diff] [blame] | 421 | #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h" |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 422 | #include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h" |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 423 | #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 424 | #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h" |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 425 | #include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h" |
| 426 | #include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h" |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 427 | #include "chrome/browser/chromeos/login/signin_partition_manager.h" |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 428 | #include "chrome/browser/chromeos/login/startup_utils.h" |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 429 | #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 430 | #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 431 | #include "chrome/browser/chromeos/policy/system_features_disable_list_policy_handler.h" |
Andreea Costinas | 81218bf | 2021-01-08 11:48:14 | [diff] [blame] | 432 | #include "chrome/browser/chromeos/policy/system_proxy_manager.h" |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 433 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
Anand K. Mistry | 7694c36 | 2020-03-17 23:33:34 | [diff] [blame] | 434 | #include "chrome/browser/chromeos/smb_client/fileapi/smbfs_file_system_backend_delegate.h" |
[email protected] | c94ac69 | 2013-07-27 00:50:10 | [diff] [blame] | 435 | #include "chrome/browser/chromeos/system/input_device_settings.h" |
Katie D | b2d0709 | 2018-12-04 18:59:36 | [diff] [blame] | 436 | #include "chrome/browser/speech/tts_chromeos.h" |
Steven Bennetts | 81d07be | 2018-01-08 20:45:27 | [diff] [blame] | 437 | #include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h" |
djacobo | 21e56e0 | 2016-07-02 01:14:31 | [diff] [blame] | 438 | #include "chrome/browser/ui/browser_dialogs.h" |
Jesse Schettler | b7047f3 | 2020-09-18 14:50:40 | [diff] [blame] | 439 | #include "chromeos/components/scanning/url_constants.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 440 | #include "chromeos/constants/chromeos_constants.h" |
Kyle Horimoto | 1d6a679f | 2019-04-16 23:24:21 | [diff] [blame] | 441 | #include "chromeos/constants/chromeos_features.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 442 | #include "chromeos/constants/chromeos_switches.h" |
Rohit Rao | 92f84b6a | 2020-03-25 14:57:50 | [diff] [blame] | 443 | #include "components/crash/core/app/breakpad_linux.h" |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 444 | #include "components/policy/core/common/policy_pref_names.h" |
| 445 | #include "components/prefs/pref_service.h" |
John Abd-El-Malek | 35bfaa5 | 2019-08-20 16:22:07 | [diff] [blame] | 446 | #include "components/user_manager/user.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 447 | #include "components/user_manager/user_manager.h" |
Ken Rockot | 543f5e3 | 2018-02-04 02:13:50 | [diff] [blame] | 448 | #include "services/service_manager/public/mojom/interface_provider_spec.mojom.h" |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 449 | #elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 450 | #include "chrome/browser/chrome_browser_main_linux.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 451 | #elif defined(OS_ANDROID) |
Bo Liu | 4ade6b1b2 | 2017-11-28 02:26:35 | [diff] [blame] | 452 | #include "base/android/application_status_listener.h" |
Brandon Wylie | 21a88ac9 | 2020-05-15 02:49:23 | [diff] [blame] | 453 | #include "base/feature_list.h" |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 454 | #include "chrome/android/features/dev_ui/buildflags.h" |
Tibor Goldschwendt | bf1b96e | 2019-10-07 22:03:47 | [diff] [blame] | 455 | #include "chrome/android/modules/extra_icu/provider/module_provider.h" |
John Abd-El-Malek | 4f380d9 | 2020-02-19 16:43:36 | [diff] [blame] | 456 | #include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 457 | #include "chrome/browser/android/devtools_manager_delegate_android.h" |
| 458 | #include "chrome/browser/android/ntp/new_tab_page_url_handler.h" |
| 459 | #include "chrome/browser/android/service_tab_launcher.h" |
| 460 | #include "chrome/browser/android/tab_android.h" |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 461 | #include "chrome/browser/android/tab_web_contents_delegate_android.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 462 | #include "chrome/browser/chrome_browser_main_android.h" |
Min Qin | 86987406 | 2019-10-15 19:27:56 | [diff] [blame] | 463 | #include "chrome/browser/download/android/available_offline_content_provider.h" |
| 464 | #include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h" |
Brandon Wylie | 21a88ac9 | 2020-05-15 02:49:23 | [diff] [blame] | 465 | #include "chrome/browser/flags/android/chrome_feature_list.h" |
Jinsuk Kim | 6f9253c | 2019-03-11 02:45:07 | [diff] [blame] | 466 | #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
James Cook | 01e3e5ef | 2019-04-09 14:44:38 | [diff] [blame] | 467 | #include "chrome/common/chrome_descriptors.h" |
Joshua Peraza | 934e559 | 2018-07-18 23:43:11 | [diff] [blame] | 468 | #include "components/crash/content/browser/child_exit_observer_android.h" |
Yuzu Saijo | 2d12ef9 | 2018-08-21 04:52:07 | [diff] [blame] | 469 | #include "components/crash/content/browser/crash_memory_metrics_collector_android.h" |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 470 | #include "components/navigation_interception/intercept_navigation_delegate.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 471 | #include "content/public/browser/android/java_interfaces.h" |
mfomitchev | 220b856 | 2017-07-13 23:08:54 | [diff] [blame] | 472 | #include "services/service_manager/public/cpp/interface_provider.h" |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 473 | #include "ui/base/resource/resource_bundle_android.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 474 | #include "ui/base/ui_base_paths.h" |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 475 | #if BUILDFLAG(DFMIFY_DEV_UI) |
Samuel Huang | 3a1ce1c3 | 2019-10-16 17:34:04 | [diff] [blame] | 476 | #include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h" |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 477 | #endif // BUILDFLAG(DFMIFY_DEV_UI) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 478 | #elif defined(OS_POSIX) |
| 479 | #include "chrome/browser/chrome_browser_main_posix.h" |
| 480 | #endif |
| 481 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 482 | #if !BUILDFLAG(IS_CHROMEOS_ASH) |
Alice Boxhall | a9aafba4 | 2020-06-24 05:42:51 | [diff] [blame] | 483 | #include "ui/accessibility/accessibility_features.h" |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 484 | #endif // !BUILDFLAG(IS_CHROMEOS_ASH) |
Alice Boxhall | a9aafba4 | 2020-06-24 05:42:51 | [diff] [blame] | 485 | |
tmartino | fb34188 | 2017-02-10 19:36:53 | [diff] [blame] | 486 | #if !defined(OS_ANDROID) |
Jay Harris | 1ddcffa | 2019-07-09 03:07:40 | [diff] [blame] | 487 | #include "chrome/browser/badging/badge_manager.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 488 | #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 489 | #include "chrome/browser/devtools/devtools_window.h" |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 490 | #include "chrome/browser/media/unified_autoplay_config.h" |
Zach Trudo | cc4aa4d | 2020-09-21 22:19:45 | [diff] [blame] | 491 | #include "chrome/browser/policy/dm_token_utils.h" |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 492 | #include "chrome/browser/search/instant_service.h" |
| 493 | #include "chrome/browser/search/instant_service_factory.h" |
Reilly Grant | 2814fb7 | 2019-03-19 17:04:46 | [diff] [blame] | 494 | #include "chrome/browser/serial/chrome_serial_delegate.h" |
Collin Baker | 8a21755 | 2019-05-29 19:47:51 | [diff] [blame] | 495 | #include "chrome/browser/ui/browser.h" |
| 496 | #include "chrome/browser/ui/browser_finder.h" |
| 497 | #include "chrome/browser/ui/browser_list.h" |
| 498 | #include "chrome/browser/ui/browser_window.h" |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 499 | #include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h" |
Nina Satragno | 8c832df | 2019-07-29 15:59:39 | [diff] [blame] | 500 | #include "chrome/browser/webauthn/authenticator_request_scheduler.h" |
| 501 | #include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h" |
Jay Civelli | 4d53be9b | 2017-08-31 22:01:43 | [diff] [blame] | 502 | #include "chrome/common/importer/profile_import.mojom.h" |
Glen Robertson | 8a825ae4f | 2020-09-16 06:50:08 | [diff] [blame] | 503 | #include "chrome/grit/chrome_unscaled_resources.h" // nogncheck crbug.com/1125897 |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 504 | #endif // !defined(OS_ANDROID) |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 505 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 506 | // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch |
| 507 | // of lacros-chrome is complete. |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 508 | #if defined(OS_WIN) || defined(OS_MAC) || \ |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 509 | (defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)) |
Nicolas Ouellet-Payeur | 4b840a9 | 2018-09-18 14:46:52 | [diff] [blame] | 510 | #include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h" |
| 511 | #endif |
| 512 | |
Sean McAllister | 0d73ca3d | 2020-08-19 17:54:37 | [diff] [blame] | 513 | #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
Rohit Rao | 92f84b6a | 2020-03-25 14:57:50 | [diff] [blame] | 514 | #include "components/crash/core/app/crash_switches.h" |
| 515 | #include "components/crash/core/app/crashpad.h" |
Joshua Peraza | ce68e2f | 2019-09-23 18:44:24 | [diff] [blame] | 516 | #endif |
| 517 | |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 518 | #if defined(OS_POSIX) && !defined(OS_MAC) |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 519 | #if !defined(OS_ANDROID) |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 520 | #include "base/debug/leak_annotations.h" |
Rohit Rao | 92f84b6a | 2020-03-25 14:57:50 | [diff] [blame] | 521 | #include "components/crash/core/app/breakpad_linux.h" |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 522 | #endif // !defined(OS_ANDROID) |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 523 | #include "components/crash/content/browser/crash_handler_host_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 524 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 525 | |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 526 | // TODO(crbug.com/939205): Once the upcoming App Service is available, use a |
| 527 | // single navigation throttle to display the intent picker on all platforms. |
| 528 | #if !defined(OS_ANDROID) |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 529 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 530 | #include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h" |
Maggie Cai | 00e2a21e | 2019-10-16 00:47:51 | [diff] [blame] | 531 | #include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h" |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 532 | #else |
| 533 | #include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h" |
| 534 | #endif |
| 535 | #endif |
| 536 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 537 | #if defined(TOOLKIT_VIEWS) |
| 538 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h" |
| 539 | #endif |
| 540 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 541 | // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch |
| 542 | // of lacros-chrome is complete. |
| 543 | #if defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 544 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h" |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 545 | #endif |
| 546 | |
Mohsen Izadi | f1958f2 | 2019-01-18 20:29:31 | [diff] [blame] | 547 | #if defined(USE_OZONE) |
| 548 | #include "ui/ozone/public/ozone_platform.h" |
| 549 | #endif |
| 550 | |
Maksim Sisov | 1686fc2 | 2020-06-17 07:59:20 | [diff] [blame] | 551 | #if defined(USE_X11) || defined(USE_OZONE) |
| 552 | #include "chrome/browser/chrome_browser_main_extra_parts_ozone.h" |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 553 | #endif |
| 554 | |
brettw | ab78fef | 2016-10-12 02:56:05 | [diff] [blame] | 555 | #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
Colin Blundell | ca2b20e | 2020-01-28 10:07:10 | [diff] [blame] | 556 | #include "components/captive_portal/content/captive_portal_tab_helper.h" |
Colin Blundell | 11999f37 | 2020-01-28 14:17:38 | [diff] [blame] | 557 | #include "components/captive_portal/content/captive_portal_url_loader_throttle.h" |
[email protected] | 7a2a6d80 | 2014-06-06 13:39:19 | [diff] [blame] | 558 | #endif |
| 559 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 560 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 561 | #include "components/nacl/browser/nacl_browser.h" |
| 562 | #include "components/nacl/browser/nacl_host_message_filter.h" |
| 563 | #include "components/nacl/browser/nacl_process_host.h" |
| 564 | #include "components/nacl/common/nacl_process_type.h" |
| 565 | #include "components/nacl/common/nacl_switches.h" |
| 566 | #endif |
| 567 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 568 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 569 | #include "chrome/browser/accessibility/animation_policy_prefs.h" |
Dominick Ng | 6ff5105 | 2018-07-06 05:30:20 | [diff] [blame] | 570 | #include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h" |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 571 | #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 572 | #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
Pavol Marko | 41c37b1 | 2019-08-07 10:56:32 | [diff] [blame] | 573 | #include "chrome/browser/extensions/extension_util.h" |
Clark DuVall | 2cf99249e | 2018-09-19 19:11:51 | [diff] [blame] | 574 | #include "chrome/browser/extensions/user_script_listener.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 575 | #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" |
Evan Stade | 1e71d6dd | 2019-10-29 03:04:49 | [diff] [blame] | 576 | #include "chrome/browser/ui/browser_commands.h" |
Eric Willigers | 007ef30 | 2019-08-29 09:58:46 | [diff] [blame] | 577 | #include "chrome/browser/ui/web_applications/app_browser_controller.h" |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 578 | #include "components/guest_view/browser/guest_view_base.h" |
| 579 | #include "components/guest_view/browser/guest_view_manager.h" |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 580 | #include "extensions/browser/api/web_request/web_request_api.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 581 | #include "extensions/browser/extension_host.h" |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 582 | #include "extensions/browser/extension_navigation_throttle.h" |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 583 | #include "extensions/browser/extension_protocols.h" |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 584 | #include "extensions/browser/extension_registry.h" |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 585 | #include "extensions/browser/extension_system.h" |
Aaron Colwell | 8c43064 | 2020-08-04 01:55:20 | [diff] [blame] | 586 | #include "extensions/browser/extension_util.h" |
hanxi | 0d0a1e9 | 2014-08-26 18:39:48 | [diff] [blame] | 587 | #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 588 | #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
| 589 | #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 590 | #include "extensions/browser/process_manager.h" |
Dan Beam | 836c02a | 2019-06-15 01:58:27 | [diff] [blame] | 591 | #include "extensions/common/constants.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 592 | #include "extensions/common/extension.h" |
| 593 | #include "extensions/common/extension_set.h" |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 594 | #include "extensions/common/manifest_handlers/background_info.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 595 | #include "extensions/common/manifest_handlers/shared_module_info.h" |
Clark DuVall | bf7722f | 2018-08-03 18:03:33 | [diff] [blame] | 596 | #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 597 | #include "extensions/common/permissions/permissions_data.h" |
| 598 | #include "extensions/common/permissions/socket_permission.h" |
| 599 | #include "extensions/common/switches.h" |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 600 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
merkin | db10455e | 2017-02-28 13:16:25 | [diff] [blame] | 601 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 602 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 603 | #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h" |
John Abd-El-Malek | ecc6f5f | 2018-03-02 18:47:39 | [diff] [blame] | 604 | #include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h" |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 605 | #endif |
| 606 | |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 607 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 608 | #include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h" |
| 609 | #endif |
| 610 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 611 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Henrique Ferreiro | 53d4dc4 | 2021-01-27 01:02:38 | [diff] [blame] | 612 | #include "chrome/browser/ash/app_mode/kiosk_settings_navigation_throttle.h" |
yilkal | 240b4f2 | 2019-11-27 19:09:06 | [diff] [blame] | 613 | #include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h" |
Scott Violet | 1644cf7 | 2020-06-24 04:51:55 | [diff] [blame] | 614 | #include "chrome/browser/speech/tts_controller_delegate_impl.h" |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 615 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
yilkal | 240b4f2 | 2019-11-27 19:09:06 | [diff] [blame] | 616 | |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 617 | #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 618 | #include "chrome/browser/media/cast_remoting_connector.h" |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 619 | #endif |
| 620 | |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 621 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c86d76e4 | 2016-03-14 23:38:49 | [diff] [blame] | 622 | #include "chrome/browser/media/output_protection_impl.h" |
Jeffrey Kardatzke | 61442423 | 2020-12-12 00:54:06 | [diff] [blame] | 623 | #if BUILDFLAG(ENABLE_WIDEVINE) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 624 | #include "third_party/widevine/cdm/widevine_cdm_common.h" |
Jeffrey Kardatzke | 61442423 | 2020-12-12 00:54:06 | [diff] [blame] | 625 | #if defined(OS_WIN) || BUILDFLAG(USE_CHROMEOS_PROTECTED_MEDIA) |
| 626 | #include "chrome/browser/media/widevine_hardware_caps.h" |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 627 | #endif |
Jeffrey Kardatzke | 61442423 | 2020-12-12 00:54:06 | [diff] [blame] | 628 | #endif // BUILDFLAG(ENABLE_WIDEVINE) |
| 629 | #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 630 | |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 631 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 632 | #include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h" |
| 633 | #endif |
| 634 | |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 635 | #if BUILDFLAG(SAFE_BROWSING_AVAILABLE) |
Daniel Rubery | a1611e3 | 2019-04-24 21:38:35 | [diff] [blame] | 636 | #include "chrome/browser/safe_browsing/chrome_password_protection_service.h" |
Daniel Rubery | 9eb1e091 | 2020-05-08 17:57:32 | [diff] [blame] | 637 | #include "chrome/browser/safe_browsing/client_side_detection_service_factory.h" |
Daniel Rubery | a1611e3 | 2019-04-24 21:38:35 | [diff] [blame] | 638 | #endif |
| 639 | |
Glen Robertson | 8a825ae4f | 2020-09-16 06:50:08 | [diff] [blame] | 640 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) |
| 641 | #include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service.h" // nogncheck crbug.com/1125897 |
| 642 | #include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service_factory.h" // nogncheck crbug.com/1125897 |
| 643 | #endif |
| 644 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 645 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 646 | #include "chrome/browser/offline_pages/offline_page_tab_helper.h" |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 647 | #include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h" |
| 648 | #endif |
| 649 | |
Will Cassella | 40837ba | 2019-07-01 21:32:00 | [diff] [blame] | 650 | #if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID) |
Glen Robertson | 8a825ae4f | 2020-09-16 06:50:08 | [diff] [blame] | 651 | #include "device/vr/public/mojom/isolated_xr_service.mojom.h" // nogncheck crbug.com/1125897 |
Bill Orr | eb42922 | 2018-08-08 21:14:43 | [diff] [blame] | 652 | #endif |
| 653 | |
John Lee | 0ee748bf | 2019-12-11 21:35:44 | [diff] [blame] | 654 | #if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP) |
| 655 | #include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h" |
| 656 | #endif |
| 657 | |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 658 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
Dominique Fauteux-Chapleau | 7191299 | 2020-10-22 18:15:37 | [diff] [blame] | 659 | #include "chrome/browser/enterprise/connectors/content_analysis_delegate.h" |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 660 | #endif |
| 661 | |
Alexander Cooper | c844870 | 2020-03-14 01:39:56 | [diff] [blame] | 662 | #if BUILDFLAG(ENABLE_VR) |
Alexander Cooper | f4b3013d | 2020-03-23 18:47:23 | [diff] [blame] | 663 | #include "chrome/browser/vr/chrome_xr_integration_client.h" |
Alexander Cooper | c844870 | 2020-03-14 01:39:56 | [diff] [blame] | 664 | #endif |
| 665 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 666 | #if BUILDFLAG(IS_CHROMEOS_LACROS) |
James Cook | 70fee986 | 2020-11-18 17:28:40 | [diff] [blame] | 667 | #include "chrome/browser/chrome_browser_main_parts_lacros.h" |
Antonio Gomes | aa260336 | 2020-10-24 12:20:18 | [diff] [blame] | 668 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_lacros.h" |
James Cook | 9273025 | 2020-07-22 01:57:26 | [diff] [blame] | 669 | #include "chromeos/lacros/lacros_chrome_service_impl.h" |
James Cook | 247a8cb | 2020-12-22 23:09:51 | [diff] [blame] | 670 | #include "ui/base/ui_base_switches.h" |
Hidehiko Abe | eaffbbce | 2020-06-23 19:41:52 | [diff] [blame] | 671 | #endif |
| 672 | |
Koji Ishii | 3cbd93a | 2020-10-16 13:48:02 | [diff] [blame] | 673 | #if BUILDFLAG(USE_MINIKIN_HYPHENATION) && !defined(OS_ANDROID) |
| 674 | #include "chrome/browser/component_updater/hyphenation_component_installer.h" |
| 675 | #endif |
| 676 | |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 677 | using base::FileDescriptor; |
Gyuyoung Kim | d6d4f99 | 2020-11-20 14:13:22 | [diff] [blame] | 678 | using blink::mojom::EffectiveConnectionType; |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 679 | using blink::web_pref::WebPreferences; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 680 | using content::BrowserThread; |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 681 | using content::BrowserURLHandler; |
msramek | a3c7cfd | 2017-02-03 13:34:13 | [diff] [blame] | 682 | using content::BrowsingDataFilterBuilder; |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 683 | using content::ChildProcessSecurityPolicy; |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 684 | using content::QuotaPermissionContext; |
[email protected] | 2626d14 | 2014-04-22 17:24:02 | [diff] [blame] | 685 | using content::RenderFrameHost; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 686 | using content::RenderViewHost; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 687 | using content::SiteInstance; |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 688 | using content::WebContents; |
[email protected] | 593d2a7 | 2013-07-26 08:48:38 | [diff] [blame] | 689 | using message_center::NotifierId; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 690 | |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 691 | #if defined(OS_POSIX) |
brettw | 3c98c7d3 | 2017-07-25 01:44:20 | [diff] [blame] | 692 | using content::PosixFileDescriptorInfo; |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 693 | #endif |
| 694 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 695 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 696 | using extensions::APIPermission; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 697 | using extensions::ChromeContentBrowserClientExtensionsPart; |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 698 | using extensions::Extension; |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 699 | using extensions::Manifest; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 700 | #endif |
| 701 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 702 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 703 | using plugins::ChromeContentBrowserClientPluginsPart; |
| 704 | #endif |
| 705 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 706 | namespace { |
| 707 | |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 708 | #if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 709 | // Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when |
| 710 | // running on Windows 10 1511 and above. See |
| 711 | // https://blogs.windows.com/blog/tag/code-integrity-guard/. |
| 712 | const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity", |
Will Harris | a9eaa28 | 2019-11-01 17:51:35 | [diff] [blame] | 713 | base::FEATURE_ENABLED_BY_DEFAULT}; |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 714 | #endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) && |
| 715 | // !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 716 | |
Nicolas Arciniega | fa9f4c9 | 2021-01-22 19:49:25 | [diff] [blame] | 717 | bool IsSSLErrorOverrideAllowedForUrl(const GURL& request_url, |
| 718 | PrefService* prefs) { |
| 719 | DCHECK(request_url.SchemeIsCryptographic()); |
| 720 | |
| 721 | if (!prefs->GetBoolean(prefs::kSSLErrorOverrideAllowed)) |
| 722 | return false; |
| 723 | |
| 724 | if (!prefs->GetList(prefs::kSSLErrorOverrideAllowedForUrls)) |
| 725 | return true; |
| 726 | |
| 727 | base::Value::ConstListView allow_list_urls = |
| 728 | prefs->GetList(prefs::kSSLErrorOverrideAllowedForUrls)->GetList(); |
| 729 | if (allow_list_urls.empty()) |
| 730 | return true; |
| 731 | |
| 732 | for (auto const& value : allow_list_urls) { |
| 733 | ContentSettingsPattern pattern = |
| 734 | ContentSettingsPattern::FromString(value.GetString()); |
| 735 | if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid()) |
| 736 | continue; |
| 737 | if (pattern.Matches(request_url)) |
| 738 | return true; |
| 739 | } |
| 740 | |
| 741 | return false; |
| 742 | } |
| 743 | |
Colin Blundell | 9ee731dd | 2020-01-23 10:42:38 | [diff] [blame] | 744 | // Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level |
| 745 | // parameters. |
| 746 | void HandleSSLErrorWrapper( |
| 747 | content::WebContents* web_contents, |
| 748 | int cert_error, |
| 749 | const net::SSLInfo& ssl_info, |
| 750 | const GURL& request_url, |
| 751 | std::unique_ptr<SSLCertReporter> ssl_cert_reporter, |
Colin Blundell | 9ee731dd | 2020-01-23 10:42:38 | [diff] [blame] | 752 | SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) { |
| 753 | Profile* profile = |
| 754 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Scott Violet | 2fb48110 | 2020-07-27 00:23:54 | [diff] [blame] | 755 | // Profile should always outlive a WebContents |
| 756 | DCHECK(profile); |
Colin Blundell | 9ee731dd | 2020-01-23 10:42:38 | [diff] [blame] | 757 | |
Colin Blundell | 27331f9 | 2020-02-05 21:13:01 | [diff] [blame] | 758 | captive_portal::CaptivePortalService* captive_portal_service = nullptr; |
Colin Blundell | 111b61c0 | 2020-01-24 11:53:51 | [diff] [blame] | 759 | |
| 760 | #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 761 | captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile); |
| 762 | #endif |
| 763 | |
Colin Blundell | 9ee731dd | 2020-01-23 10:42:38 | [diff] [blame] | 764 | SSLErrorHandler::HandleSSLError( |
| 765 | web_contents, cert_error, ssl_info, request_url, |
Colin Blundell | a3fc122 | 2020-01-23 11:41:53 | [diff] [blame] | 766 | std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback), |
Colin Blundell | 111b61c0 | 2020-01-24 11:53:51 | [diff] [blame] | 767 | g_browser_process->network_time_tracker(), captive_portal_service, |
Colin Blundell | 13e92ec | 2020-01-27 09:47:38 | [diff] [blame] | 768 | std::make_unique<ChromeSecurityBlockingPageFactory>(), |
Nicolas Arciniega | fa9f4c9 | 2021-01-22 19:49:25 | [diff] [blame] | 769 | IsSSLErrorOverrideAllowedForUrl(request_url, profile->GetPrefs())); |
Colin Blundell | 9ee731dd | 2020-01-23 10:42:38 | [diff] [blame] | 770 | } |
| 771 | |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 772 | enum AppLoadedInTabSource { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 773 | // A platform app page tried to load one of its own URLs in a tab. |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 774 | APP_LOADED_IN_TAB_SOURCE_APP = 0, |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 775 | |
| 776 | // A platform app background page tried to load one of its own URLs in a tab. |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 777 | APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE, |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 778 | |
| 779 | // An extension or app tried to load a resource of a different platform app in |
| 780 | // a tab. |
| 781 | APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION, |
| 782 | |
| 783 | // A non-app and non-extension page tried to load a platform app in a tab. |
| 784 | APP_LOADED_IN_TAB_SOURCE_OTHER, |
| 785 | |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 786 | APP_LOADED_IN_TAB_SOURCE_MAX |
| 787 | }; |
| 788 | |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 789 | // Cached version of the locale so we can return the locale on the I/O |
| 790 | // thread. |
| 791 | std::string& GetIOThreadApplicationLocale() { |
| 792 | static base::NoDestructor<std::string> s; |
| 793 | return *s; |
| 794 | } |
| 795 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 796 | // Returns a copy of the given url with its host set to given host and path set |
| 797 | // to given path. Other parts of the url will be the same. |
| 798 | GURL ReplaceURLHostAndPath(const GURL& url, |
| 799 | const std::string& host, |
| 800 | const std::string& path) { |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 801 | url::Replacements<char> replacements; |
| 802 | replacements.SetHost(host.c_str(), url::Component(0, host.length())); |
| 803 | replacements.SetPath(path.c_str(), url::Component(0, path.length())); |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 804 | return url.ReplaceComponents(replacements); |
| 805 | } |
| 806 | |
mad | fbd1085 | 2017-01-20 03:15:33 | [diff] [blame] | 807 | // Handles the rewriting of the new tab page URL based on group policy. |
| 808 | bool HandleNewTabPageLocationOverride( |
| 809 | GURL* url, |
| 810 | content::BrowserContext* browser_context) { |
| 811 | if (!url->SchemeIs(content::kChromeUIScheme) || |
| 812 | url->host() != chrome::kChromeUINewTabHost) |
| 813 | return false; |
| 814 | |
| 815 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 816 | std::string ntp_location = |
| 817 | profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride); |
| 818 | if (ntp_location.empty()) |
| 819 | return false; |
Olya Kalitova | 78ae0493 | 2020-09-21 11:26:06 | [diff] [blame] | 820 | url::Component scheme; |
| 821 | if (!url::ExtractScheme(ntp_location.data(), |
| 822 | static_cast<int>(ntp_location.length()), &scheme)) { |
| 823 | ntp_location = base::StrCat( |
| 824 | {url::kHttpsScheme, url::kStandardSchemeSeparator, ntp_location}); |
| 825 | } |
mad | fbd1085 | 2017-01-20 03:15:33 | [diff] [blame] | 826 | |
| 827 | *url = GURL(ntp_location); |
| 828 | return true; |
| 829 | } |
| 830 | |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 831 | #if !defined(OS_ANDROID) |
| 832 | // Check if the current url is whitelisted based on a list of whitelisted urls. |
| 833 | bool IsURLWhitelisted(const GURL& current_url, |
Jan Wilken Dörrie | 8d9034f1 | 2019-11-28 14:48:57 | [diff] [blame] | 834 | base::Value::ConstListView whitelisted_urls) { |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 835 | // Only check on HTTP and HTTPS pages. |
| 836 | if (!current_url.SchemeIsHTTPOrHTTPS()) |
| 837 | return false; |
| 838 | |
| 839 | for (auto const& value : whitelisted_urls) { |
| 840 | ContentSettingsPattern pattern = |
| 841 | ContentSettingsPattern::FromString(value.GetString()); |
| 842 | if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid()) |
| 843 | continue; |
| 844 | if (pattern.Matches(current_url)) |
| 845 | return true; |
| 846 | } |
| 847 | |
| 848 | return false; |
| 849 | } |
| 850 | |
| 851 | // Check if autoplay is allowed by policy configuration. |
| 852 | bool IsAutoplayAllowedByPolicy(content::WebContents* contents, |
| 853 | PrefService* prefs) { |
| 854 | DCHECK(prefs); |
| 855 | |
| 856 | // Check if we have globally allowed autoplay by policy. |
| 857 | if (prefs->GetBoolean(prefs::kAutoplayAllowed) && |
| 858 | prefs->IsManagedPreference(prefs::kAutoplayAllowed)) { |
| 859 | return true; |
| 860 | } |
| 861 | |
| 862 | if (!contents) |
| 863 | return false; |
| 864 | |
| 865 | // Check if the current URL matches a URL pattern on the whitelist. |
| 866 | const base::ListValue* autoplay_whitelist = |
| 867 | prefs->GetList(prefs::kAutoplayWhitelist); |
| 868 | return autoplay_whitelist && |
| 869 | prefs->IsManagedPreference(prefs::kAutoplayWhitelist) && |
| 870 | IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList()); |
| 871 | } |
| 872 | #endif |
| 873 | |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 874 | #if defined(OS_ANDROID) |
| 875 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
| 876 | return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket(); |
| 877 | } |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 878 | #elif defined(OS_POSIX) && !defined(OS_MAC) |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 879 | breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( |
| 880 | const std::string& process_type) { |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 881 | base::FilePath dumps_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 882 | base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 883 | { |
| 884 | ANNOTATE_SCOPED_MEMORY_LEAK; |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 885 | bool upload = !getenv(env_vars::kHeadless); |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 886 | breakpad::CrashHandlerHostLinux* crash_handler = |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 887 | new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 888 | crash_handler->StartUploaderThread(); |
| 889 | return crash_handler; |
| 890 | } |
| 891 | } |
| 892 | |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 893 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
Joshua Peraza | ce68e2f | 2019-09-23 18:44:24 | [diff] [blame] | 894 | if (crash_reporter::IsCrashpadEnabled()) { |
| 895 | int fd; |
| 896 | pid_t pid; |
| 897 | return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1; |
| 898 | } |
| 899 | |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 900 | // Extensions have the same process type as renderers. |
[email protected] | cd0f7af | 2014-01-16 23:50:39 | [diff] [blame] | 901 | if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 902 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 903 | if (!crash_handler) |
| 904 | crash_handler = CreateCrashHandlerHost("extension"); |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 905 | return crash_handler->GetDeathSignalSocket(); |
| 906 | } |
| 907 | |
| 908 | std::string process_type = |
| 909 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 910 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 911 | if (process_type == switches::kRendererProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 912 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 913 | if (!crash_handler) |
| 914 | crash_handler = CreateCrashHandlerHost(process_type); |
| 915 | return crash_handler->GetDeathSignalSocket(); |
| 916 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 917 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 918 | if (process_type == switches::kPpapiPluginProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 919 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 920 | if (!crash_handler) |
| 921 | crash_handler = CreateCrashHandlerHost(process_type); |
| 922 | return crash_handler->GetDeathSignalSocket(); |
| 923 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 924 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 925 | if (process_type == switches::kGpuProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 926 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 927 | if (!crash_handler) |
| 928 | crash_handler = CreateCrashHandlerHost(process_type); |
| 929 | return crash_handler->GetDeathSignalSocket(); |
| 930 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 931 | |
James Cook | 9207cc1 | 2017-10-19 17:08:39 | [diff] [blame] | 932 | if (process_type == switches::kUtilityProcess) { |
| 933 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
| 934 | if (!crash_handler) |
| 935 | crash_handler = CreateCrashHandlerHost(process_type); |
| 936 | return crash_handler->GetDeathSignalSocket(); |
| 937 | } |
| 938 | |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 939 | return -1; |
| 940 | } |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 941 | #endif // defined(OS_ANDROID) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 942 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 943 | void SetApplicationLocaleOnIOThread(const std::string& locale) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 944 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 945 | GetIOThreadApplicationLocale() = locale; |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 946 | } |
| 947 | |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 948 | // An implementation of the SSLCertReporter interface used by |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 949 | // SSLErrorHandler. Uses CertificateReportingService to send reports. The |
| 950 | // service handles queueing and re-sending of failed reports. Each certificate |
| 951 | // error creates a new instance of this class. |
| 952 | class CertificateReportingServiceCertReporter : public SSLCertReporter { |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 953 | public: |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 954 | explicit CertificateReportingServiceCertReporter( |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 955 | content::WebContents* web_contents) |
| 956 | : service_(CertificateReportingServiceFactory::GetForBrowserContext( |
| 957 | web_contents->GetBrowserContext())) {} |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 958 | ~CertificateReportingServiceCertReporter() override {} |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 959 | |
| 960 | // SSLCertReporter implementation |
estark | 4282f117 | 2015-05-13 22:01:55 | [diff] [blame] | 961 | void ReportInvalidCertificateChain( |
| 962 | const std::string& serialized_report) override { |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 963 | service_->Send(serialized_report); |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | private: |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 967 | CertificateReportingService* service_; |
| 968 | |
| 969 | DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter); |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 970 | }; |
| 971 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 972 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 973 | |
| 974 | AppLoadedInTabSource ClassifyAppLoadedInTabSource( |
| 975 | const GURL& opener_url, |
| 976 | const extensions::Extension* target_platform_app) { |
Lei Zhang | 7d0b0f4 | 2019-10-12 03:47:58 | [diff] [blame] | 977 | if (!opener_url.SchemeIs(extensions::kExtensionScheme)) { |
| 978 | // The forbidden app URL was being opened by a non-extension page (e.g. |
| 979 | // http). |
| 980 | return APP_LOADED_IN_TAB_SOURCE_OTHER; |
| 981 | } |
| 982 | |
| 983 | if (opener_url.host_piece() != target_platform_app->id()) { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 984 | // The forbidden app URL was being opened by a different app or extension. |
| 985 | return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION; |
| 986 | } |
Lei Zhang | 7d0b0f4 | 2019-10-12 03:47:58 | [diff] [blame] | 987 | |
| 988 | // This platform app was trying to window.open() one of its own URLs. |
| 989 | if (opener_url == |
| 990 | extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) { |
| 991 | // Source was the background page. |
| 992 | return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE; |
| 993 | } |
| 994 | |
| 995 | // Source was a different page inside the app. |
| 996 | return APP_LOADED_IN_TAB_SOURCE_APP; |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 997 | } |
[email protected] | 9c765638 | 2014-08-08 21:02:30 | [diff] [blame] | 998 | |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 999 | // Returns true if there is is an extension matching |url| in |
| 1000 | // |opener_render_process_id| with APIPermission::kBackground. |
| 1001 | // |
| 1002 | // Note that GetExtensionOrAppByURL requires a full URL in order to match with a |
| 1003 | // hosted app, even though normal extensions just use the host. |
| 1004 | bool URLHasExtensionBackgroundPermission( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 1005 | extensions::ProcessMap* process_map, |
| 1006 | extensions::ExtensionRegistry* registry, |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 1007 | const GURL& url, |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 1008 | int opener_render_process_id) { |
| 1009 | // Note: includes web URLs that are part of an extension's web extent. |
| 1010 | const Extension* extension = |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 1011 | registry->enabled_extensions().GetExtensionOrAppByURL(url); |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 1012 | return extension && |
| 1013 | extension->permissions_data()->HasAPIPermission( |
| 1014 | APIPermission::kBackground) && |
| 1015 | process_map->Contains(extension->id(), opener_render_process_id); |
| 1016 | } |
Kevin Marshall | 32f99d7e | 2017-07-11 23:17:46 | [diff] [blame] | 1017 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 1018 | #endif |
| 1019 | |
Miyoung Shin | 6694b8e | 2020-06-18 01:38:17 | [diff] [blame] | 1020 | mojo::PendingRemote<prerender::mojom::PrerenderCanceler> GetPrerenderCanceler( |
Alexander Cooper | bc87af3 | 2020-07-15 15:59:45 | [diff] [blame] | 1021 | base::OnceCallback<content::WebContents*()> wc_getter) { |
Miyoung Shin | 6694b8e | 2020-06-18 01:38:17 | [diff] [blame] | 1022 | mojo::PendingRemote<prerender::mojom::PrerenderCanceler> canceler; |
Hiroki Nakagawa | 7230e341 | 2021-01-22 10:08:29 | [diff] [blame] | 1023 | prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents( |
Mugdha Lakhani | 2c6b23af | 2020-07-31 14:55:57 | [diff] [blame] | 1024 | std::move(wc_getter).Run()) |
Darin Fisher | e41aab5 | 2020-01-29 18:31:23 | [diff] [blame] | 1025 | ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver()); |
| 1026 | return canceler; |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 1027 | } |
| 1028 | |
Julian Pastarmov | b4773b8 | 2020-04-21 16:34:14 | [diff] [blame] | 1029 | // Encapculates logic to determine if enterprise policies should be honored. |
| 1030 | // This is a copy of the code in policy_loader_win.cc but it's ok to duplicate |
| 1031 | // as a new central class to replace those checks is in the making. |
| 1032 | bool ShouldHonorPolicies() { |
| 1033 | #if defined(OS_WIN) |
| 1034 | bool is_enterprise_version = |
| 1035 | base::win::OSInfo::GetInstance()->version_type() != base::win::SUITE_HOME; |
| 1036 | return base::win::IsEnrolledToDomain() || |
| 1037 | (base::win::IsDeviceRegisteredWithManagement() && |
| 1038 | is_enterprise_version); |
| 1039 | #else // defined(OS_WIN) |
| 1040 | // TODO(pastarmovj): Replace this with check for MacOS and the new management |
| 1041 | // service once it is ready. |
| 1042 | return true; |
| 1043 | #endif // defined(OS_WIN) |
| 1044 | } |
| 1045 | |
John Abd-El-Malek | 92bf360 | 2019-07-31 02:25:48 | [diff] [blame] | 1046 | void LaunchURL(const GURL& url, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 1047 | content::WebContents::OnceGetter web_contents_getter, |
John Abd-El-Malek | 92bf360 | 2019-07-31 02:25:48 | [diff] [blame] | 1048 | ui::PageTransition page_transition, |
Emily Stark | 13b66bdf | 2019-10-04 17:11:45 | [diff] [blame] | 1049 | bool has_user_gesture, |
| 1050 | const base::Optional<url::Origin>& initiating_origin) { |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1051 | // If there is no longer a WebContents, the request may have raced with tab |
| 1052 | // closing. Don't fire the external request. (It may have been a prerender.) |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 1053 | content::WebContents* web_contents = std::move(web_contents_getter).Run(); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1054 | if (!web_contents) |
| 1055 | return; |
| 1056 | |
Hiroki Nakagawa | 7230e341 | 2021-01-22 10:08:29 | [diff] [blame] | 1057 | // Do not launch external requests attached to unswapped no-state prefetchers. |
| 1058 | prerender::NoStatePrefetchContents* no_state_prefetch_contents = |
| 1059 | prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents( |
| 1060 | web_contents); |
| 1061 | if (no_state_prefetch_contents) { |
| 1062 | no_state_prefetch_contents->Destroy( |
| 1063 | prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1064 | return; |
| 1065 | } |
| 1066 | |
Robbie McElrath | 1294d24 | 2019-05-31 20:46:22 | [diff] [blame] | 1067 | // Do not launch external requests for schemes that have a handler registered. |
| 1068 | ProtocolHandlerRegistry* protocol_handler_registry = |
| 1069 | ProtocolHandlerRegistryFactory::GetForBrowserContext( |
| 1070 | web_contents->GetBrowserContext()); |
| 1071 | if (protocol_handler_registry && |
| 1072 | protocol_handler_registry->IsHandledProtocol(url.scheme())) |
| 1073 | return; |
| 1074 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1075 | bool is_whitelisted = false; |
Aaron Colwell | f94fd97a | 2020-07-21 19:37:08 | [diff] [blame] | 1076 | PolicyBlocklistService* service = |
| 1077 | PolicyBlocklistFactory::GetForBrowserContext( |
Oleg Davydov | 5cfe7ab | 2019-02-01 12:27:19 | [diff] [blame] | 1078 | web_contents->GetBrowserContext()); |
Julian Pastarmov | b4773b8 | 2020-04-21 16:34:14 | [diff] [blame] | 1079 | if (ShouldHonorPolicies() && service) { |
Aaron Colwell | f94fd97a | 2020-07-21 19:37:08 | [diff] [blame] | 1080 | const policy::URLBlocklist::URLBlocklistState url_state = |
| 1081 | service->GetURLBlocklistState(url); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1082 | is_whitelisted = |
Aaron Colwell | f94fd97a | 2020-07-21 19:37:08 | [diff] [blame] | 1083 | url_state == policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST; |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | // If the URL is in whitelist, we launch it without asking the user and |
| 1087 | // without any additional security checks. Since the URL is whitelisted, |
| 1088 | // we assume it can be executed. |
| 1089 | if (is_whitelisted) { |
| 1090 | ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents); |
| 1091 | } else { |
| 1092 | ExternalProtocolHandler::LaunchUrl( |
| 1093 | url, web_contents->GetRenderViewHost()->GetProcess()->GetID(), |
| 1094 | web_contents->GetRenderViewHost()->GetRoutingID(), page_transition, |
Emily Stark | 13b66bdf | 2019-10-04 17:11:45 | [diff] [blame] | 1095 | has_user_gesture, initiating_origin); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 1099 | void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) { |
| 1100 | // |allowlist| combines pref/policy + cmdline switch in the browser process. |
| 1101 | // For renderer and utility (e.g. NetworkService) processes the switch is the |
| 1102 | // only available source, so below the combined (pref/policy + cmdline) |
| 1103 | // allowlist of secure origins is injected into |cmdline| for these other |
| 1104 | // processes. |
| 1105 | std::vector<std::string> allowlist = |
| 1106 | network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist(); |
| 1107 | if (!allowlist.empty()) { |
| 1108 | cmdline->AppendSwitchASCII( |
| 1109 | network::switches::kUnsafelyTreatInsecureOriginAsSecure, |
| 1110 | base::JoinString(allowlist, ",")); |
| 1111 | } |
| 1112 | } |
| 1113 | |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 1114 | #if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 1115 | // Returns the full path to |module_name|. Both dev builds (where |module_name| |
| 1116 | // is in the current executable's directory) and proper installs (where |
| 1117 | // |module_name| is in a versioned sub-directory of the current executable's |
| 1118 | // directory) are supported. The identified file is not guaranteed to exist. |
| 1119 | base::FilePath GetModulePath(base::StringPiece16 module_name) { |
| 1120 | base::FilePath exe_dir; |
| 1121 | const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir); |
| 1122 | DCHECK(has_path); |
| 1123 | |
| 1124 | // Look for the module in a versioned sub-directory of the current |
| 1125 | // executable's directory and return the path if it can be read. This is the |
| 1126 | // expected location of modules for proper installs. |
| 1127 | const base::FilePath module_path = |
| 1128 | exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name); |
| 1129 | if (base::PathExists(module_path)) |
| 1130 | return module_path; |
| 1131 | |
| 1132 | // Otherwise, return the path to the module in the current executable's |
| 1133 | // directory. This is the expected location of modules for dev builds. |
| 1134 | return exe_dir.Append(module_name); |
| 1135 | } |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 1136 | #endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) && |
| 1137 | // !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 1138 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 1139 | void MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 1140 | std::unique_ptr<content::NavigationThrottle> maybe_throttle, |
| 1141 | std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) { |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 1142 | if (maybe_throttle) |
| 1143 | throttles->push_back(std::move(maybe_throttle)); |
| 1144 | } |
| 1145 | |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 1146 | void MaybeAddThrottles( |
| 1147 | std::vector<std::unique_ptr<content::NavigationThrottle>> additional, |
| 1148 | std::vector<std::unique_ptr<content::NavigationThrottle>>* combined) { |
| 1149 | combined->insert(combined->end(), std::make_move_iterator(additional.begin()), |
| 1150 | std::make_move_iterator(additional.end())); |
| 1151 | } |
| 1152 | |
Evan Stade | 1e71d6dd | 2019-10-29 03:04:49 | [diff] [blame] | 1153 | // Returns whether |web_contents| is within a hosted app. |
| 1154 | bool IsInHostedApp(WebContents* web_contents) { |
| 1155 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1156 | Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
Glen Robertson | 83263c7 | 2020-12-10 06:16:16 | [diff] [blame] | 1157 | return web_app::AppBrowserController::IsWebApp(browser); |
Evan Stade | 1e71d6dd | 2019-10-29 03:04:49 | [diff] [blame] | 1158 | #else |
| 1159 | return false; |
| 1160 | #endif |
| 1161 | } |
| 1162 | |
Lily Chen | c2c9e9f | 2019-12-05 19:55:31 | [diff] [blame] | 1163 | void MaybeRecordSameSiteCookieEngagementHistogram( |
| 1164 | content::RenderFrameHost* render_frame_host, |
| 1165 | blink::mojom::WebFeature feature) { |
| 1166 | if (feature != blink::mojom::WebFeature::kCookieNoSameSite && |
| 1167 | feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) { |
| 1168 | return; |
| 1169 | } |
| 1170 | |
| 1171 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 1172 | DCHECK(render_frame_host); |
| 1173 | |
| 1174 | content::BrowserContext* browser_context = |
| 1175 | WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext(); |
| 1176 | Profile* profile = Profile::FromBrowserContext(browser_context); |
Evan Stade | 7a98480 | 2020-12-14 19:10:15 | [diff] [blame] | 1177 | auto* site_engagement_service = |
| 1178 | site_engagement::SiteEngagementService::Get(profile); |
Lily Chen | c2c9e9f | 2019-12-05 19:55:31 | [diff] [blame] | 1179 | if (!site_engagement_service) |
| 1180 | return; |
| 1181 | |
| 1182 | blink::mojom::EngagementLevel engagement_level = |
| 1183 | site_engagement_service->GetEngagementLevel( |
| 1184 | render_frame_host->GetLastCommittedURL()); |
| 1185 | if (feature == blink::mojom::WebFeature::kCookieNoSameSite) { |
| 1186 | UMA_HISTOGRAM_ENUMERATION( |
| 1187 | "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite", |
| 1188 | engagement_level); |
| 1189 | } else { |
| 1190 | UMA_HISTOGRAM_ENUMERATION( |
| 1191 | "Net.SameSiteBlockedCookieSiteEngagement." |
| 1192 | "CookieInsecureAndSameSiteNone", |
| 1193 | engagement_level); |
| 1194 | } |
| 1195 | } |
| 1196 | |
Ken Rockot | 4408a0f | 2020-07-27 19:40:54 | [diff] [blame] | 1197 | bool IsErrorPageAutoReloadEnabled() { |
| 1198 | const base::CommandLine& command_line = |
| 1199 | *base::CommandLine::ForCurrentProcess(); |
| 1200 | if (command_line.HasSwitch(switches::kEnableAutomation)) |
| 1201 | return false; |
| 1202 | if (command_line.HasSwitch(switches::kEnableAutoReload)) |
| 1203 | return true; |
| 1204 | if (command_line.HasSwitch(switches::kDisableAutoReload)) |
| 1205 | return false; |
| 1206 | return true; |
| 1207 | } |
| 1208 | |
Thomas Lukaszewicz | f87f343 | 2021-01-21 17:20:05 | [diff] [blame] | 1209 | bool IsTopChromeWebUIURL(const GURL& url) { |
| 1210 | return url.SchemeIs(content::kChromeUIScheme) && |
| 1211 | base::EndsWith(url.host_piece(), chrome::kChromeUITopChromeDomain); |
| 1212 | } |
| 1213 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 1214 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 1215 | |
Yutaka Hirano | 311a741 | 2021-01-06 06:17:35 | [diff] [blame] | 1216 | #if !defined(OS_ANDROID) |
| 1217 | base::TimeDelta GetKeepaliveTimerTimeout() { |
| 1218 | constexpr base::TimeDelta kDefaultValue = base::TimeDelta::FromSeconds(1); |
| 1219 | |
| 1220 | const int seconds = base::GetFieldTrialParamByFeatureAsInt( |
| 1221 | features::kShutdownSupportForKeepalive, "timeout", -1); |
| 1222 | if (seconds < 0 || seconds > 60) { |
| 1223 | return kDefaultValue; |
| 1224 | } |
| 1225 | return base::TimeDelta::FromSeconds(seconds); |
| 1226 | } |
| 1227 | #endif |
| 1228 | |
danakj | 5beedd0 | 2020-10-30 15:55:13 | [diff] [blame] | 1229 | ChromeContentBrowserClient::ChromeContentBrowserClient() { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1230 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 1231 | extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 1232 | #endif |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 1233 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 1234 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 1235 | extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart); |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 1236 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 1237 | |
John Lee | 0ee748bf | 2019-12-11 21:35:44 | [diff] [blame] | 1238 | #if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP) |
| 1239 | extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart); |
| 1240 | #endif |
| 1241 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1242 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1243 | extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1244 | #endif |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 1245 | |
Sigurdur Asgeirsson | 7069667 | 2019-02-08 16:14:51 | [diff] [blame] | 1246 | extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | ChromeContentBrowserClient::~ChromeContentBrowserClient() { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1250 | for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i) |
| 1251 | delete extra_parts_[i]; |
| 1252 | extra_parts_.clear(); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1253 | } |
| 1254 | |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 1255 | // static |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1256 | void ChromeContentBrowserClient::RegisterLocalStatePrefs( |
| 1257 | PrefRegistrySimple* registry) { |
Greg Thompson | 8c922756 | 2019-08-05 17:47:13 | [diff] [blame] | 1258 | registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath()); |
| 1259 | registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1260 | registry->RegisterStringPref(prefs::kIsolateOrigins, std::string()); |
| 1261 | registry->RegisterBooleanPref(prefs::kSitePerProcess, false); |
Francois Doray | 424bd99 | 2019-10-16 20:59:46 | [diff] [blame] | 1262 | registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | // static |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 1266 | void ChromeContentBrowserClient::RegisterProfilePrefs( |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 1267 | user_prefs::PrefRegistrySyncable* registry) { |
raymes | aa60872 | 2015-04-27 03:00:25 | [diff] [blame] | 1268 | registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false); |
| 1269 | registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true); |
Pavol Marko | 6adbea7f | 2018-02-20 16:35:28 | [diff] [blame] | 1270 | // Register user prefs for mapping SitePerProcess and IsolateOrigins in |
| 1271 | // user policy in addition to the same named ones in Local State (which are |
| 1272 | // used for mapping the command-line flags). |
| 1273 | registry->RegisterStringPref(prefs::kIsolateOrigins, std::string()); |
| 1274 | registry->RegisterBooleanPref(prefs::kSitePerProcess, false); |
Clark DuVall | aadc244c | 2020-06-06 03:47:14 | [diff] [blame] | 1275 | registry->RegisterListPref( |
| 1276 | site_isolation::prefs::kUserTriggeredIsolatedOrigins); |
Rayan Kanso | 411e84e | 2019-02-13 15:27:40 | [diff] [blame] | 1277 | registry->RegisterDictionaryPref( |
| 1278 | prefs::kDevToolsBackgroundServicesExpirationDict); |
Kunihiko Sakamoto | f586da6 | 2019-03-28 03:03:04 | [diff] [blame] | 1279 | registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 1280 | #if !defined(OS_ANDROID) |
| 1281 | registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false); |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 1282 | registry->RegisterListPref(prefs::kAutoplayWhitelist); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 1283 | #endif |
Nicolas Arciniega | fa9f4c9 | 2021-01-22 19:49:25 | [diff] [blame] | 1284 | registry->RegisterBooleanPref(prefs::kSSLErrorOverrideAllowed, true); |
| 1285 | registry->RegisterListPref(prefs::kSSLErrorOverrideAllowedForUrls); |
Piotr Bialecki | 3fde5fa | 2021-01-23 01:08:03 | [diff] [blame] | 1286 | #if defined(OS_ANDROID) |
| 1287 | registry->RegisterBooleanPref(prefs::kWebXRImmersiveArEnabled, true); |
| 1288 | #endif |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 1289 | } |
| 1290 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1291 | // static |
| 1292 | void ChromeContentBrowserClient::SetApplicationLocale( |
| 1293 | const std::string& locale) { |
Scott Violet | 875789e | 2018-02-02 07:46:48 | [diff] [blame] | 1294 | // The common case is that this function is called early in Chrome startup |
| 1295 | // before any threads are created or registered. When there are no threads, |
| 1296 | // we can just set the string without worrying about threadsafety. |
Gabriel Charette | 192b8c9 | 2018-03-21 21:16:00 | [diff] [blame] | 1297 | if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) { |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 1298 | GetIOThreadApplicationLocale() = locale; |
Scott Violet | 875789e | 2018-02-02 07:46:48 | [diff] [blame] | 1299 | return; |
| 1300 | } |
| 1301 | |
| 1302 | // Otherwise we're being called to change the locale. In this case set it on |
| 1303 | // the IO thread. |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 1304 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1305 | |
Gabriel Charette | e7cdc5cd | 2020-05-27 23:35:05 | [diff] [blame] | 1306 | content::GetIOThreadTaskRunner({})->PostTask( |
| 1307 | FROM_HERE, base::BindOnce(&SetApplicationLocaleOnIOThread, locale)); |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1308 | } |
| 1309 | |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1310 | std::unique_ptr<content::BrowserMainParts> |
| 1311 | ChromeContentBrowserClient::CreateBrowserMainParts( |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1312 | const content::MainFunctionParams& parameters) { |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1313 | std::unique_ptr<ChromeBrowserMainParts> main_parts; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1314 | // Construct the Main browser parts based on the OS type. |
| 1315 | #if defined(OS_WIN) |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 1316 | main_parts = |
danakj | 5beedd0 | 2020-10-30 15:55:13 | [diff] [blame] | 1317 | std::make_unique<ChromeBrowserMainPartsWin>(parameters, &startup_data_); |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 1318 | #elif defined(OS_MAC) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1319 | main_parts = |
danakj | 5beedd0 | 2020-10-30 15:55:13 | [diff] [blame] | 1320 | std::make_unique<ChromeBrowserMainPartsMac>(parameters, &startup_data_); |
James Cook | 70fee986 | 2020-11-18 17:28:40 | [diff] [blame] | 1321 | #elif BUILDFLAG(IS_CHROMEOS_ASH) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1322 | main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>( |
danakj | 5beedd0 | 2020-10-30 15:55:13 | [diff] [blame] | 1323 | parameters, &startup_data_); |
James Cook | 70fee986 | 2020-11-18 17:28:40 | [diff] [blame] | 1324 | #elif BUILDFLAG(IS_CHROMEOS_LACROS) |
| 1325 | main_parts = std::make_unique<ChromeBrowserMainPartsLacros>(parameters, |
| 1326 | &startup_data_); |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 1327 | #elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1328 | main_parts = |
danakj | 5beedd0 | 2020-10-30 15:55:13 | [diff] [blame] | 1329 | std::make_unique<ChromeBrowserMainPartsLinux>(parameters, &startup_data_); |
[email protected] | 6e677a34 | 2012-02-11 01:21:14 | [diff] [blame] | 1330 | #elif defined(OS_ANDROID) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1331 | main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters, |
danakj | 5beedd0 | 2020-10-30 15:55:13 | [diff] [blame] | 1332 | &startup_data_); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1333 | #elif defined(OS_POSIX) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1334 | main_parts = |
danakj | 5beedd0 | 2020-10-30 15:55:13 | [diff] [blame] | 1335 | std::make_unique<ChromeBrowserMainPartsPosix>(parameters, &startup_data_); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1336 | #else |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1337 | NOTREACHED(); |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1338 | main_parts = |
danakj | 5beedd0 | 2020-10-30 15:55:13 | [diff] [blame] | 1339 | std::make_unique<ChromeBrowserMainParts>(parameters, &startup_data_); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1340 | #endif |
| 1341 | |
Xi Han | 9fd4400 | 2019-04-30 17:39:36 | [diff] [blame] | 1342 | bool add_profiles_extra_parts = true; |
| 1343 | #if defined(OS_ANDROID) |
danakj | 5beedd0 | 2020-10-30 15:55:13 | [diff] [blame] | 1344 | if (startup_data_.HasBuiltProfilePrefService()) |
Xi Han | 9fd4400 | 2019-04-30 17:39:36 | [diff] [blame] | 1345 | add_profiles_extra_parts = false; |
| 1346 | #endif |
| 1347 | if (add_profiles_extra_parts) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1348 | chrome::AddProfilesExtraParts(main_parts.get()); |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 1349 | |
Xi Han | 9fd4400 | 2019-04-30 17:39:36 | [diff] [blame] | 1350 | // Construct additional browser parts. Stages are called in the order in |
| 1351 | // which they are added. |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 1352 | #if defined(TOOLKIT_VIEWS) |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 1353 | #if BUILDFLAG(IS_CHROMEOS_LACROS) |
Antonio Gomes | aa260336 | 2020-10-24 12:20:18 | [diff] [blame] | 1354 | main_parts->AddParts( |
| 1355 | std::make_unique<ChromeBrowserMainExtraPartsViewsLacros>()); |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 1356 | // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch |
| 1357 | // of lacros-chrome is complete. |
| 1358 | #elif defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS) |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1359 | main_parts->AddParts( |
| 1360 | std::make_unique<ChromeBrowserMainExtraPartsViewsLinux>()); |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 1361 | #else |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1362 | main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsViews>()); |
James Cook | f9d34d2 | 2017-10-04 16:39:35 | [diff] [blame] | 1363 | #endif |
| 1364 | #endif |
| 1365 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 1366 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
James Cook | f9d34d2 | 2017-10-04 16:39:35 | [diff] [blame] | 1367 | // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos. |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1368 | main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsAsh>()); |
sky | cea631e | 2016-12-16 21:52:22 | [diff] [blame] | 1369 | #endif |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 1370 | |
Maksim Sisov | 1686fc2 | 2020-06-17 07:59:20 | [diff] [blame] | 1371 | #if defined(USE_X11) || defined(USE_OZONE) |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1372 | main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsOzone>()); |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 1373 | #endif |
| 1374 | |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1375 | main_parts->AddParts( |
Patrick Monette | a408469 | 2021-01-18 17:51:30 | [diff] [blame] | 1376 | std::make_unique<ChromeBrowserMainExtraPartsPerformanceMonitor>()); |
| 1377 | |
| 1378 | main_parts->AddParts( |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1379 | std::make_unique<ChromeBrowserMainExtraPartsPerformanceManager>()); |
Etienne Bergeron | 05d6253 | 2017-10-13 18:24:00 | [diff] [blame] | 1380 | |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1381 | main_parts->AddParts( |
| 1382 | std::make_unique<ChromeBrowserMainExtraPartsProfiling>()); |
Albert J. Wong | 59d85acb | 2017-08-10 00:50:57 | [diff] [blame] | 1383 | |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1384 | main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsMemory>()); |
Sebastien Marchand | 8c008810 | 2019-10-11 16:47:56 | [diff] [blame] | 1385 | |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1386 | chrome::AddMetricsExtraParts(main_parts.get()); |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 1387 | |
Zhenyao Mo | 7314465 | 2020-04-06 18:55:05 | [diff] [blame] | 1388 | // Always add ChromeBrowserMainExtraPartsGpu last to make sure |
| 1389 | // GpuDataManager initialization could pick up about:flags settings. |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1390 | main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsGpu>()); |
Zhenyao Mo | 7314465 | 2020-04-06 18:55:05 | [diff] [blame] | 1391 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1392 | return main_parts; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1393 | } |
| 1394 | |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1395 | void ChromeContentBrowserClient::PostAfterStartupTask( |
Brett Wilson | e1a7042 | 2017-09-12 05:10:09 | [diff] [blame] | 1396 | const base::Location& from_here, |
Gabriel Charette | e926fc1 | 2019-12-16 19:00:02 | [diff] [blame] | 1397 | const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
tzik | 6e42784 | 2017-04-05 10:13:21 | [diff] [blame] | 1398 | base::OnceClosure task) { |
tzik | 070c8ffb | 2017-03-29 05:28:12 | [diff] [blame] | 1399 | AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task)); |
John Abd-El-Malek | 0e82fe7f | 2019-07-27 00:06:29 | [diff] [blame] | 1400 | |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 1401 | InitNetworkContextsParentDirectory(); |
| 1402 | |
John Abd-El-Malek | 0e82fe7f | 2019-07-27 00:06:29 | [diff] [blame] | 1403 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1404 | safe_browsing_service_ = g_browser_process->safe_browsing_service(); |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1405 | } |
| 1406 | |
falken | b09d443f | 2016-04-07 12:36:12 | [diff] [blame] | 1407 | bool ChromeContentBrowserClient::IsBrowserStartupComplete() { |
| 1408 | return AfterStartupTaskUtils::IsBrowserStartupComplete(); |
| 1409 | } |
| 1410 | |
Gabriel Charette | c8cca99 | 2017-08-10 18:21:49 | [diff] [blame] | 1411 | void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() { |
| 1412 | AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); |
| 1413 | } |
| 1414 | |
John Abd-El-Malek | 9d57f9c | 2019-02-20 18:50:04 | [diff] [blame] | 1415 | bool ChromeContentBrowserClient::IsShuttingDown() { |
Greg Thompson | ae8a5b1 | 2019-11-21 12:35:36 | [diff] [blame] | 1416 | return browser_shutdown::HasShutdownStarted(); |
John Abd-El-Malek | 9d57f9c | 2019-02-20 18:50:04 | [diff] [blame] | 1417 | } |
| 1418 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 1419 | std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1420 | content::BrowserContext* browser_context, |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 1421 | const GURL& site) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1422 | std::string partition_id; |
| 1423 | |
| 1424 | // The partition ID for webview guest processes is the string value of its |
| 1425 | // SiteInstance URL - "chrome-guest://app_id/persist?partition". |
rogerta | 5f5bb82 | 2015-12-17 03:24:45 | [diff] [blame] | 1426 | if (site.SchemeIs(content::kGuestScheme)) |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1427 | partition_id = site.spec(); |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1428 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
blundell | f650ea0 | 2016-02-08 11:50:50 | [diff] [blame] | 1429 | // The partition ID for extensions with isolated storage is treated similarly |
| 1430 | // to the above. |
Aaron Colwell | 8c43064 | 2020-08-04 01:55:20 | [diff] [blame] | 1431 | else if (extensions::util::IsExtensionSiteWithIsolatedStorage( |
| 1432 | site, browser_context)) |
blundell | f650ea0 | 2016-02-08 11:50:50 | [diff] [blame] | 1433 | partition_id = site.spec(); |
| 1434 | #endif |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1435 | |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 1436 | DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1437 | return partition_id; |
| 1438 | } |
| 1439 | |
| 1440 | bool ChromeContentBrowserClient::IsValidStoragePartitionId( |
| 1441 | content::BrowserContext* browser_context, |
| 1442 | const std::string& partition_id) { |
| 1443 | // The default ID is empty and is always valid. |
| 1444 | if (partition_id.empty()) |
| 1445 | return true; |
| 1446 | |
| 1447 | return GURL(partition_id).is_valid(); |
| 1448 | } |
| 1449 | |
Bret Sepulveda | 5665215 | 2020-06-24 14:47:13 | [diff] [blame] | 1450 | content::StoragePartitionConfig |
| 1451 | ChromeContentBrowserClient::GetStoragePartitionConfigForSite( |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1452 | content::BrowserContext* browser_context, |
Bret Sepulveda | 5665215 | 2020-06-24 14:47:13 | [diff] [blame] | 1453 | const GURL& site) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1454 | // Default to the browser-wide storage partition and override based on |site| |
| 1455 | // below. |
Bret Sepulveda | 5665215 | 2020-06-24 14:47:13 | [diff] [blame] | 1456 | content::StoragePartitionConfig storage_partition_config = |
| 1457 | content::StoragePartitionConfig::CreateDefault(); |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1458 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1459 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Aaron Colwell | 0ee2213 | 2020-06-23 00:28:41 | [diff] [blame] | 1460 | if (extensions::WebViewGuest::GetGuestPartitionConfigForSite( |
Bret Sepulveda | 5665215 | 2020-06-24 14:47:13 | [diff] [blame] | 1461 | site, &storage_partition_config)) { |
| 1462 | return storage_partition_config; |
Aaron Colwell | 0ee2213 | 2020-06-23 00:28:41 | [diff] [blame] | 1463 | } |
[email protected] | 3f24f97c | 2013-11-17 21:53:33 | [diff] [blame] | 1464 | |
Aaron Colwell | 8c43064 | 2020-08-04 01:55:20 | [diff] [blame] | 1465 | if (site.SchemeIs(extensions::kExtensionScheme)) { |
| 1466 | // The host in an extension site URL is the extension_id. |
Aaron Colwell | 0ee2213 | 2020-06-23 00:28:41 | [diff] [blame] | 1467 | CHECK(site.has_host()); |
Aaron Colwell | 8c43064 | 2020-08-04 01:55:20 | [diff] [blame] | 1468 | return extensions::util::GetStoragePartitionConfigForExtensionId( |
| 1469 | site.host(), browser_context); |
[email protected] | 1df3d97 | 2014-06-11 04:55:18 | [diff] [blame] | 1470 | } |
| 1471 | #endif |
Bret Sepulveda | 5665215 | 2020-06-24 14:47:13 | [diff] [blame] | 1472 | |
| 1473 | return storage_partition_config; |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 1474 | } |
| 1475 | |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 1476 | content::WebContentsViewDelegate* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1477 | ChromeContentBrowserClient::GetWebContentsViewDelegate( |
| 1478 | content::WebContents* web_contents) { |
Chris Hamilton | c3d5c0d1 | 2020-06-01 19:30:05 | [diff] [blame] | 1479 | if (auto* registry = |
| 1480 | performance_manager::PerformanceManagerRegistry::GetInstance()) { |
Chris Hamilton | 4269bab | 2020-06-04 20:03:21 | [diff] [blame] | 1481 | registry->MaybeCreatePageNodeForWebContents(web_contents); |
Chris Hamilton | c3d5c0d1 | 2020-06-01 19:30:05 | [diff] [blame] | 1482 | } |
cm.sanchi | 2db24a8 | 2017-11-16 07:22:10 | [diff] [blame] | 1483 | return CreateWebContentsViewDelegate(web_contents); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 1484 | } |
| 1485 | |
Bo Liu | 4ade6b1b2 | 2017-11-28 02:26:35 | [diff] [blame] | 1486 | bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() { |
| 1487 | #if defined(OS_ANDROID) |
| 1488 | const base::android::ApplicationState app_state = |
| 1489 | base::android::ApplicationStatusListener::GetState(); |
| 1490 | return base::android::APPLICATION_STATE_UNKNOWN == app_state || |
| 1491 | base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state || |
| 1492 | base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state; |
| 1493 | #else |
| 1494 | return true; |
| 1495 | #endif |
| 1496 | } |
| 1497 | |
[email protected] | 6f286274 | 2013-12-20 07:53:19 | [diff] [blame] | 1498 | void ChromeContentBrowserClient::RenderProcessWillLaunch( |
Ken Rockot | 7c6275b | 2019-08-02 20:00:23 | [diff] [blame] | 1499 | content::RenderProcessHost* host) { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1500 | Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
Darin Fisher | 8c84328c | 2019-07-23 02:50:00 | [diff] [blame] | 1501 | |
Darin Fisher | 09aa722 | 2019-08-29 09:27:36 | [diff] [blame] | 1502 | WebRtcLoggingController::AttachToRenderProcessHost( |
Darin Fisher | 8c84328c | 2019-07-23 02:50:00 | [diff] [blame] | 1503 | host, g_browser_process->webrtc_log_uploader()); |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1504 | |
grunell | 086a411 | 2017-03-02 09:23:04 | [diff] [blame] | 1505 | // The audio manager outlives the host, so it's safe to hand a raw pointer to |
| 1506 | // it to the AudioDebugRecordingsHandler, which is owned by the host. |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1507 | AudioDebugRecordingsHandler* audio_debug_recordings_handler = |
Marina Ciocea | 741a4fb1 | 2018-01-27 09:55:12 | [diff] [blame] | 1508 | new AudioDebugRecordingsHandler(profile); |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1509 | host->SetUserData( |
| 1510 | AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey, |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 1511 | std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>( |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1512 | audio_debug_recordings_handler)); |
| 1513 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 1514 | #if BUILDFLAG(ENABLE_NACL) |
Julie Jeongeun Kim | ae46b4e | 2021-01-07 11:38:14 | [diff] [blame] | 1515 | host->AddFilter(new nacl::NaClHostMessageFilter( |
| 1516 | host->GetID(), profile->IsOffTheRecord(), profile->GetPath())); |
[email protected] | 01e5975 | 2013-06-18 00:17:35 | [diff] [blame] | 1517 | #endif |
jeremyim | 364ac118 | 2015-03-03 18:49:43 | [diff] [blame] | 1518 | |
Xiaohan Wang | 9b34281b | 2017-09-08 23:48:33 | [diff] [blame] | 1519 | #if defined(OS_ANDROID) |
| 1520 | // Data cannot be persisted if the profile is off the record. |
| 1521 | host->AddFilter( |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 1522 | new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false)); |
Yuzu Saijo | 2d12ef9 | 2018-08-21 04:52:07 | [diff] [blame] | 1523 | |
| 1524 | // Register CrashMemoryMetricsCollector to report oom related metrics. |
| 1525 | host->SetUserData( |
| 1526 | CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey, |
| 1527 | std::make_unique<CrashMemoryMetricsCollector>(host)); |
Xiaohan Wang | 9b34281b | 2017-09-08 23:48:33 | [diff] [blame] | 1528 | #endif |
| 1529 | |
Jun Cai | db3f93cc | 2018-07-09 21:54:55 | [diff] [blame] | 1530 | Profile* original_profile = profile->GetOriginalProfile(); |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 1531 | RendererUpdaterFactory::GetForProfile(original_profile) |
| 1532 | ->InitializeRenderer(host); |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 1533 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1534 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1535 | extra_parts_[i]->RenderProcessWillLaunch(host); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 1536 | } |
| 1537 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1538 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
Alex Moshchuk | bb99a33 | 2017-11-22 04:49:57 | [diff] [blame] | 1539 | content::BrowserContext* browser_context, |
Alex Moshchuk | a31c788 | 2018-01-17 00:57:30 | [diff] [blame] | 1540 | const GURL& url) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1541 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1542 | if (!profile) |
| 1543 | return url; |
| 1544 | |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1545 | #if !defined(OS_ANDROID) |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 1546 | // If the input |url| should be assigned to the Instant renderer, make its |
| 1547 | // effective URL distinct from other URLs on the search provider's domain. |
Alex Moshchuk | ca17137 | 2017-11-28 16:11:31 | [diff] [blame] | 1548 | // This needs to happen even if |url| corresponds to an isolated origin; see |
| 1549 | // https://crbug.com/755595. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1550 | if (search::ShouldAssignURLToInstantRenderer(url, profile)) |
| 1551 | return search::GetEffectiveURLForInstant(url, profile); |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1552 | #endif |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 1553 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1554 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Alex Moshchuk | a31c788 | 2018-01-17 00:57:30 | [diff] [blame] | 1555 | return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile, |
| 1556 | url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1557 | #else |
| 1558 | return url; |
| 1559 | #endif |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1560 | } |
| 1561 | |
Alexander Yashkin | 6aedc6e | 2018-08-15 08:58:45 | [diff] [blame] | 1562 | bool ChromeContentBrowserClient:: |
| 1563 | ShouldCompareEffectiveURLsForSiteInstanceSelection( |
| 1564 | content::BrowserContext* browser_context, |
| 1565 | content::SiteInstance* candidate_site_instance, |
| 1566 | bool is_main_frame, |
| 1567 | const GURL& candidate_url, |
| 1568 | const GURL& destination_url) { |
| 1569 | DCHECK(browser_context); |
| 1570 | DCHECK(candidate_site_instance); |
| 1571 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1572 | return ChromeContentBrowserClientExtensionsPart:: |
| 1573 | ShouldCompareEffectiveURLsForSiteInstanceSelection( |
| 1574 | browser_context, candidate_site_instance, is_main_frame, |
| 1575 | candidate_url, destination_url); |
| 1576 | #else |
| 1577 | return true; |
| 1578 | #endif |
| 1579 | } |
| 1580 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 1581 | bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() { |
Ahmed Fakhry | e6a2c64 | 2018-06-20 02:58:41 | [diff] [blame] | 1582 | #if defined(OS_ANDROID) |
| 1583 | return true; |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 1584 | #elif BUILDFLAG(IS_CHROMEOS_ASH) |
Xiyuan Xia | fc9f3813 | 2019-08-02 00:51:42 | [diff] [blame] | 1585 | return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode(); |
Ahmed Fakhry | e6a2c64 | 2018-06-20 02:58:41 | [diff] [blame] | 1586 | #else |
| 1587 | return false; |
| 1588 | #endif // defined(OS_ANDROID) |
| 1589 | } |
| 1590 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1591 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1592 | content::BrowserContext* browser_context, |
Aaron Colwell | abb540b | 2020-05-05 19:15:59 | [diff] [blame] | 1593 | const GURL& site_url) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1594 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1595 | if (!profile) |
| 1596 | return false; |
| 1597 | |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1598 | // NTP should use process-per-site. This is a performance optimization to |
| 1599 | // reduce process count associated with NTP tabs. |
Tibor Goldschwendt | 52e168c | 2020-06-01 22:17:44 | [diff] [blame] | 1600 | if (site_url == GURL(chrome::kChromeUINewTabURL) || |
| 1601 | site_url == GURL(chrome::kChromeUINewTabPageURL)) { |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1602 | return true; |
Tibor Goldschwendt | 52e168c | 2020-06-01 22:17:44 | [diff] [blame] | 1603 | } |
Peter Boström | 8e9b163 | 2019-08-22 23:12:47 | [diff] [blame] | 1604 | |
| 1605 | // The web footer experiment should share its renderer to not effectively |
| 1606 | // instantiate one per window. See https://crbug.com/993502. |
Aaron Colwell | abb540b | 2020-05-05 19:15:59 | [diff] [blame] | 1607 | if (site_url == GURL(chrome::kChromeUIWebFooterExperimentURL)) |
Peter Boström | 8e9b163 | 2019-08-22 23:12:47 | [diff] [blame] | 1608 | return true; |
| 1609 | |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1610 | #if !defined(OS_ANDROID) |
Aaron Colwell | abb540b | 2020-05-05 19:15:59 | [diff] [blame] | 1611 | if (search::ShouldUseProcessPerSiteForInstantSiteURL(site_url, profile)) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1612 | return true; |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1613 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1614 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1615 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1616 | if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite( |
Aaron Colwell | abb540b | 2020-05-05 19:15:59 | [diff] [blame] | 1617 | profile, site_url)) |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1618 | return true; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1619 | #endif |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1620 | |
| 1621 | // Non-extension, non-NTP URLs should generally use process-per-site-instance |
| 1622 | // (rather than process-per-site). |
| 1623 | return false; |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1624 | } |
| 1625 | |
Lukasz Anforowicz | 32d2712 | 2018-04-09 21:48:33 | [diff] [blame] | 1626 | bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost( |
| 1627 | content::BrowserContext* browser_context, |
| 1628 | const GURL& site_url) { |
| 1629 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1630 | if (!profile) |
| 1631 | return false; |
| 1632 | |
Thomas Lukaszewicz | f87f343 | 2021-01-21 17:20:05 | [diff] [blame] | 1633 | // Top Chrome WebUI should share a RendererProcessHost. Return false here to |
| 1634 | // ensure the Spare Renderer is not assigned. |
| 1635 | if (IsTopChromeWebUIURL(site_url)) |
| 1636 | return false; |
| 1637 | |
Lukasz Anforowicz | 32d2712 | 2018-04-09 21:48:33 | [diff] [blame] | 1638 | #if !defined(OS_ANDROID) |
| 1639 | // Instant renderers should not use a spare process, because they require |
| 1640 | // passing switches::kInstantProcess to the renderer process when it |
| 1641 | // launches. A spare process is launched earlier, before it is known which |
| 1642 | // navigation will use it, so it lacks this flag. |
| 1643 | if (search::ShouldAssignURLToInstantRenderer(site_url, profile)) |
| 1644 | return false; |
| 1645 | #endif |
| 1646 | |
| 1647 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1648 | return ChromeContentBrowserClientExtensionsPart:: |
| 1649 | ShouldUseSpareRenderProcessHost(profile, site_url); |
| 1650 | #else |
| 1651 | return true; |
| 1652 | #endif |
| 1653 | } |
| 1654 | |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1655 | bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess( |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1656 | content::BrowserContext* browser_context, |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1657 | const GURL& effective_site_url) { |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1658 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1659 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1660 | if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess( |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1661 | browser_context, effective_site_url)) { |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1662 | return true; |
| 1663 | } |
| 1664 | #endif |
| 1665 | return false; |
| 1666 | } |
| 1667 | |
Aaron Colwell | 8812a97 | 2020-10-02 23:36:56 | [diff] [blame] | 1668 | bool ChromeContentBrowserClient::ShouldLockProcessToSite( |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1669 | content::BrowserContext* browser_context, |
| 1670 | const GURL& effective_site_url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1671 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Aaron Colwell | 8812a97 | 2020-10-02 23:36:56 | [diff] [blame] | 1672 | if (!ChromeContentBrowserClientExtensionsPart::ShouldLockProcessToSite( |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1673 | browser_context, effective_site_url)) { |
| 1674 | return false; |
| 1675 | } |
| 1676 | #endif |
| 1677 | return true; |
creis | e5d6d173 | 2015-08-25 19:47:06 | [diff] [blame] | 1678 | } |
| 1679 | |
Nasko Oskov | 3902367 | 2020-05-06 17:31:14 | [diff] [blame] | 1680 | bool ChromeContentBrowserClient::DoesWebUISchemeRequireProcessLock( |
| 1681 | base::StringPiece scheme) { |
| 1682 | // Note: This method can be called from multiple threads. It is not safe to |
| 1683 | // assume it runs only on the UI thread. |
| 1684 | |
| 1685 | // chrome-search: documents commit only in the NTP instant process and are not |
Alex Moshchuk | 7de3846 | 2020-05-20 00:05:37 | [diff] [blame] | 1686 | // locked to chrome-search: origin. Locking to chrome-search would kill |
| 1687 | // processes upon legitimate requests for cookies from the search engine's |
| 1688 | // domain. |
Nasko Oskov | 3902367 | 2020-05-06 17:31:14 | [diff] [blame] | 1689 | if (scheme == chrome::kChromeSearchScheme) |
| 1690 | return false; |
| 1691 | |
| 1692 | // All other WebUIs must be locked to origin. |
| 1693 | return true; |
| 1694 | } |
| 1695 | |
Maks Orlovich | 0e23e31 | 2019-07-16 13:13:56 | [diff] [blame] | 1696 | bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel( |
Lily Chen | 0db055b | 2019-11-15 20:29:02 | [diff] [blame] | 1697 | base::StringPiece scheme, |
| 1698 | bool is_embedded_origin_secure) { |
Lily Chen | 2387bd9 | 2020-06-02 21:15:27 | [diff] [blame] | 1699 | // This is needed to bypass the normal SameSite rules for any chrome:// page |
| 1700 | // embedding a secure origin, regardless of the registrable domains of any |
| 1701 | // intervening frames. For example, this is needed for browser UI to interact |
| 1702 | // with SameSite cookies on accounts.google.com, which are used for logging |
| 1703 | // into Cloud Print from chrome://print, for displaying a list of available |
| 1704 | // accounts on the NTP (chrome://new-tab-page), etc. |
Lily Chen | 0db055b | 2019-11-15 20:29:02 | [diff] [blame] | 1705 | if (is_embedded_origin_secure && scheme == content::kChromeUIScheme) |
| 1706 | return true; |
Maks Orlovich | 0e23e31 | 2019-07-16 13:13:56 | [diff] [blame] | 1707 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1708 | return scheme == extensions::kExtensionScheme; |
| 1709 | #else |
| 1710 | return false; |
| 1711 | #endif |
| 1712 | } |
| 1713 | |
Lily Chen | 0db055b | 2019-11-15 20:29:02 | [diff] [blame] | 1714 | bool ChromeContentBrowserClient:: |
| 1715 | ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel( |
| 1716 | base::StringPiece scheme, |
| 1717 | bool is_embedded_origin_secure) { |
| 1718 | return is_embedded_origin_secure && scheme == content::kChromeUIScheme; |
| 1719 | } |
| 1720 | |
Xiaohan Wang | 15a07af | 2020-05-28 23:24:55 | [diff] [blame] | 1721 | // TODO(crbug.com/1087559): This is based on SubframeTask::GetTitle() |
| 1722 | // implementation. Find a general solution to avoid code duplication. |
| 1723 | std::string ChromeContentBrowserClient::GetSiteDisplayNameForCdmProcess( |
| 1724 | content::BrowserContext* browser_context, |
| 1725 | const GURL& site_url) { |
| 1726 | // By default, use the |site_url| spec as the display name. |
| 1727 | std::string name = site_url.spec(); |
| 1728 | |
| 1729 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1730 | // If |site_url| wraps a chrome extension ID, we can display the extension |
| 1731 | // name instead, which is more human-readable. |
| 1732 | if (site_url.SchemeIs(extensions::kExtensionScheme)) { |
| 1733 | const extensions::Extension* extension = |
| 1734 | extensions::ExtensionRegistry::Get(browser_context) |
| 1735 | ->enabled_extensions() |
| 1736 | .GetExtensionOrAppByURL(site_url); |
| 1737 | if (extension) |
| 1738 | name = extension->name(); |
| 1739 | } |
| 1740 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 1741 | |
| 1742 | return name; |
| 1743 | } |
| 1744 | |
Lukasz Anforowicz | 7097890d | 2019-11-20 21:49:22 | [diff] [blame] | 1745 | void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams( |
Lukasz Anforowicz | e00adef | 2019-12-06 23:07:02 | [diff] [blame] | 1746 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 5f335256 | 2019-11-14 16:53:59 | [diff] [blame] | 1747 | const url::Origin& origin, |
Lukasz Anforowicz | e00adef | 2019-12-06 23:07:02 | [diff] [blame] | 1748 | bool is_for_isolated_world, |
Lukasz Anforowicz | 7097890d | 2019-11-20 21:49:22 | [diff] [blame] | 1749 | network::mojom::URLLoaderFactoryParams* factory_params) { |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1750 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | 7097890d | 2019-11-20 21:49:22 | [diff] [blame] | 1751 | ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams( |
Lukasz Anforowicz | e00adef | 2019-12-06 23:07:02 | [diff] [blame] | 1752 | browser_context, origin, is_for_isolated_world, factory_params); |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1753 | #endif |
| 1754 | } |
| 1755 | |
[email protected] | 73b718f | 2014-01-27 02:59:46 | [diff] [blame] | 1756 | // These are treated as WebUI schemes but do not get WebUI bindings. Also, |
| 1757 | // view-source is allowed for these schemes. |
[email protected] | 8f89dd41 | 2013-04-17 02:35:41 | [diff] [blame] | 1758 | void ChromeContentBrowserClient::GetAdditionalWebUISchemes( |
| 1759 | std::vector<std::string>* additional_schemes) { |
| 1760 | additional_schemes->push_back(chrome::kChromeSearchScheme); |
[email protected] | 474a5a3 | 2014-07-28 18:23:24 | [diff] [blame] | 1761 | additional_schemes->push_back(dom_distiller::kDomDistillerScheme); |
Andrey Kosyakov | 031e9e3 | 2017-08-18 21:00:35 | [diff] [blame] | 1762 | additional_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1763 | } |
| 1764 | |
alexmos | 94875b3b | 2017-03-16 22:19:01 | [diff] [blame] | 1765 | void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes( |
| 1766 | std::vector<std::string>* additional_schemes) { |
| 1767 | GetAdditionalWebUISchemes(additional_schemes); |
| 1768 | |
| 1769 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1770 | additional_schemes->push_back(extensions::kExtensionScheme); |
| 1771 | #endif |
| 1772 | } |
| 1773 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 1774 | bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) { |
dbeam | baee5bd | 2015-09-26 03:07:01 | [diff] [blame] | 1775 | return webui::LogWebUIUrl(web_ui_url); |
| 1776 | } |
| 1777 | |
John Abd-El-Malek | 04bfa853 | 2018-07-12 05:28:22 | [diff] [blame] | 1778 | bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests( |
| 1779 | const url::Origin& origin) { |
| 1780 | return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests( |
| 1781 | origin); |
| 1782 | } |
| 1783 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 1784 | bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { |
| 1785 | return ProfileIOData::IsHandledURL(url); |
| 1786 | } |
| 1787 | |
Frédéric Wang | 1eabba7 | 2020-10-23 15:36:55 | [diff] [blame] | 1788 | bool ChromeContentBrowserClient::HasCustomSchemeHandler( |
| 1789 | content::BrowserContext* browser_context, |
| 1790 | const std::string& scheme) { |
| 1791 | if (ProtocolHandlerRegistry* protocol_handler_registry = |
| 1792 | ProtocolHandlerRegistryFactory::GetForBrowserContext( |
| 1793 | browser_context)) { |
| 1794 | return protocol_handler_registry->IsHandledProtocol(scheme); |
| 1795 | } |
| 1796 | |
| 1797 | return false; |
| 1798 | } |
| 1799 | |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1800 | bool ChromeContentBrowserClient::CanCommitURL( |
| 1801 | content::RenderProcessHost* process_host, |
| 1802 | const GURL& url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1803 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1804 | return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host, |
| 1805 | url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1806 | #else |
| 1807 | return true; |
| 1808 | #endif |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1809 | } |
| 1810 | |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1811 | void ChromeContentBrowserClient::OverrideNavigationParams( |
Scott Violet | 5ae6c42e | 2020-10-28 02:47:37 | [diff] [blame] | 1812 | content::WebContents* web_contents, |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1813 | SiteInstance* site_instance, |
| 1814 | ui::PageTransition* transition, |
| 1815 | bool* is_renderer_initiated, |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1816 | content::Referrer* referrer, |
| 1817 | base::Optional<url::Origin>* initiator_origin) { |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1818 | DCHECK(transition); |
| 1819 | DCHECK(is_renderer_initiated); |
| 1820 | DCHECK(referrer); |
Moe Ahmadi | 26e2f50 | 2019-07-16 02:34:47 | [diff] [blame] | 1821 | // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to |
| 1822 | // use for making security decisions 99.44% of the time, for detecting the NTP |
| 1823 | // it is reliable and the correct way. See http://crbug.com/624410. |
| 1824 | if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) && |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1825 | ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) { |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1826 | // Clicks on tiles of the new tab page should be treated as if a user |
| 1827 | // clicked on a bookmark. This is consistent with native implementations |
| 1828 | // like Android's. This also helps ensure that security features (like |
| 1829 | // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as |
| 1830 | // browser-initiated. |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1831 | *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK; |
| 1832 | *is_renderer_initiated = false; |
| 1833 | *referrer = content::Referrer(); |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1834 | *initiator_origin = base::nullopt; |
mastiz | a77db699 | 2016-06-30 09:48:42 | [diff] [blame] | 1835 | } |
Scott Violet | 5ae6c42e | 2020-10-28 02:47:37 | [diff] [blame] | 1836 | #if defined(OS_ANDROID) |
| 1837 | if (web_contents) { |
| 1838 | TabAndroid* tab = TabAndroid::FromWebContents(web_contents); |
| 1839 | if (tab && tab->should_add_api2_transition_to_future_navigations()) { |
| 1840 | *transition = ui::PageTransitionFromInt(*transition | |
| 1841 | ui::PAGE_TRANSITION_FROM_API_2); |
| 1842 | } |
| 1843 | } |
| 1844 | #endif |
mastiz | a77db699 | 2016-06-30 09:48:42 | [diff] [blame] | 1845 | } |
| 1846 | |
Charles Reis | 29e9dd1 | 2017-09-28 00:59:15 | [diff] [blame] | 1847 | bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP( |
| 1848 | const GURL& url, |
| 1849 | SiteInstance* parent_site_instance) { |
Moe Ahmadi | 26e2f50 | 2019-07-16 02:34:47 | [diff] [blame] | 1850 | // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to |
| 1851 | // use for making security decisions 99.44% of the time, for detecting the NTP |
| 1852 | // it is reliable and the correct way. See http://crbug.com/624410. |
| 1853 | return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance && |
| 1854 | search::IsNTPURL(parent_site_instance->GetSiteURL()); |
Charles Reis | 29e9dd1 | 2017-09-28 00:59:15 | [diff] [blame] | 1855 | } |
| 1856 | |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1857 | bool ChromeContentBrowserClient::IsSuitableHost( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1858 | content::RenderProcessHost* process_host, |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1859 | const GURL& site_url) { |
| 1860 | Profile* profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1861 | Profile::FromBrowserContext(process_host->GetBrowserContext()); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1862 | // This may be nullptr during tests. In that case, just assume any site can |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1863 | // share any host. |
| 1864 | if (!profile) |
| 1865 | return true; |
| 1866 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1867 | #if !defined(OS_ANDROID) |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1868 | // Instant URLs should only be in the instant process and instant process |
| 1869 | // should only have Instant URLs. |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1870 | InstantService* instant_service = |
| 1871 | InstantServiceFactory::GetForProfile(profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1872 | if (instant_service) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1873 | bool is_instant_process = |
| 1874 | instant_service->IsInstantProcess(process_host->GetID()); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1875 | bool should_be_in_instant_process = |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1876 | search::ShouldAssignURLToInstantRenderer(site_url, profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1877 | if (is_instant_process || should_be_in_instant_process) |
| 1878 | return is_instant_process && should_be_in_instant_process; |
| 1879 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1880 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1881 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1882 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1883 | return ChromeContentBrowserClientExtensionsPart::IsSuitableHost( |
| 1884 | profile, process_host, site_url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1885 | #else |
| 1886 | return true; |
| 1887 | #endif |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1888 | } |
| 1889 | |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1890 | bool ChromeContentBrowserClient::MayReuseHost( |
| 1891 | content::RenderProcessHost* process_host) { |
Hiroki Nakagawa | b4cd18aa | 2021-01-25 18:11:01 | [diff] [blame] | 1892 | // If there is currently a no-state prefetcher in progress for the host |
| 1893 | // provided, it may not be shared. We require prefetchers to be by themselves |
| 1894 | // in a separate process so that we can monitor their resource usage. |
| 1895 | prerender::NoStatePrefetchManager* no_state_prefetch_manager = |
| 1896 | prerender::NoStatePrefetchManagerFactory::GetForBrowserContext( |
droger | c154315 | 2016-09-20 13:03:37 | [diff] [blame] | 1897 | process_host->GetBrowserContext()); |
Hiroki Nakagawa | b4cd18aa | 2021-01-25 18:11:01 | [diff] [blame] | 1898 | if (no_state_prefetch_manager && |
| 1899 | !no_state_prefetch_manager->MayReuseProcessHost(process_host)) { |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1900 | return false; |
| 1901 | } |
| 1902 | |
| 1903 | return true; |
| 1904 | } |
| 1905 | |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1906 | bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1907 | content::BrowserContext* browser_context, |
| 1908 | const GURL& url) { |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1909 | // It has to be a valid URL for us to check for an extension. |
| 1910 | if (!url.is_valid()) |
| 1911 | return false; |
| 1912 | |
Thomas Lukaszewicz | f87f343 | 2021-01-21 17:20:05 | [diff] [blame] | 1913 | // Top Chrome WebUI should try to share a RenderProcessHost with other |
| 1914 | // existing Top Chrome WebUI. |
| 1915 | if (IsTopChromeWebUIURL(url)) |
| 1916 | return true; |
| 1917 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1918 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1919 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1920 | return ChromeContentBrowserClientExtensionsPart:: |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1921 | ShouldTryToUseExistingProcessHost(profile, url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1922 | #else |
| 1923 | return false; |
| 1924 | #endif |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1925 | } |
| 1926 | |
Alex Moshchuk | 9c9e388 | 2018-11-02 19:57:03 | [diff] [blame] | 1927 | bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess( |
| 1928 | content::RenderFrameHost* main_frame) { |
| 1929 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1930 | return ChromeContentBrowserClientExtensionsPart:: |
| 1931 | ShouldSubframesTryToReuseExistingProcess(main_frame); |
| 1932 | #else |
| 1933 | return true; |
| 1934 | #endif |
| 1935 | } |
| 1936 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1937 | void ChromeContentBrowserClient::SiteInstanceGotProcess( |
| 1938 | SiteInstance* site_instance) { |
| 1939 | CHECK(site_instance->HasProcess()); |
| 1940 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1941 | Profile* profile = |
| 1942 | Profile::FromBrowserContext(site_instance->GetBrowserContext()); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1943 | if (!profile) |
| 1944 | return; |
| 1945 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1946 | #if !defined(OS_ANDROID) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1947 | // Remember the ID of the Instant process to signal the renderer process |
| 1948 | // on startup in |AppendExtraCommandLineSwitches| below. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1949 | if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(), |
| 1950 | profile)) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1951 | InstantService* instant_service = |
| 1952 | InstantServiceFactory::GetForProfile(profile); |
| 1953 | if (instant_service) |
| 1954 | instant_service->AddInstantProcess(site_instance->GetProcess()->GetID()); |
| 1955 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1956 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1957 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1958 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1959 | extra_parts_[i]->SiteInstanceGotProcess(site_instance); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | void ChromeContentBrowserClient::SiteInstanceDeleting( |
| 1963 | SiteInstance* site_instance) { |
| 1964 | if (!site_instance->HasProcess()) |
| 1965 | return; |
| 1966 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1967 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1968 | extra_parts_[i]->SiteInstanceDeleting(site_instance); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1969 | } |
| 1970 | |
[email protected] | 453f543 | 2013-11-26 19:43:00 | [diff] [blame] | 1971 | bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation( |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1972 | SiteInstance* site_instance, |
Aaron Colwell | 16b4985d | 2019-11-13 00:20:56 | [diff] [blame] | 1973 | const GURL& current_effective_url, |
| 1974 | const GURL& destination_effective_url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1975 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1976 | return ChromeContentBrowserClientExtensionsPart:: |
Aaron Colwell | 16b4985d | 2019-11-13 00:20:56 | [diff] [blame] | 1977 | ShouldSwapBrowsingInstancesForNavigation( |
| 1978 | site_instance, current_effective_url, destination_effective_url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1979 | #else |
| 1980 | return false; |
| 1981 | #endif |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1982 | } |
| 1983 | |
Nasko Oskov | d83b571 | 2018-05-04 04:50:57 | [diff] [blame] | 1984 | bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) { |
| 1985 | // TODO(nasko): Consider supporting error page isolation in subframes if |
| 1986 | // Site Isolation is enabled. |
Nasko Oskov | 55d21e15 | 2018-06-27 23:59:38 | [diff] [blame] | 1987 | return in_main_frame; |
Nasko Oskov | d83b571 | 2018-05-04 04:50:57 | [diff] [blame] | 1988 | } |
| 1989 | |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 1990 | bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) { |
| 1991 | return !url.SchemeIs(chrome::kChromeNativeScheme); |
| 1992 | } |
| 1993 | |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1994 | std::vector<url::Origin> |
| 1995 | ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() { |
| 1996 | std::vector<url::Origin> isolated_origin_list; |
| 1997 | |
Alex Moshchuk | 89352a7 | 2017-10-25 20:25:59 | [diff] [blame] | 1998 | // Sign-in process isolation is not needed on Android, see |
| 1999 | // https://crbug.com/739418. |
| 2000 | #if !defined(OS_ANDROID) |
Alex Moshchuk | 81d2a29e | 2019-07-16 01:14:38 | [diff] [blame] | 2001 | isolated_origin_list.push_back( |
Alex Moshchuk | 36417aa | 2018-06-13 18:01:12 | [diff] [blame] | 2002 | url::Origin::Create(GaiaUrls::GetInstance()->gaia_url())); |
Alex Moshchuk | 89352a7 | 2017-10-25 20:25:59 | [diff] [blame] | 2003 | #endif |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 2004 | |
Alex Moshchuk | 81d2a29e | 2019-07-16 01:14:38 | [diff] [blame] | 2005 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 2006 | auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart:: |
| 2007 | GetOriginsRequiringDedicatedProcess(); |
| 2008 | std::move(std::begin(origins_from_extensions), |
| 2009 | std::end(origins_from_extensions), |
| 2010 | std::back_inserter(isolated_origin_list)); |
| 2011 | #endif |
| 2012 | |
Alex Moshchuk | 51e1428b | 2020-04-22 18:00:54 | [diff] [blame] | 2013 | // Include additional origins preloaded with specific browser configurations, |
| 2014 | // if any. For example, this is used on Google Chrome for Android to preload |
| 2015 | // a list of important sites to isolate. |
| 2016 | auto built_in_origins = |
| 2017 | site_isolation::GetBrowserSpecificBuiltInIsolatedOrigins(); |
| 2018 | std::move(std::begin(built_in_origins), std::end(built_in_origins), |
| 2019 | std::back_inserter(isolated_origin_list)); |
| 2020 | |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 2021 | return isolated_origin_list; |
| 2022 | } |
| 2023 | |
Lukasz Anforowicz | 5e201abd | 2018-03-24 00:41:06 | [diff] [blame] | 2024 | bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() { |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 2025 | return base::FeatureList::IsEnabled(features::kSitePerProcess); |
| 2026 | } |
| 2027 | |
| 2028 | bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() { |
Clark DuVall | aadc244c | 2020-06-06 03:47:14 | [diff] [blame] | 2029 | return site_isolation::SiteIsolationPolicy:: |
| 2030 | ShouldDisableSiteIsolationDueToMemoryThreshold(); |
Lukasz Anforowicz | 5e201abd | 2018-03-24 00:41:06 | [diff] [blame] | 2031 | } |
| 2032 | |
Alex Moshchuk | 082b5f8 | 2019-03-14 01:34:16 | [diff] [blame] | 2033 | std::vector<std::string> |
| 2034 | ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() { |
Clark DuVall | aadc244c | 2020-06-06 03:47:14 | [diff] [blame] | 2035 | if (site_isolation::SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled()) |
Alex Moshchuk | 082b5f8 | 2019-03-14 01:34:16 | [diff] [blame] | 2036 | return {"Isolate Password Sites"}; |
| 2037 | else |
| 2038 | return {}; |
| 2039 | } |
| 2040 | |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 2041 | void ChromeContentBrowserClient::PersistIsolatedOrigin( |
| 2042 | content::BrowserContext* context, |
| 2043 | const url::Origin& origin) { |
| 2044 | DCHECK(!context->IsOffTheRecord()); |
| 2045 | Profile* profile = Profile::FromBrowserContext(context); |
| 2046 | ListPrefUpdate update(profile->GetPrefs(), |
Clark DuVall | aadc244c | 2020-06-06 03:47:14 | [diff] [blame] | 2047 | site_isolation::prefs::kUserTriggeredIsolatedOrigins); |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 2048 | base::ListValue* list = update.Get(); |
| 2049 | base::Value value(origin.Serialize()); |
Jan Wilken Dörrie | a8cb5630 | 2019-06-06 18:59:36 | [diff] [blame] | 2050 | if (!base::Contains(list->GetList(), value)) |
Jan Wilken Dörrie | 91e4ef0 | 2019-09-11 08:22:12 | [diff] [blame] | 2051 | list->Append(std::move(value)); |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 2052 | } |
| 2053 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 2054 | bool ChromeContentBrowserClient::IsFileAccessAllowed( |
| 2055 | const base::FilePath& path, |
| 2056 | const base::FilePath& absolute_path, |
| 2057 | const base::FilePath& profile_path) { |
| 2058 | return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path, |
| 2059 | profile_path); |
| 2060 | } |
| 2061 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 2062 | namespace { |
| 2063 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2064 | void MaybeAppendBlinkSettingsSwitchForFieldTrial( |
| 2065 | const base::CommandLine& browser_command_line, |
| 2066 | base::CommandLine* command_line) { |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 2067 | // List of field trials that modify the blink-settings command line flag. No |
| 2068 | // two field trials in the list should specify the same keys, otherwise one |
| 2069 | // field trial may overwrite another. See Source/core/frame/Settings.in in |
| 2070 | // Blink for the list of valid keys. |
| 2071 | static const char* const kBlinkSettingsFieldTrials[] = { |
jkarlin | 3bddb7d | 2016-09-21 18:44:16 | [diff] [blame] | 2072 | // Keys: disallowFetchForDocWrittenScriptsInMainFrame |
| 2073 | // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections |
| 2074 | // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G |
| 2075 | "DisallowFetchForDocWrittenScriptsInMainFrame", |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 2076 | }; |
| 2077 | |
| 2078 | std::vector<std::string> blink_settings; |
| 2079 | for (const char* field_trial_name : kBlinkSettingsFieldTrials) { |
| 2080 | // Each blink-settings field trial should include a forcing_flag group, |
| 2081 | // to make sure that clients that specify the blink-settings flag on the |
| 2082 | // command line are excluded from the experiment groups. To make |
| 2083 | // sure we assign clients that specify this flag to the forcing_flag |
| 2084 | // group, we must call GetVariationParams for each field trial first |
| 2085 | // (for example, before checking HasSwitch() and returning), since |
| 2086 | // GetVariationParams has the side-effect of assigning the client to |
| 2087 | // a field trial group. |
| 2088 | std::map<std::string, std::string> params; |
| 2089 | if (variations::GetVariationParams(field_trial_name, ¶ms)) { |
| 2090 | for (const auto& param : params) { |
| 2091 | blink_settings.push_back(base::StringPrintf( |
| 2092 | "%s=%s", param.first.c_str(), param.second.c_str())); |
| 2093 | } |
| 2094 | } |
| 2095 | } |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 2096 | |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 2097 | if (blink_settings.empty()) { |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2098 | return; |
| 2099 | } |
| 2100 | |
Gyuyoung Kim | a252d4a | 2020-09-16 07:20:31 | [diff] [blame] | 2101 | if (browser_command_line.HasSwitch(blink::switches::kBlinkSettings) || |
| 2102 | command_line->HasSwitch(blink::switches::kBlinkSettings)) { |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 2103 | // The field trials should be configured to force users that specify the |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 2104 | // blink-settings flag into a group with no params, and we return |
| 2105 | // above if no params were specified, so it's an error if we reach |
| 2106 | // this point. |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2107 | LOG(WARNING) << "Received field trial params, " |
| 2108 | "but blink-settings switch already specified."; |
| 2109 | return; |
| 2110 | } |
| 2111 | |
Gyuyoung Kim | a252d4a | 2020-09-16 07:20:31 | [diff] [blame] | 2112 | command_line->AppendSwitchASCII(blink::switches::kBlinkSettings, |
brettw | d94a2214 | 2015-07-15 05:19:26 | [diff] [blame] | 2113 | base::JoinString(blink_settings, ",")); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2114 | } |
| 2115 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 2116 | } // namespace |
| 2117 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2118 | void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 2119 | base::CommandLine* command_line, |
| 2120 | int child_process_id) { |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 2121 | #if defined(OS_MAC) |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2122 | std::unique_ptr<metrics::ClientInfo> client_info = |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2123 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
| 2124 | if (client_info) { |
| 2125 | command_line->AppendSwitchASCII(switches::kMetricsClientID, |
| 2126 | client_info->client_id); |
| 2127 | } |
| 2128 | #elif defined(OS_POSIX) |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 2129 | #if defined(OS_ANDROID) |
| 2130 | bool enable_crash_reporter = true; |
| 2131 | #else |
Joshua Peraza | ce68e2f | 2019-09-23 18:44:24 | [diff] [blame] | 2132 | bool enable_crash_reporter = false; |
| 2133 | if (crash_reporter::IsCrashpadEnabled()) { |
| 2134 | command_line->AppendSwitch(crash_reporter::kEnableCrashpad); |
| 2135 | enable_crash_reporter = true; |
| 2136 | |
| 2137 | int fd; |
| 2138 | pid_t pid; |
| 2139 | if (crash_reporter::GetHandlerSocket(&fd, &pid)) { |
| 2140 | command_line->AppendSwitchASCII( |
| 2141 | crash_reporter::switches::kCrashpadHandlerPid, |
| 2142 | base::NumberToString(pid)); |
| 2143 | } |
| 2144 | } else { |
| 2145 | enable_crash_reporter = breakpad::IsCrashReporterEnabled(); |
| 2146 | } |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 2147 | #endif |
| 2148 | if (enable_crash_reporter) { |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2149 | std::string switch_value; |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2150 | std::unique_ptr<metrics::ClientInfo> client_info = |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 2151 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2152 | if (client_info) |
| 2153 | switch_value = client_info->client_id; |
| 2154 | switch_value.push_back(','); |
Boris Vidolov | 8657801 | 2018-03-21 16:55:25 | [diff] [blame] | 2155 | switch_value.append(chrome::GetChannelName()); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2156 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2157 | switch_value); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2158 | } |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2159 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2160 | |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 2161 | if (logging::DialogsAreSuppressed()) |
| 2162 | command_line->AppendSwitch(switches::kNoErrorDialogs); |
| 2163 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2164 | std::string process_type = |
| 2165 | command_line->GetSwitchValueASCII(switches::kProcessType); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 2166 | const base::CommandLine& browser_command_line = |
| 2167 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 2168 | |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 2169 | static const char* const kCommonSwitchNames[] = { |
John Abd-El-Malek | ec1fc69e | 2021-01-28 19:14:41 | [diff] [blame^] | 2170 | embedder_support::kUserAgent, |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2171 | switches::kUserDataDir, // Make logs go to the right file. |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 2172 | }; |
| 2173 | command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2174 | base::size(kCommonSwitchNames)); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 2175 | |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2176 | static const char* const kDinosaurEasterEggSwitches[] = { |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 2177 | error_page::switches::kDisableDinosaurEasterEgg, |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 2178 | }; |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2179 | command_line->CopySwitchesFrom(browser_command_line, |
| 2180 | kDinosaurEasterEggSwitches, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2181 | base::size(kDinosaurEasterEggSwitches)); |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 2182 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 2183 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | 6bdc5227 | 2014-05-27 00:12:33 | [diff] [blame] | 2184 | // On Chrome OS need to pass primary user homedir (in multi-profiles session). |
| 2185 | base::FilePath homedir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 2186 | base::PathService::Get(base::DIR_HOME, &homedir); |
[email protected] | 6bdc5227 | 2014-05-27 00:12:33 | [diff] [blame] | 2187 | command_line->AppendSwitchASCII(chromeos::switches::kHomedir, |
| 2188 | homedir.value().c_str()); |
| 2189 | #endif |
| 2190 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 2191 | if (process_type == switches::kRendererProcess) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2192 | content::RenderProcessHost* process = |
| 2193 | content::RenderProcessHost::FromID(child_process_id); |
| 2194 | Profile* profile = |
| 2195 | process ? Profile::FromBrowserContext(process->GetBrowserContext()) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2196 | : nullptr; |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2197 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2198 | extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line, |
| 2199 | process, profile); |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2200 | } |
| 2201 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 2202 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2203 | const std::string& login_profile = browser_command_line.GetSwitchValueASCII( |
| 2204 | chromeos::switches::kLoginProfile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2205 | if (!login_profile.empty()) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2206 | command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, |
| 2207 | login_profile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2208 | #endif |
| 2209 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2210 | MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line, |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 2211 | chrome::GetChannel()); |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2212 | if (process) { |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2213 | PrefService* prefs = profile->GetPrefs(); |
| 2214 | // Currently this pref is only registered if applied via a policy. |
| 2215 | if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && |
| 2216 | prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 2217 | // Turn this policy into a command line switch. |
| 2218 | command_line->AppendSwitch(switches::kDisable3DAPIs); |
| 2219 | } |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 2220 | |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 2221 | #if BUILDFLAG(SAFE_BROWSING_AVAILABLE) |
| 2222 | bool client_side_detection_enabled = |
| 2223 | safe_browsing::IsSafeBrowsingEnabled(*prefs) && |
Daniel Rubery | 33506f9f | 2020-10-07 00:28:13 | [diff] [blame] | 2224 | !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2225 | ::switches::kDisableClientSidePhishingDetection); |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 2226 | #if BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
| 2227 | client_side_detection_enabled &= base::FeatureList::IsEnabled( |
| 2228 | safe_browsing::kClientSideDetectionForAndroid); |
| 2229 | #endif // BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
| 2230 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2231 | // Disable client-side phishing detection in the renderer if it is |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 2232 | // disabled in the Profile preferences, or by command line flag, or by not |
| 2233 | // being enabled on Android. |
| 2234 | if (!client_side_detection_enabled) { |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2235 | command_line->AppendSwitch( |
| 2236 | switches::kDisableClientSidePhishingDetection); |
| 2237 | } |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 2238 | #endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE) |
[email protected] | 0045b0f4 | 2012-07-26 11:52:08 | [diff] [blame] | 2239 | |
vitalybuka | a7ae505 | 2014-09-26 04:11:13 | [diff] [blame] | 2240 | if (prefs->GetBoolean(prefs::kPrintPreviewDisabled)) |
| 2241 | command_line->AppendSwitch(switches::kDisablePrintPreview); |
| 2242 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 2243 | #if !defined(OS_ANDROID) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 2244 | InstantService* instant_service = |
| 2245 | InstantServiceFactory::GetForProfile(profile); |
| 2246 | if (instant_service && |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2247 | instant_service->IsInstantProcess(process->GetID())) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 2248 | command_line->AppendSwitch(switches::kInstantProcess); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2249 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 2250 | #endif |
fqj | ba8749c | 2015-10-29 15:33:07 | [diff] [blame] | 2251 | |
fqj | 38306f7b | 2015-11-02 16:59:06 | [diff] [blame] | 2252 | if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) && |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2253 | !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) { |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 2254 | command_line->AppendSwitch( |
| 2255 | error_page::switches::kDisableDinosaurEasterEgg); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2256 | } |
Daniel Vogelheim | 976f1c2 | 2017-11-22 16:26:03 | [diff] [blame] | 2257 | |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 2258 | MaybeAppendSecureOriginsAllowlistSwitch(command_line); |
| 2259 | |
Katie Dillon | c25ee5c9 | 2019-09-12 17:05:42 | [diff] [blame] | 2260 | if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) && |
| 2261 | prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) { |
| 2262 | command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal); |
| 2263 | } |
Takashi Toyoshima | 12844146 | 2019-10-16 04:19:17 | [diff] [blame] | 2264 | |
Daniel Libby | c5bfd91f | 2020-03-07 03:44:10 | [diff] [blame] | 2265 | if (prefs->HasPrefPath(prefs::kScrollToTextFragmentEnabled) && |
| 2266 | !prefs->GetBoolean(prefs::kScrollToTextFragmentEnabled)) { |
| 2267 | command_line->AppendSwitch(switches::kDisableScrollToTextFragment); |
| 2268 | } |
| 2269 | |
Adrienne Walker | 29765129 | 2020-05-08 00:23:18 | [diff] [blame] | 2270 | if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) && |
| 2271 | prefs->GetBoolean(prefs::kAppCacheForceEnabled)) { |
| 2272 | command_line->AppendSwitch(switches::kAppCacheForceEnabled); |
| 2273 | } |
Chris Hamilton | 65c4131 | 2020-06-10 13:14:40 | [diff] [blame] | 2274 | |
| 2275 | // The IntensiveWakeUpThrottling feature is typically managed via a |
| 2276 | // base::Feature, but it has a managed policy override. The override is |
| 2277 | // communicated to blink via a custom command-line flag. See |
| 2278 | // PageSchedulerImpl for the other half of related logic. |
| 2279 | PrefService* local_state = g_browser_process->local_state(); |
| 2280 | const PrefService::Preference* pref = local_state->FindPreference( |
| 2281 | policy::policy_prefs::kIntensiveWakeUpThrottlingEnabled); |
| 2282 | if (pref && pref->IsManaged()) { |
| 2283 | command_line->AppendSwitchASCII( |
| 2284 | blink::switches::kIntensiveWakeUpThrottlingPolicy, |
| 2285 | pref->GetValue()->GetBool() |
| 2286 | ? blink::switches::kIntensiveWakeUpThrottlingPolicy_ForceEnable |
| 2287 | : blink::switches:: |
| 2288 | kIntensiveWakeUpThrottlingPolicy_ForceDisable); |
| 2289 | } |
Aaron Tagliaboschi | 8f3a2830 | 2020-06-24 03:08:26 | [diff] [blame] | 2290 | |
| 2291 | // Same as above, but for the blink side of UserAgentClientHints |
| 2292 | if (!local_state->GetBoolean( |
| 2293 | policy::policy_prefs::kUserAgentClientHintsEnabled)) { |
| 2294 | command_line->AppendSwitch( |
| 2295 | blink::switches::kUserAgentClientHintDisable); |
| 2296 | } |
Rakina Zata Amni | c123bd2 | 2020-07-31 19:08:39 | [diff] [blame] | 2297 | |
Eric Lawrence | a8a460c | 2020-11-06 21:10:42 | [diff] [blame] | 2298 | if (!local_state->GetBoolean( |
| 2299 | policy::policy_prefs::kTargetBlankImpliesNoOpener)) { |
| 2300 | command_line->AppendSwitch( |
| 2301 | switches::kDisableTargetBlankImpliesNoOpener); |
| 2302 | } |
| 2303 | |
Rakina Zata Amni | c123bd2 | 2020-07-31 19:08:39 | [diff] [blame] | 2304 | #if defined(OS_ANDROID) |
| 2305 | // Communicating to content/ for BackForwardCache. |
| 2306 | if (prefs->HasPrefPath(policy::policy_prefs::kBackForwardCacheEnabled) && |
| 2307 | !prefs->GetBoolean(policy::policy_prefs::kBackForwardCacheEnabled)) { |
| 2308 | command_line->AppendSwitch(switches::kDisableBackForwardCache); |
| 2309 | } |
| 2310 | #endif // defined(OS_ANDROID) |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2311 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2312 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2313 | MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line, |
| 2314 | command_line); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2315 | |
mdjones | a6b9e17 | 2016-09-23 16:24:30 | [diff] [blame] | 2316 | #if defined(OS_ANDROID) |
| 2317 | // If the platform is Android, force the distillability service on. |
| 2318 | command_line->AppendSwitch(switches::kEnableDistillabilityService); |
| 2319 | #endif |
| 2320 | |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2321 | // Please keep this in alphabetical order. |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2322 | static const char* const kSwitchNames[] = { |
estade | 0ee9126 | 2014-10-23 19:29:19 | [diff] [blame] | 2323 | autofill::switches::kIgnoreAutocompleteOffForAutofill, |
kolos | ad36993 | 2017-02-23 13:29:41 | [diff] [blame] | 2324 | autofill::switches::kShowAutofillSignatures, |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 2325 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Chris Mumford | 6b1696b | 2019-01-25 02:54:30 | [diff] [blame] | 2326 | switches::kShortMergeSessionTimeoutForTest, // For tests only. |
| 2327 | #endif |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2328 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 2329 | extensions::switches::kAllowHTTPBackgroundPage, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2330 | extensions::switches::kAllowLegacyExtensionManifests, |
Chris Mumford | 3f0eda9 | 2018-07-23 14:51:17 | [diff] [blame] | 2331 | extensions::switches::kDisableExtensionsHttpThrottling, |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 2332 | extensions::switches::kEnableExperimentalExtensionApis, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2333 | extensions::switches::kExtensionsOnChromeURLs, |
Chris Mumford | 3f0eda9 | 2018-07-23 14:51:17 | [diff] [blame] | 2334 | extensions::switches::kSetExtensionThrottleTestParams, // For tests only. |
[email protected] | 5adb774 | 2020-06-30 14:28:12 | [diff] [blame] | 2335 | extensions::switches::kAllowlistedExtensionID, |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 2336 | #endif |
estark | 4b003b33 | 2015-02-14 01:07:05 | [diff] [blame] | 2337 | switches::kAllowInsecureLocalhost, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2338 | switches::kAppsGalleryURL, |
[email protected] | 09cff7878 | 2014-04-20 22:04:48 | [diff] [blame] | 2339 | switches::kCloudPrintURL, |
[email protected] | 6f5c141a | 2014-04-15 21:44:51 | [diff] [blame] | 2340 | switches::kCloudPrintXmppEndpoint, |
dslomov | a893e97 | 2014-12-05 09:39:57 | [diff] [blame] | 2341 | switches::kDisableJavaScriptHarmonyShipping, |
Kyle Milka | b5c048e | 2017-07-07 02:38:46 | [diff] [blame] | 2342 | variations::switches::kEnableBenchmarking, |
mdjones | a6b9e17 | 2016-09-23 16:24:30 | [diff] [blame] | 2343 | switches::kEnableDistillabilityService, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2344 | switches::kEnableNaCl, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2345 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | 1b4ec38 | 2014-03-07 02:32:24 | [diff] [blame] | 2346 | switches::kEnableNaClDebug, |
[email protected] | b2c73f4 | 2014-03-07 15:44:48 | [diff] [blame] | 2347 | switches::kEnableNaClNonSfiMode, |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 2348 | #endif |
[email protected] | ce304ce | 2013-02-22 21:54:45 | [diff] [blame] | 2349 | switches::kEnableNetBenchmarking, |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 2350 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Anatoliy Potapchuk | ce6f880 | 2020-01-30 09:30:34 | [diff] [blame] | 2351 | switches::kForceAppMode, |
| 2352 | #endif |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2353 | #if BUILDFLAG(ENABLE_NACL) |
stichnot | 7040ac83 | 2016-02-24 23:40:59 | [diff] [blame] | 2354 | switches::kForcePNaClSubzero, |
| 2355 | #endif |
Marc Treib | ad33cf94 | 2017-08-24 11:19:00 | [diff] [blame] | 2356 | switches::kForceUIDirection, |
John Abd-El-Malek | cdb5b52 | 2020-05-26 22:41:03 | [diff] [blame] | 2357 | switches::kIgnoreGooglePortNumbers, |
erikcorry | b251cb9 | 2014-09-25 23:48:51 | [diff] [blame] | 2358 | switches::kJavaScriptHarmony, |
Andreas Haas | b400d91 | 2019-08-28 18:54:10 | [diff] [blame] | 2359 | switches::kEnableExperimentalWebAssemblyFeatures, |
Clark DuVall | 3d4e89b9 | 2020-04-03 23:07:32 | [diff] [blame] | 2360 | embedder_support::kOriginTrialDisabledFeatures, |
| 2361 | embedder_support::kOriginTrialDisabledTokens, |
| 2362 | embedder_support::kOriginTrialPublicKey, |
wychen | e5568734 | 2015-11-13 20:17:03 | [diff] [blame] | 2363 | switches::kReaderModeHeuristics, |
[email protected] | 499e7c5 | 2013-10-04 16:03:09 | [diff] [blame] | 2364 | translate::switches::kTranslateSecurityOrigin, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2365 | }; |
| 2366 | |
| 2367 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2368 | base::size(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 2369 | } else if (process_type == switches::kUtilityProcess) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2370 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 2371 | static const char* const kSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2372 | extensions::switches::kAllowHTTPBackgroundPage, |
| 2373 | extensions::switches::kEnableExperimentalExtensionApis, |
| 2374 | extensions::switches::kExtensionsOnChromeURLs, |
[email protected] | 5adb774 | 2020-06-30 14:28:12 | [diff] [blame] | 2375 | extensions::switches::kAllowlistedExtensionID, |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 2376 | }; |
| 2377 | |
| 2378 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2379 | base::size(kSwitchNames)); |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 2380 | #endif |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 2381 | MaybeAppendSecureOriginsAllowlistSwitch(command_line); |
Ken Rockot | 4e805fd | 2020-10-01 03:07:39 | [diff] [blame] | 2382 | } else if (process_type == switches::kZygoteProcess) { |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 2383 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2384 | #if BUILDFLAG(ENABLE_NACL) |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 2385 | static const char* const kSwitchNames[] = { |
| 2386 | switches::kEnableNaClDebug, |
| 2387 | switches::kEnableNaClNonSfiMode, |
| 2388 | switches::kForcePNaClSubzero, |
| 2389 | switches::kNaClDangerousNoSandboxNonSfi, |
| 2390 | }; |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2391 | |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 2392 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 2393 | base::size(kSwitchNames)); |
Bill Budge | 431f0b3 | 2020-10-27 21:31:38 | [diff] [blame] | 2394 | #endif |
James Cook | 247a8cb | 2020-12-22 23:09:51 | [diff] [blame] | 2395 | #if BUILDFLAG(IS_CHROMEOS_LACROS) |
| 2396 | // Ensure zygote loads the resource bundle for the right locale. |
| 2397 | static const char* const kMoreSwitchNames[] = {switches::kLang}; |
| 2398 | command_line->CopySwitchesFrom(browser_command_line, kMoreSwitchNames, |
| 2399 | base::size(kMoreSwitchNames)); |
| 2400 | #endif |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 2401 | } else if (process_type == switches::kGpuProcess) { |
Corentin Wallez | e660b15 | 2020-07-15 16:07:54 | [diff] [blame] | 2402 | // If --ignore-gpu-blocklist is passed in, don't send in crash reports |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 2403 | // because GPU is expected to be unreliable. |
Corentin Wallez | 49c0110d | 2020-11-17 10:15:16 | [diff] [blame] | 2404 | if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlocklist) && |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 2405 | !command_line->HasSwitch(switches::kDisableBreakpad)) |
| 2406 | command_line->AppendSwitch(switches::kDisableBreakpad); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2407 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 2408 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 2409 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Joshua Peraza | 30d8fc7 | 2019-08-19 17:24:30 | [diff] [blame] | 2410 | if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) { |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2411 | static const char* const kSwitchNames[] = { |
Joshua Peraza | 86b7958 | 2019-10-08 15:56:29 | [diff] [blame] | 2412 | crash_reporter::switches::kCrashLoopBefore, |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2413 | }; |
| 2414 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 2415 | base::size(kSwitchNames)); |
| 2416 | } |
| 2417 | #endif |
| 2418 | |
Mike Wittman | 67d6311 | 2020-09-19 00:33:46 | [diff] [blame] | 2419 | ThreadProfilerConfiguration::Get()->AppendCommandLineSwitchForChildProcess( |
Mike Wittman | 0d21648f | 2020-09-30 19:05:08 | [diff] [blame] | 2420 | command_line); |
Andrew Comminos | 6605767 | 2019-05-01 00:03:34 | [diff] [blame] | 2421 | |
Sean McAllister | 0d73ca3d | 2020-08-19 17:54:37 | [diff] [blame] | 2422 | #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
Andrew Comminos | 6605767 | 2019-05-01 00:03:34 | [diff] [blame] | 2423 | // Processes may only query perf_event_open with the BPF sandbox disabled. |
| 2424 | if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) && |
Robert Sesek | 7d0b49b | 2020-07-08 18:31:27 | [diff] [blame] | 2425 | command_line->HasSwitch(sandbox::policy::switches::kNoSandbox)) { |
Andrew Comminos | 6605767 | 2019-05-01 00:03:34 | [diff] [blame] | 2426 | command_line->AppendSwitch(switches::kEnableThreadInstructionCount); |
| 2427 | } |
| 2428 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2429 | } |
| 2430 | |
Olivier Yiptong | 0daa93f | 2019-08-22 19:40:08 | [diff] [blame] | 2431 | std::string |
| 2432 | ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() { |
| 2433 | return std::string(chrome::kApplicationClientIDStringForAVScanning); |
| 2434 | } |
| 2435 | |
Marijn Kruisselbrink | efe0bef6 | 2020-07-21 22:44:59 | [diff] [blame] | 2436 | download::QuarantineConnectionCallback |
| 2437 | ChromeContentBrowserClient::GetQuarantineConnectionCallback() { |
| 2438 | return base::BindRepeating( |
| 2439 | &ChromeDownloadManagerDelegate::ConnectToQuarantineService); |
| 2440 | } |
| 2441 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2442 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
[email protected] | e9a32a5 | 2012-06-14 23:32:43 | [diff] [blame] | 2443 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 2444 | return GetIOThreadApplicationLocale(); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2445 | return g_browser_process->GetApplicationLocale(); |
| 2446 | } |
| 2447 | |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 2448 | std::string ChromeContentBrowserClient::GetAcceptLangs( |
| 2449 | content::BrowserContext* context) { |
| 2450 | Profile* profile = Profile::FromBrowserContext(context); |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 2451 | return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 2452 | } |
| 2453 | |
Dana Fried | 34d58000 | 2019-04-24 20:05:48 | [diff] [blame] | 2454 | gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() { |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 2455 | ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
Dana Fried | 34d58000 | 2019-04-24 20:05:48 | [diff] [blame] | 2456 | return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia(); |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 2457 | } |
| 2458 | |
bengr | e8a146f | 2016-03-10 01:20:22 | [diff] [blame] | 2459 | bool ChromeContentBrowserClient::IsDataSaverEnabled( |
| 2460 | content::BrowserContext* browser_context) { |
rajendrant | fb95964d | 2019-10-17 20:05:38 | [diff] [blame] | 2461 | if (!browser_context || browser_context->IsOffTheRecord()) |
| 2462 | return false; |
| 2463 | |
Robert Ogden | c995d4fe | 2019-03-25 19:18:37 | [diff] [blame] | 2464 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2465 | return profile && data_reduction_proxy::DataReductionProxySettings:: |
Tarun Bansal | c91d5bb8 | 2019-11-05 00:17:41 | [diff] [blame] | 2466 | IsDataSaverEnabledByUser(profile->IsOffTheRecord(), |
| 2467 | profile->GetPrefs()); |
bengr | e8a146f | 2016-03-10 01:20:22 | [diff] [blame] | 2468 | } |
| 2469 | |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 2470 | void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker( |
| 2471 | content::BrowserContext* browser_context, |
Mario Sanchez Prada | 0bd8b8c | 2020-10-21 17:49:23 | [diff] [blame] | 2472 | blink::RendererPreferences* out_prefs) { |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 2473 | DCHECK(browser_context); |
| 2474 | DCHECK(out_prefs); |
| 2475 | renderer_preferences_util::UpdateFromSystemSettings( |
| 2476 | out_prefs, Profile::FromBrowserContext(browser_context)); |
| 2477 | } |
| 2478 | |
Clark DuVall | 5690e74 | 2019-07-17 18:26:17 | [diff] [blame] | 2479 | bool ChromeContentBrowserClient::AllowAppCache( |
| 2480 | const GURL& manifest_url, |
Christian Dullweber | 7774015 | 2020-05-12 09:54:17 | [diff] [blame] | 2481 | const GURL& site_for_cookies, |
| 2482 | const base::Optional<url::Origin>& top_frame_origin, |
Clark DuVall | 5690e74 | 2019-07-17 18:26:17 | [diff] [blame] | 2483 | content::BrowserContext* context) { |
| 2484 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2485 | return CookieSettingsFactory::GetForProfile( |
| 2486 | Profile::FromBrowserContext(context)) |
Christian Dullweber | 7774015 | 2020-05-12 09:54:17 | [diff] [blame] | 2487 | ->IsCookieAccessAllowed(manifest_url, site_for_cookies, top_frame_origin); |
Clark DuVall | 5690e74 | 2019-07-17 18:26:17 | [diff] [blame] | 2488 | } |
| 2489 | |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 2490 | content::AllowServiceWorkerResult |
John Abd-El-Malek | 7081094 | 2020-10-27 05:14:38 | [diff] [blame] | 2491 | ChromeContentBrowserClient::AllowServiceWorker( |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2492 | const GURL& scope, |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2493 | const GURL& site_for_cookies, |
| 2494 | const base::Optional<url::Origin>& top_frame_origin, |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2495 | const GURL& script_url, |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 2496 | content::BrowserContext* context) { |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2497 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2498 | GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL(); |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2499 | |
| 2500 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2501 | // Check if this is an extension-related service worker, and, if so, if it's |
| 2502 | // allowed (this can return false if, e.g., the extension is disabled). |
| 2503 | // If it's not allowed, return immediately. We deliberately do *not* report |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 2504 | // to the PageSpecificContentSettings, since the service worker is blocked |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2505 | // because of the extension, rather than because of the user's content |
| 2506 | // settings. |
John Abd-El-Malek | 7081094 | 2020-10-27 05:14:38 | [diff] [blame] | 2507 | if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorker( |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2508 | scope, first_party_url, script_url, context)) { |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 2509 | return content::AllowServiceWorkerResult::No(); |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2510 | } |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2511 | #endif |
| 2512 | |
| 2513 | Profile* profile = Profile::FromBrowserContext(context); |
| 2514 | |
| 2515 | // Check if JavaScript is allowed. |
| 2516 | content_settings::SettingInfo info; |
| 2517 | std::unique_ptr<base::Value> value = |
| 2518 | HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting( |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2519 | first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT, |
Illia Klimov | 48f643c | 2020-11-05 20:06:14 | [diff] [blame] | 2520 | &info); |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2521 | ContentSetting setting = content_settings::ValueToContentSetting(value.get()); |
| 2522 | bool allow_javascript = (setting == CONTENT_SETTING_ALLOW); |
| 2523 | |
| 2524 | // Check if cookies are allowed. |
| 2525 | bool allow_cookies = |
| 2526 | CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed( |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2527 | scope, site_for_cookies, top_frame_origin); |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2528 | |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 2529 | return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript, |
| 2530 | !allow_cookies); |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2531 | } |
| 2532 | |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2533 | bool ChromeContentBrowserClient::AllowSharedWorker( |
| 2534 | const GURL& worker_url, |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2535 | const GURL& site_for_cookies, |
| 2536 | const base::Optional<url::Origin>& top_frame_origin, |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2537 | const std::string& name, |
Hiroki Nakagawa | 018bb6d | 2017-11-30 03:31:37 | [diff] [blame] | 2538 | const url::Origin& constructor_origin, |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2539 | content::BrowserContext* context, |
| 2540 | int render_process_id, |
| 2541 | int render_frame_id) { |
| 2542 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2543 | |
| 2544 | // Check if cookies are allowed. |
| 2545 | bool allow = |
| 2546 | CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context)) |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2547 | ->IsCookieAccessAllowed(worker_url, site_for_cookies, |
| 2548 | top_frame_origin); |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2549 | |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 2550 | content_settings::PageSpecificContentSettings::SharedWorkerAccessed( |
Hiroki Nakagawa | 018bb6d | 2017-11-30 03:31:37 | [diff] [blame] | 2551 | render_process_id, render_frame_id, worker_url, name, constructor_origin, |
| 2552 | !allow); |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2553 | return allow; |
| 2554 | } |
| 2555 | |
Patrick Monette | 6cb099a | 2019-09-18 19:31:27 | [diff] [blame] | 2556 | bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker( |
| 2557 | const std::string& scheme) { |
| 2558 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 2559 | // Extensions are allowed to start cross-origin shared workers. |
| 2560 | if (scheme == extensions::kExtensionScheme) |
| 2561 | return true; |
| 2562 | #endif |
| 2563 | |
| 2564 | return false; |
| 2565 | } |
| 2566 | |
Clark DuVall | ab63d14 | 2019-07-23 04:24:36 | [diff] [blame] | 2567 | bool ChromeContentBrowserClient::AllowSignedExchange( |
| 2568 | content::BrowserContext* browser_context) { |
| 2569 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2570 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2571 | return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled); |
| 2572 | } |
| 2573 | |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2574 | void ChromeContentBrowserClient::AllowWorkerFileSystem( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2575 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2576 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2577 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2578 | base::OnceCallback<void(bool)> callback) { |
| 2579 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2580 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
Christian Dullweber | 7774015 | 2020-05-12 09:54:17 | [diff] [blame] | 2581 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2582 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2583 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2584 | GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2585 | #else |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2586 | FileSystemAccessed(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2587 | #endif |
| 2588 | } |
| 2589 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2590 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2591 | void ChromeContentBrowserClient::GuestPermissionRequestHelper( |
| 2592 | const GURL& url, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2593 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2594 | base::OnceCallback<void(bool)> callback, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2595 | bool allow) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2596 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2597 | std::map<int, int> process_map; |
| 2598 | std::map<int, int>::const_iterator it; |
| 2599 | bool has_web_view_guest = false; |
| 2600 | // Record access to file system for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2601 | for (const auto& it : render_frames) { |
| 2602 | if (process_map.find(it.child_id) != process_map.end()) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2603 | continue; |
| 2604 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2605 | process_map.insert(std::pair<int, int>(it.child_id, it.frame_routing_id)); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2606 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2607 | if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id)) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2608 | has_web_view_guest = true; |
| 2609 | } |
| 2610 | if (!has_web_view_guest) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2611 | FileSystemAccessed(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2612 | return; |
| 2613 | } |
[email protected] | dffb9fc | 2014-07-16 04:14:02 | [diff] [blame] | 2614 | DCHECK_EQ(1U, process_map.size()); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2615 | it = process_map.begin(); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2616 | |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 2617 | extensions::WebViewPermissionHelper* web_view_permission_helper = |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2618 | extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second); |
| 2619 | web_view_permission_helper->RequestFileSystemPermission( |
| 2620 | url, allow, |
| 2621 | base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed, |
| 2622 | weak_factory_.GetWeakPtr(), url, render_frames, |
| 2623 | std::move(callback))); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2624 | } |
| 2625 | #endif |
| 2626 | |
| 2627 | void ChromeContentBrowserClient::FileSystemAccessed( |
| 2628 | const GURL& url, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2629 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2630 | base::OnceCallback<void(bool)> callback, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2631 | bool allow) { |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 2632 | // Record access to file system for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2633 | for (const auto& it : render_frames) { |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 2634 | content_settings::PageSpecificContentSettings::FileSystemAccessed( |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2635 | it.child_id, it.frame_routing_id, url, !allow); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2636 | } |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2637 | std::move(callback).Run(allow); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2638 | } |
| 2639 | |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2640 | bool ChromeContentBrowserClient::AllowWorkerIndexedDB( |
| 2641 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2642 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2643 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2644 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2645 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
| 2646 | |
Christian Dullweber | 7774015 | 2020-05-12 09:54:17 | [diff] [blame] | 2647 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2648 | |
| 2649 | // Record access to IndexedDB for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2650 | for (const auto& it : render_frames) { |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 2651 | content_settings::PageSpecificContentSettings::IndexedDBAccessed( |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2652 | it.child_id, it.frame_routing_id, url, !allow); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | return allow; |
| 2656 | } |
| 2657 | |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2658 | bool ChromeContentBrowserClient::AllowWorkerCacheStorage( |
| 2659 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2660 | content::BrowserContext* browser_context, |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2661 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2662 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2663 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
Christian Dullweber | 7774015 | 2020-05-12 09:54:17 | [diff] [blame] | 2664 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt); |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2665 | |
| 2666 | // Record access to CacheStorage for potential display in UI. |
| 2667 | for (const auto& it : render_frames) { |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 2668 | content_settings::PageSpecificContentSettings::CacheStorageAccessed( |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2669 | it.child_id, it.frame_routing_id, url, !allow); |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | return allow; |
| 2673 | } |
| 2674 | |
Joshua Bell | 1ebc8df | 2019-11-06 00:27:58 | [diff] [blame] | 2675 | bool ChromeContentBrowserClient::AllowWorkerWebLocks( |
| 2676 | const GURL& url, |
| 2677 | content::BrowserContext* browser_context, |
| 2678 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
| 2679 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2680 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
Christian Dullweber | 7774015 | 2020-05-12 09:54:17 | [diff] [blame] | 2681 | return cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt); |
Joshua Bell | 1ebc8df | 2019-11-06 00:27:58 | [diff] [blame] | 2682 | } |
| 2683 | |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2684 | ChromeContentBrowserClient::AllowWebBluetoothResult |
| 2685 | ChromeContentBrowserClient::AllowWebBluetooth( |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2686 | content::BrowserContext* browser_context, |
| 2687 | const url::Origin& requesting_origin, |
| 2688 | const url::Origin& embedding_origin) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2689 | // TODO(crbug.com/598890): Don't disable if |
| 2690 | // base::CommandLine::ForCurrentProcess()-> |
| 2691 | // HasSwitch(switches::kEnableWebBluetooth) is true. |
| 2692 | if (variations::GetVariationParamValue( |
Clark DuVall | a11361ad3 | 2020-02-20 22:14:27 | [diff] [blame] | 2693 | permissions::PermissionContextBase::kPermissionsKillSwitchFieldStudy, |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2694 | "Bluetooth") == |
Clark DuVall | a11361ad3 | 2020-02-20 22:14:27 | [diff] [blame] | 2695 | permissions::PermissionContextBase::kPermissionsKillSwitchBlockedValue) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2696 | // The kill switch is enabled for this permission. Block requests. |
| 2697 | return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED; |
| 2698 | } |
| 2699 | |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2700 | const HostContentSettingsMap* const content_settings = |
| 2701 | HostContentSettingsMapFactory::GetForProfile( |
| 2702 | Profile::FromBrowserContext(browser_context)); |
| 2703 | |
csharrison | aec2c54 | 2016-10-12 19:40:36 | [diff] [blame] | 2704 | if (content_settings->GetContentSetting( |
| 2705 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
Illia Klimov | 48f643c | 2020-11-05 20:06:14 | [diff] [blame] | 2706 | ContentSettingsType::BLUETOOTH_GUARD) == CONTENT_SETTING_BLOCK) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2707 | return AllowWebBluetoothResult::BLOCK_POLICY; |
| 2708 | } |
| 2709 | return AllowWebBluetoothResult::ALLOW; |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2710 | } |
| 2711 | |
beaufort.francois | 01135bf | 2016-11-23 14:37:36 | [diff] [blame] | 2712 | std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() { |
| 2713 | return variations::GetVariationParamValue("WebBluetoothBlocklist", |
| 2714 | "blocklist_additions"); |
scheib | 7425032 | 2016-04-07 03:32:21 | [diff] [blame] | 2715 | } |
| 2716 | |
John Delaney | c278279 | 2021-01-15 01:29:07 | [diff] [blame] | 2717 | bool ChromeContentBrowserClient::IsConversionMeasurementAllowed( |
Charlie Harrison | 071ac92 | 2020-06-25 19:11:22 | [diff] [blame] | 2718 | content::BrowserContext* browser_context) { |
Charlie Harrison | 071ac92 | 2020-06-25 19:11:22 | [diff] [blame] | 2719 | Profile* profile = Profile::FromBrowserContext(browser_context); |
John Delaney | c278279 | 2021-01-15 01:29:07 | [diff] [blame] | 2720 | PrivacySandboxSettings* privacy_sandbox_settings = |
| 2721 | PrivacySandboxSettingsFactory::GetForProfile(profile); |
| 2722 | |
| 2723 | return privacy_sandbox_settings && |
| 2724 | privacy_sandbox_settings->IsPrivacySandboxAllowed(); |
| 2725 | } |
| 2726 | |
| 2727 | bool ChromeContentBrowserClient::IsConversionMeasurementOperationAllowed( |
| 2728 | content::BrowserContext* browser_context, |
| 2729 | ConversionMeasurementOperation operation, |
| 2730 | const url::Origin* impression_origin, |
| 2731 | const url::Origin* conversion_origin, |
| 2732 | const url::Origin* reporting_origin) { |
| 2733 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2734 | |
| 2735 | PrivacySandboxSettings* privacy_sandbox_settings = |
| 2736 | PrivacySandboxSettingsFactory::GetForProfile(profile); |
| 2737 | if (!privacy_sandbox_settings) |
| 2738 | return false; |
| 2739 | |
| 2740 | switch (operation) { |
| 2741 | case ConversionMeasurementOperation::kImpression: |
| 2742 | DCHECK(impression_origin); |
| 2743 | DCHECK(reporting_origin); |
| 2744 | return privacy_sandbox_settings->IsConversionMeasurementAllowed( |
| 2745 | *impression_origin, *reporting_origin); |
| 2746 | case ConversionMeasurementOperation::kConversion: |
| 2747 | DCHECK(conversion_origin); |
| 2748 | DCHECK(reporting_origin); |
| 2749 | return privacy_sandbox_settings->IsConversionMeasurementAllowed( |
| 2750 | *conversion_origin, *reporting_origin); |
| 2751 | case ConversionMeasurementOperation::kReport: |
| 2752 | DCHECK(impression_origin); |
| 2753 | DCHECK(conversion_origin); |
| 2754 | DCHECK(reporting_origin); |
| 2755 | return privacy_sandbox_settings->ShouldSendConversionReport( |
| 2756 | *impression_origin, *conversion_origin, *reporting_origin); |
| 2757 | } |
Charlie Harrison | 071ac92 | 2020-06-25 19:11:22 | [diff] [blame] | 2758 | } |
| 2759 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 2760 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
John Abd-El-Malek | a5b1a5d60 | 2018-11-05 19:20:52 | [diff] [blame] | 2761 | void ChromeContentBrowserClient::OnTrustAnchorUsed( |
John Abd-El-Malek | 35bfaa5 | 2019-08-20 16:22:07 | [diff] [blame] | 2762 | content::BrowserContext* browser_context) { |
| 2763 | user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 2764 | if (user_manager) { |
| 2765 | const user_manager::User* user = |
| 2766 | chromeos::ProfileHelper::Get()->GetUserByProfile( |
| 2767 | Profile::FromBrowserContext(browser_context)); |
| 2768 | if (user && !user->username_hash().empty()) { |
| 2769 | policy::PolicyCertServiceFactory::SetUsedPolicyCertificates( |
Andreea Costinas | e1dd9e3a | 2020-09-22 11:43:35 | [diff] [blame] | 2770 | user->GetAccountId().GetUserEmail()); |
John Abd-El-Malek | 35bfaa5 | 2019-08-20 16:22:07 | [diff] [blame] | 2771 | } |
| 2772 | } |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 2773 | } |
| 2774 | #endif |
| 2775 | |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2776 | scoped_refptr<network::SharedURLLoaderFactory> |
| 2777 | ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() { |
Min Qin | da0d55b | 2018-10-12 18:30:05 | [diff] [blame] | 2778 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 2779 | !BrowserThread::IsThreadInitialized(BrowserThread::UI)); |
| 2780 | |
| 2781 | if (!SystemNetworkContextManager::GetInstance()) |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2782 | return nullptr; |
| 2783 | |
Min Qin | da0d55b | 2018-10-12 18:30:05 | [diff] [blame] | 2784 | return SystemNetworkContextManager::GetInstance() |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2785 | ->GetSharedURLLoaderFactory(); |
Andrew Moylan | 8673dba | 2017-10-10 04:29:04 | [diff] [blame] | 2786 | } |
| 2787 | |
Sean Gilhuly | da1ee4b | 2018-11-13 21:56:09 | [diff] [blame] | 2788 | network::mojom::NetworkContext* |
| 2789 | ChromeContentBrowserClient::GetSystemNetworkContext() { |
| 2790 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2791 | DCHECK(g_browser_process->system_network_context_manager()); |
| 2792 | return g_browser_process->system_network_context_manager()->GetContext(); |
| 2793 | } |
| 2794 | |
Andrew Moylan | 17329fc | 2017-09-25 07:43:30 | [diff] [blame] | 2795 | std::string ChromeContentBrowserClient::GetGeolocationApiKey() { |
| 2796 | return google_apis::GetAPIKey(); |
| 2797 | } |
| 2798 | |
Ke He | 21ee87f | 2018-05-30 02:35:32 | [diff] [blame] | 2799 | #if defined(OS_ANDROID) |
| 2800 | bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() { |
| 2801 | // Indicate that Chrome uses the GMS core location provider. |
| 2802 | return true; |
| 2803 | } |
| 2804 | #endif |
| 2805 | |
Yeol | f3dc22ca | 2019-04-18 17:25:32 | [diff] [blame] | 2806 | scoped_refptr<content::QuotaPermissionContext> |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 2807 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
Scott Violet | 9389378 | 2020-03-27 16:23:54 | [diff] [blame] | 2808 | return new permissions::QuotaPermissionContextImpl(); |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 2809 | } |
| 2810 | |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 2811 | content::GeneratedCodeCacheSettings |
| 2812 | ChromeContentBrowserClient::GetGeneratedCodeCacheSettings( |
| 2813 | content::BrowserContext* context) { |
| 2814 | base::FilePath cache_path; |
| 2815 | chrome::GetUserCacheDirectory(context->GetPath(), &cache_path); |
| 2816 | // If we pass 0 for size, disk_cache will pick a default size using the |
| 2817 | // heuristics based on available disk size. These are implemented in |
| 2818 | // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc. |
Mythri A | b248657 | 2019-06-13 14:48:16 | [diff] [blame] | 2819 | int64_t size_in_bytes = 0; |
Greg Thompson | 8c922756 | 2019-08-05 17:47:13 | [diff] [blame] | 2820 | DCHECK(g_browser_process); |
| 2821 | PrefService* local_state = g_browser_process->local_state(); |
| 2822 | if (local_state) { |
| 2823 | size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize); |
| 2824 | base::FilePath disk_cache_dir = |
| 2825 | local_state->GetFilePath(prefs::kDiskCacheDir); |
| 2826 | if (!disk_cache_dir.empty()) |
| 2827 | cache_path = disk_cache_dir.Append(cache_path.BaseName()); |
| 2828 | } |
Mythri A | b248657 | 2019-06-13 14:48:16 | [diff] [blame] | 2829 | return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path); |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 2830 | } |
| 2831 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 2832 | void ChromeContentBrowserClient::AllowCertificateError( |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2833 | content::WebContents* web_contents, |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 2834 | int cert_error, |
| 2835 | const net::SSLInfo& ssl_info, |
| 2836 | const GURL& request_url, |
John Abd-El-Malek | c5b8df91 | 2019-05-07 17:02:23 | [diff] [blame] | 2837 | bool is_main_frame_request, |
[email protected] | d9be4770 | 2012-05-16 03:41:22 | [diff] [blame] | 2838 | bool strict_enforcement, |
Erik Staab | a65a603 | 2019-11-27 22:23:26 | [diff] [blame] | 2839 | base::OnceCallback<void(content::CertificateRequestResultType)> callback) { |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2840 | DCHECK(web_contents); |
John Abd-El-Malek | c5b8df91 | 2019-05-07 17:02:23 | [diff] [blame] | 2841 | if (!is_main_frame_request) { |
irisu | 8452ddd6 | 2017-03-22 07:46:14 | [diff] [blame] | 2842 | // A sub-resource has a certificate error. The user doesn't really |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 2843 | // have a context for making the right decision, so block the |
| 2844 | // request hard, without an info bar to allow showing the insecure |
| 2845 | // content. |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2846 | if (!callback.is_null()) |
Erik Staab | a65a603 | 2019-11-27 22:23:26 | [diff] [blame] | 2847 | std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 2848 | return; |
| 2849 | } |
| 2850 | |
Hiroki Nakagawa | 7230e341 | 2021-01-22 10:08:29 | [diff] [blame] | 2851 | // If the tab is being no-state prefetched, cancel the prefetcher and the |
| 2852 | // request. |
| 2853 | prerender::NoStatePrefetchContents* no_state_prefetch_contents = |
| 2854 | prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents( |
| 2855 | web_contents); |
| 2856 | if (no_state_prefetch_contents) { |
| 2857 | no_state_prefetch_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR); |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2858 | if (!callback.is_null()) { |
Erik Staab | a65a603 | 2019-11-27 22:23:26 | [diff] [blame] | 2859 | std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL); |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2860 | } |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2861 | return; |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 2862 | } |
| 2863 | |
Erik Staab | a65a603 | 2019-11-27 22:23:26 | [diff] [blame] | 2864 | std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 2865 | return; |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 2866 | } |
| 2867 | |
Katie D | 1882617e | 2020-05-06 20:06:01 | [diff] [blame] | 2868 | #if !defined(OS_ANDROID) |
| 2869 | bool ChromeContentBrowserClient::ShouldDenyRequestOnCertificateError( |
| 2870 | const GURL main_page_url) { |
| 2871 | // Desktop Reader Mode pages should never load resources with certificate |
| 2872 | // errors. Desktop Reader Mode is more strict about security than Reader Mode |
| 2873 | // on Android: the desktop version has its own security indicator and |
| 2874 | // is not downgraded to a WARNING, whereas Android will show "Not secure" |
| 2875 | // in the omnibox (for low-end devices which show the omnibox on Reader Mode |
| 2876 | // pages). |
| 2877 | return main_page_url.SchemeIs(dom_distiller::kDomDistillerScheme); |
| 2878 | } |
| 2879 | #endif |
| 2880 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2881 | namespace { |
| 2882 | |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2883 | certificate_matching::CertificatePrincipalPattern |
| 2884 | ParseCertificatePrincipalPattern(const base::Value* pattern) { |
| 2885 | return certificate_matching::CertificatePrincipalPattern:: |
| 2886 | ParseFromOptionalDict(pattern, "CN", "L", "O", "OU"); |
| 2887 | } |
| 2888 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2889 | // Attempts to auto-select a client certificate according to the value of |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2890 | // |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2891 | // |requesting_url|. If no certificate was auto-selected, returns nullptr. |
| 2892 | std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate( |
| 2893 | Profile* profile, |
| 2894 | const GURL& requesting_url, |
| 2895 | net::ClientCertIdentityList& client_certs) { |
| 2896 | HostContentSettingsMap* host_content_settings_map = |
| 2897 | HostContentSettingsMapFactory::GetForProfile(profile); |
| 2898 | std::unique_ptr<base::Value> setting = |
| 2899 | host_content_settings_map->GetWebsiteSetting( |
| 2900 | requesting_url, requesting_url, |
Illia Klimov | 48f643c | 2020-11-05 20:06:14 | [diff] [blame] | 2901 | ContentSettingsType::AUTO_SELECT_CERTIFICATE, nullptr); |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2902 | |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2903 | if (!setting || !setting->is_dict()) |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2904 | return nullptr; |
| 2905 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2906 | const base::Value* filters = |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2907 | setting->FindKeyOfType("filters", base::Value::Type::LIST); |
| 2908 | if (!filters) { |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2909 | // |setting_dict| has the wrong format (e.g. single filter instead of a |
| 2910 | // list of filters). This content setting is only provided by |
| 2911 | // the |PolicyProvider|, which should always set it to a valid format. |
| 2912 | // Therefore, delete the invalid value. |
| 2913 | host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 2914 | requesting_url, requesting_url, |
Illia Klimov | 48f643c | 2020-11-05 20:06:14 | [diff] [blame] | 2915 | ContentSettingsType::AUTO_SELECT_CERTIFICATE, nullptr); |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2916 | return nullptr; |
| 2917 | } |
| 2918 | |
| 2919 | for (const base::Value& filter : filters->GetList()) { |
| 2920 | DCHECK(filter.is_dict()); |
| 2921 | |
| 2922 | auto issuer_pattern = ParseCertificatePrincipalPattern( |
| 2923 | filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY)); |
| 2924 | auto subject_pattern = ParseCertificatePrincipalPattern( |
| 2925 | filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY)); |
| 2926 | // Use the first certificate that is matched by the filter. |
| 2927 | for (auto& client_cert : client_certs) { |
| 2928 | if (issuer_pattern.Matches(client_cert->certificate()->issuer()) && |
| 2929 | subject_pattern.Matches(client_cert->certificate()->subject())) { |
| 2930 | return std::move(client_cert); |
| 2931 | } |
| 2932 | } |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | return nullptr; |
| 2936 | } |
| 2937 | |
Prashant Nevase | 788dcee | 2020-10-30 19:00:17 | [diff] [blame] | 2938 | #if !defined(OS_ANDROID) |
| 2939 | blink::mojom::PreferredColorScheme ToBlinkPreferredColorScheme( |
| 2940 | ui::NativeTheme::PreferredColorScheme native_theme_scheme) { |
| 2941 | switch (native_theme_scheme) { |
| 2942 | case ui::NativeTheme::PreferredColorScheme::kDark: |
| 2943 | return blink::mojom::PreferredColorScheme::kDark; |
| 2944 | case ui::NativeTheme::PreferredColorScheme::kLight: |
| 2945 | return blink::mojom::PreferredColorScheme::kLight; |
| 2946 | } |
| 2947 | |
| 2948 | NOTREACHED(); |
| 2949 | } |
| 2950 | #endif // !defined(OS_ANDROID) |
| 2951 | |
| 2952 | // Returns true if preferred color scheme is modified based on at least one of |
| 2953 | // the following - |
| 2954 | // |url| - Last committed url. |
| 2955 | // |web_contents| - For Android based on IsNightModeEnabled(). |
| 2956 | // |native_theme| - For other platforms based on native theme scheme. |
| 2957 | bool UpdatePreferredColorScheme(WebPreferences* web_prefs, |
| 2958 | const GURL& url, |
| 2959 | WebContents* web_contents, |
| 2960 | const ui::NativeTheme* native_theme) { |
| 2961 | auto old_preferred_color_scheme = web_prefs->preferred_color_scheme; |
| 2962 | |
| 2963 | #if defined(OS_ANDROID) |
| 2964 | auto* delegate = TabAndroid::FromWebContents(web_contents) |
| 2965 | ? static_cast<android::TabWebContentsDelegateAndroid*>( |
| 2966 | web_contents->GetDelegate()) |
| 2967 | : nullptr; |
| 2968 | if (delegate) { |
| 2969 | web_prefs->preferred_color_scheme = |
| 2970 | delegate->IsNightModeEnabled() |
| 2971 | ? blink::mojom::PreferredColorScheme::kDark |
| 2972 | : blink::mojom::PreferredColorScheme::kLight; |
| 2973 | } |
| 2974 | #else |
| 2975 | // Update based on native theme scheme. |
| 2976 | web_prefs->preferred_color_scheme = |
| 2977 | ToBlinkPreferredColorScheme(native_theme->GetPreferredColorScheme()); |
| 2978 | #endif // defined(OS_ANDROID) |
| 2979 | |
Alex Ilin | 85e8fd9 | 2020-12-01 14:07:18 | [diff] [blame] | 2980 | bool force_light = false; |
Prashant Nevase | 788dcee | 2020-10-30 19:00:17 | [diff] [blame] | 2981 | // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is |
| 2982 | // disabled; some of the UI is not yet correctly themed. |
| 2983 | if (!base::FeatureList::IsEnabled(features::kWebUIDarkMode)) { |
| 2984 | // Update based on last committed url. |
Alex Ilin | 85e8fd9 | 2020-12-01 14:07:18 | [diff] [blame] | 2985 | force_light |= url.SchemeIs(content::kChromeUIScheme); |
Prashant Nevase | 788dcee | 2020-10-30 19:00:17 | [diff] [blame] | 2986 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Alex Ilin | 85e8fd9 | 2020-12-01 14:07:18 | [diff] [blame] | 2987 | force_light |= url.SchemeIs(extensions::kExtensionScheme) && |
| 2988 | url.host_piece() == extension_misc::kPdfExtensionId; |
Prashant Nevase | 788dcee | 2020-10-30 19:00:17 | [diff] [blame] | 2989 | #endif |
Alex Ilin | 85e8fd9 | 2020-12-01 14:07:18 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | // Reauth WebUI doesn't support dark mode yet because it shares the dialog |
| 2993 | // with GAIA web contents that is not correctly themed. |
| 2994 | force_light |= url.SchemeIs(content::kChromeUIScheme) && |
| 2995 | url.host_piece() == chrome::kChromeUISigninReauthHost; |
| 2996 | |
| 2997 | if (force_light) { |
| 2998 | web_prefs->preferred_color_scheme = |
| 2999 | blink::mojom::PreferredColorScheme::kLight; |
Prashant Nevase | 788dcee | 2020-10-30 19:00:17 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | return old_preferred_color_scheme != web_prefs->preferred_color_scheme; |
| 3003 | } |
| 3004 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 3005 | } // namespace |
| 3006 | |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 3007 | base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate( |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 3008 | content::WebContents* web_contents, |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 3009 | net::SSLCertRequestInfo* cert_request_info, |
mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 3010 | net::ClientCertIdentityList client_certs, |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 3011 | std::unique_ptr<content::ClientCertificateDelegate> delegate) { |
Hiroki Nakagawa | 7230e341 | 2021-01-22 10:08:29 | [diff] [blame] | 3012 | prerender::NoStatePrefetchContents* no_state_prefetch_contents = |
| 3013 | prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents( |
| 3014 | web_contents); |
| 3015 | if (no_state_prefetch_contents) { |
| 3016 | no_state_prefetch_contents->Destroy( |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 3017 | prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 3018 | return base::OnceClosure(); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 3019 | } |
| 3020 | |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 3021 | GURL requesting_url("https://" + cert_request_info->host_and_port.ToString()); |
| 3022 | DCHECK(requesting_url.is_valid()) |
| 3023 | << "Invalid URL string: https://" |
| 3024 | << cert_request_info->host_and_port.ToString(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 3025 | |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3026 | bool may_show_cert_selection = true; |
| 3027 | |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 3028 | Profile* profile = |
| 3029 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 3030 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3031 | if (chromeos::ProfileHelper::IsSigninProfile(profile)) { |
Pavol Marko | ddc4ea4 | 2020-01-24 12:02:25 | [diff] [blame] | 3032 | // On the sign-in profile, never show certificate selection to the user. A |
| 3033 | // client certificate is an identifier that can be stable for a long time, |
| 3034 | // so only the administrator is allowed to decide which endpoints should see |
| 3035 | // it. |
| 3036 | may_show_cert_selection = false; |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3037 | |
| 3038 | content::StoragePartition* storage_partition = |
| 3039 | content::BrowserContext::GetStoragePartition( |
| 3040 | profile, web_contents->GetSiteInstance()); |
| 3041 | chromeos::login::SigninPartitionManager* signin_partition_manager = |
| 3042 | chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext( |
| 3043 | profile); |
| 3044 | |
| 3045 | // On the sign-in profile, only allow client certs in the context of the |
| 3046 | // sign-in frame. |
| 3047 | if (!signin_partition_manager->IsCurrentSigninStoragePartition( |
| 3048 | storage_partition)) { |
| 3049 | LOG(WARNING) |
| 3050 | << "Client cert requested in sign-in profile in wrong context."; |
| 3051 | // Continue without client certificate. We do this to mimic the case of no |
| 3052 | // client certificate being present in the profile's certificate store. |
| 3053 | delegate->ContinueWithCertificate(nullptr, nullptr); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 3054 | return base::OnceClosure(); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3055 | } |
| 3056 | VLOG(1) << "Client cert requested in sign-in profile."; |
| 3057 | } |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 3058 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3059 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 3060 | std::unique_ptr<net::ClientCertIdentity> auto_selected_identity = |
| 3061 | AutoSelectCertificate(profile, requesting_url, client_certs); |
| 3062 | if (auto_selected_identity) { |
| 3063 | // The callback will own |auto_selected_identity| and |delegate|, keeping |
| 3064 | // them alive until after ContinueWithCertificate is called. |
| 3065 | scoped_refptr<net::X509Certificate> cert = |
| 3066 | auto_selected_identity->certificate(); |
| 3067 | net::ClientCertIdentity::SelfOwningAcquirePrivateKey( |
| 3068 | std::move(auto_selected_identity), |
David Benjamin | 0cda204 | 2019-04-08 23:00:58 | [diff] [blame] | 3069 | base::BindOnce( |
| 3070 | &content::ClientCertificateDelegate::ContinueWithCertificate, |
| 3071 | std::move(delegate), std::move(cert))); |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 3072 | LogClientAuthResult(ClientCertSelectionResult::kAutoSelect); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 3073 | return base::OnceClosure(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 3074 | } |
| 3075 | |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3076 | if (!may_show_cert_selection) { |
| 3077 | LOG(WARNING) << "No client cert matched by policy and user selection is " |
| 3078 | "not allowed."; |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 3079 | LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3080 | // Continue without client certificate. We do this to mimic the case of no |
| 3081 | // client certificate being present in the profile's certificate store. |
| 3082 | delegate->ContinueWithCertificate(nullptr, nullptr); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 3083 | return base::OnceClosure(); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3084 | } |
| 3085 | |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 3086 | return chrome::ShowSSLClientCertificateSelector( |
| 3087 | web_contents, cert_request_info, std::move(client_certs), |
| 3088 | std::move(delegate)); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 3089 | } |
| 3090 | |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 3091 | content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { |
[email protected] | 11158e2d | 2013-02-01 02:31:56 | [diff] [blame] | 3092 | return MediaCaptureDevicesDispatcher::GetInstance(); |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 3093 | } |
| 3094 | |
Adrienne Walker | 80d95f0 | 2020-02-07 22:37:04 | [diff] [blame] | 3095 | content::FeatureObserverClient* |
| 3096 | ChromeContentBrowserClient::GetFeatureObserverClient() { |
François Doray | aa3f8010 | 2019-10-12 02:29:24 | [diff] [blame] | 3097 | return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance() |
Adrienne Walker | 80d95f0 | 2020-02-07 22:37:04 | [diff] [blame] | 3098 | ->GetFeatureObserverClient(); |
Francois Doray | fd823bb1 | 2019-10-04 18:03:05 | [diff] [blame] | 3099 | } |
| 3100 | |
peter | c26c6c6 | 2014-12-10 14:13:59 | [diff] [blame] | 3101 | content::PlatformNotificationService* |
Richard Knoll | d0eae96 | 2019-04-04 12:34:02 | [diff] [blame] | 3102 | ChromeContentBrowserClient::GetPlatformNotificationService( |
| 3103 | content::BrowserContext* browser_context) { |
| 3104 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 3105 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 3106 | return PlatformNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 3107 | } |
| 3108 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 3109 | bool ChromeContentBrowserClient::CanCreateWindow( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3110 | RenderFrameHost* opener, |
[email protected] | 2b751a1 | 2012-03-06 03:00:35 | [diff] [blame] | 3111 | const GURL& opener_url, |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 3112 | const GURL& opener_top_level_frame_url, |
Nasko Oskov | e9f1978 | 2019-01-04 18:32:35 | [diff] [blame] | 3113 | const url::Origin& source_origin, |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 3114 | content::mojom::WindowContainerType container_type, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3115 | const GURL& target_url, |
| 3116 | const content::Referrer& referrer, |
jochen | 67b271b | 2016-08-03 13:50:21 | [diff] [blame] | 3117 | const std::string& frame_name, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3118 | WindowOpenDisposition disposition, |
scottmg | 8e6c608 | 2017-02-13 23:15:48 | [diff] [blame] | 3119 | const blink::mojom::WindowFeatures& features, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3120 | bool user_gesture, |
| 3121 | bool opener_suppressed, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 3122 | bool* no_javascript_access) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3123 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 3124 | DCHECK(opener); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 3125 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3126 | content::WebContents* web_contents = |
| 3127 | content::WebContents::FromRenderFrameHost(opener); |
| 3128 | Profile* profile = |
| 3129 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 3130 | DCHECK(profile); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 3131 | *no_javascript_access = false; |
| 3132 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 3133 | // If the opener is trying to create a background window but doesn't have |
| 3134 | // the appropriate permission, fail the attempt. |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 3135 | if (container_type == content::mojom::WindowContainerType::BACKGROUND) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3136 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3137 | auto* process_map = extensions::ProcessMap::Get(profile); |
| 3138 | auto* registry = extensions::ExtensionRegistry::Get(profile); |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 3139 | if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url, |
| 3140 | opener->GetProcess()->GetID())) { |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 3141 | return false; |
| 3142 | } |
| 3143 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 3144 | // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may |
| 3145 | // return a recently installed Extension even if this CanCreateWindow call |
| 3146 | // was made by an old copy of the page in a normal web process. That's ok, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 3147 | // because the permission check above would have caused an early return |
| 3148 | // already. We must use the full URL to find hosted apps, though, and not |
| 3149 | // just the origin. |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 3150 | const Extension* extension = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3151 | registry->enabled_extensions().GetExtensionOrAppByURL(opener_url); |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 3152 | if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 3153 | *no_javascript_access = true; |
[email protected] | dffb9fc | 2014-07-16 04:14:02 | [diff] [blame] | 3154 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3155 | |
| 3156 | return true; |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 3157 | } |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 3158 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3159 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 3160 | if (extensions::WebViewRendererState::GetInstance()->IsGuest( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3161 | opener->GetProcess()->GetID())) { |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3162 | return true; |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 3163 | } |
| 3164 | |
nick | 0fbc392 | 2016-12-16 20:52:07 | [diff] [blame] | 3165 | if (target_url.SchemeIs(extensions::kExtensionScheme)) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3166 | // Intentionally duplicating |registry| code from above because we want to |
| 3167 | // reduce calls to retrieve them as this function is a SYNC IPC handler. |
| 3168 | auto* registry = extensions::ExtensionRegistry::Get(profile); |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 3169 | const Extension* extension = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3170 | registry->enabled_extensions().GetExtensionOrAppByURL(target_url); |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 3171 | if (extension && extension->is_platform_app()) { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 3172 | UMA_HISTOGRAM_ENUMERATION( |
| 3173 | "Extensions.AppLoadedInTab", |
| 3174 | ClassifyAppLoadedInTabSource(opener_url, extension), |
| 3175 | APP_LOADED_IN_TAB_SOURCE_MAX); |
| 3176 | |
| 3177 | // window.open() may not be used to load v2 apps in a regular tab. |
lazyboy | 39585ed | 2016-12-06 19:30:16 | [diff] [blame] | 3178 | return false; |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 3179 | } |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 3180 | } |
[email protected] | 5940b0d | 2014-07-01 00:18:26 | [diff] [blame] | 3181 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3182 | |
Hiroki Nakagawa | 7230e341 | 2021-01-22 10:08:29 | [diff] [blame] | 3183 | DCHECK(!prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents( |
Mugdha Lakhani | 2c6b23af | 2020-07-31 14:55:57 | [diff] [blame] | 3184 | web_contents)); |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 3185 | |
Aaron Colwell | 9dab165 | 2019-12-09 18:29:49 | [diff] [blame] | 3186 | BlockedWindowParams blocked_params( |
| 3187 | target_url, source_origin, opener->GetSiteInstance(), referrer, |
| 3188 | frame_name, disposition, features, user_gesture, opener_suppressed); |
cm.sanchi | 2522bc9 | 2017-12-04 08:04:13 | [diff] [blame] | 3189 | NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents); |
Clark DuVall | 8a020d62 | 2020-06-04 00:45:50 | [diff] [blame] | 3190 | return blocked_content::MaybeBlockPopup( |
| 3191 | web_contents, &opener_top_level_frame_url, |
| 3192 | std::make_unique<ChromePopupNavigationDelegate>( |
| 3193 | std::move(nav_params)), |
| 3194 | nullptr /*=open_url_params*/, blocked_params.features(), |
| 3195 | HostContentSettingsMapFactory::GetForProfile(profile)) != nullptr; |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 3196 | } |
| 3197 | |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 3198 | content::SpeechRecognitionManagerDelegate* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3199 | ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() { |
[email protected] | 855e18b | 2013-07-08 21:02:00 | [diff] [blame] | 3200 | return new speech::ChromeSpeechRecognitionManagerDelegate(); |
[email protected] | 66cfec6 | 2012-02-24 17:57:51 | [diff] [blame] | 3201 | } |
| 3202 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 3203 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 3204 | content::TtsControllerDelegate* |
| 3205 | ChromeContentBrowserClient::GetTtsControllerDelegate() { |
Scott Violet | 1644cf7 | 2020-06-24 04:51:55 | [diff] [blame] | 3206 | return TtsControllerDelegateImpl::GetInstance(); |
| 3207 | } |
| 3208 | #endif |
| 3209 | |
| 3210 | content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() { |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 3211 | #if !defined(OS_ANDROID) |
Scott Violet | e217e5e | 2020-06-22 19:18:22 | [diff] [blame] | 3212 | content::TtsController::GetInstance()->SetTtsEngineDelegate( |
| 3213 | TtsExtensionEngine::GetInstance()); |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 3214 | #endif |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 3215 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 3216 | return TtsPlatformImplChromeOs::GetInstance(); |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 3217 | #else |
| 3218 | return nullptr; |
| 3219 | #endif |
| 3220 | } |
| 3221 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3222 | void ChromeContentBrowserClient::OverrideWebkitPrefs( |
Aaron Colwell | bd02c6c | 2021-01-16 00:34:29 | [diff] [blame] | 3223 | WebContents* web_contents, |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3224 | WebPreferences* web_prefs) { |
| 3225 | Profile* profile = |
Aaron Colwell | bd02c6c | 2021-01-16 00:34:29 | [diff] [blame] | 3226 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3227 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3228 | |
aelias | 0df335a | 2017-03-02 23:43:51 | [diff] [blame] | 3229 | // Fill font preferences. These are not registered on Android |
| 3230 | // - http://crbug.com/308033, http://crbug.com/696364. |
[email protected] | 33b7954 | 2013-10-18 11:18:45 | [diff] [blame] | 3231 | #if !defined(OS_ANDROID) |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3232 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3233 | prefs::kWebKitStandardFontFamilyMap, |
| 3234 | &web_prefs->standard_font_family_map); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3235 | FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap, |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3236 | &web_prefs->fixed_font_family_map); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3237 | FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap, |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3238 | &web_prefs->serif_font_family_map); |
| 3239 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3240 | prefs::kWebKitSansSerifFontFamilyMap, |
| 3241 | &web_prefs->sans_serif_font_family_map); |
| 3242 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3243 | prefs::kWebKitCursiveFontFamilyMap, |
| 3244 | &web_prefs->cursive_font_family_map); |
| 3245 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3246 | prefs::kWebKitFantasyFontFamilyMap, |
| 3247 | &web_prefs->fantasy_font_family_map); |
| 3248 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3249 | prefs::kWebKitPictographFontFamilyMap, |
| 3250 | &web_prefs->pictograph_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3251 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3252 | web_prefs->default_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3253 | prefs->GetInteger(prefs::kWebKitDefaultFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3254 | web_prefs->default_fixed_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3255 | prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3256 | web_prefs->minimum_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3257 | prefs->GetInteger(prefs::kWebKitMinimumFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3258 | web_prefs->minimum_logical_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3259 | prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize); |
aelias | 0df335a | 2017-03-02 23:43:51 | [diff] [blame] | 3260 | #endif |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3261 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3262 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3263 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3264 | web_prefs->dom_paste_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3265 | prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); |
Joel Hockey | 08a6c84c | 2018-04-11 10:09:21 | [diff] [blame] | 3266 | web_prefs->javascript_can_access_clipboard = |
| 3267 | prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3268 | web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3269 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3270 | if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3271 | web_prefs->javascript_enabled = false; |
mkwst | a1f7749b | 2015-12-28 09:28:57 | [diff] [blame] | 3272 | |
Avi Drissman | 1aa6cb9 | 2019-01-23 15:58:38 | [diff] [blame] | 3273 | if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3274 | web_prefs->web_security_enabled = false; |
mkwst | a1f7749b | 2015-12-28 09:28:57 | [diff] [blame] | 3275 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3276 | if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3277 | web_prefs->plugins_enabled = false; |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3278 | web_prefs->loads_images_automatically = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3279 | prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3280 | |
Zhenyao Mo | a3fda997 | 2017-09-16 01:34:40 | [diff] [blame] | 3281 | if (prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 3282 | web_prefs->webgl1_enabled = false; |
| 3283 | web_prefs->webgl2_enabled = false; |
| 3284 | } |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3285 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3286 | web_prefs->allow_running_insecure_content = |
| 3287 | prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3288 | #if defined(OS_ANDROID) |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 3289 | web_prefs->font_scale_factor = |
| 3290 | static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor)); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3291 | web_prefs->force_enable_zoom = |
| 3292 | prefs->GetBoolean(prefs::kWebKitForceEnableZoom); |
Aran Gilman | 5e9672bed | 2019-08-02 19:07:49 | [diff] [blame] | 3293 | #endif |
Becky Zhou | bbfbde3 | 2019-02-20 17:07:59 | [diff] [blame] | 3294 | web_prefs->force_dark_mode_enabled = |
| 3295 | prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled); |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 3296 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 3297 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Alice Boxhall | da265914 | 2020-05-14 06:04:37 | [diff] [blame] | 3298 | web_prefs->always_show_focus = |
| 3299 | prefs->GetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled); |
Alice Boxhall | a9aafba4 | 2020-06-24 05:42:51 | [diff] [blame] | 3300 | #else |
| 3301 | if (features::IsAccessibilityFocusHighlightEnabled()) { |
| 3302 | web_prefs->always_show_focus = |
| 3303 | prefs->GetBoolean(prefs::kAccessibilityFocusHighlightEnabled); |
| 3304 | } |
Alice Boxhall | da265914 | 2020-05-14 06:04:37 | [diff] [blame] | 3305 | #endif |
| 3306 | |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 3307 | #if defined(OS_ANDROID) |
| 3308 | web_prefs->password_echo_enabled = |
| 3309 | prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled); |
| 3310 | #else |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 3311 | web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled; |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 3312 | #endif |
| 3313 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3314 | web_prefs->text_areas_are_resizable = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3315 | prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3316 | web_prefs->hyperlink_auditing_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3317 | prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); |
| 3318 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3319 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 3320 | std::string image_animation_policy = |
| 3321 | prefs->GetString(prefs::kAnimationPolicy); |
Gyuyoung Kim | 3b4703d | 2020-09-18 00:25:49 | [diff] [blame] | 3322 | if (image_animation_policy == kAnimationPolicyOnce) { |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 3323 | web_prefs->animation_policy = |
Gyuyoung Kim | 1e9d3c3 | 2020-10-12 14:04:57 | [diff] [blame] | 3324 | blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAnimateOnce; |
Gyuyoung Kim | 3b4703d | 2020-09-18 00:25:49 | [diff] [blame] | 3325 | } else if (image_animation_policy == kAnimationPolicyNone) { |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 3326 | web_prefs->animation_policy = |
Gyuyoung Kim | 1e9d3c3 | 2020-10-12 14:04:57 | [diff] [blame] | 3327 | blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyNoAnimation; |
Gyuyoung Kim | 3b4703d | 2020-09-18 00:25:49 | [diff] [blame] | 3328 | } else { |
Gyuyoung Kim | 1e9d3c3 | 2020-10-12 14:04:57 | [diff] [blame] | 3329 | web_prefs->animation_policy = |
| 3330 | blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed; |
Gyuyoung Kim | 3b4703d | 2020-09-18 00:25:49 | [diff] [blame] | 3331 | } |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 3332 | #endif |
| 3333 | |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3334 | // Make sure we will set the default_encoding with canonical encoding name. |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 3335 | web_prefs->default_encoding = |
| 3336 | base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3337 | if (web_prefs->default_encoding.empty()) { |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3338 | prefs->ClearPref(prefs::kDefaultCharset); |
| 3339 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3340 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3341 | DCHECK(!web_prefs->default_encoding.empty()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3342 | |
mkwst | 0554410 | 2015-01-10 20:26:16 | [diff] [blame] | 3343 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3344 | switches::kEnablePotentiallyAnnoyingSecurityFeatures)) { |
mkwst | 772ce814 | 2015-01-16 13:28:07 | [diff] [blame] | 3345 | web_prefs->disable_reading_from_canvas = true; |
mkwst | 0554410 | 2015-01-10 20:26:16 | [diff] [blame] | 3346 | web_prefs->strict_mixed_content_checking = true; |
| 3347 | web_prefs->strict_powerful_feature_restrictions = true; |
| 3348 | } |
| 3349 | |
Robert Ogden | cf2872d | 2019-03-19 18:59:37 | [diff] [blame] | 3350 | web_prefs->data_saver_enabled = IsDataSaverEnabled(profile); |
Ben Greenstein | 49878f5 | 2015-12-18 19:13:21 | [diff] [blame] | 3351 | |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 3352 | web_prefs->data_saver_holdback_web_api_enabled = |
| 3353 | base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback, |
| 3354 | "holdback_web", false); |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 3355 | |
Aaron Colwell | bd02c6c | 2021-01-16 00:34:29 | [diff] [blame] | 3356 | if (web_contents) { |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3357 | #if defined(OS_ANDROID) |
Aaron Colwell | bd02c6c | 2021-01-16 00:34:29 | [diff] [blame] | 3358 | auto* delegate = TabAndroid::FromWebContents(web_contents) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3359 | ? static_cast<android::TabWebContentsDelegateAndroid*>( |
Aaron Colwell | bd02c6c | 2021-01-16 00:34:29 | [diff] [blame] | 3360 | web_contents->GetDelegate()) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3361 | : nullptr; |
| 3362 | if (delegate) { |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3363 | web_prefs->embedded_media_experience_enabled = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3364 | delegate->ShouldEnableEmbeddedMediaExperience(); |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3365 | |
Mounir Lamouri | 9c99a160 | 2018-07-05 15:01:44 | [diff] [blame] | 3366 | web_prefs->picture_in_picture_enabled = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3367 | delegate->IsPictureInPictureEnabled(); |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3368 | } |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3369 | #endif // defined(OS_ANDROID) |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3370 | |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3371 | // web_app_scope value is platform specific. |
| 3372 | #if defined(OS_ANDROID) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3373 | if (delegate) |
| 3374 | web_prefs->web_app_scope = delegate->GetManifestScope(); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3375 | #elif BUILDFLAG(ENABLE_EXTENSIONS) |
| 3376 | { |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3377 | web_prefs->web_app_scope = GURL(); |
| 3378 | // Set |web_app_scope| based on the app associated with the app window if |
| 3379 | // any. Note that the app associated with the window never changes, even |
| 3380 | // if the app navigates off scope. This is not a problem because we still |
| 3381 | // want to use the scope of the app associated with the window, not the |
| 3382 | // WebContents. |
Aaron Colwell | bd02c6c | 2021-01-16 00:34:29 | [diff] [blame] | 3383 | Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
Alan Cutter | d0bd5190 | 2019-05-22 04:15:23 | [diff] [blame] | 3384 | if (browser && browser->app_controller() && |
Alan Cutter | 1797f46a | 2020-02-12 02:48:59 | [diff] [blame] | 3385 | browser->app_controller()->HasAppId()) { |
| 3386 | const web_app::AppId& app_id = browser->app_controller()->GetAppId(); |
| 3387 | const web_app::AppRegistrar& registrar = |
| 3388 | web_app::WebAppProviderBase::GetProviderBase(profile)->registrar(); |
| 3389 | if (registrar.IsLocallyInstalled(app_id)) |
| 3390 | web_prefs->web_app_scope = registrar.GetAppScope(app_id); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3391 | } |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3392 | } |
| 3393 | #endif |
| 3394 | |
Aaron Colwell | bd02c6c | 2021-01-16 00:34:29 | [diff] [blame] | 3395 | web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(web_contents); |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3396 | } |
zqzhang | 93e959d1 | 2017-03-16 13:10:20 | [diff] [blame] | 3397 | |
Aaron Colwell | bd02c6c | 2021-01-16 00:34:29 | [diff] [blame] | 3398 | web_prefs->lazy_load_enabled = |
| 3399 | !web_contents || !web_contents->GetDelegate() || |
| 3400 | web_contents->GetDelegate()->ShouldAllowLazyLoad(); |
rajendrant | e87ed71 | 2018-11-30 01:55:00 | [diff] [blame] | 3401 | |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 3402 | if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) { |
| 3403 | const char* param_name = |
| 3404 | web_prefs->data_saver_enabled |
| 3405 | ? "lazy_frame_loading_distance_thresholds_px_by_ect" |
| 3406 | : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_" |
| 3407 | "saver_enabled"; |
| 3408 | |
| 3409 | base::StringPairs pairs; |
| 3410 | base::SplitStringIntoKeyValuePairs( |
| 3411 | base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading, |
| 3412 | param_name), |
| 3413 | ':', ',', &pairs); |
| 3414 | |
| 3415 | for (const auto& pair : pairs) { |
| 3416 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3417 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3418 | int value = 0; |
| 3419 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
Gyuyoung Kim | d6d4f99 | 2020-11-20 14:13:22 | [diff] [blame] | 3420 | web_prefs->lazy_frame_loading_distance_thresholds_px[static_cast< |
| 3421 | EffectiveConnectionType>(effective_connection_type.value())] = |
| 3422 | value; |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 3423 | } |
| 3424 | } |
| 3425 | } |
| 3426 | |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 3427 | if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) { |
| 3428 | const char* param_name = |
| 3429 | web_prefs->data_saver_enabled |
| 3430 | ? "lazy_image_loading_distance_thresholds_px_by_ect" |
| 3431 | : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_" |
| 3432 | "saver_enabled"; |
| 3433 | |
| 3434 | base::StringPairs pairs; |
| 3435 | base::SplitStringIntoKeyValuePairs( |
| 3436 | base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading, |
| 3437 | param_name), |
| 3438 | ':', ',', &pairs); |
| 3439 | |
| 3440 | for (const auto& pair : pairs) { |
| 3441 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3442 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3443 | int value = 0; |
| 3444 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
Gyuyoung Kim | d6d4f99 | 2020-11-20 14:13:22 | [diff] [blame] | 3445 | web_prefs->lazy_image_loading_distance_thresholds_px[static_cast< |
| 3446 | EffectiveConnectionType>(effective_connection_type.value())] = |
| 3447 | value; |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 3448 | } |
| 3449 | } |
rajendrant | 3daeae29 | 2019-09-20 07:57:54 | [diff] [blame] | 3450 | |
| 3451 | pairs.clear(); |
| 3452 | base::SplitStringIntoKeyValuePairs( |
| 3453 | base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading, |
| 3454 | "lazy_image_first_k_fully_load"), |
| 3455 | ':', ',', &pairs); |
| 3456 | |
| 3457 | for (const auto& pair : pairs) { |
| 3458 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3459 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3460 | int value = 0; |
| 3461 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
Gyuyoung Kim | d6d4f99 | 2020-11-20 14:13:22 | [diff] [blame] | 3462 | web_prefs->lazy_image_first_k_fully_load[static_cast< |
| 3463 | EffectiveConnectionType>(effective_connection_type.value())] = |
rajendrant | 3daeae29 | 2019-09-20 07:57:54 | [diff] [blame] | 3464 | value; |
| 3465 | } |
| 3466 | } |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 3467 | } |
| 3468 | |
Tarun Bansal | d10f17a0 | 2018-09-13 00:23:17 | [diff] [blame] | 3469 | if (base::FeatureList::IsEnabled( |
| 3470 | features::kNetworkQualityEstimatorWebHoldback)) { |
| 3471 | std::string effective_connection_type_param = |
| 3472 | base::GetFieldTrialParamValueByFeature( |
| 3473 | features::kNetworkQualityEstimatorWebHoldback, |
| 3474 | "web_effective_connection_type_override"); |
| 3475 | |
| 3476 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3477 | net::GetEffectiveConnectionTypeForName(effective_connection_type_param); |
| 3478 | DCHECK(effective_connection_type_param.empty() || |
| 3479 | effective_connection_type); |
| 3480 | if (effective_connection_type) { |
| 3481 | DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 3482 | effective_connection_type.value()); |
| 3483 | web_prefs->network_quality_estimator_web_holdback = |
Gyuyoung Kim | d6d4f99 | 2020-11-20 14:13:22 | [diff] [blame] | 3484 | static_cast<EffectiveConnectionType>( |
| 3485 | effective_connection_type.value()); |
Tarun Bansal | d10f17a0 | 2018-09-13 00:23:17 | [diff] [blame] | 3486 | } |
| 3487 | } |
| 3488 | |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3489 | #if !defined(OS_ANDROID) |
Aaron Colwell | bd02c6c | 2021-01-16 00:34:29 | [diff] [blame] | 3490 | if (IsAutoplayAllowedByPolicy(web_contents, prefs)) { |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3491 | // If autoplay is allowed by policy then force the no user gesture required |
| 3492 | // autoplay policy. |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3493 | web_prefs->autoplay_policy = |
Gyuyoung Kim | f6c02a26 | 2020-10-13 01:36:13 | [diff] [blame] | 3494 | blink::mojom::AutoplayPolicy::kNoUserGestureRequired; |
Mounir Lamouri | c2186808 | 2018-10-11 21:09:55 | [diff] [blame] | 3495 | } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) && |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3496 | web_prefs->autoplay_policy == |
Gyuyoung Kim | f6c02a26 | 2020-10-13 01:36:13 | [diff] [blame] | 3497 | blink::mojom::AutoplayPolicy:: |
Gyuyoung Kim | 1ac4ca78 | 2020-09-11 03:32:51 | [diff] [blame] | 3498 | kDocumentUserActivationRequired) { |
Mounir Lamouri | c2186808 | 2018-10-11 21:09:55 | [diff] [blame] | 3499 | // If the autoplay disable settings feature is enabled and the autoplay |
| 3500 | // policy is set to using the unified policy then set the default autoplay |
| 3501 | // policy based on user preference. |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3502 | web_prefs->autoplay_policy = |
| 3503 | UnifiedAutoplayConfig::ShouldBlockAutoplay(profile) |
Gyuyoung Kim | f6c02a26 | 2020-10-13 01:36:13 | [diff] [blame] | 3504 | ? blink::mojom::AutoplayPolicy::kDocumentUserActivationRequired |
| 3505 | : blink::mojom::AutoplayPolicy::kNoUserGestureRequired; |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3506 | } |
| 3507 | #endif // !defined(OS_ANDROID) |
| 3508 | |
Prashant Nevase | 788dcee | 2020-10-30 19:00:17 | [diff] [blame] | 3509 | switch (GetWebTheme()->GetPreferredContrast()) { |
Alison Maher | 3b11e94 | 2020-10-27 17:17:50 | [diff] [blame] | 3510 | case ui::NativeTheme::PreferredContrast::kNoPreference: |
| 3511 | web_prefs->preferred_contrast = |
| 3512 | blink::mojom::PreferredContrast::kNoPreference; |
| 3513 | break; |
| 3514 | case ui::NativeTheme::PreferredContrast::kMore: |
| 3515 | web_prefs->preferred_contrast = blink::mojom::PreferredContrast::kMore; |
| 3516 | break; |
| 3517 | case ui::NativeTheme::PreferredContrast::kLess: |
| 3518 | web_prefs->preferred_contrast = blink::mojom::PreferredContrast::kLess; |
| 3519 | break; |
| 3520 | } |
| 3521 | |
Aaron Colwell | bd02c6c | 2021-01-16 00:34:29 | [diff] [blame] | 3522 | UpdatePreferredColorScheme( |
| 3523 | web_prefs, web_contents->GetMainFrame()->GetSiteInstance()->GetSiteURL(), |
| 3524 | web_contents, GetWebTheme()); |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3525 | |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 3526 | web_prefs->translate_service_available = TranslateService::IsAvailable(prefs); |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 3527 | |
Abigail Klein | a81f2e2 | 2020-05-04 14:32:41 | [diff] [blame] | 3528 | base::Optional<ui::CaptionStyle> style = |
| 3529 | captions::GetCaptionStyleFromUserSettings(prefs, |
| 3530 | true /* record_metrics */); |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3531 | if (style) { |
| 3532 | web_prefs->text_track_background_color = style->background_color; |
| 3533 | web_prefs->text_track_text_color = style->text_color; |
| 3534 | web_prefs->text_track_text_size = style->text_size; |
| 3535 | web_prefs->text_track_text_shadow = style->text_shadow; |
| 3536 | web_prefs->text_track_font_family = style->font_family; |
| 3537 | web_prefs->text_track_font_variant = style->font_variant; |
Abigail Klein | 74de85bd | 2019-07-11 19:11:56 | [diff] [blame] | 3538 | web_prefs->text_track_window_color = style->window_color; |
| 3539 | web_prefs->text_track_window_padding = style->window_padding; |
| 3540 | web_prefs->text_track_window_radius = style->window_radius; |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3541 | } |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3542 | |
Piotr Bialecki | 3fde5fa | 2021-01-23 01:08:03 | [diff] [blame] | 3543 | #if defined(OS_ANDROID) |
| 3544 | // If the pref is not set, the default value (true) will be used: |
| 3545 | web_prefs->webxr_immersive_ar_allowed = |
| 3546 | prefs->GetBoolean(prefs::kWebXRImmersiveArEnabled); |
| 3547 | #endif |
| 3548 | |
| 3549 | for (ChromeContentBrowserClientParts* parts : extra_parts_) |
| 3550 | parts->OverrideWebkitPrefs(web_contents, web_prefs); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 3551 | } |
| 3552 | |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 3553 | bool ChromeContentBrowserClient::OverrideWebPreferencesAfterNavigation( |
| 3554 | WebContents* web_contents, |
| 3555 | WebPreferences* prefs) { |
Prashant Nevase | 788dcee | 2020-10-30 19:00:17 | [diff] [blame] | 3556 | return UpdatePreferredColorScheme(prefs, web_contents->GetLastCommittedURL(), |
| 3557 | web_contents, GetWebTheme()); |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 3558 | } |
| 3559 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3560 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 3561 | BrowserURLHandler* handler) { |
Nicolas Ouellet-Payeur | 5e6d210 | 2020-08-21 16:28:41 | [diff] [blame] | 3562 | // The group policy NTP URL handler must be registered before the other NTP |
| 3563 | // URL handlers below. Also register it before the "parts" handlers, so the |
| 3564 | // NTP policy takes precedence over extensions that override the NTP. |
| 3565 | handler->AddHandlerPair(&HandleNewTabPageLocationOverride, |
| 3566 | BrowserURLHandler::null_handler()); |
| 3567 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3568 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 3569 | extra_parts_[i]->BrowserURLHandlerCreated(handler); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3570 | |
Lukasz Anforowicz | 7b07879 | 2020-10-20 17:04:31 | [diff] [blame] | 3571 | // Handler to rewrite chrome://about and chrome://sync URLs. |
| 3572 | handler->AddHandlerPair(&HandleChromeAboutAndChromeSyncRewrite, |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3573 | BrowserURLHandler::null_handler()); |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3574 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 3575 | #if defined(OS_ANDROID) |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3576 | // Handler to rewrite chrome://newtab on Android. |
ianwen | 465e17b | 2015-01-20 18:32:35 | [diff] [blame] | 3577 | handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL, |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3578 | BrowserURLHandler::null_handler()); |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 3579 | #else // defined(OS_ANDROID) |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3580 | // Handler to rewrite chrome://newtab for InstantExtended. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 3581 | handler->AddHandlerPair(&search::HandleNewTabURLRewrite, |
| 3582 | &search::HandleNewTabURLReverseRewrite); |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 3583 | #endif // defined(OS_ANDROID) |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3584 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3585 | // chrome: & friends. |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 3586 | handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI, |
| 3587 | &ChromeContentBrowserClient::HandleWebUIReverse); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3588 | } |
| 3589 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3590 | base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 3591 | return DownloadPrefs::GetDefaultDownloadDirectory(); |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 3592 | } |
| 3593 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 3594 | std::string ChromeContentBrowserClient::GetDefaultDownloadName() { |
| 3595 | return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 3596 | } |
| 3597 | |
Dominik Röttsches | 4734783 | 2019-03-12 17:45:01 | [diff] [blame] | 3598 | base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() { |
| 3599 | base::FilePath user_data_dir; |
| 3600 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 3601 | DCHECK(!user_data_dir.empty()); |
| 3602 | return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache")); |
| 3603 | } |
| 3604 | |
jmadill | 57b52d4 | 2015-08-21 18:16:13 | [diff] [blame] | 3605 | base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() { |
| 3606 | base::FilePath user_data_dir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 3607 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
jmadill | 57b52d4 | 2015-08-21 18:16:13 | [diff] [blame] | 3608 | DCHECK(!user_data_dir.empty()); |
| 3609 | return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache")); |
| 3610 | } |
| 3611 | |
Khushal | 7ca0b78 | 2018-07-20 05:53:27 | [diff] [blame] | 3612 | base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() { |
| 3613 | base::FilePath user_data_dir; |
| 3614 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 3615 | DCHECK(!user_data_dir.empty()); |
| 3616 | return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache")); |
| 3617 | } |
| 3618 | |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 3619 | void ChromeContentBrowserClient::DidCreatePpapiPlugin( |
| 3620 | content::BrowserPpapiHost* browser_host) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3621 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 3622 | ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host); |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 3623 | #endif |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 3624 | } |
| 3625 | |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3626 | content::BrowserPpapiHost* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3627 | ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) { |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 3628 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 3629 | content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3630 | while (!iter.Done()) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3631 | nacl::NaClProcessHost* host = |
| 3632 | static_cast<nacl::NaClProcessHost*>(iter.GetDelegate()); |
| 3633 | if (host->process() && host->process()->GetData().id == plugin_process_id) { |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3634 | // Found the plugin. |
| 3635 | return host->browser_ppapi_host(); |
| 3636 | } |
| 3637 | ++iter; |
| 3638 | } |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 3639 | #endif |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3640 | return nullptr; |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3641 | } |
| 3642 | |
[email protected] | 38cd8f7f | 2012-06-15 22:06:07 | [diff] [blame] | 3643 | bool ChromeContentBrowserClient::AllowPepperSocketAPI( |
[email protected] | 157cc90 | 2012-11-02 06:31:58 | [diff] [blame] | 3644 | content::BrowserContext* browser_context, |
| 3645 | const GURL& url, |
[email protected] | dda5482 | 2013-06-15 01:26:39 | [diff] [blame] | 3646 | bool private_api, |
[email protected] | 8b92ed18 | 2013-09-21 04:47:12 | [diff] [blame] | 3647 | const content::SocketPermissionRequest* params) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3648 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 3649 | return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI( |
Lei Zhang | 19736cde | 2020-02-07 18:51:19 | [diff] [blame] | 3650 | browser_context, url, private_api, params); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 3651 | #else |
[email protected] | a658d45 | 2012-03-02 12:45:29 | [diff] [blame] | 3652 | return false; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 3653 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 3654 | } |
| 3655 | |
adrian.belgun | d54465ba | 2016-05-18 10:03:58 | [diff] [blame] | 3656 | bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed( |
| 3657 | content::BrowserContext* browser_context, |
| 3658 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3659 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
adrian.belgun | d54465ba | 2016-05-18 10:03:58 | [diff] [blame] | 3660 | return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed( |
| 3661 | browser_context, url); |
| 3662 | #else |
| 3663 | return false; |
| 3664 | #endif |
| 3665 | } |
| 3666 | |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 3667 | std::unique_ptr<content::VpnServiceProxy> |
| 3668 | ChromeContentBrowserClient::GetVpnServiceProxy( |
| 3669 | content::BrowserContext* browser_context) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3670 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 3671 | return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy( |
| 3672 | browser_context); |
| 3673 | #else |
| 3674 | return nullptr; |
| 3675 | #endif |
| 3676 | } |
| 3677 | |
Brett Wilson | 804e83c | 2017-08-18 22:57:33 | [diff] [blame] | 3678 | std::unique_ptr<ui::SelectFilePolicy> |
| 3679 | ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) { |
| 3680 | return std::make_unique<ChromeSelectFilePolicy>(web_contents); |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 3681 | } |
| 3682 | |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 3683 | void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 3684 | std::vector<std::string>* additional_allowed_schemes) { |
| 3685 | ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 3686 | additional_allowed_schemes); |
[email protected] | b3690f7 | 2014-02-17 00:32:48 | [diff] [blame] | 3687 | additional_allowed_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 3688 | additional_allowed_schemes->push_back(content::kChromeUIScheme); |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3689 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
| 3690 | extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem( |
| 3691 | additional_allowed_schemes); |
| 3692 | } |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 3693 | } |
| 3694 | |
Ayu Ishii | fbb1fad | 2020-06-22 20:15:07 | [diff] [blame] | 3695 | void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckAllowlist( |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 3696 | std::set<std::string>* schemes) { |
Ayu Ishii | fbb1fad | 2020-06-22 20:15:07 | [diff] [blame] | 3697 | *schemes = secure_origin_allowlist::GetSchemesBypassingSecureContextCheck(); |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 3698 | } |
| 3699 | |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 3700 | void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3701 | std::vector<storage::URLRequestAutoMountHandler>* handlers) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3702 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 3703 | extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers); |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 3704 | } |
| 3705 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 3706 | void ChromeContentBrowserClient::GetAdditionalFileSystemBackends( |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 3707 | content::BrowserContext* browser_context, |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 3708 | const base::FilePath& storage_partition_path, |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3709 | std::vector<std::unique_ptr<storage::FileSystemBackend>>* |
| 3710 | additional_backends) { |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 3711 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3712 | storage::ExternalMountPoints* external_mount_points = |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 3713 | content::BrowserContext::GetMountPoints(browser_context); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3714 | DCHECK(external_mount_points); |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3715 | auto backend = std::make_unique<chromeos::FileSystemBackend>( |
David Black | 8f8c1eb | 2020-12-09 04:02:23 | [diff] [blame] | 3716 | Profile::FromBrowserContext(browser_context), |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3717 | std::make_unique<chromeos::file_system_provider::BackendDelegate>(), |
| 3718 | std::make_unique<chromeos::MTPFileSystemBackendDelegate>( |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 3719 | storage_partition_path), |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3720 | std::make_unique<arc::ArcContentFileSystemBackendDelegate>(), |
| 3721 | std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(), |
Sam McNally | 47f2eac | 2018-08-28 06:45:05 | [diff] [blame] | 3722 | std::make_unique<drive::DriveFsFileSystemBackendDelegate>( |
| 3723 | Profile::FromBrowserContext(browser_context)), |
Anand K. Mistry | 7694c36 | 2020-03-17 23:33:34 | [diff] [blame] | 3724 | std::make_unique<chromeos::smb_client::SmbFsFileSystemBackendDelegate>( |
| 3725 | Profile::FromBrowserContext(browser_context)), |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 3726 | external_mount_points, storage::ExternalMountPoints::GetSystemInstance()); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 3727 | backend->AddSystemMountPoints(); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3728 | DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal)); |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3729 | additional_backends->push_back(std::move(backend)); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3730 | #endif |
[email protected] | 445b7db | 2013-08-02 04:58:27 | [diff] [blame] | 3731 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3732 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
| 3733 | extra_parts_[i]->GetAdditionalFileSystemBackends( |
| 3734 | browser_context, storage_partition_path, additional_backends); |
| 3735 | } |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 3736 | } |
| 3737 | |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 3738 | #if defined(OS_POSIX) && !defined(OS_MAC) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 3739 | void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 3740 | const base::CommandLine& command_line, |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3741 | int child_process_id, |
brettw | 3c98c7d3 | 2017-07-25 01:44:20 | [diff] [blame] | 3742 | PosixFileDescriptorInfo* mappings) { |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3743 | #if defined(OS_ANDROID) |
| 3744 | base::MemoryMappedFile::Region region; |
| 3745 | int fd = ui::GetMainAndroidPackFd(®ion); |
| 3746 | mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region); |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 3747 | |
Samuel Huang | 31eadf08 | 2019-08-28 19:50:43 | [diff] [blame] | 3748 | // For Android: Native resources for DFMs should only be used by the browser |
| 3749 | // process. Their file descriptors and memory mapped file regions are not |
| 3750 | // passed to child processes. |
| 3751 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3752 | fd = ui::GetCommonResourcesPackFd(®ion); |
| 3753 | mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region); |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 3754 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3755 | fd = ui::GetLocalePackFd(®ion); |
| 3756 | mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region); |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3757 | |
zpeng | 368afac8 | 2017-07-17 18:47:45 | [diff] [blame] | 3758 | // Optional secondary locale .pak file. |
| 3759 | fd = ui::GetSecondaryLocalePackFd(®ion); |
| 3760 | if (fd != -1) { |
| 3761 | mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region); |
| 3762 | } |
| 3763 | |
[email protected] | 09560f7f | 2014-06-10 18:40:28 | [diff] [blame] | 3764 | base::FilePath app_data_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 3765 | base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path); |
[email protected] | 09560f7f | 2014-06-10 18:40:28 | [diff] [blame] | 3766 | DCHECK(!app_data_path.empty()); |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 3767 | #endif // defined(OS_ANDROID) |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3768 | int crash_signal_fd = GetCrashSignalFD(command_line); |
| 3769 | if (crash_signal_fd >= 0) { |
Ken Rockot | 69fbb96 | 2020-09-21 22:22:03 | [diff] [blame] | 3770 | mappings->Share(kCrashDumpSignal, crash_signal_fd); |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3771 | } |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3772 | } |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 3773 | #endif // defined(OS_POSIX) && !defined(OS_MAC) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 3774 | |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 3775 | #if defined(OS_WIN) |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3776 | base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType( |
Robert Sesek | 7d0b49b | 2020-07-08 18:31:27 | [diff] [blame] | 3777 | sandbox::policy::SandboxType sandbox_type) { |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3778 | // TODO(wfh): Add support for more process types here. crbug.com/499523 |
| 3779 | switch (sandbox_type) { |
Robert Sesek | 7d0b49b | 2020-07-08 18:31:27 | [diff] [blame] | 3780 | case sandbox::policy::SandboxType::kRenderer: |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 3781 | return base::string16(install_static::GetSandboxSidPrefix()) + |
| 3782 | L"129201922"; |
Robert Sesek | 7d0b49b | 2020-07-08 18:31:27 | [diff] [blame] | 3783 | case sandbox::policy::SandboxType::kUtility: |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3784 | return base::string16(); |
Robert Sesek | 7d0b49b | 2020-07-08 18:31:27 | [diff] [blame] | 3785 | case sandbox::policy::SandboxType::kGpu: |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3786 | return base::string16(); |
Robert Sesek | 7d0b49b | 2020-07-08 18:31:27 | [diff] [blame] | 3787 | case sandbox::policy::SandboxType::kPpapi: |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 3788 | return base::string16(install_static::GetSandboxSidPrefix()) + |
| 3789 | L"129201925"; |
Robert Sesek | 7d0b49b | 2020-07-08 18:31:27 | [diff] [blame] | 3790 | case sandbox::policy::SandboxType::kNoSandbox: |
| 3791 | case sandbox::policy::SandboxType::kNoSandboxAndElevatedPrivileges: |
| 3792 | case sandbox::policy::SandboxType::kXrCompositing: |
| 3793 | case sandbox::policy::SandboxType::kNetwork: |
| 3794 | case sandbox::policy::SandboxType::kCdm: |
| 3795 | case sandbox::policy::SandboxType::kPrintCompositor: |
| 3796 | case sandbox::policy::SandboxType::kAudio: |
| 3797 | case sandbox::policy::SandboxType::kSpeechRecognition: |
| 3798 | case sandbox::policy::SandboxType::kProxyResolver: |
| 3799 | case sandbox::policy::SandboxType::kPdfConversion: |
| 3800 | case sandbox::policy::SandboxType::kSharingService: |
| 3801 | case sandbox::policy::SandboxType::kVideoCapture: |
| 3802 | case sandbox::policy::SandboxType::kIconReader: |
Frank Li | 49bb691 | 2020-09-30 18:05:52 | [diff] [blame] | 3803 | case sandbox::policy::SandboxType::kMediaFoundationCdm: |
Alex Gough | 9ab468a6c3 | 2019-12-10 19:10:22 | [diff] [blame] | 3804 | // Should never reach here. |
| 3805 | CHECK(0); |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3806 | return base::string16(); |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3807 | } |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3808 | } |
| 3809 | |
Will Harris | aa8939b | 2021-01-26 21:54:39 | [diff] [blame] | 3810 | // Note: Only use sparingly to add Chrome specific sandbox functionality here. |
| 3811 | // Other code should reside in the content layer. Changes to this function |
| 3812 | // should be reviewed by the security team. |
| 3813 | bool ChromeContentBrowserClient::PreSpawnChild( |
| 3814 | sandbox::TargetPolicy* policy, |
| 3815 | sandbox::policy::SandboxType sandbox_type, |
| 3816 | ChildSpawnFlags flags) { |
| 3817 | switch (sandbox_type) { |
| 3818 | case sandbox::policy::SandboxType::kRenderer: { |
| 3819 | // Does not work under component build because all the component DLLs |
| 3820 | // would need to be manually added and maintained. Does not work under |
| 3821 | // ASAN build because ASAN has not yet fully initialized its |
| 3822 | // instrumentation by the time the CIG intercepts run. |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 3823 | #if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | aa8939b | 2021-01-26 21:54:39 | [diff] [blame] | 3824 | if ((flags & ChildSpawnFlags::RENDERER_CODE_INTEGRITY) == 0) |
| 3825 | return true; |
| 3826 | if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity)) |
| 3827 | return true; |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3828 | |
Will Harris | aa8939b | 2021-01-26 21:54:39 | [diff] [blame] | 3829 | // Only enable signing mitigation if launching from chrome.exe. |
| 3830 | base::FilePath exe_path; |
| 3831 | if (!base::PathService::Get(base::FILE_EXE, &exe_path)) |
| 3832 | return true; |
| 3833 | if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value()) |
| 3834 | return true; |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3835 | |
Will Harris | aa8939b | 2021-01-26 21:54:39 | [diff] [blame] | 3836 | sandbox::MitigationFlags mitigations = policy->GetProcessMitigations(); |
| 3837 | mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS; |
| 3838 | sandbox::ResultCode result = policy->SetProcessMitigations(mitigations); |
| 3839 | if (result != sandbox::SBOX_ALL_OK) |
| 3840 | return false; |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3841 | |
Will Harris | aa8939b | 2021-01-26 21:54:39 | [diff] [blame] | 3842 | // Allow loading Chrome's DLLs. |
| 3843 | for (const auto* dll : {chrome::kBrowserResourcesDll, chrome::kElfDll}) { |
| 3844 | result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY, |
| 3845 | sandbox::TargetPolicy::SIGNED_ALLOW_LOAD, |
| 3846 | GetModulePath(dll).value().c_str()); |
| 3847 | if (result != sandbox::SBOX_ALL_OK) |
| 3848 | return false; |
| 3849 | } |
| 3850 | return true; |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 3851 | #endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | aa8939b | 2021-01-26 21:54:39 | [diff] [blame] | 3852 | return true; |
| 3853 | } |
| 3854 | case sandbox::policy::SandboxType::kNetwork: |
| 3855 | case sandbox::policy::SandboxType::kUtility: |
| 3856 | case sandbox::policy::SandboxType::kGpu: |
| 3857 | case sandbox::policy::SandboxType::kPpapi: |
| 3858 | case sandbox::policy::SandboxType::kNoSandbox: |
| 3859 | case sandbox::policy::SandboxType::kNoSandboxAndElevatedPrivileges: |
| 3860 | case sandbox::policy::SandboxType::kXrCompositing: |
| 3861 | case sandbox::policy::SandboxType::kCdm: |
| 3862 | case sandbox::policy::SandboxType::kPrintCompositor: |
| 3863 | case sandbox::policy::SandboxType::kAudio: |
| 3864 | case sandbox::policy::SandboxType::kSpeechRecognition: |
| 3865 | case sandbox::policy::SandboxType::kProxyResolver: |
| 3866 | case sandbox::policy::SandboxType::kPdfConversion: |
| 3867 | case sandbox::policy::SandboxType::kSharingService: |
| 3868 | case sandbox::policy::SandboxType::kVideoCapture: |
| 3869 | case sandbox::policy::SandboxType::kIconReader: |
| 3870 | case sandbox::policy::SandboxType::kMediaFoundationCdm: |
| 3871 | return true; |
| 3872 | } |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 3873 | } |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3874 | |
| 3875 | bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() { |
| 3876 | PrefService* local_state = g_browser_process->local_state(); |
| 3877 | if (local_state && |
| 3878 | local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) && |
| 3879 | !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled)) |
| 3880 | return false; |
| 3881 | return true; |
| 3882 | } |
| 3883 | |
wfh | c91e967 | 2016-01-27 00:14:20 | [diff] [blame] | 3884 | #endif // defined(OS_WIN) |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 3885 | |
Lingqi Chi | 775e6075 | 2020-12-14 06:31:16 | [diff] [blame] | 3886 | void ChromeContentBrowserClient::RegisterMojoBinderPoliciesForPrerendering( |
| 3887 | content::MojoBinderPolicyMap& policy_map) { |
| 3888 | // Changes to `policy_map` should be made in |
| 3889 | // RegisterChromeMojoBinderPoliciesForPrerendering() which requires security |
| 3890 | // review. |
| 3891 | RegisterChromeMojoBinderPoliciesForPrerendering(policy_map); |
| 3892 | } |
| 3893 | |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 3894 | void ChromeContentBrowserClient::OpenURL( |
Matt Falkenhagen | 18c5c5d | 2018-11-26 02:55:37 | [diff] [blame] | 3895 | content::SiteInstance* site_instance, |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 3896 | const content::OpenURLParams& params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 3897 | base::OnceCallback<void(content::WebContents*)> callback) { |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3898 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Matt Falkenhagen | 18c5c5d | 2018-11-26 02:55:37 | [diff] [blame] | 3899 | |
| 3900 | content::BrowserContext* browser_context = site_instance->GetBrowserContext(); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3901 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 3902 | #if defined(OS_ANDROID) |
pkotwicz | aa289f0 | 2016-07-05 22:26:22 | [diff] [blame] | 3903 | ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 3904 | std::move(callback)); |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 3905 | #else |
cm.sanchi | 2522bc9 | 2017-12-04 08:04:13 | [diff] [blame] | 3906 | NavigateParams nav_params(Profile::FromBrowserContext(browser_context), |
| 3907 | params.url, params.transition); |
| 3908 | nav_params.FillNavigateParamsFromOpenURLParams(params); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3909 | |
| 3910 | Navigate(&nav_params); |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 3911 | std::move(callback).Run(nav_params.navigated_or_inserted_contents); |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 3912 | #endif |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3913 | } |
| 3914 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 3915 | content::ControllerPresentationServiceDelegate* |
| 3916 | ChromeContentBrowserClient::GetControllerPresentationServiceDelegate( |
| 3917 | content::WebContents* web_contents) { |
mfoltz | 99bd44c | 2016-03-18 20:36:46 | [diff] [blame] | 3918 | if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) { |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 3919 | return media_router::PresentationServiceDelegateImpl:: |
| 3920 | GetOrCreateForWebContents(web_contents); |
| 3921 | } |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 3922 | return nullptr; |
| 3923 | } |
| 3924 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 3925 | content::ReceiverPresentationServiceDelegate* |
| 3926 | ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate( |
| 3927 | content::WebContents* web_contents) { |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 3928 | if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) { |
| 3929 | // ReceiverPresentationServiceDelegateImpl exists only for WebContents |
| 3930 | // created for offscreen presentations. The WebContents must belong to |
| 3931 | // an incognito profile. |
| 3932 | if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl:: |
| 3933 | FromWebContents(web_contents)) { |
| 3934 | DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord()); |
| 3935 | return impl; |
| 3936 | } |
| 3937 | } |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 3938 | return nullptr; |
| 3939 | } |
| 3940 | |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3941 | std::vector<std::unique_ptr<content::NavigationThrottle>> |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3942 | ChromeContentBrowserClient::CreateThrottlesForNavigation( |
| 3943 | content::NavigationHandle* handle) { |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3944 | std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 3945 | |
bmcquade | b455655 | 2017-03-24 22:24:37 | [diff] [blame] | 3946 | // MetricsNavigationThrottle requires that it runs before NavigationThrottles |
| 3947 | // that may delay or cancel navigations, so only NavigationThrottles that |
| 3948 | // don't delay or cancel navigations (e.g. throttles that are only observing |
| 3949 | // callbacks without affecting navigation behavior) should be added before |
| 3950 | // MetricsNavigationThrottle. |
| 3951 | if (handle->IsInMainFrame()) { |
| 3952 | throttles.push_back( |
| 3953 | page_load_metrics::MetricsNavigationThrottle::Create(handle)); |
| 3954 | } |
| 3955 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 3956 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
yilkal | 240b4f2 | 2019-11-27 19:09:06 | [diff] [blame] | 3957 | MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 3958 | chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 3959 | &throttles); |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 3960 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
yilkal | 240b4f2 | 2019-11-27 19:09:06 | [diff] [blame] | 3961 | |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 3962 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3963 | MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 3964 | SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 3965 | &throttles); |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 3966 | #endif |
| 3967 | |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3968 | #if defined(OS_ANDROID) |
| 3969 | // TODO(davidben): This is insufficient to integrate with prerender properly. |
| 3970 | // https://crbug.com/370595 |
Hiroki Nakagawa | 7230e341 | 2021-01-22 10:08:29 | [diff] [blame] | 3971 | prerender::NoStatePrefetchContents* no_state_prefetch_contents = |
| 3972 | prerender::ChromeNoStatePrefetchContentsDelegate::FromWebContents( |
Mugdha Lakhani | 2c6b23af | 2020-07-31 14:55:57 | [diff] [blame] | 3973 | handle->GetWebContents()); |
Hiroki Nakagawa | 7230e341 | 2021-01-22 10:08:29 | [diff] [blame] | 3974 | if (!no_state_prefetch_contents && handle->IsInMainFrame()) { |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3975 | throttles.push_back( |
| 3976 | navigation_interception::InterceptNavigationDelegate::CreateThrottleFor( |
Charlie Harrison | 3286ab7 | 2019-02-13 20:13:30 | [diff] [blame] | 3977 | handle, navigation_interception::SynchronyMode::kAsync)); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3978 | } |
Min Qin | 0ab0e16 | 2017-11-14 21:57:19 | [diff] [blame] | 3979 | throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle)); |
Samuel Huang | 3a1ce1c3 | 2019-10-16 17:34:04 | [diff] [blame] | 3980 | |
| 3981 | #if BUILDFLAG(DFMIFY_DEV_UI) |
| 3982 | // If the DevUI DFM is already installed, then this is a no-op, except for the |
| 3983 | // side effect of ensuring that the DevUI DFM is loaded. |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 3984 | MaybeAddThrottle(dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle), |
| 3985 | &throttles); |
Samuel Huang | 3a1ce1c3 | 2019-10-16 17:34:04 | [diff] [blame] | 3986 | #endif // BUILDFLAG(DFMIFY_DEV_UI) |
| 3987 | |
Giovanni Ortuño Urquidi | 7ae7fb0 | 2017-10-09 01:49:57 | [diff] [blame] | 3988 | #elif BUILDFLAG(ENABLE_EXTENSIONS) |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3989 | if (handle->IsInMainFrame()) { |
| 3990 | // Redirect some navigations to apps that have registered matching URL |
| 3991 | // handlers ('url_handlers' in the manifest). |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 3992 | MaybeAddThrottle( |
| 3993 | PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle), |
| 3994 | &throttles); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3995 | } |
| 3996 | #endif |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 3997 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 3998 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 3999 | // Check if we need to add merge session throttle. This throttle will postpone |
| 4000 | // loading of main frames. |
| 4001 | if (handle->IsInMainFrame()) { |
| 4002 | // Add interstitial page while merge session process (cookie reconstruction |
| 4003 | // from OAuth2 refresh token in ChromeOS login) is still in progress while |
| 4004 | // we are attempting to load a google property. |
csharrison | dd06bab | 2016-07-22 14:15:02 | [diff] [blame] | 4005 | if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() && |
| 4006 | !merge_session_throttling_utils::AreAllSessionMergedAlready() && |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4007 | handle->GetURL().SchemeIsHTTPOrHTTPS()) { |
| 4008 | throttles.push_back(MergeSessionNavigationThrottle::Create(handle)); |
| 4009 | } |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4010 | } |
| 4011 | #endif |
djacobo | 21e56e0 | 2016-07-02 01:14:31 | [diff] [blame] | 4012 | |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4013 | #if !defined(OS_ANDROID) |
Maggie Cai | c08b7d4 | 2020-05-05 03:51:10 | [diff] [blame] | 4014 | auto url_to_apps_throttle = |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 4015 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Maggie Cai | c08b7d4 | 2020-05-05 03:51:10 | [diff] [blame] | 4016 | base::FeatureList::IsEnabled(features::kAppServiceIntentHandling) |
| 4017 | ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle) |
| 4018 | : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle); |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4019 | #else |
Maggie Cai | c08b7d4 | 2020-05-05 03:51:10 | [diff] [blame] | 4020 | apps::AppsNavigationThrottle::MaybeCreate(handle); |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4021 | #endif |
Maggie Cai | c08b7d4 | 2020-05-05 03:51:10 | [diff] [blame] | 4022 | if (url_to_apps_throttle) |
| 4023 | throttles.push_back(std::move(url_to_apps_throttle)); |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4024 | #endif |
| 4025 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 4026 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 4027 | throttles.push_back( |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4028 | std::make_unique<extensions::ExtensionNavigationThrottle>(handle)); |
Clark DuVall | 2cf99249e | 2018-09-19 19:11:51 | [diff] [blame] | 4029 | |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4030 | MaybeAddThrottle(extensions::ExtensionsBrowserClient::Get() |
| 4031 | ->GetUserScriptListener() |
| 4032 | ->CreateNavigationThrottle(handle), |
| 4033 | &throttles); |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 4034 | #endif |
| 4035 | |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 4036 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 4037 | MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4038 | SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle), |
| 4039 | &throttles); |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 4040 | #endif |
| 4041 | |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 4042 | content::WebContents* web_contents = handle->GetWebContents(); |
Colin Blundell | 0ec5d64 | 2020-10-06 17:29:52 | [diff] [blame] | 4043 | if (auto* throttle_manager = |
| 4044 | subresource_filter::ContentSubresourceFilterThrottleManager:: |
| 4045 | FromWebContents(web_contents)) { |
| 4046 | throttle_manager->MaybeAppendNavigationThrottles(handle, &throttles); |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 4047 | } |
| 4048 | |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 4049 | #if !defined(OS_ANDROID) |
| 4050 | // BackgroundTabNavigationThrottle is used by TabManager, which is only |
| 4051 | // enabled on non-Android platforms. |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4052 | MaybeAddThrottle(resource_coordinator::BackgroundTabNavigationThrottle:: |
| 4053 | MaybeCreateThrottleFor(handle), |
| 4054 | &throttles); |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 4055 | #endif |
| 4056 | |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 4057 | #if BUILDFLAG(SAFE_BROWSING_AVAILABLE) |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4058 | MaybeAddThrottle(safe_browsing::MaybeCreateNavigationThrottle(handle), |
| 4059 | &throttles); |
Jialiu Lin | bdbb81d | 2017-10-11 21:29:09 | [diff] [blame] | 4060 | #endif |
| 4061 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 4062 | MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4063 | LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle), |
| 4064 | &throttles); |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 4065 | |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4066 | MaybeAddThrottle(PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 4067 | &throttles); |
Amber Won | 6b5edc75 | 2017-08-17 19:23:54 | [diff] [blame] | 4068 | |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4069 | MaybeAddThrottle(TabUnderNavigationThrottle::MaybeCreate(handle), &throttles); |
Charles Harrison | 6dd11d28 | 2017-10-03 06:14:51 | [diff] [blame] | 4070 | |
Jonathan Mengedoht | 42a19bb | 2020-07-28 14:10:16 | [diff] [blame] | 4071 | MaybeAddThrottle( |
| 4072 | WellKnownChangePasswordNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 4073 | &throttles); |
| 4074 | |
Yann Dago | 3256b87 | 2021-01-13 18:48:03 | [diff] [blame] | 4075 | policy::PolicyService* policy_service = nullptr; |
| 4076 | Profile* profile = Profile::FromBrowserContext( |
| 4077 | handle->GetWebContents()->GetBrowserContext()); |
| 4078 | if (profile && profile->GetProfilePolicyConnector()) |
| 4079 | policy_service = profile->GetProfilePolicyConnector()->policy_service(); |
| 4080 | |
Aaron Colwell | f94fd97a | 2020-07-21 19:37:08 | [diff] [blame] | 4081 | throttles.push_back(std::make_unique<PolicyBlocklistNavigationThrottle>( |
Yann Dago | 3256b87 | 2021-01-13 18:48:03 | [diff] [blame] | 4082 | handle, handle->GetWebContents()->GetBrowserContext(), policy_service)); |
Doug Turner | 9dcaf596 | 2017-12-21 04:38:53 | [diff] [blame] | 4083 | |
Colin Blundell | eaa7377bf | 2020-01-22 08:49:10 | [diff] [blame] | 4084 | // Before setting up SSL error detection, configure SSLErrorHandler to invoke |
| 4085 | // the relevant extension API whenever an SSL interstitial is shown. |
| 4086 | SSLErrorHandler::SetClientCallbackOnInterstitialsShown( |
| 4087 | base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent)); |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4088 | throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>( |
| 4089 | handle, |
| 4090 | std::make_unique<CertificateReportingServiceCertReporter>(web_contents), |
Mustafa Emre Acer | 06028d79 | 2021-01-05 19:48:51 | [diff] [blame] | 4091 | base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp), |
| 4092 | base::BindOnce( |
| 4093 | &TypedNavigationUpgradeThrottle:: |
| 4094 | ShouldIgnoreInterstitialBecauseNavigationDefaultedToHttps))); |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 4095 | |
Emily Stark | d6896cd3 | 2019-08-21 04:55:54 | [diff] [blame] | 4096 | throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle)); |
| 4097 | |
Mustafa Emre Acer | 06028d79 | 2021-01-05 19:48:51 | [diff] [blame] | 4098 | if (base::FeatureList::IsEnabled(omnibox::kDefaultTypedNavigationsToHttps)) { |
| 4099 | MaybeAddThrottle( |
| 4100 | TypedNavigationUpgradeThrottle::MaybeCreateThrottleFor(handle), |
| 4101 | &throttles); |
| 4102 | } |
| 4103 | |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 4104 | #if !defined(OS_ANDROID) |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4105 | MaybeAddThrottle(DevToolsWindow::MaybeCreateNavigationThrottle(handle), |
| 4106 | &throttles); |
| 4107 | |
| 4108 | MaybeAddThrottle(NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 4109 | &throttles); |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 4110 | #endif |
| 4111 | |
Carlos IL | 800e350 | 2020-04-30 16:35:59 | [diff] [blame] | 4112 | throttles.push_back( |
| 4113 | std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(handle)); |
Robert Ogden | afd250b | 2018-07-25 22:21:03 | [diff] [blame] | 4114 | |
Mustafa Emre Acer | 97be475 | 2020-05-13 01:24:43 | [diff] [blame] | 4115 | if (base::FeatureList::IsEnabled(safe_browsing::kDelayedWarnings)) { |
| 4116 | throttles.push_back( |
| 4117 | std::make_unique<safe_browsing::DelayedWarningNavigationThrottle>( |
| 4118 | handle)); |
| 4119 | } |
| 4120 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 4121 | // TODO(crbug.com/1052397): Revisit the macro expression once build flag switch |
| 4122 | // of lacros-chrome is complete. |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 4123 | #if defined(OS_WIN) || defined(OS_MAC) || \ |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 4124 | (defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)) |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4125 | MaybeAddThrottle(browser_switcher::BrowserSwitcherNavigationThrottle:: |
| 4126 | MaybeCreateThrottleFor(handle), |
| 4127 | &throttles); |
Nicolas Ouellet-Payeur | 995e777 | 2018-09-13 16:02:13 | [diff] [blame] | 4128 | #endif |
| 4129 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 4130 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Anatoliy Potapchuk | 762c40d | 2020-05-11 15:10:37 | [diff] [blame] | 4131 | MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4132 | chromeos::KioskSettingsNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 4133 | &throttles); |
Anatoliy Potapchuk | 762c40d | 2020-05-11 15:10:37 | [diff] [blame] | 4134 | #endif |
| 4135 | |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4136 | auto* performance_manager_registry = |
| 4137 | performance_manager::PerformanceManagerRegistry::GetInstance(); |
| 4138 | if (performance_manager_registry) { |
| 4139 | MaybeAddThrottles( |
| 4140 | performance_manager_registry->CreateThrottlesForNavigation(handle), |
| 4141 | &throttles); |
| 4142 | } |
| 4143 | |
Carlos IL | 06e6c8c | 2020-07-28 00:25:19 | [diff] [blame] | 4144 | if (profile && profile->GetPrefs()) { |
| 4145 | MaybeAddThrottle( |
| 4146 | security_interstitials::InsecureFormNavigationThrottle:: |
| 4147 | MaybeCreateNavigationThrottle( |
| 4148 | handle, std::make_unique<ChromeSecurityBlockingPageFactory>(), |
| 4149 | profile->GetPrefs()), |
| 4150 | &throttles); |
| 4151 | } |
Carlos IL | 1a5edec | 2020-06-12 17:56:57 | [diff] [blame] | 4152 | |
Ken Rockot | 4408a0f | 2020-07-27 19:40:54 | [diff] [blame] | 4153 | if (IsErrorPageAutoReloadEnabled() && handle->IsInMainFrame()) { |
| 4154 | MaybeAddThrottle( |
| 4155 | error_page::NetErrorAutoReloader::MaybeCreateThrottleFor(handle), |
| 4156 | &throttles); |
| 4157 | } |
| 4158 | |
Liquan (Max) Gu | d648f45 | 2020-12-18 05:28:44 | [diff] [blame] | 4159 | MaybeAddThrottle( |
| 4160 | payments::PaymentHandlerNavigationThrottle::MaybeCreateThrottleFor( |
| 4161 | handle), |
| 4162 | &throttles); |
Liquan (Max) Gu | d648f45 | 2020-12-18 05:28:44 | [diff] [blame] | 4163 | |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 4164 | return throttles; |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4165 | } |
| 4166 | |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 4167 | std::unique_ptr<content::NavigationUIData> |
| 4168 | ChromeContentBrowserClient::GetNavigationUIData( |
| 4169 | content::NavigationHandle* navigation_handle) { |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4170 | return std::make_unique<ChromeNavigationUIData>(navigation_handle); |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 4171 | } |
| 4172 | |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4173 | void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps( |
| 4174 | const std::string& key_system, |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4175 | base::flat_set<media::VideoCodec>* video_codecs, |
Yuchen Liu | b33bfc1 | 2019-11-08 20:16:12 | [diff] [blame] | 4176 | base::flat_set<media::EncryptionScheme>* encryption_schemes) { |
Jeffrey Kardatzke | 61442423 | 2020-12-12 00:54:06 | [diff] [blame] | 4177 | #if (defined(OS_WIN) || BUILDFLAG(USE_CHROMEOS_PROTECTED_MEDIA)) && \ |
| 4178 | BUILDFLAG(ENABLE_LIBRARY_CDMS) && BUILDFLAG(ENABLE_WIDEVINE) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4179 | if (key_system == kWidevineKeySystem) { |
Xiaohan Wang | fd9e354 | 2020-04-14 00:39:33 | [diff] [blame] | 4180 | GetWidevineHardwareCaps(video_codecs, encryption_schemes); |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4181 | } |
| 4182 | #endif |
| 4183 | } |
| 4184 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4185 | content::DevToolsManagerDelegate* |
| 4186 | ChromeContentBrowserClient::GetDevToolsManagerDelegate() { |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 4187 | #if defined(OS_ANDROID) |
| 4188 | return new DevToolsManagerDelegateAndroid(); |
| 4189 | #else |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4190 | return new ChromeDevToolsManagerDelegate(); |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 4191 | #endif |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4192 | } |
| 4193 | |
Rayan Kanso | 411e84e | 2019-02-13 15:27:40 | [diff] [blame] | 4194 | void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration( |
| 4195 | content::BrowserContext* browser_context, |
| 4196 | int service, |
| 4197 | base::Time expiration_time) { |
| 4198 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4199 | DCHECK(profile); |
| 4200 | |
| 4201 | auto* pref_service = profile->GetPrefs(); |
| 4202 | DCHECK(pref_service); |
| 4203 | |
| 4204 | DictionaryPrefUpdate pref_update( |
| 4205 | pref_service, prefs::kDevToolsBackgroundServicesExpirationDict); |
| 4206 | base::DictionaryValue* exp_dict = pref_update.Get(); |
| 4207 | |
| 4208 | // Convert |expiration_time| to minutes since that is the most granular |
| 4209 | // option that returns an int. base::Value does not accept int64. |
| 4210 | int expiration_time_minutes = |
| 4211 | expiration_time.ToDeltaSinceWindowsEpoch().InMinutes(); |
| 4212 | exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes); |
| 4213 | } |
| 4214 | |
| 4215 | base::flat_map<int, base::Time> |
| 4216 | ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations( |
| 4217 | content::BrowserContext* browser_context) { |
| 4218 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4219 | DCHECK(profile); |
| 4220 | |
| 4221 | auto* pref_service = profile->GetPrefs(); |
| 4222 | DCHECK(pref_service); |
| 4223 | |
| 4224 | auto* expiration_dict = pref_service->GetDictionary( |
| 4225 | prefs::kDevToolsBackgroundServicesExpirationDict); |
| 4226 | DCHECK(expiration_dict); |
| 4227 | |
| 4228 | base::flat_map<int, base::Time> expiration_times; |
| 4229 | for (const auto& it : *expiration_dict) { |
| 4230 | // key. |
| 4231 | int service = 0; |
| 4232 | bool did_convert = base::StringToInt(it.first, &service); |
| 4233 | DCHECK(did_convert); |
| 4234 | |
| 4235 | // value. |
| 4236 | DCHECK(it.second->is_int()); |
| 4237 | base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt()); |
| 4238 | base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta); |
| 4239 | |
| 4240 | expiration_times[service] = expiration_time; |
| 4241 | } |
| 4242 | |
| 4243 | return expiration_times; |
| 4244 | } |
| 4245 | |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4246 | content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() { |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4247 | return new ChromeTracingDelegate(); |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4248 | } |
| 4249 | |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 4250 | bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle( |
| 4251 | content::BrowserContext* browser_context, |
| 4252 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4253 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 4254 | return ChromeContentBrowserClientPluginsPart:: |
Lei Zhang | 19736cde | 2020-02-07 18:51:19 | [diff] [blame] | 4255 | IsPluginAllowedToCallRequestOSFileHandle(browser_context, url); |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 4256 | #else |
| 4257 | return false; |
| 4258 | #endif |
| 4259 | } |
| 4260 | |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 4261 | bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs( |
| 4262 | content::BrowserContext* browser_context, |
| 4263 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4264 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 4265 | return ChromeContentBrowserClientPluginsPart:: |
Lei Zhang | 19736cde | 2020-02-07 18:51:19 | [diff] [blame] | 4266 | IsPluginAllowedToUseDevChannelAPIs(browser_context, url); |
[email protected] | 8ddc6b7c | 2013-12-12 20:42:06 | [diff] [blame] | 4267 | #else |
| 4268 | return false; |
| 4269 | #endif |
| 4270 | } |
| 4271 | |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4272 | void ChromeContentBrowserClient::OverridePageVisibilityState( |
xzhan96 | cf0a3c54 | 2017-11-17 04:33:01 | [diff] [blame] | 4273 | RenderFrameHost* render_frame_host, |
danakj | 0018a29a | 2018-12-01 01:03:43 | [diff] [blame] | 4274 | content::PageVisibilityState* visibility_state) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 4275 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4276 | |
| 4277 | WebContents* web_contents = |
| 4278 | WebContents::FromRenderFrameHost(render_frame_host); |
| 4279 | DCHECK(web_contents); |
| 4280 | |
Hiroki Nakagawa | b4cd18aa | 2021-01-25 18:11:01 | [diff] [blame] | 4281 | prerender::NoStatePrefetchManager* no_state_prefetch_manager = |
| 4282 | prerender::NoStatePrefetchManagerFactory::GetForBrowserContext( |
droger | c154315 | 2016-09-20 13:03:37 | [diff] [blame] | 4283 | web_contents->GetBrowserContext()); |
Hiroki Nakagawa | b4cd18aa | 2021-01-25 18:11:01 | [diff] [blame] | 4284 | if (no_state_prefetch_manager && |
| 4285 | no_state_prefetch_manager->IsWebContentsPrerendering(web_contents)) { |
Collin Baker | 98457b5 | 2019-11-06 21:34:29 | [diff] [blame] | 4286 | *visibility_state = content::PageVisibilityState::kHiddenButPainting; |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4287 | } |
| 4288 | } |
| 4289 | |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 4290 | void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() { |
| 4291 | base::FilePath user_data_dir; |
| 4292 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 4293 | DCHECK(!user_data_dir.empty()); |
| 4294 | network_contexts_parent_directory_.push_back(user_data_dir); |
| 4295 | |
| 4296 | base::FilePath cache_dir; |
| 4297 | chrome::GetUserCacheDirectory(user_data_dir, &cache_dir); |
| 4298 | DCHECK(!cache_dir.empty()); |
| 4299 | // On some platforms, the cache is a child of the user_data_dir so only |
| 4300 | // return the one path. |
| 4301 | if (!user_data_dir.IsParent(cache_dir)) |
| 4302 | network_contexts_parent_directory_.push_back(cache_dir); |
| 4303 | |
| 4304 | // If the cache location has been overridden by a switch or preference, |
| 4305 | // include that as well. |
| 4306 | if (auto* local_state = g_browser_process->local_state()) { |
| 4307 | base::FilePath pref_cache_dir = |
| 4308 | local_state->GetFilePath(prefs::kDiskCacheDir); |
| 4309 | if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir)) |
| 4310 | network_contexts_parent_directory_.push_back(pref_cache_dir); |
| 4311 | } |
| 4312 | } |
| 4313 | |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4314 | void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 4315 | base::CommandLine* to_command_line, |
| 4316 | const base::CommandLine& from_command_line, |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4317 | version_info::Channel channel) { |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4318 | #if defined(OS_ANDROID) |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4319 | const version_info::Channel kMaxDisableEncryptionChannel = |
| 4320 | version_info::Channel::BETA; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4321 | #else |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4322 | const version_info::Channel kMaxDisableEncryptionChannel = |
| 4323 | version_info::Channel::DEV; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4324 | #endif |
| 4325 | if (channel <= kMaxDisableEncryptionChannel) { |
| 4326 | static const char* const kWebRtcDevSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 4327 | switches::kDisableWebRtcEncryption, |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4328 | }; |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 4329 | to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames, |
| 4330 | base::size(kWebRtcDevSwitchNames)); |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4331 | } |
| 4332 | } |
bashi | 93362955 | 2016-10-13 23:32:40 | [diff] [blame] | 4333 | |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4334 | #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 4335 | void ChromeContentBrowserClient::CreateMediaRemoter( |
| 4336 | content::RenderFrameHost* render_frame_host, |
Gyuyoung Kim | a4f9f94 | 2019-10-26 02:55:50 | [diff] [blame] | 4337 | mojo::PendingRemote<media::mojom::RemotingSource> source, |
| 4338 | mojo::PendingReceiver<media::mojom::Remoter> receiver) { |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4339 | CastRemotingConnector::CreateMediaRemoter( |
Gyuyoung Kim | a4f9f94 | 2019-10-26 02:55:50 | [diff] [blame] | 4340 | render_frame_host, std::move(source), std::move(receiver)); |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4341 | } |
| 4342 | #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING) |
robliao | bf5a32e | 2016-12-09 03:35:46 | [diff] [blame] | 4343 | |
Michael Giuffrida | 6802ffe | 2017-09-29 03:40:25 | [diff] [blame] | 4344 | base::FilePath ChromeContentBrowserClient::GetLoggingFileName( |
| 4345 | const base::CommandLine& command_line) { |
| 4346 | return logging::GetLogFileName(command_line); |
kerrnel | a67fad5 | 2017-06-14 20:18:16 | [diff] [blame] | 4347 | } |
| 4348 | |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4349 | namespace { |
| 4350 | // TODO(jam): move this to a separate file. |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4351 | class ProtocolHandlerThrottle : public blink::URLLoaderThrottle { |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4352 | public: |
| 4353 | explicit ProtocolHandlerThrottle( |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4354 | ProtocolHandlerRegistry* protocol_handler_registry) |
Matt Falkenhagen | 7811fd4 | 2020-06-24 22:42:41 | [diff] [blame] | 4355 | : protocol_handler_registry_(protocol_handler_registry) { |
| 4356 | DCHECK(protocol_handler_registry); |
| 4357 | } |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4358 | ~ProtocolHandlerThrottle() override = default; |
| 4359 | |
| 4360 | void WillStartRequest(network::ResourceRequest* request, |
| 4361 | bool* defer) override { |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4362 | TranslateUrl(&request->url); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4363 | } |
| 4364 | |
Takashi Toyoshima | eb2ba20c5 | 2020-04-27 16:34:58 | [diff] [blame] | 4365 | void WillRedirectRequest( |
| 4366 | net::RedirectInfo* redirect_info, |
| 4367 | const network::mojom::URLResponseHead& response_head, |
| 4368 | bool* defer, |
| 4369 | std::vector<std::string>* to_be_removed_headers, |
| 4370 | net::HttpRequestHeaders* modified_headers, |
| 4371 | net::HttpRequestHeaders* modified_cors_exempt_headers) override { |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4372 | TranslateUrl(&redirect_info->new_url); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | private: |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4376 | void TranslateUrl(GURL* url) { |
| 4377 | if (!protocol_handler_registry_->IsHandledProtocol(url->scheme())) |
| 4378 | return; |
| 4379 | GURL translated_url = protocol_handler_registry_->Translate(*url); |
| 4380 | if (!translated_url.is_empty()) |
| 4381 | *url = translated_url; |
| 4382 | } |
| 4383 | |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4384 | ProtocolHandlerRegistry* protocol_handler_registry_; |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4385 | }; |
| 4386 | } // namespace |
| 4387 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4388 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4389 | ChromeContentBrowserClient::CreateURLLoaderThrottles( |
| 4390 | const network::ResourceRequest& request, |
| 4391 | content::BrowserContext* browser_context, |
| 4392 | const base::RepeatingCallback<content::WebContents*()>& wc_getter, |
| 4393 | content::NavigationUIData* navigation_ui_data, |
| 4394 | int frame_tree_node_id) { |
| 4395 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 4396 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4397 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result; |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4398 | |
Matt Falkenhagen | 7811fd4 | 2020-06-24 22:42:41 | [diff] [blame] | 4399 | DCHECK(browser_context); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4400 | Profile* profile = Profile::FromBrowserContext(browser_context); |
Matt Falkenhagen | 7811fd4 | 2020-06-24 22:42:41 | [diff] [blame] | 4401 | DCHECK(profile); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4402 | |
| 4403 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4404 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4405 | |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 4406 | #if BUILDFLAG(SAFE_BROWSING_AVAILABLE) |
Josh Karlin | aabf510 | 2021-01-25 16:39:39 | [diff] [blame] | 4407 | bool matches_enterprise_whitelist = safe_browsing::IsURLAllowlistedByPolicy( |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4408 | request.url, *profile->GetPrefs()); |
| 4409 | if (!matches_enterprise_whitelist) { |
Xinghui Lu | f45d7ef7 | 2020-06-09 02:16:38 | [diff] [blame] | 4410 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) |
Dominique Fauteux-Chapleau | 5fd6beb | 2021-01-13 18:46:49 | [diff] [blame] | 4411 | auto* connectors_service = |
| 4412 | enterprise_connectors::ConnectorsServiceFactory::GetForBrowserContext( |
| 4413 | browser_context); |
| 4414 | bool has_valid_dm_token = |
| 4415 | connectors_service && |
| 4416 | connectors_service->GetDMTokenForRealTimeUrlCheck().has_value(); |
| 4417 | bool is_enterprise_lookup_enabled = |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 4418 | safe_browsing::RealTimePolicyEngine::CanPerformEnterpriseFullURLLookup( |
Dominique Fauteux-Chapleau | 5fd6beb | 2021-01-13 18:46:49 | [diff] [blame] | 4419 | profile->GetPrefs(), has_valid_dm_token, profile->IsOffTheRecord()); |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 4420 | #else |
Dominique Fauteux-Chapleau | 5fd6beb | 2021-01-13 18:46:49 | [diff] [blame] | 4421 | bool is_enterprise_lookup_enabled = false; |
Xinghui Lu | f45d7ef7 | 2020-06-09 02:16:38 | [diff] [blame] | 4422 | #endif |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 4423 | bool is_consumer_lookup_enabled = |
Xinghui Lu | f45d7ef7 | 2020-06-09 02:16:38 | [diff] [blame] | 4424 | safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup( |
| 4425 | profile->GetPrefs(), profile->IsOffTheRecord(), |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 4426 | g_browser_process->variations_service()); |
| 4427 | |
| 4428 | // |url_lookup_service| is used when real time url check is enabled. |
| 4429 | safe_browsing::RealTimeUrlLookupServiceBase* url_lookup_service = |
| 4430 | GetUrlLookupService(browser_context, is_enterprise_lookup_enabled, |
| 4431 | is_consumer_lookup_enabled); |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4432 | result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create( |
| 4433 | base::BindOnce( |
| 4434 | &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate, |
Matt Menke | 562675cfe | 2020-01-07 15:50:53 | [diff] [blame] | 4435 | base::Unretained(this), |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 4436 | safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs()), |
| 4437 | // Should check for enterprise when safe browsing is disabled. |
| 4438 | /*should_check_on_sb_disabled=*/is_enterprise_lookup_enabled), |
Xinghui Lu | a142c10 | 2020-03-02 20:50:08 | [diff] [blame] | 4439 | wc_getter, frame_tree_node_id, |
Xinghui Lu | e17b1994 | 2020-02-24 21:19:58 | [diff] [blame] | 4440 | url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr)); |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4441 | } |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4442 | #endif |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4443 | |
dalyk | ba7bbfc | 2019-12-18 19:59:21 | [diff] [blame] | 4444 | #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 4445 | result.push_back( |
Colin Blundell | 27331f9 | 2020-02-05 21:13:01 | [diff] [blame] | 4446 | std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>( |
| 4447 | wc_getter.Run())); |
dalyk | ba7bbfc | 2019-12-18 19:59:21 | [diff] [blame] | 4448 | #endif |
| 4449 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4450 | if (chrome_navigation_ui_data && |
Hiroki Nakagawa | 78ebf06 | 2021-01-20 16:23:53 | [diff] [blame] | 4451 | chrome_navigation_ui_data->is_no_state_prefetching()) { |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4452 | result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>( |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4453 | chrome_navigation_ui_data->prerender_histogram_prefix(), |
Darin Fisher | e41aab5 | 2020-01-29 18:31:23 | [diff] [blame] | 4454 | GetPrerenderCanceler(wc_getter))); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4455 | } |
| 4456 | |
John Abd-El-Malek | 4f380d9 | 2020-02-19 16:43:36 | [diff] [blame] | 4457 | #if defined(OS_ANDROID) |
| 4458 | std::string client_data_header; |
Brandon Wylie | 21a88ac9 | 2020-05-15 02:49:23 | [diff] [blame] | 4459 | bool night_mode_enabled = false; |
John Abd-El-Malek | fb9f546 | 2020-02-20 01:18:37 | [diff] [blame] | 4460 | if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) { |
| 4461 | auto* web_contents = WebContents::FromFrameTreeNodeId(frame_tree_node_id); |
John Abd-El-Malek | 2ea0554 | 2020-03-04 00:03:36 | [diff] [blame] | 4462 | // Could be null if the FrameTreeNode's RenderFrameHost is shutting down. |
| 4463 | if (web_contents) { |
| 4464 | auto* client_data_header_observer = |
| 4465 | customtabs::ClientDataHeaderWebContentsObserver::FromWebContents( |
| 4466 | web_contents); |
| 4467 | if (client_data_header_observer) |
| 4468 | client_data_header = client_data_header_observer->header(); |
Brandon Wylie | 21a88ac9 | 2020-05-15 02:49:23 | [diff] [blame] | 4469 | |
Brandon Wylie | f6bfdab | 2020-08-12 21:49:36 | [diff] [blame] | 4470 | auto* delegate = |
| 4471 | TabAndroid::FromWebContents(web_contents) |
| 4472 | ? static_cast<android::TabWebContentsDelegateAndroid*>( |
| 4473 | web_contents->GetDelegate()) |
| 4474 | : nullptr; |
| 4475 | if (delegate) |
| 4476 | night_mode_enabled = delegate->IsNightModeEnabled(); |
Brandon Wylie | 21a88ac9 | 2020-05-15 02:49:23 | [diff] [blame] | 4477 | } |
John Abd-El-Malek | fb9f546 | 2020-02-20 01:18:37 | [diff] [blame] | 4478 | } |
John Abd-El-Malek | 4f380d9 | 2020-02-19 16:43:36 | [diff] [blame] | 4479 | #endif |
| 4480 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4481 | chrome::mojom::DynamicParams dynamic_params = { |
| 4482 | profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch), |
| 4483 | profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict), |
Alex Clarke | 3ebd977 | 2020-02-28 10:50:27 | [diff] [blame] | 4484 | profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps)}; |
| 4485 | result.push_back(std::make_unique<GoogleURLLoaderThrottle>( |
John Abd-El-Malek | 4f380d9 | 2020-02-19 16:43:36 | [diff] [blame] | 4486 | #if defined(OS_ANDROID) |
Brandon Wylie | 21a88ac9 | 2020-05-15 02:49:23 | [diff] [blame] | 4487 | client_data_header, night_mode_enabled, |
John Abd-El-Malek | 4f380d9 | 2020-02-19 16:43:36 | [diff] [blame] | 4488 | #endif |
Alex Clarke | 3ebd977 | 2020-02-28 10:50:27 | [diff] [blame] | 4489 | std::move(dynamic_params))); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4490 | |
Matt Falkenhagen | 7811fd4 | 2020-06-24 22:42:41 | [diff] [blame] | 4491 | { |
| 4492 | auto* factory = |
| 4493 | ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context); |
| 4494 | // null in unit tests. |
| 4495 | if (factory) |
| 4496 | result.push_back(std::make_unique<ProtocolHandlerThrottle>(factory)); |
| 4497 | } |
Clark DuVall | 8512cee6 | 2019-06-26 01:14:21 | [diff] [blame] | 4498 | |
Clark DuVall | 39c2cfc | 2019-06-25 21:49:28 | [diff] [blame] | 4499 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 4500 | result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>( |
Julie Jeongeun Kim | 44dcfab | 2021-01-20 07:39:18 | [diff] [blame] | 4501 | request.destination, frame_tree_node_id)); |
Clark DuVall | 39c2cfc | 2019-06-25 21:49:28 | [diff] [blame] | 4502 | #endif |
| 4503 | |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 4504 | auto delegate = |
Robbie McElrath | 38f47af | 2019-09-19 21:51:40 | [diff] [blame] | 4505 | std::make_unique<signin::HeaderModificationDelegateImpl>(profile); |
David Roger | 615cb9f0 | 2020-01-30 12:06:58 | [diff] [blame] | 4506 | auto signin_throttle = |
| 4507 | signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter); |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 4508 | if (signin_throttle) |
| 4509 | result.push_back(std::move(signin_throttle)); |
| 4510 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4511 | return result; |
| 4512 | } |
| 4513 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4514 | void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4515 | int frame_tree_node_id, |
Yue Ru Sun | 03a6990a | 2020-10-24 18:04:31 | [diff] [blame] | 4516 | ukm::SourceIdObj ukm_source_id, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4517 | NonNetworkURLLoaderFactoryMap* factories) { |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 4518 | #if BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(IS_CHROMEOS_ASH) |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4519 | content::WebContents* web_contents = |
| 4520 | content::WebContents::FromFrameTreeNodeId(frame_tree_node_id); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4521 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | a782c5a | 2020-09-26 02:15:17 | [diff] [blame] | 4522 | factories->emplace( |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4523 | extensions::kExtensionScheme, |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 4524 | extensions::CreateExtensionNavigationURLLoaderFactory( |
Maks Orlovich | 5408ddfc | 2020-07-28 23:07:35 | [diff] [blame] | 4525 | web_contents->GetBrowserContext(), ukm_source_id, |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4526 | !!extensions::WebViewGuest::FromWebContents(web_contents))); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4527 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 4528 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4529 | Profile* profile = |
| 4530 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Lukasz Anforowicz | eb016c5 | 2020-10-03 02:15:35 | [diff] [blame] | 4531 | factories->emplace(content::kExternalFileScheme, |
| 4532 | chromeos::ExternalFileURLLoaderFactory::Create( |
| 4533 | profile, content::ChildProcessHost::kInvalidUniqueID)); |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 4534 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
| 4535 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) || BUILDFLAG(IS_CHROMEOS_ASH) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4536 | } |
| 4537 | |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4538 | void ChromeContentBrowserClient:: |
Hiroki Nakagawa | 1efa31d | 2019-10-01 22:36:34 | [diff] [blame] | 4539 | RegisterNonNetworkWorkerMainResourceURLLoaderFactories( |
| 4540 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | a782c5a | 2020-09-26 02:15:17 | [diff] [blame] | 4541 | NonNetworkURLLoaderFactoryMap* factories) { |
Hiroki Nakagawa | 1efa31d | 2019-10-01 22:36:34 | [diff] [blame] | 4542 | DCHECK(browser_context); |
| 4543 | DCHECK(factories); |
Lukasz Anforowicz | a782c5a | 2020-09-26 02:15:17 | [diff] [blame] | 4544 | |
| 4545 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Hiroki Nakagawa | 1efa31d | 2019-10-01 22:36:34 | [diff] [blame] | 4546 | factories->emplace( |
| 4547 | extensions::kExtensionScheme, |
| 4548 | extensions::CreateExtensionWorkerMainResourceURLLoaderFactory( |
| 4549 | browser_context)); |
| 4550 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 4551 | } |
| 4552 | |
| 4553 | void ChromeContentBrowserClient:: |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4554 | RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories( |
| 4555 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | a782c5a | 2020-09-26 02:15:17 | [diff] [blame] | 4556 | NonNetworkURLLoaderFactoryMap* factories) { |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4557 | DCHECK(browser_context); |
| 4558 | DCHECK(factories); |
Lukasz Anforowicz | a782c5a | 2020-09-26 02:15:17 | [diff] [blame] | 4559 | |
| 4560 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4561 | factories->emplace( |
| 4562 | extensions::kExtensionScheme, |
| 4563 | extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory( |
| 4564 | browser_context)); |
| 4565 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4566 | } |
| 4567 | |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4568 | namespace { |
| 4569 | |
Lukasz Anforowicz | 44a0f9e | 2020-09-30 15:05:38 | [diff] [blame] | 4570 | // The SpecialAccessFileURLLoaderFactory provided to the extension background |
| 4571 | // pages. Checks with the ChildProcessSecurityPolicy to validate the file |
| 4572 | // access. |
| 4573 | class SpecialAccessFileURLLoaderFactory |
Lukasz Anforowicz | 25620d3 | 2021-01-27 22:03:44 | [diff] [blame] | 4574 | : public network::SelfDeletingURLLoaderFactory { |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4575 | public: |
Lukasz Anforowicz | 44a0f9e | 2020-09-30 15:05:38 | [diff] [blame] | 4576 | // Returns mojo::PendingRemote to a newly constructed |
| 4577 | // SpecialAccessFileURLLoaderFactory. The factory is self-owned - it will |
| 4578 | // delete itself once there are no more receivers (including the receiver |
| 4579 | // associated with the returned mojo::PendingRemote and the receivers bound by |
| 4580 | // the Clone method). |
| 4581 | static mojo::PendingRemote<network::mojom::URLLoaderFactory> Create( |
| 4582 | int child_id) { |
| 4583 | mojo::PendingRemote<network::mojom::URLLoaderFactory> pending_remote; |
| 4584 | |
| 4585 | // The SpecialAccessFileURLLoaderFactory will delete itself when there are |
Lukasz Anforowicz | 25620d3 | 2021-01-27 22:03:44 | [diff] [blame] | 4586 | // no more receivers - see the |
| 4587 | // network::SelfDeletingURLLoaderFactory::OnDisconnect method. |
Lukasz Anforowicz | 44a0f9e | 2020-09-30 15:05:38 | [diff] [blame] | 4588 | new SpecialAccessFileURLLoaderFactory( |
| 4589 | child_id, pending_remote.InitWithNewPipeAndPassReceiver()); |
| 4590 | |
| 4591 | return pending_remote; |
| 4592 | } |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4593 | |
| 4594 | private: |
Lukasz Anforowicz | 44a0f9e | 2020-09-30 15:05:38 | [diff] [blame] | 4595 | explicit SpecialAccessFileURLLoaderFactory( |
| 4596 | int child_id, |
| 4597 | mojo::PendingReceiver<network::mojom::URLLoaderFactory> factory_receiver) |
Lukasz Anforowicz | 25620d3 | 2021-01-27 22:03:44 | [diff] [blame] | 4598 | : network::SelfDeletingURLLoaderFactory(std::move(factory_receiver)), |
Lukasz Anforowicz | 44a0f9e | 2020-09-30 15:05:38 | [diff] [blame] | 4599 | child_id_(child_id) {} |
| 4600 | |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4601 | // network::mojom::URLLoaderFactory: |
Julie Jeongeun Kim | e003de5 | 2019-10-29 05:14:27 | [diff] [blame] | 4602 | void CreateLoaderAndStart( |
| 4603 | mojo::PendingReceiver<network::mojom::URLLoader> loader, |
| 4604 | int32_t routing_id, |
| 4605 | int32_t request_id, |
| 4606 | uint32_t options, |
| 4607 | const network::ResourceRequest& request, |
Julie Jeongeun Kim | 6dd4c7b | 2019-11-18 05:56:30 | [diff] [blame] | 4608 | mojo::PendingRemote<network::mojom::URLLoaderClient> client, |
Julie Jeongeun Kim | e003de5 | 2019-10-29 05:14:27 | [diff] [blame] | 4609 | const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) |
| 4610 | override { |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4611 | if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL( |
| 4612 | child_id_, request.url)) { |
Julie Jeongeun Kim | 6dd4c7b | 2019-11-18 05:56:30 | [diff] [blame] | 4613 | mojo::Remote<network::mojom::URLLoaderClient>(std::move(client)) |
| 4614 | ->OnComplete( |
| 4615 | network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED)); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4616 | return; |
| 4617 | } |
Yutaka Hirano | df83dca4 | 2020-01-07 06:24:55 | [diff] [blame] | 4618 | content::CreateFileURLLoaderBypassingSecurityChecks( |
| 4619 | request, std::move(loader), std::move(client), |
| 4620 | /*observer=*/nullptr, |
| 4621 | /* allow_directory_listing */ true); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4622 | } |
| 4623 | |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4624 | int child_id_; |
Lukasz Anforowicz | 44a0f9e | 2020-09-30 15:05:38 | [diff] [blame] | 4625 | DISALLOW_COPY_AND_ASSIGN(SpecialAccessFileURLLoaderFactory); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4626 | }; |
| 4627 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 4628 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 4629 | bool IsSystemFeatureDisabled(policy::SystemFeature system_feature) { |
| 4630 | PrefService* const local_state = g_browser_process->local_state(); |
| 4631 | if (!local_state) // Sometimes it's not available in tests. |
| 4632 | return false; |
| 4633 | |
| 4634 | const base::ListValue* disabled_system_features_pref = |
| 4635 | local_state->GetList(policy::policy_prefs::kSystemFeaturesDisableList); |
| 4636 | if (!disabled_system_features_pref) |
| 4637 | return false; |
| 4638 | |
| 4639 | const auto disabled_system_features = |
| 4640 | disabled_system_features_pref->GetList(); |
| 4641 | return base::Contains(disabled_system_features, base::Value(system_feature)); |
| 4642 | } |
| 4643 | |
| 4644 | bool IsSystemFeatureURLDisabled(const GURL& url) { |
| 4645 | if (!url.SchemeIs(content::kChromeUIScheme)) |
| 4646 | return false; |
| 4647 | |
| 4648 | // chrome://os-settings/pwa.html shouldn't be replaced to let the settings app |
| 4649 | // installation complete successfully. |
| 4650 | if (url.DomainIs(chrome::kChromeUIOSSettingsHost) && |
| 4651 | url.path() != "/pwa.html" && |
Anqing Zhao | d99eda17 | 2020-11-30 13:49:49 | [diff] [blame] | 4652 | IsSystemFeatureDisabled(policy::SystemFeature::kOsSettings)) { |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 4653 | return true; |
| 4654 | } |
| 4655 | |
| 4656 | if (url.DomainIs(chrome::kChromeUISettingsHost) && |
Anqing Zhao | d99eda17 | 2020-11-30 13:49:49 | [diff] [blame] | 4657 | IsSystemFeatureDisabled(policy::SystemFeature::kBrowserSettings)) { |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 4658 | return true; |
| 4659 | } |
| 4660 | |
Jesse Schettler | b7047f3 | 2020-09-18 14:50:40 | [diff] [blame] | 4661 | if (url.DomainIs(chromeos::kChromeUIScanningAppHost) && |
Anqing Zhao | d99eda17 | 2020-11-30 13:49:49 | [diff] [blame] | 4662 | IsSystemFeatureDisabled(policy::SystemFeature::kScanning)) { |
Jesse Schettler | b7047f3 | 2020-09-18 14:50:40 | [diff] [blame] | 4663 | return true; |
| 4664 | } |
| 4665 | |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 4666 | return false; |
| 4667 | } |
| 4668 | #endif |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4669 | } // namespace |
| 4670 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4671 | void ChromeContentBrowserClient:: |
| 4672 | RegisterNonNetworkSubresourceURLLoaderFactories( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4673 | int render_process_id, |
| 4674 | int render_frame_id, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4675 | NonNetworkURLLoaderFactoryMap* factories) { |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 4676 | #if BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4677 | content::RenderFrameHost* frame_host = |
| 4678 | RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 4679 | WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host); |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 4680 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) || BUILDFLAG(ENABLE_EXTENSIONS) |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4681 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 4682 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4683 | if (web_contents) { |
| 4684 | Profile* profile = |
| 4685 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Lukasz Anforowicz | eb016c5 | 2020-10-03 02:15:35 | [diff] [blame] | 4686 | factories->emplace(content::kExternalFileScheme, |
| 4687 | chromeos::ExternalFileURLLoaderFactory::Create( |
| 4688 | profile, render_process_id)); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4689 | } |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 4690 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4691 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4692 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | a782c5a | 2020-09-26 02:15:17 | [diff] [blame] | 4693 | factories->emplace(extensions::kExtensionScheme, |
| 4694 | extensions::CreateExtensionURLLoaderFactory( |
| 4695 | render_process_id, render_frame_id)); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4696 | |
| 4697 | // This logic should match |
| 4698 | // ChromeExtensionWebContentsObserver::RenderFrameCreated. |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4699 | if (!web_contents) |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4700 | return; |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4701 | |
| 4702 | Profile* profile = |
| 4703 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 4704 | InstantService* instant_service = |
| 4705 | InstantServiceFactory::GetForProfile(profile); |
| 4706 | // The test below matches what's done by ShouldServiceRequestIOThread in |
| 4707 | // local_ntp_source.cc. |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4708 | if (instant_service->IsInstantProcess(render_process_id)) { |
Lukasz Anforowicz | 7f69553 | 2020-09-15 16:05:22 | [diff] [blame] | 4709 | factories->emplace( |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4710 | chrome::kChromeSearchScheme, |
Lukasz Anforowicz | 7f69553 | 2020-09-15 16:05:22 | [diff] [blame] | 4711 | content::CreateWebUIURLLoaderFactory( |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4712 | frame_host, chrome::kChromeSearchScheme, |
| 4713 | /*allowed_webui_hosts=*/base::flat_set<std::string>())); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4714 | } |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4715 | |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4716 | extensions::ChromeExtensionWebContentsObserver* web_observer = |
| 4717 | extensions::ChromeExtensionWebContentsObserver::FromWebContents( |
| 4718 | web_contents); |
| 4719 | |
Karan Bhatia | 9192857 | 2018-03-06 01:18:07 | [diff] [blame] | 4720 | // There is nothing to do if no ChromeExtensionWebContentsObserver is attached |
| 4721 | // to the |web_contents|. |
| 4722 | if (!web_observer) |
| 4723 | return; |
| 4724 | |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4725 | const Extension* extension = |
| 4726 | web_observer->GetExtensionFromFrame(frame_host, false); |
| 4727 | if (!extension) |
| 4728 | return; |
| 4729 | |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4730 | std::vector<std::string> allowed_webui_hosts; |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4731 | // Support for chrome:// scheme if appropriate. |
| 4732 | if ((extension->is_extension() || extension->is_platform_app()) && |
| 4733 | Manifest::IsComponentLocation(extension->location())) { |
| 4734 | // Components of chrome that are implemented as extensions or platform apps |
| 4735 | // are allowed to use chrome://resources/ and chrome://theme/ URLs. |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4736 | allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost); |
| 4737 | allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost); |
| 4738 | } |
| 4739 | if (extension->is_extension() || extension->is_legacy_packaged_app() || |
| 4740 | (extension->is_platform_app() && |
| 4741 | Manifest::IsComponentLocation(extension->location()))) { |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4742 | // Extensions, legacy packaged apps, and component platform apps are allowed |
Lucas Tenório | 3dd8092 | 2019-03-27 03:51:02 | [diff] [blame] | 4743 | // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon |
| 4744 | // URLs. Hosted apps are not allowed because they are served via web servers |
| 4745 | // (and are generally never given access to Chrome APIs). |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4746 | allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost); |
| 4747 | allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost); |
Lucas Tenório | 3dd8092 | 2019-03-27 03:51:02 | [diff] [blame] | 4748 | allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost); |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4749 | } |
| 4750 | if (!allowed_webui_hosts.empty()) { |
Lukasz Anforowicz | 7f69553 | 2020-09-15 16:05:22 | [diff] [blame] | 4751 | factories->emplace(content::kChromeUIScheme, |
| 4752 | content::CreateWebUIURLLoaderFactory( |
| 4753 | frame_host, content::kChromeUIScheme, |
| 4754 | std::move(allowed_webui_hosts))); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4755 | } |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4756 | |
| 4757 | // Extension with a background page get file access that gets approval from |
| 4758 | // ChildProcessSecurityPolicy. |
| 4759 | extensions::ExtensionHost* host = |
| 4760 | extensions::ProcessManager::Get(web_contents->GetBrowserContext()) |
| 4761 | ->GetBackgroundHostForExtension(extension->id()); |
| 4762 | if (host) { |
Lukasz Anforowicz | 44a0f9e | 2020-09-30 15:05:38 | [diff] [blame] | 4763 | factories->emplace( |
Lukasz Anforowicz | b7d8b54 | 2020-09-03 19:50:34 | [diff] [blame] | 4764 | url::kFileScheme, |
Lukasz Anforowicz | 44a0f9e | 2020-09-30 15:05:38 | [diff] [blame] | 4765 | SpecialAccessFileURLLoaderFactory::Create(render_process_id)); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4766 | } |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4767 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4768 | } |
| 4769 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4770 | bool ChromeContentBrowserClient::WillCreateURLLoaderFactory( |
Ken Rockot | 428b1d6 | 2018-06-06 17:12:21 | [diff] [blame] | 4771 | content::BrowserContext* browser_context, |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4772 | content::RenderFrameHost* frame, |
Kenichi Ishibashi | 09ee5e7 | 2018-11-27 07:12:38 | [diff] [blame] | 4773 | int render_process_id, |
Karan Bhatia | 4a834b3 | 2019-08-16 22:26:44 | [diff] [blame] | 4774 | URLLoaderFactoryType type, |
Lukasz Anforowicz | 76273365 | 2018-09-28 14:48:26 | [diff] [blame] | 4775 | const url::Origin& request_initiator, |
Karan Bhatia | 303d0ac0 | 2019-12-05 03:01:00 | [diff] [blame] | 4776 | base::Optional<int64_t> navigation_id, |
Yue Ru Sun | 03a6990a | 2020-10-24 18:04:31 | [diff] [blame] | 4777 | ukm::SourceIdObj ukm_source_id, |
Dominic Farolino | 1be897a | 2019-07-20 08:11:42 | [diff] [blame] | 4778 | mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver, |
Julie Jeongeun Kim | 47499a0c | 2019-08-28 07:23:18 | [diff] [blame] | 4779 | mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>* |
| 4780 | header_client, |
Yutaka Hirano | 499d1321 | 2019-12-04 11:03:33 | [diff] [blame] | 4781 | bool* bypass_redirect_checks, |
dalyk | 0018c16f | 2020-01-08 20:20:08 | [diff] [blame] | 4782 | bool* disable_secure_dns, |
Yutaka Hirano | 499d1321 | 2019-12-04 11:03:33 | [diff] [blame] | 4783 | network::mojom::URLLoaderFactoryOverridePtr* factory_override) { |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4784 | bool use_proxy = false; |
| 4785 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4786 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4787 | auto* web_request_api = |
| 4788 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
Ken Rockot | 428b1d6 | 2018-06-06 17:12:21 | [diff] [blame] | 4789 | browser_context); |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4790 | |
| 4791 | // NOTE: Some unit test environments do not initialize |
| 4792 | // BrowserContextKeyedAPI factories for e.g. WebRequest. |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4793 | if (web_request_api) { |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4794 | bool use_proxy_for_web_request = |
Kenichi Ishibashi | 09ee5e7 | 2018-11-27 07:12:38 | [diff] [blame] | 4795 | web_request_api->MaybeProxyURLLoaderFactory( |
Karan Bhatia | 303d0ac0 | 2019-12-05 03:01:00 | [diff] [blame] | 4796 | browser_context, frame, render_process_id, type, |
Maks Orlovich | f334d64 | 2020-09-21 22:19:59 | [diff] [blame] | 4797 | std::move(navigation_id), ukm_source_id, factory_receiver, |
| 4798 | header_client); |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4799 | if (bypass_redirect_checks) |
| 4800 | *bypass_redirect_checks = use_proxy_for_web_request; |
| 4801 | use_proxy |= use_proxy_for_web_request; |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4802 | } |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4803 | #endif |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4804 | |
Reilly Grant | cc22e60 | 2018-09-07 15:25:20 | [diff] [blame] | 4805 | use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest( |
Karan Bhatia | 4a834b3 | 2019-08-16 22:26:44 | [diff] [blame] | 4806 | frame, type == URLLoaderFactoryType::kNavigation, request_initiator, |
| 4807 | factory_receiver); |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4808 | |
Hiroki Nakagawa | 483686a9 | 2020-10-29 04:31:45 | [diff] [blame] | 4809 | auto* prefetch_proxy_service = PrefetchProxyServiceFactory::GetForProfile( |
| 4810 | Profile::FromBrowserContext(browser_context)); |
Robert Ogden | 31b23471 | 2020-06-04 22:51:21 | [diff] [blame] | 4811 | // |frame| is null when |type| is service worker. |
Hiroki Nakagawa | 483686a9 | 2020-10-29 04:31:45 | [diff] [blame] | 4812 | if (frame && prefetch_proxy_service) { |
| 4813 | use_proxy |= prefetch_proxy_service->MaybeProxyURLLoaderFactory( |
Robert Ogden | 8c53bc5 | 2020-06-19 21:24:18 | [diff] [blame] | 4814 | frame, render_process_id, type, factory_receiver); |
Robert Ogden | 31b23471 | 2020-06-04 22:51:21 | [diff] [blame] | 4815 | } |
| 4816 | |
dalyk | 0018c16f | 2020-01-08 20:20:08 | [diff] [blame] | 4817 | #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 4818 | if (disable_secure_dns) { |
| 4819 | WebContents* web_contents = WebContents::FromRenderFrameHost(frame); |
| 4820 | *disable_secure_dns = |
Colin Blundell | 27331f9 | 2020-02-05 21:13:01 | [diff] [blame] | 4821 | web_contents && |
| 4822 | captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) && |
| 4823 | captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) |
dalyk | 0018c16f | 2020-01-08 20:20:08 | [diff] [blame] | 4824 | ->is_captive_portal_window(); |
| 4825 | } |
| 4826 | #endif |
| 4827 | |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4828 | return use_proxy; |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4829 | } |
| 4830 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4831 | std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> |
| 4832 | ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors( |
| 4833 | content::NavigationUIData* navigation_ui_data, |
Ryan Sturm | 27d93f41 | 2019-02-15 21:30:14 | [diff] [blame] | 4834 | int frame_tree_node_id, |
| 4835 | const scoped_refptr<network::SharedURLLoaderFactory>& |
| 4836 | network_loader_factory) { |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4837 | std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> |
| 4838 | interceptors; |
| 4839 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 4840 | interceptors.push_back( |
| 4841 | std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>( |
| 4842 | navigation_ui_data, frame_tree_node_id)); |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4843 | #endif |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 4844 | |
Robert Ogden | 6946ad4 | 2020-01-13 18:01:30 | [diff] [blame] | 4845 | if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) { |
Hiroki Nakagawa | 483686a9 | 2020-10-29 04:31:45 | [diff] [blame] | 4846 | interceptors.push_back(std::make_unique<PrefetchProxyURLLoaderInterceptor>( |
| 4847 | frame_tree_node_id)); |
Robert Ogden | 6946ad4 | 2020-01-13 18:01:30 | [diff] [blame] | 4848 | } |
| 4849 | |
Ryan Sturm | 8670b57 | 2020-10-21 18:45:30 | [diff] [blame] | 4850 | if (SearchPrefetchServiceIsEnabled()) { |
| 4851 | interceptors.push_back(std::make_unique<SearchPrefetchURLLoaderInterceptor>( |
| 4852 | frame_tree_node_id)); |
| 4853 | } |
| 4854 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4855 | return interceptors; |
| 4856 | } |
| 4857 | |
Ryan Sturm | 6b2f639 | 2020-12-09 21:46:00 | [diff] [blame] | 4858 | content::ContentBrowserClient::URLLoaderRequestHandler |
| 4859 | ChromeContentBrowserClient:: |
| 4860 | CreateURLLoaderHandlerForServiceWorkerNavigationPreload( |
| 4861 | int frame_tree_node_id, |
| 4862 | const network::ResourceRequest& resource_request) { |
| 4863 | content::ContentBrowserClient::URLLoaderRequestHandler callback; |
| 4864 | |
| 4865 | // If search prefetch is disabled, nothing needs to be handled. |
| 4866 | if (!SearchPrefetchServiceIsEnabled()) { |
| 4867 | return callback; |
| 4868 | } |
| 4869 | |
| 4870 | std::unique_ptr<SearchPrefetchURLLoader> loader = |
| 4871 | SearchPrefetchURLLoaderInterceptor::MaybeCreateLoaderForRequest( |
| 4872 | resource_request, frame_tree_node_id); |
| 4873 | if (!loader) { |
| 4874 | return callback; |
| 4875 | } |
| 4876 | |
| 4877 | auto* raw_loader = loader.get(); |
| 4878 | |
| 4879 | // Hand ownership of the loader to the callback, when it runs, mojo will |
| 4880 | // manage it. If the callback is deleted, the loader will be deleted. |
| 4881 | callback = raw_loader->ServingResponseHandler(std::move(loader)); |
| 4882 | return callback; |
| 4883 | } |
| 4884 | |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4885 | bool ChromeContentBrowserClient::WillInterceptWebSocket( |
| 4886 | content::RenderFrameHost* frame) { |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4887 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4888 | if (!frame) { |
| 4889 | return false; |
| 4890 | } |
| 4891 | const auto* web_request_api = |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4892 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
| 4893 | frame->GetProcess()->GetBrowserContext()); |
| 4894 | |
| 4895 | // NOTE: Some unit test environments do not initialize |
| 4896 | // BrowserContextKeyedAPI factories for e.g. WebRequest. |
| 4897 | if (!web_request_api) |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4898 | return false; |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4899 | |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4900 | return web_request_api->MayHaveProxies(); |
| 4901 | #else |
| 4902 | return false; |
| 4903 | #endif |
| 4904 | } |
| 4905 | |
| 4906 | void ChromeContentBrowserClient::CreateWebSocket( |
| 4907 | content::RenderFrameHost* frame, |
| 4908 | WebSocketFactory factory, |
| 4909 | const GURL& url, |
Maks Orlovich | ab27e24 | 2020-01-07 18:10:39 | [diff] [blame] | 4910 | const net::SiteForCookies& site_for_cookies, |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4911 | const base::Optional<std::string>& user_agent, |
Julie Jeongeun Kim | 3e973f9 | 2019-08-22 08:02:40 | [diff] [blame] | 4912 | mojo::PendingRemote<network::mojom::WebSocketHandshakeClient> |
| 4913 | handshake_client) { |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4914 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4915 | if (!frame) { |
| 4916 | return; |
| 4917 | } |
| 4918 | auto* web_request_api = |
| 4919 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
| 4920 | frame->GetProcess()->GetBrowserContext()); |
| 4921 | |
| 4922 | DCHECK(web_request_api); |
| 4923 | web_request_api->ProxyWebSocket(frame, std::move(factory), url, |
Maks Orlovich | ab27e24 | 2020-01-07 18:10:39 | [diff] [blame] | 4924 | site_for_cookies.RepresentativeUrl(), |
| 4925 | user_agent, std::move(handshake_client)); |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4926 | #endif |
| 4927 | } |
| 4928 | |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4929 | bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager( |
Maks Orlovich | e7db7a2 | 2019-07-25 01:47:46 | [diff] [blame] | 4930 | network::mojom::RestrictedCookieManagerRole role, |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4931 | content::BrowserContext* browser_context, |
Shuran Huang | bd4d169 | 2021-01-26 17:03:41 | [diff] [blame] | 4932 | const url::Origin& origin, |
Shuran Huang | 92b415d7 | 2021-01-12 20:48:15 | [diff] [blame] | 4933 | const net::IsolationInfo& isolation_info, |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4934 | bool is_service_worker, |
| 4935 | int process_id, |
| 4936 | int routing_id, |
Julie Jeongeun Kim | d20f64b | 2019-08-26 04:13:03 | [diff] [blame] | 4937 | mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) { |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4938 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 4939 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Shuran Huang | f20a28c | 2021-01-27 19:36:28 | [diff] [blame] | 4940 | if (origin.scheme() == extensions::kExtensionScheme) { |
Maks Orlovich | e7db7a2 | 2019-07-25 01:47:46 | [diff] [blame] | 4941 | DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role); |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4942 | extensions::ChromeExtensionCookies::Get(browser_context) |
Shuran Huang | bd4d169 | 2021-01-26 17:03:41 | [diff] [blame] | 4943 | ->CreateRestrictedCookieManager(origin, isolation_info, |
| 4944 | std::move(*receiver)); |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4945 | return true; |
| 4946 | } |
| 4947 | #endif |
| 4948 | return false; |
| 4949 | } |
| 4950 | |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 4951 | void ChromeContentBrowserClient::OnNetworkServiceCreated( |
| 4952 | network::mojom::NetworkService* network_service) { |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4953 | PrefService* local_state; |
| 4954 | if (g_browser_process) { |
| 4955 | DCHECK(g_browser_process->local_state()); |
| 4956 | local_state = g_browser_process->local_state(); |
| 4957 | } else { |
danakj | 5beedd0 | 2020-10-30 15:55:13 | [diff] [blame] | 4958 | DCHECK(startup_data_.chrome_feature_list_creator()->local_state()); |
| 4959 | local_state = startup_data_.chrome_feature_list_creator()->local_state(); |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4960 | } |
| 4961 | |
| 4962 | if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance()) |
| 4963 | data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state); |
| 4964 | |
Henrique Nakashima | a3b1c5d | 2019-07-03 19:25:49 | [diff] [blame] | 4965 | // Create SystemNetworkContextManager if it has not been created yet. We need |
| 4966 | // to set up global NetworkService state before anything else uses it and this |
| 4967 | // is the first opportunity to initialize SystemNetworkContextManager with the |
| 4968 | // NetworkService. |
| 4969 | if (!SystemNetworkContextManager::HasInstance()) |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4970 | SystemNetworkContextManager::CreateInstance(local_state); |
John Abd-El-Malek | 897374f4 | 2019-05-30 03:58:07 | [diff] [blame] | 4971 | |
Min Qin | 8caab1d | 2018-10-03 17:28:13 | [diff] [blame] | 4972 | SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated( |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 4973 | network_service); |
| 4974 | } |
| 4975 | |
Matthew Denton | 8888ae5 | 2020-05-14 08:20:02 | [diff] [blame] | 4976 | void ChromeContentBrowserClient::ConfigureNetworkContextParams( |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4977 | content::BrowserContext* context, |
| 4978 | bool in_memory, |
Matthew Denton | 8888ae5 | 2020-05-14 08:20:02 | [diff] [blame] | 4979 | const base::FilePath& relative_partition_path, |
| 4980 | network::mojom::NetworkContextParams* network_context_params, |
| 4981 | network::mojom::CertVerifierCreationParams* cert_verifier_creation_params) { |
Glen Robertson | cbb40ac | 2020-11-23 04:04:04 | [diff] [blame] | 4982 | ProfileNetworkContextService* service = |
| 4983 | ProfileNetworkContextServiceFactory::GetForContext(context); |
| 4984 | if (service) { |
| 4985 | service->ConfigureNetworkContextParams(in_memory, relative_partition_path, |
| 4986 | network_context_params, |
| 4987 | cert_verifier_creation_params); |
| 4988 | } else { |
| 4989 | // Set default params. |
| 4990 | network_context_params->user_agent = GetUserAgent(); |
| 4991 | network_context_params->accept_language = GetApplicationLocale(); |
| 4992 | } |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4993 | } |
| 4994 | |
Robert Sesek | 34f68f31 | 2019-01-14 20:25:11 | [diff] [blame] | 4995 | std::vector<base::FilePath> |
| 4996 | ChromeContentBrowserClient::GetNetworkContextsParentDirectory() { |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 4997 | DCHECK(!network_contexts_parent_directory_.empty()); |
| 4998 | return network_contexts_parent_directory_; |
Robert Sesek | 34f68f31 | 2019-01-14 20:25:11 | [diff] [blame] | 4999 | } |
| 5000 | |
John Abd-El-Malek | c240cfc4 | 2020-07-08 12:22:44 | [diff] [blame] | 5001 | base::DictionaryValue ChromeContentBrowserClient::GetNetLogConstants() { |
| 5002 | auto platform_dict = net_log::GetPlatformConstantsForNetLog( |
| 5003 | base::CommandLine::ForCurrentProcess()->GetCommandLineString(), |
| 5004 | chrome::GetChannelName()); |
| 5005 | if (platform_dict) |
| 5006 | return std::move(*platform_dict); |
| 5007 | else |
| 5008 | return base::DictionaryValue(); |
| 5009 | } |
| 5010 | |
Min Qin | 75ed6df | 2017-12-01 20:39:15 | [diff] [blame] | 5011 | bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp( |
Min Qin | 30a78a1 | 2017-12-06 01:29:13 | [diff] [blame] | 5012 | content::NavigationUIData* navigation_ui_data) { |
Min Qin | 75ed6df | 2017-12-01 20:39:15 | [diff] [blame] | 5013 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 5014 | // It is OK to load the saved offline copy, in MHTML format. |
| 5015 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 5016 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 5017 | if (!chrome_navigation_ui_data) |
| 5018 | return false; |
| 5019 | offline_pages::OfflinePageNavigationUIData* offline_page_data = |
| 5020 | chrome_navigation_ui_data->GetOfflinePageNavigationUIData(); |
| 5021 | return offline_page_data && offline_page_data->is_offline_page(); |
| 5022 | #else |
| 5023 | return false; |
| 5024 | #endif |
| 5025 | } |
| 5026 | |
Min Qin | 30a78a1 | 2017-12-06 01:29:13 | [diff] [blame] | 5027 | bool ChromeContentBrowserClient::ShouldForceDownloadResource( |
| 5028 | const GURL& url, |
| 5029 | const std::string& mime_type) { |
| 5030 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5031 | // Special-case user scripts to get downloaded instead of viewed. |
| 5032 | return extensions::UserScript::IsURLUserScript(url, mime_type); |
| 5033 | #else |
| 5034 | return false; |
| 5035 | #endif |
| 5036 | } |
| 5037 | |
Donna Wu | 838ac36 | 2018-08-10 10:36:33 | [diff] [blame] | 5038 | void ChromeContentBrowserClient::CreateWebUsbService( |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5039 | content::RenderFrameHost* render_frame_host, |
Miyoung Shin | 6262215 | 2019-08-27 05:13:04 | [diff] [blame] | 5040 | mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) { |
Reilly Grant | 27b2a3c | 2020-04-28 23:52:46 | [diff] [blame] | 5041 | if (!base::FeatureList::IsEnabled(features::kWebUsb)) |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5042 | return; |
| 5043 | |
[email protected] | 95ebe7c | 2020-04-08 19:12:45 | [diff] [blame] | 5044 | CHECK(render_frame_host); |
| 5045 | FrameUsbServices::CreateFrameUsbServices(render_frame_host, |
| 5046 | std::move(receiver)); |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5047 | } |
| 5048 | |
Ovidio Henriquez | 3d729f6 | 2020-02-07 00:43:29 | [diff] [blame] | 5049 | content::BluetoothDelegate* ChromeContentBrowserClient::GetBluetoothDelegate() { |
| 5050 | if (!bluetooth_delegate_) |
| 5051 | bluetooth_delegate_ = std::make_unique<ChromeBluetoothDelegate>(); |
| 5052 | return bluetooth_delegate_.get(); |
| 5053 | } |
| 5054 | |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 5055 | #if !defined(OS_ANDROID) |
Anatoliy Potapchuk | 096e4d0a | 2020-12-01 16:49:21 | [diff] [blame] | 5056 | void ChromeContentBrowserClient::CreateDeviceInfoService( |
| 5057 | content::RenderFrameHost* render_frame_host, |
| 5058 | mojo::PendingReceiver<blink::mojom::DeviceAPIService> receiver) { |
| 5059 | DCHECK(render_frame_host); |
| 5060 | DeviceServiceImpl::Create(render_frame_host, std::move(receiver)); |
| 5061 | } |
| 5062 | |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 5063 | content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() { |
| 5064 | if (!serial_delegate_) |
| 5065 | serial_delegate_ = std::make_unique<ChromeSerialDelegate>(); |
| 5066 | return serial_delegate_.get(); |
| 5067 | } |
Matt Reynolds | 93616f9b | 2019-06-07 01:28:52 | [diff] [blame] | 5068 | |
| 5069 | content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() { |
| 5070 | if (!hid_delegate_) |
| 5071 | hid_delegate_ = std::make_unique<ChromeHidDelegate>(); |
| 5072 | return hid_delegate_.get(); |
| 5073 | } |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 5074 | |
Olivier Yiptong | 935e6c4 | 2020-11-21 01:28:23 | [diff] [blame] | 5075 | content::FontAccessDelegate* |
| 5076 | ChromeContentBrowserClient::GetFontAccessDelegate() { |
| 5077 | if (!font_access_delegate_) |
| 5078 | font_access_delegate_ = std::make_unique<ChromeFontAccessDelegate>(); |
| 5079 | return static_cast<content::FontAccessDelegate*>(font_access_delegate_.get()); |
| 5080 | } |
| 5081 | |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 5082 | std::unique_ptr<content::AuthenticatorRequestClientDelegate> |
| 5083 | ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate( |
Adam Langley | 5f3963f1 | 2020-01-21 19:10:33 | [diff] [blame] | 5084 | content::RenderFrameHost* render_frame_host) { |
| 5085 | return AuthenticatorRequestScheduler::CreateRequestDelegate( |
| 5086 | render_frame_host); |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 5087 | } |
Nina Satragno | 8c832df | 2019-07-29 15:59:39 | [diff] [blame] | 5088 | #endif |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 5089 | |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 5090 | std::unique_ptr<net::ClientCertStore> |
| 5091 | ChromeContentBrowserClient::CreateClientCertStore( |
David Benjamin | f6a3409 | 2019-11-07 19:55:10 | [diff] [blame] | 5092 | content::BrowserContext* browser_context) { |
| 5093 | return ProfileNetworkContextServiceFactory::GetForContext(browser_context) |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 5094 | ->CreateClientCertStore(); |
| 5095 | } |
| 5096 | |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 5097 | std::unique_ptr<content::LoginDelegate> |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5098 | ChromeContentBrowserClient::CreateLoginDelegate( |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5099 | const net::AuthChallengeInfo& auth_info, |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 5100 | content::WebContents* web_contents, |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5101 | const content::GlobalRequestID& request_id, |
Jun Cai | 8e165d2 | 2018-05-14 19:21:24 | [diff] [blame] | 5102 | bool is_request_for_main_frame, |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5103 | const GURL& url, |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5104 | scoped_refptr<net::HttpResponseHeaders> response_headers, |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5105 | bool first_auth_attempt, |
Mark Pilgrim | 7cfcd11 | 2018-05-08 00:07:56 | [diff] [blame] | 5106 | LoginAuthRequiredCallback auth_required_callback) { |
Andreea Costinas | 81218bf | 2021-01-08 11:48:14 | [diff] [blame] | 5107 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
| 5108 | policy::SystemProxyManager* system_proxy_manager = |
| 5109 | g_browser_process->platform_part() |
| 5110 | ->browser_policy_connector_chromeos() |
| 5111 | ->GetSystemProxyManager(); |
| 5112 | // For Managed Guest Session and Kiosk devices, the credentials configured |
| 5113 | // via the policy SystemProxySettings may be used for proxy authentication. |
| 5114 | // Note: |system_proxy_manager| may be missing in tests. |
| 5115 | if (system_proxy_manager && system_proxy_manager->CanUsePolicyCredentials( |
| 5116 | auth_info, first_auth_attempt)) { |
| 5117 | return system_proxy_manager->CreateLoginDelegate( |
| 5118 | std::move(auth_required_callback)); |
| 5119 | } |
| 5120 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
| 5121 | |
Emily Stark | 63c884f | 2020-05-12 03:55:28 | [diff] [blame] | 5122 | // For subresources, create a LoginHandler directly, which may show a login |
| 5123 | // prompt to the user. Main frame resources go through LoginTabHelper, which |
| 5124 | // manages a more complicated flow to avoid confusion about which website is |
| 5125 | // showing the prompt. |
| 5126 | if (is_request_for_main_frame) { |
| 5127 | LoginTabHelper::CreateForWebContents(web_contents); |
| 5128 | return LoginTabHelper::FromWebContents(web_contents) |
| 5129 | ->CreateAndStartMainFrameLoginDelegate( |
| 5130 | auth_info, web_contents, request_id, url, response_headers, |
| 5131 | std::move(auth_required_callback)); |
| 5132 | } |
| 5133 | std::unique_ptr<LoginHandler> login_handler = LoginHandler::Create( |
| 5134 | auth_info, web_contents, std::move(auth_required_callback)); |
| 5135 | login_handler->StartSubresource(request_id, url, response_headers); |
| 5136 | return login_handler; |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5137 | } |
| 5138 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5139 | bool ChromeContentBrowserClient::HandleExternalProtocol( |
| 5140 | const GURL& url, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 5141 | content::WebContents::OnceGetter web_contents_getter, |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5142 | int child_id, |
| 5143 | content::NavigationUIData* navigation_data, |
| 5144 | bool is_main_frame, |
| 5145 | ui::PageTransition page_transition, |
Tim Volodine | b24393f3 | 2018-11-16 18:45:45 | [diff] [blame] | 5146 | bool has_user_gesture, |
Emily Stark | 13b66bdf | 2019-10-04 17:11:45 | [diff] [blame] | 5147 | const base::Optional<url::Origin>& initiating_origin, |
Julie Jeongeun Kim | fb6f530 | 2019-10-17 17:24:10 | [diff] [blame] | 5148 | mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) { |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5149 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5150 | // External protocols are disabled for guests. An exception is made for the |
| 5151 | // "mailto" protocol, so that pages that utilize it work properly in a |
| 5152 | // WebView. |
| 5153 | ChromeNavigationUIData* chrome_data = |
| 5154 | static_cast<ChromeNavigationUIData*>(navigation_data); |
| 5155 | if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) || |
| 5156 | (chrome_data && |
| 5157 | chrome_data->GetExtensionNavigationUIData()->is_web_view())) && |
| 5158 | !url.SchemeIs(url::kMailToScheme)) { |
| 5159 | return false; |
| 5160 | } |
| 5161 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 5162 | |
| 5163 | #if defined(OS_ANDROID) |
| 5164 | // Main frame external protocols are handled by |
| 5165 | // InterceptNavigationResourceThrottle. |
| 5166 | if (is_main_frame) |
| 5167 | return false; |
| 5168 | #endif // defined(ANDROID) |
| 5169 | |
Gabriel Charette | e7cdc5cd | 2020-05-27 23:35:05 | [diff] [blame] | 5170 | content::GetUIThreadTaskRunner({})->PostTask( |
| 5171 | FROM_HERE, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 5172 | base::BindOnce(&LaunchURL, url, std::move(web_contents_getter), |
| 5173 | page_transition, has_user_gesture, initiating_origin)); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5174 | return true; |
| 5175 | } |
| 5176 | |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5177 | std::unique_ptr<content::OverlayWindow> |
Jennifer Apacible | 6010b023 | 2018-04-12 23:35:28 | [diff] [blame] | 5178 | ChromeContentBrowserClient::CreateWindowForPictureInPicture( |
| 5179 | content::PictureInPictureWindowController* controller) { |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5180 | // Note: content::OverlayWindow::Create() is defined by platform-specific |
| 5181 | // implementation in chrome/browser/ui/views. This layering hack, which goes |
| 5182 | // through //content and ContentBrowserClient, allows us to work around the |
| 5183 | // dependency constraints that disallow directly calling |
| 5184 | // chrome/browser/ui/views code either from here or from other code in |
| 5185 | // chrome/browser. |
Jennifer Apacible | 6010b023 | 2018-04-12 23:35:28 | [diff] [blame] | 5186 | return content::OverlayWindow::Create(controller); |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5187 | } |
| 5188 | |
Kunihiko Sakamoto | 19aa708 | 2019-02-25 03:14:43 | [diff] [blame] | 5189 | void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher( |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5190 | content::BrowserContext* browser_context, |
Julie Jeongeun Kim | 6d8b749 | 2019-08-20 19:24:11 | [diff] [blame] | 5191 | mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) { |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5192 | Profile* profile = Profile::FromBrowserContext(browser_context); |
Kunihiko Sakamoto | 19aa708 | 2019-02-25 03:14:43 | [diff] [blame] | 5193 | PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher( |
| 5194 | std::move(watcher)); |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5195 | } |
| 5196 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5197 | // Static; handles rewriting Web UI URLs. |
| 5198 | bool ChromeContentBrowserClient::HandleWebUI( |
| 5199 | GURL* url, |
| 5200 | content::BrowserContext* browser_context) { |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 5201 | // Rewrite chrome://help to chrome://settings/help. |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5202 | if (url->SchemeIs(content::kChromeUIScheme) && |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 5203 | url->host() == chrome::kChromeUIHelpHost) { |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5204 | *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost, |
| 5205 | chrome::kChromeUIHelpHost); |
| 5206 | return true; // Return true to update the displayed URL. |
| 5207 | } |
| 5208 | |
sauski | b5f8276 | 2020-07-21 17:13:22 | [diff] [blame] | 5209 | // Replace deprecated cookie settings URL with the current version. |
| 5210 | if (*url == GURL(chrome::kChromeUICookieSettingsDeprecatedURL)) { |
| 5211 | *url = GURL(chrome::kChromeUICookieSettingsURL); |
| 5212 | return true; |
| 5213 | } |
| 5214 | |
Hector Carmona | 566a20b | 2019-09-13 22:44:42 | [diff] [blame] | 5215 | #if defined(OS_WIN) |
| 5216 | // TODO(crbug.com/1003960): Remove when issue is resolved. |
| 5217 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 5218 | url->host() == chrome::kChromeUIWelcomeWin10Host) { |
| 5219 | url::Replacements<char> replacements; |
| 5220 | replacements.SetHost( |
| 5221 | chrome::kChromeUIWelcomeHost, |
| 5222 | url::Component(0, strlen(chrome::kChromeUIWelcomeHost))); |
| 5223 | *url = url->ReplaceComponents(replacements); |
| 5224 | return true; |
| 5225 | } |
| 5226 | #endif // defined(OS_WIN) |
| 5227 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5228 | if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 5229 | browser_context, *url)) { |
| 5230 | return false; |
| 5231 | } |
| 5232 | |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 5233 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5234 | // Special case : in ChromeOS in Guest mode bookmarks and history are |
| 5235 | // disabled for security reasons. New tab page explains the reasons, so |
| 5236 | // we redirect user to new tab page. |
| 5237 | if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { |
| 5238 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 5239 | (url->DomainIs(chrome::kChromeUIBookmarksHost) || |
| 5240 | url->DomainIs(chrome::kChromeUIHistoryHost))) { |
| 5241 | // Rewrite with new tab URL |
| 5242 | *url = GURL(chrome::kChromeUINewTabURL); |
| 5243 | } |
| 5244 | } |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 5245 | |
| 5246 | if (IsSystemFeatureURLDisabled(*url)) { |
| 5247 | *url = ReplaceURLHostAndPath(*url, chrome::kChromeUIAppDisabledHost, ""); |
| 5248 | return true; |
| 5249 | } |
| 5250 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5251 | #endif |
| 5252 | |
| 5253 | return true; |
| 5254 | } |
| 5255 | |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 5256 | bool ChromeContentBrowserClient::ShowPaymentHandlerWindow( |
| 5257 | content::BrowserContext* browser_context, |
| 5258 | const GURL& url, |
Anthony Vallee-Dubois | 98befeaa | 2018-01-18 16:31:32 | [diff] [blame] | 5259 | base::OnceCallback<void(bool, int, int)> callback) { |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 5260 | #if defined(OS_ANDROID) |
| 5261 | return false; |
| 5262 | #else |
| 5263 | payments::PaymentRequestDisplayManagerFactory::GetInstance() |
| 5264 | ->GetForBrowserContext(browser_context) |
| 5265 | ->ShowPaymentHandlerWindow(url, std::move(callback)); |
| 5266 | return true; |
| 5267 | #endif |
| 5268 | } |
| 5269 | |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 5270 | // static |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5271 | bool ChromeContentBrowserClient::HandleWebUIReverse( |
| 5272 | GURL* url, |
| 5273 | content::BrowserContext* browser_context) { |
Hector Carmona | 566a20b | 2019-09-13 22:44:42 | [diff] [blame] | 5274 | #if defined(OS_WIN) |
| 5275 | // TODO(crbug.com/1003960): Remove when issue is resolved. |
| 5276 | // No need to actually reverse-rewrite the URL, but return true to update the |
| 5277 | // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome. |
| 5278 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 5279 | url->host() == chrome::kChromeUIWelcomeHost) { |
| 5280 | return true; |
| 5281 | } |
| 5282 | #endif // defined(OS_WIN) |
| 5283 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5284 | // No need to actually reverse-rewrite the URL, but return true to update the |
| 5285 | // displayed URL when rewriting chrome://help to chrome://settings/help. |
| 5286 | return url->SchemeIs(content::kChromeUIScheme) && |
| 5287 | url->host() == chrome::kChromeUISettingsHost; |
| 5288 | } |
| 5289 | |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 5290 | const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const { |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 5291 | return ui::NativeTheme::GetInstanceForWeb(); |
| 5292 | } |
| 5293 | |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 5294 | scoped_refptr<safe_browsing::UrlCheckerDelegate> |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 5295 | ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate( |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 5296 | bool safe_browsing_enabled_for_profile, |
| 5297 | bool should_check_on_sb_disabled) { |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5298 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 5299 | |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 5300 | // Should not bypass safe browsing check if the check is for enterprise |
| 5301 | // lookup. |
| 5302 | if (!safe_browsing_enabled_for_profile && !should_check_on_sb_disabled) |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 5303 | return nullptr; |
| 5304 | |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5305 | // |safe_browsing_service_| may be unavailable in tests. |
| 5306 | if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) { |
| 5307 | safe_browsing_url_checker_delegate_ = |
Jialiu Lin | 0de6756c | 2018-03-22 00:57:43 | [diff] [blame] | 5308 | base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>( |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5309 | safe_browsing_service_->database_manager(), |
Jialiu Lin | 0de6756c | 2018-03-22 00:57:43 | [diff] [blame] | 5310 | safe_browsing_service_->ui_manager()); |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5311 | } |
| 5312 | |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 5313 | return safe_browsing_url_checker_delegate_; |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5314 | } |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 5315 | |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 5316 | safe_browsing::RealTimeUrlLookupServiceBase* |
| 5317 | ChromeContentBrowserClient::GetUrlLookupService( |
| 5318 | content::BrowserContext* browser_context, |
| 5319 | bool is_enterprise_lookup_enabled, |
| 5320 | bool is_consumer_lookup_enabled) { |
| 5321 | // |safe_browsing_service_| may be unavailable in tests. |
| 5322 | if (!safe_browsing_service_) { |
| 5323 | return nullptr; |
| 5324 | } |
| 5325 | |
| 5326 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 5327 | |
| 5328 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) |
| 5329 | if (is_enterprise_lookup_enabled) { |
| 5330 | return safe_browsing::ChromeEnterpriseRealTimeUrlLookupServiceFactory:: |
| 5331 | GetForProfile(profile); |
| 5332 | } |
| 5333 | #endif |
| 5334 | |
| 5335 | if (is_consumer_lookup_enabled) { |
| 5336 | return safe_browsing::RealTimeUrlLookupServiceFactory::GetForProfile( |
| 5337 | profile); |
| 5338 | } |
| 5339 | return nullptr; |
| 5340 | } |
| 5341 | |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 5342 | base::Optional<std::string> |
| 5343 | ChromeContentBrowserClient::GetOriginPolicyErrorPage( |
Domenic Denicola | c3fedd4 | 2020-03-20 21:16:59 | [diff] [blame] | 5344 | network::OriginPolicyState error_reason, |
Daniel Vogelheim | 7badd0d | 2019-02-04 14:42:18 | [diff] [blame] | 5345 | content::NavigationHandle* handle) { |
Domenic Denicola | c3fedd4 | 2020-03-20 21:16:59 | [diff] [blame] | 5346 | return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML( |
| 5347 | error_reason, handle); |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 5348 | } |
Kunihiko Sakamoto | 73b803d | 2018-10-05 09:09:52 | [diff] [blame] | 5349 | |
Takashi Toyoshima | 5af383aa | 2019-07-22 15:24:22 | [diff] [blame] | 5350 | bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() { |
Kunihiko Sakamoto | 73b803d | 2018-10-05 09:09:52 | [diff] [blame] | 5351 | // We require --user-data-dir flag too so that no dangerous changes are made |
| 5352 | // in the user's regular profile. |
| 5353 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 5354 | switches::kUserDataDir); |
| 5355 | } |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 5356 | |
| 5357 | void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate( |
| 5358 | int32_t network_traffic_annotation_id_hash, |
| 5359 | int64_t recv_bytes, |
| 5360 | int64_t sent_bytes) { |
Min Qin | cafb27b | 2018-10-30 18:02:03 | [diff] [blame] | 5361 | if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) { |
| 5362 | data_use_measurement::ChromeDataUseMeasurement::GetInstance() |
| 5363 | ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash, |
| 5364 | recv_bytes, sent_bytes); |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 5365 | } |
| 5366 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5367 | |
Ken Rockot | 4e284d3 | 2020-03-06 06:26:49 | [diff] [blame] | 5368 | base::FilePath |
| 5369 | ChromeContentBrowserClient::GetSandboxedStorageServiceDataDirectory() { |
Ken Rockot | a22aaa57 | 2020-10-14 18:46:14 | [diff] [blame] | 5370 | if (!g_browser_process || !g_browser_process->profile_manager()) |
| 5371 | return base::FilePath(); |
Ken Rockot | 4e284d3 | 2020-03-06 06:26:49 | [diff] [blame] | 5372 | return g_browser_process->profile_manager()->user_data_dir(); |
| 5373 | } |
| 5374 | |
Guido Urdaneta | e02b572 | 2020-07-22 05:58:21 | [diff] [blame] | 5375 | bool ChromeContentBrowserClient::ShouldSandboxAudioService() { |
| 5376 | return IsAudioServiceSandboxEnabled(); |
| 5377 | } |
| 5378 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5379 | blink::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews( |
| 5380 | blink::PreviewsState initial_state, |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5381 | content::NavigationHandle* navigation_handle, |
| 5382 | const GURL& current_navigation_url) { |
Sophie Chang | c4ddda677 | 2020-07-15 15:08:32 | [diff] [blame] | 5383 | return DetermineAllowedPreviewsWithoutHoldback( |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5384 | initial_state, navigation_handle, current_navigation_url); |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5385 | } |
| 5386 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5387 | blink::PreviewsState |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5388 | ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback( |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5389 | blink::PreviewsState initial_state, |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5390 | content::NavigationHandle* navigation_handle, |
| 5391 | const GURL& current_navigation_url) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5392 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
Tarun Bansal | b89c1d5 | 2019-01-16 06:56:29 | [diff] [blame] | 5393 | DCHECK(!navigation_handle->HasCommitted()); |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5394 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5395 | // If this is not a main frame, return the initial state. If there are no |
| 5396 | // previews in the state, return the state as is. |
| 5397 | if (!navigation_handle->IsInMainFrame() || |
| 5398 | navigation_handle->IsSameDocument()) { |
| 5399 | return initial_state; |
| 5400 | } |
| 5401 | |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5402 | if (!current_navigation_url.SchemeIsHTTPOrHTTPS()) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5403 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5404 | |
Doug Arnett | b3b99bc | 2019-08-09 16:55:56 | [diff] [blame] | 5405 | // Check if initial state specifies no previews should be considered. |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5406 | if (initial_state == blink::PreviewsTypes::PREVIEWS_OFF) |
Doug Arnett | b3b99bc | 2019-08-09 16:55:56 | [diff] [blame] | 5407 | return initial_state; |
| 5408 | |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5409 | // Do not allow previews on POST navigations since the primary opt-out |
| 5410 | // mechanism is to reload the page. Because POST navigations are not |
| 5411 | // idempotent, we do not want to show a preview on a POST navigation where |
| 5412 | // opting out would cause another navigation, i.e.: a reload. |
| 5413 | if (navigation_handle->IsPost()) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5414 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5415 | |
| 5416 | content::WebContents* web_contents = navigation_handle->GetWebContents(); |
| 5417 | content::WebContentsDelegate* delegate = web_contents->GetDelegate(); |
| 5418 | |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5419 | auto* browser_context = web_contents->GetBrowserContext(); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5420 | |
| 5421 | PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile( |
| 5422 | Profile::FromBrowserContext(browser_context)); |
| 5423 | auto* data_reduction_proxy_settings = |
| 5424 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 5425 | browser_context); |
| 5426 | // If the profile does not support previews or Data Saver, do not turn on |
| 5427 | // Previews. |
| 5428 | if (!previews_service || !previews_service->previews_ui_service() || |
Owen Min | 08a7289 | 2019-07-31 20:03:35 | [diff] [blame] | 5429 | !data_reduction_proxy_settings) { |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5430 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | PreviewsUITabHelper* ui_tab_helper = |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5434 | PreviewsUITabHelper::FromWebContents(web_contents); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5435 | // If this tab does not have a PreviewsUITabHelper, no preview should be |
| 5436 | // served. |
| 5437 | if (!ui_tab_helper) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5438 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5439 | |
| 5440 | DCHECK(!browser_context->IsOffTheRecord()); |
| 5441 | |
| 5442 | // Other previews objects should all exist and be initialized if we have made |
| 5443 | // it past earlier checks. |
| 5444 | previews::PreviewsDeciderImpl* previews_decider_impl = |
| 5445 | previews_service->previews_ui_service()->previews_decider_impl(); |
| 5446 | DCHECK(previews_decider_impl); |
| 5447 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5448 | // Start with an unspecified state. |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5449 | blink::PreviewsState previews_state = |
| 5450 | blink::PreviewsTypes::PREVIEWS_UNSPECIFIED; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5451 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5452 | previews::PreviewsUserData* previews_data = |
| 5453 | ui_tab_helper->GetPreviewsUserData(navigation_handle); |
| 5454 | |
| 5455 | // Certain PreviewsStates are used within URLLoaders (Offline, server |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5456 | // previews) and cannot re-evaluate PreviewsState once previews triggering |
| 5457 | // logic has already been run, so they should not change. Assume that |
Robert Ogden | 54892d0 | 2020-04-28 22:36:37 | [diff] [blame] | 5458 | // previews triggering logic has run when PreviewsUserData already exists. |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5459 | bool previews_triggering_logic_already_ran = false; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5460 | if (previews_data) { |
Robert Ogden | 54892d0 | 2020-04-28 22:36:37 | [diff] [blame] | 5461 | previews_triggering_logic_already_ran = true; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5462 | } else { |
| 5463 | previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle( |
| 5464 | navigation_handle, previews_decider_impl->GeneratePageId()); |
| 5465 | } |
| 5466 | |
| 5467 | DCHECK(previews_data); |
| 5468 | |
Sophie Chang | a71fa5d | 2019-11-19 23:53:51 | [diff] [blame] | 5469 | // Evaluate client-side previews. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5470 | previews_state |= previews::DetermineAllowedClientPreviewsState( |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5471 | previews_data, previews_triggering_logic_already_ran, |
Owen Min | 08a7289 | 2019-07-31 20:03:35 | [diff] [blame] | 5472 | data_reduction_proxy_settings->IsDataReductionProxyEnabled(), |
| 5473 | previews_decider_impl, navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5474 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5475 | if (previews_state & blink::PreviewsTypes::PREVIEWS_OFF) { |
| 5476 | previews_data->set_allowed_previews_state( |
| 5477 | blink::PreviewsTypes::PREVIEWS_OFF); |
| 5478 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5479 | } |
| 5480 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5481 | if (previews_state & blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM) { |
| 5482 | previews_data->set_allowed_previews_state( |
| 5483 | blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM); |
| 5484 | return blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5485 | } |
| 5486 | |
| 5487 | // At this point, if no Preview is allowed, don't allow previews. |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5488 | if (previews_state == blink::PreviewsTypes::PREVIEWS_UNSPECIFIED) { |
| 5489 | previews_data->set_allowed_previews_state( |
| 5490 | blink::PreviewsTypes::PREVIEWS_OFF); |
| 5491 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5492 | } |
| 5493 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5494 | blink::PreviewsState embedder_state = |
| 5495 | blink::PreviewsTypes::PREVIEWS_UNSPECIFIED; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5496 | if (delegate) { |
| 5497 | delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state); |
| 5498 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5499 | |
| 5500 | // If the allowed previews are limited by the embedder, ensure previews honors |
| 5501 | // those limits. |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5502 | if (embedder_state != blink::PreviewsTypes::PREVIEWS_UNSPECIFIED) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5503 | previews_state = previews_state & embedder_state; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5504 | // If no valid previews are left, set the state explicitly to PREVIEWS_OFF. |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5505 | if (previews_state == blink::PreviewsTypes::PREVIEWS_UNSPECIFIED) |
| 5506 | previews_state = blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5507 | } |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5508 | previews_data->set_allowed_previews_state(previews_state); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5509 | return previews_state; |
| 5510 | } |
| 5511 | |
| 5512 | // static |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5513 | blink::PreviewsState |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5514 | ChromeContentBrowserClient::DetermineCommittedPreviewsForURL( |
| 5515 | const GURL& url, |
| 5516 | data_reduction_proxy::DataReductionProxyData* drp_data, |
| 5517 | previews::PreviewsUserData* previews_user_data, |
| 5518 | const previews::PreviewsDecider* previews_decider, |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5519 | blink::PreviewsState initial_state, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5520 | content::NavigationHandle* navigation_handle) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5521 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 5522 | if (!previews::HasEnabledPreviews(initial_state)) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5523 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5524 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5525 | // Check the various other client previews types. |
| 5526 | return previews::DetermineCommittedClientPreviewsState( |
Sophie Chang | c4ddda677 | 2020-07-15 15:08:32 | [diff] [blame] | 5527 | previews_user_data, url, initial_state, previews_decider, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5528 | navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5529 | } |
| 5530 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5531 | blink::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews( |
| 5532 | blink::PreviewsState initial_state, |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5533 | content::NavigationHandle* navigation_handle, |
| 5534 | const net::HttpResponseHeaders* response_headers) { |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5535 | blink::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback( |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5536 | initial_state, navigation_handle, response_headers); |
| 5537 | |
| 5538 | return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle); |
| 5539 | } |
| 5540 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5541 | blink::PreviewsState |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5542 | ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback( |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5543 | blink::PreviewsState initial_state, |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5544 | content::NavigationHandle* navigation_handle, |
| 5545 | const net::HttpResponseHeaders* response_headers) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5546 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
arthursonzogni | 90bb092 | 2020-05-28 09:22:23 | [diff] [blame] | 5547 | DCHECK(!navigation_handle->HasCommitted()); |
| 5548 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5549 | // Only support HTTP and HTTPS. |
arthursonzogni | 90bb092 | 2020-05-28 09:22:23 | [diff] [blame] | 5550 | if (!navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5551 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5552 | |
| 5553 | // If this is not a main frame, return the initial state. If there are no |
| 5554 | // previews in the state, return the state as is. |
| 5555 | if (!previews::HasEnabledPreviews(initial_state) || |
| 5556 | !navigation_handle->IsInMainFrame() || |
| 5557 | navigation_handle->IsSameDocument()) { |
| 5558 | return initial_state; |
| 5559 | } |
| 5560 | |
| 5561 | // WebContents that don't have a PreviewsUITabHelper are not supported. |
| 5562 | PreviewsUITabHelper* ui_tab_helper = |
| 5563 | PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents()); |
| 5564 | if (!ui_tab_helper) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5565 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5566 | |
| 5567 | // If we did not previously create a PreviewsUserData, do not go any further. |
| 5568 | previews::PreviewsUserData* previews_user_data = |
| 5569 | ui_tab_helper->GetPreviewsUserData(navigation_handle); |
| 5570 | if (!previews_user_data) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5571 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5572 | |
| 5573 | PreviewsService* previews_service = |
| 5574 | PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext( |
| 5575 | navigation_handle->GetWebContents()->GetBrowserContext())); |
| 5576 | |
| 5577 | if (!previews_service || !previews_service->previews_ui_service()) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5578 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5579 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5580 | // Annotate request if no-transform directive found in response headers. |
| 5581 | if (response_headers && |
| 5582 | response_headers->HasHeaderValue("cache-control", "no-transform")) { |
Jered Gray | ba1da12 | 2018-10-31 23:06:26 | [diff] [blame] | 5583 | previews_user_data->set_cache_control_no_transform_directive(); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5584 | } |
| 5585 | |
| 5586 | previews::PreviewsDeciderImpl* previews_decider_impl = |
| 5587 | previews_service->previews_ui_service()->previews_decider_impl(); |
| 5588 | DCHECK(previews_decider_impl); |
| 5589 | |
Clark DuVall | 9c5a72cc | 2018-10-25 01:29:21 | [diff] [blame] | 5590 | std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data; |
| 5591 | auto* settings = |
| 5592 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 5593 | navigation_handle->GetWebContents()->GetBrowserContext()); |
| 5594 | if (settings) { |
| 5595 | // TODO(898326): |drp_data| may be incomplete because |navigation_handle| |
| 5596 | // does not yet have all the response information. |
| 5597 | drp_data = settings->CreateDataFromNavigationHandle(navigation_handle, |
| 5598 | response_headers); |
| 5599 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5600 | |
| 5601 | // Determine effective PreviewsState for this committed main frame response. |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5602 | blink::PreviewsState committed_state = DetermineCommittedPreviewsForURL( |
Clark DuVall | 9c5a72cc | 2018-10-25 01:29:21 | [diff] [blame] | 5603 | navigation_handle->GetURL(), drp_data.get(), previews_user_data, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5604 | previews_decider_impl, initial_state, navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5605 | |
| 5606 | // Double check that we never serve a preview when we have a |
| 5607 | // cache-control:no-transform directive. |
| 5608 | DCHECK(!previews_user_data->cache_control_no_transform_directive() || |
| 5609 | !previews::HasEnabledPreviews(committed_state)); |
| 5610 | |
Robert Ogden | ded292c6f | 2019-05-03 22:44:51 | [diff] [blame] | 5611 | // TODO(robertogden): Consider moving this to after the holdback logic. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5612 | previews_user_data->set_committed_previews_state(committed_state); |
| 5613 | |
| 5614 | previews::PreviewsType committed_type = |
| 5615 | previews::GetMainFramePreviewsType(committed_state); |
| 5616 | |
| 5617 | // Capture committed previews type, if any, in PreviewsUserData. |
| 5618 | // Note: this is for the subset of previews types that are decided upon |
| 5619 | // navigation commit. Previews types that are determined prior to |
| 5620 | // navigation (such as for offline pages or for redirecting to another |
| 5621 | // url), are not set here. |
| 5622 | previews_user_data->SetCommittedPreviewsType(committed_type); |
| 5623 | |
| 5624 | // Log the commit decision. |
| 5625 | std::vector<previews::PreviewsEligibilityReason> passed_reasons; |
| 5626 | previews_decider_impl->LogPreviewDecisionMade( |
| 5627 | (previews_user_data->cache_control_no_transform_directive() |
| 5628 | ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM |
| 5629 | : previews::PreviewsEligibilityReason::COMMITTED), |
| 5630 | navigation_handle->GetURL(), base::Time::Now(), |
Robert Ogden | 869986f | 2019-06-20 19:12:05 | [diff] [blame] | 5631 | previews_user_data->CommittedPreviewsType(), std::move(passed_reasons), |
Robert Ogden | 33e3631 | 2019-05-06 19:17:05 | [diff] [blame] | 5632 | previews_user_data); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5633 | |
| 5634 | return committed_state; |
| 5635 | } |
Charlie Harrison | 650e1142 | 2018-12-04 00:37:26 | [diff] [blame] | 5636 | |
| 5637 | void ChromeContentBrowserClient::LogWebFeatureForCurrentPage( |
| 5638 | content::RenderFrameHost* render_frame_host, |
| 5639 | blink::mojom::WebFeature feature) { |
| 5640 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 5641 | page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {}); |
| 5642 | page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage( |
| 5643 | render_frame_host, new_features); |
Lily Chen | c2c9e9f | 2019-12-05 19:55:31 | [diff] [blame] | 5644 | |
| 5645 | // For the SameSite-by-default-cookies related features, log |
| 5646 | // the site engagement score for the site whose cookie was blocked. This is to |
| 5647 | // gauge the user impact of the cookies being blocked. |
| 5648 | MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature); |
Charlie Harrison | 650e1142 | 2018-12-04 00:37:26 | [diff] [blame] | 5649 | } |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5650 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5651 | std::string ChromeContentBrowserClient::GetProduct() { |
John Abd-El-Malek | ec1fc69e | 2021-01-28 19:14:41 | [diff] [blame^] | 5652 | return embedder_support::GetProduct(); |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5653 | } |
| 5654 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5655 | std::string ChromeContentBrowserClient::GetUserAgent() { |
John Abd-El-Malek | ec1fc69e | 2021-01-28 19:14:41 | [diff] [blame^] | 5656 | return embedder_support::GetUserAgent(); |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5657 | } |
Sam McNally | d54e23f9 | 2019-01-16 04:42:39 | [diff] [blame] | 5658 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5659 | blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() { |
John Abd-El-Malek | ec1fc69e | 2021-01-28 19:14:41 | [diff] [blame^] | 5660 | return embedder_support::GetUserAgentMetadata(); |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 5661 | } |
| 5662 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5663 | base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() { |
Austin Orion | e250d01 | 2019-05-29 02:56:27 | [diff] [blame] | 5664 | // This icon is available on Android, but adds 19KiB to the APK. Since it |
| 5665 | // isn't used on Android we exclude it to avoid bloat. |
| 5666 | #if !defined(OS_ANDROID) |
| 5667 | return base::Optional<gfx::ImageSkia>( |
| 5668 | *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 5669 | IDR_PRODUCT_LOGO_256)); |
| 5670 | #else |
| 5671 | return base::nullopt; |
| 5672 | #endif |
| 5673 | } |
| 5674 | |
Sam McNally | d54e23f9 | 2019-01-16 04:42:39 | [diff] [blame] | 5675 | bool ChromeContentBrowserClient::IsBuiltinComponent( |
| 5676 | content::BrowserContext* browser_context, |
| 5677 | const url::Origin& origin) { |
| 5678 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5679 | return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent( |
| 5680 | browser_context, origin); |
| 5681 | #else |
| 5682 | return false; |
| 5683 | #endif |
| 5684 | } |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 5685 | |
Aaron Colwell | e1908d98 | 2020-06-26 22:08:15 | [diff] [blame] | 5686 | bool ChromeContentBrowserClient::ShouldBlockRendererDebugURL( |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 5687 | const GURL& url, |
| 5688 | content::BrowserContext* context) { |
Aaron Colwell | f94fd97a | 2020-07-21 19:37:08 | [diff] [blame] | 5689 | PolicyBlocklistService* service = |
| 5690 | PolicyBlocklistFactory::GetForBrowserContext(context); |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 5691 | |
Aaron Colwell | f94fd97a | 2020-07-21 19:37:08 | [diff] [blame] | 5692 | using URLBlocklistState = policy::URLBlocklist::URLBlocklistState; |
| 5693 | URLBlocklistState blocklist_state = service->GetURLBlocklistState(url); |
| 5694 | return blocklist_state == URLBlocklistState::URL_IN_BLOCKLIST; |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 5695 | } |
Dominic Mazzoni | 21fb028 | 2019-02-13 18:32:47 | [diff] [blame] | 5696 | |
| 5697 | ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext( |
| 5698 | content::BrowserContext* browser_context) { |
| 5699 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 5700 | return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode(); |
| 5701 | } |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5702 | |
| 5703 | #if defined(OS_ANDROID) |
| 5704 | content::ContentBrowserClient::WideColorGamutHeuristic |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5705 | ChromeContentBrowserClient::GetWideColorGamutHeuristic() { |
Chris Blume | 7f752e3 | 2020-02-14 22:22:33 | [diff] [blame] | 5706 | if (viz::AlwaysUseWideColorGamut() || |
Chris Blume | 5b36a01a | 2020-03-13 21:35:42 | [diff] [blame] | 5707 | features::IsDynamicColorGamutEnabled()) { |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5708 | return WideColorGamutHeuristic::kUseDisplay; |
| 5709 | } |
Khushal | 1fc0da5 | 2019-10-09 00:38:56 | [diff] [blame] | 5710 | |
| 5711 | if (display::Display::HasForceDisplayColorProfile() && |
| 5712 | display::Display::GetForcedDisplayColorProfile() == |
| 5713 | gfx::ColorSpace::CreateDisplayP3D65()) { |
| 5714 | return WideColorGamutHeuristic::kUseDisplay; |
| 5715 | } |
| 5716 | |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5717 | return WideColorGamutHeuristic::kNone; |
| 5718 | } |
| 5719 | #endif |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5720 | |
| 5721 | base::flat_set<std::string> |
Ehsan Karamad | 466529d | 2019-05-24 03:24:43 | [diff] [blame] | 5722 | ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers( |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 5723 | content::BrowserContext* browser_context) { |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5724 | base::flat_set<std::string> mime_types; |
| 5725 | #if BUILDFLAG(ENABLE_PLUGINS) |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 5726 | auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context); |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5727 | for (const auto& pair : map) |
| 5728 | mime_types.insert(pair.first); |
| 5729 | #endif |
| 5730 | return mime_types; |
| 5731 | } |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5732 | |
| 5733 | void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy( |
Alex Turner | 5d3dd257 | 2020-12-16 18:08:05 | [diff] [blame] | 5734 | content::WebContents* web_contents, |
| 5735 | content::RenderFrameHost* frame_host, |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5736 | bool user_gesture, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5737 | content::NavigationDownloadPolicy* download_policy) { |
Colin Blundell | 0ec5d64 | 2020-10-06 17:29:52 | [diff] [blame] | 5738 | const auto* throttle_manager = subresource_filter:: |
| 5739 | ContentSubresourceFilterThrottleManager::FromWebContents(web_contents); |
| 5740 | if (throttle_manager && throttle_manager->IsFrameTaggedAsAd(frame_host)) { |
Yao Xiao | f6064666 | 2019-07-25 07:25:04 | [diff] [blame] | 5741 | download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame); |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5742 | if (!user_gesture) { |
| 5743 | if (base::FeatureList::IsEnabled( |
| 5744 | blink::features:: |
| 5745 | kBlockingDownloadsInAdFrameWithoutUserActivation)) { |
| 5746 | download_policy->SetDisallowed( |
| 5747 | content::NavigationDownloadType::kAdFrameNoGesture); |
| 5748 | } else { |
| 5749 | download_policy->SetAllowed( |
| 5750 | content::NavigationDownloadType::kAdFrameNoGesture); |
| 5751 | } |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5752 | } |
| 5753 | } |
| 5754 | } |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5755 | |
Yao Xiao | ebed8c1 | 2020-09-26 07:51:20 | [diff] [blame] | 5756 | std::string ChromeContentBrowserClient::GetInterestCohortForJsApi( |
Yao Xiao | c5436ad | 2021-01-12 00:22:30 | [diff] [blame] | 5757 | content::WebContents* web_contents, |
Yao Xiao | 1e28cd4 | 2020-12-22 19:31:21 | [diff] [blame] | 5758 | const GURL& url, |
| 5759 | const base::Optional<url::Origin>& top_frame_origin) { |
Yao Xiao | c5436ad | 2021-01-12 00:22:30 | [diff] [blame] | 5760 | federated_learning::FlocEligibilityObserver::GetOrCreateForCurrentDocument( |
| 5761 | web_contents->GetMainFrame()) |
| 5762 | ->OnInterestCohortApiUsed(); |
| 5763 | |
Yao Xiao | ebed8c1 | 2020-09-26 07:51:20 | [diff] [blame] | 5764 | federated_learning::FlocIdProvider* floc_id_provider = |
| 5765 | federated_learning::FlocIdProviderFactory::GetForProfile( |
Yao Xiao | c5436ad | 2021-01-12 00:22:30 | [diff] [blame] | 5766 | Profile::FromBrowserContext(web_contents->GetBrowserContext())); |
Yao Xiao | ebed8c1 | 2020-09-26 07:51:20 | [diff] [blame] | 5767 | |
| 5768 | if (!floc_id_provider) |
| 5769 | return std::string(); |
| 5770 | |
Yao Xiao | 1e28cd4 | 2020-12-22 19:31:21 | [diff] [blame] | 5771 | return floc_id_provider->GetInterestCohortForJsApi(url, top_frame_origin); |
Yao Xiao | ebed8c1 | 2020-09-26 07:51:20 | [diff] [blame] | 5772 | } |
| 5773 | |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5774 | bool ChromeContentBrowserClient::IsBluetoothScanningBlocked( |
| 5775 | content::BrowserContext* browser_context, |
| 5776 | const url::Origin& requesting_origin, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5777 | const url::Origin& embedding_origin) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5778 | const HostContentSettingsMap* const content_settings = |
| 5779 | HostContentSettingsMapFactory::GetForProfile( |
| 5780 | Profile::FromBrowserContext(browser_context)); |
| 5781 | |
| 5782 | if (content_settings->GetContentSetting( |
| 5783 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
Illia Klimov | 48f643c | 2020-11-05 20:06:14 | [diff] [blame] | 5784 | ContentSettingsType::BLUETOOTH_SCANNING) == CONTENT_SETTING_BLOCK) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5785 | return true; |
| 5786 | } |
| 5787 | |
| 5788 | return false; |
| 5789 | } |
| 5790 | |
| 5791 | void ChromeContentBrowserClient::BlockBluetoothScanning( |
| 5792 | content::BrowserContext* browser_context, |
| 5793 | const url::Origin& requesting_origin, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5794 | const url::Origin& embedding_origin) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5795 | HostContentSettingsMap* const content_settings = |
| 5796 | HostContentSettingsMapFactory::GetForProfile( |
| 5797 | Profile::FromBrowserContext(browser_context)); |
| 5798 | |
| 5799 | content_settings->SetContentSettingDefaultScope( |
| 5800 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
Illia Klimov | 48f643c | 2020-11-05 20:06:14 | [diff] [blame] | 5801 | ContentSettingsType::BLUETOOTH_SCANNING, CONTENT_SETTING_BLOCK); |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5802 | } |
Tibor Goldschwendt | bf1b96e | 2019-10-07 22:03:47 | [diff] [blame] | 5803 | |
Clark DuVall | 1635a6b0 | 2020-11-06 18:53:51 | [diff] [blame] | 5804 | bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile( |
| 5805 | std::string* split_name) { |
Tibor Goldschwendt | bf1b96e | 2019-10-07 22:03:47 | [diff] [blame] | 5806 | #if defined(OS_ANDROID) |
Clark DuVall | 1635a6b0 | 2020-11-06 18:53:51 | [diff] [blame] | 5807 | *split_name = "extra_icu"; |
Tibor Goldschwendt | bf1b96e | 2019-10-07 22:03:47 | [diff] [blame] | 5808 | return extra_icu::ModuleProvider::IsModuleInstalled(); |
| 5809 | #endif |
| 5810 | return false; |
| 5811 | } |
Guido Urdaneta | 4030d6a3 | 2019-10-17 09:38:16 | [diff] [blame] | 5812 | |
| 5813 | bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed( |
| 5814 | content::BrowserContext* browser_context, |
| 5815 | const GURL& url, |
| 5816 | const GURL& site_for_cookies, |
| 5817 | const base::Optional<url::Origin>& top_frame_origin) { |
| 5818 | // Persistent MediaDevice IDs are allowed if cookies are allowed. |
| 5819 | return CookieSettingsFactory::GetForProfile( |
| 5820 | Profile::FromBrowserContext(browser_context)) |
| 5821 | ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin); |
| 5822 | } |
Sam Goto | 5cf068e8 | 2019-11-04 23:08:44 | [diff] [blame] | 5823 | |
| 5824 | #if !defined(OS_ANDROID) |
| 5825 | void ChromeContentBrowserClient::FetchRemoteSms( |
| 5826 | content::BrowserContext* browser_context, |
| 5827 | const url::Origin& origin, |
| 5828 | base::OnceCallback<void(base::Optional<std::string>)> callback) { |
| 5829 | ::FetchRemoteSms(browser_context, origin, std::move(callback)); |
| 5830 | } |
| 5831 | #endif |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 5832 | |
| 5833 | void ChromeContentBrowserClient::IsClipboardPasteAllowed( |
| 5834 | content::WebContents* web_contents, |
| 5835 | const GURL& url, |
| 5836 | const ui::ClipboardFormatType& data_type, |
| 5837 | const std::string& data, |
| 5838 | IsClipboardPasteAllowedCallback callback) { |
| 5839 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
| 5840 | // Safe browsing does not support images, so accept without checking. |
| 5841 | // TODO(crbug.com/1013584): check policy on what to do about unsupported |
| 5842 | // types when it is implemented. |
Darwin Huang | 0024dbf | 2020-08-04 00:53:55 | [diff] [blame] | 5843 | if (data_type == ui::ClipboardFormatType::GetBitmapType()) { |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 5844 | std::move(callback).Run(ClipboardPasteAllowed(true)); |
| 5845 | return; |
| 5846 | } |
| 5847 | |
| 5848 | Profile* profile = |
| 5849 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Dominique Fauteux-Chapleau | 7191299 | 2020-10-22 18:15:37 | [diff] [blame] | 5850 | enterprise_connectors::ContentAnalysisDelegate::Data dialog_data; |
| 5851 | if (enterprise_connectors::ContentAnalysisDelegate::IsEnabled( |
Dominique Fauteux-Chapleau | c08c8c96 | 2020-05-07 18:46:26 | [diff] [blame] | 5852 | profile, url, &dialog_data, |
| 5853 | enterprise_connectors::AnalysisConnector::BULK_DATA_ENTRY)) { |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 5854 | dialog_data.text.push_back(base::UTF8ToUTF16(data)); |
Dominique Fauteux-Chapleau | 7191299 | 2020-10-22 18:15:37 | [diff] [blame] | 5855 | enterprise_connectors::ContentAnalysisDelegate::CreateForWebContents( |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 5856 | web_contents, std::move(dialog_data), |
| 5857 | base::BindOnce( |
| 5858 | [](IsClipboardPasteAllowedCallback callback, |
Dominique Fauteux-Chapleau | 7191299 | 2020-10-22 18:15:37 | [diff] [blame] | 5859 | const enterprise_connectors::ContentAnalysisDelegate::Data& data, |
| 5860 | const enterprise_connectors::ContentAnalysisDelegate::Result& |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 5861 | result) { |
| 5862 | std::move(callback).Run( |
| 5863 | ClipboardPasteAllowed(result.text_results[0])); |
| 5864 | }, |
Dominique Fauteux-Chapleau | 5b14716 | 2020-01-17 17:08:24 | [diff] [blame] | 5865 | std::move(callback)), |
| 5866 | safe_browsing::DeepScanAccessPoint::PASTE); |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 5867 | } else { |
| 5868 | std::move(callback).Run(ClipboardPasteAllowed(true)); |
| 5869 | } |
| 5870 | #else |
| 5871 | std::move(callback).Run(ClipboardPasteAllowed(true)); |
| 5872 | #endif // BUILDFLAG(FULL_SAFE_BROWSING) |
| 5873 | } |
Lukasz Anforowicz | 4600ea3 | 2020-01-18 02:37:48 | [diff] [blame] | 5874 | |
| 5875 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 5876 | bool ChromeContentBrowserClient::ShouldAllowPluginCreation( |
| 5877 | const url::Origin& embedder_origin, |
| 5878 | const content::PepperPluginInfo& plugin_info) { |
| 5879 | #if BUILDFLAG(ENABLE_PDF) |
| 5880 | if (plugin_info.name == ChromeContentClient::kPDFInternalPluginName) { |
| 5881 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5882 | // Allow embedding the internal PDF plugin in the built-in PDF extension. |
| 5883 | if (embedder_origin.scheme() == extensions::kExtensionScheme && |
| 5884 | embedder_origin.host() == extension_misc::kPdfExtensionId) { |
| 5885 | return true; |
| 5886 | } |
| 5887 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 5888 | |
| 5889 | // Allow embedding the internal PDF plugin in chrome://print. |
| 5890 | if (embedder_origin == url::Origin::Create(GURL(chrome::kChromeUIPrintURL))) |
| 5891 | return true; |
| 5892 | |
| 5893 | // Only allow the PDF plugin in the known, trustworthy origins that are |
| 5894 | // allowlisted above. See also https://crbug.com/520422 and |
| 5895 | // https://crbug.com/1027173. |
| 5896 | return false; |
| 5897 | } |
| 5898 | #endif // BUILDFLAG(ENABLE_PDF) |
| 5899 | |
| 5900 | return true; |
| 5901 | } |
| 5902 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
Alexander Cooper | c844870 | 2020-03-14 01:39:56 | [diff] [blame] | 5903 | |
| 5904 | #if BUILDFLAG(ENABLE_VR) |
| 5905 | content::XrIntegrationClient* |
| 5906 | ChromeContentBrowserClient::GetXrIntegrationClient() { |
| 5907 | if (!xr_integration_client_) |
| 5908 | xr_integration_client_ = std::make_unique<vr::ChromeXrIntegrationClient>( |
Peter Kasting | 796cde2 | 2020-11-18 21:06:53 | [diff] [blame] | 5909 | base::PassKey<ChromeContentBrowserClient>()); |
Alexander Cooper | c844870 | 2020-03-14 01:39:56 | [diff] [blame] | 5910 | return xr_integration_client_.get(); |
| 5911 | } |
| 5912 | #endif // BUILDFLAG(ENABLE_VR) |
Adrienne Walker | 29765129 | 2020-05-08 00:23:18 | [diff] [blame] | 5913 | |
| 5914 | bool ChromeContentBrowserClient::IsOriginTrialRequiredForAppCache( |
| 5915 | content::BrowserContext* browser_context) { |
| 5916 | auto* profile = Profile::FromBrowserContext(browser_context); |
| 5917 | auto* prefs = profile->GetPrefs(); |
| 5918 | |
| 5919 | if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) && |
| 5920 | prefs->GetBoolean(prefs::kAppCacheForceEnabled)) { |
| 5921 | return false; |
| 5922 | } |
| 5923 | if (base::FeatureList::IsEnabled( |
| 5924 | blink::features::kAppCacheRequireOriginTrial)) { |
| 5925 | return true; |
| 5926 | } |
| 5927 | |
| 5928 | return false; |
| 5929 | } |
Yutaka Hirano | 3e61366 | 2020-06-02 02:59:34 | [diff] [blame] | 5930 | |
Hidehiko Abe | eaffbbce | 2020-06-23 19:41:52 | [diff] [blame] | 5931 | void ChromeContentBrowserClient::BindBrowserControlInterface( |
Hidehiko Abe | 23e45e8 | 2020-08-25 08:41:48 | [diff] [blame] | 5932 | mojo::ScopedMessagePipeHandle pipe) { |
Yuta Hijikata | 235fc62b | 2020-12-08 03:48:32 | [diff] [blame] | 5933 | #if BUILDFLAG(IS_CHROMEOS_LACROS) |
Hidehiko Abe | 23e45e8 | 2020-08-25 08:41:48 | [diff] [blame] | 5934 | chromeos::LacrosChromeServiceImpl::Get()->BindReceiver( |
Hidehiko Abe | 67fb6a8 | 2021-01-21 07:50:36 | [diff] [blame] | 5935 | mojo::PendingReceiver<crosapi::mojom::BrowserService>(std::move(pipe))); |
Hidehiko Abe | eaffbbce | 2020-06-23 19:41:52 | [diff] [blame] | 5936 | #endif |
| 5937 | } |
| 5938 | |
Yutaka Hirano | 3e61366 | 2020-06-02 02:59:34 | [diff] [blame] | 5939 | bool ChromeContentBrowserClient:: |
| 5940 | ShouldInheritCrossOriginEmbedderPolicyImplicitly(const GURL& url) { |
| 5941 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5942 | return url.SchemeIs(extensions::kExtensionScheme); |
| 5943 | #else |
| 5944 | return false; |
| 5945 | #endif |
| 5946 | } |
John Abd-El-Malek | dc02601 | 2020-06-15 23:28:56 | [diff] [blame] | 5947 | |
Titouan Rigoudy | cfc7355 | 2020-08-21 14:18:30 | [diff] [blame] | 5948 | bool ChromeContentBrowserClient::ShouldAllowInsecurePrivateNetworkRequests( |
Titouan Rigoudy | 9c2c014 | 2020-08-19 17:57:12 | [diff] [blame] | 5949 | content::BrowserContext* browser_context, |
Titouan Rigoudy | ce223ab | 2021-01-27 16:08:02 | [diff] [blame] | 5950 | const url::Origin& origin) { |
Titouan Rigoudy | cfc7355 | 2020-08-21 14:18:30 | [diff] [blame] | 5951 | return content_settings::ShouldAllowInsecurePrivateNetworkRequests( |
Titouan Rigoudy | ce223ab | 2021-01-27 16:08:02 | [diff] [blame] | 5952 | HostContentSettingsMapFactory::GetForProfile(browser_context), origin); |
Titouan Rigoudy | 9c2c014 | 2020-08-19 17:57:12 | [diff] [blame] | 5953 | } |
| 5954 | |
John Abd-El-Malek | dc02601 | 2020-06-15 23:28:56 | [diff] [blame] | 5955 | ukm::UkmService* ChromeContentBrowserClient::GetUkmService() { |
| 5956 | return g_browser_process->GetMetricsServicesManager()->GetUkmService(); |
| 5957 | } |
Evan Liu | 054dc08 | 2020-09-30 14:09:42 | [diff] [blame] | 5958 | |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 5959 | void ChromeContentBrowserClient::OnKeepaliveRequestStarted() { |
| 5960 | #if !defined(OS_ANDROID) |
| 5961 | if (base::FeatureList::IsEnabled(features::kShutdownSupportForKeepalive)) { |
Yutaka Hirano | 311a741 | 2021-01-06 06:17:35 | [diff] [blame] | 5962 | // TODO(crbug.com/1161996): Remove this entry once the investigation is |
| 5963 | // done. |
| 5964 | VLOG(1) << "OnKeepaliveRequestStarted: " << num_keepalive_requests_ |
| 5965 | << " ==> " << num_keepalive_requests_ + 1; |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 5966 | ++num_keepalive_requests_; |
| 5967 | |
| 5968 | DCHECK_GT(num_keepalive_requests_, 0u); |
| 5969 | last_keepalive_request_time_ = base::TimeTicks::Now(); |
| 5970 | if (!keepalive_timer_.IsRunning()) { |
Yutaka Hirano | 311a741 | 2021-01-06 06:17:35 | [diff] [blame] | 5971 | const auto timeout = GetKeepaliveTimerTimeout(); |
| 5972 | // TODO(crbug.com/1161996): Remove this entry once the investigation is |
| 5973 | // done. |
| 5974 | VLOG(1) << "Starting a keepalive timer(" << timeout.InSecondsF() |
| 5975 | << " seconds)"; |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 5976 | keepalive_timer_.Start( |
Yutaka Hirano | 311a741 | 2021-01-06 06:17:35 | [diff] [blame] | 5977 | FROM_HERE, timeout, |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 5978 | base::BindOnce( |
| 5979 | &ChromeContentBrowserClient::OnKeepaliveTimerFired, |
| 5980 | weak_factory_.GetWeakPtr(), |
| 5981 | std::make_unique<ScopedKeepAlive>( |
| 5982 | KeepAliveOrigin::BROWSER, KeepAliveRestartOption::DISABLED))); |
| 5983 | } |
| 5984 | } |
| 5985 | #endif // !defined(OS_ANDROID) |
| 5986 | } |
| 5987 | |
| 5988 | void ChromeContentBrowserClient::OnKeepaliveRequestFinished() { |
| 5989 | #if !defined(OS_ANDROID) |
| 5990 | if (base::FeatureList::IsEnabled(features::kShutdownSupportForKeepalive)) { |
| 5991 | DCHECK_GT(num_keepalive_requests_, 0u); |
Yutaka Hirano | 311a741 | 2021-01-06 06:17:35 | [diff] [blame] | 5992 | // TODO(crbug.com/1161996): Remove this entry once the investigation is |
| 5993 | // done. |
| 5994 | VLOG(1) << "OnKeepaliveRequestFinished: " << num_keepalive_requests_ |
| 5995 | << " ==> " << num_keepalive_requests_ - 1; |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 5996 | --num_keepalive_requests_; |
| 5997 | if (num_keepalive_requests_ == 0) { |
Yutaka Hirano | 311a741 | 2021-01-06 06:17:35 | [diff] [blame] | 5998 | // TODO(crbug.com/1161996): Remove this entry once the investigation is |
| 5999 | // done. |
| 6000 | VLOG(1) << "Stopping the keepalive timer"; |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 6001 | keepalive_timer_.Stop(); |
| 6002 | // This deletes the keep alive handle attached to the timer function and |
| 6003 | // unblock the shutdown sequence. |
| 6004 | } |
| 6005 | } |
| 6006 | #endif // !defined(OS_ANDROID) |
| 6007 | } |
| 6008 | |
Evan Liu | 054dc08 | 2020-09-30 14:09:42 | [diff] [blame] | 6009 | #if defined(OS_MAC) |
| 6010 | bool ChromeContentBrowserClient::SetupEmbedderSandboxParameters( |
| 6011 | sandbox::policy::SandboxType sandbox_type, |
| 6012 | sandbox::SeatbeltExecClient* client) { |
| 6013 | if (sandbox_type == sandbox::policy::SandboxType::kSpeechRecognition) { |
| 6014 | base::FilePath soda_component_path = speech::GetSodaDirectory(); |
| 6015 | CHECK(!soda_component_path.empty()); |
| 6016 | CHECK(client->SetParameter( |
| 6017 | sandbox::policy::SandboxMac::kSandboxSodaComponentPath, |
| 6018 | soda_component_path.value())); |
| 6019 | |
| 6020 | base::FilePath soda_language_pack_path = |
| 6021 | speech::GetSodaLanguagePacksDirectory(); |
| 6022 | CHECK(!soda_language_pack_path.empty()); |
| 6023 | CHECK(client->SetParameter( |
| 6024 | sandbox::policy::SandboxMac::kSandboxSodaLanguagePackPath, |
| 6025 | soda_language_pack_path.value())); |
| 6026 | return true; |
| 6027 | } |
| 6028 | |
| 6029 | return false; |
| 6030 | } |
| 6031 | |
| 6032 | #endif // defined(OS_MAC) |
Koji Ishii | 3cbd93a | 2020-10-16 13:48:02 | [diff] [blame] | 6033 | |
| 6034 | void ChromeContentBrowserClient::GetHyphenationDictionary( |
| 6035 | base::OnceCallback<void(const base::FilePath&)> callback) { |
| 6036 | #if BUILDFLAG(USE_MINIKIN_HYPHENATION) && !defined(OS_ANDROID) |
| 6037 | component_updater::HyphenationComponentInstallerPolicy:: |
| 6038 | GetHyphenationDictionary(std::move(callback)); |
| 6039 | #endif |
| 6040 | } |
Rakina Zata Amni | ba3eecb | 2020-11-02 10:12:28 | [diff] [blame] | 6041 | |
| 6042 | bool ChromeContentBrowserClient::HasErrorPage(int http_status_code) { |
| 6043 | // Use an internal error page, if we have one for the status code. |
| 6044 | return error_page::LocalizedError::HasStrings( |
| 6045 | error_page::Error::kHttpErrorDomain, http_status_code); |
| 6046 | } |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 6047 | |
Ken Buchanan | 7d68835 | 2020-12-05 05:45:57 | [diff] [blame] | 6048 | std::unique_ptr<content::IdentityRequestDialogController> |
| 6049 | ChromeContentBrowserClient::CreateIdentityRequestDialogController() { |
| 6050 | return std::make_unique<IdentityDialogController>(); |
| 6051 | } |
| 6052 | |
Reid Kleckner | 4d3f21c | 2021-01-25 22:48:31 | [diff] [blame] | 6053 | #if !defined(OS_ANDROID) |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 6054 | void ChromeContentBrowserClient::OnKeepaliveTimerFired( |
| 6055 | std::unique_ptr<ScopedKeepAlive> keep_alive_handle) { |
Yutaka Hirano | 311a741 | 2021-01-06 06:17:35 | [diff] [blame] | 6056 | // TODO(crbug.com/1161996): Remove this entry once the investigation is done. |
| 6057 | VLOG(1) << "OnKeepaliveTimerFired"; |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 6058 | DCHECK(base::FeatureList::IsEnabled(features::kShutdownSupportForKeepalive)); |
| 6059 | const auto now = base::TimeTicks::Now(); |
Yutaka Hirano | 311a741 | 2021-01-06 06:17:35 | [diff] [blame] | 6060 | const auto then = last_keepalive_request_time_ + GetKeepaliveTimerTimeout(); |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 6061 | if (now < then) { |
Yutaka Hirano | 311a741 | 2021-01-06 06:17:35 | [diff] [blame] | 6062 | // TODO(crbug.com/1161996): Remove this entry once the investigation is |
| 6063 | // done. |
| 6064 | VLOG(1) << "Extending keepalive timer"; |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 6065 | keepalive_timer_.Start( |
| 6066 | FROM_HERE, then - now, |
| 6067 | base::BindOnce(&ChromeContentBrowserClient::OnKeepaliveTimerFired, |
| 6068 | weak_factory_.GetWeakPtr(), |
| 6069 | std::move(keep_alive_handle))); |
| 6070 | } |
Yutaka Hirano | 93e92474 | 2020-11-11 10:40:13 | [diff] [blame] | 6071 | } |
Reid Kleckner | 4d3f21c | 2021-01-25 22:48:31 | [diff] [blame] | 6072 | #endif |