[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" |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 15 | #include "base/bind_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" |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 18 | #include "base/files/file_util.h" |
morrita | d95714f | 2014-10-01 02:37:24 | [diff] [blame] | 19 | #include "base/files/scoped_file.h" |
Marc Treib | ad33cf94 | 2017-08-24 11:19:00 | [diff] [blame] | 20 | #include "base/i18n/base_i18n_switches.h" |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 21 | #include "base/i18n/character_encoding.h" |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 22 | #include "base/macros.h" |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 23 | #include "base/metrics/field_trial_params.h" |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 24 | #include "base/metrics/histogram_macros.h" |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 25 | #include "base/no_destructor.h" |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 26 | #include "base/path_service.h" |
Gabriel Charette | e926fc1 | 2019-12-16 19:00:02 | [diff] [blame] | 27 | #include "base/sequenced_task_runner.h" |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 28 | #include "base/stl_util.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" |
James Cook | 26d2712 | 2020-06-26 19:57:07 | [diff] [blame] | 39 | #include "build/lacros_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" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 46 | #include "chrome/browser/browser_process.h" |
msramek | 1c2b3ca | 2017-03-14 17:57:56 | [diff] [blame] | 47 | #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
Colin Blundell | 111b61c0 | 2020-01-24 11:53:51 | [diff] [blame] | 48 | #include "chrome/browser/captive_portal/captive_portal_service_factory.h" |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 49 | #include "chrome/browser/chrome_content_browser_client_parts.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 50 | #include "chrome/browser/content_settings/cookie_settings_factory.h" |
peconn | 5100d43 | 2015-09-16 12:03:08 | [diff] [blame] | 51 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
Robbie McElrath | 1294d24 | 2019-05-31 20:46:22 | [diff] [blame] | 52 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 53 | #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
Zhuoyu Qian | cb197638 | 2018-12-13 02:18:30 | [diff] [blame] | 54 | #include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h" |
| 55 | #include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h" |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 56 | #include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h" |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 57 | #include "chrome/browser/defaults.h" |
Marijn Kruisselbrink | efe0bef6 | 2020-07-21 22:44:59 | [diff] [blame] | 58 | #include "chrome/browser/download/chrome_download_manager_delegate.h" |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 59 | #include "chrome/browser/download/download_prefs.h" |
Lily Chen | c2c9e9f | 2019-12-05 19:55:31 | [diff] [blame] | 60 | #include "chrome/browser/engagement/site_engagement_service.h" |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 61 | #include "chrome/browser/extensions/chrome_extension_cookies.h" |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 62 | #include "chrome/browser/external_protocol/external_protocol_handler.h" |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 63 | #include "chrome/browser/font_family_cache.h" |
Peng Huang | 71d398ed | 2020-02-28 01:30:53 | [diff] [blame] | 64 | #include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h" |
Matt Reynolds | 93616f9b | 2019-06-07 01:28:52 | [diff] [blame] | 65 | #include "chrome/browser/hid/chrome_hid_delegate.h" |
Colin Blundell | eaa7377bf | 2020-01-22 08:49:10 | [diff] [blame] | 66 | #include "chrome/browser/interstitials/enterprise_util.h" |
Avi Drissman | d3092734 | 2018-05-22 15:04:27 | [diff] [blame] | 67 | #include "chrome/browser/lifetime/browser_shutdown.h" |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 68 | #include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h" |
Guido Urdaneta | e02b572 | 2020-07-22 05:58:21 | [diff] [blame] | 69 | #include "chrome/browser/media/audio_service_util.h" |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 70 | #include "chrome/browser/media/router/media_router_feature.h" |
Derek Cheng | eb64b19a | 2018-01-02 20:20:42 | [diff] [blame] | 71 | #include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h" |
| 72 | #include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h" |
Patrik Höglund | b564859b | 2018-05-17 11:17:16 | [diff] [blame] | 73 | #include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h" |
mcasas | a2023ab | 2016-09-08 01:06:36 | [diff] [blame] | 74 | #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
Darin Fisher | 09aa722 | 2019-08-29 09:27:36 | [diff] [blame] | 75 | #include "chrome/browser/media/webrtc/webrtc_logging_controller.h" |
Sebastien Marchand | 8c008810 | 2019-10-11 16:47:56 | [diff] [blame] | 76 | #include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h" |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 77 | #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 78 | #include "chrome/browser/metrics/chrome_feature_list_creator.h" |
[email protected] | a2b4c5c | 2013-10-18 02:06:07 | [diff] [blame] | 79 | #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h" |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 80 | #include "chrome/browser/net/chrome_network_delegate.h" |
David Benjamin | f6a3409 | 2019-11-07 19:55:10 | [diff] [blame] | 81 | #include "chrome/browser/net/profile_network_context_service.h" |
| 82 | #include "chrome/browser/net/profile_network_context_service_factory.h" |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 83 | #include "chrome/browser/net/system_network_context_manager.h" |
Richard Knoll | d0eae96 | 2019-04-04 12:34:02 | [diff] [blame] | 84 | #include "chrome/browser/notifications/platform_notification_service_factory.h" |
peter | c26c6c6 | 2014-12-10 14:13:59 | [diff] [blame] | 85 | #include "chrome/browser/notifications/platform_notification_service_impl.h" |
leon.han | 952ea325 | 2016-04-13 02:44:56 | [diff] [blame] | 86 | #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 87 | #include "chrome/browser/payments/payment_request_display_manager_factory.h" |
Sigurdur Asgeirsson | 54b7270 | 2019-04-12 14:18:54 | [diff] [blame] | 88 | #include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h" |
Sigurdur Asgeirsson | 7069667 | 2019-02-08 16:14:51 | [diff] [blame] | 89 | #include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h" |
Adam Langley | 85339f6 | 2018-02-12 22:03:56 | [diff] [blame] | 90 | #include "chrome/browser/permissions/attestation_permission_request.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 91 | #include "chrome/browser/platform_util.h" |
Amber Won | 94afd811 | 2017-08-23 17:30:11 | [diff] [blame] | 92 | #include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h" |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 93 | #include "chrome/browser/plugins/plugin_utils.h" |
Mugdha Lakhani | 2c6b23af | 2020-07-31 14:55:57 | [diff] [blame] | 94 | #include "chrome/browser/prerender/chrome_prerender_contents_delegate.h" |
Robert Ogden | ea4ea739 | 2020-01-25 01:44:53 | [diff] [blame] | 95 | #include "chrome/browser/prerender/isolated/isolated_prerender_features.h" |
Robert Ogden | 31b23471 | 2020-06-04 22:51:21 | [diff] [blame] | 96 | #include "chrome/browser/prerender/isolated/isolated_prerender_service.h" |
| 97 | #include "chrome/browser/prerender/isolated/isolated_prerender_service_factory.h" |
Robert Ogden | 6946ad4 | 2020-01-13 18:01:30 | [diff] [blame] | 98 | #include "chrome/browser/prerender/isolated/isolated_prerender_url_loader_interceptor.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 99 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
Ryan Sturm | cc5071be | 2019-02-16 02:15:19 | [diff] [blame] | 100 | #include "chrome/browser/previews/previews_content_util.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 101 | #include "chrome/browser/previews/previews_service.h" |
| 102 | #include "chrome/browser/previews/previews_service_factory.h" |
| 103 | #include "chrome/browser/previews/previews_ui_tab_helper.h" |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 104 | #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 105 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 106 | #include "chrome/browser/profiles/profile_io_data.h" |
Ken Rockot | 4e284d3 | 2020-03-06 06:26:49 | [diff] [blame] | 107 | #include "chrome/browser/profiles/profile_manager.h" |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 108 | #include "chrome/browser/profiles/renderer_updater.h" |
| 109 | #include "chrome/browser/profiles/renderer_updater_factory.h" |
Erik Chen | 49bbfa2 | 2017-08-18 08:49:56 | [diff] [blame] | 110 | #include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h" |
| 111 | #include "chrome/browser/profiling_host/profiling_process_host.h" |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 112 | #include "chrome/browser/renderer_host/chrome_navigation_ui_data.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 113 | #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 114 | #include "chrome/browser/renderer_preferences_util.h" |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 115 | #include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h" |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 116 | #include "chrome/browser/safe_browsing/certificate_reporting_service.h" |
| 117 | #include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h" |
Xinghui Lu | f45d7ef7 | 2020-06-09 02:16:38 | [diff] [blame] | 118 | #include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service.h" |
| 119 | #include "chrome/browser/safe_browsing/chrome_enterprise_url_lookup_service_factory.h" |
Dominique Fauteux-Chapleau | 5b14716 | 2020-01-17 17:08:24 | [diff] [blame] | 120 | #include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_utils.h" |
Mustafa Emre Acer | 97be475 | 2020-05-13 01:24:43 | [diff] [blame] | 121 | #include "chrome/browser/safe_browsing/delayed_warning_navigation_throttle.h" |
Carlos IL | 4ee307e | 2018-12-22 03:19:00 | [diff] [blame] | 122 | #include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h" |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 123 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 124 | #include "chrome/browser/safe_browsing/ui_manager.h" |
| 125 | #include "chrome/browser/safe_browsing/url_checker_delegate_impl.h" |
Xinghui Lu | e17b1994 | 2020-02-24 21:19:58 | [diff] [blame] | 126 | #include "chrome/browser/safe_browsing/url_lookup_service_factory.h" |
[email protected] | a7b8e43d | 2013-03-18 18:52:43 | [diff] [blame] | 127 | #include "chrome/browser/search/search.h" |
Sam Goto | 5cf068e8 | 2019-11-04 23:08:44 | [diff] [blame] | 128 | #include "chrome/browser/sharing/sms/sms_remote_fetcher.h" |
Reilly Grant | cc22e60 | 2018-09-07 15:25:20 | [diff] [blame] | 129 | #include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h" |
Reilly Grant | 3787780 | 2018-08-18 00:58:35 | [diff] [blame] | 130 | #include "chrome/browser/signin/chrome_signin_url_loader_throttle.h" |
Robbie McElrath | 38f47af | 2019-09-19 21:51:40 | [diff] [blame] | 131 | #include "chrome/browser/signin/header_modification_delegate_impl.h" |
David Roger | e8e83f3c | 2019-09-12 10:56:23 | [diff] [blame] | 132 | #include "chrome/browser/signin/identity_manager_factory.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 133 | #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" |
Colin Blundell | 13e92ec | 2020-01-27 09:47:38 | [diff] [blame] | 134 | #include "chrome/browser/ssl/chrome_security_blocking_page_factory.h" |
Chris Thompson | e2e073d4 | 2020-07-23 12:33:45 | [diff] [blame] | 135 | #include "chrome/browser/ssl/sct_reporting_service.h" |
| 136 | #include "chrome/browser/ssl/sct_reporting_service_factory.h" |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 137 | #include "chrome/browser/ssl/ssl_client_auth_metrics.h" |
[email protected] | 25af6ec | 2014-06-06 19:35:07 | [diff] [blame] | 138 | #include "chrome/browser/ssl/ssl_client_certificate_selector.h" |
csharrison | 77bf834 | 2017-05-04 18:23:10 | [diff] [blame] | 139 | #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" |
meacer | 4ef065e | 2015-01-09 03:21:35 | [diff] [blame] | 140 | #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 141 | #include "chrome/browser/tab_contents/tab_util.h" |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 142 | #include "chrome/browser/tracing/chrome_tracing_delegate.h" |
Dave Tapuska | c6627e1 | 2018-08-30 15:07:19 | [diff] [blame] | 143 | #include "chrome/browser/translate/translate_service.h" |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 144 | #include "chrome/browser/ui/blocked_content/blocked_window_params.h" |
Clark DuVall | 8a020d62 | 2020-06-04 00:45:50 | [diff] [blame] | 145 | #include "chrome/browser/ui/blocked_content/chrome_popup_navigation_delegate.h" |
Charles Harrison | 6dd11d28 | 2017-10-03 06:14:51 | [diff] [blame] | 146 | #include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h" |
thestig | e8082124 | 2015-09-30 23:46:08 | [diff] [blame] | 147 | #include "chrome/browser/ui/browser_navigator.h" |
| 148 | #include "chrome/browser/ui/browser_navigator_params.h" |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 149 | #include "chrome/browser/ui/chrome_select_file_policy.h" |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 150 | #include "chrome/browser/ui/login/login_handler.h" |
Emily Stark | d6896cd3 | 2019-08-21 04:55:54 | [diff] [blame] | 151 | #include "chrome/browser/ui/login/login_navigation_throttle.h" |
Emily Stark | 63c884f | 2020-05-12 03:55:28 | [diff] [blame] | 152 | #include "chrome/browser/ui/login/login_tab_helper.h" |
Jonathan Mengedoht | 42a19bb | 2020-07-28 14:10:16 | [diff] [blame] | 153 | #include "chrome/browser/ui/passwords/well_known_change_password_navigation_throttle.h" |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 154 | #include "chrome/browser/ui/prefs/pref_watcher.h" |
[email protected] | 329ac97 | 2013-06-21 15:24:25 | [diff] [blame] | 155 | #include "chrome/browser/ui/sync/sync_promo_ui.h" |
[email protected] | b5d7342 | 2012-06-02 23:46:44 | [diff] [blame] | 156 | #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h" |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 157 | #include "chrome/browser/ui/ui_features.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 158 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
dbeam | baee5bd | 2015-09-26 03:07:01 | [diff] [blame] | 159 | #include "chrome/browser/ui/webui/log_web_ui_url.h" |
[email protected] | 95ebe7c | 2020-04-08 19:12:45 | [diff] [blame] | 160 | #include "chrome/browser/usb/frame_usb_services.h" |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 161 | #include "chrome/browser/vr/vr_tab_helper.h" |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 162 | #include "chrome/browser/web_applications/components/app_registrar.h" |
Alan Cutter | 1797f46a | 2020-02-12 02:48:59 | [diff] [blame] | 163 | #include "chrome/browser/web_applications/components/web_app_provider_base.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 164 | #include "chrome/common/buildflags.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 165 | #include "chrome/common/channel_info.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 166 | #include "chrome/common/chrome_constants.h" |
Lukasz Anforowicz | 4600ea3 | 2020-01-18 02:37:48 | [diff] [blame] | 167 | #include "chrome/common/chrome_content_client.h" |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 168 | #include "chrome/common/chrome_features.h" |
[email protected] | a7944aa | 2012-10-15 10:12:14 | [diff] [blame] | 169 | #include "chrome/common/chrome_paths.h" |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 170 | #include "chrome/common/chrome_paths_internal.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 171 | #include "chrome/common/chrome_switches.h" |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 172 | #include "chrome/common/env_vars.h" |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 173 | #include "chrome/common/google_url_loader_throttle.h" |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 174 | #include "chrome/common/logging_chrome.h" |
[email protected] | 9d45049 | 2013-06-13 23:08:37 | [diff] [blame] | 175 | #include "chrome/common/pepper_permission_util.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 176 | #include "chrome/common/pref_names.h" |
Mike Wittman | 08b377d | 2019-11-27 21:06:32 | [diff] [blame] | 177 | #include "chrome/common/profiler/stack_sampling_configuration.h" |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 178 | #include "chrome/common/render_messages.h" |
nigeltao | 7cd8d558 | 2016-12-12 06:05:28 | [diff] [blame] | 179 | #include "chrome/common/renderer_configuration.mojom.h" |
Ayu Ishii | fbb1fad | 2020-06-22 20:15:07 | [diff] [blame] | 180 | #include "chrome/common/secure_origin_allowlist.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 181 | #include "chrome/common/url_constants.h" |
Peter Boström | 8e9b163 | 2019-08-22 23:12:47 | [diff] [blame] | 182 | #include "chrome/common/webui_url_constants.h" |
ben | c70c0e3 | 2016-09-22 03:50:37 | [diff] [blame] | 183 | #include "chrome/grit/browser_resources.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 184 | #include "chrome/grit/generated_resources.h" |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 185 | #include "chrome/installer/util/google_update_settings.h" |
brettw | f195891 | 2015-10-07 19:43:12 | [diff] [blame] | 186 | #include "components/autofill/core/common/autofill_switches.h" |
Clark DuVall | 8a020d62 | 2020-06-04 00:45:50 | [diff] [blame] | 187 | #include "components/blocked_content/popup_blocker.h" |
Clark DuVall | f518925 | 2020-04-15 22:33:34 | [diff] [blame] | 188 | #include "components/browsing_data/content/browsing_data_helper.h" |
msramek | 1c8e19d | 2017-01-04 20:04:53 | [diff] [blame] | 189 | #include "components/browsing_data/core/browsing_data_utils.h" |
Colin Blundell | 111b61c0 | 2020-01-24 11:53:51 | [diff] [blame] | 190 | #include "components/captive_portal/content/captive_portal_service.h" |
Colin Blundell | 7cf3fe3 | 2020-01-23 09:52:49 | [diff] [blame] | 191 | #include "components/captive_portal/core/buildflags.h" |
[email protected] | 649b5727 | 2014-05-09 14:54:44 | [diff] [blame] | 192 | #include "components/cdm/browser/cdm_message_filter_android.h" |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 193 | #include "components/certificate_matching/certificate_principal_pattern.h" |
[email protected] | 09cff7878 | 2014-04-20 22:04:48 | [diff] [blame] | 194 | #include "components/cloud_devices/common/cloud_devices_switches.h" |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 195 | #include "components/content_settings/browser/page_specific_content_settings.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 196 | #include "components/content_settings/core/browser/content_settings_utils.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 197 | #include "components/content_settings/core/browser/cookie_settings.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 198 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 199 | #include "components/content_settings/core/common/content_settings.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 200 | #include "components/content_settings/core/common/content_settings_types.h" |
tbansal | 08a0e3e | 2017-06-30 21:30:08 | [diff] [blame] | 201 | #include "components/content_settings/core/common/content_settings_utils.h" |
Daniel Vogelheim | 976f1c2 | 2017-11-22 16:26:03 | [diff] [blame] | 202 | #include "components/content_settings/core/common/pref_names.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 203 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h" |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 204 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h" |
rajendrant | 4319407 | 2019-04-15 22:13:43 | [diff] [blame] | 205 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h" |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 206 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
wychen | e5568734 | 2015-11-13 20:17:03 | [diff] [blame] | 207 | #include "components/dom_distiller/core/dom_distiller_switches.h" |
[email protected] | 474a5a3 | 2014-07-28 18:23:24 | [diff] [blame] | 208 | #include "components/dom_distiller/core/url_constants.h" |
Clark DuVall | 3d4e89b9 | 2020-04-03 23:07:32 | [diff] [blame] | 209 | #include "components/embedder_support/switches.h" |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 210 | #include "components/error_page/common/error_page_switches.h" |
Ken Rockot | 4408a0f | 2020-07-27 19:40:54 | [diff] [blame] | 211 | #include "components/error_page/content/browser/net_error_auto_reloader.h" |
khushalsagar | c5447db2 | 2017-08-22 17:53:01 | [diff] [blame] | 212 | #include "components/feature_engagement/public/feature_constants.h" |
| 213 | #include "components/feature_engagement/public/feature_list.h" |
John Abd-El-Malek | cdb5b52 | 2020-05-26 22:41:03 | [diff] [blame] | 214 | #include "components/google/core/common/google_switches.h" |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 215 | #include "components/language/core/browser/pref_names.h" |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 216 | #include "components/metrics/client_info.h" |
John Abd-El-Malek | dc02601 | 2020-06-15 23:28:56 | [diff] [blame] | 217 | #include "components/metrics_services_manager/metrics_services_manager.h" |
droger | c690e880 | 2015-09-21 14:29:16 | [diff] [blame] | 218 | #include "components/net_log/chrome_net_log.h" |
Tao Bai | b827b20 | 2019-09-19 21:22:12 | [diff] [blame] | 219 | #include "components/page_load_metrics/browser/metrics_navigation_throttle.h" |
| 220 | #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 221 | #include "components/payments/content/payment_request_display_manager.h" |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 222 | #include "components/performance_manager/embedder/performance_manager_registry.h" |
Clark DuVall | a11361ad3 | 2020-02-20 22:14:27 | [diff] [blame] | 223 | #include "components/permissions/permission_context_base.h" |
Scott Violet | 9389378 | 2020-03-27 16:23:54 | [diff] [blame] | 224 | #include "components/permissions/quota_permission_context_impl.h" |
Aaron Colwell | b422622 | 2020-07-25 16:11:36 | [diff] [blame] | 225 | #include "components/policy/content/policy_blocklist_navigation_throttle.h" |
| 226 | #include "components/policy/content/policy_blocklist_service.h" |
Chris Hamilton | 65c4131 | 2020-06-10 13:14:40 | [diff] [blame] | 227 | #include "components/policy/core/common/policy_pref_names.h" |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 228 | #include "components/policy/core/common/policy_service.h" |
| 229 | #include "components/policy/policy_constants.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 230 | #include "components/pref_registry/pref_registry_syncable.h" |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 231 | #include "components/prefs/pref_registry_simple.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 232 | #include "components/prefs/pref_service.h" |
| 233 | #include "components/prefs/scoped_user_pref_update.h" |
Mugdha Lakhani | 827a5f4 | 2020-07-21 12:35:22 | [diff] [blame] | 234 | #include "components/prerender//common/prerender_url_loader_throttle.h" |
Mugdha Lakhani | 3cff533 | 2020-08-05 07:31:20 | [diff] [blame] | 235 | #include "components/prerender/browser/prerender_manager.h" |
Mugdha Lakhani | 8ff91c8 | 2020-06-08 18:17:33 | [diff] [blame] | 236 | #include "components/prerender/common/prerender_final_status.h" |
Miyoung Shin | f53c2e79 | 2020-06-19 03:20:25 | [diff] [blame] | 237 | #include "components/prerender/common/prerender_types.mojom.h" |
Mugdha Lakhani | fdb9f66 | 2020-07-20 15:36:12 | [diff] [blame] | 238 | #include "components/prerender/common/prerender_util.h" |
Sophie Chang | ff1fc38 | 2019-08-21 16:30:21 | [diff] [blame] | 239 | #include "components/previews/content/previews_decider.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 240 | #include "components/previews/content/previews_decider_impl.h" |
| 241 | #include "components/previews/content/previews_ui_service.h" |
| 242 | #include "components/previews/content/previews_user_data.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 243 | #include "components/previews/core/previews_experiments.h" |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 244 | #include "components/previews/core/previews_features.h" |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 245 | #include "components/previews/core/previews_switches.h" |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 246 | #include "components/safe_browsing/buildflags.h" |
Ali Juma | fb3dc1f | 2020-01-07 17:33:47 | [diff] [blame] | 247 | #include "components/safe_browsing/content/browser/browser_url_loader_throttle.h" |
| 248 | #include "components/safe_browsing/content/password_protection/password_protection_navigation_throttle.h" |
| 249 | #include "components/safe_browsing/core/browser/url_checker_delegate.h" |
| 250 | #include "components/safe_browsing/core/common/safe_browsing_prefs.h" |
| 251 | #include "components/safe_browsing/core/db/database_manager.h" |
| 252 | #include "components/safe_browsing/core/features.h" |
| 253 | #include "components/safe_browsing/core/realtime/policy_engine.h" |
Xinghui Lu | e17b1994 | 2020-02-24 21:19:58 | [diff] [blame] | 254 | #include "components/safe_browsing/core/realtime/url_lookup_service.h" |
Carlos IL | 1a5edec | 2020-06-12 17:56:57 | [diff] [blame] | 255 | #include "components/security_interstitials/content/insecure_form_navigation_throttle.h" |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 256 | #include "components/security_interstitials/content/origin_policy_ui.h" |
Evan Stade | 1e71d6dd | 2019-10-29 03:04:49 | [diff] [blame] | 257 | #include "components/security_interstitials/content/ssl_cert_reporter.h" |
Colin Blundell | 5eb994b | 2020-01-28 11:50:48 | [diff] [blame] | 258 | #include "components/security_interstitials/content/ssl_error_handler.h" |
Evan Stade | 1e71d6dd | 2019-10-29 03:04:49 | [diff] [blame] | 259 | #include "components/security_interstitials/content/ssl_error_navigation_throttle.h" |
David Roger | e8e83f3c | 2019-09-12 10:56:23 | [diff] [blame] | 260 | #include "components/signin/public/identity_manager/identity_manager.h" |
Clark DuVall | aadc244c | 2020-06-06 03:47:14 | [diff] [blame] | 261 | #include "components/site_isolation/pref_names.h" |
Alex Moshchuk | 51e1428b | 2020-04-22 18:00:54 | [diff] [blame] | 262 | #include "components/site_isolation/preloaded_isolated_origins.h" |
Clark DuVall | aadc244c | 2020-06-06 03:47:14 | [diff] [blame] | 263 | #include "components/site_isolation/site_isolation_policy.h" |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 264 | #include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h" |
[email protected] | eba93c9 | 2014-01-07 17:34:17 | [diff] [blame] | 265 | #include "components/translate/core/common/translate_switches.h" |
Lukasz Anforowicz | 1feeba18 | 2020-03-16 20:32:02 | [diff] [blame] | 266 | #include "components/ukm/app_source_url_recorder.h" |
Maks Orlovich | 5408ddfc | 2020-07-28 23:07:35 | [diff] [blame] | 267 | #include "components/ukm/content/source_url_recorder.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 268 | #include "components/url_formatter/url_fixer.h" |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 269 | #include "components/variations/variations_associated_data.h" |
Ben Goldberger | 72533cd | 2020-07-21 16:11:38 | [diff] [blame] | 270 | #include "components/variations/variations_ids_provider.h" |
Kyle Milka | b5c048e | 2017-07-07 02:38:46 | [diff] [blame] | 271 | #include "components/variations/variations_switches.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 272 | #include "components/version_info/version_info.h" |
Chris Blume | f59fc628 | 2020-02-21 00:18:39 | [diff] [blame] | 273 | #include "components/viz/common/features.h" |
Chris Blume | 7f752e3 | 2020-02-14 22:22:33 | [diff] [blame] | 274 | #include "components/viz/common/viz_utils.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 275 | #include "content/public/browser/browser_child_process_host.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 276 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 277 | #include "content/public/browser/browser_ppapi_host.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 278 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 279 | #include "content/public/browser/browser_thread.h" |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 280 | #include "content/public/browser/browser_url_handler.h" |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 281 | #include "content/public/browser/browsing_data_remover.h" |
Lucas Garron | b9539b73 | 2017-10-31 00:22:09 | [diff] [blame] | 282 | #include "content/public/browser/certificate_request_result_type.h" |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 283 | #include "content/public/browser/child_process_data.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 284 | #include "content/public/browser/child_process_security_policy.h" |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 285 | #include "content/public/browser/client_certificate_delegate.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 286 | #include "content/public/browser/file_url_loader.h" |
Mohsen Izadi | 6a6476b7 | 2018-12-07 04:34:35 | [diff] [blame] | 287 | #include "content/public/browser/gpu_data_manager.h" |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 288 | #include "content/public/browser/navigation_handle.h" |
| 289 | #include "content/public/browser/navigation_throttle.h" |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 290 | #include "content/public/browser/overlay_window.h" |
[email protected] | 094c877 | 2013-12-21 17:54:50 | [diff] [blame] | 291 | #include "content/public/browser/render_frame_host.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 292 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 293 | #include "content/public/browser/render_view_host.h" |
[email protected] | ce96786 | 2012-02-09 22:47:05 | [diff] [blame] | 294 | #include "content/public/browser/resource_context.h" |
Alex Moshchuk | 51e1428b | 2020-04-22 18:00:54 | [diff] [blame] | 295 | #include "content/public/browser/site_isolation_policy.h" |
jam | 608f299 | 2016-03-31 16:35:34 | [diff] [blame] | 296 | #include "content/public/browser/storage_partition.h" |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 297 | #include "content/public/browser/tts_controller.h" |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 298 | #include "content/public/browser/tts_platform.h" |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 299 | #include "content/public/browser/url_loader_request_interceptor.h" |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 300 | #include "content/public/browser/vpn_service_proxy.h" |
[email protected] | 91ee368 | 2012-01-19 15:02:19 | [diff] [blame] | 301 | #include "content/public/browser/web_contents.h" |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 302 | #include "content/public/browser/web_contents_delegate.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 303 | #include "content/public/browser/web_ui_url_loader_factory.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 304 | #include "content/public/common/child_process_host.h" |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 305 | #include "content/public/common/content_descriptors.h" |
juncai | 1bf9f7c | 2016-03-22 20:46:56 | [diff] [blame] | 306 | #include "content/public/common/content_features.h" |
brettw | 90e9260 | 2015-10-10 00:12:40 | [diff] [blame] | 307 | #include "content/public/common/content_switches.h" |
Hans Wennborg | 5ffd139 | 2019-10-16 11:00:02 | [diff] [blame] | 308 | #include "content/public/common/navigation_policy.h" |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 309 | #include "content/public/common/network_service_util.h" |
ben | 51bb6c6 | 2016-11-17 20:15:57 | [diff] [blame] | 310 | #include "content/public/common/service_names.mojom.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 311 | #include "content/public/common/url_constants.h" |
[email protected] | 22aa4f8 | 2013-09-24 17:01:44 | [diff] [blame] | 312 | #include "content/public/common/url_utils.h" |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 313 | #include "content/public/common/user_agent.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 314 | #include "content/public/common/web_preferences.h" |
Takuto Ikuta | aa3b796c | 2019-02-06 02:54:56 | [diff] [blame] | 315 | #include "content/public/common/window_container_type.mojom-shared.h" |
Bill Orr | eb42922 | 2018-08-08 21:14:43 | [diff] [blame] | 316 | #include "device/vr/buildflags/buildflags.h" |
Karandeep Bhatia | ae5d9f3 | 2020-07-17 02:52:34 | [diff] [blame] | 317 | #include "extensions/browser/process_map.h" |
Scott Violet | c8240b0 | 2018-03-08 22:03:59 | [diff] [blame] | 318 | #include "extensions/buildflags/buildflags.h" |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 319 | #include "google_apis/gaia/gaia_urls.h" |
Andrew Moylan | 17329fc | 2017-09-25 07:43:30 | [diff] [blame] | 320 | #include "google_apis/google_api_keys.h" |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 321 | #include "gpu/config/gpu_switches.h" |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 322 | #include "ipc/ipc_message.h" |
grunell | 086a411 | 2017-03-02 09:23:04 | [diff] [blame] | 323 | #include "media/audio/audio_manager.h" |
François Beaufort | 8c08979fc | 2018-03-05 13:06:31 | [diff] [blame] | 324 | #include "media/base/media_switches.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 325 | #include "media/media_buildflags.h" |
| 326 | #include "media/mojo/buildflags.h" |
Guido Urdaneta | d06ae84 | 2019-10-10 20:04:12 | [diff] [blame] | 327 | #include "media/webrtc/webrtc_switches.h" |
Shimi Zhang | 6b72d29 | 2019-07-12 20:52:42 | [diff] [blame] | 328 | #include "mojo/public/cpp/bindings/pending_associated_receiver.h" |
Julie Jeongeun Kim | 7f8e26a2 | 2019-10-10 12:09:52 | [diff] [blame] | 329 | #include "mojo/public/cpp/bindings/receiver_set.h" |
Ken Rockot | 0adc1e4 | 2019-05-24 08:20:08 | [diff] [blame] | 330 | #include "mojo/public/cpp/bindings/remote.h" |
engedy | afef048 | 2017-07-06 15:40:53 | [diff] [blame] | 331 | #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 332 | #include "net/base/load_flags.h" |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 333 | #include "net/base/mime_util.h" |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 334 | #include "net/http/http_util.h" |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 335 | #include "net/ssl/client_cert_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 336 | #include "net/ssl/ssl_cert_request_info.h" |
Lukasz Anforowicz | 4600ea3 | 2020-01-18 02:37:48 | [diff] [blame] | 337 | #include "pdf/buildflags.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 338 | #include "ppapi/buildflags/buildflags.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 339 | #include "ppapi/host/ppapi_host.h" |
Scott Violet | 318a55f | 2018-03-30 19:08:19 | [diff] [blame] | 340 | #include "printing/buildflags/buildflags.h" |
Guido Urdaneta | e02b572 | 2020-07-22 05:58:21 | [diff] [blame] | 341 | #include "sandbox/policy/features.h" |
Robert Sesek | 7d0b49b | 2020-07-08 18:31:27 | [diff] [blame] | 342 | #include "sandbox/policy/sandbox_type.h" |
| 343 | #include "sandbox/policy/switches.h" |
Lukasz Anforowicz | 1feeba18 | 2020-03-16 20:32:02 | [diff] [blame] | 344 | #include "services/metrics/public/cpp/ukm_builders.h" |
| 345 | #include "services/metrics/public/cpp/ukm_recorder.h" |
Takashi Toyoshima | 12844146 | 2019-10-16 04:19:17 | [diff] [blame] | 346 | #include "services/network/public/cpp/features.h" |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 347 | #include "services/network/public/cpp/is_potentially_trustworthy.h" |
Lukasz Anforowicz | 9527fd4 | 2019-03-13 19:08:50 | [diff] [blame] | 348 | #include "services/network/public/cpp/network_switches.h" |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 349 | #include "services/network/public/cpp/resource_request.h" |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 350 | #include "services/service_manager/embedder/switches.h" |
Ken Rockot | cebdf9c8 | 2019-05-28 20:33:03 | [diff] [blame] | 351 | #include "services/strings/grit/services_strings.h" |
DongJun Kim | febb3c2 | 2019-10-21 02:08:06 | [diff] [blame] | 352 | #include "storage/browser/file_system/external_mount_points.h" |
Hans Wennborg | 5ffd139 | 2019-10-16 11:00:02 | [diff] [blame] | 353 | #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" |
John Delaney | ac24e57 | 2019-04-30 19:47:02 | [diff] [blame] | 354 | #include "third_party/blink/public/common/features.h" |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 355 | #include "third_party/blink/public/common/loader/url_loader_throttle.h" |
Chris Hamilton | 65c4131 | 2020-06-10 13:14:40 | [diff] [blame] | 356 | #include "third_party/blink/public/common/switches.h" |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 357 | #include "third_party/blink/public/mojom/renderer_preferences.mojom.h" |
Lily Chen | c2c9e9f | 2019-12-05 19:55:31 | [diff] [blame] | 358 | #include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h" |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 359 | #include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h" |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 360 | #include "third_party/skia/include/core/SkColor.h" |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 361 | #include "third_party/widevine/cdm/buildflags.h" |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 362 | #include "ui/base/clipboard/clipboard_format_type.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 363 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 364 | #include "ui/base/resource/resource_bundle.h" |
Scott Violet | 8ff9c30 | 2018-02-22 22:28:35 | [diff] [blame] | 365 | #include "ui/base/ui_base_features.h" |
Khushal | 1fc0da5 | 2019-10-09 00:38:56 | [diff] [blame] | 366 | #include "ui/display/display.h" |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 367 | #include "ui/gfx/color_utils.h" |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 368 | #include "ui/native_theme/native_theme.h" |
[email protected] | b47dc49 | 2014-08-17 07:05:57 | [diff] [blame] | 369 | #include "ui/resources/grit/ui_resources.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 370 | #include "url/gurl.h" |
| 371 | #include "url/origin.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 372 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 373 | #if defined(OS_WIN) |
wfh | c91e967 | 2016-01-27 00:14:20 | [diff] [blame] | 374 | #include "base/strings/string_tokenizer.h" |
Julian Pastarmov | b4773b8 | 2020-04-21 16:34:14 | [diff] [blame] | 375 | #include "base/win/win_util.h" |
| 376 | #include "base/win/windows_version.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 377 | #include "chrome/browser/chrome_browser_main_win.h" |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 378 | #include "chrome/install_static/install_util.h" |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 379 | #include "sandbox/win/src/sandbox_policy.h" |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 380 | #elif defined(OS_MAC) |
Avi Drissman | a2969a55 | 2019-10-30 15:32:25 | [diff] [blame] | 381 | #include "chrome/browser/apps/intent_helper/mac_apps_navigation_throttle.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 382 | #include "chrome/browser/chrome_browser_main_mac.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 383 | #elif defined(OS_CHROMEOS) |
Alice Boxhall | da265914 | 2020-05-14 06:04:37 | [diff] [blame] | 384 | #include "ash/public/cpp/ash_pref_names.h" |
Xiyuan Xia | fc9f3813 | 2019-08-02 00:51:42 | [diff] [blame] | 385 | #include "ash/public/cpp/tablet_mode.h" |
Joshua Peraza | 30d8fc7 | 2019-08-19 17:24:30 | [diff] [blame] | 386 | #include "chrome/app/chrome_crash_reporter_client.h" |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 387 | #include "chrome/browser/browser_process.h" |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 388 | #include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h" |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 389 | #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 390 | #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 391 | #include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h" |
Sam McNally | d8b7d82 | 2018-08-21 03:18:18 | [diff] [blame] | 392 | #include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h" |
[email protected] | 5bc61cad | 2014-07-08 05:05:08 | [diff] [blame] | 393 | #include "chrome/browser/chromeos/file_manager/app_id.h" |
[email protected] | 43420a1 | 2014-04-21 03:20:48 | [diff] [blame] | 394 | #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h" |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 395 | #include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h" |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 396 | #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 397 | #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h" |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 398 | #include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h" |
| 399 | #include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h" |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 400 | #include "chrome/browser/chromeos/login/signin_partition_manager.h" |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 401 | #include "chrome/browser/chromeos/login/startup_utils.h" |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 402 | #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 403 | #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 404 | #include "chrome/browser/chromeos/policy/system_features_disable_list_policy_handler.h" |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 405 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
Anand K. Mistry | 7694c36 | 2020-03-17 23:33:34 | [diff] [blame] | 406 | #include "chrome/browser/chromeos/smb_client/fileapi/smbfs_file_system_backend_delegate.h" |
[email protected] | c94ac69 | 2013-07-27 00:50:10 | [diff] [blame] | 407 | #include "chrome/browser/chromeos/system/input_device_settings.h" |
Katie D | b2d0709 | 2018-12-04 18:59:36 | [diff] [blame] | 408 | #include "chrome/browser/speech/tts_chromeos.h" |
Steven Bennetts | 81d07be | 2018-01-08 20:45:27 | [diff] [blame] | 409 | #include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h" |
djacobo | 21e56e0 | 2016-07-02 01:14:31 | [diff] [blame] | 410 | #include "chrome/browser/ui/browser_dialogs.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 411 | #include "chromeos/constants/chromeos_constants.h" |
Kyle Horimoto | 1d6a679f | 2019-04-16 23:24:21 | [diff] [blame] | 412 | #include "chromeos/constants/chromeos_features.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 413 | #include "chromeos/constants/chromeos_switches.h" |
Rohit Rao | 92f84b6a | 2020-03-25 14:57:50 | [diff] [blame] | 414 | #include "components/crash/core/app/breakpad_linux.h" |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 415 | #include "components/policy/core/common/policy_pref_names.h" |
| 416 | #include "components/prefs/pref_service.h" |
John Abd-El-Malek | 35bfaa5 | 2019-08-20 16:22:07 | [diff] [blame] | 417 | #include "components/user_manager/user.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 418 | #include "components/user_manager/user_manager.h" |
Ken Rockot | 543f5e3 | 2018-02-04 02:13:50 | [diff] [blame] | 419 | #include "services/service_manager/public/mojom/interface_provider_spec.mojom.h" |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 420 | #elif defined(OS_LINUX) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 421 | #include "chrome/browser/chrome_browser_main_linux.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 422 | #elif defined(OS_ANDROID) |
Bo Liu | 4ade6b1b2 | 2017-11-28 02:26:35 | [diff] [blame] | 423 | #include "base/android/application_status_listener.h" |
Brandon Wylie | 21a88ac9 | 2020-05-15 02:49:23 | [diff] [blame] | 424 | #include "base/feature_list.h" |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 425 | #include "chrome/android/features/dev_ui/buildflags.h" |
Tibor Goldschwendt | bf1b96e | 2019-10-07 22:03:47 | [diff] [blame] | 426 | #include "chrome/android/modules/extra_icu/provider/module_provider.h" |
John Abd-El-Malek | 4f380d9 | 2020-02-19 16:43:36 | [diff] [blame] | 427 | #include "chrome/browser/android/customtabs/client_data_header_web_contents_observer.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 428 | #include "chrome/browser/android/devtools_manager_delegate_android.h" |
| 429 | #include "chrome/browser/android/ntp/new_tab_page_url_handler.h" |
| 430 | #include "chrome/browser/android/service_tab_launcher.h" |
| 431 | #include "chrome/browser/android/tab_android.h" |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 432 | #include "chrome/browser/android/tab_web_contents_delegate_android.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 433 | #include "chrome/browser/chrome_browser_main_android.h" |
Min Qin | 86987406 | 2019-10-15 19:27:56 | [diff] [blame] | 434 | #include "chrome/browser/download/android/available_offline_content_provider.h" |
| 435 | #include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h" |
Brandon Wylie | 21a88ac9 | 2020-05-15 02:49:23 | [diff] [blame] | 436 | #include "chrome/browser/flags/android/chrome_feature_list.h" |
Jinsuk Kim | 6f9253c | 2019-03-11 02:45:07 | [diff] [blame] | 437 | #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
James Cook | 01e3e5ef | 2019-04-09 14:44:38 | [diff] [blame] | 438 | #include "chrome/common/chrome_descriptors.h" |
Joshua Peraza | 934e559 | 2018-07-18 23:43:11 | [diff] [blame] | 439 | #include "components/crash/content/browser/child_exit_observer_android.h" |
Yuzu Saijo | 2d12ef9 | 2018-08-21 04:52:07 | [diff] [blame] | 440 | #include "components/crash/content/browser/crash_memory_metrics_collector_android.h" |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 441 | #include "components/navigation_interception/intercept_navigation_delegate.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 442 | #include "content/public/browser/android/java_interfaces.h" |
mfomitchev | 220b856 | 2017-07-13 23:08:54 | [diff] [blame] | 443 | #include "services/service_manager/public/cpp/interface_provider.h" |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 444 | #include "ui/base/resource/resource_bundle_android.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 445 | #include "ui/base/ui_base_paths.h" |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 446 | #if BUILDFLAG(DFMIFY_DEV_UI) |
Samuel Huang | 3a1ce1c3 | 2019-10-16 17:34:04 | [diff] [blame] | 447 | #include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h" |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 448 | #endif // BUILDFLAG(DFMIFY_DEV_UI) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 449 | #elif defined(OS_POSIX) |
| 450 | #include "chrome/browser/chrome_browser_main_posix.h" |
| 451 | #endif |
| 452 | |
Alice Boxhall | a9aafba4 | 2020-06-24 05:42:51 | [diff] [blame] | 453 | #if !defined(OS_CHROMEOS) |
| 454 | #include "ui/accessibility/accessibility_features.h" |
| 455 | #endif // !defined(OS_CHROMEOS) |
| 456 | |
tmartino | fb34188 | 2017-02-10 19:36:53 | [diff] [blame] | 457 | #if !defined(OS_ANDROID) |
Jay Harris | 1ddcffa | 2019-07-09 03:07:40 | [diff] [blame] | 458 | #include "chrome/browser/badging/badge_manager.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 459 | #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 460 | #include "chrome/browser/devtools/devtools_window.h" |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 461 | #include "chrome/browser/media/unified_autoplay_config.h" |
Xinghui Lu | f45d7ef7 | 2020-06-09 02:16:38 | [diff] [blame] | 462 | #include "chrome/browser/safe_browsing/dm_token_utils.h" |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 463 | #include "chrome/browser/search/instant_service.h" |
| 464 | #include "chrome/browser/search/instant_service_factory.h" |
Reilly Grant | 2814fb7 | 2019-03-19 17:04:46 | [diff] [blame] | 465 | #include "chrome/browser/serial/chrome_serial_delegate.h" |
Collin Baker | 8a21755 | 2019-05-29 19:47:51 | [diff] [blame] | 466 | #include "chrome/browser/ui/browser.h" |
| 467 | #include "chrome/browser/ui/browser_finder.h" |
| 468 | #include "chrome/browser/ui/browser_list.h" |
| 469 | #include "chrome/browser/ui/browser_window.h" |
jdoerrie | 4f9376f | 2018-12-12 18:26:20 | [diff] [blame] | 470 | #include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h" |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 471 | #include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h" |
Nina Satragno | 8c832df | 2019-07-29 15:59:39 | [diff] [blame] | 472 | #include "chrome/browser/webauthn/authenticator_request_scheduler.h" |
| 473 | #include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h" |
Jay Civelli | 4d53be9b | 2017-08-31 22:01:43 | [diff] [blame] | 474 | #include "chrome/common/importer/profile_import.mojom.h" |
Austin Orion | e250d01 | 2019-05-29 02:56:27 | [diff] [blame] | 475 | #include "chrome/grit/chrome_unscaled_resources.h" |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 476 | #endif // !defined(OS_ANDROID) |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 477 | |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 478 | #if defined(OS_WIN) || defined(OS_MAC) || \ |
Nicolas Ouellet-Payeur | bdcab009 | 2018-10-22 14:50:33 | [diff] [blame] | 479 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
Nicolas Ouellet-Payeur | 4b840a9 | 2018-09-18 14:46:52 | [diff] [blame] | 480 | #include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h" |
| 481 | #endif |
| 482 | |
Joshua Peraza | ce68e2f | 2019-09-23 18:44:24 | [diff] [blame] | 483 | #if defined(OS_LINUX) |
Rohit Rao | 92f84b6a | 2020-03-25 14:57:50 | [diff] [blame] | 484 | #include "components/crash/core/app/crash_switches.h" |
| 485 | #include "components/crash/core/app/crashpad.h" |
Joshua Peraza | ce68e2f | 2019-09-23 18:44:24 | [diff] [blame] | 486 | #endif |
| 487 | |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 488 | #if defined(OS_POSIX) && !defined(OS_MAC) |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 489 | #if !defined(OS_ANDROID) |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 490 | #include "base/debug/leak_annotations.h" |
Rohit Rao | 92f84b6a | 2020-03-25 14:57:50 | [diff] [blame] | 491 | #include "components/crash/core/app/breakpad_linux.h" |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 492 | #endif // !defined(OS_ANDROID) |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 493 | #include "components/crash/content/browser/crash_handler_host_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 494 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 495 | |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 496 | // TODO(crbug.com/939205): Once the upcoming App Service is available, use a |
| 497 | // single navigation throttle to display the intent picker on all platforms. |
| 498 | #if !defined(OS_ANDROID) |
| 499 | #if defined(OS_CHROMEOS) |
| 500 | #include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h" |
Maggie Cai | 00e2a21e | 2019-10-16 00:47:51 | [diff] [blame] | 501 | #include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h" |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 502 | #else |
| 503 | #include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h" |
| 504 | #endif |
| 505 | #endif |
| 506 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 507 | #if defined(TOOLKIT_VIEWS) |
| 508 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h" |
| 509 | #endif |
| 510 | |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 511 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 512 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h" |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 513 | #endif |
| 514 | |
Mohsen Izadi | f1958f2 | 2019-01-18 20:29:31 | [diff] [blame] | 515 | #if defined(USE_OZONE) |
| 516 | #include "ui/ozone/public/ozone_platform.h" |
| 517 | #endif |
| 518 | |
Maksim Sisov | 1686fc2 | 2020-06-17 07:59:20 | [diff] [blame] | 519 | #if defined(USE_X11) || defined(USE_OZONE) |
| 520 | #include "chrome/browser/chrome_browser_main_extra_parts_ozone.h" |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 521 | #endif |
| 522 | |
brettw | ab78fef | 2016-10-12 02:56:05 | [diff] [blame] | 523 | #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
Colin Blundell | ca2b20e | 2020-01-28 10:07:10 | [diff] [blame] | 524 | #include "components/captive_portal/content/captive_portal_tab_helper.h" |
Colin Blundell | 11999f37 | 2020-01-28 14:17:38 | [diff] [blame] | 525 | #include "components/captive_portal/content/captive_portal_url_loader_throttle.h" |
[email protected] | 7a2a6d80 | 2014-06-06 13:39:19 | [diff] [blame] | 526 | #endif |
| 527 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 528 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 529 | #include "components/nacl/browser/nacl_browser.h" |
| 530 | #include "components/nacl/browser/nacl_host_message_filter.h" |
| 531 | #include "components/nacl/browser/nacl_process_host.h" |
| 532 | #include "components/nacl/common/nacl_process_type.h" |
| 533 | #include "components/nacl/common/nacl_switches.h" |
| 534 | #endif |
| 535 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 536 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 537 | #include "chrome/browser/accessibility/animation_policy_prefs.h" |
Dominick Ng | 6ff5105 | 2018-07-06 05:30:20 | [diff] [blame] | 538 | #include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h" |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 539 | #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 540 | #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
Pavol Marko | 41c37b1 | 2019-08-07 10:56:32 | [diff] [blame] | 541 | #include "chrome/browser/extensions/extension_util.h" |
Clark DuVall | 2cf99249e | 2018-09-19 19:11:51 | [diff] [blame] | 542 | #include "chrome/browser/extensions/user_script_listener.h" |
| 543 | #include "chrome/browser/media/cast_transport_host_filter.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 544 | #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" |
Evan Stade | 1e71d6dd | 2019-10-29 03:04:49 | [diff] [blame] | 545 | #include "chrome/browser/ui/browser_commands.h" |
Eric Willigers | 007ef30 | 2019-08-29 09:58:46 | [diff] [blame] | 546 | #include "chrome/browser/ui/web_applications/app_browser_controller.h" |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 547 | #include "components/guest_view/browser/guest_view_base.h" |
| 548 | #include "components/guest_view/browser/guest_view_manager.h" |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 549 | #include "extensions/browser/api/web_request/web_request_api.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 550 | #include "extensions/browser/extension_host.h" |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 551 | #include "extensions/browser/extension_navigation_throttle.h" |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 552 | #include "extensions/browser/extension_protocols.h" |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 553 | #include "extensions/browser/extension_registry.h" |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 554 | #include "extensions/browser/extension_system.h" |
Aaron Colwell | 8c43064 | 2020-08-04 01:55:20 | [diff] [blame] | 555 | #include "extensions/browser/extension_util.h" |
hanxi | 0d0a1e9 | 2014-08-26 18:39:48 | [diff] [blame] | 556 | #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 557 | #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
| 558 | #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 559 | #include "extensions/browser/process_manager.h" |
Dan Beam | 836c02a | 2019-06-15 01:58:27 | [diff] [blame] | 560 | #include "extensions/common/constants.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 561 | #include "extensions/common/extension.h" |
| 562 | #include "extensions/common/extension_set.h" |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 563 | #include "extensions/common/manifest_handlers/background_info.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 564 | #include "extensions/common/manifest_handlers/shared_module_info.h" |
Clark DuVall | bf7722f | 2018-08-03 18:03:33 | [diff] [blame] | 565 | #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 566 | #include "extensions/common/permissions/permissions_data.h" |
| 567 | #include "extensions/common/permissions/socket_permission.h" |
| 568 | #include "extensions/common/switches.h" |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 569 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
merkin | db10455e | 2017-02-28 13:16:25 | [diff] [blame] | 570 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 571 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 572 | #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h" |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 573 | #include "chrome/browser/plugins/flash_download_interception.h" |
John Abd-El-Malek | ecc6f5f | 2018-03-02 18:47:39 | [diff] [blame] | 574 | #include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h" |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 575 | #endif |
| 576 | |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 577 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 578 | #include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h" |
| 579 | #endif |
| 580 | |
yilkal | 240b4f2 | 2019-11-27 19:09:06 | [diff] [blame] | 581 | #if defined(OS_CHROMEOS) |
Anatoliy Potapchuk | 762c40d | 2020-05-11 15:10:37 | [diff] [blame] | 582 | #include "chrome/browser/chromeos/app_mode/kiosk_settings_navigation_throttle.h" |
yilkal | 240b4f2 | 2019-11-27 19:09:06 | [diff] [blame] | 583 | #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] | 584 | #include "chrome/browser/speech/tts_controller_delegate_impl.h" |
yilkal | 240b4f2 | 2019-11-27 19:09:06 | [diff] [blame] | 585 | #endif // defined(OS_CHROMEOS) |
| 586 | |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 587 | #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 588 | #include "chrome/browser/media/cast_remoting_connector.h" |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 589 | #endif |
| 590 | |
weili | fabbf757 | 2017-05-22 19:05:16 | [diff] [blame] | 591 | #if BUILDFLAG(ENABLE_PRINTING) |
Lei Zhang | a2fa14c | 2018-05-15 00:05:21 | [diff] [blame] | 592 | #include "chrome/browser/printing/printing_message_filter.h" |
weili | fabbf757 | 2017-05-22 19:05:16 | [diff] [blame] | 593 | #endif |
Lei Zhang | a2fa14c | 2018-05-15 00:05:21 | [diff] [blame] | 594 | |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 595 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c86d76e4 | 2016-03-14 23:38:49 | [diff] [blame] | 596 | #include "chrome/browser/media/output_protection_impl.h" |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 597 | #if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 598 | #include "chrome/browser/media/widevine_hardware_caps_win.h" |
| 599 | #include "third_party/widevine/cdm/widevine_cdm_common.h" |
| 600 | #endif |
| 601 | #endif |
| 602 | |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 603 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 604 | #include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h" |
| 605 | #endif |
| 606 | |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 607 | #if BUILDFLAG(SAFE_BROWSING_AVAILABLE) |
Daniel Rubery | a1611e3 | 2019-04-24 21:38:35 | [diff] [blame] | 608 | #include "chrome/browser/safe_browsing/chrome_password_protection_service.h" |
Daniel Rubery | 9eb1e091 | 2020-05-08 17:57:32 | [diff] [blame] | 609 | #include "chrome/browser/safe_browsing/client_side_detection_service_factory.h" |
Daniel Rubery | a1611e3 | 2019-04-24 21:38:35 | [diff] [blame] | 610 | #endif |
| 611 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 612 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 613 | #include "chrome/browser/offline_pages/offline_page_tab_helper.h" |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 614 | #include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h" |
| 615 | #endif |
| 616 | |
Will Cassella | 40837ba | 2019-07-01 21:32:00 | [diff] [blame] | 617 | #if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID) |
Bill Orr | eb42922 | 2018-08-08 21:14:43 | [diff] [blame] | 618 | #include "device/vr/public/mojom/isolated_xr_service.mojom.h" |
| 619 | #endif |
| 620 | |
John Lee | 0ee748bf | 2019-12-11 21:35:44 | [diff] [blame] | 621 | #if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP) |
| 622 | #include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h" |
| 623 | #endif |
| 624 | |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 625 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
| 626 | #include "chrome/browser/safe_browsing/cloud_content_scanning/deep_scanning_dialog_delegate.h" |
| 627 | #endif |
| 628 | |
Alexander Cooper | c844870 | 2020-03-14 01:39:56 | [diff] [blame] | 629 | #if BUILDFLAG(ENABLE_VR) |
Alexander Cooper | f4b3013d | 2020-03-23 18:47:23 | [diff] [blame] | 630 | #include "chrome/browser/vr/chrome_xr_integration_client.h" |
Alexander Cooper | c844870 | 2020-03-14 01:39:56 | [diff] [blame] | 631 | #endif |
| 632 | |
James Cook | 26d2712 | 2020-06-26 19:57:07 | [diff] [blame] | 633 | #if BUILDFLAG(IS_LACROS) |
James Cook | be13cc0 | 2020-06-29 22:32:51 | [diff] [blame] | 634 | #include "chrome/browser/chrome_browser_main_extra_parts_lacros.h" |
James Cook | 9273025 | 2020-07-22 01:57:26 | [diff] [blame] | 635 | #include "chromeos/lacros/lacros_chrome_service_impl.h" |
Hidehiko Abe | eaffbbce | 2020-06-23 19:41:52 | [diff] [blame] | 636 | #endif |
| 637 | |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 638 | using base::FileDescriptor; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 639 | using content::BrowserThread; |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 640 | using content::BrowserURLHandler; |
msramek | a3c7cfd | 2017-02-03 13:34:13 | [diff] [blame] | 641 | using content::BrowsingDataFilterBuilder; |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 642 | using content::ChildProcessSecurityPolicy; |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 643 | using content::QuotaPermissionContext; |
[email protected] | 2626d14 | 2014-04-22 17:24:02 | [diff] [blame] | 644 | using content::RenderFrameHost; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 645 | using content::RenderViewHost; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 646 | using content::SiteInstance; |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 647 | using content::WebContents; |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 648 | using content::WebPreferences; |
[email protected] | 593d2a7 | 2013-07-26 08:48:38 | [diff] [blame] | 649 | using message_center::NotifierId; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 650 | |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 651 | #if defined(OS_POSIX) |
brettw | 3c98c7d3 | 2017-07-25 01:44:20 | [diff] [blame] | 652 | using content::PosixFileDescriptorInfo; |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 653 | #endif |
| 654 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 655 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 656 | using extensions::APIPermission; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 657 | using extensions::ChromeContentBrowserClientExtensionsPart; |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 658 | using extensions::Extension; |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 659 | using extensions::Manifest; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 660 | #endif |
| 661 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 662 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 663 | using plugins::ChromeContentBrowserClientPluginsPart; |
| 664 | #endif |
| 665 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 666 | namespace { |
| 667 | |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 668 | #if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 669 | // Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when |
| 670 | // running on Windows 10 1511 and above. See |
| 671 | // https://blogs.windows.com/blog/tag/code-integrity-guard/. |
| 672 | const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity", |
Will Harris | a9eaa28 | 2019-11-01 17:51:35 | [diff] [blame] | 673 | base::FEATURE_ENABLED_BY_DEFAULT}; |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 674 | #endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) && |
| 675 | // !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 676 | |
Colin Blundell | 9ee731dd | 2020-01-23 10:42:38 | [diff] [blame] | 677 | // Wrapper for SSLErrorHandler::HandleSSLError() that supplies //chrome-level |
| 678 | // parameters. |
| 679 | void HandleSSLErrorWrapper( |
| 680 | content::WebContents* web_contents, |
| 681 | int cert_error, |
| 682 | const net::SSLInfo& ssl_info, |
| 683 | const GURL& request_url, |
| 684 | std::unique_ptr<SSLCertReporter> ssl_cert_reporter, |
Colin Blundell | 9ee731dd | 2020-01-23 10:42:38 | [diff] [blame] | 685 | SSLErrorHandler::BlockingPageReadyCallback blocking_page_ready_callback) { |
| 686 | Profile* profile = |
| 687 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Scott Violet | 2fb48110 | 2020-07-27 00:23:54 | [diff] [blame] | 688 | // Profile should always outlive a WebContents |
| 689 | DCHECK(profile); |
Colin Blundell | 9ee731dd | 2020-01-23 10:42:38 | [diff] [blame] | 690 | |
Colin Blundell | 27331f9 | 2020-02-05 21:13:01 | [diff] [blame] | 691 | captive_portal::CaptivePortalService* captive_portal_service = nullptr; |
Colin Blundell | 111b61c0 | 2020-01-24 11:53:51 | [diff] [blame] | 692 | |
| 693 | #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 694 | captive_portal_service = CaptivePortalServiceFactory::GetForProfile(profile); |
| 695 | #endif |
| 696 | |
Colin Blundell | 9ee731dd | 2020-01-23 10:42:38 | [diff] [blame] | 697 | SSLErrorHandler::HandleSSLError( |
| 698 | web_contents, cert_error, ssl_info, request_url, |
Colin Blundell | a3fc122 | 2020-01-23 11:41:53 | [diff] [blame] | 699 | std::move(ssl_cert_reporter), std::move(blocking_page_ready_callback), |
Colin Blundell | 111b61c0 | 2020-01-24 11:53:51 | [diff] [blame] | 700 | g_browser_process->network_time_tracker(), captive_portal_service, |
Colin Blundell | 13e92ec | 2020-01-27 09:47:38 | [diff] [blame] | 701 | std::make_unique<ChromeSecurityBlockingPageFactory>(), |
Colin Blundell | 9ee731dd | 2020-01-23 10:42:38 | [diff] [blame] | 702 | profile->GetPrefs()->GetBoolean(prefs::kSSLErrorOverrideAllowed)); |
| 703 | } |
| 704 | |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 705 | enum AppLoadedInTabSource { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 706 | // 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] | 707 | APP_LOADED_IN_TAB_SOURCE_APP = 0, |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 708 | |
| 709 | // 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] | 710 | APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE, |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 711 | |
| 712 | // An extension or app tried to load a resource of a different platform app in |
| 713 | // a tab. |
| 714 | APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION, |
| 715 | |
| 716 | // A non-app and non-extension page tried to load a platform app in a tab. |
| 717 | APP_LOADED_IN_TAB_SOURCE_OTHER, |
| 718 | |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 719 | APP_LOADED_IN_TAB_SOURCE_MAX |
| 720 | }; |
| 721 | |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 722 | // Cached version of the locale so we can return the locale on the I/O |
| 723 | // thread. |
| 724 | std::string& GetIOThreadApplicationLocale() { |
| 725 | static base::NoDestructor<std::string> s; |
| 726 | return *s; |
| 727 | } |
| 728 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 729 | // Returns a copy of the given url with its host set to given host and path set |
| 730 | // to given path. Other parts of the url will be the same. |
| 731 | GURL ReplaceURLHostAndPath(const GURL& url, |
| 732 | const std::string& host, |
| 733 | const std::string& path) { |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 734 | url::Replacements<char> replacements; |
| 735 | replacements.SetHost(host.c_str(), url::Component(0, host.length())); |
| 736 | replacements.SetPath(path.c_str(), url::Component(0, path.length())); |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 737 | return url.ReplaceComponents(replacements); |
| 738 | } |
| 739 | |
mad | fbd1085 | 2017-01-20 03:15:33 | [diff] [blame] | 740 | // Handles the rewriting of the new tab page URL based on group policy. |
| 741 | bool HandleNewTabPageLocationOverride( |
| 742 | GURL* url, |
| 743 | content::BrowserContext* browser_context) { |
| 744 | if (!url->SchemeIs(content::kChromeUIScheme) || |
| 745 | url->host() != chrome::kChromeUINewTabHost) |
| 746 | return false; |
| 747 | |
| 748 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 749 | std::string ntp_location = |
| 750 | profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride); |
| 751 | if (ntp_location.empty()) |
| 752 | return false; |
| 753 | |
| 754 | *url = GURL(ntp_location); |
| 755 | return true; |
| 756 | } |
| 757 | |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 758 | #if !defined(OS_ANDROID) |
| 759 | // Check if the current url is whitelisted based on a list of whitelisted urls. |
| 760 | bool IsURLWhitelisted(const GURL& current_url, |
Jan Wilken Dörrie | 8d9034f1 | 2019-11-28 14:48:57 | [diff] [blame] | 761 | base::Value::ConstListView whitelisted_urls) { |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 762 | // Only check on HTTP and HTTPS pages. |
| 763 | if (!current_url.SchemeIsHTTPOrHTTPS()) |
| 764 | return false; |
| 765 | |
| 766 | for (auto const& value : whitelisted_urls) { |
| 767 | ContentSettingsPattern pattern = |
| 768 | ContentSettingsPattern::FromString(value.GetString()); |
| 769 | if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid()) |
| 770 | continue; |
| 771 | if (pattern.Matches(current_url)) |
| 772 | return true; |
| 773 | } |
| 774 | |
| 775 | return false; |
| 776 | } |
| 777 | |
| 778 | // Check if autoplay is allowed by policy configuration. |
| 779 | bool IsAutoplayAllowedByPolicy(content::WebContents* contents, |
| 780 | PrefService* prefs) { |
| 781 | DCHECK(prefs); |
| 782 | |
| 783 | // Check if we have globally allowed autoplay by policy. |
| 784 | if (prefs->GetBoolean(prefs::kAutoplayAllowed) && |
| 785 | prefs->IsManagedPreference(prefs::kAutoplayAllowed)) { |
| 786 | return true; |
| 787 | } |
| 788 | |
| 789 | if (!contents) |
| 790 | return false; |
| 791 | |
| 792 | // Check if the current URL matches a URL pattern on the whitelist. |
| 793 | const base::ListValue* autoplay_whitelist = |
| 794 | prefs->GetList(prefs::kAutoplayWhitelist); |
| 795 | return autoplay_whitelist && |
| 796 | prefs->IsManagedPreference(prefs::kAutoplayWhitelist) && |
| 797 | IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList()); |
| 798 | } |
| 799 | #endif |
| 800 | |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 801 | #if defined(OS_ANDROID) |
| 802 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
| 803 | return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket(); |
| 804 | } |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 805 | #elif defined(OS_POSIX) && !defined(OS_MAC) |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 806 | breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( |
| 807 | const std::string& process_type) { |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 808 | base::FilePath dumps_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 809 | base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 810 | { |
| 811 | ANNOTATE_SCOPED_MEMORY_LEAK; |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 812 | bool upload = !getenv(env_vars::kHeadless); |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 813 | breakpad::CrashHandlerHostLinux* crash_handler = |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 814 | new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 815 | crash_handler->StartUploaderThread(); |
| 816 | return crash_handler; |
| 817 | } |
| 818 | } |
| 819 | |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 820 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
Joshua Peraza | ce68e2f | 2019-09-23 18:44:24 | [diff] [blame] | 821 | if (crash_reporter::IsCrashpadEnabled()) { |
| 822 | int fd; |
| 823 | pid_t pid; |
| 824 | return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1; |
| 825 | } |
| 826 | |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 827 | // Extensions have the same process type as renderers. |
[email protected] | cd0f7af | 2014-01-16 23:50:39 | [diff] [blame] | 828 | if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 829 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 830 | if (!crash_handler) |
| 831 | crash_handler = CreateCrashHandlerHost("extension"); |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 832 | return crash_handler->GetDeathSignalSocket(); |
| 833 | } |
| 834 | |
| 835 | std::string process_type = |
| 836 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 837 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 838 | if (process_type == switches::kRendererProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 839 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 840 | if (!crash_handler) |
| 841 | crash_handler = CreateCrashHandlerHost(process_type); |
| 842 | return crash_handler->GetDeathSignalSocket(); |
| 843 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 844 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 845 | if (process_type == switches::kPpapiPluginProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 846 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 847 | if (!crash_handler) |
| 848 | crash_handler = CreateCrashHandlerHost(process_type); |
| 849 | return crash_handler->GetDeathSignalSocket(); |
| 850 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 851 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 852 | if (process_type == switches::kGpuProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 853 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 854 | if (!crash_handler) |
| 855 | crash_handler = CreateCrashHandlerHost(process_type); |
| 856 | return crash_handler->GetDeathSignalSocket(); |
| 857 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 858 | |
James Cook | 9207cc1 | 2017-10-19 17:08:39 | [diff] [blame] | 859 | if (process_type == switches::kUtilityProcess) { |
| 860 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
| 861 | if (!crash_handler) |
| 862 | crash_handler = CreateCrashHandlerHost(process_type); |
| 863 | return crash_handler->GetDeathSignalSocket(); |
| 864 | } |
| 865 | |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 866 | return -1; |
| 867 | } |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 868 | #endif // defined(OS_ANDROID) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 869 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 870 | void SetApplicationLocaleOnIOThread(const std::string& locale) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 871 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 872 | GetIOThreadApplicationLocale() = locale; |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 873 | } |
| 874 | |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 875 | // An implementation of the SSLCertReporter interface used by |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 876 | // SSLErrorHandler. Uses CertificateReportingService to send reports. The |
| 877 | // service handles queueing and re-sending of failed reports. Each certificate |
| 878 | // error creates a new instance of this class. |
| 879 | class CertificateReportingServiceCertReporter : public SSLCertReporter { |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 880 | public: |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 881 | explicit CertificateReportingServiceCertReporter( |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 882 | content::WebContents* web_contents) |
| 883 | : service_(CertificateReportingServiceFactory::GetForBrowserContext( |
| 884 | web_contents->GetBrowserContext())) {} |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 885 | ~CertificateReportingServiceCertReporter() override {} |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 886 | |
| 887 | // SSLCertReporter implementation |
estark | 4282f117 | 2015-05-13 22:01:55 | [diff] [blame] | 888 | void ReportInvalidCertificateChain( |
| 889 | const std::string& serialized_report) override { |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 890 | service_->Send(serialized_report); |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | private: |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 894 | CertificateReportingService* service_; |
| 895 | |
| 896 | DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter); |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 897 | }; |
| 898 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 899 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 900 | |
| 901 | AppLoadedInTabSource ClassifyAppLoadedInTabSource( |
| 902 | const GURL& opener_url, |
| 903 | const extensions::Extension* target_platform_app) { |
Lei Zhang | 7d0b0f4 | 2019-10-12 03:47:58 | [diff] [blame] | 904 | if (!opener_url.SchemeIs(extensions::kExtensionScheme)) { |
| 905 | // The forbidden app URL was being opened by a non-extension page (e.g. |
| 906 | // http). |
| 907 | return APP_LOADED_IN_TAB_SOURCE_OTHER; |
| 908 | } |
| 909 | |
| 910 | if (opener_url.host_piece() != target_platform_app->id()) { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 911 | // The forbidden app URL was being opened by a different app or extension. |
| 912 | return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION; |
| 913 | } |
Lei Zhang | 7d0b0f4 | 2019-10-12 03:47:58 | [diff] [blame] | 914 | |
| 915 | // This platform app was trying to window.open() one of its own URLs. |
| 916 | if (opener_url == |
| 917 | extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) { |
| 918 | // Source was the background page. |
| 919 | return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE; |
| 920 | } |
| 921 | |
| 922 | // Source was a different page inside the app. |
| 923 | return APP_LOADED_IN_TAB_SOURCE_APP; |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 924 | } |
[email protected] | 9c765638 | 2014-08-08 21:02:30 | [diff] [blame] | 925 | |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 926 | // Returns true if there is is an extension matching |url| in |
| 927 | // |opener_render_process_id| with APIPermission::kBackground. |
| 928 | // |
| 929 | // Note that GetExtensionOrAppByURL requires a full URL in order to match with a |
| 930 | // hosted app, even though normal extensions just use the host. |
| 931 | bool URLHasExtensionBackgroundPermission( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 932 | extensions::ProcessMap* process_map, |
| 933 | extensions::ExtensionRegistry* registry, |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 934 | const GURL& url, |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 935 | int opener_render_process_id) { |
| 936 | // Note: includes web URLs that are part of an extension's web extent. |
| 937 | const Extension* extension = |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 938 | registry->enabled_extensions().GetExtensionOrAppByURL(url); |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 939 | return extension && |
| 940 | extension->permissions_data()->HasAPIPermission( |
| 941 | APIPermission::kBackground) && |
| 942 | process_map->Contains(extension->id(), opener_render_process_id); |
| 943 | } |
Kevin Marshall | 32f99d7e | 2017-07-11 23:17:46 | [diff] [blame] | 944 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 945 | #endif |
| 946 | |
Miyoung Shin | 6694b8e | 2020-06-18 01:38:17 | [diff] [blame] | 947 | mojo::PendingRemote<prerender::mojom::PrerenderCanceler> GetPrerenderCanceler( |
Alexander Cooper | bc87af3 | 2020-07-15 15:59:45 | [diff] [blame] | 948 | base::OnceCallback<content::WebContents*()> wc_getter) { |
Miyoung Shin | 6694b8e | 2020-06-18 01:38:17 | [diff] [blame] | 949 | mojo::PendingRemote<prerender::mojom::PrerenderCanceler> canceler; |
Mugdha Lakhani | 2c6b23af | 2020-07-31 14:55:57 | [diff] [blame] | 950 | prerender::ChromePrerenderContentsDelegate::FromWebContents( |
| 951 | std::move(wc_getter).Run()) |
Darin Fisher | e41aab5 | 2020-01-29 18:31:23 | [diff] [blame] | 952 | ->AddPrerenderCancelerReceiver(canceler.InitWithNewPipeAndPassReceiver()); |
| 953 | return canceler; |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 954 | } |
| 955 | |
Julian Pastarmov | b4773b8 | 2020-04-21 16:34:14 | [diff] [blame] | 956 | // Encapculates logic to determine if enterprise policies should be honored. |
| 957 | // This is a copy of the code in policy_loader_win.cc but it's ok to duplicate |
| 958 | // as a new central class to replace those checks is in the making. |
| 959 | bool ShouldHonorPolicies() { |
| 960 | #if defined(OS_WIN) |
| 961 | bool is_enterprise_version = |
| 962 | base::win::OSInfo::GetInstance()->version_type() != base::win::SUITE_HOME; |
| 963 | return base::win::IsEnrolledToDomain() || |
| 964 | (base::win::IsDeviceRegisteredWithManagement() && |
| 965 | is_enterprise_version); |
| 966 | #else // defined(OS_WIN) |
| 967 | // TODO(pastarmovj): Replace this with check for MacOS and the new management |
| 968 | // service once it is ready. |
| 969 | return true; |
| 970 | #endif // defined(OS_WIN) |
| 971 | } |
| 972 | |
John Abd-El-Malek | 92bf360 | 2019-07-31 02:25:48 | [diff] [blame] | 973 | void LaunchURL(const GURL& url, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 974 | content::WebContents::OnceGetter web_contents_getter, |
John Abd-El-Malek | 92bf360 | 2019-07-31 02:25:48 | [diff] [blame] | 975 | ui::PageTransition page_transition, |
Emily Stark | 13b66bdf | 2019-10-04 17:11:45 | [diff] [blame] | 976 | bool has_user_gesture, |
| 977 | const base::Optional<url::Origin>& initiating_origin) { |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 978 | // If there is no longer a WebContents, the request may have raced with tab |
| 979 | // closing. Don't fire the external request. (It may have been a prerender.) |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 980 | content::WebContents* web_contents = std::move(web_contents_getter).Run(); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 981 | if (!web_contents) |
| 982 | return; |
| 983 | |
| 984 | // Do not launch external requests attached to unswapped prerenders. |
| 985 | prerender::PrerenderContents* prerender_contents = |
Mugdha Lakhani | 2c6b23af | 2020-07-31 14:55:57 | [diff] [blame] | 986 | prerender::ChromePrerenderContentsDelegate::FromWebContents(web_contents); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 987 | if (prerender_contents) { |
| 988 | prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 989 | return; |
| 990 | } |
| 991 | |
Robbie McElrath | 1294d24 | 2019-05-31 20:46:22 | [diff] [blame] | 992 | // Do not launch external requests for schemes that have a handler registered. |
| 993 | ProtocolHandlerRegistry* protocol_handler_registry = |
| 994 | ProtocolHandlerRegistryFactory::GetForBrowserContext( |
| 995 | web_contents->GetBrowserContext()); |
| 996 | if (protocol_handler_registry && |
| 997 | protocol_handler_registry->IsHandledProtocol(url.scheme())) |
| 998 | return; |
| 999 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1000 | bool is_whitelisted = false; |
Aaron Colwell | f94fd97a | 2020-07-21 19:37:08 | [diff] [blame] | 1001 | PolicyBlocklistService* service = |
| 1002 | PolicyBlocklistFactory::GetForBrowserContext( |
Oleg Davydov | 5cfe7ab | 2019-02-01 12:27:19 | [diff] [blame] | 1003 | web_contents->GetBrowserContext()); |
Julian Pastarmov | b4773b8 | 2020-04-21 16:34:14 | [diff] [blame] | 1004 | if (ShouldHonorPolicies() && service) { |
Aaron Colwell | f94fd97a | 2020-07-21 19:37:08 | [diff] [blame] | 1005 | const policy::URLBlocklist::URLBlocklistState url_state = |
| 1006 | service->GetURLBlocklistState(url); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1007 | is_whitelisted = |
Aaron Colwell | f94fd97a | 2020-07-21 19:37:08 | [diff] [blame] | 1008 | url_state == policy::URLBlocklist::URLBlocklistState::URL_IN_ALLOWLIST; |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | // If the URL is in whitelist, we launch it without asking the user and |
| 1012 | // without any additional security checks. Since the URL is whitelisted, |
| 1013 | // we assume it can be executed. |
| 1014 | if (is_whitelisted) { |
| 1015 | ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents); |
| 1016 | } else { |
| 1017 | ExternalProtocolHandler::LaunchUrl( |
| 1018 | url, web_contents->GetRenderViewHost()->GetProcess()->GetID(), |
| 1019 | web_contents->GetRenderViewHost()->GetRoutingID(), page_transition, |
Emily Stark | 13b66bdf | 2019-10-04 17:11:45 | [diff] [blame] | 1020 | has_user_gesture, initiating_origin); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1021 | } |
| 1022 | } |
| 1023 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1024 | std::string GetProduct() { |
| 1025 | return version_info::GetProductNameAndVersionForUserAgent(); |
| 1026 | } |
| 1027 | |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 1028 | void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) { |
| 1029 | // |allowlist| combines pref/policy + cmdline switch in the browser process. |
| 1030 | // For renderer and utility (e.g. NetworkService) processes the switch is the |
| 1031 | // only available source, so below the combined (pref/policy + cmdline) |
| 1032 | // allowlist of secure origins is injected into |cmdline| for these other |
| 1033 | // processes. |
| 1034 | std::vector<std::string> allowlist = |
| 1035 | network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist(); |
| 1036 | if (!allowlist.empty()) { |
| 1037 | cmdline->AppendSwitchASCII( |
| 1038 | network::switches::kUnsafelyTreatInsecureOriginAsSecure, |
| 1039 | base::JoinString(allowlist, ",")); |
| 1040 | } |
| 1041 | } |
| 1042 | |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 1043 | #if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 1044 | // Returns the full path to |module_name|. Both dev builds (where |module_name| |
| 1045 | // is in the current executable's directory) and proper installs (where |
| 1046 | // |module_name| is in a versioned sub-directory of the current executable's |
| 1047 | // directory) are supported. The identified file is not guaranteed to exist. |
| 1048 | base::FilePath GetModulePath(base::StringPiece16 module_name) { |
| 1049 | base::FilePath exe_dir; |
| 1050 | const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir); |
| 1051 | DCHECK(has_path); |
| 1052 | |
| 1053 | // Look for the module in a versioned sub-directory of the current |
| 1054 | // executable's directory and return the path if it can be read. This is the |
| 1055 | // expected location of modules for proper installs. |
| 1056 | const base::FilePath module_path = |
| 1057 | exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name); |
| 1058 | if (base::PathExists(module_path)) |
| 1059 | return module_path; |
| 1060 | |
| 1061 | // Otherwise, return the path to the module in the current executable's |
| 1062 | // directory. This is the expected location of modules for dev builds. |
| 1063 | return exe_dir.Append(module_name); |
| 1064 | } |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 1065 | #endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) && |
| 1066 | // !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 1067 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 1068 | void MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 1069 | std::unique_ptr<content::NavigationThrottle> maybe_throttle, |
| 1070 | std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles) { |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 1071 | if (maybe_throttle) |
| 1072 | throttles->push_back(std::move(maybe_throttle)); |
| 1073 | } |
| 1074 | |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 1075 | void MaybeAddThrottles( |
| 1076 | std::vector<std::unique_ptr<content::NavigationThrottle>> additional, |
| 1077 | std::vector<std::unique_ptr<content::NavigationThrottle>>* combined) { |
| 1078 | combined->insert(combined->end(), std::make_move_iterator(additional.begin()), |
| 1079 | std::make_move_iterator(additional.end())); |
| 1080 | } |
| 1081 | |
Evan Stade | 1e71d6dd | 2019-10-29 03:04:49 | [diff] [blame] | 1082 | // Returns whether |web_contents| is within a hosted app. |
| 1083 | bool IsInHostedApp(WebContents* web_contents) { |
| 1084 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1085 | Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 1086 | return (browser && |
| 1087 | web_app::AppBrowserController::IsForWebAppBrowser(browser)); |
| 1088 | #else |
| 1089 | return false; |
| 1090 | #endif |
| 1091 | } |
| 1092 | |
Lily Chen | c2c9e9f | 2019-12-05 19:55:31 | [diff] [blame] | 1093 | void MaybeRecordSameSiteCookieEngagementHistogram( |
| 1094 | content::RenderFrameHost* render_frame_host, |
| 1095 | blink::mojom::WebFeature feature) { |
| 1096 | if (feature != blink::mojom::WebFeature::kCookieNoSameSite && |
| 1097 | feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) { |
| 1098 | return; |
| 1099 | } |
| 1100 | |
| 1101 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 1102 | DCHECK(render_frame_host); |
| 1103 | |
| 1104 | content::BrowserContext* browser_context = |
| 1105 | WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext(); |
| 1106 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1107 | SiteEngagementService* site_engagement_service = |
| 1108 | SiteEngagementService::Get(profile); |
| 1109 | if (!site_engagement_service) |
| 1110 | return; |
| 1111 | |
| 1112 | blink::mojom::EngagementLevel engagement_level = |
| 1113 | site_engagement_service->GetEngagementLevel( |
| 1114 | render_frame_host->GetLastCommittedURL()); |
| 1115 | if (feature == blink::mojom::WebFeature::kCookieNoSameSite) { |
| 1116 | UMA_HISTOGRAM_ENUMERATION( |
| 1117 | "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite", |
| 1118 | engagement_level); |
| 1119 | } else { |
| 1120 | UMA_HISTOGRAM_ENUMERATION( |
| 1121 | "Net.SameSiteBlockedCookieSiteEngagement." |
| 1122 | "CookieInsecureAndSameSiteNone", |
| 1123 | engagement_level); |
| 1124 | } |
| 1125 | } |
| 1126 | |
Ken Rockot | 4408a0f | 2020-07-27 19:40:54 | [diff] [blame] | 1127 | bool IsErrorPageAutoReloadEnabled() { |
| 1128 | const base::CommandLine& command_line = |
| 1129 | *base::CommandLine::ForCurrentProcess(); |
| 1130 | if (command_line.HasSwitch(switches::kEnableAutomation)) |
| 1131 | return false; |
| 1132 | if (command_line.HasSwitch(switches::kEnableAutoReload)) |
| 1133 | return true; |
| 1134 | if (command_line.HasSwitch(switches::kDisableAutoReload)) |
| 1135 | return false; |
| 1136 | return true; |
| 1137 | } |
| 1138 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 1139 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 1140 | |
Aaron Tagliaboschi | 19ad8d3 | 2020-05-12 20:10:44 | [diff] [blame] | 1141 | // Generate a pseudo-random permutation of the following brand/version pairs: |
| 1142 | // 1. The base project (i.e. Chromium) |
| 1143 | // 2. The browser brand, if available |
| 1144 | // 3. A randomized string containing escaped characters to ensure proper |
| 1145 | // header parsing, along with an arbitrarily low version to ensure proper |
| 1146 | // version checking. |
| 1147 | blink::UserAgentBrandList GenerateBrandVersionList( |
| 1148 | int seed, |
| 1149 | base::Optional<std::string> brand, |
| 1150 | std::string major_version) { |
| 1151 | DCHECK_GE(seed, 0); |
| 1152 | const int npermutations = 6; // 3! |
| 1153 | int permutation = seed % npermutations; |
| 1154 | |
| 1155 | // Pick a stable permutation seeded by major version number. any values here |
| 1156 | // and in order should be under three. |
| 1157 | const std::vector<std::vector<int>> orders{{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, |
| 1158 | {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}; |
| 1159 | const std::vector<int> order = orders[permutation]; |
| 1160 | DCHECK_EQ(6u, orders.size()); |
| 1161 | DCHECK_EQ(3u, order.size()); |
| 1162 | |
| 1163 | const std::vector<std::string> escaped_chars = {"\\", "\"", ";"}; |
| 1164 | std::string greasey_brand = |
| 1165 | base::StrCat({escaped_chars[order[0]], "Not", escaped_chars[order[1]], |
| 1166 | "A", escaped_chars[order[2]], "Brand"}); |
| 1167 | |
| 1168 | blink::UserAgentBrandVersion greasey_bv = {greasey_brand, "99"}; |
| 1169 | blink::UserAgentBrandVersion chromium_bv = {"Chromium", major_version}; |
| 1170 | |
| 1171 | blink::UserAgentBrandList greased_brand_version_list(3); |
| 1172 | |
| 1173 | if (brand) { |
| 1174 | blink::UserAgentBrandVersion brand_bv = {brand.value(), major_version}; |
| 1175 | |
| 1176 | greased_brand_version_list[order[0]] = greasey_bv; |
| 1177 | greased_brand_version_list[order[1]] = chromium_bv; |
| 1178 | greased_brand_version_list[order[2]] = brand_bv; |
| 1179 | } else { |
| 1180 | greased_brand_version_list[seed % 2] = greasey_bv; |
| 1181 | greased_brand_version_list[(seed + 1) % 2] = chromium_bv; |
| 1182 | |
| 1183 | // If left, the last element would make a blank "" at the end of the header. |
| 1184 | greased_brand_version_list.pop_back(); |
| 1185 | } |
| 1186 | |
| 1187 | return greased_brand_version_list; |
| 1188 | } |
| 1189 | |
| 1190 | const blink::UserAgentBrandList& GetBrandVersionList() { |
| 1191 | static const base::NoDestructor<blink::UserAgentBrandList> |
| 1192 | greased_brand_version_list([] { |
| 1193 | int major_version_number; |
| 1194 | std::string major_version = version_info::GetMajorVersionNumber(); |
| 1195 | base::StringToInt(major_version, &major_version_number); |
| 1196 | base::Optional<std::string> brand; |
| 1197 | #if !BUILDFLAG(CHROMIUM_BRANDING) |
| 1198 | brand = version_info::GetProductName(); |
| 1199 | #endif |
| 1200 | return GenerateBrandVersionList(major_version_number, brand, |
| 1201 | major_version); |
| 1202 | }()); |
| 1203 | return *greased_brand_version_list; |
| 1204 | } |
| 1205 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1206 | std::string GetUserAgent() { |
| 1207 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1208 | if (command_line->HasSwitch(switches::kUserAgent)) { |
| 1209 | std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent); |
| 1210 | if (net::HttpUtil::IsValidHeaderValue(ua)) |
| 1211 | return ua; |
| 1212 | LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent; |
| 1213 | } |
| 1214 | |
John Delaney | ac24e57 | 2019-04-30 19:47:02 | [diff] [blame] | 1215 | if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) { |
| 1216 | return content::GetFrozenUserAgent( |
Maks Orlovich | 449df8f | 2020-04-02 21:21:35 | [diff] [blame] | 1217 | command_line->HasSwitch(switches::kUseMobileUserAgent), |
| 1218 | version_info::GetMajorVersionNumber()); |
John Delaney | ac24e57 | 2019-04-30 19:47:02 | [diff] [blame] | 1219 | } |
| 1220 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1221 | std::string product = GetProduct(); |
| 1222 | #if defined(OS_ANDROID) |
| 1223 | if (command_line->HasSwitch(switches::kUseMobileUserAgent)) |
| 1224 | product += " Mobile"; |
| 1225 | #endif |
| 1226 | return content::BuildUserAgentFromProduct(product); |
| 1227 | } |
| 1228 | |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1229 | blink::UserAgentMetadata GetUserAgentMetadata() { |
| 1230 | blink::UserAgentMetadata metadata; |
Aaron Tagliaboschi | 9f01b68 | 2020-05-05 21:03:17 | [diff] [blame] | 1231 | |
Aaron Tagliaboschi | 19ad8d3 | 2020-05-12 20:10:44 | [diff] [blame] | 1232 | metadata.brand_version_list = GetBrandVersionList(); |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 1233 | metadata.full_version = version_info::GetVersionNumber(); |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1234 | metadata.platform = version_info::GetOSType(); |
Yoav Weiss | 4838f1b | 2020-04-30 21:37:00 | [diff] [blame] | 1235 | metadata.platform_version = |
| 1236 | content::GetOSVersion(content::IncludeAndroidBuildNumber::Exclude, |
| 1237 | content::IncludeAndroidModel::Exclude); |
Aaron Tagliaboschi | 0585bc93 | 2020-05-08 20:03:17 | [diff] [blame] | 1238 | metadata.architecture = content::GetLowEntropyCpuArchitecture(); |
Aaron Tagliaboschi | cb8d3ee | 2019-12-09 19:31:36 | [diff] [blame] | 1239 | metadata.model = content::BuildModelInfo(); |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1240 | |
Aaron Tagliaboschi | be775e1 | 2019-12-09 19:33:04 | [diff] [blame] | 1241 | metadata.mobile = false; |
| 1242 | #if defined(OS_ANDROID) |
| 1243 | metadata.mobile = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1244 | switches::kUseMobileUserAgent); |
| 1245 | #endif |
| 1246 | |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1247 | return metadata; |
| 1248 | } |
| 1249 | |
Ran Ji | a96d43d4 | 2018-05-02 17:14:53 | [diff] [blame] | 1250 | ChromeContentBrowserClient::ChromeContentBrowserClient( |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 1251 | StartupData* startup_data) |
Wojciech Dzierżanowski | e7c8e3f | 2019-09-27 20:50:31 | [diff] [blame] | 1252 | : startup_data_(startup_data) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1253 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 1254 | extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 1255 | #endif |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 1256 | |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 1257 | #if defined(OS_CHROMEOS) |
| 1258 | extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart); |
| 1259 | #endif // defined(OS_CHROMEOS) |
| 1260 | |
John Lee | 0ee748bf | 2019-12-11 21:35:44 | [diff] [blame] | 1261 | #if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP) |
| 1262 | extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart); |
| 1263 | #endif |
| 1264 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1265 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1266 | extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1267 | #endif |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 1268 | |
Sigurdur Asgeirsson | 7069667 | 2019-02-08 16:14:51 | [diff] [blame] | 1269 | extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | ChromeContentBrowserClient::~ChromeContentBrowserClient() { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1273 | for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i) |
| 1274 | delete extra_parts_[i]; |
| 1275 | extra_parts_.clear(); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1276 | } |
| 1277 | |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 1278 | // static |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1279 | void ChromeContentBrowserClient::RegisterLocalStatePrefs( |
| 1280 | PrefRegistrySimple* registry) { |
Greg Thompson | 8c922756 | 2019-08-05 17:47:13 | [diff] [blame] | 1281 | registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath()); |
| 1282 | registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1283 | registry->RegisterStringPref(prefs::kIsolateOrigins, std::string()); |
| 1284 | registry->RegisterBooleanPref(prefs::kSitePerProcess, false); |
Francois Doray | 424bd99 | 2019-10-16 20:59:46 | [diff] [blame] | 1285 | registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | // static |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 1289 | void ChromeContentBrowserClient::RegisterProfilePrefs( |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 1290 | user_prefs::PrefRegistrySyncable* registry) { |
raymes | aa60872 | 2015-04-27 03:00:25 | [diff] [blame] | 1291 | registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false); |
| 1292 | registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true); |
| 1293 | registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures); |
Pavol Marko | 6adbea7f | 2018-02-20 16:35:28 | [diff] [blame] | 1294 | // Register user prefs for mapping SitePerProcess and IsolateOrigins in |
| 1295 | // user policy in addition to the same named ones in Local State (which are |
| 1296 | // used for mapping the command-line flags). |
| 1297 | registry->RegisterStringPref(prefs::kIsolateOrigins, std::string()); |
| 1298 | registry->RegisterBooleanPref(prefs::kSitePerProcess, false); |
Clark DuVall | aadc244c | 2020-06-06 03:47:14 | [diff] [blame] | 1299 | registry->RegisterListPref( |
| 1300 | site_isolation::prefs::kUserTriggeredIsolatedOrigins); |
Rayan Kanso | 411e84e | 2019-02-13 15:27:40 | [diff] [blame] | 1301 | registry->RegisterDictionaryPref( |
| 1302 | prefs::kDevToolsBackgroundServicesExpirationDict); |
Kunihiko Sakamoto | f586da6 | 2019-03-28 03:03:04 | [diff] [blame] | 1303 | registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 1304 | #if !defined(OS_ANDROID) |
| 1305 | registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false); |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 1306 | registry->RegisterListPref(prefs::kAutoplayWhitelist); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 1307 | #endif |
Takashi Toyoshima | 12844146 | 2019-10-16 04:19:17 | [diff] [blame] | 1308 | registry->RegisterListPref(prefs::kCorsMitigationList); |
| 1309 | registry->RegisterBooleanPref(prefs::kCorsLegacyModeEnabled, false); |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 1310 | } |
| 1311 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1312 | // static |
| 1313 | void ChromeContentBrowserClient::SetApplicationLocale( |
| 1314 | const std::string& locale) { |
Scott Violet | 875789e | 2018-02-02 07:46:48 | [diff] [blame] | 1315 | // The common case is that this function is called early in Chrome startup |
| 1316 | // before any threads are created or registered. When there are no threads, |
| 1317 | // we can just set the string without worrying about threadsafety. |
Gabriel Charette | 192b8c9 | 2018-03-21 21:16:00 | [diff] [blame] | 1318 | if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) { |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 1319 | GetIOThreadApplicationLocale() = locale; |
Scott Violet | 875789e | 2018-02-02 07:46:48 | [diff] [blame] | 1320 | return; |
| 1321 | } |
| 1322 | |
| 1323 | // Otherwise we're being called to change the locale. In this case set it on |
| 1324 | // the IO thread. |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 1325 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1326 | |
Gabriel Charette | e7cdc5cd | 2020-05-27 23:35:05 | [diff] [blame] | 1327 | content::GetIOThreadTaskRunner({})->PostTask( |
| 1328 | FROM_HERE, base::BindOnce(&SetApplicationLocaleOnIOThread, locale)); |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1329 | } |
| 1330 | |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1331 | std::unique_ptr<content::BrowserMainParts> |
| 1332 | ChromeContentBrowserClient::CreateBrowserMainParts( |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1333 | const content::MainFunctionParams& parameters) { |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1334 | std::unique_ptr<ChromeBrowserMainParts> main_parts; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1335 | // Construct the Main browser parts based on the OS type. |
| 1336 | #if defined(OS_WIN) |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 1337 | main_parts = |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1338 | std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_); |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 1339 | #elif defined(OS_MAC) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1340 | main_parts = |
| 1341 | std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_); |
| 1342 | #elif defined(OS_CHROMEOS) |
| 1343 | main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>( |
| 1344 | parameters, startup_data_); |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 1345 | #elif defined(OS_LINUX) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1346 | main_parts = |
| 1347 | std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_); |
[email protected] | 6e677a34 | 2012-02-11 01:21:14 | [diff] [blame] | 1348 | #elif defined(OS_ANDROID) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1349 | main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters, |
| 1350 | startup_data_); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1351 | #elif defined(OS_POSIX) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1352 | main_parts = |
| 1353 | std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1354 | #else |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1355 | NOTREACHED(); |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1356 | main_parts = |
| 1357 | std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1358 | #endif |
| 1359 | |
Xi Han | 9fd4400 | 2019-04-30 17:39:36 | [diff] [blame] | 1360 | bool add_profiles_extra_parts = true; |
| 1361 | #if defined(OS_ANDROID) |
| 1362 | if (startup_data_->HasBuiltProfilePrefService()) |
| 1363 | add_profiles_extra_parts = false; |
| 1364 | #endif |
| 1365 | if (add_profiles_extra_parts) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1366 | chrome::AddProfilesExtraParts(main_parts.get()); |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 1367 | |
Xi Han | 9fd4400 | 2019-04-30 17:39:36 | [diff] [blame] | 1368 | // Construct additional browser parts. Stages are called in the order in |
| 1369 | // which they are added. |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 1370 | #if defined(TOOLKIT_VIEWS) |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 1371 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1372 | main_parts->AddParts( |
| 1373 | std::make_unique<ChromeBrowserMainExtraPartsViewsLinux>()); |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 1374 | #else |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1375 | main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsViews>()); |
James Cook | f9d34d2 | 2017-10-04 16:39:35 | [diff] [blame] | 1376 | #endif |
| 1377 | #endif |
| 1378 | |
| 1379 | #if defined(OS_CHROMEOS) |
| 1380 | // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos. |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1381 | main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsAsh>()); |
sky | cea631e | 2016-12-16 21:52:22 | [diff] [blame] | 1382 | #endif |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 1383 | |
James Cook | be13cc0 | 2020-06-29 22:32:51 | [diff] [blame] | 1384 | #if BUILDFLAG(IS_LACROS) |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1385 | main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsLacros>()); |
James Cook | be13cc0 | 2020-06-29 22:32:51 | [diff] [blame] | 1386 | #endif |
| 1387 | |
Maksim Sisov | 1686fc2 | 2020-06-17 07:59:20 | [diff] [blame] | 1388 | #if defined(USE_X11) || defined(USE_OZONE) |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1389 | main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsOzone>()); |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 1390 | #endif |
| 1391 | |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1392 | main_parts->AddParts( |
| 1393 | std::make_unique<ChromeBrowserMainExtraPartsPerformanceManager>()); |
Etienne Bergeron | 05d6253 | 2017-10-13 18:24:00 | [diff] [blame] | 1394 | |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1395 | main_parts->AddParts( |
| 1396 | std::make_unique<ChromeBrowserMainExtraPartsProfiling>()); |
Albert J. Wong | 59d85acb | 2017-08-10 00:50:57 | [diff] [blame] | 1397 | |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1398 | main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsMemory>()); |
Sebastien Marchand | 8c008810 | 2019-10-11 16:47:56 | [diff] [blame] | 1399 | |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1400 | chrome::AddMetricsExtraParts(main_parts.get()); |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 1401 | |
Zhenyao Mo | 7314465 | 2020-04-06 18:55:05 | [diff] [blame] | 1402 | // Always add ChromeBrowserMainExtraPartsGpu last to make sure |
| 1403 | // GpuDataManager initialization could pick up about:flags settings. |
James Cook | 42e93306 | 2020-07-06 20:56:12 | [diff] [blame] | 1404 | main_parts->AddParts(std::make_unique<ChromeBrowserMainExtraPartsGpu>()); |
Zhenyao Mo | 7314465 | 2020-04-06 18:55:05 | [diff] [blame] | 1405 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1406 | return main_parts; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1407 | } |
| 1408 | |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1409 | void ChromeContentBrowserClient::PostAfterStartupTask( |
Brett Wilson | e1a7042 | 2017-09-12 05:10:09 | [diff] [blame] | 1410 | const base::Location& from_here, |
Gabriel Charette | e926fc1 | 2019-12-16 19:00:02 | [diff] [blame] | 1411 | const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
tzik | 6e42784 | 2017-04-05 10:13:21 | [diff] [blame] | 1412 | base::OnceClosure task) { |
tzik | 070c8ffb | 2017-03-29 05:28:12 | [diff] [blame] | 1413 | AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task)); |
John Abd-El-Malek | 0e82fe7f | 2019-07-27 00:06:29 | [diff] [blame] | 1414 | |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 1415 | InitNetworkContextsParentDirectory(); |
| 1416 | |
John Abd-El-Malek | 0e82fe7f | 2019-07-27 00:06:29 | [diff] [blame] | 1417 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1418 | safe_browsing_service_ = g_browser_process->safe_browsing_service(); |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1419 | } |
| 1420 | |
falken | b09d443f | 2016-04-07 12:36:12 | [diff] [blame] | 1421 | bool ChromeContentBrowserClient::IsBrowserStartupComplete() { |
| 1422 | return AfterStartupTaskUtils::IsBrowserStartupComplete(); |
| 1423 | } |
| 1424 | |
Gabriel Charette | c8cca99 | 2017-08-10 18:21:49 | [diff] [blame] | 1425 | void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() { |
| 1426 | AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); |
| 1427 | } |
| 1428 | |
John Abd-El-Malek | 9d57f9c | 2019-02-20 18:50:04 | [diff] [blame] | 1429 | bool ChromeContentBrowserClient::IsShuttingDown() { |
Greg Thompson | ae8a5b1 | 2019-11-21 12:35:36 | [diff] [blame] | 1430 | return browser_shutdown::HasShutdownStarted(); |
John Abd-El-Malek | 9d57f9c | 2019-02-20 18:50:04 | [diff] [blame] | 1431 | } |
| 1432 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 1433 | std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1434 | content::BrowserContext* browser_context, |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 1435 | const GURL& site) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1436 | std::string partition_id; |
| 1437 | |
| 1438 | // The partition ID for webview guest processes is the string value of its |
| 1439 | // SiteInstance URL - "chrome-guest://app_id/persist?partition". |
rogerta | 5f5bb82 | 2015-12-17 03:24:45 | [diff] [blame] | 1440 | if (site.SchemeIs(content::kGuestScheme)) |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1441 | partition_id = site.spec(); |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1442 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
blundell | f650ea0 | 2016-02-08 11:50:50 | [diff] [blame] | 1443 | // The partition ID for extensions with isolated storage is treated similarly |
| 1444 | // to the above. |
Aaron Colwell | 8c43064 | 2020-08-04 01:55:20 | [diff] [blame] | 1445 | else if (extensions::util::IsExtensionSiteWithIsolatedStorage( |
| 1446 | site, browser_context)) |
blundell | f650ea0 | 2016-02-08 11:50:50 | [diff] [blame] | 1447 | partition_id = site.spec(); |
| 1448 | #endif |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1449 | |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 1450 | DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1451 | return partition_id; |
| 1452 | } |
| 1453 | |
| 1454 | bool ChromeContentBrowserClient::IsValidStoragePartitionId( |
| 1455 | content::BrowserContext* browser_context, |
| 1456 | const std::string& partition_id) { |
| 1457 | // The default ID is empty and is always valid. |
| 1458 | if (partition_id.empty()) |
| 1459 | return true; |
| 1460 | |
| 1461 | return GURL(partition_id).is_valid(); |
| 1462 | } |
| 1463 | |
Bret Sepulveda | 5665215 | 2020-06-24 14:47:13 | [diff] [blame] | 1464 | content::StoragePartitionConfig |
| 1465 | ChromeContentBrowserClient::GetStoragePartitionConfigForSite( |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1466 | content::BrowserContext* browser_context, |
Bret Sepulveda | 5665215 | 2020-06-24 14:47:13 | [diff] [blame] | 1467 | const GURL& site) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1468 | // Default to the browser-wide storage partition and override based on |site| |
| 1469 | // below. |
Bret Sepulveda | 5665215 | 2020-06-24 14:47:13 | [diff] [blame] | 1470 | content::StoragePartitionConfig storage_partition_config = |
| 1471 | content::StoragePartitionConfig::CreateDefault(); |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1472 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1473 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Aaron Colwell | 0ee2213 | 2020-06-23 00:28:41 | [diff] [blame] | 1474 | if (extensions::WebViewGuest::GetGuestPartitionConfigForSite( |
Bret Sepulveda | 5665215 | 2020-06-24 14:47:13 | [diff] [blame] | 1475 | site, &storage_partition_config)) { |
| 1476 | return storage_partition_config; |
Aaron Colwell | 0ee2213 | 2020-06-23 00:28:41 | [diff] [blame] | 1477 | } |
[email protected] | 3f24f97c | 2013-11-17 21:53:33 | [diff] [blame] | 1478 | |
Aaron Colwell | 8c43064 | 2020-08-04 01:55:20 | [diff] [blame] | 1479 | if (site.SchemeIs(extensions::kExtensionScheme)) { |
| 1480 | // The host in an extension site URL is the extension_id. |
Aaron Colwell | 0ee2213 | 2020-06-23 00:28:41 | [diff] [blame] | 1481 | CHECK(site.has_host()); |
Aaron Colwell | 8c43064 | 2020-08-04 01:55:20 | [diff] [blame] | 1482 | return extensions::util::GetStoragePartitionConfigForExtensionId( |
| 1483 | site.host(), browser_context); |
[email protected] | 1df3d97 | 2014-06-11 04:55:18 | [diff] [blame] | 1484 | } |
| 1485 | #endif |
Bret Sepulveda | 5665215 | 2020-06-24 14:47:13 | [diff] [blame] | 1486 | |
| 1487 | return storage_partition_config; |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 1488 | } |
| 1489 | |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 1490 | content::WebContentsViewDelegate* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1491 | ChromeContentBrowserClient::GetWebContentsViewDelegate( |
| 1492 | content::WebContents* web_contents) { |
Chris Hamilton | c3d5c0d1 | 2020-06-01 19:30:05 | [diff] [blame] | 1493 | if (auto* registry = |
| 1494 | performance_manager::PerformanceManagerRegistry::GetInstance()) { |
Chris Hamilton | 4269bab | 2020-06-04 20:03:21 | [diff] [blame] | 1495 | registry->MaybeCreatePageNodeForWebContents(web_contents); |
Chris Hamilton | c3d5c0d1 | 2020-06-01 19:30:05 | [diff] [blame] | 1496 | } |
cm.sanchi | 2db24a8 | 2017-11-16 07:22:10 | [diff] [blame] | 1497 | return CreateWebContentsViewDelegate(web_contents); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 1498 | } |
| 1499 | |
Bo Liu | 4ade6b1b2 | 2017-11-28 02:26:35 | [diff] [blame] | 1500 | bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() { |
| 1501 | #if defined(OS_ANDROID) |
| 1502 | const base::android::ApplicationState app_state = |
| 1503 | base::android::ApplicationStatusListener::GetState(); |
| 1504 | return base::android::APPLICATION_STATE_UNKNOWN == app_state || |
| 1505 | base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state || |
| 1506 | base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state; |
| 1507 | #else |
| 1508 | return true; |
| 1509 | #endif |
| 1510 | } |
| 1511 | |
[email protected] | 6f286274 | 2013-12-20 07:53:19 | [diff] [blame] | 1512 | void ChromeContentBrowserClient::RenderProcessWillLaunch( |
Ken Rockot | 7c6275b | 2019-08-02 20:00:23 | [diff] [blame] | 1513 | content::RenderProcessHost* host) { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1514 | int id = host->GetID(); |
| 1515 | Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 1516 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | b79dd6ba | 2018-12-07 01:20:49 | [diff] [blame] | 1517 | host->AddFilter(new cast::CastTransportHostFilter()); |
thestig | 73f4cdc | 2015-01-15 01:51:06 | [diff] [blame] | 1518 | #endif |
Brett Wilson | 65f951c | 2016-11-03 22:06:12 | [diff] [blame] | 1519 | #if BUILDFLAG(ENABLE_PRINTING) |
[email protected] | 168b7799 | 2014-08-20 11:48:40 | [diff] [blame] | 1520 | host->AddFilter(new printing::PrintingMessageFilter(id, profile)); |
[email protected] | 058e573 | 2012-03-01 22:48:03 | [diff] [blame] | 1521 | #endif |
Darin Fisher | 8c84328c | 2019-07-23 02:50:00 | [diff] [blame] | 1522 | |
Darin Fisher | 09aa722 | 2019-08-29 09:27:36 | [diff] [blame] | 1523 | WebRtcLoggingController::AttachToRenderProcessHost( |
Darin Fisher | 8c84328c | 2019-07-23 02:50:00 | [diff] [blame] | 1524 | host, g_browser_process->webrtc_log_uploader()); |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1525 | |
grunell | 086a411 | 2017-03-02 09:23:04 | [diff] [blame] | 1526 | // The audio manager outlives the host, so it's safe to hand a raw pointer to |
| 1527 | // it to the AudioDebugRecordingsHandler, which is owned by the host. |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1528 | AudioDebugRecordingsHandler* audio_debug_recordings_handler = |
Marina Ciocea | 741a4fb1 | 2018-01-27 09:55:12 | [diff] [blame] | 1529 | new AudioDebugRecordingsHandler(profile); |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1530 | host->SetUserData( |
| 1531 | AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey, |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 1532 | std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>( |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1533 | audio_debug_recordings_handler)); |
| 1534 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 1535 | #if BUILDFLAG(ENABLE_NACL) |
Helen Li | 8897b02 | 2018-05-03 13:29:03 | [diff] [blame] | 1536 | host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(), |
| 1537 | profile->GetPath())); |
[email protected] | 01e5975 | 2013-06-18 00:17:35 | [diff] [blame] | 1538 | #endif |
jeremyim | 364ac118 | 2015-03-03 18:49:43 | [diff] [blame] | 1539 | |
Xiaohan Wang | 9b34281b | 2017-09-08 23:48:33 | [diff] [blame] | 1540 | #if defined(OS_ANDROID) |
| 1541 | // Data cannot be persisted if the profile is off the record. |
| 1542 | host->AddFilter( |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 1543 | new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false)); |
Yuzu Saijo | 2d12ef9 | 2018-08-21 04:52:07 | [diff] [blame] | 1544 | |
| 1545 | // Register CrashMemoryMetricsCollector to report oom related metrics. |
| 1546 | host->SetUserData( |
| 1547 | CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey, |
| 1548 | std::make_unique<CrashMemoryMetricsCollector>(host)); |
Xiaohan Wang | 9b34281b | 2017-09-08 23:48:33 | [diff] [blame] | 1549 | #endif |
| 1550 | |
Jun Cai | db3f93cc | 2018-07-09 21:54:55 | [diff] [blame] | 1551 | Profile* original_profile = profile->GetOriginalProfile(); |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 1552 | RendererUpdaterFactory::GetForProfile(original_profile) |
| 1553 | ->InitializeRenderer(host); |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 1554 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1555 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1556 | extra_parts_[i]->RenderProcessWillLaunch(host); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 1557 | } |
| 1558 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1559 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
Alex Moshchuk | bb99a33 | 2017-11-22 04:49:57 | [diff] [blame] | 1560 | content::BrowserContext* browser_context, |
Alex Moshchuk | a31c788 | 2018-01-17 00:57:30 | [diff] [blame] | 1561 | const GURL& url) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1562 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1563 | if (!profile) |
| 1564 | return url; |
| 1565 | |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1566 | #if !defined(OS_ANDROID) |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 1567 | // If the input |url| should be assigned to the Instant renderer, make its |
| 1568 | // effective URL distinct from other URLs on the search provider's domain. |
Alex Moshchuk | ca17137 | 2017-11-28 16:11:31 | [diff] [blame] | 1569 | // This needs to happen even if |url| corresponds to an isolated origin; see |
| 1570 | // https://crbug.com/755595. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1571 | if (search::ShouldAssignURLToInstantRenderer(url, profile)) |
| 1572 | return search::GetEffectiveURLForInstant(url, profile); |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1573 | #endif |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 1574 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1575 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Alex Moshchuk | a31c788 | 2018-01-17 00:57:30 | [diff] [blame] | 1576 | return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile, |
| 1577 | url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1578 | #else |
| 1579 | return url; |
| 1580 | #endif |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1581 | } |
| 1582 | |
Alexander Yashkin | 6aedc6e | 2018-08-15 08:58:45 | [diff] [blame] | 1583 | bool ChromeContentBrowserClient:: |
| 1584 | ShouldCompareEffectiveURLsForSiteInstanceSelection( |
| 1585 | content::BrowserContext* browser_context, |
| 1586 | content::SiteInstance* candidate_site_instance, |
| 1587 | bool is_main_frame, |
| 1588 | const GURL& candidate_url, |
| 1589 | const GURL& destination_url) { |
| 1590 | DCHECK(browser_context); |
| 1591 | DCHECK(candidate_site_instance); |
| 1592 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1593 | return ChromeContentBrowserClientExtensionsPart:: |
| 1594 | ShouldCompareEffectiveURLsForSiteInstanceSelection( |
| 1595 | browser_context, candidate_site_instance, is_main_frame, |
| 1596 | candidate_url, destination_url); |
| 1597 | #else |
| 1598 | return true; |
| 1599 | #endif |
| 1600 | } |
| 1601 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 1602 | bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() { |
Ahmed Fakhry | e6a2c64 | 2018-06-20 02:58:41 | [diff] [blame] | 1603 | #if defined(OS_ANDROID) |
| 1604 | return true; |
| 1605 | #elif defined(OS_CHROMEOS) |
Xiyuan Xia | fc9f3813 | 2019-08-02 00:51:42 | [diff] [blame] | 1606 | return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode(); |
Ahmed Fakhry | e6a2c64 | 2018-06-20 02:58:41 | [diff] [blame] | 1607 | #else |
| 1608 | return false; |
| 1609 | #endif // defined(OS_ANDROID) |
| 1610 | } |
| 1611 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1612 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1613 | content::BrowserContext* browser_context, |
Aaron Colwell | abb540b | 2020-05-05 19:15:59 | [diff] [blame] | 1614 | const GURL& site_url) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1615 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1616 | if (!profile) |
| 1617 | return false; |
| 1618 | |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1619 | // NTP should use process-per-site. This is a performance optimization to |
| 1620 | // reduce process count associated with NTP tabs. |
Tibor Goldschwendt | 52e168c | 2020-06-01 22:17:44 | [diff] [blame] | 1621 | if (site_url == GURL(chrome::kChromeUINewTabURL) || |
| 1622 | site_url == GURL(chrome::kChromeUINewTabPageURL)) { |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1623 | return true; |
Tibor Goldschwendt | 52e168c | 2020-06-01 22:17:44 | [diff] [blame] | 1624 | } |
Peter Boström | 8e9b163 | 2019-08-22 23:12:47 | [diff] [blame] | 1625 | |
| 1626 | // The web footer experiment should share its renderer to not effectively |
| 1627 | // instantiate one per window. See https://crbug.com/993502. |
Aaron Colwell | abb540b | 2020-05-05 19:15:59 | [diff] [blame] | 1628 | if (site_url == GURL(chrome::kChromeUIWebFooterExperimentURL)) |
Peter Boström | 8e9b163 | 2019-08-22 23:12:47 | [diff] [blame] | 1629 | return true; |
| 1630 | |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1631 | #if !defined(OS_ANDROID) |
Aaron Colwell | abb540b | 2020-05-05 19:15:59 | [diff] [blame] | 1632 | if (search::ShouldUseProcessPerSiteForInstantSiteURL(site_url, profile)) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1633 | return true; |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1634 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1635 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1636 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1637 | if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite( |
Aaron Colwell | abb540b | 2020-05-05 19:15:59 | [diff] [blame] | 1638 | profile, site_url)) |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1639 | return true; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1640 | #endif |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1641 | |
| 1642 | // Non-extension, non-NTP URLs should generally use process-per-site-instance |
| 1643 | // (rather than process-per-site). |
| 1644 | return false; |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1645 | } |
| 1646 | |
Lukasz Anforowicz | 32d2712 | 2018-04-09 21:48:33 | [diff] [blame] | 1647 | bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost( |
| 1648 | content::BrowserContext* browser_context, |
| 1649 | const GURL& site_url) { |
| 1650 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1651 | if (!profile) |
| 1652 | return false; |
| 1653 | |
| 1654 | #if !defined(OS_ANDROID) |
| 1655 | // Instant renderers should not use a spare process, because they require |
| 1656 | // passing switches::kInstantProcess to the renderer process when it |
| 1657 | // launches. A spare process is launched earlier, before it is known which |
| 1658 | // navigation will use it, so it lacks this flag. |
| 1659 | if (search::ShouldAssignURLToInstantRenderer(site_url, profile)) |
| 1660 | return false; |
| 1661 | #endif |
| 1662 | |
| 1663 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1664 | return ChromeContentBrowserClientExtensionsPart:: |
| 1665 | ShouldUseSpareRenderProcessHost(profile, site_url); |
| 1666 | #else |
| 1667 | return true; |
| 1668 | #endif |
| 1669 | } |
| 1670 | |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1671 | bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess( |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1672 | content::BrowserContext* browser_context, |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1673 | const GURL& effective_site_url) { |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1674 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1675 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1676 | if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess( |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1677 | browser_context, effective_site_url)) { |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1678 | return true; |
| 1679 | } |
| 1680 | #endif |
| 1681 | return false; |
| 1682 | } |
| 1683 | |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1684 | // TODO(creis, nick): https://crbug.com/160576 describes a weakness in our |
| 1685 | // origin-lock enforcement, where we don't have a way to efficiently know |
| 1686 | // effective URLs on the IO thread, and wind up killing processes that e.g. |
| 1687 | // request cookies for their actual URL. This whole function (and its |
| 1688 | // ExtensionsPart) should be removed once we add that ability to the IO thread. |
W. James MacLean | e84fa11 | 2020-07-14 17:25:54 | [diff] [blame] | 1689 | bool ChromeContentBrowserClient::ShouldLockProcess( |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1690 | content::BrowserContext* browser_context, |
| 1691 | const GURL& effective_site_url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1692 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
W. James MacLean | e84fa11 | 2020-07-14 17:25:54 | [diff] [blame] | 1693 | if (!ChromeContentBrowserClientExtensionsPart::ShouldLockProcess( |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1694 | browser_context, effective_site_url)) { |
| 1695 | return false; |
| 1696 | } |
| 1697 | #endif |
| 1698 | return true; |
creis | e5d6d173 | 2015-08-25 19:47:06 | [diff] [blame] | 1699 | } |
| 1700 | |
Nasko Oskov | 3902367 | 2020-05-06 17:31:14 | [diff] [blame] | 1701 | bool ChromeContentBrowserClient::DoesWebUISchemeRequireProcessLock( |
| 1702 | base::StringPiece scheme) { |
| 1703 | // Note: This method can be called from multiple threads. It is not safe to |
| 1704 | // assume it runs only on the UI thread. |
| 1705 | |
| 1706 | // chrome-search: documents commit only in the NTP instant process and are not |
Alex Moshchuk | 7de3846 | 2020-05-20 00:05:37 | [diff] [blame] | 1707 | // locked to chrome-search: origin. Locking to chrome-search would kill |
| 1708 | // processes upon legitimate requests for cookies from the search engine's |
| 1709 | // domain. |
Nasko Oskov | 3902367 | 2020-05-06 17:31:14 | [diff] [blame] | 1710 | if (scheme == chrome::kChromeSearchScheme) |
| 1711 | return false; |
| 1712 | |
| 1713 | // All other WebUIs must be locked to origin. |
| 1714 | return true; |
| 1715 | } |
| 1716 | |
Maks Orlovich | 0e23e31 | 2019-07-16 13:13:56 | [diff] [blame] | 1717 | bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel( |
Lily Chen | 0db055b | 2019-11-15 20:29:02 | [diff] [blame] | 1718 | base::StringPiece scheme, |
| 1719 | bool is_embedded_origin_secure) { |
Lily Chen | 2387bd9 | 2020-06-02 21:15:27 | [diff] [blame] | 1720 | // This is needed to bypass the normal SameSite rules for any chrome:// page |
| 1721 | // embedding a secure origin, regardless of the registrable domains of any |
| 1722 | // intervening frames. For example, this is needed for browser UI to interact |
| 1723 | // with SameSite cookies on accounts.google.com, which are used for logging |
| 1724 | // into Cloud Print from chrome://print, for displaying a list of available |
| 1725 | // accounts on the NTP (chrome://new-tab-page), etc. |
Lily Chen | 0db055b | 2019-11-15 20:29:02 | [diff] [blame] | 1726 | if (is_embedded_origin_secure && scheme == content::kChromeUIScheme) |
| 1727 | return true; |
Maks Orlovich | 0e23e31 | 2019-07-16 13:13:56 | [diff] [blame] | 1728 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1729 | return scheme == extensions::kExtensionScheme; |
| 1730 | #else |
| 1731 | return false; |
| 1732 | #endif |
| 1733 | } |
| 1734 | |
Lily Chen | 0db055b | 2019-11-15 20:29:02 | [diff] [blame] | 1735 | bool ChromeContentBrowserClient:: |
| 1736 | ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel( |
| 1737 | base::StringPiece scheme, |
| 1738 | bool is_embedded_origin_secure) { |
| 1739 | return is_embedded_origin_secure && scheme == content::kChromeUIScheme; |
| 1740 | } |
| 1741 | |
Xiaohan Wang | 15a07af | 2020-05-28 23:24:55 | [diff] [blame] | 1742 | // TODO(crbug.com/1087559): This is based on SubframeTask::GetTitle() |
| 1743 | // implementation. Find a general solution to avoid code duplication. |
| 1744 | std::string ChromeContentBrowserClient::GetSiteDisplayNameForCdmProcess( |
| 1745 | content::BrowserContext* browser_context, |
| 1746 | const GURL& site_url) { |
| 1747 | // By default, use the |site_url| spec as the display name. |
| 1748 | std::string name = site_url.spec(); |
| 1749 | |
| 1750 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1751 | // If |site_url| wraps a chrome extension ID, we can display the extension |
| 1752 | // name instead, which is more human-readable. |
| 1753 | if (site_url.SchemeIs(extensions::kExtensionScheme)) { |
| 1754 | const extensions::Extension* extension = |
| 1755 | extensions::ExtensionRegistry::Get(browser_context) |
| 1756 | ->enabled_extensions() |
| 1757 | .GetExtensionOrAppByURL(site_url); |
| 1758 | if (extension) |
| 1759 | name = extension->name(); |
| 1760 | } |
| 1761 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 1762 | |
| 1763 | return name; |
| 1764 | } |
| 1765 | |
Lukasz Anforowicz | 7097890d | 2019-11-20 21:49:22 | [diff] [blame] | 1766 | void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams( |
Lukasz Anforowicz | e00adef | 2019-12-06 23:07:02 | [diff] [blame] | 1767 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 5f335256 | 2019-11-14 16:53:59 | [diff] [blame] | 1768 | const url::Origin& origin, |
Lukasz Anforowicz | e00adef | 2019-12-06 23:07:02 | [diff] [blame] | 1769 | bool is_for_isolated_world, |
Lukasz Anforowicz | 7097890d | 2019-11-20 21:49:22 | [diff] [blame] | 1770 | network::mojom::URLLoaderFactoryParams* factory_params) { |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1771 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | 7097890d | 2019-11-20 21:49:22 | [diff] [blame] | 1772 | ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams( |
Lukasz Anforowicz | e00adef | 2019-12-06 23:07:02 | [diff] [blame] | 1773 | browser_context, origin, is_for_isolated_world, factory_params); |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1774 | #endif |
| 1775 | } |
| 1776 | |
[email protected] | 73b718f | 2014-01-27 02:59:46 | [diff] [blame] | 1777 | // These are treated as WebUI schemes but do not get WebUI bindings. Also, |
| 1778 | // view-source is allowed for these schemes. |
[email protected] | 8f89dd41 | 2013-04-17 02:35:41 | [diff] [blame] | 1779 | void ChromeContentBrowserClient::GetAdditionalWebUISchemes( |
| 1780 | std::vector<std::string>* additional_schemes) { |
| 1781 | additional_schemes->push_back(chrome::kChromeSearchScheme); |
[email protected] | 474a5a3 | 2014-07-28 18:23:24 | [diff] [blame] | 1782 | additional_schemes->push_back(dom_distiller::kDomDistillerScheme); |
Andrey Kosyakov | 031e9e3 | 2017-08-18 21:00:35 | [diff] [blame] | 1783 | additional_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1784 | } |
| 1785 | |
alexmos | 94875b3b | 2017-03-16 22:19:01 | [diff] [blame] | 1786 | void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes( |
| 1787 | std::vector<std::string>* additional_schemes) { |
| 1788 | GetAdditionalWebUISchemes(additional_schemes); |
| 1789 | |
| 1790 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1791 | additional_schemes->push_back(extensions::kExtensionScheme); |
| 1792 | #endif |
| 1793 | } |
| 1794 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 1795 | bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) { |
dbeam | baee5bd | 2015-09-26 03:07:01 | [diff] [blame] | 1796 | return webui::LogWebUIUrl(web_ui_url); |
| 1797 | } |
| 1798 | |
John Abd-El-Malek | 04bfa853 | 2018-07-12 05:28:22 | [diff] [blame] | 1799 | bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests( |
| 1800 | const url::Origin& origin) { |
| 1801 | return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests( |
| 1802 | origin); |
| 1803 | } |
| 1804 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 1805 | bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { |
| 1806 | return ProfileIOData::IsHandledURL(url); |
| 1807 | } |
| 1808 | |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1809 | bool ChromeContentBrowserClient::CanCommitURL( |
| 1810 | content::RenderProcessHost* process_host, |
| 1811 | const GURL& url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1812 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1813 | return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host, |
| 1814 | url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1815 | #else |
| 1816 | return true; |
| 1817 | #endif |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1818 | } |
| 1819 | |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1820 | void ChromeContentBrowserClient::OverrideNavigationParams( |
| 1821 | SiteInstance* site_instance, |
| 1822 | ui::PageTransition* transition, |
| 1823 | bool* is_renderer_initiated, |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1824 | content::Referrer* referrer, |
| 1825 | base::Optional<url::Origin>* initiator_origin) { |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1826 | DCHECK(transition); |
| 1827 | DCHECK(is_renderer_initiated); |
| 1828 | DCHECK(referrer); |
Moe Ahmadi | 26e2f50 | 2019-07-16 02:34:47 | [diff] [blame] | 1829 | // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to |
| 1830 | // use for making security decisions 99.44% of the time, for detecting the NTP |
| 1831 | // it is reliable and the correct way. See http://crbug.com/624410. |
| 1832 | if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) && |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1833 | ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) { |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1834 | // Clicks on tiles of the new tab page should be treated as if a user |
| 1835 | // clicked on a bookmark. This is consistent with native implementations |
| 1836 | // like Android's. This also helps ensure that security features (like |
| 1837 | // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as |
| 1838 | // browser-initiated. |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1839 | *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK; |
| 1840 | *is_renderer_initiated = false; |
| 1841 | *referrer = content::Referrer(); |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1842 | *initiator_origin = base::nullopt; |
mastiz | a77db699 | 2016-06-30 09:48:42 | [diff] [blame] | 1843 | } |
| 1844 | } |
| 1845 | |
Charles Reis | 29e9dd1 | 2017-09-28 00:59:15 | [diff] [blame] | 1846 | bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP( |
| 1847 | const GURL& url, |
| 1848 | SiteInstance* parent_site_instance) { |
Moe Ahmadi | 26e2f50 | 2019-07-16 02:34:47 | [diff] [blame] | 1849 | // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to |
| 1850 | // use for making security decisions 99.44% of the time, for detecting the NTP |
| 1851 | // it is reliable and the correct way. See http://crbug.com/624410. |
| 1852 | return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance && |
| 1853 | search::IsNTPURL(parent_site_instance->GetSiteURL()); |
Charles Reis | 29e9dd1 | 2017-09-28 00:59:15 | [diff] [blame] | 1854 | } |
| 1855 | |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1856 | bool ChromeContentBrowserClient::IsSuitableHost( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1857 | content::RenderProcessHost* process_host, |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1858 | const GURL& site_url) { |
| 1859 | Profile* profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1860 | Profile::FromBrowserContext(process_host->GetBrowserContext()); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1861 | // 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] | 1862 | // share any host. |
| 1863 | if (!profile) |
| 1864 | return true; |
| 1865 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1866 | #if !defined(OS_ANDROID) |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1867 | // Instant URLs should only be in the instant process and instant process |
| 1868 | // should only have Instant URLs. |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1869 | InstantService* instant_service = |
| 1870 | InstantServiceFactory::GetForProfile(profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1871 | if (instant_service) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1872 | bool is_instant_process = |
| 1873 | instant_service->IsInstantProcess(process_host->GetID()); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1874 | bool should_be_in_instant_process = |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1875 | search::ShouldAssignURLToInstantRenderer(site_url, profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1876 | if (is_instant_process || should_be_in_instant_process) |
| 1877 | return is_instant_process && should_be_in_instant_process; |
| 1878 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1879 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1880 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1881 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1882 | return ChromeContentBrowserClientExtensionsPart::IsSuitableHost( |
| 1883 | profile, process_host, site_url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1884 | #else |
| 1885 | return true; |
| 1886 | #endif |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1887 | } |
| 1888 | |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1889 | bool ChromeContentBrowserClient::MayReuseHost( |
| 1890 | content::RenderProcessHost* process_host) { |
| 1891 | // If there is currently a prerender in progress for the host provided, |
| 1892 | // it may not be shared. We require prerenders to be by themselves in a |
davidben | 879199c | 2015-03-06 00:55:04 | [diff] [blame] | 1893 | // separate process so that we can monitor their resource usage. |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1894 | prerender::PrerenderManager* prerender_manager = |
droger | c154315 | 2016-09-20 13:03:37 | [diff] [blame] | 1895 | prerender::PrerenderManagerFactory::GetForBrowserContext( |
| 1896 | process_host->GetBrowserContext()); |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1897 | if (prerender_manager && |
[email protected] | 2290af2 | 2014-05-26 15:44:49 | [diff] [blame] | 1898 | !prerender_manager->MayReuseProcessHost(process_host)) { |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1899 | return false; |
| 1900 | } |
| 1901 | |
| 1902 | return true; |
| 1903 | } |
| 1904 | |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1905 | bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1906 | content::BrowserContext* browser_context, |
| 1907 | const GURL& url) { |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1908 | // It has to be a valid URL for us to check for an extension. |
| 1909 | if (!url.is_valid()) |
| 1910 | return false; |
| 1911 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1912 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1913 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1914 | return ChromeContentBrowserClientExtensionsPart:: |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1915 | ShouldTryToUseExistingProcessHost(profile, url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1916 | #else |
| 1917 | return false; |
| 1918 | #endif |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1919 | } |
| 1920 | |
Alex Moshchuk | 9c9e388 | 2018-11-02 19:57:03 | [diff] [blame] | 1921 | bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess( |
| 1922 | content::RenderFrameHost* main_frame) { |
| 1923 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1924 | return ChromeContentBrowserClientExtensionsPart:: |
| 1925 | ShouldSubframesTryToReuseExistingProcess(main_frame); |
| 1926 | #else |
| 1927 | return true; |
| 1928 | #endif |
| 1929 | } |
| 1930 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1931 | void ChromeContentBrowserClient::SiteInstanceGotProcess( |
| 1932 | SiteInstance* site_instance) { |
| 1933 | CHECK(site_instance->HasProcess()); |
| 1934 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1935 | Profile* profile = |
| 1936 | Profile::FromBrowserContext(site_instance->GetBrowserContext()); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1937 | if (!profile) |
| 1938 | return; |
| 1939 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1940 | #if !defined(OS_ANDROID) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1941 | // Remember the ID of the Instant process to signal the renderer process |
| 1942 | // on startup in |AppendExtraCommandLineSwitches| below. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1943 | if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(), |
| 1944 | profile)) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1945 | InstantService* instant_service = |
| 1946 | InstantServiceFactory::GetForProfile(profile); |
| 1947 | if (instant_service) |
| 1948 | instant_service->AddInstantProcess(site_instance->GetProcess()->GetID()); |
| 1949 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1950 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1951 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1952 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1953 | extra_parts_[i]->SiteInstanceGotProcess(site_instance); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | void ChromeContentBrowserClient::SiteInstanceDeleting( |
| 1957 | SiteInstance* site_instance) { |
| 1958 | if (!site_instance->HasProcess()) |
| 1959 | return; |
| 1960 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1961 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1962 | extra_parts_[i]->SiteInstanceDeleting(site_instance); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1963 | } |
| 1964 | |
[email protected] | 453f543 | 2013-11-26 19:43:00 | [diff] [blame] | 1965 | bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation( |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1966 | SiteInstance* site_instance, |
Aaron Colwell | 16b4985d | 2019-11-13 00:20:56 | [diff] [blame] | 1967 | const GURL& current_effective_url, |
| 1968 | const GURL& destination_effective_url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1969 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1970 | return ChromeContentBrowserClientExtensionsPart:: |
Aaron Colwell | 16b4985d | 2019-11-13 00:20:56 | [diff] [blame] | 1971 | ShouldSwapBrowsingInstancesForNavigation( |
| 1972 | site_instance, current_effective_url, destination_effective_url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1973 | #else |
| 1974 | return false; |
| 1975 | #endif |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1976 | } |
| 1977 | |
Nasko Oskov | d83b571 | 2018-05-04 04:50:57 | [diff] [blame] | 1978 | bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) { |
| 1979 | // TODO(nasko): Consider supporting error page isolation in subframes if |
| 1980 | // Site Isolation is enabled. |
Nasko Oskov | 55d21e15 | 2018-06-27 23:59:38 | [diff] [blame] | 1981 | return in_main_frame; |
Nasko Oskov | d83b571 | 2018-05-04 04:50:57 | [diff] [blame] | 1982 | } |
| 1983 | |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 1984 | bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) { |
| 1985 | return !url.SchemeIs(chrome::kChromeNativeScheme); |
| 1986 | } |
| 1987 | |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1988 | std::vector<url::Origin> |
| 1989 | ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() { |
| 1990 | std::vector<url::Origin> isolated_origin_list; |
| 1991 | |
Alex Moshchuk | 89352a7 | 2017-10-25 20:25:59 | [diff] [blame] | 1992 | // Sign-in process isolation is not needed on Android, see |
| 1993 | // https://crbug.com/739418. |
| 1994 | #if !defined(OS_ANDROID) |
Alex Moshchuk | 81d2a29e | 2019-07-16 01:14:38 | [diff] [blame] | 1995 | isolated_origin_list.push_back( |
Alex Moshchuk | 36417aa | 2018-06-13 18:01:12 | [diff] [blame] | 1996 | url::Origin::Create(GaiaUrls::GetInstance()->gaia_url())); |
Alex Moshchuk | 89352a7 | 2017-10-25 20:25:59 | [diff] [blame] | 1997 | #endif |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1998 | |
Alex Moshchuk | 81d2a29e | 2019-07-16 01:14:38 | [diff] [blame] | 1999 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 2000 | auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart:: |
| 2001 | GetOriginsRequiringDedicatedProcess(); |
| 2002 | std::move(std::begin(origins_from_extensions), |
| 2003 | std::end(origins_from_extensions), |
| 2004 | std::back_inserter(isolated_origin_list)); |
| 2005 | #endif |
| 2006 | |
Alex Moshchuk | 51e1428b | 2020-04-22 18:00:54 | [diff] [blame] | 2007 | // Include additional origins preloaded with specific browser configurations, |
| 2008 | // if any. For example, this is used on Google Chrome for Android to preload |
| 2009 | // a list of important sites to isolate. |
| 2010 | auto built_in_origins = |
| 2011 | site_isolation::GetBrowserSpecificBuiltInIsolatedOrigins(); |
| 2012 | std::move(std::begin(built_in_origins), std::end(built_in_origins), |
| 2013 | std::back_inserter(isolated_origin_list)); |
| 2014 | |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 2015 | return isolated_origin_list; |
| 2016 | } |
| 2017 | |
Lukasz Anforowicz | 5e201abd | 2018-03-24 00:41:06 | [diff] [blame] | 2018 | bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() { |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 2019 | return base::FeatureList::IsEnabled(features::kSitePerProcess); |
| 2020 | } |
| 2021 | |
| 2022 | bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() { |
Clark DuVall | aadc244c | 2020-06-06 03:47:14 | [diff] [blame] | 2023 | return site_isolation::SiteIsolationPolicy:: |
| 2024 | ShouldDisableSiteIsolationDueToMemoryThreshold(); |
Lukasz Anforowicz | 5e201abd | 2018-03-24 00:41:06 | [diff] [blame] | 2025 | } |
| 2026 | |
Alex Moshchuk | 082b5f8 | 2019-03-14 01:34:16 | [diff] [blame] | 2027 | std::vector<std::string> |
| 2028 | ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() { |
Clark DuVall | aadc244c | 2020-06-06 03:47:14 | [diff] [blame] | 2029 | if (site_isolation::SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled()) |
Alex Moshchuk | 082b5f8 | 2019-03-14 01:34:16 | [diff] [blame] | 2030 | return {"Isolate Password Sites"}; |
| 2031 | else |
| 2032 | return {}; |
| 2033 | } |
| 2034 | |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 2035 | void ChromeContentBrowserClient::PersistIsolatedOrigin( |
| 2036 | content::BrowserContext* context, |
| 2037 | const url::Origin& origin) { |
| 2038 | DCHECK(!context->IsOffTheRecord()); |
| 2039 | Profile* profile = Profile::FromBrowserContext(context); |
| 2040 | ListPrefUpdate update(profile->GetPrefs(), |
Clark DuVall | aadc244c | 2020-06-06 03:47:14 | [diff] [blame] | 2041 | site_isolation::prefs::kUserTriggeredIsolatedOrigins); |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 2042 | base::ListValue* list = update.Get(); |
| 2043 | base::Value value(origin.Serialize()); |
Jan Wilken Dörrie | a8cb5630 | 2019-06-06 18:59:36 | [diff] [blame] | 2044 | if (!base::Contains(list->GetList(), value)) |
Jan Wilken Dörrie | 91e4ef0 | 2019-09-11 08:22:12 | [diff] [blame] | 2045 | list->Append(std::move(value)); |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 2046 | } |
| 2047 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 2048 | bool ChromeContentBrowserClient::IsFileAccessAllowed( |
| 2049 | const base::FilePath& path, |
| 2050 | const base::FilePath& absolute_path, |
| 2051 | const base::FilePath& profile_path) { |
| 2052 | return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path, |
| 2053 | profile_path); |
| 2054 | } |
| 2055 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 2056 | namespace { |
| 2057 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2058 | void MaybeAppendBlinkSettingsSwitchForFieldTrial( |
| 2059 | const base::CommandLine& browser_command_line, |
| 2060 | base::CommandLine* command_line) { |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 2061 | // List of field trials that modify the blink-settings command line flag. No |
| 2062 | // two field trials in the list should specify the same keys, otherwise one |
| 2063 | // field trial may overwrite another. See Source/core/frame/Settings.in in |
| 2064 | // Blink for the list of valid keys. |
| 2065 | static const char* const kBlinkSettingsFieldTrials[] = { |
jkarlin | 3bddb7d | 2016-09-21 18:44:16 | [diff] [blame] | 2066 | // Keys: disallowFetchForDocWrittenScriptsInMainFrame |
| 2067 | // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections |
| 2068 | // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G |
| 2069 | "DisallowFetchForDocWrittenScriptsInMainFrame", |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 2070 | }; |
| 2071 | |
| 2072 | std::vector<std::string> blink_settings; |
| 2073 | for (const char* field_trial_name : kBlinkSettingsFieldTrials) { |
| 2074 | // Each blink-settings field trial should include a forcing_flag group, |
| 2075 | // to make sure that clients that specify the blink-settings flag on the |
| 2076 | // command line are excluded from the experiment groups. To make |
| 2077 | // sure we assign clients that specify this flag to the forcing_flag |
| 2078 | // group, we must call GetVariationParams for each field trial first |
| 2079 | // (for example, before checking HasSwitch() and returning), since |
| 2080 | // GetVariationParams has the side-effect of assigning the client to |
| 2081 | // a field trial group. |
| 2082 | std::map<std::string, std::string> params; |
| 2083 | if (variations::GetVariationParams(field_trial_name, ¶ms)) { |
| 2084 | for (const auto& param : params) { |
| 2085 | blink_settings.push_back(base::StringPrintf( |
| 2086 | "%s=%s", param.first.c_str(), param.second.c_str())); |
| 2087 | } |
| 2088 | } |
| 2089 | } |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 2090 | |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 2091 | if (blink_settings.empty()) { |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2092 | return; |
| 2093 | } |
| 2094 | |
| 2095 | if (browser_command_line.HasSwitch(switches::kBlinkSettings) || |
| 2096 | command_line->HasSwitch(switches::kBlinkSettings)) { |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 2097 | // The field trials should be configured to force users that specify the |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 2098 | // blink-settings flag into a group with no params, and we return |
| 2099 | // above if no params were specified, so it's an error if we reach |
| 2100 | // this point. |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2101 | LOG(WARNING) << "Received field trial params, " |
| 2102 | "but blink-settings switch already specified."; |
| 2103 | return; |
| 2104 | } |
| 2105 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2106 | command_line->AppendSwitchASCII(switches::kBlinkSettings, |
brettw | d94a2214 | 2015-07-15 05:19:26 | [diff] [blame] | 2107 | base::JoinString(blink_settings, ",")); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2108 | } |
| 2109 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 2110 | } // namespace |
| 2111 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2112 | void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 2113 | base::CommandLine* command_line, |
| 2114 | int child_process_id) { |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 2115 | #if defined(OS_MAC) |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2116 | std::unique_ptr<metrics::ClientInfo> client_info = |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2117 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
| 2118 | if (client_info) { |
| 2119 | command_line->AppendSwitchASCII(switches::kMetricsClientID, |
| 2120 | client_info->client_id); |
| 2121 | } |
| 2122 | #elif defined(OS_POSIX) |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 2123 | #if defined(OS_ANDROID) |
| 2124 | bool enable_crash_reporter = true; |
| 2125 | #else |
Joshua Peraza | ce68e2f | 2019-09-23 18:44:24 | [diff] [blame] | 2126 | bool enable_crash_reporter = false; |
| 2127 | if (crash_reporter::IsCrashpadEnabled()) { |
| 2128 | command_line->AppendSwitch(crash_reporter::kEnableCrashpad); |
| 2129 | enable_crash_reporter = true; |
| 2130 | |
| 2131 | int fd; |
| 2132 | pid_t pid; |
| 2133 | if (crash_reporter::GetHandlerSocket(&fd, &pid)) { |
| 2134 | command_line->AppendSwitchASCII( |
| 2135 | crash_reporter::switches::kCrashpadHandlerPid, |
| 2136 | base::NumberToString(pid)); |
| 2137 | } |
| 2138 | } else { |
| 2139 | enable_crash_reporter = breakpad::IsCrashReporterEnabled(); |
| 2140 | } |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 2141 | #endif |
| 2142 | if (enable_crash_reporter) { |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2143 | std::string switch_value; |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2144 | std::unique_ptr<metrics::ClientInfo> client_info = |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 2145 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2146 | if (client_info) |
| 2147 | switch_value = client_info->client_id; |
| 2148 | switch_value.push_back(','); |
Boris Vidolov | 8657801 | 2018-03-21 16:55:25 | [diff] [blame] | 2149 | switch_value.append(chrome::GetChannelName()); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2150 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2151 | switch_value); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2152 | } |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2153 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2154 | |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 2155 | if (logging::DialogsAreSuppressed()) |
| 2156 | command_line->AppendSwitch(switches::kNoErrorDialogs); |
| 2157 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2158 | std::string process_type = |
| 2159 | command_line->GetSwitchValueASCII(switches::kProcessType); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 2160 | const base::CommandLine& browser_command_line = |
| 2161 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 2162 | |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 2163 | static const char* const kCommonSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2164 | switches::kUserAgent, |
| 2165 | switches::kUserDataDir, // Make logs go to the right file. |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 2166 | }; |
| 2167 | command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2168 | base::size(kCommonSwitchNames)); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 2169 | |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2170 | static const char* const kDinosaurEasterEggSwitches[] = { |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 2171 | error_page::switches::kDisableDinosaurEasterEgg, |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 2172 | }; |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2173 | command_line->CopySwitchesFrom(browser_command_line, |
| 2174 | kDinosaurEasterEggSwitches, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2175 | base::size(kDinosaurEasterEggSwitches)); |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 2176 | |
David Van Cleve | 3df6abb | 2019-11-26 17:52:51 | [diff] [blame] | 2177 | if (content::Referrer::ShouldForceLegacyDefaultReferrerPolicy()) |
| 2178 | command_line->AppendSwitch(switches::kForceLegacyDefaultReferrerPolicy); |
| 2179 | |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2180 | #if defined(OS_CHROMEOS) |
[email protected] | 6bdc5227 | 2014-05-27 00:12:33 | [diff] [blame] | 2181 | // On Chrome OS need to pass primary user homedir (in multi-profiles session). |
| 2182 | base::FilePath homedir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 2183 | base::PathService::Get(base::DIR_HOME, &homedir); |
[email protected] | 6bdc5227 | 2014-05-27 00:12:33 | [diff] [blame] | 2184 | command_line->AppendSwitchASCII(chromeos::switches::kHomedir, |
| 2185 | homedir.value().c_str()); |
| 2186 | #endif |
| 2187 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 2188 | if (process_type == switches::kRendererProcess) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2189 | content::RenderProcessHost* process = |
| 2190 | content::RenderProcessHost::FromID(child_process_id); |
| 2191 | Profile* profile = |
| 2192 | process ? Profile::FromBrowserContext(process->GetBrowserContext()) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2193 | : nullptr; |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2194 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2195 | extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line, |
| 2196 | process, profile); |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2197 | } |
| 2198 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2199 | #if defined(OS_CHROMEOS) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2200 | const std::string& login_profile = browser_command_line.GetSwitchValueASCII( |
| 2201 | chromeos::switches::kLoginProfile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2202 | if (!login_profile.empty()) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2203 | command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, |
| 2204 | login_profile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2205 | #endif |
| 2206 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2207 | MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line, |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 2208 | chrome::GetChannel()); |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2209 | if (process) { |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2210 | PrefService* prefs = profile->GetPrefs(); |
| 2211 | // Currently this pref is only registered if applied via a policy. |
| 2212 | if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && |
| 2213 | prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 2214 | // Turn this policy into a command line switch. |
| 2215 | command_line->AppendSwitch(switches::kDisable3DAPIs); |
| 2216 | } |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 2217 | |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2218 | const base::ListValue* switches = |
| 2219 | prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures); |
| 2220 | if (switches) { |
| 2221 | // Enable any deprecated features that have been re-enabled by policy. |
jdoerrie | 601c715 | 2018-10-02 23:43:11 | [diff] [blame] | 2222 | for (auto it = switches->begin(); it != switches->end(); ++it) { |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2223 | std::string switch_to_enable; |
jdoerrie | a5676c6 | 2017-04-11 18:09:14 | [diff] [blame] | 2224 | if (it->GetAsString(&switch_to_enable)) |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2225 | command_line->AppendSwitch(switch_to_enable); |
| 2226 | } |
| 2227 | } |
| 2228 | |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 2229 | #if BUILDFLAG(SAFE_BROWSING_AVAILABLE) |
| 2230 | bool client_side_detection_enabled = |
| 2231 | safe_browsing::IsSafeBrowsingEnabled(*prefs) && |
| 2232 | safe_browsing::ClientSideDetectionServiceFactory::GetForProfile( |
| 2233 | profile); |
| 2234 | #if BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
| 2235 | client_side_detection_enabled &= base::FeatureList::IsEnabled( |
| 2236 | safe_browsing::kClientSideDetectionForAndroid); |
| 2237 | #endif // BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
| 2238 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2239 | // Disable client-side phishing detection in the renderer if it is |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 2240 | // disabled in the Profile preferences, or by command line flag, or by not |
| 2241 | // being enabled on Android. |
| 2242 | if (!client_side_detection_enabled) { |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2243 | command_line->AppendSwitch( |
| 2244 | switches::kDisableClientSidePhishingDetection); |
| 2245 | } |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 2246 | #endif // BUILDFLAG(SAFE_BROWSING_AVAILABLE) |
[email protected] | 0045b0f4 | 2012-07-26 11:52:08 | [diff] [blame] | 2247 | |
vitalybuka | a7ae505 | 2014-09-26 04:11:13 | [diff] [blame] | 2248 | if (prefs->GetBoolean(prefs::kPrintPreviewDisabled)) |
| 2249 | command_line->AppendSwitch(switches::kDisablePrintPreview); |
| 2250 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 2251 | #if !defined(OS_ANDROID) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 2252 | InstantService* instant_service = |
| 2253 | InstantServiceFactory::GetForProfile(profile); |
| 2254 | if (instant_service && |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2255 | instant_service->IsInstantProcess(process->GetID())) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 2256 | command_line->AppendSwitch(switches::kInstantProcess); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2257 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 2258 | #endif |
fqj | ba8749c | 2015-10-29 15:33:07 | [diff] [blame] | 2259 | |
fqj | 38306f7b | 2015-11-02 16:59:06 | [diff] [blame] | 2260 | if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) && |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2261 | !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) { |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 2262 | command_line->AppendSwitch( |
| 2263 | error_page::switches::kDisableDinosaurEasterEgg); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2264 | } |
Daniel Vogelheim | 976f1c2 | 2017-11-22 16:26:03 | [diff] [blame] | 2265 | |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 2266 | MaybeAppendSecureOriginsAllowlistSwitch(command_line); |
| 2267 | |
Amr Aboelkher | b04cbf3 | 2019-04-29 15:17:10 | [diff] [blame] | 2268 | if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) && |
| 2269 | prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) { |
Avi Drissman | fb96126 | 2019-03-05 22:50:29 | [diff] [blame] | 2270 | command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload); |
Amr Aboelkher | b04cbf3 | 2019-04-29 15:17:10 | [diff] [blame] | 2271 | } |
Katie Dillon | c25ee5c9 | 2019-09-12 17:05:42 | [diff] [blame] | 2272 | |
| 2273 | if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) && |
| 2274 | prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) { |
| 2275 | command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal); |
| 2276 | } |
Takashi Toyoshima | 12844146 | 2019-10-16 04:19:17 | [diff] [blame] | 2277 | |
Daniel Libby | c5bfd91f | 2020-03-07 03:44:10 | [diff] [blame] | 2278 | if (prefs->HasPrefPath(prefs::kScrollToTextFragmentEnabled) && |
| 2279 | !prefs->GetBoolean(prefs::kScrollToTextFragmentEnabled)) { |
| 2280 | command_line->AppendSwitch(switches::kDisableScrollToTextFragment); |
| 2281 | } |
| 2282 | |
Takashi Toyoshima | 0dab7330 | 2019-10-18 01:51:36 | [diff] [blame] | 2283 | if (!profile->ShouldEnableOutOfBlinkCors()) { |
| 2284 | command_line->AppendSwitch( |
| 2285 | network::switches::kForceToDisableOutOfBlinkCors); |
| 2286 | } |
Adrienne Walker | 29765129 | 2020-05-08 00:23:18 | [diff] [blame] | 2287 | |
| 2288 | if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) && |
| 2289 | prefs->GetBoolean(prefs::kAppCacheForceEnabled)) { |
| 2290 | command_line->AppendSwitch(switches::kAppCacheForceEnabled); |
| 2291 | } |
Chris Hamilton | 65c4131 | 2020-06-10 13:14:40 | [diff] [blame] | 2292 | |
| 2293 | // The IntensiveWakeUpThrottling feature is typically managed via a |
| 2294 | // base::Feature, but it has a managed policy override. The override is |
| 2295 | // communicated to blink via a custom command-line flag. See |
| 2296 | // PageSchedulerImpl for the other half of related logic. |
| 2297 | PrefService* local_state = g_browser_process->local_state(); |
| 2298 | const PrefService::Preference* pref = local_state->FindPreference( |
| 2299 | policy::policy_prefs::kIntensiveWakeUpThrottlingEnabled); |
| 2300 | if (pref && pref->IsManaged()) { |
| 2301 | command_line->AppendSwitchASCII( |
| 2302 | blink::switches::kIntensiveWakeUpThrottlingPolicy, |
| 2303 | pref->GetValue()->GetBool() |
| 2304 | ? blink::switches::kIntensiveWakeUpThrottlingPolicy_ForceEnable |
| 2305 | : blink::switches:: |
| 2306 | kIntensiveWakeUpThrottlingPolicy_ForceDisable); |
| 2307 | } |
Aaron Tagliaboschi | 8f3a2830 | 2020-06-24 03:08:26 | [diff] [blame] | 2308 | |
| 2309 | // Same as above, but for the blink side of UserAgentClientHints |
| 2310 | if (!local_state->GetBoolean( |
| 2311 | policy::policy_prefs::kUserAgentClientHintsEnabled)) { |
| 2312 | command_line->AppendSwitch( |
| 2313 | blink::switches::kUserAgentClientHintDisable); |
| 2314 | } |
Rakina Zata Amni | c123bd2 | 2020-07-31 19:08:39 | [diff] [blame] | 2315 | |
| 2316 | #if defined(OS_ANDROID) |
| 2317 | // Communicating to content/ for BackForwardCache. |
| 2318 | if (prefs->HasPrefPath(policy::policy_prefs::kBackForwardCacheEnabled) && |
| 2319 | !prefs->GetBoolean(policy::policy_prefs::kBackForwardCacheEnabled)) { |
| 2320 | command_line->AppendSwitch(switches::kDisableBackForwardCache); |
| 2321 | } |
| 2322 | #endif // defined(OS_ANDROID) |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2323 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2324 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2325 | MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line, |
| 2326 | command_line); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2327 | |
mdjones | a6b9e17 | 2016-09-23 16:24:30 | [diff] [blame] | 2328 | #if defined(OS_ANDROID) |
| 2329 | // If the platform is Android, force the distillability service on. |
| 2330 | command_line->AppendSwitch(switches::kEnableDistillabilityService); |
| 2331 | #endif |
| 2332 | |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2333 | // Please keep this in alphabetical order. |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2334 | static const char* const kSwitchNames[] = { |
estade | 0ee9126 | 2014-10-23 19:29:19 | [diff] [blame] | 2335 | autofill::switches::kIgnoreAutocompleteOffForAutofill, |
kolos | ad36993 | 2017-02-23 13:29:41 | [diff] [blame] | 2336 | autofill::switches::kShowAutofillSignatures, |
Chris Mumford | 6b1696b | 2019-01-25 02:54:30 | [diff] [blame] | 2337 | #if defined(OS_CHROMEOS) |
| 2338 | switches::kShortMergeSessionTimeoutForTest, // For tests only. |
| 2339 | #endif |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2340 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 2341 | extensions::switches::kAllowHTTPBackgroundPage, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2342 | extensions::switches::kAllowLegacyExtensionManifests, |
Chris Mumford | 3f0eda9 | 2018-07-23 14:51:17 | [diff] [blame] | 2343 | extensions::switches::kDisableExtensionsHttpThrottling, |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 2344 | extensions::switches::kEnableExperimentalExtensionApis, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2345 | extensions::switches::kExtensionsOnChromeURLs, |
Chris Mumford | 3f0eda9 | 2018-07-23 14:51:17 | [diff] [blame] | 2346 | extensions::switches::kSetExtensionThrottleTestParams, // For tests only. |
[email protected] | 5adb774 | 2020-06-30 14:28:12 | [diff] [blame] | 2347 | extensions::switches::kAllowlistedExtensionID, |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 2348 | #endif |
estark | 4b003b33 | 2015-02-14 01:07:05 | [diff] [blame] | 2349 | switches::kAllowInsecureLocalhost, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2350 | switches::kAppsGalleryURL, |
[email protected] | 09cff7878 | 2014-04-20 22:04:48 | [diff] [blame] | 2351 | switches::kCloudPrintURL, |
[email protected] | 6f5c141a | 2014-04-15 21:44:51 | [diff] [blame] | 2352 | switches::kCloudPrintXmppEndpoint, |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 2353 | switches::kDisableBundledPpapiFlash, |
dslomov | a893e97 | 2014-12-05 09:39:57 | [diff] [blame] | 2354 | switches::kDisableJavaScriptHarmonyShipping, |
Kyle Milka | b5c048e | 2017-07-07 02:38:46 | [diff] [blame] | 2355 | variations::switches::kEnableBenchmarking, |
mdjones | a6b9e17 | 2016-09-23 16:24:30 | [diff] [blame] | 2356 | switches::kEnableDistillabilityService, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2357 | switches::kEnableNaCl, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2358 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | 1b4ec38 | 2014-03-07 02:32:24 | [diff] [blame] | 2359 | switches::kEnableNaClDebug, |
[email protected] | b2c73f4 | 2014-03-07 15:44:48 | [diff] [blame] | 2360 | switches::kEnableNaClNonSfiMode, |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 2361 | #endif |
[email protected] | ce304ce | 2013-02-22 21:54:45 | [diff] [blame] | 2362 | switches::kEnableNetBenchmarking, |
Anatoliy Potapchuk | ce6f880 | 2020-01-30 09:30:34 | [diff] [blame] | 2363 | #if defined(OS_CHROMEOS) |
| 2364 | switches::kForceAppMode, |
| 2365 | #endif |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2366 | #if BUILDFLAG(ENABLE_NACL) |
stichnot | 7040ac83 | 2016-02-24 23:40:59 | [diff] [blame] | 2367 | switches::kForcePNaClSubzero, |
| 2368 | #endif |
Marc Treib | ad33cf94 | 2017-08-24 11:19:00 | [diff] [blame] | 2369 | switches::kForceUIDirection, |
John Abd-El-Malek | cdb5b52 | 2020-05-26 22:41:03 | [diff] [blame] | 2370 | switches::kIgnoreGooglePortNumbers, |
erikcorry | b251cb9 | 2014-09-25 23:48:51 | [diff] [blame] | 2371 | switches::kJavaScriptHarmony, |
Andreas Haas | b400d91 | 2019-08-28 18:54:10 | [diff] [blame] | 2372 | switches::kEnableExperimentalWebAssemblyFeatures, |
Clark DuVall | 3d4e89b9 | 2020-04-03 23:07:32 | [diff] [blame] | 2373 | embedder_support::kOriginTrialDisabledFeatures, |
| 2374 | embedder_support::kOriginTrialDisabledTokens, |
| 2375 | embedder_support::kOriginTrialPublicKey, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2376 | switches::kPpapiFlashArgs, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2377 | switches::kPpapiFlashPath, |
| 2378 | switches::kPpapiFlashVersion, |
wychen | e5568734 | 2015-11-13 20:17:03 | [diff] [blame] | 2379 | switches::kReaderModeHeuristics, |
[email protected] | 499e7c5 | 2013-10-04 16:03:09 | [diff] [blame] | 2380 | translate::switches::kTranslateSecurityOrigin, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2381 | }; |
| 2382 | |
| 2383 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2384 | base::size(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 2385 | } else if (process_type == switches::kUtilityProcess) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2386 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 2387 | static const char* const kSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2388 | extensions::switches::kAllowHTTPBackgroundPage, |
| 2389 | extensions::switches::kEnableExperimentalExtensionApis, |
| 2390 | extensions::switches::kExtensionsOnChromeURLs, |
[email protected] | 5adb774 | 2020-06-30 14:28:12 | [diff] [blame] | 2391 | extensions::switches::kAllowlistedExtensionID, |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 2392 | }; |
| 2393 | |
| 2394 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2395 | base::size(kSwitchNames)); |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 2396 | #endif |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 2397 | MaybeAppendSecureOriginsAllowlistSwitch(command_line); |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 2398 | } else if (process_type == service_manager::switches::kZygoteProcess) { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2399 | static const char* const kSwitchNames[] = { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2400 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 2401 | switches::kDisableBundledPpapiFlash, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2402 | #if BUILDFLAG(ENABLE_NACL) |
rickyz | 3638a21 | 2014-10-29 23:50:24 | [diff] [blame] | 2403 | switches::kEnableNaClDebug, |
[email protected] | a9a8e2f | 2014-05-13 23:32:58 | [diff] [blame] | 2404 | switches::kEnableNaClNonSfiMode, |
stichnot | 7040ac83 | 2016-02-24 23:40:59 | [diff] [blame] | 2405 | switches::kForcePNaClSubzero, |
[email protected] | 0b47034 | 2014-04-15 12:59:41 | [diff] [blame] | 2406 | switches::kNaClDangerousNoSandboxNonSfi, |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 2407 | #endif |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2408 | switches::kPpapiFlashPath, |
| 2409 | switches::kPpapiFlashVersion, |
| 2410 | }; |
| 2411 | |
| 2412 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2413 | base::size(kSwitchNames)); |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 2414 | } else if (process_type == switches::kGpuProcess) { |
Corentin Wallez | e660b15 | 2020-07-15 16:07:54 | [diff] [blame] | 2415 | // If --ignore-gpu-blocklist is passed in, don't send in crash reports |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 2416 | // because GPU is expected to be unreliable. |
Corentin Wallez | e660b15 | 2020-07-15 16:07:54 | [diff] [blame] | 2417 | if ((browser_command_line.HasSwitch(switches::kIgnoreGpuBlocklist) || |
| 2418 | browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist)) && |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 2419 | !command_line->HasSwitch(switches::kDisableBreakpad)) |
| 2420 | command_line->AppendSwitch(switches::kDisableBreakpad); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2421 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 2422 | |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2423 | #if defined(OS_CHROMEOS) |
Joshua Peraza | 30d8fc7 | 2019-08-19 17:24:30 | [diff] [blame] | 2424 | if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) { |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2425 | static const char* const kSwitchNames[] = { |
Joshua Peraza | 86b7958 | 2019-10-08 15:56:29 | [diff] [blame] | 2426 | crash_reporter::switches::kCrashLoopBefore, |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2427 | }; |
| 2428 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 2429 | base::size(kSwitchNames)); |
| 2430 | } |
| 2431 | #endif |
| 2432 | |
wittman | 832321f5 | 2016-10-10 18:18:38 | [diff] [blame] | 2433 | StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2434 | process_type, command_line); |
Andrew Comminos | 6605767 | 2019-05-01 00:03:34 | [diff] [blame] | 2435 | |
| 2436 | #if defined(OS_LINUX) |
| 2437 | // Processes may only query perf_event_open with the BPF sandbox disabled. |
| 2438 | if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) && |
Robert Sesek | 7d0b49b | 2020-07-08 18:31:27 | [diff] [blame] | 2439 | command_line->HasSwitch(sandbox::policy::switches::kNoSandbox)) { |
Andrew Comminos | 6605767 | 2019-05-01 00:03:34 | [diff] [blame] | 2440 | command_line->AppendSwitch(switches::kEnableThreadInstructionCount); |
| 2441 | } |
| 2442 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2443 | } |
| 2444 | |
Olivier Yiptong | 0daa93f | 2019-08-22 19:40:08 | [diff] [blame] | 2445 | std::string |
| 2446 | ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() { |
| 2447 | return std::string(chrome::kApplicationClientIDStringForAVScanning); |
| 2448 | } |
| 2449 | |
Marijn Kruisselbrink | efe0bef6 | 2020-07-21 22:44:59 | [diff] [blame] | 2450 | download::QuarantineConnectionCallback |
| 2451 | ChromeContentBrowserClient::GetQuarantineConnectionCallback() { |
| 2452 | return base::BindRepeating( |
| 2453 | &ChromeDownloadManagerDelegate::ConnectToQuarantineService); |
| 2454 | } |
| 2455 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2456 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
[email protected] | e9a32a5 | 2012-06-14 23:32:43 | [diff] [blame] | 2457 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 2458 | return GetIOThreadApplicationLocale(); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2459 | return g_browser_process->GetApplicationLocale(); |
| 2460 | } |
| 2461 | |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 2462 | std::string ChromeContentBrowserClient::GetAcceptLangs( |
| 2463 | content::BrowserContext* context) { |
| 2464 | Profile* profile = Profile::FromBrowserContext(context); |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 2465 | return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 2466 | } |
| 2467 | |
Dana Fried | 34d58000 | 2019-04-24 20:05:48 | [diff] [blame] | 2468 | gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() { |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 2469 | ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
Dana Fried | 34d58000 | 2019-04-24 20:05:48 | [diff] [blame] | 2470 | return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia(); |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 2471 | } |
| 2472 | |
bengr | e8a146f | 2016-03-10 01:20:22 | [diff] [blame] | 2473 | bool ChromeContentBrowserClient::IsDataSaverEnabled( |
| 2474 | content::BrowserContext* browser_context) { |
rajendrant | fb95964d | 2019-10-17 20:05:38 | [diff] [blame] | 2475 | if (!browser_context || browser_context->IsOffTheRecord()) |
| 2476 | return false; |
| 2477 | |
Robert Ogden | c995d4fe | 2019-03-25 19:18:37 | [diff] [blame] | 2478 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2479 | return profile && data_reduction_proxy::DataReductionProxySettings:: |
Tarun Bansal | c91d5bb8 | 2019-11-05 00:17:41 | [diff] [blame] | 2480 | IsDataSaverEnabledByUser(profile->IsOffTheRecord(), |
| 2481 | profile->GetPrefs()); |
bengr | e8a146f | 2016-03-10 01:20:22 | [diff] [blame] | 2482 | } |
| 2483 | |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 2484 | void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker( |
| 2485 | content::BrowserContext* browser_context, |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 2486 | blink::mojom::RendererPreferences* out_prefs) { |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 2487 | DCHECK(browser_context); |
| 2488 | DCHECK(out_prefs); |
| 2489 | renderer_preferences_util::UpdateFromSystemSettings( |
| 2490 | out_prefs, Profile::FromBrowserContext(browser_context)); |
| 2491 | } |
| 2492 | |
Clark DuVall | 5690e74 | 2019-07-17 18:26:17 | [diff] [blame] | 2493 | bool ChromeContentBrowserClient::AllowAppCache( |
| 2494 | const GURL& manifest_url, |
Christian Dullweber | 7774015 | 2020-05-12 09:54:17 | [diff] [blame] | 2495 | const GURL& site_for_cookies, |
| 2496 | const base::Optional<url::Origin>& top_frame_origin, |
Clark DuVall | 5690e74 | 2019-07-17 18:26:17 | [diff] [blame] | 2497 | content::BrowserContext* context) { |
| 2498 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2499 | return CookieSettingsFactory::GetForProfile( |
| 2500 | Profile::FromBrowserContext(context)) |
Christian Dullweber | 7774015 | 2020-05-12 09:54:17 | [diff] [blame] | 2501 | ->IsCookieAccessAllowed(manifest_url, site_for_cookies, top_frame_origin); |
Clark DuVall | 5690e74 | 2019-07-17 18:26:17 | [diff] [blame] | 2502 | } |
| 2503 | |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 2504 | content::AllowServiceWorkerResult |
| 2505 | ChromeContentBrowserClient::AllowServiceWorkerOnIO( |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2506 | const GURL& scope, |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2507 | const GURL& site_for_cookies, |
| 2508 | const base::Optional<url::Origin>& top_frame_origin, |
David Bertoni | 3b3597d8 | 2019-06-22 02:29:36 | [diff] [blame] | 2509 | const GURL& script_url, |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 2510 | content::ResourceContext* context) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 2511 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2512 | GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL(); |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2513 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2514 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2515 | // Check if this is an extension-related service worker, and, if so, if it's |
| 2516 | // allowed (this can return false if, e.g., the extension is disabled). |
| 2517 | // If it's not allowed, return immediately. We deliberately do *not* report |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 2518 | // to the PageSpecificContentSettings, since the service worker is blocked |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2519 | // because of the extension, rather than because of the user's content |
| 2520 | // settings. |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2521 | if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO( |
David Bertoni | 3b3597d8 | 2019-06-22 02:29:36 | [diff] [blame] | 2522 | scope, first_party_url, script_url, context)) { |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 2523 | return content::AllowServiceWorkerResult::No(); |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2524 | } |
| 2525 | #endif |
| 2526 | |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2527 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2528 | |
shimazu | ce8af8812 | 2016-10-06 23:49:21 | [diff] [blame] | 2529 | // Check if JavaScript is allowed. |
| 2530 | content_settings::SettingInfo info; |
| 2531 | std::unique_ptr<base::Value> value = |
| 2532 | io_data->GetHostContentSettingsMap()->GetWebsiteSetting( |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2533 | first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT, |
shimazu | ce8af8812 | 2016-10-06 23:49:21 | [diff] [blame] | 2534 | std::string(), &info); |
| 2535 | ContentSetting setting = content_settings::ValueToContentSetting(value.get()); |
| 2536 | bool allow_javascript = (setting == CONTENT_SETTING_ALLOW); |
| 2537 | |
| 2538 | // Check if cookies are allowed. |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2539 | bool allow_cookies = io_data->GetCookieSettings()->IsCookieAccessAllowed( |
| 2540 | scope, site_for_cookies, top_frame_origin); |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 2541 | |
| 2542 | return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript, |
| 2543 | !allow_cookies); |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2544 | } |
| 2545 | |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 2546 | content::AllowServiceWorkerResult |
| 2547 | ChromeContentBrowserClient::AllowServiceWorkerOnUI( |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2548 | const GURL& scope, |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2549 | const GURL& site_for_cookies, |
| 2550 | const base::Optional<url::Origin>& top_frame_origin, |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2551 | const GURL& script_url, |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 2552 | content::BrowserContext* context) { |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2553 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2554 | GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL(); |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2555 | |
| 2556 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2557 | // Check if this is an extension-related service worker, and, if so, if it's |
| 2558 | // allowed (this can return false if, e.g., the extension is disabled). |
| 2559 | // If it's not allowed, return immediately. We deliberately do *not* report |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 2560 | // to the PageSpecificContentSettings, since the service worker is blocked |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2561 | // because of the extension, rather than because of the user's content |
| 2562 | // settings. |
| 2563 | if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI( |
| 2564 | scope, first_party_url, script_url, context)) { |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 2565 | return content::AllowServiceWorkerResult::No(); |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2566 | } |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2567 | #endif |
| 2568 | |
| 2569 | Profile* profile = Profile::FromBrowserContext(context); |
| 2570 | |
| 2571 | // Check if JavaScript is allowed. |
| 2572 | content_settings::SettingInfo info; |
| 2573 | std::unique_ptr<base::Value> value = |
| 2574 | HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting( |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2575 | first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT, |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2576 | std::string(), &info); |
| 2577 | ContentSetting setting = content_settings::ValueToContentSetting(value.get()); |
| 2578 | bool allow_javascript = (setting == CONTENT_SETTING_ALLOW); |
| 2579 | |
| 2580 | // Check if cookies are allowed. |
| 2581 | bool allow_cookies = |
| 2582 | CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed( |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2583 | scope, site_for_cookies, top_frame_origin); |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2584 | |
Alexander Timin | 17edc74 | 2020-04-23 18:22:18 | [diff] [blame] | 2585 | return content::AllowServiceWorkerResult::FromPolicy(!allow_javascript, |
| 2586 | !allow_cookies); |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2587 | } |
| 2588 | |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2589 | bool ChromeContentBrowserClient::AllowSharedWorker( |
| 2590 | const GURL& worker_url, |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2591 | const GURL& site_for_cookies, |
| 2592 | const base::Optional<url::Origin>& top_frame_origin, |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2593 | const std::string& name, |
Hiroki Nakagawa | 018bb6d | 2017-11-30 03:31:37 | [diff] [blame] | 2594 | const url::Origin& constructor_origin, |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2595 | content::BrowserContext* context, |
| 2596 | int render_process_id, |
| 2597 | int render_frame_id) { |
| 2598 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2599 | |
| 2600 | // Check if cookies are allowed. |
| 2601 | bool allow = |
| 2602 | CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context)) |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2603 | ->IsCookieAccessAllowed(worker_url, site_for_cookies, |
| 2604 | top_frame_origin); |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2605 | |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 2606 | content_settings::PageSpecificContentSettings::SharedWorkerAccessed( |
Hiroki Nakagawa | 018bb6d | 2017-11-30 03:31:37 | [diff] [blame] | 2607 | render_process_id, render_frame_id, worker_url, name, constructor_origin, |
| 2608 | !allow); |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2609 | return allow; |
| 2610 | } |
| 2611 | |
Patrick Monette | 6cb099a | 2019-09-18 19:31:27 | [diff] [blame] | 2612 | bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker( |
| 2613 | const std::string& scheme) { |
| 2614 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 2615 | // Extensions are allowed to start cross-origin shared workers. |
| 2616 | if (scheme == extensions::kExtensionScheme) |
| 2617 | return true; |
| 2618 | #endif |
| 2619 | |
| 2620 | return false; |
| 2621 | } |
| 2622 | |
Clark DuVall | ab63d14 | 2019-07-23 04:24:36 | [diff] [blame] | 2623 | bool ChromeContentBrowserClient::AllowSignedExchange( |
| 2624 | content::BrowserContext* browser_context) { |
| 2625 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2626 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2627 | return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled); |
| 2628 | } |
| 2629 | |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2630 | void ChromeContentBrowserClient::AllowWorkerFileSystem( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2631 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2632 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2633 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2634 | base::OnceCallback<void(bool)> callback) { |
| 2635 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2636 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
Christian Dullweber | 7774015 | 2020-05-12 09:54:17 | [diff] [blame] | 2637 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2638 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2639 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2640 | GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2641 | #else |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2642 | FileSystemAccessed(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2643 | #endif |
| 2644 | } |
| 2645 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2646 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2647 | void ChromeContentBrowserClient::GuestPermissionRequestHelper( |
| 2648 | const GURL& url, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2649 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2650 | base::OnceCallback<void(bool)> callback, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2651 | bool allow) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2652 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2653 | std::map<int, int> process_map; |
| 2654 | std::map<int, int>::const_iterator it; |
| 2655 | bool has_web_view_guest = false; |
| 2656 | // Record access to file system for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2657 | for (const auto& it : render_frames) { |
| 2658 | if (process_map.find(it.child_id) != process_map.end()) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2659 | continue; |
| 2660 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2661 | 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] | 2662 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2663 | if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id)) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2664 | has_web_view_guest = true; |
| 2665 | } |
| 2666 | if (!has_web_view_guest) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2667 | FileSystemAccessed(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2668 | return; |
| 2669 | } |
[email protected] | dffb9fc | 2014-07-16 04:14:02 | [diff] [blame] | 2670 | DCHECK_EQ(1U, process_map.size()); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2671 | it = process_map.begin(); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2672 | |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 2673 | extensions::WebViewPermissionHelper* web_view_permission_helper = |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2674 | extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second); |
| 2675 | web_view_permission_helper->RequestFileSystemPermission( |
| 2676 | url, allow, |
| 2677 | base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed, |
| 2678 | weak_factory_.GetWeakPtr(), url, render_frames, |
| 2679 | std::move(callback))); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2680 | } |
| 2681 | #endif |
| 2682 | |
| 2683 | void ChromeContentBrowserClient::FileSystemAccessed( |
| 2684 | const GURL& url, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2685 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2686 | base::OnceCallback<void(bool)> callback, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2687 | bool allow) { |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 2688 | // Record access to file system for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2689 | for (const auto& it : render_frames) { |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 2690 | content_settings::PageSpecificContentSettings::FileSystemAccessed( |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2691 | it.child_id, it.frame_routing_id, url, !allow); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2692 | } |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2693 | std::move(callback).Run(allow); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2694 | } |
| 2695 | |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2696 | bool ChromeContentBrowserClient::AllowWorkerIndexedDB( |
| 2697 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2698 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2699 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2700 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2701 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
| 2702 | |
Christian Dullweber | 7774015 | 2020-05-12 09:54:17 | [diff] [blame] | 2703 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2704 | |
| 2705 | // Record access to IndexedDB for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2706 | for (const auto& it : render_frames) { |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 2707 | content_settings::PageSpecificContentSettings::IndexedDBAccessed( |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2708 | it.child_id, it.frame_routing_id, url, !allow); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | return allow; |
| 2712 | } |
| 2713 | |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2714 | bool ChromeContentBrowserClient::AllowWorkerCacheStorage( |
| 2715 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2716 | content::BrowserContext* browser_context, |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2717 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2718 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2719 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
Christian Dullweber | 7774015 | 2020-05-12 09:54:17 | [diff] [blame] | 2720 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt); |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2721 | |
| 2722 | // Record access to CacheStorage for potential display in UI. |
| 2723 | for (const auto& it : render_frames) { |
Carlos Caballero | b428320 | 2020-08-10 14:40:46 | [diff] [blame] | 2724 | content_settings::PageSpecificContentSettings::CacheStorageAccessed( |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2725 | it.child_id, it.frame_routing_id, url, !allow); |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | return allow; |
| 2729 | } |
| 2730 | |
Joshua Bell | 1ebc8df | 2019-11-06 00:27:58 | [diff] [blame] | 2731 | bool ChromeContentBrowserClient::AllowWorkerWebLocks( |
| 2732 | const GURL& url, |
| 2733 | content::BrowserContext* browser_context, |
| 2734 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
| 2735 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2736 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
Christian Dullweber | 7774015 | 2020-05-12 09:54:17 | [diff] [blame] | 2737 | return cookie_settings->IsCookieAccessAllowed(url, url, base::nullopt); |
Joshua Bell | 1ebc8df | 2019-11-06 00:27:58 | [diff] [blame] | 2738 | } |
| 2739 | |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2740 | ChromeContentBrowserClient::AllowWebBluetoothResult |
| 2741 | ChromeContentBrowserClient::AllowWebBluetooth( |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2742 | content::BrowserContext* browser_context, |
| 2743 | const url::Origin& requesting_origin, |
| 2744 | const url::Origin& embedding_origin) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2745 | // TODO(crbug.com/598890): Don't disable if |
| 2746 | // base::CommandLine::ForCurrentProcess()-> |
| 2747 | // HasSwitch(switches::kEnableWebBluetooth) is true. |
| 2748 | if (variations::GetVariationParamValue( |
Clark DuVall | a11361ad3 | 2020-02-20 22:14:27 | [diff] [blame] | 2749 | permissions::PermissionContextBase::kPermissionsKillSwitchFieldStudy, |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2750 | "Bluetooth") == |
Clark DuVall | a11361ad3 | 2020-02-20 22:14:27 | [diff] [blame] | 2751 | permissions::PermissionContextBase::kPermissionsKillSwitchBlockedValue) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2752 | // The kill switch is enabled for this permission. Block requests. |
| 2753 | return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED; |
| 2754 | } |
| 2755 | |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2756 | const HostContentSettingsMap* const content_settings = |
| 2757 | HostContentSettingsMapFactory::GetForProfile( |
| 2758 | Profile::FromBrowserContext(browser_context)); |
| 2759 | |
csharrison | aec2c54 | 2016-10-12 19:40:36 | [diff] [blame] | 2760 | if (content_settings->GetContentSetting( |
| 2761 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2762 | ContentSettingsType::BLUETOOTH_GUARD, |
csharrison | aec2c54 | 2016-10-12 19:40:36 | [diff] [blame] | 2763 | std::string()) == CONTENT_SETTING_BLOCK) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2764 | return AllowWebBluetoothResult::BLOCK_POLICY; |
| 2765 | } |
| 2766 | return AllowWebBluetoothResult::ALLOW; |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2767 | } |
| 2768 | |
beaufort.francois | 01135bf | 2016-11-23 14:37:36 | [diff] [blame] | 2769 | std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() { |
| 2770 | return variations::GetVariationParamValue("WebBluetoothBlocklist", |
| 2771 | "blocklist_additions"); |
scheib | 7425032 | 2016-04-07 03:32:21 | [diff] [blame] | 2772 | } |
| 2773 | |
Charlie Harrison | 071ac92 | 2020-06-25 19:11:22 | [diff] [blame] | 2774 | bool ChromeContentBrowserClient::AllowConversionMeasurement( |
| 2775 | content::BrowserContext* browser_context) { |
| 2776 | // For now, disable conversion measurement if third party cookie blocking is |
| 2777 | // enabled. |
| 2778 | // TODO(crbug.com/1058018): Add dedicated UI to this feature. |
| 2779 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2780 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
| 2781 | return !cookie_settings->ShouldBlockThirdPartyCookies(); |
| 2782 | } |
| 2783 | |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 2784 | #if defined(OS_CHROMEOS) |
John Abd-El-Malek | a5b1a5d60 | 2018-11-05 19:20:52 | [diff] [blame] | 2785 | void ChromeContentBrowserClient::OnTrustAnchorUsed( |
John Abd-El-Malek | 35bfaa5 | 2019-08-20 16:22:07 | [diff] [blame] | 2786 | content::BrowserContext* browser_context) { |
| 2787 | user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 2788 | if (user_manager) { |
| 2789 | const user_manager::User* user = |
| 2790 | chromeos::ProfileHelper::Get()->GetUserByProfile( |
| 2791 | Profile::FromBrowserContext(browser_context)); |
| 2792 | if (user && !user->username_hash().empty()) { |
| 2793 | policy::PolicyCertServiceFactory::SetUsedPolicyCertificates( |
| 2794 | user->username_hash()); |
| 2795 | } |
| 2796 | } |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 2797 | } |
| 2798 | #endif |
| 2799 | |
Chris Thompson | e2e073d4 | 2020-07-23 12:33:45 | [diff] [blame] | 2800 | void ChromeContentBrowserClient::OnSCTReportReady( |
| 2801 | content::BrowserContext* browser_context, |
| 2802 | const std::string& cache_key) { |
| 2803 | auto* sct_reporting_service = |
| 2804 | SCTReportingServiceFactory::GetInstance()->GetForBrowserContext( |
| 2805 | browser_context); |
| 2806 | if (sct_reporting_service) { |
| 2807 | sct_reporting_service->OnSCTReportReady(cache_key); |
| 2808 | } |
| 2809 | } |
| 2810 | |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2811 | scoped_refptr<network::SharedURLLoaderFactory> |
| 2812 | ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() { |
Min Qin | da0d55b | 2018-10-12 18:30:05 | [diff] [blame] | 2813 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 2814 | !BrowserThread::IsThreadInitialized(BrowserThread::UI)); |
| 2815 | |
| 2816 | if (!SystemNetworkContextManager::GetInstance()) |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2817 | return nullptr; |
| 2818 | |
Min Qin | da0d55b | 2018-10-12 18:30:05 | [diff] [blame] | 2819 | return SystemNetworkContextManager::GetInstance() |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2820 | ->GetSharedURLLoaderFactory(); |
Andrew Moylan | 8673dba | 2017-10-10 04:29:04 | [diff] [blame] | 2821 | } |
| 2822 | |
Sean Gilhuly | da1ee4b | 2018-11-13 21:56:09 | [diff] [blame] | 2823 | network::mojom::NetworkContext* |
| 2824 | ChromeContentBrowserClient::GetSystemNetworkContext() { |
| 2825 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2826 | DCHECK(g_browser_process->system_network_context_manager()); |
| 2827 | return g_browser_process->system_network_context_manager()->GetContext(); |
| 2828 | } |
| 2829 | |
Andrew Moylan | 17329fc | 2017-09-25 07:43:30 | [diff] [blame] | 2830 | std::string ChromeContentBrowserClient::GetGeolocationApiKey() { |
| 2831 | return google_apis::GetAPIKey(); |
| 2832 | } |
| 2833 | |
Ke He | 21ee87f | 2018-05-30 02:35:32 | [diff] [blame] | 2834 | #if defined(OS_ANDROID) |
| 2835 | bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() { |
| 2836 | // Indicate that Chrome uses the GMS core location provider. |
| 2837 | return true; |
| 2838 | } |
| 2839 | #endif |
| 2840 | |
Yeol | f3dc22ca | 2019-04-18 17:25:32 | [diff] [blame] | 2841 | scoped_refptr<content::QuotaPermissionContext> |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 2842 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
Scott Violet | 9389378 | 2020-03-27 16:23:54 | [diff] [blame] | 2843 | return new permissions::QuotaPermissionContextImpl(); |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 2844 | } |
| 2845 | |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 2846 | content::GeneratedCodeCacheSettings |
| 2847 | ChromeContentBrowserClient::GetGeneratedCodeCacheSettings( |
| 2848 | content::BrowserContext* context) { |
| 2849 | base::FilePath cache_path; |
| 2850 | chrome::GetUserCacheDirectory(context->GetPath(), &cache_path); |
| 2851 | // If we pass 0 for size, disk_cache will pick a default size using the |
| 2852 | // heuristics based on available disk size. These are implemented in |
| 2853 | // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc. |
Mythri A | b248657 | 2019-06-13 14:48:16 | [diff] [blame] | 2854 | int64_t size_in_bytes = 0; |
Greg Thompson | 8c922756 | 2019-08-05 17:47:13 | [diff] [blame] | 2855 | DCHECK(g_browser_process); |
| 2856 | PrefService* local_state = g_browser_process->local_state(); |
| 2857 | if (local_state) { |
| 2858 | size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize); |
| 2859 | base::FilePath disk_cache_dir = |
| 2860 | local_state->GetFilePath(prefs::kDiskCacheDir); |
| 2861 | if (!disk_cache_dir.empty()) |
| 2862 | cache_path = disk_cache_dir.Append(cache_path.BaseName()); |
| 2863 | } |
Mythri A | b248657 | 2019-06-13 14:48:16 | [diff] [blame] | 2864 | return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path); |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 2865 | } |
| 2866 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 2867 | void ChromeContentBrowserClient::AllowCertificateError( |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2868 | content::WebContents* web_contents, |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 2869 | int cert_error, |
| 2870 | const net::SSLInfo& ssl_info, |
| 2871 | const GURL& request_url, |
John Abd-El-Malek | c5b8df91 | 2019-05-07 17:02:23 | [diff] [blame] | 2872 | bool is_main_frame_request, |
[email protected] | d9be4770 | 2012-05-16 03:41:22 | [diff] [blame] | 2873 | bool strict_enforcement, |
Erik Staab | a65a603 | 2019-11-27 22:23:26 | [diff] [blame] | 2874 | base::OnceCallback<void(content::CertificateRequestResultType)> callback) { |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2875 | DCHECK(web_contents); |
John Abd-El-Malek | c5b8df91 | 2019-05-07 17:02:23 | [diff] [blame] | 2876 | if (!is_main_frame_request) { |
irisu | 8452ddd6 | 2017-03-22 07:46:14 | [diff] [blame] | 2877 | // A sub-resource has a certificate error. The user doesn't really |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 2878 | // have a context for making the right decision, so block the |
| 2879 | // request hard, without an info bar to allow showing the insecure |
| 2880 | // content. |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2881 | if (!callback.is_null()) |
Erik Staab | a65a603 | 2019-11-27 22:23:26 | [diff] [blame] | 2882 | std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 2883 | return; |
| 2884 | } |
| 2885 | |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 2886 | // If the tab is being prerendered, cancel the prerender and the request. |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2887 | prerender::PrerenderContents* prerender_contents = |
Mugdha Lakhani | 2c6b23af | 2020-07-31 14:55:57 | [diff] [blame] | 2888 | prerender::ChromePrerenderContentsDelegate::FromWebContents(web_contents); |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2889 | if (prerender_contents) { |
| 2890 | prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR); |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2891 | if (!callback.is_null()) { |
Erik Staab | a65a603 | 2019-11-27 22:23:26 | [diff] [blame] | 2892 | std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL); |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2893 | } |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2894 | return; |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 2895 | } |
| 2896 | |
Erik Staab | a65a603 | 2019-11-27 22:23:26 | [diff] [blame] | 2897 | std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 2898 | return; |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 2899 | } |
| 2900 | |
Katie D | 1882617e | 2020-05-06 20:06:01 | [diff] [blame] | 2901 | #if !defined(OS_ANDROID) |
| 2902 | bool ChromeContentBrowserClient::ShouldDenyRequestOnCertificateError( |
| 2903 | const GURL main_page_url) { |
| 2904 | // Desktop Reader Mode pages should never load resources with certificate |
| 2905 | // errors. Desktop Reader Mode is more strict about security than Reader Mode |
| 2906 | // on Android: the desktop version has its own security indicator and |
| 2907 | // is not downgraded to a WARNING, whereas Android will show "Not secure" |
| 2908 | // in the omnibox (for low-end devices which show the omnibox on Reader Mode |
| 2909 | // pages). |
| 2910 | return main_page_url.SchemeIs(dom_distiller::kDomDistillerScheme); |
| 2911 | } |
| 2912 | #endif |
| 2913 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2914 | namespace { |
| 2915 | |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2916 | certificate_matching::CertificatePrincipalPattern |
| 2917 | ParseCertificatePrincipalPattern(const base::Value* pattern) { |
| 2918 | return certificate_matching::CertificatePrincipalPattern:: |
| 2919 | ParseFromOptionalDict(pattern, "CN", "L", "O", "OU"); |
| 2920 | } |
| 2921 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2922 | // Attempts to auto-select a client certificate according to the value of |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2923 | // |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2924 | // |requesting_url|. If no certificate was auto-selected, returns nullptr. |
| 2925 | std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate( |
| 2926 | Profile* profile, |
| 2927 | const GURL& requesting_url, |
| 2928 | net::ClientCertIdentityList& client_certs) { |
| 2929 | HostContentSettingsMap* host_content_settings_map = |
| 2930 | HostContentSettingsMapFactory::GetForProfile(profile); |
| 2931 | std::unique_ptr<base::Value> setting = |
| 2932 | host_content_settings_map->GetWebsiteSetting( |
| 2933 | requesting_url, requesting_url, |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2934 | ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr); |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2935 | |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2936 | if (!setting || !setting->is_dict()) |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2937 | return nullptr; |
| 2938 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2939 | const base::Value* filters = |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2940 | setting->FindKeyOfType("filters", base::Value::Type::LIST); |
| 2941 | if (!filters) { |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2942 | // |setting_dict| has the wrong format (e.g. single filter instead of a |
| 2943 | // list of filters). This content setting is only provided by |
| 2944 | // the |PolicyProvider|, which should always set it to a valid format. |
| 2945 | // Therefore, delete the invalid value. |
| 2946 | host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 2947 | requesting_url, requesting_url, |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2948 | ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr); |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2949 | return nullptr; |
| 2950 | } |
| 2951 | |
| 2952 | for (const base::Value& filter : filters->GetList()) { |
| 2953 | DCHECK(filter.is_dict()); |
| 2954 | |
| 2955 | auto issuer_pattern = ParseCertificatePrincipalPattern( |
| 2956 | filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY)); |
| 2957 | auto subject_pattern = ParseCertificatePrincipalPattern( |
| 2958 | filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY)); |
| 2959 | // Use the first certificate that is matched by the filter. |
| 2960 | for (auto& client_cert : client_certs) { |
| 2961 | if (issuer_pattern.Matches(client_cert->certificate()->issuer()) && |
| 2962 | subject_pattern.Matches(client_cert->certificate()->subject())) { |
| 2963 | return std::move(client_cert); |
| 2964 | } |
| 2965 | } |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2966 | } |
| 2967 | |
| 2968 | return nullptr; |
| 2969 | } |
| 2970 | |
| 2971 | } // namespace |
| 2972 | |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2973 | base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate( |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2974 | content::WebContents* web_contents, |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 2975 | net::SSLCertRequestInfo* cert_request_info, |
mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 2976 | net::ClientCertIdentityList client_certs, |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2977 | std::unique_ptr<content::ClientCertificateDelegate> delegate) { |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 2978 | prerender::PrerenderContents* prerender_contents = |
Mugdha Lakhani | 2c6b23af | 2020-07-31 14:55:57 | [diff] [blame] | 2979 | prerender::ChromePrerenderContentsDelegate::FromWebContents(web_contents); |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 2980 | if (prerender_contents) { |
| 2981 | prerender_contents->Destroy( |
| 2982 | prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2983 | return base::OnceClosure(); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 2984 | } |
| 2985 | |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 2986 | GURL requesting_url("https://" + cert_request_info->host_and_port.ToString()); |
| 2987 | DCHECK(requesting_url.is_valid()) |
| 2988 | << "Invalid URL string: https://" |
| 2989 | << cert_request_info->host_and_port.ToString(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 2990 | |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2991 | bool may_show_cert_selection = true; |
| 2992 | |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2993 | Profile* profile = |
| 2994 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2995 | #if defined(OS_CHROMEOS) |
| 2996 | if (chromeos::ProfileHelper::IsSigninProfile(profile)) { |
Pavol Marko | ddc4ea4 | 2020-01-24 12:02:25 | [diff] [blame] | 2997 | // On the sign-in profile, never show certificate selection to the user. A |
| 2998 | // client certificate is an identifier that can be stable for a long time, |
| 2999 | // so only the administrator is allowed to decide which endpoints should see |
| 3000 | // it. |
| 3001 | may_show_cert_selection = false; |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3002 | |
| 3003 | content::StoragePartition* storage_partition = |
| 3004 | content::BrowserContext::GetStoragePartition( |
| 3005 | profile, web_contents->GetSiteInstance()); |
| 3006 | chromeos::login::SigninPartitionManager* signin_partition_manager = |
| 3007 | chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext( |
| 3008 | profile); |
| 3009 | |
| 3010 | // On the sign-in profile, only allow client certs in the context of the |
| 3011 | // sign-in frame. |
| 3012 | if (!signin_partition_manager->IsCurrentSigninStoragePartition( |
| 3013 | storage_partition)) { |
| 3014 | LOG(WARNING) |
| 3015 | << "Client cert requested in sign-in profile in wrong context."; |
| 3016 | // Continue without client certificate. We do this to mimic the case of no |
| 3017 | // client certificate being present in the profile's certificate store. |
| 3018 | delegate->ContinueWithCertificate(nullptr, nullptr); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 3019 | return base::OnceClosure(); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3020 | } |
| 3021 | VLOG(1) << "Client cert requested in sign-in profile."; |
| 3022 | } |
| 3023 | #endif // defined(OS_CHROMEOS) |
| 3024 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 3025 | std::unique_ptr<net::ClientCertIdentity> auto_selected_identity = |
| 3026 | AutoSelectCertificate(profile, requesting_url, client_certs); |
| 3027 | if (auto_selected_identity) { |
| 3028 | // The callback will own |auto_selected_identity| and |delegate|, keeping |
| 3029 | // them alive until after ContinueWithCertificate is called. |
| 3030 | scoped_refptr<net::X509Certificate> cert = |
| 3031 | auto_selected_identity->certificate(); |
| 3032 | net::ClientCertIdentity::SelfOwningAcquirePrivateKey( |
| 3033 | std::move(auto_selected_identity), |
David Benjamin | 0cda204 | 2019-04-08 23:00:58 | [diff] [blame] | 3034 | base::BindOnce( |
| 3035 | &content::ClientCertificateDelegate::ContinueWithCertificate, |
| 3036 | std::move(delegate), std::move(cert))); |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 3037 | LogClientAuthResult(ClientCertSelectionResult::kAutoSelect); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 3038 | return base::OnceClosure(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 3039 | } |
| 3040 | |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3041 | if (!may_show_cert_selection) { |
| 3042 | LOG(WARNING) << "No client cert matched by policy and user selection is " |
| 3043 | "not allowed."; |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 3044 | LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3045 | // Continue without client certificate. We do this to mimic the case of no |
| 3046 | // client certificate being present in the profile's certificate store. |
| 3047 | delegate->ContinueWithCertificate(nullptr, nullptr); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 3048 | return base::OnceClosure(); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 3049 | } |
| 3050 | |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 3051 | return chrome::ShowSSLClientCertificateSelector( |
| 3052 | web_contents, cert_request_info, std::move(client_certs), |
| 3053 | std::move(delegate)); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 3054 | } |
| 3055 | |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 3056 | content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { |
[email protected] | 11158e2d | 2013-02-01 02:31:56 | [diff] [blame] | 3057 | return MediaCaptureDevicesDispatcher::GetInstance(); |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 3058 | } |
| 3059 | |
Adrienne Walker | 80d95f0 | 2020-02-07 22:37:04 | [diff] [blame] | 3060 | content::FeatureObserverClient* |
| 3061 | ChromeContentBrowserClient::GetFeatureObserverClient() { |
François Doray | aa3f8010 | 2019-10-12 02:29:24 | [diff] [blame] | 3062 | return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance() |
Adrienne Walker | 80d95f0 | 2020-02-07 22:37:04 | [diff] [blame] | 3063 | ->GetFeatureObserverClient(); |
Francois Doray | fd823bb1 | 2019-10-04 18:03:05 | [diff] [blame] | 3064 | } |
| 3065 | |
peter | c26c6c6 | 2014-12-10 14:13:59 | [diff] [blame] | 3066 | content::PlatformNotificationService* |
Richard Knoll | d0eae96 | 2019-04-04 12:34:02 | [diff] [blame] | 3067 | ChromeContentBrowserClient::GetPlatformNotificationService( |
| 3068 | content::BrowserContext* browser_context) { |
| 3069 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 3070 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 3071 | return PlatformNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 3072 | } |
| 3073 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 3074 | bool ChromeContentBrowserClient::CanCreateWindow( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3075 | RenderFrameHost* opener, |
[email protected] | 2b751a1 | 2012-03-06 03:00:35 | [diff] [blame] | 3076 | const GURL& opener_url, |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 3077 | const GURL& opener_top_level_frame_url, |
Nasko Oskov | e9f1978 | 2019-01-04 18:32:35 | [diff] [blame] | 3078 | const url::Origin& source_origin, |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 3079 | content::mojom::WindowContainerType container_type, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3080 | const GURL& target_url, |
| 3081 | const content::Referrer& referrer, |
jochen | 67b271b | 2016-08-03 13:50:21 | [diff] [blame] | 3082 | const std::string& frame_name, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3083 | WindowOpenDisposition disposition, |
scottmg | 8e6c608 | 2017-02-13 23:15:48 | [diff] [blame] | 3084 | const blink::mojom::WindowFeatures& features, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3085 | bool user_gesture, |
| 3086 | bool opener_suppressed, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 3087 | bool* no_javascript_access) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3088 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 3089 | DCHECK(opener); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 3090 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3091 | content::WebContents* web_contents = |
| 3092 | content::WebContents::FromRenderFrameHost(opener); |
| 3093 | Profile* profile = |
| 3094 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 3095 | DCHECK(profile); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 3096 | *no_javascript_access = false; |
| 3097 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 3098 | // If the opener is trying to create a background window but doesn't have |
| 3099 | // the appropriate permission, fail the attempt. |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 3100 | if (container_type == content::mojom::WindowContainerType::BACKGROUND) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3101 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3102 | auto* process_map = extensions::ProcessMap::Get(profile); |
| 3103 | auto* registry = extensions::ExtensionRegistry::Get(profile); |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 3104 | if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url, |
| 3105 | opener->GetProcess()->GetID())) { |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 3106 | return false; |
| 3107 | } |
| 3108 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 3109 | // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may |
| 3110 | // return a recently installed Extension even if this CanCreateWindow call |
| 3111 | // 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] | 3112 | // because the permission check above would have caused an early return |
| 3113 | // already. We must use the full URL to find hosted apps, though, and not |
| 3114 | // just the origin. |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 3115 | const Extension* extension = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3116 | registry->enabled_extensions().GetExtensionOrAppByURL(opener_url); |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 3117 | if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 3118 | *no_javascript_access = true; |
[email protected] | dffb9fc | 2014-07-16 04:14:02 | [diff] [blame] | 3119 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3120 | |
| 3121 | return true; |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 3122 | } |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 3123 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3124 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 3125 | if (extensions::WebViewRendererState::GetInstance()->IsGuest( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3126 | opener->GetProcess()->GetID())) { |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3127 | return true; |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 3128 | } |
| 3129 | |
nick | 0fbc392 | 2016-12-16 20:52:07 | [diff] [blame] | 3130 | if (target_url.SchemeIs(extensions::kExtensionScheme)) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3131 | // Intentionally duplicating |registry| code from above because we want to |
| 3132 | // reduce calls to retrieve them as this function is a SYNC IPC handler. |
| 3133 | auto* registry = extensions::ExtensionRegistry::Get(profile); |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 3134 | const Extension* extension = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3135 | registry->enabled_extensions().GetExtensionOrAppByURL(target_url); |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 3136 | if (extension && extension->is_platform_app()) { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 3137 | UMA_HISTOGRAM_ENUMERATION( |
| 3138 | "Extensions.AppLoadedInTab", |
| 3139 | ClassifyAppLoadedInTabSource(opener_url, extension), |
| 3140 | APP_LOADED_IN_TAB_SOURCE_MAX); |
| 3141 | |
| 3142 | // window.open() may not be used to load v2 apps in a regular tab. |
lazyboy | 39585ed | 2016-12-06 19:30:16 | [diff] [blame] | 3143 | return false; |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 3144 | } |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 3145 | } |
[email protected] | 5940b0d | 2014-07-01 00:18:26 | [diff] [blame] | 3146 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3147 | |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 3148 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3149 | HostContentSettingsMap* content_settings = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3150 | HostContentSettingsMapFactory::GetForProfile(profile); |
tommycli | 61f6f0c | 2016-09-21 00:26:58 | [diff] [blame] | 3151 | if (FlashDownloadInterception::ShouldStopFlashDownloadAction( |
| 3152 | content_settings, opener_top_level_frame_url, target_url, |
| 3153 | user_gesture)) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3154 | FlashDownloadInterception::InterceptFlashDownloadNavigation( |
| 3155 | web_contents, opener_top_level_frame_url); |
tommycli | 61f6f0c | 2016-09-21 00:26:58 | [diff] [blame] | 3156 | return false; |
| 3157 | } |
| 3158 | #endif |
| 3159 | |
Mugdha Lakhani | 2c6b23af | 2020-07-31 14:55:57 | [diff] [blame] | 3160 | DCHECK(!prerender::ChromePrerenderContentsDelegate::FromWebContents( |
| 3161 | web_contents)); |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 3162 | |
Aaron Colwell | 9dab165 | 2019-12-09 18:29:49 | [diff] [blame] | 3163 | BlockedWindowParams blocked_params( |
| 3164 | target_url, source_origin, opener->GetSiteInstance(), referrer, |
| 3165 | frame_name, disposition, features, user_gesture, opener_suppressed); |
cm.sanchi | 2522bc9 | 2017-12-04 08:04:13 | [diff] [blame] | 3166 | NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents); |
Clark DuVall | 8a020d62 | 2020-06-04 00:45:50 | [diff] [blame] | 3167 | return blocked_content::MaybeBlockPopup( |
| 3168 | web_contents, &opener_top_level_frame_url, |
| 3169 | std::make_unique<ChromePopupNavigationDelegate>( |
| 3170 | std::move(nav_params)), |
| 3171 | nullptr /*=open_url_params*/, blocked_params.features(), |
| 3172 | HostContentSettingsMapFactory::GetForProfile(profile)) != nullptr; |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 3173 | } |
| 3174 | |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 3175 | content::SpeechRecognitionManagerDelegate* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3176 | ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() { |
[email protected] | 855e18b | 2013-07-08 21:02:00 | [diff] [blame] | 3177 | return new speech::ChromeSpeechRecognitionManagerDelegate(); |
[email protected] | 66cfec6 | 2012-02-24 17:57:51 | [diff] [blame] | 3178 | } |
| 3179 | |
Scott Violet | 1644cf7 | 2020-06-24 04:51:55 | [diff] [blame] | 3180 | #if defined(OS_CHROMEOS) |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 3181 | content::TtsControllerDelegate* |
| 3182 | ChromeContentBrowserClient::GetTtsControllerDelegate() { |
Scott Violet | 1644cf7 | 2020-06-24 04:51:55 | [diff] [blame] | 3183 | return TtsControllerDelegateImpl::GetInstance(); |
| 3184 | } |
| 3185 | #endif |
| 3186 | |
| 3187 | content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() { |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 3188 | #if !defined(OS_ANDROID) |
Scott Violet | e217e5e | 2020-06-22 19:18:22 | [diff] [blame] | 3189 | content::TtsController::GetInstance()->SetTtsEngineDelegate( |
| 3190 | TtsExtensionEngine::GetInstance()); |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 3191 | #endif |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 3192 | #ifdef OS_CHROMEOS |
| 3193 | return TtsPlatformImplChromeOs::GetInstance(); |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 3194 | #else |
| 3195 | return nullptr; |
| 3196 | #endif |
| 3197 | } |
| 3198 | |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 3199 | bool UpdatePreferredColorSchemesBasedOnURLIfNeeded(WebPreferences* web_prefs, |
| 3200 | const GURL& url) { |
| 3201 | // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is |
| 3202 | // disabled; some of the UI is not yet correctly themed. |
| 3203 | if (base::FeatureList::IsEnabled(features::kWebUIDarkMode)) |
| 3204 | return false; |
| 3205 | bool force_light = url.SchemeIs(content::kChromeUIScheme); |
| 3206 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 3207 | if (!force_light) { |
| 3208 | force_light = url.SchemeIs(extensions::kExtensionScheme) && |
| 3209 | url.host_piece() == extension_misc::kPdfExtensionId; |
| 3210 | } |
| 3211 | #endif |
| 3212 | auto old_preferred_color_scheme = web_prefs->preferred_color_scheme; |
| 3213 | if (force_light) |
| 3214 | web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight; |
| 3215 | return old_preferred_color_scheme != web_prefs->preferred_color_scheme; |
| 3216 | } |
| 3217 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3218 | void ChromeContentBrowserClient::OverrideWebkitPrefs( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3219 | RenderViewHost* rvh, |
| 3220 | WebPreferences* web_prefs) { |
| 3221 | Profile* profile = |
| 3222 | Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3223 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3224 | |
aelias | 0df335a | 2017-03-02 23:43:51 | [diff] [blame] | 3225 | // Fill font preferences. These are not registered on Android |
| 3226 | // - http://crbug.com/308033, http://crbug.com/696364. |
[email protected] | 33b7954 | 2013-10-18 11:18:45 | [diff] [blame] | 3227 | #if !defined(OS_ANDROID) |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3228 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3229 | prefs::kWebKitStandardFontFamilyMap, |
| 3230 | &web_prefs->standard_font_family_map); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3231 | FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap, |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3232 | &web_prefs->fixed_font_family_map); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3233 | FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap, |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3234 | &web_prefs->serif_font_family_map); |
| 3235 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3236 | prefs::kWebKitSansSerifFontFamilyMap, |
| 3237 | &web_prefs->sans_serif_font_family_map); |
| 3238 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3239 | prefs::kWebKitCursiveFontFamilyMap, |
| 3240 | &web_prefs->cursive_font_family_map); |
| 3241 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3242 | prefs::kWebKitFantasyFontFamilyMap, |
| 3243 | &web_prefs->fantasy_font_family_map); |
| 3244 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3245 | prefs::kWebKitPictographFontFamilyMap, |
| 3246 | &web_prefs->pictograph_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3247 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3248 | web_prefs->default_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3249 | prefs->GetInteger(prefs::kWebKitDefaultFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3250 | web_prefs->default_fixed_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3251 | prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3252 | web_prefs->minimum_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3253 | prefs->GetInteger(prefs::kWebKitMinimumFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3254 | web_prefs->minimum_logical_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3255 | prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize); |
aelias | 0df335a | 2017-03-02 23:43:51 | [diff] [blame] | 3256 | #endif |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3257 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3258 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3259 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3260 | web_prefs->dom_paste_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3261 | prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); |
Joel Hockey | 08a6c84c | 2018-04-11 10:09:21 | [diff] [blame] | 3262 | web_prefs->javascript_can_access_clipboard = |
| 3263 | prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3264 | web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3265 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3266 | if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3267 | web_prefs->javascript_enabled = false; |
mkwst | a1f7749b | 2015-12-28 09:28:57 | [diff] [blame] | 3268 | |
Avi Drissman | 1aa6cb9 | 2019-01-23 15:58:38 | [diff] [blame] | 3269 | if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3270 | web_prefs->web_security_enabled = false; |
mkwst | a1f7749b | 2015-12-28 09:28:57 | [diff] [blame] | 3271 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3272 | if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3273 | web_prefs->plugins_enabled = false; |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3274 | web_prefs->loads_images_automatically = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3275 | prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3276 | |
Zhenyao Mo | a3fda997 | 2017-09-16 01:34:40 | [diff] [blame] | 3277 | if (prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 3278 | web_prefs->webgl1_enabled = false; |
| 3279 | web_prefs->webgl2_enabled = false; |
| 3280 | } |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3281 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3282 | web_prefs->allow_running_insecure_content = |
| 3283 | prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3284 | #if defined(OS_ANDROID) |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 3285 | web_prefs->font_scale_factor = |
| 3286 | static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor)); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3287 | web_prefs->force_enable_zoom = |
| 3288 | prefs->GetBoolean(prefs::kWebKitForceEnableZoom); |
Aran Gilman | 5e9672bed | 2019-08-02 19:07:49 | [diff] [blame] | 3289 | #endif |
Becky Zhou | bbfbde3 | 2019-02-20 17:07:59 | [diff] [blame] | 3290 | web_prefs->force_dark_mode_enabled = |
| 3291 | prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled); |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 3292 | |
Alice Boxhall | da265914 | 2020-05-14 06:04:37 | [diff] [blame] | 3293 | #if defined(OS_CHROMEOS) |
| 3294 | web_prefs->always_show_focus = |
| 3295 | prefs->GetBoolean(ash::prefs::kAccessibilityFocusHighlightEnabled); |
Alice Boxhall | a9aafba4 | 2020-06-24 05:42:51 | [diff] [blame] | 3296 | #else |
| 3297 | if (features::IsAccessibilityFocusHighlightEnabled()) { |
| 3298 | web_prefs->always_show_focus = |
| 3299 | prefs->GetBoolean(prefs::kAccessibilityFocusHighlightEnabled); |
| 3300 | } |
Alice Boxhall | da265914 | 2020-05-14 06:04:37 | [diff] [blame] | 3301 | #endif |
| 3302 | |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 3303 | #if defined(OS_ANDROID) |
| 3304 | web_prefs->password_echo_enabled = |
| 3305 | prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled); |
| 3306 | #else |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 3307 | web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled; |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 3308 | #endif |
| 3309 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3310 | web_prefs->text_areas_are_resizable = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3311 | prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3312 | web_prefs->hyperlink_auditing_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3313 | prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); |
| 3314 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3315 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 3316 | std::string image_animation_policy = |
| 3317 | prefs->GetString(prefs::kAnimationPolicy); |
| 3318 | if (image_animation_policy == kAnimationPolicyOnce) |
| 3319 | web_prefs->animation_policy = |
| 3320 | content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE; |
| 3321 | else if (image_animation_policy == kAnimationPolicyNone) |
| 3322 | web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION; |
| 3323 | else |
| 3324 | web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED; |
| 3325 | #endif |
| 3326 | |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3327 | // Make sure we will set the default_encoding with canonical encoding name. |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 3328 | web_prefs->default_encoding = |
| 3329 | base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3330 | if (web_prefs->default_encoding.empty()) { |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3331 | prefs->ClearPref(prefs::kDefaultCharset); |
| 3332 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3333 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3334 | DCHECK(!web_prefs->default_encoding.empty()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3335 | |
mkwst | 0554410 | 2015-01-10 20:26:16 | [diff] [blame] | 3336 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3337 | switches::kEnablePotentiallyAnnoyingSecurityFeatures)) { |
mkwst | 772ce814 | 2015-01-16 13:28:07 | [diff] [blame] | 3338 | web_prefs->disable_reading_from_canvas = true; |
mkwst | 0554410 | 2015-01-10 20:26:16 | [diff] [blame] | 3339 | web_prefs->strict_mixed_content_checking = true; |
| 3340 | web_prefs->strict_powerful_feature_restrictions = true; |
| 3341 | } |
| 3342 | |
Robert Ogden | cf2872d | 2019-03-19 18:59:37 | [diff] [blame] | 3343 | web_prefs->data_saver_enabled = IsDataSaverEnabled(profile); |
Ben Greenstein | 49878f5 | 2015-12-18 19:13:21 | [diff] [blame] | 3344 | |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 3345 | web_prefs->data_saver_holdback_web_api_enabled = |
| 3346 | base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback, |
| 3347 | "holdback_web", false); |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 3348 | |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3349 | auto* contents = content::WebContents::FromRenderViewHost(rvh); |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3350 | if (contents) { |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3351 | #if defined(OS_ANDROID) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3352 | auto* delegate = TabAndroid::FromWebContents(contents) |
| 3353 | ? static_cast<android::TabWebContentsDelegateAndroid*>( |
| 3354 | contents->GetDelegate()) |
| 3355 | : nullptr; |
| 3356 | if (delegate) { |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3357 | web_prefs->embedded_media_experience_enabled = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3358 | delegate->ShouldEnableEmbeddedMediaExperience(); |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3359 | |
Mounir Lamouri | 9c99a160 | 2018-07-05 15:01:44 | [diff] [blame] | 3360 | web_prefs->picture_in_picture_enabled = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3361 | delegate->IsPictureInPictureEnabled(); |
Rune Lillesveen | 17e4832 | 2019-04-15 23:12:38 | [diff] [blame] | 3362 | |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 3363 | web_prefs->preferred_color_scheme = |
| 3364 | delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark |
| 3365 | : blink::PreferredColorScheme::kLight; |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3366 | } |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3367 | #endif // defined(OS_ANDROID) |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3368 | |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3369 | // web_app_scope value is platform specific. |
| 3370 | #if defined(OS_ANDROID) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3371 | if (delegate) |
| 3372 | web_prefs->web_app_scope = delegate->GetManifestScope(); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3373 | #elif BUILDFLAG(ENABLE_EXTENSIONS) |
| 3374 | { |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3375 | web_prefs->web_app_scope = GURL(); |
| 3376 | // Set |web_app_scope| based on the app associated with the app window if |
| 3377 | // any. Note that the app associated with the window never changes, even |
| 3378 | // if the app navigates off scope. This is not a problem because we still |
| 3379 | // want to use the scope of the app associated with the window, not the |
| 3380 | // WebContents. |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3381 | Browser* browser = chrome::FindBrowserWithWebContents(contents); |
Alan Cutter | d0bd5190 | 2019-05-22 04:15:23 | [diff] [blame] | 3382 | if (browser && browser->app_controller() && |
Alan Cutter | 1797f46a | 2020-02-12 02:48:59 | [diff] [blame] | 3383 | browser->app_controller()->HasAppId()) { |
| 3384 | const web_app::AppId& app_id = browser->app_controller()->GetAppId(); |
| 3385 | const web_app::AppRegistrar& registrar = |
| 3386 | web_app::WebAppProviderBase::GetProviderBase(profile)->registrar(); |
| 3387 | if (registrar.IsLocallyInstalled(app_id)) |
| 3388 | web_prefs->web_app_scope = registrar.GetAppScope(app_id); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3389 | } |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3390 | } |
| 3391 | #endif |
| 3392 | |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3393 | web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents); |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3394 | } |
zqzhang | 93e959d1 | 2017-03-16 13:10:20 | [diff] [blame] | 3395 | |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 3396 | if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) { |
| 3397 | // Obtain the maximum effective connection type at which the feature is |
| 3398 | // enabled. |
| 3399 | std::string effective_connection_type_param = |
| 3400 | base::GetFieldTrialParamValueByFeature( |
| 3401 | features::kLowPriorityIframes, |
| 3402 | "max_effective_connection_type_threshold"); |
| 3403 | |
| 3404 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3405 | net::GetEffectiveConnectionTypeForName(effective_connection_type_param); |
| 3406 | if (effective_connection_type) { |
| 3407 | web_prefs->low_priority_iframes_threshold = |
| 3408 | effective_connection_type.value(); |
| 3409 | } |
| 3410 | } |
| 3411 | |
rajendrant | 0521cee | 2019-07-29 06:09:26 | [diff] [blame] | 3412 | web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() || |
| 3413 | contents->GetDelegate()->ShouldAllowLazyLoad(); |
rajendrant | e87ed71 | 2018-11-30 01:55:00 | [diff] [blame] | 3414 | |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 3415 | if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) { |
| 3416 | const char* param_name = |
| 3417 | web_prefs->data_saver_enabled |
| 3418 | ? "lazy_frame_loading_distance_thresholds_px_by_ect" |
| 3419 | : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_" |
| 3420 | "saver_enabled"; |
| 3421 | |
| 3422 | base::StringPairs pairs; |
| 3423 | base::SplitStringIntoKeyValuePairs( |
| 3424 | base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading, |
| 3425 | param_name), |
| 3426 | ':', ',', &pairs); |
| 3427 | |
| 3428 | for (const auto& pair : pairs) { |
| 3429 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3430 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3431 | int value = 0; |
| 3432 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3433 | web_prefs->lazy_frame_loading_distance_thresholds_px |
| 3434 | [effective_connection_type.value()] = value; |
| 3435 | } |
| 3436 | } |
| 3437 | } |
| 3438 | |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 3439 | if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) { |
| 3440 | const char* param_name = |
| 3441 | web_prefs->data_saver_enabled |
| 3442 | ? "lazy_image_loading_distance_thresholds_px_by_ect" |
| 3443 | : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_" |
| 3444 | "saver_enabled"; |
| 3445 | |
| 3446 | base::StringPairs pairs; |
| 3447 | base::SplitStringIntoKeyValuePairs( |
| 3448 | base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading, |
| 3449 | param_name), |
| 3450 | ':', ',', &pairs); |
| 3451 | |
| 3452 | for (const auto& pair : pairs) { |
| 3453 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3454 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3455 | int value = 0; |
| 3456 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3457 | web_prefs->lazy_image_loading_distance_thresholds_px |
| 3458 | [effective_connection_type.value()] = value; |
| 3459 | } |
| 3460 | } |
rajendrant | 3daeae29 | 2019-09-20 07:57:54 | [diff] [blame] | 3461 | |
| 3462 | pairs.clear(); |
| 3463 | base::SplitStringIntoKeyValuePairs( |
| 3464 | base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading, |
| 3465 | "lazy_image_first_k_fully_load"), |
| 3466 | ':', ',', &pairs); |
| 3467 | |
| 3468 | for (const auto& pair : pairs) { |
| 3469 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3470 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3471 | int value = 0; |
| 3472 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3473 | web_prefs |
| 3474 | ->lazy_image_first_k_fully_load[effective_connection_type.value()] = |
| 3475 | value; |
| 3476 | } |
| 3477 | } |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 3478 | } |
| 3479 | |
Tarun Bansal | d10f17a0 | 2018-09-13 00:23:17 | [diff] [blame] | 3480 | if (base::FeatureList::IsEnabled( |
| 3481 | features::kNetworkQualityEstimatorWebHoldback)) { |
| 3482 | std::string effective_connection_type_param = |
| 3483 | base::GetFieldTrialParamValueByFeature( |
| 3484 | features::kNetworkQualityEstimatorWebHoldback, |
| 3485 | "web_effective_connection_type_override"); |
| 3486 | |
| 3487 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3488 | net::GetEffectiveConnectionTypeForName(effective_connection_type_param); |
| 3489 | DCHECK(effective_connection_type_param.empty() || |
| 3490 | effective_connection_type); |
| 3491 | if (effective_connection_type) { |
| 3492 | DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 3493 | effective_connection_type.value()); |
| 3494 | web_prefs->network_quality_estimator_web_holdback = |
| 3495 | effective_connection_type.value(); |
| 3496 | } |
| 3497 | } |
| 3498 | |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3499 | #if !defined(OS_ANDROID) |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 3500 | if (IsAutoplayAllowedByPolicy(contents, prefs)) { |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3501 | // If autoplay is allowed by policy then force the no user gesture required |
| 3502 | // autoplay policy. |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3503 | web_prefs->autoplay_policy = |
| 3504 | content::AutoplayPolicy::kNoUserGestureRequired; |
Mounir Lamouri | c2186808 | 2018-10-11 21:09:55 | [diff] [blame] | 3505 | } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) && |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3506 | web_prefs->autoplay_policy == |
| 3507 | content::AutoplayPolicy::kDocumentUserActivationRequired) { |
Mounir Lamouri | c2186808 | 2018-10-11 21:09:55 | [diff] [blame] | 3508 | // If the autoplay disable settings feature is enabled and the autoplay |
| 3509 | // policy is set to using the unified policy then set the default autoplay |
| 3510 | // policy based on user preference. |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3511 | web_prefs->autoplay_policy = |
| 3512 | UnifiedAutoplayConfig::ShouldBlockAutoplay(profile) |
| 3513 | ? content::AutoplayPolicy::kDocumentUserActivationRequired |
| 3514 | : content::AutoplayPolicy::kNoUserGestureRequired; |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3515 | } |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 3516 | |
Abigail Klein | a81f2e2 | 2020-05-04 14:32:41 | [diff] [blame] | 3517 | auto* native_theme = GetWebTheme(); |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 3518 | switch (native_theme->GetPreferredColorScheme()) { |
| 3519 | case ui::NativeTheme::PreferredColorScheme::kDark: |
| 3520 | web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark; |
| 3521 | break; |
| 3522 | case ui::NativeTheme::PreferredColorScheme::kLight: |
| 3523 | web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight; |
| 3524 | break; |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 3525 | } |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3526 | #endif // !defined(OS_ANDROID) |
| 3527 | |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 3528 | UpdatePreferredColorSchemesBasedOnURLIfNeeded( |
| 3529 | web_prefs, rvh->GetSiteInstance()->GetSiteURL()); |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3530 | |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 3531 | web_prefs->translate_service_available = TranslateService::IsAvailable(prefs); |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 3532 | |
Abigail Klein | a81f2e2 | 2020-05-04 14:32:41 | [diff] [blame] | 3533 | base::Optional<ui::CaptionStyle> style = |
| 3534 | captions::GetCaptionStyleFromUserSettings(prefs, |
| 3535 | true /* record_metrics */); |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3536 | if (style) { |
| 3537 | web_prefs->text_track_background_color = style->background_color; |
| 3538 | web_prefs->text_track_text_color = style->text_color; |
| 3539 | web_prefs->text_track_text_size = style->text_size; |
| 3540 | web_prefs->text_track_text_shadow = style->text_shadow; |
| 3541 | web_prefs->text_track_font_family = style->font_family; |
| 3542 | web_prefs->text_track_font_variant = style->font_variant; |
Abigail Klein | 74de85bd | 2019-07-11 19:11:56 | [diff] [blame] | 3543 | web_prefs->text_track_window_color = style->window_color; |
| 3544 | web_prefs->text_track_window_padding = style->window_padding; |
| 3545 | web_prefs->text_track_window_radius = style->window_radius; |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3546 | } |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3547 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3548 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
creis | 7b2d3d1 | 2015-02-12 23:29:50 | [diff] [blame] | 3549 | extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 3550 | } |
| 3551 | |
Rakina Zata Amni | 347b7090 | 2020-07-22 10:49:04 | [diff] [blame] | 3552 | bool ChromeContentBrowserClient::OverrideWebPreferencesAfterNavigation( |
| 3553 | WebContents* web_contents, |
| 3554 | WebPreferences* prefs) { |
| 3555 | return UpdatePreferredColorSchemesBasedOnURLIfNeeded( |
| 3556 | prefs, web_contents->GetLastCommittedURL()); |
| 3557 | } |
| 3558 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3559 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 3560 | BrowserURLHandler* handler) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3561 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 3562 | extra_parts_[i]->BrowserURLHandlerCreated(handler); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3563 | |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 3564 | // about: handler. Must come before chrome: handler, since it will |
| 3565 | // rewrite about: urls to chrome: URLs and then expect chrome: to |
creis | 94a977f6 | 2015-02-18 23:51:05 | [diff] [blame] | 3566 | // actually handle them. Also relies on a preliminary fixup phase. |
| 3567 | handler->SetFixupHandler(&FixupBrowserAboutURL); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3568 | handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 3569 | BrowserURLHandler::null_handler()); |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3570 | |
mad | fbd1085 | 2017-01-20 03:15:33 | [diff] [blame] | 3571 | // The group policy NTP URL handler must be registered before the other NTP |
| 3572 | // URL handlers below. |
| 3573 | handler->AddHandlerPair(&HandleNewTabPageLocationOverride, |
| 3574 | BrowserURLHandler::null_handler()); |
| 3575 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 3576 | #if defined(OS_ANDROID) |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3577 | // Handler to rewrite chrome://newtab on Android. |
ianwen | 465e17b | 2015-01-20 18:32:35 | [diff] [blame] | 3578 | handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL, |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3579 | BrowserURLHandler::null_handler()); |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 3580 | #else // defined(OS_ANDROID) |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3581 | // Handler to rewrite chrome://newtab for InstantExtended. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 3582 | handler->AddHandlerPair(&search::HandleNewTabURLRewrite, |
| 3583 | &search::HandleNewTabURLReverseRewrite); |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 3584 | #endif // defined(OS_ANDROID) |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3585 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3586 | // chrome: & friends. |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 3587 | handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI, |
| 3588 | &ChromeContentBrowserClient::HandleWebUIReverse); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3589 | } |
| 3590 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3591 | base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 3592 | return DownloadPrefs::GetDefaultDownloadDirectory(); |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 3593 | } |
| 3594 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 3595 | std::string ChromeContentBrowserClient::GetDefaultDownloadName() { |
| 3596 | return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 3597 | } |
| 3598 | |
Dominik Röttsches | 4734783 | 2019-03-12 17:45:01 | [diff] [blame] | 3599 | base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() { |
| 3600 | base::FilePath user_data_dir; |
| 3601 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 3602 | DCHECK(!user_data_dir.empty()); |
| 3603 | return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache")); |
| 3604 | } |
| 3605 | |
jmadill | 57b52d4 | 2015-08-21 18:16:13 | [diff] [blame] | 3606 | base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() { |
| 3607 | base::FilePath user_data_dir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 3608 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
jmadill | 57b52d4 | 2015-08-21 18:16:13 | [diff] [blame] | 3609 | DCHECK(!user_data_dir.empty()); |
| 3610 | return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache")); |
| 3611 | } |
| 3612 | |
Khushal | 7ca0b78 | 2018-07-20 05:53:27 | [diff] [blame] | 3613 | base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() { |
| 3614 | base::FilePath user_data_dir; |
| 3615 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 3616 | DCHECK(!user_data_dir.empty()); |
| 3617 | return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache")); |
| 3618 | } |
| 3619 | |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 3620 | void ChromeContentBrowserClient::DidCreatePpapiPlugin( |
| 3621 | content::BrowserPpapiHost* browser_host) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3622 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 3623 | ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host); |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 3624 | #endif |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 3625 | } |
| 3626 | |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3627 | content::BrowserPpapiHost* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3628 | ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) { |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 3629 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 3630 | content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3631 | while (!iter.Done()) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3632 | nacl::NaClProcessHost* host = |
| 3633 | static_cast<nacl::NaClProcessHost*>(iter.GetDelegate()); |
| 3634 | if (host->process() && host->process()->GetData().id == plugin_process_id) { |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3635 | // Found the plugin. |
| 3636 | return host->browser_ppapi_host(); |
| 3637 | } |
| 3638 | ++iter; |
| 3639 | } |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 3640 | #endif |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3641 | return nullptr; |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3642 | } |
| 3643 | |
[email protected] | 38cd8f7f | 2012-06-15 22:06:07 | [diff] [blame] | 3644 | bool ChromeContentBrowserClient::AllowPepperSocketAPI( |
[email protected] | 157cc90 | 2012-11-02 06:31:58 | [diff] [blame] | 3645 | content::BrowserContext* browser_context, |
| 3646 | const GURL& url, |
[email protected] | dda5482 | 2013-06-15 01:26:39 | [diff] [blame] | 3647 | bool private_api, |
[email protected] | 8b92ed18 | 2013-09-21 04:47:12 | [diff] [blame] | 3648 | const content::SocketPermissionRequest* params) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3649 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 3650 | return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI( |
Lei Zhang | 19736cde | 2020-02-07 18:51:19 | [diff] [blame] | 3651 | browser_context, url, private_api, params); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 3652 | #else |
[email protected] | a658d45 | 2012-03-02 12:45:29 | [diff] [blame] | 3653 | return false; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 3654 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 3655 | } |
| 3656 | |
adrian.belgun | d54465ba | 2016-05-18 10:03:58 | [diff] [blame] | 3657 | bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed( |
| 3658 | content::BrowserContext* browser_context, |
| 3659 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3660 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
adrian.belgun | d54465ba | 2016-05-18 10:03:58 | [diff] [blame] | 3661 | return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed( |
| 3662 | browser_context, url); |
| 3663 | #else |
| 3664 | return false; |
| 3665 | #endif |
| 3666 | } |
| 3667 | |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 3668 | std::unique_ptr<content::VpnServiceProxy> |
| 3669 | ChromeContentBrowserClient::GetVpnServiceProxy( |
| 3670 | content::BrowserContext* browser_context) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3671 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 3672 | return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy( |
| 3673 | browser_context); |
| 3674 | #else |
| 3675 | return nullptr; |
| 3676 | #endif |
| 3677 | } |
| 3678 | |
Brett Wilson | 804e83c | 2017-08-18 22:57:33 | [diff] [blame] | 3679 | std::unique_ptr<ui::SelectFilePolicy> |
| 3680 | ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) { |
| 3681 | return std::make_unique<ChromeSelectFilePolicy>(web_contents); |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 3682 | } |
| 3683 | |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 3684 | void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 3685 | std::vector<std::string>* additional_allowed_schemes) { |
| 3686 | ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 3687 | additional_allowed_schemes); |
[email protected] | b3690f7 | 2014-02-17 00:32:48 | [diff] [blame] | 3688 | additional_allowed_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 3689 | additional_allowed_schemes->push_back(content::kChromeUIScheme); |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3690 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
| 3691 | extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem( |
| 3692 | additional_allowed_schemes); |
| 3693 | } |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 3694 | } |
| 3695 | |
Ayu Ishii | fbb1fad | 2020-06-22 20:15:07 | [diff] [blame] | 3696 | void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckAllowlist( |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 3697 | std::set<std::string>* schemes) { |
Ayu Ishii | fbb1fad | 2020-06-22 20:15:07 | [diff] [blame] | 3698 | *schemes = secure_origin_allowlist::GetSchemesBypassingSecureContextCheck(); |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 3699 | } |
| 3700 | |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 3701 | void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3702 | std::vector<storage::URLRequestAutoMountHandler>* handlers) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3703 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 3704 | extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers); |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 3705 | } |
| 3706 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 3707 | void ChromeContentBrowserClient::GetAdditionalFileSystemBackends( |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 3708 | content::BrowserContext* browser_context, |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 3709 | const base::FilePath& storage_partition_path, |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3710 | std::vector<std::unique_ptr<storage::FileSystemBackend>>* |
| 3711 | additional_backends) { |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3712 | #if defined(OS_CHROMEOS) |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3713 | storage::ExternalMountPoints* external_mount_points = |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 3714 | content::BrowserContext::GetMountPoints(browser_context); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3715 | DCHECK(external_mount_points); |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3716 | auto backend = std::make_unique<chromeos::FileSystemBackend>( |
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) { |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 3770 | mappings->Share(service_manager::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: |
Alex Gough | 9ab468a6c3 | 2019-12-10 19:10:22 | [diff] [blame] | 3803 | // Should never reach here. |
| 3804 | CHECK(0); |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3805 | return base::string16(); |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3806 | } |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3807 | } |
| 3808 | |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3809 | bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy, |
| 3810 | RendererSpawnFlags flags) { |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 3811 | // Does not work under component build because all the component DLLs would need |
| 3812 | // to be manually added and maintained. Does not work under ASAN build because |
| 3813 | // ASAN has not yet fully initialized its instrumentation by the time the CIG |
| 3814 | // intercepts run. |
| 3815 | #if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3816 | if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0) |
| 3817 | return true; |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3818 | if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity)) |
| 3819 | return true; |
| 3820 | |
| 3821 | // Only enable signing mitigation if launching from chrome.exe. |
| 3822 | base::FilePath exe_path; |
| 3823 | if (!base::PathService::Get(base::FILE_EXE, &exe_path)) |
| 3824 | return true; |
| 3825 | if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value()) |
| 3826 | return true; |
| 3827 | |
| 3828 | sandbox::MitigationFlags mitigations = policy->GetProcessMitigations(); |
| 3829 | mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS; |
Alex Gough | 59f406b | 2019-12-03 18:04:09 | [diff] [blame] | 3830 | sandbox::ResultCode result = policy->SetProcessMitigations(mitigations); |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3831 | if (result != sandbox::SBOX_ALL_OK) |
| 3832 | return false; |
| 3833 | |
Nico Weber | c36b015 | 2020-04-18 03:12:46 | [diff] [blame] | 3834 | // Allow loading Chrome's DLLs. |
| 3835 | for (const auto* dll : {chrome::kBrowserResourcesDll, chrome::kElfDll}) { |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3836 | result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY, |
| 3837 | sandbox::TargetPolicy::SIGNED_ALLOW_LOAD, |
| 3838 | GetModulePath(dll).value().c_str()); |
| 3839 | if (result != sandbox::SBOX_ALL_OK) |
| 3840 | return false; |
| 3841 | } |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 3842 | #endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3843 | |
| 3844 | return true; |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 3845 | } |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3846 | |
| 3847 | bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() { |
| 3848 | PrefService* local_state = g_browser_process->local_state(); |
| 3849 | if (local_state && |
| 3850 | local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) && |
| 3851 | !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled)) |
| 3852 | return false; |
| 3853 | return true; |
| 3854 | } |
| 3855 | |
wfh | c91e967 | 2016-01-27 00:14:20 | [diff] [blame] | 3856 | #endif // defined(OS_WIN) |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 3857 | |
Armando Miraglia | 3a7be23 | 2019-11-08 00:33:32 | [diff] [blame] | 3858 | |
Ken Rockot | fa5d5711 | 2019-05-29 20:57:14 | [diff] [blame] | 3859 | void ChromeContentBrowserClient::WillStartServiceManager() { |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 3860 | #if defined(OS_WIN) || defined(OS_MAC) || \ |
Guido Urdaneta | d06ae84 | 2019-10-10 20:04:12 | [diff] [blame] | 3861 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 3862 | if (startup_data_) { |
| 3863 | auto* chrome_feature_list_creator = |
| 3864 | startup_data_->chrome_feature_list_creator(); |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3865 | // This has to run very early before ServiceManagerContext is created. |
Guido Urdaneta | d06ae84 | 2019-10-10 20:04:12 | [diff] [blame] | 3866 | const policy::PolicyMap& policies = |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 3867 | chrome_feature_list_creator->browser_policy_connector() |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3868 | ->GetPolicyService() |
| 3869 | ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
Guido Urdaneta | d06ae84 | 2019-10-10 20:04:12 | [diff] [blame] | 3870 | std::string())); |
Guido Urdaneta | e02b572 | 2020-07-22 05:58:21 | [diff] [blame] | 3871 | const base::Value* audio_sandbox_enabled_policy_value = |
| 3872 | policies.GetValue(policy::key::kAudioSandboxEnabled); |
| 3873 | if (audio_sandbox_enabled_policy_value) { |
| 3874 | bool force_enable_audio_sandbox; |
| 3875 | audio_sandbox_enabled_policy_value->GetAsBoolean( |
| 3876 | &force_enable_audio_sandbox); |
| 3877 | SetForceAudioServiceSandboxed(force_enable_audio_sandbox); |
| 3878 | } |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3879 | } |
| 3880 | #endif |
xhwang | 5e63046 | 2015-10-30 03:18:48 | [diff] [blame] | 3881 | } |
| 3882 | |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 3883 | void ChromeContentBrowserClient::OpenURL( |
Matt Falkenhagen | 18c5c5d | 2018-11-26 02:55:37 | [diff] [blame] | 3884 | content::SiteInstance* site_instance, |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 3885 | const content::OpenURLParams& params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 3886 | base::OnceCallback<void(content::WebContents*)> callback) { |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3887 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Matt Falkenhagen | 18c5c5d | 2018-11-26 02:55:37 | [diff] [blame] | 3888 | |
| 3889 | content::BrowserContext* browser_context = site_instance->GetBrowserContext(); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3890 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 3891 | #if defined(OS_ANDROID) |
pkotwicz | aa289f0 | 2016-07-05 22:26:22 | [diff] [blame] | 3892 | ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 3893 | std::move(callback)); |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 3894 | #else |
cm.sanchi | 2522bc9 | 2017-12-04 08:04:13 | [diff] [blame] | 3895 | NavigateParams nav_params(Profile::FromBrowserContext(browser_context), |
| 3896 | params.url, params.transition); |
| 3897 | nav_params.FillNavigateParamsFromOpenURLParams(params); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3898 | |
| 3899 | Navigate(&nav_params); |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 3900 | std::move(callback).Run(nav_params.navigated_or_inserted_contents); |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 3901 | #endif |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3902 | } |
| 3903 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 3904 | content::ControllerPresentationServiceDelegate* |
| 3905 | ChromeContentBrowserClient::GetControllerPresentationServiceDelegate( |
| 3906 | content::WebContents* web_contents) { |
mfoltz | 99bd44c | 2016-03-18 20:36:46 | [diff] [blame] | 3907 | if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) { |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 3908 | return media_router::PresentationServiceDelegateImpl:: |
| 3909 | GetOrCreateForWebContents(web_contents); |
| 3910 | } |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 3911 | return nullptr; |
| 3912 | } |
| 3913 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 3914 | content::ReceiverPresentationServiceDelegate* |
| 3915 | ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate( |
| 3916 | content::WebContents* web_contents) { |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 3917 | if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) { |
| 3918 | // ReceiverPresentationServiceDelegateImpl exists only for WebContents |
| 3919 | // created for offscreen presentations. The WebContents must belong to |
| 3920 | // an incognito profile. |
| 3921 | if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl:: |
| 3922 | FromWebContents(web_contents)) { |
| 3923 | DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord()); |
| 3924 | return impl; |
| 3925 | } |
| 3926 | } |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 3927 | return nullptr; |
| 3928 | } |
| 3929 | |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3930 | std::vector<std::unique_ptr<content::NavigationThrottle>> |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3931 | ChromeContentBrowserClient::CreateThrottlesForNavigation( |
| 3932 | content::NavigationHandle* handle) { |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3933 | std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 3934 | |
bmcquade | b455655 | 2017-03-24 22:24:37 | [diff] [blame] | 3935 | // MetricsNavigationThrottle requires that it runs before NavigationThrottles |
| 3936 | // that may delay or cancel navigations, so only NavigationThrottles that |
| 3937 | // don't delay or cancel navigations (e.g. throttles that are only observing |
| 3938 | // callbacks without affecting navigation behavior) should be added before |
| 3939 | // MetricsNavigationThrottle. |
| 3940 | if (handle->IsInMainFrame()) { |
| 3941 | throttles.push_back( |
| 3942 | page_load_metrics::MetricsNavigationThrottle::Create(handle)); |
| 3943 | } |
| 3944 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3945 | #if BUILDFLAG(ENABLE_PLUGINS) |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 3946 | MaybeAddThrottle(FlashDownloadInterception::MaybeCreateThrottleFor(handle), |
| 3947 | &throttles); |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 3948 | #endif |
| 3949 | |
yilkal | 240b4f2 | 2019-11-27 19:09:06 | [diff] [blame] | 3950 | #if defined(OS_CHROMEOS) |
| 3951 | MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 3952 | chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 3953 | &throttles); |
yilkal | 240b4f2 | 2019-11-27 19:09:06 | [diff] [blame] | 3954 | #endif // defined(OS_CHROMEOS) |
| 3955 | |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 3956 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3957 | MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 3958 | SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 3959 | &throttles); |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 3960 | #endif |
| 3961 | |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3962 | #if defined(OS_ANDROID) |
| 3963 | // TODO(davidben): This is insufficient to integrate with prerender properly. |
| 3964 | // https://crbug.com/370595 |
| 3965 | prerender::PrerenderContents* prerender_contents = |
Mugdha Lakhani | 2c6b23af | 2020-07-31 14:55:57 | [diff] [blame] | 3966 | prerender::ChromePrerenderContentsDelegate::FromWebContents( |
| 3967 | handle->GetWebContents()); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3968 | if (!prerender_contents && handle->IsInMainFrame()) { |
| 3969 | throttles.push_back( |
| 3970 | navigation_interception::InterceptNavigationDelegate::CreateThrottleFor( |
Charlie Harrison | 3286ab7 | 2019-02-13 20:13:30 | [diff] [blame] | 3971 | handle, navigation_interception::SynchronyMode::kAsync)); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3972 | } |
Min Qin | 0ab0e16 | 2017-11-14 21:57:19 | [diff] [blame] | 3973 | throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle)); |
Samuel Huang | 3a1ce1c3 | 2019-10-16 17:34:04 | [diff] [blame] | 3974 | |
| 3975 | #if BUILDFLAG(DFMIFY_DEV_UI) |
| 3976 | // If the DevUI DFM is already installed, then this is a no-op, except for the |
| 3977 | // side effect of ensuring that the DevUI DFM is loaded. |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 3978 | MaybeAddThrottle(dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle), |
| 3979 | &throttles); |
Samuel Huang | 3a1ce1c3 | 2019-10-16 17:34:04 | [diff] [blame] | 3980 | #endif // BUILDFLAG(DFMIFY_DEV_UI) |
| 3981 | |
Giovanni Ortuño Urquidi | 7ae7fb0 | 2017-10-09 01:49:57 | [diff] [blame] | 3982 | #elif BUILDFLAG(ENABLE_EXTENSIONS) |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3983 | if (handle->IsInMainFrame()) { |
| 3984 | // Redirect some navigations to apps that have registered matching URL |
| 3985 | // handlers ('url_handlers' in the manifest). |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 3986 | MaybeAddThrottle( |
| 3987 | PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle), |
| 3988 | &throttles); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3989 | } |
| 3990 | #endif |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 3991 | |
| 3992 | #if defined(OS_CHROMEOS) |
| 3993 | // Check if we need to add merge session throttle. This throttle will postpone |
| 3994 | // loading of main frames. |
| 3995 | if (handle->IsInMainFrame()) { |
| 3996 | // Add interstitial page while merge session process (cookie reconstruction |
| 3997 | // from OAuth2 refresh token in ChromeOS login) is still in progress while |
| 3998 | // we are attempting to load a google property. |
csharrison | dd06bab | 2016-07-22 14:15:02 | [diff] [blame] | 3999 | if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() && |
| 4000 | !merge_session_throttling_utils::AreAllSessionMergedAlready() && |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4001 | handle->GetURL().SchemeIsHTTPOrHTTPS()) { |
| 4002 | throttles.push_back(MergeSessionNavigationThrottle::Create(handle)); |
| 4003 | } |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4004 | } |
| 4005 | #endif |
djacobo | 21e56e0 | 2016-07-02 01:14:31 | [diff] [blame] | 4006 | |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4007 | #if !defined(OS_ANDROID) |
Maggie Cai | c08b7d4 | 2020-05-05 03:51:10 | [diff] [blame] | 4008 | auto url_to_apps_throttle = |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4009 | #if defined(OS_CHROMEOS) |
Maggie Cai | c08b7d4 | 2020-05-05 03:51:10 | [diff] [blame] | 4010 | base::FeatureList::IsEnabled(features::kAppServiceIntentHandling) |
| 4011 | ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle) |
| 4012 | : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle); |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 4013 | #elif defined(OS_MAC) |
Maggie Cai | c08b7d4 | 2020-05-05 03:51:10 | [diff] [blame] | 4014 | apps::MacAppsNavigationThrottle::MaybeCreate(handle); |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4015 | #else |
Maggie Cai | c08b7d4 | 2020-05-05 03:51:10 | [diff] [blame] | 4016 | apps::AppsNavigationThrottle::MaybeCreate(handle); |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4017 | #endif |
Maggie Cai | c08b7d4 | 2020-05-05 03:51:10 | [diff] [blame] | 4018 | if (url_to_apps_throttle) |
| 4019 | throttles.push_back(std::move(url_to_apps_throttle)); |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4020 | #endif |
| 4021 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 4022 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 4023 | throttles.push_back( |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4024 | std::make_unique<extensions::ExtensionNavigationThrottle>(handle)); |
Clark DuVall | 2cf99249e | 2018-09-19 19:11:51 | [diff] [blame] | 4025 | |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4026 | MaybeAddThrottle(extensions::ExtensionsBrowserClient::Get() |
| 4027 | ->GetUserScriptListener() |
| 4028 | ->CreateNavigationThrottle(handle), |
| 4029 | &throttles); |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 4030 | #endif |
| 4031 | |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 4032 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 4033 | MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4034 | SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle), |
| 4035 | &throttles); |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 4036 | #endif |
| 4037 | |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 4038 | content::WebContents* web_contents = handle->GetWebContents(); |
csharrison | 77bf834 | 2017-05-04 18:23:10 | [diff] [blame] | 4039 | if (auto* subresource_filter_client = |
| 4040 | ChromeSubresourceFilterClient::FromWebContents(web_contents)) { |
| 4041 | subresource_filter_client->MaybeAppendNavigationThrottles(handle, |
| 4042 | &throttles); |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 4043 | } |
| 4044 | |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 4045 | #if !defined(OS_ANDROID) |
| 4046 | // BackgroundTabNavigationThrottle is used by TabManager, which is only |
| 4047 | // enabled on non-Android platforms. |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4048 | MaybeAddThrottle(resource_coordinator::BackgroundTabNavigationThrottle:: |
| 4049 | MaybeCreateThrottleFor(handle), |
| 4050 | &throttles); |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 4051 | #endif |
| 4052 | |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 4053 | #if BUILDFLAG(SAFE_BROWSING_AVAILABLE) |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4054 | MaybeAddThrottle(safe_browsing::MaybeCreateNavigationThrottle(handle), |
| 4055 | &throttles); |
Jialiu Lin | bdbb81d | 2017-10-11 21:29:09 | [diff] [blame] | 4056 | #endif |
| 4057 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 4058 | MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4059 | LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle), |
| 4060 | &throttles); |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 4061 | |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4062 | MaybeAddThrottle(PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 4063 | &throttles); |
Amber Won | 6b5edc75 | 2017-08-17 19:23:54 | [diff] [blame] | 4064 | |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4065 | MaybeAddThrottle(TabUnderNavigationThrottle::MaybeCreate(handle), &throttles); |
Charles Harrison | 6dd11d28 | 2017-10-03 06:14:51 | [diff] [blame] | 4066 | |
Jonathan Mengedoht | 42a19bb | 2020-07-28 14:10:16 | [diff] [blame] | 4067 | MaybeAddThrottle( |
| 4068 | WellKnownChangePasswordNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 4069 | &throttles); |
| 4070 | |
Aaron Colwell | f94fd97a | 2020-07-21 19:37:08 | [diff] [blame] | 4071 | throttles.push_back(std::make_unique<PolicyBlocklistNavigationThrottle>( |
Doug Turner | 9dcaf596 | 2017-12-21 04:38:53 | [diff] [blame] | 4072 | handle, handle->GetWebContents()->GetBrowserContext())); |
| 4073 | |
Colin Blundell | eaa7377bf | 2020-01-22 08:49:10 | [diff] [blame] | 4074 | // Before setting up SSL error detection, configure SSLErrorHandler to invoke |
| 4075 | // the relevant extension API whenever an SSL interstitial is shown. |
| 4076 | SSLErrorHandler::SetClientCallbackOnInterstitialsShown( |
| 4077 | base::BindRepeating(&MaybeTriggerSecurityInterstitialShownEvent)); |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4078 | throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>( |
| 4079 | handle, |
| 4080 | std::make_unique<CertificateReportingServiceCertReporter>(web_contents), |
Colin Blundell | 9ee731dd | 2020-01-23 10:42:38 | [diff] [blame] | 4081 | base::BindOnce(&HandleSSLErrorWrapper), base::BindOnce(&IsInHostedApp))); |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 4082 | |
Emily Stark | d6896cd3 | 2019-08-21 04:55:54 | [diff] [blame] | 4083 | throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle)); |
| 4084 | |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 4085 | #if !defined(OS_ANDROID) |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4086 | MaybeAddThrottle(DevToolsWindow::MaybeCreateNavigationThrottle(handle), |
| 4087 | &throttles); |
| 4088 | |
| 4089 | MaybeAddThrottle(NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 4090 | &throttles); |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 4091 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 4092 | MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4093 | GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 4094 | &throttles); |
Jonathan Mengedoht | a881f6dd | 2020-06-19 16:03:20 | [diff] [blame] | 4095 | |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 4096 | #endif |
| 4097 | |
Carlos IL | 800e350 | 2020-04-30 16:35:59 | [diff] [blame] | 4098 | throttles.push_back( |
| 4099 | std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>(handle)); |
Robert Ogden | afd250b | 2018-07-25 22:21:03 | [diff] [blame] | 4100 | |
Mustafa Emre Acer | 97be475 | 2020-05-13 01:24:43 | [diff] [blame] | 4101 | if (base::FeatureList::IsEnabled(safe_browsing::kDelayedWarnings)) { |
| 4102 | throttles.push_back( |
| 4103 | std::make_unique<safe_browsing::DelayedWarningNavigationThrottle>( |
| 4104 | handle)); |
| 4105 | } |
| 4106 | |
Avi Drissman | 2e458df | 2020-07-29 16:24:31 | [diff] [blame] | 4107 | #if defined(OS_WIN) || defined(OS_MAC) || \ |
Nicolas Ouellet-Payeur | bdcab009 | 2018-10-22 14:50:33 | [diff] [blame] | 4108 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4109 | MaybeAddThrottle(browser_switcher::BrowserSwitcherNavigationThrottle:: |
| 4110 | MaybeCreateThrottleFor(handle), |
| 4111 | &throttles); |
Nicolas Ouellet-Payeur | 995e777 | 2018-09-13 16:02:13 | [diff] [blame] | 4112 | #endif |
| 4113 | |
Anatoliy Potapchuk | 762c40d | 2020-05-11 15:10:37 | [diff] [blame] | 4114 | #if defined(OS_CHROMEOS) |
| 4115 | MaybeAddThrottle( |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4116 | chromeos::KioskSettingsNavigationThrottle::MaybeCreateThrottleFor(handle), |
| 4117 | &throttles); |
Anatoliy Potapchuk | 762c40d | 2020-05-11 15:10:37 | [diff] [blame] | 4118 | #endif |
| 4119 | |
Chris Hamilton | ab472212 | 2020-05-13 18:01:28 | [diff] [blame] | 4120 | auto* performance_manager_registry = |
| 4121 | performance_manager::PerformanceManagerRegistry::GetInstance(); |
| 4122 | if (performance_manager_registry) { |
| 4123 | MaybeAddThrottles( |
| 4124 | performance_manager_registry->CreateThrottlesForNavigation(handle), |
| 4125 | &throttles); |
| 4126 | } |
| 4127 | |
Carlos IL | 06e6c8c | 2020-07-28 00:25:19 | [diff] [blame] | 4128 | Profile* profile = Profile::FromBrowserContext( |
| 4129 | handle->GetWebContents()->GetBrowserContext()); |
| 4130 | if (profile && profile->GetPrefs()) { |
| 4131 | MaybeAddThrottle( |
| 4132 | security_interstitials::InsecureFormNavigationThrottle:: |
| 4133 | MaybeCreateNavigationThrottle( |
| 4134 | handle, std::make_unique<ChromeSecurityBlockingPageFactory>(), |
| 4135 | profile->GetPrefs()), |
| 4136 | &throttles); |
| 4137 | } |
Carlos IL | 1a5edec | 2020-06-12 17:56:57 | [diff] [blame] | 4138 | |
Ken Rockot | 4408a0f | 2020-07-27 19:40:54 | [diff] [blame] | 4139 | if (IsErrorPageAutoReloadEnabled() && handle->IsInMainFrame()) { |
| 4140 | MaybeAddThrottle( |
| 4141 | error_page::NetErrorAutoReloader::MaybeCreateThrottleFor(handle), |
| 4142 | &throttles); |
| 4143 | } |
| 4144 | |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 4145 | return throttles; |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4146 | } |
| 4147 | |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 4148 | std::unique_ptr<content::NavigationUIData> |
| 4149 | ChromeContentBrowserClient::GetNavigationUIData( |
| 4150 | content::NavigationHandle* navigation_handle) { |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4151 | return std::make_unique<ChromeNavigationUIData>(navigation_handle); |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 4152 | } |
| 4153 | |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4154 | void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps( |
| 4155 | const std::string& key_system, |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4156 | base::flat_set<media::VideoCodec>* video_codecs, |
Yuchen Liu | b33bfc1 | 2019-11-08 20:16:12 | [diff] [blame] | 4157 | base::flat_set<media::EncryptionScheme>* encryption_schemes) { |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4158 | #if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \ |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 4159 | BUILDFLAG(ENABLE_WIDEVINE) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4160 | if (key_system == kWidevineKeySystem) { |
Xiaohan Wang | fd9e354 | 2020-04-14 00:39:33 | [diff] [blame] | 4161 | GetWidevineHardwareCaps(video_codecs, encryption_schemes); |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4162 | } |
| 4163 | #endif |
| 4164 | } |
| 4165 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4166 | content::DevToolsManagerDelegate* |
| 4167 | ChromeContentBrowserClient::GetDevToolsManagerDelegate() { |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 4168 | #if defined(OS_ANDROID) |
| 4169 | return new DevToolsManagerDelegateAndroid(); |
| 4170 | #else |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4171 | return new ChromeDevToolsManagerDelegate(); |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 4172 | #endif |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4173 | } |
| 4174 | |
Rayan Kanso | 411e84e | 2019-02-13 15:27:40 | [diff] [blame] | 4175 | void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration( |
| 4176 | content::BrowserContext* browser_context, |
| 4177 | int service, |
| 4178 | base::Time expiration_time) { |
| 4179 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4180 | DCHECK(profile); |
| 4181 | |
| 4182 | auto* pref_service = profile->GetPrefs(); |
| 4183 | DCHECK(pref_service); |
| 4184 | |
| 4185 | DictionaryPrefUpdate pref_update( |
| 4186 | pref_service, prefs::kDevToolsBackgroundServicesExpirationDict); |
| 4187 | base::DictionaryValue* exp_dict = pref_update.Get(); |
| 4188 | |
| 4189 | // Convert |expiration_time| to minutes since that is the most granular |
| 4190 | // option that returns an int. base::Value does not accept int64. |
| 4191 | int expiration_time_minutes = |
| 4192 | expiration_time.ToDeltaSinceWindowsEpoch().InMinutes(); |
| 4193 | exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes); |
| 4194 | } |
| 4195 | |
| 4196 | base::flat_map<int, base::Time> |
| 4197 | ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations( |
| 4198 | content::BrowserContext* browser_context) { |
| 4199 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4200 | DCHECK(profile); |
| 4201 | |
| 4202 | auto* pref_service = profile->GetPrefs(); |
| 4203 | DCHECK(pref_service); |
| 4204 | |
| 4205 | auto* expiration_dict = pref_service->GetDictionary( |
| 4206 | prefs::kDevToolsBackgroundServicesExpirationDict); |
| 4207 | DCHECK(expiration_dict); |
| 4208 | |
| 4209 | base::flat_map<int, base::Time> expiration_times; |
| 4210 | for (const auto& it : *expiration_dict) { |
| 4211 | // key. |
| 4212 | int service = 0; |
| 4213 | bool did_convert = base::StringToInt(it.first, &service); |
| 4214 | DCHECK(did_convert); |
| 4215 | |
| 4216 | // value. |
| 4217 | DCHECK(it.second->is_int()); |
| 4218 | base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt()); |
| 4219 | base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta); |
| 4220 | |
| 4221 | expiration_times[service] = expiration_time; |
| 4222 | } |
| 4223 | |
| 4224 | return expiration_times; |
| 4225 | } |
| 4226 | |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4227 | content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() { |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4228 | return new ChromeTracingDelegate(); |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4229 | } |
| 4230 | |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 4231 | bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle( |
| 4232 | content::BrowserContext* browser_context, |
| 4233 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4234 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 4235 | return ChromeContentBrowserClientPluginsPart:: |
Lei Zhang | 19736cde | 2020-02-07 18:51:19 | [diff] [blame] | 4236 | IsPluginAllowedToCallRequestOSFileHandle(browser_context, url); |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 4237 | #else |
| 4238 | return false; |
| 4239 | #endif |
| 4240 | } |
| 4241 | |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 4242 | bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs( |
| 4243 | content::BrowserContext* browser_context, |
| 4244 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4245 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 4246 | return ChromeContentBrowserClientPluginsPart:: |
Lei Zhang | 19736cde | 2020-02-07 18:51:19 | [diff] [blame] | 4247 | IsPluginAllowedToUseDevChannelAPIs(browser_context, url); |
[email protected] | 8ddc6b7c | 2013-12-12 20:42:06 | [diff] [blame] | 4248 | #else |
| 4249 | return false; |
| 4250 | #endif |
| 4251 | } |
| 4252 | |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4253 | void ChromeContentBrowserClient::OverridePageVisibilityState( |
xzhan96 | cf0a3c54 | 2017-11-17 04:33:01 | [diff] [blame] | 4254 | RenderFrameHost* render_frame_host, |
danakj | 0018a29a | 2018-12-01 01:03:43 | [diff] [blame] | 4255 | content::PageVisibilityState* visibility_state) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 4256 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4257 | |
| 4258 | WebContents* web_contents = |
| 4259 | WebContents::FromRenderFrameHost(render_frame_host); |
| 4260 | DCHECK(web_contents); |
| 4261 | |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4262 | prerender::PrerenderManager* prerender_manager = |
droger | c154315 | 2016-09-20 13:03:37 | [diff] [blame] | 4263 | prerender::PrerenderManagerFactory::GetForBrowserContext( |
| 4264 | web_contents->GetBrowserContext()); |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4265 | if (prerender_manager && |
| 4266 | prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) { |
Collin Baker | 98457b5 | 2019-11-06 21:34:29 | [diff] [blame] | 4267 | *visibility_state = content::PageVisibilityState::kHiddenButPainting; |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4268 | } |
| 4269 | } |
| 4270 | |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 4271 | void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() { |
| 4272 | base::FilePath user_data_dir; |
| 4273 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 4274 | DCHECK(!user_data_dir.empty()); |
| 4275 | network_contexts_parent_directory_.push_back(user_data_dir); |
| 4276 | |
| 4277 | base::FilePath cache_dir; |
| 4278 | chrome::GetUserCacheDirectory(user_data_dir, &cache_dir); |
| 4279 | DCHECK(!cache_dir.empty()); |
| 4280 | // On some platforms, the cache is a child of the user_data_dir so only |
| 4281 | // return the one path. |
| 4282 | if (!user_data_dir.IsParent(cache_dir)) |
| 4283 | network_contexts_parent_directory_.push_back(cache_dir); |
| 4284 | |
| 4285 | // If the cache location has been overridden by a switch or preference, |
| 4286 | // include that as well. |
| 4287 | if (auto* local_state = g_browser_process->local_state()) { |
| 4288 | base::FilePath pref_cache_dir = |
| 4289 | local_state->GetFilePath(prefs::kDiskCacheDir); |
| 4290 | if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir)) |
| 4291 | network_contexts_parent_directory_.push_back(pref_cache_dir); |
| 4292 | } |
| 4293 | } |
| 4294 | |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4295 | void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 4296 | base::CommandLine* to_command_line, |
| 4297 | const base::CommandLine& from_command_line, |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4298 | version_info::Channel channel) { |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4299 | #if defined(OS_ANDROID) |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4300 | const version_info::Channel kMaxDisableEncryptionChannel = |
| 4301 | version_info::Channel::BETA; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4302 | #else |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4303 | const version_info::Channel kMaxDisableEncryptionChannel = |
| 4304 | version_info::Channel::DEV; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4305 | #endif |
| 4306 | if (channel <= kMaxDisableEncryptionChannel) { |
| 4307 | static const char* const kWebRtcDevSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 4308 | switches::kDisableWebRtcEncryption, |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4309 | }; |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 4310 | to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames, |
| 4311 | base::size(kWebRtcDevSwitchNames)); |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4312 | } |
| 4313 | } |
bashi | 93362955 | 2016-10-13 23:32:40 | [diff] [blame] | 4314 | |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4315 | #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 4316 | void ChromeContentBrowserClient::CreateMediaRemoter( |
| 4317 | content::RenderFrameHost* render_frame_host, |
Gyuyoung Kim | a4f9f94 | 2019-10-26 02:55:50 | [diff] [blame] | 4318 | mojo::PendingRemote<media::mojom::RemotingSource> source, |
| 4319 | mojo::PendingReceiver<media::mojom::Remoter> receiver) { |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4320 | CastRemotingConnector::CreateMediaRemoter( |
Gyuyoung Kim | a4f9f94 | 2019-10-26 02:55:50 | [diff] [blame] | 4321 | render_frame_host, std::move(source), std::move(receiver)); |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4322 | } |
| 4323 | #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING) |
robliao | bf5a32e | 2016-12-09 03:35:46 | [diff] [blame] | 4324 | |
Michael Giuffrida | 6802ffe | 2017-09-29 03:40:25 | [diff] [blame] | 4325 | base::FilePath ChromeContentBrowserClient::GetLoggingFileName( |
| 4326 | const base::CommandLine& command_line) { |
| 4327 | return logging::GetLogFileName(command_line); |
kerrnel | a67fad5 | 2017-06-14 20:18:16 | [diff] [blame] | 4328 | } |
| 4329 | |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4330 | namespace { |
| 4331 | // TODO(jam): move this to a separate file. |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4332 | class ProtocolHandlerThrottle : public blink::URLLoaderThrottle { |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4333 | public: |
| 4334 | explicit ProtocolHandlerThrottle( |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4335 | ProtocolHandlerRegistry* protocol_handler_registry) |
Matt Falkenhagen | 7811fd4 | 2020-06-24 22:42:41 | [diff] [blame] | 4336 | : protocol_handler_registry_(protocol_handler_registry) { |
| 4337 | DCHECK(protocol_handler_registry); |
| 4338 | } |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4339 | ~ProtocolHandlerThrottle() override = default; |
| 4340 | |
| 4341 | void WillStartRequest(network::ResourceRequest* request, |
| 4342 | bool* defer) override { |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4343 | TranslateUrl(&request->url); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4344 | } |
| 4345 | |
Takashi Toyoshima | eb2ba20c5 | 2020-04-27 16:34:58 | [diff] [blame] | 4346 | void WillRedirectRequest( |
| 4347 | net::RedirectInfo* redirect_info, |
| 4348 | const network::mojom::URLResponseHead& response_head, |
| 4349 | bool* defer, |
| 4350 | std::vector<std::string>* to_be_removed_headers, |
| 4351 | net::HttpRequestHeaders* modified_headers, |
| 4352 | net::HttpRequestHeaders* modified_cors_exempt_headers) override { |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4353 | TranslateUrl(&redirect_info->new_url); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | private: |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4357 | void TranslateUrl(GURL* url) { |
| 4358 | if (!protocol_handler_registry_->IsHandledProtocol(url->scheme())) |
| 4359 | return; |
| 4360 | GURL translated_url = protocol_handler_registry_->Translate(*url); |
| 4361 | if (!translated_url.is_empty()) |
| 4362 | *url = translated_url; |
| 4363 | } |
| 4364 | |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4365 | ProtocolHandlerRegistry* protocol_handler_registry_; |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4366 | }; |
| 4367 | } // namespace |
| 4368 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4369 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4370 | ChromeContentBrowserClient::CreateURLLoaderThrottles( |
| 4371 | const network::ResourceRequest& request, |
| 4372 | content::BrowserContext* browser_context, |
| 4373 | const base::RepeatingCallback<content::WebContents*()>& wc_getter, |
| 4374 | content::NavigationUIData* navigation_ui_data, |
| 4375 | int frame_tree_node_id) { |
| 4376 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 4377 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4378 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result; |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4379 | |
Matt Falkenhagen | 7811fd4 | 2020-06-24 22:42:41 | [diff] [blame] | 4380 | DCHECK(browser_context); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4381 | Profile* profile = Profile::FromBrowserContext(browser_context); |
Matt Falkenhagen | 7811fd4 | 2020-06-24 22:42:41 | [diff] [blame] | 4382 | DCHECK(profile); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4383 | |
| 4384 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4385 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4386 | |
Bettina | fd0c110 | 2020-08-06 00:23:43 | [diff] [blame] | 4387 | #if BUILDFLAG(SAFE_BROWSING_AVAILABLE) |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4388 | bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy( |
| 4389 | request.url, *profile->GetPrefs()); |
| 4390 | if (!matches_enterprise_whitelist) { |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 4391 | bool is_enterprise_lookup_enabled = |
Xinghui Lu | f45d7ef7 | 2020-06-09 02:16:38 | [diff] [blame] | 4392 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 4393 | safe_browsing::RealTimePolicyEngine::CanPerformEnterpriseFullURLLookup( |
Xinghui Lu | d9358809 | 2020-06-29 20:18:24 | [diff] [blame] | 4394 | profile->GetPrefs(), safe_browsing::GetDMToken(profile).is_valid(), |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 4395 | profile->IsOffTheRecord()); |
| 4396 | #else |
| 4397 | false; |
Xinghui Lu | f45d7ef7 | 2020-06-09 02:16:38 | [diff] [blame] | 4398 | #endif |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 4399 | bool is_consumer_lookup_enabled = |
Xinghui Lu | f45d7ef7 | 2020-06-09 02:16:38 | [diff] [blame] | 4400 | safe_browsing::RealTimePolicyEngine::CanPerformFullURLLookup( |
| 4401 | profile->GetPrefs(), profile->IsOffTheRecord(), |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 4402 | g_browser_process->variations_service()); |
| 4403 | |
| 4404 | // |url_lookup_service| is used when real time url check is enabled. |
| 4405 | safe_browsing::RealTimeUrlLookupServiceBase* url_lookup_service = |
| 4406 | GetUrlLookupService(browser_context, is_enterprise_lookup_enabled, |
| 4407 | is_consumer_lookup_enabled); |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4408 | result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create( |
| 4409 | base::BindOnce( |
| 4410 | &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate, |
Matt Menke | 562675cfe | 2020-01-07 15:50:53 | [diff] [blame] | 4411 | base::Unretained(this), |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 4412 | safe_browsing::IsSafeBrowsingEnabled(*profile->GetPrefs()), |
| 4413 | // Should check for enterprise when safe browsing is disabled. |
| 4414 | /*should_check_on_sb_disabled=*/is_enterprise_lookup_enabled), |
Xinghui Lu | a142c10 | 2020-03-02 20:50:08 | [diff] [blame] | 4415 | wc_getter, frame_tree_node_id, |
Xinghui Lu | e17b1994 | 2020-02-24 21:19:58 | [diff] [blame] | 4416 | url_lookup_service ? url_lookup_service->GetWeakPtr() : nullptr)); |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4417 | } |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4418 | #endif |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4419 | |
dalyk | ba7bbfc | 2019-12-18 19:59:21 | [diff] [blame] | 4420 | #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 4421 | result.push_back( |
Colin Blundell | 27331f9 | 2020-02-05 21:13:01 | [diff] [blame] | 4422 | std::make_unique<captive_portal::CaptivePortalURLLoaderThrottle>( |
| 4423 | wc_getter.Run())); |
dalyk | ba7bbfc | 2019-12-18 19:59:21 | [diff] [blame] | 4424 | #endif |
| 4425 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4426 | if (chrome_navigation_ui_data && |
Miyoung Shin | f53c2e79 | 2020-06-19 03:20:25 | [diff] [blame] | 4427 | chrome_navigation_ui_data->prerender_mode() != |
| 4428 | prerender::mojom::PrerenderMode::kNoPrerender) { |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4429 | result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>( |
| 4430 | chrome_navigation_ui_data->prerender_mode(), |
| 4431 | chrome_navigation_ui_data->prerender_histogram_prefix(), |
Darin Fisher | e41aab5 | 2020-01-29 18:31:23 | [diff] [blame] | 4432 | GetPrerenderCanceler(wc_getter))); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4433 | } |
| 4434 | |
John Abd-El-Malek | 4f380d9 | 2020-02-19 16:43:36 | [diff] [blame] | 4435 | #if defined(OS_ANDROID) |
| 4436 | std::string client_data_header; |
Brandon Wylie | 21a88ac9 | 2020-05-15 02:49:23 | [diff] [blame] | 4437 | bool night_mode_enabled = false; |
John Abd-El-Malek | fb9f546 | 2020-02-20 01:18:37 | [diff] [blame] | 4438 | if (frame_tree_node_id != content::RenderFrameHost::kNoFrameTreeNodeId) { |
| 4439 | auto* web_contents = WebContents::FromFrameTreeNodeId(frame_tree_node_id); |
John Abd-El-Malek | 2ea0554 | 2020-03-04 00:03:36 | [diff] [blame] | 4440 | // Could be null if the FrameTreeNode's RenderFrameHost is shutting down. |
| 4441 | if (web_contents) { |
| 4442 | auto* client_data_header_observer = |
| 4443 | customtabs::ClientDataHeaderWebContentsObserver::FromWebContents( |
| 4444 | web_contents); |
| 4445 | if (client_data_header_observer) |
| 4446 | client_data_header = client_data_header_observer->header(); |
Brandon Wylie | 21a88ac9 | 2020-05-15 02:49:23 | [diff] [blame] | 4447 | |
Brandon Wylie | f6bfdab | 2020-08-12 21:49:36 | [diff] [blame^] | 4448 | auto* delegate = |
| 4449 | TabAndroid::FromWebContents(web_contents) |
| 4450 | ? static_cast<android::TabWebContentsDelegateAndroid*>( |
| 4451 | web_contents->GetDelegate()) |
| 4452 | : nullptr; |
| 4453 | if (delegate) |
| 4454 | night_mode_enabled = delegate->IsNightModeEnabled(); |
Brandon Wylie | 21a88ac9 | 2020-05-15 02:49:23 | [diff] [blame] | 4455 | } |
John Abd-El-Malek | fb9f546 | 2020-02-20 01:18:37 | [diff] [blame] | 4456 | } |
John Abd-El-Malek | 4f380d9 | 2020-02-19 16:43:36 | [diff] [blame] | 4457 | #endif |
| 4458 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4459 | chrome::mojom::DynamicParams dynamic_params = { |
| 4460 | profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch), |
| 4461 | profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict), |
Alex Clarke | 3ebd977 | 2020-02-28 10:50:27 | [diff] [blame] | 4462 | profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps)}; |
| 4463 | result.push_back(std::make_unique<GoogleURLLoaderThrottle>( |
John Abd-El-Malek | 4f380d9 | 2020-02-19 16:43:36 | [diff] [blame] | 4464 | #if defined(OS_ANDROID) |
Brandon Wylie | 21a88ac9 | 2020-05-15 02:49:23 | [diff] [blame] | 4465 | client_data_header, night_mode_enabled, |
John Abd-El-Malek | 4f380d9 | 2020-02-19 16:43:36 | [diff] [blame] | 4466 | #endif |
Alex Clarke | 3ebd977 | 2020-02-28 10:50:27 | [diff] [blame] | 4467 | std::move(dynamic_params))); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4468 | |
Matt Falkenhagen | 7811fd4 | 2020-06-24 22:42:41 | [diff] [blame] | 4469 | { |
| 4470 | auto* factory = |
| 4471 | ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context); |
| 4472 | // null in unit tests. |
| 4473 | if (factory) |
| 4474 | result.push_back(std::make_unique<ProtocolHandlerThrottle>(factory)); |
| 4475 | } |
Clark DuVall | 8512cee6 | 2019-06-26 01:14:21 | [diff] [blame] | 4476 | |
Clark DuVall | 39c2cfc | 2019-06-25 21:49:28 | [diff] [blame] | 4477 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 4478 | result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>( |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 4479 | request.resource_type, frame_tree_node_id)); |
Clark DuVall | 39c2cfc | 2019-06-25 21:49:28 | [diff] [blame] | 4480 | #endif |
| 4481 | |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 4482 | auto delegate = |
Robbie McElrath | 38f47af | 2019-09-19 21:51:40 | [diff] [blame] | 4483 | std::make_unique<signin::HeaderModificationDelegateImpl>(profile); |
David Roger | 615cb9f0 | 2020-01-30 12:06:58 | [diff] [blame] | 4484 | auto signin_throttle = |
| 4485 | signin::URLLoaderThrottle::MaybeCreate(std::move(delegate), wc_getter); |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 4486 | if (signin_throttle) |
| 4487 | result.push_back(std::move(signin_throttle)); |
| 4488 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4489 | return result; |
| 4490 | } |
| 4491 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4492 | void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4493 | int frame_tree_node_id, |
Maks Orlovich | 5408ddfc | 2020-07-28 23:07:35 | [diff] [blame] | 4494 | base::UkmSourceId ukm_source_id, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4495 | NonNetworkURLLoaderFactoryMap* factories) { |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4496 | #if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4497 | content::WebContents* web_contents = |
| 4498 | content::WebContents::FromFrameTreeNodeId(frame_tree_node_id); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4499 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4500 | factories->emplace( |
| 4501 | extensions::kExtensionScheme, |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 4502 | extensions::CreateExtensionNavigationURLLoaderFactory( |
Maks Orlovich | 5408ddfc | 2020-07-28 23:07:35 | [diff] [blame] | 4503 | web_contents->GetBrowserContext(), ukm_source_id, |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4504 | !!extensions::WebViewGuest::FromWebContents(web_contents))); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4505 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 4506 | #if defined(OS_CHROMEOS) |
| 4507 | Profile* profile = |
| 4508 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Robbie McElrath | 89cc933 | 2019-03-05 02:12:30 | [diff] [blame] | 4509 | factories->emplace(content::kExternalFileScheme, |
| 4510 | std::make_unique<chromeos::ExternalFileURLLoaderFactory>( |
| 4511 | profile, content::ChildProcessHost::kInvalidUniqueID)); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4512 | #endif // defined(OS_CHROMEOS) |
| 4513 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4514 | } |
| 4515 | |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4516 | void ChromeContentBrowserClient:: |
Hiroki Nakagawa | 1efa31d | 2019-10-01 22:36:34 | [diff] [blame] | 4517 | RegisterNonNetworkWorkerMainResourceURLLoaderFactories( |
| 4518 | content::BrowserContext* browser_context, |
| 4519 | NonNetworkURLLoaderFactoryMap* factories) { |
| 4520 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4521 | DCHECK(browser_context); |
| 4522 | DCHECK(factories); |
| 4523 | factories->emplace( |
| 4524 | extensions::kExtensionScheme, |
| 4525 | extensions::CreateExtensionWorkerMainResourceURLLoaderFactory( |
| 4526 | browser_context)); |
| 4527 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 4528 | } |
| 4529 | |
| 4530 | void ChromeContentBrowserClient:: |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4531 | RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories( |
| 4532 | content::BrowserContext* browser_context, |
| 4533 | NonNetworkURLLoaderFactoryMap* factories) { |
Hiroki Nakagawa | d5e7e89d8 | 2019-09-11 09:42:11 | [diff] [blame] | 4534 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4535 | DCHECK(browser_context); |
| 4536 | DCHECK(factories); |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4537 | factories->emplace( |
| 4538 | extensions::kExtensionScheme, |
| 4539 | extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory( |
| 4540 | browser_context)); |
| 4541 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4542 | } |
| 4543 | |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4544 | namespace { |
| 4545 | |
| 4546 | // The FileURLLoaderFactory provided to the extension background pages. |
| 4547 | // Checks with the ChildProcessSecurityPolicy to validate the file access. |
| 4548 | class FileURLLoaderFactory : public network::mojom::URLLoaderFactory { |
| 4549 | public: |
| 4550 | explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {} |
| 4551 | |
| 4552 | private: |
| 4553 | // network::mojom::URLLoaderFactory: |
Julie Jeongeun Kim | e003de5 | 2019-10-29 05:14:27 | [diff] [blame] | 4554 | void CreateLoaderAndStart( |
| 4555 | mojo::PendingReceiver<network::mojom::URLLoader> loader, |
| 4556 | int32_t routing_id, |
| 4557 | int32_t request_id, |
| 4558 | uint32_t options, |
| 4559 | const network::ResourceRequest& request, |
Julie Jeongeun Kim | 6dd4c7b | 2019-11-18 05:56:30 | [diff] [blame] | 4560 | mojo::PendingRemote<network::mojom::URLLoaderClient> client, |
Julie Jeongeun Kim | e003de5 | 2019-10-29 05:14:27 | [diff] [blame] | 4561 | const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) |
| 4562 | override { |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4563 | if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL( |
| 4564 | child_id_, request.url)) { |
Julie Jeongeun Kim | 6dd4c7b | 2019-11-18 05:56:30 | [diff] [blame] | 4565 | mojo::Remote<network::mojom::URLLoaderClient>(std::move(client)) |
| 4566 | ->OnComplete( |
| 4567 | network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED)); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4568 | return; |
| 4569 | } |
Yutaka Hirano | df83dca4 | 2020-01-07 06:24:55 | [diff] [blame] | 4570 | content::CreateFileURLLoaderBypassingSecurityChecks( |
| 4571 | request, std::move(loader), std::move(client), |
| 4572 | /*observer=*/nullptr, |
| 4573 | /* allow_directory_listing */ true); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4574 | } |
| 4575 | |
Julie Jeongeun Kim | 7f8e26a2 | 2019-10-10 12:09:52 | [diff] [blame] | 4576 | void Clone( |
| 4577 | mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader) override { |
| 4578 | receivers_.Add(this, std::move(loader)); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4579 | } |
| 4580 | |
| 4581 | int child_id_; |
Julie Jeongeun Kim | 7f8e26a2 | 2019-10-10 12:09:52 | [diff] [blame] | 4582 | mojo::ReceiverSet<network::mojom::URLLoaderFactory> receivers_; |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4583 | DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory); |
| 4584 | }; |
| 4585 | |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 4586 | #if defined(OS_CHROMEOS) |
| 4587 | bool IsSystemFeatureDisabled(policy::SystemFeature system_feature) { |
| 4588 | PrefService* const local_state = g_browser_process->local_state(); |
| 4589 | if (!local_state) // Sometimes it's not available in tests. |
| 4590 | return false; |
| 4591 | |
| 4592 | const base::ListValue* disabled_system_features_pref = |
| 4593 | local_state->GetList(policy::policy_prefs::kSystemFeaturesDisableList); |
| 4594 | if (!disabled_system_features_pref) |
| 4595 | return false; |
| 4596 | |
| 4597 | const auto disabled_system_features = |
| 4598 | disabled_system_features_pref->GetList(); |
| 4599 | return base::Contains(disabled_system_features, base::Value(system_feature)); |
| 4600 | } |
| 4601 | |
| 4602 | bool IsSystemFeatureURLDisabled(const GURL& url) { |
| 4603 | if (!url.SchemeIs(content::kChromeUIScheme)) |
| 4604 | return false; |
| 4605 | |
| 4606 | // chrome://os-settings/pwa.html shouldn't be replaced to let the settings app |
| 4607 | // installation complete successfully. |
| 4608 | if (url.DomainIs(chrome::kChromeUIOSSettingsHost) && |
| 4609 | url.path() != "/pwa.html" && |
| 4610 | IsSystemFeatureDisabled(policy::SystemFeature::OS_SETTINGS)) { |
| 4611 | return true; |
| 4612 | } |
| 4613 | |
| 4614 | if (url.DomainIs(chrome::kChromeUISettingsHost) && |
| 4615 | IsSystemFeatureDisabled(policy::SystemFeature::BROWSER_SETTINGS)) { |
| 4616 | return true; |
| 4617 | } |
| 4618 | |
| 4619 | return false; |
| 4620 | } |
| 4621 | #endif |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4622 | } // namespace |
| 4623 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4624 | void ChromeContentBrowserClient:: |
| 4625 | RegisterNonNetworkSubresourceURLLoaderFactories( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4626 | int render_process_id, |
| 4627 | int render_frame_id, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4628 | NonNetworkURLLoaderFactoryMap* factories) { |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4629 | #if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS) |
| 4630 | content::RenderFrameHost* frame_host = |
| 4631 | RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 4632 | WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host); |
| 4633 | #endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS) |
| 4634 | |
| 4635 | #if defined(OS_CHROMEOS) |
| 4636 | if (web_contents) { |
| 4637 | Profile* profile = |
| 4638 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Robbie McElrath | 89cc933 | 2019-03-05 02:12:30 | [diff] [blame] | 4639 | factories->emplace(content::kExternalFileScheme, |
| 4640 | std::make_unique<chromeos::ExternalFileURLLoaderFactory>( |
| 4641 | profile, render_process_id)); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4642 | } |
| 4643 | #endif // defined(OS_CHROMEOS) |
| 4644 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4645 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4646 | auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id, |
| 4647 | render_frame_id); |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4648 | if (factory) |
| 4649 | factories->emplace(extensions::kExtensionScheme, std::move(factory)); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4650 | |
| 4651 | // This logic should match |
| 4652 | // ChromeExtensionWebContentsObserver::RenderFrameCreated. |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4653 | if (!web_contents) |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4654 | return; |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4655 | |
| 4656 | Profile* profile = |
| 4657 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 4658 | InstantService* instant_service = |
| 4659 | InstantServiceFactory::GetForProfile(profile); |
| 4660 | // The test below matches what's done by ShouldServiceRequestIOThread in |
| 4661 | // local_ntp_source.cc. |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4662 | if (instant_service->IsInstantProcess(render_process_id)) { |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4663 | factories->emplace( |
| 4664 | chrome::kChromeSearchScheme, |
| 4665 | content::CreateWebUIURLLoader( |
| 4666 | frame_host, chrome::kChromeSearchScheme, |
| 4667 | /*allowed_webui_hosts=*/base::flat_set<std::string>())); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4668 | } |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4669 | |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4670 | extensions::ChromeExtensionWebContentsObserver* web_observer = |
| 4671 | extensions::ChromeExtensionWebContentsObserver::FromWebContents( |
| 4672 | web_contents); |
| 4673 | |
Karan Bhatia | 9192857 | 2018-03-06 01:18:07 | [diff] [blame] | 4674 | // There is nothing to do if no ChromeExtensionWebContentsObserver is attached |
| 4675 | // to the |web_contents|. |
| 4676 | if (!web_observer) |
| 4677 | return; |
| 4678 | |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4679 | const Extension* extension = |
| 4680 | web_observer->GetExtensionFromFrame(frame_host, false); |
| 4681 | if (!extension) |
| 4682 | return; |
| 4683 | |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4684 | std::vector<std::string> allowed_webui_hosts; |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4685 | // Support for chrome:// scheme if appropriate. |
| 4686 | if ((extension->is_extension() || extension->is_platform_app()) && |
| 4687 | Manifest::IsComponentLocation(extension->location())) { |
| 4688 | // Components of chrome that are implemented as extensions or platform apps |
| 4689 | // are allowed to use chrome://resources/ and chrome://theme/ URLs. |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4690 | allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost); |
| 4691 | allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost); |
| 4692 | } |
| 4693 | if (extension->is_extension() || extension->is_legacy_packaged_app() || |
| 4694 | (extension->is_platform_app() && |
| 4695 | Manifest::IsComponentLocation(extension->location()))) { |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4696 | // Extensions, legacy packaged apps, and component platform apps are allowed |
Lucas Tenório | 3dd8092 | 2019-03-27 03:51:02 | [diff] [blame] | 4697 | // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon |
| 4698 | // URLs. Hosted apps are not allowed because they are served via web servers |
| 4699 | // (and are generally never given access to Chrome APIs). |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4700 | allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost); |
| 4701 | allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost); |
Lucas Tenório | 3dd8092 | 2019-03-27 03:51:02 | [diff] [blame] | 4702 | allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost); |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4703 | } |
| 4704 | if (!allowed_webui_hosts.empty()) { |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4705 | factories->emplace( |
| 4706 | content::kChromeUIScheme, |
| 4707 | content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme, |
| 4708 | std::move(allowed_webui_hosts))); |
| 4709 | } |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4710 | |
| 4711 | // Extension with a background page get file access that gets approval from |
| 4712 | // ChildProcessSecurityPolicy. |
| 4713 | extensions::ExtensionHost* host = |
| 4714 | extensions::ProcessManager::Get(web_contents->GetBrowserContext()) |
| 4715 | ->GetBackgroundHostForExtension(extension->id()); |
| 4716 | if (host) { |
| 4717 | factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>( |
| 4718 | render_process_id)); |
| 4719 | } |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4720 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4721 | } |
| 4722 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4723 | bool ChromeContentBrowserClient::WillCreateURLLoaderFactory( |
Ken Rockot | 428b1d6 | 2018-06-06 17:12:21 | [diff] [blame] | 4724 | content::BrowserContext* browser_context, |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4725 | content::RenderFrameHost* frame, |
Kenichi Ishibashi | 09ee5e7 | 2018-11-27 07:12:38 | [diff] [blame] | 4726 | int render_process_id, |
Karan Bhatia | 4a834b3 | 2019-08-16 22:26:44 | [diff] [blame] | 4727 | URLLoaderFactoryType type, |
Lukasz Anforowicz | 76273365 | 2018-09-28 14:48:26 | [diff] [blame] | 4728 | const url::Origin& request_initiator, |
Karan Bhatia | 303d0ac0 | 2019-12-05 03:01:00 | [diff] [blame] | 4729 | base::Optional<int64_t> navigation_id, |
Dominic Farolino | 1be897a | 2019-07-20 08:11:42 | [diff] [blame] | 4730 | mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver, |
Julie Jeongeun Kim | 47499a0c | 2019-08-28 07:23:18 | [diff] [blame] | 4731 | mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>* |
| 4732 | header_client, |
Yutaka Hirano | 499d1321 | 2019-12-04 11:03:33 | [diff] [blame] | 4733 | bool* bypass_redirect_checks, |
dalyk | 0018c16f | 2020-01-08 20:20:08 | [diff] [blame] | 4734 | bool* disable_secure_dns, |
Yutaka Hirano | 499d1321 | 2019-12-04 11:03:33 | [diff] [blame] | 4735 | network::mojom::URLLoaderFactoryOverridePtr* factory_override) { |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4736 | bool use_proxy = false; |
| 4737 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4738 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4739 | auto* web_request_api = |
| 4740 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
Ken Rockot | 428b1d6 | 2018-06-06 17:12:21 | [diff] [blame] | 4741 | browser_context); |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4742 | |
| 4743 | // NOTE: Some unit test environments do not initialize |
| 4744 | // BrowserContextKeyedAPI factories for e.g. WebRequest. |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4745 | if (web_request_api) { |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4746 | bool use_proxy_for_web_request = |
Kenichi Ishibashi | 09ee5e7 | 2018-11-27 07:12:38 | [diff] [blame] | 4747 | web_request_api->MaybeProxyURLLoaderFactory( |
Karan Bhatia | 303d0ac0 | 2019-12-05 03:01:00 | [diff] [blame] | 4748 | browser_context, frame, render_process_id, type, |
| 4749 | std::move(navigation_id), factory_receiver, header_client); |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4750 | if (bypass_redirect_checks) |
| 4751 | *bypass_redirect_checks = use_proxy_for_web_request; |
| 4752 | use_proxy |= use_proxy_for_web_request; |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4753 | } |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4754 | #endif |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4755 | |
Reilly Grant | cc22e60 | 2018-09-07 15:25:20 | [diff] [blame] | 4756 | use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest( |
Karan Bhatia | 4a834b3 | 2019-08-16 22:26:44 | [diff] [blame] | 4757 | frame, type == URLLoaderFactoryType::kNavigation, request_initiator, |
| 4758 | factory_receiver); |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4759 | |
Robert Ogden | 31b23471 | 2020-06-04 22:51:21 | [diff] [blame] | 4760 | auto* isolated_prerender_service = |
| 4761 | IsolatedPrerenderServiceFactory::GetForProfile( |
| 4762 | Profile::FromBrowserContext(browser_context)); |
| 4763 | // |frame| is null when |type| is service worker. |
| 4764 | if (frame && isolated_prerender_service) { |
| 4765 | use_proxy |= isolated_prerender_service->MaybeProxyURLLoaderFactory( |
Robert Ogden | 8c53bc5 | 2020-06-19 21:24:18 | [diff] [blame] | 4766 | frame, render_process_id, type, factory_receiver); |
Robert Ogden | 31b23471 | 2020-06-04 22:51:21 | [diff] [blame] | 4767 | } |
| 4768 | |
dalyk | 0018c16f | 2020-01-08 20:20:08 | [diff] [blame] | 4769 | #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
| 4770 | if (disable_secure_dns) { |
| 4771 | WebContents* web_contents = WebContents::FromRenderFrameHost(frame); |
| 4772 | *disable_secure_dns = |
Colin Blundell | 27331f9 | 2020-02-05 21:13:01 | [diff] [blame] | 4773 | web_contents && |
| 4774 | captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) && |
| 4775 | captive_portal::CaptivePortalTabHelper::FromWebContents(web_contents) |
dalyk | 0018c16f | 2020-01-08 20:20:08 | [diff] [blame] | 4776 | ->is_captive_portal_window(); |
| 4777 | } |
| 4778 | #endif |
| 4779 | |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4780 | return use_proxy; |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4781 | } |
| 4782 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4783 | std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> |
| 4784 | ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors( |
| 4785 | content::NavigationUIData* navigation_ui_data, |
Ryan Sturm | 27d93f41 | 2019-02-15 21:30:14 | [diff] [blame] | 4786 | int frame_tree_node_id, |
| 4787 | const scoped_refptr<network::SharedURLLoaderFactory>& |
| 4788 | network_loader_factory) { |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4789 | std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> |
| 4790 | interceptors; |
| 4791 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 4792 | interceptors.push_back( |
| 4793 | std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>( |
| 4794 | navigation_ui_data, frame_tree_node_id)); |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4795 | #endif |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 4796 | |
Robert Ogden | 6946ad4 | 2020-01-13 18:01:30 | [diff] [blame] | 4797 | if (base::FeatureList::IsEnabled(features::kIsolatePrerenders)) { |
| 4798 | interceptors.push_back( |
| 4799 | std::make_unique<IsolatedPrerenderURLLoaderInterceptor>( |
| 4800 | frame_tree_node_id)); |
| 4801 | } |
| 4802 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4803 | return interceptors; |
| 4804 | } |
| 4805 | |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4806 | bool ChromeContentBrowserClient::WillInterceptWebSocket( |
| 4807 | content::RenderFrameHost* frame) { |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4808 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4809 | if (!frame) { |
| 4810 | return false; |
| 4811 | } |
| 4812 | const auto* web_request_api = |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4813 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
| 4814 | frame->GetProcess()->GetBrowserContext()); |
| 4815 | |
| 4816 | // NOTE: Some unit test environments do not initialize |
| 4817 | // BrowserContextKeyedAPI factories for e.g. WebRequest. |
| 4818 | if (!web_request_api) |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4819 | return false; |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4820 | |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4821 | return web_request_api->MayHaveProxies(); |
| 4822 | #else |
| 4823 | return false; |
| 4824 | #endif |
| 4825 | } |
| 4826 | |
| 4827 | void ChromeContentBrowserClient::CreateWebSocket( |
| 4828 | content::RenderFrameHost* frame, |
| 4829 | WebSocketFactory factory, |
| 4830 | const GURL& url, |
Maks Orlovich | ab27e24 | 2020-01-07 18:10:39 | [diff] [blame] | 4831 | const net::SiteForCookies& site_for_cookies, |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4832 | const base::Optional<std::string>& user_agent, |
Julie Jeongeun Kim | 3e973f9 | 2019-08-22 08:02:40 | [diff] [blame] | 4833 | mojo::PendingRemote<network::mojom::WebSocketHandshakeClient> |
| 4834 | handshake_client) { |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4835 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4836 | if (!frame) { |
| 4837 | return; |
| 4838 | } |
| 4839 | auto* web_request_api = |
| 4840 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
| 4841 | frame->GetProcess()->GetBrowserContext()); |
| 4842 | |
| 4843 | DCHECK(web_request_api); |
| 4844 | web_request_api->ProxyWebSocket(frame, std::move(factory), url, |
Maks Orlovich | ab27e24 | 2020-01-07 18:10:39 | [diff] [blame] | 4845 | site_for_cookies.RepresentativeUrl(), |
| 4846 | user_agent, std::move(handshake_client)); |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4847 | #endif |
| 4848 | } |
| 4849 | |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4850 | bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager( |
Maks Orlovich | e7db7a2 | 2019-07-25 01:47:46 | [diff] [blame] | 4851 | network::mojom::RestrictedCookieManagerRole role, |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4852 | content::BrowserContext* browser_context, |
| 4853 | const url::Origin& origin, |
Maks Orlovich | ab27e24 | 2020-01-07 18:10:39 | [diff] [blame] | 4854 | const net::SiteForCookies& site_for_cookies, |
Maks Orlovich | 11001fa | 2019-10-01 20:41:40 | [diff] [blame] | 4855 | const url::Origin& top_frame_origin, |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4856 | bool is_service_worker, |
| 4857 | int process_id, |
| 4858 | int routing_id, |
Julie Jeongeun Kim | d20f64b | 2019-08-26 04:13:03 | [diff] [blame] | 4859 | mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) { |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4860 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 4861 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4862 | if (origin.scheme() == extensions::kExtensionScheme) { |
Maks Orlovich | e7db7a2 | 2019-07-25 01:47:46 | [diff] [blame] | 4863 | DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role); |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4864 | extensions::ChromeExtensionCookies::Get(browser_context) |
Maks Orlovich | 11001fa | 2019-10-01 20:41:40 | [diff] [blame] | 4865 | ->CreateRestrictedCookieManager(origin, site_for_cookies, |
| 4866 | top_frame_origin, std::move(*receiver)); |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4867 | return true; |
| 4868 | } |
| 4869 | #endif |
| 4870 | return false; |
| 4871 | } |
| 4872 | |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 4873 | void ChromeContentBrowserClient::OnNetworkServiceCreated( |
| 4874 | network::mojom::NetworkService* network_service) { |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4875 | PrefService* local_state; |
| 4876 | if (g_browser_process) { |
| 4877 | DCHECK(g_browser_process->local_state()); |
| 4878 | local_state = g_browser_process->local_state(); |
| 4879 | } else { |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 4880 | DCHECK(startup_data_->chrome_feature_list_creator()->local_state()); |
| 4881 | local_state = startup_data_->chrome_feature_list_creator()->local_state(); |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance()) |
| 4885 | data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state); |
| 4886 | |
Henrique Nakashima | a3b1c5d | 2019-07-03 19:25:49 | [diff] [blame] | 4887 | // Create SystemNetworkContextManager if it has not been created yet. We need |
| 4888 | // to set up global NetworkService state before anything else uses it and this |
| 4889 | // is the first opportunity to initialize SystemNetworkContextManager with the |
| 4890 | // NetworkService. |
| 4891 | if (!SystemNetworkContextManager::HasInstance()) |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4892 | SystemNetworkContextManager::CreateInstance(local_state); |
John Abd-El-Malek | 897374f4 | 2019-05-30 03:58:07 | [diff] [blame] | 4893 | |
Min Qin | 8caab1d | 2018-10-03 17:28:13 | [diff] [blame] | 4894 | SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated( |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 4895 | network_service); |
| 4896 | } |
| 4897 | |
Matthew Denton | 8888ae5 | 2020-05-14 08:20:02 | [diff] [blame] | 4898 | void ChromeContentBrowserClient::ConfigureNetworkContextParams( |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4899 | content::BrowserContext* context, |
| 4900 | bool in_memory, |
Matthew Denton | 8888ae5 | 2020-05-14 08:20:02 | [diff] [blame] | 4901 | const base::FilePath& relative_partition_path, |
| 4902 | network::mojom::NetworkContextParams* network_context_params, |
| 4903 | network::mojom::CertVerifierCreationParams* cert_verifier_creation_params) { |
John Abd-El-Malek | cc0b2a6 | 2018-03-20 19:32:50 | [diff] [blame] | 4904 | Profile* profile = Profile::FromBrowserContext(context); |
Matthew Denton | 8888ae5 | 2020-05-14 08:20:02 | [diff] [blame] | 4905 | profile->ConfigureNetworkContextParams(in_memory, relative_partition_path, |
| 4906 | network_context_params, |
| 4907 | cert_verifier_creation_params); |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4908 | } |
| 4909 | |
Robert Sesek | 34f68f31 | 2019-01-14 20:25:11 | [diff] [blame] | 4910 | std::vector<base::FilePath> |
| 4911 | ChromeContentBrowserClient::GetNetworkContextsParentDirectory() { |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 4912 | DCHECK(!network_contexts_parent_directory_.empty()); |
| 4913 | return network_contexts_parent_directory_; |
Robert Sesek | 34f68f31 | 2019-01-14 20:25:11 | [diff] [blame] | 4914 | } |
| 4915 | |
John Abd-El-Malek | c240cfc4 | 2020-07-08 12:22:44 | [diff] [blame] | 4916 | base::DictionaryValue ChromeContentBrowserClient::GetNetLogConstants() { |
| 4917 | auto platform_dict = net_log::GetPlatformConstantsForNetLog( |
| 4918 | base::CommandLine::ForCurrentProcess()->GetCommandLineString(), |
| 4919 | chrome::GetChannelName()); |
| 4920 | if (platform_dict) |
| 4921 | return std::move(*platform_dict); |
| 4922 | else |
| 4923 | return base::DictionaryValue(); |
| 4924 | } |
| 4925 | |
Min Qin | 75ed6df | 2017-12-01 20:39:15 | [diff] [blame] | 4926 | bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp( |
Min Qin | 30a78a1 | 2017-12-06 01:29:13 | [diff] [blame] | 4927 | content::NavigationUIData* navigation_ui_data) { |
Min Qin | 75ed6df | 2017-12-01 20:39:15 | [diff] [blame] | 4928 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 4929 | // It is OK to load the saved offline copy, in MHTML format. |
| 4930 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4931 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4932 | if (!chrome_navigation_ui_data) |
| 4933 | return false; |
| 4934 | offline_pages::OfflinePageNavigationUIData* offline_page_data = |
| 4935 | chrome_navigation_ui_data->GetOfflinePageNavigationUIData(); |
| 4936 | return offline_page_data && offline_page_data->is_offline_page(); |
| 4937 | #else |
| 4938 | return false; |
| 4939 | #endif |
| 4940 | } |
| 4941 | |
Min Qin | 30a78a1 | 2017-12-06 01:29:13 | [diff] [blame] | 4942 | bool ChromeContentBrowserClient::ShouldForceDownloadResource( |
| 4943 | const GURL& url, |
| 4944 | const std::string& mime_type) { |
| 4945 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4946 | // Special-case user scripts to get downloaded instead of viewed. |
| 4947 | return extensions::UserScript::IsURLUserScript(url, mime_type); |
| 4948 | #else |
| 4949 | return false; |
| 4950 | #endif |
| 4951 | } |
| 4952 | |
Donna Wu | 838ac36 | 2018-08-10 10:36:33 | [diff] [blame] | 4953 | void ChromeContentBrowserClient::CreateWebUsbService( |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 4954 | content::RenderFrameHost* render_frame_host, |
Miyoung Shin | 6262215 | 2019-08-27 05:13:04 | [diff] [blame] | 4955 | mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) { |
Reilly Grant | 27b2a3c | 2020-04-28 23:52:46 | [diff] [blame] | 4956 | if (!base::FeatureList::IsEnabled(features::kWebUsb)) |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 4957 | return; |
| 4958 | |
[email protected] | 95ebe7c | 2020-04-08 19:12:45 | [diff] [blame] | 4959 | CHECK(render_frame_host); |
| 4960 | FrameUsbServices::CreateFrameUsbServices(render_frame_host, |
| 4961 | std::move(receiver)); |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 4962 | } |
| 4963 | |
Ovidio Henriquez | 3d729f6 | 2020-02-07 00:43:29 | [diff] [blame] | 4964 | content::BluetoothDelegate* ChromeContentBrowserClient::GetBluetoothDelegate() { |
| 4965 | if (!bluetooth_delegate_) |
| 4966 | bluetooth_delegate_ = std::make_unique<ChromeBluetoothDelegate>(); |
| 4967 | return bluetooth_delegate_.get(); |
| 4968 | } |
| 4969 | |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 4970 | #if !defined(OS_ANDROID) |
| 4971 | content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() { |
| 4972 | if (!serial_delegate_) |
| 4973 | serial_delegate_ = std::make_unique<ChromeSerialDelegate>(); |
| 4974 | return serial_delegate_.get(); |
| 4975 | } |
Matt Reynolds | 93616f9b | 2019-06-07 01:28:52 | [diff] [blame] | 4976 | |
| 4977 | content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() { |
| 4978 | if (!hid_delegate_) |
| 4979 | hid_delegate_ = std::make_unique<ChromeHidDelegate>(); |
| 4980 | return hid_delegate_.get(); |
| 4981 | } |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 4982 | |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 4983 | std::unique_ptr<content::AuthenticatorRequestClientDelegate> |
| 4984 | ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate( |
Adam Langley | 5f3963f1 | 2020-01-21 19:10:33 | [diff] [blame] | 4985 | content::RenderFrameHost* render_frame_host) { |
| 4986 | return AuthenticatorRequestScheduler::CreateRequestDelegate( |
| 4987 | render_frame_host); |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 4988 | } |
Nina Satragno | 8c832df | 2019-07-29 15:59:39 | [diff] [blame] | 4989 | #endif |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 4990 | |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 4991 | std::unique_ptr<net::ClientCertStore> |
| 4992 | ChromeContentBrowserClient::CreateClientCertStore( |
David Benjamin | f6a3409 | 2019-11-07 19:55:10 | [diff] [blame] | 4993 | content::BrowserContext* browser_context) { |
| 4994 | return ProfileNetworkContextServiceFactory::GetForContext(browser_context) |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 4995 | ->CreateClientCertStore(); |
| 4996 | } |
| 4997 | |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 4998 | std::unique_ptr<content::LoginDelegate> |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 4999 | ChromeContentBrowserClient::CreateLoginDelegate( |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5000 | const net::AuthChallengeInfo& auth_info, |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 5001 | content::WebContents* web_contents, |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5002 | const content::GlobalRequestID& request_id, |
Jun Cai | 8e165d2 | 2018-05-14 19:21:24 | [diff] [blame] | 5003 | bool is_request_for_main_frame, |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5004 | const GURL& url, |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5005 | scoped_refptr<net::HttpResponseHeaders> response_headers, |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5006 | bool first_auth_attempt, |
Mark Pilgrim | 7cfcd11 | 2018-05-08 00:07:56 | [diff] [blame] | 5007 | LoginAuthRequiredCallback auth_required_callback) { |
Emily Stark | 63c884f | 2020-05-12 03:55:28 | [diff] [blame] | 5008 | // For subresources, create a LoginHandler directly, which may show a login |
| 5009 | // prompt to the user. Main frame resources go through LoginTabHelper, which |
| 5010 | // manages a more complicated flow to avoid confusion about which website is |
| 5011 | // showing the prompt. |
| 5012 | if (is_request_for_main_frame) { |
| 5013 | LoginTabHelper::CreateForWebContents(web_contents); |
| 5014 | return LoginTabHelper::FromWebContents(web_contents) |
| 5015 | ->CreateAndStartMainFrameLoginDelegate( |
| 5016 | auth_info, web_contents, request_id, url, response_headers, |
| 5017 | std::move(auth_required_callback)); |
| 5018 | } |
| 5019 | std::unique_ptr<LoginHandler> login_handler = LoginHandler::Create( |
| 5020 | auth_info, web_contents, std::move(auth_required_callback)); |
| 5021 | login_handler->StartSubresource(request_id, url, response_headers); |
| 5022 | return login_handler; |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5023 | } |
| 5024 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5025 | bool ChromeContentBrowserClient::HandleExternalProtocol( |
| 5026 | const GURL& url, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 5027 | content::WebContents::OnceGetter web_contents_getter, |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5028 | int child_id, |
| 5029 | content::NavigationUIData* navigation_data, |
| 5030 | bool is_main_frame, |
| 5031 | ui::PageTransition page_transition, |
Tim Volodine | b24393f3 | 2018-11-16 18:45:45 | [diff] [blame] | 5032 | bool has_user_gesture, |
Emily Stark | 13b66bdf | 2019-10-04 17:11:45 | [diff] [blame] | 5033 | const base::Optional<url::Origin>& initiating_origin, |
Julie Jeongeun Kim | fb6f530 | 2019-10-17 17:24:10 | [diff] [blame] | 5034 | mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) { |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5035 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5036 | // External protocols are disabled for guests. An exception is made for the |
| 5037 | // "mailto" protocol, so that pages that utilize it work properly in a |
| 5038 | // WebView. |
| 5039 | ChromeNavigationUIData* chrome_data = |
| 5040 | static_cast<ChromeNavigationUIData*>(navigation_data); |
| 5041 | if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) || |
| 5042 | (chrome_data && |
| 5043 | chrome_data->GetExtensionNavigationUIData()->is_web_view())) && |
| 5044 | !url.SchemeIs(url::kMailToScheme)) { |
| 5045 | return false; |
| 5046 | } |
| 5047 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 5048 | |
| 5049 | #if defined(OS_ANDROID) |
| 5050 | // Main frame external protocols are handled by |
| 5051 | // InterceptNavigationResourceThrottle. |
| 5052 | if (is_main_frame) |
| 5053 | return false; |
| 5054 | #endif // defined(ANDROID) |
| 5055 | |
Gabriel Charette | e7cdc5cd | 2020-05-27 23:35:05 | [diff] [blame] | 5056 | content::GetUIThreadTaskRunner({})->PostTask( |
| 5057 | FROM_HERE, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 5058 | base::BindOnce(&LaunchURL, url, std::move(web_contents_getter), |
| 5059 | page_transition, has_user_gesture, initiating_origin)); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5060 | return true; |
| 5061 | } |
| 5062 | |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5063 | std::unique_ptr<content::OverlayWindow> |
Jennifer Apacible | 6010b023 | 2018-04-12 23:35:28 | [diff] [blame] | 5064 | ChromeContentBrowserClient::CreateWindowForPictureInPicture( |
| 5065 | content::PictureInPictureWindowController* controller) { |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5066 | // Note: content::OverlayWindow::Create() is defined by platform-specific |
| 5067 | // implementation in chrome/browser/ui/views. This layering hack, which goes |
| 5068 | // through //content and ContentBrowserClient, allows us to work around the |
| 5069 | // dependency constraints that disallow directly calling |
| 5070 | // chrome/browser/ui/views code either from here or from other code in |
| 5071 | // chrome/browser. |
Jennifer Apacible | 6010b023 | 2018-04-12 23:35:28 | [diff] [blame] | 5072 | return content::OverlayWindow::Create(controller); |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5073 | } |
| 5074 | |
Kunihiko Sakamoto | 19aa708 | 2019-02-25 03:14:43 | [diff] [blame] | 5075 | void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher( |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5076 | content::BrowserContext* browser_context, |
Julie Jeongeun Kim | 6d8b749 | 2019-08-20 19:24:11 | [diff] [blame] | 5077 | mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) { |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5078 | Profile* profile = Profile::FromBrowserContext(browser_context); |
Kunihiko Sakamoto | 19aa708 | 2019-02-25 03:14:43 | [diff] [blame] | 5079 | PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher( |
| 5080 | std::move(watcher)); |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5081 | } |
| 5082 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5083 | // Static; handles rewriting Web UI URLs. |
| 5084 | bool ChromeContentBrowserClient::HandleWebUI( |
| 5085 | GURL* url, |
| 5086 | content::BrowserContext* browser_context) { |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 5087 | // Rewrite chrome://help to chrome://settings/help. |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5088 | if (url->SchemeIs(content::kChromeUIScheme) && |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 5089 | url->host() == chrome::kChromeUIHelpHost) { |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5090 | *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost, |
| 5091 | chrome::kChromeUIHelpHost); |
| 5092 | return true; // Return true to update the displayed URL. |
| 5093 | } |
| 5094 | |
sauski | b5f8276 | 2020-07-21 17:13:22 | [diff] [blame] | 5095 | // Replace deprecated cookie settings URL with the current version. |
| 5096 | if (*url == GURL(chrome::kChromeUICookieSettingsDeprecatedURL)) { |
| 5097 | *url = GURL(chrome::kChromeUICookieSettingsURL); |
| 5098 | return true; |
| 5099 | } |
| 5100 | |
Hector Carmona | 566a20b | 2019-09-13 22:44:42 | [diff] [blame] | 5101 | #if defined(OS_WIN) |
| 5102 | // TODO(crbug.com/1003960): Remove when issue is resolved. |
| 5103 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 5104 | url->host() == chrome::kChromeUIWelcomeWin10Host) { |
| 5105 | url::Replacements<char> replacements; |
| 5106 | replacements.SetHost( |
| 5107 | chrome::kChromeUIWelcomeHost, |
| 5108 | url::Component(0, strlen(chrome::kChromeUIWelcomeHost))); |
| 5109 | *url = url->ReplaceComponents(replacements); |
| 5110 | return true; |
| 5111 | } |
| 5112 | #endif // defined(OS_WIN) |
| 5113 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5114 | if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 5115 | browser_context, *url)) { |
| 5116 | return false; |
| 5117 | } |
| 5118 | |
| 5119 | #if defined(OS_CHROMEOS) |
| 5120 | // Special case : in ChromeOS in Guest mode bookmarks and history are |
| 5121 | // disabled for security reasons. New tab page explains the reasons, so |
| 5122 | // we redirect user to new tab page. |
| 5123 | if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { |
| 5124 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 5125 | (url->DomainIs(chrome::kChromeUIBookmarksHost) || |
| 5126 | url->DomainIs(chrome::kChromeUIHistoryHost))) { |
| 5127 | // Rewrite with new tab URL |
| 5128 | *url = GURL(chrome::kChromeUINewTabURL); |
| 5129 | } |
| 5130 | } |
Aya ElAttar | eb5fee1 | 2020-05-05 08:56:05 | [diff] [blame] | 5131 | |
| 5132 | if (IsSystemFeatureURLDisabled(*url)) { |
| 5133 | *url = ReplaceURLHostAndPath(*url, chrome::kChromeUIAppDisabledHost, ""); |
| 5134 | return true; |
| 5135 | } |
| 5136 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5137 | #endif |
| 5138 | |
| 5139 | return true; |
| 5140 | } |
| 5141 | |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 5142 | bool ChromeContentBrowserClient::ShowPaymentHandlerWindow( |
| 5143 | content::BrowserContext* browser_context, |
| 5144 | const GURL& url, |
Anthony Vallee-Dubois | 98befeaa | 2018-01-18 16:31:32 | [diff] [blame] | 5145 | base::OnceCallback<void(bool, int, int)> callback) { |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 5146 | #if defined(OS_ANDROID) |
| 5147 | return false; |
| 5148 | #else |
| 5149 | payments::PaymentRequestDisplayManagerFactory::GetInstance() |
| 5150 | ->GetForBrowserContext(browser_context) |
| 5151 | ->ShowPaymentHandlerWindow(url, std::move(callback)); |
| 5152 | return true; |
| 5153 | #endif |
| 5154 | } |
| 5155 | |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 5156 | // static |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5157 | bool ChromeContentBrowserClient::HandleWebUIReverse( |
| 5158 | GURL* url, |
| 5159 | content::BrowserContext* browser_context) { |
Hector Carmona | 566a20b | 2019-09-13 22:44:42 | [diff] [blame] | 5160 | #if defined(OS_WIN) |
| 5161 | // TODO(crbug.com/1003960): Remove when issue is resolved. |
| 5162 | // No need to actually reverse-rewrite the URL, but return true to update the |
| 5163 | // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome. |
| 5164 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 5165 | url->host() == chrome::kChromeUIWelcomeHost) { |
| 5166 | return true; |
| 5167 | } |
| 5168 | #endif // defined(OS_WIN) |
| 5169 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5170 | // No need to actually reverse-rewrite the URL, but return true to update the |
| 5171 | // displayed URL when rewriting chrome://help to chrome://settings/help. |
| 5172 | return url->SchemeIs(content::kChromeUIScheme) && |
| 5173 | url->host() == chrome::kChromeUISettingsHost; |
| 5174 | } |
| 5175 | |
Alison Maher | 7f366dc6 | 2020-03-03 19:46:00 | [diff] [blame] | 5176 | const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const { |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 5177 | return ui::NativeTheme::GetInstanceForWeb(); |
| 5178 | } |
| 5179 | |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 5180 | scoped_refptr<safe_browsing::UrlCheckerDelegate> |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 5181 | ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate( |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 5182 | bool safe_browsing_enabled_for_profile, |
| 5183 | bool should_check_on_sb_disabled) { |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5184 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 5185 | |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 5186 | // Should not bypass safe browsing check if the check is for enterprise |
| 5187 | // lookup. |
| 5188 | if (!safe_browsing_enabled_for_profile && !should_check_on_sb_disabled) |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 5189 | return nullptr; |
| 5190 | |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5191 | // |safe_browsing_service_| may be unavailable in tests. |
| 5192 | if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) { |
| 5193 | safe_browsing_url_checker_delegate_ = |
Jialiu Lin | 0de6756c | 2018-03-22 00:57:43 | [diff] [blame] | 5194 | base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>( |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5195 | safe_browsing_service_->database_manager(), |
Jialiu Lin | 0de6756c | 2018-03-22 00:57:43 | [diff] [blame] | 5196 | safe_browsing_service_->ui_manager()); |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5197 | } |
| 5198 | |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 5199 | return safe_browsing_url_checker_delegate_; |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5200 | } |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 5201 | |
Xinghui Lu | cf23c90 | 2020-06-10 17:38:25 | [diff] [blame] | 5202 | safe_browsing::RealTimeUrlLookupServiceBase* |
| 5203 | ChromeContentBrowserClient::GetUrlLookupService( |
| 5204 | content::BrowserContext* browser_context, |
| 5205 | bool is_enterprise_lookup_enabled, |
| 5206 | bool is_consumer_lookup_enabled) { |
| 5207 | // |safe_browsing_service_| may be unavailable in tests. |
| 5208 | if (!safe_browsing_service_) { |
| 5209 | return nullptr; |
| 5210 | } |
| 5211 | |
| 5212 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 5213 | |
| 5214 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) |
| 5215 | if (is_enterprise_lookup_enabled) { |
| 5216 | return safe_browsing::ChromeEnterpriseRealTimeUrlLookupServiceFactory:: |
| 5217 | GetForProfile(profile); |
| 5218 | } |
| 5219 | #endif |
| 5220 | |
| 5221 | if (is_consumer_lookup_enabled) { |
| 5222 | return safe_browsing::RealTimeUrlLookupServiceFactory::GetForProfile( |
| 5223 | profile); |
| 5224 | } |
| 5225 | return nullptr; |
| 5226 | } |
| 5227 | |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 5228 | base::Optional<std::string> |
| 5229 | ChromeContentBrowserClient::GetOriginPolicyErrorPage( |
Domenic Denicola | c3fedd4 | 2020-03-20 21:16:59 | [diff] [blame] | 5230 | network::OriginPolicyState error_reason, |
Daniel Vogelheim | 7badd0d | 2019-02-04 14:42:18 | [diff] [blame] | 5231 | content::NavigationHandle* handle) { |
Domenic Denicola | c3fedd4 | 2020-03-20 21:16:59 | [diff] [blame] | 5232 | return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML( |
| 5233 | error_reason, handle); |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 5234 | } |
Kunihiko Sakamoto | 73b803d | 2018-10-05 09:09:52 | [diff] [blame] | 5235 | |
Takashi Toyoshima | 5af383aa | 2019-07-22 15:24:22 | [diff] [blame] | 5236 | bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() { |
Kunihiko Sakamoto | 73b803d | 2018-10-05 09:09:52 | [diff] [blame] | 5237 | // We require --user-data-dir flag too so that no dangerous changes are made |
| 5238 | // in the user's regular profile. |
| 5239 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 5240 | switches::kUserDataDir); |
| 5241 | } |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 5242 | |
| 5243 | void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate( |
| 5244 | int32_t network_traffic_annotation_id_hash, |
| 5245 | int64_t recv_bytes, |
| 5246 | int64_t sent_bytes) { |
Min Qin | cafb27b | 2018-10-30 18:02:03 | [diff] [blame] | 5247 | if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) { |
| 5248 | data_use_measurement::ChromeDataUseMeasurement::GetInstance() |
| 5249 | ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash, |
| 5250 | recv_bytes, sent_bytes); |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 5251 | } |
| 5252 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5253 | |
Ken Rockot | 4e284d3 | 2020-03-06 06:26:49 | [diff] [blame] | 5254 | base::FilePath |
| 5255 | ChromeContentBrowserClient::GetSandboxedStorageServiceDataDirectory() { |
| 5256 | return g_browser_process->profile_manager()->user_data_dir(); |
| 5257 | } |
| 5258 | |
Guido Urdaneta | e02b572 | 2020-07-22 05:58:21 | [diff] [blame] | 5259 | bool ChromeContentBrowserClient::ShouldSandboxAudioService() { |
| 5260 | return IsAudioServiceSandboxEnabled(); |
| 5261 | } |
| 5262 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5263 | blink::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews( |
| 5264 | blink::PreviewsState initial_state, |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5265 | content::NavigationHandle* navigation_handle, |
| 5266 | const GURL& current_navigation_url) { |
Sophie Chang | c4ddda677 | 2020-07-15 15:08:32 | [diff] [blame] | 5267 | return DetermineAllowedPreviewsWithoutHoldback( |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5268 | initial_state, navigation_handle, current_navigation_url); |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5269 | } |
| 5270 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5271 | blink::PreviewsState |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5272 | ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback( |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5273 | blink::PreviewsState initial_state, |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5274 | content::NavigationHandle* navigation_handle, |
| 5275 | const GURL& current_navigation_url) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5276 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
Tarun Bansal | b89c1d5 | 2019-01-16 06:56:29 | [diff] [blame] | 5277 | DCHECK(!navigation_handle->HasCommitted()); |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5278 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5279 | // If this is not a main frame, return the initial state. If there are no |
| 5280 | // previews in the state, return the state as is. |
| 5281 | if (!navigation_handle->IsInMainFrame() || |
| 5282 | navigation_handle->IsSameDocument()) { |
| 5283 | return initial_state; |
| 5284 | } |
| 5285 | |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5286 | if (!current_navigation_url.SchemeIsHTTPOrHTTPS()) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5287 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5288 | |
Doug Arnett | b3b99bc | 2019-08-09 16:55:56 | [diff] [blame] | 5289 | // Check if initial state specifies no previews should be considered. |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5290 | if (initial_state == blink::PreviewsTypes::PREVIEWS_OFF) |
Doug Arnett | b3b99bc | 2019-08-09 16:55:56 | [diff] [blame] | 5291 | return initial_state; |
| 5292 | |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5293 | // Do not allow previews on POST navigations since the primary opt-out |
| 5294 | // mechanism is to reload the page. Because POST navigations are not |
| 5295 | // idempotent, we do not want to show a preview on a POST navigation where |
| 5296 | // opting out would cause another navigation, i.e.: a reload. |
| 5297 | if (navigation_handle->IsPost()) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5298 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5299 | |
| 5300 | content::WebContents* web_contents = navigation_handle->GetWebContents(); |
| 5301 | content::WebContentsDelegate* delegate = web_contents->GetDelegate(); |
| 5302 | |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5303 | auto* browser_context = web_contents->GetBrowserContext(); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5304 | |
| 5305 | PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile( |
| 5306 | Profile::FromBrowserContext(browser_context)); |
| 5307 | auto* data_reduction_proxy_settings = |
| 5308 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 5309 | browser_context); |
| 5310 | // If the profile does not support previews or Data Saver, do not turn on |
| 5311 | // Previews. |
| 5312 | if (!previews_service || !previews_service->previews_ui_service() || |
Owen Min | 08a7289 | 2019-07-31 20:03:35 | [diff] [blame] | 5313 | !data_reduction_proxy_settings) { |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5314 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5315 | } |
| 5316 | |
| 5317 | PreviewsUITabHelper* ui_tab_helper = |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5318 | PreviewsUITabHelper::FromWebContents(web_contents); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5319 | // If this tab does not have a PreviewsUITabHelper, no preview should be |
| 5320 | // served. |
| 5321 | if (!ui_tab_helper) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5322 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5323 | |
| 5324 | DCHECK(!browser_context->IsOffTheRecord()); |
| 5325 | |
| 5326 | // Other previews objects should all exist and be initialized if we have made |
| 5327 | // it past earlier checks. |
| 5328 | previews::PreviewsDeciderImpl* previews_decider_impl = |
| 5329 | previews_service->previews_ui_service()->previews_decider_impl(); |
| 5330 | DCHECK(previews_decider_impl); |
| 5331 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5332 | // Start with an unspecified state. |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5333 | blink::PreviewsState previews_state = |
| 5334 | blink::PreviewsTypes::PREVIEWS_UNSPECIFIED; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5335 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5336 | previews::PreviewsUserData* previews_data = |
| 5337 | ui_tab_helper->GetPreviewsUserData(navigation_handle); |
| 5338 | |
| 5339 | // Certain PreviewsStates are used within URLLoaders (Offline, server |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5340 | // previews) and cannot re-evaluate PreviewsState once previews triggering |
| 5341 | // logic has already been run, so they should not change. Assume that |
Robert Ogden | 54892d0 | 2020-04-28 22:36:37 | [diff] [blame] | 5342 | // previews triggering logic has run when PreviewsUserData already exists. |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5343 | bool previews_triggering_logic_already_ran = false; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5344 | if (previews_data) { |
Robert Ogden | 54892d0 | 2020-04-28 22:36:37 | [diff] [blame] | 5345 | previews_triggering_logic_already_ran = true; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5346 | } else { |
| 5347 | previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle( |
| 5348 | navigation_handle, previews_decider_impl->GeneratePageId()); |
| 5349 | } |
| 5350 | |
| 5351 | DCHECK(previews_data); |
| 5352 | |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 5353 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 5354 | previews::switches::kForceEnablePreviews)) { |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5355 | return blink::ALL_SUPPORTED_PREVIEWS; |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 5356 | } |
| 5357 | |
Sophie Chang | a71fa5d | 2019-11-19 23:53:51 | [diff] [blame] | 5358 | // Evaluate client-side previews. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5359 | previews_state |= previews::DetermineAllowedClientPreviewsState( |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5360 | previews_data, previews_triggering_logic_already_ran, |
Owen Min | 08a7289 | 2019-07-31 20:03:35 | [diff] [blame] | 5361 | data_reduction_proxy_settings->IsDataReductionProxyEnabled(), |
| 5362 | previews_decider_impl, navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5363 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5364 | if (previews_state & blink::PreviewsTypes::PREVIEWS_OFF) { |
| 5365 | previews_data->set_allowed_previews_state( |
| 5366 | blink::PreviewsTypes::PREVIEWS_OFF); |
| 5367 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5368 | } |
| 5369 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5370 | if (previews_state & blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM) { |
| 5371 | previews_data->set_allowed_previews_state( |
| 5372 | blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM); |
| 5373 | return blink::PreviewsTypes::PREVIEWS_NO_TRANSFORM; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5374 | } |
| 5375 | |
| 5376 | // At this point, if no Preview is allowed, don't allow previews. |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5377 | if (previews_state == blink::PreviewsTypes::PREVIEWS_UNSPECIFIED) { |
| 5378 | previews_data->set_allowed_previews_state( |
| 5379 | blink::PreviewsTypes::PREVIEWS_OFF); |
| 5380 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5381 | } |
| 5382 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5383 | blink::PreviewsState embedder_state = |
| 5384 | blink::PreviewsTypes::PREVIEWS_UNSPECIFIED; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5385 | if (delegate) { |
| 5386 | delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state); |
| 5387 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5388 | |
| 5389 | // If the allowed previews are limited by the embedder, ensure previews honors |
| 5390 | // those limits. |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5391 | if (embedder_state != blink::PreviewsTypes::PREVIEWS_UNSPECIFIED) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5392 | previews_state = previews_state & embedder_state; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5393 | // If no valid previews are left, set the state explicitly to PREVIEWS_OFF. |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5394 | if (previews_state == blink::PreviewsTypes::PREVIEWS_UNSPECIFIED) |
| 5395 | previews_state = blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5396 | } |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5397 | previews_data->set_allowed_previews_state(previews_state); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5398 | return previews_state; |
| 5399 | } |
| 5400 | |
| 5401 | // static |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5402 | blink::PreviewsState |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5403 | ChromeContentBrowserClient::DetermineCommittedPreviewsForURL( |
| 5404 | const GURL& url, |
| 5405 | data_reduction_proxy::DataReductionProxyData* drp_data, |
| 5406 | previews::PreviewsUserData* previews_user_data, |
| 5407 | const previews::PreviewsDecider* previews_decider, |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5408 | blink::PreviewsState initial_state, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5409 | content::NavigationHandle* navigation_handle) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5410 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 5411 | if (!previews::HasEnabledPreviews(initial_state)) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5412 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5413 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5414 | // Check the various other client previews types. |
| 5415 | return previews::DetermineCommittedClientPreviewsState( |
Sophie Chang | c4ddda677 | 2020-07-15 15:08:32 | [diff] [blame] | 5416 | previews_user_data, url, initial_state, previews_decider, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5417 | navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5418 | } |
| 5419 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5420 | blink::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews( |
| 5421 | blink::PreviewsState initial_state, |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5422 | content::NavigationHandle* navigation_handle, |
| 5423 | const net::HttpResponseHeaders* response_headers) { |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5424 | blink::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback( |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5425 | initial_state, navigation_handle, response_headers); |
| 5426 | |
| 5427 | return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle); |
| 5428 | } |
| 5429 | |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5430 | blink::PreviewsState |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5431 | ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback( |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5432 | blink::PreviewsState initial_state, |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5433 | content::NavigationHandle* navigation_handle, |
| 5434 | const net::HttpResponseHeaders* response_headers) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5435 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
arthursonzogni | 90bb092 | 2020-05-28 09:22:23 | [diff] [blame] | 5436 | DCHECK(!navigation_handle->HasCommitted()); |
| 5437 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5438 | // Only support HTTP and HTTPS. |
arthursonzogni | 90bb092 | 2020-05-28 09:22:23 | [diff] [blame] | 5439 | if (!navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5440 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5441 | |
| 5442 | // If this is not a main frame, return the initial state. If there are no |
| 5443 | // previews in the state, return the state as is. |
| 5444 | if (!previews::HasEnabledPreviews(initial_state) || |
| 5445 | !navigation_handle->IsInMainFrame() || |
| 5446 | navigation_handle->IsSameDocument()) { |
| 5447 | return initial_state; |
| 5448 | } |
| 5449 | |
| 5450 | // WebContents that don't have a PreviewsUITabHelper are not supported. |
| 5451 | PreviewsUITabHelper* ui_tab_helper = |
| 5452 | PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents()); |
| 5453 | if (!ui_tab_helper) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5454 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5455 | |
| 5456 | // If we did not previously create a PreviewsUserData, do not go any further. |
| 5457 | previews::PreviewsUserData* previews_user_data = |
| 5458 | ui_tab_helper->GetPreviewsUserData(navigation_handle); |
| 5459 | if (!previews_user_data) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5460 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5461 | |
| 5462 | PreviewsService* previews_service = |
| 5463 | PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext( |
| 5464 | navigation_handle->GetWebContents()->GetBrowserContext())); |
| 5465 | |
| 5466 | if (!previews_service || !previews_service->previews_ui_service()) |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5467 | return blink::PreviewsTypes::PREVIEWS_OFF; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5468 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5469 | // Annotate request if no-transform directive found in response headers. |
| 5470 | if (response_headers && |
| 5471 | response_headers->HasHeaderValue("cache-control", "no-transform")) { |
Jered Gray | ba1da12 | 2018-10-31 23:06:26 | [diff] [blame] | 5472 | previews_user_data->set_cache_control_no_transform_directive(); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5473 | } |
| 5474 | |
| 5475 | previews::PreviewsDeciderImpl* previews_decider_impl = |
| 5476 | previews_service->previews_ui_service()->previews_decider_impl(); |
| 5477 | DCHECK(previews_decider_impl); |
| 5478 | |
Clark DuVall | 9c5a72cc | 2018-10-25 01:29:21 | [diff] [blame] | 5479 | std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data; |
| 5480 | auto* settings = |
| 5481 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 5482 | navigation_handle->GetWebContents()->GetBrowserContext()); |
| 5483 | if (settings) { |
| 5484 | // TODO(898326): |drp_data| may be incomplete because |navigation_handle| |
| 5485 | // does not yet have all the response information. |
| 5486 | drp_data = settings->CreateDataFromNavigationHandle(navigation_handle, |
| 5487 | response_headers); |
| 5488 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5489 | |
| 5490 | // Determine effective PreviewsState for this committed main frame response. |
Hiroki Nakagawa | 4136615 | 2020-07-27 18:31:40 | [diff] [blame] | 5491 | blink::PreviewsState committed_state = DetermineCommittedPreviewsForURL( |
Clark DuVall | 9c5a72cc | 2018-10-25 01:29:21 | [diff] [blame] | 5492 | navigation_handle->GetURL(), drp_data.get(), previews_user_data, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5493 | previews_decider_impl, initial_state, navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5494 | |
| 5495 | // Double check that we never serve a preview when we have a |
| 5496 | // cache-control:no-transform directive. |
| 5497 | DCHECK(!previews_user_data->cache_control_no_transform_directive() || |
| 5498 | !previews::HasEnabledPreviews(committed_state)); |
| 5499 | |
Robert Ogden | ded292c6f | 2019-05-03 22:44:51 | [diff] [blame] | 5500 | // TODO(robertogden): Consider moving this to after the holdback logic. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5501 | previews_user_data->set_committed_previews_state(committed_state); |
| 5502 | |
| 5503 | previews::PreviewsType committed_type = |
| 5504 | previews::GetMainFramePreviewsType(committed_state); |
| 5505 | |
| 5506 | // Capture committed previews type, if any, in PreviewsUserData. |
| 5507 | // Note: this is for the subset of previews types that are decided upon |
| 5508 | // navigation commit. Previews types that are determined prior to |
| 5509 | // navigation (such as for offline pages or for redirecting to another |
| 5510 | // url), are not set here. |
| 5511 | previews_user_data->SetCommittedPreviewsType(committed_type); |
| 5512 | |
| 5513 | // Log the commit decision. |
| 5514 | std::vector<previews::PreviewsEligibilityReason> passed_reasons; |
| 5515 | previews_decider_impl->LogPreviewDecisionMade( |
| 5516 | (previews_user_data->cache_control_no_transform_directive() |
| 5517 | ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM |
| 5518 | : previews::PreviewsEligibilityReason::COMMITTED), |
| 5519 | navigation_handle->GetURL(), base::Time::Now(), |
Robert Ogden | 869986f | 2019-06-20 19:12:05 | [diff] [blame] | 5520 | previews_user_data->CommittedPreviewsType(), std::move(passed_reasons), |
Robert Ogden | 33e3631 | 2019-05-06 19:17:05 | [diff] [blame] | 5521 | previews_user_data); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5522 | |
| 5523 | return committed_state; |
| 5524 | } |
Charlie Harrison | 650e1142 | 2018-12-04 00:37:26 | [diff] [blame] | 5525 | |
| 5526 | void ChromeContentBrowserClient::LogWebFeatureForCurrentPage( |
| 5527 | content::RenderFrameHost* render_frame_host, |
| 5528 | blink::mojom::WebFeature feature) { |
| 5529 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 5530 | page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {}); |
| 5531 | page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage( |
| 5532 | render_frame_host, new_features); |
Lily Chen | c2c9e9f | 2019-12-05 19:55:31 | [diff] [blame] | 5533 | |
| 5534 | // For the SameSite-by-default-cookies related features, log |
| 5535 | // the site engagement score for the site whose cookie was blocked. This is to |
| 5536 | // gauge the user impact of the cookies being blocked. |
| 5537 | MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature); |
Charlie Harrison | 650e1142 | 2018-12-04 00:37:26 | [diff] [blame] | 5538 | } |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5539 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5540 | std::string ChromeContentBrowserClient::GetProduct() { |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5541 | return ::GetProduct(); |
| 5542 | } |
| 5543 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5544 | std::string ChromeContentBrowserClient::GetUserAgent() { |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5545 | return ::GetUserAgent(); |
| 5546 | } |
Sam McNally | d54e23f9 | 2019-01-16 04:42:39 | [diff] [blame] | 5547 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5548 | blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() { |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 5549 | return ::GetUserAgentMetadata(); |
| 5550 | } |
| 5551 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5552 | base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() { |
Austin Orion | e250d01 | 2019-05-29 02:56:27 | [diff] [blame] | 5553 | // This icon is available on Android, but adds 19KiB to the APK. Since it |
| 5554 | // isn't used on Android we exclude it to avoid bloat. |
| 5555 | #if !defined(OS_ANDROID) |
| 5556 | return base::Optional<gfx::ImageSkia>( |
| 5557 | *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 5558 | IDR_PRODUCT_LOGO_256)); |
| 5559 | #else |
| 5560 | return base::nullopt; |
| 5561 | #endif |
| 5562 | } |
| 5563 | |
Sam McNally | d54e23f9 | 2019-01-16 04:42:39 | [diff] [blame] | 5564 | bool ChromeContentBrowserClient::IsBuiltinComponent( |
| 5565 | content::BrowserContext* browser_context, |
| 5566 | const url::Origin& origin) { |
| 5567 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5568 | return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent( |
| 5569 | browser_context, origin); |
| 5570 | #else |
| 5571 | return false; |
| 5572 | #endif |
| 5573 | } |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 5574 | |
Aaron Colwell | e1908d98 | 2020-06-26 22:08:15 | [diff] [blame] | 5575 | bool ChromeContentBrowserClient::ShouldBlockRendererDebugURL( |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 5576 | const GURL& url, |
| 5577 | content::BrowserContext* context) { |
Aaron Colwell | f94fd97a | 2020-07-21 19:37:08 | [diff] [blame] | 5578 | PolicyBlocklistService* service = |
| 5579 | PolicyBlocklistFactory::GetForBrowserContext(context); |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 5580 | |
Aaron Colwell | f94fd97a | 2020-07-21 19:37:08 | [diff] [blame] | 5581 | using URLBlocklistState = policy::URLBlocklist::URLBlocklistState; |
| 5582 | URLBlocklistState blocklist_state = service->GetURLBlocklistState(url); |
| 5583 | return blocklist_state == URLBlocklistState::URL_IN_BLOCKLIST; |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 5584 | } |
Dominic Mazzoni | 21fb028 | 2019-02-13 18:32:47 | [diff] [blame] | 5585 | |
| 5586 | ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext( |
| 5587 | content::BrowserContext* browser_context) { |
| 5588 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 5589 | return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode(); |
| 5590 | } |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5591 | |
| 5592 | #if defined(OS_ANDROID) |
| 5593 | content::ContentBrowserClient::WideColorGamutHeuristic |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5594 | ChromeContentBrowserClient::GetWideColorGamutHeuristic() { |
Chris Blume | 7f752e3 | 2020-02-14 22:22:33 | [diff] [blame] | 5595 | if (viz::AlwaysUseWideColorGamut() || |
Chris Blume | 5b36a01a | 2020-03-13 21:35:42 | [diff] [blame] | 5596 | features::IsDynamicColorGamutEnabled()) { |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5597 | return WideColorGamutHeuristic::kUseDisplay; |
| 5598 | } |
Khushal | 1fc0da5 | 2019-10-09 00:38:56 | [diff] [blame] | 5599 | |
| 5600 | if (display::Display::HasForceDisplayColorProfile() && |
| 5601 | display::Display::GetForcedDisplayColorProfile() == |
| 5602 | gfx::ColorSpace::CreateDisplayP3D65()) { |
| 5603 | return WideColorGamutHeuristic::kUseDisplay; |
| 5604 | } |
| 5605 | |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5606 | return WideColorGamutHeuristic::kNone; |
| 5607 | } |
| 5608 | #endif |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5609 | |
| 5610 | base::flat_set<std::string> |
Ehsan Karamad | 466529d | 2019-05-24 03:24:43 | [diff] [blame] | 5611 | ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers( |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 5612 | content::BrowserContext* browser_context) { |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5613 | base::flat_set<std::string> mime_types; |
| 5614 | #if BUILDFLAG(ENABLE_PLUGINS) |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 5615 | auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context); |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5616 | for (const auto& pair : map) |
| 5617 | mime_types.insert(pair.first); |
| 5618 | #endif |
| 5619 | return mime_types; |
| 5620 | } |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5621 | |
| 5622 | void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy( |
| 5623 | const content::WebContents* web_contents, |
| 5624 | const content::RenderFrameHost* frame_host, |
| 5625 | bool user_gesture, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5626 | content::NavigationDownloadPolicy* download_policy) { |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5627 | const ChromeSubresourceFilterClient* client = |
| 5628 | ChromeSubresourceFilterClient::FromWebContents(web_contents); |
| 5629 | if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) { |
Yao Xiao | f6064666 | 2019-07-25 07:25:04 | [diff] [blame] | 5630 | download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame); |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5631 | if (!user_gesture) { |
| 5632 | if (base::FeatureList::IsEnabled( |
| 5633 | blink::features:: |
| 5634 | kBlockingDownloadsInAdFrameWithoutUserActivation)) { |
| 5635 | download_policy->SetDisallowed( |
| 5636 | content::NavigationDownloadType::kAdFrameNoGesture); |
| 5637 | } else { |
| 5638 | download_policy->SetAllowed( |
| 5639 | content::NavigationDownloadType::kAdFrameNoGesture); |
| 5640 | } |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5641 | } |
| 5642 | } |
| 5643 | } |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5644 | |
| 5645 | bool ChromeContentBrowserClient::IsBluetoothScanningBlocked( |
| 5646 | content::BrowserContext* browser_context, |
| 5647 | const url::Origin& requesting_origin, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5648 | const url::Origin& embedding_origin) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5649 | const HostContentSettingsMap* const content_settings = |
| 5650 | HostContentSettingsMapFactory::GetForProfile( |
| 5651 | Profile::FromBrowserContext(browser_context)); |
| 5652 | |
| 5653 | if (content_settings->GetContentSetting( |
| 5654 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 5655 | ContentSettingsType::BLUETOOTH_SCANNING, |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5656 | std::string()) == CONTENT_SETTING_BLOCK) { |
| 5657 | return true; |
| 5658 | } |
| 5659 | |
| 5660 | return false; |
| 5661 | } |
| 5662 | |
| 5663 | void ChromeContentBrowserClient::BlockBluetoothScanning( |
| 5664 | content::BrowserContext* browser_context, |
| 5665 | const url::Origin& requesting_origin, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5666 | const url::Origin& embedding_origin) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5667 | HostContentSettingsMap* const content_settings = |
| 5668 | HostContentSettingsMapFactory::GetForProfile( |
| 5669 | Profile::FromBrowserContext(browser_context)); |
| 5670 | |
| 5671 | content_settings->SetContentSettingDefaultScope( |
| 5672 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 5673 | ContentSettingsType::BLUETOOTH_SCANNING, std::string(), |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5674 | CONTENT_SETTING_BLOCK); |
| 5675 | } |
Tibor Goldschwendt | bf1b96e | 2019-10-07 22:03:47 | [diff] [blame] | 5676 | |
| 5677 | bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile() { |
| 5678 | #if defined(OS_ANDROID) |
| 5679 | return extra_icu::ModuleProvider::IsModuleInstalled(); |
| 5680 | #endif |
| 5681 | return false; |
| 5682 | } |
Guido Urdaneta | 4030d6a3 | 2019-10-17 09:38:16 | [diff] [blame] | 5683 | |
| 5684 | bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed( |
| 5685 | content::BrowserContext* browser_context, |
| 5686 | const GURL& url, |
| 5687 | const GURL& site_for_cookies, |
| 5688 | const base::Optional<url::Origin>& top_frame_origin) { |
| 5689 | // Persistent MediaDevice IDs are allowed if cookies are allowed. |
| 5690 | return CookieSettingsFactory::GetForProfile( |
| 5691 | Profile::FromBrowserContext(browser_context)) |
| 5692 | ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin); |
| 5693 | } |
Sam Goto | 5cf068e8 | 2019-11-04 23:08:44 | [diff] [blame] | 5694 | |
| 5695 | #if !defined(OS_ANDROID) |
| 5696 | void ChromeContentBrowserClient::FetchRemoteSms( |
| 5697 | content::BrowserContext* browser_context, |
| 5698 | const url::Origin& origin, |
| 5699 | base::OnceCallback<void(base::Optional<std::string>)> callback) { |
| 5700 | ::FetchRemoteSms(browser_context, origin, std::move(callback)); |
| 5701 | } |
| 5702 | #endif |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 5703 | |
| 5704 | void ChromeContentBrowserClient::IsClipboardPasteAllowed( |
| 5705 | content::WebContents* web_contents, |
| 5706 | const GURL& url, |
| 5707 | const ui::ClipboardFormatType& data_type, |
| 5708 | const std::string& data, |
| 5709 | IsClipboardPasteAllowedCallback callback) { |
| 5710 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
| 5711 | // Safe browsing does not support images, so accept without checking. |
| 5712 | // TODO(crbug.com/1013584): check policy on what to do about unsupported |
| 5713 | // types when it is implemented. |
Darwin Huang | 0024dbf | 2020-08-04 00:53:55 | [diff] [blame] | 5714 | if (data_type == ui::ClipboardFormatType::GetBitmapType()) { |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 5715 | std::move(callback).Run(ClipboardPasteAllowed(true)); |
| 5716 | return; |
| 5717 | } |
| 5718 | |
| 5719 | Profile* profile = |
| 5720 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 5721 | safe_browsing::DeepScanningDialogDelegate::Data dialog_data; |
Dominique Fauteux-Chapleau | c08c8c96 | 2020-05-07 18:46:26 | [diff] [blame] | 5722 | if (safe_browsing::DeepScanningDialogDelegate::IsEnabled( |
| 5723 | profile, url, &dialog_data, |
| 5724 | enterprise_connectors::AnalysisConnector::BULK_DATA_ENTRY)) { |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 5725 | dialog_data.text.push_back(base::UTF8ToUTF16(data)); |
| 5726 | safe_browsing::DeepScanningDialogDelegate::ShowForWebContents( |
| 5727 | web_contents, std::move(dialog_data), |
| 5728 | base::BindOnce( |
| 5729 | [](IsClipboardPasteAllowedCallback callback, |
| 5730 | const safe_browsing::DeepScanningDialogDelegate::Data& data, |
| 5731 | const safe_browsing::DeepScanningDialogDelegate::Result& |
| 5732 | result) { |
| 5733 | std::move(callback).Run( |
| 5734 | ClipboardPasteAllowed(result.text_results[0])); |
| 5735 | }, |
Dominique Fauteux-Chapleau | 5b14716 | 2020-01-17 17:08:24 | [diff] [blame] | 5736 | std::move(callback)), |
| 5737 | safe_browsing::DeepScanAccessPoint::PASTE); |
Roger Tawa | 03ffdbd | 2020-01-16 18:12:54 | [diff] [blame] | 5738 | } else { |
| 5739 | std::move(callback).Run(ClipboardPasteAllowed(true)); |
| 5740 | } |
| 5741 | #else |
| 5742 | std::move(callback).Run(ClipboardPasteAllowed(true)); |
| 5743 | #endif // BUILDFLAG(FULL_SAFE_BROWSING) |
| 5744 | } |
Lukasz Anforowicz | 4600ea3 | 2020-01-18 02:37:48 | [diff] [blame] | 5745 | |
Lukasz Anforowicz | 1feeba18 | 2020-03-16 20:32:02 | [diff] [blame] | 5746 | void ChromeContentBrowserClient:: |
| 5747 | LogUkmEventForCrossOriginFetchFromContentScript3( |
| 5748 | const std::string& isolated_world_host) { |
| 5749 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5750 | const std::string& extension_id = isolated_world_host; |
| 5751 | ukm::SourceId source_id = |
| 5752 | ukm::AppSourceUrlRecorder::GetSourceIdForChromeExtension(extension_id); |
| 5753 | if (source_id != ukm::kInvalidSourceId) { |
| 5754 | ukm::builders::Extensions_CrossOriginFetchFromContentScript3 ukm_event( |
| 5755 | source_id); |
| 5756 | ukm_event.SetEventHappened(true).Record(ukm::UkmRecorder::Get()); |
| 5757 | } |
| 5758 | #endif |
| 5759 | } |
| 5760 | |
Lukasz Anforowicz | 4600ea3 | 2020-01-18 02:37:48 | [diff] [blame] | 5761 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 5762 | bool ChromeContentBrowserClient::ShouldAllowPluginCreation( |
| 5763 | const url::Origin& embedder_origin, |
| 5764 | const content::PepperPluginInfo& plugin_info) { |
| 5765 | #if BUILDFLAG(ENABLE_PDF) |
| 5766 | if (plugin_info.name == ChromeContentClient::kPDFInternalPluginName) { |
| 5767 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5768 | // Allow embedding the internal PDF plugin in the built-in PDF extension. |
| 5769 | if (embedder_origin.scheme() == extensions::kExtensionScheme && |
| 5770 | embedder_origin.host() == extension_misc::kPdfExtensionId) { |
| 5771 | return true; |
| 5772 | } |
| 5773 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 5774 | |
| 5775 | // Allow embedding the internal PDF plugin in chrome://print. |
| 5776 | if (embedder_origin == url::Origin::Create(GURL(chrome::kChromeUIPrintURL))) |
| 5777 | return true; |
| 5778 | |
| 5779 | // Only allow the PDF plugin in the known, trustworthy origins that are |
| 5780 | // allowlisted above. See also https://crbug.com/520422 and |
| 5781 | // https://crbug.com/1027173. |
| 5782 | return false; |
| 5783 | } |
| 5784 | #endif // BUILDFLAG(ENABLE_PDF) |
| 5785 | |
| 5786 | return true; |
| 5787 | } |
| 5788 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
Alexander Cooper | c844870 | 2020-03-14 01:39:56 | [diff] [blame] | 5789 | |
| 5790 | #if BUILDFLAG(ENABLE_VR) |
| 5791 | content::XrIntegrationClient* |
| 5792 | ChromeContentBrowserClient::GetXrIntegrationClient() { |
| 5793 | if (!xr_integration_client_) |
| 5794 | xr_integration_client_ = std::make_unique<vr::ChromeXrIntegrationClient>( |
| 5795 | util::PassKey<ChromeContentBrowserClient>()); |
| 5796 | return xr_integration_client_.get(); |
| 5797 | } |
| 5798 | #endif // BUILDFLAG(ENABLE_VR) |
Adrienne Walker | 29765129 | 2020-05-08 00:23:18 | [diff] [blame] | 5799 | |
| 5800 | bool ChromeContentBrowserClient::IsOriginTrialRequiredForAppCache( |
| 5801 | content::BrowserContext* browser_context) { |
| 5802 | auto* profile = Profile::FromBrowserContext(browser_context); |
| 5803 | auto* prefs = profile->GetPrefs(); |
| 5804 | |
| 5805 | if (prefs->HasPrefPath(prefs::kAppCacheForceEnabled) && |
| 5806 | prefs->GetBoolean(prefs::kAppCacheForceEnabled)) { |
| 5807 | return false; |
| 5808 | } |
| 5809 | if (base::FeatureList::IsEnabled( |
| 5810 | blink::features::kAppCacheRequireOriginTrial)) { |
| 5811 | return true; |
| 5812 | } |
| 5813 | |
| 5814 | return false; |
| 5815 | } |
Yutaka Hirano | 3e61366 | 2020-06-02 02:59:34 | [diff] [blame] | 5816 | |
Hidehiko Abe | eaffbbce | 2020-06-23 19:41:52 | [diff] [blame] | 5817 | void ChromeContentBrowserClient::BindBrowserControlInterface( |
| 5818 | mojo::GenericPendingReceiver receiver) { |
James Cook | 26d2712 | 2020-06-26 19:57:07 | [diff] [blame] | 5819 | #if BUILDFLAG(IS_LACROS) |
Erik Chen | 8e73ffd | 2020-07-10 22:18:27 | [diff] [blame] | 5820 | if (auto r = receiver.As<crosapi::mojom::LacrosChromeService>()) { |
James Cook | be13cc0 | 2020-06-29 22:32:51 | [diff] [blame] | 5821 | chromeos::LacrosChromeServiceImpl::Get()->BindReceiver(std::move(r)); |
Hidehiko Abe | eaffbbce | 2020-06-23 19:41:52 | [diff] [blame] | 5822 | } |
| 5823 | #endif |
| 5824 | } |
| 5825 | |
Yutaka Hirano | 3e61366 | 2020-06-02 02:59:34 | [diff] [blame] | 5826 | bool ChromeContentBrowserClient:: |
| 5827 | ShouldInheritCrossOriginEmbedderPolicyImplicitly(const GURL& url) { |
| 5828 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5829 | return url.SchemeIs(extensions::kExtensionScheme); |
| 5830 | #else |
| 5831 | return false; |
| 5832 | #endif |
| 5833 | } |
John Abd-El-Malek | dc02601 | 2020-06-15 23:28:56 | [diff] [blame] | 5834 | |
| 5835 | ukm::UkmService* ChromeContentBrowserClient::GetUkmService() { |
| 5836 | return g_browser_process->GetMetricsServicesManager()->GetUkmService(); |
| 5837 | } |