[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" |
morrita | d95714f | 2014-10-01 02:37:24 | [diff] [blame] | 16 | #include "base/files/scoped_file.h" |
Marc Treib | ad33cf94 | 2017-08-24 11:19:00 | [diff] [blame] | 17 | #include "base/i18n/base_i18n_switches.h" |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 18 | #include "base/i18n/character_encoding.h" |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 19 | #include "base/macros.h" |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 20 | #include "base/metrics/field_trial_params.h" |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 21 | #include "base/metrics/histogram_macros.h" |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 22 | #include "base/no_destructor.h" |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 23 | #include "base/path_service.h" |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 24 | #include "base/stl_util.h" |
[email protected] | e746341 | 2013-06-10 22:53:46 | [diff] [blame] | 25 | #include "base/strings/string_number_conversions.h" |
markdittmer | 67b71ea | 2016-03-03 22:40:03 | [diff] [blame] | 26 | #include "base/strings/string_split.h" |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 27 | #include "base/strings/string_util.h" |
| 28 | #include "base/strings/stringprintf.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 29 | #include "base/strings/utf_string_conversions.h" |
Sebastien Marchand | 75a7cdf | 2018-11-13 23:47:03 | [diff] [blame] | 30 | #include "base/system/sys_info.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 31 | #include "base/task/post_task.h" |
Wojciech Dzierżanowski | 4538080 | 2019-04-29 14:50:32 | [diff] [blame] | 32 | #include "base/threading/sequenced_task_runner_handle.h" |
gab | b15e1907 | 2016-05-11 20:45:41 | [diff] [blame] | 33 | #include "base/threading/thread_task_runner_handle.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 34 | #include "build/build_config.h" |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 35 | #include "chrome/app/builtin_service_manifests.h" |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 36 | #include "chrome/app/chrome_content_browser_overlay_manifest.h" |
| 37 | #include "chrome/app/chrome_content_gpu_overlay_manifest.h" |
| 38 | #include "chrome/app/chrome_content_renderer_overlay_manifest.h" |
| 39 | #include "chrome/app/chrome_content_utility_overlay_manifest.h" |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 40 | #include "chrome/app/chrome_renderer_manifest.h" |
Dominic Mazzoni | 21fb028 | 2019-02-13 18:32:47 | [diff] [blame] | 41 | #include "chrome/browser/accessibility/accessibility_labels_service.h" |
| 42 | #include "chrome/browser/accessibility/accessibility_labels_service_factory.h" |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 43 | #include "chrome/browser/after_startup_task_utils.h" |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 44 | #include "chrome/browser/browser_about_handler.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 45 | #include "chrome/browser/browser_process.h" |
[email protected] | b0cb5e8 | 2012-07-19 19:22:47 | [diff] [blame] | 46 | #include "chrome/browser/browsing_data/browsing_data_helper.h" |
msramek | 1c2b3ca | 2017-03-14 17:57:56 | [diff] [blame] | 47 | #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
nigeltao | beff0a10 | 2017-04-29 09:30:37 | [diff] [blame] | 48 | #include "chrome/browser/cache_stats_recorder.h" |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 49 | #include "chrome/browser/chrome_content_browser_client_parts.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 50 | #include "chrome/browser/chrome_quota_permission_context.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 51 | #include "chrome/browser/content_settings/cookie_settings_factory.h" |
peconn | 5100d43 | 2015-09-16 12:03:08 | [diff] [blame] | 52 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 53 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
Robbie McElrath | 1294d24 | 2019-05-31 20:46:22 | [diff] [blame] | 54 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 55 | #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
Zhuoyu Qian | cb197638 | 2018-12-13 02:18:30 | [diff] [blame] | 56 | #include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h" |
| 57 | #include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h" |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 58 | #include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h" |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 59 | #include "chrome/browser/defaults.h" |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 60 | #include "chrome/browser/download/download_prefs.h" |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 61 | #include "chrome/browser/extensions/chrome_extension_cookies.h" |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 62 | #include "chrome/browser/external_protocol/external_protocol_handler.h" |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 63 | #include "chrome/browser/font_family_cache.h" |
Matt Reynolds | 93616f9b | 2019-06-07 01:28:52 | [diff] [blame] | 64 | #include "chrome/browser/hid/chrome_hid_delegate.h" |
Anthony Vallee-Dubois | e2432137a | 2019-01-17 20:06:01 | [diff] [blame] | 65 | #include "chrome/browser/language/translate_frame_binder.h" |
Avi Drissman | d3092734 | 2018-05-22 15:04:27 | [diff] [blame] | 66 | #include "chrome/browser/lifetime/browser_shutdown.h" |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 67 | #include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h" |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 68 | #include "chrome/browser/media/router/media_router_feature.h" |
Derek Cheng | eb64b19a | 2018-01-02 20:20:42 | [diff] [blame] | 69 | #include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h" |
| 70 | #include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h" |
Patrik Höglund | b564859b | 2018-05-17 11:17:16 | [diff] [blame] | 71 | #include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h" |
mcasas | a2023ab | 2016-09-08 01:06:36 | [diff] [blame] | 72 | #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
Patrik Höglund | b564859b | 2018-05-17 11:17:16 | [diff] [blame] | 73 | #include "chrome/browser/media/webrtc/webrtc_logging_handler_host.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" |
Lu Chen | 5bec7a30 | 2018-06-26 18:52:32 | [diff] [blame] | 77 | #include "chrome/browser/navigation_predictor/navigation_predictor.h" |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 78 | #include "chrome/browser/net/chrome_network_delegate.h" |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 79 | #include "chrome/browser/net/system_network_context_manager.h" |
dvallet | 233f57ab | 2016-12-21 03:17:10 | [diff] [blame] | 80 | #include "chrome/browser/net_benchmarking.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" |
csharrison | 4bd8a19 | 2016-08-02 18:03:15 | [diff] [blame] | 83 | #include "chrome/browser/page_load_metrics/metrics_navigation_throttle.h" |
Charlie Harrison | 650e1142 | 2018-12-04 00:37:26 | [diff] [blame] | 84 | #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 85 | #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
leon.han | 952ea325 | 2016-04-13 02:44:56 | [diff] [blame] | 86 | #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 87 | #include "chrome/browser/payments/payment_request_display_manager_factory.h" |
Sigurdur Asgeirsson | 54b7270 | 2019-04-12 14:18:54 | [diff] [blame] | 88 | #include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h" |
Sigurdur Asgeirsson | 7069667 | 2019-02-08 16:14:51 | [diff] [blame] | 89 | #include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h" |
Adam Langley | 85339f6 | 2018-02-12 22:03:56 | [diff] [blame] | 90 | #include "chrome/browser/permissions/attestation_permission_request.h" |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 91 | #include "chrome/browser/permissions/permission_context_base.h" |
Adam Langley | 85339f6 | 2018-02-12 22:03:56 | [diff] [blame] | 92 | #include "chrome/browser/permissions/permission_request_manager.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 93 | #include "chrome/browser/platform_util.h" |
Amber Won | 94afd811 | 2017-08-23 17:30:11 | [diff] [blame] | 94 | #include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h" |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 95 | #include "chrome/browser/plugins/plugin_utils.h" |
Alexandr Ilin | 4909ec8 | 2018-06-06 10:22:48 | [diff] [blame] | 96 | #include "chrome/browser/predictors/loading_predictor.h" |
| 97 | #include "chrome/browser/predictors/loading_predictor_factory.h" |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 98 | #include "chrome/browser/prerender/prerender_final_status.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 99 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 100 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | 2736c03 | 2012-05-11 18:06:07 | [diff] [blame] | 101 | #include "chrome/browser/prerender/prerender_message_filter.h" |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 102 | #include "chrome/browser/prerender/prerender_util.h" |
Ryan Sturm | cc5071be | 2019-02-16 02:15:19 | [diff] [blame] | 103 | #include "chrome/browser/previews/previews_content_util.h" |
Robert Ogden | afd250b | 2018-07-25 22:21:03 | [diff] [blame] | 104 | #include "chrome/browser/previews/previews_lite_page_decider.h" |
Robert Ogden | e7fdca9 | 2018-10-12 17:53:06 | [diff] [blame] | 105 | #include "chrome/browser/previews/previews_lite_page_navigation_throttle.h" |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 106 | #include "chrome/browser/previews/previews_lite_page_url_loader_interceptor.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 107 | #include "chrome/browser/previews/previews_service.h" |
| 108 | #include "chrome/browser/previews/previews_service_factory.h" |
| 109 | #include "chrome/browser/previews/previews_ui_tab_helper.h" |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 110 | #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 111 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 112 | #include "chrome/browser/profiles/profile_io_data.h" |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 113 | #include "chrome/browser/profiles/renderer_updater.h" |
| 114 | #include "chrome/browser/profiles/renderer_updater_factory.h" |
Erik Chen | 49bbfa2 | 2017-08-18 08:49:56 | [diff] [blame] | 115 | #include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h" |
| 116 | #include "chrome/browser/profiling_host/profiling_process_host.h" |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 117 | #include "chrome/browser/renderer_host/chrome_navigation_ui_data.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 118 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 119 | #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 120 | #include "chrome/browser/renderer_preferences_util.h" |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 121 | #include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h" |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 122 | #include "chrome/browser/safe_browsing/certificate_reporting_service.h" |
| 123 | #include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h" |
Carlos IL | 4ee307e | 2018-12-22 03:19:00 | [diff] [blame] | 124 | #include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h" |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 125 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 126 | #include "chrome/browser/safe_browsing/ui_manager.h" |
| 127 | #include "chrome/browser/safe_browsing/url_checker_delegate_impl.h" |
[email protected] | a7b8e43d | 2013-03-18 18:52:43 | [diff] [blame] | 128 | #include "chrome/browser/search/search.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 129 | #include "chrome/browser/sessions/session_tab_helper.h" |
Reilly Grant | cc22e60 | 2018-09-07 15:25:20 | [diff] [blame] | 130 | #include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h" |
Reilly Grant | 3787780 | 2018-08-18 00:58:35 | [diff] [blame] | 131 | #include "chrome/browser/signin/chrome_signin_url_loader_throttle.h" |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 132 | #include "chrome/browser/signin/header_modification_delegate_on_io_thread_impl.h" |
| 133 | #include "chrome/browser/signin/header_modification_delegate_on_ui_thread_impl.h" |
Lukasz Anforowicz | fd30af3 | 2019-03-28 17:33:28 | [diff] [blame] | 134 | #include "chrome/browser/site_isolation/site_isolation_policy.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 135 | #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 136 | #include "chrome/browser/speech/tts_controller_delegate_impl.h" |
[email protected] | 7a06d28 | 2013-05-03 04:39:33 | [diff] [blame] | 137 | #include "chrome/browser/speech/tts_message_filter.h" |
Eric Lawrence | d0acf2a7c | 2017-07-20 18:02:48 | [diff] [blame] | 138 | #include "chrome/browser/ssl/insecure_sensitive_input_driver_factory.h" |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 139 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 140 | #include "chrome/browser/ssl/ssl_cert_reporter.h" |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 141 | #include "chrome/browser/ssl/ssl_client_auth_metrics.h" |
[email protected] | 25af6ec | 2014-06-06 19:35:07 | [diff] [blame] | 142 | #include "chrome/browser/ssl/ssl_client_certificate_selector.h" |
meacer | 4ef065e | 2015-01-09 03:21:35 | [diff] [blame] | 143 | #include "chrome/browser/ssl/ssl_error_handler.h" |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 144 | #include "chrome/browser/ssl/ssl_error_navigation_throttle.h" |
Christopher Thompson | 4137cec | 2017-12-19 05:34:23 | [diff] [blame] | 145 | #include "chrome/browser/ssl/typed_navigation_timing_throttle.h" |
csharrison | 77bf834 | 2017-05-04 18:23:10 | [diff] [blame] | 146 | #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" |
meacer | 4ef065e | 2015-01-09 03:21:35 | [diff] [blame] | 147 | #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 148 | #include "chrome/browser/tab_contents/tab_util.h" |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 149 | #include "chrome/browser/tracing/chrome_tracing_delegate.h" |
Dave Tapuska | c6627e1 | 2018-08-30 15:07:19 | [diff] [blame] | 150 | #include "chrome/browser/translate/translate_service.h" |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 151 | #include "chrome/browser/ui/blocked_content/blocked_window_params.h" |
Charlie Harrison | 804659a | 2018-10-16 16:43:38 | [diff] [blame] | 152 | #include "chrome/browser/ui/blocked_content/popup_blocker.h" |
Charles Harrison | 6dd11d28 | 2017-10-03 06:14:51 | [diff] [blame] | 153 | #include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h" |
thestig | e8082124 | 2015-09-30 23:46:08 | [diff] [blame] | 154 | #include "chrome/browser/ui/browser_navigator.h" |
| 155 | #include "chrome/browser/ui/browser_navigator_params.h" |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 156 | #include "chrome/browser/ui/chrome_select_file_policy.h" |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 157 | #include "chrome/browser/ui/login/login_handler.h" |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 158 | #include "chrome/browser/ui/prefs/pref_watcher.h" |
[email protected] | 329ac97 | 2013-06-21 15:24:25 | [diff] [blame] | 159 | #include "chrome/browser/ui/sync/sync_promo_ui.h" |
[email protected] | b5d7342 | 2012-06-02 23:46:44 | [diff] [blame] | 160 | #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h" |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 161 | #include "chrome/browser/ui/ui_features.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 162 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
dbeam | baee5bd | 2015-09-26 03:07:01 | [diff] [blame] | 163 | #include "chrome/browser/ui/webui/log_web_ui_url.h" |
reillyg | 3ff4532 | 2015-10-23 21:16:25 | [diff] [blame] | 164 | #include "chrome/browser/usb/usb_tab_helper.h" |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 165 | #include "chrome/browser/vr/vr_tab_helper.h" |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 166 | #include "chrome/browser/web_applications/components/app_registrar.h" |
| 167 | #include "chrome/browser/web_applications/web_app_provider.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 168 | #include "chrome/common/buildflags.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 169 | #include "chrome/common/channel_info.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 170 | #include "chrome/common/chrome_constants.h" |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 171 | #include "chrome/common/chrome_features.h" |
[email protected] | a7944aa | 2012-10-15 10:12:14 | [diff] [blame] | 172 | #include "chrome/common/chrome_paths.h" |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 173 | #include "chrome/common/chrome_paths_internal.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 174 | #include "chrome/common/chrome_switches.h" |
Ben Goodger | e25ef85 | 2017-08-11 00:17:50 | [diff] [blame] | 175 | #include "chrome/common/constants.mojom.h" |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 176 | #include "chrome/common/env_vars.h" |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 177 | #include "chrome/common/google_url_loader_throttle.h" |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 178 | #include "chrome/common/logging_chrome.h" |
[email protected] | 9d45049 | 2013-06-13 23:08:37 | [diff] [blame] | 179 | #include "chrome/common/pepper_permission_util.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 180 | #include "chrome/common/pref_names.h" |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 181 | #include "chrome/common/prerender_url_loader_throttle.h" |
Egor Pasko | d52474c3 | 2018-06-19 12:03:22 | [diff] [blame] | 182 | #include "chrome/common/prerender_util.h" |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 183 | #include "chrome/common/render_messages.h" |
nigeltao | 7cd8d558 | 2016-12-12 06:05:28 | [diff] [blame] | 184 | #include "chrome/common/renderer_configuration.mojom.h" |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 185 | #include "chrome/common/secure_origin_whitelist.h" |
wittman | 832321f5 | 2016-10-10 18:18:38 | [diff] [blame] | 186 | #include "chrome/common/stack_sampling_configuration.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 187 | #include "chrome/common/url_constants.h" |
ben | c70c0e3 | 2016-09-22 03:50:37 | [diff] [blame] | 188 | #include "chrome/grit/browser_resources.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 189 | #include "chrome/grit/generated_resources.h" |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 190 | #include "chrome/installer/util/google_update_settings.h" |
leon.han | 04b276e | 2016-06-01 01:34:16 | [diff] [blame] | 191 | #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
brettw | f195891 | 2015-10-07 19:43:12 | [diff] [blame] | 192 | #include "components/autofill/core/common/autofill_switches.h" |
msramek | 1c8e19d | 2017-01-04 20:04:53 | [diff] [blame] | 193 | #include "components/browsing_data/core/browsing_data_utils.h" |
[email protected] | 649b5727 | 2014-05-09 14:54:44 | [diff] [blame] | 194 | #include "components/cdm/browser/cdm_message_filter_android.h" |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 195 | #include "components/certificate_matching/certificate_principal_pattern.h" |
[email protected] | 09cff7878 | 2014-04-20 22:04:48 | [diff] [blame] | 196 | #include "components/cloud_devices/common/cloud_devices_switches.h" |
Tao Bai | 02ab4dd4 | 2019-03-06 00:30:37 | [diff] [blame] | 197 | #include "components/content_capture/browser/content_capture_receiver_manager.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 198 | #include "components/content_settings/core/browser/content_settings_utils.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 199 | #include "components/content_settings/core/browser/cookie_settings.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 200 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 201 | #include "components/content_settings/core/common/content_settings.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 202 | #include "components/content_settings/core/common/content_settings_types.h" |
tbansal | 08a0e3e | 2017-06-30 21:30:08 | [diff] [blame] | 203 | #include "components/content_settings/core/common/content_settings_utils.h" |
Daniel Vogelheim | 976f1c2 | 2017-11-22 16:26:03 | [diff] [blame] | 204 | #include "components/content_settings/core/common/pref_names.h" |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 205 | #include "components/data_reduction_proxy/content/common/data_reduction_proxy_url_loader_throttle.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 206 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h" |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 207 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_data.h" |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 208 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h" |
rajendrant | 4319407 | 2019-04-15 22:13:43 | [diff] [blame] | 209 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h" |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 210 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
Wojciech Dzierżanowski | 4538080 | 2019-04-29 14:50:32 | [diff] [blame] | 211 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_throttle_manager.h" |
wychen | e5568734 | 2015-11-13 20:17:03 | [diff] [blame] | 212 | #include "components/dom_distiller/core/dom_distiller_switches.h" |
[email protected] | 474a5a3 | 2014-07-28 18:23:24 | [diff] [blame] | 213 | #include "components/dom_distiller/core/url_constants.h" |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 214 | #include "components/error_page/common/error_page_switches.h" |
khushalsagar | c5447db2 | 2017-08-22 17:53:01 | [diff] [blame] | 215 | #include "components/feature_engagement/public/feature_constants.h" |
| 216 | #include "components/feature_engagement/public/feature_list.h" |
John Abd-El-Malek | 9cf3d7f0 | 2018-07-27 02:40:39 | [diff] [blame] | 217 | #include "components/google/core/common/google_util.h" |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 218 | #include "components/language/core/browser/pref_names.h" |
wittman | e16da278 | 2016-09-21 16:43:04 | [diff] [blame] | 219 | #include "components/metrics/call_stack_profile_collector.h" |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 220 | #include "components/metrics/client_info.h" |
Xiangjun Zhang | 4547484 | 2018-08-17 21:07:59 | [diff] [blame] | 221 | #include "components/mirroring/mojom/constants.mojom.h" |
| 222 | #include "components/mirroring/service/features.h" |
Scott Violet | 9ae8289 | 2018-03-01 18:38:12 | [diff] [blame] | 223 | #include "components/nacl/common/buildflags.h" |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 224 | #include "components/nacl/common/nacl_constants.h" |
droger | c690e880 | 2015-09-21 14:29:16 | [diff] [blame] | 225 | #include "components/net_log/chrome_net_log.h" |
leon.han | 97e8f75 | 2016-09-06 06:13:20 | [diff] [blame] | 226 | #include "components/password_manager/content/browser/content_password_manager_driver_factory.h" |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 227 | #include "components/payments/content/payment_request_display_manager.h" |
Doug Turner | 9dcaf596 | 2017-12-21 04:38:53 | [diff] [blame] | 228 | #include "components/policy/content/policy_blacklist_navigation_throttle.h" |
Michael Giuffrida | 01d7b5d | 2018-08-21 07:55:54 | [diff] [blame] | 229 | #include "components/policy/content/policy_blacklist_service.h" |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 230 | #include "components/policy/core/common/policy_service.h" |
| 231 | #include "components/policy/policy_constants.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 232 | #include "components/pref_registry/pref_registry_syncable.h" |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 233 | #include "components/prefs/pref_registry_simple.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 234 | #include "components/prefs/pref_service.h" |
| 235 | #include "components/prefs/scoped_user_pref_update.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 236 | #include "components/previews/content/previews_decider_impl.h" |
| 237 | #include "components/previews/content/previews_ui_service.h" |
| 238 | #include "components/previews/content/previews_user_data.h" |
| 239 | #include "components/previews/core/previews_decider.h" |
| 240 | #include "components/previews/core/previews_experiments.h" |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 241 | #include "components/previews/core/previews_features.h" |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 242 | #include "components/previews/core/previews_switches.h" |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 243 | #include "components/rappor/public/rappor_utils.h" |
nigeltao | 2f67376 | 2016-10-14 03:27:28 | [diff] [blame] | 244 | #include "components/rappor/rappor_recorder_impl.h" |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 245 | #include "components/rappor/rappor_service_impl.h" |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 246 | #include "components/safe_browsing/browser/browser_url_loader_throttle.h" |
| 247 | #include "components/safe_browsing/browser/mojo_safe_browsing_impl.h" |
| 248 | #include "components/safe_browsing/browser/url_checker_delegate.h" |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 249 | #include "components/safe_browsing/buildflags.h" |
timvolodine | 89cf1171 | 2017-05-15 18:05:07 | [diff] [blame] | 250 | #include "components/safe_browsing/common/safe_browsing_prefs.h" |
Tim Volodine | e4593847 | 2017-09-21 10:08:22 | [diff] [blame] | 251 | #include "components/safe_browsing/db/database_manager.h" |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 252 | #include "components/safe_browsing/features.h" |
Jialiu Lin | bdbb81d | 2017-10-11 21:29:09 | [diff] [blame] | 253 | #include "components/safe_browsing/password_protection/password_protection_navigation_throttle.h" |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 254 | #include "components/security_interstitials/content/origin_policy_ui.h" |
Alexei Filippov | 65c08b9 | 2019-02-02 03:41:00 | [diff] [blame] | 255 | #include "components/services/heap_profiling/heap_profiling_service.h" |
| 256 | #include "components/services/heap_profiling/public/cpp/settings.h" |
erikchen | 0d4a601 | 2018-04-03 16:06:33 | [diff] [blame] | 257 | #include "components/services/heap_profiling/public/mojom/constants.mojom.h" |
Miyoung Shin | ea48f77 | 2019-07-19 01:20:27 | [diff] [blame] | 258 | #include "components/services/patch/public/mojom/constants.mojom.h" |
Alexander Woolf | ed183c51 | 2019-05-17 01:18:03 | [diff] [blame] | 259 | #include "components/services/quarantine/public/mojom/quarantine.mojom.h" |
| 260 | #include "components/services/quarantine/quarantine_service.h" |
Colin Blundell | 3517170e | 2019-07-11 08:16:34 | [diff] [blame] | 261 | #include "components/signin/public/base/signin_pref_names.h" |
Scott Violet | d7983c5 | 2018-03-03 00:24:41 | [diff] [blame] | 262 | #include "components/spellcheck/spellcheck_buildflags.h" |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 263 | #include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h" |
[email protected] | eba93c9 | 2014-01-07 17:34:17 | [diff] [blame] | 264 | #include "components/translate/core/common/translate_switches.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 265 | #include "components/url_formatter/url_fixer.h" |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 266 | #include "components/variations/variations_associated_data.h" |
Jun Cai | 0e56863 | 2018-08-09 02:05:33 | [diff] [blame] | 267 | #include "components/variations/variations_http_header_provider.h" |
Kyle Milka | b5c048e | 2017-07-07 02:38:46 | [diff] [blame] | 268 | #include "components/variations/variations_switches.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 269 | #include "components/version_info/version_info.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 270 | #include "content/public/browser/browser_child_process_host.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 271 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 272 | #include "content/public/browser/browser_ppapi_host.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 273 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 274 | #include "content/public/browser/browser_thread.h" |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 275 | #include "content/public/browser/browser_url_handler.h" |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 276 | #include "content/public/browser/browsing_data_remover.h" |
Lucas Garron | b9539b73 | 2017-10-31 00:22:09 | [diff] [blame] | 277 | #include "content/public/browser/certificate_request_result_type.h" |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 278 | #include "content/public/browser/child_process_data.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 279 | #include "content/public/browser/child_process_security_policy.h" |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 280 | #include "content/public/browser/client_certificate_delegate.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 281 | #include "content/public/browser/file_url_loader.h" |
Mohsen Izadi | 6a6476b7 | 2018-12-07 04:34:35 | [diff] [blame] | 282 | #include "content/public/browser/gpu_data_manager.h" |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 283 | #include "content/public/browser/navigation_handle.h" |
| 284 | #include "content/public/browser/navigation_throttle.h" |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 285 | #include "content/public/browser/overlay_window.h" |
[email protected] | 094c877 | 2013-12-21 17:54:50 | [diff] [blame] | 286 | #include "content/public/browser/render_frame_host.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 287 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 288 | #include "content/public/browser/render_view_host.h" |
[email protected] | ce96786 | 2012-02-09 22:47:05 | [diff] [blame] | 289 | #include "content/public/browser/resource_context.h" |
jam | 608f299 | 2016-03-31 16:35:34 | [diff] [blame] | 290 | #include "content/public/browser/storage_partition.h" |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 291 | #include "content/public/browser/tts_controller.h" |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 292 | #include "content/public/browser/tts_platform.h" |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 293 | #include "content/public/browser/url_loader_request_interceptor.h" |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 294 | #include "content/public/browser/vpn_service_proxy.h" |
[email protected] | 91ee368 | 2012-01-19 15:02:19 | [diff] [blame] | 295 | #include "content/public/browser/web_contents.h" |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 296 | #include "content/public/browser/web_contents_delegate.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 297 | #include "content/public/browser/web_ui_url_loader_factory.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 298 | #include "content/public/common/child_process_host.h" |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 299 | #include "content/public/common/content_descriptors.h" |
juncai | 1bf9f7c | 2016-03-22 20:46:56 | [diff] [blame] | 300 | #include "content/public/common/content_features.h" |
brettw | 90e9260 | 2015-10-10 00:12:40 | [diff] [blame] | 301 | #include "content/public/common/content_switches.h" |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 302 | #include "content/public/common/network_service_util.h" |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 303 | #include "content/public/common/service_manager_connection.h" |
ben | 51bb6c6 | 2016-11-17 20:15:57 | [diff] [blame] | 304 | #include "content/public/common/service_names.mojom.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 305 | #include "content/public/common/url_constants.h" |
[email protected] | 22aa4f8 | 2013-09-24 17:01:44 | [diff] [blame] | 306 | #include "content/public/common/url_utils.h" |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 307 | #include "content/public/common/user_agent.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 308 | #include "content/public/common/web_preferences.h" |
Takuto Ikuta | aa3b796c | 2019-02-06 02:54:56 | [diff] [blame] | 309 | #include "content/public/common/window_container_type.mojom-shared.h" |
Bill Orr | eb42922 | 2018-08-08 21:14:43 | [diff] [blame] | 310 | #include "device/vr/buildflags/buildflags.h" |
Scott Violet | c8240b0 | 2018-03-08 22:03:59 | [diff] [blame] | 311 | #include "extensions/buildflags/buildflags.h" |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 312 | #include "google_apis/gaia/gaia_urls.h" |
Andrew Moylan | 17329fc | 2017-09-25 07:43:30 | [diff] [blame] | 313 | #include "google_apis/google_api_keys.h" |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 314 | #include "gpu/config/gpu_switches.h" |
grunell | 086a411 | 2017-03-02 09:23:04 | [diff] [blame] | 315 | #include "media/audio/audio_manager.h" |
François Beaufort | 8c08979fc | 2018-03-05 13:06:31 | [diff] [blame] | 316 | #include "media/base/media_switches.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 317 | #include "media/media_buildflags.h" |
| 318 | #include "media/mojo/buildflags.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 319 | #include "mojo/public/cpp/bindings/binding_set.h" |
Shimi Zhang | 6b72d29 | 2019-07-12 20:52:42 | [diff] [blame] | 320 | #include "mojo/public/cpp/bindings/pending_associated_receiver.h" |
Ken Rockot | 40a1df79 | 2019-05-08 22:15:52 | [diff] [blame] | 321 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
| 322 | #include "mojo/public/cpp/bindings/pending_remote.h" |
Ken Rockot | 0adc1e4 | 2019-05-24 08:20:08 | [diff] [blame] | 323 | #include "mojo/public/cpp/bindings/remote.h" |
engedy | afef048 | 2017-07-06 15:40:53 | [diff] [blame] | 324 | #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 325 | #include "net/base/load_flags.h" |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 326 | #include "net/base/mime_util.h" |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 327 | #include "net/http/http_util.h" |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 328 | #include "net/ssl/client_cert_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 329 | #include "net/ssl/ssl_cert_request_info.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 330 | #include "ppapi/buildflags/buildflags.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 331 | #include "ppapi/host/ppapi_host.h" |
Scott Violet | 318a55f | 2018-03-30 19:08:19 | [diff] [blame] | 332 | #include "printing/buildflags/buildflags.h" |
Andrew Moylan | 8ed9d83c8 | 2019-01-29 20:23:52 | [diff] [blame] | 333 | #include "services/image_annotation/public/mojom/constants.mojom.h" |
| 334 | #include "services/image_annotation/public/mojom/image_annotation.mojom.h" |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 335 | #include "services/network/public/cpp/is_potentially_trustworthy.h" |
Lukasz Anforowicz | 9527fd4 | 2019-03-13 19:08:50 | [diff] [blame] | 336 | #include "services/network/public/cpp/network_switches.h" |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 337 | #include "services/network/public/cpp/resource_request.h" |
Sam McNally | e36abbc | 2017-07-20 01:04:28 | [diff] [blame] | 338 | #include "services/preferences/public/cpp/in_process_service_factory.h" |
Ken Rockot | f7f533e | 2018-02-11 02:21:33 | [diff] [blame] | 339 | #include "services/preferences/public/mojom/preferences.mojom.h" |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 340 | #include "services/service_manager/embedder/switches.h" |
erikchen | a9db3a7 | 2018-04-12 16:24:00 | [diff] [blame] | 341 | #include "services/service_manager/public/cpp/connector.h" |
Ken Rockot | 543f5e3 | 2018-02-04 02:13:50 | [diff] [blame] | 342 | #include "services/service_manager/public/mojom/connector.mojom.h" |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 343 | #include "services/service_manager/sandbox/sandbox_type.h" |
Andrew Comminos | 6605767 | 2019-05-01 00:03:34 | [diff] [blame] | 344 | #include "services/service_manager/sandbox/switches.h" |
Ken Rockot | cebdf9c8 | 2019-05-28 20:33:03 | [diff] [blame] | 345 | #include "services/strings/grit/services_strings.h" |
pilgrim | e92c5fcd | 2014-09-10 23:31:23 | [diff] [blame] | 346 | #include "storage/browser/fileapi/external_mount_points.h" |
John Delaney | ac24e57 | 2019-04-30 19:47:02 | [diff] [blame] | 347 | #include "third_party/blink/public/common/features.h" |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 348 | #include "third_party/blink/public/common/loader/url_loader_throttle.h" |
Julie Jeongeun Kim | d3d00a1 | 2019-03-25 01:46:25 | [diff] [blame] | 349 | #include "third_party/blink/public/mojom/installedapp/installed_app_provider.mojom.h" |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 350 | #include "third_party/blink/public/mojom/renderer_preferences.mojom.h" |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 351 | #include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h" |
Eric Willigers | 3eeae17c | 2019-03-13 17:32:10 | [diff] [blame] | 352 | #include "third_party/blink/public/mojom/webshare/webshare.mojom.h" |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 353 | #include "third_party/skia/include/core/SkColor.h" |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 354 | #include "third_party/widevine/cdm/buildflags.h" |
Scott Violet | b72577d | 2019-01-09 22:18:18 | [diff] [blame] | 355 | #include "ui/base/buildflags.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 356 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 357 | #include "ui/base/resource/resource_bundle.h" |
Scott Violet | 8ff9c30 | 2018-02-22 22:28:35 | [diff] [blame] | 358 | #include "ui/base/ui_base_features.h" |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 359 | #include "ui/base/ui_base_switches.h" |
| 360 | #include "ui/gfx/color_utils.h" |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 361 | #include "ui/native_theme/caption_style.h" |
| 362 | #include "ui/native_theme/native_theme.h" |
[email protected] | b47dc49 | 2014-08-17 07:05:57 | [diff] [blame] | 363 | #include "ui/resources/grit/ui_resources.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 364 | #include "url/gurl.h" |
| 365 | #include "url/origin.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 366 | |
Ken Rockot | 69aade0 | 2019-01-23 21:19:51 | [diff] [blame] | 367 | #if BUILDFLAG(ENABLE_NACL) |
| 368 | #include "components/nacl/loader/nacl_loader_manifest.h" |
| 369 | #if defined(OS_WIN) && defined(ARCH_CPU_X86) |
| 370 | #include "components/nacl/broker/nacl_broker_manifest.h" |
| 371 | #endif |
| 372 | #endif |
| 373 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 374 | #if defined(OS_WIN) |
wfh | c91e967 | 2016-01-27 00:14:20 | [diff] [blame] | 375 | #include "base/strings/string_tokenizer.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 376 | #include "chrome/browser/chrome_browser_main_win.h" |
Patrick Monette | bb54394 | 2019-05-17 17:45:32 | [diff] [blame] | 377 | #include "chrome/browser/win/conflicts/module_database.h" |
| 378 | #include "chrome/browser/win/conflicts/module_event_sink_impl.h" |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 379 | #include "chrome/install_static/install_util.h" |
Ken Rockot | fba9e74 | 2018-02-10 16:36:20 | [diff] [blame] | 380 | #include "chrome/services/wifi_util_win/public/mojom/constants.mojom.h" |
Ken Rockot | 7c16850 | 2019-05-30 07:58:46 | [diff] [blame] | 381 | #include "components/services/quarantine/public/cpp/quarantine_features_win.h" |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 382 | #include "sandbox/win/src/sandbox_policy.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 383 | #elif defined(OS_MACOSX) |
| 384 | #include "chrome/browser/chrome_browser_main_mac.h" |
Guido Urdaneta | 1a291743 | 2018-05-10 18:32:32 | [diff] [blame] | 385 | #include "services/audio/public/mojom/constants.mojom.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 386 | #elif defined(OS_CHROMEOS) |
Scott Violet | 776edf8 | 2017-09-29 02:03:01 | [diff] [blame] | 387 | #include "ash/public/interfaces/constants.mojom.h" |
Scott Violet | 47f00e5 | 2018-05-04 22:50:31 | [diff] [blame] | 388 | #include "chrome/browser/ash_service_registry.h" |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 389 | #include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h" |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 390 | #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 391 | #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 392 | #include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 393 | #include "chrome/browser/chromeos/chrome_service_name.h" |
Sam McNally | d8b7d82 | 2018-08-21 03:18:18 | [diff] [blame] | 394 | #include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h" |
[email protected] | 07fe275 | 2014-01-29 11:21:55 | [diff] [blame] | 395 | #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h" |
[email protected] | 5bc61cad | 2014-07-08 05:05:08 | [diff] [blame] | 396 | #include "chrome/browser/chromeos/file_manager/app_id.h" |
[email protected] | 43420a1 | 2014-04-21 03:20:48 | [diff] [blame] | 397 | #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h" |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 398 | #include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h" |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 399 | #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 400 | #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h" |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 401 | #include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h" |
| 402 | #include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h" |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 403 | #include "chrome/browser/chromeos/login/signin_partition_manager.h" |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 404 | #include "chrome/browser/chromeos/login/startup_utils.h" |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 405 | #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 406 | #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 407 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
[email protected] | c94ac69 | 2013-07-27 00:50:10 | [diff] [blame] | 408 | #include "chrome/browser/chromeos/system/input_device_settings.h" |
Katie D | b2d0709 | 2018-12-04 18:59:36 | [diff] [blame] | 409 | #include "chrome/browser/speech/tts_chromeos.h" |
Steven Bennetts | 81d07be | 2018-01-08 20:45:27 | [diff] [blame] | 410 | #include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h" |
Huanzhong Huang | afa9809 | 2019-06-24 12:01:24 | [diff] [blame] | 411 | #include "chrome/browser/ui/ash/tablet_mode_client.h" |
djacobo | 21e56e0 | 2016-07-02 01:14:31 | [diff] [blame] | 412 | #include "chrome/browser/ui/browser_dialogs.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 413 | #include "chromeos/constants/chromeos_constants.h" |
Kyle Horimoto | 1d6a679f | 2019-04-16 23:24:21 | [diff] [blame] | 414 | #include "chromeos/constants/chromeos_features.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 415 | #include "chromeos/constants/chromeos_switches.h" |
Kyle Horimoto | 1d6a679f | 2019-04-16 23:24:21 | [diff] [blame] | 416 | #include "chromeos/services/cellular_setup/cellular_setup_service.h" |
| 417 | #include "chromeos/services/cellular_setup/public/mojom/cellular_setup.mojom.h" |
| 418 | #include "chromeos/services/cellular_setup/public/mojom/constants.mojom.h" |
Leo Zhang | 84ce09e9 | 2018-08-25 01:55:36 | [diff] [blame] | 419 | #include "chromeos/services/ime/public/mojom/constants.mojom.h" |
Steven Bennetts | 0c565d5b | 2019-04-24 23:52:45 | [diff] [blame] | 420 | #include "chromeos/services/network_config/network_config_service.h" |
| 421 | #include "chromeos/services/network_config/public/mojom/constants.mojom.h" |
Ryan Hansberry | 9a08623c | 2018-06-14 21:28:05 | [diff] [blame] | 422 | #include "chromeos/services/secure_channel/public/mojom/constants.mojom.h" |
| 423 | #include "chromeos/services/secure_channel/secure_channel_service.h" |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 424 | #include "components/crash/content/app/breakpad_linux.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 425 | #include "components/user_manager/user_manager.h" |
Ken Rockot | 543f5e3 | 2018-02-04 02:13:50 | [diff] [blame] | 426 | #include "services/service_manager/public/mojom/interface_provider_spec.mojom.h" |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 427 | #elif defined(OS_LINUX) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 428 | #include "chrome/browser/chrome_browser_main_linux.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 429 | #elif defined(OS_ANDROID) |
Bo Liu | 4ade6b1b2 | 2017-11-28 02:26:35 | [diff] [blame] | 430 | #include "base/android/application_status_listener.h" |
zqzhang | 93e959d1 | 2017-03-16 13:10:20 | [diff] [blame] | 431 | #include "chrome/browser/android/app_hooks.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 432 | #include "chrome/browser/android/chrome_context_util.h" |
| 433 | #include "chrome/browser/android/devtools_manager_delegate_android.h" |
Dan Harrington | 964d48c | 2018-08-03 15:52:24 | [diff] [blame] | 434 | #include "chrome/browser/android/download/available_offline_content_provider.h" |
Min Qin | 0ab0e16 | 2017-11-14 21:57:19 | [diff] [blame] | 435 | #include "chrome/browser/android/download/intercept_oma_download_navigation_throttle.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 436 | #include "chrome/browser/android/ntp/new_tab_page_url_handler.h" |
| 437 | #include "chrome/browser/android/service_tab_launcher.h" |
| 438 | #include "chrome/browser/android/tab_android.h" |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 439 | #include "chrome/browser/android/tab_web_contents_delegate_android.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 440 | #include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 441 | #include "chrome/browser/chrome_browser_main_android.h" |
Dan Harrington | 954c882 | 2019-01-09 18:40:48 | [diff] [blame] | 442 | #include "chrome/browser/offline_pages/android/offline_page_auto_fetcher.h" |
Jinsuk Kim | 6f9253c | 2019-03-11 02:45:07 | [diff] [blame] | 443 | #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
James Cook | 01e3e5ef | 2019-04-09 14:44:38 | [diff] [blame] | 444 | #include "chrome/common/chrome_descriptors.h" |
Xing Liu | 302e065 | 2018-04-27 18:23:08 | [diff] [blame] | 445 | #include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h" |
Joshua Peraza | 934e559 | 2018-07-18 23:43:11 | [diff] [blame] | 446 | #include "components/crash/content/browser/child_exit_observer_android.h" |
Yuzu Saijo | 2d12ef9 | 2018-08-21 04:52:07 | [diff] [blame] | 447 | #include "components/crash/content/browser/crash_memory_metrics_collector_android.h" |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 448 | #include "components/navigation_interception/intercept_navigation_delegate.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 449 | #include "content/public/browser/android/java_interfaces.h" |
mfomitchev | 220b856 | 2017-07-13 23:08:54 | [diff] [blame] | 450 | #include "services/service_manager/public/cpp/interface_provider.h" |
Han Leon | abbe7c90 | 2018-08-30 02:08:10 | [diff] [blame] | 451 | #include "third_party/blink/public/mojom/payments/payment_request.mojom.h" |
Julie Jeongeun Kim | b6a0a1f | 2019-03-21 05:08:26 | [diff] [blame] | 452 | #include "third_party/blink/public/mojom/webauthn/authenticator.mojom.h" |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 453 | #include "ui/base/resource/resource_bundle_android.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 454 | #include "ui/base/ui_base_paths.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 455 | #elif defined(OS_POSIX) |
| 456 | #include "chrome/browser/chrome_browser_main_posix.h" |
| 457 | #endif |
| 458 | |
tmartino | fb34188 | 2017-02-10 19:36:53 | [diff] [blame] | 459 | #if !defined(OS_ANDROID) |
Jay Harris | 1ddcffa | 2019-07-09 03:07:40 | [diff] [blame] | 460 | #include "chrome/browser/badging/badge_manager.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 461 | #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 462 | #include "chrome/browser/devtools/devtools_window.h" |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 463 | #include "chrome/browser/media/unified_autoplay_config.h" |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 464 | #include "chrome/browser/payments/payment_request_factory.h" |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 465 | #include "chrome/browser/search/instant_service.h" |
| 466 | #include "chrome/browser/search/instant_service_factory.h" |
Reilly Grant | 2814fb7 | 2019-03-19 17:04:46 | [diff] [blame] | 467 | #include "chrome/browser/serial/chrome_serial_delegate.h" |
Collin Baker | 8a21755 | 2019-05-29 19:47:51 | [diff] [blame] | 468 | #include "chrome/browser/ui/browser.h" |
| 469 | #include "chrome/browser/ui/browser_finder.h" |
| 470 | #include "chrome/browser/ui/browser_list.h" |
| 471 | #include "chrome/browser/ui/browser_window.h" |
jdoerrie | 4f9376f | 2018-12-12 18:26:20 | [diff] [blame] | 472 | #include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h" |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 473 | #include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h" |
Nina Satragno | 8c832df | 2019-07-29 15:59:39 | [diff] [blame^] | 474 | #include "chrome/browser/webauthn/authenticator_request_scheduler.h" |
| 475 | #include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h" |
Jay Civelli | 4d53be9b | 2017-08-31 22:01:43 | [diff] [blame] | 476 | #include "chrome/common/importer/profile_import.mojom.h" |
Austin Orion | e250d01 | 2019-05-29 02:56:27 | [diff] [blame] | 477 | #include "chrome/grit/chrome_unscaled_resources.h" |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 478 | #endif // !defined(OS_ANDROID) |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 479 | |
Nicolas Ouellet-Payeur | bdcab009 | 2018-10-22 14:50:33 | [diff] [blame] | 480 | #if defined(OS_WIN) || defined(OS_MACOSX) || \ |
| 481 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
Nicolas Ouellet-Payeur | 4b840a9 | 2018-09-18 14:46:52 | [diff] [blame] | 482 | #include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h" |
| 483 | #endif |
| 484 | |
[email protected] | a220b593 | 2013-09-21 03:47:44 | [diff] [blame] | 485 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 486 | #if !defined(OS_ANDROID) |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 487 | #include "base/debug/leak_annotations.h" |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 488 | #include "components/crash/content/app/breakpad_linux.h" |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 489 | #endif // !defined(OS_ANDROID) |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 490 | #include "components/crash/content/browser/crash_handler_host_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 491 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 492 | |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 493 | // TODO(crbug.com/939205): Once the upcoming App Service is available, use a |
| 494 | // single navigation throttle to display the intent picker on all platforms. |
| 495 | #if !defined(OS_ANDROID) |
| 496 | #if defined(OS_CHROMEOS) |
| 497 | #include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h" |
| 498 | #else |
| 499 | #include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h" |
| 500 | #endif |
| 501 | #endif |
| 502 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 503 | #if defined(TOOLKIT_VIEWS) |
| 504 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h" |
| 505 | #endif |
| 506 | |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 507 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 508 | #if defined(USE_X11) |
| 509 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux_x11.h" |
| 510 | #else |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 511 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h" |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 512 | #endif // USE_X11 |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 513 | #endif |
| 514 | |
Mohsen Izadi | f1958f2 | 2019-01-18 20:29:31 | [diff] [blame] | 515 | #if defined(USE_OZONE) |
| 516 | #include "ui/ozone/public/ozone_platform.h" |
| 517 | #endif |
| 518 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 519 | #if defined(USE_X11) |
| 520 | #include "chrome/browser/chrome_browser_main_extra_parts_x11.h" |
| 521 | #endif |
| 522 | |
brettw | ab78fef | 2016-10-12 02:56:05 | [diff] [blame] | 523 | #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
[email protected] | 7a2a6d80 | 2014-06-06 13:39:19 | [diff] [blame] | 524 | #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 525 | #endif |
| 526 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 527 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 528 | #include "components/nacl/browser/nacl_browser.h" |
| 529 | #include "components/nacl/browser/nacl_host_message_filter.h" |
| 530 | #include "components/nacl/browser/nacl_process_host.h" |
| 531 | #include "components/nacl/common/nacl_process_type.h" |
| 532 | #include "components/nacl/common/nacl_switches.h" |
| 533 | #endif |
| 534 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 535 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 536 | #include "chrome/browser/accessibility/animation_policy_prefs.h" |
Dominick Ng | 6ff5105 | 2018-07-06 05:30:20 | [diff] [blame] | 537 | #include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h" |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 538 | #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 539 | #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
Clark DuVall | 2cf99249e | 2018-09-19 19:11:51 | [diff] [blame] | 540 | #include "chrome/browser/extensions/user_script_listener.h" |
| 541 | #include "chrome/browser/media/cast_transport_host_filter.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 542 | #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 543 | #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" |
Ken Rockot | 551f748 | 2018-02-10 11:18:46 | [diff] [blame] | 544 | #include "chrome/services/media_gallery_util/public/mojom/constants.mojom.h" |
Ken Rockot | 2ad4db3 | 2018-02-10 16:24:10 | [diff] [blame] | 545 | #include "chrome/services/removable_storage_writer/public/mojom/constants.mojom.h" |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 546 | #include "components/guest_view/browser/guest_view_base.h" |
| 547 | #include "components/guest_view/browser/guest_view_manager.h" |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 548 | #include "extensions/browser/api/web_request/web_request_api.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 549 | #include "extensions/browser/extension_host.h" |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 550 | #include "extensions/browser/extension_navigation_throttle.h" |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 551 | #include "extensions/browser/extension_protocols.h" |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 552 | #include "extensions/browser/extension_registry.h" |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 553 | #include "extensions/browser/extension_system.h" |
tfarina | 01710e3 | 2015-07-13 21:53:22 | [diff] [blame] | 554 | #include "extensions/browser/extension_util.h" |
hanxi | 0d0a1e9 | 2014-08-26 18:39:48 | [diff] [blame] | 555 | #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 556 | #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
| 557 | #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 558 | #include "extensions/browser/process_manager.h" |
Dan Beam | 836c02a | 2019-06-15 01:58:27 | [diff] [blame] | 559 | #include "extensions/common/constants.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 560 | #include "extensions/common/extension.h" |
| 561 | #include "extensions/common/extension_set.h" |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 562 | #include "extensions/common/manifest_handlers/background_info.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 563 | #include "extensions/common/manifest_handlers/shared_module_info.h" |
Clark DuVall | bf7722f | 2018-08-03 18:03:33 | [diff] [blame] | 564 | #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 565 | #include "extensions/common/permissions/permissions_data.h" |
| 566 | #include "extensions/common/permissions/socket_permission.h" |
| 567 | #include "extensions/common/switches.h" |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 568 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
merkin | db10455e | 2017-02-28 13:16:25 | [diff] [blame] | 569 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 570 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 571 | #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h" |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 572 | #include "chrome/browser/plugins/flash_download_interception.h" |
John Abd-El-Malek | ecc6f5f | 2018-03-02 18:47:39 | [diff] [blame] | 573 | #include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h" |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 574 | #endif |
| 575 | |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 576 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 577 | #include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h" |
| 578 | #endif |
| 579 | |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 580 | #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 581 | #include "chrome/browser/media/cast_remoting_connector.h" |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 582 | #endif |
| 583 | |
weili | fabbf757 | 2017-05-22 19:05:16 | [diff] [blame] | 584 | #if BUILDFLAG(ENABLE_PRINTING) |
Lei Zhang | a2fa14c | 2018-05-15 00:05:21 | [diff] [blame] | 585 | #include "chrome/browser/printing/printing_message_filter.h" |
Miyoung Shin | 0f25ee540 | 2019-07-19 01:26:14 | [diff] [blame] | 586 | #include "components/services/pdf_compositor/public/mojom/pdf_compositor.mojom.h" |
weili | fabbf757 | 2017-05-22 19:05:16 | [diff] [blame] | 587 | #endif |
Lei Zhang | a2fa14c | 2018-05-15 00:05:21 | [diff] [blame] | 588 | |
| 589 | #if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \ |
| 590 | (BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN)) |
Ken Rockot | ed7f41b | 2018-02-10 16:19:10 | [diff] [blame] | 591 | #include "chrome/services/printing/public/mojom/constants.mojom.h" |
Jay Civelli | 9237eac | 2017-09-21 16:10:21 | [diff] [blame] | 592 | #endif |
weili | fabbf757 | 2017-05-22 19:05:16 | [diff] [blame] | 593 | |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 594 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c86d76e4 | 2016-03-14 23:38:49 | [diff] [blame] | 595 | #include "chrome/browser/media/output_protection_impl.h" |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 596 | #include "chrome/browser/media/platform_verification_impl.h" |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 597 | #if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 598 | #include "chrome/browser/media/widevine_hardware_caps_win.h" |
| 599 | #include "third_party/widevine/cdm/widevine_cdm_common.h" |
| 600 | #endif |
| 601 | #endif |
| 602 | |
xhwang | db24d60 | 2017-05-20 06:32:24 | [diff] [blame] | 603 | #if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID) |
xhwang | 116acb9 | 2017-04-03 18:27:20 | [diff] [blame] | 604 | #include "chrome/browser/media/android/cdm/media_drm_storage_factory.h" |
| 605 | #endif |
xhwang | c86d76e4 | 2016-03-14 23:38:49 | [diff] [blame] | 606 | |
xhwang | db24d60 | 2017-05-20 06:32:24 | [diff] [blame] | 607 | #if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS) |
Xiaohan Wang | 3fcfc15 | 2017-07-06 00:51:55 | [diff] [blame] | 608 | #include "media/mojo/interfaces/constants.mojom.h" // nogncheck |
xhwang | b1d65fd | 2016-10-19 20:55:52 | [diff] [blame] | 609 | #include "media/mojo/services/media_service_factory.h" // nogncheck |
alokp | 6ecb238 | 2016-01-27 00:40:00 | [diff] [blame] | 610 | #endif |
| 611 | |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 612 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 613 | #include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h" |
| 614 | #endif |
| 615 | |
Luum Habtemariam | 7f7c6175 | 2018-07-18 00:41:18 | [diff] [blame] | 616 | #if BUILDFLAG(ENABLE_PRINTING) && defined(OS_CHROMEOS) |
Luum Habtemariam | c295b4ea | 2019-04-24 20:18:51 | [diff] [blame] | 617 | // TODO(crbug.com/948800): Doesn't match BUILD.gn of use_cups && is_chromeos. |
Luum Habtemariam | 9d99993 | 2018-10-15 23:04:12 | [diff] [blame] | 618 | #include "chrome/services/cups_ipp_parser/public/mojom/constants.mojom.h" |
Luum Habtemariam | 7f7c6175 | 2018-07-18 00:41:18 | [diff] [blame] | 619 | #endif |
| 620 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 621 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
Daniel Rubery | a1611e3 | 2019-04-24 21:38:35 | [diff] [blame] | 622 | #include "chrome/browser/safe_browsing/chrome_password_protection_service.h" |
| 623 | #endif |
| 624 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 625 | #if BUILDFLAG(FULL_SAFE_BROWSING) || defined(OS_CHROMEOS) |
Ken Rockot | 3d36668 | 2018-02-10 11:13:26 | [diff] [blame] | 626 | #include "chrome/services/file_util/public/mojom/constants.mojom.h" |
Jay Civelli | d5b61433 | 2017-11-10 03:37:05 | [diff] [blame] | 627 | #endif |
| 628 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 629 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 630 | #include "chrome/browser/offline_pages/offline_page_tab_helper.h" |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 631 | #include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h" |
| 632 | #endif |
| 633 | |
Ken Rockot | 80b08e9 | 2018-08-15 04:22:02 | [diff] [blame] | 634 | #if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS) |
| 635 | #include "services/content/simple_browser/public/mojom/constants.mojom.h" |
| 636 | #include "services/content/simple_browser/simple_browser_service.h" |
| 637 | #endif |
| 638 | |
| 639 | #if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_OUT_OF_PROCESS) |
Ken Rockot | 99c5bc74 | 2018-07-12 15:36:56 | [diff] [blame] | 640 | #include "services/content/simple_browser/public/mojom/constants.mojom.h" |
| 641 | #endif |
| 642 | |
Will Cassella | 40837ba | 2019-07-01 21:32:00 | [diff] [blame] | 643 | #if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID) |
Bill Orr | eb42922 | 2018-08-08 21:14:43 | [diff] [blame] | 644 | #include "device/vr/public/mojom/isolated_xr_service.mojom.h" |
| 645 | #endif |
| 646 | |
Michael Thiessen | 909ba03 | 2019-03-26 23:47:43 | [diff] [blame] | 647 | #if defined(BROWSER_MEDIA_CONTROLS_MENU) |
| 648 | #include "third_party/blink/public/mojom/media_controls/touchless/media_controls.mojom.h" |
| 649 | #endif |
| 650 | |
Michael Thiessen | 07c444c | 2019-04-26 03:53:11 | [diff] [blame] | 651 | #if defined(ENABLE_SPATIAL_NAVIGATION_HOST) |
| 652 | #include "third_party/blink/public/mojom/page/spatial_navigation.mojom.h" |
| 653 | #endif |
| 654 | |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 655 | using base::FileDescriptor; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 656 | using content::BrowserThread; |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 657 | using content::BrowserURLHandler; |
msramek | a3c7cfd | 2017-02-03 13:34:13 | [diff] [blame] | 658 | using content::BrowsingDataFilterBuilder; |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 659 | using content::ChildProcessSecurityPolicy; |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 660 | using content::QuotaPermissionContext; |
[email protected] | 2626d14 | 2014-04-22 17:24:02 | [diff] [blame] | 661 | using content::RenderFrameHost; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 662 | using content::RenderViewHost; |
[email protected] | 7491ad0 | 2014-07-05 19:10:07 | [diff] [blame] | 663 | using content::ResourceType; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 664 | using content::SiteInstance; |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 665 | using content::WebContents; |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 666 | using content::WebPreferences; |
[email protected] | 593d2a7 | 2013-07-26 08:48:38 | [diff] [blame] | 667 | using message_center::NotifierId; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 668 | |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 669 | #if defined(OS_POSIX) |
brettw | 3c98c7d3 | 2017-07-25 01:44:20 | [diff] [blame] | 670 | using content::PosixFileDescriptorInfo; |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 671 | #endif |
| 672 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 673 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 674 | using extensions::APIPermission; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 675 | using extensions::ChromeContentBrowserClientExtensionsPart; |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 676 | using extensions::Extension; |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 677 | using extensions::Manifest; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 678 | #endif |
| 679 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 680 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 681 | using plugins::ChromeContentBrowserClientPluginsPart; |
| 682 | #endif |
| 683 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 684 | namespace { |
| 685 | |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 686 | const storage::QuotaSettings* g_default_quota_settings; |
| 687 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 688 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 689 | // TODO(teravest): Add renderer-side API-specific checking for these APIs so |
| 690 | // that blanket permission isn't granted to all dev channel APIs for these. |
| 691 | // http://crbug.com/386743 |
| 692 | const char* const kPredefinedAllowedDevChannelOrigins[] = { |
| 693 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937 |
| 694 | "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937 |
| 695 | }; |
| 696 | |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 697 | const char* const kPredefinedAllowedFileHandleOrigins[] = { |
[email protected] | 10c3922 | 2013-11-13 20:09:25 | [diff] [blame] | 698 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789 |
| 699 | "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789 |
| 700 | }; |
| 701 | |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 702 | const char* const kPredefinedAllowedSocketOrigins[] = { |
Mike Frysinger | a9864c6a | 2017-12-18 22:12:31 | [diff] [blame] | 703 | "okddffdblfhhnmhodogpojmfkjmhinfp", // Secure Shell App (dev) |
| 704 | "pnhechapfaindjhompbnflcldabbghjo", // Secure Shell App (stable) |
| 705 | "algkcnfjnajfhgimadimbjhmpaeohhln", // Secure Shell Extension (dev) |
| 706 | "iodihamcpbpeioajjeobimgagajmlibd", // Secure Shell Extension (stable) |
[email protected] | 9913268 | 2012-04-24 19:00:45 | [diff] [blame] | 707 | "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126 |
| 708 | "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop |
| 709 | "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop |
| 710 | "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop |
[email protected] | a450b6be | 2012-05-22 19:30:35 | [diff] [blame] | 711 | "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary |
[email protected] | 9040a0c2 | 2012-06-22 19:06:54 | [diff] [blame] | 712 | "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 |
| 713 | "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 |
| 714 | "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099 |
| 715 | "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099 |
| 716 | "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099 |
| 717 | "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099 |
[email protected] | 4dc30b8 | 2012-08-15 00:24:38 | [diff] [blame] | 718 | "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099 |
[email protected] | 45db05f | 2012-12-10 21:52:58 | [diff] [blame] | 719 | "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514 |
[email protected] | b7131323 | 2013-05-06 06:16:29 | [diff] [blame] | 720 | "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080 |
[email protected] | 3f6fca2 | 2013-08-12 23:13:42 | [diff] [blame] | 721 | "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080 |
[email protected] | 3f6fca2 | 2013-08-12 23:13:42 | [diff] [blame] | 722 | "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084 |
| 723 | "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084 |
| 724 | "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084 |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 725 | }; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 726 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 727 | |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 728 | enum AppLoadedInTabSource { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 729 | // 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] | 730 | APP_LOADED_IN_TAB_SOURCE_APP = 0, |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 731 | |
| 732 | // 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] | 733 | APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE, |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 734 | |
| 735 | // An extension or app tried to load a resource of a different platform app in |
| 736 | // a tab. |
| 737 | APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION, |
| 738 | |
| 739 | // A non-app and non-extension page tried to load a platform app in a tab. |
| 740 | APP_LOADED_IN_TAB_SOURCE_OTHER, |
| 741 | |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 742 | APP_LOADED_IN_TAB_SOURCE_MAX |
| 743 | }; |
| 744 | |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 745 | // Cached version of the locale so we can return the locale on the I/O |
| 746 | // thread. |
| 747 | std::string& GetIOThreadApplicationLocale() { |
| 748 | static base::NoDestructor<std::string> s; |
| 749 | return *s; |
| 750 | } |
| 751 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 752 | // Returns a copy of the given url with its host set to given host and path set |
| 753 | // to given path. Other parts of the url will be the same. |
| 754 | GURL ReplaceURLHostAndPath(const GURL& url, |
| 755 | const std::string& host, |
| 756 | const std::string& path) { |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 757 | url::Replacements<char> replacements; |
| 758 | replacements.SetHost(host.c_str(), url::Component(0, host.length())); |
| 759 | replacements.SetPath(path.c_str(), url::Component(0, path.length())); |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 760 | return url.ReplaceComponents(replacements); |
| 761 | } |
| 762 | |
mad | fbd1085 | 2017-01-20 03:15:33 | [diff] [blame] | 763 | // Handles the rewriting of the new tab page URL based on group policy. |
| 764 | bool HandleNewTabPageLocationOverride( |
| 765 | GURL* url, |
| 766 | content::BrowserContext* browser_context) { |
| 767 | if (!url->SchemeIs(content::kChromeUIScheme) || |
| 768 | url->host() != chrome::kChromeUINewTabHost) |
| 769 | return false; |
| 770 | |
| 771 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 772 | std::string ntp_location = |
| 773 | profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride); |
| 774 | if (ntp_location.empty()) |
| 775 | return false; |
| 776 | |
| 777 | *url = GURL(ntp_location); |
| 778 | return true; |
| 779 | } |
| 780 | |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 781 | #if !defined(OS_ANDROID) |
| 782 | // Check if the current url is whitelisted based on a list of whitelisted urls. |
| 783 | bool IsURLWhitelisted(const GURL& current_url, |
| 784 | const base::Value::ListStorage& whitelisted_urls) { |
| 785 | // Only check on HTTP and HTTPS pages. |
| 786 | if (!current_url.SchemeIsHTTPOrHTTPS()) |
| 787 | return false; |
| 788 | |
| 789 | for (auto const& value : whitelisted_urls) { |
| 790 | ContentSettingsPattern pattern = |
| 791 | ContentSettingsPattern::FromString(value.GetString()); |
| 792 | if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid()) |
| 793 | continue; |
| 794 | if (pattern.Matches(current_url)) |
| 795 | return true; |
| 796 | } |
| 797 | |
| 798 | return false; |
| 799 | } |
| 800 | |
| 801 | // Check if autoplay is allowed by policy configuration. |
| 802 | bool IsAutoplayAllowedByPolicy(content::WebContents* contents, |
| 803 | PrefService* prefs) { |
| 804 | DCHECK(prefs); |
| 805 | |
| 806 | // Check if we have globally allowed autoplay by policy. |
| 807 | if (prefs->GetBoolean(prefs::kAutoplayAllowed) && |
| 808 | prefs->IsManagedPreference(prefs::kAutoplayAllowed)) { |
| 809 | return true; |
| 810 | } |
| 811 | |
| 812 | if (!contents) |
| 813 | return false; |
| 814 | |
| 815 | // Check if the current URL matches a URL pattern on the whitelist. |
| 816 | const base::ListValue* autoplay_whitelist = |
| 817 | prefs->GetList(prefs::kAutoplayWhitelist); |
| 818 | return autoplay_whitelist && |
| 819 | prefs->IsManagedPreference(prefs::kAutoplayWhitelist) && |
| 820 | IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList()); |
| 821 | } |
| 822 | #endif |
| 823 | |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 824 | #if defined(OS_ANDROID) |
| 825 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
| 826 | return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket(); |
| 827 | } |
| 828 | #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 829 | breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( |
| 830 | const std::string& process_type) { |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 831 | base::FilePath dumps_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 832 | base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 833 | { |
| 834 | ANNOTATE_SCOPED_MEMORY_LEAK; |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 835 | bool upload = !getenv(env_vars::kHeadless); |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 836 | breakpad::CrashHandlerHostLinux* crash_handler = |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 837 | new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 838 | crash_handler->StartUploaderThread(); |
| 839 | return crash_handler; |
| 840 | } |
| 841 | } |
| 842 | |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 843 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 844 | // Extensions have the same process type as renderers. |
[email protected] | cd0f7af | 2014-01-16 23:50:39 | [diff] [blame] | 845 | if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 846 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 847 | if (!crash_handler) |
| 848 | crash_handler = CreateCrashHandlerHost("extension"); |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 849 | return crash_handler->GetDeathSignalSocket(); |
| 850 | } |
| 851 | |
James Cook | 783fdeb | 2018-05-24 22:28:46 | [diff] [blame] | 852 | #if defined(OS_CHROMEOS) |
| 853 | // Mash services are utility processes, but crashes are reported using the |
| 854 | // service name as the process type to make the crash console easier to read. |
| 855 | if (command_line.HasSwitch(switches::kMashServiceName)) { |
| 856 | static base::NoDestructor< |
| 857 | std::map<std::string, breakpad::CrashHandlerHostLinux*>> |
| 858 | crash_handlers; |
| 859 | std::string service_name = |
| 860 | command_line.GetSwitchValueASCII(switches::kMashServiceName); |
| 861 | auto it = crash_handlers->find(service_name); |
| 862 | if (it == crash_handlers->end()) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 863 | auto insert_result = crash_handlers->insert( |
James Cook | 783fdeb | 2018-05-24 22:28:46 | [diff] [blame] | 864 | std::make_pair(service_name, CreateCrashHandlerHost(service_name))); |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 865 | it = insert_result.first; |
James Cook | 783fdeb | 2018-05-24 22:28:46 | [diff] [blame] | 866 | } |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 867 | return it->second->GetDeathSignalSocket(); |
James Cook | 783fdeb | 2018-05-24 22:28:46 | [diff] [blame] | 868 | } |
| 869 | #endif // defined(OS_CHROMEOS) |
| 870 | |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 871 | std::string process_type = |
| 872 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 873 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 874 | if (process_type == switches::kRendererProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 875 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 876 | if (!crash_handler) |
| 877 | crash_handler = CreateCrashHandlerHost(process_type); |
| 878 | return crash_handler->GetDeathSignalSocket(); |
| 879 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 880 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 881 | if (process_type == switches::kPpapiPluginProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 882 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 883 | if (!crash_handler) |
| 884 | crash_handler = CreateCrashHandlerHost(process_type); |
| 885 | return crash_handler->GetDeathSignalSocket(); |
| 886 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 887 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 888 | if (process_type == switches::kGpuProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 889 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 890 | if (!crash_handler) |
| 891 | crash_handler = CreateCrashHandlerHost(process_type); |
| 892 | return crash_handler->GetDeathSignalSocket(); |
| 893 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 894 | |
James Cook | 9207cc1 | 2017-10-19 17:08:39 | [diff] [blame] | 895 | if (process_type == switches::kUtilityProcess) { |
| 896 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
| 897 | if (!crash_handler) |
| 898 | crash_handler = CreateCrashHandlerHost(process_type); |
| 899 | return crash_handler->GetDeathSignalSocket(); |
| 900 | } |
| 901 | |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 902 | return -1; |
| 903 | } |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 904 | #endif // defined(OS_ANDROID) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 905 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 906 | void SetApplicationLocaleOnIOThread(const std::string& locale) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 907 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 908 | GetIOThreadApplicationLocale() = locale; |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 909 | } |
| 910 | |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 911 | // An implementation of the SSLCertReporter interface used by |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 912 | // SSLErrorHandler. Uses CertificateReportingService to send reports. The |
| 913 | // service handles queueing and re-sending of failed reports. Each certificate |
| 914 | // error creates a new instance of this class. |
| 915 | class CertificateReportingServiceCertReporter : public SSLCertReporter { |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 916 | public: |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 917 | explicit CertificateReportingServiceCertReporter( |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 918 | content::WebContents* web_contents) |
| 919 | : service_(CertificateReportingServiceFactory::GetForBrowserContext( |
| 920 | web_contents->GetBrowserContext())) {} |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 921 | ~CertificateReportingServiceCertReporter() override {} |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 922 | |
| 923 | // SSLCertReporter implementation |
estark | 4282f117 | 2015-05-13 22:01:55 | [diff] [blame] | 924 | void ReportInvalidCertificateChain( |
| 925 | const std::string& serialized_report) override { |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 926 | service_->Send(serialized_report); |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | private: |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 930 | CertificateReportingService* service_; |
| 931 | |
| 932 | DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter); |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 933 | }; |
| 934 | |
bshe | 4f53ce4 | 2015-11-30 16:56:31 | [diff] [blame] | 935 | #if defined(OS_ANDROID) |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 936 | float GetDeviceScaleAdjustment() { |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 937 | static const float kMinFSM = 1.05f; |
| 938 | static const int kWidthForMinFSM = 320; |
| 939 | static const float kMaxFSM = 1.3f; |
| 940 | static const int kWidthForMaxFSM = 800; |
| 941 | |
boliu | 21c5afa | 2017-01-11 19:34:23 | [diff] [blame] | 942 | int minWidth = chrome::android::ChromeContextUtil::GetSmallestDIPWidth(); |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 943 | |
| 944 | if (minWidth <= kWidthForMinFSM) |
| 945 | return kMinFSM; |
| 946 | if (minWidth >= kWidthForMaxFSM) |
| 947 | return kMaxFSM; |
| 948 | |
| 949 | // The font scale multiplier varies linearly between kMinFSM and kMaxFSM. |
| 950 | float ratio = static_cast<float>(minWidth - kWidthForMinFSM) / |
| 951 | (kWidthForMaxFSM - kWidthForMinFSM); |
| 952 | return ratio * (kMaxFSM - kMinFSM) + kMinFSM; |
| 953 | } |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 954 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 955 | #endif // defined(OS_ANDROID) |
| 956 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 957 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 958 | |
| 959 | AppLoadedInTabSource ClassifyAppLoadedInTabSource( |
| 960 | const GURL& opener_url, |
| 961 | const extensions::Extension* target_platform_app) { |
| 962 | if (opener_url.SchemeIs(extensions::kExtensionScheme)) { |
| 963 | if (opener_url.host_piece() == target_platform_app->id()) { |
| 964 | // This platform app was trying to window.open() one of its own URLs. |
| 965 | if (opener_url == |
| 966 | extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) { |
| 967 | // Source was the background page. |
| 968 | return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE; |
| 969 | } else { |
| 970 | // Source was a different page inside the app. |
| 971 | return APP_LOADED_IN_TAB_SOURCE_APP; |
| 972 | } |
| 973 | } |
| 974 | // The forbidden app URL was being opened by a different app or extension. |
| 975 | return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION; |
| 976 | } |
| 977 | // The forbidden app URL was being opened by a non-extension page (e.g. http). |
| 978 | return APP_LOADED_IN_TAB_SOURCE_OTHER; |
| 979 | } |
[email protected] | 9c765638 | 2014-08-08 21:02:30 | [diff] [blame] | 980 | |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 981 | // Returns true if there is is an extension matching |url| in |
| 982 | // |opener_render_process_id| with APIPermission::kBackground. |
| 983 | // |
| 984 | // Note that GetExtensionOrAppByURL requires a full URL in order to match with a |
| 985 | // hosted app, even though normal extensions just use the host. |
| 986 | bool URLHasExtensionBackgroundPermission( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 987 | extensions::ProcessMap* process_map, |
| 988 | extensions::ExtensionRegistry* registry, |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 989 | const GURL& url, |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 990 | int opener_render_process_id) { |
| 991 | // Note: includes web URLs that are part of an extension's web extent. |
| 992 | const Extension* extension = |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 993 | registry->enabled_extensions().GetExtensionOrAppByURL(url); |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 994 | return extension && |
| 995 | extension->permissions_data()->HasAPIPermission( |
| 996 | APIPermission::kBackground) && |
| 997 | process_map->Contains(extension->id(), opener_render_process_id); |
| 998 | } |
Kevin Marshall | 32f99d7e | 2017-07-11 23:17:46 | [diff] [blame] | 999 | |
| 1000 | void InvokeCallbackOnThread( |
| 1001 | scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 1002 | base::Callback<void(bool)> callback, |
| 1003 | bool result) { |
tzik | df81f14 | 2018-10-26 00:23:34 | [diff] [blame] | 1004 | task_runner->PostTask(FROM_HERE, base::BindOnce(std::move(callback), result)); |
Kevin Marshall | 32f99d7e | 2017-07-11 23:17:46 | [diff] [blame] | 1005 | } |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 1006 | #endif |
| 1007 | |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 1008 | chrome::mojom::PrerenderCanceler* GetPrerenderCanceller( |
| 1009 | const base::Callback<content::WebContents*()>& wc_getter) { |
| 1010 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 1011 | auto* web_contents = wc_getter.Run(); |
| 1012 | if (!web_contents) |
| 1013 | return nullptr; |
| 1014 | |
| 1015 | return prerender::PrerenderContents::FromWebContents(web_contents); |
| 1016 | } |
| 1017 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1018 | void LaunchURL( |
| 1019 | const GURL& url, |
| 1020 | const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter, |
| 1021 | ui::PageTransition page_transition, |
| 1022 | bool has_user_gesture) { |
| 1023 | // If there is no longer a WebContents, the request may have raced with tab |
| 1024 | // closing. Don't fire the external request. (It may have been a prerender.) |
| 1025 | content::WebContents* web_contents = web_contents_getter.Run(); |
| 1026 | if (!web_contents) |
| 1027 | return; |
| 1028 | |
| 1029 | // Do not launch external requests attached to unswapped prerenders. |
| 1030 | prerender::PrerenderContents* prerender_contents = |
| 1031 | prerender::PrerenderContents::FromWebContents(web_contents); |
| 1032 | if (prerender_contents) { |
| 1033 | prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); |
| 1034 | prerender::ReportPrerenderExternalURL(); |
| 1035 | return; |
| 1036 | } |
| 1037 | |
Robbie McElrath | 1294d24 | 2019-05-31 20:46:22 | [diff] [blame] | 1038 | // Do not launch external requests for schemes that have a handler registered. |
| 1039 | ProtocolHandlerRegistry* protocol_handler_registry = |
| 1040 | ProtocolHandlerRegistryFactory::GetForBrowserContext( |
| 1041 | web_contents->GetBrowserContext()); |
| 1042 | if (protocol_handler_registry && |
| 1043 | protocol_handler_registry->IsHandledProtocol(url.scheme())) |
| 1044 | return; |
| 1045 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1046 | bool is_whitelisted = false; |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1047 | PolicyBlacklistService* service = |
Oleg Davydov | 5cfe7ab | 2019-02-01 12:27:19 | [diff] [blame] | 1048 | PolicyBlacklistFactory::GetForBrowserContext( |
| 1049 | web_contents->GetBrowserContext()); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 1050 | if (service) { |
| 1051 | const policy::URLBlacklist::URLBlacklistState url_state = |
| 1052 | service->GetURLBlacklistState(url); |
| 1053 | is_whitelisted = |
| 1054 | url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST; |
| 1055 | } |
| 1056 | |
| 1057 | // If the URL is in whitelist, we launch it without asking the user and |
| 1058 | // without any additional security checks. Since the URL is whitelisted, |
| 1059 | // we assume it can be executed. |
| 1060 | if (is_whitelisted) { |
| 1061 | ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents); |
| 1062 | } else { |
| 1063 | ExternalProtocolHandler::LaunchUrl( |
| 1064 | url, web_contents->GetRenderViewHost()->GetProcess()->GetID(), |
| 1065 | web_contents->GetRenderViewHost()->GetRoutingID(), page_transition, |
| 1066 | has_user_gesture); |
| 1067 | } |
| 1068 | } |
| 1069 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1070 | std::string GetProduct() { |
| 1071 | return version_info::GetProductNameAndVersionForUserAgent(); |
| 1072 | } |
| 1073 | |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 1074 | void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) { |
| 1075 | // |allowlist| combines pref/policy + cmdline switch in the browser process. |
| 1076 | // For renderer and utility (e.g. NetworkService) processes the switch is the |
| 1077 | // only available source, so below the combined (pref/policy + cmdline) |
| 1078 | // allowlist of secure origins is injected into |cmdline| for these other |
| 1079 | // processes. |
| 1080 | std::vector<std::string> allowlist = |
| 1081 | network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist(); |
| 1082 | if (!allowlist.empty()) { |
| 1083 | cmdline->AppendSwitchASCII( |
| 1084 | network::switches::kUnsafelyTreatInsecureOriginAsSecure, |
| 1085 | base::JoinString(allowlist, ",")); |
| 1086 | } |
| 1087 | } |
| 1088 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 1089 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 1090 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1091 | std::string GetUserAgent() { |
| 1092 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1093 | if (command_line->HasSwitch(switches::kUserAgent)) { |
| 1094 | std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent); |
| 1095 | if (net::HttpUtil::IsValidHeaderValue(ua)) |
| 1096 | return ua; |
| 1097 | LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent; |
| 1098 | } |
| 1099 | |
John Delaney | ac24e57 | 2019-04-30 19:47:02 | [diff] [blame] | 1100 | if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) { |
| 1101 | return content::GetFrozenUserAgent( |
| 1102 | command_line->HasSwitch(switches::kUseMobileUserAgent)) |
| 1103 | .as_string(); |
| 1104 | } |
| 1105 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1106 | std::string product = GetProduct(); |
| 1107 | #if defined(OS_ANDROID) |
| 1108 | if (command_line->HasSwitch(switches::kUseMobileUserAgent)) |
| 1109 | product += " Mobile"; |
| 1110 | #endif |
| 1111 | return content::BuildUserAgentFromProduct(product); |
| 1112 | } |
| 1113 | |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1114 | blink::UserAgentMetadata GetUserAgentMetadata() { |
| 1115 | blink::UserAgentMetadata metadata; |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1116 | metadata.brand = version_info::GetProductName(); |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 1117 | metadata.full_version = version_info::GetVersionNumber(); |
| 1118 | metadata.major_version = version_info::GetMajorVersionNumber(); |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1119 | metadata.platform = version_info::GetOSType(); |
| 1120 | |
| 1121 | // TODO(mkwst): Poke at BuildUserAgentFromProduct to split out these pieces. |
| 1122 | metadata.architecture = ""; |
| 1123 | metadata.model = ""; |
| 1124 | |
| 1125 | return metadata; |
| 1126 | } |
| 1127 | |
Ran Ji | a96d43d4 | 2018-05-02 17:14:53 | [diff] [blame] | 1128 | ChromeContentBrowserClient::ChromeContentBrowserClient( |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 1129 | StartupData* startup_data) |
Wojciech Dzierżanowski | 4538080 | 2019-04-29 14:50:32 | [diff] [blame] | 1130 | : data_reduction_proxy_throttle_manager_( |
| 1131 | nullptr, |
| 1132 | base::OnTaskRunnerDeleter(nullptr)), |
Jeremy Roman | 495db68 | 2019-07-12 16:03:24 | [diff] [blame] | 1133 | startup_data_(startup_data) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1134 | #if BUILDFLAG(ENABLE_PLUGINS) |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 1135 | for (size_t i = 0; i < base::size(kPredefinedAllowedDevChannelOrigins); ++i) |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 1136 | allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 1137 | for (size_t i = 0; i < base::size(kPredefinedAllowedFileHandleOrigins); ++i) |
[email protected] | 10c3922 | 2013-11-13 20:09:25 | [diff] [blame] | 1138 | allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 1139 | for (size_t i = 0; i < base::size(kPredefinedAllowedSocketOrigins); ++i) |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1140 | allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 1141 | |
| 1142 | extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 1143 | #endif |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 1144 | |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 1145 | #if defined(OS_CHROMEOS) |
| 1146 | extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart); |
| 1147 | #endif // defined(OS_CHROMEOS) |
| 1148 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1149 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1150 | extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1151 | #endif |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 1152 | |
Sigurdur Asgeirsson | 7069667 | 2019-02-08 16:14:51 | [diff] [blame] | 1153 | extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart); |
Sigurdur Asgeirsson | 50945f9 | 2019-01-25 20:26:01 | [diff] [blame] | 1154 | |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 1155 | gpu_binder_registry_.AddInterface( |
Mike Wittman | 16fa536 | 2018-09-04 17:27:30 | [diff] [blame] | 1156 | base::Bind(&metrics::CallStackProfileCollector::Create)); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | ChromeContentBrowserClient::~ChromeContentBrowserClient() { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1160 | for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i) |
| 1161 | delete extra_parts_[i]; |
| 1162 | extra_parts_.clear(); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1163 | } |
| 1164 | |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 1165 | // static |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1166 | void ChromeContentBrowserClient::RegisterLocalStatePrefs( |
| 1167 | PrefRegistrySimple* registry) { |
| 1168 | registry->RegisterStringPref(prefs::kIsolateOrigins, std::string()); |
| 1169 | registry->RegisterBooleanPref(prefs::kSitePerProcess, false); |
Chris Hamilton | 8206aad | 2018-07-18 01:00:03 | [diff] [blame] | 1170 | registry->RegisterBooleanPref(prefs::kTabLifecyclesEnabled, true); |
Julian Pastarmov | fac2800 | 2018-02-01 11:17:45 | [diff] [blame] | 1171 | registry->RegisterBooleanPref(prefs::kWebDriverOverridesIncompatiblePolicies, |
| 1172 | false); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | // static |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 1176 | void ChromeContentBrowserClient::RegisterProfilePrefs( |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 1177 | user_prefs::PrefRegistrySyncable* registry) { |
raymes | aa60872 | 2015-04-27 03:00:25 | [diff] [blame] | 1178 | registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false); |
| 1179 | registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true); |
| 1180 | registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures); |
Pavol Marko | 6adbea7f | 2018-02-20 16:35:28 | [diff] [blame] | 1181 | // Register user prefs for mapping SitePerProcess and IsolateOrigins in |
| 1182 | // user policy in addition to the same named ones in Local State (which are |
| 1183 | // used for mapping the command-line flags). |
| 1184 | registry->RegisterStringPref(prefs::kIsolateOrigins, std::string()); |
| 1185 | registry->RegisterBooleanPref(prefs::kSitePerProcess, false); |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 1186 | registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins); |
Rayan Kanso | 411e84e | 2019-02-13 15:27:40 | [diff] [blame] | 1187 | registry->RegisterDictionaryPref( |
| 1188 | prefs::kDevToolsBackgroundServicesExpirationDict); |
Kunihiko Sakamoto | f586da6 | 2019-03-28 03:03:04 | [diff] [blame] | 1189 | registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 1190 | #if !defined(OS_ANDROID) |
| 1191 | registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false); |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 1192 | registry->RegisterListPref(prefs::kAutoplayWhitelist); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 1193 | #endif |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 1194 | } |
| 1195 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1196 | // static |
| 1197 | void ChromeContentBrowserClient::SetApplicationLocale( |
| 1198 | const std::string& locale) { |
Scott Violet | 875789e | 2018-02-02 07:46:48 | [diff] [blame] | 1199 | // The common case is that this function is called early in Chrome startup |
| 1200 | // before any threads are created or registered. When there are no threads, |
| 1201 | // we can just set the string without worrying about threadsafety. |
Gabriel Charette | 192b8c9 | 2018-03-21 21:16:00 | [diff] [blame] | 1202 | if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) { |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 1203 | GetIOThreadApplicationLocale() = locale; |
Scott Violet | 875789e | 2018-02-02 07:46:48 | [diff] [blame] | 1204 | return; |
| 1205 | } |
| 1206 | |
| 1207 | // Otherwise we're being called to change the locale. In this case set it on |
| 1208 | // the IO thread. |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 1209 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1210 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 1211 | base::PostTaskWithTraits( |
| 1212 | FROM_HERE, {BrowserThread::IO}, |
Scott Violet | 875789e | 2018-02-02 07:46:48 | [diff] [blame] | 1213 | base::BindOnce(&SetApplicationLocaleOnIOThread, locale)); |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1214 | } |
| 1215 | |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1216 | std::unique_ptr<content::BrowserMainParts> |
| 1217 | ChromeContentBrowserClient::CreateBrowserMainParts( |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1218 | const content::MainFunctionParams& parameters) { |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1219 | std::unique_ptr<ChromeBrowserMainParts> main_parts; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1220 | // Construct the Main browser parts based on the OS type. |
| 1221 | #if defined(OS_WIN) |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 1222 | main_parts = |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1223 | std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_); |
| 1224 | #elif defined(OS_MACOSX) |
| 1225 | main_parts = |
| 1226 | std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_); |
| 1227 | #elif defined(OS_CHROMEOS) |
| 1228 | main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>( |
| 1229 | parameters, startup_data_); |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 1230 | #elif defined(OS_LINUX) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1231 | main_parts = |
| 1232 | std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_); |
[email protected] | 6e677a34 | 2012-02-11 01:21:14 | [diff] [blame] | 1233 | #elif defined(OS_ANDROID) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1234 | main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters, |
| 1235 | startup_data_); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1236 | #elif defined(OS_POSIX) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1237 | main_parts = |
| 1238 | std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1239 | #else |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1240 | NOTREACHED(); |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1241 | main_parts = |
| 1242 | std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1243 | #endif |
| 1244 | |
Xi Han | 9fd4400 | 2019-04-30 17:39:36 | [diff] [blame] | 1245 | bool add_profiles_extra_parts = true; |
| 1246 | #if defined(OS_ANDROID) |
| 1247 | if (startup_data_->HasBuiltProfilePrefService()) |
| 1248 | add_profiles_extra_parts = false; |
| 1249 | #endif |
| 1250 | if (add_profiles_extra_parts) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1251 | chrome::AddProfilesExtraParts(main_parts.get()); |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 1252 | |
Xi Han | 9fd4400 | 2019-04-30 17:39:36 | [diff] [blame] | 1253 | // Construct additional browser parts. Stages are called in the order in |
| 1254 | // which they are added. |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 1255 | #if defined(TOOLKIT_VIEWS) |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 1256 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 1257 | #if defined(USE_X11) |
| 1258 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinuxX11()); |
| 1259 | #else |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 1260 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux()); |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 1261 | #endif // USE_X11 |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 1262 | #else |
riajiang | 7d6ec5c | 2017-01-25 16:40:33 | [diff] [blame] | 1263 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); |
James Cook | f9d34d2 | 2017-10-04 16:39:35 | [diff] [blame] | 1264 | #endif |
| 1265 | #endif |
| 1266 | |
| 1267 | #if defined(OS_CHROMEOS) |
| 1268 | // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos. |
riajiang | 7d6ec5c | 2017-01-25 16:40:33 | [diff] [blame] | 1269 | main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh()); |
sky | cea631e | 2016-12-16 21:52:22 | [diff] [blame] | 1270 | #endif |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 1271 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 1272 | #if defined(USE_X11) |
| 1273 | main_parts->AddParts(new ChromeBrowserMainExtraPartsX11()); |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 1274 | #endif |
| 1275 | |
Sigurdur Asgeirsson | 54b7270 | 2019-04-12 14:18:54 | [diff] [blame] | 1276 | main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager); |
Etienne Bergeron | 05d6253 | 2017-10-13 18:24:00 | [diff] [blame] | 1277 | |
Albert J. Wong | 59d85acb | 2017-08-10 00:50:57 | [diff] [blame] | 1278 | main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling); |
Albert J. Wong | 59d85acb | 2017-08-10 00:50:57 | [diff] [blame] | 1279 | |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1280 | chrome::AddMetricsExtraParts(main_parts.get()); |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 1281 | |
Ben Goodger | 1633130 | 2018-01-23 00:43:21 | [diff] [blame] | 1282 | main_parts->AddParts(ChromeService::GetInstance()->CreateExtraParts()); |
| 1283 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1284 | return main_parts; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1285 | } |
| 1286 | |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1287 | void ChromeContentBrowserClient::PostAfterStartupTask( |
Brett Wilson | e1a7042 | 2017-09-12 05:10:09 | [diff] [blame] | 1288 | const base::Location& from_here, |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1289 | const scoped_refptr<base::TaskRunner>& task_runner, |
tzik | 6e42784 | 2017-04-05 10:13:21 | [diff] [blame] | 1290 | base::OnceClosure task) { |
tzik | 070c8ffb | 2017-03-29 05:28:12 | [diff] [blame] | 1291 | AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task)); |
John Abd-El-Malek | 0e82fe7f | 2019-07-27 00:06:29 | [diff] [blame] | 1292 | |
| 1293 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1294 | safe_browsing_service_ = g_browser_process->safe_browsing_service(); |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1295 | } |
| 1296 | |
falken | b09d443f | 2016-04-07 12:36:12 | [diff] [blame] | 1297 | bool ChromeContentBrowserClient::IsBrowserStartupComplete() { |
| 1298 | return AfterStartupTaskUtils::IsBrowserStartupComplete(); |
| 1299 | } |
| 1300 | |
Gabriel Charette | c8cca99 | 2017-08-10 18:21:49 | [diff] [blame] | 1301 | void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() { |
| 1302 | AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); |
| 1303 | } |
| 1304 | |
John Abd-El-Malek | 9d57f9c | 2019-02-20 18:50:04 | [diff] [blame] | 1305 | bool ChromeContentBrowserClient::IsShuttingDown() { |
| 1306 | return browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID; |
| 1307 | } |
| 1308 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 1309 | std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1310 | content::BrowserContext* browser_context, |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 1311 | const GURL& site) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1312 | std::string partition_id; |
| 1313 | |
| 1314 | // The partition ID for webview guest processes is the string value of its |
| 1315 | // SiteInstance URL - "chrome-guest://app_id/persist?partition". |
rogerta | 5f5bb82 | 2015-12-17 03:24:45 | [diff] [blame] | 1316 | if (site.SchemeIs(content::kGuestScheme)) |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1317 | partition_id = site.spec(); |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1318 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
blundell | f650ea0 | 2016-02-08 11:50:50 | [diff] [blame] | 1319 | // The partition ID for extensions with isolated storage is treated similarly |
| 1320 | // to the above. |
| 1321 | else if (site.SchemeIs(extensions::kExtensionScheme) && |
| 1322 | extensions::util::SiteHasIsolatedStorage(site, browser_context)) |
| 1323 | partition_id = site.spec(); |
| 1324 | #endif |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1325 | |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 1326 | DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1327 | return partition_id; |
| 1328 | } |
| 1329 | |
| 1330 | bool ChromeContentBrowserClient::IsValidStoragePartitionId( |
| 1331 | content::BrowserContext* browser_context, |
| 1332 | const std::string& partition_id) { |
| 1333 | // The default ID is empty and is always valid. |
| 1334 | if (partition_id.empty()) |
| 1335 | return true; |
| 1336 | |
| 1337 | return GURL(partition_id).is_valid(); |
| 1338 | } |
| 1339 | |
| 1340 | void ChromeContentBrowserClient::GetStoragePartitionConfigForSite( |
| 1341 | content::BrowserContext* browser_context, |
| 1342 | const GURL& site, |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1343 | bool can_be_default, |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1344 | std::string* partition_domain, |
| 1345 | std::string* partition_name, |
| 1346 | bool* in_memory) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1347 | // Default to the browser-wide storage partition and override based on |site| |
| 1348 | // below. |
| 1349 | partition_domain->clear(); |
| 1350 | partition_name->clear(); |
| 1351 | *in_memory = false; |
| 1352 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1353 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
rogerta | 5f5bb82 | 2015-12-17 03:24:45 | [diff] [blame] | 1354 | bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite( |
[email protected] | 3f24f97c | 2013-11-17 21:53:33 | [diff] [blame] | 1355 | site, partition_domain, partition_name, in_memory); |
| 1356 | |
| 1357 | if (!success && site.SchemeIs(extensions::kExtensionScheme)) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1358 | // If |can_be_default| is false, the caller is stating that the |site| |
| 1359 | // should be parsed as if it had isolated storage. In particular it is |
| 1360 | // important to NOT check ExtensionService for the is_storage_isolated() |
| 1361 | // attribute because this code path is run during Extension uninstall |
| 1362 | // to do cleanup after the Extension has already been unloaded from the |
| 1363 | // ExtensionService. |
| 1364 | bool is_isolated = !can_be_default; |
| 1365 | if (can_be_default) { |
[email protected] | ca033634 | 2014-03-21 12:58:34 | [diff] [blame] | 1366 | if (extensions::util::SiteHasIsolatedStorage(site, browser_context)) |
| 1367 | is_isolated = true; |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1368 | } |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1369 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1370 | if (is_isolated) { |
| 1371 | CHECK(site.has_host()); |
| 1372 | // For extensions with isolated storage, the the host of the |site| is |
| 1373 | // the |partition_domain|. The |in_memory| and |partition_name| are only |
| 1374 | // used in guest schemes so they are cleared here. |
| 1375 | *partition_domain = site.host(); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1376 | *in_memory = false; |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1377 | partition_name->clear(); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1378 | } |
[email protected] | 1df3d97 | 2014-06-11 04:55:18 | [diff] [blame] | 1379 | success = true; |
| 1380 | } |
| 1381 | #endif |
| 1382 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1383 | // Assert that if |can_be_default| is false, the code above must have found a |
| 1384 | // non-default partition. If this fails, the caller has a serious logic |
| 1385 | // error about which StoragePartition they expect to be in and it is not |
| 1386 | // safe to continue. |
| 1387 | CHECK(can_be_default || !partition_domain->empty()); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 1388 | } |
| 1389 | |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 1390 | content::WebContentsViewDelegate* |
| 1391 | ChromeContentBrowserClient::GetWebContentsViewDelegate( |
| 1392 | content::WebContents* web_contents) { |
cm.sanchi | 2db24a8 | 2017-11-16 07:22:10 | [diff] [blame] | 1393 | return CreateWebContentsViewDelegate(web_contents); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 1394 | } |
| 1395 | |
Bo Liu | 4ade6b1b2 | 2017-11-28 02:26:35 | [diff] [blame] | 1396 | bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() { |
| 1397 | #if defined(OS_ANDROID) |
| 1398 | const base::android::ApplicationState app_state = |
| 1399 | base::android::ApplicationStatusListener::GetState(); |
| 1400 | return base::android::APPLICATION_STATE_UNKNOWN == app_state || |
| 1401 | base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state || |
| 1402 | base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state; |
| 1403 | #else |
| 1404 | return true; |
| 1405 | #endif |
| 1406 | } |
| 1407 | |
[email protected] | 6f286274 | 2013-12-20 07:53:19 | [diff] [blame] | 1408 | void ChromeContentBrowserClient::RenderProcessWillLaunch( |
Ben Goodger | 1633130 | 2018-01-23 00:43:21 | [diff] [blame] | 1409 | content::RenderProcessHost* host, |
| 1410 | service_manager::mojom::ServiceRequest* service_request) { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1411 | int id = host->GetID(); |
| 1412 | Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
horo | 062ef535 | 2017-03-29 08:16:07 | [diff] [blame] | 1413 | host->AddFilter(new ChromeRenderMessageFilter(id, profile)); |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 1414 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | b79dd6ba | 2018-12-07 01:20:49 | [diff] [blame] | 1415 | host->AddFilter(new cast::CastTransportHostFilter()); |
thestig | 73f4cdc | 2015-01-15 01:51:06 | [diff] [blame] | 1416 | #endif |
Brett Wilson | 65f951c | 2016-11-03 22:06:12 | [diff] [blame] | 1417 | #if BUILDFLAG(ENABLE_PRINTING) |
[email protected] | 168b7799 | 2014-08-20 11:48:40 | [diff] [blame] | 1418 | host->AddFilter(new printing::PrintingMessageFilter(id, profile)); |
[email protected] | 058e573 | 2012-03-01 22:48:03 | [diff] [blame] | 1419 | #endif |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 1420 | host->AddFilter(new prerender::PrerenderMessageFilter(id, profile)); |
thestig | 397accd | 2015-04-04 00:03:04 | [diff] [blame] | 1421 | host->AddFilter(new TtsMessageFilter(host->GetBrowserContext())); |
Darin Fisher | 8c84328c | 2019-07-23 02:50:00 | [diff] [blame] | 1422 | |
| 1423 | WebRtcLoggingHandlerHost::AttachToRenderProcessHost( |
| 1424 | host, g_browser_process->webrtc_log_uploader()); |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1425 | |
grunell | 086a411 | 2017-03-02 09:23:04 | [diff] [blame] | 1426 | // The audio manager outlives the host, so it's safe to hand a raw pointer to |
| 1427 | // it to the AudioDebugRecordingsHandler, which is owned by the host. |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1428 | AudioDebugRecordingsHandler* audio_debug_recordings_handler = |
Marina Ciocea | 741a4fb1 | 2018-01-27 09:55:12 | [diff] [blame] | 1429 | new AudioDebugRecordingsHandler(profile); |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1430 | host->SetUserData( |
| 1431 | AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey, |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 1432 | std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>( |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1433 | audio_debug_recordings_handler)); |
| 1434 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 1435 | #if BUILDFLAG(ENABLE_NACL) |
Helen Li | 8897b02 | 2018-05-03 13:29:03 | [diff] [blame] | 1436 | host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(), |
| 1437 | profile->GetPath())); |
[email protected] | 01e5975 | 2013-06-18 00:17:35 | [diff] [blame] | 1438 | #endif |
jeremyim | 364ac118 | 2015-03-03 18:49:43 | [diff] [blame] | 1439 | |
Xiaohan Wang | 9b34281b | 2017-09-08 23:48:33 | [diff] [blame] | 1440 | #if defined(OS_ANDROID) |
| 1441 | // Data cannot be persisted if the profile is off the record. |
| 1442 | host->AddFilter( |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 1443 | new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false)); |
Yuzu Saijo | 2d12ef9 | 2018-08-21 04:52:07 | [diff] [blame] | 1444 | |
| 1445 | // Register CrashMemoryMetricsCollector to report oom related metrics. |
| 1446 | host->SetUserData( |
| 1447 | CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey, |
| 1448 | std::make_unique<CrashMemoryMetricsCollector>(host)); |
Xiaohan Wang | 9b34281b | 2017-09-08 23:48:33 | [diff] [blame] | 1449 | #endif |
| 1450 | |
Jun Cai | db3f93cc | 2018-07-09 21:54:55 | [diff] [blame] | 1451 | Profile* original_profile = profile->GetOriginalProfile(); |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 1452 | RendererUpdaterFactory::GetForProfile(original_profile) |
| 1453 | ->InitializeRenderer(host); |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 1454 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1455 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1456 | extra_parts_[i]->RenderProcessWillLaunch(host); |
[email protected] | edece21 | 2011-11-16 11:56:56 | [diff] [blame] | 1457 | |
Ken Rockot | 40a1df79 | 2019-05-08 22:15:52 | [diff] [blame] | 1458 | mojo::PendingRemote<service_manager::mojom::Service> service; |
| 1459 | *service_request = service.InitWithNewPipeAndPassReceiver(); |
Ben Goodger | 1633130 | 2018-01-23 00:43:21 | [diff] [blame] | 1460 | service_manager::Identity renderer_identity = host->GetChildIdentity(); |
Ken Rockot | 0adc1e4 | 2019-05-24 08:20:08 | [diff] [blame] | 1461 | mojo::Remote<service_manager::mojom::ProcessMetadata> metadata; |
Ken Rockot | a86fa54 | 2018-11-13 21:47:13 | [diff] [blame] | 1462 | ChromeService::GetInstance()->connector()->RegisterServiceInstance( |
Ben Goodger | 1633130 | 2018-01-23 00:43:21 | [diff] [blame] | 1463 | service_manager::Identity(chrome::mojom::kRendererServiceName, |
Ken Rockot | d2ed25a | 2018-11-06 22:25:37 | [diff] [blame] | 1464 | renderer_identity.instance_group(), |
Ken Rockot | a86fa54 | 2018-11-13 21:47:13 | [diff] [blame] | 1465 | renderer_identity.instance_id(), |
| 1466 | base::Token::CreateRandom()), |
Ken Rockot | 0adc1e4 | 2019-05-24 08:20:08 | [diff] [blame] | 1467 | std::move(service), metadata.BindNewPipeAndPassReceiver()); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 1468 | } |
| 1469 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1470 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
Alex Moshchuk | bb99a33 | 2017-11-22 04:49:57 | [diff] [blame] | 1471 | content::BrowserContext* browser_context, |
Alex Moshchuk | a31c788 | 2018-01-17 00:57:30 | [diff] [blame] | 1472 | const GURL& url) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1473 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1474 | if (!profile) |
| 1475 | return url; |
| 1476 | |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1477 | #if !defined(OS_ANDROID) |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 1478 | // If the input |url| should be assigned to the Instant renderer, make its |
| 1479 | // effective URL distinct from other URLs on the search provider's domain. |
Alex Moshchuk | ca17137 | 2017-11-28 16:11:31 | [diff] [blame] | 1480 | // This needs to happen even if |url| corresponds to an isolated origin; see |
| 1481 | // https://crbug.com/755595. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1482 | if (search::ShouldAssignURLToInstantRenderer(url, profile)) |
| 1483 | return search::GetEffectiveURLForInstant(url, profile); |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1484 | #endif |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 1485 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1486 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Alex Moshchuk | a31c788 | 2018-01-17 00:57:30 | [diff] [blame] | 1487 | return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile, |
| 1488 | url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1489 | #else |
| 1490 | return url; |
| 1491 | #endif |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1492 | } |
| 1493 | |
Alexander Yashkin | 6aedc6e | 2018-08-15 08:58:45 | [diff] [blame] | 1494 | bool ChromeContentBrowserClient:: |
| 1495 | ShouldCompareEffectiveURLsForSiteInstanceSelection( |
| 1496 | content::BrowserContext* browser_context, |
| 1497 | content::SiteInstance* candidate_site_instance, |
| 1498 | bool is_main_frame, |
| 1499 | const GURL& candidate_url, |
| 1500 | const GURL& destination_url) { |
| 1501 | DCHECK(browser_context); |
| 1502 | DCHECK(candidate_site_instance); |
| 1503 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1504 | return ChromeContentBrowserClientExtensionsPart:: |
| 1505 | ShouldCompareEffectiveURLsForSiteInstanceSelection( |
| 1506 | browser_context, candidate_site_instance, is_main_frame, |
| 1507 | candidate_url, destination_url); |
| 1508 | #else |
| 1509 | return true; |
| 1510 | #endif |
| 1511 | } |
| 1512 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 1513 | bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() { |
Ahmed Fakhry | e6a2c64 | 2018-06-20 02:58:41 | [diff] [blame] | 1514 | #if defined(OS_ANDROID) |
| 1515 | return true; |
| 1516 | #elif defined(OS_CHROMEOS) |
Huanzhong Huang | afa9809 | 2019-06-24 12:01:24 | [diff] [blame] | 1517 | return TabletModeClient::Get() && |
| 1518 | TabletModeClient::Get()->tablet_mode_enabled(); |
Ahmed Fakhry | e6a2c64 | 2018-06-20 02:58:41 | [diff] [blame] | 1519 | #else |
| 1520 | return false; |
| 1521 | #endif // defined(OS_ANDROID) |
| 1522 | } |
| 1523 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1524 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1525 | content::BrowserContext* browser_context, const GURL& effective_url) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1526 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1527 | if (!profile) |
| 1528 | return false; |
| 1529 | |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1530 | // NTP should use process-per-site. This is a performance optimization to |
| 1531 | // reduce process count associated with NTP tabs. |
| 1532 | if (effective_url == GURL(chrome::kChromeUINewTabURL)) |
| 1533 | return true; |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1534 | #if !defined(OS_ANDROID) |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1535 | if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile)) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1536 | return true; |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1537 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1538 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1539 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1540 | if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite( |
| 1541 | profile, effective_url)) |
| 1542 | return true; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1543 | #endif |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1544 | |
| 1545 | // Non-extension, non-NTP URLs should generally use process-per-site-instance |
| 1546 | // (rather than process-per-site). |
| 1547 | return false; |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1548 | } |
| 1549 | |
Lukasz Anforowicz | 32d2712 | 2018-04-09 21:48:33 | [diff] [blame] | 1550 | bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost( |
| 1551 | content::BrowserContext* browser_context, |
| 1552 | const GURL& site_url) { |
| 1553 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1554 | if (!profile) |
| 1555 | return false; |
| 1556 | |
| 1557 | #if !defined(OS_ANDROID) |
| 1558 | // Instant renderers should not use a spare process, because they require |
| 1559 | // passing switches::kInstantProcess to the renderer process when it |
| 1560 | // launches. A spare process is launched earlier, before it is known which |
| 1561 | // navigation will use it, so it lacks this flag. |
| 1562 | if (search::ShouldAssignURLToInstantRenderer(site_url, profile)) |
| 1563 | return false; |
| 1564 | #endif |
| 1565 | |
| 1566 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1567 | return ChromeContentBrowserClientExtensionsPart:: |
| 1568 | ShouldUseSpareRenderProcessHost(profile, site_url); |
| 1569 | #else |
| 1570 | return true; |
| 1571 | #endif |
| 1572 | } |
| 1573 | |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1574 | bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess( |
Lukasz Anforowicz | 4aff3b8 | 2019-04-04 16:00:33 | [diff] [blame] | 1575 | content::BrowserOrResourceContext browser_or_resource_context, |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1576 | const GURL& effective_site_url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1577 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1578 | if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess( |
Lukasz Anforowicz | 4aff3b8 | 2019-04-04 16:00:33 | [diff] [blame] | 1579 | browser_or_resource_context, effective_site_url)) { |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1580 | return true; |
| 1581 | } |
| 1582 | #endif |
| 1583 | return false; |
| 1584 | } |
| 1585 | |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1586 | // TODO(creis, nick): https://crbug.com/160576 describes a weakness in our |
| 1587 | // origin-lock enforcement, where we don't have a way to efficiently know |
| 1588 | // effective URLs on the IO thread, and wind up killing processes that e.g. |
| 1589 | // request cookies for their actual URL. This whole function (and its |
| 1590 | // ExtensionsPart) should be removed once we add that ability to the IO thread. |
| 1591 | bool ChromeContentBrowserClient::ShouldLockToOrigin( |
| 1592 | content::BrowserContext* browser_context, |
| 1593 | const GURL& effective_site_url) { |
| 1594 | // Origin lock to the search scheme would kill processes upon legitimate |
| 1595 | // requests for cookies from the search engine's domain. |
| 1596 | if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme)) |
| 1597 | return false; |
| 1598 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1599 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1600 | if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin( |
| 1601 | browser_context, effective_site_url)) { |
| 1602 | return false; |
| 1603 | } |
| 1604 | #endif |
| 1605 | return true; |
creis | e5d6d173 | 2015-08-25 19:47:06 | [diff] [blame] | 1606 | } |
| 1607 | |
Lukasz Anforowicz | 05f356e | 2018-03-13 20:26:11 | [diff] [blame] | 1608 | const char* |
Lukasz Anforowicz | ce869f0b | 2018-08-06 18:33:37 | [diff] [blame] | 1609 | ChromeContentBrowserClient::GetInitiatorSchemeBypassingDocumentBlocking() { |
Charles Reis | 358baf47 | 2017-12-06 05:30:43 | [diff] [blame] | 1610 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | 05f356e | 2018-03-13 20:26:11 | [diff] [blame] | 1611 | // Don't block responses for extension processes or for content scripts. |
| 1612 | // TODO(creis): When every extension fetch (including content scripts) has |
| 1613 | // been made to go through an extension-specific URLLoaderFactory, this |
| 1614 | // mechanism ought to work by enumerating the host permissions from the |
| 1615 | // extension manifest, and forwarding them on to the network service while |
| 1616 | // brokering the URLLoaderFactory. |
| 1617 | return extensions::kExtensionScheme; |
| 1618 | #else |
| 1619 | return nullptr; |
Charles Reis | 358baf47 | 2017-12-06 05:30:43 | [diff] [blame] | 1620 | #endif |
Charles Reis | 358baf47 | 2017-12-06 05:30:43 | [diff] [blame] | 1621 | } |
| 1622 | |
Maks Orlovich | 0e23e31 | 2019-07-16 13:13:56 | [diff] [blame] | 1623 | bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel( |
| 1624 | base::StringPiece scheme) { |
| 1625 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1626 | return scheme == extensions::kExtensionScheme; |
| 1627 | #else |
| 1628 | return false; |
| 1629 | #endif |
| 1630 | } |
| 1631 | |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1632 | network::mojom::URLLoaderFactoryPtrInfo |
| 1633 | ChromeContentBrowserClient::CreateURLLoaderFactoryForNetworkRequests( |
| 1634 | content::RenderProcessHost* process, |
| 1635 | network::mojom::NetworkContext* network_context, |
Clark DuVall | a5e25b75 | 2018-11-27 22:08:16 | [diff] [blame] | 1636 | network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client, |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1637 | const url::Origin& request_initiator) { |
| 1638 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1639 | return ChromeContentBrowserClientExtensionsPart:: |
Clark DuVall | a5e25b75 | 2018-11-27 22:08:16 | [diff] [blame] | 1640 | CreateURLLoaderFactoryForNetworkRequests( |
| 1641 | process, network_context, header_client, request_initiator); |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1642 | #else |
| 1643 | return network::mojom::URLLoaderFactoryPtrInfo(); |
| 1644 | #endif |
| 1645 | } |
| 1646 | |
[email protected] | 73b718f | 2014-01-27 02:59:46 | [diff] [blame] | 1647 | // These are treated as WebUI schemes but do not get WebUI bindings. Also, |
| 1648 | // view-source is allowed for these schemes. |
[email protected] | 8f89dd41 | 2013-04-17 02:35:41 | [diff] [blame] | 1649 | void ChromeContentBrowserClient::GetAdditionalWebUISchemes( |
| 1650 | std::vector<std::string>* additional_schemes) { |
| 1651 | additional_schemes->push_back(chrome::kChromeSearchScheme); |
[email protected] | 474a5a3 | 2014-07-28 18:23:24 | [diff] [blame] | 1652 | additional_schemes->push_back(dom_distiller::kDomDistillerScheme); |
Andrey Kosyakov | 031e9e3 | 2017-08-18 21:00:35 | [diff] [blame] | 1653 | additional_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1654 | } |
| 1655 | |
alexmos | 94875b3b | 2017-03-16 22:19:01 | [diff] [blame] | 1656 | void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes( |
| 1657 | std::vector<std::string>* additional_schemes) { |
| 1658 | GetAdditionalWebUISchemes(additional_schemes); |
| 1659 | |
| 1660 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1661 | additional_schemes->push_back(extensions::kExtensionScheme); |
| 1662 | #endif |
| 1663 | } |
| 1664 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 1665 | bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) { |
dbeam | baee5bd | 2015-09-26 03:07:01 | [diff] [blame] | 1666 | return webui::LogWebUIUrl(web_ui_url); |
| 1667 | } |
| 1668 | |
John Abd-El-Malek | 04bfa853 | 2018-07-12 05:28:22 | [diff] [blame] | 1669 | bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests( |
| 1670 | const url::Origin& origin) { |
| 1671 | return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests( |
| 1672 | origin); |
| 1673 | } |
| 1674 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 1675 | bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { |
| 1676 | return ProfileIOData::IsHandledURL(url); |
| 1677 | } |
| 1678 | |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1679 | bool ChromeContentBrowserClient::CanCommitURL( |
| 1680 | content::RenderProcessHost* process_host, |
| 1681 | const GURL& url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1682 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1683 | return ChromeContentBrowserClientExtensionsPart::CanCommitURL( |
| 1684 | process_host, url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1685 | #else |
| 1686 | return true; |
| 1687 | #endif |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1688 | } |
| 1689 | |
[email protected] | 9a60d160 | 2013-09-11 04:09:12 | [diff] [blame] | 1690 | bool ChromeContentBrowserClient::ShouldAllowOpenURL( |
| 1691 | content::SiteInstance* site_instance, const GURL& url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1692 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1693 | bool result; |
| 1694 | if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL( |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1695 | site_instance, url, &result)) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1696 | return result; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1697 | #endif |
[email protected] | 879816a9 | 2014-04-29 00:53:54 | [diff] [blame] | 1698 | |
| 1699 | // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since |
| 1700 | // the signin page may host untrusted web content. |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1701 | GURL from_url = site_instance->GetSiteURL(); |
[email protected] | 879816a9 | 2014-04-29 00:53:54 | [diff] [blame] | 1702 | if (from_url.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL && |
| 1703 | url.SchemeIs(content::kChromeUIScheme) && |
brettw | b65cd5c | 2016-01-23 00:46:38 | [diff] [blame] | 1704 | url.host_piece() != chrome::kChromeUIChromeSigninHost) { |
[email protected] | 879816a9 | 2014-04-29 00:53:54 | [diff] [blame] | 1705 | VLOG(1) << "Blocked navigation to " << url.spec() << " from " |
| 1706 | << chrome::kChromeUIChromeSigninURL; |
| 1707 | return false; |
| 1708 | } |
| 1709 | |
[email protected] | 9a60d160 | 2013-09-11 04:09:12 | [diff] [blame] | 1710 | return true; |
| 1711 | } |
| 1712 | |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1713 | void ChromeContentBrowserClient::OverrideNavigationParams( |
| 1714 | SiteInstance* site_instance, |
| 1715 | ui::PageTransition* transition, |
| 1716 | bool* is_renderer_initiated, |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1717 | content::Referrer* referrer, |
| 1718 | base::Optional<url::Origin>* initiator_origin) { |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1719 | DCHECK(transition); |
| 1720 | DCHECK(is_renderer_initiated); |
| 1721 | DCHECK(referrer); |
Moe Ahmadi | 26e2f50 | 2019-07-16 02:34:47 | [diff] [blame] | 1722 | // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to |
| 1723 | // use for making security decisions 99.44% of the time, for detecting the NTP |
| 1724 | // it is reliable and the correct way. See http://crbug.com/624410. |
| 1725 | if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) && |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1726 | ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) { |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1727 | // Clicks on tiles of the new tab page should be treated as if a user |
| 1728 | // clicked on a bookmark. This is consistent with native implementations |
| 1729 | // like Android's. This also helps ensure that security features (like |
| 1730 | // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as |
| 1731 | // browser-initiated. |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1732 | *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK; |
| 1733 | *is_renderer_initiated = false; |
| 1734 | *referrer = content::Referrer(); |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1735 | *initiator_origin = base::nullopt; |
mastiz | a77db699 | 2016-06-30 09:48:42 | [diff] [blame] | 1736 | } |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1737 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1738 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1739 | ChromeContentBrowserClientExtensionsPart::OverrideNavigationParams( |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1740 | site_instance, transition, is_renderer_initiated, referrer, |
| 1741 | initiator_origin); |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1742 | #endif |
mastiz | a77db699 | 2016-06-30 09:48:42 | [diff] [blame] | 1743 | } |
| 1744 | |
Charles Reis | 29e9dd1 | 2017-09-28 00:59:15 | [diff] [blame] | 1745 | bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP( |
| 1746 | const GURL& url, |
| 1747 | SiteInstance* parent_site_instance) { |
Moe Ahmadi | 26e2f50 | 2019-07-16 02:34:47 | [diff] [blame] | 1748 | // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to |
| 1749 | // use for making security decisions 99.44% of the time, for detecting the NTP |
| 1750 | // it is reliable and the correct way. See http://crbug.com/624410. |
| 1751 | return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance && |
| 1752 | search::IsNTPURL(parent_site_instance->GetSiteURL()); |
Charles Reis | 29e9dd1 | 2017-09-28 00:59:15 | [diff] [blame] | 1753 | } |
| 1754 | |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1755 | bool ChromeContentBrowserClient::IsSuitableHost( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1756 | content::RenderProcessHost* process_host, |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1757 | const GURL& site_url) { |
| 1758 | Profile* profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1759 | Profile::FromBrowserContext(process_host->GetBrowserContext()); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1760 | // This may be NULL during tests. In that case, just assume any site can |
| 1761 | // share any host. |
| 1762 | if (!profile) |
| 1763 | return true; |
| 1764 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1765 | #if !defined(OS_ANDROID) |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1766 | // Instant URLs should only be in the instant process and instant process |
| 1767 | // should only have Instant URLs. |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1768 | InstantService* instant_service = |
| 1769 | InstantServiceFactory::GetForProfile(profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1770 | if (instant_service) { |
| 1771 | bool is_instant_process = instant_service->IsInstantProcess( |
| 1772 | process_host->GetID()); |
| 1773 | bool should_be_in_instant_process = |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1774 | search::ShouldAssignURLToInstantRenderer(site_url, profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1775 | if (is_instant_process || should_be_in_instant_process) |
| 1776 | return is_instant_process && should_be_in_instant_process; |
| 1777 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1778 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1779 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1780 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1781 | return ChromeContentBrowserClientExtensionsPart::IsSuitableHost( |
| 1782 | profile, process_host, site_url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1783 | #else |
| 1784 | return true; |
| 1785 | #endif |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1786 | } |
| 1787 | |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1788 | bool ChromeContentBrowserClient::MayReuseHost( |
| 1789 | content::RenderProcessHost* process_host) { |
| 1790 | // If there is currently a prerender in progress for the host provided, |
| 1791 | // it may not be shared. We require prerenders to be by themselves in a |
davidben | 879199c | 2015-03-06 00:55:04 | [diff] [blame] | 1792 | // separate process so that we can monitor their resource usage. |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1793 | prerender::PrerenderManager* prerender_manager = |
droger | c154315 | 2016-09-20 13:03:37 | [diff] [blame] | 1794 | prerender::PrerenderManagerFactory::GetForBrowserContext( |
| 1795 | process_host->GetBrowserContext()); |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1796 | if (prerender_manager && |
[email protected] | 2290af2 | 2014-05-26 15:44:49 | [diff] [blame] | 1797 | !prerender_manager->MayReuseProcessHost(process_host)) { |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1798 | return false; |
| 1799 | } |
| 1800 | |
| 1801 | return true; |
| 1802 | } |
| 1803 | |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1804 | bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( |
| 1805 | content::BrowserContext* browser_context, const GURL& url) { |
| 1806 | // It has to be a valid URL for us to check for an extension. |
| 1807 | if (!url.is_valid()) |
| 1808 | return false; |
| 1809 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1810 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1811 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1812 | return ChromeContentBrowserClientExtensionsPart:: |
| 1813 | ShouldTryToUseExistingProcessHost( |
| 1814 | profile, url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1815 | #else |
| 1816 | return false; |
| 1817 | #endif |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1818 | } |
| 1819 | |
Alex Moshchuk | 9c9e388 | 2018-11-02 19:57:03 | [diff] [blame] | 1820 | bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess( |
| 1821 | content::RenderFrameHost* main_frame) { |
| 1822 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1823 | return ChromeContentBrowserClientExtensionsPart:: |
| 1824 | ShouldSubframesTryToReuseExistingProcess(main_frame); |
| 1825 | #else |
| 1826 | return true; |
| 1827 | #endif |
| 1828 | } |
| 1829 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1830 | void ChromeContentBrowserClient::SiteInstanceGotProcess( |
| 1831 | SiteInstance* site_instance) { |
| 1832 | CHECK(site_instance->HasProcess()); |
| 1833 | |
| 1834 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 1835 | site_instance->GetBrowserContext()); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1836 | if (!profile) |
| 1837 | return; |
| 1838 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1839 | #if !defined(OS_ANDROID) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1840 | // Remember the ID of the Instant process to signal the renderer process |
| 1841 | // on startup in |AppendExtraCommandLineSwitches| below. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1842 | if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(), |
| 1843 | profile)) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1844 | InstantService* instant_service = |
| 1845 | InstantServiceFactory::GetForProfile(profile); |
| 1846 | if (instant_service) |
| 1847 | instant_service->AddInstantProcess(site_instance->GetProcess()->GetID()); |
| 1848 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1849 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1850 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1851 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1852 | extra_parts_[i]->SiteInstanceGotProcess(site_instance); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | void ChromeContentBrowserClient::SiteInstanceDeleting( |
| 1856 | SiteInstance* site_instance) { |
| 1857 | if (!site_instance->HasProcess()) |
| 1858 | return; |
| 1859 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1860 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1861 | extra_parts_[i]->SiteInstanceDeleting(site_instance); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1862 | } |
| 1863 | |
[email protected] | 453f543 | 2013-11-26 19:43:00 | [diff] [blame] | 1864 | bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation( |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1865 | SiteInstance* site_instance, |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1866 | const GURL& current_url, |
| 1867 | const GURL& new_url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1868 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1869 | return ChromeContentBrowserClientExtensionsPart:: |
| 1870 | ShouldSwapBrowsingInstancesForNavigation( |
| 1871 | site_instance, current_url, new_url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1872 | #else |
| 1873 | return false; |
| 1874 | #endif |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1875 | } |
| 1876 | |
Nasko Oskov | d83b571 | 2018-05-04 04:50:57 | [diff] [blame] | 1877 | bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) { |
| 1878 | // TODO(nasko): Consider supporting error page isolation in subframes if |
| 1879 | // Site Isolation is enabled. |
Nasko Oskov | 55d21e15 | 2018-06-27 23:59:38 | [diff] [blame] | 1880 | return in_main_frame; |
Nasko Oskov | d83b571 | 2018-05-04 04:50:57 | [diff] [blame] | 1881 | } |
| 1882 | |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 1883 | bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) { |
| 1884 | return !url.SchemeIs(chrome::kChromeNativeScheme); |
| 1885 | } |
| 1886 | |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1887 | std::vector<url::Origin> |
| 1888 | ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() { |
| 1889 | std::vector<url::Origin> isolated_origin_list; |
| 1890 | |
Alex Moshchuk | 89352a7 | 2017-10-25 20:25:59 | [diff] [blame] | 1891 | // Sign-in process isolation is not needed on Android, see |
| 1892 | // https://crbug.com/739418. |
| 1893 | #if !defined(OS_ANDROID) |
Alex Moshchuk | 81d2a29e | 2019-07-16 01:14:38 | [diff] [blame] | 1894 | isolated_origin_list.push_back( |
Alex Moshchuk | 36417aa | 2018-06-13 18:01:12 | [diff] [blame] | 1895 | url::Origin::Create(GaiaUrls::GetInstance()->gaia_url())); |
Alex Moshchuk | 89352a7 | 2017-10-25 20:25:59 | [diff] [blame] | 1896 | #endif |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1897 | |
Alex Moshchuk | 81d2a29e | 2019-07-16 01:14:38 | [diff] [blame] | 1898 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1899 | auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart:: |
| 1900 | GetOriginsRequiringDedicatedProcess(); |
| 1901 | std::move(std::begin(origins_from_extensions), |
| 1902 | std::end(origins_from_extensions), |
| 1903 | std::back_inserter(isolated_origin_list)); |
| 1904 | #endif |
| 1905 | |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1906 | return isolated_origin_list; |
| 1907 | } |
| 1908 | |
Lukasz Anforowicz | 5e201abd | 2018-03-24 00:41:06 | [diff] [blame] | 1909 | bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() { |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1910 | return base::FeatureList::IsEnabled(features::kSitePerProcess); |
| 1911 | } |
| 1912 | |
| 1913 | bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() { |
Lukasz Anforowicz | 0711a0f | 2019-03-28 18:15:31 | [diff] [blame] | 1914 | // Using 1077 rather than 1024 because 1) it helps ensure that devices with |
| 1915 | // exactly 1GB of RAM won't get included because of inaccuracies or off-by-one |
| 1916 | // errors and 2) this is the bucket boundary in Memory.Stats.Win.TotalPhys2. |
| 1917 | // See also https://crbug.com/844118. |
| 1918 | constexpr int kDefaultMemoryThresholdMb = 1077; |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1919 | |
| 1920 | // TODO(acolwell): Rename feature since it now affects more than just the |
| 1921 | // site-per-process case. |
Lukasz Anforowicz | 46275d9 | 2018-04-12 14:57:38 | [diff] [blame] | 1922 | if (base::FeatureList::IsEnabled( |
| 1923 | features::kSitePerProcessOnlyForHighMemoryClients)) { |
Lukasz Anforowicz | 46275d9 | 2018-04-12 14:57:38 | [diff] [blame] | 1924 | int memory_threshold_mb = base::GetFieldTrialParamByFeatureAsInt( |
| 1925 | features::kSitePerProcessOnlyForHighMemoryClients, |
| 1926 | features::kSitePerProcessOnlyForHighMemoryClientsParamName, |
| 1927 | kDefaultMemoryThresholdMb); |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1928 | return base::SysInfo::AmountOfPhysicalMemoryMB() <= memory_threshold_mb; |
Lukasz Anforowicz | 46275d9 | 2018-04-12 14:57:38 | [diff] [blame] | 1929 | } |
| 1930 | |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1931 | #if defined(OS_ANDROID) |
| 1932 | if (base::SysInfo::AmountOfPhysicalMemoryMB() <= kDefaultMemoryThresholdMb) { |
| 1933 | return true; |
| 1934 | } |
| 1935 | #endif |
| 1936 | |
| 1937 | return false; |
Lukasz Anforowicz | 5e201abd | 2018-03-24 00:41:06 | [diff] [blame] | 1938 | } |
| 1939 | |
Alex Moshchuk | 082b5f8 | 2019-03-14 01:34:16 | [diff] [blame] | 1940 | std::vector<std::string> |
| 1941 | ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() { |
| 1942 | if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled()) |
| 1943 | return {"Isolate Password Sites"}; |
| 1944 | else |
| 1945 | return {}; |
| 1946 | } |
| 1947 | |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 1948 | void ChromeContentBrowserClient::PersistIsolatedOrigin( |
| 1949 | content::BrowserContext* context, |
| 1950 | const url::Origin& origin) { |
| 1951 | DCHECK(!context->IsOffTheRecord()); |
| 1952 | Profile* profile = Profile::FromBrowserContext(context); |
| 1953 | ListPrefUpdate update(profile->GetPrefs(), |
| 1954 | prefs::kUserTriggeredIsolatedOrigins); |
| 1955 | base::ListValue* list = update.Get(); |
| 1956 | base::Value value(origin.Serialize()); |
Jan Wilken Dörrie | a8cb5630 | 2019-06-06 18:59:36 | [diff] [blame] | 1957 | if (!base::Contains(list->GetList(), value)) |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 1958 | list->GetList().push_back(std::move(value)); |
| 1959 | } |
| 1960 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 1961 | bool ChromeContentBrowserClient::IsFileAccessAllowed( |
| 1962 | const base::FilePath& path, |
| 1963 | const base::FilePath& absolute_path, |
| 1964 | const base::FilePath& profile_path) { |
| 1965 | return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path, |
| 1966 | profile_path); |
| 1967 | } |
| 1968 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1969 | namespace { |
| 1970 | |
| 1971 | bool IsAutoReloadEnabled() { |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 1972 | const base::CommandLine& browser_command_line = |
| 1973 | *base::CommandLine::ForCurrentProcess(); |
Elly Fong-Jones | 5f13ee1 | 2019-05-10 19:20:35 | [diff] [blame] | 1974 | if (browser_command_line.HasSwitch(switches::kEnableAutoReload)) |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1975 | return true; |
Elly Fong-Jones | 5f13ee1 | 2019-05-10 19:20:35 | [diff] [blame] | 1976 | if (browser_command_line.HasSwitch(switches::kDisableAutoReload)) |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1977 | return false; |
[email protected] | 9ef49b4 | 2014-08-07 16:44:24 | [diff] [blame] | 1978 | return true; |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1979 | } |
| 1980 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1981 | void MaybeAppendBlinkSettingsSwitchForFieldTrial( |
| 1982 | const base::CommandLine& browser_command_line, |
| 1983 | base::CommandLine* command_line) { |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1984 | // List of field trials that modify the blink-settings command line flag. No |
| 1985 | // two field trials in the list should specify the same keys, otherwise one |
| 1986 | // field trial may overwrite another. See Source/core/frame/Settings.in in |
| 1987 | // Blink for the list of valid keys. |
| 1988 | static const char* const kBlinkSettingsFieldTrials[] = { |
jkarlin | 3bddb7d | 2016-09-21 18:44:16 | [diff] [blame] | 1989 | // Keys: disallowFetchForDocWrittenScriptsInMainFrame |
| 1990 | // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections |
| 1991 | // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G |
| 1992 | "DisallowFetchForDocWrittenScriptsInMainFrame", |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1993 | }; |
| 1994 | |
| 1995 | std::vector<std::string> blink_settings; |
| 1996 | for (const char* field_trial_name : kBlinkSettingsFieldTrials) { |
| 1997 | // Each blink-settings field trial should include a forcing_flag group, |
| 1998 | // to make sure that clients that specify the blink-settings flag on the |
| 1999 | // command line are excluded from the experiment groups. To make |
| 2000 | // sure we assign clients that specify this flag to the forcing_flag |
| 2001 | // group, we must call GetVariationParams for each field trial first |
| 2002 | // (for example, before checking HasSwitch() and returning), since |
| 2003 | // GetVariationParams has the side-effect of assigning the client to |
| 2004 | // a field trial group. |
| 2005 | std::map<std::string, std::string> params; |
| 2006 | if (variations::GetVariationParams(field_trial_name, ¶ms)) { |
| 2007 | for (const auto& param : params) { |
| 2008 | blink_settings.push_back(base::StringPrintf( |
| 2009 | "%s=%s", param.first.c_str(), param.second.c_str())); |
| 2010 | } |
| 2011 | } |
| 2012 | } |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 2013 | |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 2014 | if (blink_settings.empty()) { |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2015 | return; |
| 2016 | } |
| 2017 | |
| 2018 | if (browser_command_line.HasSwitch(switches::kBlinkSettings) || |
| 2019 | command_line->HasSwitch(switches::kBlinkSettings)) { |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 2020 | // The field trials should be configured to force users that specify the |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 2021 | // blink-settings flag into a group with no params, and we return |
| 2022 | // above if no params were specified, so it's an error if we reach |
| 2023 | // this point. |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2024 | LOG(WARNING) << "Received field trial params, " |
| 2025 | "but blink-settings switch already specified."; |
| 2026 | return; |
| 2027 | } |
| 2028 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2029 | command_line->AppendSwitchASCII(switches::kBlinkSettings, |
brettw | d94a2214 | 2015-07-15 05:19:26 | [diff] [blame] | 2030 | base::JoinString(blink_settings, ",")); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2031 | } |
| 2032 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 2033 | #if defined(OS_ANDROID) |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 2034 | template <typename Interface> |
| 2035 | void ForwardToJavaFrameRegistry( |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 2036 | mojo::InterfaceRequest<Interface> request, |
| 2037 | content::RenderFrameHost* render_frame_host) { |
| 2038 | render_frame_host->GetJavaInterfaces()->GetInterface(std::move(request)); |
mgiuca | 3d9a196 | 2017-04-07 05:25:44 | [diff] [blame] | 2039 | } |
| 2040 | |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 2041 | template <typename Interface> |
| 2042 | void ForwardToJavaWebContentsRegistry( |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 2043 | mojo::InterfaceRequest<Interface> request, |
| 2044 | content::RenderFrameHost* render_frame_host) { |
| 2045 | content::WebContents* contents = |
| 2046 | content::WebContents::FromRenderFrameHost(render_frame_host); |
| 2047 | if (contents) |
| 2048 | contents->GetJavaInterfaces()->GetInterface(std::move(request)); |
sammc | 0285a44 | 2016-10-04 23:03:56 | [diff] [blame] | 2049 | } |
| 2050 | #endif |
| 2051 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 2052 | } // namespace |
| 2053 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2054 | void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 2055 | base::CommandLine* command_line, |
| 2056 | int child_process_id) { |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2057 | #if defined(OS_MACOSX) |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2058 | std::unique_ptr<metrics::ClientInfo> client_info = |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2059 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
| 2060 | if (client_info) { |
| 2061 | command_line->AppendSwitchASCII(switches::kMetricsClientID, |
| 2062 | client_info->client_id); |
| 2063 | } |
| 2064 | #elif defined(OS_POSIX) |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 2065 | #if defined(OS_ANDROID) |
| 2066 | bool enable_crash_reporter = true; |
| 2067 | #else |
| 2068 | bool enable_crash_reporter = breakpad::IsCrashReporterEnabled(); |
| 2069 | #endif |
| 2070 | if (enable_crash_reporter) { |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2071 | std::string switch_value; |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2072 | std::unique_ptr<metrics::ClientInfo> client_info = |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 2073 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2074 | if (client_info) |
| 2075 | switch_value = client_info->client_id; |
| 2076 | switch_value.push_back(','); |
Boris Vidolov | 8657801 | 2018-03-21 16:55:25 | [diff] [blame] | 2077 | switch_value.append(chrome::GetChannelName()); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2078 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2079 | switch_value); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2080 | } |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2081 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2082 | |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 2083 | if (logging::DialogsAreSuppressed()) |
| 2084 | command_line->AppendSwitch(switches::kNoErrorDialogs); |
| 2085 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2086 | std::string process_type = |
| 2087 | command_line->GetSwitchValueASCII(switches::kProcessType); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 2088 | const base::CommandLine& browser_command_line = |
| 2089 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 2090 | |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 2091 | static const char* const kCommonSwitchNames[] = { |
[email protected] | aa05127 | 2014-03-10 05:56:56 | [diff] [blame] | 2092 | switches::kUserAgent, |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 2093 | switches::kUserDataDir, // Make logs go to the right file. |
| 2094 | }; |
| 2095 | command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2096 | base::size(kCommonSwitchNames)); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 2097 | |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2098 | static const char* const kDinosaurEasterEggSwitches[] = { |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 2099 | error_page::switches::kDisableDinosaurEasterEgg, |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 2100 | }; |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2101 | command_line->CopySwitchesFrom(browser_command_line, |
| 2102 | kDinosaurEasterEggSwitches, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2103 | base::size(kDinosaurEasterEggSwitches)); |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 2104 | |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2105 | #if defined(OS_CHROMEOS) |
[email protected] | 6bdc5227 | 2014-05-27 00:12:33 | [diff] [blame] | 2106 | // On Chrome OS need to pass primary user homedir (in multi-profiles session). |
| 2107 | base::FilePath homedir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 2108 | base::PathService::Get(base::DIR_HOME, &homedir); |
[email protected] | 6bdc5227 | 2014-05-27 00:12:33 | [diff] [blame] | 2109 | command_line->AppendSwitchASCII(chromeos::switches::kHomedir, |
| 2110 | homedir.value().c_str()); |
| 2111 | #endif |
| 2112 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 2113 | if (process_type == switches::kRendererProcess) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2114 | content::RenderProcessHost* process = |
| 2115 | content::RenderProcessHost::FromID(child_process_id); |
| 2116 | Profile* profile = |
| 2117 | process ? Profile::FromBrowserContext(process->GetBrowserContext()) |
| 2118 | : NULL; |
| 2119 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
| 2120 | extra_parts_[i]->AppendExtraRendererCommandLineSwitches( |
| 2121 | command_line, process, profile); |
| 2122 | } |
| 2123 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2124 | #if defined(OS_CHROMEOS) |
| 2125 | const std::string& login_profile = |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 2126 | browser_command_line.GetSwitchValueASCII( |
| 2127 | chromeos::switches::kLoginProfile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2128 | if (!login_profile.empty()) |
[email protected] | 931d104 | 2013-04-05 17:50:44 | [diff] [blame] | 2129 | command_line->AppendSwitchASCII( |
| 2130 | chromeos::switches::kLoginProfile, login_profile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2131 | #endif |
| 2132 | |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 2133 | MaybeCopyDisableWebRtcEncryptionSwitch(command_line, |
| 2134 | browser_command_line, |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 2135 | chrome::GetChannel()); |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2136 | if (process) { |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2137 | PrefService* prefs = profile->GetPrefs(); |
| 2138 | // Currently this pref is only registered if applied via a policy. |
| 2139 | if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && |
| 2140 | prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 2141 | // Turn this policy into a command line switch. |
| 2142 | command_line->AppendSwitch(switches::kDisable3DAPIs); |
| 2143 | } |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 2144 | |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2145 | const base::ListValue* switches = |
| 2146 | prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures); |
| 2147 | if (switches) { |
| 2148 | // Enable any deprecated features that have been re-enabled by policy. |
jdoerrie | 601c715 | 2018-10-02 23:43:11 | [diff] [blame] | 2149 | for (auto it = switches->begin(); it != switches->end(); ++it) { |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2150 | std::string switch_to_enable; |
jdoerrie | a5676c6 | 2017-04-11 18:09:14 | [diff] [blame] | 2151 | if (it->GetAsString(&switch_to_enable)) |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2152 | command_line->AppendSwitch(switch_to_enable); |
| 2153 | } |
| 2154 | } |
| 2155 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2156 | // Disable client-side phishing detection in the renderer if it is |
| 2157 | // disabled in the Profile preferences or the browser process. |
| 2158 | if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) || |
| 2159 | !g_browser_process->safe_browsing_detection_service()) { |
| 2160 | command_line->AppendSwitch( |
| 2161 | switches::kDisableClientSidePhishingDetection); |
| 2162 | } |
[email protected] | 0045b0f4 | 2012-07-26 11:52:08 | [diff] [blame] | 2163 | |
vitalybuka | a7ae505 | 2014-09-26 04:11:13 | [diff] [blame] | 2164 | if (prefs->GetBoolean(prefs::kPrintPreviewDisabled)) |
| 2165 | command_line->AppendSwitch(switches::kDisablePrintPreview); |
| 2166 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 2167 | #if !defined(OS_ANDROID) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 2168 | InstantService* instant_service = |
| 2169 | InstantServiceFactory::GetForProfile(profile); |
| 2170 | if (instant_service && |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2171 | instant_service->IsInstantProcess(process->GetID())) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 2172 | command_line->AppendSwitch(switches::kInstantProcess); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2173 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 2174 | #endif |
fqj | ba8749c | 2015-10-29 15:33:07 | [diff] [blame] | 2175 | |
fqj | 38306f7b | 2015-11-02 16:59:06 | [diff] [blame] | 2176 | if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) && |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2177 | !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) { |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 2178 | command_line->AppendSwitch( |
| 2179 | error_page::switches::kDisableDinosaurEasterEgg); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2180 | } |
Daniel Vogelheim | 976f1c2 | 2017-11-22 16:26:03 | [diff] [blame] | 2181 | |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 2182 | MaybeAppendSecureOriginsAllowlistSwitch(command_line); |
| 2183 | |
Amr Aboelkher | b04cbf3 | 2019-04-29 15:17:10 | [diff] [blame] | 2184 | if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) && |
| 2185 | prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) { |
Avi Drissman | fb96126 | 2019-03-05 22:50:29 | [diff] [blame] | 2186 | command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload); |
Amr Aboelkher | b04cbf3 | 2019-04-29 15:17:10 | [diff] [blame] | 2187 | } |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2188 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2189 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 2190 | if (IsAutoReloadEnabled()) |
Elly Fong-Jones | 5f13ee1 | 2019-05-10 19:20:35 | [diff] [blame] | 2191 | command_line->AppendSwitch(switches::kEnableAutoReload); |
[email protected] | 28ee4e7 | 2014-03-28 19:29:04 | [diff] [blame] | 2192 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2193 | MaybeAppendBlinkSettingsSwitchForFieldTrial( |
| 2194 | browser_command_line, command_line); |
| 2195 | |
mdjones | a6b9e17 | 2016-09-23 16:24:30 | [diff] [blame] | 2196 | #if defined(OS_ANDROID) |
| 2197 | // If the platform is Android, force the distillability service on. |
| 2198 | command_line->AppendSwitch(switches::kEnableDistillabilityService); |
| 2199 | #endif |
| 2200 | |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2201 | // Please keep this in alphabetical order. |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2202 | static const char* const kSwitchNames[] = { |
estade | 0ee9126 | 2014-10-23 19:29:19 | [diff] [blame] | 2203 | autofill::switches::kIgnoreAutocompleteOffForAutofill, |
kolos | ad36993 | 2017-02-23 13:29:41 | [diff] [blame] | 2204 | autofill::switches::kShowAutofillSignatures, |
Chris Mumford | 6b1696b | 2019-01-25 02:54:30 | [diff] [blame] | 2205 | #if defined(OS_CHROMEOS) |
| 2206 | switches::kShortMergeSessionTimeoutForTest, // For tests only. |
| 2207 | #endif |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2208 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 2209 | extensions::switches::kAllowHTTPBackgroundPage, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2210 | extensions::switches::kAllowLegacyExtensionManifests, |
Chris Mumford | 3f0eda9 | 2018-07-23 14:51:17 | [diff] [blame] | 2211 | extensions::switches::kDisableExtensionsHttpThrottling, |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 2212 | extensions::switches::kEnableExperimentalExtensionApis, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2213 | extensions::switches::kExtensionsOnChromeURLs, |
Chris Mumford | 3f0eda9 | 2018-07-23 14:51:17 | [diff] [blame] | 2214 | extensions::switches::kSetExtensionThrottleTestParams, // For tests only. |
[email protected] | a612eb3 | 2014-03-31 22:09:17 | [diff] [blame] | 2215 | extensions::switches::kWhitelistedExtensionID, |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 2216 | #endif |
estark | 4b003b33 | 2015-02-14 01:07:05 | [diff] [blame] | 2217 | switches::kAllowInsecureLocalhost, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2218 | switches::kAppsGalleryURL, |
[email protected] | 09cff7878 | 2014-04-20 22:04:48 | [diff] [blame] | 2219 | switches::kCloudPrintURL, |
[email protected] | 6f5c141a | 2014-04-15 21:44:51 | [diff] [blame] | 2220 | switches::kCloudPrintXmppEndpoint, |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 2221 | switches::kDisableBundledPpapiFlash, |
dslomov | a893e97 | 2014-12-05 09:39:57 | [diff] [blame] | 2222 | switches::kDisableJavaScriptHarmonyShipping, |
Kyle Milka | b5c048e | 2017-07-07 02:38:46 | [diff] [blame] | 2223 | variations::switches::kEnableBenchmarking, |
mdjones | a6b9e17 | 2016-09-23 16:24:30 | [diff] [blame] | 2224 | switches::kEnableDistillabilityService, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2225 | switches::kEnableNaCl, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2226 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | 1b4ec38 | 2014-03-07 02:32:24 | [diff] [blame] | 2227 | switches::kEnableNaClDebug, |
[email protected] | b2c73f4 | 2014-03-07 15:44:48 | [diff] [blame] | 2228 | switches::kEnableNaClNonSfiMode, |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 2229 | #endif |
[email protected] | ce304ce | 2013-02-22 21:54:45 | [diff] [blame] | 2230 | switches::kEnableNetBenchmarking, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2231 | #if BUILDFLAG(ENABLE_NACL) |
stichnot | 7040ac83 | 2016-02-24 23:40:59 | [diff] [blame] | 2232 | switches::kForcePNaClSubzero, |
| 2233 | #endif |
Marc Treib | ad33cf94 | 2017-08-24 11:19:00 | [diff] [blame] | 2234 | switches::kForceUIDirection, |
erikcorry | b251cb9 | 2014-09-25 23:48:51 | [diff] [blame] | 2235 | switches::kJavaScriptHarmony, |
iclelland | 79237e9 | 2016-06-23 12:03:51 | [diff] [blame] | 2236 | switches::kOriginTrialDisabledFeatures, |
chasej | dfec22ae | 2017-03-16 20:58:55 | [diff] [blame] | 2237 | switches::kOriginTrialDisabledTokens, |
iclelland | ee4f4a7 | 2016-04-26 18:59:02 | [diff] [blame] | 2238 | switches::kOriginTrialPublicKey, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2239 | switches::kPpapiFlashArgs, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2240 | switches::kPpapiFlashPath, |
| 2241 | switches::kPpapiFlashVersion, |
wychen | e5568734 | 2015-11-13 20:17:03 | [diff] [blame] | 2242 | switches::kReaderModeHeuristics, |
[email protected] | 499e7c5 | 2013-10-04 16:03:09 | [diff] [blame] | 2243 | translate::switches::kTranslateSecurityOrigin, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2244 | }; |
| 2245 | |
| 2246 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2247 | base::size(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 2248 | } else if (process_type == switches::kUtilityProcess) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2249 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 2250 | static const char* const kSwitchNames[] = { |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 2251 | extensions::switches::kAllowHTTPBackgroundPage, |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 2252 | extensions::switches::kEnableExperimentalExtensionApis, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2253 | extensions::switches::kExtensionsOnChromeURLs, |
[email protected] | a612eb3 | 2014-03-31 22:09:17 | [diff] [blame] | 2254 | extensions::switches::kWhitelistedExtensionID, |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 2255 | }; |
| 2256 | |
| 2257 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2258 | base::size(kSwitchNames)); |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 2259 | #endif |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 2260 | MaybeAppendSecureOriginsAllowlistSwitch(command_line); |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 2261 | } else if (process_type == service_manager::switches::kZygoteProcess) { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2262 | static const char* const kSwitchNames[] = { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2263 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 2264 | switches::kDisableBundledPpapiFlash, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2265 | #if BUILDFLAG(ENABLE_NACL) |
rickyz | 3638a21 | 2014-10-29 23:50:24 | [diff] [blame] | 2266 | switches::kEnableNaClDebug, |
[email protected] | a9a8e2f | 2014-05-13 23:32:58 | [diff] [blame] | 2267 | switches::kEnableNaClNonSfiMode, |
stichnot | 7040ac83 | 2016-02-24 23:40:59 | [diff] [blame] | 2268 | switches::kForcePNaClSubzero, |
[email protected] | 0b47034 | 2014-04-15 12:59:41 | [diff] [blame] | 2269 | switches::kNaClDangerousNoSandboxNonSfi, |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 2270 | #endif |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2271 | switches::kPpapiFlashPath, |
| 2272 | switches::kPpapiFlashVersion, |
| 2273 | }; |
| 2274 | |
| 2275 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2276 | base::size(kSwitchNames)); |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 2277 | } else if (process_type == switches::kGpuProcess) { |
| 2278 | // If --ignore-gpu-blacklist is passed in, don't send in crash reports |
| 2279 | // because GPU is expected to be unreliable. |
| 2280 | if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) && |
| 2281 | !command_line->HasSwitch(switches::kDisableBreakpad)) |
| 2282 | command_line->AppendSwitch(switches::kDisableBreakpad); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2283 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 2284 | |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2285 | #if defined(OS_CHROMEOS) |
| 2286 | if (breakpad::ShouldPassCrashLoopBefore(process_type)) { |
| 2287 | static const char* const kSwitchNames[] = { |
| 2288 | switches::kCrashLoopBefore, |
| 2289 | }; |
| 2290 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 2291 | base::size(kSwitchNames)); |
| 2292 | } |
| 2293 | #endif |
| 2294 | |
wittman | 832321f5 | 2016-10-10 18:18:38 | [diff] [blame] | 2295 | StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess( |
| 2296 | process_type, |
| 2297 | command_line); |
Andrew Comminos | 6605767 | 2019-05-01 00:03:34 | [diff] [blame] | 2298 | |
| 2299 | #if defined(OS_LINUX) |
| 2300 | // Processes may only query perf_event_open with the BPF sandbox disabled. |
| 2301 | if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) && |
| 2302 | command_line->HasSwitch(service_manager::switches::kNoSandbox)) { |
| 2303 | command_line->AppendSwitch(switches::kEnableThreadInstructionCount); |
| 2304 | } |
| 2305 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2306 | } |
| 2307 | |
Scott Violet | 776edf8 | 2017-09-29 02:03:01 | [diff] [blame] | 2308 | void ChromeContentBrowserClient::AdjustUtilityServiceProcessCommandLine( |
| 2309 | const service_manager::Identity& identity, |
| 2310 | base::CommandLine* command_line) { |
Guido Urdaneta | 191635e | 2018-05-09 16:00:53 | [diff] [blame] | 2311 | #if defined(OS_MACOSX) |
Ken Rockot | 2f8c1dd2 | 2019-07-23 21:56:02 | [diff] [blame] | 2312 | // On Mac, the audio service requires a CFRunLoop, provided by a UI message |
| 2313 | // loop, to run AVFoundation and CoreAudio code. See https://crbug.com/834581. |
| 2314 | if (identity.name() == audio::mojom::kServiceName) |
Guido Urdaneta | 191635e | 2018-05-09 16:00:53 | [diff] [blame] | 2315 | command_line->AppendSwitch(switches::kMessageLoopTypeUi); |
| 2316 | #endif |
Scott Violet | 776edf8 | 2017-09-29 02:03:01 | [diff] [blame] | 2317 | } |
| 2318 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2319 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
[email protected] | e9a32a5 | 2012-06-14 23:32:43 | [diff] [blame] | 2320 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 2321 | return GetIOThreadApplicationLocale(); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2322 | return g_browser_process->GetApplicationLocale(); |
| 2323 | } |
| 2324 | |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 2325 | std::string ChromeContentBrowserClient::GetAcceptLangs( |
| 2326 | content::BrowserContext* context) { |
| 2327 | Profile* profile = Profile::FromBrowserContext(context); |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 2328 | return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 2329 | } |
| 2330 | |
Dana Fried | 34d58000 | 2019-04-24 20:05:48 | [diff] [blame] | 2331 | gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() { |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 2332 | ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
Dana Fried | 34d58000 | 2019-04-24 20:05:48 | [diff] [blame] | 2333 | return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia(); |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 2334 | } |
| 2335 | |
bengr | e8a146f | 2016-03-10 01:20:22 | [diff] [blame] | 2336 | bool ChromeContentBrowserClient::IsDataSaverEnabled( |
| 2337 | content::BrowserContext* browser_context) { |
Robert Ogden | c995d4fe | 2019-03-25 19:18:37 | [diff] [blame] | 2338 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2339 | return profile && data_reduction_proxy::DataReductionProxySettings:: |
| 2340 | IsDataSaverEnabledByUser(profile->GetPrefs()); |
bengr | e8a146f | 2016-03-10 01:20:22 | [diff] [blame] | 2341 | } |
| 2342 | |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 2343 | void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker( |
| 2344 | content::BrowserContext* browser_context, |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 2345 | blink::mojom::RendererPreferences* out_prefs) { |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 2346 | DCHECK(browser_context); |
| 2347 | DCHECK(out_prefs); |
| 2348 | renderer_preferences_util::UpdateFromSystemSettings( |
| 2349 | out_prefs, Profile::FromBrowserContext(browser_context)); |
| 2350 | } |
| 2351 | |
Clark DuVall | 5690e74 | 2019-07-17 18:26:17 | [diff] [blame] | 2352 | bool ChromeContentBrowserClient::AllowAppCacheOnIO( |
[email protected] | 5b52ad4 | 2011-05-26 14:26:09 | [diff] [blame] | 2353 | const GURL& manifest_url, |
[email protected] | 0a60884 | 2011-09-08 10:55:19 | [diff] [blame] | 2354 | const GURL& first_party, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 2355 | content::ResourceContext* context) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 2356 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
Clark DuVall | 5690e74 | 2019-07-17 18:26:17 | [diff] [blame] | 2357 | DCHECK(!base::FeatureList::IsEnabled(features::kNavigationLoaderOnUI)); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 2358 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 2359 | return io_data->GetCookieSettings()->IsCookieAccessAllowed(manifest_url, |
| 2360 | first_party); |
[email protected] | a217679 | 2011-05-08 19:30:49 | [diff] [blame] | 2361 | } |
| 2362 | |
Clark DuVall | 5690e74 | 2019-07-17 18:26:17 | [diff] [blame] | 2363 | bool ChromeContentBrowserClient::AllowAppCache( |
| 2364 | const GURL& manifest_url, |
| 2365 | const GURL& first_party, |
| 2366 | content::BrowserContext* context) { |
| 2367 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2368 | return CookieSettingsFactory::GetForProfile( |
| 2369 | Profile::FromBrowserContext(context)) |
| 2370 | ->IsCookieAccessAllowed(manifest_url, first_party); |
| 2371 | } |
| 2372 | |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2373 | bool ChromeContentBrowserClient::AllowServiceWorker( |
| 2374 | const GURL& scope, |
| 2375 | const GURL& first_party_url, |
David Bertoni | 3b3597d8 | 2019-06-22 02:29:36 | [diff] [blame] | 2376 | const GURL& script_url, |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2377 | content::ResourceContext* context, |
tzik | df81f14 | 2018-10-26 00:23:34 | [diff] [blame] | 2378 | base::RepeatingCallback<content::WebContents*()> wc_getter) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 2379 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2380 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2381 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2382 | // Check if this is an extension-related service worker, and, if so, if it's |
| 2383 | // allowed (this can return false if, e.g., the extension is disabled). |
| 2384 | // If it's not allowed, return immediately. We deliberately do *not* report |
| 2385 | // to the TabSpecificContentSettings, since the service worker is blocked |
| 2386 | // because of the extension, rather than because of the user's content |
| 2387 | // settings. |
| 2388 | if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorker( |
David Bertoni | 3b3597d8 | 2019-06-22 02:29:36 | [diff] [blame] | 2389 | scope, first_party_url, script_url, context)) { |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2390 | return false; |
| 2391 | } |
| 2392 | #endif |
| 2393 | |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2394 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2395 | |
shimazu | ce8af8812 | 2016-10-06 23:49:21 | [diff] [blame] | 2396 | // Check if JavaScript is allowed. |
| 2397 | content_settings::SettingInfo info; |
| 2398 | std::unique_ptr<base::Value> value = |
| 2399 | io_data->GetHostContentSettingsMap()->GetWebsiteSetting( |
| 2400 | first_party_url, first_party_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 2401 | std::string(), &info); |
| 2402 | ContentSetting setting = content_settings::ValueToContentSetting(value.get()); |
| 2403 | bool allow_javascript = (setting == CONTENT_SETTING_ALLOW); |
| 2404 | |
| 2405 | // Check if cookies are allowed. |
| 2406 | bool allow_serviceworker = |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 2407 | io_data->GetCookieSettings()->IsCookieAccessAllowed(scope, |
| 2408 | first_party_url); |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2409 | // Record access to database for potential display in UI. |
yzshen | bc36c97 | 2016-12-21 21:39:24 | [diff] [blame] | 2410 | // Only post the task if this is for a specific tab. |
| 2411 | if (!wc_getter.is_null()) { |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 2412 | base::PostTaskWithTraits( |
| 2413 | FROM_HERE, {BrowserThread::UI}, |
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 2414 | base::BindOnce(&TabSpecificContentSettings::ServiceWorkerAccessed, |
tzik | df81f14 | 2018-10-26 00:23:34 | [diff] [blame] | 2415 | std::move(wc_getter), scope, !allow_javascript, |
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 2416 | !allow_serviceworker)); |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2417 | } |
shimazu | ce8af8812 | 2016-10-06 23:49:21 | [diff] [blame] | 2418 | return allow_javascript && allow_serviceworker; |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2419 | } |
| 2420 | |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2421 | bool ChromeContentBrowserClient::AllowSharedWorker( |
| 2422 | const GURL& worker_url, |
| 2423 | const GURL& main_frame_url, |
| 2424 | const std::string& name, |
Hiroki Nakagawa | 018bb6d | 2017-11-30 03:31:37 | [diff] [blame] | 2425 | const url::Origin& constructor_origin, |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2426 | content::BrowserContext* context, |
| 2427 | int render_process_id, |
| 2428 | int render_frame_id) { |
| 2429 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2430 | |
| 2431 | // Check if cookies are allowed. |
| 2432 | bool allow = |
| 2433 | CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context)) |
| 2434 | ->IsCookieAccessAllowed(worker_url, main_frame_url); |
| 2435 | |
| 2436 | TabSpecificContentSettings::SharedWorkerAccessed( |
Hiroki Nakagawa | 018bb6d | 2017-11-30 03:31:37 | [diff] [blame] | 2437 | render_process_id, render_frame_id, worker_url, name, constructor_origin, |
| 2438 | !allow); |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2439 | return allow; |
| 2440 | } |
| 2441 | |
Clark DuVall | ab63d14 | 2019-07-23 04:24:36 | [diff] [blame] | 2442 | bool ChromeContentBrowserClient::AllowSignedExchangeOnIO( |
Kunihiko Sakamoto | f586da6 | 2019-03-28 03:03:04 | [diff] [blame] | 2443 | content::ResourceContext* resource_context) { |
| 2444 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
Clark DuVall | ab63d14 | 2019-07-23 04:24:36 | [diff] [blame] | 2445 | DCHECK(!base::FeatureList::IsEnabled(features::kNavigationLoaderOnUI)); |
Kunihiko Sakamoto | f586da6 | 2019-03-28 03:03:04 | [diff] [blame] | 2446 | // Null-check safe_browsing_service_ as in unit tests |resource_context| is a |
| 2447 | // MockResourceContext and the cast doesn't work. |
| 2448 | if (!safe_browsing_service_) |
| 2449 | return false; |
| 2450 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 2451 | return io_data->signed_exchange_enabled()->GetValue(); |
| 2452 | } |
| 2453 | |
Clark DuVall | ab63d14 | 2019-07-23 04:24:36 | [diff] [blame] | 2454 | bool ChromeContentBrowserClient::AllowSignedExchange( |
| 2455 | content::BrowserContext* browser_context) { |
| 2456 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2457 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2458 | return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled); |
| 2459 | } |
| 2460 | |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2461 | void ChromeContentBrowserClient::AllowWorkerFileSystem( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2462 | const GURL& url, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 2463 | content::ResourceContext* context, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2464 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2465 | base::Callback<void(bool)> callback) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 2466 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 2467 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 2468 | content_settings::CookieSettings* cookie_settings = |
| 2469 | io_data->GetCookieSettings(); |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 2470 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2471 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2472 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2473 | GuestPermissionRequestHelper(url, render_frames, callback, allow); |
| 2474 | #else |
| 2475 | FileSystemAccessed(url, render_frames, callback, allow); |
| 2476 | #endif |
| 2477 | } |
| 2478 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2479 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2480 | void ChromeContentBrowserClient::GuestPermissionRequestHelper( |
| 2481 | const GURL& url, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2482 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2483 | base::Callback<void(bool)> callback, |
| 2484 | bool allow) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 2485 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2486 | std::map<int, int> process_map; |
| 2487 | std::map<int, int>::const_iterator it; |
| 2488 | bool has_web_view_guest = false; |
| 2489 | // Record access to file system for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2490 | for (const auto& it : render_frames) { |
| 2491 | if (process_map.find(it.child_id) != process_map.end()) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2492 | continue; |
| 2493 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2494 | 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] | 2495 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2496 | if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id)) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2497 | has_web_view_guest = true; |
| 2498 | } |
| 2499 | if (!has_web_view_guest) { |
| 2500 | FileSystemAccessed(url, render_frames, callback, allow); |
| 2501 | return; |
| 2502 | } |
[email protected] | dffb9fc | 2014-07-16 04:14:02 | [diff] [blame] | 2503 | DCHECK_EQ(1U, process_map.size()); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2504 | it = process_map.begin(); |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 2505 | base::PostTaskWithTraits( |
| 2506 | FROM_HERE, {BrowserThread::UI}, |
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 2507 | base::BindOnce( |
| 2508 | &ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread, |
| 2509 | it->first, it->second, url, allow, |
Kevin Marshall | 32f99d7e | 2017-07-11 23:17:46 | [diff] [blame] | 2510 | base::Bind( |
| 2511 | &ChromeContentBrowserClient::FileSystemAccessed, |
| 2512 | weak_factory_.GetWeakPtr(), url, render_frames, |
| 2513 | base::Bind(&InvokeCallbackOnThread, |
| 2514 | base::SequencedTaskRunnerHandle::Get(), callback)))); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | void ChromeContentBrowserClient::RequestFileSystemPermissionOnUIThread( |
| 2518 | int render_process_id, |
| 2519 | int render_frame_id, |
| 2520 | const GURL& url, |
| 2521 | bool allowed_by_default, |
| 2522 | const base::Callback<void(bool)>& callback) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 2523 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 2524 | extensions::WebViewPermissionHelper* web_view_permission_helper = |
| 2525 | extensions::WebViewPermissionHelper::FromFrameID( |
| 2526 | render_process_id, render_frame_id); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2527 | web_view_permission_helper->RequestFileSystemPermission(url, |
| 2528 | allowed_by_default, |
| 2529 | callback); |
| 2530 | } |
| 2531 | #endif |
| 2532 | |
| 2533 | void ChromeContentBrowserClient::FileSystemAccessed( |
| 2534 | const GURL& url, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2535 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2536 | base::Callback<void(bool)> callback, |
| 2537 | bool allow) { |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 2538 | // Record access to file system for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2539 | for (const auto& it : render_frames) { |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 2540 | base::PostTaskWithTraits( |
| 2541 | FROM_HERE, {BrowserThread::UI}, |
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 2542 | base::BindOnce(&TabSpecificContentSettings::FileSystemAccessed, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2543 | it.child_id, it.frame_routing_id, url, !allow)); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2544 | } |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2545 | callback.Run(allow); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2546 | } |
| 2547 | |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2548 | bool ChromeContentBrowserClient::AllowWorkerIndexedDB( |
| 2549 | const GURL& url, |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2550 | content::ResourceContext* context, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2551 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 2552 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2553 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 2554 | content_settings::CookieSettings* cookie_settings = |
| 2555 | io_data->GetCookieSettings(); |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 2556 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2557 | |
| 2558 | // Record access to IndexedDB for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2559 | for (const auto& it : render_frames) { |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 2560 | base::PostTaskWithTraits( |
| 2561 | FROM_HERE, {BrowserThread::UI}, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2562 | base::BindOnce(&TabSpecificContentSettings::IndexedDBAccessed, |
Joshua Bell | 7cdaafca | 2018-10-31 06:27:11 | [diff] [blame] | 2563 | it.child_id, it.frame_routing_id, url, !allow)); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | return allow; |
| 2567 | } |
| 2568 | |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2569 | bool ChromeContentBrowserClient::AllowWorkerCacheStorage( |
| 2570 | const GURL& url, |
| 2571 | content::ResourceContext* context, |
| 2572 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
| 2573 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 2574 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
| 2575 | content_settings::CookieSettings* cookie_settings = |
| 2576 | io_data->GetCookieSettings(); |
| 2577 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
| 2578 | |
| 2579 | // Record access to CacheStorage for potential display in UI. |
| 2580 | for (const auto& it : render_frames) { |
| 2581 | base::PostTaskWithTraits( |
| 2582 | FROM_HERE, {BrowserThread::UI}, |
| 2583 | base::BindOnce(&TabSpecificContentSettings::CacheStorageAccessed, |
| 2584 | it.child_id, it.frame_routing_id, url, !allow)); |
| 2585 | } |
| 2586 | |
| 2587 | return allow; |
| 2588 | } |
| 2589 | |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2590 | ChromeContentBrowserClient::AllowWebBluetoothResult |
| 2591 | ChromeContentBrowserClient::AllowWebBluetooth( |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2592 | content::BrowserContext* browser_context, |
| 2593 | const url::Origin& requesting_origin, |
| 2594 | const url::Origin& embedding_origin) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2595 | // TODO(crbug.com/598890): Don't disable if |
| 2596 | // base::CommandLine::ForCurrentProcess()-> |
| 2597 | // HasSwitch(switches::kEnableWebBluetooth) is true. |
| 2598 | if (variations::GetVariationParamValue( |
| 2599 | PermissionContextBase::kPermissionsKillSwitchFieldStudy, |
| 2600 | "Bluetooth") == |
| 2601 | PermissionContextBase::kPermissionsKillSwitchBlockedValue) { |
| 2602 | // The kill switch is enabled for this permission. Block requests. |
| 2603 | return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED; |
| 2604 | } |
| 2605 | |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2606 | const HostContentSettingsMap* const content_settings = |
| 2607 | HostContentSettingsMapFactory::GetForProfile( |
| 2608 | Profile::FromBrowserContext(browser_context)); |
| 2609 | |
csharrison | aec2c54 | 2016-10-12 19:40:36 | [diff] [blame] | 2610 | if (content_settings->GetContentSetting( |
| 2611 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
| 2612 | CONTENT_SETTINGS_TYPE_BLUETOOTH_GUARD, |
| 2613 | std::string()) == CONTENT_SETTING_BLOCK) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2614 | return AllowWebBluetoothResult::BLOCK_POLICY; |
| 2615 | } |
| 2616 | return AllowWebBluetoothResult::ALLOW; |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2617 | } |
| 2618 | |
beaufort.francois | 01135bf | 2016-11-23 14:37:36 | [diff] [blame] | 2619 | std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() { |
| 2620 | return variations::GetVariationParamValue("WebBluetoothBlocklist", |
| 2621 | "blocklist_additions"); |
scheib | 7425032 | 2016-04-07 03:32:21 | [diff] [blame] | 2622 | } |
| 2623 | |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 2624 | #if defined(OS_CHROMEOS) |
John Abd-El-Malek | a5b1a5d60 | 2018-11-05 19:20:52 | [diff] [blame] | 2625 | void ChromeContentBrowserClient::OnTrustAnchorUsed( |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 2626 | const std::string& username_hash) { |
| 2627 | policy::PolicyCertServiceFactory::SetUsedPolicyCertificates(username_hash); |
| 2628 | } |
| 2629 | #endif |
| 2630 | |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2631 | scoped_refptr<network::SharedURLLoaderFactory> |
| 2632 | ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() { |
Min Qin | da0d55b | 2018-10-12 18:30:05 | [diff] [blame] | 2633 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 2634 | !BrowserThread::IsThreadInitialized(BrowserThread::UI)); |
| 2635 | |
| 2636 | if (!SystemNetworkContextManager::GetInstance()) |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2637 | return nullptr; |
| 2638 | |
Min Qin | da0d55b | 2018-10-12 18:30:05 | [diff] [blame] | 2639 | return SystemNetworkContextManager::GetInstance() |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2640 | ->GetSharedURLLoaderFactory(); |
Andrew Moylan | 8673dba | 2017-10-10 04:29:04 | [diff] [blame] | 2641 | } |
| 2642 | |
Sean Gilhuly | da1ee4b | 2018-11-13 21:56:09 | [diff] [blame] | 2643 | network::mojom::NetworkContext* |
| 2644 | ChromeContentBrowserClient::GetSystemNetworkContext() { |
| 2645 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2646 | DCHECK(g_browser_process->system_network_context_manager()); |
| 2647 | return g_browser_process->system_network_context_manager()->GetContext(); |
| 2648 | } |
| 2649 | |
Andrew Moylan | 17329fc | 2017-09-25 07:43:30 | [diff] [blame] | 2650 | std::string ChromeContentBrowserClient::GetGeolocationApiKey() { |
| 2651 | return google_apis::GetAPIKey(); |
| 2652 | } |
| 2653 | |
Ke He | 21ee87f | 2018-05-30 02:35:32 | [diff] [blame] | 2654 | #if defined(OS_ANDROID) |
| 2655 | bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() { |
| 2656 | // Indicate that Chrome uses the GMS core location provider. |
| 2657 | return true; |
| 2658 | } |
| 2659 | #endif |
| 2660 | |
Yeol | f3dc22ca | 2019-04-18 17:25:32 | [diff] [blame] | 2661 | scoped_refptr<content::QuotaPermissionContext> |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 2662 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
| 2663 | return new ChromeQuotaPermissionContext(); |
| 2664 | } |
| 2665 | |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 2666 | void ChromeContentBrowserClient::GetQuotaSettings( |
| 2667 | content::BrowserContext* context, |
| 2668 | content::StoragePartition* partition, |
tapted | e6d878e | 2017-06-24 01:53:45 | [diff] [blame] | 2669 | storage::OptionalQuotaSettingsCallback callback) { |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 2670 | if (g_default_quota_settings) { |
| 2671 | // For debugging tests harness can inject settings. |
tapted | e6d878e | 2017-06-24 01:53:45 | [diff] [blame] | 2672 | std::move(callback).Run(*g_default_quota_settings); |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 2673 | return; |
| 2674 | } |
tapted | e6d878e | 2017-06-24 01:53:45 | [diff] [blame] | 2675 | storage::GetNominalDynamicSettings( |
Jarryd | 451ab7b | 2019-02-12 06:39:06 | [diff] [blame] | 2676 | partition->GetPath(), context->IsOffTheRecord(), |
| 2677 | storage::GetDefaultDiskInfoHelper(), std::move(callback)); |
calamity | c96116b | 2015-11-03 04:30:51 | [diff] [blame] | 2678 | } |
| 2679 | |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 2680 | content::GeneratedCodeCacheSettings |
| 2681 | ChromeContentBrowserClient::GetGeneratedCodeCacheSettings( |
| 2682 | content::BrowserContext* context) { |
| 2683 | base::FilePath cache_path; |
| 2684 | chrome::GetUserCacheDirectory(context->GetPath(), &cache_path); |
| 2685 | // If we pass 0 for size, disk_cache will pick a default size using the |
| 2686 | // heuristics based on available disk size. These are implemented in |
| 2687 | // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc. |
Mythri A | b248657 | 2019-06-13 14:48:16 | [diff] [blame] | 2688 | int64_t size_in_bytes = 0; |
| 2689 | PrefService* prefs = Profile::FromBrowserContext(context)->GetPrefs(); |
| 2690 | DCHECK(prefs); |
| 2691 | size_in_bytes = prefs->GetInteger(prefs::kDiskCacheSize); |
Mythri A | 6c1e4d1 | 2019-07-18 15:05:20 | [diff] [blame] | 2692 | base::FilePath disk_cache_dir = prefs->GetFilePath(prefs::kDiskCacheDir); |
| 2693 | if (!disk_cache_dir.empty()) |
| 2694 | cache_path = disk_cache_dir.Append(cache_path.BaseName()); |
Mythri A | b248657 | 2019-06-13 14:48:16 | [diff] [blame] | 2695 | return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path); |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 2696 | } |
| 2697 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 2698 | void ChromeContentBrowserClient::AllowCertificateError( |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2699 | content::WebContents* web_contents, |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 2700 | int cert_error, |
| 2701 | const net::SSLInfo& ssl_info, |
| 2702 | const GURL& request_url, |
John Abd-El-Malek | c5b8df91 | 2019-05-07 17:02:23 | [diff] [blame] | 2703 | bool is_main_frame_request, |
[email protected] | d9be4770 | 2012-05-16 03:41:22 | [diff] [blame] | 2704 | bool strict_enforcement, |
[email protected] | 83c13fe | 2014-08-15 04:49:10 | [diff] [blame] | 2705 | bool expired_previous_decision, |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2706 | const base::Callback<void(content::CertificateRequestResultType)>& |
| 2707 | callback) { |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2708 | DCHECK(web_contents); |
John Abd-El-Malek | c5b8df91 | 2019-05-07 17:02:23 | [diff] [blame] | 2709 | if (!is_main_frame_request) { |
irisu | 8452ddd6 | 2017-03-22 07:46:14 | [diff] [blame] | 2710 | // A sub-resource has a certificate error. The user doesn't really |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 2711 | // have a context for making the right decision, so block the |
| 2712 | // request hard, without an info bar to allow showing the insecure |
| 2713 | // content. |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2714 | if (!callback.is_null()) |
| 2715 | callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 2716 | return; |
| 2717 | } |
| 2718 | |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 2719 | // If the tab is being prerendered, cancel the prerender and the request. |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2720 | prerender::PrerenderContents* prerender_contents = |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2721 | prerender::PrerenderContents::FromWebContents(web_contents); |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2722 | if (prerender_contents) { |
| 2723 | prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR); |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2724 | if (!callback.is_null()) { |
| 2725 | callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL); |
| 2726 | } |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2727 | return; |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 2728 | } |
| 2729 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 2730 | callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
| 2731 | return; |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 2732 | } |
| 2733 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2734 | namespace { |
| 2735 | |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2736 | certificate_matching::CertificatePrincipalPattern |
| 2737 | ParseCertificatePrincipalPattern(const base::Value* pattern) { |
| 2738 | return certificate_matching::CertificatePrincipalPattern:: |
| 2739 | ParseFromOptionalDict(pattern, "CN", "L", "O", "OU"); |
| 2740 | } |
| 2741 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2742 | // Attempts to auto-select a client certificate according to the value of |
| 2743 | // |CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE| content setting for |
| 2744 | // |requesting_url|. If no certificate was auto-selected, returns nullptr. |
| 2745 | std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate( |
| 2746 | Profile* profile, |
| 2747 | const GURL& requesting_url, |
| 2748 | net::ClientCertIdentityList& client_certs) { |
| 2749 | HostContentSettingsMap* host_content_settings_map = |
| 2750 | HostContentSettingsMapFactory::GetForProfile(profile); |
| 2751 | std::unique_ptr<base::Value> setting = |
| 2752 | host_content_settings_map->GetWebsiteSetting( |
| 2753 | requesting_url, requesting_url, |
| 2754 | CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), NULL); |
| 2755 | |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2756 | if (!setting || !setting->is_dict()) |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2757 | return nullptr; |
| 2758 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2759 | const base::Value* filters = |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2760 | setting->FindKeyOfType("filters", base::Value::Type::LIST); |
| 2761 | if (!filters) { |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2762 | // |setting_dict| has the wrong format (e.g. single filter instead of a |
| 2763 | // list of filters). This content setting is only provided by |
| 2764 | // the |PolicyProvider|, which should always set it to a valid format. |
| 2765 | // Therefore, delete the invalid value. |
| 2766 | host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 2767 | requesting_url, requesting_url, |
| 2768 | CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), nullptr); |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2769 | return nullptr; |
| 2770 | } |
| 2771 | |
| 2772 | for (const base::Value& filter : filters->GetList()) { |
| 2773 | DCHECK(filter.is_dict()); |
| 2774 | |
| 2775 | auto issuer_pattern = ParseCertificatePrincipalPattern( |
| 2776 | filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY)); |
| 2777 | auto subject_pattern = ParseCertificatePrincipalPattern( |
| 2778 | filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY)); |
| 2779 | // Use the first certificate that is matched by the filter. |
| 2780 | for (auto& client_cert : client_certs) { |
| 2781 | if (issuer_pattern.Matches(client_cert->certificate()->issuer()) && |
| 2782 | subject_pattern.Matches(client_cert->certificate()->subject())) { |
| 2783 | return std::move(client_cert); |
| 2784 | } |
| 2785 | } |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | return nullptr; |
| 2789 | } |
| 2790 | |
Eric Roman | a00cf68 | 2018-11-01 20:09:11 | [diff] [blame] | 2791 | void AddDataReductionProxyBinding( |
| 2792 | content::ResourceContext* resource_context, |
| 2793 | data_reduction_proxy::mojom::DataReductionProxyRequest request) { |
| 2794 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 2795 | auto* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 2796 | if (io_data && io_data->data_reduction_proxy_io_data()) { |
| 2797 | io_data->data_reduction_proxy_io_data()->Clone(std::move(request)); |
| 2798 | } |
| 2799 | } |
| 2800 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2801 | } // namespace |
| 2802 | |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2803 | base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate( |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2804 | content::WebContents* web_contents, |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 2805 | net::SSLCertRequestInfo* cert_request_info, |
mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 2806 | net::ClientCertIdentityList client_certs, |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2807 | std::unique_ptr<content::ClientCertificateDelegate> delegate) { |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 2808 | prerender::PrerenderContents* prerender_contents = |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2809 | prerender::PrerenderContents::FromWebContents(web_contents); |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 2810 | if (prerender_contents) { |
| 2811 | prerender_contents->Destroy( |
| 2812 | prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2813 | return base::OnceClosure(); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 2814 | } |
| 2815 | |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 2816 | GURL requesting_url("https://" + cert_request_info->host_and_port.ToString()); |
| 2817 | DCHECK(requesting_url.is_valid()) |
| 2818 | << "Invalid URL string: https://" |
| 2819 | << cert_request_info->host_and_port.ToString(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 2820 | |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2821 | bool may_show_cert_selection = true; |
| 2822 | |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2823 | Profile* profile = |
| 2824 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2825 | #if defined(OS_CHROMEOS) |
| 2826 | if (chromeos::ProfileHelper::IsSigninProfile(profile)) { |
| 2827 | // TODO(pmarko): crbug.com/723849: Set |may_show_cert_selection| to false |
| 2828 | // and remove the command-line flag after prototype phase when the |
| 2829 | // DeviceLoginScreenAutoSelectCertificateForUrls policy is live. |
| 2830 | may_show_cert_selection = |
| 2831 | chromeos::switches::IsSigninFrameClientCertUserSelectionEnabled(); |
| 2832 | |
| 2833 | content::StoragePartition* storage_partition = |
| 2834 | content::BrowserContext::GetStoragePartition( |
| 2835 | profile, web_contents->GetSiteInstance()); |
| 2836 | chromeos::login::SigninPartitionManager* signin_partition_manager = |
| 2837 | chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext( |
| 2838 | profile); |
| 2839 | |
| 2840 | // On the sign-in profile, only allow client certs in the context of the |
| 2841 | // sign-in frame. |
| 2842 | if (!signin_partition_manager->IsCurrentSigninStoragePartition( |
| 2843 | storage_partition)) { |
| 2844 | LOG(WARNING) |
| 2845 | << "Client cert requested in sign-in profile in wrong context."; |
| 2846 | // Continue without client certificate. We do this to mimic the case of no |
| 2847 | // client certificate being present in the profile's certificate store. |
| 2848 | delegate->ContinueWithCertificate(nullptr, nullptr); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2849 | return base::OnceClosure(); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2850 | } |
| 2851 | VLOG(1) << "Client cert requested in sign-in profile."; |
| 2852 | } |
| 2853 | #endif // defined(OS_CHROMEOS) |
| 2854 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2855 | std::unique_ptr<net::ClientCertIdentity> auto_selected_identity = |
| 2856 | AutoSelectCertificate(profile, requesting_url, client_certs); |
| 2857 | if (auto_selected_identity) { |
| 2858 | // The callback will own |auto_selected_identity| and |delegate|, keeping |
| 2859 | // them alive until after ContinueWithCertificate is called. |
| 2860 | scoped_refptr<net::X509Certificate> cert = |
| 2861 | auto_selected_identity->certificate(); |
| 2862 | net::ClientCertIdentity::SelfOwningAcquirePrivateKey( |
| 2863 | std::move(auto_selected_identity), |
David Benjamin | 0cda204 | 2019-04-08 23:00:58 | [diff] [blame] | 2864 | base::BindOnce( |
| 2865 | &content::ClientCertificateDelegate::ContinueWithCertificate, |
| 2866 | std::move(delegate), std::move(cert))); |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 2867 | LogClientAuthResult(ClientCertSelectionResult::kAutoSelect); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2868 | return base::OnceClosure(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 2869 | } |
| 2870 | |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2871 | if (!may_show_cert_selection) { |
| 2872 | LOG(WARNING) << "No client cert matched by policy and user selection is " |
| 2873 | "not allowed."; |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 2874 | LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2875 | // Continue without client certificate. We do this to mimic the case of no |
| 2876 | // client certificate being present in the profile's certificate store. |
| 2877 | delegate->ContinueWithCertificate(nullptr, nullptr); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2878 | return base::OnceClosure(); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2879 | } |
| 2880 | |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2881 | return chrome::ShowSSLClientCertificateSelector( |
| 2882 | web_contents, cert_request_info, std::move(client_certs), |
| 2883 | std::move(delegate)); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 2884 | } |
| 2885 | |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 2886 | content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { |
[email protected] | 11158e2d | 2013-02-01 02:31:56 | [diff] [blame] | 2887 | return MediaCaptureDevicesDispatcher::GetInstance(); |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 2888 | } |
| 2889 | |
peter | c26c6c6 | 2014-12-10 14:13:59 | [diff] [blame] | 2890 | content::PlatformNotificationService* |
Richard Knoll | d0eae96 | 2019-04-04 12:34:02 | [diff] [blame] | 2891 | ChromeContentBrowserClient::GetPlatformNotificationService( |
| 2892 | content::BrowserContext* browser_context) { |
| 2893 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2894 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2895 | return PlatformNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2896 | } |
| 2897 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2898 | bool ChromeContentBrowserClient::CanCreateWindow( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2899 | RenderFrameHost* opener, |
[email protected] | 2b751a1 | 2012-03-06 03:00:35 | [diff] [blame] | 2900 | const GURL& opener_url, |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 2901 | const GURL& opener_top_level_frame_url, |
Nasko Oskov | e9f1978 | 2019-01-04 18:32:35 | [diff] [blame] | 2902 | const url::Origin& source_origin, |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 2903 | content::mojom::WindowContainerType container_type, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2904 | const GURL& target_url, |
| 2905 | const content::Referrer& referrer, |
jochen | 67b271b | 2016-08-03 13:50:21 | [diff] [blame] | 2906 | const std::string& frame_name, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2907 | WindowOpenDisposition disposition, |
scottmg | 8e6c608 | 2017-02-13 23:15:48 | [diff] [blame] | 2908 | const blink::mojom::WindowFeatures& features, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2909 | bool user_gesture, |
| 2910 | bool opener_suppressed, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2911 | bool* no_javascript_access) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2912 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2913 | DCHECK(opener); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2914 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2915 | content::WebContents* web_contents = |
| 2916 | content::WebContents::FromRenderFrameHost(opener); |
| 2917 | Profile* profile = |
| 2918 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 2919 | DCHECK(profile); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2920 | *no_javascript_access = false; |
| 2921 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2922 | // If the opener is trying to create a background window but doesn't have |
| 2923 | // the appropriate permission, fail the attempt. |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 2924 | if (container_type == content::mojom::WindowContainerType::BACKGROUND) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2925 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2926 | auto* process_map = extensions::ProcessMap::Get(profile); |
| 2927 | auto* registry = extensions::ExtensionRegistry::Get(profile); |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 2928 | if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url, |
| 2929 | opener->GetProcess()->GetID())) { |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2930 | return false; |
| 2931 | } |
| 2932 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 2933 | // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may |
| 2934 | // return a recently installed Extension even if this CanCreateWindow call |
| 2935 | // was made by an old copy of the page in a normal web process. That's ok, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2936 | // because the permission check above would have caused an early return |
| 2937 | // already. We must use the full URL to find hosted apps, though, and not |
| 2938 | // just the origin. |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 2939 | const Extension* extension = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2940 | registry->enabled_extensions().GetExtensionOrAppByURL(opener_url); |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 2941 | if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2942 | *no_javascript_access = true; |
[email protected] | dffb9fc | 2014-07-16 04:14:02 | [diff] [blame] | 2943 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2944 | |
| 2945 | return true; |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2946 | } |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 2947 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2948 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 2949 | if (extensions::WebViewRendererState::GetInstance()->IsGuest( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2950 | opener->GetProcess()->GetID())) { |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2951 | return true; |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 2952 | } |
| 2953 | |
nick | 0fbc392 | 2016-12-16 20:52:07 | [diff] [blame] | 2954 | if (target_url.SchemeIs(extensions::kExtensionScheme)) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2955 | // Intentionally duplicating |registry| code from above because we want to |
| 2956 | // reduce calls to retrieve them as this function is a SYNC IPC handler. |
| 2957 | auto* registry = extensions::ExtensionRegistry::Get(profile); |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 2958 | const Extension* extension = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2959 | registry->enabled_extensions().GetExtensionOrAppByURL(target_url); |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 2960 | if (extension && extension->is_platform_app()) { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 2961 | UMA_HISTOGRAM_ENUMERATION( |
| 2962 | "Extensions.AppLoadedInTab", |
| 2963 | ClassifyAppLoadedInTabSource(opener_url, extension), |
| 2964 | APP_LOADED_IN_TAB_SOURCE_MAX); |
| 2965 | |
| 2966 | // window.open() may not be used to load v2 apps in a regular tab. |
lazyboy | 39585ed | 2016-12-06 19:30:16 | [diff] [blame] | 2967 | return false; |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 2968 | } |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 2969 | } |
[email protected] | 5940b0d | 2014-07-01 00:18:26 | [diff] [blame] | 2970 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2971 | |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 2972 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2973 | HostContentSettingsMap* content_settings = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2974 | HostContentSettingsMapFactory::GetForProfile(profile); |
tommycli | 61f6f0c | 2016-09-21 00:26:58 | [diff] [blame] | 2975 | if (FlashDownloadInterception::ShouldStopFlashDownloadAction( |
| 2976 | content_settings, opener_top_level_frame_url, target_url, |
| 2977 | user_gesture)) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2978 | FlashDownloadInterception::InterceptFlashDownloadNavigation( |
| 2979 | web_contents, opener_top_level_frame_url); |
tommycli | 61f6f0c | 2016-09-21 00:26:58 | [diff] [blame] | 2980 | return false; |
| 2981 | } |
| 2982 | #endif |
| 2983 | |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 2984 | // Don't let prerenders open popups. |
| 2985 | if (auto* prerender_contents = |
| 2986 | prerender::PrerenderContents::FromWebContents(web_contents)) { |
| 2987 | prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW); |
| 2988 | return false; |
| 2989 | } |
| 2990 | |
Nasko Oskov | e9f1978 | 2019-01-04 18:32:35 | [diff] [blame] | 2991 | BlockedWindowParams blocked_params(target_url, source_origin, referrer, |
| 2992 | frame_name, disposition, features, |
| 2993 | user_gesture, opener_suppressed); |
cm.sanchi | 2522bc9 | 2017-12-04 08:04:13 | [diff] [blame] | 2994 | NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents); |
Charlie Harrison | 804659a | 2018-10-16 16:43:38 | [diff] [blame] | 2995 | if (MaybeBlockPopup(web_contents, opener_top_level_frame_url, &nav_params, |
| 2996 | nullptr /*=open_url_params*/, |
| 2997 | blocked_params.features())) { |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 2998 | return false; |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2999 | } |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3000 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 3001 | #if defined(OS_ANDROID) |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 3002 | auto* single_tab_mode_helper = |
| 3003 | SingleTabModeTabHelper::FromWebContents(web_contents); |
Bo Liu | 3d5b8d69 | 2017-12-14 22:42:03 | [diff] [blame] | 3004 | if (single_tab_mode_helper && |
| 3005 | single_tab_mode_helper->block_all_new_windows()) { |
Jinsuk Kim | 6f9253c | 2019-03-11 02:45:07 | [diff] [blame] | 3006 | TabModelList::HandlePopupNavigation(&nav_params); |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3007 | return false; |
| 3008 | } |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 3009 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 3010 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 3011 | return true; |
| 3012 | } |
| 3013 | |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 3014 | content::SpeechRecognitionManagerDelegate* |
zork | b548de08 | 2014-11-14 21:40:47 | [diff] [blame] | 3015 | ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() { |
[email protected] | 855e18b | 2013-07-08 21:02:00 | [diff] [blame] | 3016 | return new speech::ChromeSpeechRecognitionManagerDelegate(); |
[email protected] | 66cfec6 | 2012-02-24 17:57:51 | [diff] [blame] | 3017 | } |
| 3018 | |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 3019 | content::TtsControllerDelegate* |
| 3020 | ChromeContentBrowserClient::GetTtsControllerDelegate() { |
| 3021 | TtsControllerDelegateImpl* delegate = |
| 3022 | TtsControllerDelegateImpl::GetInstance(); |
| 3023 | #if !defined(OS_ANDROID) |
| 3024 | TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance(); |
| 3025 | delegate->SetTtsEngineDelegate(tts_extension_engine); |
| 3026 | #endif |
| 3027 | return delegate; |
| 3028 | } |
| 3029 | |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 3030 | content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() { |
| 3031 | #ifdef OS_CHROMEOS |
| 3032 | return TtsPlatformImplChromeOs::GetInstance(); |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 3033 | #else |
| 3034 | return nullptr; |
| 3035 | #endif |
| 3036 | } |
| 3037 | |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3038 | base::Optional<ui::CaptionStyle> GetCaptionStyleFromPrefs(PrefService* prefs) { |
| 3039 | if (!prefs) { |
| 3040 | return base::nullopt; |
| 3041 | } |
| 3042 | |
| 3043 | ui::CaptionStyle style; |
| 3044 | |
| 3045 | style.text_size = prefs->GetString(prefs::kAccessibilityCaptionsTextSize); |
| 3046 | style.font_family = prefs->GetString(prefs::kAccessibilityCaptionsTextFont); |
Evan Liu | f248d40 | 2019-06-26 22:57:10 | [diff] [blame] | 3047 | if (!prefs->GetString(prefs::kAccessibilityCaptionsTextColor).empty()) { |
| 3048 | style.text_color = base::StringPrintf( |
| 3049 | "rgba(%s,%s)", |
| 3050 | prefs->GetString(prefs::kAccessibilityCaptionsTextColor).c_str(), |
| 3051 | base::NumberToString( |
| 3052 | prefs->GetInteger(prefs::kAccessibilityCaptionsTextOpacity) / 100.0) |
| 3053 | .c_str()); |
| 3054 | } |
| 3055 | |
| 3056 | if (!prefs->GetString(prefs::kAccessibilityCaptionsBackgroundColor).empty()) { |
| 3057 | style.background_color = base::StringPrintf( |
| 3058 | "rgba(%s,%s)", |
| 3059 | prefs->GetString(prefs::kAccessibilityCaptionsBackgroundColor).c_str(), |
| 3060 | base::NumberToString( |
| 3061 | prefs->GetInteger(prefs::kAccessibilityCaptionsBackgroundOpacity) / |
| 3062 | 100.0) |
| 3063 | .c_str()); |
| 3064 | } |
| 3065 | |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3066 | style.text_shadow = prefs->GetString(prefs::kAccessibilityCaptionsTextShadow); |
| 3067 | |
| 3068 | return style; |
| 3069 | } |
| 3070 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3071 | void ChromeContentBrowserClient::OverrideWebkitPrefs( |
creis | 7b2d3d1 | 2015-02-12 23:29:50 | [diff] [blame] | 3072 | RenderViewHost* rvh, WebPreferences* web_prefs) { |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3073 | Profile* profile = Profile::FromBrowserContext( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 3074 | rvh->GetProcess()->GetBrowserContext()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3075 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3076 | |
aelias | 0df335a | 2017-03-02 23:43:51 | [diff] [blame] | 3077 | // Fill font preferences. These are not registered on Android |
| 3078 | // - http://crbug.com/308033, http://crbug.com/696364. |
[email protected] | 33b7954 | 2013-10-18 11:18:45 | [diff] [blame] | 3079 | #if !defined(OS_ANDROID) |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3080 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3081 | prefs::kWebKitStandardFontFamilyMap, |
| 3082 | &web_prefs->standard_font_family_map); |
| 3083 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3084 | prefs::kWebKitFixedFontFamilyMap, |
| 3085 | &web_prefs->fixed_font_family_map); |
| 3086 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3087 | prefs::kWebKitSerifFontFamilyMap, |
| 3088 | &web_prefs->serif_font_family_map); |
| 3089 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3090 | prefs::kWebKitSansSerifFontFamilyMap, |
| 3091 | &web_prefs->sans_serif_font_family_map); |
| 3092 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3093 | prefs::kWebKitCursiveFontFamilyMap, |
| 3094 | &web_prefs->cursive_font_family_map); |
| 3095 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3096 | prefs::kWebKitFantasyFontFamilyMap, |
| 3097 | &web_prefs->fantasy_font_family_map); |
| 3098 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3099 | prefs::kWebKitPictographFontFamilyMap, |
| 3100 | &web_prefs->pictograph_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3101 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3102 | web_prefs->default_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3103 | prefs->GetInteger(prefs::kWebKitDefaultFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3104 | web_prefs->default_fixed_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3105 | prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3106 | web_prefs->minimum_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3107 | prefs->GetInteger(prefs::kWebKitMinimumFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3108 | web_prefs->minimum_logical_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3109 | prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize); |
aelias | 0df335a | 2017-03-02 23:43:51 | [diff] [blame] | 3110 | #endif |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3111 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3112 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3113 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3114 | web_prefs->dom_paste_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3115 | prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); |
Joel Hockey | 08a6c84c | 2018-04-11 10:09:21 | [diff] [blame] | 3116 | web_prefs->javascript_can_access_clipboard = |
| 3117 | prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3118 | web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3119 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3120 | if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3121 | web_prefs->javascript_enabled = false; |
mkwst | a1f7749b | 2015-12-28 09:28:57 | [diff] [blame] | 3122 | |
Avi Drissman | 1aa6cb9 | 2019-01-23 15:58:38 | [diff] [blame] | 3123 | if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3124 | web_prefs->web_security_enabled = false; |
mkwst | a1f7749b | 2015-12-28 09:28:57 | [diff] [blame] | 3125 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3126 | if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3127 | web_prefs->plugins_enabled = false; |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3128 | web_prefs->loads_images_automatically = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3129 | prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3130 | |
Zhenyao Mo | a3fda997 | 2017-09-16 01:34:40 | [diff] [blame] | 3131 | if (prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 3132 | web_prefs->webgl1_enabled = false; |
| 3133 | web_prefs->webgl2_enabled = false; |
| 3134 | } |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3135 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3136 | web_prefs->allow_running_insecure_content = |
| 3137 | prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3138 | #if defined(OS_ANDROID) |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 3139 | web_prefs->font_scale_factor = |
| 3140 | static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor)); |
| 3141 | web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment(); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3142 | web_prefs->force_enable_zoom = |
| 3143 | prefs->GetBoolean(prefs::kWebKitForceEnableZoom); |
Becky Zhou | bbfbde3 | 2019-02-20 17:07:59 | [diff] [blame] | 3144 | web_prefs->force_dark_mode_enabled = |
| 3145 | prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3146 | #endif |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 3147 | |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 3148 | #if defined(OS_ANDROID) |
| 3149 | web_prefs->password_echo_enabled = |
| 3150 | prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled); |
| 3151 | #else |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 3152 | web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled; |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 3153 | #endif |
| 3154 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3155 | web_prefs->text_areas_are_resizable = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3156 | prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3157 | web_prefs->hyperlink_auditing_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3158 | prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); |
| 3159 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3160 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 3161 | std::string image_animation_policy = |
| 3162 | prefs->GetString(prefs::kAnimationPolicy); |
| 3163 | if (image_animation_policy == kAnimationPolicyOnce) |
| 3164 | web_prefs->animation_policy = |
| 3165 | content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE; |
| 3166 | else if (image_animation_policy == kAnimationPolicyNone) |
| 3167 | web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION; |
| 3168 | else |
| 3169 | web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED; |
| 3170 | #endif |
| 3171 | |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3172 | // Make sure we will set the default_encoding with canonical encoding name. |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 3173 | web_prefs->default_encoding = |
| 3174 | base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3175 | if (web_prefs->default_encoding.empty()) { |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3176 | prefs->ClearPref(prefs::kDefaultCharset); |
| 3177 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3178 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3179 | DCHECK(!web_prefs->default_encoding.empty()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3180 | |
mkwst | 0554410 | 2015-01-10 20:26:16 | [diff] [blame] | 3181 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3182 | switches::kEnablePotentiallyAnnoyingSecurityFeatures)) { |
mkwst | 772ce814 | 2015-01-16 13:28:07 | [diff] [blame] | 3183 | web_prefs->disable_reading_from_canvas = true; |
mkwst | 0554410 | 2015-01-10 20:26:16 | [diff] [blame] | 3184 | web_prefs->strict_mixed_content_checking = true; |
| 3185 | web_prefs->strict_powerful_feature_restrictions = true; |
| 3186 | } |
| 3187 | |
Robert Ogden | cf2872d | 2019-03-19 18:59:37 | [diff] [blame] | 3188 | web_prefs->data_saver_enabled = IsDataSaverEnabled(profile); |
Ben Greenstein | 49878f5 | 2015-12-18 19:13:21 | [diff] [blame] | 3189 | |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 3190 | web_prefs->data_saver_holdback_web_api_enabled = |
| 3191 | base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback, |
| 3192 | "holdback_web", false); |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 3193 | |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3194 | auto* contents = content::WebContents::FromRenderViewHost(rvh); |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3195 | if (contents) { |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3196 | #if defined(OS_ANDROID) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3197 | auto* delegate = TabAndroid::FromWebContents(contents) |
| 3198 | ? static_cast<android::TabWebContentsDelegateAndroid*>( |
| 3199 | contents->GetDelegate()) |
| 3200 | : nullptr; |
| 3201 | if (delegate) { |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3202 | web_prefs->embedded_media_experience_enabled = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3203 | delegate->ShouldEnableEmbeddedMediaExperience(); |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3204 | |
Mounir Lamouri | 9c99a160 | 2018-07-05 15:01:44 | [diff] [blame] | 3205 | web_prefs->picture_in_picture_enabled = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3206 | delegate->IsPictureInPictureEnabled(); |
Rune Lillesveen | 17e4832 | 2019-04-15 23:12:38 | [diff] [blame] | 3207 | |
| 3208 | web_prefs->preferred_color_scheme = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3209 | delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark |
| 3210 | : blink::PreferredColorScheme::kLight; |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3211 | } |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3212 | #endif // defined(OS_ANDROID) |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3213 | |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3214 | // web_app_scope value is platform specific. |
| 3215 | #if defined(OS_ANDROID) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3216 | if (delegate) |
| 3217 | web_prefs->web_app_scope = delegate->GetManifestScope(); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3218 | #elif BUILDFLAG(ENABLE_EXTENSIONS) |
| 3219 | { |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3220 | web_prefs->web_app_scope = GURL(); |
| 3221 | // Set |web_app_scope| based on the app associated with the app window if |
| 3222 | // any. Note that the app associated with the window never changes, even |
| 3223 | // if the app navigates off scope. This is not a problem because we still |
| 3224 | // want to use the scope of the app associated with the window, not the |
| 3225 | // WebContents. |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3226 | Browser* browser = chrome::FindBrowserWithWebContents(contents); |
Alan Cutter | d0bd5190 | 2019-05-22 04:15:23 | [diff] [blame] | 3227 | if (browser && browser->app_controller() && |
Eric Willigers | e339c1e | 2019-05-13 19:22:44 | [diff] [blame] | 3228 | browser->app_controller()->CreatedForInstalledPwa()) { |
Yining Wang | 234ad327 | 2019-04-08 18:47:27 | [diff] [blame] | 3229 | // PWAs should be hosted apps. |
Eric Willigers | e339c1e | 2019-05-13 19:22:44 | [diff] [blame] | 3230 | DCHECK(browser->app_controller()->IsHostedApp()); |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3231 | // HostedApps that are PWAs are always created through WebAppProvider |
Alexey Baskakov | aca7a0c | 2019-07-29 07:34:05 | [diff] [blame] | 3232 | // for profiles that support them, so we should always be able to |
| 3233 | // retrieve a WebAppProvider from the Profile. |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3234 | // |
| 3235 | // 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] | 3236 | // so there is no need to test for has_value(). |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3237 | web_prefs->web_app_scope = |
| 3238 | web_app::WebAppProvider::Get(profile) |
| 3239 | ->registrar() |
Alan Cutter | f25cfe4 | 2019-07-16 02:40:12 | [diff] [blame] | 3240 | .GetAppScope(*browser->app_controller()->GetAppId()) |
| 3241 | .value(); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3242 | } |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3243 | } |
| 3244 | #endif |
| 3245 | |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3246 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 3247 | Browser* browser = chrome::FindBrowserWithWebContents(contents); |
Eric Willigers | e339c1e | 2019-05-13 19:22:44 | [diff] [blame] | 3248 | if (browser && browser->app_controller() && |
| 3249 | browser->app_controller()->CreatedForInstalledPwa()) { |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3250 | web_prefs->strict_mixed_content_checking = true; |
| 3251 | } |
| 3252 | #endif |
| 3253 | |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3254 | web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents); |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3255 | } |
zqzhang | 93e959d1 | 2017-03-16 13:10:20 | [diff] [blame] | 3256 | |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3257 | #if defined(OS_ANDROID) |
Ted Choc | 81c89fc5 | 2018-06-22 23:51:14 | [diff] [blame] | 3258 | web_prefs->video_fullscreen_detection_enabled = true; |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3259 | #endif // defined(OS_ANDROID) |
| 3260 | |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 3261 | if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) { |
| 3262 | // Obtain the maximum effective connection type at which the feature is |
| 3263 | // enabled. |
| 3264 | std::string effective_connection_type_param = |
| 3265 | base::GetFieldTrialParamValueByFeature( |
| 3266 | features::kLowPriorityIframes, |
| 3267 | "max_effective_connection_type_threshold"); |
| 3268 | |
| 3269 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3270 | net::GetEffectiveConnectionTypeForName(effective_connection_type_param); |
| 3271 | if (effective_connection_type) { |
| 3272 | web_prefs->low_priority_iframes_threshold = |
| 3273 | effective_connection_type.value(); |
| 3274 | } |
| 3275 | } |
| 3276 | |
rajendrant | 0521cee | 2019-07-29 06:09:26 | [diff] [blame] | 3277 | web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() || |
| 3278 | contents->GetDelegate()->ShouldAllowLazyLoad(); |
rajendrant | e87ed71 | 2018-11-30 01:55:00 | [diff] [blame] | 3279 | |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 3280 | if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) { |
| 3281 | const char* param_name = |
| 3282 | web_prefs->data_saver_enabled |
| 3283 | ? "lazy_frame_loading_distance_thresholds_px_by_ect" |
| 3284 | : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_" |
| 3285 | "saver_enabled"; |
| 3286 | |
| 3287 | base::StringPairs pairs; |
| 3288 | base::SplitStringIntoKeyValuePairs( |
| 3289 | base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading, |
| 3290 | param_name), |
| 3291 | ':', ',', &pairs); |
| 3292 | |
| 3293 | for (const auto& pair : pairs) { |
| 3294 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3295 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3296 | int value = 0; |
| 3297 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3298 | web_prefs->lazy_frame_loading_distance_thresholds_px |
| 3299 | [effective_connection_type.value()] = value; |
| 3300 | } |
| 3301 | } |
| 3302 | } |
| 3303 | |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 3304 | if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) { |
| 3305 | const char* param_name = |
| 3306 | web_prefs->data_saver_enabled |
| 3307 | ? "lazy_image_loading_distance_thresholds_px_by_ect" |
| 3308 | : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_" |
| 3309 | "saver_enabled"; |
| 3310 | |
| 3311 | base::StringPairs pairs; |
| 3312 | base::SplitStringIntoKeyValuePairs( |
| 3313 | base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading, |
| 3314 | param_name), |
| 3315 | ':', ',', &pairs); |
| 3316 | |
| 3317 | for (const auto& pair : pairs) { |
| 3318 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3319 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3320 | int value = 0; |
| 3321 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3322 | web_prefs->lazy_image_loading_distance_thresholds_px |
| 3323 | [effective_connection_type.value()] = value; |
| 3324 | } |
| 3325 | } |
| 3326 | } |
| 3327 | |
Tarun Bansal | d10f17a0 | 2018-09-13 00:23:17 | [diff] [blame] | 3328 | if (base::FeatureList::IsEnabled( |
| 3329 | features::kNetworkQualityEstimatorWebHoldback)) { |
| 3330 | std::string effective_connection_type_param = |
| 3331 | base::GetFieldTrialParamValueByFeature( |
| 3332 | features::kNetworkQualityEstimatorWebHoldback, |
| 3333 | "web_effective_connection_type_override"); |
| 3334 | |
| 3335 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3336 | net::GetEffectiveConnectionTypeForName(effective_connection_type_param); |
| 3337 | DCHECK(effective_connection_type_param.empty() || |
| 3338 | effective_connection_type); |
| 3339 | if (effective_connection_type) { |
| 3340 | DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 3341 | effective_connection_type.value()); |
| 3342 | web_prefs->network_quality_estimator_web_holdback = |
| 3343 | effective_connection_type.value(); |
| 3344 | } |
| 3345 | } |
| 3346 | |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 3347 | auto* native_theme = GetWebTheme(); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3348 | #if !defined(OS_ANDROID) |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 3349 | if (IsAutoplayAllowedByPolicy(contents, prefs)) { |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3350 | // If autoplay is allowed by policy then force the no user gesture required |
| 3351 | // autoplay policy. |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3352 | web_prefs->autoplay_policy = |
| 3353 | content::AutoplayPolicy::kNoUserGestureRequired; |
Mounir Lamouri | c2186808 | 2018-10-11 21:09:55 | [diff] [blame] | 3354 | } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) && |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3355 | web_prefs->autoplay_policy == |
| 3356 | content::AutoplayPolicy::kDocumentUserActivationRequired) { |
Mounir Lamouri | c2186808 | 2018-10-11 21:09:55 | [diff] [blame] | 3357 | // If the autoplay disable settings feature is enabled and the autoplay |
| 3358 | // policy is set to using the unified policy then set the default autoplay |
| 3359 | // policy based on user preference. |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3360 | web_prefs->autoplay_policy = |
| 3361 | UnifiedAutoplayConfig::ShouldBlockAutoplay(profile) |
| 3362 | ? content::AutoplayPolicy::kDocumentUserActivationRequired |
| 3363 | : content::AutoplayPolicy::kNoUserGestureRequired; |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3364 | } |
Alison Maher | 67fd4d9f | 2019-07-12 18:34:21 | [diff] [blame] | 3365 | #if !defined(OS_MACOSX) |
| 3366 | // Mac has a concept of high contrast that does not relate to forced colors. |
Alison Maher | be15c07 | 2019-07-08 18:12:39 | [diff] [blame] | 3367 | web_prefs->forced_colors = native_theme->UsesHighContrastColors() |
| 3368 | ? blink::ForcedColors::kActive |
| 3369 | : blink::ForcedColors::kNone; |
Alison Maher | 67fd4d9f | 2019-07-12 18:34:21 | [diff] [blame] | 3370 | #endif // !defined(OS_MACOSX) |
| 3371 | |
| 3372 | switch (native_theme->GetPreferredColorScheme()) { |
| 3373 | case ui::NativeTheme::PreferredColorScheme::kDark: |
| 3374 | web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark; |
| 3375 | break; |
| 3376 | case ui::NativeTheme::PreferredColorScheme::kLight: |
| 3377 | web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight; |
| 3378 | break; |
| 3379 | case ui::NativeTheme::PreferredColorScheme::kNoPreference: |
| 3380 | web_prefs->preferred_color_scheme = |
| 3381 | blink::PreferredColorScheme::kNoPreference; |
| 3382 | } |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3383 | #endif // !defined(OS_ANDROID) |
| 3384 | |
Dave Tapuska | c6627e1 | 2018-08-30 15:07:19 | [diff] [blame] | 3385 | web_prefs->translate_service_available = TranslateService::IsAvailable(prefs); |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3386 | |
Dan Beam | 836c02a | 2019-06-15 01:58:27 | [diff] [blame] | 3387 | // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is |
| 3388 | // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS |
| 3389 | // explicitly uses light (instead of not dark), which is why we don't reset |
| 3390 | // back to no-preference. https://crbug.com/965811 |
| 3391 | if (contents && !base::FeatureList::IsEnabled(features::kWebUIDarkMode)) { |
| 3392 | bool force_light = contents->GetURL().SchemeIs(content::kChromeUIScheme); |
| 3393 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 3394 | if (!force_light) { |
| 3395 | force_light = |
| 3396 | contents->GetURL().SchemeIs(extensions::kExtensionScheme) && |
| 3397 | contents->GetURL().host_piece() == extension_misc::kPdfExtensionId; |
| 3398 | } |
| 3399 | #endif |
| 3400 | if (force_light) |
| 3401 | web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight; |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 3402 | } |
| 3403 | |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3404 | // Apply native CaptionStyle parameters. |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3405 | base::Optional<ui::CaptionStyle> style; |
| 3406 | |
| 3407 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3408 | ::switches::kForceCaptionStyle)) { |
| 3409 | style = ui::CaptionStyle::FromSpec( |
| 3410 | base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 3411 | switches::kForceCaptionStyle)); |
| 3412 | } |
| 3413 | |
| 3414 | // Apply system caption style. |
| 3415 | if (!style) { |
| 3416 | style = native_theme->GetSystemCaptionStyle(); |
| 3417 | } |
| 3418 | |
| 3419 | // Apply caption style from preferences if system caption style is undefined. |
| 3420 | if (!style && base::FeatureList::IsEnabled(features::kCaptionSettings)) { |
| 3421 | style = GetCaptionStyleFromPrefs(prefs); |
| 3422 | } |
| 3423 | |
| 3424 | if (style) { |
| 3425 | web_prefs->text_track_background_color = style->background_color; |
| 3426 | web_prefs->text_track_text_color = style->text_color; |
| 3427 | web_prefs->text_track_text_size = style->text_size; |
| 3428 | web_prefs->text_track_text_shadow = style->text_shadow; |
| 3429 | web_prefs->text_track_font_family = style->font_family; |
| 3430 | web_prefs->text_track_font_variant = style->font_variant; |
Abigail Klein | 74de85bd | 2019-07-11 19:11:56 | [diff] [blame] | 3431 | web_prefs->text_track_window_color = style->window_color; |
| 3432 | web_prefs->text_track_window_padding = style->window_padding; |
| 3433 | web_prefs->text_track_window_radius = style->window_radius; |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3434 | } |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3435 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3436 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
creis | 7b2d3d1 | 2015-02-12 23:29:50 | [diff] [blame] | 3437 | extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 3438 | } |
| 3439 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3440 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 3441 | BrowserURLHandler* handler) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3442 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 3443 | extra_parts_[i]->BrowserURLHandlerCreated(handler); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3444 | |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 3445 | // about: handler. Must come before chrome: handler, since it will |
| 3446 | // rewrite about: urls to chrome: URLs and then expect chrome: to |
creis | 94a977f6 | 2015-02-18 23:51:05 | [diff] [blame] | 3447 | // actually handle them. Also relies on a preliminary fixup phase. |
| 3448 | handler->SetFixupHandler(&FixupBrowserAboutURL); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3449 | handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 3450 | BrowserURLHandler::null_handler()); |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3451 | |
mad | fbd1085 | 2017-01-20 03:15:33 | [diff] [blame] | 3452 | // The group policy NTP URL handler must be registered before the other NTP |
| 3453 | // URL handlers below. |
| 3454 | handler->AddHandlerPair(&HandleNewTabPageLocationOverride, |
| 3455 | BrowserURLHandler::null_handler()); |
| 3456 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 3457 | #if defined(OS_ANDROID) |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3458 | // Handler to rewrite chrome://newtab on Android. |
ianwen | 465e17b | 2015-01-20 18:32:35 | [diff] [blame] | 3459 | handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL, |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3460 | BrowserURLHandler::null_handler()); |
| 3461 | #else |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3462 | // Handler to rewrite chrome://newtab for InstantExtended. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 3463 | handler->AddHandlerPair(&search::HandleNewTabURLRewrite, |
| 3464 | &search::HandleNewTabURLReverseRewrite); |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3465 | #endif |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3466 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3467 | // chrome: & friends. |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 3468 | handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI, |
| 3469 | &ChromeContentBrowserClient::HandleWebUIReverse); |
Robert Ogden | e7fdca9 | 2018-10-12 17:53:06 | [diff] [blame] | 3470 | |
| 3471 | // Handler to rewrite Preview's Server Lite Page, to show the original URL to |
| 3472 | // the user. |
| 3473 | handler->AddHandlerPair(&HandlePreviewsLitePageURLRewrite, |
| 3474 | &HandlePreviewsLitePageURLRewriteReverse); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3475 | } |
| 3476 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3477 | base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 3478 | return DownloadPrefs::GetDefaultDownloadDirectory(); |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 3479 | } |
| 3480 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 3481 | std::string ChromeContentBrowserClient::GetDefaultDownloadName() { |
| 3482 | return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 3483 | } |
| 3484 | |
Dominik Röttsches | 4734783 | 2019-03-12 17:45:01 | [diff] [blame] | 3485 | base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() { |
| 3486 | base::FilePath user_data_dir; |
| 3487 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 3488 | DCHECK(!user_data_dir.empty()); |
| 3489 | return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache")); |
| 3490 | } |
| 3491 | |
jmadill | 57b52d4 | 2015-08-21 18:16:13 | [diff] [blame] | 3492 | base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() { |
| 3493 | base::FilePath user_data_dir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 3494 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
jmadill | 57b52d4 | 2015-08-21 18:16:13 | [diff] [blame] | 3495 | DCHECK(!user_data_dir.empty()); |
| 3496 | return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache")); |
| 3497 | } |
| 3498 | |
Khushal | 7ca0b78 | 2018-07-20 05:53:27 | [diff] [blame] | 3499 | base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() { |
| 3500 | base::FilePath user_data_dir; |
| 3501 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 3502 | DCHECK(!user_data_dir.empty()); |
| 3503 | return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache")); |
| 3504 | } |
| 3505 | |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 3506 | void ChromeContentBrowserClient::DidCreatePpapiPlugin( |
| 3507 | content::BrowserPpapiHost* browser_host) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3508 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 3509 | ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host); |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 3510 | #endif |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 3511 | } |
| 3512 | |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3513 | content::BrowserPpapiHost* |
| 3514 | ChromeContentBrowserClient::GetExternalBrowserPpapiHost( |
| 3515 | int plugin_process_id) { |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 3516 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 3517 | content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3518 | while (!iter.Done()) { |
[email protected] | 7c766e9 | 2013-11-22 20:44:02 | [diff] [blame] | 3519 | nacl::NaClProcessHost* host = static_cast<nacl::NaClProcessHost*>( |
| 3520 | iter.GetDelegate()); |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3521 | if (host->process() && |
| 3522 | host->process()->GetData().id == plugin_process_id) { |
| 3523 | // Found the plugin. |
| 3524 | return host->browser_ppapi_host(); |
| 3525 | } |
| 3526 | ++iter; |
| 3527 | } |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 3528 | #endif |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3529 | return NULL; |
| 3530 | } |
| 3531 | |
[email protected] | 38cd8f7f | 2012-06-15 22:06:07 | [diff] [blame] | 3532 | bool ChromeContentBrowserClient::AllowPepperSocketAPI( |
[email protected] | 157cc90 | 2012-11-02 06:31:58 | [diff] [blame] | 3533 | content::BrowserContext* browser_context, |
| 3534 | const GURL& url, |
[email protected] | dda5482 | 2013-06-15 01:26:39 | [diff] [blame] | 3535 | bool private_api, |
[email protected] | 8b92ed18 | 2013-09-21 04:47:12 | [diff] [blame] | 3536 | const content::SocketPermissionRequest* params) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3537 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 3538 | return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI( |
| 3539 | browser_context, url, private_api, params, allowed_socket_origins_); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 3540 | #else |
[email protected] | a658d45 | 2012-03-02 12:45:29 | [diff] [blame] | 3541 | return false; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 3542 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 3543 | } |
| 3544 | |
adrian.belgun | d54465ba | 2016-05-18 10:03:58 | [diff] [blame] | 3545 | bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed( |
| 3546 | content::BrowserContext* browser_context, |
| 3547 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3548 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
adrian.belgun | d54465ba | 2016-05-18 10:03:58 | [diff] [blame] | 3549 | return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed( |
| 3550 | browser_context, url); |
| 3551 | #else |
| 3552 | return false; |
| 3553 | #endif |
| 3554 | } |
| 3555 | |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 3556 | std::unique_ptr<content::VpnServiceProxy> |
| 3557 | ChromeContentBrowserClient::GetVpnServiceProxy( |
| 3558 | content::BrowserContext* browser_context) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3559 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 3560 | return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy( |
| 3561 | browser_context); |
| 3562 | #else |
| 3563 | return nullptr; |
| 3564 | #endif |
| 3565 | } |
| 3566 | |
Brett Wilson | 804e83c | 2017-08-18 22:57:33 | [diff] [blame] | 3567 | std::unique_ptr<ui::SelectFilePolicy> |
| 3568 | ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) { |
| 3569 | return std::make_unique<ChromeSelectFilePolicy>(web_contents); |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 3570 | } |
| 3571 | |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 3572 | void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 3573 | std::vector<std::string>* additional_allowed_schemes) { |
| 3574 | ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 3575 | additional_allowed_schemes); |
[email protected] | b3690f7 | 2014-02-17 00:32:48 | [diff] [blame] | 3576 | additional_allowed_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 3577 | additional_allowed_schemes->push_back(content::kChromeUIScheme); |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3578 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
| 3579 | extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem( |
| 3580 | additional_allowed_schemes); |
| 3581 | } |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 3582 | } |
| 3583 | |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 3584 | void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist( |
| 3585 | std::set<std::string>* schemes) { |
Daniel Vogelheim | 11e59b7 | 2017-11-22 15:44:04 | [diff] [blame] | 3586 | *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck(); |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 3587 | } |
| 3588 | |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 3589 | void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3590 | std::vector<storage::URLRequestAutoMountHandler>* handlers) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3591 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 3592 | extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers); |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 3593 | } |
| 3594 | |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 3595 | ::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() { |
| 3596 | return g_browser_process->rappor_service(); |
| 3597 | } |
| 3598 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 3599 | void ChromeContentBrowserClient::GetAdditionalFileSystemBackends( |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 3600 | content::BrowserContext* browser_context, |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 3601 | const base::FilePath& storage_partition_path, |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3602 | std::vector<std::unique_ptr<storage::FileSystemBackend>>* |
| 3603 | additional_backends) { |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3604 | #if defined(OS_CHROMEOS) |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3605 | storage::ExternalMountPoints* external_mount_points = |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 3606 | content::BrowserContext::GetMountPoints(browser_context); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3607 | DCHECK(external_mount_points); |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3608 | auto backend = std::make_unique<chromeos::FileSystemBackend>( |
| 3609 | std::make_unique<drive::FileSystemBackendDelegate>(), |
| 3610 | std::make_unique<chromeos::file_system_provider::BackendDelegate>(), |
| 3611 | std::make_unique<chromeos::MTPFileSystemBackendDelegate>( |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 3612 | storage_partition_path), |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3613 | std::make_unique<arc::ArcContentFileSystemBackendDelegate>(), |
| 3614 | std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(), |
Sam McNally | 47f2eac | 2018-08-28 06:45:05 | [diff] [blame] | 3615 | std::make_unique<drive::DriveFsFileSystemBackendDelegate>( |
| 3616 | Profile::FromBrowserContext(browser_context)), |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 3617 | external_mount_points, storage::ExternalMountPoints::GetSystemInstance()); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 3618 | backend->AddSystemMountPoints(); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3619 | DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal)); |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3620 | additional_backends->push_back(std::move(backend)); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3621 | #endif |
[email protected] | 445b7db | 2013-08-02 04:58:27 | [diff] [blame] | 3622 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3623 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
| 3624 | extra_parts_[i]->GetAdditionalFileSystemBackends( |
| 3625 | browser_context, storage_partition_path, additional_backends); |
| 3626 | } |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 3627 | } |
| 3628 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3629 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 3630 | void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 3631 | const base::CommandLine& command_line, |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3632 | int child_process_id, |
brettw | 3c98c7d3 | 2017-07-25 01:44:20 | [diff] [blame] | 3633 | PosixFileDescriptorInfo* mappings) { |
Albert J. Wong | b694253 | 2017-07-13 22:49:30 | [diff] [blame] | 3634 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3635 | #if defined(OS_ANDROID) |
| 3636 | base::MemoryMappedFile::Region region; |
| 3637 | int fd = ui::GetMainAndroidPackFd(®ion); |
| 3638 | mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region); |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 3639 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3640 | fd = ui::GetCommonResourcesPackFd(®ion); |
| 3641 | mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region); |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 3642 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3643 | fd = ui::GetLocalePackFd(®ion); |
| 3644 | mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region); |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3645 | |
zpeng | 368afac8 | 2017-07-17 18:47:45 | [diff] [blame] | 3646 | // Optional secondary locale .pak file. |
| 3647 | fd = ui::GetSecondaryLocalePackFd(®ion); |
| 3648 | if (fd != -1) { |
| 3649 | mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region); |
| 3650 | } |
| 3651 | |
[email protected] | 09560f7f | 2014-06-10 18:40:28 | [diff] [blame] | 3652 | base::FilePath app_data_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 3653 | base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path); |
[email protected] | 09560f7f | 2014-06-10 18:40:28 | [diff] [blame] | 3654 | DCHECK(!app_data_path.empty()); |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 3655 | #endif // defined(OS_ANDROID) |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3656 | int crash_signal_fd = GetCrashSignalFD(command_line); |
| 3657 | if (crash_signal_fd >= 0) { |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 3658 | mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd); |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3659 | } |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3660 | } |
| 3661 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 3662 | |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 3663 | #if defined(OS_WIN) |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3664 | base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType( |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 3665 | int sandbox_type) { |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3666 | // TODO(wfh): Add support for more process types here. crbug.com/499523 |
| 3667 | switch (sandbox_type) { |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 3668 | case service_manager::SANDBOX_TYPE_RENDERER: |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 3669 | return base::string16(install_static::GetSandboxSidPrefix()) + |
| 3670 | L"129201922"; |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 3671 | case service_manager::SANDBOX_TYPE_UTILITY: |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3672 | return base::string16(); |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 3673 | case service_manager::SANDBOX_TYPE_GPU: |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3674 | return base::string16(); |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 3675 | case service_manager::SANDBOX_TYPE_PPAPI: |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 3676 | return base::string16(install_static::GetSandboxSidPrefix()) + |
| 3677 | L"129201925"; |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 3678 | #if BUILDFLAG(ENABLE_NACL) |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3679 | case PROCESS_TYPE_NACL_LOADER: |
| 3680 | return base::string16(); |
| 3681 | case PROCESS_TYPE_NACL_BROKER: |
| 3682 | return base::string16(); |
| 3683 | #endif |
| 3684 | } |
| 3685 | |
| 3686 | // Should never reach here. |
| 3687 | CHECK(0); |
| 3688 | return base::string16(); |
| 3689 | } |
| 3690 | |
rickyz | 5010931 | 2015-11-11 00:37:08 | [diff] [blame] | 3691 | bool ChromeContentBrowserClient::PreSpawnRenderer( |
| 3692 | sandbox::TargetPolicy* policy) { |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 3693 | // This code is duplicated in nacl_exe_win_64.cc. |
| 3694 | // Allow the server side of a pipe restricted to the "chrome.nacl." |
| 3695 | // namespace so that it cannot impersonate other system or other chrome |
| 3696 | // service pipes. |
| 3697 | sandbox::ResultCode result = policy->AddRule( |
| 3698 | sandbox::TargetPolicy::SUBSYS_NAMED_PIPES, |
| 3699 | sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY, |
| 3700 | L"\\\\.\\pipe\\chrome.nacl.*"); |
rickyz | 5010931 | 2015-11-11 00:37:08 | [diff] [blame] | 3701 | if (result != sandbox::SBOX_ALL_OK) |
| 3702 | return false; |
rickyz | 5010931 | 2015-11-11 00:37:08 | [diff] [blame] | 3703 | return result == sandbox::SBOX_ALL_OK; |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 3704 | } |
wfh | c91e967 | 2016-01-27 00:14:20 | [diff] [blame] | 3705 | #endif // defined(OS_WIN) |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 3706 | |
ben | d1dd50f5 | 2016-06-26 22:10:48 | [diff] [blame] | 3707 | void ChromeContentBrowserClient::ExposeInterfacesToRenderer( |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 3708 | service_manager::BinderRegistry* registry, |
Sam McNally | 52e5028 | 2017-11-29 00:54:02 | [diff] [blame] | 3709 | blink::AssociatedInterfaceRegistry* associated_registry, |
leon.han | 0b61879 | 2016-06-16 01:53:51 | [diff] [blame] | 3710 | content::RenderProcessHost* render_process_host) { |
nigeltao | beff0a10 | 2017-04-29 09:30:37 | [diff] [blame] | 3711 | // The CacheStatsRecorder is an associated binding, instead of a |
| 3712 | // non-associated one, because the sender (in the renderer process) posts the |
| 3713 | // message after a time delay, in order to rate limit. The association |
| 3714 | // protects against the render process host ID being recycled in that time |
| 3715 | // gap between the preparation and the execution of that IPC. |
| 3716 | associated_registry->AddInterface( |
| 3717 | base::Bind(&CacheStatsRecorder::Create, render_process_host->GetID())); |
| 3718 | |
ben | 5be0b913 | 2016-08-03 00:17:18 | [diff] [blame] | 3719 | scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner = |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 3720 | base::CreateSingleThreadTaskRunnerWithTraits( |
| 3721 | {content::BrowserThread::UI}); |
ben | d1dd50f5 | 2016-06-26 22:10:48 | [diff] [blame] | 3722 | registry->AddInterface( |
nigeltao | 2f67376 | 2016-10-14 03:27:28 | [diff] [blame] | 3723 | base::Bind(&rappor::RapporRecorderImpl::Create, |
| 3724 | g_browser_process->rappor_service()), |
| 3725 | ui_task_runner); |
Sadrul Habib Chowdhury | 16b3a16 | 2018-02-03 01:43:18 | [diff] [blame] | 3726 | registry->AddInterface( |
Mike Wittman | 16fa536 | 2018-09-04 17:27:30 | [diff] [blame] | 3727 | base::BindRepeating(&metrics::CallStackProfileCollector::Create)); |
Sadrul Habib Chowdhury | 16b3a16 | 2018-02-03 01:43:18 | [diff] [blame] | 3728 | |
dvallet | 233f57ab | 2016-12-21 03:17:10 | [diff] [blame] | 3729 | if (NetBenchmarking::CheckBenchmarkingEnabled()) { |
| 3730 | Profile* profile = |
| 3731 | Profile::FromBrowserContext(render_process_host->GetBrowserContext()); |
Alexandr Ilin | 4909ec8 | 2018-06-06 10:22:48 | [diff] [blame] | 3732 | auto* loading_predictor = |
| 3733 | predictors::LoadingPredictorFactory::GetForProfile(profile); |
Robbie McElrath | b0f248c | 2018-07-24 19:44:16 | [diff] [blame] | 3734 | registry->AddInterface( |
| 3735 | base::BindRepeating( |
| 3736 | &NetBenchmarking::Create, |
| 3737 | loading_predictor ? loading_predictor->GetWeakPtr() : nullptr, |
Robbie McElrath | b0f248c | 2018-07-24 19:44:16 | [diff] [blame] | 3738 | render_process_host->GetID()), |
| 3739 | ui_task_runner); |
dvallet | 233f57ab | 2016-12-21 03:17:10 | [diff] [blame] | 3740 | } |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 3741 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 3742 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
Adam Rice | 41b8959 | 2017-07-28 10:33:44 | [diff] [blame] | 3743 | if (safe_browsing_service_) { |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 3744 | content::ResourceContext* resource_context = |
| 3745 | render_process_host->GetBrowserContext()->GetResourceContext(); |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 3746 | registry->AddInterface( |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 3747 | base::Bind( |
| 3748 | &safe_browsing::MojoSafeBrowsingImpl::MaybeCreate, |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 3749 | render_process_host->GetID(), resource_context, |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 3750 | base::Bind( |
| 3751 | &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate, |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 3752 | base::Unretained(this), resource_context)), |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 3753 | base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::IO})); |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 3754 | } |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 3755 | #endif |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 3756 | |
Eric Roman | a00cf68 | 2018-11-01 20:09:11 | [diff] [blame] | 3757 | if (data_reduction_proxy::params::IsEnabledWithNetworkService()) { |
| 3758 | registry->AddInterface(base::BindRepeating( |
| 3759 | &AddDataReductionProxyBinding, |
| 3760 | render_process_host->GetBrowserContext()->GetResourceContext())); |
| 3761 | } |
| 3762 | |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 3763 | #if defined(OS_WIN) |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3764 | // Add the ModuleEventSink interface. This is the interface used by renderer |
| 3765 | // processes to notify the browser of modules in their address space. The |
| 3766 | // process handle is not yet available at this point so pass in a callback |
| 3767 | // to allow to retrieve a duplicate at the time the interface is actually |
| 3768 | // created. It is safe to pass a raw pointer to |render_process_host|: the |
Patrick Monette | aa2ec56 | 2019-03-20 23:37:45 | [diff] [blame] | 3769 | // callback will be invoked during the Mojo initialization, which occurs while |
| 3770 | // the |render_process_host| is alive. |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3771 | auto get_process = base::BindRepeating( |
| 3772 | [](content::RenderProcessHost* host) -> base::Process { |
| 3773 | return host->GetProcess().Duplicate(); |
| 3774 | }, |
| 3775 | base::Unretained(render_process_host)); |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3776 | registry->AddInterface( |
Patrick Monette | aa2ec56 | 2019-03-20 23:37:45 | [diff] [blame] | 3777 | base::BindRepeating( |
| 3778 | &ModuleEventSinkImpl::Create, std::move(get_process), |
| 3779 | content::PROCESS_TYPE_RENDERER, |
| 3780 | base::BindRepeating(&ModuleDatabase::HandleModuleLoadEvent)), |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3781 | ui_task_runner); |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 3782 | #endif |
Dan Harrington | 964d48c | 2018-08-03 15:52:24 | [diff] [blame] | 3783 | #if defined(OS_ANDROID) |
Carlos Knippschild | 63b3f04 | 2018-11-20 22:55:04 | [diff] [blame] | 3784 | Profile* profile = |
| 3785 | Profile::FromBrowserContext(render_process_host->GetBrowserContext()); |
Dan Harrington | 964d48c | 2018-08-03 15:52:24 | [diff] [blame] | 3786 | registry->AddInterface( |
| 3787 | base::BindRepeating(&android::AvailableOfflineContentProvider::Create, |
Carlos Knippschild | 63b3f04 | 2018-11-20 22:55:04 | [diff] [blame] | 3788 | profile), |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 3789 | base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI})); |
Dan Harrington | 964d48c | 2018-08-03 15:52:24 | [diff] [blame] | 3790 | #endif |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 3791 | |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 3792 | for (auto* ep : extra_parts_) { |
| 3793 | ep->ExposeInterfacesToRenderer(registry, associated_registry, |
| 3794 | render_process_host); |
| 3795 | } |
sammc | 33584452 | 2016-06-09 10:15:59 | [diff] [blame] | 3796 | } |
| 3797 | |
ben | dd157e1a | 2016-07-22 03:15:57 | [diff] [blame] | 3798 | void ChromeContentBrowserClient::ExposeInterfacesToMediaService( |
ben | 8408b13 | 2017-05-01 23:48:50 | [diff] [blame] | 3799 | service_manager::BinderRegistry* registry, |
xhwang | 9ab9648 | 2015-05-11 22:02:33 | [diff] [blame] | 3800 | content::RenderFrameHost* render_frame_host) { |
Xiaohan Wang | 15303d0c | 2017-10-06 05:22:44 | [diff] [blame] | 3801 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
| 3802 | registry->AddInterface( |
| 3803 | base::Bind(&OutputProtectionImpl::Create, render_frame_host)); |
ben | 155ecf8 | 2016-06-21 22:43:26 | [diff] [blame] | 3804 | registry->AddInterface( |
John Rummell | 1b5da610 | 2017-11-02 02:15:45 | [diff] [blame] | 3805 | base::Bind(&PlatformVerificationImpl::Create, render_frame_host)); |
Xiaohan Wang | 15303d0c | 2017-10-06 05:22:44 | [diff] [blame] | 3806 | #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c86d76e4 | 2016-03-14 23:38:49 | [diff] [blame] | 3807 | |
xhwang | db24d60 | 2017-05-20 06:32:24 | [diff] [blame] | 3808 | #if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID) |
cm.sanchi | ad3f42a6 | 2017-11-07 11:33:35 | [diff] [blame] | 3809 | registry->AddInterface(base::Bind(&CreateMediaDrmStorage, render_frame_host)); |
xhwang | 116acb9 | 2017-04-03 18:27:20 | [diff] [blame] | 3810 | #endif |
xhwang | 9ab9648 | 2015-05-11 22:02:33 | [diff] [blame] | 3811 | } |
| 3812 | |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 3813 | void ChromeContentBrowserClient::BindInterfaceRequestFromFrame( |
| 3814 | content::RenderFrameHost* render_frame_host, |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 3815 | const std::string& interface_name, |
| 3816 | mojo::ScopedMessagePipeHandle interface_pipe) { |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 3817 | if (!frame_interfaces_ && !frame_interfaces_parameterized_ && |
| 3818 | !worker_interfaces_parameterized_) { |
| 3819 | InitWebContextInterfaces(); |
| 3820 | } |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 3821 | |
Ben Goodger | 272e063 | 2017-07-19 23:27:00 | [diff] [blame] | 3822 | if (!frame_interfaces_parameterized_->TryBindInterface( |
| 3823 | interface_name, &interface_pipe, render_frame_host)) { |
| 3824 | frame_interfaces_->TryBindInterface(interface_name, &interface_pipe); |
juncai | 1bf9f7c | 2016-03-22 20:46:56 | [diff] [blame] | 3825 | } |
rockot | 0fa66a8 | 2015-06-11 17:25:45 | [diff] [blame] | 3826 | } |
| 3827 | |
Mario Sanchez Prada | 39dee4a | 2019-07-09 07:15:40 | [diff] [blame] | 3828 | void ChromeContentBrowserClient::BindCredentialManagerReceiver( |
Oksana Zhuravlova | 23ecbb40 | 2019-03-29 19:44:11 | [diff] [blame] | 3829 | content::RenderFrameHost* render_frame_host, |
Mario Sanchez Prada | 39dee4a | 2019-07-09 07:15:40 | [diff] [blame] | 3830 | mojo::PendingReceiver<blink::mojom::CredentialManager> receiver) { |
| 3831 | ChromePasswordManagerClient::BindCredentialManager(std::move(receiver), |
Oksana Zhuravlova | 23ecbb40 | 2019-03-29 19:44:11 | [diff] [blame] | 3832 | render_frame_host); |
| 3833 | } |
| 3834 | |
Ken Rockot | 0aad7ec | 2018-07-31 15:58:44 | [diff] [blame] | 3835 | bool ChromeContentBrowserClient::BindAssociatedInterfaceRequestFromFrame( |
| 3836 | content::RenderFrameHost* render_frame_host, |
| 3837 | const std::string& interface_name, |
| 3838 | mojo::ScopedInterfaceEndpointHandle* handle) { |
| 3839 | if (interface_name == autofill::mojom::AutofillDriver::Name_) { |
| 3840 | autofill::ContentAutofillDriverFactory::BindAutofillDriver( |
Shimi Zhang | 6b72d29 | 2019-07-12 20:52:42 | [diff] [blame] | 3841 | mojo::PendingAssociatedReceiver<autofill::mojom::AutofillDriver>( |
| 3842 | std::move(*handle)), |
Ken Rockot | 0aad7ec | 2018-07-31 15:58:44 | [diff] [blame] | 3843 | render_frame_host); |
| 3844 | return true; |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3845 | } |
| 3846 | if (interface_name == autofill::mojom::PasswordManagerDriver::Name_) { |
Shimi Zhang | 6b72d29 | 2019-07-12 20:52:42 | [diff] [blame] | 3847 | password_manager::ContentPasswordManagerDriverFactory:: |
| 3848 | BindPasswordManagerDriver( |
| 3849 | autofill::mojom::PasswordManagerDriverAssociatedRequest( |
| 3850 | std::move(*handle)), |
| 3851 | render_frame_host); |
Dominic Battre | 97d5edf | 2019-03-26 13:41:38 | [diff] [blame] | 3852 | return true; |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3853 | } |
| 3854 | if (interface_name == content_capture::mojom::ContentCaptureReceiver::Name_) { |
Tao Bai | 02ab4dd4 | 2019-03-06 00:30:37 | [diff] [blame] | 3855 | content_capture::ContentCaptureReceiverManager::BindContentCaptureReceiver( |
Shimi Zhang | 8ee3233 | 2019-07-12 17:59:36 | [diff] [blame] | 3856 | mojo::PendingAssociatedReceiver< |
| 3857 | content_capture::mojom::ContentCaptureReceiver>(std::move(*handle)), |
Tao Bai | 02ab4dd4 | 2019-03-06 00:30:37 | [diff] [blame] | 3858 | render_frame_host); |
| 3859 | return true; |
Ken Rockot | 0aad7ec | 2018-07-31 15:58:44 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | return false; |
| 3863 | } |
| 3864 | |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 3865 | void ChromeContentBrowserClient::BindInterfaceRequestFromWorker( |
| 3866 | content::RenderProcessHost* render_process_host, |
| 3867 | const url::Origin& origin, |
| 3868 | const std::string& interface_name, |
| 3869 | mojo::ScopedMessagePipeHandle interface_pipe) { |
| 3870 | if (!frame_interfaces_ && !frame_interfaces_parameterized_ && |
| 3871 | !worker_interfaces_parameterized_) { |
| 3872 | InitWebContextInterfaces(); |
| 3873 | } |
| 3874 | |
| 3875 | worker_interfaces_parameterized_->BindInterface( |
| 3876 | interface_name, std::move(interface_pipe), render_process_host, origin); |
| 3877 | } |
| 3878 | |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 3879 | void ChromeContentBrowserClient::BindInterfaceRequest( |
ben | 2c36828d | 2017-05-02 04:09:01 | [diff] [blame] | 3880 | const service_manager::BindSourceInfo& source_info, |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 3881 | const std::string& interface_name, |
| 3882 | mojo::ScopedMessagePipeHandle* interface_pipe) { |
Ben Goodger | 272e063 | 2017-07-19 23:27:00 | [diff] [blame] | 3883 | if (source_info.identity.name() == content::mojom::kGpuServiceName) |
| 3884 | gpu_binder_registry_.TryBindInterface(interface_name, interface_pipe); |
wittman | 757af87 | 2016-08-16 00:13:46 | [diff] [blame] | 3885 | } |
| 3886 | |
Ken Rockot | fa5d5711 | 2019-05-29 20:57:14 | [diff] [blame] | 3887 | void ChromeContentBrowserClient::WillStartServiceManager() { |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3888 | #if defined(OS_WIN) |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 3889 | if (startup_data_) { |
| 3890 | auto* chrome_feature_list_creator = |
| 3891 | startup_data_->chrome_feature_list_creator(); |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3892 | // This has to run very early before ServiceManagerContext is created. |
| 3893 | const base::Value* force_network_in_process_value = |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 3894 | chrome_feature_list_creator->browser_policy_connector() |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3895 | ->GetPolicyService() |
| 3896 | ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
| 3897 | std::string())) |
| 3898 | .GetValue(policy::key::kForceNetworkInProcess); |
| 3899 | bool force_network_in_process = false; |
| 3900 | if (force_network_in_process_value) |
| 3901 | force_network_in_process_value->GetAsBoolean(&force_network_in_process); |
| 3902 | if (force_network_in_process) |
| 3903 | content::ForceInProcessNetworkService(true); |
| 3904 | } |
| 3905 | #endif |
xhwang | 5e63046 | 2015-10-30 03:18:48 | [diff] [blame] | 3906 | } |
| 3907 | |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3908 | void ChromeContentBrowserClient::RunServiceInstance( |
| 3909 | const service_manager::Identity& identity, |
| 3910 | mojo::PendingReceiver<service_manager::mojom::Service>* receiver) { |
| 3911 | const std::string& service_name = identity.name(); |
Ken Rockot | 0875052 | 2018-11-29 07:41:34 | [diff] [blame] | 3912 | if (service_name == prefs::mojom::kLocalStateServiceName) { |
| 3913 | if (!g_browser_process || !g_browser_process->pref_service_factory()) |
| 3914 | return; |
| 3915 | |
Ken Rockot | d80eb10 | 2018-11-29 14:55:16 | [diff] [blame] | 3916 | service_manager::Service::RunAsyncUntilTermination( |
Ken Rockot | 0875052 | 2018-11-29 07:41:34 | [diff] [blame] | 3917 | g_browser_process->pref_service_factory()->CreatePrefService( |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3918 | std::move(*receiver))); |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3919 | return; |
Ken Rockot | 0875052 | 2018-11-29 07:41:34 | [diff] [blame] | 3920 | } |
| 3921 | |
Alexander Woolf | ed183c51 | 2019-05-17 01:18:03 | [diff] [blame] | 3922 | #if defined(OS_WIN) |
| 3923 | bool run_quarantine_service_in_process = |
| 3924 | !base::FeatureList::IsEnabled(quarantine::kOutOfProcessQuarantine); |
| 3925 | #else |
| 3926 | bool run_quarantine_service_in_process = true; |
| 3927 | #endif |
| 3928 | |
| 3929 | if (run_quarantine_service_in_process && |
| 3930 | service_name == quarantine::mojom::kServiceName) { |
| 3931 | service_manager::Service::RunAsyncUntilTermination( |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3932 | std::make_unique<quarantine::QuarantineService>(std::move(*receiver))); |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3933 | return; |
Alexander Woolf | ed183c51 | 2019-05-17 01:18:03 | [diff] [blame] | 3934 | } |
| 3935 | |
Ken Rockot | 3d8be74 | 2018-11-22 08:59:38 | [diff] [blame] | 3936 | #if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS) |
| 3937 | if (service_name == media::mojom::kMediaServiceName) { |
Ken Rockot | d80eb10 | 2018-11-29 14:55:16 | [diff] [blame] | 3938 | service_manager::Service::RunAsyncUntilTermination( |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3939 | media::CreateMediaService(std::move(*receiver))); |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3940 | return; |
Ken Rockot | 3d8be74 | 2018-11-22 08:59:38 | [diff] [blame] | 3941 | } |
| 3942 | #endif |
Ken Rockot | e116c20 | 2018-11-30 01:52:50 | [diff] [blame] | 3943 | |
Ken Rockot | c15f3499 | 2018-12-01 21:27:57 | [diff] [blame] | 3944 | #if BUILDFLAG(ENABLE_SIMPLE_BROWSER_SERVICE_IN_PROCESS) |
| 3945 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3946 | switches::kLaunchInProcessSimpleBrowserSwitch) && |
| 3947 | service_name == simple_browser::mojom::kServiceName) { |
| 3948 | service_manager::Service::RunAsyncUntilTermination( |
| 3949 | std::make_unique<simple_browser::SimpleBrowserService>( |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3950 | std::move(*receiver), simple_browser::SimpleBrowserService:: |
| 3951 | UIInitializationMode::kUseEnvironmentUI)); |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3952 | return; |
Ken Rockot | c15f3499 | 2018-12-01 21:27:57 | [diff] [blame] | 3953 | } |
| 3954 | #endif |
| 3955 | |
Ken Rockot | e116c20 | 2018-11-30 01:52:50 | [diff] [blame] | 3956 | #if defined(OS_CHROMEOS) |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3957 | if (base::FeatureList::IsEnabled( |
| 3958 | chromeos::features::kUpdatedCellularActivationUi) && |
| 3959 | service_name == chromeos::cellular_setup::mojom::kServiceName) { |
Kyle Horimoto | 1d6a679f | 2019-04-16 23:24:21 | [diff] [blame] | 3960 | service_manager::Service::RunAsyncUntilTermination( |
| 3961 | std::make_unique<chromeos::cellular_setup::CellularSetupService>( |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3962 | std::move(*receiver))); |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3963 | return; |
Kyle Horimoto | 1d6a679f | 2019-04-16 23:24:21 | [diff] [blame] | 3964 | } |
| 3965 | |
Regan Hsu | 07912b7d | 2018-12-13 21:27:01 | [diff] [blame] | 3966 | if (service_name == chromeos::secure_channel::mojom::kServiceName) { |
Ken Rockot | c15f3499 | 2018-12-01 21:27:57 | [diff] [blame] | 3967 | service_manager::Service::RunAsyncUntilTermination( |
| 3968 | std::make_unique<chromeos::secure_channel::SecureChannelService>( |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3969 | std::move(*receiver))); |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3970 | return; |
Ken Rockot | c15f3499 | 2018-12-01 21:27:57 | [diff] [blame] | 3971 | } |
| 3972 | |
Steven Bennetts | 0c565d5b | 2019-04-24 23:52:45 | [diff] [blame] | 3973 | if (service_name == chromeos::network_config::mojom::kServiceName) { |
| 3974 | service_manager::Service::RunAsyncUntilTermination( |
| 3975 | std::make_unique<chromeos::network_config::NetworkConfigService>( |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3976 | std::move(*receiver))); |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3977 | return; |
Steven Bennetts | 0c565d5b | 2019-04-24 23:52:45 | [diff] [blame] | 3978 | } |
| 3979 | |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3980 | auto service = ash_service_registry::HandleServiceRequest( |
| 3981 | service_name, std::move(*receiver)); |
Ken Rockot | c15f3499 | 2018-12-01 21:27:57 | [diff] [blame] | 3982 | if (service) |
| 3983 | service_manager::Service::RunAsyncUntilTermination(std::move(service)); |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3984 | #endif // defined(OS_CHROMEOS) |
Ken Rockot | 3d8be74 | 2018-11-22 08:59:38 | [diff] [blame] | 3985 | } |
| 3986 | |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3987 | void ChromeContentBrowserClient::RunServiceInstanceOnIOThread( |
| 3988 | const service_manager::Identity& identity, |
| 3989 | mojo::PendingReceiver<service_manager::mojom::Service>* receiver) { |
| 3990 | if (identity.name() == chrome::mojom::kServiceName) { |
| 3991 | ChromeService::GetInstance()->CreateChromeServiceRequestHandler().Run( |
| 3992 | std::move(*receiver)); |
| 3993 | return; |
| 3994 | } |
| 3995 | |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3996 | if (identity.name() == heap_profiling::mojom::kServiceName) { |
| 3997 | heap_profiling::HeapProfilingService::GetServiceFactory().Run( |
| 3998 | std::move(*receiver)); |
| 3999 | return; |
| 4000 | } |
| 4001 | } |
| 4002 | |
Ken Rockot | 8f39a27 | 2018-12-21 23:38:35 | [diff] [blame] | 4003 | base::Optional<service_manager::Manifest> |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 4004 | ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) { |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 4005 | if (name == content::mojom::kBrowserServiceName) |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 4006 | return GetChromeContentBrowserOverlayManifest(); |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 4007 | if (name == content::mojom::kGpuServiceName) |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 4008 | return GetChromeContentGpuOverlayManifest(); |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 4009 | if (name == content::mojom::kRendererServiceName) |
| 4010 | return GetChromeContentRendererOverlayManifest(); |
| 4011 | if (name == content::mojom::kUtilityServiceName) |
| 4012 | return GetChromeContentUtilityOverlayManifest(); |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 4013 | return base::nullopt; |
ben | c70c0e3 | 2016-09-22 03:50:37 | [diff] [blame] | 4014 | } |
| 4015 | |
Ken Rockot | 69aade0 | 2019-01-23 21:19:51 | [diff] [blame] | 4016 | std::vector<service_manager::Manifest> |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 4017 | ChromeContentBrowserClient::GetExtraServiceManifests() { |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 4018 | auto manifests = GetChromeBuiltinServiceManifests(); |
| 4019 | manifests.push_back(GetChromeRendererManifest()); |
| 4020 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 4021 | #if BUILDFLAG(ENABLE_NACL) |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 4022 | manifests.push_back(GetNaClLoaderManifest()); |
Ken Rockot | 69aade0 | 2019-01-23 21:19:51 | [diff] [blame] | 4023 | #if defined(OS_WIN) && defined(ARCH_CPU_X86) |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 4024 | manifests.push_back(GetNaClBrokerManifest()); |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 4025 | #endif // defined(OS_WIN) |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 4026 | #endif // BUILDFLAG(ENABLE_NACL) |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 4027 | |
| 4028 | return manifests; |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 4029 | } |
| 4030 | |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 4031 | void ChromeContentBrowserClient::OpenURL( |
Matt Falkenhagen | 18c5c5d | 2018-11-26 02:55:37 | [diff] [blame] | 4032 | content::SiteInstance* site_instance, |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 4033 | const content::OpenURLParams& params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 4034 | base::OnceCallback<void(content::WebContents*)> callback) { |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 4035 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Matt Falkenhagen | 18c5c5d | 2018-11-26 02:55:37 | [diff] [blame] | 4036 | DCHECK(ShouldAllowOpenURL(site_instance, params.url)); |
| 4037 | |
| 4038 | content::BrowserContext* browser_context = site_instance->GetBrowserContext(); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 4039 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 4040 | #if defined(OS_ANDROID) |
pkotwicz | aa289f0 | 2016-07-05 22:26:22 | [diff] [blame] | 4041 | ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 4042 | std::move(callback)); |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 4043 | #else |
cm.sanchi | 2522bc9 | 2017-12-04 08:04:13 | [diff] [blame] | 4044 | NavigateParams nav_params(Profile::FromBrowserContext(browser_context), |
| 4045 | params.url, params.transition); |
| 4046 | nav_params.FillNavigateParamsFromOpenURLParams(params); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 4047 | nav_params.user_gesture = params.user_gesture; |
| 4048 | |
| 4049 | Navigate(&nav_params); |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 4050 | std::move(callback).Run(nav_params.navigated_or_inserted_contents); |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 4051 | #endif |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 4052 | } |
| 4053 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 4054 | content::ControllerPresentationServiceDelegate* |
| 4055 | ChromeContentBrowserClient::GetControllerPresentationServiceDelegate( |
| 4056 | content::WebContents* web_contents) { |
mfoltz | 99bd44c | 2016-03-18 20:36:46 | [diff] [blame] | 4057 | if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) { |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 4058 | return media_router::PresentationServiceDelegateImpl:: |
| 4059 | GetOrCreateForWebContents(web_contents); |
| 4060 | } |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 4061 | return nullptr; |
| 4062 | } |
| 4063 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 4064 | content::ReceiverPresentationServiceDelegate* |
| 4065 | ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate( |
| 4066 | content::WebContents* web_contents) { |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 4067 | if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) { |
| 4068 | // ReceiverPresentationServiceDelegateImpl exists only for WebContents |
| 4069 | // created for offscreen presentations. The WebContents must belong to |
| 4070 | // an incognito profile. |
| 4071 | if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl:: |
| 4072 | FromWebContents(web_contents)) { |
| 4073 | DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord()); |
| 4074 | return impl; |
| 4075 | } |
| 4076 | } |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 4077 | return nullptr; |
| 4078 | } |
| 4079 | |
horo | 48d4d3e | 2015-02-27 03:04:00 | [diff] [blame] | 4080 | void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric, |
| 4081 | const GURL& url) { |
mathp | 46284f3 | 2015-03-11 13:06:41 | [diff] [blame] | 4082 | if (url.is_valid()) { |
| 4083 | rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
| 4084 | metric, url); |
| 4085 | } |
horo | 48d4d3e | 2015-02-27 03:04:00 | [diff] [blame] | 4086 | } |
| 4087 | |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 4088 | std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) { |
| 4089 | // Don't change these returned strings. They are written (in hashed form) into |
| 4090 | // UMA logs. If you add more strings, you must update histograms.xml and get |
| 4091 | // histograms review. Only Google domains should be here for privacy purposes. |
| 4092 | // TODO(falken): Ideally Chrome would log the relevant UMA directly and this |
| 4093 | // function could be removed. |
Matt Falkenhagen | 2c98ee29a | 2017-07-20 16:43:19 | [diff] [blame] | 4094 | if (page_load_metrics::IsGoogleSearchResultUrl(url)) |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 4095 | return "search"; |
Matt Falkenhagen | 2c98ee29a | 2017-07-20 16:43:19 | [diff] [blame] | 4096 | if (url.host() == "docs.google.com") |
| 4097 | return "docs"; |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 4098 | return std::string(); |
| 4099 | } |
| 4100 | |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 4101 | std::vector<std::unique_ptr<content::NavigationThrottle>> |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4102 | ChromeContentBrowserClient::CreateThrottlesForNavigation( |
| 4103 | content::NavigationHandle* handle) { |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 4104 | std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 4105 | |
bmcquade | b455655 | 2017-03-24 22:24:37 | [diff] [blame] | 4106 | // MetricsNavigationThrottle requires that it runs before NavigationThrottles |
| 4107 | // that may delay or cancel navigations, so only NavigationThrottles that |
| 4108 | // don't delay or cancel navigations (e.g. throttles that are only observing |
| 4109 | // callbacks without affecting navigation behavior) should be added before |
| 4110 | // MetricsNavigationThrottle. |
| 4111 | if (handle->IsInMainFrame()) { |
| 4112 | throttles.push_back( |
| 4113 | page_load_metrics::MetricsNavigationThrottle::Create(handle)); |
| 4114 | } |
| 4115 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4116 | #if BUILDFLAG(ENABLE_PLUGINS) |
tommycli | ae590f160 | 2016-11-02 03:59:23 | [diff] [blame] | 4117 | std::unique_ptr<content::NavigationThrottle> flash_url_throttle = |
| 4118 | FlashDownloadInterception::MaybeCreateThrottleFor(handle); |
| 4119 | if (flash_url_throttle) |
| 4120 | throttles.push_back(std::move(flash_url_throttle)); |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 4121 | #endif |
| 4122 | |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 4123 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 4124 | std::unique_ptr<content::NavigationThrottle> supervised_user_throttle = |
| 4125 | SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle); |
| 4126 | if (supervised_user_throttle) |
| 4127 | throttles.push_back(std::move(supervised_user_throttle)); |
| 4128 | #endif |
| 4129 | |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4130 | #if defined(OS_ANDROID) |
| 4131 | // TODO(davidben): This is insufficient to integrate with prerender properly. |
| 4132 | // https://crbug.com/370595 |
| 4133 | prerender::PrerenderContents* prerender_contents = |
| 4134 | prerender::PrerenderContents::FromWebContents(handle->GetWebContents()); |
| 4135 | if (!prerender_contents && handle->IsInMainFrame()) { |
| 4136 | throttles.push_back( |
| 4137 | navigation_interception::InterceptNavigationDelegate::CreateThrottleFor( |
Charlie Harrison | 3286ab7 | 2019-02-13 20:13:30 | [diff] [blame] | 4138 | handle, navigation_interception::SynchronyMode::kAsync)); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4139 | } |
Min Qin | 0ab0e16 | 2017-11-14 21:57:19 | [diff] [blame] | 4140 | throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle)); |
Giovanni Ortuño Urquidi | 7ae7fb0 | 2017-10-09 01:49:57 | [diff] [blame] | 4141 | #elif BUILDFLAG(ENABLE_EXTENSIONS) |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4142 | if (handle->IsInMainFrame()) { |
| 4143 | // Redirect some navigations to apps that have registered matching URL |
| 4144 | // handlers ('url_handlers' in the manifest). |
Giovanni Ortuño Urquidi | 7ae7fb0 | 2017-10-09 01:49:57 | [diff] [blame] | 4145 | auto url_to_app_throttle = |
| 4146 | PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4147 | if (url_to_app_throttle) |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 4148 | throttles.push_back(std::move(url_to_app_throttle)); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4149 | } |
| 4150 | #endif |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4151 | |
| 4152 | #if defined(OS_CHROMEOS) |
| 4153 | // Check if we need to add merge session throttle. This throttle will postpone |
| 4154 | // loading of main frames. |
| 4155 | if (handle->IsInMainFrame()) { |
| 4156 | // Add interstitial page while merge session process (cookie reconstruction |
| 4157 | // from OAuth2 refresh token in ChromeOS login) is still in progress while |
| 4158 | // we are attempting to load a google property. |
csharrison | dd06bab | 2016-07-22 14:15:02 | [diff] [blame] | 4159 | if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() && |
| 4160 | !merge_session_throttling_utils::AreAllSessionMergedAlready() && |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4161 | handle->GetURL().SchemeIsHTTPOrHTTPS()) { |
| 4162 | throttles.push_back(MergeSessionNavigationThrottle::Create(handle)); |
| 4163 | } |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4164 | } |
| 4165 | #endif |
djacobo | 21e56e0 | 2016-07-02 01:14:31 | [diff] [blame] | 4166 | |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4167 | #if !defined(OS_ANDROID) |
| 4168 | if (base::FeatureList::IsEnabled(features::kIntentPicker)) { |
Dominick Ng | 7c28994 | 2018-03-27 05:57:15 | [diff] [blame] | 4169 | auto url_to_apps_throttle = |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4170 | #if defined(OS_CHROMEOS) |
| 4171 | chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle); |
| 4172 | #else |
| 4173 | apps::AppsNavigationThrottle::MaybeCreate(handle); |
| 4174 | #endif |
Dominick Ng | 7c28994 | 2018-03-27 05:57:15 | [diff] [blame] | 4175 | if (url_to_apps_throttle) |
| 4176 | throttles.push_back(std::move(url_to_apps_throttle)); |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4177 | } |
| 4178 | #endif |
| 4179 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 4180 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 4181 | throttles.push_back( |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4182 | std::make_unique<extensions::ExtensionNavigationThrottle>(handle)); |
Clark DuVall | 2cf99249e | 2018-09-19 19:11:51 | [diff] [blame] | 4183 | |
| 4184 | std::unique_ptr<content::NavigationThrottle> user_script_throttle = |
| 4185 | extensions::ExtensionsBrowserClient::Get() |
| 4186 | ->GetUserScriptListener() |
| 4187 | ->CreateNavigationThrottle(handle); |
| 4188 | if (user_script_throttle) |
| 4189 | throttles.push_back(std::move(user_script_throttle)); |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 4190 | #endif |
| 4191 | |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 4192 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 4193 | std::unique_ptr<content::NavigationThrottle> supervised_user_nav_throttle = |
| 4194 | SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle); |
| 4195 | if (supervised_user_nav_throttle) |
| 4196 | throttles.push_back(std::move(supervised_user_nav_throttle)); |
| 4197 | #endif |
| 4198 | |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 4199 | content::WebContents* web_contents = handle->GetWebContents(); |
csharrison | 77bf834 | 2017-05-04 18:23:10 | [diff] [blame] | 4200 | if (auto* subresource_filter_client = |
| 4201 | ChromeSubresourceFilterClient::FromWebContents(web_contents)) { |
| 4202 | subresource_filter_client->MaybeAppendNavigationThrottles(handle, |
| 4203 | &throttles); |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 4204 | } |
| 4205 | |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 4206 | #if !defined(OS_ANDROID) |
| 4207 | // BackgroundTabNavigationThrottle is used by TabManager, which is only |
| 4208 | // enabled on non-Android platforms. |
| 4209 | std::unique_ptr<content::NavigationThrottle> |
| 4210 | background_tab_navigation_throttle = resource_coordinator:: |
| 4211 | BackgroundTabNavigationThrottle::MaybeCreateThrottleFor(handle); |
| 4212 | if (background_tab_navigation_throttle) |
| 4213 | throttles.push_back(std::move(background_tab_navigation_throttle)); |
| 4214 | #endif |
| 4215 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4216 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
Jialiu Lin | bdbb81d | 2017-10-11 21:29:09 | [diff] [blame] | 4217 | std::unique_ptr<content::NavigationThrottle> |
| 4218 | password_protection_navigation_throttle = |
| 4219 | safe_browsing::MaybeCreateNavigationThrottle(handle); |
| 4220 | if (password_protection_navigation_throttle) { |
| 4221 | throttles.push_back(std::move(password_protection_navigation_throttle)); |
| 4222 | } |
| 4223 | #endif |
| 4224 | |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 4225 | std::unique_ptr<content::NavigationThrottle> |
Mustafa Emre Acer | e14f626 | 2019-04-02 00:19:31 | [diff] [blame] | 4226 | lookalike_url_navigation_throttle = lookalikes:: |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 4227 | LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle); |
| 4228 | if (lookalike_url_navigation_throttle) |
| 4229 | throttles.push_back(std::move(lookalike_url_navigation_throttle)); |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 4230 | |
Amber Won | f56d8f4 | 2017-08-31 22:29:40 | [diff] [blame] | 4231 | std::unique_ptr<content::NavigationThrottle> pdf_iframe_throttle = |
| 4232 | PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle); |
| 4233 | if (pdf_iframe_throttle) |
| 4234 | throttles.push_back(std::move(pdf_iframe_throttle)); |
Amber Won | 6b5edc75 | 2017-08-17 19:23:54 | [diff] [blame] | 4235 | |
Charles Harrison | 6dd11d28 | 2017-10-03 06:14:51 | [diff] [blame] | 4236 | std::unique_ptr<content::NavigationThrottle> tab_under_throttle = |
| 4237 | TabUnderNavigationThrottle::MaybeCreate(handle); |
| 4238 | if (tab_under_throttle) |
| 4239 | throttles.push_back(std::move(tab_under_throttle)); |
| 4240 | |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4241 | throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>( |
Doug Turner | 9dcaf596 | 2017-12-21 04:38:53 | [diff] [blame] | 4242 | handle, handle->GetWebContents()->GetBrowserContext())); |
| 4243 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4244 | throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>( |
| 4245 | handle, |
| 4246 | std::make_unique<CertificateReportingServiceCertReporter>(web_contents), |
| 4247 | base::Bind(&SSLErrorHandler::HandleSSLError))); |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 4248 | |
Christopher Thompson | 4137cec | 2017-12-19 05:34:23 | [diff] [blame] | 4249 | std::unique_ptr<content::NavigationThrottle> https_upgrade_timing_throttle = |
| 4250 | TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle); |
| 4251 | if (https_upgrade_timing_throttle) |
| 4252 | throttles.push_back(std::move(https_upgrade_timing_throttle)); |
| 4253 | |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 4254 | #if !defined(OS_ANDROID) |
| 4255 | std::unique_ptr<content::NavigationThrottle> devtools_throttle = |
| 4256 | DevToolsWindow::MaybeCreateNavigationThrottle(handle); |
| 4257 | if (devtools_throttle) |
| 4258 | throttles.push_back(std::move(devtools_throttle)); |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 4259 | |
| 4260 | std::unique_ptr<content::NavigationThrottle> new_tab_page_throttle = |
| 4261 | NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle); |
| 4262 | if (new_tab_page_throttle) |
| 4263 | throttles.push_back(std::move(new_tab_page_throttle)); |
jdoerrie | 4f9376f | 2018-12-12 18:26:20 | [diff] [blame] | 4264 | |
| 4265 | std::unique_ptr<content::NavigationThrottle> |
| 4266 | google_password_manager_throttle = |
| 4267 | GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor( |
| 4268 | handle); |
| 4269 | if (google_password_manager_throttle) |
| 4270 | throttles.push_back(std::move(google_password_manager_throttle)); |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 4271 | #endif |
| 4272 | |
Robert Ogden | afd250b | 2018-07-25 22:21:03 | [diff] [blame] | 4273 | std::unique_ptr<content::NavigationThrottle> previews_lite_page_throttle = |
| 4274 | PreviewsLitePageDecider::MaybeCreateThrottleFor(handle); |
| 4275 | if (previews_lite_page_throttle) |
| 4276 | throttles.push_back(std::move(previews_lite_page_throttle)); |
Carlos IL | 4ee307e | 2018-12-22 03:19:00 | [diff] [blame] | 4277 | if (base::FeatureList::IsEnabled(safe_browsing::kCommittedSBInterstitials)) { |
| 4278 | throttles.push_back( |
| 4279 | std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>( |
| 4280 | handle)); |
| 4281 | } |
Robert Ogden | afd250b | 2018-07-25 22:21:03 | [diff] [blame] | 4282 | |
Nicolas Ouellet-Payeur | bdcab009 | 2018-10-22 14:50:33 | [diff] [blame] | 4283 | #if defined(OS_WIN) || defined(OS_MACOSX) || \ |
| 4284 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
Nicolas Ouellet-Payeur | 995e777 | 2018-09-13 16:02:13 | [diff] [blame] | 4285 | std::unique_ptr<content::NavigationThrottle> browser_switcher_throttle = |
| 4286 | browser_switcher::BrowserSwitcherNavigationThrottle :: |
| 4287 | MaybeCreateThrottleFor(handle); |
| 4288 | if (browser_switcher_throttle) |
| 4289 | throttles.push_back(std::move(browser_switcher_throttle)); |
| 4290 | #endif |
| 4291 | |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 4292 | return throttles; |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4293 | } |
| 4294 | |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 4295 | std::unique_ptr<content::NavigationUIData> |
| 4296 | ChromeContentBrowserClient::GetNavigationUIData( |
| 4297 | content::NavigationHandle* navigation_handle) { |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4298 | return std::make_unique<ChromeNavigationUIData>(navigation_handle); |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 4299 | } |
| 4300 | |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4301 | void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps( |
| 4302 | const std::string& key_system, |
| 4303 | const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols, |
| 4304 | base::flat_set<media::VideoCodec>* video_codecs, |
| 4305 | base::flat_set<media::EncryptionMode>* encryption_schemes) { |
| 4306 | #if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \ |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 4307 | BUILDFLAG(ENABLE_WIDEVINE) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4308 | if (key_system == kWidevineKeySystem) { |
| 4309 | GetWidevineHardwareCaps(cdm_proxy_protocols, video_codecs, |
| 4310 | encryption_schemes); |
| 4311 | } |
| 4312 | #endif |
| 4313 | } |
| 4314 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4315 | content::DevToolsManagerDelegate* |
| 4316 | ChromeContentBrowserClient::GetDevToolsManagerDelegate() { |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 4317 | #if defined(OS_ANDROID) |
| 4318 | return new DevToolsManagerDelegateAndroid(); |
| 4319 | #else |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4320 | return new ChromeDevToolsManagerDelegate(); |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 4321 | #endif |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4322 | } |
| 4323 | |
Rayan Kanso | 411e84e | 2019-02-13 15:27:40 | [diff] [blame] | 4324 | void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration( |
| 4325 | content::BrowserContext* browser_context, |
| 4326 | int service, |
| 4327 | base::Time expiration_time) { |
| 4328 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4329 | DCHECK(profile); |
| 4330 | |
| 4331 | auto* pref_service = profile->GetPrefs(); |
| 4332 | DCHECK(pref_service); |
| 4333 | |
| 4334 | DictionaryPrefUpdate pref_update( |
| 4335 | pref_service, prefs::kDevToolsBackgroundServicesExpirationDict); |
| 4336 | base::DictionaryValue* exp_dict = pref_update.Get(); |
| 4337 | |
| 4338 | // Convert |expiration_time| to minutes since that is the most granular |
| 4339 | // option that returns an int. base::Value does not accept int64. |
| 4340 | int expiration_time_minutes = |
| 4341 | expiration_time.ToDeltaSinceWindowsEpoch().InMinutes(); |
| 4342 | exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes); |
| 4343 | } |
| 4344 | |
| 4345 | base::flat_map<int, base::Time> |
| 4346 | ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations( |
| 4347 | content::BrowserContext* browser_context) { |
| 4348 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4349 | DCHECK(profile); |
| 4350 | |
| 4351 | auto* pref_service = profile->GetPrefs(); |
| 4352 | DCHECK(pref_service); |
| 4353 | |
| 4354 | auto* expiration_dict = pref_service->GetDictionary( |
| 4355 | prefs::kDevToolsBackgroundServicesExpirationDict); |
| 4356 | DCHECK(expiration_dict); |
| 4357 | |
| 4358 | base::flat_map<int, base::Time> expiration_times; |
| 4359 | for (const auto& it : *expiration_dict) { |
| 4360 | // key. |
| 4361 | int service = 0; |
| 4362 | bool did_convert = base::StringToInt(it.first, &service); |
| 4363 | DCHECK(did_convert); |
| 4364 | |
| 4365 | // value. |
| 4366 | DCHECK(it.second->is_int()); |
| 4367 | base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt()); |
| 4368 | base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta); |
| 4369 | |
| 4370 | expiration_times[service] = expiration_time; |
| 4371 | } |
| 4372 | |
| 4373 | return expiration_times; |
| 4374 | } |
| 4375 | |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4376 | content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() { |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4377 | return new ChromeTracingDelegate(); |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4378 | } |
| 4379 | |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 4380 | bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle( |
| 4381 | content::BrowserContext* browser_context, |
| 4382 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4383 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 4384 | return ChromeContentBrowserClientPluginsPart:: |
| 4385 | IsPluginAllowedToCallRequestOSFileHandle(browser_context, url, |
| 4386 | allowed_file_handle_origins_); |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 4387 | #else |
| 4388 | return false; |
| 4389 | #endif |
| 4390 | } |
| 4391 | |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 4392 | bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs( |
| 4393 | content::BrowserContext* browser_context, |
| 4394 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4395 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 4396 | return ChromeContentBrowserClientPluginsPart:: |
| 4397 | IsPluginAllowedToUseDevChannelAPIs(browser_context, url, |
| 4398 | allowed_dev_channel_origins_); |
[email protected] | 8ddc6b7c | 2013-12-12 20:42:06 | [diff] [blame] | 4399 | #else |
| 4400 | return false; |
| 4401 | #endif |
| 4402 | } |
| 4403 | |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4404 | void ChromeContentBrowserClient::OverridePageVisibilityState( |
xzhan96 | cf0a3c54 | 2017-11-17 04:33:01 | [diff] [blame] | 4405 | RenderFrameHost* render_frame_host, |
danakj | 0018a29a | 2018-12-01 01:03:43 | [diff] [blame] | 4406 | content::PageVisibilityState* visibility_state) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 4407 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4408 | |
| 4409 | WebContents* web_contents = |
| 4410 | WebContents::FromRenderFrameHost(render_frame_host); |
| 4411 | DCHECK(web_contents); |
| 4412 | |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4413 | prerender::PrerenderManager* prerender_manager = |
droger | c154315 | 2016-09-20 13:03:37 | [diff] [blame] | 4414 | prerender::PrerenderManagerFactory::GetForBrowserContext( |
| 4415 | web_contents->GetBrowserContext()); |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4416 | if (prerender_manager && |
| 4417 | prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) { |
danakj | 0018a29a | 2018-12-01 01:03:43 | [diff] [blame] | 4418 | *visibility_state = content::PageVisibilityState::kPrerender; |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4419 | } |
| 4420 | } |
| 4421 | |
Andrew Moylan | 8ed9d83c8 | 2019-01-29 20:23:52 | [diff] [blame] | 4422 | // Forward image Annotator requests to the image_annotation service. |
| 4423 | void BindImageAnnotator(image_annotation::mojom::AnnotatorRequest request, |
| 4424 | RenderFrameHost* const frame_host) { |
| 4425 | content::BrowserContext::GetConnectorFor( |
| 4426 | frame_host->GetProcess()->GetBrowserContext()) |
| 4427 | ->BindInterface(image_annotation::mojom::kServiceName, |
| 4428 | std::move(request)); |
| 4429 | } |
| 4430 | |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 4431 | void ChromeContentBrowserClient::InitWebContextInterfaces() { |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4432 | frame_interfaces_ = std::make_unique<service_manager::BinderRegistry>(); |
| 4433 | frame_interfaces_parameterized_ = std::make_unique< |
Ben Goodger | 21ada1e | 2017-07-19 14:53:01 | [diff] [blame] | 4434 | service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>(); |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 4435 | worker_interfaces_parameterized_ = |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4436 | std::make_unique<service_manager::BinderRegistryWithArgs< |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 4437 | content::RenderProcessHost*, const url::Origin&>>(); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4438 | |
Michael Martis | 4a542f5 | 2017-07-28 01:51:44 | [diff] [blame] | 4439 | // Register mojo ContentTranslateDriver interface only for main frame. |
Anthony Vallee-Dubois | e2432137a | 2019-01-17 20:06:01 | [diff] [blame] | 4440 | frame_interfaces_parameterized_->AddInterface( |
| 4441 | base::BindRepeating(&language::BindContentTranslateDriver)); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4442 | |
| 4443 | frame_interfaces_parameterized_->AddInterface( |
Eric Lawrence | d0acf2a7c | 2017-07-20 18:02:48 | [diff] [blame] | 4444 | base::Bind(&InsecureSensitiveInputDriverFactory::BindDriver)); |
Andrew Moylan | 8ed9d83c8 | 2019-01-29 20:23:52 | [diff] [blame] | 4445 | frame_interfaces_parameterized_->AddInterface( |
| 4446 | base::BindRepeating(&BindImageAnnotator)); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4447 | |
| 4448 | #if defined(OS_ANDROID) |
| 4449 | frame_interfaces_parameterized_->AddInterface(base::Bind( |
Matt Giuca | ee4aefb | 2017-08-04 03:11:55 | [diff] [blame] | 4450 | &ForwardToJavaFrameRegistry<blink::mojom::InstalledAppProvider>)); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4451 | frame_interfaces_parameterized_->AddInterface( |
| 4452 | base::Bind(&ForwardToJavaFrameRegistry<payments::mojom::PaymentRequest>)); |
Kim Paulhamus | 3d33e44 | 2018-03-29 23:04:14 | [diff] [blame] | 4453 | frame_interfaces_parameterized_->AddInterface( |
Amos Lim | dddb699 | 2018-07-19 22:14:32 | [diff] [blame] | 4454 | base::Bind(&ForwardToJavaFrameRegistry<blink::mojom::Authenticator>)); |
Michael Thiessen | 909ba03 | 2019-03-26 23:47:43 | [diff] [blame] | 4455 | #if defined(BROWSER_MEDIA_CONTROLS_MENU) |
| 4456 | frame_interfaces_parameterized_->AddInterface(base::Bind( |
| 4457 | &ForwardToJavaFrameRegistry<blink::mojom::MediaControlsMenuHost>)); |
| 4458 | #endif |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4459 | #else |
| 4460 | if (base::FeatureList::IsEnabled(features::kWebPayments)) { |
| 4461 | frame_interfaces_parameterized_->AddInterface( |
| 4462 | base::Bind(&payments::CreatePaymentRequest)); |
| 4463 | } |
| 4464 | #endif |
| 4465 | |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4466 | #if defined(OS_ANDROID) |
Matt Giuca | 00e99360 | 2017-06-23 05:17:54 | [diff] [blame] | 4467 | frame_interfaces_parameterized_->AddInterface(base::Bind( |
| 4468 | &ForwardToJavaWebContentsRegistry<blink::mojom::ShareService>)); |
Michael Thiessen | 07c444c | 2019-04-26 03:53:11 | [diff] [blame] | 4469 | #if defined(ENABLE_SPATIAL_NAVIGATION_HOST) |
| 4470 | frame_interfaces_parameterized_->AddInterface(base::Bind( |
| 4471 | &ForwardToJavaWebContentsRegistry<blink::mojom::SpatialNavigationHost>)); |
| 4472 | #endif |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4473 | #endif |
Reilly Grant | 8e5c85c | 2017-07-07 16:35:06 | [diff] [blame] | 4474 | |
Jay Harris | 5a42aa21b | 2018-11-28 01:23:55 | [diff] [blame] | 4475 | #if !defined(OS_ANDROID) |
Eric Stevenson | 1d074a97 | 2018-12-07 14:16:45 | [diff] [blame] | 4476 | frame_interfaces_parameterized_->AddInterface( |
Jay Harris | 1ddcffa | 2019-07-09 03:07:40 | [diff] [blame] | 4477 | base::BindRepeating(&badging::BadgeManager::BindRequest)); |
Eric Stevenson | c3b1805 | 2018-10-01 22:22:00 | [diff] [blame] | 4478 | #endif |
| 4479 | |
Reilly Grant | 8e5c85c | 2017-07-07 16:35:06 | [diff] [blame] | 4480 | frame_interfaces_parameterized_->AddInterface( |
Lu Chen | 5bec7a30 | 2018-06-26 18:52:32 | [diff] [blame] | 4481 | base::BindRepeating(&NavigationPredictor::Create)); |
Dan Harrington | bc87c06 | 2018-10-31 15:21:24 | [diff] [blame] | 4482 | |
| 4483 | #if defined(OS_ANDROID) |
| 4484 | frame_interfaces_parameterized_->AddInterface( |
| 4485 | base::BindRepeating(&offline_pages::OfflinePageAutoFetcher::Create), |
| 4486 | base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI})); |
| 4487 | #endif |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4488 | } |
| 4489 | |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4490 | void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 4491 | base::CommandLine* to_command_line, |
| 4492 | const base::CommandLine& from_command_line, |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4493 | version_info::Channel channel) { |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4494 | #if defined(OS_ANDROID) |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4495 | const version_info::Channel kMaxDisableEncryptionChannel = |
| 4496 | version_info::Channel::BETA; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4497 | #else |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4498 | const version_info::Channel kMaxDisableEncryptionChannel = |
| 4499 | version_info::Channel::DEV; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4500 | #endif |
| 4501 | if (channel <= kMaxDisableEncryptionChannel) { |
| 4502 | static const char* const kWebRtcDevSwitchNames[] = { |
| 4503 | switches::kDisableWebRtcEncryption, |
| 4504 | }; |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 4505 | to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames, |
| 4506 | base::size(kWebRtcDevSwitchNames)); |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4507 | } |
| 4508 | } |
bashi | 93362955 | 2016-10-13 23:32:40 | [diff] [blame] | 4509 | |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4510 | #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 4511 | void ChromeContentBrowserClient::CreateMediaRemoter( |
| 4512 | content::RenderFrameHost* render_frame_host, |
| 4513 | media::mojom::RemotingSourcePtr source, |
| 4514 | media::mojom::RemoterRequest request) { |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4515 | CastRemotingConnector::CreateMediaRemoter( |
| 4516 | render_frame_host, std::move(source), std::move(request)); |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4517 | } |
| 4518 | #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING) |
robliao | bf5a32e | 2016-12-09 03:35:46 | [diff] [blame] | 4519 | |
Michael Giuffrida | 6802ffe | 2017-09-29 03:40:25 | [diff] [blame] | 4520 | base::FilePath ChromeContentBrowserClient::GetLoggingFileName( |
| 4521 | const base::CommandLine& command_line) { |
| 4522 | return logging::GetLogFileName(command_line); |
kerrnel | a67fad5 | 2017-06-14 20:18:16 | [diff] [blame] | 4523 | } |
| 4524 | |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4525 | namespace { |
| 4526 | // TODO(jam): move this to a separate file. |
Clark DuVall | 8512cee6 | 2019-06-26 01:14:21 | [diff] [blame] | 4527 | template <class HandlerRegistry> |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4528 | class ProtocolHandlerThrottle : public blink::URLLoaderThrottle { |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4529 | public: |
| 4530 | explicit ProtocolHandlerThrottle( |
Clark DuVall | 8512cee6 | 2019-06-26 01:14:21 | [diff] [blame] | 4531 | const HandlerRegistry& protocol_handler_registry) |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4532 | : protocol_handler_registry_(protocol_handler_registry) {} |
| 4533 | ~ProtocolHandlerThrottle() override = default; |
| 4534 | |
| 4535 | void WillStartRequest(network::ResourceRequest* request, |
| 4536 | bool* defer) override { |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4537 | TranslateUrl(&request->url); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | void WillRedirectRequest(net::RedirectInfo* redirect_info, |
| 4541 | const network::ResourceResponseHead& response_head, |
| 4542 | bool* defer, |
| 4543 | std::vector<std::string>* to_be_removed_headers, |
| 4544 | net::HttpRequestHeaders* modified_headers) override { |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4545 | TranslateUrl(&redirect_info->new_url); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4546 | } |
| 4547 | |
| 4548 | private: |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4549 | void TranslateUrl(GURL* url) { |
| 4550 | if (!protocol_handler_registry_->IsHandledProtocol(url->scheme())) |
| 4551 | return; |
| 4552 | GURL translated_url = protocol_handler_registry_->Translate(*url); |
| 4553 | if (!translated_url.is_empty()) |
| 4554 | *url = translated_url; |
| 4555 | } |
| 4556 | |
Clark DuVall | 8512cee6 | 2019-06-26 01:14:21 | [diff] [blame] | 4557 | HandlerRegistry protocol_handler_registry_; |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4558 | }; |
| 4559 | } // namespace |
| 4560 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4561 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4562 | ChromeContentBrowserClient::CreateURLLoaderThrottlesOnIO( |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 4563 | const network::ResourceRequest& request, |
| 4564 | content::ResourceContext* resource_context, |
| 4565 | const base::RepeatingCallback<content::WebContents*()>& wc_getter, |
Yuzhu Shen | 9508fc7 | 2018-02-08 23:18:59 | [diff] [blame] | 4566 | content::NavigationUIData* navigation_ui_data, |
| 4567 | int frame_tree_node_id) { |
yzshen | efcb7c7 | 2017-06-16 23:12:30 | [diff] [blame] | 4568 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
Matt Falkenhagen | 7c94374 | 2019-07-18 08:03:08 | [diff] [blame] | 4569 | // TODO(falken): Uncomment out the DCHECK when PlzWorker is moved to the UI |
| 4570 | // thread. |
| 4571 | // DCHECK(!base::FeatureList::IsEnabled(features::kNavigationLoaderOnUI)); |
yzshen | efcb7c7 | 2017-06-16 23:12:30 | [diff] [blame] | 4572 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4573 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result; |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 4574 | |
Vasilii Sukhanov | 0163c514 | 2018-10-10 08:30:03 | [diff] [blame] | 4575 | ProfileIOData* io_data = nullptr; |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 4576 | // Only set |io_data| if needed, as in unit tests |resource_context| is a |
Clark DuVall | 6eee9cb | 2018-10-09 22:08:12 | [diff] [blame] | 4577 | // MockResourceContext and the cast doesn't work. |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 4578 | if (safe_browsing_service_ || |
| 4579 | data_reduction_proxy::params::IsEnabledWithNetworkService()) { |
Vasilii Sukhanov | 0163c514 | 2018-10-10 08:30:03 | [diff] [blame] | 4580 | io_data = ProfileIOData::FromResourceContext(resource_context); |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 4581 | } |
| 4582 | |
rajendrant | 4319407 | 2019-04-15 22:13:43 | [diff] [blame] | 4583 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4584 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4585 | if (chrome_navigation_ui_data && io_data && |
| 4586 | io_data->data_reduction_proxy_io_data() && |
Clark DuVall | 05faba1 | 2018-10-29 19:34:48 | [diff] [blame] | 4587 | data_reduction_proxy::params::IsEnabledWithNetworkService()) { |
Wojciech Dzierżanowski | 4538080 | 2019-04-29 14:50:32 | [diff] [blame] | 4588 | if (!data_reduction_proxy_throttle_manager_) { |
| 4589 | data_reduction_proxy_throttle_manager_ = std::unique_ptr< |
| 4590 | data_reduction_proxy::DataReductionProxyThrottleManager, |
| 4591 | base::OnTaskRunnerDeleter>( |
| 4592 | new data_reduction_proxy::DataReductionProxyThrottleManager( |
| 4593 | io_data->data_reduction_proxy_io_data(), |
| 4594 | io_data->data_reduction_proxy_io_data()->CreateThrottleConfig()), |
| 4595 | base::OnTaskRunnerDeleter(base::SequencedTaskRunnerHandle::Get())); |
| 4596 | } |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 4597 | net::HttpRequestHeaders headers; |
| 4598 | data_reduction_proxy::DataReductionProxyRequestOptions* request_options = |
| 4599 | io_data->data_reduction_proxy_io_data()->request_options(); |
rajendrant | 4319407 | 2019-04-15 22:13:43 | [diff] [blame] | 4600 | uint64_t page_id = |
| 4601 | base::FeatureList::IsEnabled( |
| 4602 | data_reduction_proxy::features:: |
| 4603 | kDataReductionProxyPopulatePreviewsPageIDToPingback) |
| 4604 | ? chrome_navigation_ui_data->data_reduction_proxy_page_id() |
| 4605 | : request_options->GeneratePageId(); |
| 4606 | request_options->AddPageIDRequestHeader(&headers, page_id); |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 4607 | result.push_back(std::make_unique< |
| 4608 | data_reduction_proxy::DataReductionProxyURLLoaderThrottle>( |
Wojciech Dzierżanowski | 4538080 | 2019-04-29 14:50:32 | [diff] [blame] | 4609 | headers, data_reduction_proxy_throttle_manager_.get())); |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 4610 | } |
Vasilii Sukhanov | 0163c514 | 2018-10-10 08:30:03 | [diff] [blame] | 4611 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4612 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 4613 | if (io_data && safe_browsing_service_) { |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 4614 | bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy( |
| 4615 | request.url, io_data->safe_browsing_whitelist_domains()); |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 4616 | if (!matches_enterprise_whitelist) { |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4617 | result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create( |
| 4618 | base::BindOnce( |
| 4619 | &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate, |
| 4620 | base::Unretained(this)), |
| 4621 | wc_getter, frame_tree_node_id, resource_context)); |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 4622 | } |
| 4623 | } |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4624 | #endif |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 4625 | |
Egor Pasko | 0f4403e | 2019-01-24 17:42:20 | [diff] [blame] | 4626 | if (chrome_navigation_ui_data && |
| 4627 | chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) { |
| 4628 | result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>( |
| 4629 | chrome_navigation_ui_data->prerender_mode(), |
| 4630 | chrome_navigation_ui_data->prerender_histogram_prefix(), |
| 4631 | base::BindOnce(GetPrerenderCanceller, wc_getter), |
| 4632 | base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}))); |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 4633 | } |
Jun Cai | 605ff0e7 | 2018-06-12 22:29:20 | [diff] [blame] | 4634 | |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 4635 | if (io_data) { |
Jun Cai | 605ff0e7 | 2018-06-12 22:29:20 | [diff] [blame] | 4636 | bool is_off_the_record = io_data->IsOffTheRecord(); |
| 4637 | bool is_signed_in = |
| 4638 | !is_off_the_record && |
| 4639 | !io_data->google_services_account_id()->GetValue().empty(); |
| 4640 | |
Chris Mumford | 809d8fb | 2018-11-10 12:26:11 | [diff] [blame] | 4641 | chrome::mojom::DynamicParams dynamic_params = { |
| 4642 | io_data->force_google_safesearch()->GetValue(), |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 4643 | io_data->force_youtube_restrict()->GetValue(), |
Chris Mumford | 809d8fb | 2018-11-10 12:26:11 | [diff] [blame] | 4644 | io_data->allowed_domains_for_apps()->GetValue(), |
| 4645 | variations::VariationsHttpHeaderProvider::GetInstance() |
| 4646 | ->GetClientDataHeader(is_signed_in)}; |
| 4647 | result.push_back(std::make_unique<GoogleURLLoaderThrottle>( |
| 4648 | is_off_the_record, std::move(dynamic_params))); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4649 | |
Clark DuVall | 8512cee6 | 2019-06-26 01:14:21 | [diff] [blame] | 4650 | result.push_back( |
| 4651 | std::make_unique<ProtocolHandlerThrottle< |
| 4652 | scoped_refptr<ProtocolHandlerRegistry::IOThreadDelegate>>>( |
| 4653 | io_data->protocol_handler_registry_io_thread_delegate())); |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 4654 | } |
| 4655 | |
John Abd-El-Malek | ecc6f5f | 2018-03-02 18:47:39 | [diff] [blame] | 4656 | #if BUILDFLAG(ENABLE_PLUGINS) |
Matt Falkenhagen | e75bdd45 | 2019-04-03 07:41:52 | [diff] [blame] | 4657 | result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>( |
| 4658 | resource_context, request.resource_type, frame_tree_node_id)); |
John Abd-El-Malek | ecc6f5f | 2018-03-02 18:47:39 | [diff] [blame] | 4659 | #endif |
Reilly Grant | 3787780 | 2018-08-18 00:58:35 | [diff] [blame] | 4660 | |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 4661 | auto delegate = |
| 4662 | std::make_unique<signin::HeaderModificationDelegateOnIOThreadImpl>( |
| 4663 | resource_context); |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 4664 | auto signin_throttle = signin::URLLoaderThrottle::MaybeCreate( |
| 4665 | std::move(delegate), navigation_ui_data, wc_getter); |
| 4666 | if (signin_throttle) |
| 4667 | result.push_back(std::move(signin_throttle)); |
| 4668 | |
yzshen | efcb7c7 | 2017-06-16 23:12:30 | [diff] [blame] | 4669 | return result; |
| 4670 | } |
| 4671 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4672 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4673 | ChromeContentBrowserClient::CreateURLLoaderThrottles( |
| 4674 | const network::ResourceRequest& request, |
| 4675 | content::BrowserContext* browser_context, |
| 4676 | const base::RepeatingCallback<content::WebContents*()>& wc_getter, |
| 4677 | content::NavigationUIData* navigation_ui_data, |
| 4678 | int frame_tree_node_id) { |
| 4679 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 4680 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4681 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result; |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4682 | |
| 4683 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4684 | |
| 4685 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4686 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4687 | |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 4688 | auto* drp_settings = |
| 4689 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 4690 | browser_context); |
| 4691 | if (chrome_navigation_ui_data && !profile->IsIncognitoProfile() && |
| 4692 | data_reduction_proxy::params::IsEnabledWithNetworkService() && |
| 4693 | drp_settings) { |
| 4694 | if (!data_reduction_proxy_throttle_manager_) { |
| 4695 | data_reduction_proxy_throttle_manager_ = std::unique_ptr< |
| 4696 | data_reduction_proxy::DataReductionProxyThrottleManager, |
| 4697 | base::OnTaskRunnerDeleter>( |
| 4698 | new data_reduction_proxy::DataReductionProxyThrottleManager( |
| 4699 | drp_settings->data_reduction_proxy_service(), |
| 4700 | data_reduction_proxy::DataReductionProxyThrottleManager:: |
| 4701 | CreateConfig(drp_settings->proxies_for_http())), |
| 4702 | base::OnTaskRunnerDeleter(base::SequencedTaskRunnerHandle::Get())); |
| 4703 | } |
| 4704 | net::HttpRequestHeaders headers; |
| 4705 | data_reduction_proxy::DataReductionProxyRequestOptions:: |
| 4706 | AddPageIDRequestHeader( |
| 4707 | &headers, |
| 4708 | chrome_navigation_ui_data->data_reduction_proxy_page_id()); |
| 4709 | result.push_back(std::make_unique< |
| 4710 | data_reduction_proxy::DataReductionProxyURLLoaderThrottle>( |
| 4711 | headers, data_reduction_proxy_throttle_manager_.get())); |
| 4712 | } |
| 4713 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4714 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4715 | bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy( |
| 4716 | request.url, *profile->GetPrefs()); |
| 4717 | if (!matches_enterprise_whitelist) { |
| 4718 | result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create( |
| 4719 | base::BindOnce( |
| 4720 | &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate, |
| 4721 | base::Unretained(this)), |
| 4722 | wc_getter, frame_tree_node_id, profile->GetResourceContext())); |
| 4723 | } |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4724 | #endif |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4725 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4726 | if (chrome_navigation_ui_data && |
| 4727 | chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) { |
| 4728 | result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>( |
| 4729 | chrome_navigation_ui_data->prerender_mode(), |
| 4730 | chrome_navigation_ui_data->prerender_histogram_prefix(), |
| 4731 | base::BindOnce(GetPrerenderCanceller, wc_getter), |
| 4732 | base::CreateSingleThreadTaskRunnerWithTraits({BrowserThread::UI}))); |
| 4733 | } |
| 4734 | |
| 4735 | bool is_off_the_record = profile->IsOffTheRecord(); |
| 4736 | bool is_signed_in = !is_off_the_record && |
| 4737 | !profile->GetPrefs() |
| 4738 | ->GetString(prefs::kGoogleServicesUserAccountId) |
| 4739 | .empty(); |
| 4740 | |
| 4741 | chrome::mojom::DynamicParams dynamic_params = { |
| 4742 | profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch), |
| 4743 | profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict), |
| 4744 | profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps), |
| 4745 | variations::VariationsHttpHeaderProvider::GetInstance() |
| 4746 | ->GetClientDataHeader(is_signed_in)}; |
| 4747 | result.push_back(std::make_unique<GoogleURLLoaderThrottle>( |
| 4748 | is_off_the_record, std::move(dynamic_params))); |
| 4749 | |
Clark DuVall | 8512cee6 | 2019-06-26 01:14:21 | [diff] [blame] | 4750 | result.push_back( |
| 4751 | std::make_unique<ProtocolHandlerThrottle<ProtocolHandlerRegistry*>>( |
| 4752 | ProtocolHandlerRegistryFactory::GetForBrowserContext( |
| 4753 | browser_context))); |
| 4754 | |
Clark DuVall | 39c2cfc | 2019-06-25 21:49:28 | [diff] [blame] | 4755 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 4756 | result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>( |
| 4757 | browser_context, request.resource_type, frame_tree_node_id)); |
| 4758 | #endif |
| 4759 | |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 4760 | auto delegate = |
| 4761 | std::make_unique<signin::HeaderModificationDelegateOnUIThreadImpl>( |
| 4762 | profile); |
| 4763 | auto signin_throttle = signin::URLLoaderThrottle::MaybeCreate( |
| 4764 | std::move(delegate), navigation_ui_data, wc_getter); |
| 4765 | if (signin_throttle) |
| 4766 | result.push_back(std::move(signin_throttle)); |
| 4767 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4768 | return result; |
| 4769 | } |
| 4770 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4771 | void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4772 | int frame_tree_node_id, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4773 | NonNetworkURLLoaderFactoryMap* factories) { |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4774 | #if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4775 | content::WebContents* web_contents = |
| 4776 | content::WebContents::FromFrameTreeNodeId(frame_tree_node_id); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4777 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4778 | factories->emplace( |
| 4779 | extensions::kExtensionScheme, |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 4780 | extensions::CreateExtensionNavigationURLLoaderFactory( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4781 | web_contents->GetBrowserContext(), |
| 4782 | !!extensions::WebViewGuest::FromWebContents(web_contents))); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4783 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 4784 | #if defined(OS_CHROMEOS) |
| 4785 | Profile* profile = |
| 4786 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Robbie McElrath | 89cc933 | 2019-03-05 02:12:30 | [diff] [blame] | 4787 | factories->emplace(content::kExternalFileScheme, |
| 4788 | std::make_unique<chromeos::ExternalFileURLLoaderFactory>( |
| 4789 | profile, content::ChildProcessHost::kInvalidUniqueID)); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4790 | #endif // defined(OS_CHROMEOS) |
| 4791 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4792 | } |
| 4793 | |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4794 | void ChromeContentBrowserClient:: |
| 4795 | RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories( |
| 4796 | content::BrowserContext* browser_context, |
| 4797 | NonNetworkURLLoaderFactoryMap* factories) { |
| 4798 | #if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
| 4799 | DCHECK(browser_context); |
| 4800 | DCHECK(factories); |
| 4801 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4802 | factories->emplace( |
| 4803 | extensions::kExtensionScheme, |
| 4804 | extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory( |
| 4805 | browser_context)); |
| 4806 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 4807 | #if defined(OS_CHROMEOS) |
| 4808 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4809 | factories->emplace(content::kExternalFileScheme, |
| 4810 | std::make_unique<chromeos::ExternalFileURLLoaderFactory>( |
| 4811 | profile, content::ChildProcessHost::kInvalidUniqueID)); |
| 4812 | #endif // defined(OS_CHROMEOS) |
| 4813 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
| 4814 | } |
| 4815 | |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4816 | namespace { |
| 4817 | |
| 4818 | // The FileURLLoaderFactory provided to the extension background pages. |
| 4819 | // Checks with the ChildProcessSecurityPolicy to validate the file access. |
| 4820 | class FileURLLoaderFactory : public network::mojom::URLLoaderFactory { |
| 4821 | public: |
| 4822 | explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {} |
| 4823 | |
| 4824 | private: |
| 4825 | // network::mojom::URLLoaderFactory: |
| 4826 | void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader, |
| 4827 | int32_t routing_id, |
| 4828 | int32_t request_id, |
| 4829 | uint32_t options, |
| 4830 | const network::ResourceRequest& request, |
| 4831 | network::mojom::URLLoaderClientPtr client, |
| 4832 | const net::MutableNetworkTrafficAnnotationTag& |
| 4833 | traffic_annotation) override { |
| 4834 | if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL( |
| 4835 | child_id_, request.url)) { |
| 4836 | client->OnComplete( |
| 4837 | network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED)); |
| 4838 | return; |
| 4839 | } |
| 4840 | content::CreateFileURLLoader(request, std::move(loader), std::move(client), |
John Abd-El-Malek | 916f2b8 | 2019-02-19 23:49:45 | [diff] [blame] | 4841 | /*observer=*/nullptr, |
| 4842 | /* allow_directory_listing */ true); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4843 | } |
| 4844 | |
| 4845 | void Clone(network::mojom::URLLoaderFactoryRequest loader) override { |
| 4846 | bindings_.AddBinding(this, std::move(loader)); |
| 4847 | } |
| 4848 | |
| 4849 | int child_id_; |
| 4850 | mojo::BindingSet<network::mojom::URLLoaderFactory> bindings_; |
| 4851 | DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory); |
| 4852 | }; |
| 4853 | |
| 4854 | } // namespace |
| 4855 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4856 | void ChromeContentBrowserClient:: |
| 4857 | RegisterNonNetworkSubresourceURLLoaderFactories( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4858 | int render_process_id, |
| 4859 | int render_frame_id, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4860 | NonNetworkURLLoaderFactoryMap* factories) { |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4861 | #if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS) |
| 4862 | content::RenderFrameHost* frame_host = |
| 4863 | RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 4864 | WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host); |
| 4865 | #endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS) |
| 4866 | |
| 4867 | #if defined(OS_CHROMEOS) |
| 4868 | if (web_contents) { |
| 4869 | Profile* profile = |
| 4870 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Robbie McElrath | 89cc933 | 2019-03-05 02:12:30 | [diff] [blame] | 4871 | factories->emplace(content::kExternalFileScheme, |
| 4872 | std::make_unique<chromeos::ExternalFileURLLoaderFactory>( |
| 4873 | profile, render_process_id)); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4874 | } |
| 4875 | #endif // defined(OS_CHROMEOS) |
| 4876 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4877 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4878 | auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id, |
| 4879 | render_frame_id); |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4880 | if (factory) |
| 4881 | factories->emplace(extensions::kExtensionScheme, std::move(factory)); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4882 | |
| 4883 | // This logic should match |
| 4884 | // ChromeExtensionWebContentsObserver::RenderFrameCreated. |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4885 | if (!web_contents) |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4886 | return; |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4887 | |
| 4888 | Profile* profile = |
| 4889 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 4890 | InstantService* instant_service = |
| 4891 | InstantServiceFactory::GetForProfile(profile); |
| 4892 | // The test below matches what's done by ShouldServiceRequestIOThread in |
| 4893 | // local_ntp_source.cc. |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4894 | if (instant_service->IsInstantProcess(render_process_id)) { |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4895 | factories->emplace( |
| 4896 | chrome::kChromeSearchScheme, |
| 4897 | content::CreateWebUIURLLoader( |
| 4898 | frame_host, chrome::kChromeSearchScheme, |
| 4899 | /*allowed_webui_hosts=*/base::flat_set<std::string>())); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4900 | } |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4901 | |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4902 | extensions::ChromeExtensionWebContentsObserver* web_observer = |
| 4903 | extensions::ChromeExtensionWebContentsObserver::FromWebContents( |
| 4904 | web_contents); |
| 4905 | |
Karan Bhatia | 9192857 | 2018-03-06 01:18:07 | [diff] [blame] | 4906 | // There is nothing to do if no ChromeExtensionWebContentsObserver is attached |
| 4907 | // to the |web_contents|. |
| 4908 | if (!web_observer) |
| 4909 | return; |
| 4910 | |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4911 | const Extension* extension = |
| 4912 | web_observer->GetExtensionFromFrame(frame_host, false); |
| 4913 | if (!extension) |
| 4914 | return; |
| 4915 | |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4916 | std::vector<std::string> allowed_webui_hosts; |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4917 | // Support for chrome:// scheme if appropriate. |
| 4918 | if ((extension->is_extension() || extension->is_platform_app()) && |
| 4919 | Manifest::IsComponentLocation(extension->location())) { |
| 4920 | // Components of chrome that are implemented as extensions or platform apps |
| 4921 | // are allowed to use chrome://resources/ and chrome://theme/ URLs. |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4922 | allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost); |
| 4923 | allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost); |
| 4924 | } |
| 4925 | if (extension->is_extension() || extension->is_legacy_packaged_app() || |
| 4926 | (extension->is_platform_app() && |
| 4927 | Manifest::IsComponentLocation(extension->location()))) { |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4928 | // Extensions, legacy packaged apps, and component platform apps are allowed |
Lucas Tenório | 3dd8092 | 2019-03-27 03:51:02 | [diff] [blame] | 4929 | // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon |
| 4930 | // URLs. Hosted apps are not allowed because they are served via web servers |
| 4931 | // (and are generally never given access to Chrome APIs). |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4932 | allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost); |
| 4933 | allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost); |
Lucas Tenório | 3dd8092 | 2019-03-27 03:51:02 | [diff] [blame] | 4934 | allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost); |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4935 | } |
| 4936 | if (!allowed_webui_hosts.empty()) { |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4937 | factories->emplace( |
| 4938 | content::kChromeUIScheme, |
| 4939 | content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme, |
| 4940 | std::move(allowed_webui_hosts))); |
| 4941 | } |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4942 | |
| 4943 | // Extension with a background page get file access that gets approval from |
| 4944 | // ChildProcessSecurityPolicy. |
| 4945 | extensions::ExtensionHost* host = |
| 4946 | extensions::ProcessManager::Get(web_contents->GetBrowserContext()) |
| 4947 | ->GetBackgroundHostForExtension(extension->id()); |
| 4948 | if (host) { |
| 4949 | factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>( |
| 4950 | render_process_id)); |
| 4951 | } |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4952 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4953 | } |
| 4954 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4955 | bool ChromeContentBrowserClient::WillCreateURLLoaderFactory( |
Ken Rockot | 428b1d6 | 2018-06-06 17:12:21 | [diff] [blame] | 4956 | content::BrowserContext* browser_context, |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4957 | content::RenderFrameHost* frame, |
Kenichi Ishibashi | 09ee5e7 | 2018-11-27 07:12:38 | [diff] [blame] | 4958 | int render_process_id, |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4959 | bool is_navigation, |
Ken Rockot | 1726e18 | 2019-02-28 09:48:56 | [diff] [blame] | 4960 | bool is_download, |
Lukasz Anforowicz | 76273365 | 2018-09-28 14:48:26 | [diff] [blame] | 4961 | const url::Origin& request_initiator, |
Dominic Farolino | 1be897a | 2019-07-20 08:11:42 | [diff] [blame] | 4962 | mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver, |
Clark DuVall | a5e25b75 | 2018-11-27 22:08:16 | [diff] [blame] | 4963 | network::mojom::TrustedURLLoaderHeaderClientPtrInfo* header_client, |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4964 | bool* bypass_redirect_checks) { |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4965 | bool use_proxy = false; |
| 4966 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4967 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4968 | auto* web_request_api = |
| 4969 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
Ken Rockot | 428b1d6 | 2018-06-06 17:12:21 | [diff] [blame] | 4970 | browser_context); |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4971 | |
| 4972 | // NOTE: Some unit test environments do not initialize |
| 4973 | // BrowserContextKeyedAPI factories for e.g. WebRequest. |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4974 | if (web_request_api) { |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4975 | bool use_proxy_for_web_request = |
Kenichi Ishibashi | 09ee5e7 | 2018-11-27 07:12:38 | [diff] [blame] | 4976 | web_request_api->MaybeProxyURLLoaderFactory( |
| 4977 | browser_context, frame, render_process_id, is_navigation, |
Dominic Farolino | 1be897a | 2019-07-20 08:11:42 | [diff] [blame] | 4978 | is_download, factory_receiver, header_client); |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4979 | if (bypass_redirect_checks) |
| 4980 | *bypass_redirect_checks = use_proxy_for_web_request; |
| 4981 | use_proxy |= use_proxy_for_web_request; |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4982 | } |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4983 | #endif |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4984 | |
Reilly Grant | cc22e60 | 2018-09-07 15:25:20 | [diff] [blame] | 4985 | use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest( |
Dominic Farolino | 1be897a | 2019-07-20 08:11:42 | [diff] [blame] | 4986 | frame, is_navigation, request_initiator, factory_receiver); |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4987 | |
| 4988 | return use_proxy; |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4989 | } |
| 4990 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4991 | std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> |
| 4992 | ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors( |
| 4993 | content::NavigationUIData* navigation_ui_data, |
Ryan Sturm | 27d93f41 | 2019-02-15 21:30:14 | [diff] [blame] | 4994 | int frame_tree_node_id, |
| 4995 | const scoped_refptr<network::SharedURLLoaderFactory>& |
| 4996 | network_loader_factory) { |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4997 | std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> |
| 4998 | interceptors; |
| 4999 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 5000 | interceptors.push_back( |
| 5001 | std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>( |
| 5002 | navigation_ui_data, frame_tree_node_id)); |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 5003 | #endif |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 5004 | |
Robert Ogden | 3d5d5b4 | 2019-04-22 05:13:11 | [diff] [blame] | 5005 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 5006 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 5007 | |
Ryan Sturm | 27d93f41 | 2019-02-15 21:30:14 | [diff] [blame] | 5008 | // TODO(ryansturm): Once this is on the UI thread, stop passing |
| 5009 | // |network_loader_factory| and have interceptors create one themselves. |
| 5010 | // https://crbug.com/931786 |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 5011 | if (base::FeatureList::IsEnabled( |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 5012 | previews::features::kHTTPSServerPreviewsUsingURLLoader)) { |
| 5013 | interceptors.push_back( |
| 5014 | std::make_unique<previews::PreviewsLitePageURLLoaderInterceptor>( |
Robert Ogden | 3d5d5b4 | 2019-04-22 05:13:11 | [diff] [blame] | 5015 | network_loader_factory, |
| 5016 | chrome_navigation_ui_data->data_reduction_proxy_page_id(), |
| 5017 | frame_tree_node_id)); |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 5018 | } |
| 5019 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 5020 | return interceptors; |
| 5021 | } |
| 5022 | |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 5023 | bool ChromeContentBrowserClient::WillInterceptWebSocket( |
| 5024 | content::RenderFrameHost* frame) { |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 5025 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 5026 | if (!frame) { |
| 5027 | return false; |
| 5028 | } |
| 5029 | const auto* web_request_api = |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 5030 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
| 5031 | frame->GetProcess()->GetBrowserContext()); |
| 5032 | |
| 5033 | // NOTE: Some unit test environments do not initialize |
| 5034 | // BrowserContextKeyedAPI factories for e.g. WebRequest. |
| 5035 | if (!web_request_api) |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 5036 | return false; |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 5037 | |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 5038 | return web_request_api->MayHaveProxies(); |
| 5039 | #else |
| 5040 | return false; |
| 5041 | #endif |
| 5042 | } |
| 5043 | |
| 5044 | void ChromeContentBrowserClient::CreateWebSocket( |
| 5045 | content::RenderFrameHost* frame, |
| 5046 | WebSocketFactory factory, |
| 5047 | const GURL& url, |
| 5048 | const GURL& site_for_cookies, |
| 5049 | const base::Optional<std::string>& user_agent, |
| 5050 | network::mojom::WebSocketHandshakeClientPtr handshake_client) { |
| 5051 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5052 | if (!frame) { |
| 5053 | return; |
| 5054 | } |
| 5055 | auto* web_request_api = |
| 5056 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
| 5057 | frame->GetProcess()->GetBrowserContext()); |
| 5058 | |
| 5059 | DCHECK(web_request_api); |
| 5060 | web_request_api->ProxyWebSocket(frame, std::move(factory), url, |
| 5061 | site_for_cookies, user_agent, |
| 5062 | std::move(handshake_client)); |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 5063 | #endif |
| 5064 | } |
| 5065 | |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 5066 | bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager( |
Maks Orlovich | e7db7a2 | 2019-07-25 01:47:46 | [diff] [blame] | 5067 | network::mojom::RestrictedCookieManagerRole role, |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 5068 | content::BrowserContext* browser_context, |
| 5069 | const url::Origin& origin, |
| 5070 | bool is_service_worker, |
| 5071 | int process_id, |
| 5072 | int routing_id, |
| 5073 | network::mojom::RestrictedCookieManagerRequest* request) { |
| 5074 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 5075 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5076 | if (origin.scheme() == extensions::kExtensionScheme) { |
Maks Orlovich | e7db7a2 | 2019-07-25 01:47:46 | [diff] [blame] | 5077 | DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role); |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 5078 | extensions::ChromeExtensionCookies::Get(browser_context) |
| 5079 | ->CreateRestrictedCookieManager(origin, std::move(*request)); |
| 5080 | return true; |
| 5081 | } |
| 5082 | #endif |
| 5083 | return false; |
| 5084 | } |
| 5085 | |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 5086 | void ChromeContentBrowserClient::OnNetworkServiceCreated( |
| 5087 | network::mojom::NetworkService* network_service) { |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 5088 | PrefService* local_state; |
| 5089 | if (g_browser_process) { |
| 5090 | DCHECK(g_browser_process->local_state()); |
| 5091 | local_state = g_browser_process->local_state(); |
| 5092 | } else { |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 5093 | DCHECK(startup_data_->chrome_feature_list_creator()->local_state()); |
| 5094 | local_state = startup_data_->chrome_feature_list_creator()->local_state(); |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 5095 | } |
| 5096 | |
| 5097 | if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance()) |
| 5098 | data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state); |
| 5099 | |
Henrique Nakashima | a3b1c5d | 2019-07-03 19:25:49 | [diff] [blame] | 5100 | // Create SystemNetworkContextManager if it has not been created yet. We need |
| 5101 | // to set up global NetworkService state before anything else uses it and this |
| 5102 | // is the first opportunity to initialize SystemNetworkContextManager with the |
| 5103 | // NetworkService. |
| 5104 | if (!SystemNetworkContextManager::HasInstance()) |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 5105 | SystemNetworkContextManager::CreateInstance(local_state); |
John Abd-El-Malek | 897374f4 | 2019-05-30 03:58:07 | [diff] [blame] | 5106 | |
Min Qin | 8caab1d | 2018-10-03 17:28:13 | [diff] [blame] | 5107 | SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated( |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 5108 | network_service); |
| 5109 | } |
| 5110 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 5111 | network::mojom::NetworkContextPtr |
| 5112 | ChromeContentBrowserClient::CreateNetworkContext( |
| 5113 | content::BrowserContext* context, |
| 5114 | bool in_memory, |
| 5115 | const base::FilePath& relative_partition_path) { |
John Abd-El-Malek | cc0b2a6 | 2018-03-20 19:32:50 | [diff] [blame] | 5116 | Profile* profile = Profile::FromBrowserContext(context); |
Matt Menke | d38efd9 | 2018-08-14 20:39:45 | [diff] [blame] | 5117 | return profile->CreateNetworkContext(in_memory, relative_partition_path); |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 5118 | } |
| 5119 | |
Robert Sesek | 34f68f31 | 2019-01-14 20:25:11 | [diff] [blame] | 5120 | std::vector<base::FilePath> |
| 5121 | ChromeContentBrowserClient::GetNetworkContextsParentDirectory() { |
| 5122 | base::FilePath user_data_dir; |
| 5123 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 5124 | DCHECK(!user_data_dir.empty()); |
| 5125 | |
| 5126 | base::FilePath cache_dir; |
| 5127 | chrome::GetUserCacheDirectory(user_data_dir, &cache_dir); |
| 5128 | DCHECK(!cache_dir.empty()); |
| 5129 | |
| 5130 | // On some platforms, the cache is a child of the user_data_dir so only |
| 5131 | // return the one path. |
| 5132 | if (user_data_dir.IsParent(cache_dir)) |
| 5133 | return {user_data_dir}; |
| 5134 | |
| 5135 | return {user_data_dir, cache_dir}; |
| 5136 | } |
| 5137 | |
Min Qin | 75ed6df | 2017-12-01 20:39:15 | [diff] [blame] | 5138 | bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp( |
Min Qin | 30a78a1 | 2017-12-06 01:29:13 | [diff] [blame] | 5139 | content::NavigationUIData* navigation_ui_data) { |
Min Qin | 75ed6df | 2017-12-01 20:39:15 | [diff] [blame] | 5140 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 5141 | // It is OK to load the saved offline copy, in MHTML format. |
| 5142 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 5143 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 5144 | if (!chrome_navigation_ui_data) |
| 5145 | return false; |
| 5146 | offline_pages::OfflinePageNavigationUIData* offline_page_data = |
| 5147 | chrome_navigation_ui_data->GetOfflinePageNavigationUIData(); |
| 5148 | return offline_page_data && offline_page_data->is_offline_page(); |
| 5149 | #else |
| 5150 | return false; |
| 5151 | #endif |
| 5152 | } |
| 5153 | |
Min Qin | 30a78a1 | 2017-12-06 01:29:13 | [diff] [blame] | 5154 | bool ChromeContentBrowserClient::ShouldForceDownloadResource( |
| 5155 | const GURL& url, |
| 5156 | const std::string& mime_type) { |
| 5157 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5158 | // Special-case user scripts to get downloaded instead of viewed. |
| 5159 | return extensions::UserScript::IsURLUserScript(url, mime_type); |
| 5160 | #else |
| 5161 | return false; |
| 5162 | #endif |
| 5163 | } |
| 5164 | |
Donna Wu | 838ac36 | 2018-08-10 10:36:33 | [diff] [blame] | 5165 | void ChromeContentBrowserClient::CreateWebUsbService( |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5166 | content::RenderFrameHost* render_frame_host, |
Donna Wu | 838ac36 | 2018-08-10 10:36:33 | [diff] [blame] | 5167 | mojo::InterfaceRequest<blink::mojom::WebUsbService> request) { |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5168 | if (!base::FeatureList::IsEnabled(features::kWebUsb)) |
| 5169 | return; |
| 5170 | |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5171 | WebContents* web_contents = |
| 5172 | WebContents::FromRenderFrameHost(render_frame_host); |
| 5173 | if (!web_contents) { |
| 5174 | NOTREACHED(); |
| 5175 | return; |
| 5176 | } |
| 5177 | |
| 5178 | UsbTabHelper* tab_helper = |
| 5179 | UsbTabHelper::GetOrCreateForWebContents(web_contents); |
Donna Wu | 838ac36 | 2018-08-10 10:36:33 | [diff] [blame] | 5180 | tab_helper->CreateWebUsbService(render_frame_host, std::move(request)); |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5181 | } |
| 5182 | |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 5183 | #if !defined(OS_ANDROID) |
| 5184 | content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() { |
| 5185 | if (!serial_delegate_) |
| 5186 | serial_delegate_ = std::make_unique<ChromeSerialDelegate>(); |
| 5187 | return serial_delegate_.get(); |
| 5188 | } |
Matt Reynolds | 93616f9b | 2019-06-07 01:28:52 | [diff] [blame] | 5189 | |
| 5190 | content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() { |
| 5191 | if (!hid_delegate_) |
| 5192 | hid_delegate_ = std::make_unique<ChromeHidDelegate>(); |
| 5193 | return hid_delegate_.get(); |
| 5194 | } |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 5195 | |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 5196 | std::unique_ptr<content::AuthenticatorRequestClientDelegate> |
| 5197 | ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate( |
Adam Langley | eeac87e | 2019-04-13 22:58:22 | [diff] [blame] | 5198 | content::RenderFrameHost* render_frame_host, |
| 5199 | const std::string& relying_party_id) { |
| 5200 | return AuthenticatorRequestScheduler::CreateRequestDelegate(render_frame_host, |
| 5201 | relying_party_id); |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 5202 | } |
Nina Satragno | 8c832df | 2019-07-29 15:59:39 | [diff] [blame^] | 5203 | #endif |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 5204 | |
Dominic Battré | f6f1ec69 | 2019-07-27 01:59:26 | [diff] [blame] | 5205 | #if defined(OS_MACOSX) |
| 5206 | bool ChromeContentBrowserClient:: |
| 5207 | IsWebAuthenticationTouchIdAuthenticatorSupported() { |
| 5208 | return true; |
| 5209 | } |
| 5210 | #endif |
| 5211 | |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 5212 | std::unique_ptr<net::ClientCertStore> |
| 5213 | ChromeContentBrowserClient::CreateClientCertStore( |
| 5214 | content::ResourceContext* resource_context) { |
| 5215 | if (!resource_context) |
| 5216 | return nullptr; |
| 5217 | return ProfileIOData::FromResourceContext(resource_context) |
| 5218 | ->CreateClientCertStore(); |
| 5219 | } |
| 5220 | |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 5221 | std::unique_ptr<content::LoginDelegate> |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5222 | ChromeContentBrowserClient::CreateLoginDelegate( |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5223 | const net::AuthChallengeInfo& auth_info, |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 5224 | content::WebContents* web_contents, |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5225 | const content::GlobalRequestID& request_id, |
Jun Cai | 8e165d2 | 2018-05-14 19:21:24 | [diff] [blame] | 5226 | bool is_request_for_main_frame, |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5227 | const GURL& url, |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5228 | scoped_refptr<net::HttpResponseHeaders> response_headers, |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5229 | bool first_auth_attempt, |
Mark Pilgrim | 7cfcd11 | 2018-05-08 00:07:56 | [diff] [blame] | 5230 | LoginAuthRequiredCallback auth_required_callback) { |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5231 | return CreateLoginPrompt( |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 5232 | auth_info, web_contents, request_id, is_request_for_main_frame, url, |
Emily Stark | c5f1579 | 2019-05-19 17:24:20 | [diff] [blame] | 5233 | std::move(response_headers), LoginHandler::PRE_COMMIT, |
| 5234 | std::move(auth_required_callback)); |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5235 | } |
| 5236 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5237 | bool ChromeContentBrowserClient::HandleExternalProtocol( |
| 5238 | const GURL& url, |
| 5239 | content::ResourceRequestInfo::WebContentsGetter web_contents_getter, |
| 5240 | int child_id, |
| 5241 | content::NavigationUIData* navigation_data, |
| 5242 | bool is_main_frame, |
| 5243 | ui::PageTransition page_transition, |
Tim Volodine | b24393f3 | 2018-11-16 18:45:45 | [diff] [blame] | 5244 | bool has_user_gesture, |
Clark DuVall | b6042ed3 | 2019-07-15 17:20:45 | [diff] [blame] | 5245 | network::mojom::URLLoaderFactoryPtr* out_factory) { |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5246 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5247 | // External protocols are disabled for guests. An exception is made for the |
| 5248 | // "mailto" protocol, so that pages that utilize it work properly in a |
| 5249 | // WebView. |
| 5250 | ChromeNavigationUIData* chrome_data = |
| 5251 | static_cast<ChromeNavigationUIData*>(navigation_data); |
| 5252 | if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) || |
| 5253 | (chrome_data && |
| 5254 | chrome_data->GetExtensionNavigationUIData()->is_web_view())) && |
| 5255 | !url.SchemeIs(url::kMailToScheme)) { |
| 5256 | return false; |
| 5257 | } |
| 5258 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 5259 | |
| 5260 | #if defined(OS_ANDROID) |
| 5261 | // Main frame external protocols are handled by |
| 5262 | // InterceptNavigationResourceThrottle. |
| 5263 | if (is_main_frame) |
| 5264 | return false; |
| 5265 | #endif // defined(ANDROID) |
| 5266 | |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 5267 | base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI}, |
| 5268 | base::BindOnce(&LaunchURL, url, web_contents_getter, |
| 5269 | page_transition, has_user_gesture)); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5270 | return true; |
| 5271 | } |
| 5272 | |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5273 | std::unique_ptr<content::OverlayWindow> |
Jennifer Apacible | 6010b023 | 2018-04-12 23:35:28 | [diff] [blame] | 5274 | ChromeContentBrowserClient::CreateWindowForPictureInPicture( |
| 5275 | content::PictureInPictureWindowController* controller) { |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5276 | // Note: content::OverlayWindow::Create() is defined by platform-specific |
| 5277 | // implementation in chrome/browser/ui/views. This layering hack, which goes |
| 5278 | // through //content and ContentBrowserClient, allows us to work around the |
| 5279 | // dependency constraints that disallow directly calling |
| 5280 | // chrome/browser/ui/views code either from here or from other code in |
| 5281 | // chrome/browser. |
Jennifer Apacible | 6010b023 | 2018-04-12 23:35:28 | [diff] [blame] | 5282 | return content::OverlayWindow::Create(controller); |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5283 | } |
| 5284 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 5285 | bool ChromeContentBrowserClient::IsSafeRedirectTargetOnIO( |
Clark DuVall | bf7722f | 2018-08-03 18:03:33 | [diff] [blame] | 5286 | const GURL& url, |
| 5287 | content::ResourceContext* context) { |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 5288 | DCHECK(!base::FeatureList::IsEnabled(features::kNavigationLoaderOnUI)); |
Clark DuVall | bf7722f | 2018-08-03 18:03:33 | [diff] [blame] | 5289 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5290 | if (url.SchemeIs(extensions::kExtensionScheme)) { |
| 5291 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
| 5292 | const Extension* extension = |
| 5293 | io_data->GetExtensionInfoMap()->extensions().GetByID(url.host()); |
| 5294 | if (!extension) |
| 5295 | return false; |
| 5296 | return extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible( |
| 5297 | extension, url.path()); |
| 5298 | } |
| 5299 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 5300 | return true; |
| 5301 | } |
| 5302 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 5303 | bool ChromeContentBrowserClient::IsSafeRedirectTarget( |
| 5304 | const GURL& url, |
| 5305 | content::BrowserContext* context) { |
| 5306 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5307 | if (url.SchemeIs(extensions::kExtensionScheme)) { |
| 5308 | const Extension* extension = extensions::ExtensionRegistry::Get(context) |
| 5309 | ->enabled_extensions() |
| 5310 | .GetByID(url.host()); |
| 5311 | if (!extension) |
| 5312 | return false; |
| 5313 | return extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible( |
| 5314 | extension, url.path()); |
| 5315 | } |
| 5316 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 5317 | return true; |
| 5318 | } |
| 5319 | |
Kunihiko Sakamoto | 19aa708 | 2019-02-25 03:14:43 | [diff] [blame] | 5320 | void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher( |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5321 | content::BrowserContext* browser_context, |
Leon Han | f4003a16 | 2019-01-28 05:31:58 | [diff] [blame] | 5322 | blink::mojom::RendererPreferenceWatcherPtr watcher) { |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5323 | Profile* profile = Profile::FromBrowserContext(browser_context); |
Kunihiko Sakamoto | 19aa708 | 2019-02-25 03:14:43 | [diff] [blame] | 5324 | PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher( |
| 5325 | std::move(watcher)); |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5326 | } |
| 5327 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5328 | // Static; handles rewriting Web UI URLs. |
| 5329 | bool ChromeContentBrowserClient::HandleWebUI( |
| 5330 | GURL* url, |
| 5331 | content::BrowserContext* browser_context) { |
| 5332 | // Rewrite chrome://help and chrome://chrome to chrome://settings/help. |
| 5333 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 5334 | (url->host() == chrome::kChromeUIHelpHost || |
| 5335 | (url->host() == chrome::kChromeUIUberHost && |
| 5336 | (url->path().empty() || url->path() == "/")))) { |
| 5337 | *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost, |
| 5338 | chrome::kChromeUIHelpHost); |
| 5339 | return true; // Return true to update the displayed URL. |
| 5340 | } |
| 5341 | |
| 5342 | if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 5343 | browser_context, *url)) { |
| 5344 | return false; |
| 5345 | } |
| 5346 | |
| 5347 | #if defined(OS_CHROMEOS) |
| 5348 | // Special case : in ChromeOS in Guest mode bookmarks and history are |
| 5349 | // disabled for security reasons. New tab page explains the reasons, so |
| 5350 | // we redirect user to new tab page. |
| 5351 | if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { |
| 5352 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 5353 | (url->DomainIs(chrome::kChromeUIBookmarksHost) || |
| 5354 | url->DomainIs(chrome::kChromeUIHistoryHost))) { |
| 5355 | // Rewrite with new tab URL |
| 5356 | *url = GURL(chrome::kChromeUINewTabURL); |
| 5357 | } |
| 5358 | } |
| 5359 | #endif |
| 5360 | |
| 5361 | return true; |
| 5362 | } |
| 5363 | |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 5364 | bool ChromeContentBrowserClient::ShowPaymentHandlerWindow( |
| 5365 | content::BrowserContext* browser_context, |
| 5366 | const GURL& url, |
Anthony Vallee-Dubois | 98befeaa | 2018-01-18 16:31:32 | [diff] [blame] | 5367 | base::OnceCallback<void(bool, int, int)> callback) { |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 5368 | #if defined(OS_ANDROID) |
| 5369 | return false; |
| 5370 | #else |
| 5371 | payments::PaymentRequestDisplayManagerFactory::GetInstance() |
| 5372 | ->GetForBrowserContext(browser_context) |
| 5373 | ->ShowPaymentHandlerWindow(url, std::move(callback)); |
| 5374 | return true; |
| 5375 | #endif |
| 5376 | } |
| 5377 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5378 | // Static; reverse URL handler for Web UI. Maps "chrome://chrome/foo/" to |
| 5379 | // "chrome://foo/". |
| 5380 | bool ChromeContentBrowserClient::HandleWebUIReverse( |
| 5381 | GURL* url, |
| 5382 | content::BrowserContext* browser_context) { |
| 5383 | // No need to actually reverse-rewrite the URL, but return true to update the |
| 5384 | // displayed URL when rewriting chrome://help to chrome://settings/help. |
| 5385 | return url->SchemeIs(content::kChromeUIScheme) && |
| 5386 | url->host() == chrome::kChromeUISettingsHost; |
| 5387 | } |
| 5388 | |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 5389 | const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const { |
| 5390 | return ui::NativeTheme::GetInstanceForWeb(); |
| 5391 | } |
| 5392 | |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 5393 | // static |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 5394 | void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( |
| 5395 | const storage::QuotaSettings* settings) { |
| 5396 | g_default_quota_settings = settings; |
| 5397 | } |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5398 | |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 5399 | scoped_refptr<safe_browsing::UrlCheckerDelegate> |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 5400 | ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate( |
| 5401 | content::ResourceContext* resource_context) { |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5402 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 5403 | |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 5404 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 5405 | if (!io_data->safe_browsing_enabled()->GetValue()) |
| 5406 | return nullptr; |
| 5407 | |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5408 | // |safe_browsing_service_| may be unavailable in tests. |
| 5409 | if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) { |
| 5410 | safe_browsing_url_checker_delegate_ = |
Jialiu Lin | 0de6756c | 2018-03-22 00:57:43 | [diff] [blame] | 5411 | base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>( |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5412 | safe_browsing_service_->database_manager(), |
Jialiu Lin | 0de6756c | 2018-03-22 00:57:43 | [diff] [blame] | 5413 | safe_browsing_service_->ui_manager()); |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5414 | } |
| 5415 | |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 5416 | return safe_browsing_url_checker_delegate_; |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5417 | } |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 5418 | |
| 5419 | base::Optional<std::string> |
| 5420 | ChromeContentBrowserClient::GetOriginPolicyErrorPage( |
Andy Paicu | 8b6f871 | 2019-07-16 15:02:26 | [diff] [blame] | 5421 | network::OriginPolicyState error_reason, |
Daniel Vogelheim | 7badd0d | 2019-02-04 14:42:18 | [diff] [blame] | 5422 | content::NavigationHandle* handle) { |
| 5423 | return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML( |
| 5424 | error_reason, handle); |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 5425 | } |
Kunihiko Sakamoto | 73b803d | 2018-10-05 09:09:52 | [diff] [blame] | 5426 | |
Takashi Toyoshima | 5af383aa | 2019-07-22 15:24:22 | [diff] [blame] | 5427 | bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() { |
Kunihiko Sakamoto | 73b803d | 2018-10-05 09:09:52 | [diff] [blame] | 5428 | // We require --user-data-dir flag too so that no dangerous changes are made |
| 5429 | // in the user's regular profile. |
| 5430 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 5431 | switches::kUserDataDir); |
| 5432 | } |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 5433 | |
| 5434 | void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate( |
| 5435 | int32_t network_traffic_annotation_id_hash, |
| 5436 | int64_t recv_bytes, |
| 5437 | int64_t sent_bytes) { |
Min Qin | cafb27b | 2018-10-30 18:02:03 | [diff] [blame] | 5438 | if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) { |
| 5439 | data_use_measurement::ChromeDataUseMeasurement::GetInstance() |
| 5440 | ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash, |
| 5441 | recv_bytes, sent_bytes); |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 5442 | } |
| 5443 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5444 | |
| 5445 | content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews( |
| 5446 | content::PreviewsState initial_state, |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5447 | content::NavigationHandle* navigation_handle, |
| 5448 | const GURL& current_navigation_url) { |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5449 | content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback( |
| 5450 | initial_state, navigation_handle, current_navigation_url); |
| 5451 | |
| 5452 | return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle); |
| 5453 | } |
| 5454 | |
| 5455 | content::PreviewsState |
| 5456 | ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback( |
| 5457 | content::PreviewsState initial_state, |
| 5458 | content::NavigationHandle* navigation_handle, |
| 5459 | const GURL& current_navigation_url) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5460 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
Tarun Bansal | b89c1d5 | 2019-01-16 06:56:29 | [diff] [blame] | 5461 | DCHECK(!navigation_handle->HasCommitted()); |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5462 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5463 | // If this is not a main frame, return the initial state. If there are no |
| 5464 | // previews in the state, return the state as is. |
| 5465 | if (!navigation_handle->IsInMainFrame() || |
| 5466 | navigation_handle->IsSameDocument()) { |
| 5467 | return initial_state; |
| 5468 | } |
| 5469 | |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5470 | if (!current_navigation_url.SchemeIsHTTPOrHTTPS()) |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5471 | return content::PREVIEWS_OFF; |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5472 | |
| 5473 | // Do not allow previews on POST navigations since the primary opt-out |
| 5474 | // mechanism is to reload the page. Because POST navigations are not |
| 5475 | // idempotent, we do not want to show a preview on a POST navigation where |
| 5476 | // opting out would cause another navigation, i.e.: a reload. |
| 5477 | if (navigation_handle->IsPost()) |
| 5478 | return content::PREVIEWS_OFF; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5479 | |
| 5480 | content::WebContents* web_contents = navigation_handle->GetWebContents(); |
| 5481 | content::WebContentsDelegate* delegate = web_contents->GetDelegate(); |
| 5482 | |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5483 | auto* browser_context = web_contents->GetBrowserContext(); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5484 | |
| 5485 | PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile( |
| 5486 | Profile::FromBrowserContext(browser_context)); |
| 5487 | auto* data_reduction_proxy_settings = |
| 5488 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 5489 | browser_context); |
| 5490 | // If the profile does not support previews or Data Saver, do not turn on |
| 5491 | // Previews. |
| 5492 | if (!previews_service || !previews_service->previews_ui_service() || |
| 5493 | !data_reduction_proxy_settings) { |
| 5494 | return content::PREVIEWS_OFF; |
| 5495 | } |
| 5496 | |
| 5497 | PreviewsUITabHelper* ui_tab_helper = |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5498 | PreviewsUITabHelper::FromWebContents(web_contents); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5499 | // If this tab does not have a PreviewsUITabHelper, no preview should be |
| 5500 | // served. |
| 5501 | if (!ui_tab_helper) |
| 5502 | return content::PREVIEWS_OFF; |
| 5503 | |
| 5504 | DCHECK(!browser_context->IsOffTheRecord()); |
| 5505 | |
| 5506 | // Other previews objects should all exist and be initialized if we have made |
| 5507 | // it past earlier checks. |
| 5508 | previews::PreviewsDeciderImpl* previews_decider_impl = |
| 5509 | previews_service->previews_ui_service()->previews_decider_impl(); |
| 5510 | DCHECK(previews_decider_impl); |
| 5511 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5512 | // Start with an unspecified state. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5513 | content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED; |
| 5514 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5515 | previews::PreviewsUserData* previews_data = |
| 5516 | ui_tab_helper->GetPreviewsUserData(navigation_handle); |
| 5517 | |
| 5518 | // Certain PreviewsStates are used within URLLoaders (Offline, server |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5519 | // previews) and cannot re-evaluate PreviewsState once previews triggering |
| 5520 | // logic has already been run, so they should not change. Assume that |
| 5521 | // previews triggering logic has run when PreviewsUserData already exists and |
| 5522 | // a Lite Page Redirect preview is not being attempted, since it may also |
| 5523 | // create a previews_data before this point. |
| 5524 | bool previews_triggering_logic_already_ran = false; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5525 | if (previews_data) { |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5526 | previews_triggering_logic_already_ran = |
| 5527 | !previews_data->server_lite_page_info(); |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5528 | } else { |
| 5529 | previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle( |
| 5530 | navigation_handle, previews_decider_impl->GeneratePageId()); |
| 5531 | } |
| 5532 | |
| 5533 | DCHECK(previews_data); |
| 5534 | |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 5535 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 5536 | previews::switches::kForceEnablePreviews)) { |
| 5537 | previews_decider_impl->LoadPageHints(current_navigation_url); |
| 5538 | return content::ALL_SUPPORTED_PREVIEWS; |
| 5539 | } |
| 5540 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5541 | bool is_reload = |
| 5542 | navigation_handle->GetReloadType() != content::ReloadType::NONE; |
| 5543 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5544 | content::PreviewsState server_previews_enabled_state = |
Robert Ogden | 54bb4ff | 2019-06-19 01:31:51 | [diff] [blame] | 5545 | content::SERVER_LITE_PAGE_ON; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5546 | |
| 5547 | // For now, treat server previews types as a single decision, and do not |
| 5548 | // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT |
| 5549 | // header, nor does the plumbing exist to modify the PreviewsState within the |
| 5550 | // URLLoader. |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5551 | if (previews_triggering_logic_already_ran) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5552 | // Copy the server state that was used before the redirect for the initial |
| 5553 | // URL. |
Robert Ogden | 869986f | 2019-06-20 19:12:05 | [diff] [blame] | 5554 | previews_state |= |
| 5555 | (previews_data->AllowedPreviewsState() & server_previews_enabled_state); |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5556 | } else { |
Doug Arnett | a3dc7158 | 2018-11-08 00:25:10 | [diff] [blame] | 5557 | if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart( |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5558 | previews_data, current_navigation_url, is_reload, |
Doug Arnett | d5a6003 | 2018-11-12 19:37:30 | [diff] [blame] | 5559 | previews::PreviewsType::LITE_PAGE)) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5560 | previews_state |= server_previews_enabled_state; |
| 5561 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5562 | } |
| 5563 | |
Robert Ogden | 198d657 | 2019-06-26 15:15:33 | [diff] [blame] | 5564 | // Evaluate Offline, NoScript, and ResourceBlocking previews. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5565 | previews_state |= previews::DetermineAllowedClientPreviewsState( |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5566 | previews_data, previews_triggering_logic_already_ran, |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5567 | data_reduction_proxy_settings->IsDataReductionProxyEnabled(), |
Ryan Sturm | 37b3069e | 2019-02-22 04:11:24 | [diff] [blame] | 5568 | previews_decider_impl, navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5569 | |
| 5570 | if (previews_state & content::PREVIEWS_OFF) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5571 | previews_data->set_allowed_previews_state(content::PREVIEWS_OFF); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5572 | return content::PREVIEWS_OFF; |
| 5573 | } |
| 5574 | |
| 5575 | if (previews_state & content::PREVIEWS_NO_TRANSFORM) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5576 | previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5577 | return content::PREVIEWS_NO_TRANSFORM; |
| 5578 | } |
| 5579 | |
| 5580 | // At this point, if no Preview is allowed, don't allow previews. |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5581 | if (previews_state == content::PREVIEWS_UNSPECIFIED) { |
| 5582 | previews_data->set_allowed_previews_state(content::PREVIEWS_OFF); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5583 | return content::PREVIEWS_OFF; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5584 | } |
| 5585 | |
| 5586 | content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED; |
| 5587 | if (delegate) { |
| 5588 | delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state); |
| 5589 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5590 | |
| 5591 | // If the allowed previews are limited by the embedder, ensure previews honors |
| 5592 | // those limits. |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5593 | if (embedder_state != content::PREVIEWS_UNSPECIFIED) { |
| 5594 | previews_state = previews_state & embedder_state; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5595 | // If no valid previews are left, set the state explicitly to PREVIEWS_OFF. |
| 5596 | if (previews_state == content::PREVIEWS_UNSPECIFIED) |
| 5597 | previews_state = content::PREVIEWS_OFF; |
| 5598 | } |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5599 | previews_data->set_allowed_previews_state(previews_state); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5600 | return previews_state; |
| 5601 | } |
| 5602 | |
| 5603 | // static |
| 5604 | content::PreviewsState |
| 5605 | ChromeContentBrowserClient::DetermineCommittedPreviewsForURL( |
| 5606 | const GURL& url, |
| 5607 | data_reduction_proxy::DataReductionProxyData* drp_data, |
| 5608 | previews::PreviewsUserData* previews_user_data, |
| 5609 | const previews::PreviewsDecider* previews_decider, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5610 | content::PreviewsState initial_state, |
| 5611 | content::NavigationHandle* navigation_handle) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5612 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 5613 | if (!previews::HasEnabledPreviews(initial_state)) |
| 5614 | return content::PREVIEWS_OFF; |
| 5615 | |
| 5616 | // Check if the server sent a preview directive. |
| 5617 | content::PreviewsState previews_state = |
Clark DuVall | 0ec5214 | 2019-06-06 19:53:55 | [diff] [blame] | 5618 | previews::DetermineCommittedServerPreviewsState(drp_data, initial_state); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5619 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5620 | // Check the various other client previews types. |
| 5621 | return previews::DetermineCommittedClientPreviewsState( |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5622 | previews_user_data, url, previews_state, previews_decider, |
| 5623 | navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5624 | } |
| 5625 | |
| 5626 | content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews( |
| 5627 | content::PreviewsState initial_state, |
| 5628 | content::NavigationHandle* navigation_handle, |
| 5629 | const net::HttpResponseHeaders* response_headers) { |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5630 | content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback( |
| 5631 | initial_state, navigation_handle, response_headers); |
| 5632 | |
| 5633 | return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle); |
| 5634 | } |
| 5635 | |
| 5636 | content::PreviewsState |
| 5637 | ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback( |
| 5638 | content::PreviewsState initial_state, |
| 5639 | content::NavigationHandle* navigation_handle, |
| 5640 | const net::HttpResponseHeaders* response_headers) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5641 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 5642 | // Only support HTTP and HTTPS. |
| 5643 | if (navigation_handle->IsErrorPage() || |
| 5644 | !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) { |
| 5645 | return content::PREVIEWS_OFF; |
| 5646 | } |
| 5647 | |
| 5648 | // If this is not a main frame, return the initial state. If there are no |
| 5649 | // previews in the state, return the state as is. |
| 5650 | if (!previews::HasEnabledPreviews(initial_state) || |
| 5651 | !navigation_handle->IsInMainFrame() || |
| 5652 | navigation_handle->IsSameDocument()) { |
| 5653 | return initial_state; |
| 5654 | } |
| 5655 | |
| 5656 | // WebContents that don't have a PreviewsUITabHelper are not supported. |
| 5657 | PreviewsUITabHelper* ui_tab_helper = |
| 5658 | PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents()); |
| 5659 | if (!ui_tab_helper) |
| 5660 | return content::PREVIEWS_OFF; |
| 5661 | |
| 5662 | // If we did not previously create a PreviewsUserData, do not go any further. |
| 5663 | previews::PreviewsUserData* previews_user_data = |
| 5664 | ui_tab_helper->GetPreviewsUserData(navigation_handle); |
| 5665 | if (!previews_user_data) |
| 5666 | return content::PREVIEWS_OFF; |
| 5667 | |
| 5668 | PreviewsService* previews_service = |
| 5669 | PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext( |
| 5670 | navigation_handle->GetWebContents()->GetBrowserContext())); |
| 5671 | |
| 5672 | if (!previews_service || !previews_service->previews_ui_service()) |
| 5673 | return content::PREVIEWS_OFF; |
| 5674 | |
| 5675 | // Check if offline previews are being used and set it in the user data. |
| 5676 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 5677 | offline_pages::OfflinePageTabHelper* tab_helper = |
| 5678 | offline_pages::OfflinePageTabHelper::FromWebContents( |
| 5679 | navigation_handle->GetWebContents()); |
| 5680 | |
Ryan Sturm | fc7d92f | 2019-02-12 02:24:23 | [diff] [blame] | 5681 | bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage(); |
| 5682 | bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem(); |
| 5683 | |
| 5684 | // If this is an offline page, but not a preview, then we should not attempt |
| 5685 | // any previews or surface the previews UI. |
| 5686 | if (is_offline_page && !is_offline_preview) |
| 5687 | return content::PREVIEWS_OFF; |
| 5688 | |
| 5689 | previews_user_data->set_offline_preview_used(is_offline_preview); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5690 | #endif // BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 5691 | |
| 5692 | // Annotate request if no-transform directive found in response headers. |
| 5693 | if (response_headers && |
| 5694 | response_headers->HasHeaderValue("cache-control", "no-transform")) { |
Jered Gray | ba1da12 | 2018-10-31 23:06:26 | [diff] [blame] | 5695 | previews_user_data->set_cache_control_no_transform_directive(); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5696 | } |
| 5697 | |
| 5698 | previews::PreviewsDeciderImpl* previews_decider_impl = |
| 5699 | previews_service->previews_ui_service()->previews_decider_impl(); |
| 5700 | DCHECK(previews_decider_impl); |
| 5701 | |
Clark DuVall | 9c5a72cc | 2018-10-25 01:29:21 | [diff] [blame] | 5702 | std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data; |
| 5703 | auto* settings = |
| 5704 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 5705 | navigation_handle->GetWebContents()->GetBrowserContext()); |
| 5706 | if (settings) { |
| 5707 | // TODO(898326): |drp_data| may be incomplete because |navigation_handle| |
| 5708 | // does not yet have all the response information. |
| 5709 | drp_data = settings->CreateDataFromNavigationHandle(navigation_handle, |
| 5710 | response_headers); |
| 5711 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5712 | |
| 5713 | // Determine effective PreviewsState for this committed main frame response. |
| 5714 | content::PreviewsState committed_state = DetermineCommittedPreviewsForURL( |
Clark DuVall | 9c5a72cc | 2018-10-25 01:29:21 | [diff] [blame] | 5715 | navigation_handle->GetURL(), drp_data.get(), previews_user_data, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5716 | previews_decider_impl, initial_state, navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5717 | |
| 5718 | // Double check that we never serve a preview when we have a |
| 5719 | // cache-control:no-transform directive. |
| 5720 | DCHECK(!previews_user_data->cache_control_no_transform_directive() || |
| 5721 | !previews::HasEnabledPreviews(committed_state)); |
| 5722 | |
Robert Ogden | ded292c6f | 2019-05-03 22:44:51 | [diff] [blame] | 5723 | // TODO(robertogden): Consider moving this to after the holdback logic. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5724 | previews_user_data->set_committed_previews_state(committed_state); |
| 5725 | |
| 5726 | previews::PreviewsType committed_type = |
| 5727 | previews::GetMainFramePreviewsType(committed_state); |
| 5728 | |
| 5729 | // Capture committed previews type, if any, in PreviewsUserData. |
| 5730 | // Note: this is for the subset of previews types that are decided upon |
| 5731 | // navigation commit. Previews types that are determined prior to |
| 5732 | // navigation (such as for offline pages or for redirecting to another |
| 5733 | // url), are not set here. |
| 5734 | previews_user_data->SetCommittedPreviewsType(committed_type); |
| 5735 | |
| 5736 | // Log the commit decision. |
| 5737 | std::vector<previews::PreviewsEligibilityReason> passed_reasons; |
| 5738 | previews_decider_impl->LogPreviewDecisionMade( |
| 5739 | (previews_user_data->cache_control_no_transform_directive() |
| 5740 | ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM |
| 5741 | : previews::PreviewsEligibilityReason::COMMITTED), |
| 5742 | navigation_handle->GetURL(), base::Time::Now(), |
Robert Ogden | 869986f | 2019-06-20 19:12:05 | [diff] [blame] | 5743 | previews_user_data->CommittedPreviewsType(), std::move(passed_reasons), |
Robert Ogden | 33e3631 | 2019-05-06 19:17:05 | [diff] [blame] | 5744 | previews_user_data); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5745 | |
| 5746 | return committed_state; |
| 5747 | } |
Charlie Harrison | 650e1142 | 2018-12-04 00:37:26 | [diff] [blame] | 5748 | |
| 5749 | void ChromeContentBrowserClient::LogWebFeatureForCurrentPage( |
| 5750 | content::RenderFrameHost* render_frame_host, |
| 5751 | blink::mojom::WebFeature feature) { |
| 5752 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 5753 | page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {}); |
| 5754 | page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage( |
| 5755 | render_frame_host, new_features); |
| 5756 | } |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5757 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5758 | std::string ChromeContentBrowserClient::GetProduct() { |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5759 | return ::GetProduct(); |
| 5760 | } |
| 5761 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5762 | std::string ChromeContentBrowserClient::GetUserAgent() { |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5763 | return ::GetUserAgent(); |
| 5764 | } |
Sam McNally | d54e23f9 | 2019-01-16 04:42:39 | [diff] [blame] | 5765 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5766 | blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() { |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 5767 | return ::GetUserAgentMetadata(); |
| 5768 | } |
| 5769 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5770 | base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() { |
Austin Orion | e250d01 | 2019-05-29 02:56:27 | [diff] [blame] | 5771 | // This icon is available on Android, but adds 19KiB to the APK. Since it |
| 5772 | // isn't used on Android we exclude it to avoid bloat. |
| 5773 | #if !defined(OS_ANDROID) |
| 5774 | return base::Optional<gfx::ImageSkia>( |
| 5775 | *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 5776 | IDR_PRODUCT_LOGO_256)); |
| 5777 | #else |
| 5778 | return base::nullopt; |
| 5779 | #endif |
| 5780 | } |
| 5781 | |
Sam McNally | d54e23f9 | 2019-01-16 04:42:39 | [diff] [blame] | 5782 | bool ChromeContentBrowserClient::IsBuiltinComponent( |
| 5783 | content::BrowserContext* browser_context, |
| 5784 | const url::Origin& origin) { |
| 5785 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5786 | return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent( |
| 5787 | browser_context, origin); |
| 5788 | #else |
| 5789 | return false; |
| 5790 | #endif |
| 5791 | } |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 5792 | |
| 5793 | bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted( |
| 5794 | const GURL& url, |
| 5795 | content::BrowserContext* context) { |
| 5796 | PolicyBlacklistService* service = |
| 5797 | PolicyBlacklistFactory::GetForBrowserContext(context); |
| 5798 | |
| 5799 | using URLBlacklistState = policy::URLBlacklist::URLBlacklistState; |
| 5800 | URLBlacklistState blacklist_state = service->GetURLBlacklistState(url); |
| 5801 | return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST; |
| 5802 | } |
Dominic Mazzoni | 21fb028 | 2019-02-13 18:32:47 | [diff] [blame] | 5803 | |
| 5804 | ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext( |
| 5805 | content::BrowserContext* browser_context) { |
| 5806 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 5807 | return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode(); |
| 5808 | } |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5809 | |
| 5810 | #if defined(OS_ANDROID) |
| 5811 | content::ContentBrowserClient::WideColorGamutHeuristic |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5812 | ChromeContentBrowserClient::GetWideColorGamutHeuristic() { |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5813 | if (features::UseDisplayWideColorGamut()) { |
| 5814 | return WideColorGamutHeuristic::kUseDisplay; |
| 5815 | } |
| 5816 | return WideColorGamutHeuristic::kNone; |
| 5817 | } |
| 5818 | #endif |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5819 | |
| 5820 | base::flat_set<std::string> |
Ehsan Karamad | 466529d | 2019-05-24 03:24:43 | [diff] [blame] | 5821 | ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers( |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5822 | content::ResourceContext* resource_context) { |
| 5823 | base::flat_set<std::string> mime_types; |
| 5824 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 5825 | auto map = PluginUtils::GetMimeTypeToExtensionIdMap(resource_context); |
| 5826 | for (const auto& pair : map) |
| 5827 | mime_types.insert(pair.first); |
| 5828 | #endif |
| 5829 | return mime_types; |
| 5830 | } |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5831 | |
| 5832 | void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy( |
| 5833 | const content::WebContents* web_contents, |
| 5834 | const content::RenderFrameHost* frame_host, |
| 5835 | bool user_gesture, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5836 | content::NavigationDownloadPolicy* download_policy) { |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5837 | const ChromeSubresourceFilterClient* client = |
| 5838 | ChromeSubresourceFilterClient::FromWebContents(web_contents); |
| 5839 | if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) { |
Yao Xiao | f6064666 | 2019-07-25 07:25:04 | [diff] [blame] | 5840 | download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame); |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5841 | if (!user_gesture) { |
| 5842 | if (base::FeatureList::IsEnabled( |
| 5843 | blink::features:: |
| 5844 | kBlockingDownloadsInAdFrameWithoutUserActivation)) { |
| 5845 | download_policy->SetDisallowed( |
| 5846 | content::NavigationDownloadType::kAdFrameNoGesture); |
| 5847 | } else { |
| 5848 | download_policy->SetAllowed( |
| 5849 | content::NavigationDownloadType::kAdFrameNoGesture); |
| 5850 | } |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5851 | } |
| 5852 | } |
| 5853 | } |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5854 | |
| 5855 | bool ChromeContentBrowserClient::IsBluetoothScanningBlocked( |
| 5856 | content::BrowserContext* browser_context, |
| 5857 | const url::Origin& requesting_origin, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5858 | const url::Origin& embedding_origin) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5859 | const HostContentSettingsMap* const content_settings = |
| 5860 | HostContentSettingsMapFactory::GetForProfile( |
| 5861 | Profile::FromBrowserContext(browser_context)); |
| 5862 | |
| 5863 | if (content_settings->GetContentSetting( |
| 5864 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
| 5865 | CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING, |
| 5866 | std::string()) == CONTENT_SETTING_BLOCK) { |
| 5867 | return true; |
| 5868 | } |
| 5869 | |
| 5870 | return false; |
| 5871 | } |
| 5872 | |
| 5873 | void ChromeContentBrowserClient::BlockBluetoothScanning( |
| 5874 | content::BrowserContext* browser_context, |
| 5875 | const url::Origin& requesting_origin, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5876 | const url::Origin& embedding_origin) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5877 | HostContentSettingsMap* const content_settings = |
| 5878 | HostContentSettingsMapFactory::GetForProfile( |
| 5879 | Profile::FromBrowserContext(browser_context)); |
| 5880 | |
| 5881 | content_settings->SetContentSettingDefaultScope( |
| 5882 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
| 5883 | CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING, std::string(), |
| 5884 | CONTENT_SETTING_BLOCK); |
| 5885 | } |