[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 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 7 | #include <map> |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 8 | #include <set> |
[email protected] | 1033acd | 2012-02-08 08:46:27 | [diff] [blame] | 9 | #include <utility> |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
brettw | f195891 | 2015-10-07 19:43:12 | [diff] [blame] | 12 | #include "base/base_switches.h" |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 13 | #include "base/bind.h" |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 14 | #include "base/bind_helpers.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 15 | #include "base/command_line.h" |
Ken Rockot | 91c40da8 | 2019-08-12 20:07:11 | [diff] [blame] | 16 | #include "base/compiler_specific.h" |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 17 | #include "base/files/file_util.h" |
morrita | d95714f | 2014-10-01 02:37:24 | [diff] [blame] | 18 | #include "base/files/scoped_file.h" |
Marc Treib | ad33cf94 | 2017-08-24 11:19:00 | [diff] [blame] | 19 | #include "base/i18n/base_i18n_switches.h" |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 20 | #include "base/i18n/character_encoding.h" |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 21 | #include "base/macros.h" |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 22 | #include "base/metrics/field_trial_params.h" |
evliu | edcbb87d | 2019-11-22 19:49:41 | [diff] [blame] | 23 | #include "base/metrics/histogram_functions.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" |
[email protected] | e746341 | 2013-06-10 22:53:46 | [diff] [blame] | 29 | #include "base/strings/string_number_conversions.h" |
markdittmer | 67b71ea | 2016-03-03 22:40:03 | [diff] [blame] | 30 | #include "base/strings/string_split.h" |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 31 | #include "base/strings/string_util.h" |
| 32 | #include "base/strings/stringprintf.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 33 | #include "base/strings/utf_string_conversions.h" |
Sebastien Marchand | 75a7cdf | 2018-11-13 23:47:03 | [diff] [blame] | 34 | #include "base/system/sys_info.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 35 | #include "base/task/post_task.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" |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 39 | #include "chrome/app/chrome_content_browser_overlay_manifest.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" |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 42 | #include "chrome/browser/after_startup_task_utils.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 43 | #include "chrome/browser/browser_about_handler.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 44 | #include "chrome/browser/browser_process.h" |
[email protected] | b0cb5e8 | 2012-07-19 19:22:47 | [diff] [blame] | 45 | #include "chrome/browser/browsing_data/browsing_data_helper.h" |
msramek | 1c2b3ca | 2017-03-14 17:57:56 | [diff] [blame] | 46 | #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 47 | #include "chrome/browser/chrome_content_browser_client_parts.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 48 | #include "chrome/browser/chrome_quota_permission_context.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 49 | #include "chrome/browser/content_settings/cookie_settings_factory.h" |
peconn | 5100d43 | 2015-09-16 12:03:08 | [diff] [blame] | 50 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 51 | #include "chrome/browser/content_settings/tab_specific_content_settings.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" |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 58 | #include "chrome/browser/download/download_prefs.h" |
Lily Chen | c2c9e9f | 2019-12-05 19:55:31 | [diff] [blame] | 59 | #include "chrome/browser/engagement/site_engagement_service.h" |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 60 | #include "chrome/browser/extensions/chrome_extension_cookies.h" |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 61 | #include "chrome/browser/external_protocol/external_protocol_handler.h" |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 62 | #include "chrome/browser/font_family_cache.h" |
Peng Huang | ee82ef8 | 2019-11-22 13:15:29 | [diff] [blame] | 63 | #include "chrome/browser/gpu/chrome_browser_main_extra_parts_gpu.h" |
Matt Reynolds | 93616f9b | 2019-06-07 01:28:52 | [diff] [blame] | 64 | #include "chrome/browser/hid/chrome_hid_delegate.h" |
Avi Drissman | d3092734 | 2018-05-22 15:04:27 | [diff] [blame] | 65 | #include "chrome/browser/lifetime/browser_shutdown.h" |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 66 | #include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h" |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 67 | #include "chrome/browser/media/router/media_router_feature.h" |
Derek Cheng | eb64b19a | 2018-01-02 20:20:42 | [diff] [blame] | 68 | #include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h" |
| 69 | #include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h" |
Patrik Höglund | b564859b | 2018-05-17 11:17:16 | [diff] [blame] | 70 | #include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h" |
mcasas | a2023ab | 2016-09-08 01:06:36 | [diff] [blame] | 71 | #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
Darin Fisher | 09aa722 | 2019-08-29 09:27:36 | [diff] [blame] | 72 | #include "chrome/browser/media/webrtc/webrtc_logging_controller.h" |
Sebastien Marchand | 8c008810 | 2019-10-11 16:47:56 | [diff] [blame] | 73 | #include "chrome/browser/memory/chrome_browser_main_extra_parts_memory.h" |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 74 | #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 75 | #include "chrome/browser/metrics/chrome_feature_list_creator.h" |
[email protected] | a2b4c5c | 2013-10-18 02:06:07 | [diff] [blame] | 76 | #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h" |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 77 | #include "chrome/browser/net/chrome_network_delegate.h" |
David Benjamin | f6a3409 | 2019-11-07 19:55:10 | [diff] [blame] | 78 | #include "chrome/browser/net/profile_network_context_service.h" |
| 79 | #include "chrome/browser/net/profile_network_context_service_factory.h" |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 80 | #include "chrome/browser/net/system_network_context_manager.h" |
Richard Knoll | d0eae96 | 2019-04-04 12:34:02 | [diff] [blame] | 81 | #include "chrome/browser/notifications/platform_notification_service_factory.h" |
peter | c26c6c6 | 2014-12-10 14:13:59 | [diff] [blame] | 82 | #include "chrome/browser/notifications/platform_notification_service_impl.h" |
leon.han | 952ea325 | 2016-04-13 02:44:56 | [diff] [blame] | 83 | #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 84 | #include "chrome/browser/payments/payment_request_display_manager_factory.h" |
Sigurdur Asgeirsson | 54b7270 | 2019-04-12 14:18:54 | [diff] [blame] | 85 | #include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h" |
Sigurdur Asgeirsson | 7069667 | 2019-02-08 16:14:51 | [diff] [blame] | 86 | #include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h" |
Adam Langley | 85339f6 | 2018-02-12 22:03:56 | [diff] [blame] | 87 | #include "chrome/browser/permissions/attestation_permission_request.h" |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 88 | #include "chrome/browser/permissions/permission_context_base.h" |
Adam Langley | 85339f6 | 2018-02-12 22:03:56 | [diff] [blame] | 89 | #include "chrome/browser/permissions/permission_request_manager.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 90 | #include "chrome/browser/platform_util.h" |
Amber Won | 94afd811 | 2017-08-23 17:30:11 | [diff] [blame] | 91 | #include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h" |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 92 | #include "chrome/browser/plugins/plugin_utils.h" |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 93 | #include "chrome/browser/prerender/prerender_final_status.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 94 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 95 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | 2736c03 | 2012-05-11 18:06:07 | [diff] [blame] | 96 | #include "chrome/browser/prerender/prerender_message_filter.h" |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 97 | #include "chrome/browser/prerender/prerender_util.h" |
Ryan Sturm | cc5071be | 2019-02-16 02:15:19 | [diff] [blame] | 98 | #include "chrome/browser/previews/previews_content_util.h" |
Robert Ogden | 0f4d8868 | 2019-09-24 22:27:52 | [diff] [blame] | 99 | #include "chrome/browser/previews/previews_lite_page_redirect_decider.h" |
| 100 | #include "chrome/browser/previews/previews_lite_page_redirect_url_loader_interceptor.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" |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 107 | #include "chrome/browser/profiles/renderer_updater.h" |
| 108 | #include "chrome/browser/profiles/renderer_updater_factory.h" |
Erik Chen | 49bbfa2 | 2017-08-18 08:49:56 | [diff] [blame] | 109 | #include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h" |
| 110 | #include "chrome/browser/profiling_host/profiling_process_host.h" |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 111 | #include "chrome/browser/renderer_host/chrome_navigation_ui_data.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 112 | #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 113 | #include "chrome/browser/renderer_preferences_util.h" |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 114 | #include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h" |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 115 | #include "chrome/browser/safe_browsing/certificate_reporting_service.h" |
| 116 | #include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h" |
Carlos IL | 4ee307e | 2018-12-22 03:19:00 | [diff] [blame] | 117 | #include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h" |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 118 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 119 | #include "chrome/browser/safe_browsing/ui_manager.h" |
| 120 | #include "chrome/browser/safe_browsing/url_checker_delegate_impl.h" |
[email protected] | a7b8e43d | 2013-03-18 18:52:43 | [diff] [blame] | 121 | #include "chrome/browser/search/search.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 122 | #include "chrome/browser/sessions/session_tab_helper.h" |
Sam Goto | 5cf068e8 | 2019-11-04 23:08:44 | [diff] [blame] | 123 | #include "chrome/browser/sharing/sms/sms_remote_fetcher.h" |
Reilly Grant | cc22e60 | 2018-09-07 15:25:20 | [diff] [blame] | 124 | #include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h" |
Reilly Grant | 3787780 | 2018-08-18 00:58:35 | [diff] [blame] | 125 | #include "chrome/browser/signin/chrome_signin_url_loader_throttle.h" |
Robbie McElrath | 38f47af | 2019-09-19 21:51:40 | [diff] [blame] | 126 | #include "chrome/browser/signin/header_modification_delegate_impl.h" |
David Roger | e8e83f3c | 2019-09-12 10:56:23 | [diff] [blame] | 127 | #include "chrome/browser/signin/identity_manager_factory.h" |
Lukasz Anforowicz | fd30af3 | 2019-03-28 17:33:28 | [diff] [blame] | 128 | #include "chrome/browser/site_isolation/site_isolation_policy.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 129 | #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 130 | #include "chrome/browser/speech/tts_controller_delegate_impl.h" |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 131 | #include "chrome/browser/ssl/ssl_client_auth_metrics.h" |
[email protected] | 25af6ec | 2014-06-06 19:35:07 | [diff] [blame] | 132 | #include "chrome/browser/ssl/ssl_client_certificate_selector.h" |
meacer | 4ef065e | 2015-01-09 03:21:35 | [diff] [blame] | 133 | #include "chrome/browser/ssl/ssl_error_handler.h" |
Christopher Thompson | 4137cec | 2017-12-19 05:34:23 | [diff] [blame] | 134 | #include "chrome/browser/ssl/typed_navigation_timing_throttle.h" |
csharrison | 77bf834 | 2017-05-04 18:23:10 | [diff] [blame] | 135 | #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" |
meacer | 4ef065e | 2015-01-09 03:21:35 | [diff] [blame] | 136 | #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 137 | #include "chrome/browser/tab_contents/tab_util.h" |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 138 | #include "chrome/browser/tracing/chrome_tracing_delegate.h" |
Dave Tapuska | c6627e1 | 2018-08-30 15:07:19 | [diff] [blame] | 139 | #include "chrome/browser/translate/translate_service.h" |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 140 | #include "chrome/browser/ui/blocked_content/blocked_window_params.h" |
Charlie Harrison | 804659a | 2018-10-16 16:43:38 | [diff] [blame] | 141 | #include "chrome/browser/ui/blocked_content/popup_blocker.h" |
Charles Harrison | 6dd11d28 | 2017-10-03 06:14:51 | [diff] [blame] | 142 | #include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h" |
thestig | e8082124 | 2015-09-30 23:46:08 | [diff] [blame] | 143 | #include "chrome/browser/ui/browser_navigator.h" |
| 144 | #include "chrome/browser/ui/browser_navigator_params.h" |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 145 | #include "chrome/browser/ui/chrome_select_file_policy.h" |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 146 | #include "chrome/browser/ui/login/login_handler.h" |
Emily Stark | d6896cd3 | 2019-08-21 04:55:54 | [diff] [blame] | 147 | #include "chrome/browser/ui/login/login_navigation_throttle.h" |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 148 | #include "chrome/browser/ui/prefs/pref_watcher.h" |
[email protected] | 329ac97 | 2013-06-21 15:24:25 | [diff] [blame] | 149 | #include "chrome/browser/ui/sync/sync_promo_ui.h" |
[email protected] | b5d7342 | 2012-06-02 23:46:44 | [diff] [blame] | 150 | #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h" |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 151 | #include "chrome/browser/ui/ui_features.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 152 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
dbeam | baee5bd | 2015-09-26 03:07:01 | [diff] [blame] | 153 | #include "chrome/browser/ui/webui/log_web_ui_url.h" |
reillyg | 3ff4532 | 2015-10-23 21:16:25 | [diff] [blame] | 154 | #include "chrome/browser/usb/usb_tab_helper.h" |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 155 | #include "chrome/browser/vr/vr_tab_helper.h" |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 156 | #include "chrome/browser/web_applications/components/app_registrar.h" |
| 157 | #include "chrome/browser/web_applications/web_app_provider.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 158 | #include "chrome/common/buildflags.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 159 | #include "chrome/common/channel_info.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 160 | #include "chrome/common/chrome_constants.h" |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 161 | #include "chrome/common/chrome_features.h" |
[email protected] | a7944aa | 2012-10-15 10:12:14 | [diff] [blame] | 162 | #include "chrome/common/chrome_paths.h" |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 163 | #include "chrome/common/chrome_paths_internal.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 164 | #include "chrome/common/chrome_switches.h" |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 165 | #include "chrome/common/env_vars.h" |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 166 | #include "chrome/common/google_url_loader_throttle.h" |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 167 | #include "chrome/common/logging_chrome.h" |
[email protected] | 9d45049 | 2013-06-13 23:08:37 | [diff] [blame] | 168 | #include "chrome/common/pepper_permission_util.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 169 | #include "chrome/common/pref_names.h" |
evliu | bc2aa047 | 2019-08-09 20:19:19 | [diff] [blame] | 170 | #include "chrome/common/pref_names_util.h" |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 171 | #include "chrome/common/prerender_url_loader_throttle.h" |
Egor Pasko | d52474c3 | 2018-06-19 12:03:22 | [diff] [blame] | 172 | #include "chrome/common/prerender_util.h" |
Mike Wittman | 08b377d | 2019-11-27 21:06:32 | [diff] [blame] | 173 | #include "chrome/common/profiler/stack_sampling_configuration.h" |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 174 | #include "chrome/common/render_messages.h" |
nigeltao | 7cd8d558 | 2016-12-12 06:05:28 | [diff] [blame] | 175 | #include "chrome/common/renderer_configuration.mojom.h" |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 176 | #include "chrome/common/secure_origin_whitelist.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 177 | #include "chrome/common/url_constants.h" |
Peter Boström | 8e9b163 | 2019-08-22 23:12:47 | [diff] [blame] | 178 | #include "chrome/common/webui_url_constants.h" |
ben | c70c0e3 | 2016-09-22 03:50:37 | [diff] [blame] | 179 | #include "chrome/grit/browser_resources.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 180 | #include "chrome/grit/generated_resources.h" |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 181 | #include "chrome/installer/util/google_update_settings.h" |
brettw | f195891 | 2015-10-07 19:43:12 | [diff] [blame] | 182 | #include "components/autofill/core/common/autofill_switches.h" |
msramek | 1c8e19d | 2017-01-04 20:04:53 | [diff] [blame] | 183 | #include "components/browsing_data/core/browsing_data_utils.h" |
[email protected] | 649b5727 | 2014-05-09 14:54:44 | [diff] [blame] | 184 | #include "components/cdm/browser/cdm_message_filter_android.h" |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 185 | #include "components/certificate_matching/certificate_principal_pattern.h" |
[email protected] | 09cff7878 | 2014-04-20 22:04:48 | [diff] [blame] | 186 | #include "components/cloud_devices/common/cloud_devices_switches.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 187 | #include "components/content_settings/core/browser/content_settings_utils.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 188 | #include "components/content_settings/core/browser/cookie_settings.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 189 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 190 | #include "components/content_settings/core/common/content_settings.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 191 | #include "components/content_settings/core/common/content_settings_types.h" |
tbansal | 08a0e3e | 2017-06-30 21:30:08 | [diff] [blame] | 192 | #include "components/content_settings/core/common/content_settings_utils.h" |
Daniel Vogelheim | 976f1c2 | 2017-11-22 16:26:03 | [diff] [blame] | 193 | #include "components/content_settings/core/common/pref_names.h" |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 194 | #include "components/data_reduction_proxy/content/common/data_reduction_proxy_url_loader_throttle.h" |
Clark DuVall | 0e90172 | 2019-08-14 23:31:37 | [diff] [blame] | 195 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 196 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h" |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 197 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h" |
rajendrant | 4319407 | 2019-04-15 22:13:43 | [diff] [blame] | 198 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h" |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 199 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
Wojciech Dzierżanowski | 4538080 | 2019-04-29 14:50:32 | [diff] [blame] | 200 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_throttle_manager.h" |
wychen | e5568734 | 2015-11-13 20:17:03 | [diff] [blame] | 201 | #include "components/dom_distiller/core/dom_distiller_switches.h" |
[email protected] | 474a5a3 | 2014-07-28 18:23:24 | [diff] [blame] | 202 | #include "components/dom_distiller/core/url_constants.h" |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 203 | #include "components/error_page/common/error_page_switches.h" |
khushalsagar | c5447db2 | 2017-08-22 17:53:01 | [diff] [blame] | 204 | #include "components/feature_engagement/public/feature_constants.h" |
| 205 | #include "components/feature_engagement/public/feature_list.h" |
John Abd-El-Malek | 9cf3d7f0 | 2018-07-27 02:40:39 | [diff] [blame] | 206 | #include "components/google/core/common/google_util.h" |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 207 | #include "components/language/core/browser/pref_names.h" |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 208 | #include "components/metrics/client_info.h" |
droger | c690e880 | 2015-09-21 14:29:16 | [diff] [blame] | 209 | #include "components/net_log/chrome_net_log.h" |
Tao Bai | b827b20 | 2019-09-19 21:22:12 | [diff] [blame] | 210 | #include "components/page_load_metrics/browser/metrics_navigation_throttle.h" |
| 211 | #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" |
| 212 | #include "components/page_load_metrics/browser/page_load_metrics_util.h" |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 213 | #include "components/payments/content/payment_request_display_manager.h" |
Doug Turner | 9dcaf596 | 2017-12-21 04:38:53 | [diff] [blame] | 214 | #include "components/policy/content/policy_blacklist_navigation_throttle.h" |
Michael Giuffrida | 01d7b5d | 2018-08-21 07:55:54 | [diff] [blame] | 215 | #include "components/policy/content/policy_blacklist_service.h" |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 216 | #include "components/policy/core/common/policy_service.h" |
| 217 | #include "components/policy/policy_constants.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 218 | #include "components/pref_registry/pref_registry_syncable.h" |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 219 | #include "components/prefs/pref_registry_simple.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 220 | #include "components/prefs/pref_service.h" |
| 221 | #include "components/prefs/scoped_user_pref_update.h" |
Sophie Chang | ff1fc38 | 2019-08-21 16:30:21 | [diff] [blame] | 222 | #include "components/previews/content/previews_decider.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 223 | #include "components/previews/content/previews_decider_impl.h" |
| 224 | #include "components/previews/content/previews_ui_service.h" |
| 225 | #include "components/previews/content/previews_user_data.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 226 | #include "components/previews/core/previews_experiments.h" |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 227 | #include "components/previews/core/previews_features.h" |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 228 | #include "components/previews/core/previews_switches.h" |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 229 | #include "components/rappor/public/rappor_utils.h" |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 230 | #include "components/rappor/rappor_service_impl.h" |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 231 | #include "components/safe_browsing/browser/browser_url_loader_throttle.h" |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 232 | #include "components/safe_browsing/browser/url_checker_delegate.h" |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 233 | #include "components/safe_browsing/buildflags.h" |
timvolodine | 89cf1171 | 2017-05-15 18:05:07 | [diff] [blame] | 234 | #include "components/safe_browsing/common/safe_browsing_prefs.h" |
Tim Volodine | e4593847 | 2017-09-21 10:08:22 | [diff] [blame] | 235 | #include "components/safe_browsing/db/database_manager.h" |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 236 | #include "components/safe_browsing/features.h" |
Jialiu Lin | bdbb81d | 2017-10-11 21:29:09 | [diff] [blame] | 237 | #include "components/safe_browsing/password_protection/password_protection_navigation_throttle.h" |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 238 | #include "components/security_interstitials/content/origin_policy_ui.h" |
Evan Stade | 1e71d6dd | 2019-10-29 03:04:49 | [diff] [blame] | 239 | #include "components/security_interstitials/content/ssl_cert_reporter.h" |
| 240 | #include "components/security_interstitials/content/ssl_error_navigation_throttle.h" |
David Roger | e8e83f3c | 2019-09-12 10:56:23 | [diff] [blame] | 241 | #include "components/signin/public/identity_manager/identity_manager.h" |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 242 | #include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h" |
[email protected] | eba93c9 | 2014-01-07 17:34:17 | [diff] [blame] | 243 | #include "components/translate/core/common/translate_switches.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 244 | #include "components/url_formatter/url_fixer.h" |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 245 | #include "components/variations/variations_associated_data.h" |
Jun Cai | 0e56863 | 2018-08-09 02:05:33 | [diff] [blame] | 246 | #include "components/variations/variations_http_header_provider.h" |
Kyle Milka | b5c048e | 2017-07-07 02:38:46 | [diff] [blame] | 247 | #include "components/variations/variations_switches.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 248 | #include "components/version_info/version_info.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 249 | #include "content/public/browser/browser_child_process_host.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 250 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 251 | #include "content/public/browser/browser_ppapi_host.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 252 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 253 | #include "content/public/browser/browser_thread.h" |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 254 | #include "content/public/browser/browser_url_handler.h" |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 255 | #include "content/public/browser/browsing_data_remover.h" |
Lucas Garron | b9539b73 | 2017-10-31 00:22:09 | [diff] [blame] | 256 | #include "content/public/browser/certificate_request_result_type.h" |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 257 | #include "content/public/browser/child_process_data.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 258 | #include "content/public/browser/child_process_security_policy.h" |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 259 | #include "content/public/browser/client_certificate_delegate.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 260 | #include "content/public/browser/file_url_loader.h" |
Mohsen Izadi | 6a6476b7 | 2018-12-07 04:34:35 | [diff] [blame] | 261 | #include "content/public/browser/gpu_data_manager.h" |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 262 | #include "content/public/browser/navigation_handle.h" |
| 263 | #include "content/public/browser/navigation_throttle.h" |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 264 | #include "content/public/browser/overlay_window.h" |
[email protected] | 094c877 | 2013-12-21 17:54:50 | [diff] [blame] | 265 | #include "content/public/browser/render_frame_host.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 266 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 267 | #include "content/public/browser/render_view_host.h" |
[email protected] | ce96786 | 2012-02-09 22:47:05 | [diff] [blame] | 268 | #include "content/public/browser/resource_context.h" |
jam | 608f299 | 2016-03-31 16:35:34 | [diff] [blame] | 269 | #include "content/public/browser/storage_partition.h" |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 270 | #include "content/public/browser/tts_controller.h" |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 271 | #include "content/public/browser/tts_platform.h" |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 272 | #include "content/public/browser/url_loader_request_interceptor.h" |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 273 | #include "content/public/browser/vpn_service_proxy.h" |
[email protected] | 91ee368 | 2012-01-19 15:02:19 | [diff] [blame] | 274 | #include "content/public/browser/web_contents.h" |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 275 | #include "content/public/browser/web_contents_delegate.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 276 | #include "content/public/browser/web_ui_url_loader_factory.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 277 | #include "content/public/common/child_process_host.h" |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 278 | #include "content/public/common/content_descriptors.h" |
juncai | 1bf9f7c | 2016-03-22 20:46:56 | [diff] [blame] | 279 | #include "content/public/common/content_features.h" |
brettw | 90e9260 | 2015-10-10 00:12:40 | [diff] [blame] | 280 | #include "content/public/common/content_switches.h" |
Hans Wennborg | 5ffd139 | 2019-10-16 11:00:02 | [diff] [blame] | 281 | #include "content/public/common/navigation_policy.h" |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 282 | #include "content/public/common/network_service_util.h" |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 283 | #include "content/public/common/service_manager_connection.h" |
ben | 51bb6c6 | 2016-11-17 20:15:57 | [diff] [blame] | 284 | #include "content/public/common/service_names.mojom.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 285 | #include "content/public/common/url_constants.h" |
[email protected] | 22aa4f8 | 2013-09-24 17:01:44 | [diff] [blame] | 286 | #include "content/public/common/url_utils.h" |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 287 | #include "content/public/common/user_agent.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 288 | #include "content/public/common/web_preferences.h" |
Takuto Ikuta | aa3b796c | 2019-02-06 02:54:56 | [diff] [blame] | 289 | #include "content/public/common/window_container_type.mojom-shared.h" |
Bill Orr | eb42922 | 2018-08-08 21:14:43 | [diff] [blame] | 290 | #include "device/vr/buildflags/buildflags.h" |
Scott Violet | c8240b0 | 2018-03-08 22:03:59 | [diff] [blame] | 291 | #include "extensions/buildflags/buildflags.h" |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 292 | #include "google_apis/gaia/gaia_urls.h" |
Andrew Moylan | 17329fc | 2017-09-25 07:43:30 | [diff] [blame] | 293 | #include "google_apis/google_api_keys.h" |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 294 | #include "gpu/config/gpu_switches.h" |
grunell | 086a411 | 2017-03-02 09:23:04 | [diff] [blame] | 295 | #include "media/audio/audio_manager.h" |
François Beaufort | 8c08979fc | 2018-03-05 13:06:31 | [diff] [blame] | 296 | #include "media/base/media_switches.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 297 | #include "media/media_buildflags.h" |
| 298 | #include "media/mojo/buildflags.h" |
Guido Urdaneta | d06ae84 | 2019-10-10 20:04:12 | [diff] [blame] | 299 | #include "media/webrtc/webrtc_switches.h" |
Shimi Zhang | 6b72d29 | 2019-07-12 20:52:42 | [diff] [blame] | 300 | #include "mojo/public/cpp/bindings/pending_associated_receiver.h" |
Julie Jeongeun Kim | 7f8e26a2 | 2019-10-10 12:09:52 | [diff] [blame] | 301 | #include "mojo/public/cpp/bindings/receiver_set.h" |
Ken Rockot | 0adc1e4 | 2019-05-24 08:20:08 | [diff] [blame] | 302 | #include "mojo/public/cpp/bindings/remote.h" |
engedy | afef048 | 2017-07-06 15:40:53 | [diff] [blame] | 303 | #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 304 | #include "net/base/load_flags.h" |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 305 | #include "net/base/mime_util.h" |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 306 | #include "net/http/http_util.h" |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 307 | #include "net/ssl/client_cert_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 308 | #include "net/ssl/ssl_cert_request_info.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 309 | #include "ppapi/buildflags/buildflags.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 310 | #include "ppapi/host/ppapi_host.h" |
Scott Violet | 318a55f | 2018-03-30 19:08:19 | [diff] [blame] | 311 | #include "printing/buildflags/buildflags.h" |
Takashi Toyoshima | 12844146 | 2019-10-16 04:19:17 | [diff] [blame] | 312 | #include "services/network/public/cpp/features.h" |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 313 | #include "services/network/public/cpp/is_potentially_trustworthy.h" |
Lukasz Anforowicz | 9527fd4 | 2019-03-13 19:08:50 | [diff] [blame] | 314 | #include "services/network/public/cpp/network_switches.h" |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 315 | #include "services/network/public/cpp/resource_request.h" |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 316 | #include "services/service_manager/embedder/switches.h" |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 317 | #include "services/service_manager/sandbox/sandbox_type.h" |
Andrew Comminos | 6605767 | 2019-05-01 00:03:34 | [diff] [blame] | 318 | #include "services/service_manager/sandbox/switches.h" |
Ken Rockot | cebdf9c8 | 2019-05-28 20:33:03 | [diff] [blame] | 319 | #include "services/strings/grit/services_strings.h" |
DongJun Kim | febb3c2 | 2019-10-21 02:08:06 | [diff] [blame] | 320 | #include "storage/browser/file_system/external_mount_points.h" |
Hans Wennborg | 5ffd139 | 2019-10-16 11:00:02 | [diff] [blame] | 321 | #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" |
John Delaney | ac24e57 | 2019-04-30 19:47:02 | [diff] [blame] | 322 | #include "third_party/blink/public/common/features.h" |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 323 | #include "third_party/blink/public/common/loader/url_loader_throttle.h" |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 324 | #include "third_party/blink/public/mojom/renderer_preferences.mojom.h" |
Lily Chen | c2c9e9f | 2019-12-05 19:55:31 | [diff] [blame] | 325 | #include "third_party/blink/public/mojom/site_engagement/site_engagement.mojom.h" |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 326 | #include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h" |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 327 | #include "third_party/skia/include/core/SkColor.h" |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 328 | #include "third_party/widevine/cdm/buildflags.h" |
Scott Violet | b72577d | 2019-01-09 22:18:18 | [diff] [blame] | 329 | #include "ui/base/buildflags.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 330 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 331 | #include "ui/base/resource/resource_bundle.h" |
Scott Violet | 8ff9c30 | 2018-02-22 22:28:35 | [diff] [blame] | 332 | #include "ui/base/ui_base_features.h" |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 333 | #include "ui/base/ui_base_switches.h" |
Khushal | 1fc0da5 | 2019-10-09 00:38:56 | [diff] [blame] | 334 | #include "ui/display/display.h" |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 335 | #include "ui/gfx/color_utils.h" |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 336 | #include "ui/native_theme/caption_style.h" |
| 337 | #include "ui/native_theme/native_theme.h" |
[email protected] | b47dc49 | 2014-08-17 07:05:57 | [diff] [blame] | 338 | #include "ui/resources/grit/ui_resources.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 339 | #include "url/gurl.h" |
| 340 | #include "url/origin.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 341 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 342 | #if defined(OS_WIN) |
wfh | c91e967 | 2016-01-27 00:14:20 | [diff] [blame] | 343 | #include "base/strings/string_tokenizer.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 344 | #include "chrome/browser/chrome_browser_main_win.h" |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 345 | #include "chrome/install_static/install_util.h" |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 346 | #include "sandbox/win/src/sandbox_policy.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 347 | #elif defined(OS_MACOSX) |
Avi Drissman | a2969a55 | 2019-10-30 15:32:25 | [diff] [blame] | 348 | #include "chrome/browser/apps/intent_helper/mac_apps_navigation_throttle.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 349 | #include "chrome/browser/chrome_browser_main_mac.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 350 | #elif defined(OS_CHROMEOS) |
Xiyuan Xia | fc9f3813 | 2019-08-02 00:51:42 | [diff] [blame] | 351 | #include "ash/public/cpp/tablet_mode.h" |
Joshua Peraza | 30d8fc7 | 2019-08-19 17:24:30 | [diff] [blame] | 352 | #include "chrome/app/chrome_crash_reporter_client.h" |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 353 | #include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h" |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 354 | #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 355 | #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 356 | #include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h" |
Sam McNally | d8b7d82 | 2018-08-21 03:18:18 | [diff] [blame] | 357 | #include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h" |
[email protected] | 5bc61cad | 2014-07-08 05:05:08 | [diff] [blame] | 358 | #include "chrome/browser/chromeos/file_manager/app_id.h" |
[email protected] | 43420a1 | 2014-04-21 03:20:48 | [diff] [blame] | 359 | #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h" |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 360 | #include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h" |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 361 | #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 362 | #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h" |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 363 | #include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h" |
| 364 | #include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h" |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 365 | #include "chrome/browser/chromeos/login/signin_partition_manager.h" |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 366 | #include "chrome/browser/chromeos/login/startup_utils.h" |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 367 | #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 368 | #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 369 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
[email protected] | c94ac69 | 2013-07-27 00:50:10 | [diff] [blame] | 370 | #include "chrome/browser/chromeos/system/input_device_settings.h" |
Katie D | b2d0709 | 2018-12-04 18:59:36 | [diff] [blame] | 371 | #include "chrome/browser/speech/tts_chromeos.h" |
Steven Bennetts | 81d07be | 2018-01-08 20:45:27 | [diff] [blame] | 372 | #include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h" |
djacobo | 21e56e0 | 2016-07-02 01:14:31 | [diff] [blame] | 373 | #include "chrome/browser/ui/browser_dialogs.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 374 | #include "chromeos/constants/chromeos_constants.h" |
Kyle Horimoto | 1d6a679f | 2019-04-16 23:24:21 | [diff] [blame] | 375 | #include "chromeos/constants/chromeos_features.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 376 | #include "chromeos/constants/chromeos_switches.h" |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 377 | #include "components/crash/content/app/breakpad_linux.h" |
John Abd-El-Malek | 35bfaa5 | 2019-08-20 16:22:07 | [diff] [blame] | 378 | #include "components/user_manager/user.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 379 | #include "components/user_manager/user_manager.h" |
Ken Rockot | 543f5e3 | 2018-02-04 02:13:50 | [diff] [blame] | 380 | #include "services/service_manager/public/mojom/interface_provider_spec.mojom.h" |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 381 | #elif defined(OS_LINUX) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 382 | #include "chrome/browser/chrome_browser_main_linux.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 383 | #elif defined(OS_ANDROID) |
Bo Liu | 4ade6b1b2 | 2017-11-28 02:26:35 | [diff] [blame] | 384 | #include "base/android/application_status_listener.h" |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 385 | #include "chrome/android/features/dev_ui/buildflags.h" |
Tibor Goldschwendt | bf1b96e | 2019-10-07 22:03:47 | [diff] [blame] | 386 | #include "chrome/android/modules/extra_icu/provider/module_provider.h" |
zqzhang | 93e959d1 | 2017-03-16 13:10:20 | [diff] [blame] | 387 | #include "chrome/browser/android/app_hooks.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 388 | #include "chrome/browser/android/chrome_context_util.h" |
| 389 | #include "chrome/browser/android/devtools_manager_delegate_android.h" |
| 390 | #include "chrome/browser/android/ntp/new_tab_page_url_handler.h" |
| 391 | #include "chrome/browser/android/service_tab_launcher.h" |
| 392 | #include "chrome/browser/android/tab_android.h" |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 393 | #include "chrome/browser/android/tab_web_contents_delegate_android.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 394 | #include "chrome/browser/chrome_browser_main_android.h" |
Min Qin | 86987406 | 2019-10-15 19:27:56 | [diff] [blame] | 395 | #include "chrome/browser/download/android/available_offline_content_provider.h" |
| 396 | #include "chrome/browser/download/android/intercept_oma_download_navigation_throttle.h" |
Jinsuk Kim | 6f9253c | 2019-03-11 02:45:07 | [diff] [blame] | 397 | #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
James Cook | 01e3e5ef | 2019-04-09 14:44:38 | [diff] [blame] | 398 | #include "chrome/common/chrome_descriptors.h" |
Joshua Peraza | 934e559 | 2018-07-18 23:43:11 | [diff] [blame] | 399 | #include "components/crash/content/browser/child_exit_observer_android.h" |
Yuzu Saijo | 2d12ef9 | 2018-08-21 04:52:07 | [diff] [blame] | 400 | #include "components/crash/content/browser/crash_memory_metrics_collector_android.h" |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 401 | #include "components/navigation_interception/intercept_navigation_delegate.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 402 | #include "content/public/browser/android/java_interfaces.h" |
mfomitchev | 220b856 | 2017-07-13 23:08:54 | [diff] [blame] | 403 | #include "services/service_manager/public/cpp/interface_provider.h" |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 404 | #include "ui/base/resource/resource_bundle_android.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 405 | #include "ui/base/ui_base_paths.h" |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 406 | #if BUILDFLAG(DFMIFY_DEV_UI) |
Samuel Huang | 3a1ce1c3 | 2019-10-16 17:34:04 | [diff] [blame] | 407 | #include "chrome/browser/dev_ui/android/dev_ui_loader_throttle.h" |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 408 | #endif // BUILDFLAG(DFMIFY_DEV_UI) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 409 | #elif defined(OS_POSIX) |
| 410 | #include "chrome/browser/chrome_browser_main_posix.h" |
| 411 | #endif |
| 412 | |
tmartino | fb34188 | 2017-02-10 19:36:53 | [diff] [blame] | 413 | #if !defined(OS_ANDROID) |
Jay Harris | 1ddcffa | 2019-07-09 03:07:40 | [diff] [blame] | 414 | #include "chrome/browser/badging/badge_manager.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 415 | #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 416 | #include "chrome/browser/devtools/devtools_window.h" |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 417 | #include "chrome/browser/media/unified_autoplay_config.h" |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 418 | #include "chrome/browser/search/instant_service.h" |
| 419 | #include "chrome/browser/search/instant_service_factory.h" |
Reilly Grant | 2814fb7 | 2019-03-19 17:04:46 | [diff] [blame] | 420 | #include "chrome/browser/serial/chrome_serial_delegate.h" |
Collin Baker | 8a21755 | 2019-05-29 19:47:51 | [diff] [blame] | 421 | #include "chrome/browser/ui/browser.h" |
| 422 | #include "chrome/browser/ui/browser_finder.h" |
| 423 | #include "chrome/browser/ui/browser_list.h" |
| 424 | #include "chrome/browser/ui/browser_window.h" |
jdoerrie | 4f9376f | 2018-12-12 18:26:20 | [diff] [blame] | 425 | #include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h" |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 426 | #include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h" |
Nina Satragno | 8c832df | 2019-07-29 15:59:39 | [diff] [blame] | 427 | #include "chrome/browser/webauthn/authenticator_request_scheduler.h" |
| 428 | #include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h" |
Jay Civelli | 4d53be9b | 2017-08-31 22:01:43 | [diff] [blame] | 429 | #include "chrome/common/importer/profile_import.mojom.h" |
Austin Orion | e250d01 | 2019-05-29 02:56:27 | [diff] [blame] | 430 | #include "chrome/grit/chrome_unscaled_resources.h" |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 431 | #endif // !defined(OS_ANDROID) |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 432 | |
Nicolas Ouellet-Payeur | bdcab009 | 2018-10-22 14:50:33 | [diff] [blame] | 433 | #if defined(OS_WIN) || defined(OS_MACOSX) || \ |
| 434 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
Nicolas Ouellet-Payeur | 4b840a9 | 2018-09-18 14:46:52 | [diff] [blame] | 435 | #include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h" |
Guido Urdaneta | d06ae84 | 2019-10-10 20:04:12 | [diff] [blame] | 436 | #include "services/service_manager/sandbox/features.h" |
Nicolas Ouellet-Payeur | 4b840a9 | 2018-09-18 14:46:52 | [diff] [blame] | 437 | #endif |
| 438 | |
Joshua Peraza | ce68e2f | 2019-09-23 18:44:24 | [diff] [blame] | 439 | #if defined(OS_LINUX) |
| 440 | #include "components/crash/content/app/crash_switches.h" |
| 441 | #include "components/crash/content/app/crashpad.h" |
| 442 | #endif |
| 443 | |
[email protected] | a220b593 | 2013-09-21 03:47:44 | [diff] [blame] | 444 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 445 | #if !defined(OS_ANDROID) |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 446 | #include "base/debug/leak_annotations.h" |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 447 | #include "components/crash/content/app/breakpad_linux.h" |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 448 | #endif // !defined(OS_ANDROID) |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 449 | #include "components/crash/content/browser/crash_handler_host_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 450 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 451 | |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 452 | // TODO(crbug.com/939205): Once the upcoming App Service is available, use a |
| 453 | // single navigation throttle to display the intent picker on all platforms. |
| 454 | #if !defined(OS_ANDROID) |
| 455 | #if defined(OS_CHROMEOS) |
| 456 | #include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h" |
Maggie Cai | 00e2a21e | 2019-10-16 00:47:51 | [diff] [blame] | 457 | #include "chrome/browser/chromeos/apps/intent_helper/common_apps_navigation_throttle.h" |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 458 | #else |
| 459 | #include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h" |
| 460 | #endif |
| 461 | #endif |
| 462 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 463 | #if defined(TOOLKIT_VIEWS) |
| 464 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h" |
| 465 | #endif |
| 466 | |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 467 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 468 | #if defined(USE_X11) |
| 469 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux_x11.h" |
| 470 | #else |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 471 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h" |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 472 | #endif // USE_X11 |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 473 | #endif |
| 474 | |
Mohsen Izadi | f1958f2 | 2019-01-18 20:29:31 | [diff] [blame] | 475 | #if defined(USE_OZONE) |
| 476 | #include "ui/ozone/public/ozone_platform.h" |
| 477 | #endif |
| 478 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 479 | #if defined(USE_X11) |
| 480 | #include "chrome/browser/chrome_browser_main_extra_parts_x11.h" |
| 481 | #endif |
| 482 | |
brettw | ab78fef | 2016-10-12 02:56:05 | [diff] [blame] | 483 | #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
[email protected] | 7a2a6d80 | 2014-06-06 13:39:19 | [diff] [blame] | 484 | #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 485 | #endif |
| 486 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 487 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 488 | #include "components/nacl/browser/nacl_browser.h" |
| 489 | #include "components/nacl/browser/nacl_host_message_filter.h" |
| 490 | #include "components/nacl/browser/nacl_process_host.h" |
| 491 | #include "components/nacl/common/nacl_process_type.h" |
| 492 | #include "components/nacl/common/nacl_switches.h" |
| 493 | #endif |
| 494 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 495 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 496 | #include "chrome/browser/accessibility/animation_policy_prefs.h" |
Dominick Ng | 6ff5105 | 2018-07-06 05:30:20 | [diff] [blame] | 497 | #include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h" |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 498 | #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 499 | #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
Pavol Marko | 41c37b1 | 2019-08-07 10:56:32 | [diff] [blame] | 500 | #include "chrome/browser/extensions/extension_util.h" |
Clark DuVall | 2cf99249e | 2018-09-19 19:11:51 | [diff] [blame] | 501 | #include "chrome/browser/extensions/user_script_listener.h" |
| 502 | #include "chrome/browser/media/cast_transport_host_filter.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 503 | #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" |
Evan Stade | 1e71d6dd | 2019-10-29 03:04:49 | [diff] [blame] | 504 | #include "chrome/browser/ui/browser_commands.h" |
Eric Willigers | 007ef30 | 2019-08-29 09:58:46 | [diff] [blame] | 505 | #include "chrome/browser/ui/web_applications/app_browser_controller.h" |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 506 | #include "components/guest_view/browser/guest_view_base.h" |
| 507 | #include "components/guest_view/browser/guest_view_manager.h" |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 508 | #include "extensions/browser/api/web_request/web_request_api.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 509 | #include "extensions/browser/extension_host.h" |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 510 | #include "extensions/browser/extension_navigation_throttle.h" |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 511 | #include "extensions/browser/extension_protocols.h" |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 512 | #include "extensions/browser/extension_registry.h" |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 513 | #include "extensions/browser/extension_system.h" |
hanxi | 0d0a1e9 | 2014-08-26 18:39:48 | [diff] [blame] | 514 | #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 515 | #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
| 516 | #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 517 | #include "extensions/browser/process_manager.h" |
Dan Beam | 836c02a | 2019-06-15 01:58:27 | [diff] [blame] | 518 | #include "extensions/common/constants.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 519 | #include "extensions/common/extension.h" |
| 520 | #include "extensions/common/extension_set.h" |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 521 | #include "extensions/common/manifest_handlers/background_info.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 522 | #include "extensions/common/manifest_handlers/shared_module_info.h" |
Clark DuVall | bf7722f | 2018-08-03 18:03:33 | [diff] [blame] | 523 | #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 524 | #include "extensions/common/permissions/permissions_data.h" |
| 525 | #include "extensions/common/permissions/socket_permission.h" |
| 526 | #include "extensions/common/switches.h" |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 527 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
merkin | db10455e | 2017-02-28 13:16:25 | [diff] [blame] | 528 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 529 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 530 | #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h" |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 531 | #include "chrome/browser/plugins/flash_download_interception.h" |
John Abd-El-Malek | ecc6f5f | 2018-03-02 18:47:39 | [diff] [blame] | 532 | #include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h" |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 533 | #endif |
| 534 | |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 535 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 536 | #include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h" |
| 537 | #endif |
| 538 | |
yilkal | 240b4f2 | 2019-11-27 19:09:06 | [diff] [blame] | 539 | #if defined(OS_CHROMEOS) |
| 540 | #include "chrome/browser/chromeos/child_accounts/time_limits/web_time_limit_navigation_throttle.h" |
| 541 | #endif // defined(OS_CHROMEOS) |
| 542 | |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 543 | #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 544 | #include "chrome/browser/media/cast_remoting_connector.h" |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 545 | #endif |
| 546 | |
weili | fabbf757 | 2017-05-22 19:05:16 | [diff] [blame] | 547 | #if BUILDFLAG(ENABLE_PRINTING) |
Lei Zhang | a2fa14c | 2018-05-15 00:05:21 | [diff] [blame] | 548 | #include "chrome/browser/printing/printing_message_filter.h" |
weili | fabbf757 | 2017-05-22 19:05:16 | [diff] [blame] | 549 | #endif |
Lei Zhang | a2fa14c | 2018-05-15 00:05:21 | [diff] [blame] | 550 | |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 551 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c86d76e4 | 2016-03-14 23:38:49 | [diff] [blame] | 552 | #include "chrome/browser/media/output_protection_impl.h" |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 553 | #if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 554 | #include "chrome/browser/media/widevine_hardware_caps_win.h" |
| 555 | #include "third_party/widevine/cdm/widevine_cdm_common.h" |
| 556 | #endif |
| 557 | #endif |
| 558 | |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 559 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 560 | #include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h" |
| 561 | #endif |
| 562 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 563 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
Daniel Rubery | a1611e3 | 2019-04-24 21:38:35 | [diff] [blame] | 564 | #include "chrome/browser/safe_browsing/chrome_password_protection_service.h" |
| 565 | #endif |
| 566 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 567 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 568 | #include "chrome/browser/offline_pages/offline_page_tab_helper.h" |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 569 | #include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h" |
| 570 | #endif |
| 571 | |
Will Cassella | 40837ba | 2019-07-01 21:32:00 | [diff] [blame] | 572 | #if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID) |
Bill Orr | eb42922 | 2018-08-08 21:14:43 | [diff] [blame] | 573 | #include "device/vr/public/mojom/isolated_xr_service.mojom.h" |
| 574 | #endif |
| 575 | |
John Lee | 0ee748bf | 2019-12-11 21:35:44 | [diff] [blame] | 576 | #if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP) |
| 577 | #include "chrome/browser/ui/webui/tab_strip/chrome_content_browser_client_tab_strip_part.h" |
| 578 | #endif |
| 579 | |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 580 | using base::FileDescriptor; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 581 | using content::BrowserThread; |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 582 | using content::BrowserURLHandler; |
msramek | a3c7cfd | 2017-02-03 13:34:13 | [diff] [blame] | 583 | using content::BrowsingDataFilterBuilder; |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 584 | using content::ChildProcessSecurityPolicy; |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 585 | using content::QuotaPermissionContext; |
[email protected] | 2626d14 | 2014-04-22 17:24:02 | [diff] [blame] | 586 | using content::RenderFrameHost; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 587 | using content::RenderViewHost; |
[email protected] | 7491ad0 | 2014-07-05 19:10:07 | [diff] [blame] | 588 | using content::ResourceType; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 589 | using content::SiteInstance; |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 590 | using content::WebContents; |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 591 | using content::WebPreferences; |
[email protected] | 593d2a7 | 2013-07-26 08:48:38 | [diff] [blame] | 592 | using message_center::NotifierId; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 593 | |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 594 | #if defined(OS_POSIX) |
brettw | 3c98c7d3 | 2017-07-25 01:44:20 | [diff] [blame] | 595 | using content::PosixFileDescriptorInfo; |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 596 | #endif |
| 597 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 598 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 599 | using extensions::APIPermission; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 600 | using extensions::ChromeContentBrowserClientExtensionsPart; |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 601 | using extensions::Extension; |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 602 | using extensions::Manifest; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 603 | #endif |
| 604 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 605 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 606 | using plugins::ChromeContentBrowserClientPluginsPart; |
| 607 | #endif |
| 608 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 609 | namespace { |
| 610 | |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 611 | const storage::QuotaSettings* g_default_quota_settings; |
| 612 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 613 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 614 | // TODO(teravest): Add renderer-side API-specific checking for these APIs so |
| 615 | // that blanket permission isn't granted to all dev channel APIs for these. |
| 616 | // http://crbug.com/386743 |
| 617 | const char* const kPredefinedAllowedDevChannelOrigins[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 618 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937 |
| 619 | "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937 |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 620 | }; |
| 621 | |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 622 | const char* const kPredefinedAllowedFileHandleOrigins[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 623 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789 |
| 624 | "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789 |
[email protected] | 10c3922 | 2013-11-13 20:09:25 | [diff] [blame] | 625 | }; |
| 626 | |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 627 | const char* const kPredefinedAllowedSocketOrigins[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 628 | "okddffdblfhhnmhodogpojmfkjmhinfp", // Secure Shell App (dev) |
| 629 | "pnhechapfaindjhompbnflcldabbghjo", // Secure Shell App (stable) |
| 630 | "algkcnfjnajfhgimadimbjhmpaeohhln", // Secure Shell Extension (dev) |
| 631 | "iodihamcpbpeioajjeobimgagajmlibd", // Secure Shell Extension (stable) |
| 632 | "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126 |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 633 | "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 |
| 634 | "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 |
| 635 | "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099 |
| 636 | "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099 |
| 637 | "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099 |
| 638 | "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099 |
| 639 | "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099 |
| 640 | "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514 |
| 641 | "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080 |
| 642 | "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080 |
| 643 | "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084 |
| 644 | "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084 |
| 645 | "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084 |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 646 | }; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 647 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 648 | |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 649 | #if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 650 | // Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when |
| 651 | // running on Windows 10 1511 and above. See |
| 652 | // https://blogs.windows.com/blog/tag/code-integrity-guard/. |
| 653 | const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity", |
Will Harris | a9eaa28 | 2019-11-01 17:51:35 | [diff] [blame] | 654 | base::FEATURE_ENABLED_BY_DEFAULT}; |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 655 | #endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) && |
| 656 | // !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 657 | |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 658 | enum AppLoadedInTabSource { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 659 | // 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] | 660 | APP_LOADED_IN_TAB_SOURCE_APP = 0, |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 661 | |
| 662 | // 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] | 663 | APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE, |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 664 | |
| 665 | // An extension or app tried to load a resource of a different platform app in |
| 666 | // a tab. |
| 667 | APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION, |
| 668 | |
| 669 | // A non-app and non-extension page tried to load a platform app in a tab. |
| 670 | APP_LOADED_IN_TAB_SOURCE_OTHER, |
| 671 | |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 672 | APP_LOADED_IN_TAB_SOURCE_MAX |
| 673 | }; |
| 674 | |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 675 | // Cached version of the locale so we can return the locale on the I/O |
| 676 | // thread. |
| 677 | std::string& GetIOThreadApplicationLocale() { |
| 678 | static base::NoDestructor<std::string> s; |
| 679 | return *s; |
| 680 | } |
| 681 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 682 | // Returns a copy of the given url with its host set to given host and path set |
| 683 | // to given path. Other parts of the url will be the same. |
| 684 | GURL ReplaceURLHostAndPath(const GURL& url, |
| 685 | const std::string& host, |
| 686 | const std::string& path) { |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 687 | url::Replacements<char> replacements; |
| 688 | replacements.SetHost(host.c_str(), url::Component(0, host.length())); |
| 689 | replacements.SetPath(path.c_str(), url::Component(0, path.length())); |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 690 | return url.ReplaceComponents(replacements); |
| 691 | } |
| 692 | |
mad | fbd1085 | 2017-01-20 03:15:33 | [diff] [blame] | 693 | // Handles the rewriting of the new tab page URL based on group policy. |
| 694 | bool HandleNewTabPageLocationOverride( |
| 695 | GURL* url, |
| 696 | content::BrowserContext* browser_context) { |
| 697 | if (!url->SchemeIs(content::kChromeUIScheme) || |
| 698 | url->host() != chrome::kChromeUINewTabHost) |
| 699 | return false; |
| 700 | |
| 701 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 702 | std::string ntp_location = |
| 703 | profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride); |
| 704 | if (ntp_location.empty()) |
| 705 | return false; |
| 706 | |
| 707 | *url = GURL(ntp_location); |
| 708 | return true; |
| 709 | } |
| 710 | |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 711 | #if !defined(OS_ANDROID) |
| 712 | // Check if the current url is whitelisted based on a list of whitelisted urls. |
| 713 | bool IsURLWhitelisted(const GURL& current_url, |
Jan Wilken Dörrie | 8d9034f1 | 2019-11-28 14:48:57 | [diff] [blame] | 714 | base::Value::ConstListView whitelisted_urls) { |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 715 | // Only check on HTTP and HTTPS pages. |
| 716 | if (!current_url.SchemeIsHTTPOrHTTPS()) |
| 717 | return false; |
| 718 | |
| 719 | for (auto const& value : whitelisted_urls) { |
| 720 | ContentSettingsPattern pattern = |
| 721 | ContentSettingsPattern::FromString(value.GetString()); |
| 722 | if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid()) |
| 723 | continue; |
| 724 | if (pattern.Matches(current_url)) |
| 725 | return true; |
| 726 | } |
| 727 | |
| 728 | return false; |
| 729 | } |
| 730 | |
| 731 | // Check if autoplay is allowed by policy configuration. |
| 732 | bool IsAutoplayAllowedByPolicy(content::WebContents* contents, |
| 733 | PrefService* prefs) { |
| 734 | DCHECK(prefs); |
| 735 | |
| 736 | // Check if we have globally allowed autoplay by policy. |
| 737 | if (prefs->GetBoolean(prefs::kAutoplayAllowed) && |
| 738 | prefs->IsManagedPreference(prefs::kAutoplayAllowed)) { |
| 739 | return true; |
| 740 | } |
| 741 | |
| 742 | if (!contents) |
| 743 | return false; |
| 744 | |
| 745 | // Check if the current URL matches a URL pattern on the whitelist. |
| 746 | const base::ListValue* autoplay_whitelist = |
| 747 | prefs->GetList(prefs::kAutoplayWhitelist); |
| 748 | return autoplay_whitelist && |
| 749 | prefs->IsManagedPreference(prefs::kAutoplayWhitelist) && |
| 750 | IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList()); |
| 751 | } |
| 752 | #endif |
| 753 | |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 754 | #if defined(OS_ANDROID) |
| 755 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
| 756 | return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket(); |
| 757 | } |
| 758 | #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 759 | breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( |
| 760 | const std::string& process_type) { |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 761 | base::FilePath dumps_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 762 | base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 763 | { |
| 764 | ANNOTATE_SCOPED_MEMORY_LEAK; |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 765 | bool upload = !getenv(env_vars::kHeadless); |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 766 | breakpad::CrashHandlerHostLinux* crash_handler = |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 767 | new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 768 | crash_handler->StartUploaderThread(); |
| 769 | return crash_handler; |
| 770 | } |
| 771 | } |
| 772 | |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 773 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
Joshua Peraza | ce68e2f | 2019-09-23 18:44:24 | [diff] [blame] | 774 | if (crash_reporter::IsCrashpadEnabled()) { |
| 775 | int fd; |
| 776 | pid_t pid; |
| 777 | return crash_reporter::GetHandlerSocket(&fd, &pid) ? fd : -1; |
| 778 | } |
| 779 | |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 780 | // Extensions have the same process type as renderers. |
[email protected] | cd0f7af | 2014-01-16 23:50:39 | [diff] [blame] | 781 | if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 782 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 783 | if (!crash_handler) |
| 784 | crash_handler = CreateCrashHandlerHost("extension"); |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 785 | return crash_handler->GetDeathSignalSocket(); |
| 786 | } |
| 787 | |
| 788 | std::string process_type = |
| 789 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 790 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 791 | if (process_type == switches::kRendererProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 792 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 793 | if (!crash_handler) |
| 794 | crash_handler = CreateCrashHandlerHost(process_type); |
| 795 | return crash_handler->GetDeathSignalSocket(); |
| 796 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 797 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 798 | if (process_type == switches::kPpapiPluginProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 799 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 800 | if (!crash_handler) |
| 801 | crash_handler = CreateCrashHandlerHost(process_type); |
| 802 | return crash_handler->GetDeathSignalSocket(); |
| 803 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 804 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 805 | if (process_type == switches::kGpuProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 806 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 807 | if (!crash_handler) |
| 808 | crash_handler = CreateCrashHandlerHost(process_type); |
| 809 | return crash_handler->GetDeathSignalSocket(); |
| 810 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 811 | |
James Cook | 9207cc1 | 2017-10-19 17:08:39 | [diff] [blame] | 812 | if (process_type == switches::kUtilityProcess) { |
| 813 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
| 814 | if (!crash_handler) |
| 815 | crash_handler = CreateCrashHandlerHost(process_type); |
| 816 | return crash_handler->GetDeathSignalSocket(); |
| 817 | } |
| 818 | |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 819 | return -1; |
| 820 | } |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 821 | #endif // defined(OS_ANDROID) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 822 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 823 | void SetApplicationLocaleOnIOThread(const std::string& locale) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 824 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 825 | GetIOThreadApplicationLocale() = locale; |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 826 | } |
| 827 | |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 828 | // An implementation of the SSLCertReporter interface used by |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 829 | // SSLErrorHandler. Uses CertificateReportingService to send reports. The |
| 830 | // service handles queueing and re-sending of failed reports. Each certificate |
| 831 | // error creates a new instance of this class. |
| 832 | class CertificateReportingServiceCertReporter : public SSLCertReporter { |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 833 | public: |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 834 | explicit CertificateReportingServiceCertReporter( |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 835 | content::WebContents* web_contents) |
| 836 | : service_(CertificateReportingServiceFactory::GetForBrowserContext( |
| 837 | web_contents->GetBrowserContext())) {} |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 838 | ~CertificateReportingServiceCertReporter() override {} |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 839 | |
| 840 | // SSLCertReporter implementation |
estark | 4282f117 | 2015-05-13 22:01:55 | [diff] [blame] | 841 | void ReportInvalidCertificateChain( |
| 842 | const std::string& serialized_report) override { |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 843 | service_->Send(serialized_report); |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | private: |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 847 | CertificateReportingService* service_; |
| 848 | |
| 849 | DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter); |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 850 | }; |
| 851 | |
bshe | 4f53ce4 | 2015-11-30 16:56:31 | [diff] [blame] | 852 | #if defined(OS_ANDROID) |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 853 | float GetDeviceScaleAdjustment() { |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 854 | static const float kMinFSM = 1.05f; |
| 855 | static const int kWidthForMinFSM = 320; |
| 856 | static const float kMaxFSM = 1.3f; |
| 857 | static const int kWidthForMaxFSM = 800; |
| 858 | |
boliu | 21c5afa | 2017-01-11 19:34:23 | [diff] [blame] | 859 | int minWidth = chrome::android::ChromeContextUtil::GetSmallestDIPWidth(); |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 860 | |
| 861 | if (minWidth <= kWidthForMinFSM) |
| 862 | return kMinFSM; |
| 863 | if (minWidth >= kWidthForMaxFSM) |
| 864 | return kMaxFSM; |
| 865 | |
| 866 | // The font scale multiplier varies linearly between kMinFSM and kMaxFSM. |
| 867 | float ratio = static_cast<float>(minWidth - kWidthForMinFSM) / |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 868 | (kWidthForMaxFSM - kWidthForMinFSM); |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 869 | return ratio * (kMaxFSM - kMinFSM) + kMinFSM; |
| 870 | } |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 871 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 872 | #endif // defined(OS_ANDROID) |
| 873 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 874 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 875 | |
| 876 | AppLoadedInTabSource ClassifyAppLoadedInTabSource( |
| 877 | const GURL& opener_url, |
| 878 | const extensions::Extension* target_platform_app) { |
Lei Zhang | 7d0b0f4 | 2019-10-12 03:47:58 | [diff] [blame] | 879 | if (!opener_url.SchemeIs(extensions::kExtensionScheme)) { |
| 880 | // The forbidden app URL was being opened by a non-extension page (e.g. |
| 881 | // http). |
| 882 | return APP_LOADED_IN_TAB_SOURCE_OTHER; |
| 883 | } |
| 884 | |
| 885 | if (opener_url.host_piece() != target_platform_app->id()) { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 886 | // The forbidden app URL was being opened by a different app or extension. |
| 887 | return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION; |
| 888 | } |
Lei Zhang | 7d0b0f4 | 2019-10-12 03:47:58 | [diff] [blame] | 889 | |
| 890 | // This platform app was trying to window.open() one of its own URLs. |
| 891 | if (opener_url == |
| 892 | extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) { |
| 893 | // Source was the background page. |
| 894 | return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE; |
| 895 | } |
| 896 | |
| 897 | // Source was a different page inside the app. |
| 898 | return APP_LOADED_IN_TAB_SOURCE_APP; |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 899 | } |
[email protected] | 9c765638 | 2014-08-08 21:02:30 | [diff] [blame] | 900 | |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 901 | // Returns true if there is is an extension matching |url| in |
| 902 | // |opener_render_process_id| with APIPermission::kBackground. |
| 903 | // |
| 904 | // Note that GetExtensionOrAppByURL requires a full URL in order to match with a |
| 905 | // hosted app, even though normal extensions just use the host. |
| 906 | bool URLHasExtensionBackgroundPermission( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 907 | extensions::ProcessMap* process_map, |
| 908 | extensions::ExtensionRegistry* registry, |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 909 | const GURL& url, |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 910 | int opener_render_process_id) { |
| 911 | // Note: includes web URLs that are part of an extension's web extent. |
| 912 | const Extension* extension = |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 913 | registry->enabled_extensions().GetExtensionOrAppByURL(url); |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 914 | return extension && |
| 915 | extension->permissions_data()->HasAPIPermission( |
| 916 | APIPermission::kBackground) && |
| 917 | process_map->Contains(extension->id(), opener_render_process_id); |
| 918 | } |
Kevin Marshall | 32f99d7e | 2017-07-11 23:17:46 | [diff] [blame] | 919 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 920 | #endif |
| 921 | |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 922 | chrome::mojom::PrerenderCanceler* GetPrerenderCanceller( |
| 923 | const base::Callback<content::WebContents*()>& wc_getter) { |
| 924 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 925 | auto* web_contents = wc_getter.Run(); |
| 926 | if (!web_contents) |
| 927 | return nullptr; |
| 928 | |
| 929 | return prerender::PrerenderContents::FromWebContents(web_contents); |
| 930 | } |
| 931 | |
John Abd-El-Malek | 92bf360 | 2019-07-31 02:25:48 | [diff] [blame] | 932 | void LaunchURL(const GURL& url, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 933 | content::WebContents::OnceGetter web_contents_getter, |
John Abd-El-Malek | 92bf360 | 2019-07-31 02:25:48 | [diff] [blame] | 934 | ui::PageTransition page_transition, |
Emily Stark | 13b66bdf | 2019-10-04 17:11:45 | [diff] [blame] | 935 | bool has_user_gesture, |
| 936 | const base::Optional<url::Origin>& initiating_origin) { |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 937 | // If there is no longer a WebContents, the request may have raced with tab |
| 938 | // closing. Don't fire the external request. (It may have been a prerender.) |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 939 | content::WebContents* web_contents = std::move(web_contents_getter).Run(); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 940 | if (!web_contents) |
| 941 | return; |
| 942 | |
| 943 | // Do not launch external requests attached to unswapped prerenders. |
| 944 | prerender::PrerenderContents* prerender_contents = |
| 945 | prerender::PrerenderContents::FromWebContents(web_contents); |
| 946 | if (prerender_contents) { |
| 947 | prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); |
| 948 | prerender::ReportPrerenderExternalURL(); |
| 949 | return; |
| 950 | } |
| 951 | |
Robbie McElrath | 1294d24 | 2019-05-31 20:46:22 | [diff] [blame] | 952 | // Do not launch external requests for schemes that have a handler registered. |
| 953 | ProtocolHandlerRegistry* protocol_handler_registry = |
| 954 | ProtocolHandlerRegistryFactory::GetForBrowserContext( |
| 955 | web_contents->GetBrowserContext()); |
| 956 | if (protocol_handler_registry && |
| 957 | protocol_handler_registry->IsHandledProtocol(url.scheme())) |
| 958 | return; |
| 959 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 960 | bool is_whitelisted = false; |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 961 | PolicyBlacklistService* service = |
Oleg Davydov | 5cfe7ab | 2019-02-01 12:27:19 | [diff] [blame] | 962 | PolicyBlacklistFactory::GetForBrowserContext( |
| 963 | web_contents->GetBrowserContext()); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 964 | if (service) { |
| 965 | const policy::URLBlacklist::URLBlacklistState url_state = |
| 966 | service->GetURLBlacklistState(url); |
| 967 | is_whitelisted = |
| 968 | url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST; |
| 969 | } |
| 970 | |
| 971 | // If the URL is in whitelist, we launch it without asking the user and |
| 972 | // without any additional security checks. Since the URL is whitelisted, |
| 973 | // we assume it can be executed. |
| 974 | if (is_whitelisted) { |
| 975 | ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents); |
| 976 | } else { |
| 977 | ExternalProtocolHandler::LaunchUrl( |
| 978 | url, web_contents->GetRenderViewHost()->GetProcess()->GetID(), |
| 979 | web_contents->GetRenderViewHost()->GetRoutingID(), page_transition, |
Emily Stark | 13b66bdf | 2019-10-04 17:11:45 | [diff] [blame] | 980 | has_user_gesture, initiating_origin); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 981 | } |
| 982 | } |
| 983 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 984 | std::string GetProduct() { |
| 985 | return version_info::GetProductNameAndVersionForUserAgent(); |
| 986 | } |
| 987 | |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 988 | void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) { |
| 989 | // |allowlist| combines pref/policy + cmdline switch in the browser process. |
| 990 | // For renderer and utility (e.g. NetworkService) processes the switch is the |
| 991 | // only available source, so below the combined (pref/policy + cmdline) |
| 992 | // allowlist of secure origins is injected into |cmdline| for these other |
| 993 | // processes. |
| 994 | std::vector<std::string> allowlist = |
| 995 | network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist(); |
| 996 | if (!allowlist.empty()) { |
| 997 | cmdline->AppendSwitchASCII( |
| 998 | network::switches::kUnsafelyTreatInsecureOriginAsSecure, |
| 999 | base::JoinString(allowlist, ",")); |
| 1000 | } |
| 1001 | } |
| 1002 | |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 1003 | #if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 1004 | // Returns the full path to |module_name|. Both dev builds (where |module_name| |
| 1005 | // is in the current executable's directory) and proper installs (where |
| 1006 | // |module_name| is in a versioned sub-directory of the current executable's |
| 1007 | // directory) are supported. The identified file is not guaranteed to exist. |
| 1008 | base::FilePath GetModulePath(base::StringPiece16 module_name) { |
| 1009 | base::FilePath exe_dir; |
| 1010 | const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir); |
| 1011 | DCHECK(has_path); |
| 1012 | |
| 1013 | // Look for the module in a versioned sub-directory of the current |
| 1014 | // executable's directory and return the path if it can be read. This is the |
| 1015 | // expected location of modules for proper installs. |
| 1016 | const base::FilePath module_path = |
| 1017 | exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name); |
| 1018 | if (base::PathExists(module_path)) |
| 1019 | return module_path; |
| 1020 | |
| 1021 | // Otherwise, return the path to the module in the current executable's |
| 1022 | // directory. This is the expected location of modules for dev builds. |
| 1023 | return exe_dir.Append(module_name); |
| 1024 | } |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 1025 | #endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) && |
| 1026 | // !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 1027 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 1028 | void MaybeAddThrottle( |
| 1029 | std::vector<std::unique_ptr<content::NavigationThrottle>>* throttles, |
| 1030 | std::unique_ptr<content::NavigationThrottle> maybe_throttle) { |
| 1031 | if (maybe_throttle) |
| 1032 | throttles->push_back(std::move(maybe_throttle)); |
| 1033 | } |
| 1034 | |
Evan Stade | 1e71d6dd | 2019-10-29 03:04:49 | [diff] [blame] | 1035 | // Returns whether |web_contents| is within a hosted app. |
| 1036 | bool IsInHostedApp(WebContents* web_contents) { |
| 1037 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1038 | Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 1039 | return (browser && |
| 1040 | web_app::AppBrowserController::IsForWebAppBrowser(browser)); |
| 1041 | #else |
| 1042 | return false; |
| 1043 | #endif |
| 1044 | } |
| 1045 | |
Lily Chen | c2c9e9f | 2019-12-05 19:55:31 | [diff] [blame] | 1046 | void MaybeRecordSameSiteCookieEngagementHistogram( |
| 1047 | content::RenderFrameHost* render_frame_host, |
| 1048 | blink::mojom::WebFeature feature) { |
| 1049 | if (feature != blink::mojom::WebFeature::kCookieNoSameSite && |
| 1050 | feature != blink::mojom::WebFeature::kCookieInsecureAndSameSiteNone) { |
| 1051 | return; |
| 1052 | } |
| 1053 | |
| 1054 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 1055 | DCHECK(render_frame_host); |
| 1056 | |
| 1057 | content::BrowserContext* browser_context = |
| 1058 | WebContents::FromRenderFrameHost(render_frame_host)->GetBrowserContext(); |
| 1059 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1060 | SiteEngagementService* site_engagement_service = |
| 1061 | SiteEngagementService::Get(profile); |
| 1062 | if (!site_engagement_service) |
| 1063 | return; |
| 1064 | |
| 1065 | blink::mojom::EngagementLevel engagement_level = |
| 1066 | site_engagement_service->GetEngagementLevel( |
| 1067 | render_frame_host->GetLastCommittedURL()); |
| 1068 | if (feature == blink::mojom::WebFeature::kCookieNoSameSite) { |
| 1069 | UMA_HISTOGRAM_ENUMERATION( |
| 1070 | "Net.SameSiteBlockedCookieSiteEngagement.CookieNoSameSite", |
| 1071 | engagement_level); |
| 1072 | } else { |
| 1073 | UMA_HISTOGRAM_ENUMERATION( |
| 1074 | "Net.SameSiteBlockedCookieSiteEngagement." |
| 1075 | "CookieInsecureAndSameSiteNone", |
| 1076 | engagement_level); |
| 1077 | } |
| 1078 | } |
| 1079 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 1080 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 1081 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1082 | std::string GetUserAgent() { |
| 1083 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1084 | if (command_line->HasSwitch(switches::kUserAgent)) { |
| 1085 | std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent); |
| 1086 | if (net::HttpUtil::IsValidHeaderValue(ua)) |
| 1087 | return ua; |
| 1088 | LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent; |
| 1089 | } |
| 1090 | |
John Delaney | ac24e57 | 2019-04-30 19:47:02 | [diff] [blame] | 1091 | if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) { |
| 1092 | return content::GetFrozenUserAgent( |
| 1093 | command_line->HasSwitch(switches::kUseMobileUserAgent)) |
| 1094 | .as_string(); |
| 1095 | } |
| 1096 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1097 | std::string product = GetProduct(); |
| 1098 | #if defined(OS_ANDROID) |
| 1099 | if (command_line->HasSwitch(switches::kUseMobileUserAgent)) |
| 1100 | product += " Mobile"; |
| 1101 | #endif |
| 1102 | return content::BuildUserAgentFromProduct(product); |
| 1103 | } |
| 1104 | |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1105 | blink::UserAgentMetadata GetUserAgentMetadata() { |
| 1106 | blink::UserAgentMetadata metadata; |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1107 | metadata.brand = version_info::GetProductName(); |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 1108 | metadata.full_version = version_info::GetVersionNumber(); |
| 1109 | metadata.major_version = version_info::GetMajorVersionNumber(); |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1110 | metadata.platform = version_info::GetOSType(); |
Aaron Tagliaboschi | cb8d3ee | 2019-12-09 19:31:36 | [diff] [blame] | 1111 | metadata.architecture = content::BuildCpuInfo(); |
| 1112 | metadata.model = content::BuildModelInfo(); |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1113 | |
Aaron Tagliaboschi | be775e1 | 2019-12-09 19:33:04 | [diff] [blame] | 1114 | // TODO(crbug.com/1031511): Integrate DevTools and "Request Desktop Site" |
| 1115 | metadata.mobile = false; |
| 1116 | #if defined(OS_ANDROID) |
| 1117 | metadata.mobile = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1118 | switches::kUseMobileUserAgent); |
| 1119 | #endif |
| 1120 | |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1121 | return metadata; |
| 1122 | } |
| 1123 | |
Ran Ji | a96d43d4 | 2018-05-02 17:14:53 | [diff] [blame] | 1124 | ChromeContentBrowserClient::ChromeContentBrowserClient( |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 1125 | StartupData* startup_data) |
Wojciech Dzierżanowski | e7c8e3f | 2019-09-27 20:50:31 | [diff] [blame] | 1126 | : startup_data_(startup_data) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1127 | #if BUILDFLAG(ENABLE_PLUGINS) |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 1128 | for (size_t i = 0; i < base::size(kPredefinedAllowedDevChannelOrigins); ++i) |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 1129 | allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 1130 | for (size_t i = 0; i < base::size(kPredefinedAllowedFileHandleOrigins); ++i) |
[email protected] | 10c3922 | 2013-11-13 20:09:25 | [diff] [blame] | 1131 | allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 1132 | for (size_t i = 0; i < base::size(kPredefinedAllowedSocketOrigins); ++i) |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1133 | allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 1134 | |
| 1135 | extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 1136 | #endif |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 1137 | |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 1138 | #if defined(OS_CHROMEOS) |
| 1139 | extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart); |
| 1140 | #endif // defined(OS_CHROMEOS) |
| 1141 | |
John Lee | 0ee748bf | 2019-12-11 21:35:44 | [diff] [blame] | 1142 | #if BUILDFLAG(ENABLE_WEBUI_TAB_STRIP) |
| 1143 | extra_parts_.push_back(new ChromeContentBrowserClientTabStripPart); |
| 1144 | #endif |
| 1145 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1146 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1147 | extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1148 | #endif |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 1149 | |
Sigurdur Asgeirsson | 7069667 | 2019-02-08 16:14:51 | [diff] [blame] | 1150 | extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | ChromeContentBrowserClient::~ChromeContentBrowserClient() { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1154 | for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i) |
| 1155 | delete extra_parts_[i]; |
| 1156 | extra_parts_.clear(); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1157 | } |
| 1158 | |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 1159 | // static |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1160 | void ChromeContentBrowserClient::RegisterLocalStatePrefs( |
| 1161 | PrefRegistrySimple* registry) { |
Greg Thompson | 8c922756 | 2019-08-05 17:47:13 | [diff] [blame] | 1162 | registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath()); |
| 1163 | registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1164 | registry->RegisterStringPref(prefs::kIsolateOrigins, std::string()); |
| 1165 | registry->RegisterBooleanPref(prefs::kSitePerProcess, false); |
Francois Doray | 424bd99 | 2019-10-16 20:59:46 | [diff] [blame] | 1166 | registry->RegisterBooleanPref(prefs::kTabFreezingEnabled, true); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | // static |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 1170 | void ChromeContentBrowserClient::RegisterProfilePrefs( |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 1171 | user_prefs::PrefRegistrySyncable* registry) { |
raymes | aa60872 | 2015-04-27 03:00:25 | [diff] [blame] | 1172 | registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false); |
| 1173 | registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true); |
| 1174 | registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures); |
Pavol Marko | 6adbea7f | 2018-02-20 16:35:28 | [diff] [blame] | 1175 | // Register user prefs for mapping SitePerProcess and IsolateOrigins in |
| 1176 | // user policy in addition to the same named ones in Local State (which are |
| 1177 | // used for mapping the command-line flags). |
| 1178 | registry->RegisterStringPref(prefs::kIsolateOrigins, std::string()); |
| 1179 | registry->RegisterBooleanPref(prefs::kSitePerProcess, false); |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 1180 | registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins); |
Rayan Kanso | 411e84e | 2019-02-13 15:27:40 | [diff] [blame] | 1181 | registry->RegisterDictionaryPref( |
| 1182 | prefs::kDevToolsBackgroundServicesExpirationDict); |
Kunihiko Sakamoto | f586da6 | 2019-03-28 03:03:04 | [diff] [blame] | 1183 | registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 1184 | #if !defined(OS_ANDROID) |
| 1185 | registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false); |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 1186 | registry->RegisterListPref(prefs::kAutoplayWhitelist); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 1187 | #endif |
Takashi Toyoshima | 12844146 | 2019-10-16 04:19:17 | [diff] [blame] | 1188 | registry->RegisterListPref(prefs::kCorsMitigationList); |
| 1189 | registry->RegisterBooleanPref(prefs::kCorsLegacyModeEnabled, false); |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 1190 | } |
| 1191 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1192 | // static |
| 1193 | void ChromeContentBrowserClient::SetApplicationLocale( |
| 1194 | const std::string& locale) { |
Scott Violet | 875789e | 2018-02-02 07:46:48 | [diff] [blame] | 1195 | // The common case is that this function is called early in Chrome startup |
| 1196 | // before any threads are created or registered. When there are no threads, |
| 1197 | // we can just set the string without worrying about threadsafety. |
Gabriel Charette | 192b8c9 | 2018-03-21 21:16:00 | [diff] [blame] | 1198 | if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) { |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 1199 | GetIOThreadApplicationLocale() = locale; |
Scott Violet | 875789e | 2018-02-02 07:46:48 | [diff] [blame] | 1200 | return; |
| 1201 | } |
| 1202 | |
| 1203 | // Otherwise we're being called to change the locale. In this case set it on |
| 1204 | // the IO thread. |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 1205 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1206 | |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 1207 | base::PostTask(FROM_HERE, {BrowserThread::IO}, |
| 1208 | base::BindOnce(&SetApplicationLocaleOnIOThread, locale)); |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1209 | } |
| 1210 | |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1211 | std::unique_ptr<content::BrowserMainParts> |
| 1212 | ChromeContentBrowserClient::CreateBrowserMainParts( |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1213 | const content::MainFunctionParams& parameters) { |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1214 | std::unique_ptr<ChromeBrowserMainParts> main_parts; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1215 | // Construct the Main browser parts based on the OS type. |
| 1216 | #if defined(OS_WIN) |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 1217 | main_parts = |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1218 | std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_); |
| 1219 | #elif defined(OS_MACOSX) |
| 1220 | main_parts = |
| 1221 | std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_); |
| 1222 | #elif defined(OS_CHROMEOS) |
| 1223 | main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>( |
| 1224 | parameters, startup_data_); |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 1225 | #elif defined(OS_LINUX) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1226 | main_parts = |
| 1227 | std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_); |
[email protected] | 6e677a34 | 2012-02-11 01:21:14 | [diff] [blame] | 1228 | #elif defined(OS_ANDROID) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1229 | main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters, |
| 1230 | startup_data_); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1231 | #elif defined(OS_POSIX) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1232 | main_parts = |
| 1233 | std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1234 | #else |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1235 | NOTREACHED(); |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1236 | main_parts = |
| 1237 | std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1238 | #endif |
| 1239 | |
Xi Han | 9fd4400 | 2019-04-30 17:39:36 | [diff] [blame] | 1240 | bool add_profiles_extra_parts = true; |
| 1241 | #if defined(OS_ANDROID) |
| 1242 | if (startup_data_->HasBuiltProfilePrefService()) |
| 1243 | add_profiles_extra_parts = false; |
| 1244 | #endif |
| 1245 | if (add_profiles_extra_parts) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1246 | chrome::AddProfilesExtraParts(main_parts.get()); |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 1247 | |
Xi Han | 9fd4400 | 2019-04-30 17:39:36 | [diff] [blame] | 1248 | // Construct additional browser parts. Stages are called in the order in |
| 1249 | // which they are added. |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 1250 | #if defined(TOOLKIT_VIEWS) |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 1251 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 1252 | #if defined(USE_X11) |
| 1253 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinuxX11()); |
| 1254 | #else |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 1255 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux()); |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 1256 | #endif // USE_X11 |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 1257 | #else |
riajiang | 7d6ec5c | 2017-01-25 16:40:33 | [diff] [blame] | 1258 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); |
James Cook | f9d34d2 | 2017-10-04 16:39:35 | [diff] [blame] | 1259 | #endif |
| 1260 | #endif |
| 1261 | |
| 1262 | #if defined(OS_CHROMEOS) |
| 1263 | // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos. |
riajiang | 7d6ec5c | 2017-01-25 16:40:33 | [diff] [blame] | 1264 | main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh()); |
sky | cea631e | 2016-12-16 21:52:22 | [diff] [blame] | 1265 | #endif |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 1266 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 1267 | #if defined(USE_X11) |
| 1268 | main_parts->AddParts(new ChromeBrowserMainExtraPartsX11()); |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 1269 | #endif |
| 1270 | |
Sigurdur Asgeirsson | 54b7270 | 2019-04-12 14:18:54 | [diff] [blame] | 1271 | main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager); |
Etienne Bergeron | 05d6253 | 2017-10-13 18:24:00 | [diff] [blame] | 1272 | |
Albert J. Wong | 59d85acb | 2017-08-10 00:50:57 | [diff] [blame] | 1273 | main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling); |
Albert J. Wong | 59d85acb | 2017-08-10 00:50:57 | [diff] [blame] | 1274 | |
Sebastien Marchand | 8c008810 | 2019-10-11 16:47:56 | [diff] [blame] | 1275 | main_parts->AddParts(new ChromeBrowserMainExtraPartsMemory); |
| 1276 | |
Peng Huang | ee82ef8 | 2019-11-22 13:15:29 | [diff] [blame] | 1277 | main_parts->AddParts(new ChromeBrowserMainExtraPartsGpu); |
| 1278 | |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1279 | chrome::AddMetricsExtraParts(main_parts.get()); |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 1280 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1281 | return main_parts; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1282 | } |
| 1283 | |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1284 | void ChromeContentBrowserClient::PostAfterStartupTask( |
Brett Wilson | e1a7042 | 2017-09-12 05:10:09 | [diff] [blame] | 1285 | const base::Location& from_here, |
Gabriel Charette | e926fc1 | 2019-12-16 19:00:02 | [diff] [blame^] | 1286 | const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
tzik | 6e42784 | 2017-04-05 10:13:21 | [diff] [blame] | 1287 | base::OnceClosure task) { |
tzik | 070c8ffb | 2017-03-29 05:28:12 | [diff] [blame] | 1288 | AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task)); |
John Abd-El-Malek | 0e82fe7f | 2019-07-27 00:06:29 | [diff] [blame] | 1289 | |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 1290 | InitNetworkContextsParentDirectory(); |
| 1291 | |
John Abd-El-Malek | 0e82fe7f | 2019-07-27 00:06:29 | [diff] [blame] | 1292 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1293 | safe_browsing_service_ = g_browser_process->safe_browsing_service(); |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1294 | } |
| 1295 | |
falken | b09d443f | 2016-04-07 12:36:12 | [diff] [blame] | 1296 | bool ChromeContentBrowserClient::IsBrowserStartupComplete() { |
| 1297 | return AfterStartupTaskUtils::IsBrowserStartupComplete(); |
| 1298 | } |
| 1299 | |
Gabriel Charette | c8cca99 | 2017-08-10 18:21:49 | [diff] [blame] | 1300 | void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() { |
| 1301 | AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); |
| 1302 | } |
| 1303 | |
John Abd-El-Malek | 9d57f9c | 2019-02-20 18:50:04 | [diff] [blame] | 1304 | bool ChromeContentBrowserClient::IsShuttingDown() { |
Greg Thompson | ae8a5b1 | 2019-11-21 12:35:36 | [diff] [blame] | 1305 | return browser_shutdown::HasShutdownStarted(); |
John Abd-El-Malek | 9d57f9c | 2019-02-20 18:50:04 | [diff] [blame] | 1306 | } |
| 1307 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 1308 | std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1309 | content::BrowserContext* browser_context, |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 1310 | const GURL& site) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1311 | std::string partition_id; |
| 1312 | |
| 1313 | // The partition ID for webview guest processes is the string value of its |
| 1314 | // SiteInstance URL - "chrome-guest://app_id/persist?partition". |
rogerta | 5f5bb82 | 2015-12-17 03:24:45 | [diff] [blame] | 1315 | if (site.SchemeIs(content::kGuestScheme)) |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1316 | partition_id = site.spec(); |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1317 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
blundell | f650ea0 | 2016-02-08 11:50:50 | [diff] [blame] | 1318 | // The partition ID for extensions with isolated storage is treated similarly |
| 1319 | // to the above. |
| 1320 | else if (site.SchemeIs(extensions::kExtensionScheme) && |
| 1321 | extensions::util::SiteHasIsolatedStorage(site, browser_context)) |
| 1322 | partition_id = site.spec(); |
| 1323 | #endif |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1324 | |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 1325 | DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1326 | return partition_id; |
| 1327 | } |
| 1328 | |
| 1329 | bool ChromeContentBrowserClient::IsValidStoragePartitionId( |
| 1330 | content::BrowserContext* browser_context, |
| 1331 | const std::string& partition_id) { |
| 1332 | // The default ID is empty and is always valid. |
| 1333 | if (partition_id.empty()) |
| 1334 | return true; |
| 1335 | |
| 1336 | return GURL(partition_id).is_valid(); |
| 1337 | } |
| 1338 | |
| 1339 | void ChromeContentBrowserClient::GetStoragePartitionConfigForSite( |
| 1340 | content::BrowserContext* browser_context, |
| 1341 | const GURL& site, |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1342 | bool can_be_default, |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1343 | std::string* partition_domain, |
| 1344 | std::string* partition_name, |
| 1345 | bool* in_memory) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1346 | // Default to the browser-wide storage partition and override based on |site| |
| 1347 | // below. |
| 1348 | partition_domain->clear(); |
| 1349 | partition_name->clear(); |
| 1350 | *in_memory = false; |
| 1351 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1352 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
rogerta | 5f5bb82 | 2015-12-17 03:24:45 | [diff] [blame] | 1353 | bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite( |
[email protected] | 3f24f97c | 2013-11-17 21:53:33 | [diff] [blame] | 1354 | site, partition_domain, partition_name, in_memory); |
| 1355 | |
| 1356 | if (!success && site.SchemeIs(extensions::kExtensionScheme)) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1357 | // If |can_be_default| is false, the caller is stating that the |site| |
| 1358 | // should be parsed as if it had isolated storage. In particular it is |
| 1359 | // important to NOT check ExtensionService for the is_storage_isolated() |
| 1360 | // attribute because this code path is run during Extension uninstall |
| 1361 | // to do cleanup after the Extension has already been unloaded from the |
| 1362 | // ExtensionService. |
| 1363 | bool is_isolated = !can_be_default; |
| 1364 | if (can_be_default) { |
[email protected] | ca033634 | 2014-03-21 12:58:34 | [diff] [blame] | 1365 | if (extensions::util::SiteHasIsolatedStorage(site, browser_context)) |
| 1366 | is_isolated = true; |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1367 | } |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1368 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1369 | if (is_isolated) { |
| 1370 | CHECK(site.has_host()); |
| 1371 | // For extensions with isolated storage, the the host of the |site| is |
| 1372 | // the |partition_domain|. The |in_memory| and |partition_name| are only |
| 1373 | // used in guest schemes so they are cleared here. |
| 1374 | *partition_domain = site.host(); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1375 | *in_memory = false; |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1376 | partition_name->clear(); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1377 | } |
[email protected] | 1df3d97 | 2014-06-11 04:55:18 | [diff] [blame] | 1378 | success = true; |
| 1379 | } |
| 1380 | #endif |
| 1381 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1382 | // Assert that if |can_be_default| is false, the code above must have found a |
| 1383 | // non-default partition. If this fails, the caller has a serious logic |
| 1384 | // error about which StoragePartition they expect to be in and it is not |
| 1385 | // safe to continue. |
| 1386 | CHECK(can_be_default || !partition_domain->empty()); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 1387 | } |
| 1388 | |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 1389 | content::WebContentsViewDelegate* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1390 | ChromeContentBrowserClient::GetWebContentsViewDelegate( |
| 1391 | content::WebContents* web_contents) { |
cm.sanchi | 2db24a8 | 2017-11-16 07:22:10 | [diff] [blame] | 1392 | return CreateWebContentsViewDelegate(web_contents); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 1393 | } |
| 1394 | |
Bo Liu | 4ade6b1b2 | 2017-11-28 02:26:35 | [diff] [blame] | 1395 | bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() { |
| 1396 | #if defined(OS_ANDROID) |
| 1397 | const base::android::ApplicationState app_state = |
| 1398 | base::android::ApplicationStatusListener::GetState(); |
| 1399 | return base::android::APPLICATION_STATE_UNKNOWN == app_state || |
| 1400 | base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state || |
| 1401 | base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state; |
| 1402 | #else |
| 1403 | return true; |
| 1404 | #endif |
| 1405 | } |
| 1406 | |
[email protected] | 6f286274 | 2013-12-20 07:53:19 | [diff] [blame] | 1407 | void ChromeContentBrowserClient::RenderProcessWillLaunch( |
Ken Rockot | 7c6275b | 2019-08-02 20:00:23 | [diff] [blame] | 1408 | content::RenderProcessHost* host) { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1409 | int id = host->GetID(); |
| 1410 | Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 1411 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | b79dd6ba | 2018-12-07 01:20:49 | [diff] [blame] | 1412 | host->AddFilter(new cast::CastTransportHostFilter()); |
thestig | 73f4cdc | 2015-01-15 01:51:06 | [diff] [blame] | 1413 | #endif |
Brett Wilson | 65f951c | 2016-11-03 22:06:12 | [diff] [blame] | 1414 | #if BUILDFLAG(ENABLE_PRINTING) |
[email protected] | 168b7799 | 2014-08-20 11:48:40 | [diff] [blame] | 1415 | host->AddFilter(new printing::PrintingMessageFilter(id, profile)); |
[email protected] | 058e573 | 2012-03-01 22:48:03 | [diff] [blame] | 1416 | #endif |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 1417 | host->AddFilter(new prerender::PrerenderMessageFilter(id, profile)); |
Darin Fisher | 8c84328c | 2019-07-23 02:50:00 | [diff] [blame] | 1418 | |
Darin Fisher | 09aa722 | 2019-08-29 09:27:36 | [diff] [blame] | 1419 | WebRtcLoggingController::AttachToRenderProcessHost( |
Darin Fisher | 8c84328c | 2019-07-23 02:50:00 | [diff] [blame] | 1420 | host, g_browser_process->webrtc_log_uploader()); |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1421 | |
grunell | 086a411 | 2017-03-02 09:23:04 | [diff] [blame] | 1422 | // The audio manager outlives the host, so it's safe to hand a raw pointer to |
| 1423 | // it to the AudioDebugRecordingsHandler, which is owned by the host. |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1424 | AudioDebugRecordingsHandler* audio_debug_recordings_handler = |
Marina Ciocea | 741a4fb1 | 2018-01-27 09:55:12 | [diff] [blame] | 1425 | new AudioDebugRecordingsHandler(profile); |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1426 | host->SetUserData( |
| 1427 | AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey, |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 1428 | std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>( |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1429 | audio_debug_recordings_handler)); |
| 1430 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 1431 | #if BUILDFLAG(ENABLE_NACL) |
Helen Li | 8897b02 | 2018-05-03 13:29:03 | [diff] [blame] | 1432 | host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(), |
| 1433 | profile->GetPath())); |
[email protected] | 01e5975 | 2013-06-18 00:17:35 | [diff] [blame] | 1434 | #endif |
jeremyim | 364ac118 | 2015-03-03 18:49:43 | [diff] [blame] | 1435 | |
Xiaohan Wang | 9b34281b | 2017-09-08 23:48:33 | [diff] [blame] | 1436 | #if defined(OS_ANDROID) |
| 1437 | // Data cannot be persisted if the profile is off the record. |
| 1438 | host->AddFilter( |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 1439 | new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false)); |
Yuzu Saijo | 2d12ef9 | 2018-08-21 04:52:07 | [diff] [blame] | 1440 | |
| 1441 | // Register CrashMemoryMetricsCollector to report oom related metrics. |
| 1442 | host->SetUserData( |
| 1443 | CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey, |
| 1444 | std::make_unique<CrashMemoryMetricsCollector>(host)); |
Xiaohan Wang | 9b34281b | 2017-09-08 23:48:33 | [diff] [blame] | 1445 | #endif |
| 1446 | |
Jun Cai | db3f93cc | 2018-07-09 21:54:55 | [diff] [blame] | 1447 | Profile* original_profile = profile->GetOriginalProfile(); |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 1448 | RendererUpdaterFactory::GetForProfile(original_profile) |
| 1449 | ->InitializeRenderer(host); |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 1450 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1451 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1452 | extra_parts_[i]->RenderProcessWillLaunch(host); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 1453 | } |
| 1454 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1455 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
Alex Moshchuk | bb99a33 | 2017-11-22 04:49:57 | [diff] [blame] | 1456 | content::BrowserContext* browser_context, |
Alex Moshchuk | a31c788 | 2018-01-17 00:57:30 | [diff] [blame] | 1457 | const GURL& url) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1458 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1459 | if (!profile) |
| 1460 | return url; |
| 1461 | |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1462 | #if !defined(OS_ANDROID) |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 1463 | // If the input |url| should be assigned to the Instant renderer, make its |
| 1464 | // effective URL distinct from other URLs on the search provider's domain. |
Alex Moshchuk | ca17137 | 2017-11-28 16:11:31 | [diff] [blame] | 1465 | // This needs to happen even if |url| corresponds to an isolated origin; see |
| 1466 | // https://crbug.com/755595. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1467 | if (search::ShouldAssignURLToInstantRenderer(url, profile)) |
| 1468 | return search::GetEffectiveURLForInstant(url, profile); |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1469 | #endif |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 1470 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1471 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Alex Moshchuk | a31c788 | 2018-01-17 00:57:30 | [diff] [blame] | 1472 | return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile, |
| 1473 | url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1474 | #else |
| 1475 | return url; |
| 1476 | #endif |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1477 | } |
| 1478 | |
Alexander Yashkin | 6aedc6e | 2018-08-15 08:58:45 | [diff] [blame] | 1479 | bool ChromeContentBrowserClient:: |
| 1480 | ShouldCompareEffectiveURLsForSiteInstanceSelection( |
| 1481 | content::BrowserContext* browser_context, |
| 1482 | content::SiteInstance* candidate_site_instance, |
| 1483 | bool is_main_frame, |
| 1484 | const GURL& candidate_url, |
| 1485 | const GURL& destination_url) { |
| 1486 | DCHECK(browser_context); |
| 1487 | DCHECK(candidate_site_instance); |
| 1488 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1489 | return ChromeContentBrowserClientExtensionsPart:: |
| 1490 | ShouldCompareEffectiveURLsForSiteInstanceSelection( |
| 1491 | browser_context, candidate_site_instance, is_main_frame, |
| 1492 | candidate_url, destination_url); |
| 1493 | #else |
| 1494 | return true; |
| 1495 | #endif |
| 1496 | } |
| 1497 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 1498 | bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() { |
Ahmed Fakhry | e6a2c64 | 2018-06-20 02:58:41 | [diff] [blame] | 1499 | #if defined(OS_ANDROID) |
| 1500 | return true; |
| 1501 | #elif defined(OS_CHROMEOS) |
Xiyuan Xia | fc9f3813 | 2019-08-02 00:51:42 | [diff] [blame] | 1502 | return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode(); |
Ahmed Fakhry | e6a2c64 | 2018-06-20 02:58:41 | [diff] [blame] | 1503 | #else |
| 1504 | return false; |
| 1505 | #endif // defined(OS_ANDROID) |
| 1506 | } |
| 1507 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1508 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1509 | content::BrowserContext* browser_context, |
| 1510 | const GURL& effective_url) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1511 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1512 | if (!profile) |
| 1513 | return false; |
| 1514 | |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1515 | // NTP should use process-per-site. This is a performance optimization to |
| 1516 | // reduce process count associated with NTP tabs. |
| 1517 | if (effective_url == GURL(chrome::kChromeUINewTabURL)) |
| 1518 | return true; |
Peter Boström | 8e9b163 | 2019-08-22 23:12:47 | [diff] [blame] | 1519 | |
| 1520 | // The web footer experiment should share its renderer to not effectively |
| 1521 | // instantiate one per window. See https://crbug.com/993502. |
| 1522 | if (effective_url == GURL(chrome::kChromeUIWebFooterExperimentURL)) |
| 1523 | return true; |
| 1524 | |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1525 | #if !defined(OS_ANDROID) |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1526 | if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile)) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1527 | return true; |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1528 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1529 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1530 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1531 | if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite( |
| 1532 | profile, effective_url)) |
| 1533 | return true; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1534 | #endif |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1535 | |
| 1536 | // Non-extension, non-NTP URLs should generally use process-per-site-instance |
| 1537 | // (rather than process-per-site). |
| 1538 | return false; |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1539 | } |
| 1540 | |
Lukasz Anforowicz | 32d2712 | 2018-04-09 21:48:33 | [diff] [blame] | 1541 | bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost( |
| 1542 | content::BrowserContext* browser_context, |
| 1543 | const GURL& site_url) { |
| 1544 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1545 | if (!profile) |
| 1546 | return false; |
| 1547 | |
| 1548 | #if !defined(OS_ANDROID) |
| 1549 | // Instant renderers should not use a spare process, because they require |
| 1550 | // passing switches::kInstantProcess to the renderer process when it |
| 1551 | // launches. A spare process is launched earlier, before it is known which |
| 1552 | // navigation will use it, so it lacks this flag. |
| 1553 | if (search::ShouldAssignURLToInstantRenderer(site_url, profile)) |
| 1554 | return false; |
| 1555 | #endif |
| 1556 | |
| 1557 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1558 | return ChromeContentBrowserClientExtensionsPart:: |
| 1559 | ShouldUseSpareRenderProcessHost(profile, site_url); |
| 1560 | #else |
| 1561 | return true; |
| 1562 | #endif |
| 1563 | } |
| 1564 | |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1565 | bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess( |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1566 | content::BrowserContext* browser_context, |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1567 | const GURL& effective_site_url) { |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1568 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1569 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1570 | if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess( |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1571 | browser_context, effective_site_url)) { |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1572 | return true; |
| 1573 | } |
| 1574 | #endif |
| 1575 | return false; |
| 1576 | } |
| 1577 | |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1578 | // TODO(creis, nick): https://crbug.com/160576 describes a weakness in our |
| 1579 | // origin-lock enforcement, where we don't have a way to efficiently know |
| 1580 | // effective URLs on the IO thread, and wind up killing processes that e.g. |
| 1581 | // request cookies for their actual URL. This whole function (and its |
| 1582 | // ExtensionsPart) should be removed once we add that ability to the IO thread. |
| 1583 | bool ChromeContentBrowserClient::ShouldLockToOrigin( |
| 1584 | content::BrowserContext* browser_context, |
| 1585 | const GURL& effective_site_url) { |
| 1586 | // Origin lock to the search scheme would kill processes upon legitimate |
| 1587 | // requests for cookies from the search engine's domain. |
| 1588 | if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme)) |
| 1589 | return false; |
| 1590 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1591 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1592 | if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin( |
| 1593 | browser_context, effective_site_url)) { |
| 1594 | return false; |
| 1595 | } |
| 1596 | #endif |
| 1597 | return true; |
creis | e5d6d173 | 2015-08-25 19:47:06 | [diff] [blame] | 1598 | } |
| 1599 | |
Maks Orlovich | 0e23e31 | 2019-07-16 13:13:56 | [diff] [blame] | 1600 | bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel( |
Lily Chen | 0db055b | 2019-11-15 20:29:02 | [diff] [blame] | 1601 | base::StringPiece scheme, |
| 1602 | bool is_embedded_origin_secure) { |
| 1603 | if (is_embedded_origin_secure && scheme == content::kChromeUIScheme) |
| 1604 | return true; |
Maks Orlovich | 0e23e31 | 2019-07-16 13:13:56 | [diff] [blame] | 1605 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1606 | return scheme == extensions::kExtensionScheme; |
| 1607 | #else |
| 1608 | return false; |
| 1609 | #endif |
| 1610 | } |
| 1611 | |
Lily Chen | 0db055b | 2019-11-15 20:29:02 | [diff] [blame] | 1612 | bool ChromeContentBrowserClient:: |
| 1613 | ShouldIgnoreSameSiteCookieRestrictionsWhenTopLevel( |
| 1614 | base::StringPiece scheme, |
| 1615 | bool is_embedded_origin_secure) { |
| 1616 | return is_embedded_origin_secure && scheme == content::kChromeUIScheme; |
| 1617 | } |
| 1618 | |
Lukasz Anforowicz | 7097890d | 2019-11-20 21:49:22 | [diff] [blame] | 1619 | void ChromeContentBrowserClient::OverrideURLLoaderFactoryParams( |
Lukasz Anforowicz | e00adef | 2019-12-06 23:07:02 | [diff] [blame] | 1620 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 5f335256 | 2019-11-14 16:53:59 | [diff] [blame] | 1621 | const url::Origin& origin, |
Lukasz Anforowicz | e00adef | 2019-12-06 23:07:02 | [diff] [blame] | 1622 | bool is_for_isolated_world, |
Lukasz Anforowicz | 7097890d | 2019-11-20 21:49:22 | [diff] [blame] | 1623 | network::mojom::URLLoaderFactoryParams* factory_params) { |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1624 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | 7097890d | 2019-11-20 21:49:22 | [diff] [blame] | 1625 | ChromeContentBrowserClientExtensionsPart::OverrideURLLoaderFactoryParams( |
Lukasz Anforowicz | e00adef | 2019-12-06 23:07:02 | [diff] [blame] | 1626 | browser_context, origin, is_for_isolated_world, factory_params); |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1627 | #endif |
| 1628 | } |
| 1629 | |
[email protected] | 73b718f | 2014-01-27 02:59:46 | [diff] [blame] | 1630 | // These are treated as WebUI schemes but do not get WebUI bindings. Also, |
| 1631 | // view-source is allowed for these schemes. |
[email protected] | 8f89dd41 | 2013-04-17 02:35:41 | [diff] [blame] | 1632 | void ChromeContentBrowserClient::GetAdditionalWebUISchemes( |
| 1633 | std::vector<std::string>* additional_schemes) { |
| 1634 | additional_schemes->push_back(chrome::kChromeSearchScheme); |
[email protected] | 474a5a3 | 2014-07-28 18:23:24 | [diff] [blame] | 1635 | additional_schemes->push_back(dom_distiller::kDomDistillerScheme); |
Andrey Kosyakov | 031e9e3 | 2017-08-18 21:00:35 | [diff] [blame] | 1636 | additional_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1637 | } |
| 1638 | |
alexmos | 94875b3b | 2017-03-16 22:19:01 | [diff] [blame] | 1639 | void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes( |
| 1640 | std::vector<std::string>* additional_schemes) { |
| 1641 | GetAdditionalWebUISchemes(additional_schemes); |
| 1642 | |
| 1643 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1644 | additional_schemes->push_back(extensions::kExtensionScheme); |
| 1645 | #endif |
| 1646 | } |
| 1647 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 1648 | bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) { |
dbeam | baee5bd | 2015-09-26 03:07:01 | [diff] [blame] | 1649 | return webui::LogWebUIUrl(web_ui_url); |
| 1650 | } |
| 1651 | |
John Abd-El-Malek | 04bfa853 | 2018-07-12 05:28:22 | [diff] [blame] | 1652 | bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests( |
| 1653 | const url::Origin& origin) { |
| 1654 | return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests( |
| 1655 | origin); |
| 1656 | } |
| 1657 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 1658 | bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { |
| 1659 | return ProfileIOData::IsHandledURL(url); |
| 1660 | } |
| 1661 | |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1662 | bool ChromeContentBrowserClient::CanCommitURL( |
| 1663 | content::RenderProcessHost* process_host, |
| 1664 | const GURL& url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1665 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1666 | return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host, |
| 1667 | url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1668 | #else |
| 1669 | return true; |
| 1670 | #endif |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1671 | } |
| 1672 | |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1673 | void ChromeContentBrowserClient::OverrideNavigationParams( |
| 1674 | SiteInstance* site_instance, |
| 1675 | ui::PageTransition* transition, |
| 1676 | bool* is_renderer_initiated, |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1677 | content::Referrer* referrer, |
| 1678 | base::Optional<url::Origin>* initiator_origin) { |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1679 | DCHECK(transition); |
| 1680 | DCHECK(is_renderer_initiated); |
| 1681 | DCHECK(referrer); |
Moe Ahmadi | 26e2f50 | 2019-07-16 02:34:47 | [diff] [blame] | 1682 | // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to |
| 1683 | // use for making security decisions 99.44% of the time, for detecting the NTP |
| 1684 | // it is reliable and the correct way. See http://crbug.com/624410. |
| 1685 | if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) && |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1686 | ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) { |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1687 | // Clicks on tiles of the new tab page should be treated as if a user |
| 1688 | // clicked on a bookmark. This is consistent with native implementations |
| 1689 | // like Android's. This also helps ensure that security features (like |
| 1690 | // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as |
| 1691 | // browser-initiated. |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1692 | *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK; |
| 1693 | *is_renderer_initiated = false; |
| 1694 | *referrer = content::Referrer(); |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1695 | *initiator_origin = base::nullopt; |
mastiz | a77db699 | 2016-06-30 09:48:42 | [diff] [blame] | 1696 | } |
| 1697 | } |
| 1698 | |
Charles Reis | 29e9dd1 | 2017-09-28 00:59:15 | [diff] [blame] | 1699 | bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP( |
| 1700 | const GURL& url, |
| 1701 | SiteInstance* parent_site_instance) { |
Moe Ahmadi | 26e2f50 | 2019-07-16 02:34:47 | [diff] [blame] | 1702 | // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to |
| 1703 | // use for making security decisions 99.44% of the time, for detecting the NTP |
| 1704 | // it is reliable and the correct way. See http://crbug.com/624410. |
| 1705 | return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance && |
| 1706 | search::IsNTPURL(parent_site_instance->GetSiteURL()); |
Charles Reis | 29e9dd1 | 2017-09-28 00:59:15 | [diff] [blame] | 1707 | } |
| 1708 | |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1709 | bool ChromeContentBrowserClient::IsSuitableHost( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1710 | content::RenderProcessHost* process_host, |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1711 | const GURL& site_url) { |
| 1712 | Profile* profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1713 | Profile::FromBrowserContext(process_host->GetBrowserContext()); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1714 | // 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] | 1715 | // share any host. |
| 1716 | if (!profile) |
| 1717 | return true; |
| 1718 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1719 | #if !defined(OS_ANDROID) |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1720 | // Instant URLs should only be in the instant process and instant process |
| 1721 | // should only have Instant URLs. |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1722 | InstantService* instant_service = |
| 1723 | InstantServiceFactory::GetForProfile(profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1724 | if (instant_service) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1725 | bool is_instant_process = |
| 1726 | instant_service->IsInstantProcess(process_host->GetID()); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1727 | bool should_be_in_instant_process = |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1728 | search::ShouldAssignURLToInstantRenderer(site_url, profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1729 | if (is_instant_process || should_be_in_instant_process) |
| 1730 | return is_instant_process && should_be_in_instant_process; |
| 1731 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1732 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1733 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1734 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1735 | return ChromeContentBrowserClientExtensionsPart::IsSuitableHost( |
| 1736 | profile, process_host, site_url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1737 | #else |
| 1738 | return true; |
| 1739 | #endif |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1740 | } |
| 1741 | |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1742 | bool ChromeContentBrowserClient::MayReuseHost( |
| 1743 | content::RenderProcessHost* process_host) { |
| 1744 | // If there is currently a prerender in progress for the host provided, |
| 1745 | // it may not be shared. We require prerenders to be by themselves in a |
davidben | 879199c | 2015-03-06 00:55:04 | [diff] [blame] | 1746 | // separate process so that we can monitor their resource usage. |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1747 | prerender::PrerenderManager* prerender_manager = |
droger | c154315 | 2016-09-20 13:03:37 | [diff] [blame] | 1748 | prerender::PrerenderManagerFactory::GetForBrowserContext( |
| 1749 | process_host->GetBrowserContext()); |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1750 | if (prerender_manager && |
[email protected] | 2290af2 | 2014-05-26 15:44:49 | [diff] [blame] | 1751 | !prerender_manager->MayReuseProcessHost(process_host)) { |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1752 | return false; |
| 1753 | } |
| 1754 | |
| 1755 | return true; |
| 1756 | } |
| 1757 | |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1758 | bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1759 | content::BrowserContext* browser_context, |
| 1760 | const GURL& url) { |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1761 | // It has to be a valid URL for us to check for an extension. |
| 1762 | if (!url.is_valid()) |
| 1763 | return false; |
| 1764 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1765 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1766 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1767 | return ChromeContentBrowserClientExtensionsPart:: |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1768 | ShouldTryToUseExistingProcessHost(profile, url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1769 | #else |
| 1770 | return false; |
| 1771 | #endif |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1772 | } |
| 1773 | |
Alex Moshchuk | 9c9e388 | 2018-11-02 19:57:03 | [diff] [blame] | 1774 | bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess( |
| 1775 | content::RenderFrameHost* main_frame) { |
| 1776 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1777 | return ChromeContentBrowserClientExtensionsPart:: |
| 1778 | ShouldSubframesTryToReuseExistingProcess(main_frame); |
| 1779 | #else |
| 1780 | return true; |
| 1781 | #endif |
| 1782 | } |
| 1783 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1784 | void ChromeContentBrowserClient::SiteInstanceGotProcess( |
| 1785 | SiteInstance* site_instance) { |
| 1786 | CHECK(site_instance->HasProcess()); |
| 1787 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1788 | Profile* profile = |
| 1789 | Profile::FromBrowserContext(site_instance->GetBrowserContext()); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1790 | if (!profile) |
| 1791 | return; |
| 1792 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1793 | #if !defined(OS_ANDROID) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1794 | // Remember the ID of the Instant process to signal the renderer process |
| 1795 | // on startup in |AppendExtraCommandLineSwitches| below. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1796 | if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(), |
| 1797 | profile)) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1798 | InstantService* instant_service = |
| 1799 | InstantServiceFactory::GetForProfile(profile); |
| 1800 | if (instant_service) |
| 1801 | instant_service->AddInstantProcess(site_instance->GetProcess()->GetID()); |
| 1802 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1803 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1804 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1805 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1806 | extra_parts_[i]->SiteInstanceGotProcess(site_instance); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | void ChromeContentBrowserClient::SiteInstanceDeleting( |
| 1810 | SiteInstance* site_instance) { |
| 1811 | if (!site_instance->HasProcess()) |
| 1812 | return; |
| 1813 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1814 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1815 | extra_parts_[i]->SiteInstanceDeleting(site_instance); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1816 | } |
| 1817 | |
[email protected] | 453f543 | 2013-11-26 19:43:00 | [diff] [blame] | 1818 | bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation( |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1819 | SiteInstance* site_instance, |
Aaron Colwell | 16b4985d | 2019-11-13 00:20:56 | [diff] [blame] | 1820 | const GURL& current_effective_url, |
| 1821 | const GURL& destination_effective_url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1822 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1823 | return ChromeContentBrowserClientExtensionsPart:: |
Aaron Colwell | 16b4985d | 2019-11-13 00:20:56 | [diff] [blame] | 1824 | ShouldSwapBrowsingInstancesForNavigation( |
| 1825 | site_instance, current_effective_url, destination_effective_url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1826 | #else |
| 1827 | return false; |
| 1828 | #endif |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1829 | } |
| 1830 | |
Nasko Oskov | d83b571 | 2018-05-04 04:50:57 | [diff] [blame] | 1831 | bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) { |
| 1832 | // TODO(nasko): Consider supporting error page isolation in subframes if |
| 1833 | // Site Isolation is enabled. |
Nasko Oskov | 55d21e15 | 2018-06-27 23:59:38 | [diff] [blame] | 1834 | return in_main_frame; |
Nasko Oskov | d83b571 | 2018-05-04 04:50:57 | [diff] [blame] | 1835 | } |
| 1836 | |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 1837 | bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) { |
| 1838 | return !url.SchemeIs(chrome::kChromeNativeScheme); |
| 1839 | } |
| 1840 | |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1841 | std::vector<url::Origin> |
| 1842 | ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() { |
| 1843 | std::vector<url::Origin> isolated_origin_list; |
| 1844 | |
Alex Moshchuk | 89352a7 | 2017-10-25 20:25:59 | [diff] [blame] | 1845 | // Sign-in process isolation is not needed on Android, see |
| 1846 | // https://crbug.com/739418. |
| 1847 | #if !defined(OS_ANDROID) |
Alex Moshchuk | 81d2a29e | 2019-07-16 01:14:38 | [diff] [blame] | 1848 | isolated_origin_list.push_back( |
Alex Moshchuk | 36417aa | 2018-06-13 18:01:12 | [diff] [blame] | 1849 | url::Origin::Create(GaiaUrls::GetInstance()->gaia_url())); |
Alex Moshchuk | 89352a7 | 2017-10-25 20:25:59 | [diff] [blame] | 1850 | #endif |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1851 | |
Alex Moshchuk | 81d2a29e | 2019-07-16 01:14:38 | [diff] [blame] | 1852 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1853 | auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart:: |
| 1854 | GetOriginsRequiringDedicatedProcess(); |
| 1855 | std::move(std::begin(origins_from_extensions), |
| 1856 | std::end(origins_from_extensions), |
| 1857 | std::back_inserter(isolated_origin_list)); |
| 1858 | #endif |
| 1859 | |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1860 | return isolated_origin_list; |
| 1861 | } |
| 1862 | |
Lukasz Anforowicz | 5e201abd | 2018-03-24 00:41:06 | [diff] [blame] | 1863 | bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() { |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1864 | return base::FeatureList::IsEnabled(features::kSitePerProcess); |
| 1865 | } |
| 1866 | |
| 1867 | bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() { |
Alex Moshchuk | 7a737b63 | 2019-10-10 05:03:37 | [diff] [blame] | 1868 | return SiteIsolationPolicy::ShouldDisableSiteIsolationDueToMemoryThreshold(); |
Lukasz Anforowicz | 5e201abd | 2018-03-24 00:41:06 | [diff] [blame] | 1869 | } |
| 1870 | |
Alex Moshchuk | 082b5f8 | 2019-03-14 01:34:16 | [diff] [blame] | 1871 | std::vector<std::string> |
| 1872 | ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() { |
| 1873 | if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled()) |
| 1874 | return {"Isolate Password Sites"}; |
| 1875 | else |
| 1876 | return {}; |
| 1877 | } |
| 1878 | |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 1879 | void ChromeContentBrowserClient::PersistIsolatedOrigin( |
| 1880 | content::BrowserContext* context, |
| 1881 | const url::Origin& origin) { |
| 1882 | DCHECK(!context->IsOffTheRecord()); |
| 1883 | Profile* profile = Profile::FromBrowserContext(context); |
| 1884 | ListPrefUpdate update(profile->GetPrefs(), |
| 1885 | prefs::kUserTriggeredIsolatedOrigins); |
| 1886 | base::ListValue* list = update.Get(); |
| 1887 | base::Value value(origin.Serialize()); |
Jan Wilken Dörrie | a8cb5630 | 2019-06-06 18:59:36 | [diff] [blame] | 1888 | if (!base::Contains(list->GetList(), value)) |
Jan Wilken Dörrie | 91e4ef0 | 2019-09-11 08:22:12 | [diff] [blame] | 1889 | list->Append(std::move(value)); |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 1890 | } |
| 1891 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 1892 | bool ChromeContentBrowserClient::IsFileAccessAllowed( |
| 1893 | const base::FilePath& path, |
| 1894 | const base::FilePath& absolute_path, |
| 1895 | const base::FilePath& profile_path) { |
| 1896 | return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path, |
| 1897 | profile_path); |
| 1898 | } |
| 1899 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1900 | namespace { |
| 1901 | |
| 1902 | bool IsAutoReloadEnabled() { |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 1903 | const base::CommandLine& browser_command_line = |
| 1904 | *base::CommandLine::ForCurrentProcess(); |
Elly Fong-Jones | 5f13ee1 | 2019-05-10 19:20:35 | [diff] [blame] | 1905 | if (browser_command_line.HasSwitch(switches::kEnableAutoReload)) |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1906 | return true; |
Elly Fong-Jones | 5f13ee1 | 2019-05-10 19:20:35 | [diff] [blame] | 1907 | if (browser_command_line.HasSwitch(switches::kDisableAutoReload)) |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1908 | return false; |
[email protected] | 9ef49b4 | 2014-08-07 16:44:24 | [diff] [blame] | 1909 | return true; |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1910 | } |
| 1911 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1912 | void MaybeAppendBlinkSettingsSwitchForFieldTrial( |
| 1913 | const base::CommandLine& browser_command_line, |
| 1914 | base::CommandLine* command_line) { |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1915 | // List of field trials that modify the blink-settings command line flag. No |
| 1916 | // two field trials in the list should specify the same keys, otherwise one |
| 1917 | // field trial may overwrite another. See Source/core/frame/Settings.in in |
| 1918 | // Blink for the list of valid keys. |
| 1919 | static const char* const kBlinkSettingsFieldTrials[] = { |
jkarlin | 3bddb7d | 2016-09-21 18:44:16 | [diff] [blame] | 1920 | // Keys: disallowFetchForDocWrittenScriptsInMainFrame |
| 1921 | // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections |
| 1922 | // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G |
| 1923 | "DisallowFetchForDocWrittenScriptsInMainFrame", |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1924 | }; |
| 1925 | |
| 1926 | std::vector<std::string> blink_settings; |
| 1927 | for (const char* field_trial_name : kBlinkSettingsFieldTrials) { |
| 1928 | // Each blink-settings field trial should include a forcing_flag group, |
| 1929 | // to make sure that clients that specify the blink-settings flag on the |
| 1930 | // command line are excluded from the experiment groups. To make |
| 1931 | // sure we assign clients that specify this flag to the forcing_flag |
| 1932 | // group, we must call GetVariationParams for each field trial first |
| 1933 | // (for example, before checking HasSwitch() and returning), since |
| 1934 | // GetVariationParams has the side-effect of assigning the client to |
| 1935 | // a field trial group. |
| 1936 | std::map<std::string, std::string> params; |
| 1937 | if (variations::GetVariationParams(field_trial_name, ¶ms)) { |
| 1938 | for (const auto& param : params) { |
| 1939 | blink_settings.push_back(base::StringPrintf( |
| 1940 | "%s=%s", param.first.c_str(), param.second.c_str())); |
| 1941 | } |
| 1942 | } |
| 1943 | } |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 1944 | |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1945 | if (blink_settings.empty()) { |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1946 | return; |
| 1947 | } |
| 1948 | |
| 1949 | if (browser_command_line.HasSwitch(switches::kBlinkSettings) || |
| 1950 | command_line->HasSwitch(switches::kBlinkSettings)) { |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 1951 | // The field trials should be configured to force users that specify the |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1952 | // blink-settings flag into a group with no params, and we return |
| 1953 | // above if no params were specified, so it's an error if we reach |
| 1954 | // this point. |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1955 | LOG(WARNING) << "Received field trial params, " |
| 1956 | "but blink-settings switch already specified."; |
| 1957 | return; |
| 1958 | } |
| 1959 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1960 | command_line->AppendSwitchASCII(switches::kBlinkSettings, |
brettw | d94a2214 | 2015-07-15 05:19:26 | [diff] [blame] | 1961 | base::JoinString(blink_settings, ",")); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1962 | } |
| 1963 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1964 | } // namespace |
| 1965 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 1966 | void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 1967 | base::CommandLine* command_line, |
| 1968 | int child_process_id) { |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 1969 | #if defined(OS_MACOSX) |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 1970 | std::unique_ptr<metrics::ClientInfo> client_info = |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 1971 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
| 1972 | if (client_info) { |
| 1973 | command_line->AppendSwitchASCII(switches::kMetricsClientID, |
| 1974 | client_info->client_id); |
| 1975 | } |
| 1976 | #elif defined(OS_POSIX) |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 1977 | #if defined(OS_ANDROID) |
| 1978 | bool enable_crash_reporter = true; |
| 1979 | #else |
Joshua Peraza | ce68e2f | 2019-09-23 18:44:24 | [diff] [blame] | 1980 | bool enable_crash_reporter = false; |
| 1981 | if (crash_reporter::IsCrashpadEnabled()) { |
| 1982 | command_line->AppendSwitch(crash_reporter::kEnableCrashpad); |
| 1983 | enable_crash_reporter = true; |
| 1984 | |
| 1985 | int fd; |
| 1986 | pid_t pid; |
| 1987 | if (crash_reporter::GetHandlerSocket(&fd, &pid)) { |
| 1988 | command_line->AppendSwitchASCII( |
| 1989 | crash_reporter::switches::kCrashpadHandlerPid, |
| 1990 | base::NumberToString(pid)); |
| 1991 | } |
| 1992 | } else { |
| 1993 | enable_crash_reporter = breakpad::IsCrashReporterEnabled(); |
| 1994 | } |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 1995 | #endif |
| 1996 | if (enable_crash_reporter) { |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 1997 | std::string switch_value; |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 1998 | std::unique_ptr<metrics::ClientInfo> client_info = |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 1999 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2000 | if (client_info) |
| 2001 | switch_value = client_info->client_id; |
| 2002 | switch_value.push_back(','); |
Boris Vidolov | 8657801 | 2018-03-21 16:55:25 | [diff] [blame] | 2003 | switch_value.append(chrome::GetChannelName()); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2004 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2005 | switch_value); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2006 | } |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2007 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2008 | |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 2009 | if (logging::DialogsAreSuppressed()) |
| 2010 | command_line->AppendSwitch(switches::kNoErrorDialogs); |
| 2011 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2012 | std::string process_type = |
| 2013 | command_line->GetSwitchValueASCII(switches::kProcessType); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 2014 | const base::CommandLine& browser_command_line = |
| 2015 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 2016 | |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 2017 | static const char* const kCommonSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2018 | switches::kUserAgent, |
| 2019 | switches::kUserDataDir, // Make logs go to the right file. |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 2020 | }; |
| 2021 | command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2022 | base::size(kCommonSwitchNames)); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 2023 | |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2024 | static const char* const kDinosaurEasterEggSwitches[] = { |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 2025 | error_page::switches::kDisableDinosaurEasterEgg, |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 2026 | }; |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2027 | command_line->CopySwitchesFrom(browser_command_line, |
| 2028 | kDinosaurEasterEggSwitches, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2029 | base::size(kDinosaurEasterEggSwitches)); |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 2030 | |
David Van Cleve | 3df6abb | 2019-11-26 17:52:51 | [diff] [blame] | 2031 | if (content::Referrer::ShouldForceLegacyDefaultReferrerPolicy()) |
| 2032 | command_line->AppendSwitch(switches::kForceLegacyDefaultReferrerPolicy); |
| 2033 | |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2034 | #if defined(OS_CHROMEOS) |
[email protected] | 6bdc5227 | 2014-05-27 00:12:33 | [diff] [blame] | 2035 | // On Chrome OS need to pass primary user homedir (in multi-profiles session). |
| 2036 | base::FilePath homedir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 2037 | base::PathService::Get(base::DIR_HOME, &homedir); |
[email protected] | 6bdc5227 | 2014-05-27 00:12:33 | [diff] [blame] | 2038 | command_line->AppendSwitchASCII(chromeos::switches::kHomedir, |
| 2039 | homedir.value().c_str()); |
| 2040 | #endif |
| 2041 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 2042 | if (process_type == switches::kRendererProcess) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2043 | content::RenderProcessHost* process = |
| 2044 | content::RenderProcessHost::FromID(child_process_id); |
| 2045 | Profile* profile = |
| 2046 | process ? Profile::FromBrowserContext(process->GetBrowserContext()) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2047 | : nullptr; |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2048 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2049 | extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line, |
| 2050 | process, profile); |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2051 | } |
| 2052 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2053 | #if defined(OS_CHROMEOS) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2054 | const std::string& login_profile = browser_command_line.GetSwitchValueASCII( |
| 2055 | chromeos::switches::kLoginProfile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2056 | if (!login_profile.empty()) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2057 | command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, |
| 2058 | login_profile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2059 | #endif |
| 2060 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2061 | MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line, |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 2062 | chrome::GetChannel()); |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2063 | if (process) { |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2064 | PrefService* prefs = profile->GetPrefs(); |
| 2065 | // Currently this pref is only registered if applied via a policy. |
| 2066 | if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && |
| 2067 | prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 2068 | // Turn this policy into a command line switch. |
| 2069 | command_line->AppendSwitch(switches::kDisable3DAPIs); |
| 2070 | } |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 2071 | |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2072 | const base::ListValue* switches = |
| 2073 | prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures); |
| 2074 | if (switches) { |
| 2075 | // Enable any deprecated features that have been re-enabled by policy. |
jdoerrie | 601c715 | 2018-10-02 23:43:11 | [diff] [blame] | 2076 | for (auto it = switches->begin(); it != switches->end(); ++it) { |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2077 | std::string switch_to_enable; |
jdoerrie | a5676c6 | 2017-04-11 18:09:14 | [diff] [blame] | 2078 | if (it->GetAsString(&switch_to_enable)) |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2079 | command_line->AppendSwitch(switch_to_enable); |
| 2080 | } |
| 2081 | } |
| 2082 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2083 | // Disable client-side phishing detection in the renderer if it is |
| 2084 | // disabled in the Profile preferences or the browser process. |
| 2085 | if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) || |
| 2086 | !g_browser_process->safe_browsing_detection_service()) { |
| 2087 | command_line->AppendSwitch( |
| 2088 | switches::kDisableClientSidePhishingDetection); |
| 2089 | } |
[email protected] | 0045b0f4 | 2012-07-26 11:52:08 | [diff] [blame] | 2090 | |
vitalybuka | a7ae505 | 2014-09-26 04:11:13 | [diff] [blame] | 2091 | if (prefs->GetBoolean(prefs::kPrintPreviewDisabled)) |
| 2092 | command_line->AppendSwitch(switches::kDisablePrintPreview); |
| 2093 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 2094 | #if !defined(OS_ANDROID) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 2095 | InstantService* instant_service = |
| 2096 | InstantServiceFactory::GetForProfile(profile); |
| 2097 | if (instant_service && |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2098 | instant_service->IsInstantProcess(process->GetID())) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 2099 | command_line->AppendSwitch(switches::kInstantProcess); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2100 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 2101 | #endif |
fqj | ba8749c | 2015-10-29 15:33:07 | [diff] [blame] | 2102 | |
fqj | 38306f7b | 2015-11-02 16:59:06 | [diff] [blame] | 2103 | if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) && |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2104 | !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) { |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 2105 | command_line->AppendSwitch( |
| 2106 | error_page::switches::kDisableDinosaurEasterEgg); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2107 | } |
Daniel Vogelheim | 976f1c2 | 2017-11-22 16:26:03 | [diff] [blame] | 2108 | |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 2109 | MaybeAppendSecureOriginsAllowlistSwitch(command_line); |
| 2110 | |
Amr Aboelkher | b04cbf3 | 2019-04-29 15:17:10 | [diff] [blame] | 2111 | if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) && |
| 2112 | prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) { |
Avi Drissman | fb96126 | 2019-03-05 22:50:29 | [diff] [blame] | 2113 | command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload); |
Amr Aboelkher | b04cbf3 | 2019-04-29 15:17:10 | [diff] [blame] | 2114 | } |
Katie Dillon | c25ee5c9 | 2019-09-12 17:05:42 | [diff] [blame] | 2115 | |
| 2116 | if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) && |
| 2117 | prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) { |
| 2118 | command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal); |
| 2119 | } |
Takashi Toyoshima | 12844146 | 2019-10-16 04:19:17 | [diff] [blame] | 2120 | |
Mason Freed | 490f2a2 | 2019-11-05 21:41:29 | [diff] [blame] | 2121 | if (prefs->HasPrefPath(prefs::kWebComponentsV0Enabled) && |
| 2122 | prefs->GetBoolean(prefs::kWebComponentsV0Enabled)) { |
| 2123 | command_line->AppendSwitch(switches::kWebComponentsV0Enabled); |
| 2124 | } |
| 2125 | |
Takashi Toyoshima | 0dab7330 | 2019-10-18 01:51:36 | [diff] [blame] | 2126 | if (!profile->ShouldEnableOutOfBlinkCors()) { |
| 2127 | command_line->AppendSwitch( |
| 2128 | network::switches::kForceToDisableOutOfBlinkCors); |
| 2129 | } |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2130 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2131 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 2132 | if (IsAutoReloadEnabled()) |
Elly Fong-Jones | 5f13ee1 | 2019-05-10 19:20:35 | [diff] [blame] | 2133 | command_line->AppendSwitch(switches::kEnableAutoReload); |
[email protected] | 28ee4e7 | 2014-03-28 19:29:04 | [diff] [blame] | 2134 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2135 | MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line, |
| 2136 | command_line); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2137 | |
mdjones | a6b9e17 | 2016-09-23 16:24:30 | [diff] [blame] | 2138 | #if defined(OS_ANDROID) |
| 2139 | // If the platform is Android, force the distillability service on. |
| 2140 | command_line->AppendSwitch(switches::kEnableDistillabilityService); |
| 2141 | #endif |
| 2142 | |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2143 | // Please keep this in alphabetical order. |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2144 | static const char* const kSwitchNames[] = { |
estade | 0ee9126 | 2014-10-23 19:29:19 | [diff] [blame] | 2145 | autofill::switches::kIgnoreAutocompleteOffForAutofill, |
kolos | ad36993 | 2017-02-23 13:29:41 | [diff] [blame] | 2146 | autofill::switches::kShowAutofillSignatures, |
Chris Mumford | 6b1696b | 2019-01-25 02:54:30 | [diff] [blame] | 2147 | #if defined(OS_CHROMEOS) |
| 2148 | switches::kShortMergeSessionTimeoutForTest, // For tests only. |
| 2149 | #endif |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2150 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 2151 | extensions::switches::kAllowHTTPBackgroundPage, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2152 | extensions::switches::kAllowLegacyExtensionManifests, |
Chris Mumford | 3f0eda9 | 2018-07-23 14:51:17 | [diff] [blame] | 2153 | extensions::switches::kDisableExtensionsHttpThrottling, |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 2154 | extensions::switches::kEnableExperimentalExtensionApis, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2155 | extensions::switches::kExtensionsOnChromeURLs, |
Chris Mumford | 3f0eda9 | 2018-07-23 14:51:17 | [diff] [blame] | 2156 | extensions::switches::kSetExtensionThrottleTestParams, // For tests only. |
[email protected] | a612eb3 | 2014-03-31 22:09:17 | [diff] [blame] | 2157 | extensions::switches::kWhitelistedExtensionID, |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 2158 | #endif |
estark | 4b003b33 | 2015-02-14 01:07:05 | [diff] [blame] | 2159 | switches::kAllowInsecureLocalhost, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2160 | switches::kAppsGalleryURL, |
[email protected] | 09cff7878 | 2014-04-20 22:04:48 | [diff] [blame] | 2161 | switches::kCloudPrintURL, |
[email protected] | 6f5c141a | 2014-04-15 21:44:51 | [diff] [blame] | 2162 | switches::kCloudPrintXmppEndpoint, |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 2163 | switches::kDisableBundledPpapiFlash, |
dslomov | a893e97 | 2014-12-05 09:39:57 | [diff] [blame] | 2164 | switches::kDisableJavaScriptHarmonyShipping, |
Kyle Milka | b5c048e | 2017-07-07 02:38:46 | [diff] [blame] | 2165 | variations::switches::kEnableBenchmarking, |
mdjones | a6b9e17 | 2016-09-23 16:24:30 | [diff] [blame] | 2166 | switches::kEnableDistillabilityService, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2167 | switches::kEnableNaCl, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2168 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | 1b4ec38 | 2014-03-07 02:32:24 | [diff] [blame] | 2169 | switches::kEnableNaClDebug, |
[email protected] | b2c73f4 | 2014-03-07 15:44:48 | [diff] [blame] | 2170 | switches::kEnableNaClNonSfiMode, |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 2171 | #endif |
[email protected] | ce304ce | 2013-02-22 21:54:45 | [diff] [blame] | 2172 | switches::kEnableNetBenchmarking, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2173 | #if BUILDFLAG(ENABLE_NACL) |
stichnot | 7040ac83 | 2016-02-24 23:40:59 | [diff] [blame] | 2174 | switches::kForcePNaClSubzero, |
| 2175 | #endif |
Marc Treib | ad33cf94 | 2017-08-24 11:19:00 | [diff] [blame] | 2176 | switches::kForceUIDirection, |
erikcorry | b251cb9 | 2014-09-25 23:48:51 | [diff] [blame] | 2177 | switches::kJavaScriptHarmony, |
Andreas Haas | b400d91 | 2019-08-28 18:54:10 | [diff] [blame] | 2178 | switches::kEnableExperimentalWebAssemblyFeatures, |
iclelland | 79237e9 | 2016-06-23 12:03:51 | [diff] [blame] | 2179 | switches::kOriginTrialDisabledFeatures, |
chasej | dfec22ae | 2017-03-16 20:58:55 | [diff] [blame] | 2180 | switches::kOriginTrialDisabledTokens, |
iclelland | ee4f4a7 | 2016-04-26 18:59:02 | [diff] [blame] | 2181 | switches::kOriginTrialPublicKey, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2182 | switches::kPpapiFlashArgs, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2183 | switches::kPpapiFlashPath, |
| 2184 | switches::kPpapiFlashVersion, |
wychen | e5568734 | 2015-11-13 20:17:03 | [diff] [blame] | 2185 | switches::kReaderModeHeuristics, |
[email protected] | 499e7c5 | 2013-10-04 16:03:09 | [diff] [blame] | 2186 | translate::switches::kTranslateSecurityOrigin, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2187 | }; |
| 2188 | |
| 2189 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2190 | base::size(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 2191 | } else if (process_type == switches::kUtilityProcess) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2192 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 2193 | static const char* const kSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2194 | extensions::switches::kAllowHTTPBackgroundPage, |
| 2195 | extensions::switches::kEnableExperimentalExtensionApis, |
| 2196 | extensions::switches::kExtensionsOnChromeURLs, |
| 2197 | extensions::switches::kWhitelistedExtensionID, |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 2198 | }; |
| 2199 | |
| 2200 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2201 | base::size(kSwitchNames)); |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 2202 | #endif |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 2203 | MaybeAppendSecureOriginsAllowlistSwitch(command_line); |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 2204 | } else if (process_type == service_manager::switches::kZygoteProcess) { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2205 | static const char* const kSwitchNames[] = { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2206 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 2207 | switches::kDisableBundledPpapiFlash, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2208 | #if BUILDFLAG(ENABLE_NACL) |
rickyz | 3638a21 | 2014-10-29 23:50:24 | [diff] [blame] | 2209 | switches::kEnableNaClDebug, |
[email protected] | a9a8e2f | 2014-05-13 23:32:58 | [diff] [blame] | 2210 | switches::kEnableNaClNonSfiMode, |
stichnot | 7040ac83 | 2016-02-24 23:40:59 | [diff] [blame] | 2211 | switches::kForcePNaClSubzero, |
[email protected] | 0b47034 | 2014-04-15 12:59:41 | [diff] [blame] | 2212 | switches::kNaClDangerousNoSandboxNonSfi, |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 2213 | #endif |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2214 | switches::kPpapiFlashPath, |
| 2215 | switches::kPpapiFlashVersion, |
| 2216 | }; |
| 2217 | |
| 2218 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2219 | base::size(kSwitchNames)); |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 2220 | } else if (process_type == switches::kGpuProcess) { |
| 2221 | // If --ignore-gpu-blacklist is passed in, don't send in crash reports |
| 2222 | // because GPU is expected to be unreliable. |
| 2223 | if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) && |
| 2224 | !command_line->HasSwitch(switches::kDisableBreakpad)) |
| 2225 | command_line->AppendSwitch(switches::kDisableBreakpad); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2226 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 2227 | |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2228 | #if defined(OS_CHROMEOS) |
Joshua Peraza | 30d8fc7 | 2019-08-19 17:24:30 | [diff] [blame] | 2229 | if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) { |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2230 | static const char* const kSwitchNames[] = { |
Joshua Peraza | 86b7958 | 2019-10-08 15:56:29 | [diff] [blame] | 2231 | crash_reporter::switches::kCrashLoopBefore, |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2232 | }; |
| 2233 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 2234 | base::size(kSwitchNames)); |
| 2235 | } |
| 2236 | #endif |
| 2237 | |
wittman | 832321f5 | 2016-10-10 18:18:38 | [diff] [blame] | 2238 | StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2239 | process_type, command_line); |
Andrew Comminos | 6605767 | 2019-05-01 00:03:34 | [diff] [blame] | 2240 | |
| 2241 | #if defined(OS_LINUX) |
| 2242 | // Processes may only query perf_event_open with the BPF sandbox disabled. |
| 2243 | if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) && |
| 2244 | command_line->HasSwitch(service_manager::switches::kNoSandbox)) { |
| 2245 | command_line->AppendSwitch(switches::kEnableThreadInstructionCount); |
| 2246 | } |
| 2247 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2248 | } |
| 2249 | |
Olivier Yiptong | 0daa93f | 2019-08-22 19:40:08 | [diff] [blame] | 2250 | std::string |
| 2251 | ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() { |
| 2252 | return std::string(chrome::kApplicationClientIDStringForAVScanning); |
| 2253 | } |
| 2254 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2255 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
[email protected] | e9a32a5 | 2012-06-14 23:32:43 | [diff] [blame] | 2256 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 2257 | return GetIOThreadApplicationLocale(); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2258 | return g_browser_process->GetApplicationLocale(); |
| 2259 | } |
| 2260 | |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 2261 | std::string ChromeContentBrowserClient::GetAcceptLangs( |
| 2262 | content::BrowserContext* context) { |
| 2263 | Profile* profile = Profile::FromBrowserContext(context); |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 2264 | return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 2265 | } |
| 2266 | |
Dana Fried | 34d58000 | 2019-04-24 20:05:48 | [diff] [blame] | 2267 | gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() { |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 2268 | ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
Dana Fried | 34d58000 | 2019-04-24 20:05:48 | [diff] [blame] | 2269 | return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia(); |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 2270 | } |
| 2271 | |
bengr | e8a146f | 2016-03-10 01:20:22 | [diff] [blame] | 2272 | bool ChromeContentBrowserClient::IsDataSaverEnabled( |
| 2273 | content::BrowserContext* browser_context) { |
rajendrant | fb95964d | 2019-10-17 20:05:38 | [diff] [blame] | 2274 | if (!browser_context || browser_context->IsOffTheRecord()) |
| 2275 | return false; |
| 2276 | |
Robert Ogden | c995d4fe | 2019-03-25 19:18:37 | [diff] [blame] | 2277 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2278 | return profile && data_reduction_proxy::DataReductionProxySettings:: |
Tarun Bansal | c91d5bb8 | 2019-11-05 00:17:41 | [diff] [blame] | 2279 | IsDataSaverEnabledByUser(profile->IsOffTheRecord(), |
| 2280 | profile->GetPrefs()); |
bengr | e8a146f | 2016-03-10 01:20:22 | [diff] [blame] | 2281 | } |
| 2282 | |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 2283 | void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker( |
| 2284 | content::BrowserContext* browser_context, |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 2285 | blink::mojom::RendererPreferences* out_prefs) { |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 2286 | DCHECK(browser_context); |
| 2287 | DCHECK(out_prefs); |
| 2288 | renderer_preferences_util::UpdateFromSystemSettings( |
| 2289 | out_prefs, Profile::FromBrowserContext(browser_context)); |
| 2290 | } |
| 2291 | |
Clark DuVall | 5690e74 | 2019-07-17 18:26:17 | [diff] [blame] | 2292 | bool ChromeContentBrowserClient::AllowAppCache( |
| 2293 | const GURL& manifest_url, |
| 2294 | const GURL& first_party, |
| 2295 | content::BrowserContext* context) { |
| 2296 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2297 | return CookieSettingsFactory::GetForProfile( |
| 2298 | Profile::FromBrowserContext(context)) |
| 2299 | ->IsCookieAccessAllowed(manifest_url, first_party); |
| 2300 | } |
| 2301 | |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2302 | bool ChromeContentBrowserClient::AllowServiceWorkerOnIO( |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2303 | const GURL& scope, |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2304 | const GURL& site_for_cookies, |
| 2305 | const base::Optional<url::Origin>& top_frame_origin, |
David Bertoni | 3b3597d8 | 2019-06-22 02:29:36 | [diff] [blame] | 2306 | const GURL& script_url, |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2307 | content::ResourceContext* context, |
tzik | df81f14 | 2018-10-26 00:23:34 | [diff] [blame] | 2308 | base::RepeatingCallback<content::WebContents*()> wc_getter) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 2309 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2310 | GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL(); |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2311 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2312 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2313 | // Check if this is an extension-related service worker, and, if so, if it's |
| 2314 | // allowed (this can return false if, e.g., the extension is disabled). |
| 2315 | // If it's not allowed, return immediately. We deliberately do *not* report |
| 2316 | // to the TabSpecificContentSettings, since the service worker is blocked |
| 2317 | // because of the extension, rather than because of the user's content |
| 2318 | // settings. |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2319 | if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO( |
David Bertoni | 3b3597d8 | 2019-06-22 02:29:36 | [diff] [blame] | 2320 | scope, first_party_url, script_url, context)) { |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2321 | return false; |
| 2322 | } |
| 2323 | #endif |
| 2324 | |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2325 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2326 | |
shimazu | ce8af8812 | 2016-10-06 23:49:21 | [diff] [blame] | 2327 | // Check if JavaScript is allowed. |
| 2328 | content_settings::SettingInfo info; |
| 2329 | std::unique_ptr<base::Value> value = |
| 2330 | io_data->GetHostContentSettingsMap()->GetWebsiteSetting( |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2331 | first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT, |
shimazu | ce8af8812 | 2016-10-06 23:49:21 | [diff] [blame] | 2332 | std::string(), &info); |
| 2333 | ContentSetting setting = content_settings::ValueToContentSetting(value.get()); |
| 2334 | bool allow_javascript = (setting == CONTENT_SETTING_ALLOW); |
| 2335 | |
| 2336 | // Check if cookies are allowed. |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2337 | bool allow_cookies = io_data->GetCookieSettings()->IsCookieAccessAllowed( |
| 2338 | scope, site_for_cookies, top_frame_origin); |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2339 | // Record access to database for potential display in UI. |
yzshen | bc36c97 | 2016-12-21 21:39:24 | [diff] [blame] | 2340 | // Only post the task if this is for a specific tab. |
| 2341 | if (!wc_getter.is_null()) { |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 2342 | base::PostTask( |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 2343 | FROM_HERE, {BrowserThread::UI}, |
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 2344 | base::BindOnce(&TabSpecificContentSettings::ServiceWorkerAccessed, |
tzik | df81f14 | 2018-10-26 00:23:34 | [diff] [blame] | 2345 | std::move(wc_getter), scope, !allow_javascript, |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2346 | !allow_cookies)); |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2347 | } |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2348 | return allow_javascript && allow_cookies; |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2349 | } |
| 2350 | |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2351 | bool ChromeContentBrowserClient::AllowServiceWorkerOnUI( |
| 2352 | const GURL& scope, |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2353 | const GURL& site_for_cookies, |
| 2354 | const base::Optional<url::Origin>& top_frame_origin, |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2355 | const GURL& script_url, |
| 2356 | content::BrowserContext* context, |
| 2357 | base::RepeatingCallback<content::WebContents*()> wc_getter) { |
| 2358 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2359 | GURL first_party_url = top_frame_origin ? top_frame_origin->GetURL() : GURL(); |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2360 | |
| 2361 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2362 | // Check if this is an extension-related service worker, and, if so, if it's |
| 2363 | // allowed (this can return false if, e.g., the extension is disabled). |
| 2364 | // If it's not allowed, return immediately. We deliberately do *not* report |
| 2365 | // to the TabSpecificContentSettings, since the service worker is blocked |
| 2366 | // because of the extension, rather than because of the user's content |
| 2367 | // settings. |
| 2368 | if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI( |
| 2369 | scope, first_party_url, script_url, context)) { |
| 2370 | return false; |
| 2371 | } |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2372 | #endif |
| 2373 | |
| 2374 | Profile* profile = Profile::FromBrowserContext(context); |
| 2375 | |
| 2376 | // Check if JavaScript is allowed. |
| 2377 | content_settings::SettingInfo info; |
| 2378 | std::unique_ptr<base::Value> value = |
| 2379 | HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting( |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2380 | first_party_url, first_party_url, ContentSettingsType::JAVASCRIPT, |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2381 | std::string(), &info); |
| 2382 | ContentSetting setting = content_settings::ValueToContentSetting(value.get()); |
| 2383 | bool allow_javascript = (setting == CONTENT_SETTING_ALLOW); |
| 2384 | |
| 2385 | // Check if cookies are allowed. |
| 2386 | bool allow_cookies = |
| 2387 | CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed( |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2388 | scope, site_for_cookies, top_frame_origin); |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2389 | |
| 2390 | // Record access to database for potential display in UI. |
| 2391 | // Only post the task if this is for a specific tab. |
| 2392 | if (!wc_getter.is_null()) { |
| 2393 | TabSpecificContentSettings::ServiceWorkerAccessed( |
| 2394 | std::move(wc_getter), scope, !allow_javascript, !allow_cookies); |
| 2395 | } |
| 2396 | return allow_javascript && allow_cookies; |
| 2397 | } |
| 2398 | |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2399 | bool ChromeContentBrowserClient::AllowSharedWorker( |
| 2400 | const GURL& worker_url, |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2401 | const GURL& site_for_cookies, |
| 2402 | const base::Optional<url::Origin>& top_frame_origin, |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2403 | const std::string& name, |
Hiroki Nakagawa | 018bb6d | 2017-11-30 03:31:37 | [diff] [blame] | 2404 | const url::Origin& constructor_origin, |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2405 | content::BrowserContext* context, |
| 2406 | int render_process_id, |
| 2407 | int render_frame_id) { |
| 2408 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2409 | |
| 2410 | // Check if cookies are allowed. |
| 2411 | bool allow = |
| 2412 | CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context)) |
Christian Dullweber | 2a2f218 | 2019-09-25 15:44:54 | [diff] [blame] | 2413 | ->IsCookieAccessAllowed(worker_url, site_for_cookies, |
| 2414 | top_frame_origin); |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2415 | |
| 2416 | TabSpecificContentSettings::SharedWorkerAccessed( |
Hiroki Nakagawa | 018bb6d | 2017-11-30 03:31:37 | [diff] [blame] | 2417 | render_process_id, render_frame_id, worker_url, name, constructor_origin, |
| 2418 | !allow); |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2419 | return allow; |
| 2420 | } |
| 2421 | |
Patrick Monette | 6cb099a | 2019-09-18 19:31:27 | [diff] [blame] | 2422 | bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker( |
| 2423 | const std::string& scheme) { |
| 2424 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 2425 | // Extensions are allowed to start cross-origin shared workers. |
| 2426 | if (scheme == extensions::kExtensionScheme) |
| 2427 | return true; |
| 2428 | #endif |
| 2429 | |
| 2430 | return false; |
| 2431 | } |
| 2432 | |
Clark DuVall | ab63d14 | 2019-07-23 04:24:36 | [diff] [blame] | 2433 | bool ChromeContentBrowserClient::AllowSignedExchange( |
| 2434 | content::BrowserContext* browser_context) { |
| 2435 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2436 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2437 | return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled); |
| 2438 | } |
| 2439 | |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2440 | void ChromeContentBrowserClient::AllowWorkerFileSystem( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2441 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2442 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2443 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2444 | base::OnceCallback<void(bool)> callback) { |
| 2445 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2446 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 2447 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2448 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2449 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2450 | GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2451 | #else |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2452 | FileSystemAccessed(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2453 | #endif |
| 2454 | } |
| 2455 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2456 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2457 | void ChromeContentBrowserClient::GuestPermissionRequestHelper( |
| 2458 | const GURL& url, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2459 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2460 | base::OnceCallback<void(bool)> callback, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2461 | bool allow) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2462 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2463 | std::map<int, int> process_map; |
| 2464 | std::map<int, int>::const_iterator it; |
| 2465 | bool has_web_view_guest = false; |
| 2466 | // Record access to file system for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2467 | for (const auto& it : render_frames) { |
| 2468 | if (process_map.find(it.child_id) != process_map.end()) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2469 | continue; |
| 2470 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2471 | 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] | 2472 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2473 | if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id)) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2474 | has_web_view_guest = true; |
| 2475 | } |
| 2476 | if (!has_web_view_guest) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2477 | FileSystemAccessed(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2478 | return; |
| 2479 | } |
[email protected] | dffb9fc | 2014-07-16 04:14:02 | [diff] [blame] | 2480 | DCHECK_EQ(1U, process_map.size()); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2481 | it = process_map.begin(); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2482 | |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 2483 | extensions::WebViewPermissionHelper* web_view_permission_helper = |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2484 | extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second); |
| 2485 | web_view_permission_helper->RequestFileSystemPermission( |
| 2486 | url, allow, |
| 2487 | base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed, |
| 2488 | weak_factory_.GetWeakPtr(), url, render_frames, |
| 2489 | std::move(callback))); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2490 | } |
| 2491 | #endif |
| 2492 | |
| 2493 | void ChromeContentBrowserClient::FileSystemAccessed( |
| 2494 | const GURL& url, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2495 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2496 | base::OnceCallback<void(bool)> callback, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2497 | bool allow) { |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 2498 | // Record access to file system for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2499 | for (const auto& it : render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2500 | TabSpecificContentSettings::FileSystemAccessed( |
| 2501 | it.child_id, it.frame_routing_id, url, !allow); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2502 | } |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2503 | std::move(callback).Run(allow); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2504 | } |
| 2505 | |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2506 | bool ChromeContentBrowserClient::AllowWorkerIndexedDB( |
| 2507 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2508 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2509 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2510 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2511 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
| 2512 | |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 2513 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2514 | |
| 2515 | // Record access to IndexedDB for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2516 | for (const auto& it : render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2517 | TabSpecificContentSettings::IndexedDBAccessed( |
| 2518 | it.child_id, it.frame_routing_id, url, !allow); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | return allow; |
| 2522 | } |
| 2523 | |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2524 | bool ChromeContentBrowserClient::AllowWorkerCacheStorage( |
| 2525 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2526 | content::BrowserContext* browser_context, |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2527 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2528 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2529 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2530 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
| 2531 | |
| 2532 | // Record access to CacheStorage for potential display in UI. |
| 2533 | for (const auto& it : render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2534 | TabSpecificContentSettings::CacheStorageAccessed( |
| 2535 | it.child_id, it.frame_routing_id, url, !allow); |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | return allow; |
| 2539 | } |
| 2540 | |
Joshua Bell | 1ebc8df | 2019-11-06 00:27:58 | [diff] [blame] | 2541 | bool ChromeContentBrowserClient::AllowWorkerWebLocks( |
| 2542 | const GURL& url, |
| 2543 | content::BrowserContext* browser_context, |
| 2544 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
| 2545 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2546 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
| 2547 | return cookie_settings->IsCookieAccessAllowed(url, url); |
| 2548 | } |
| 2549 | |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2550 | ChromeContentBrowserClient::AllowWebBluetoothResult |
| 2551 | ChromeContentBrowserClient::AllowWebBluetooth( |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2552 | content::BrowserContext* browser_context, |
| 2553 | const url::Origin& requesting_origin, |
| 2554 | const url::Origin& embedding_origin) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2555 | // TODO(crbug.com/598890): Don't disable if |
| 2556 | // base::CommandLine::ForCurrentProcess()-> |
| 2557 | // HasSwitch(switches::kEnableWebBluetooth) is true. |
| 2558 | if (variations::GetVariationParamValue( |
| 2559 | PermissionContextBase::kPermissionsKillSwitchFieldStudy, |
| 2560 | "Bluetooth") == |
| 2561 | PermissionContextBase::kPermissionsKillSwitchBlockedValue) { |
| 2562 | // The kill switch is enabled for this permission. Block requests. |
| 2563 | return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED; |
| 2564 | } |
| 2565 | |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2566 | const HostContentSettingsMap* const content_settings = |
| 2567 | HostContentSettingsMapFactory::GetForProfile( |
| 2568 | Profile::FromBrowserContext(browser_context)); |
| 2569 | |
csharrison | aec2c54 | 2016-10-12 19:40:36 | [diff] [blame] | 2570 | if (content_settings->GetContentSetting( |
| 2571 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2572 | ContentSettingsType::BLUETOOTH_GUARD, |
csharrison | aec2c54 | 2016-10-12 19:40:36 | [diff] [blame] | 2573 | std::string()) == CONTENT_SETTING_BLOCK) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2574 | return AllowWebBluetoothResult::BLOCK_POLICY; |
| 2575 | } |
| 2576 | return AllowWebBluetoothResult::ALLOW; |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2577 | } |
| 2578 | |
beaufort.francois | 01135bf | 2016-11-23 14:37:36 | [diff] [blame] | 2579 | std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() { |
| 2580 | return variations::GetVariationParamValue("WebBluetoothBlocklist", |
| 2581 | "blocklist_additions"); |
scheib | 7425032 | 2016-04-07 03:32:21 | [diff] [blame] | 2582 | } |
| 2583 | |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 2584 | #if defined(OS_CHROMEOS) |
John Abd-El-Malek | a5b1a5d60 | 2018-11-05 19:20:52 | [diff] [blame] | 2585 | void ChromeContentBrowserClient::OnTrustAnchorUsed( |
John Abd-El-Malek | 35bfaa5 | 2019-08-20 16:22:07 | [diff] [blame] | 2586 | content::BrowserContext* browser_context) { |
| 2587 | user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 2588 | if (user_manager) { |
| 2589 | const user_manager::User* user = |
| 2590 | chromeos::ProfileHelper::Get()->GetUserByProfile( |
| 2591 | Profile::FromBrowserContext(browser_context)); |
| 2592 | if (user && !user->username_hash().empty()) { |
| 2593 | policy::PolicyCertServiceFactory::SetUsedPolicyCertificates( |
| 2594 | user->username_hash()); |
| 2595 | } |
| 2596 | } |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 2597 | } |
| 2598 | #endif |
| 2599 | |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2600 | scoped_refptr<network::SharedURLLoaderFactory> |
| 2601 | ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() { |
Min Qin | da0d55b | 2018-10-12 18:30:05 | [diff] [blame] | 2602 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 2603 | !BrowserThread::IsThreadInitialized(BrowserThread::UI)); |
| 2604 | |
| 2605 | if (!SystemNetworkContextManager::GetInstance()) |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2606 | return nullptr; |
| 2607 | |
Min Qin | da0d55b | 2018-10-12 18:30:05 | [diff] [blame] | 2608 | return SystemNetworkContextManager::GetInstance() |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2609 | ->GetSharedURLLoaderFactory(); |
Andrew Moylan | 8673dba | 2017-10-10 04:29:04 | [diff] [blame] | 2610 | } |
| 2611 | |
Sean Gilhuly | da1ee4b | 2018-11-13 21:56:09 | [diff] [blame] | 2612 | network::mojom::NetworkContext* |
| 2613 | ChromeContentBrowserClient::GetSystemNetworkContext() { |
| 2614 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2615 | DCHECK(g_browser_process->system_network_context_manager()); |
| 2616 | return g_browser_process->system_network_context_manager()->GetContext(); |
| 2617 | } |
| 2618 | |
Andrew Moylan | 17329fc | 2017-09-25 07:43:30 | [diff] [blame] | 2619 | std::string ChromeContentBrowserClient::GetGeolocationApiKey() { |
| 2620 | return google_apis::GetAPIKey(); |
| 2621 | } |
| 2622 | |
Ke He | 21ee87f | 2018-05-30 02:35:32 | [diff] [blame] | 2623 | #if defined(OS_ANDROID) |
| 2624 | bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() { |
| 2625 | // Indicate that Chrome uses the GMS core location provider. |
| 2626 | return true; |
| 2627 | } |
| 2628 | #endif |
| 2629 | |
Yeol | f3dc22ca | 2019-04-18 17:25:32 | [diff] [blame] | 2630 | scoped_refptr<content::QuotaPermissionContext> |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 2631 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
| 2632 | return new ChromeQuotaPermissionContext(); |
| 2633 | } |
| 2634 | |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 2635 | void ChromeContentBrowserClient::GetQuotaSettings( |
| 2636 | content::BrowserContext* context, |
| 2637 | content::StoragePartition* partition, |
tapted | e6d878e | 2017-06-24 01:53:45 | [diff] [blame] | 2638 | storage::OptionalQuotaSettingsCallback callback) { |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 2639 | if (g_default_quota_settings) { |
| 2640 | // For debugging tests harness can inject settings. |
tapted | e6d878e | 2017-06-24 01:53:45 | [diff] [blame] | 2641 | std::move(callback).Run(*g_default_quota_settings); |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 2642 | return; |
| 2643 | } |
tapted | e6d878e | 2017-06-24 01:53:45 | [diff] [blame] | 2644 | storage::GetNominalDynamicSettings( |
Jarryd | 451ab7b | 2019-02-12 06:39:06 | [diff] [blame] | 2645 | partition->GetPath(), context->IsOffTheRecord(), |
Jarryd | 1f02b90 | 2019-11-07 03:29:57 | [diff] [blame] | 2646 | storage::GetDefaultDeviceInfoHelper(), std::move(callback)); |
calamity | c96116b | 2015-11-03 04:30:51 | [diff] [blame] | 2647 | } |
| 2648 | |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 2649 | content::GeneratedCodeCacheSettings |
| 2650 | ChromeContentBrowserClient::GetGeneratedCodeCacheSettings( |
| 2651 | content::BrowserContext* context) { |
| 2652 | base::FilePath cache_path; |
| 2653 | chrome::GetUserCacheDirectory(context->GetPath(), &cache_path); |
| 2654 | // If we pass 0 for size, disk_cache will pick a default size using the |
| 2655 | // heuristics based on available disk size. These are implemented in |
| 2656 | // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc. |
Mythri A | b248657 | 2019-06-13 14:48:16 | [diff] [blame] | 2657 | int64_t size_in_bytes = 0; |
Greg Thompson | 8c922756 | 2019-08-05 17:47:13 | [diff] [blame] | 2658 | DCHECK(g_browser_process); |
| 2659 | PrefService* local_state = g_browser_process->local_state(); |
| 2660 | if (local_state) { |
| 2661 | size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize); |
| 2662 | base::FilePath disk_cache_dir = |
| 2663 | local_state->GetFilePath(prefs::kDiskCacheDir); |
| 2664 | if (!disk_cache_dir.empty()) |
| 2665 | cache_path = disk_cache_dir.Append(cache_path.BaseName()); |
| 2666 | } |
Mythri A | b248657 | 2019-06-13 14:48:16 | [diff] [blame] | 2667 | return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path); |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 2668 | } |
| 2669 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 2670 | void ChromeContentBrowserClient::AllowCertificateError( |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2671 | content::WebContents* web_contents, |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 2672 | int cert_error, |
| 2673 | const net::SSLInfo& ssl_info, |
| 2674 | const GURL& request_url, |
John Abd-El-Malek | c5b8df91 | 2019-05-07 17:02:23 | [diff] [blame] | 2675 | bool is_main_frame_request, |
[email protected] | d9be4770 | 2012-05-16 03:41:22 | [diff] [blame] | 2676 | bool strict_enforcement, |
Erik Staab | a65a603 | 2019-11-27 22:23:26 | [diff] [blame] | 2677 | base::OnceCallback<void(content::CertificateRequestResultType)> callback) { |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2678 | DCHECK(web_contents); |
John Abd-El-Malek | c5b8df91 | 2019-05-07 17:02:23 | [diff] [blame] | 2679 | if (!is_main_frame_request) { |
irisu | 8452ddd6 | 2017-03-22 07:46:14 | [diff] [blame] | 2680 | // A sub-resource has a certificate error. The user doesn't really |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 2681 | // have a context for making the right decision, so block the |
| 2682 | // request hard, without an info bar to allow showing the insecure |
| 2683 | // content. |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2684 | if (!callback.is_null()) |
Erik Staab | a65a603 | 2019-11-27 22:23:26 | [diff] [blame] | 2685 | std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 2686 | return; |
| 2687 | } |
| 2688 | |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 2689 | // If the tab is being prerendered, cancel the prerender and the request. |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2690 | prerender::PrerenderContents* prerender_contents = |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2691 | prerender::PrerenderContents::FromWebContents(web_contents); |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2692 | if (prerender_contents) { |
| 2693 | prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR); |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2694 | if (!callback.is_null()) { |
Erik Staab | a65a603 | 2019-11-27 22:23:26 | [diff] [blame] | 2695 | std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL); |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2696 | } |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2697 | return; |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 2698 | } |
| 2699 | |
Erik Staab | a65a603 | 2019-11-27 22:23:26 | [diff] [blame] | 2700 | std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 2701 | return; |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 2702 | } |
| 2703 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2704 | namespace { |
| 2705 | |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2706 | certificate_matching::CertificatePrincipalPattern |
| 2707 | ParseCertificatePrincipalPattern(const base::Value* pattern) { |
| 2708 | return certificate_matching::CertificatePrincipalPattern:: |
| 2709 | ParseFromOptionalDict(pattern, "CN", "L", "O", "OU"); |
| 2710 | } |
| 2711 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2712 | // Attempts to auto-select a client certificate according to the value of |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2713 | // |ContentSettingsType::AUTO_SELECT_CERTIFICATE| content setting for |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2714 | // |requesting_url|. If no certificate was auto-selected, returns nullptr. |
| 2715 | std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate( |
| 2716 | Profile* profile, |
| 2717 | const GURL& requesting_url, |
| 2718 | net::ClientCertIdentityList& client_certs) { |
| 2719 | HostContentSettingsMap* host_content_settings_map = |
| 2720 | HostContentSettingsMapFactory::GetForProfile(profile); |
| 2721 | std::unique_ptr<base::Value> setting = |
| 2722 | host_content_settings_map->GetWebsiteSetting( |
| 2723 | requesting_url, requesting_url, |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2724 | ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr); |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2725 | |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2726 | if (!setting || !setting->is_dict()) |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2727 | return nullptr; |
| 2728 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2729 | const base::Value* filters = |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2730 | setting->FindKeyOfType("filters", base::Value::Type::LIST); |
| 2731 | if (!filters) { |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2732 | // |setting_dict| has the wrong format (e.g. single filter instead of a |
| 2733 | // list of filters). This content setting is only provided by |
| 2734 | // the |PolicyProvider|, which should always set it to a valid format. |
| 2735 | // Therefore, delete the invalid value. |
| 2736 | host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 2737 | requesting_url, requesting_url, |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 2738 | ContentSettingsType::AUTO_SELECT_CERTIFICATE, std::string(), nullptr); |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2739 | return nullptr; |
| 2740 | } |
| 2741 | |
| 2742 | for (const base::Value& filter : filters->GetList()) { |
| 2743 | DCHECK(filter.is_dict()); |
| 2744 | |
| 2745 | auto issuer_pattern = ParseCertificatePrincipalPattern( |
| 2746 | filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY)); |
| 2747 | auto subject_pattern = ParseCertificatePrincipalPattern( |
| 2748 | filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY)); |
| 2749 | // Use the first certificate that is matched by the filter. |
| 2750 | for (auto& client_cert : client_certs) { |
| 2751 | if (issuer_pattern.Matches(client_cert->certificate()->issuer()) && |
| 2752 | subject_pattern.Matches(client_cert->certificate()->subject())) { |
| 2753 | return std::move(client_cert); |
| 2754 | } |
| 2755 | } |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | return nullptr; |
| 2759 | } |
| 2760 | |
| 2761 | } // namespace |
| 2762 | |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2763 | base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate( |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2764 | content::WebContents* web_contents, |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 2765 | net::SSLCertRequestInfo* cert_request_info, |
mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 2766 | net::ClientCertIdentityList client_certs, |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2767 | std::unique_ptr<content::ClientCertificateDelegate> delegate) { |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 2768 | prerender::PrerenderContents* prerender_contents = |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2769 | prerender::PrerenderContents::FromWebContents(web_contents); |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 2770 | if (prerender_contents) { |
| 2771 | prerender_contents->Destroy( |
| 2772 | prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2773 | return base::OnceClosure(); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 2774 | } |
| 2775 | |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 2776 | GURL requesting_url("https://" + cert_request_info->host_and_port.ToString()); |
| 2777 | DCHECK(requesting_url.is_valid()) |
| 2778 | << "Invalid URL string: https://" |
| 2779 | << cert_request_info->host_and_port.ToString(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 2780 | |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2781 | bool may_show_cert_selection = true; |
| 2782 | |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2783 | Profile* profile = |
| 2784 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2785 | #if defined(OS_CHROMEOS) |
| 2786 | if (chromeos::ProfileHelper::IsSigninProfile(profile)) { |
| 2787 | // TODO(pmarko): crbug.com/723849: Set |may_show_cert_selection| to false |
| 2788 | // and remove the command-line flag after prototype phase when the |
| 2789 | // DeviceLoginScreenAutoSelectCertificateForUrls policy is live. |
| 2790 | may_show_cert_selection = |
| 2791 | chromeos::switches::IsSigninFrameClientCertUserSelectionEnabled(); |
| 2792 | |
| 2793 | content::StoragePartition* storage_partition = |
| 2794 | content::BrowserContext::GetStoragePartition( |
| 2795 | profile, web_contents->GetSiteInstance()); |
| 2796 | chromeos::login::SigninPartitionManager* signin_partition_manager = |
| 2797 | chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext( |
| 2798 | profile); |
| 2799 | |
| 2800 | // On the sign-in profile, only allow client certs in the context of the |
| 2801 | // sign-in frame. |
| 2802 | if (!signin_partition_manager->IsCurrentSigninStoragePartition( |
| 2803 | storage_partition)) { |
| 2804 | LOG(WARNING) |
| 2805 | << "Client cert requested in sign-in profile in wrong context."; |
| 2806 | // Continue without client certificate. We do this to mimic the case of no |
| 2807 | // client certificate being present in the profile's certificate store. |
| 2808 | delegate->ContinueWithCertificate(nullptr, nullptr); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2809 | return base::OnceClosure(); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2810 | } |
| 2811 | VLOG(1) << "Client cert requested in sign-in profile."; |
| 2812 | } |
| 2813 | #endif // defined(OS_CHROMEOS) |
| 2814 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2815 | std::unique_ptr<net::ClientCertIdentity> auto_selected_identity = |
| 2816 | AutoSelectCertificate(profile, requesting_url, client_certs); |
| 2817 | if (auto_selected_identity) { |
| 2818 | // The callback will own |auto_selected_identity| and |delegate|, keeping |
| 2819 | // them alive until after ContinueWithCertificate is called. |
| 2820 | scoped_refptr<net::X509Certificate> cert = |
| 2821 | auto_selected_identity->certificate(); |
| 2822 | net::ClientCertIdentity::SelfOwningAcquirePrivateKey( |
| 2823 | std::move(auto_selected_identity), |
David Benjamin | 0cda204 | 2019-04-08 23:00:58 | [diff] [blame] | 2824 | base::BindOnce( |
| 2825 | &content::ClientCertificateDelegate::ContinueWithCertificate, |
| 2826 | std::move(delegate), std::move(cert))); |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 2827 | LogClientAuthResult(ClientCertSelectionResult::kAutoSelect); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2828 | return base::OnceClosure(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 2829 | } |
| 2830 | |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2831 | if (!may_show_cert_selection) { |
| 2832 | LOG(WARNING) << "No client cert matched by policy and user selection is " |
| 2833 | "not allowed."; |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 2834 | LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2835 | // Continue without client certificate. We do this to mimic the case of no |
| 2836 | // client certificate being present in the profile's certificate store. |
| 2837 | delegate->ContinueWithCertificate(nullptr, nullptr); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2838 | return base::OnceClosure(); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2839 | } |
| 2840 | |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2841 | return chrome::ShowSSLClientCertificateSelector( |
| 2842 | web_contents, cert_request_info, std::move(client_certs), |
| 2843 | std::move(delegate)); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 2844 | } |
| 2845 | |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 2846 | content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { |
[email protected] | 11158e2d | 2013-02-01 02:31:56 | [diff] [blame] | 2847 | return MediaCaptureDevicesDispatcher::GetInstance(); |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 2848 | } |
| 2849 | |
Francois Doray | fd823bb1 | 2019-10-04 18:03:05 | [diff] [blame] | 2850 | content::LockObserver* ChromeContentBrowserClient::GetLockObserver() { |
François Doray | aa3f8010 | 2019-10-12 02:29:24 | [diff] [blame] | 2851 | return ChromeBrowserMainExtraPartsPerformanceManager::GetInstance() |
| 2852 | ->GetLockObserver(); |
Francois Doray | fd823bb1 | 2019-10-04 18:03:05 | [diff] [blame] | 2853 | } |
| 2854 | |
peter | c26c6c6 | 2014-12-10 14:13:59 | [diff] [blame] | 2855 | content::PlatformNotificationService* |
Richard Knoll | d0eae96 | 2019-04-04 12:34:02 | [diff] [blame] | 2856 | ChromeContentBrowserClient::GetPlatformNotificationService( |
| 2857 | content::BrowserContext* browser_context) { |
| 2858 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2859 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2860 | return PlatformNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2861 | } |
| 2862 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2863 | bool ChromeContentBrowserClient::CanCreateWindow( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2864 | RenderFrameHost* opener, |
[email protected] | 2b751a1 | 2012-03-06 03:00:35 | [diff] [blame] | 2865 | const GURL& opener_url, |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 2866 | const GURL& opener_top_level_frame_url, |
Nasko Oskov | e9f1978 | 2019-01-04 18:32:35 | [diff] [blame] | 2867 | const url::Origin& source_origin, |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 2868 | content::mojom::WindowContainerType container_type, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2869 | const GURL& target_url, |
| 2870 | const content::Referrer& referrer, |
jochen | 67b271b | 2016-08-03 13:50:21 | [diff] [blame] | 2871 | const std::string& frame_name, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2872 | WindowOpenDisposition disposition, |
scottmg | 8e6c608 | 2017-02-13 23:15:48 | [diff] [blame] | 2873 | const blink::mojom::WindowFeatures& features, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2874 | bool user_gesture, |
| 2875 | bool opener_suppressed, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2876 | bool* no_javascript_access) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2877 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2878 | DCHECK(opener); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2879 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2880 | content::WebContents* web_contents = |
| 2881 | content::WebContents::FromRenderFrameHost(opener); |
| 2882 | Profile* profile = |
| 2883 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 2884 | DCHECK(profile); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2885 | *no_javascript_access = false; |
| 2886 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2887 | // If the opener is trying to create a background window but doesn't have |
| 2888 | // the appropriate permission, fail the attempt. |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 2889 | if (container_type == content::mojom::WindowContainerType::BACKGROUND) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2890 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2891 | auto* process_map = extensions::ProcessMap::Get(profile); |
| 2892 | auto* registry = extensions::ExtensionRegistry::Get(profile); |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 2893 | if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url, |
| 2894 | opener->GetProcess()->GetID())) { |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2895 | return false; |
| 2896 | } |
| 2897 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 2898 | // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may |
| 2899 | // return a recently installed Extension even if this CanCreateWindow call |
| 2900 | // 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] | 2901 | // because the permission check above would have caused an early return |
| 2902 | // already. We must use the full URL to find hosted apps, though, and not |
| 2903 | // just the origin. |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 2904 | const Extension* extension = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2905 | registry->enabled_extensions().GetExtensionOrAppByURL(opener_url); |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 2906 | if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2907 | *no_javascript_access = true; |
[email protected] | dffb9fc | 2014-07-16 04:14:02 | [diff] [blame] | 2908 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2909 | |
| 2910 | return true; |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2911 | } |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 2912 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2913 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 2914 | if (extensions::WebViewRendererState::GetInstance()->IsGuest( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2915 | opener->GetProcess()->GetID())) { |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2916 | return true; |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 2917 | } |
| 2918 | |
nick | 0fbc392 | 2016-12-16 20:52:07 | [diff] [blame] | 2919 | if (target_url.SchemeIs(extensions::kExtensionScheme)) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2920 | // Intentionally duplicating |registry| code from above because we want to |
| 2921 | // reduce calls to retrieve them as this function is a SYNC IPC handler. |
| 2922 | auto* registry = extensions::ExtensionRegistry::Get(profile); |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 2923 | const Extension* extension = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2924 | registry->enabled_extensions().GetExtensionOrAppByURL(target_url); |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 2925 | if (extension && extension->is_platform_app()) { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 2926 | UMA_HISTOGRAM_ENUMERATION( |
| 2927 | "Extensions.AppLoadedInTab", |
| 2928 | ClassifyAppLoadedInTabSource(opener_url, extension), |
| 2929 | APP_LOADED_IN_TAB_SOURCE_MAX); |
| 2930 | |
| 2931 | // window.open() may not be used to load v2 apps in a regular tab. |
lazyboy | 39585ed | 2016-12-06 19:30:16 | [diff] [blame] | 2932 | return false; |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 2933 | } |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 2934 | } |
[email protected] | 5940b0d | 2014-07-01 00:18:26 | [diff] [blame] | 2935 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2936 | |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 2937 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2938 | HostContentSettingsMap* content_settings = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2939 | HostContentSettingsMapFactory::GetForProfile(profile); |
tommycli | 61f6f0c | 2016-09-21 00:26:58 | [diff] [blame] | 2940 | if (FlashDownloadInterception::ShouldStopFlashDownloadAction( |
| 2941 | content_settings, opener_top_level_frame_url, target_url, |
| 2942 | user_gesture)) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2943 | FlashDownloadInterception::InterceptFlashDownloadNavigation( |
| 2944 | web_contents, opener_top_level_frame_url); |
tommycli | 61f6f0c | 2016-09-21 00:26:58 | [diff] [blame] | 2945 | return false; |
| 2946 | } |
| 2947 | #endif |
| 2948 | |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 2949 | // Don't let prerenders open popups. |
| 2950 | if (auto* prerender_contents = |
| 2951 | prerender::PrerenderContents::FromWebContents(web_contents)) { |
| 2952 | prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW); |
| 2953 | return false; |
| 2954 | } |
| 2955 | |
Aaron Colwell | 9dab165 | 2019-12-09 18:29:49 | [diff] [blame] | 2956 | BlockedWindowParams blocked_params( |
| 2957 | target_url, source_origin, opener->GetSiteInstance(), referrer, |
| 2958 | frame_name, disposition, features, user_gesture, opener_suppressed); |
cm.sanchi | 2522bc9 | 2017-12-04 08:04:13 | [diff] [blame] | 2959 | NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents); |
Lei Zhang | 31c778f | 2019-09-23 20:32:19 | [diff] [blame] | 2960 | return !MaybeBlockPopup(web_contents, &opener_top_level_frame_url, |
| 2961 | &nav_params, nullptr /*=open_url_params*/, |
| 2962 | blocked_params.features()); |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2963 | } |
| 2964 | |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 2965 | content::SpeechRecognitionManagerDelegate* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2966 | ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() { |
[email protected] | 855e18b | 2013-07-08 21:02:00 | [diff] [blame] | 2967 | return new speech::ChromeSpeechRecognitionManagerDelegate(); |
[email protected] | 66cfec6 | 2012-02-24 17:57:51 | [diff] [blame] | 2968 | } |
| 2969 | |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 2970 | content::TtsControllerDelegate* |
| 2971 | ChromeContentBrowserClient::GetTtsControllerDelegate() { |
| 2972 | TtsControllerDelegateImpl* delegate = |
| 2973 | TtsControllerDelegateImpl::GetInstance(); |
| 2974 | #if !defined(OS_ANDROID) |
| 2975 | TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance(); |
| 2976 | delegate->SetTtsEngineDelegate(tts_extension_engine); |
| 2977 | #endif |
| 2978 | return delegate; |
| 2979 | } |
| 2980 | |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 2981 | content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() { |
| 2982 | #ifdef OS_CHROMEOS |
| 2983 | return TtsPlatformImplChromeOs::GetInstance(); |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 2984 | #else |
| 2985 | return nullptr; |
| 2986 | #endif |
| 2987 | } |
| 2988 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 2989 | void ChromeContentBrowserClient::OverrideWebkitPrefs( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2990 | RenderViewHost* rvh, |
| 2991 | WebPreferences* web_prefs) { |
| 2992 | Profile* profile = |
| 2993 | Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2994 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 2995 | |
aelias | 0df335a | 2017-03-02 23:43:51 | [diff] [blame] | 2996 | // Fill font preferences. These are not registered on Android |
| 2997 | // - http://crbug.com/308033, http://crbug.com/696364. |
[email protected] | 33b7954 | 2013-10-18 11:18:45 | [diff] [blame] | 2998 | #if !defined(OS_ANDROID) |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 2999 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3000 | prefs::kWebKitStandardFontFamilyMap, |
| 3001 | &web_prefs->standard_font_family_map); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3002 | FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap, |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3003 | &web_prefs->fixed_font_family_map); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3004 | FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap, |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3005 | &web_prefs->serif_font_family_map); |
| 3006 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3007 | prefs::kWebKitSansSerifFontFamilyMap, |
| 3008 | &web_prefs->sans_serif_font_family_map); |
| 3009 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3010 | prefs::kWebKitCursiveFontFamilyMap, |
| 3011 | &web_prefs->cursive_font_family_map); |
| 3012 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3013 | prefs::kWebKitFantasyFontFamilyMap, |
| 3014 | &web_prefs->fantasy_font_family_map); |
| 3015 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3016 | prefs::kWebKitPictographFontFamilyMap, |
| 3017 | &web_prefs->pictograph_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3018 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3019 | web_prefs->default_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3020 | prefs->GetInteger(prefs::kWebKitDefaultFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3021 | web_prefs->default_fixed_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3022 | prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3023 | web_prefs->minimum_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3024 | prefs->GetInteger(prefs::kWebKitMinimumFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3025 | web_prefs->minimum_logical_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3026 | prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize); |
aelias | 0df335a | 2017-03-02 23:43:51 | [diff] [blame] | 3027 | #endif |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3028 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3029 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3030 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3031 | web_prefs->dom_paste_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3032 | prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); |
Joel Hockey | 08a6c84c | 2018-04-11 10:09:21 | [diff] [blame] | 3033 | web_prefs->javascript_can_access_clipboard = |
| 3034 | prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3035 | web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3036 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3037 | if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3038 | web_prefs->javascript_enabled = false; |
mkwst | a1f7749b | 2015-12-28 09:28:57 | [diff] [blame] | 3039 | |
Avi Drissman | 1aa6cb9 | 2019-01-23 15:58:38 | [diff] [blame] | 3040 | if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3041 | web_prefs->web_security_enabled = false; |
mkwst | a1f7749b | 2015-12-28 09:28:57 | [diff] [blame] | 3042 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3043 | if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3044 | web_prefs->plugins_enabled = false; |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3045 | web_prefs->loads_images_automatically = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3046 | prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3047 | |
Zhenyao Mo | a3fda997 | 2017-09-16 01:34:40 | [diff] [blame] | 3048 | if (prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 3049 | web_prefs->webgl1_enabled = false; |
| 3050 | web_prefs->webgl2_enabled = false; |
| 3051 | } |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3052 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3053 | web_prefs->allow_running_insecure_content = |
| 3054 | prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3055 | #if defined(OS_ANDROID) |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 3056 | web_prefs->font_scale_factor = |
| 3057 | static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor)); |
| 3058 | web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment(); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3059 | web_prefs->force_enable_zoom = |
| 3060 | prefs->GetBoolean(prefs::kWebKitForceEnableZoom); |
Aran Gilman | 5e9672bed | 2019-08-02 19:07:49 | [diff] [blame] | 3061 | #endif |
Becky Zhou | bbfbde3 | 2019-02-20 17:07:59 | [diff] [blame] | 3062 | web_prefs->force_dark_mode_enabled = |
| 3063 | prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled); |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 3064 | |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 3065 | #if defined(OS_ANDROID) |
| 3066 | web_prefs->password_echo_enabled = |
| 3067 | prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled); |
| 3068 | #else |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 3069 | web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled; |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 3070 | #endif |
| 3071 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3072 | web_prefs->text_areas_are_resizable = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3073 | prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3074 | web_prefs->hyperlink_auditing_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3075 | prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); |
| 3076 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3077 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 3078 | std::string image_animation_policy = |
| 3079 | prefs->GetString(prefs::kAnimationPolicy); |
| 3080 | if (image_animation_policy == kAnimationPolicyOnce) |
| 3081 | web_prefs->animation_policy = |
| 3082 | content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE; |
| 3083 | else if (image_animation_policy == kAnimationPolicyNone) |
| 3084 | web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION; |
| 3085 | else |
| 3086 | web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED; |
| 3087 | #endif |
| 3088 | |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3089 | // Make sure we will set the default_encoding with canonical encoding name. |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 3090 | web_prefs->default_encoding = |
| 3091 | base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3092 | if (web_prefs->default_encoding.empty()) { |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3093 | prefs->ClearPref(prefs::kDefaultCharset); |
| 3094 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3095 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3096 | DCHECK(!web_prefs->default_encoding.empty()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3097 | |
mkwst | 0554410 | 2015-01-10 20:26:16 | [diff] [blame] | 3098 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3099 | switches::kEnablePotentiallyAnnoyingSecurityFeatures)) { |
mkwst | 772ce814 | 2015-01-16 13:28:07 | [diff] [blame] | 3100 | web_prefs->disable_reading_from_canvas = true; |
mkwst | 0554410 | 2015-01-10 20:26:16 | [diff] [blame] | 3101 | web_prefs->strict_mixed_content_checking = true; |
| 3102 | web_prefs->strict_powerful_feature_restrictions = true; |
| 3103 | } |
| 3104 | |
Robert Ogden | cf2872d | 2019-03-19 18:59:37 | [diff] [blame] | 3105 | web_prefs->data_saver_enabled = IsDataSaverEnabled(profile); |
Ben Greenstein | 49878f5 | 2015-12-18 19:13:21 | [diff] [blame] | 3106 | |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 3107 | web_prefs->data_saver_holdback_web_api_enabled = |
| 3108 | base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback, |
| 3109 | "holdback_web", false); |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 3110 | |
Alison Maher | 28a73e2 | 2019-10-18 19:26:35 | [diff] [blame] | 3111 | auto* native_theme = GetWebTheme(); |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3112 | auto* contents = content::WebContents::FromRenderViewHost(rvh); |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3113 | if (contents) { |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3114 | #if defined(OS_ANDROID) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3115 | auto* delegate = TabAndroid::FromWebContents(contents) |
| 3116 | ? static_cast<android::TabWebContentsDelegateAndroid*>( |
| 3117 | contents->GetDelegate()) |
| 3118 | : nullptr; |
| 3119 | if (delegate) { |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3120 | web_prefs->embedded_media_experience_enabled = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3121 | delegate->ShouldEnableEmbeddedMediaExperience(); |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3122 | |
Mounir Lamouri | 9c99a160 | 2018-07-05 15:01:44 | [diff] [blame] | 3123 | web_prefs->picture_in_picture_enabled = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3124 | delegate->IsPictureInPictureEnabled(); |
Rune Lillesveen | 17e4832 | 2019-04-15 23:12:38 | [diff] [blame] | 3125 | |
Alison Maher | 28a73e2 | 2019-10-18 19:26:35 | [diff] [blame] | 3126 | // Notify NativeTheme of changes to night mode. |
| 3127 | native_theme->set_preferred_color_scheme( |
| 3128 | delegate->IsNightModeEnabled() |
| 3129 | ? ui::NativeTheme::PreferredColorScheme::kDark |
| 3130 | : ui::NativeTheme::PreferredColorScheme::kLight); |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3131 | } |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3132 | #endif // defined(OS_ANDROID) |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3133 | |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3134 | // web_app_scope value is platform specific. |
| 3135 | #if defined(OS_ANDROID) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3136 | if (delegate) |
| 3137 | web_prefs->web_app_scope = delegate->GetManifestScope(); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3138 | #elif BUILDFLAG(ENABLE_EXTENSIONS) |
| 3139 | { |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3140 | web_prefs->web_app_scope = GURL(); |
| 3141 | // Set |web_app_scope| based on the app associated with the app window if |
| 3142 | // any. Note that the app associated with the window never changes, even |
| 3143 | // if the app navigates off scope. This is not a problem because we still |
| 3144 | // want to use the scope of the app associated with the window, not the |
| 3145 | // WebContents. |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3146 | Browser* browser = chrome::FindBrowserWithWebContents(contents); |
Alan Cutter | d0bd5190 | 2019-05-22 04:15:23 | [diff] [blame] | 3147 | if (browser && browser->app_controller() && |
Eric Willigers | e339c1e | 2019-05-13 19:22:44 | [diff] [blame] | 3148 | browser->app_controller()->CreatedForInstalledPwa()) { |
Yining Wang | 234ad327 | 2019-04-08 18:47:27 | [diff] [blame] | 3149 | // PWAs should be hosted apps. |
Eric Willigers | e339c1e | 2019-05-13 19:22:44 | [diff] [blame] | 3150 | DCHECK(browser->app_controller()->IsHostedApp()); |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3151 | // HostedApps that are PWAs are always created through WebAppProvider |
Alexey Baskakov | aca7a0c | 2019-07-29 07:34:05 | [diff] [blame] | 3152 | // for profiles that support them, so we should always be able to |
| 3153 | // retrieve a WebAppProvider from the Profile. |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3154 | // |
| 3155 | // Similarly, if a Hosted Apps is a PWA, it will always have a scope |
Alan Cutter | f25cfe4 | 2019-07-16 02:40:12 | [diff] [blame] | 3156 | // so there is no need to test for has_value(). |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3157 | web_prefs->web_app_scope = |
| 3158 | web_app::WebAppProvider::Get(profile) |
| 3159 | ->registrar() |
Jiewei Qian | f33ba1a | 2019-11-04 23:23:03 | [diff] [blame] | 3160 | .GetAppScope(browser->app_controller()->GetAppId()) |
Alan Cutter | f25cfe4 | 2019-07-16 02:40:12 | [diff] [blame] | 3161 | .value(); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3162 | } |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3163 | } |
| 3164 | #endif |
| 3165 | |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3166 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 3167 | Browser* browser = chrome::FindBrowserWithWebContents(contents); |
Eric Willigers | e339c1e | 2019-05-13 19:22:44 | [diff] [blame] | 3168 | if (browser && browser->app_controller() && |
| 3169 | browser->app_controller()->CreatedForInstalledPwa()) { |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3170 | web_prefs->strict_mixed_content_checking = true; |
| 3171 | } |
| 3172 | #endif |
| 3173 | |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3174 | web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents); |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3175 | } |
zqzhang | 93e959d1 | 2017-03-16 13:10:20 | [diff] [blame] | 3176 | |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3177 | #if defined(OS_ANDROID) |
Ted Choc | 81c89fc5 | 2018-06-22 23:51:14 | [diff] [blame] | 3178 | web_prefs->video_fullscreen_detection_enabled = true; |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3179 | #endif // defined(OS_ANDROID) |
| 3180 | |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 3181 | if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) { |
| 3182 | // Obtain the maximum effective connection type at which the feature is |
| 3183 | // enabled. |
| 3184 | std::string effective_connection_type_param = |
| 3185 | base::GetFieldTrialParamValueByFeature( |
| 3186 | features::kLowPriorityIframes, |
| 3187 | "max_effective_connection_type_threshold"); |
| 3188 | |
| 3189 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3190 | net::GetEffectiveConnectionTypeForName(effective_connection_type_param); |
| 3191 | if (effective_connection_type) { |
| 3192 | web_prefs->low_priority_iframes_threshold = |
| 3193 | effective_connection_type.value(); |
| 3194 | } |
| 3195 | } |
| 3196 | |
rajendrant | 0521cee | 2019-07-29 06:09:26 | [diff] [blame] | 3197 | web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() || |
| 3198 | contents->GetDelegate()->ShouldAllowLazyLoad(); |
rajendrant | e87ed71 | 2018-11-30 01:55:00 | [diff] [blame] | 3199 | |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 3200 | if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) { |
| 3201 | const char* param_name = |
| 3202 | web_prefs->data_saver_enabled |
| 3203 | ? "lazy_frame_loading_distance_thresholds_px_by_ect" |
| 3204 | : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_" |
| 3205 | "saver_enabled"; |
| 3206 | |
| 3207 | base::StringPairs pairs; |
| 3208 | base::SplitStringIntoKeyValuePairs( |
| 3209 | base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading, |
| 3210 | param_name), |
| 3211 | ':', ',', &pairs); |
| 3212 | |
| 3213 | for (const auto& pair : pairs) { |
| 3214 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3215 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3216 | int value = 0; |
| 3217 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3218 | web_prefs->lazy_frame_loading_distance_thresholds_px |
| 3219 | [effective_connection_type.value()] = value; |
| 3220 | } |
| 3221 | } |
| 3222 | } |
| 3223 | |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 3224 | if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) { |
| 3225 | const char* param_name = |
| 3226 | web_prefs->data_saver_enabled |
| 3227 | ? "lazy_image_loading_distance_thresholds_px_by_ect" |
| 3228 | : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_" |
| 3229 | "saver_enabled"; |
| 3230 | |
| 3231 | base::StringPairs pairs; |
| 3232 | base::SplitStringIntoKeyValuePairs( |
| 3233 | base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading, |
| 3234 | param_name), |
| 3235 | ':', ',', &pairs); |
| 3236 | |
| 3237 | for (const auto& pair : pairs) { |
| 3238 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3239 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3240 | int value = 0; |
| 3241 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3242 | web_prefs->lazy_image_loading_distance_thresholds_px |
| 3243 | [effective_connection_type.value()] = value; |
| 3244 | } |
| 3245 | } |
rajendrant | 3daeae29 | 2019-09-20 07:57:54 | [diff] [blame] | 3246 | |
| 3247 | pairs.clear(); |
| 3248 | base::SplitStringIntoKeyValuePairs( |
| 3249 | base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading, |
| 3250 | "lazy_image_first_k_fully_load"), |
| 3251 | ':', ',', &pairs); |
| 3252 | |
| 3253 | for (const auto& pair : pairs) { |
| 3254 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3255 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3256 | int value = 0; |
| 3257 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3258 | web_prefs |
| 3259 | ->lazy_image_first_k_fully_load[effective_connection_type.value()] = |
| 3260 | value; |
| 3261 | } |
| 3262 | } |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 3263 | } |
| 3264 | |
Tarun Bansal | d10f17a0 | 2018-09-13 00:23:17 | [diff] [blame] | 3265 | if (base::FeatureList::IsEnabled( |
| 3266 | features::kNetworkQualityEstimatorWebHoldback)) { |
| 3267 | std::string effective_connection_type_param = |
| 3268 | base::GetFieldTrialParamValueByFeature( |
| 3269 | features::kNetworkQualityEstimatorWebHoldback, |
| 3270 | "web_effective_connection_type_override"); |
| 3271 | |
| 3272 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3273 | net::GetEffectiveConnectionTypeForName(effective_connection_type_param); |
| 3274 | DCHECK(effective_connection_type_param.empty() || |
| 3275 | effective_connection_type); |
| 3276 | if (effective_connection_type) { |
| 3277 | DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 3278 | effective_connection_type.value()); |
| 3279 | web_prefs->network_quality_estimator_web_holdback = |
| 3280 | effective_connection_type.value(); |
| 3281 | } |
| 3282 | } |
| 3283 | |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3284 | #if !defined(OS_ANDROID) |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 3285 | if (IsAutoplayAllowedByPolicy(contents, prefs)) { |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3286 | // If autoplay is allowed by policy then force the no user gesture required |
| 3287 | // autoplay policy. |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3288 | web_prefs->autoplay_policy = |
| 3289 | content::AutoplayPolicy::kNoUserGestureRequired; |
Mounir Lamouri | c2186808 | 2018-10-11 21:09:55 | [diff] [blame] | 3290 | } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) && |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3291 | web_prefs->autoplay_policy == |
| 3292 | content::AutoplayPolicy::kDocumentUserActivationRequired) { |
Mounir Lamouri | c2186808 | 2018-10-11 21:09:55 | [diff] [blame] | 3293 | // If the autoplay disable settings feature is enabled and the autoplay |
| 3294 | // policy is set to using the unified policy then set the default autoplay |
| 3295 | // policy based on user preference. |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3296 | web_prefs->autoplay_policy = |
| 3297 | UnifiedAutoplayConfig::ShouldBlockAutoplay(profile) |
| 3298 | ? content::AutoplayPolicy::kDocumentUserActivationRequired |
| 3299 | : content::AutoplayPolicy::kNoUserGestureRequired; |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3300 | } |
| 3301 | #endif // !defined(OS_ANDROID) |
| 3302 | |
Dave Tapuska | c6627e1 | 2018-08-30 15:07:19 | [diff] [blame] | 3303 | web_prefs->translate_service_available = TranslateService::IsAvailable(prefs); |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3304 | |
| 3305 | // Apply native CaptionStyle parameters. |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3306 | base::Optional<ui::CaptionStyle> style; |
| 3307 | |
| 3308 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3309 | ::switches::kForceCaptionStyle)) { |
| 3310 | style = ui::CaptionStyle::FromSpec( |
| 3311 | base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 3312 | switches::kForceCaptionStyle)); |
| 3313 | } |
| 3314 | |
| 3315 | // Apply system caption style. |
| 3316 | if (!style) { |
| 3317 | style = native_theme->GetSystemCaptionStyle(); |
| 3318 | } |
| 3319 | |
| 3320 | // Apply caption style from preferences if system caption style is undefined. |
| 3321 | if (!style && base::FeatureList::IsEnabled(features::kCaptionSettings)) { |
evliu | bc2aa047 | 2019-08-09 20:19:19 | [diff] [blame] | 3322 | style = pref_names_util::GetCaptionStyleFromPrefs(prefs); |
evliu | edcbb87d | 2019-11-22 19:49:41 | [diff] [blame] | 3323 | |
| 3324 | base::UmaHistogramBoolean("Accessibility.CaptionSettingsLoadedFromPrefs", |
| 3325 | style.has_value()); |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | if (style) { |
| 3329 | web_prefs->text_track_background_color = style->background_color; |
| 3330 | web_prefs->text_track_text_color = style->text_color; |
| 3331 | web_prefs->text_track_text_size = style->text_size; |
| 3332 | web_prefs->text_track_text_shadow = style->text_shadow; |
| 3333 | web_prefs->text_track_font_family = style->font_family; |
| 3334 | web_prefs->text_track_font_variant = style->font_variant; |
Abigail Klein | 74de85bd | 2019-07-11 19:11:56 | [diff] [blame] | 3335 | web_prefs->text_track_window_color = style->window_color; |
| 3336 | web_prefs->text_track_window_padding = style->window_padding; |
| 3337 | web_prefs->text_track_window_radius = style->window_radius; |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3338 | } |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3339 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3340 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
creis | 7b2d3d1 | 2015-02-12 23:29:50 | [diff] [blame] | 3341 | extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 3342 | } |
| 3343 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3344 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 3345 | BrowserURLHandler* handler) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3346 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 3347 | extra_parts_[i]->BrowserURLHandlerCreated(handler); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3348 | |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 3349 | // about: handler. Must come before chrome: handler, since it will |
| 3350 | // rewrite about: urls to chrome: URLs and then expect chrome: to |
creis | 94a977f6 | 2015-02-18 23:51:05 | [diff] [blame] | 3351 | // actually handle them. Also relies on a preliminary fixup phase. |
| 3352 | handler->SetFixupHandler(&FixupBrowserAboutURL); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3353 | handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 3354 | BrowserURLHandler::null_handler()); |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3355 | |
mad | fbd1085 | 2017-01-20 03:15:33 | [diff] [blame] | 3356 | // The group policy NTP URL handler must be registered before the other NTP |
| 3357 | // URL handlers below. |
| 3358 | handler->AddHandlerPair(&HandleNewTabPageLocationOverride, |
| 3359 | BrowserURLHandler::null_handler()); |
| 3360 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 3361 | #if defined(OS_ANDROID) |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3362 | // Handler to rewrite chrome://newtab on Android. |
ianwen | 465e17b | 2015-01-20 18:32:35 | [diff] [blame] | 3363 | handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL, |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3364 | BrowserURLHandler::null_handler()); |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 3365 | #else // defined(OS_ANDROID) |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3366 | // Handler to rewrite chrome://newtab for InstantExtended. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 3367 | handler->AddHandlerPair(&search::HandleNewTabURLRewrite, |
| 3368 | &search::HandleNewTabURLReverseRewrite); |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 3369 | #endif // defined(OS_ANDROID) |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3370 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3371 | // chrome: & friends. |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 3372 | handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI, |
| 3373 | &ChromeContentBrowserClient::HandleWebUIReverse); |
Robert Ogden | e7fdca9 | 2018-10-12 17:53:06 | [diff] [blame] | 3374 | |
| 3375 | // Handler to rewrite Preview's Server Lite Page, to show the original URL to |
| 3376 | // the user. |
Robert Ogden | 0f4d8868 | 2019-09-24 22:27:52 | [diff] [blame] | 3377 | handler->AddHandlerPair( |
| 3378 | &previews::HandlePreviewsLitePageRedirectURLRewrite, |
| 3379 | &previews::HandlePreviewsLitePageRedirectURLRewriteReverse); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3380 | } |
| 3381 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3382 | base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 3383 | return DownloadPrefs::GetDefaultDownloadDirectory(); |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 3384 | } |
| 3385 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 3386 | std::string ChromeContentBrowserClient::GetDefaultDownloadName() { |
| 3387 | return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 3388 | } |
| 3389 | |
Dominik Röttsches | 4734783 | 2019-03-12 17:45:01 | [diff] [blame] | 3390 | base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() { |
| 3391 | base::FilePath user_data_dir; |
| 3392 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 3393 | DCHECK(!user_data_dir.empty()); |
| 3394 | return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache")); |
| 3395 | } |
| 3396 | |
jmadill | 57b52d4 | 2015-08-21 18:16:13 | [diff] [blame] | 3397 | base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() { |
| 3398 | base::FilePath user_data_dir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 3399 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
jmadill | 57b52d4 | 2015-08-21 18:16:13 | [diff] [blame] | 3400 | DCHECK(!user_data_dir.empty()); |
| 3401 | return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache")); |
| 3402 | } |
| 3403 | |
Khushal | 7ca0b78 | 2018-07-20 05:53:27 | [diff] [blame] | 3404 | base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() { |
| 3405 | base::FilePath user_data_dir; |
| 3406 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 3407 | DCHECK(!user_data_dir.empty()); |
| 3408 | return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache")); |
| 3409 | } |
| 3410 | |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 3411 | void ChromeContentBrowserClient::DidCreatePpapiPlugin( |
| 3412 | content::BrowserPpapiHost* browser_host) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3413 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 3414 | ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host); |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 3415 | #endif |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 3416 | } |
| 3417 | |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3418 | content::BrowserPpapiHost* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3419 | ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) { |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 3420 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 3421 | content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3422 | while (!iter.Done()) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3423 | nacl::NaClProcessHost* host = |
| 3424 | static_cast<nacl::NaClProcessHost*>(iter.GetDelegate()); |
| 3425 | if (host->process() && host->process()->GetData().id == plugin_process_id) { |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3426 | // Found the plugin. |
| 3427 | return host->browser_ppapi_host(); |
| 3428 | } |
| 3429 | ++iter; |
| 3430 | } |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 3431 | #endif |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3432 | return nullptr; |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3433 | } |
| 3434 | |
[email protected] | 38cd8f7f | 2012-06-15 22:06:07 | [diff] [blame] | 3435 | bool ChromeContentBrowserClient::AllowPepperSocketAPI( |
[email protected] | 157cc90 | 2012-11-02 06:31:58 | [diff] [blame] | 3436 | content::BrowserContext* browser_context, |
| 3437 | const GURL& url, |
[email protected] | dda5482 | 2013-06-15 01:26:39 | [diff] [blame] | 3438 | bool private_api, |
[email protected] | 8b92ed18 | 2013-09-21 04:47:12 | [diff] [blame] | 3439 | const content::SocketPermissionRequest* params) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3440 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 3441 | return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI( |
| 3442 | browser_context, url, private_api, params, allowed_socket_origins_); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 3443 | #else |
[email protected] | a658d45 | 2012-03-02 12:45:29 | [diff] [blame] | 3444 | return false; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 3445 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 3446 | } |
| 3447 | |
adrian.belgun | d54465ba | 2016-05-18 10:03:58 | [diff] [blame] | 3448 | bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed( |
| 3449 | content::BrowserContext* browser_context, |
| 3450 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3451 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
adrian.belgun | d54465ba | 2016-05-18 10:03:58 | [diff] [blame] | 3452 | return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed( |
| 3453 | browser_context, url); |
| 3454 | #else |
| 3455 | return false; |
| 3456 | #endif |
| 3457 | } |
| 3458 | |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 3459 | std::unique_ptr<content::VpnServiceProxy> |
| 3460 | ChromeContentBrowserClient::GetVpnServiceProxy( |
| 3461 | content::BrowserContext* browser_context) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3462 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 3463 | return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy( |
| 3464 | browser_context); |
| 3465 | #else |
| 3466 | return nullptr; |
| 3467 | #endif |
| 3468 | } |
| 3469 | |
Brett Wilson | 804e83c | 2017-08-18 22:57:33 | [diff] [blame] | 3470 | std::unique_ptr<ui::SelectFilePolicy> |
| 3471 | ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) { |
| 3472 | return std::make_unique<ChromeSelectFilePolicy>(web_contents); |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 3473 | } |
| 3474 | |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 3475 | void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 3476 | std::vector<std::string>* additional_allowed_schemes) { |
| 3477 | ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 3478 | additional_allowed_schemes); |
[email protected] | b3690f7 | 2014-02-17 00:32:48 | [diff] [blame] | 3479 | additional_allowed_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 3480 | additional_allowed_schemes->push_back(content::kChromeUIScheme); |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3481 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
| 3482 | extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem( |
| 3483 | additional_allowed_schemes); |
| 3484 | } |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 3485 | } |
| 3486 | |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 3487 | void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist( |
| 3488 | std::set<std::string>* schemes) { |
Daniel Vogelheim | 11e59b7 | 2017-11-22 15:44:04 | [diff] [blame] | 3489 | *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck(); |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 3490 | } |
| 3491 | |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 3492 | void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3493 | std::vector<storage::URLRequestAutoMountHandler>* handlers) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3494 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 3495 | extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers); |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 3496 | } |
| 3497 | |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 3498 | ::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() { |
| 3499 | return g_browser_process->rappor_service(); |
| 3500 | } |
| 3501 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 3502 | void ChromeContentBrowserClient::GetAdditionalFileSystemBackends( |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 3503 | content::BrowserContext* browser_context, |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 3504 | const base::FilePath& storage_partition_path, |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3505 | std::vector<std::unique_ptr<storage::FileSystemBackend>>* |
| 3506 | additional_backends) { |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3507 | #if defined(OS_CHROMEOS) |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3508 | storage::ExternalMountPoints* external_mount_points = |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 3509 | content::BrowserContext::GetMountPoints(browser_context); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3510 | DCHECK(external_mount_points); |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3511 | auto backend = std::make_unique<chromeos::FileSystemBackend>( |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3512 | std::make_unique<chromeos::file_system_provider::BackendDelegate>(), |
| 3513 | std::make_unique<chromeos::MTPFileSystemBackendDelegate>( |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 3514 | storage_partition_path), |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3515 | std::make_unique<arc::ArcContentFileSystemBackendDelegate>(), |
| 3516 | std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(), |
Sam McNally | 47f2eac | 2018-08-28 06:45:05 | [diff] [blame] | 3517 | std::make_unique<drive::DriveFsFileSystemBackendDelegate>( |
| 3518 | Profile::FromBrowserContext(browser_context)), |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 3519 | external_mount_points, storage::ExternalMountPoints::GetSystemInstance()); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 3520 | backend->AddSystemMountPoints(); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3521 | DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal)); |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3522 | additional_backends->push_back(std::move(backend)); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3523 | #endif |
[email protected] | 445b7db | 2013-08-02 04:58:27 | [diff] [blame] | 3524 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3525 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
| 3526 | extra_parts_[i]->GetAdditionalFileSystemBackends( |
| 3527 | browser_context, storage_partition_path, additional_backends); |
| 3528 | } |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 3529 | } |
| 3530 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3531 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 3532 | void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 3533 | const base::CommandLine& command_line, |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3534 | int child_process_id, |
brettw | 3c98c7d3 | 2017-07-25 01:44:20 | [diff] [blame] | 3535 | PosixFileDescriptorInfo* mappings) { |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3536 | #if defined(OS_ANDROID) |
| 3537 | base::MemoryMappedFile::Region region; |
| 3538 | int fd = ui::GetMainAndroidPackFd(®ion); |
| 3539 | mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region); |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 3540 | |
Samuel Huang | 31eadf08 | 2019-08-28 19:50:43 | [diff] [blame] | 3541 | // For Android: Native resources for DFMs should only be used by the browser |
| 3542 | // process. Their file descriptors and memory mapped file regions are not |
| 3543 | // passed to child processes. |
| 3544 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3545 | fd = ui::GetCommonResourcesPackFd(®ion); |
| 3546 | mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region); |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 3547 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3548 | fd = ui::GetLocalePackFd(®ion); |
| 3549 | mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region); |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3550 | |
zpeng | 368afac8 | 2017-07-17 18:47:45 | [diff] [blame] | 3551 | // Optional secondary locale .pak file. |
| 3552 | fd = ui::GetSecondaryLocalePackFd(®ion); |
| 3553 | if (fd != -1) { |
| 3554 | mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region); |
| 3555 | } |
| 3556 | |
[email protected] | 09560f7f | 2014-06-10 18:40:28 | [diff] [blame] | 3557 | base::FilePath app_data_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 3558 | base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path); |
[email protected] | 09560f7f | 2014-06-10 18:40:28 | [diff] [blame] | 3559 | DCHECK(!app_data_path.empty()); |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 3560 | #endif // defined(OS_ANDROID) |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3561 | int crash_signal_fd = GetCrashSignalFD(command_line); |
| 3562 | if (crash_signal_fd >= 0) { |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 3563 | mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd); |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3564 | } |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3565 | } |
| 3566 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 3567 | |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 3568 | #if defined(OS_WIN) |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3569 | base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType( |
Alex Gough | 9ab468a6c3 | 2019-12-10 19:10:22 | [diff] [blame] | 3570 | service_manager::SandboxType sandbox_type) { |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3571 | // TODO(wfh): Add support for more process types here. crbug.com/499523 |
| 3572 | switch (sandbox_type) { |
Alex Gough | 9ab468a6c3 | 2019-12-10 19:10:22 | [diff] [blame] | 3573 | case service_manager::SandboxType::kRenderer: |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 3574 | return base::string16(install_static::GetSandboxSidPrefix()) + |
| 3575 | L"129201922"; |
Alex Gough | 9ab468a6c3 | 2019-12-10 19:10:22 | [diff] [blame] | 3576 | case service_manager::SandboxType::kUtility: |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3577 | return base::string16(); |
Alex Gough | 9ab468a6c3 | 2019-12-10 19:10:22 | [diff] [blame] | 3578 | case service_manager::SandboxType::kGpu: |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3579 | return base::string16(); |
Alex Gough | 9ab468a6c3 | 2019-12-10 19:10:22 | [diff] [blame] | 3580 | case service_manager::SandboxType::kPpapi: |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 3581 | return base::string16(install_static::GetSandboxSidPrefix()) + |
| 3582 | L"129201925"; |
Alex Gough | 9ab468a6c3 | 2019-12-10 19:10:22 | [diff] [blame] | 3583 | case service_manager::SandboxType::kInvalid: |
| 3584 | case service_manager::SandboxType::kNoSandbox: |
| 3585 | case service_manager::SandboxType::kNoSandboxAndElevatedPrivileges: |
| 3586 | case service_manager::SandboxType::kXrCompositing: |
| 3587 | case service_manager::SandboxType::kNetwork: |
| 3588 | case service_manager::SandboxType::kCdm: |
| 3589 | case service_manager::SandboxType::kPdfCompositor: |
| 3590 | case service_manager::SandboxType::kProfiling: |
| 3591 | case service_manager::SandboxType::kAudio: |
| 3592 | // Should never reach here. |
| 3593 | CHECK(0); |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3594 | return base::string16(); |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3595 | } |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3596 | } |
| 3597 | |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3598 | bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy, |
| 3599 | RendererSpawnFlags flags) { |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 3600 | // Does not work under component build because all the component DLLs would need |
| 3601 | // to be manually added and maintained. Does not work under ASAN build because |
| 3602 | // ASAN has not yet fully initialized its instrumentation by the time the CIG |
| 3603 | // intercepts run. |
| 3604 | #if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3605 | if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0) |
| 3606 | return true; |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3607 | if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity)) |
| 3608 | return true; |
| 3609 | |
| 3610 | // Only enable signing mitigation if launching from chrome.exe. |
| 3611 | base::FilePath exe_path; |
| 3612 | if (!base::PathService::Get(base::FILE_EXE, &exe_path)) |
| 3613 | return true; |
| 3614 | if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value()) |
| 3615 | return true; |
| 3616 | |
| 3617 | sandbox::MitigationFlags mitigations = policy->GetProcessMitigations(); |
| 3618 | mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS; |
Alex Gough | 59f406b | 2019-12-03 18:04:09 | [diff] [blame] | 3619 | sandbox::ResultCode result = policy->SetProcessMitigations(mitigations); |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3620 | if (result != sandbox::SBOX_ALL_OK) |
| 3621 | return false; |
| 3622 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3623 | // Allow loading Chrome's DLLs. The name of this depends on whether |
| 3624 | // is_multi_dll_chrome is defined or not. For multi-DLL Chrome, |
| 3625 | // chrome_child.dll is loaded, but for single-DLL Chrome, it would be the |
| 3626 | // same DLL as the browser process. |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3627 | #if defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 3628 | constexpr auto* child_dll_path = chrome::kChildDll; |
| 3629 | #else |
| 3630 | constexpr auto* child_dll_path = chrome::kBrowserResourcesDll; |
| 3631 | #endif |
| 3632 | for (const auto* dll : {child_dll_path, chrome::kElfDll}) { |
| 3633 | result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY, |
| 3634 | sandbox::TargetPolicy::SIGNED_ALLOW_LOAD, |
| 3635 | GetModulePath(dll).value().c_str()); |
| 3636 | if (result != sandbox::SBOX_ALL_OK) |
| 3637 | return false; |
| 3638 | } |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 3639 | #endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3640 | |
| 3641 | return true; |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 3642 | } |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3643 | |
| 3644 | bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() { |
| 3645 | PrefService* local_state = g_browser_process->local_state(); |
| 3646 | if (local_state && |
| 3647 | local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) && |
| 3648 | !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled)) |
| 3649 | return false; |
| 3650 | return true; |
| 3651 | } |
| 3652 | |
wfh | c91e967 | 2016-01-27 00:14:20 | [diff] [blame] | 3653 | #endif // defined(OS_WIN) |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 3654 | |
Mario Sanchez Prada | 39dee4a | 2019-07-09 07:15:40 | [diff] [blame] | 3655 | void ChromeContentBrowserClient::BindCredentialManagerReceiver( |
Oksana Zhuravlova | 23ecbb40 | 2019-03-29 19:44:11 | [diff] [blame] | 3656 | content::RenderFrameHost* render_frame_host, |
Mario Sanchez Prada | 39dee4a | 2019-07-09 07:15:40 | [diff] [blame] | 3657 | mojo::PendingReceiver<blink::mojom::CredentialManager> receiver) { |
| 3658 | ChromePasswordManagerClient::BindCredentialManager(std::move(receiver), |
Oksana Zhuravlova | 23ecbb40 | 2019-03-29 19:44:11 | [diff] [blame] | 3659 | render_frame_host); |
| 3660 | } |
| 3661 | |
Armando Miraglia | 3a7be23 | 2019-11-08 00:33:32 | [diff] [blame] | 3662 | #if defined(OS_WIN) || defined(OS_MACOSX) || \ |
| 3663 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
| 3664 | bool ShouldEnableAudioSandbox(const policy::PolicyMap& policies) { |
| 3665 | const base::Value* audio_sandbox_enabled_policy_value = |
| 3666 | policies.GetValue(policy::key::kAudioSandboxEnabled); |
| 3667 | if (audio_sandbox_enabled_policy_value) { |
| 3668 | bool force_enable_audio_sandbox; |
| 3669 | audio_sandbox_enabled_policy_value->GetAsBoolean( |
| 3670 | &force_enable_audio_sandbox); |
| 3671 | return force_enable_audio_sandbox; |
| 3672 | } |
| 3673 | |
| 3674 | return base::FeatureList::IsEnabled( |
| 3675 | service_manager::features::kAudioServiceSandbox); |
| 3676 | } |
| 3677 | #endif |
| 3678 | |
Ken Rockot | fa5d5711 | 2019-05-29 20:57:14 | [diff] [blame] | 3679 | void ChromeContentBrowserClient::WillStartServiceManager() { |
Guido Urdaneta | d06ae84 | 2019-10-10 20:04:12 | [diff] [blame] | 3680 | #if defined(OS_WIN) || defined(OS_MACOSX) || \ |
| 3681 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 3682 | if (startup_data_) { |
| 3683 | auto* chrome_feature_list_creator = |
| 3684 | startup_data_->chrome_feature_list_creator(); |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3685 | // This has to run very early before ServiceManagerContext is created. |
Guido Urdaneta | d06ae84 | 2019-10-10 20:04:12 | [diff] [blame] | 3686 | const policy::PolicyMap& policies = |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 3687 | chrome_feature_list_creator->browser_policy_connector() |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3688 | ->GetPolicyService() |
| 3689 | ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
Guido Urdaneta | d06ae84 | 2019-10-10 20:04:12 | [diff] [blame] | 3690 | std::string())); |
| 3691 | |
| 3692 | #if defined(OS_WIN) |
| 3693 | const base::Value* force_network_in_process_value = |
| 3694 | policies.GetValue(policy::key::kForceNetworkInProcess); |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3695 | bool force_network_in_process = false; |
| 3696 | if (force_network_in_process_value) |
| 3697 | force_network_in_process_value->GetAsBoolean(&force_network_in_process); |
| 3698 | if (force_network_in_process) |
| 3699 | content::ForceInProcessNetworkService(true); |
Guido Urdaneta | d06ae84 | 2019-10-10 20:04:12 | [diff] [blame] | 3700 | #endif |
| 3701 | bool enable_audio_process = |
| 3702 | base::FeatureList::IsEnabled(features::kAudioServiceOutOfProcess); |
Armando Miraglia | 3a7be23 | 2019-11-08 00:33:32 | [diff] [blame] | 3703 | |
| 3704 | service_manager::EnableAudioSandbox(ShouldEnableAudioSandbox(policies)); |
| 3705 | if (!service_manager::IsAudioSandboxEnabled() || !enable_audio_process) { |
Guido Urdaneta | d06ae84 | 2019-10-10 20:04:12 | [diff] [blame] | 3706 | // Disabling the audio process or audio sandbox implies disabling APM in |
| 3707 | // the audio service for security reasons. Append a switch so that this |
| 3708 | // is communicated to the audio and renderer processes. |
| 3709 | base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 3710 | switches::kForceDisableWebRtcApmInAudioService); |
| 3711 | } |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3712 | } |
| 3713 | #endif |
xhwang | 5e63046 | 2015-10-30 03:18:48 | [diff] [blame] | 3714 | } |
| 3715 | |
Ken Rockot | 8f39a27 | 2018-12-21 23:38:35 | [diff] [blame] | 3716 | base::Optional<service_manager::Manifest> |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 3717 | ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) { |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3718 | if (name == content::mojom::kBrowserServiceName) |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 3719 | return GetChromeContentBrowserOverlayManifest(); |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 3720 | return base::nullopt; |
ben | c70c0e3 | 2016-09-22 03:50:37 | [diff] [blame] | 3721 | } |
| 3722 | |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 3723 | void ChromeContentBrowserClient::OpenURL( |
Matt Falkenhagen | 18c5c5d | 2018-11-26 02:55:37 | [diff] [blame] | 3724 | content::SiteInstance* site_instance, |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 3725 | const content::OpenURLParams& params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 3726 | base::OnceCallback<void(content::WebContents*)> callback) { |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3727 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Matt Falkenhagen | 18c5c5d | 2018-11-26 02:55:37 | [diff] [blame] | 3728 | |
| 3729 | content::BrowserContext* browser_context = site_instance->GetBrowserContext(); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3730 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 3731 | #if defined(OS_ANDROID) |
pkotwicz | aa289f0 | 2016-07-05 22:26:22 | [diff] [blame] | 3732 | ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 3733 | std::move(callback)); |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 3734 | #else |
cm.sanchi | 2522bc9 | 2017-12-04 08:04:13 | [diff] [blame] | 3735 | NavigateParams nav_params(Profile::FromBrowserContext(browser_context), |
| 3736 | params.url, params.transition); |
| 3737 | nav_params.FillNavigateParamsFromOpenURLParams(params); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3738 | |
| 3739 | Navigate(&nav_params); |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 3740 | std::move(callback).Run(nav_params.navigated_or_inserted_contents); |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 3741 | #endif |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3742 | } |
| 3743 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 3744 | content::ControllerPresentationServiceDelegate* |
| 3745 | ChromeContentBrowserClient::GetControllerPresentationServiceDelegate( |
| 3746 | content::WebContents* web_contents) { |
mfoltz | 99bd44c | 2016-03-18 20:36:46 | [diff] [blame] | 3747 | if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) { |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 3748 | return media_router::PresentationServiceDelegateImpl:: |
| 3749 | GetOrCreateForWebContents(web_contents); |
| 3750 | } |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 3751 | return nullptr; |
| 3752 | } |
| 3753 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 3754 | content::ReceiverPresentationServiceDelegate* |
| 3755 | ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate( |
| 3756 | content::WebContents* web_contents) { |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 3757 | if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) { |
| 3758 | // ReceiverPresentationServiceDelegateImpl exists only for WebContents |
| 3759 | // created for offscreen presentations. The WebContents must belong to |
| 3760 | // an incognito profile. |
| 3761 | if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl:: |
| 3762 | FromWebContents(web_contents)) { |
| 3763 | DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord()); |
| 3764 | return impl; |
| 3765 | } |
| 3766 | } |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 3767 | return nullptr; |
| 3768 | } |
| 3769 | |
horo | 48d4d3e | 2015-02-27 03:04:00 | [diff] [blame] | 3770 | void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric, |
| 3771 | const GURL& url) { |
mathp | 46284f3 | 2015-03-11 13:06:41 | [diff] [blame] | 3772 | if (url.is_valid()) { |
| 3773 | rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
| 3774 | metric, url); |
| 3775 | } |
horo | 48d4d3e | 2015-02-27 03:04:00 | [diff] [blame] | 3776 | } |
| 3777 | |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 3778 | std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) { |
| 3779 | // Don't change these returned strings. They are written (in hashed form) into |
| 3780 | // UMA logs. If you add more strings, you must update histograms.xml and get |
| 3781 | // histograms review. Only Google domains should be here for privacy purposes. |
| 3782 | // TODO(falken): Ideally Chrome would log the relevant UMA directly and this |
| 3783 | // function could be removed. |
Matt Falkenhagen | 2c98ee29a | 2017-07-20 16:43:19 | [diff] [blame] | 3784 | if (page_load_metrics::IsGoogleSearchResultUrl(url)) |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 3785 | return "search"; |
Matt Falkenhagen | 2c98ee29a | 2017-07-20 16:43:19 | [diff] [blame] | 3786 | if (url.host() == "docs.google.com") |
| 3787 | return "docs"; |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 3788 | return std::string(); |
| 3789 | } |
| 3790 | |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3791 | std::vector<std::unique_ptr<content::NavigationThrottle>> |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3792 | ChromeContentBrowserClient::CreateThrottlesForNavigation( |
| 3793 | content::NavigationHandle* handle) { |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3794 | std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 3795 | |
bmcquade | b455655 | 2017-03-24 22:24:37 | [diff] [blame] | 3796 | // MetricsNavigationThrottle requires that it runs before NavigationThrottles |
| 3797 | // that may delay or cancel navigations, so only NavigationThrottles that |
| 3798 | // don't delay or cancel navigations (e.g. throttles that are only observing |
| 3799 | // callbacks without affecting navigation behavior) should be added before |
| 3800 | // MetricsNavigationThrottle. |
| 3801 | if (handle->IsInMainFrame()) { |
| 3802 | throttles.push_back( |
| 3803 | page_load_metrics::MetricsNavigationThrottle::Create(handle)); |
| 3804 | } |
| 3805 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3806 | #if BUILDFLAG(ENABLE_PLUGINS) |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3807 | MaybeAddThrottle(&throttles, |
| 3808 | FlashDownloadInterception::MaybeCreateThrottleFor(handle)); |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 3809 | #endif |
| 3810 | |
yilkal | 240b4f2 | 2019-11-27 19:09:06 | [diff] [blame] | 3811 | #if defined(OS_CHROMEOS) |
| 3812 | MaybeAddThrottle( |
| 3813 | &throttles, |
| 3814 | chromeos::WebTimeLimitNavigationThrottle::MaybeCreateThrottleFor(handle)); |
| 3815 | #endif // defined(OS_CHROMEOS) |
| 3816 | |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 3817 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3818 | MaybeAddThrottle( |
| 3819 | &throttles, |
| 3820 | SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle)); |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 3821 | #endif |
| 3822 | |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3823 | #if defined(OS_ANDROID) |
| 3824 | // TODO(davidben): This is insufficient to integrate with prerender properly. |
| 3825 | // https://crbug.com/370595 |
| 3826 | prerender::PrerenderContents* prerender_contents = |
| 3827 | prerender::PrerenderContents::FromWebContents(handle->GetWebContents()); |
| 3828 | if (!prerender_contents && handle->IsInMainFrame()) { |
| 3829 | throttles.push_back( |
| 3830 | navigation_interception::InterceptNavigationDelegate::CreateThrottleFor( |
Charlie Harrison | 3286ab7 | 2019-02-13 20:13:30 | [diff] [blame] | 3831 | handle, navigation_interception::SynchronyMode::kAsync)); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3832 | } |
Min Qin | 0ab0e16 | 2017-11-14 21:57:19 | [diff] [blame] | 3833 | throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle)); |
Samuel Huang | 3a1ce1c3 | 2019-10-16 17:34:04 | [diff] [blame] | 3834 | |
| 3835 | #if BUILDFLAG(DFMIFY_DEV_UI) |
| 3836 | // If the DevUI DFM is already installed, then this is a no-op, except for the |
| 3837 | // side effect of ensuring that the DevUI DFM is loaded. |
| 3838 | MaybeAddThrottle(&throttles, |
| 3839 | dev_ui::DevUiLoaderThrottle::MaybeCreateThrottleFor(handle)); |
| 3840 | #endif // BUILDFLAG(DFMIFY_DEV_UI) |
| 3841 | |
Giovanni Ortuño Urquidi | 7ae7fb0 | 2017-10-09 01:49:57 | [diff] [blame] | 3842 | #elif BUILDFLAG(ENABLE_EXTENSIONS) |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3843 | if (handle->IsInMainFrame()) { |
| 3844 | // Redirect some navigations to apps that have registered matching URL |
| 3845 | // handlers ('url_handlers' in the manifest). |
Giovanni Ortuño Urquidi | 7ae7fb0 | 2017-10-09 01:49:57 | [diff] [blame] | 3846 | auto url_to_app_throttle = |
| 3847 | PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3848 | if (url_to_app_throttle) |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 3849 | throttles.push_back(std::move(url_to_app_throttle)); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3850 | } |
| 3851 | #endif |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 3852 | |
| 3853 | #if defined(OS_CHROMEOS) |
| 3854 | // Check if we need to add merge session throttle. This throttle will postpone |
| 3855 | // loading of main frames. |
| 3856 | if (handle->IsInMainFrame()) { |
| 3857 | // Add interstitial page while merge session process (cookie reconstruction |
| 3858 | // from OAuth2 refresh token in ChromeOS login) is still in progress while |
| 3859 | // we are attempting to load a google property. |
csharrison | dd06bab | 2016-07-22 14:15:02 | [diff] [blame] | 3860 | if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() && |
| 3861 | !merge_session_throttling_utils::AreAllSessionMergedAlready() && |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 3862 | handle->GetURL().SchemeIsHTTPOrHTTPS()) { |
| 3863 | throttles.push_back(MergeSessionNavigationThrottle::Create(handle)); |
| 3864 | } |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 3865 | } |
| 3866 | #endif |
djacobo | 21e56e0 | 2016-07-02 01:14:31 | [diff] [blame] | 3867 | |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 3868 | #if !defined(OS_ANDROID) |
| 3869 | if (base::FeatureList::IsEnabled(features::kIntentPicker)) { |
Dominick Ng | 7c28994 | 2018-03-27 05:57:15 | [diff] [blame] | 3870 | auto url_to_apps_throttle = |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 3871 | #if defined(OS_CHROMEOS) |
Maggie Cai | 00e2a21e | 2019-10-16 00:47:51 | [diff] [blame] | 3872 | base::FeatureList::IsEnabled(features::kAppServiceIntentHandling) |
| 3873 | ? apps::CommonAppsNavigationThrottle::MaybeCreate(handle) |
| 3874 | : chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle); |
Avi Drissman | a2969a55 | 2019-10-30 15:32:25 | [diff] [blame] | 3875 | #elif defined(OS_MACOSX) |
| 3876 | apps::MacAppsNavigationThrottle::MaybeCreate(handle); |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 3877 | #else |
| 3878 | apps::AppsNavigationThrottle::MaybeCreate(handle); |
| 3879 | #endif |
Dominick Ng | 7c28994 | 2018-03-27 05:57:15 | [diff] [blame] | 3880 | if (url_to_apps_throttle) |
| 3881 | throttles.push_back(std::move(url_to_apps_throttle)); |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 3882 | } |
| 3883 | #endif |
| 3884 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3885 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3886 | throttles.push_back( |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3887 | std::make_unique<extensions::ExtensionNavigationThrottle>(handle)); |
Clark DuVall | 2cf99249e | 2018-09-19 19:11:51 | [diff] [blame] | 3888 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3889 | MaybeAddThrottle(&throttles, extensions::ExtensionsBrowserClient::Get() |
| 3890 | ->GetUserScriptListener() |
| 3891 | ->CreateNavigationThrottle(handle)); |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 3892 | #endif |
| 3893 | |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 3894 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3895 | MaybeAddThrottle( |
| 3896 | &throttles, |
| 3897 | SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle)); |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 3898 | #endif |
| 3899 | |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 3900 | content::WebContents* web_contents = handle->GetWebContents(); |
csharrison | 77bf834 | 2017-05-04 18:23:10 | [diff] [blame] | 3901 | if (auto* subresource_filter_client = |
| 3902 | ChromeSubresourceFilterClient::FromWebContents(web_contents)) { |
| 3903 | subresource_filter_client->MaybeAppendNavigationThrottles(handle, |
| 3904 | &throttles); |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 3905 | } |
| 3906 | |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 3907 | #if !defined(OS_ANDROID) |
| 3908 | // BackgroundTabNavigationThrottle is used by TabManager, which is only |
| 3909 | // enabled on non-Android platforms. |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3910 | MaybeAddThrottle(&throttles, |
| 3911 | resource_coordinator::BackgroundTabNavigationThrottle:: |
| 3912 | MaybeCreateThrottleFor(handle)); |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 3913 | #endif |
| 3914 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 3915 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3916 | MaybeAddThrottle(&throttles, |
| 3917 | safe_browsing::MaybeCreateNavigationThrottle(handle)); |
Jialiu Lin | bdbb81d | 2017-10-11 21:29:09 | [diff] [blame] | 3918 | #endif |
| 3919 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3920 | MaybeAddThrottle( |
| 3921 | &throttles, |
Emily Stark | fa0ddb4 | 2019-10-24 15:49:58 | [diff] [blame] | 3922 | LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle)); |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 3923 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3924 | MaybeAddThrottle(&throttles, |
| 3925 | PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle)); |
Amber Won | 6b5edc75 | 2017-08-17 19:23:54 | [diff] [blame] | 3926 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3927 | MaybeAddThrottle(&throttles, TabUnderNavigationThrottle::MaybeCreate(handle)); |
Charles Harrison | 6dd11d28 | 2017-10-03 06:14:51 | [diff] [blame] | 3928 | |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3929 | throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>( |
Doug Turner | 9dcaf596 | 2017-12-21 04:38:53 | [diff] [blame] | 3930 | handle, handle->GetWebContents()->GetBrowserContext())); |
| 3931 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 3932 | throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>( |
| 3933 | handle, |
| 3934 | std::make_unique<CertificateReportingServiceCertReporter>(web_contents), |
danakj | 20514c9 | 2019-12-13 17:30:19 | [diff] [blame] | 3935 | base::BindOnce(&SSLErrorHandler::HandleSSLError), |
| 3936 | base::BindOnce(&IsInHostedApp))); |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 3937 | |
Emily Stark | d6896cd3 | 2019-08-21 04:55:54 | [diff] [blame] | 3938 | throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle)); |
| 3939 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3940 | MaybeAddThrottle( |
| 3941 | &throttles, |
| 3942 | TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle)); |
Christopher Thompson | 4137cec | 2017-12-19 05:34:23 | [diff] [blame] | 3943 | |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 3944 | #if !defined(OS_ANDROID) |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3945 | MaybeAddThrottle(&throttles, |
| 3946 | DevToolsWindow::MaybeCreateNavigationThrottle(handle)); |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 3947 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3948 | MaybeAddThrottle( |
| 3949 | &throttles, NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle)); |
jdoerrie | 4f9376f | 2018-12-12 18:26:20 | [diff] [blame] | 3950 | |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3951 | MaybeAddThrottle( |
| 3952 | &throttles, |
| 3953 | GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor(handle)); |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 3954 | #endif |
| 3955 | |
Carlos IL | 4ee307e | 2018-12-22 03:19:00 | [diff] [blame] | 3956 | if (base::FeatureList::IsEnabled(safe_browsing::kCommittedSBInterstitials)) { |
| 3957 | throttles.push_back( |
| 3958 | std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>( |
| 3959 | handle)); |
| 3960 | } |
Robert Ogden | afd250b | 2018-07-25 22:21:03 | [diff] [blame] | 3961 | |
Nicolas Ouellet-Payeur | bdcab009 | 2018-10-22 14:50:33 | [diff] [blame] | 3962 | #if defined(OS_WIN) || defined(OS_MACOSX) || \ |
| 3963 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
Lukasz Anforowicz | 7724d09 | 2019-10-03 23:50:21 | [diff] [blame] | 3964 | MaybeAddThrottle(&throttles, |
| 3965 | browser_switcher::BrowserSwitcherNavigationThrottle:: |
| 3966 | MaybeCreateThrottleFor(handle)); |
Nicolas Ouellet-Payeur | 995e777 | 2018-09-13 16:02:13 | [diff] [blame] | 3967 | #endif |
| 3968 | |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 3969 | return throttles; |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 3970 | } |
| 3971 | |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 3972 | std::unique_ptr<content::NavigationUIData> |
| 3973 | ChromeContentBrowserClient::GetNavigationUIData( |
| 3974 | content::NavigationHandle* navigation_handle) { |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3975 | return std::make_unique<ChromeNavigationUIData>(navigation_handle); |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 3976 | } |
| 3977 | |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 3978 | void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps( |
| 3979 | const std::string& key_system, |
| 3980 | const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols, |
| 3981 | base::flat_set<media::VideoCodec>* video_codecs, |
Yuchen Liu | b33bfc1 | 2019-11-08 20:16:12 | [diff] [blame] | 3982 | base::flat_set<media::EncryptionScheme>* encryption_schemes) { |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 3983 | #if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \ |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 3984 | BUILDFLAG(ENABLE_WIDEVINE) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 3985 | if (key_system == kWidevineKeySystem) { |
| 3986 | GetWidevineHardwareCaps(cdm_proxy_protocols, video_codecs, |
| 3987 | encryption_schemes); |
| 3988 | } |
| 3989 | #endif |
| 3990 | } |
| 3991 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 3992 | content::DevToolsManagerDelegate* |
| 3993 | ChromeContentBrowserClient::GetDevToolsManagerDelegate() { |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 3994 | #if defined(OS_ANDROID) |
| 3995 | return new DevToolsManagerDelegateAndroid(); |
| 3996 | #else |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 3997 | return new ChromeDevToolsManagerDelegate(); |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 3998 | #endif |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 3999 | } |
| 4000 | |
Rayan Kanso | 411e84e | 2019-02-13 15:27:40 | [diff] [blame] | 4001 | void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration( |
| 4002 | content::BrowserContext* browser_context, |
| 4003 | int service, |
| 4004 | base::Time expiration_time) { |
| 4005 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4006 | DCHECK(profile); |
| 4007 | |
| 4008 | auto* pref_service = profile->GetPrefs(); |
| 4009 | DCHECK(pref_service); |
| 4010 | |
| 4011 | DictionaryPrefUpdate pref_update( |
| 4012 | pref_service, prefs::kDevToolsBackgroundServicesExpirationDict); |
| 4013 | base::DictionaryValue* exp_dict = pref_update.Get(); |
| 4014 | |
| 4015 | // Convert |expiration_time| to minutes since that is the most granular |
| 4016 | // option that returns an int. base::Value does not accept int64. |
| 4017 | int expiration_time_minutes = |
| 4018 | expiration_time.ToDeltaSinceWindowsEpoch().InMinutes(); |
| 4019 | exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes); |
| 4020 | } |
| 4021 | |
| 4022 | base::flat_map<int, base::Time> |
| 4023 | ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations( |
| 4024 | content::BrowserContext* browser_context) { |
| 4025 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4026 | DCHECK(profile); |
| 4027 | |
| 4028 | auto* pref_service = profile->GetPrefs(); |
| 4029 | DCHECK(pref_service); |
| 4030 | |
| 4031 | auto* expiration_dict = pref_service->GetDictionary( |
| 4032 | prefs::kDevToolsBackgroundServicesExpirationDict); |
| 4033 | DCHECK(expiration_dict); |
| 4034 | |
| 4035 | base::flat_map<int, base::Time> expiration_times; |
| 4036 | for (const auto& it : *expiration_dict) { |
| 4037 | // key. |
| 4038 | int service = 0; |
| 4039 | bool did_convert = base::StringToInt(it.first, &service); |
| 4040 | DCHECK(did_convert); |
| 4041 | |
| 4042 | // value. |
| 4043 | DCHECK(it.second->is_int()); |
| 4044 | base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt()); |
| 4045 | base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta); |
| 4046 | |
| 4047 | expiration_times[service] = expiration_time; |
| 4048 | } |
| 4049 | |
| 4050 | return expiration_times; |
| 4051 | } |
| 4052 | |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4053 | content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() { |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4054 | return new ChromeTracingDelegate(); |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4055 | } |
| 4056 | |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 4057 | bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle( |
| 4058 | content::BrowserContext* browser_context, |
| 4059 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4060 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 4061 | return ChromeContentBrowserClientPluginsPart:: |
| 4062 | IsPluginAllowedToCallRequestOSFileHandle(browser_context, url, |
| 4063 | allowed_file_handle_origins_); |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 4064 | #else |
| 4065 | return false; |
| 4066 | #endif |
| 4067 | } |
| 4068 | |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 4069 | bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs( |
| 4070 | content::BrowserContext* browser_context, |
| 4071 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4072 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 4073 | return ChromeContentBrowserClientPluginsPart:: |
| 4074 | IsPluginAllowedToUseDevChannelAPIs(browser_context, url, |
| 4075 | allowed_dev_channel_origins_); |
[email protected] | 8ddc6b7c | 2013-12-12 20:42:06 | [diff] [blame] | 4076 | #else |
| 4077 | return false; |
| 4078 | #endif |
| 4079 | } |
| 4080 | |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4081 | void ChromeContentBrowserClient::OverridePageVisibilityState( |
xzhan96 | cf0a3c54 | 2017-11-17 04:33:01 | [diff] [blame] | 4082 | RenderFrameHost* render_frame_host, |
danakj | 0018a29a | 2018-12-01 01:03:43 | [diff] [blame] | 4083 | content::PageVisibilityState* visibility_state) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 4084 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4085 | |
| 4086 | WebContents* web_contents = |
| 4087 | WebContents::FromRenderFrameHost(render_frame_host); |
| 4088 | DCHECK(web_contents); |
| 4089 | |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4090 | prerender::PrerenderManager* prerender_manager = |
droger | c154315 | 2016-09-20 13:03:37 | [diff] [blame] | 4091 | prerender::PrerenderManagerFactory::GetForBrowserContext( |
| 4092 | web_contents->GetBrowserContext()); |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4093 | if (prerender_manager && |
| 4094 | prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) { |
Collin Baker | 98457b5 | 2019-11-06 21:34:29 | [diff] [blame] | 4095 | *visibility_state = content::PageVisibilityState::kHiddenButPainting; |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4096 | } |
| 4097 | } |
| 4098 | |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 4099 | void ChromeContentBrowserClient::InitWebContextInterfaces() { |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4100 | frame_interfaces_ = std::make_unique<service_manager::BinderRegistry>(); |
| 4101 | frame_interfaces_parameterized_ = std::make_unique< |
Ben Goodger | 21ada1e | 2017-07-19 14:53:01 | [diff] [blame] | 4102 | service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>(); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4103 | } |
| 4104 | |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 4105 | void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() { |
| 4106 | base::FilePath user_data_dir; |
| 4107 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 4108 | DCHECK(!user_data_dir.empty()); |
| 4109 | network_contexts_parent_directory_.push_back(user_data_dir); |
| 4110 | |
| 4111 | base::FilePath cache_dir; |
| 4112 | chrome::GetUserCacheDirectory(user_data_dir, &cache_dir); |
| 4113 | DCHECK(!cache_dir.empty()); |
| 4114 | // On some platforms, the cache is a child of the user_data_dir so only |
| 4115 | // return the one path. |
| 4116 | if (!user_data_dir.IsParent(cache_dir)) |
| 4117 | network_contexts_parent_directory_.push_back(cache_dir); |
| 4118 | |
| 4119 | // If the cache location has been overridden by a switch or preference, |
| 4120 | // include that as well. |
| 4121 | if (auto* local_state = g_browser_process->local_state()) { |
| 4122 | base::FilePath pref_cache_dir = |
| 4123 | local_state->GetFilePath(prefs::kDiskCacheDir); |
| 4124 | if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir)) |
| 4125 | network_contexts_parent_directory_.push_back(pref_cache_dir); |
| 4126 | } |
| 4127 | } |
| 4128 | |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4129 | void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 4130 | base::CommandLine* to_command_line, |
| 4131 | const base::CommandLine& from_command_line, |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4132 | version_info::Channel channel) { |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4133 | #if defined(OS_ANDROID) |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4134 | const version_info::Channel kMaxDisableEncryptionChannel = |
| 4135 | version_info::Channel::BETA; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4136 | #else |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4137 | const version_info::Channel kMaxDisableEncryptionChannel = |
| 4138 | version_info::Channel::DEV; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4139 | #endif |
| 4140 | if (channel <= kMaxDisableEncryptionChannel) { |
| 4141 | static const char* const kWebRtcDevSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 4142 | switches::kDisableWebRtcEncryption, |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4143 | }; |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 4144 | to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames, |
| 4145 | base::size(kWebRtcDevSwitchNames)); |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4146 | } |
| 4147 | } |
bashi | 93362955 | 2016-10-13 23:32:40 | [diff] [blame] | 4148 | |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4149 | #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 4150 | void ChromeContentBrowserClient::CreateMediaRemoter( |
| 4151 | content::RenderFrameHost* render_frame_host, |
Gyuyoung Kim | a4f9f94 | 2019-10-26 02:55:50 | [diff] [blame] | 4152 | mojo::PendingRemote<media::mojom::RemotingSource> source, |
| 4153 | mojo::PendingReceiver<media::mojom::Remoter> receiver) { |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4154 | CastRemotingConnector::CreateMediaRemoter( |
Gyuyoung Kim | a4f9f94 | 2019-10-26 02:55:50 | [diff] [blame] | 4155 | render_frame_host, std::move(source), std::move(receiver)); |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4156 | } |
| 4157 | #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING) |
robliao | bf5a32e | 2016-12-09 03:35:46 | [diff] [blame] | 4158 | |
Michael Giuffrida | 6802ffe | 2017-09-29 03:40:25 | [diff] [blame] | 4159 | base::FilePath ChromeContentBrowserClient::GetLoggingFileName( |
| 4160 | const base::CommandLine& command_line) { |
| 4161 | return logging::GetLogFileName(command_line); |
kerrnel | a67fad5 | 2017-06-14 20:18:16 | [diff] [blame] | 4162 | } |
| 4163 | |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4164 | namespace { |
| 4165 | // TODO(jam): move this to a separate file. |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4166 | class ProtocolHandlerThrottle : public blink::URLLoaderThrottle { |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4167 | public: |
| 4168 | explicit ProtocolHandlerThrottle( |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4169 | ProtocolHandlerRegistry* protocol_handler_registry) |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4170 | : protocol_handler_registry_(protocol_handler_registry) {} |
| 4171 | ~ProtocolHandlerThrottle() override = default; |
| 4172 | |
| 4173 | void WillStartRequest(network::ResourceRequest* request, |
| 4174 | bool* defer) override { |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4175 | TranslateUrl(&request->url); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4176 | } |
| 4177 | |
| 4178 | void WillRedirectRequest(net::RedirectInfo* redirect_info, |
Lucas Furukawa Gadani | 01188659 | 2019-10-23 17:12:24 | [diff] [blame] | 4179 | const network::mojom::URLResponseHead& response_head, |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4180 | bool* defer, |
| 4181 | std::vector<std::string>* to_be_removed_headers, |
| 4182 | net::HttpRequestHeaders* modified_headers) override { |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4183 | TranslateUrl(&redirect_info->new_url); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | private: |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4187 | void TranslateUrl(GURL* url) { |
| 4188 | if (!protocol_handler_registry_->IsHandledProtocol(url->scheme())) |
| 4189 | return; |
| 4190 | GURL translated_url = protocol_handler_registry_->Translate(*url); |
| 4191 | if (!translated_url.is_empty()) |
| 4192 | *url = translated_url; |
| 4193 | } |
| 4194 | |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4195 | ProtocolHandlerRegistry* protocol_handler_registry_; |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4196 | }; |
| 4197 | } // namespace |
| 4198 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4199 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4200 | ChromeContentBrowserClient::CreateURLLoaderThrottles( |
| 4201 | const network::ResourceRequest& request, |
| 4202 | content::BrowserContext* browser_context, |
| 4203 | const base::RepeatingCallback<content::WebContents*()>& wc_getter, |
| 4204 | content::NavigationUIData* navigation_ui_data, |
| 4205 | int frame_tree_node_id) { |
| 4206 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 4207 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4208 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result; |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4209 | |
| 4210 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4211 | |
| 4212 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4213 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4214 | |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 4215 | auto* drp_settings = |
| 4216 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 4217 | browser_context); |
| 4218 | if (chrome_navigation_ui_data && !profile->IsIncognitoProfile() && |
| 4219 | data_reduction_proxy::params::IsEnabledWithNetworkService() && |
| 4220 | drp_settings) { |
| 4221 | if (!data_reduction_proxy_throttle_manager_) { |
Wojciech Dzierżanowski | e7c8e3f | 2019-09-27 20:50:31 | [diff] [blame] | 4222 | data_reduction_proxy_throttle_manager_ = std::make_unique< |
| 4223 | data_reduction_proxy::DataReductionProxyThrottleManager>( |
| 4224 | drp_settings->data_reduction_proxy_service(), |
| 4225 | data_reduction_proxy::DataReductionProxyThrottleManager::CreateConfig( |
| 4226 | drp_settings->data_reduction_proxy_service() |
| 4227 | ->config() |
| 4228 | ->GetProxiesForHttp())); |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 4229 | } |
| 4230 | net::HttpRequestHeaders headers; |
| 4231 | data_reduction_proxy::DataReductionProxyRequestOptions:: |
| 4232 | AddPageIDRequestHeader( |
| 4233 | &headers, |
| 4234 | chrome_navigation_ui_data->data_reduction_proxy_page_id()); |
| 4235 | result.push_back(std::make_unique< |
| 4236 | data_reduction_proxy::DataReductionProxyURLLoaderThrottle>( |
| 4237 | headers, data_reduction_proxy_throttle_manager_.get())); |
| 4238 | } |
| 4239 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4240 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4241 | bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy( |
| 4242 | request.url, *profile->GetPrefs()); |
| 4243 | if (!matches_enterprise_whitelist) { |
| 4244 | result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create( |
| 4245 | base::BindOnce( |
| 4246 | &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate, |
| 4247 | base::Unretained(this)), |
| 4248 | wc_getter, frame_tree_node_id, profile->GetResourceContext())); |
| 4249 | } |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4250 | #endif |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4251 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4252 | if (chrome_navigation_ui_data && |
| 4253 | chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) { |
| 4254 | result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>( |
| 4255 | chrome_navigation_ui_data->prerender_mode(), |
| 4256 | chrome_navigation_ui_data->prerender_histogram_prefix(), |
| 4257 | base::BindOnce(GetPrerenderCanceller, wc_getter), |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 4258 | base::CreateSingleThreadTaskRunner({BrowserThread::UI}))); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4259 | } |
| 4260 | |
David Roger | e8e83f3c | 2019-09-12 10:56:23 | [diff] [blame] | 4261 | signin::IdentityManager* identity_manager = |
| 4262 | IdentityManagerFactory::GetForProfile(profile); |
| 4263 | bool is_signed_in = identity_manager && identity_manager->HasPrimaryAccount(); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4264 | |
| 4265 | chrome::mojom::DynamicParams dynamic_params = { |
| 4266 | profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch), |
| 4267 | profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict), |
| 4268 | profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps), |
| 4269 | variations::VariationsHttpHeaderProvider::GetInstance() |
| 4270 | ->GetClientDataHeader(is_signed_in)}; |
| 4271 | result.push_back(std::make_unique<GoogleURLLoaderThrottle>( |
David Roger | e8e83f3c | 2019-09-12 10:56:23 | [diff] [blame] | 4272 | profile->IsOffTheRecord(), std::move(dynamic_params))); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4273 | |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4274 | result.push_back(std::make_unique<ProtocolHandlerThrottle>( |
| 4275 | ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context))); |
Clark DuVall | 8512cee6 | 2019-06-26 01:14:21 | [diff] [blame] | 4276 | |
Clark DuVall | 39c2cfc | 2019-06-25 21:49:28 | [diff] [blame] | 4277 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 4278 | result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>( |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 4279 | request.resource_type, frame_tree_node_id)); |
Clark DuVall | 39c2cfc | 2019-06-25 21:49:28 | [diff] [blame] | 4280 | #endif |
| 4281 | |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 4282 | auto delegate = |
Robbie McElrath | 38f47af | 2019-09-19 21:51:40 | [diff] [blame] | 4283 | std::make_unique<signin::HeaderModificationDelegateImpl>(profile); |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 4284 | auto signin_throttle = signin::URLLoaderThrottle::MaybeCreate( |
| 4285 | std::move(delegate), navigation_ui_data, wc_getter); |
| 4286 | if (signin_throttle) |
| 4287 | result.push_back(std::move(signin_throttle)); |
| 4288 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4289 | return result; |
| 4290 | } |
| 4291 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4292 | void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4293 | int frame_tree_node_id, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4294 | NonNetworkURLLoaderFactoryMap* factories) { |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4295 | #if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4296 | content::WebContents* web_contents = |
| 4297 | content::WebContents::FromFrameTreeNodeId(frame_tree_node_id); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4298 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4299 | factories->emplace( |
| 4300 | extensions::kExtensionScheme, |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 4301 | extensions::CreateExtensionNavigationURLLoaderFactory( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4302 | web_contents->GetBrowserContext(), |
| 4303 | !!extensions::WebViewGuest::FromWebContents(web_contents))); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4304 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 4305 | #if defined(OS_CHROMEOS) |
| 4306 | Profile* profile = |
| 4307 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Robbie McElrath | 89cc933 | 2019-03-05 02:12:30 | [diff] [blame] | 4308 | factories->emplace(content::kExternalFileScheme, |
| 4309 | std::make_unique<chromeos::ExternalFileURLLoaderFactory>( |
| 4310 | profile, content::ChildProcessHost::kInvalidUniqueID)); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4311 | #endif // defined(OS_CHROMEOS) |
| 4312 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4313 | } |
| 4314 | |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4315 | void ChromeContentBrowserClient:: |
Hiroki Nakagawa | 1efa31d | 2019-10-01 22:36:34 | [diff] [blame] | 4316 | RegisterNonNetworkWorkerMainResourceURLLoaderFactories( |
| 4317 | content::BrowserContext* browser_context, |
| 4318 | NonNetworkURLLoaderFactoryMap* factories) { |
| 4319 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4320 | DCHECK(browser_context); |
| 4321 | DCHECK(factories); |
| 4322 | factories->emplace( |
| 4323 | extensions::kExtensionScheme, |
| 4324 | extensions::CreateExtensionWorkerMainResourceURLLoaderFactory( |
| 4325 | browser_context)); |
| 4326 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 4327 | } |
| 4328 | |
| 4329 | void ChromeContentBrowserClient:: |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4330 | RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories( |
| 4331 | content::BrowserContext* browser_context, |
| 4332 | NonNetworkURLLoaderFactoryMap* factories) { |
Hiroki Nakagawa | d5e7e89d8 | 2019-09-11 09:42:11 | [diff] [blame] | 4333 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4334 | DCHECK(browser_context); |
| 4335 | DCHECK(factories); |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4336 | factories->emplace( |
| 4337 | extensions::kExtensionScheme, |
| 4338 | extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory( |
| 4339 | browser_context)); |
| 4340 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4341 | } |
| 4342 | |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4343 | namespace { |
| 4344 | |
| 4345 | // The FileURLLoaderFactory provided to the extension background pages. |
| 4346 | // Checks with the ChildProcessSecurityPolicy to validate the file access. |
| 4347 | class FileURLLoaderFactory : public network::mojom::URLLoaderFactory { |
| 4348 | public: |
| 4349 | explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {} |
| 4350 | |
| 4351 | private: |
| 4352 | // network::mojom::URLLoaderFactory: |
Julie Jeongeun Kim | e003de5 | 2019-10-29 05:14:27 | [diff] [blame] | 4353 | void CreateLoaderAndStart( |
| 4354 | mojo::PendingReceiver<network::mojom::URLLoader> loader, |
| 4355 | int32_t routing_id, |
| 4356 | int32_t request_id, |
| 4357 | uint32_t options, |
| 4358 | const network::ResourceRequest& request, |
Julie Jeongeun Kim | 6dd4c7b | 2019-11-18 05:56:30 | [diff] [blame] | 4359 | mojo::PendingRemote<network::mojom::URLLoaderClient> client, |
Julie Jeongeun Kim | e003de5 | 2019-10-29 05:14:27 | [diff] [blame] | 4360 | const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) |
| 4361 | override { |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4362 | if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL( |
| 4363 | child_id_, request.url)) { |
Julie Jeongeun Kim | 6dd4c7b | 2019-11-18 05:56:30 | [diff] [blame] | 4364 | mojo::Remote<network::mojom::URLLoaderClient>(std::move(client)) |
| 4365 | ->OnComplete( |
| 4366 | network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED)); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4367 | return; |
| 4368 | } |
| 4369 | content::CreateFileURLLoader(request, std::move(loader), std::move(client), |
John Abd-El-Malek | 916f2b8 | 2019-02-19 23:49:45 | [diff] [blame] | 4370 | /*observer=*/nullptr, |
| 4371 | /* allow_directory_listing */ true); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4372 | } |
| 4373 | |
Julie Jeongeun Kim | 7f8e26a2 | 2019-10-10 12:09:52 | [diff] [blame] | 4374 | void Clone( |
| 4375 | mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader) override { |
| 4376 | receivers_.Add(this, std::move(loader)); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | int child_id_; |
Julie Jeongeun Kim | 7f8e26a2 | 2019-10-10 12:09:52 | [diff] [blame] | 4380 | mojo::ReceiverSet<network::mojom::URLLoaderFactory> receivers_; |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4381 | DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory); |
| 4382 | }; |
| 4383 | |
| 4384 | } // namespace |
| 4385 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4386 | void ChromeContentBrowserClient:: |
| 4387 | RegisterNonNetworkSubresourceURLLoaderFactories( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4388 | int render_process_id, |
| 4389 | int render_frame_id, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4390 | NonNetworkURLLoaderFactoryMap* factories) { |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4391 | #if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS) |
| 4392 | content::RenderFrameHost* frame_host = |
| 4393 | RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 4394 | WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host); |
| 4395 | #endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS) |
| 4396 | |
| 4397 | #if defined(OS_CHROMEOS) |
| 4398 | if (web_contents) { |
| 4399 | Profile* profile = |
| 4400 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Robbie McElrath | 89cc933 | 2019-03-05 02:12:30 | [diff] [blame] | 4401 | factories->emplace(content::kExternalFileScheme, |
| 4402 | std::make_unique<chromeos::ExternalFileURLLoaderFactory>( |
| 4403 | profile, render_process_id)); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4404 | } |
| 4405 | #endif // defined(OS_CHROMEOS) |
| 4406 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4407 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4408 | auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id, |
| 4409 | render_frame_id); |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4410 | if (factory) |
| 4411 | factories->emplace(extensions::kExtensionScheme, std::move(factory)); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4412 | |
| 4413 | // This logic should match |
| 4414 | // ChromeExtensionWebContentsObserver::RenderFrameCreated. |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4415 | if (!web_contents) |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4416 | return; |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4417 | |
| 4418 | Profile* profile = |
| 4419 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 4420 | InstantService* instant_service = |
| 4421 | InstantServiceFactory::GetForProfile(profile); |
| 4422 | // The test below matches what's done by ShouldServiceRequestIOThread in |
| 4423 | // local_ntp_source.cc. |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4424 | if (instant_service->IsInstantProcess(render_process_id)) { |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4425 | factories->emplace( |
| 4426 | chrome::kChromeSearchScheme, |
| 4427 | content::CreateWebUIURLLoader( |
| 4428 | frame_host, chrome::kChromeSearchScheme, |
| 4429 | /*allowed_webui_hosts=*/base::flat_set<std::string>())); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4430 | } |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4431 | |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4432 | extensions::ChromeExtensionWebContentsObserver* web_observer = |
| 4433 | extensions::ChromeExtensionWebContentsObserver::FromWebContents( |
| 4434 | web_contents); |
| 4435 | |
Karan Bhatia | 9192857 | 2018-03-06 01:18:07 | [diff] [blame] | 4436 | // There is nothing to do if no ChromeExtensionWebContentsObserver is attached |
| 4437 | // to the |web_contents|. |
| 4438 | if (!web_observer) |
| 4439 | return; |
| 4440 | |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4441 | const Extension* extension = |
| 4442 | web_observer->GetExtensionFromFrame(frame_host, false); |
| 4443 | if (!extension) |
| 4444 | return; |
| 4445 | |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4446 | std::vector<std::string> allowed_webui_hosts; |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4447 | // Support for chrome:// scheme if appropriate. |
| 4448 | if ((extension->is_extension() || extension->is_platform_app()) && |
| 4449 | Manifest::IsComponentLocation(extension->location())) { |
| 4450 | // Components of chrome that are implemented as extensions or platform apps |
| 4451 | // are allowed to use chrome://resources/ and chrome://theme/ URLs. |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4452 | allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost); |
| 4453 | allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost); |
| 4454 | } |
| 4455 | if (extension->is_extension() || extension->is_legacy_packaged_app() || |
| 4456 | (extension->is_platform_app() && |
| 4457 | Manifest::IsComponentLocation(extension->location()))) { |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4458 | // Extensions, legacy packaged apps, and component platform apps are allowed |
Lucas Tenório | 3dd8092 | 2019-03-27 03:51:02 | [diff] [blame] | 4459 | // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon |
| 4460 | // URLs. Hosted apps are not allowed because they are served via web servers |
| 4461 | // (and are generally never given access to Chrome APIs). |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4462 | allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost); |
| 4463 | allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost); |
Lucas Tenório | 3dd8092 | 2019-03-27 03:51:02 | [diff] [blame] | 4464 | allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost); |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4465 | } |
| 4466 | if (!allowed_webui_hosts.empty()) { |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4467 | factories->emplace( |
| 4468 | content::kChromeUIScheme, |
| 4469 | content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme, |
| 4470 | std::move(allowed_webui_hosts))); |
| 4471 | } |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4472 | |
| 4473 | // Extension with a background page get file access that gets approval from |
| 4474 | // ChildProcessSecurityPolicy. |
| 4475 | extensions::ExtensionHost* host = |
| 4476 | extensions::ProcessManager::Get(web_contents->GetBrowserContext()) |
| 4477 | ->GetBackgroundHostForExtension(extension->id()); |
| 4478 | if (host) { |
| 4479 | factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>( |
| 4480 | render_process_id)); |
| 4481 | } |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4482 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4483 | } |
| 4484 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4485 | bool ChromeContentBrowserClient::WillCreateURLLoaderFactory( |
Ken Rockot | 428b1d6 | 2018-06-06 17:12:21 | [diff] [blame] | 4486 | content::BrowserContext* browser_context, |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4487 | content::RenderFrameHost* frame, |
Kenichi Ishibashi | 09ee5e7 | 2018-11-27 07:12:38 | [diff] [blame] | 4488 | int render_process_id, |
Karan Bhatia | 4a834b3 | 2019-08-16 22:26:44 | [diff] [blame] | 4489 | URLLoaderFactoryType type, |
Lukasz Anforowicz | 76273365 | 2018-09-28 14:48:26 | [diff] [blame] | 4490 | const url::Origin& request_initiator, |
Karan Bhatia | 303d0ac0 | 2019-12-05 03:01:00 | [diff] [blame] | 4491 | base::Optional<int64_t> navigation_id, |
Dominic Farolino | 1be897a | 2019-07-20 08:11:42 | [diff] [blame] | 4492 | mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver, |
Julie Jeongeun Kim | 47499a0c | 2019-08-28 07:23:18 | [diff] [blame] | 4493 | mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>* |
| 4494 | header_client, |
Yutaka Hirano | 499d1321 | 2019-12-04 11:03:33 | [diff] [blame] | 4495 | bool* bypass_redirect_checks, |
| 4496 | network::mojom::URLLoaderFactoryOverridePtr* factory_override) { |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4497 | bool use_proxy = false; |
| 4498 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4499 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4500 | auto* web_request_api = |
| 4501 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
Ken Rockot | 428b1d6 | 2018-06-06 17:12:21 | [diff] [blame] | 4502 | browser_context); |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4503 | |
| 4504 | // NOTE: Some unit test environments do not initialize |
| 4505 | // BrowserContextKeyedAPI factories for e.g. WebRequest. |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4506 | if (web_request_api) { |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4507 | bool use_proxy_for_web_request = |
Kenichi Ishibashi | 09ee5e7 | 2018-11-27 07:12:38 | [diff] [blame] | 4508 | web_request_api->MaybeProxyURLLoaderFactory( |
Karan Bhatia | 303d0ac0 | 2019-12-05 03:01:00 | [diff] [blame] | 4509 | browser_context, frame, render_process_id, type, |
| 4510 | std::move(navigation_id), factory_receiver, header_client); |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4511 | if (bypass_redirect_checks) |
| 4512 | *bypass_redirect_checks = use_proxy_for_web_request; |
| 4513 | use_proxy |= use_proxy_for_web_request; |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4514 | } |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4515 | #endif |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4516 | |
Reilly Grant | cc22e60 | 2018-09-07 15:25:20 | [diff] [blame] | 4517 | use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest( |
Karan Bhatia | 4a834b3 | 2019-08-16 22:26:44 | [diff] [blame] | 4518 | frame, type == URLLoaderFactoryType::kNavigation, request_initiator, |
| 4519 | factory_receiver); |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4520 | |
| 4521 | return use_proxy; |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4522 | } |
| 4523 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4524 | std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> |
| 4525 | ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors( |
| 4526 | content::NavigationUIData* navigation_ui_data, |
Ryan Sturm | 27d93f41 | 2019-02-15 21:30:14 | [diff] [blame] | 4527 | int frame_tree_node_id, |
| 4528 | const scoped_refptr<network::SharedURLLoaderFactory>& |
| 4529 | network_loader_factory) { |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4530 | std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> |
| 4531 | interceptors; |
| 4532 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 4533 | interceptors.push_back( |
| 4534 | std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>( |
| 4535 | navigation_ui_data, frame_tree_node_id)); |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4536 | #endif |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 4537 | |
Robert Ogden | 3d5d5b4 | 2019-04-22 05:13:11 | [diff] [blame] | 4538 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4539 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4540 | |
Ryan Sturm | 27d93f41 | 2019-02-15 21:30:14 | [diff] [blame] | 4541 | // TODO(ryansturm): Once this is on the UI thread, stop passing |
| 4542 | // |network_loader_factory| and have interceptors create one themselves. |
| 4543 | // https://crbug.com/931786 |
Doug Arnett | 2715479 | 2019-10-15 21:00:59 | [diff] [blame] | 4544 | if (previews::params::IsLitePageServerPreviewsEnabled()) { |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 4545 | interceptors.push_back( |
Robert Ogden | 0f4d8868 | 2019-09-24 22:27:52 | [diff] [blame] | 4546 | std::make_unique< |
| 4547 | previews::PreviewsLitePageRedirectURLLoaderInterceptor>( |
Robert Ogden | 3d5d5b4 | 2019-04-22 05:13:11 | [diff] [blame] | 4548 | network_loader_factory, |
| 4549 | chrome_navigation_ui_data->data_reduction_proxy_page_id(), |
| 4550 | frame_tree_node_id)); |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 4551 | } |
| 4552 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4553 | return interceptors; |
| 4554 | } |
| 4555 | |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4556 | bool ChromeContentBrowserClient::WillInterceptWebSocket( |
| 4557 | content::RenderFrameHost* frame) { |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4558 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4559 | if (!frame) { |
| 4560 | return false; |
| 4561 | } |
| 4562 | const auto* web_request_api = |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4563 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
| 4564 | frame->GetProcess()->GetBrowserContext()); |
| 4565 | |
| 4566 | // NOTE: Some unit test environments do not initialize |
| 4567 | // BrowserContextKeyedAPI factories for e.g. WebRequest. |
| 4568 | if (!web_request_api) |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4569 | return false; |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4570 | |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4571 | return web_request_api->MayHaveProxies(); |
| 4572 | #else |
| 4573 | return false; |
| 4574 | #endif |
| 4575 | } |
| 4576 | |
| 4577 | void ChromeContentBrowserClient::CreateWebSocket( |
| 4578 | content::RenderFrameHost* frame, |
| 4579 | WebSocketFactory factory, |
| 4580 | const GURL& url, |
| 4581 | const GURL& site_for_cookies, |
| 4582 | const base::Optional<std::string>& user_agent, |
Julie Jeongeun Kim | 3e973f9 | 2019-08-22 08:02:40 | [diff] [blame] | 4583 | mojo::PendingRemote<network::mojom::WebSocketHandshakeClient> |
| 4584 | handshake_client) { |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4585 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4586 | if (!frame) { |
| 4587 | return; |
| 4588 | } |
| 4589 | auto* web_request_api = |
| 4590 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
| 4591 | frame->GetProcess()->GetBrowserContext()); |
| 4592 | |
| 4593 | DCHECK(web_request_api); |
| 4594 | web_request_api->ProxyWebSocket(frame, std::move(factory), url, |
| 4595 | site_for_cookies, user_agent, |
| 4596 | std::move(handshake_client)); |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4597 | #endif |
| 4598 | } |
| 4599 | |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4600 | bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager( |
Maks Orlovich | e7db7a2 | 2019-07-25 01:47:46 | [diff] [blame] | 4601 | network::mojom::RestrictedCookieManagerRole role, |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4602 | content::BrowserContext* browser_context, |
| 4603 | const url::Origin& origin, |
Maks Orlovich | 11001fa | 2019-10-01 20:41:40 | [diff] [blame] | 4604 | const GURL& site_for_cookies, |
| 4605 | const url::Origin& top_frame_origin, |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4606 | bool is_service_worker, |
| 4607 | int process_id, |
| 4608 | int routing_id, |
Julie Jeongeun Kim | d20f64b | 2019-08-26 04:13:03 | [diff] [blame] | 4609 | mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) { |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4610 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 4611 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4612 | if (origin.scheme() == extensions::kExtensionScheme) { |
Maks Orlovich | e7db7a2 | 2019-07-25 01:47:46 | [diff] [blame] | 4613 | DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role); |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4614 | extensions::ChromeExtensionCookies::Get(browser_context) |
Maks Orlovich | 11001fa | 2019-10-01 20:41:40 | [diff] [blame] | 4615 | ->CreateRestrictedCookieManager(origin, site_for_cookies, |
| 4616 | top_frame_origin, std::move(*receiver)); |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4617 | return true; |
| 4618 | } |
| 4619 | #endif |
| 4620 | return false; |
| 4621 | } |
| 4622 | |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 4623 | void ChromeContentBrowserClient::OnNetworkServiceCreated( |
| 4624 | network::mojom::NetworkService* network_service) { |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4625 | PrefService* local_state; |
| 4626 | if (g_browser_process) { |
| 4627 | DCHECK(g_browser_process->local_state()); |
| 4628 | local_state = g_browser_process->local_state(); |
| 4629 | } else { |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 4630 | DCHECK(startup_data_->chrome_feature_list_creator()->local_state()); |
| 4631 | local_state = startup_data_->chrome_feature_list_creator()->local_state(); |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4632 | } |
| 4633 | |
| 4634 | if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance()) |
| 4635 | data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state); |
| 4636 | |
Henrique Nakashima | a3b1c5d | 2019-07-03 19:25:49 | [diff] [blame] | 4637 | // Create SystemNetworkContextManager if it has not been created yet. We need |
| 4638 | // to set up global NetworkService state before anything else uses it and this |
| 4639 | // is the first opportunity to initialize SystemNetworkContextManager with the |
| 4640 | // NetworkService. |
| 4641 | if (!SystemNetworkContextManager::HasInstance()) |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4642 | SystemNetworkContextManager::CreateInstance(local_state); |
John Abd-El-Malek | 897374f4 | 2019-05-30 03:58:07 | [diff] [blame] | 4643 | |
Min Qin | 8caab1d | 2018-10-03 17:28:13 | [diff] [blame] | 4644 | SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated( |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 4645 | network_service); |
| 4646 | } |
| 4647 | |
Julie Jeongeun Kim | 5984e99 | 2019-09-11 11:00:46 | [diff] [blame] | 4648 | mojo::Remote<network::mojom::NetworkContext> |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4649 | ChromeContentBrowserClient::CreateNetworkContext( |
| 4650 | content::BrowserContext* context, |
| 4651 | bool in_memory, |
| 4652 | const base::FilePath& relative_partition_path) { |
John Abd-El-Malek | cc0b2a6 | 2018-03-20 19:32:50 | [diff] [blame] | 4653 | Profile* profile = Profile::FromBrowserContext(context); |
Matt Menke | d38efd9 | 2018-08-14 20:39:45 | [diff] [blame] | 4654 | return profile->CreateNetworkContext(in_memory, relative_partition_path); |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4655 | } |
| 4656 | |
Robert Sesek | 34f68f31 | 2019-01-14 20:25:11 | [diff] [blame] | 4657 | std::vector<base::FilePath> |
| 4658 | ChromeContentBrowserClient::GetNetworkContextsParentDirectory() { |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 4659 | DCHECK(!network_contexts_parent_directory_.empty()); |
| 4660 | return network_contexts_parent_directory_; |
Robert Sesek | 34f68f31 | 2019-01-14 20:25:11 | [diff] [blame] | 4661 | } |
| 4662 | |
Min Qin | 75ed6df | 2017-12-01 20:39:15 | [diff] [blame] | 4663 | bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp( |
Min Qin | 30a78a1 | 2017-12-06 01:29:13 | [diff] [blame] | 4664 | content::NavigationUIData* navigation_ui_data) { |
Min Qin | 75ed6df | 2017-12-01 20:39:15 | [diff] [blame] | 4665 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 4666 | // It is OK to load the saved offline copy, in MHTML format. |
| 4667 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4668 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4669 | if (!chrome_navigation_ui_data) |
| 4670 | return false; |
| 4671 | offline_pages::OfflinePageNavigationUIData* offline_page_data = |
| 4672 | chrome_navigation_ui_data->GetOfflinePageNavigationUIData(); |
| 4673 | return offline_page_data && offline_page_data->is_offline_page(); |
| 4674 | #else |
| 4675 | return false; |
| 4676 | #endif |
| 4677 | } |
| 4678 | |
Min Qin | 30a78a1 | 2017-12-06 01:29:13 | [diff] [blame] | 4679 | bool ChromeContentBrowserClient::ShouldForceDownloadResource( |
| 4680 | const GURL& url, |
| 4681 | const std::string& mime_type) { |
| 4682 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4683 | // Special-case user scripts to get downloaded instead of viewed. |
| 4684 | return extensions::UserScript::IsURLUserScript(url, mime_type); |
| 4685 | #else |
| 4686 | return false; |
| 4687 | #endif |
| 4688 | } |
| 4689 | |
Donna Wu | 838ac36 | 2018-08-10 10:36:33 | [diff] [blame] | 4690 | void ChromeContentBrowserClient::CreateWebUsbService( |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 4691 | content::RenderFrameHost* render_frame_host, |
Miyoung Shin | 6262215 | 2019-08-27 05:13:04 | [diff] [blame] | 4692 | mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) { |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 4693 | if (!base::FeatureList::IsEnabled(features::kWebUsb)) |
| 4694 | return; |
| 4695 | |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 4696 | WebContents* web_contents = |
| 4697 | WebContents::FromRenderFrameHost(render_frame_host); |
| 4698 | if (!web_contents) { |
| 4699 | NOTREACHED(); |
| 4700 | return; |
| 4701 | } |
| 4702 | |
| 4703 | UsbTabHelper* tab_helper = |
| 4704 | UsbTabHelper::GetOrCreateForWebContents(web_contents); |
Miyoung Shin | 6262215 | 2019-08-27 05:13:04 | [diff] [blame] | 4705 | tab_helper->CreateWebUsbService(render_frame_host, std::move(receiver)); |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 4706 | } |
| 4707 | |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 4708 | #if !defined(OS_ANDROID) |
| 4709 | content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() { |
| 4710 | if (!serial_delegate_) |
| 4711 | serial_delegate_ = std::make_unique<ChromeSerialDelegate>(); |
| 4712 | return serial_delegate_.get(); |
| 4713 | } |
Matt Reynolds | 93616f9b | 2019-06-07 01:28:52 | [diff] [blame] | 4714 | |
| 4715 | content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() { |
| 4716 | if (!hid_delegate_) |
| 4717 | hid_delegate_ = std::make_unique<ChromeHidDelegate>(); |
| 4718 | return hid_delegate_.get(); |
| 4719 | } |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 4720 | |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 4721 | std::unique_ptr<content::AuthenticatorRequestClientDelegate> |
| 4722 | ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate( |
Adam Langley | eeac87e | 2019-04-13 22:58:22 | [diff] [blame] | 4723 | content::RenderFrameHost* render_frame_host, |
| 4724 | const std::string& relying_party_id) { |
| 4725 | return AuthenticatorRequestScheduler::CreateRequestDelegate(render_frame_host, |
| 4726 | relying_party_id); |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 4727 | } |
Nina Satragno | 8c832df | 2019-07-29 15:59:39 | [diff] [blame] | 4728 | #endif |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 4729 | |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 4730 | std::unique_ptr<net::ClientCertStore> |
| 4731 | ChromeContentBrowserClient::CreateClientCertStore( |
David Benjamin | f6a3409 | 2019-11-07 19:55:10 | [diff] [blame] | 4732 | content::BrowserContext* browser_context) { |
| 4733 | return ProfileNetworkContextServiceFactory::GetForContext(browser_context) |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 4734 | ->CreateClientCertStore(); |
| 4735 | } |
| 4736 | |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 4737 | std::unique_ptr<content::LoginDelegate> |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 4738 | ChromeContentBrowserClient::CreateLoginDelegate( |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 4739 | const net::AuthChallengeInfo& auth_info, |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 4740 | content::WebContents* web_contents, |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 4741 | const content::GlobalRequestID& request_id, |
Jun Cai | 8e165d2 | 2018-05-14 19:21:24 | [diff] [blame] | 4742 | bool is_request_for_main_frame, |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 4743 | const GURL& url, |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 4744 | scoped_refptr<net::HttpResponseHeaders> response_headers, |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 4745 | bool first_auth_attempt, |
Mark Pilgrim | 7cfcd11 | 2018-05-08 00:07:56 | [diff] [blame] | 4746 | LoginAuthRequiredCallback auth_required_callback) { |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 4747 | return CreateLoginPrompt( |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 4748 | auth_info, web_contents, request_id, is_request_for_main_frame, url, |
Emily Stark | c5f1579 | 2019-05-19 17:24:20 | [diff] [blame] | 4749 | std::move(response_headers), LoginHandler::PRE_COMMIT, |
| 4750 | std::move(auth_required_callback)); |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 4751 | } |
| 4752 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 4753 | bool ChromeContentBrowserClient::HandleExternalProtocol( |
| 4754 | const GURL& url, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 4755 | content::WebContents::OnceGetter web_contents_getter, |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 4756 | int child_id, |
| 4757 | content::NavigationUIData* navigation_data, |
| 4758 | bool is_main_frame, |
| 4759 | ui::PageTransition page_transition, |
Tim Volodine | b24393f3 | 2018-11-16 18:45:45 | [diff] [blame] | 4760 | bool has_user_gesture, |
Emily Stark | 13b66bdf | 2019-10-04 17:11:45 | [diff] [blame] | 4761 | const base::Optional<url::Origin>& initiating_origin, |
Julie Jeongeun Kim | fb6f530 | 2019-10-17 17:24:10 | [diff] [blame] | 4762 | mojo::PendingRemote<network::mojom::URLLoaderFactory>* out_factory) { |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 4763 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4764 | // External protocols are disabled for guests. An exception is made for the |
| 4765 | // "mailto" protocol, so that pages that utilize it work properly in a |
| 4766 | // WebView. |
| 4767 | ChromeNavigationUIData* chrome_data = |
| 4768 | static_cast<ChromeNavigationUIData*>(navigation_data); |
| 4769 | if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) || |
| 4770 | (chrome_data && |
| 4771 | chrome_data->GetExtensionNavigationUIData()->is_web_view())) && |
| 4772 | !url.SchemeIs(url::kMailToScheme)) { |
| 4773 | return false; |
| 4774 | } |
| 4775 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 4776 | |
| 4777 | #if defined(OS_ANDROID) |
| 4778 | // Main frame external protocols are handled by |
| 4779 | // InterceptNavigationResourceThrottle. |
| 4780 | if (is_main_frame) |
| 4781 | return false; |
| 4782 | #endif // defined(ANDROID) |
| 4783 | |
Emily Stark | 13b66bdf | 2019-10-04 17:11:45 | [diff] [blame] | 4784 | base::PostTask( |
| 4785 | FROM_HERE, {BrowserThread::UI}, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame] | 4786 | base::BindOnce(&LaunchURL, url, std::move(web_contents_getter), |
| 4787 | page_transition, has_user_gesture, initiating_origin)); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 4788 | return true; |
| 4789 | } |
| 4790 | |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 4791 | std::unique_ptr<content::OverlayWindow> |
Jennifer Apacible | 6010b023 | 2018-04-12 23:35:28 | [diff] [blame] | 4792 | ChromeContentBrowserClient::CreateWindowForPictureInPicture( |
| 4793 | content::PictureInPictureWindowController* controller) { |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 4794 | // Note: content::OverlayWindow::Create() is defined by platform-specific |
| 4795 | // implementation in chrome/browser/ui/views. This layering hack, which goes |
| 4796 | // through //content and ContentBrowserClient, allows us to work around the |
| 4797 | // dependency constraints that disallow directly calling |
| 4798 | // chrome/browser/ui/views code either from here or from other code in |
| 4799 | // chrome/browser. |
Jennifer Apacible | 6010b023 | 2018-04-12 23:35:28 | [diff] [blame] | 4800 | return content::OverlayWindow::Create(controller); |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 4801 | } |
| 4802 | |
Kunihiko Sakamoto | 19aa708 | 2019-02-25 03:14:43 | [diff] [blame] | 4803 | void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher( |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 4804 | content::BrowserContext* browser_context, |
Julie Jeongeun Kim | 6d8b749 | 2019-08-20 19:24:11 | [diff] [blame] | 4805 | mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) { |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 4806 | Profile* profile = Profile::FromBrowserContext(browser_context); |
Kunihiko Sakamoto | 19aa708 | 2019-02-25 03:14:43 | [diff] [blame] | 4807 | PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher( |
| 4808 | std::move(watcher)); |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 4809 | } |
| 4810 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 4811 | // Static; handles rewriting Web UI URLs. |
| 4812 | bool ChromeContentBrowserClient::HandleWebUI( |
| 4813 | GURL* url, |
| 4814 | content::BrowserContext* browser_context) { |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 4815 | // Rewrite chrome://help to chrome://settings/help. |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 4816 | if (url->SchemeIs(content::kChromeUIScheme) && |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 4817 | url->host() == chrome::kChromeUIHelpHost) { |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 4818 | *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost, |
| 4819 | chrome::kChromeUIHelpHost); |
| 4820 | return true; // Return true to update the displayed URL. |
| 4821 | } |
| 4822 | |
Hector Carmona | 566a20b | 2019-09-13 22:44:42 | [diff] [blame] | 4823 | #if defined(OS_WIN) |
| 4824 | // TODO(crbug.com/1003960): Remove when issue is resolved. |
| 4825 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 4826 | url->host() == chrome::kChromeUIWelcomeWin10Host) { |
| 4827 | url::Replacements<char> replacements; |
| 4828 | replacements.SetHost( |
| 4829 | chrome::kChromeUIWelcomeHost, |
| 4830 | url::Component(0, strlen(chrome::kChromeUIWelcomeHost))); |
| 4831 | *url = url->ReplaceComponents(replacements); |
| 4832 | return true; |
| 4833 | } |
| 4834 | #endif // defined(OS_WIN) |
| 4835 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 4836 | if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 4837 | browser_context, *url)) { |
| 4838 | return false; |
| 4839 | } |
| 4840 | |
| 4841 | #if defined(OS_CHROMEOS) |
| 4842 | // Special case : in ChromeOS in Guest mode bookmarks and history are |
| 4843 | // disabled for security reasons. New tab page explains the reasons, so |
| 4844 | // we redirect user to new tab page. |
| 4845 | if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { |
| 4846 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 4847 | (url->DomainIs(chrome::kChromeUIBookmarksHost) || |
| 4848 | url->DomainIs(chrome::kChromeUIHistoryHost))) { |
| 4849 | // Rewrite with new tab URL |
| 4850 | *url = GURL(chrome::kChromeUINewTabURL); |
| 4851 | } |
| 4852 | } |
| 4853 | #endif |
| 4854 | |
| 4855 | return true; |
| 4856 | } |
| 4857 | |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 4858 | bool ChromeContentBrowserClient::ShowPaymentHandlerWindow( |
| 4859 | content::BrowserContext* browser_context, |
| 4860 | const GURL& url, |
Anthony Vallee-Dubois | 98befeaa | 2018-01-18 16:31:32 | [diff] [blame] | 4861 | base::OnceCallback<void(bool, int, int)> callback) { |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 4862 | #if defined(OS_ANDROID) |
| 4863 | return false; |
| 4864 | #else |
| 4865 | payments::PaymentRequestDisplayManagerFactory::GetInstance() |
| 4866 | ->GetForBrowserContext(browser_context) |
| 4867 | ->ShowPaymentHandlerWindow(url, std::move(callback)); |
| 4868 | return true; |
| 4869 | #endif |
| 4870 | } |
| 4871 | |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 4872 | // static |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 4873 | bool ChromeContentBrowserClient::HandleWebUIReverse( |
| 4874 | GURL* url, |
| 4875 | content::BrowserContext* browser_context) { |
Hector Carmona | 566a20b | 2019-09-13 22:44:42 | [diff] [blame] | 4876 | #if defined(OS_WIN) |
| 4877 | // TODO(crbug.com/1003960): Remove when issue is resolved. |
| 4878 | // No need to actually reverse-rewrite the URL, but return true to update the |
| 4879 | // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome. |
| 4880 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 4881 | url->host() == chrome::kChromeUIWelcomeHost) { |
| 4882 | return true; |
| 4883 | } |
| 4884 | #endif // defined(OS_WIN) |
| 4885 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 4886 | // No need to actually reverse-rewrite the URL, but return true to update the |
| 4887 | // displayed URL when rewriting chrome://help to chrome://settings/help. |
| 4888 | return url->SchemeIs(content::kChromeUIScheme) && |
| 4889 | url->host() == chrome::kChromeUISettingsHost; |
| 4890 | } |
| 4891 | |
Alison Maher | 28a73e2 | 2019-10-18 19:26:35 | [diff] [blame] | 4892 | ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const { |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 4893 | return ui::NativeTheme::GetInstanceForWeb(); |
| 4894 | } |
| 4895 | |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 4896 | // static |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 4897 | void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( |
| 4898 | const storage::QuotaSettings* settings) { |
| 4899 | g_default_quota_settings = settings; |
| 4900 | } |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 4901 | |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4902 | scoped_refptr<safe_browsing::UrlCheckerDelegate> |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 4903 | ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate( |
| 4904 | content::ResourceContext* resource_context) { |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 4905 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 4906 | |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 4907 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 4908 | if (!io_data->safe_browsing_enabled()->GetValue()) |
| 4909 | return nullptr; |
| 4910 | |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 4911 | // |safe_browsing_service_| may be unavailable in tests. |
| 4912 | if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) { |
| 4913 | safe_browsing_url_checker_delegate_ = |
Jialiu Lin | 0de6756c | 2018-03-22 00:57:43 | [diff] [blame] | 4914 | base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>( |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 4915 | safe_browsing_service_->database_manager(), |
Jialiu Lin | 0de6756c | 2018-03-22 00:57:43 | [diff] [blame] | 4916 | safe_browsing_service_->ui_manager()); |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 4917 | } |
| 4918 | |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4919 | return safe_browsing_url_checker_delegate_; |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 4920 | } |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 4921 | |
| 4922 | base::Optional<std::string> |
| 4923 | ChromeContentBrowserClient::GetOriginPolicyErrorPage( |
Andy Paicu | 8b6f871 | 2019-07-16 15:02:26 | [diff] [blame] | 4924 | network::OriginPolicyState error_reason, |
Daniel Vogelheim | 7badd0d | 2019-02-04 14:42:18 | [diff] [blame] | 4925 | content::NavigationHandle* handle) { |
| 4926 | return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML( |
| 4927 | error_reason, handle); |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 4928 | } |
Kunihiko Sakamoto | 73b803d | 2018-10-05 09:09:52 | [diff] [blame] | 4929 | |
Takashi Toyoshima | 5af383aa | 2019-07-22 15:24:22 | [diff] [blame] | 4930 | bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() { |
Kunihiko Sakamoto | 73b803d | 2018-10-05 09:09:52 | [diff] [blame] | 4931 | // We require --user-data-dir flag too so that no dangerous changes are made |
| 4932 | // in the user's regular profile. |
| 4933 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 4934 | switches::kUserDataDir); |
| 4935 | } |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 4936 | |
| 4937 | void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate( |
| 4938 | int32_t network_traffic_annotation_id_hash, |
| 4939 | int64_t recv_bytes, |
| 4940 | int64_t sent_bytes) { |
Min Qin | cafb27b | 2018-10-30 18:02:03 | [diff] [blame] | 4941 | if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) { |
| 4942 | data_use_measurement::ChromeDataUseMeasurement::GetInstance() |
| 4943 | ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash, |
| 4944 | recv_bytes, sent_bytes); |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 4945 | } |
| 4946 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 4947 | |
| 4948 | content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews( |
| 4949 | content::PreviewsState initial_state, |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 4950 | content::NavigationHandle* navigation_handle, |
| 4951 | const GURL& current_navigation_url) { |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 4952 | content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback( |
| 4953 | initial_state, navigation_handle, current_navigation_url); |
| 4954 | |
| 4955 | return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle); |
| 4956 | } |
| 4957 | |
| 4958 | content::PreviewsState |
| 4959 | ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback( |
| 4960 | content::PreviewsState initial_state, |
| 4961 | content::NavigationHandle* navigation_handle, |
| 4962 | const GURL& current_navigation_url) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 4963 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
Tarun Bansal | b89c1d5 | 2019-01-16 06:56:29 | [diff] [blame] | 4964 | DCHECK(!navigation_handle->HasCommitted()); |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 4965 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 4966 | // If this is not a main frame, return the initial state. If there are no |
| 4967 | // previews in the state, return the state as is. |
| 4968 | if (!navigation_handle->IsInMainFrame() || |
| 4969 | navigation_handle->IsSameDocument()) { |
| 4970 | return initial_state; |
| 4971 | } |
| 4972 | |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 4973 | if (!current_navigation_url.SchemeIsHTTPOrHTTPS()) |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 4974 | return content::PREVIEWS_OFF; |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 4975 | |
Doug Arnett | b3b99bc | 2019-08-09 16:55:56 | [diff] [blame] | 4976 | // Check if initial state specifies no previews should be considered. |
| 4977 | if (initial_state == content::PREVIEWS_OFF) |
| 4978 | return initial_state; |
| 4979 | |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 4980 | // Do not allow previews on POST navigations since the primary opt-out |
| 4981 | // mechanism is to reload the page. Because POST navigations are not |
| 4982 | // idempotent, we do not want to show a preview on a POST navigation where |
| 4983 | // opting out would cause another navigation, i.e.: a reload. |
| 4984 | if (navigation_handle->IsPost()) |
| 4985 | return content::PREVIEWS_OFF; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 4986 | |
| 4987 | content::WebContents* web_contents = navigation_handle->GetWebContents(); |
| 4988 | content::WebContentsDelegate* delegate = web_contents->GetDelegate(); |
| 4989 | |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 4990 | auto* browser_context = web_contents->GetBrowserContext(); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 4991 | |
| 4992 | PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile( |
| 4993 | Profile::FromBrowserContext(browser_context)); |
| 4994 | auto* data_reduction_proxy_settings = |
| 4995 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 4996 | browser_context); |
| 4997 | // If the profile does not support previews or Data Saver, do not turn on |
| 4998 | // Previews. |
| 4999 | if (!previews_service || !previews_service->previews_ui_service() || |
Owen Min | 08a7289 | 2019-07-31 20:03:35 | [diff] [blame] | 5000 | !data_reduction_proxy_settings) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5001 | return content::PREVIEWS_OFF; |
| 5002 | } |
| 5003 | |
| 5004 | PreviewsUITabHelper* ui_tab_helper = |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5005 | PreviewsUITabHelper::FromWebContents(web_contents); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5006 | // If this tab does not have a PreviewsUITabHelper, no preview should be |
| 5007 | // served. |
| 5008 | if (!ui_tab_helper) |
| 5009 | return content::PREVIEWS_OFF; |
| 5010 | |
| 5011 | DCHECK(!browser_context->IsOffTheRecord()); |
| 5012 | |
| 5013 | // Other previews objects should all exist and be initialized if we have made |
| 5014 | // it past earlier checks. |
| 5015 | previews::PreviewsDeciderImpl* previews_decider_impl = |
| 5016 | previews_service->previews_ui_service()->previews_decider_impl(); |
| 5017 | DCHECK(previews_decider_impl); |
| 5018 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5019 | // Start with an unspecified state. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5020 | content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED; |
| 5021 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5022 | previews::PreviewsUserData* previews_data = |
| 5023 | ui_tab_helper->GetPreviewsUserData(navigation_handle); |
| 5024 | |
| 5025 | // Certain PreviewsStates are used within URLLoaders (Offline, server |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5026 | // previews) and cannot re-evaluate PreviewsState once previews triggering |
| 5027 | // logic has already been run, so they should not change. Assume that |
| 5028 | // previews triggering logic has run when PreviewsUserData already exists and |
| 5029 | // a Lite Page Redirect preview is not being attempted, since it may also |
| 5030 | // create a previews_data before this point. |
| 5031 | bool previews_triggering_logic_already_ran = false; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5032 | if (previews_data) { |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5033 | previews_triggering_logic_already_ran = |
| 5034 | !previews_data->server_lite_page_info(); |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5035 | } else { |
| 5036 | previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle( |
| 5037 | navigation_handle, previews_decider_impl->GeneratePageId()); |
| 5038 | } |
| 5039 | |
| 5040 | DCHECK(previews_data); |
| 5041 | |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 5042 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 5043 | previews::switches::kForceEnablePreviews)) { |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 5044 | return content::ALL_SUPPORTED_PREVIEWS; |
| 5045 | } |
| 5046 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5047 | bool is_reload = |
| 5048 | navigation_handle->GetReloadType() != content::ReloadType::NONE; |
| 5049 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5050 | content::PreviewsState server_previews_enabled_state = |
Robert Ogden | 54bb4ff | 2019-06-19 01:31:51 | [diff] [blame] | 5051 | content::SERVER_LITE_PAGE_ON; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5052 | |
| 5053 | // For now, treat server previews types as a single decision, and do not |
| 5054 | // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT |
| 5055 | // header, nor does the plumbing exist to modify the PreviewsState within the |
| 5056 | // URLLoader. |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5057 | if (previews_triggering_logic_already_ran) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5058 | // Copy the server state that was used before the redirect for the initial |
| 5059 | // URL. |
Robert Ogden | 869986f | 2019-06-20 19:12:05 | [diff] [blame] | 5060 | previews_state |= |
| 5061 | (previews_data->AllowedPreviewsState() & server_previews_enabled_state); |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5062 | } else { |
Doug Arnett | a3dc7158 | 2018-11-08 00:25:10 | [diff] [blame] | 5063 | if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart( |
Sophie Chang | ff1fc38 | 2019-08-21 16:30:21 | [diff] [blame] | 5064 | previews_data, navigation_handle, is_reload, |
Doug Arnett | d5a6003 | 2018-11-12 19:37:30 | [diff] [blame] | 5065 | previews::PreviewsType::LITE_PAGE)) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5066 | previews_state |= server_previews_enabled_state; |
| 5067 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5068 | } |
| 5069 | |
Sophie Chang | a71fa5d | 2019-11-19 23:53:51 | [diff] [blame] | 5070 | // Evaluate client-side previews. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5071 | previews_state |= previews::DetermineAllowedClientPreviewsState( |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5072 | previews_data, previews_triggering_logic_already_ran, |
Owen Min | 08a7289 | 2019-07-31 20:03:35 | [diff] [blame] | 5073 | data_reduction_proxy_settings->IsDataReductionProxyEnabled(), |
| 5074 | previews_decider_impl, navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5075 | |
| 5076 | if (previews_state & content::PREVIEWS_OFF) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5077 | previews_data->set_allowed_previews_state(content::PREVIEWS_OFF); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5078 | return content::PREVIEWS_OFF; |
| 5079 | } |
| 5080 | |
| 5081 | if (previews_state & content::PREVIEWS_NO_TRANSFORM) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5082 | previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5083 | return content::PREVIEWS_NO_TRANSFORM; |
| 5084 | } |
| 5085 | |
| 5086 | // At this point, if no Preview is allowed, don't allow previews. |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5087 | if (previews_state == content::PREVIEWS_UNSPECIFIED) { |
| 5088 | previews_data->set_allowed_previews_state(content::PREVIEWS_OFF); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5089 | return content::PREVIEWS_OFF; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5090 | } |
| 5091 | |
| 5092 | content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED; |
| 5093 | if (delegate) { |
| 5094 | delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state); |
| 5095 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5096 | |
| 5097 | // If the allowed previews are limited by the embedder, ensure previews honors |
| 5098 | // those limits. |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5099 | if (embedder_state != content::PREVIEWS_UNSPECIFIED) { |
| 5100 | previews_state = previews_state & embedder_state; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5101 | // If no valid previews are left, set the state explicitly to PREVIEWS_OFF. |
| 5102 | if (previews_state == content::PREVIEWS_UNSPECIFIED) |
| 5103 | previews_state = content::PREVIEWS_OFF; |
| 5104 | } |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5105 | previews_data->set_allowed_previews_state(previews_state); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5106 | return previews_state; |
| 5107 | } |
| 5108 | |
| 5109 | // static |
| 5110 | content::PreviewsState |
| 5111 | ChromeContentBrowserClient::DetermineCommittedPreviewsForURL( |
| 5112 | const GURL& url, |
| 5113 | data_reduction_proxy::DataReductionProxyData* drp_data, |
| 5114 | previews::PreviewsUserData* previews_user_data, |
| 5115 | const previews::PreviewsDecider* previews_decider, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5116 | content::PreviewsState initial_state, |
| 5117 | content::NavigationHandle* navigation_handle) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5118 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 5119 | if (!previews::HasEnabledPreviews(initial_state)) |
| 5120 | return content::PREVIEWS_OFF; |
| 5121 | |
| 5122 | // Check if the server sent a preview directive. |
| 5123 | content::PreviewsState previews_state = |
Clark DuVall | 0ec5214 | 2019-06-06 19:53:55 | [diff] [blame] | 5124 | previews::DetermineCommittedServerPreviewsState(drp_data, initial_state); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5125 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5126 | // Check the various other client previews types. |
| 5127 | return previews::DetermineCommittedClientPreviewsState( |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5128 | previews_user_data, url, previews_state, previews_decider, |
| 5129 | navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5130 | } |
| 5131 | |
| 5132 | content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews( |
| 5133 | content::PreviewsState initial_state, |
| 5134 | content::NavigationHandle* navigation_handle, |
| 5135 | const net::HttpResponseHeaders* response_headers) { |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5136 | content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback( |
| 5137 | initial_state, navigation_handle, response_headers); |
| 5138 | |
| 5139 | return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle); |
| 5140 | } |
| 5141 | |
| 5142 | content::PreviewsState |
| 5143 | ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback( |
| 5144 | content::PreviewsState initial_state, |
| 5145 | content::NavigationHandle* navigation_handle, |
| 5146 | const net::HttpResponseHeaders* response_headers) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5147 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 5148 | // Only support HTTP and HTTPS. |
| 5149 | if (navigation_handle->IsErrorPage() || |
| 5150 | !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) { |
| 5151 | return content::PREVIEWS_OFF; |
| 5152 | } |
| 5153 | |
| 5154 | // If this is not a main frame, return the initial state. If there are no |
| 5155 | // previews in the state, return the state as is. |
| 5156 | if (!previews::HasEnabledPreviews(initial_state) || |
| 5157 | !navigation_handle->IsInMainFrame() || |
| 5158 | navigation_handle->IsSameDocument()) { |
| 5159 | return initial_state; |
| 5160 | } |
| 5161 | |
| 5162 | // WebContents that don't have a PreviewsUITabHelper are not supported. |
| 5163 | PreviewsUITabHelper* ui_tab_helper = |
| 5164 | PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents()); |
| 5165 | if (!ui_tab_helper) |
| 5166 | return content::PREVIEWS_OFF; |
| 5167 | |
| 5168 | // If we did not previously create a PreviewsUserData, do not go any further. |
| 5169 | previews::PreviewsUserData* previews_user_data = |
| 5170 | ui_tab_helper->GetPreviewsUserData(navigation_handle); |
| 5171 | if (!previews_user_data) |
| 5172 | return content::PREVIEWS_OFF; |
| 5173 | |
| 5174 | PreviewsService* previews_service = |
| 5175 | PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext( |
| 5176 | navigation_handle->GetWebContents()->GetBrowserContext())); |
| 5177 | |
| 5178 | if (!previews_service || !previews_service->previews_ui_service()) |
| 5179 | return content::PREVIEWS_OFF; |
| 5180 | |
| 5181 | // Check if offline previews are being used and set it in the user data. |
| 5182 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 5183 | offline_pages::OfflinePageTabHelper* tab_helper = |
| 5184 | offline_pages::OfflinePageTabHelper::FromWebContents( |
| 5185 | navigation_handle->GetWebContents()); |
| 5186 | |
Ryan Sturm | fc7d92f | 2019-02-12 02:24:23 | [diff] [blame] | 5187 | bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage(); |
| 5188 | bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem(); |
| 5189 | |
| 5190 | // If this is an offline page, but not a preview, then we should not attempt |
| 5191 | // any previews or surface the previews UI. |
| 5192 | if (is_offline_page && !is_offline_preview) |
| 5193 | return content::PREVIEWS_OFF; |
| 5194 | |
| 5195 | previews_user_data->set_offline_preview_used(is_offline_preview); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5196 | #endif // BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 5197 | |
| 5198 | // Annotate request if no-transform directive found in response headers. |
| 5199 | if (response_headers && |
| 5200 | response_headers->HasHeaderValue("cache-control", "no-transform")) { |
Jered Gray | ba1da12 | 2018-10-31 23:06:26 | [diff] [blame] | 5201 | previews_user_data->set_cache_control_no_transform_directive(); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | previews::PreviewsDeciderImpl* previews_decider_impl = |
| 5205 | previews_service->previews_ui_service()->previews_decider_impl(); |
| 5206 | DCHECK(previews_decider_impl); |
| 5207 | |
Clark DuVall | 9c5a72cc | 2018-10-25 01:29:21 | [diff] [blame] | 5208 | std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data; |
| 5209 | auto* settings = |
| 5210 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 5211 | navigation_handle->GetWebContents()->GetBrowserContext()); |
| 5212 | if (settings) { |
| 5213 | // TODO(898326): |drp_data| may be incomplete because |navigation_handle| |
| 5214 | // does not yet have all the response information. |
| 5215 | drp_data = settings->CreateDataFromNavigationHandle(navigation_handle, |
| 5216 | response_headers); |
| 5217 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5218 | |
| 5219 | // Determine effective PreviewsState for this committed main frame response. |
| 5220 | content::PreviewsState committed_state = DetermineCommittedPreviewsForURL( |
Clark DuVall | 9c5a72cc | 2018-10-25 01:29:21 | [diff] [blame] | 5221 | navigation_handle->GetURL(), drp_data.get(), previews_user_data, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5222 | previews_decider_impl, initial_state, navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5223 | |
| 5224 | // Double check that we never serve a preview when we have a |
| 5225 | // cache-control:no-transform directive. |
| 5226 | DCHECK(!previews_user_data->cache_control_no_transform_directive() || |
| 5227 | !previews::HasEnabledPreviews(committed_state)); |
| 5228 | |
Robert Ogden | ded292c6f | 2019-05-03 22:44:51 | [diff] [blame] | 5229 | // TODO(robertogden): Consider moving this to after the holdback logic. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5230 | previews_user_data->set_committed_previews_state(committed_state); |
| 5231 | |
| 5232 | previews::PreviewsType committed_type = |
| 5233 | previews::GetMainFramePreviewsType(committed_state); |
| 5234 | |
| 5235 | // Capture committed previews type, if any, in PreviewsUserData. |
| 5236 | // Note: this is for the subset of previews types that are decided upon |
| 5237 | // navigation commit. Previews types that are determined prior to |
| 5238 | // navigation (such as for offline pages or for redirecting to another |
| 5239 | // url), are not set here. |
| 5240 | previews_user_data->SetCommittedPreviewsType(committed_type); |
| 5241 | |
| 5242 | // Log the commit decision. |
| 5243 | std::vector<previews::PreviewsEligibilityReason> passed_reasons; |
| 5244 | previews_decider_impl->LogPreviewDecisionMade( |
| 5245 | (previews_user_data->cache_control_no_transform_directive() |
| 5246 | ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM |
| 5247 | : previews::PreviewsEligibilityReason::COMMITTED), |
| 5248 | navigation_handle->GetURL(), base::Time::Now(), |
Robert Ogden | 869986f | 2019-06-20 19:12:05 | [diff] [blame] | 5249 | previews_user_data->CommittedPreviewsType(), std::move(passed_reasons), |
Robert Ogden | 33e3631 | 2019-05-06 19:17:05 | [diff] [blame] | 5250 | previews_user_data); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5251 | |
| 5252 | return committed_state; |
| 5253 | } |
Charlie Harrison | 650e1142 | 2018-12-04 00:37:26 | [diff] [blame] | 5254 | |
| 5255 | void ChromeContentBrowserClient::LogWebFeatureForCurrentPage( |
| 5256 | content::RenderFrameHost* render_frame_host, |
| 5257 | blink::mojom::WebFeature feature) { |
| 5258 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 5259 | page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {}); |
| 5260 | page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage( |
| 5261 | render_frame_host, new_features); |
Lily Chen | c2c9e9f | 2019-12-05 19:55:31 | [diff] [blame] | 5262 | |
| 5263 | // For the SameSite-by-default-cookies related features, log |
| 5264 | // the site engagement score for the site whose cookie was blocked. This is to |
| 5265 | // gauge the user impact of the cookies being blocked. |
| 5266 | MaybeRecordSameSiteCookieEngagementHistogram(render_frame_host, feature); |
Charlie Harrison | 650e1142 | 2018-12-04 00:37:26 | [diff] [blame] | 5267 | } |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5268 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5269 | std::string ChromeContentBrowserClient::GetProduct() { |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5270 | return ::GetProduct(); |
| 5271 | } |
| 5272 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5273 | std::string ChromeContentBrowserClient::GetUserAgent() { |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5274 | return ::GetUserAgent(); |
| 5275 | } |
Sam McNally | d54e23f9 | 2019-01-16 04:42:39 | [diff] [blame] | 5276 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5277 | blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() { |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 5278 | return ::GetUserAgentMetadata(); |
| 5279 | } |
| 5280 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5281 | base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() { |
Austin Orion | e250d01 | 2019-05-29 02:56:27 | [diff] [blame] | 5282 | // This icon is available on Android, but adds 19KiB to the APK. Since it |
| 5283 | // isn't used on Android we exclude it to avoid bloat. |
| 5284 | #if !defined(OS_ANDROID) |
| 5285 | return base::Optional<gfx::ImageSkia>( |
| 5286 | *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 5287 | IDR_PRODUCT_LOGO_256)); |
| 5288 | #else |
| 5289 | return base::nullopt; |
| 5290 | #endif |
| 5291 | } |
| 5292 | |
Sam McNally | d54e23f9 | 2019-01-16 04:42:39 | [diff] [blame] | 5293 | bool ChromeContentBrowserClient::IsBuiltinComponent( |
| 5294 | content::BrowserContext* browser_context, |
| 5295 | const url::Origin& origin) { |
| 5296 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5297 | return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent( |
| 5298 | browser_context, origin); |
| 5299 | #else |
| 5300 | return false; |
| 5301 | #endif |
| 5302 | } |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 5303 | |
| 5304 | bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted( |
| 5305 | const GURL& url, |
| 5306 | content::BrowserContext* context) { |
| 5307 | PolicyBlacklistService* service = |
| 5308 | PolicyBlacklistFactory::GetForBrowserContext(context); |
| 5309 | |
| 5310 | using URLBlacklistState = policy::URLBlacklist::URLBlacklistState; |
| 5311 | URLBlacklistState blacklist_state = service->GetURLBlacklistState(url); |
| 5312 | return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST; |
| 5313 | } |
Dominic Mazzoni | 21fb028 | 2019-02-13 18:32:47 | [diff] [blame] | 5314 | |
| 5315 | ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext( |
| 5316 | content::BrowserContext* browser_context) { |
| 5317 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 5318 | return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode(); |
| 5319 | } |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5320 | |
| 5321 | #if defined(OS_ANDROID) |
| 5322 | content::ContentBrowserClient::WideColorGamutHeuristic |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5323 | ChromeContentBrowserClient::GetWideColorGamutHeuristic() { |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5324 | if (features::UseDisplayWideColorGamut()) { |
| 5325 | return WideColorGamutHeuristic::kUseDisplay; |
| 5326 | } |
Khushal | 1fc0da5 | 2019-10-09 00:38:56 | [diff] [blame] | 5327 | |
| 5328 | if (display::Display::HasForceDisplayColorProfile() && |
| 5329 | display::Display::GetForcedDisplayColorProfile() == |
| 5330 | gfx::ColorSpace::CreateDisplayP3D65()) { |
| 5331 | return WideColorGamutHeuristic::kUseDisplay; |
| 5332 | } |
| 5333 | |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5334 | return WideColorGamutHeuristic::kNone; |
| 5335 | } |
| 5336 | #endif |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5337 | |
| 5338 | base::flat_set<std::string> |
Ehsan Karamad | 466529d | 2019-05-24 03:24:43 | [diff] [blame] | 5339 | ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers( |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 5340 | content::BrowserContext* browser_context) { |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5341 | base::flat_set<std::string> mime_types; |
| 5342 | #if BUILDFLAG(ENABLE_PLUGINS) |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 5343 | auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context); |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5344 | for (const auto& pair : map) |
| 5345 | mime_types.insert(pair.first); |
| 5346 | #endif |
| 5347 | return mime_types; |
| 5348 | } |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5349 | |
| 5350 | void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy( |
| 5351 | const content::WebContents* web_contents, |
| 5352 | const content::RenderFrameHost* frame_host, |
| 5353 | bool user_gesture, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5354 | content::NavigationDownloadPolicy* download_policy) { |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5355 | const ChromeSubresourceFilterClient* client = |
| 5356 | ChromeSubresourceFilterClient::FromWebContents(web_contents); |
| 5357 | if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) { |
Yao Xiao | f6064666 | 2019-07-25 07:25:04 | [diff] [blame] | 5358 | download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame); |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5359 | if (!user_gesture) { |
| 5360 | if (base::FeatureList::IsEnabled( |
| 5361 | blink::features:: |
| 5362 | kBlockingDownloadsInAdFrameWithoutUserActivation)) { |
| 5363 | download_policy->SetDisallowed( |
| 5364 | content::NavigationDownloadType::kAdFrameNoGesture); |
| 5365 | } else { |
| 5366 | download_policy->SetAllowed( |
| 5367 | content::NavigationDownloadType::kAdFrameNoGesture); |
| 5368 | } |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5369 | } |
| 5370 | } |
| 5371 | } |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5372 | |
| 5373 | bool ChromeContentBrowserClient::IsBluetoothScanningBlocked( |
| 5374 | content::BrowserContext* browser_context, |
| 5375 | const url::Origin& requesting_origin, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5376 | const url::Origin& embedding_origin) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5377 | const HostContentSettingsMap* const content_settings = |
| 5378 | HostContentSettingsMapFactory::GetForProfile( |
| 5379 | Profile::FromBrowserContext(browser_context)); |
| 5380 | |
| 5381 | if (content_settings->GetContentSetting( |
| 5382 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 5383 | ContentSettingsType::BLUETOOTH_SCANNING, |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5384 | std::string()) == CONTENT_SETTING_BLOCK) { |
| 5385 | return true; |
| 5386 | } |
| 5387 | |
| 5388 | return false; |
| 5389 | } |
| 5390 | |
| 5391 | void ChromeContentBrowserClient::BlockBluetoothScanning( |
| 5392 | content::BrowserContext* browser_context, |
| 5393 | const url::Origin& requesting_origin, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5394 | const url::Origin& embedding_origin) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5395 | HostContentSettingsMap* const content_settings = |
| 5396 | HostContentSettingsMapFactory::GetForProfile( |
| 5397 | Profile::FromBrowserContext(browser_context)); |
| 5398 | |
| 5399 | content_settings->SetContentSettingDefaultScope( |
| 5400 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
Darin Fisher | 42f5e7d | 2019-10-30 07:15:45 | [diff] [blame] | 5401 | ContentSettingsType::BLUETOOTH_SCANNING, std::string(), |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5402 | CONTENT_SETTING_BLOCK); |
| 5403 | } |
Tibor Goldschwendt | bf1b96e | 2019-10-07 22:03:47 | [diff] [blame] | 5404 | |
| 5405 | bool ChromeContentBrowserClient::ShouldLoadExtraIcuDataFile() { |
| 5406 | #if defined(OS_ANDROID) |
| 5407 | return extra_icu::ModuleProvider::IsModuleInstalled(); |
| 5408 | #endif |
| 5409 | return false; |
| 5410 | } |
Guido Urdaneta | 4030d6a3 | 2019-10-17 09:38:16 | [diff] [blame] | 5411 | |
| 5412 | bool ChromeContentBrowserClient::ArePersistentMediaDeviceIDsAllowed( |
| 5413 | content::BrowserContext* browser_context, |
| 5414 | const GURL& url, |
| 5415 | const GURL& site_for_cookies, |
| 5416 | const base::Optional<url::Origin>& top_frame_origin) { |
| 5417 | // Persistent MediaDevice IDs are allowed if cookies are allowed. |
| 5418 | return CookieSettingsFactory::GetForProfile( |
| 5419 | Profile::FromBrowserContext(browser_context)) |
| 5420 | ->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin); |
| 5421 | } |
Sam Goto | 5cf068e8 | 2019-11-04 23:08:44 | [diff] [blame] | 5422 | |
| 5423 | #if !defined(OS_ANDROID) |
| 5424 | void ChromeContentBrowserClient::FetchRemoteSms( |
| 5425 | content::BrowserContext* browser_context, |
| 5426 | const url::Origin& origin, |
| 5427 | base::OnceCallback<void(base::Optional<std::string>)> callback) { |
| 5428 | ::FetchRemoteSms(browser_context, origin, std::move(callback)); |
| 5429 | } |
| 5430 | #endif |