[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/chrome_content_browser_client.h" |
| 6 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 7 | #include <map> |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 8 | #include <set> |
[email protected] | 1033acd | 2012-02-08 08:46:27 | [diff] [blame] | 9 | #include <utility> |
[email protected] | 7c3228a | 2011-11-11 21:35:22 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
brettw | f195891 | 2015-10-07 19:43:12 | [diff] [blame] | 12 | #include "base/base_switches.h" |
[email protected] | 317c58f0 | 2011-11-09 02:15:03 | [diff] [blame] | 13 | #include "base/bind.h" |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 14 | #include "base/bind_helpers.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 15 | #include "base/command_line.h" |
Ken Rockot | 91c40da8 | 2019-08-12 20:07:11 | [diff] [blame] | 16 | #include "base/compiler_specific.h" |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 17 | #include "base/files/file_util.h" |
morrita | d95714f | 2014-10-01 02:37:24 | [diff] [blame] | 18 | #include "base/files/scoped_file.h" |
Marc Treib | ad33cf94 | 2017-08-24 11:19:00 | [diff] [blame] | 19 | #include "base/i18n/base_i18n_switches.h" |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 20 | #include "base/i18n/character_encoding.h" |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 21 | #include "base/macros.h" |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 22 | #include "base/metrics/field_trial_params.h" |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 23 | #include "base/metrics/histogram_macros.h" |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 24 | #include "base/no_destructor.h" |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 25 | #include "base/path_service.h" |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 26 | #include "base/stl_util.h" |
[email protected] | e746341 | 2013-06-10 22:53:46 | [diff] [blame] | 27 | #include "base/strings/string_number_conversions.h" |
markdittmer | 67b71ea | 2016-03-03 22:40:03 | [diff] [blame] | 28 | #include "base/strings/string_split.h" |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 29 | #include "base/strings/string_util.h" |
| 30 | #include "base/strings/stringprintf.h" |
[email protected] | 135cb80 | 2013-06-09 16:44:20 | [diff] [blame] | 31 | #include "base/strings/utf_string_conversions.h" |
Sebastien Marchand | 75a7cdf | 2018-11-13 23:47:03 | [diff] [blame] | 32 | #include "base/system/sys_info.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 33 | #include "base/task/post_task.h" |
Wojciech Dzierżanowski | 4538080 | 2019-04-29 14:50:32 | [diff] [blame] | 34 | #include "base/threading/sequenced_task_runner_handle.h" |
gab | b15e1907 | 2016-05-11 20:45:41 | [diff] [blame] | 35 | #include "base/threading/thread_task_runner_handle.h" |
avi | e4d7b6f | 2015-12-26 00:59:18 | [diff] [blame] | 36 | #include "build/build_config.h" |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 37 | #include "chrome/app/builtin_service_manifests.h" |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 38 | #include "chrome/app/chrome_content_browser_overlay_manifest.h" |
| 39 | #include "chrome/app/chrome_content_gpu_overlay_manifest.h" |
| 40 | #include "chrome/app/chrome_content_renderer_overlay_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" |
Oksana Zhuravlova | 4dd171e8 | 2019-08-16 20:54:00 | [diff] [blame] | 49 | #include "chrome/browser/chrome_browser_interface_binders.h" |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 50 | #include "chrome/browser/chrome_content_browser_client_parts.h" |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 51 | #include "chrome/browser/chrome_quota_permission_context.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 52 | #include "chrome/browser/content_settings/cookie_settings_factory.h" |
peconn | 5100d43 | 2015-09-16 12:03:08 | [diff] [blame] | 53 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 54 | #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
Robbie McElrath | 1294d24 | 2019-05-31 20:46:22 | [diff] [blame] | 55 | #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 56 | #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
Zhuoyu Qian | cb197638 | 2018-12-13 02:18:30 | [diff] [blame] | 57 | #include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h" |
| 58 | #include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h" |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 59 | #include "chrome/browser/data_use_measurement/chrome_data_use_measurement.h" |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 60 | #include "chrome/browser/defaults.h" |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 61 | #include "chrome/browser/download/download_prefs.h" |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 62 | #include "chrome/browser/extensions/chrome_extension_cookies.h" |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 63 | #include "chrome/browser/external_protocol/external_protocol_handler.h" |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 64 | #include "chrome/browser/font_family_cache.h" |
Matt Reynolds | 93616f9b | 2019-06-07 01:28:52 | [diff] [blame] | 65 | #include "chrome/browser/hid/chrome_hid_delegate.h" |
Anthony Vallee-Dubois | e2432137a | 2019-01-17 20:06:01 | [diff] [blame] | 66 | #include "chrome/browser/language/translate_frame_binder.h" |
Avi Drissman | d3092734 | 2018-05-22 15:04:27 | [diff] [blame] | 67 | #include "chrome/browser/lifetime/browser_shutdown.h" |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 68 | #include "chrome/browser/lookalikes/lookalike_url_navigation_throttle.h" |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 69 | #include "chrome/browser/media/router/media_router_feature.h" |
Derek Cheng | eb64b19a | 2018-01-02 20:20:42 | [diff] [blame] | 70 | #include "chrome/browser/media/router/presentation/presentation_service_delegate_impl.h" |
| 71 | #include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h" |
Patrik Höglund | b564859b | 2018-05-17 11:17:16 | [diff] [blame] | 72 | #include "chrome/browser/media/webrtc/audio_debug_recordings_handler.h" |
mcasas | a2023ab | 2016-09-08 01:06:36 | [diff] [blame] | 73 | #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
Darin Fisher | 09aa722 | 2019-08-29 09:27:36 | [diff] [blame] | 74 | #include "chrome/browser/media/webrtc/webrtc_logging_controller.h" |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 75 | #include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h" |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 76 | #include "chrome/browser/metrics/chrome_feature_list_creator.h" |
[email protected] | a2b4c5c | 2013-10-18 02:06:07 | [diff] [blame] | 77 | #include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h" |
Lu Chen | 5bec7a30 | 2018-06-26 18:52:32 | [diff] [blame] | 78 | #include "chrome/browser/navigation_predictor/navigation_predictor.h" |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 79 | #include "chrome/browser/net/chrome_network_delegate.h" |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 80 | #include "chrome/browser/net/system_network_context_manager.h" |
dvallet | 233f57ab | 2016-12-21 03:17:10 | [diff] [blame] | 81 | #include "chrome/browser/net_benchmarking.h" |
Richard Knoll | d0eae96 | 2019-04-04 12:34:02 | [diff] [blame] | 82 | #include "chrome/browser/notifications/platform_notification_service_factory.h" |
peter | c26c6c6 | 2014-12-10 14:13:59 | [diff] [blame] | 83 | #include "chrome/browser/notifications/platform_notification_service_impl.h" |
csharrison | 4bd8a19 | 2016-08-02 18:03:15 | [diff] [blame] | 84 | #include "chrome/browser/page_load_metrics/metrics_navigation_throttle.h" |
Charlie Harrison | 650e1142 | 2018-12-04 00:37:26 | [diff] [blame] | 85 | #include "chrome/browser/page_load_metrics/metrics_web_contents_observer.h" |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 86 | #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
leon.han | 952ea325 | 2016-04-13 02:44:56 | [diff] [blame] | 87 | #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 88 | #include "chrome/browser/payments/payment_request_display_manager_factory.h" |
Sigurdur Asgeirsson | 54b7270 | 2019-04-12 14:18:54 | [diff] [blame] | 89 | #include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h" |
Sigurdur Asgeirsson | 7069667 | 2019-02-08 16:14:51 | [diff] [blame] | 90 | #include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h" |
Adam Langley | 85339f6 | 2018-02-12 22:03:56 | [diff] [blame] | 91 | #include "chrome/browser/permissions/attestation_permission_request.h" |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 92 | #include "chrome/browser/permissions/permission_context_base.h" |
Adam Langley | 85339f6 | 2018-02-12 22:03:56 | [diff] [blame] | 93 | #include "chrome/browser/permissions/permission_request_manager.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 94 | #include "chrome/browser/platform_util.h" |
Amber Won | 94afd811 | 2017-08-23 17:30:11 | [diff] [blame] | 95 | #include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h" |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 96 | #include "chrome/browser/plugins/plugin_utils.h" |
Alexandr Ilin | 4909ec8 | 2018-06-06 10:22:48 | [diff] [blame] | 97 | #include "chrome/browser/predictors/loading_predictor.h" |
| 98 | #include "chrome/browser/predictors/loading_predictor_factory.h" |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 99 | #include "chrome/browser/prerender/prerender_final_status.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 100 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 101 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | 2736c03 | 2012-05-11 18:06:07 | [diff] [blame] | 102 | #include "chrome/browser/prerender/prerender_message_filter.h" |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 103 | #include "chrome/browser/prerender/prerender_util.h" |
Ryan Sturm | cc5071be | 2019-02-16 02:15:19 | [diff] [blame] | 104 | #include "chrome/browser/previews/previews_content_util.h" |
Robert Ogden | afd250b | 2018-07-25 22:21:03 | [diff] [blame] | 105 | #include "chrome/browser/previews/previews_lite_page_decider.h" |
Robert Ogden | e7fdca9 | 2018-10-12 17:53:06 | [diff] [blame] | 106 | #include "chrome/browser/previews/previews_lite_page_navigation_throttle.h" |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 107 | #include "chrome/browser/previews/previews_lite_page_url_loader_interceptor.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 108 | #include "chrome/browser/previews/previews_service.h" |
| 109 | #include "chrome/browser/previews/previews_service_factory.h" |
| 110 | #include "chrome/browser/previews/previews_ui_tab_helper.h" |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 111 | #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 112 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 113 | #include "chrome/browser/profiles/profile_io_data.h" |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 114 | #include "chrome/browser/profiles/renderer_updater.h" |
| 115 | #include "chrome/browser/profiles/renderer_updater_factory.h" |
Erik Chen | 49bbfa2 | 2017-08-18 08:49:56 | [diff] [blame] | 116 | #include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h" |
| 117 | #include "chrome/browser/profiling_host/profiling_process_host.h" |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 118 | #include "chrome/browser/renderer_host/chrome_navigation_ui_data.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 119 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 120 | #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 121 | #include "chrome/browser/renderer_preferences_util.h" |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 122 | #include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h" |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 123 | #include "chrome/browser/safe_browsing/certificate_reporting_service.h" |
| 124 | #include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h" |
Carlos IL | 4ee307e | 2018-12-22 03:19:00 | [diff] [blame] | 125 | #include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h" |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 126 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 127 | #include "chrome/browser/safe_browsing/ui_manager.h" |
| 128 | #include "chrome/browser/safe_browsing/url_checker_delegate_impl.h" |
[email protected] | a7b8e43d | 2013-03-18 18:52:43 | [diff] [blame] | 129 | #include "chrome/browser/search/search.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 130 | #include "chrome/browser/sessions/session_tab_helper.h" |
Reilly Grant | cc22e60 | 2018-09-07 15:25:20 | [diff] [blame] | 131 | #include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h" |
Reilly Grant | 3787780 | 2018-08-18 00:58:35 | [diff] [blame] | 132 | #include "chrome/browser/signin/chrome_signin_url_loader_throttle.h" |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 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" |
Emily Stark | d6896cd3 | 2019-08-21 04:55:54 | [diff] [blame] | 158 | #include "chrome/browser/ui/login/login_navigation_throttle.h" |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 159 | #include "chrome/browser/ui/prefs/pref_watcher.h" |
[email protected] | 329ac97 | 2013-06-21 15:24:25 | [diff] [blame] | 160 | #include "chrome/browser/ui/sync/sync_promo_ui.h" |
[email protected] | b5d7342 | 2012-06-02 23:46:44 | [diff] [blame] | 161 | #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h" |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 162 | #include "chrome/browser/ui/ui_features.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 163 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
dbeam | baee5bd | 2015-09-26 03:07:01 | [diff] [blame] | 164 | #include "chrome/browser/ui/webui/log_web_ui_url.h" |
reillyg | 3ff4532 | 2015-10-23 21:16:25 | [diff] [blame] | 165 | #include "chrome/browser/usb/usb_tab_helper.h" |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 166 | #include "chrome/browser/vr/vr_tab_helper.h" |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 167 | #include "chrome/browser/web_applications/components/app_registrar.h" |
| 168 | #include "chrome/browser/web_applications/web_app_provider.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 169 | #include "chrome/common/buildflags.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 170 | #include "chrome/common/channel_info.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 171 | #include "chrome/common/chrome_constants.h" |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 172 | #include "chrome/common/chrome_features.h" |
[email protected] | a7944aa | 2012-10-15 10:12:14 | [diff] [blame] | 173 | #include "chrome/common/chrome_paths.h" |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 174 | #include "chrome/common/chrome_paths_internal.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 175 | #include "chrome/common/chrome_switches.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" |
evliu | bc2aa047 | 2019-08-09 20:19:19 | [diff] [blame] | 181 | #include "chrome/common/pref_names_util.h" |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 182 | #include "chrome/common/prerender_url_loader_throttle.h" |
Egor Pasko | d52474c3 | 2018-06-19 12:03:22 | [diff] [blame] | 183 | #include "chrome/common/prerender_util.h" |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 184 | #include "chrome/common/render_messages.h" |
nigeltao | 7cd8d558 | 2016-12-12 06:05:28 | [diff] [blame] | 185 | #include "chrome/common/renderer_configuration.mojom.h" |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 186 | #include "chrome/common/secure_origin_whitelist.h" |
wittman | 832321f5 | 2016-10-10 18:18:38 | [diff] [blame] | 187 | #include "chrome/common/stack_sampling_configuration.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 188 | #include "chrome/common/url_constants.h" |
Peter Boström | 8e9b163 | 2019-08-22 23:12:47 | [diff] [blame] | 189 | #include "chrome/common/webui_url_constants.h" |
ben | c70c0e3 | 2016-09-22 03:50:37 | [diff] [blame] | 190 | #include "chrome/grit/browser_resources.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 191 | #include "chrome/grit/generated_resources.h" |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 192 | #include "chrome/installer/util/google_update_settings.h" |
leon.han | 04b276e | 2016-06-01 01:34:16 | [diff] [blame] | 193 | #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
brettw | f195891 | 2015-10-07 19:43:12 | [diff] [blame] | 194 | #include "components/autofill/core/common/autofill_switches.h" |
msramek | 1c8e19d | 2017-01-04 20:04:53 | [diff] [blame] | 195 | #include "components/browsing_data/core/browsing_data_utils.h" |
[email protected] | 649b5727 | 2014-05-09 14:54:44 | [diff] [blame] | 196 | #include "components/cdm/browser/cdm_message_filter_android.h" |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 197 | #include "components/certificate_matching/certificate_principal_pattern.h" |
[email protected] | 09cff7878 | 2014-04-20 22:04:48 | [diff] [blame] | 198 | #include "components/cloud_devices/common/cloud_devices_switches.h" |
Tao Bai | 02ab4dd4 | 2019-03-06 00:30:37 | [diff] [blame] | 199 | #include "components/content_capture/browser/content_capture_receiver_manager.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 200 | #include "components/content_settings/core/browser/content_settings_utils.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 201 | #include "components/content_settings/core/browser/cookie_settings.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 202 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 203 | #include "components/content_settings/core/common/content_settings.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 204 | #include "components/content_settings/core/common/content_settings_types.h" |
tbansal | 08a0e3e | 2017-06-30 21:30:08 | [diff] [blame] | 205 | #include "components/content_settings/core/common/content_settings_utils.h" |
Daniel Vogelheim | 976f1c2 | 2017-11-22 16:26:03 | [diff] [blame] | 206 | #include "components/content_settings/core/common/pref_names.h" |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 207 | #include "components/data_reduction_proxy/content/common/data_reduction_proxy_url_loader_throttle.h" |
Clark DuVall | 0e90172 | 2019-08-14 23:31:37 | [diff] [blame] | 208 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 209 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h" |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 210 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h" |
rajendrant | 4319407 | 2019-04-15 22:13:43 | [diff] [blame] | 211 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h" |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 212 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
Wojciech Dzierżanowski | 4538080 | 2019-04-29 14:50:32 | [diff] [blame] | 213 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_throttle_manager.h" |
wychen | e5568734 | 2015-11-13 20:17:03 | [diff] [blame] | 214 | #include "components/dom_distiller/core/dom_distiller_switches.h" |
[email protected] | 474a5a3 | 2014-07-28 18:23:24 | [diff] [blame] | 215 | #include "components/dom_distiller/core/url_constants.h" |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 216 | #include "components/error_page/common/error_page_switches.h" |
khushalsagar | c5447db2 | 2017-08-22 17:53:01 | [diff] [blame] | 217 | #include "components/feature_engagement/public/feature_constants.h" |
| 218 | #include "components/feature_engagement/public/feature_list.h" |
John Abd-El-Malek | 9cf3d7f0 | 2018-07-27 02:40:39 | [diff] [blame] | 219 | #include "components/google/core/common/google_util.h" |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 220 | #include "components/language/core/browser/pref_names.h" |
wittman | e16da278 | 2016-09-21 16:43:04 | [diff] [blame] | 221 | #include "components/metrics/call_stack_profile_collector.h" |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 222 | #include "components/metrics/client_info.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" |
Sophie Chang | ff1fc38 | 2019-08-21 16:30:21 | [diff] [blame] | 236 | #include "components/previews/content/previews_decider.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 237 | #include "components/previews/content/previews_decider_impl.h" |
| 238 | #include "components/previews/content/previews_ui_service.h" |
| 239 | #include "components/previews/content/previews_user_data.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 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" |
Colin Blundell | 3517170e | 2019-07-11 08:16:34 | [diff] [blame] | 255 | #include "components/signin/public/base/signin_pref_names.h" |
Scott Violet | d7983c5 | 2018-03-03 00:24:41 | [diff] [blame] | 256 | #include "components/spellcheck/spellcheck_buildflags.h" |
Ken Rockot | 7c6275b | 2019-08-02 20:00:23 | [diff] [blame] | 257 | #include "components/startup_metric_utils/browser/startup_metric_host_impl.h" |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 258 | #include "components/subresource_filter/content/browser/content_subresource_filter_throttle_manager.h" |
[email protected] | eba93c9 | 2014-01-07 17:34:17 | [diff] [blame] | 259 | #include "components/translate/core/common/translate_switches.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 260 | #include "components/url_formatter/url_fixer.h" |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 261 | #include "components/variations/variations_associated_data.h" |
Jun Cai | 0e56863 | 2018-08-09 02:05:33 | [diff] [blame] | 262 | #include "components/variations/variations_http_header_provider.h" |
Kyle Milka | b5c048e | 2017-07-07 02:38:46 | [diff] [blame] | 263 | #include "components/variations/variations_switches.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 264 | #include "components/version_info/version_info.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 265 | #include "content/public/browser/browser_child_process_host.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 266 | #include "content/public/browser/browser_main_parts.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 267 | #include "content/public/browser/browser_ppapi_host.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 268 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | 30a306f4 | 2013-06-10 03:09:03 | [diff] [blame] | 269 | #include "content/public/browser/browser_thread.h" |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 270 | #include "content/public/browser/browser_url_handler.h" |
msramek | e169ccb | 2017-04-26 05:21:41 | [diff] [blame] | 271 | #include "content/public/browser/browsing_data_remover.h" |
Lucas Garron | b9539b73 | 2017-10-31 00:22:09 | [diff] [blame] | 272 | #include "content/public/browser/certificate_request_result_type.h" |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 273 | #include "content/public/browser/child_process_data.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 274 | #include "content/public/browser/child_process_security_policy.h" |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 275 | #include "content/public/browser/client_certificate_delegate.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 276 | #include "content/public/browser/file_url_loader.h" |
Mohsen Izadi | 6a6476b7 | 2018-12-07 04:34:35 | [diff] [blame] | 277 | #include "content/public/browser/gpu_data_manager.h" |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 278 | #include "content/public/browser/navigation_handle.h" |
| 279 | #include "content/public/browser/navigation_throttle.h" |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 280 | #include "content/public/browser/overlay_window.h" |
[email protected] | 094c877 | 2013-12-21 17:54:50 | [diff] [blame] | 281 | #include "content/public/browser/render_frame_host.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 282 | #include "content/public/browser/render_process_host.h" |
[email protected] | 9c1662b | 2012-03-06 15:44:33 | [diff] [blame] | 283 | #include "content/public/browser/render_view_host.h" |
[email protected] | ce96786 | 2012-02-09 22:47:05 | [diff] [blame] | 284 | #include "content/public/browser/resource_context.h" |
jam | 608f299 | 2016-03-31 16:35:34 | [diff] [blame] | 285 | #include "content/public/browser/storage_partition.h" |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 286 | #include "content/public/browser/tts_controller.h" |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 287 | #include "content/public/browser/tts_platform.h" |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 288 | #include "content/public/browser/url_loader_request_interceptor.h" |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 289 | #include "content/public/browser/vpn_service_proxy.h" |
[email protected] | 91ee368 | 2012-01-19 15:02:19 | [diff] [blame] | 290 | #include "content/public/browser/web_contents.h" |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 291 | #include "content/public/browser/web_contents_delegate.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 292 | #include "content/public/browser/web_ui_url_loader_factory.h" |
[email protected] | e0ada9c | 2012-03-20 03:54:43 | [diff] [blame] | 293 | #include "content/public/common/child_process_host.h" |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 294 | #include "content/public/common/content_descriptors.h" |
juncai | 1bf9f7c | 2016-03-22 20:46:56 | [diff] [blame] | 295 | #include "content/public/common/content_features.h" |
brettw | 90e9260 | 2015-10-10 00:12:40 | [diff] [blame] | 296 | #include "content/public/common/content_switches.h" |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 297 | #include "content/public/common/network_service_util.h" |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 298 | #include "content/public/common/service_manager_connection.h" |
ben | 51bb6c6 | 2016-11-17 20:15:57 | [diff] [blame] | 299 | #include "content/public/common/service_names.mojom.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 300 | #include "content/public/common/url_constants.h" |
[email protected] | 22aa4f8 | 2013-09-24 17:01:44 | [diff] [blame] | 301 | #include "content/public/common/url_utils.h" |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 302 | #include "content/public/common/user_agent.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 303 | #include "content/public/common/web_preferences.h" |
Takuto Ikuta | aa3b796c | 2019-02-06 02:54:56 | [diff] [blame] | 304 | #include "content/public/common/window_container_type.mojom-shared.h" |
Bill Orr | eb42922 | 2018-08-08 21:14:43 | [diff] [blame] | 305 | #include "device/vr/buildflags/buildflags.h" |
Scott Violet | c8240b0 | 2018-03-08 22:03:59 | [diff] [blame] | 306 | #include "extensions/buildflags/buildflags.h" |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 307 | #include "google_apis/gaia/gaia_urls.h" |
Andrew Moylan | 17329fc | 2017-09-25 07:43:30 | [diff] [blame] | 308 | #include "google_apis/google_api_keys.h" |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 309 | #include "gpu/config/gpu_switches.h" |
grunell | 086a411 | 2017-03-02 09:23:04 | [diff] [blame] | 310 | #include "media/audio/audio_manager.h" |
François Beaufort | 8c08979fc | 2018-03-05 13:06:31 | [diff] [blame] | 311 | #include "media/base/media_switches.h" |
Scott Violet | a35f9a4 | 2018-03-22 22:00:44 | [diff] [blame] | 312 | #include "media/media_buildflags.h" |
| 313 | #include "media/mojo/buildflags.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 314 | #include "mojo/public/cpp/bindings/binding_set.h" |
Shimi Zhang | 6b72d29 | 2019-07-12 20:52:42 | [diff] [blame] | 315 | #include "mojo/public/cpp/bindings/pending_associated_receiver.h" |
Ken Rockot | 40a1df79 | 2019-05-08 22:15:52 | [diff] [blame] | 316 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
| 317 | #include "mojo/public/cpp/bindings/pending_remote.h" |
Ken Rockot | 0adc1e4 | 2019-05-24 08:20:08 | [diff] [blame] | 318 | #include "mojo/public/cpp/bindings/remote.h" |
engedy | afef048 | 2017-07-06 15:40:53 | [diff] [blame] | 319 | #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
Bence Béky | 6b44abf | 2018-04-11 10:32:51 | [diff] [blame] | 320 | #include "net/base/load_flags.h" |
[email protected] | 3b45550 | 2012-12-11 18:22:58 | [diff] [blame] | 321 | #include "net/base/mime_util.h" |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 322 | #include "net/http/http_util.h" |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 323 | #include "net/ssl/client_cert_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 324 | #include "net/ssl/ssl_cert_request_info.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 325 | #include "ppapi/buildflags/buildflags.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 326 | #include "ppapi/host/ppapi_host.h" |
Scott Violet | 318a55f | 2018-03-30 19:08:19 | [diff] [blame] | 327 | #include "printing/buildflags/buildflags.h" |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 328 | #include "services/network/public/cpp/is_potentially_trustworthy.h" |
Lukasz Anforowicz | 9527fd4 | 2019-03-13 19:08:50 | [diff] [blame] | 329 | #include "services/network/public/cpp/network_switches.h" |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 330 | #include "services/network/public/cpp/resource_request.h" |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 331 | #include "services/service_manager/embedder/switches.h" |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 332 | #include "services/service_manager/sandbox/sandbox_type.h" |
Andrew Comminos | 6605767 | 2019-05-01 00:03:34 | [diff] [blame] | 333 | #include "services/service_manager/sandbox/switches.h" |
Ken Rockot | cebdf9c8 | 2019-05-28 20:33:03 | [diff] [blame] | 334 | #include "services/strings/grit/services_strings.h" |
pilgrim | e92c5fcd | 2014-09-10 23:31:23 | [diff] [blame] | 335 | #include "storage/browser/fileapi/external_mount_points.h" |
John Delaney | ac24e57 | 2019-04-30 19:47:02 | [diff] [blame] | 336 | #include "third_party/blink/public/common/features.h" |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 337 | #include "third_party/blink/public/common/loader/url_loader_throttle.h" |
Julie Jeongeun Kim | d3d00a1 | 2019-03-25 01:46:25 | [diff] [blame] | 338 | #include "third_party/blink/public/mojom/installedapp/installed_app_provider.mojom.h" |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 339 | #include "third_party/blink/public/mojom/renderer_preferences.mojom.h" |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 340 | #include "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom.h" |
Eric Willigers | 3eeae17c | 2019-03-13 17:32:10 | [diff] [blame] | 341 | #include "third_party/blink/public/mojom/webshare/webshare.mojom.h" |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 342 | #include "third_party/skia/include/core/SkColor.h" |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 343 | #include "third_party/widevine/cdm/buildflags.h" |
Scott Violet | b72577d | 2019-01-09 22:18:18 | [diff] [blame] | 344 | #include "ui/base/buildflags.h" |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 345 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 346 | #include "ui/base/resource/resource_bundle.h" |
Scott Violet | 8ff9c30 | 2018-02-22 22:28:35 | [diff] [blame] | 347 | #include "ui/base/ui_base_features.h" |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 348 | #include "ui/base/ui_base_switches.h" |
| 349 | #include "ui/gfx/color_utils.h" |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 350 | #include "ui/native_theme/caption_style.h" |
| 351 | #include "ui/native_theme/native_theme.h" |
[email protected] | b47dc49 | 2014-08-17 07:05:57 | [diff] [blame] | 352 | #include "ui/resources/grit/ui_resources.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 353 | #include "url/gurl.h" |
| 354 | #include "url/origin.h" |
[email protected] | d977f9c | 2011-03-14 16:10:26 | [diff] [blame] | 355 | |
Ken Rockot | 69aade0 | 2019-01-23 21:19:51 | [diff] [blame] | 356 | #if BUILDFLAG(ENABLE_NACL) |
| 357 | #include "components/nacl/loader/nacl_loader_manifest.h" |
| 358 | #if defined(OS_WIN) && defined(ARCH_CPU_X86) |
| 359 | #include "components/nacl/broker/nacl_broker_manifest.h" |
| 360 | #endif |
| 361 | #endif |
| 362 | |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 363 | #if defined(OS_WIN) |
wfh | c91e967 | 2016-01-27 00:14:20 | [diff] [blame] | 364 | #include "base/strings/string_tokenizer.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 365 | #include "chrome/browser/chrome_browser_main_win.h" |
Patrick Monette | bb54394 | 2019-05-17 17:45:32 | [diff] [blame] | 366 | #include "chrome/browser/win/conflicts/module_database.h" |
| 367 | #include "chrome/browser/win/conflicts/module_event_sink_impl.h" |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 368 | #include "chrome/install_static/install_util.h" |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 369 | #include "sandbox/win/src/sandbox_policy.h" |
[email protected] | 199fc7a | 2011-09-28 22:45:38 | [diff] [blame] | 370 | #elif defined(OS_MACOSX) |
| 371 | #include "chrome/browser/chrome_browser_main_mac.h" |
Guido Urdaneta | 1a291743 | 2018-05-10 18:32:32 | [diff] [blame] | 372 | #include "services/audio/public/mojom/constants.mojom.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 373 | #elif defined(OS_CHROMEOS) |
Xiyuan Xia | fc9f3813 | 2019-08-02 00:51:42 | [diff] [blame] | 374 | #include "ash/public/cpp/tablet_mode.h" |
Miyoung Shin | 7e1b1b1 | 2019-08-02 12:23:50 | [diff] [blame] | 375 | #include "ash/public/mojom/constants.mojom.h" |
Joshua Peraza | 30d8fc7 | 2019-08-19 17:24:30 | [diff] [blame] | 376 | #include "chrome/app/chrome_crash_reporter_client.h" |
Scott Violet | 47f00e5 | 2018-05-04 22:50:31 | [diff] [blame] | 377 | #include "chrome/browser/ash_service_registry.h" |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 378 | #include "chrome/browser/chromeos/arc/fileapi/arc_content_file_system_backend_delegate.h" |
nya | f5df1e3 | 2016-12-14 04:36:17 | [diff] [blame] | 379 | #include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_backend_delegate.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 380 | #include "chrome/browser/chromeos/chrome_browser_main_chromeos.h" |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 381 | #include "chrome/browser/chromeos/chrome_content_browser_client_chromeos_part.h" |
Sam McNally | d8b7d82 | 2018-08-21 03:18:18 | [diff] [blame] | 382 | #include "chrome/browser/chromeos/drive/fileapi/drivefs_file_system_backend_delegate.h" |
[email protected] | 07fe275 | 2014-01-29 11:21:55 | [diff] [blame] | 383 | #include "chrome/browser/chromeos/drive/fileapi/file_system_backend_delegate.h" |
[email protected] | 5bc61cad | 2014-07-08 05:05:08 | [diff] [blame] | 384 | #include "chrome/browser/chromeos/file_manager/app_id.h" |
[email protected] | 43420a1 | 2014-04-21 03:20:48 | [diff] [blame] | 385 | #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h" |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 386 | #include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h" |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 387 | #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 388 | #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h" |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 389 | #include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h" |
| 390 | #include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h" |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 391 | #include "chrome/browser/chromeos/login/signin_partition_manager.h" |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 392 | #include "chrome/browser/chromeos/login/startup_utils.h" |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 393 | #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 394 | #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 395 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
[email protected] | c94ac69 | 2013-07-27 00:50:10 | [diff] [blame] | 396 | #include "chrome/browser/chromeos/system/input_device_settings.h" |
Katie D | b2d0709 | 2018-12-04 18:59:36 | [diff] [blame] | 397 | #include "chrome/browser/speech/tts_chromeos.h" |
Steven Bennetts | 81d07be | 2018-01-08 20:45:27 | [diff] [blame] | 398 | #include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h" |
djacobo | 21e56e0 | 2016-07-02 01:14:31 | [diff] [blame] | 399 | #include "chrome/browser/ui/browser_dialogs.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 400 | #include "chromeos/constants/chromeos_constants.h" |
Kyle Horimoto | 1d6a679f | 2019-04-16 23:24:21 | [diff] [blame] | 401 | #include "chromeos/constants/chromeos_features.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 402 | #include "chromeos/constants/chromeos_switches.h" |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 403 | #include "components/crash/content/app/breakpad_linux.h" |
John Abd-El-Malek | 35bfaa5 | 2019-08-20 16:22:07 | [diff] [blame] | 404 | #include "components/user_manager/user.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 405 | #include "components/user_manager/user_manager.h" |
Ken Rockot | 543f5e3 | 2018-02-04 02:13:50 | [diff] [blame] | 406 | #include "services/service_manager/public/mojom/interface_provider_spec.mojom.h" |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 407 | #elif defined(OS_LINUX) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 408 | #include "chrome/browser/chrome_browser_main_linux.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 409 | #elif defined(OS_ANDROID) |
Bo Liu | 4ade6b1b2 | 2017-11-28 02:26:35 | [diff] [blame] | 410 | #include "base/android/application_status_listener.h" |
zqzhang | 93e959d1 | 2017-03-16 13:10:20 | [diff] [blame] | 411 | #include "chrome/browser/android/app_hooks.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 412 | #include "chrome/browser/android/chrome_context_util.h" |
| 413 | #include "chrome/browser/android/devtools_manager_delegate_android.h" |
Dan Harrington | 964d48c | 2018-08-03 15:52:24 | [diff] [blame] | 414 | #include "chrome/browser/android/download/available_offline_content_provider.h" |
Min Qin | 0ab0e16 | 2017-11-14 21:57:19 | [diff] [blame] | 415 | #include "chrome/browser/android/download/intercept_oma_download_navigation_throttle.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 416 | #include "chrome/browser/android/ntp/new_tab_page_url_handler.h" |
| 417 | #include "chrome/browser/android/service_tab_launcher.h" |
| 418 | #include "chrome/browser/android/tab_android.h" |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 419 | #include "chrome/browser/android/tab_web_contents_delegate_android.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 420 | #include "chrome/browser/chrome_browser_main_android.h" |
Dan Harrington | 954c882 | 2019-01-09 18:40:48 | [diff] [blame] | 421 | #include "chrome/browser/offline_pages/android/offline_page_auto_fetcher.h" |
Jinsuk Kim | 6f9253c | 2019-03-11 02:45:07 | [diff] [blame] | 422 | #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
James Cook | 01e3e5ef | 2019-04-09 14:44:38 | [diff] [blame] | 423 | #include "chrome/common/chrome_descriptors.h" |
Joshua Peraza | 934e559 | 2018-07-18 23:43:11 | [diff] [blame] | 424 | #include "components/crash/content/browser/child_exit_observer_android.h" |
Yuzu Saijo | 2d12ef9 | 2018-08-21 04:52:07 | [diff] [blame] | 425 | #include "components/crash/content/browser/crash_memory_metrics_collector_android.h" |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 426 | #include "components/navigation_interception/intercept_navigation_delegate.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 427 | #include "content/public/browser/android/java_interfaces.h" |
mfomitchev | 220b856 | 2017-07-13 23:08:54 | [diff] [blame] | 428 | #include "services/service_manager/public/cpp/interface_provider.h" |
Han Leon | abbe7c90 | 2018-08-30 02:08:10 | [diff] [blame] | 429 | #include "third_party/blink/public/mojom/payments/payment_request.mojom.h" |
Julie Jeongeun Kim | b6a0a1f | 2019-03-21 05:08:26 | [diff] [blame] | 430 | #include "third_party/blink/public/mojom/webauthn/authenticator.mojom.h" |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 431 | #include "ui/base/resource/resource_bundle_android.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 432 | #include "ui/base/ui_base_paths.h" |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 433 | #elif defined(OS_POSIX) |
| 434 | #include "chrome/browser/chrome_browser_main_posix.h" |
| 435 | #endif |
| 436 | |
tmartino | fb34188 | 2017-02-10 19:36:53 | [diff] [blame] | 437 | #if !defined(OS_ANDROID) |
Jay Harris | 1ddcffa | 2019-07-09 03:07:40 | [diff] [blame] | 438 | #include "chrome/browser/badging/badge_manager.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 439 | #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 440 | #include "chrome/browser/devtools/devtools_window.h" |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 441 | #include "chrome/browser/media/unified_autoplay_config.h" |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 442 | #include "chrome/browser/payments/payment_request_factory.h" |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 443 | #include "chrome/browser/search/instant_service.h" |
| 444 | #include "chrome/browser/search/instant_service_factory.h" |
Reilly Grant | 2814fb7 | 2019-03-19 17:04:46 | [diff] [blame] | 445 | #include "chrome/browser/serial/chrome_serial_delegate.h" |
Collin Baker | 8a21755 | 2019-05-29 19:47:51 | [diff] [blame] | 446 | #include "chrome/browser/ui/browser.h" |
| 447 | #include "chrome/browser/ui/browser_finder.h" |
| 448 | #include "chrome/browser/ui/browser_list.h" |
| 449 | #include "chrome/browser/ui/browser_window.h" |
jdoerrie | 4f9376f | 2018-12-12 18:26:20 | [diff] [blame] | 450 | #include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h" |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 451 | #include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h" |
Nina Satragno | 8c832df | 2019-07-29 15:59:39 | [diff] [blame] | 452 | #include "chrome/browser/webauthn/authenticator_request_scheduler.h" |
| 453 | #include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h" |
Jay Civelli | 4d53be9b | 2017-08-31 22:01:43 | [diff] [blame] | 454 | #include "chrome/common/importer/profile_import.mojom.h" |
Austin Orion | e250d01 | 2019-05-29 02:56:27 | [diff] [blame] | 455 | #include "chrome/grit/chrome_unscaled_resources.h" |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 456 | #endif // !defined(OS_ANDROID) |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 457 | |
Nicolas Ouellet-Payeur | bdcab009 | 2018-10-22 14:50:33 | [diff] [blame] | 458 | #if defined(OS_WIN) || defined(OS_MACOSX) || \ |
| 459 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
Nicolas Ouellet-Payeur | 4b840a9 | 2018-09-18 14:46:52 | [diff] [blame] | 460 | #include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h" |
| 461 | #endif |
| 462 | |
[email protected] | a220b593 | 2013-09-21 03:47:44 | [diff] [blame] | 463 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 464 | #if !defined(OS_ANDROID) |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 465 | #include "base/debug/leak_annotations.h" |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 466 | #include "components/crash/content/app/breakpad_linux.h" |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 467 | #endif // !defined(OS_ANDROID) |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 468 | #include "components/crash/content/browser/crash_handler_host_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 469 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 470 | |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 471 | // TODO(crbug.com/939205): Once the upcoming App Service is available, use a |
| 472 | // single navigation throttle to display the intent picker on all platforms. |
| 473 | #if !defined(OS_ANDROID) |
| 474 | #if defined(OS_CHROMEOS) |
| 475 | #include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h" |
| 476 | #else |
| 477 | #include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h" |
| 478 | #endif |
| 479 | #endif |
| 480 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 481 | #if defined(TOOLKIT_VIEWS) |
| 482 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h" |
| 483 | #endif |
| 484 | |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 485 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 486 | #if defined(USE_X11) |
| 487 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux_x11.h" |
| 488 | #else |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 489 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h" |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 490 | #endif // USE_X11 |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 491 | #endif |
| 492 | |
Mohsen Izadi | f1958f2 | 2019-01-18 20:29:31 | [diff] [blame] | 493 | #if defined(USE_OZONE) |
| 494 | #include "ui/ozone/public/ozone_platform.h" |
| 495 | #endif |
| 496 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 497 | #if defined(USE_X11) |
| 498 | #include "chrome/browser/chrome_browser_main_extra_parts_x11.h" |
| 499 | #endif |
| 500 | |
brettw | ab78fef | 2016-10-12 02:56:05 | [diff] [blame] | 501 | #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
[email protected] | 7a2a6d80 | 2014-06-06 13:39:19 | [diff] [blame] | 502 | #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 503 | #endif |
| 504 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 505 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 506 | #include "components/nacl/browser/nacl_browser.h" |
| 507 | #include "components/nacl/browser/nacl_host_message_filter.h" |
| 508 | #include "components/nacl/browser/nacl_process_host.h" |
| 509 | #include "components/nacl/common/nacl_process_type.h" |
| 510 | #include "components/nacl/common/nacl_switches.h" |
| 511 | #endif |
| 512 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 513 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 514 | #include "chrome/browser/accessibility/animation_policy_prefs.h" |
Dominick Ng | 6ff5105 | 2018-07-06 05:30:20 | [diff] [blame] | 515 | #include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h" |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 516 | #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 517 | #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
Pavol Marko | 41c37b1 | 2019-08-07 10:56:32 | [diff] [blame] | 518 | #include "chrome/browser/extensions/extension_util.h" |
Clark DuVall | 2cf99249e | 2018-09-19 19:11:51 | [diff] [blame] | 519 | #include "chrome/browser/extensions/user_script_listener.h" |
| 520 | #include "chrome/browser/media/cast_transport_host_filter.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 521 | #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" |
Eric Willigers | 007ef30 | 2019-08-29 09:58:46 | [diff] [blame^] | 522 | #include "chrome/browser/ui/web_applications/app_browser_controller.h" |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 523 | #include "components/guest_view/browser/guest_view_base.h" |
| 524 | #include "components/guest_view/browser/guest_view_manager.h" |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 525 | #include "extensions/browser/api/web_request/web_request_api.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 526 | #include "extensions/browser/extension_host.h" |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 527 | #include "extensions/browser/extension_navigation_throttle.h" |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 528 | #include "extensions/browser/extension_protocols.h" |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 529 | #include "extensions/browser/extension_registry.h" |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 530 | #include "extensions/browser/extension_system.h" |
hanxi | 0d0a1e9 | 2014-08-26 18:39:48 | [diff] [blame] | 531 | #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 532 | #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
| 533 | #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 534 | #include "extensions/browser/process_manager.h" |
Dan Beam | 836c02a | 2019-06-15 01:58:27 | [diff] [blame] | 535 | #include "extensions/common/constants.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 536 | #include "extensions/common/extension.h" |
| 537 | #include "extensions/common/extension_set.h" |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 538 | #include "extensions/common/manifest_handlers/background_info.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 539 | #include "extensions/common/manifest_handlers/shared_module_info.h" |
Clark DuVall | bf7722f | 2018-08-03 18:03:33 | [diff] [blame] | 540 | #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 541 | #include "extensions/common/permissions/permissions_data.h" |
| 542 | #include "extensions/common/permissions/socket_permission.h" |
| 543 | #include "extensions/common/switches.h" |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 544 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
merkin | db10455e | 2017-02-28 13:16:25 | [diff] [blame] | 545 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 546 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 547 | #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h" |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 548 | #include "chrome/browser/plugins/flash_download_interception.h" |
John Abd-El-Malek | ecc6f5f | 2018-03-02 18:47:39 | [diff] [blame] | 549 | #include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h" |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 550 | #endif |
| 551 | |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 552 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 553 | #include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h" |
| 554 | #endif |
| 555 | |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 556 | #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 557 | #include "chrome/browser/media/cast_remoting_connector.h" |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 558 | #endif |
| 559 | |
weili | fabbf757 | 2017-05-22 19:05:16 | [diff] [blame] | 560 | #if BUILDFLAG(ENABLE_PRINTING) |
Lei Zhang | a2fa14c | 2018-05-15 00:05:21 | [diff] [blame] | 561 | #include "chrome/browser/printing/printing_message_filter.h" |
weili | fabbf757 | 2017-05-22 19:05:16 | [diff] [blame] | 562 | #endif |
Lei Zhang | a2fa14c | 2018-05-15 00:05:21 | [diff] [blame] | 563 | |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 564 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c86d76e4 | 2016-03-14 23:38:49 | [diff] [blame] | 565 | #include "chrome/browser/media/output_protection_impl.h" |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 566 | #include "chrome/browser/media/platform_verification_impl.h" |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 567 | #if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 568 | #include "chrome/browser/media/widevine_hardware_caps_win.h" |
| 569 | #include "third_party/widevine/cdm/widevine_cdm_common.h" |
| 570 | #endif |
| 571 | #endif |
| 572 | |
xhwang | db24d60 | 2017-05-20 06:32:24 | [diff] [blame] | 573 | #if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID) |
xhwang | 116acb9 | 2017-04-03 18:27:20 | [diff] [blame] | 574 | #include "chrome/browser/media/android/cdm/media_drm_storage_factory.h" |
| 575 | #endif |
xhwang | c86d76e4 | 2016-03-14 23:38:49 | [diff] [blame] | 576 | |
xhwang | db24d60 | 2017-05-20 06:32:24 | [diff] [blame] | 577 | #if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 578 | #include "media/mojo/mojom/constants.mojom.h" // nogncheck |
xhwang | b1d65fd | 2016-10-19 20:55:52 | [diff] [blame] | 579 | #include "media/mojo/services/media_service_factory.h" // nogncheck |
alokp | 6ecb238 | 2016-01-27 00:40:00 | [diff] [blame] | 580 | #endif |
| 581 | |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 582 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 583 | #include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h" |
| 584 | #endif |
| 585 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 586 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
Daniel Rubery | a1611e3 | 2019-04-24 21:38:35 | [diff] [blame] | 587 | #include "chrome/browser/safe_browsing/chrome_password_protection_service.h" |
| 588 | #endif |
| 589 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 590 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 591 | #include "chrome/browser/offline_pages/offline_page_tab_helper.h" |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 592 | #include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h" |
| 593 | #endif |
| 594 | |
Will Cassella | 40837ba | 2019-07-01 21:32:00 | [diff] [blame] | 595 | #if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID) |
Bill Orr | eb42922 | 2018-08-08 21:14:43 | [diff] [blame] | 596 | #include "device/vr/public/mojom/isolated_xr_service.mojom.h" |
| 597 | #endif |
| 598 | |
Ken Rockot | c185b2a | 2019-08-01 22:19:48 | [diff] [blame] | 599 | #if BUILDFLAG(ENABLE_SPELLCHECK) |
| 600 | #include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h" |
| 601 | #include "components/spellcheck/common/spellcheck.mojom.h" |
| 602 | #if BUILDFLAG(HAS_SPELLCHECK_PANEL) |
| 603 | #include "chrome/browser/spellchecker/spell_check_panel_host_impl.h" |
| 604 | #endif |
| 605 | #endif |
| 606 | |
Michael Thiessen | 909ba03 | 2019-03-26 23:47:43 | [diff] [blame] | 607 | #if defined(BROWSER_MEDIA_CONTROLS_MENU) |
| 608 | #include "third_party/blink/public/mojom/media_controls/touchless/media_controls.mojom.h" |
| 609 | #endif |
| 610 | |
Michael Thiessen | 07c444c | 2019-04-26 03:53:11 | [diff] [blame] | 611 | #if defined(ENABLE_SPATIAL_NAVIGATION_HOST) |
| 612 | #include "third_party/blink/public/mojom/page/spatial_navigation.mojom.h" |
| 613 | #endif |
| 614 | |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 615 | using base::FileDescriptor; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 616 | using content::BrowserThread; |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 617 | using content::BrowserURLHandler; |
msramek | a3c7cfd | 2017-02-03 13:34:13 | [diff] [blame] | 618 | using content::BrowsingDataFilterBuilder; |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 619 | using content::ChildProcessSecurityPolicy; |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 620 | using content::QuotaPermissionContext; |
[email protected] | 2626d14 | 2014-04-22 17:24:02 | [diff] [blame] | 621 | using content::RenderFrameHost; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 622 | using content::RenderViewHost; |
[email protected] | 7491ad0 | 2014-07-05 19:10:07 | [diff] [blame] | 623 | using content::ResourceType; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 624 | using content::SiteInstance; |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 625 | using content::WebContents; |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 626 | using content::WebPreferences; |
[email protected] | 593d2a7 | 2013-07-26 08:48:38 | [diff] [blame] | 627 | using message_center::NotifierId; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 628 | |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 629 | #if defined(OS_POSIX) |
brettw | 3c98c7d3 | 2017-07-25 01:44:20 | [diff] [blame] | 630 | using content::PosixFileDescriptorInfo; |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 631 | #endif |
| 632 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 633 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 634 | using extensions::APIPermission; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 635 | using extensions::ChromeContentBrowserClientExtensionsPart; |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 636 | using extensions::Extension; |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 637 | using extensions::Manifest; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 638 | #endif |
| 639 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 640 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 641 | using plugins::ChromeContentBrowserClientPluginsPart; |
| 642 | #endif |
| 643 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 644 | namespace { |
| 645 | |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 646 | const storage::QuotaSettings* g_default_quota_settings; |
| 647 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 648 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 649 | // TODO(teravest): Add renderer-side API-specific checking for these APIs so |
| 650 | // that blanket permission isn't granted to all dev channel APIs for these. |
| 651 | // http://crbug.com/386743 |
| 652 | const char* const kPredefinedAllowedDevChannelOrigins[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 653 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937 |
| 654 | "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937 |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 655 | }; |
| 656 | |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 657 | const char* const kPredefinedAllowedFileHandleOrigins[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 658 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789 |
| 659 | "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789 |
[email protected] | 10c3922 | 2013-11-13 20:09:25 | [diff] [blame] | 660 | }; |
| 661 | |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 662 | const char* const kPredefinedAllowedSocketOrigins[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 663 | "okddffdblfhhnmhodogpojmfkjmhinfp", // Secure Shell App (dev) |
| 664 | "pnhechapfaindjhompbnflcldabbghjo", // Secure Shell App (stable) |
| 665 | "algkcnfjnajfhgimadimbjhmpaeohhln", // Secure Shell Extension (dev) |
| 666 | "iodihamcpbpeioajjeobimgagajmlibd", // Secure Shell Extension (stable) |
| 667 | "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126 |
| 668 | "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop |
| 669 | "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop |
| 670 | "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop |
| 671 | "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary |
| 672 | "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 |
| 673 | "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 |
| 674 | "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099 |
| 675 | "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099 |
| 676 | "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099 |
| 677 | "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099 |
| 678 | "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099 |
| 679 | "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514 |
| 680 | "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080 |
| 681 | "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080 |
| 682 | "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084 |
| 683 | "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084 |
| 684 | "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084 |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 685 | }; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 686 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 687 | |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 688 | #if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 689 | // Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when |
| 690 | // running on Windows 10 1511 and above. See |
| 691 | // https://blogs.windows.com/blog/tag/code-integrity-guard/. |
| 692 | const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity", |
Will Harris | 6dd1f84 | 2019-08-05 21:01:33 | [diff] [blame] | 693 | base::FEATURE_ENABLED_BY_DEFAULT}; |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 694 | #endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) && |
| 695 | // !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 696 | |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 697 | enum AppLoadedInTabSource { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 698 | // 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] | 699 | APP_LOADED_IN_TAB_SOURCE_APP = 0, |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 700 | |
| 701 | // 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] | 702 | APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE, |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 703 | |
| 704 | // An extension or app tried to load a resource of a different platform app in |
| 705 | // a tab. |
| 706 | APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION, |
| 707 | |
| 708 | // A non-app and non-extension page tried to load a platform app in a tab. |
| 709 | APP_LOADED_IN_TAB_SOURCE_OTHER, |
| 710 | |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 711 | APP_LOADED_IN_TAB_SOURCE_MAX |
| 712 | }; |
| 713 | |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 714 | // Cached version of the locale so we can return the locale on the I/O |
| 715 | // thread. |
| 716 | std::string& GetIOThreadApplicationLocale() { |
| 717 | static base::NoDestructor<std::string> s; |
| 718 | return *s; |
| 719 | } |
| 720 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 721 | // Returns a copy of the given url with its host set to given host and path set |
| 722 | // to given path. Other parts of the url will be the same. |
| 723 | GURL ReplaceURLHostAndPath(const GURL& url, |
| 724 | const std::string& host, |
| 725 | const std::string& path) { |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 726 | url::Replacements<char> replacements; |
| 727 | replacements.SetHost(host.c_str(), url::Component(0, host.length())); |
| 728 | replacements.SetPath(path.c_str(), url::Component(0, path.length())); |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 729 | return url.ReplaceComponents(replacements); |
| 730 | } |
| 731 | |
mad | fbd1085 | 2017-01-20 03:15:33 | [diff] [blame] | 732 | // Handles the rewriting of the new tab page URL based on group policy. |
| 733 | bool HandleNewTabPageLocationOverride( |
| 734 | GURL* url, |
| 735 | content::BrowserContext* browser_context) { |
| 736 | if (!url->SchemeIs(content::kChromeUIScheme) || |
| 737 | url->host() != chrome::kChromeUINewTabHost) |
| 738 | return false; |
| 739 | |
| 740 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 741 | std::string ntp_location = |
| 742 | profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride); |
| 743 | if (ntp_location.empty()) |
| 744 | return false; |
| 745 | |
| 746 | *url = GURL(ntp_location); |
| 747 | return true; |
| 748 | } |
| 749 | |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 750 | #if !defined(OS_ANDROID) |
| 751 | // Check if the current url is whitelisted based on a list of whitelisted urls. |
| 752 | bool IsURLWhitelisted(const GURL& current_url, |
| 753 | const base::Value::ListStorage& whitelisted_urls) { |
| 754 | // Only check on HTTP and HTTPS pages. |
| 755 | if (!current_url.SchemeIsHTTPOrHTTPS()) |
| 756 | return false; |
| 757 | |
| 758 | for (auto const& value : whitelisted_urls) { |
| 759 | ContentSettingsPattern pattern = |
| 760 | ContentSettingsPattern::FromString(value.GetString()); |
| 761 | if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid()) |
| 762 | continue; |
| 763 | if (pattern.Matches(current_url)) |
| 764 | return true; |
| 765 | } |
| 766 | |
| 767 | return false; |
| 768 | } |
| 769 | |
| 770 | // Check if autoplay is allowed by policy configuration. |
| 771 | bool IsAutoplayAllowedByPolicy(content::WebContents* contents, |
| 772 | PrefService* prefs) { |
| 773 | DCHECK(prefs); |
| 774 | |
| 775 | // Check if we have globally allowed autoplay by policy. |
| 776 | if (prefs->GetBoolean(prefs::kAutoplayAllowed) && |
| 777 | prefs->IsManagedPreference(prefs::kAutoplayAllowed)) { |
| 778 | return true; |
| 779 | } |
| 780 | |
| 781 | if (!contents) |
| 782 | return false; |
| 783 | |
| 784 | // Check if the current URL matches a URL pattern on the whitelist. |
| 785 | const base::ListValue* autoplay_whitelist = |
| 786 | prefs->GetList(prefs::kAutoplayWhitelist); |
| 787 | return autoplay_whitelist && |
| 788 | prefs->IsManagedPreference(prefs::kAutoplayWhitelist) && |
| 789 | IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList()); |
| 790 | } |
| 791 | #endif |
| 792 | |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 793 | #if defined(OS_ANDROID) |
| 794 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
| 795 | return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket(); |
| 796 | } |
| 797 | #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 798 | breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( |
| 799 | const std::string& process_type) { |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 800 | base::FilePath dumps_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 801 | base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 802 | { |
| 803 | ANNOTATE_SCOPED_MEMORY_LEAK; |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 804 | bool upload = !getenv(env_vars::kHeadless); |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 805 | breakpad::CrashHandlerHostLinux* crash_handler = |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 806 | new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 807 | crash_handler->StartUploaderThread(); |
| 808 | return crash_handler; |
| 809 | } |
| 810 | } |
| 811 | |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 812 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 813 | // Extensions have the same process type as renderers. |
[email protected] | cd0f7af | 2014-01-16 23:50:39 | [diff] [blame] | 814 | if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 815 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 816 | if (!crash_handler) |
| 817 | crash_handler = CreateCrashHandlerHost("extension"); |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 818 | return crash_handler->GetDeathSignalSocket(); |
| 819 | } |
| 820 | |
| 821 | std::string process_type = |
| 822 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 823 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 824 | if (process_type == switches::kRendererProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 825 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 826 | if (!crash_handler) |
| 827 | crash_handler = CreateCrashHandlerHost(process_type); |
| 828 | return crash_handler->GetDeathSignalSocket(); |
| 829 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 830 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 831 | if (process_type == switches::kPpapiPluginProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 832 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 833 | if (!crash_handler) |
| 834 | crash_handler = CreateCrashHandlerHost(process_type); |
| 835 | return crash_handler->GetDeathSignalSocket(); |
| 836 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 837 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 838 | if (process_type == switches::kGpuProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 839 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 840 | if (!crash_handler) |
| 841 | crash_handler = CreateCrashHandlerHost(process_type); |
| 842 | return crash_handler->GetDeathSignalSocket(); |
| 843 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 844 | |
James Cook | 9207cc1 | 2017-10-19 17:08:39 | [diff] [blame] | 845 | if (process_type == switches::kUtilityProcess) { |
| 846 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
| 847 | if (!crash_handler) |
| 848 | crash_handler = CreateCrashHandlerHost(process_type); |
| 849 | return crash_handler->GetDeathSignalSocket(); |
| 850 | } |
| 851 | |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 852 | return -1; |
| 853 | } |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 854 | #endif // defined(OS_ANDROID) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 855 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 856 | void SetApplicationLocaleOnIOThread(const std::string& locale) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 857 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 858 | GetIOThreadApplicationLocale() = locale; |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 859 | } |
| 860 | |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 861 | // An implementation of the SSLCertReporter interface used by |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 862 | // SSLErrorHandler. Uses CertificateReportingService to send reports. The |
| 863 | // service handles queueing and re-sending of failed reports. Each certificate |
| 864 | // error creates a new instance of this class. |
| 865 | class CertificateReportingServiceCertReporter : public SSLCertReporter { |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 866 | public: |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 867 | explicit CertificateReportingServiceCertReporter( |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 868 | content::WebContents* web_contents) |
| 869 | : service_(CertificateReportingServiceFactory::GetForBrowserContext( |
| 870 | web_contents->GetBrowserContext())) {} |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 871 | ~CertificateReportingServiceCertReporter() override {} |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 872 | |
| 873 | // SSLCertReporter implementation |
estark | 4282f117 | 2015-05-13 22:01:55 | [diff] [blame] | 874 | void ReportInvalidCertificateChain( |
| 875 | const std::string& serialized_report) override { |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 876 | service_->Send(serialized_report); |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | private: |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 880 | CertificateReportingService* service_; |
| 881 | |
| 882 | DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter); |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 883 | }; |
| 884 | |
bshe | 4f53ce4 | 2015-11-30 16:56:31 | [diff] [blame] | 885 | #if defined(OS_ANDROID) |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 886 | float GetDeviceScaleAdjustment() { |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 887 | static const float kMinFSM = 1.05f; |
| 888 | static const int kWidthForMinFSM = 320; |
| 889 | static const float kMaxFSM = 1.3f; |
| 890 | static const int kWidthForMaxFSM = 800; |
| 891 | |
boliu | 21c5afa | 2017-01-11 19:34:23 | [diff] [blame] | 892 | int minWidth = chrome::android::ChromeContextUtil::GetSmallestDIPWidth(); |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 893 | |
| 894 | if (minWidth <= kWidthForMinFSM) |
| 895 | return kMinFSM; |
| 896 | if (minWidth >= kWidthForMaxFSM) |
| 897 | return kMaxFSM; |
| 898 | |
| 899 | // The font scale multiplier varies linearly between kMinFSM and kMaxFSM. |
| 900 | float ratio = static_cast<float>(minWidth - kWidthForMinFSM) / |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 901 | (kWidthForMaxFSM - kWidthForMinFSM); |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 902 | return ratio * (kMaxFSM - kMinFSM) + kMinFSM; |
| 903 | } |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 904 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 905 | #endif // defined(OS_ANDROID) |
| 906 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 907 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 908 | |
| 909 | AppLoadedInTabSource ClassifyAppLoadedInTabSource( |
| 910 | const GURL& opener_url, |
| 911 | const extensions::Extension* target_platform_app) { |
| 912 | if (opener_url.SchemeIs(extensions::kExtensionScheme)) { |
| 913 | if (opener_url.host_piece() == target_platform_app->id()) { |
| 914 | // This platform app was trying to window.open() one of its own URLs. |
| 915 | if (opener_url == |
| 916 | extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) { |
| 917 | // Source was the background page. |
| 918 | return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE; |
| 919 | } else { |
| 920 | // Source was a different page inside the app. |
| 921 | return APP_LOADED_IN_TAB_SOURCE_APP; |
| 922 | } |
| 923 | } |
| 924 | // The forbidden app URL was being opened by a different app or extension. |
| 925 | return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION; |
| 926 | } |
| 927 | // The forbidden app URL was being opened by a non-extension page (e.g. http). |
| 928 | return APP_LOADED_IN_TAB_SOURCE_OTHER; |
| 929 | } |
[email protected] | 9c765638 | 2014-08-08 21:02:30 | [diff] [blame] | 930 | |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 931 | // Returns true if there is is an extension matching |url| in |
| 932 | // |opener_render_process_id| with APIPermission::kBackground. |
| 933 | // |
| 934 | // Note that GetExtensionOrAppByURL requires a full URL in order to match with a |
| 935 | // hosted app, even though normal extensions just use the host. |
| 936 | bool URLHasExtensionBackgroundPermission( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 937 | extensions::ProcessMap* process_map, |
| 938 | extensions::ExtensionRegistry* registry, |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 939 | const GURL& url, |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 940 | int opener_render_process_id) { |
| 941 | // Note: includes web URLs that are part of an extension's web extent. |
| 942 | const Extension* extension = |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 943 | registry->enabled_extensions().GetExtensionOrAppByURL(url); |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 944 | return extension && |
| 945 | extension->permissions_data()->HasAPIPermission( |
| 946 | APIPermission::kBackground) && |
| 947 | process_map->Contains(extension->id(), opener_render_process_id); |
| 948 | } |
Kevin Marshall | 32f99d7e | 2017-07-11 23:17:46 | [diff] [blame] | 949 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 950 | #endif |
| 951 | |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 952 | chrome::mojom::PrerenderCanceler* GetPrerenderCanceller( |
| 953 | const base::Callback<content::WebContents*()>& wc_getter) { |
| 954 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 955 | auto* web_contents = wc_getter.Run(); |
| 956 | if (!web_contents) |
| 957 | return nullptr; |
| 958 | |
| 959 | return prerender::PrerenderContents::FromWebContents(web_contents); |
| 960 | } |
| 961 | |
John Abd-El-Malek | 92bf360 | 2019-07-31 02:25:48 | [diff] [blame] | 962 | void LaunchURL(const GURL& url, |
| 963 | const content::WebContents::Getter& web_contents_getter, |
| 964 | ui::PageTransition page_transition, |
| 965 | bool has_user_gesture) { |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 966 | // If there is no longer a WebContents, the request may have raced with tab |
| 967 | // closing. Don't fire the external request. (It may have been a prerender.) |
| 968 | content::WebContents* web_contents = web_contents_getter.Run(); |
| 969 | if (!web_contents) |
| 970 | return; |
| 971 | |
| 972 | // Do not launch external requests attached to unswapped prerenders. |
| 973 | prerender::PrerenderContents* prerender_contents = |
| 974 | prerender::PrerenderContents::FromWebContents(web_contents); |
| 975 | if (prerender_contents) { |
| 976 | prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); |
| 977 | prerender::ReportPrerenderExternalURL(); |
| 978 | return; |
| 979 | } |
| 980 | |
Robbie McElrath | 1294d24 | 2019-05-31 20:46:22 | [diff] [blame] | 981 | // Do not launch external requests for schemes that have a handler registered. |
| 982 | ProtocolHandlerRegistry* protocol_handler_registry = |
| 983 | ProtocolHandlerRegistryFactory::GetForBrowserContext( |
| 984 | web_contents->GetBrowserContext()); |
| 985 | if (protocol_handler_registry && |
| 986 | protocol_handler_registry->IsHandledProtocol(url.scheme())) |
| 987 | return; |
| 988 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 989 | bool is_whitelisted = false; |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 990 | PolicyBlacklistService* service = |
Oleg Davydov | 5cfe7ab | 2019-02-01 12:27:19 | [diff] [blame] | 991 | PolicyBlacklistFactory::GetForBrowserContext( |
| 992 | web_contents->GetBrowserContext()); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 993 | if (service) { |
| 994 | const policy::URLBlacklist::URLBlacklistState url_state = |
| 995 | service->GetURLBlacklistState(url); |
| 996 | is_whitelisted = |
| 997 | url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST; |
| 998 | } |
| 999 | |
| 1000 | // If the URL is in whitelist, we launch it without asking the user and |
| 1001 | // without any additional security checks. Since the URL is whitelisted, |
| 1002 | // we assume it can be executed. |
| 1003 | if (is_whitelisted) { |
| 1004 | ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents); |
| 1005 | } else { |
| 1006 | ExternalProtocolHandler::LaunchUrl( |
| 1007 | url, web_contents->GetRenderViewHost()->GetProcess()->GetID(), |
| 1008 | web_contents->GetRenderViewHost()->GetRoutingID(), page_transition, |
| 1009 | has_user_gesture); |
| 1010 | } |
| 1011 | } |
| 1012 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1013 | std::string GetProduct() { |
| 1014 | return version_info::GetProductNameAndVersionForUserAgent(); |
| 1015 | } |
| 1016 | |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 1017 | void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) { |
| 1018 | // |allowlist| combines pref/policy + cmdline switch in the browser process. |
| 1019 | // For renderer and utility (e.g. NetworkService) processes the switch is the |
| 1020 | // only available source, so below the combined (pref/policy + cmdline) |
| 1021 | // allowlist of secure origins is injected into |cmdline| for these other |
| 1022 | // processes. |
| 1023 | std::vector<std::string> allowlist = |
| 1024 | network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist(); |
| 1025 | if (!allowlist.empty()) { |
| 1026 | cmdline->AppendSwitchASCII( |
| 1027 | network::switches::kUnsafelyTreatInsecureOriginAsSecure, |
| 1028 | base::JoinString(allowlist, ",")); |
| 1029 | } |
| 1030 | } |
| 1031 | |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 1032 | #if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 1033 | // Returns the full path to |module_name|. Both dev builds (where |module_name| |
| 1034 | // is in the current executable's directory) and proper installs (where |
| 1035 | // |module_name| is in a versioned sub-directory of the current executable's |
| 1036 | // directory) are supported. The identified file is not guaranteed to exist. |
| 1037 | base::FilePath GetModulePath(base::StringPiece16 module_name) { |
| 1038 | base::FilePath exe_dir; |
| 1039 | const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir); |
| 1040 | DCHECK(has_path); |
| 1041 | |
| 1042 | // Look for the module in a versioned sub-directory of the current |
| 1043 | // executable's directory and return the path if it can be read. This is the |
| 1044 | // expected location of modules for proper installs. |
| 1045 | const base::FilePath module_path = |
| 1046 | exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name); |
| 1047 | if (base::PathExists(module_path)) |
| 1048 | return module_path; |
| 1049 | |
| 1050 | // Otherwise, return the path to the module in the current executable's |
| 1051 | // directory. This is the expected location of modules for dev builds. |
| 1052 | return exe_dir.Append(module_name); |
| 1053 | } |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 1054 | #endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) && |
| 1055 | // !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 1056 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 1057 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 1058 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1059 | std::string GetUserAgent() { |
| 1060 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1061 | if (command_line->HasSwitch(switches::kUserAgent)) { |
| 1062 | std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent); |
| 1063 | if (net::HttpUtil::IsValidHeaderValue(ua)) |
| 1064 | return ua; |
| 1065 | LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent; |
| 1066 | } |
| 1067 | |
John Delaney | ac24e57 | 2019-04-30 19:47:02 | [diff] [blame] | 1068 | if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) { |
| 1069 | return content::GetFrozenUserAgent( |
| 1070 | command_line->HasSwitch(switches::kUseMobileUserAgent)) |
| 1071 | .as_string(); |
| 1072 | } |
| 1073 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1074 | std::string product = GetProduct(); |
| 1075 | #if defined(OS_ANDROID) |
| 1076 | if (command_line->HasSwitch(switches::kUseMobileUserAgent)) |
| 1077 | product += " Mobile"; |
| 1078 | #endif |
| 1079 | return content::BuildUserAgentFromProduct(product); |
| 1080 | } |
| 1081 | |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1082 | blink::UserAgentMetadata GetUserAgentMetadata() { |
| 1083 | blink::UserAgentMetadata metadata; |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1084 | metadata.brand = version_info::GetProductName(); |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 1085 | metadata.full_version = version_info::GetVersionNumber(); |
| 1086 | metadata.major_version = version_info::GetMajorVersionNumber(); |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1087 | metadata.platform = version_info::GetOSType(); |
| 1088 | |
| 1089 | // TODO(mkwst): Poke at BuildUserAgentFromProduct to split out these pieces. |
| 1090 | metadata.architecture = ""; |
| 1091 | metadata.model = ""; |
| 1092 | |
| 1093 | return metadata; |
| 1094 | } |
| 1095 | |
Ran Ji | a96d43d4 | 2018-05-02 17:14:53 | [diff] [blame] | 1096 | ChromeContentBrowserClient::ChromeContentBrowserClient( |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 1097 | StartupData* startup_data) |
Wojciech Dzierżanowski | 4538080 | 2019-04-29 14:50:32 | [diff] [blame] | 1098 | : data_reduction_proxy_throttle_manager_( |
| 1099 | nullptr, |
| 1100 | base::OnTaskRunnerDeleter(nullptr)), |
Jeremy Roman | 495db68 | 2019-07-12 16:03:24 | [diff] [blame] | 1101 | startup_data_(startup_data) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1102 | #if BUILDFLAG(ENABLE_PLUGINS) |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 1103 | for (size_t i = 0; i < base::size(kPredefinedAllowedDevChannelOrigins); ++i) |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 1104 | allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 1105 | for (size_t i = 0; i < base::size(kPredefinedAllowedFileHandleOrigins); ++i) |
[email protected] | 10c3922 | 2013-11-13 20:09:25 | [diff] [blame] | 1106 | allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 1107 | for (size_t i = 0; i < base::size(kPredefinedAllowedSocketOrigins); ++i) |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1108 | allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 1109 | |
| 1110 | extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 1111 | #endif |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 1112 | |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 1113 | #if defined(OS_CHROMEOS) |
| 1114 | extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart); |
| 1115 | #endif // defined(OS_CHROMEOS) |
| 1116 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1117 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1118 | extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1119 | #endif |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 1120 | |
Sigurdur Asgeirsson | 7069667 | 2019-02-08 16:14:51 | [diff] [blame] | 1121 | extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart); |
Sigurdur Asgeirsson | 50945f9 | 2019-01-25 20:26:01 | [diff] [blame] | 1122 | |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 1123 | gpu_binder_registry_.AddInterface( |
Mike Wittman | 16fa536 | 2018-09-04 17:27:30 | [diff] [blame] | 1124 | base::Bind(&metrics::CallStackProfileCollector::Create)); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | ChromeContentBrowserClient::~ChromeContentBrowserClient() { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1128 | for (int i = static_cast<int>(extra_parts_.size()) - 1; i >= 0; --i) |
| 1129 | delete extra_parts_[i]; |
| 1130 | extra_parts_.clear(); |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1131 | } |
| 1132 | |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 1133 | // static |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1134 | void ChromeContentBrowserClient::RegisterLocalStatePrefs( |
| 1135 | PrefRegistrySimple* registry) { |
Greg Thompson | 8c922756 | 2019-08-05 17:47:13 | [diff] [blame] | 1136 | registry->RegisterFilePathPref(prefs::kDiskCacheDir, base::FilePath()); |
| 1137 | registry->RegisterIntegerPref(prefs::kDiskCacheSize, 0); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1138 | registry->RegisterStringPref(prefs::kIsolateOrigins, std::string()); |
| 1139 | registry->RegisterBooleanPref(prefs::kSitePerProcess, false); |
Chris Hamilton | 8206aad | 2018-07-18 01:00:03 | [diff] [blame] | 1140 | registry->RegisterBooleanPref(prefs::kTabLifecyclesEnabled, true); |
Julian Pastarmov | fac2800 | 2018-02-01 11:17:45 | [diff] [blame] | 1141 | registry->RegisterBooleanPref(prefs::kWebDriverOverridesIncompatiblePolicies, |
| 1142 | false); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | // static |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 1146 | void ChromeContentBrowserClient::RegisterProfilePrefs( |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 1147 | user_prefs::PrefRegistrySyncable* registry) { |
raymes | aa60872 | 2015-04-27 03:00:25 | [diff] [blame] | 1148 | registry->RegisterBooleanPref(prefs::kDisable3DAPIs, false); |
| 1149 | registry->RegisterBooleanPref(prefs::kEnableHyperlinkAuditing, true); |
| 1150 | registry->RegisterListPref(prefs::kEnableDeprecatedWebPlatformFeatures); |
Pavol Marko | 6adbea7f | 2018-02-20 16:35:28 | [diff] [blame] | 1151 | // Register user prefs for mapping SitePerProcess and IsolateOrigins in |
| 1152 | // user policy in addition to the same named ones in Local State (which are |
| 1153 | // used for mapping the command-line flags). |
| 1154 | registry->RegisterStringPref(prefs::kIsolateOrigins, std::string()); |
| 1155 | registry->RegisterBooleanPref(prefs::kSitePerProcess, false); |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 1156 | registry->RegisterListPref(prefs::kUserTriggeredIsolatedOrigins); |
Rayan Kanso | 411e84e | 2019-02-13 15:27:40 | [diff] [blame] | 1157 | registry->RegisterDictionaryPref( |
| 1158 | prefs::kDevToolsBackgroundServicesExpirationDict); |
Kunihiko Sakamoto | f586da6 | 2019-03-28 03:03:04 | [diff] [blame] | 1159 | registry->RegisterBooleanPref(prefs::kSignedHTTPExchangeEnabled, true); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 1160 | #if !defined(OS_ANDROID) |
| 1161 | registry->RegisterBooleanPref(prefs::kAutoplayAllowed, false); |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 1162 | registry->RegisterListPref(prefs::kAutoplayWhitelist); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 1163 | #endif |
[email protected] | bca1838 | 2012-06-25 19:15:23 | [diff] [blame] | 1164 | } |
| 1165 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1166 | // static |
| 1167 | void ChromeContentBrowserClient::SetApplicationLocale( |
| 1168 | const std::string& locale) { |
Scott Violet | 875789e | 2018-02-02 07:46:48 | [diff] [blame] | 1169 | // The common case is that this function is called early in Chrome startup |
| 1170 | // before any threads are created or registered. When there are no threads, |
| 1171 | // we can just set the string without worrying about threadsafety. |
Gabriel Charette | 192b8c9 | 2018-03-21 21:16:00 | [diff] [blame] | 1172 | if (!BrowserThread::IsThreadInitialized(BrowserThread::IO)) { |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 1173 | GetIOThreadApplicationLocale() = locale; |
Scott Violet | 875789e | 2018-02-02 07:46:48 | [diff] [blame] | 1174 | return; |
| 1175 | } |
| 1176 | |
| 1177 | // Otherwise we're being called to change the locale. In this case set it on |
| 1178 | // the IO thread. |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 1179 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1180 | |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 1181 | base::PostTask(FROM_HERE, {BrowserThread::IO}, |
| 1182 | base::BindOnce(&SetApplicationLocaleOnIOThread, locale)); |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 1183 | } |
| 1184 | |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1185 | std::unique_ptr<content::BrowserMainParts> |
| 1186 | ChromeContentBrowserClient::CreateBrowserMainParts( |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1187 | const content::MainFunctionParams& parameters) { |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1188 | std::unique_ptr<ChromeBrowserMainParts> main_parts; |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1189 | // Construct the Main browser parts based on the OS type. |
| 1190 | #if defined(OS_WIN) |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 1191 | main_parts = |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1192 | std::make_unique<ChromeBrowserMainPartsWin>(parameters, startup_data_); |
| 1193 | #elif defined(OS_MACOSX) |
| 1194 | main_parts = |
| 1195 | std::make_unique<ChromeBrowserMainPartsMac>(parameters, startup_data_); |
| 1196 | #elif defined(OS_CHROMEOS) |
| 1197 | main_parts = std::make_unique<chromeos::ChromeBrowserMainPartsChromeos>( |
| 1198 | parameters, startup_data_); |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 1199 | #elif defined(OS_LINUX) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1200 | main_parts = |
| 1201 | std::make_unique<ChromeBrowserMainPartsLinux>(parameters, startup_data_); |
[email protected] | 6e677a34 | 2012-02-11 01:21:14 | [diff] [blame] | 1202 | #elif defined(OS_ANDROID) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1203 | main_parts = std::make_unique<ChromeBrowserMainPartsAndroid>(parameters, |
| 1204 | startup_data_); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1205 | #elif defined(OS_POSIX) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1206 | main_parts = |
| 1207 | std::make_unique<ChromeBrowserMainPartsPosix>(parameters, startup_data_); |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1208 | #else |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1209 | NOTREACHED(); |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1210 | main_parts = |
| 1211 | std::make_unique<ChromeBrowserMainParts>(parameters, startup_data_); |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 1212 | #endif |
| 1213 | |
Xi Han | 9fd4400 | 2019-04-30 17:39:36 | [diff] [blame] | 1214 | bool add_profiles_extra_parts = true; |
| 1215 | #if defined(OS_ANDROID) |
| 1216 | if (startup_data_->HasBuiltProfilePrefService()) |
| 1217 | add_profiles_extra_parts = false; |
| 1218 | #endif |
| 1219 | if (add_profiles_extra_parts) |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1220 | chrome::AddProfilesExtraParts(main_parts.get()); |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 1221 | |
Xi Han | 9fd4400 | 2019-04-30 17:39:36 | [diff] [blame] | 1222 | // Construct additional browser parts. Stages are called in the order in |
| 1223 | // which they are added. |
[email protected] | c748094 | 2011-11-08 19:18:27 | [diff] [blame] | 1224 | #if defined(TOOLKIT_VIEWS) |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 1225 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 1226 | #if defined(USE_X11) |
| 1227 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinuxX11()); |
| 1228 | #else |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 1229 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViewsLinux()); |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 1230 | #endif // USE_X11 |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 1231 | #else |
riajiang | 7d6ec5c | 2017-01-25 16:40:33 | [diff] [blame] | 1232 | main_parts->AddParts(new ChromeBrowserMainExtraPartsViews()); |
James Cook | f9d34d2 | 2017-10-04 16:39:35 | [diff] [blame] | 1233 | #endif |
| 1234 | #endif |
| 1235 | |
| 1236 | #if defined(OS_CHROMEOS) |
| 1237 | // TODO(jamescook): Combine with ChromeBrowserMainPartsChromeos. |
riajiang | 7d6ec5c | 2017-01-25 16:40:33 | [diff] [blame] | 1238 | main_parts->AddParts(new ChromeBrowserMainExtraPartsAsh()); |
sky | cea631e | 2016-12-16 21:52:22 | [diff] [blame] | 1239 | #endif |
[email protected] | dc04be7c | 2012-03-15 23:57:49 | [diff] [blame] | 1240 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 1241 | #if defined(USE_X11) |
| 1242 | main_parts->AddParts(new ChromeBrowserMainExtraPartsX11()); |
[email protected] | e050ef14 | 2012-03-21 01:04:24 | [diff] [blame] | 1243 | #endif |
| 1244 | |
Sigurdur Asgeirsson | 54b7270 | 2019-04-12 14:18:54 | [diff] [blame] | 1245 | main_parts->AddParts(new ChromeBrowserMainExtraPartsPerformanceManager); |
Etienne Bergeron | 05d6253 | 2017-10-13 18:24:00 | [diff] [blame] | 1246 | |
Albert J. Wong | 59d85acb | 2017-08-10 00:50:57 | [diff] [blame] | 1247 | main_parts->AddParts(new ChromeBrowserMainExtraPartsProfiling); |
Albert J. Wong | 59d85acb | 2017-08-10 00:50:57 | [diff] [blame] | 1248 | |
Patrick Monette | 61dfef9 | 2019-05-30 23:06:27 | [diff] [blame] | 1249 | chrome::AddMetricsExtraParts(main_parts.get()); |
[email protected] | 95132f5 | 2013-04-12 02:19:04 | [diff] [blame] | 1250 | |
[email protected] | 50462bf0 | 2011-11-21 19:13:31 | [diff] [blame] | 1251 | return main_parts; |
[email protected] | f967b72 | 2011-09-07 00:58:04 | [diff] [blame] | 1252 | } |
| 1253 | |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1254 | void ChromeContentBrowserClient::PostAfterStartupTask( |
Brett Wilson | e1a7042 | 2017-09-12 05:10:09 | [diff] [blame] | 1255 | const base::Location& from_here, |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1256 | const scoped_refptr<base::TaskRunner>& task_runner, |
tzik | 6e42784 | 2017-04-05 10:13:21 | [diff] [blame] | 1257 | base::OnceClosure task) { |
tzik | 070c8ffb | 2017-03-29 05:28:12 | [diff] [blame] | 1258 | AfterStartupTaskUtils::PostTask(from_here, task_runner, std::move(task)); |
John Abd-El-Malek | 0e82fe7f | 2019-07-27 00:06:29 | [diff] [blame] | 1259 | |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 1260 | InitNetworkContextsParentDirectory(); |
| 1261 | |
John Abd-El-Malek | 0e82fe7f | 2019-07-27 00:06:29 | [diff] [blame] | 1262 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1263 | safe_browsing_service_ = g_browser_process->safe_browsing_service(); |
michaeln | 96f887e2 | 2015-04-13 23:58:31 | [diff] [blame] | 1264 | } |
| 1265 | |
falken | b09d443f | 2016-04-07 12:36:12 | [diff] [blame] | 1266 | bool ChromeContentBrowserClient::IsBrowserStartupComplete() { |
| 1267 | return AfterStartupTaskUtils::IsBrowserStartupComplete(); |
| 1268 | } |
| 1269 | |
Gabriel Charette | c8cca99 | 2017-08-10 18:21:49 | [diff] [blame] | 1270 | void ChromeContentBrowserClient::SetBrowserStartupIsCompleteForTesting() { |
| 1271 | AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); |
| 1272 | } |
| 1273 | |
John Abd-El-Malek | 9d57f9c | 2019-02-20 18:50:04 | [diff] [blame] | 1274 | bool ChromeContentBrowserClient::IsShuttingDown() { |
| 1275 | return browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID; |
| 1276 | } |
| 1277 | |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 1278 | std::string ChromeContentBrowserClient::GetStoragePartitionIdForSite( |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1279 | content::BrowserContext* browser_context, |
[email protected] | e94bbcb | 2012-09-07 05:33:57 | [diff] [blame] | 1280 | const GURL& site) { |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1281 | std::string partition_id; |
| 1282 | |
| 1283 | // The partition ID for webview guest processes is the string value of its |
| 1284 | // SiteInstance URL - "chrome-guest://app_id/persist?partition". |
rogerta | 5f5bb82 | 2015-12-17 03:24:45 | [diff] [blame] | 1285 | if (site.SchemeIs(content::kGuestScheme)) |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1286 | partition_id = site.spec(); |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1287 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
blundell | f650ea0 | 2016-02-08 11:50:50 | [diff] [blame] | 1288 | // The partition ID for extensions with isolated storage is treated similarly |
| 1289 | // to the above. |
| 1290 | else if (site.SchemeIs(extensions::kExtensionScheme) && |
| 1291 | extensions::util::SiteHasIsolatedStorage(site, browser_context)) |
| 1292 | partition_id = site.spec(); |
| 1293 | #endif |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1294 | |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 1295 | DCHECK(IsValidStoragePartitionId(browser_context, partition_id)); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1296 | return partition_id; |
| 1297 | } |
| 1298 | |
| 1299 | bool ChromeContentBrowserClient::IsValidStoragePartitionId( |
| 1300 | content::BrowserContext* browser_context, |
| 1301 | const std::string& partition_id) { |
| 1302 | // The default ID is empty and is always valid. |
| 1303 | if (partition_id.empty()) |
| 1304 | return true; |
| 1305 | |
| 1306 | return GURL(partition_id).is_valid(); |
| 1307 | } |
| 1308 | |
| 1309 | void ChromeContentBrowserClient::GetStoragePartitionConfigForSite( |
| 1310 | content::BrowserContext* browser_context, |
| 1311 | const GURL& site, |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1312 | bool can_be_default, |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1313 | std::string* partition_domain, |
| 1314 | std::string* partition_name, |
| 1315 | bool* in_memory) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1316 | // Default to the browser-wide storage partition and override based on |site| |
| 1317 | // below. |
| 1318 | partition_domain->clear(); |
| 1319 | partition_name->clear(); |
| 1320 | *in_memory = false; |
| 1321 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1322 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
rogerta | 5f5bb82 | 2015-12-17 03:24:45 | [diff] [blame] | 1323 | bool success = extensions::WebViewGuest::GetGuestPartitionConfigForSite( |
[email protected] | 3f24f97c | 2013-11-17 21:53:33 | [diff] [blame] | 1324 | site, partition_domain, partition_name, in_memory); |
| 1325 | |
| 1326 | if (!success && site.SchemeIs(extensions::kExtensionScheme)) { |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1327 | // If |can_be_default| is false, the caller is stating that the |site| |
| 1328 | // should be parsed as if it had isolated storage. In particular it is |
| 1329 | // important to NOT check ExtensionService for the is_storage_isolated() |
| 1330 | // attribute because this code path is run during Extension uninstall |
| 1331 | // to do cleanup after the Extension has already been unloaded from the |
| 1332 | // ExtensionService. |
| 1333 | bool is_isolated = !can_be_default; |
| 1334 | if (can_be_default) { |
[email protected] | ca033634 | 2014-03-21 12:58:34 | [diff] [blame] | 1335 | if (extensions::util::SiteHasIsolatedStorage(site, browser_context)) |
| 1336 | is_isolated = true; |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1337 | } |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1338 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1339 | if (is_isolated) { |
| 1340 | CHECK(site.has_host()); |
| 1341 | // For extensions with isolated storage, the the host of the |site| is |
| 1342 | // the |partition_domain|. The |in_memory| and |partition_name| are only |
| 1343 | // used in guest schemes so they are cleared here. |
| 1344 | *partition_domain = site.host(); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1345 | *in_memory = false; |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1346 | partition_name->clear(); |
[email protected] | 1bc2831 | 2012-11-08 08:31:53 | [diff] [blame] | 1347 | } |
[email protected] | 1df3d97 | 2014-06-11 04:55:18 | [diff] [blame] | 1348 | success = true; |
| 1349 | } |
| 1350 | #endif |
| 1351 | |
[email protected] | 14acc64 | 2012-11-17 12:20:10 | [diff] [blame] | 1352 | // Assert that if |can_be_default| is false, the code above must have found a |
| 1353 | // non-default partition. If this fails, the caller has a serious logic |
| 1354 | // error about which StoragePartition they expect to be in and it is not |
| 1355 | // safe to continue. |
| 1356 | CHECK(can_be_default || !partition_domain->empty()); |
[email protected] | d7c7c98a | 2012-07-12 21:27:44 | [diff] [blame] | 1357 | } |
| 1358 | |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 1359 | content::WebContentsViewDelegate* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1360 | ChromeContentBrowserClient::GetWebContentsViewDelegate( |
| 1361 | content::WebContents* web_contents) { |
cm.sanchi | 2db24a8 | 2017-11-16 07:22:10 | [diff] [blame] | 1362 | return CreateWebContentsViewDelegate(web_contents); |
[email protected] | 74313b4 | 2011-08-24 16:51:32 | [diff] [blame] | 1363 | } |
| 1364 | |
Bo Liu | 4ade6b1b2 | 2017-11-28 02:26:35 | [diff] [blame] | 1365 | bool ChromeContentBrowserClient::AllowGpuLaunchRetryOnIOThread() { |
| 1366 | #if defined(OS_ANDROID) |
| 1367 | const base::android::ApplicationState app_state = |
| 1368 | base::android::ApplicationStatusListener::GetState(); |
| 1369 | return base::android::APPLICATION_STATE_UNKNOWN == app_state || |
| 1370 | base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES == app_state || |
| 1371 | base::android::APPLICATION_STATE_HAS_PAUSED_ACTIVITIES == app_state; |
| 1372 | #else |
| 1373 | return true; |
| 1374 | #endif |
| 1375 | } |
| 1376 | |
[email protected] | 6f286274 | 2013-12-20 07:53:19 | [diff] [blame] | 1377 | void ChromeContentBrowserClient::RenderProcessWillLaunch( |
Ken Rockot | 7c6275b | 2019-08-02 20:00:23 | [diff] [blame] | 1378 | content::RenderProcessHost* host) { |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1379 | int id = host->GetID(); |
| 1380 | Profile* profile = Profile::FromBrowserContext(host->GetBrowserContext()); |
horo | 062ef535 | 2017-03-29 08:16:07 | [diff] [blame] | 1381 | host->AddFilter(new ChromeRenderMessageFilter(id, profile)); |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 1382 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | b79dd6ba | 2018-12-07 01:20:49 | [diff] [blame] | 1383 | host->AddFilter(new cast::CastTransportHostFilter()); |
thestig | 73f4cdc | 2015-01-15 01:51:06 | [diff] [blame] | 1384 | #endif |
Brett Wilson | 65f951c | 2016-11-03 22:06:12 | [diff] [blame] | 1385 | #if BUILDFLAG(ENABLE_PRINTING) |
[email protected] | 168b7799 | 2014-08-20 11:48:40 | [diff] [blame] | 1386 | host->AddFilter(new printing::PrintingMessageFilter(id, profile)); |
[email protected] | 058e573 | 2012-03-01 22:48:03 | [diff] [blame] | 1387 | #endif |
[email protected] | ba780c1 | 2013-10-01 17:07:06 | [diff] [blame] | 1388 | host->AddFilter(new prerender::PrerenderMessageFilter(id, profile)); |
thestig | 397accd | 2015-04-04 00:03:04 | [diff] [blame] | 1389 | host->AddFilter(new TtsMessageFilter(host->GetBrowserContext())); |
Darin Fisher | 8c84328c | 2019-07-23 02:50:00 | [diff] [blame] | 1390 | |
Darin Fisher | 09aa722 | 2019-08-29 09:27:36 | [diff] [blame] | 1391 | WebRtcLoggingController::AttachToRenderProcessHost( |
Darin Fisher | 8c84328c | 2019-07-23 02:50:00 | [diff] [blame] | 1392 | host, g_browser_process->webrtc_log_uploader()); |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1393 | |
grunell | 086a411 | 2017-03-02 09:23:04 | [diff] [blame] | 1394 | // The audio manager outlives the host, so it's safe to hand a raw pointer to |
| 1395 | // it to the AudioDebugRecordingsHandler, which is owned by the host. |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1396 | AudioDebugRecordingsHandler* audio_debug_recordings_handler = |
Marina Ciocea | 741a4fb1 | 2018-01-27 09:55:12 | [diff] [blame] | 1397 | new AudioDebugRecordingsHandler(profile); |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1398 | host->SetUserData( |
| 1399 | AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey, |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 1400 | std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>( |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1401 | audio_debug_recordings_handler)); |
| 1402 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 1403 | #if BUILDFLAG(ENABLE_NACL) |
Helen Li | 8897b02 | 2018-05-03 13:29:03 | [diff] [blame] | 1404 | host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(), |
| 1405 | profile->GetPath())); |
[email protected] | 01e5975 | 2013-06-18 00:17:35 | [diff] [blame] | 1406 | #endif |
jeremyim | 364ac118 | 2015-03-03 18:49:43 | [diff] [blame] | 1407 | |
Xiaohan Wang | 9b34281b | 2017-09-08 23:48:33 | [diff] [blame] | 1408 | #if defined(OS_ANDROID) |
| 1409 | // Data cannot be persisted if the profile is off the record. |
| 1410 | host->AddFilter( |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 1411 | new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false)); |
Yuzu Saijo | 2d12ef9 | 2018-08-21 04:52:07 | [diff] [blame] | 1412 | |
| 1413 | // Register CrashMemoryMetricsCollector to report oom related metrics. |
| 1414 | host->SetUserData( |
| 1415 | CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey, |
| 1416 | std::make_unique<CrashMemoryMetricsCollector>(host)); |
Xiaohan Wang | 9b34281b | 2017-09-08 23:48:33 | [diff] [blame] | 1417 | #endif |
| 1418 | |
Jun Cai | db3f93cc | 2018-07-09 21:54:55 | [diff] [blame] | 1419 | Profile* original_profile = profile->GetOriginalProfile(); |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 1420 | RendererUpdaterFactory::GetForProfile(original_profile) |
| 1421 | ->InitializeRenderer(host); |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 1422 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1423 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1424 | extra_parts_[i]->RenderProcessWillLaunch(host); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 1425 | } |
| 1426 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1427 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
Alex Moshchuk | bb99a33 | 2017-11-22 04:49:57 | [diff] [blame] | 1428 | content::BrowserContext* browser_context, |
Alex Moshchuk | a31c788 | 2018-01-17 00:57:30 | [diff] [blame] | 1429 | const GURL& url) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1430 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1431 | if (!profile) |
| 1432 | return url; |
| 1433 | |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1434 | #if !defined(OS_ANDROID) |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 1435 | // If the input |url| should be assigned to the Instant renderer, make its |
| 1436 | // effective URL distinct from other URLs on the search provider's domain. |
Alex Moshchuk | ca17137 | 2017-11-28 16:11:31 | [diff] [blame] | 1437 | // This needs to happen even if |url| corresponds to an isolated origin; see |
| 1438 | // https://crbug.com/755595. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1439 | if (search::ShouldAssignURLToInstantRenderer(url, profile)) |
| 1440 | return search::GetEffectiveURLForInstant(url, profile); |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1441 | #endif |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 1442 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1443 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Alex Moshchuk | a31c788 | 2018-01-17 00:57:30 | [diff] [blame] | 1444 | return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile, |
| 1445 | url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1446 | #else |
| 1447 | return url; |
| 1448 | #endif |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1449 | } |
| 1450 | |
Alexander Yashkin | 6aedc6e | 2018-08-15 08:58:45 | [diff] [blame] | 1451 | bool ChromeContentBrowserClient:: |
| 1452 | ShouldCompareEffectiveURLsForSiteInstanceSelection( |
| 1453 | content::BrowserContext* browser_context, |
| 1454 | content::SiteInstance* candidate_site_instance, |
| 1455 | bool is_main_frame, |
| 1456 | const GURL& candidate_url, |
| 1457 | const GURL& destination_url) { |
| 1458 | DCHECK(browser_context); |
| 1459 | DCHECK(candidate_site_instance); |
| 1460 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1461 | return ChromeContentBrowserClientExtensionsPart:: |
| 1462 | ShouldCompareEffectiveURLsForSiteInstanceSelection( |
| 1463 | browser_context, candidate_site_instance, is_main_frame, |
| 1464 | candidate_url, destination_url); |
| 1465 | #else |
| 1466 | return true; |
| 1467 | #endif |
| 1468 | } |
| 1469 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 1470 | bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() { |
Ahmed Fakhry | e6a2c64 | 2018-06-20 02:58:41 | [diff] [blame] | 1471 | #if defined(OS_ANDROID) |
| 1472 | return true; |
| 1473 | #elif defined(OS_CHROMEOS) |
Xiyuan Xia | fc9f3813 | 2019-08-02 00:51:42 | [diff] [blame] | 1474 | return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode(); |
Ahmed Fakhry | e6a2c64 | 2018-06-20 02:58:41 | [diff] [blame] | 1475 | #else |
| 1476 | return false; |
| 1477 | #endif // defined(OS_ANDROID) |
| 1478 | } |
| 1479 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1480 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1481 | content::BrowserContext* browser_context, |
| 1482 | const GURL& effective_url) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1483 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1484 | if (!profile) |
| 1485 | return false; |
| 1486 | |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1487 | // NTP should use process-per-site. This is a performance optimization to |
| 1488 | // reduce process count associated with NTP tabs. |
| 1489 | if (effective_url == GURL(chrome::kChromeUINewTabURL)) |
| 1490 | return true; |
Peter Boström | 8e9b163 | 2019-08-22 23:12:47 | [diff] [blame] | 1491 | |
| 1492 | // The web footer experiment should share its renderer to not effectively |
| 1493 | // instantiate one per window. See https://crbug.com/993502. |
| 1494 | if (effective_url == GURL(chrome::kChromeUIWebFooterExperimentURL)) |
| 1495 | return true; |
| 1496 | |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1497 | #if !defined(OS_ANDROID) |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1498 | if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile)) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1499 | return true; |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1500 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1501 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1502 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1503 | if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite( |
| 1504 | profile, effective_url)) |
| 1505 | return true; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1506 | #endif |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1507 | |
| 1508 | // Non-extension, non-NTP URLs should generally use process-per-site-instance |
| 1509 | // (rather than process-per-site). |
| 1510 | return false; |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1511 | } |
| 1512 | |
Lukasz Anforowicz | 32d2712 | 2018-04-09 21:48:33 | [diff] [blame] | 1513 | bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost( |
| 1514 | content::BrowserContext* browser_context, |
| 1515 | const GURL& site_url) { |
| 1516 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1517 | if (!profile) |
| 1518 | return false; |
| 1519 | |
| 1520 | #if !defined(OS_ANDROID) |
| 1521 | // Instant renderers should not use a spare process, because they require |
| 1522 | // passing switches::kInstantProcess to the renderer process when it |
| 1523 | // launches. A spare process is launched earlier, before it is known which |
| 1524 | // navigation will use it, so it lacks this flag. |
| 1525 | if (search::ShouldAssignURLToInstantRenderer(site_url, profile)) |
| 1526 | return false; |
| 1527 | #endif |
| 1528 | |
| 1529 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1530 | return ChromeContentBrowserClientExtensionsPart:: |
| 1531 | ShouldUseSpareRenderProcessHost(profile, site_url); |
| 1532 | #else |
| 1533 | return true; |
| 1534 | #endif |
| 1535 | } |
| 1536 | |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1537 | bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess( |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1538 | content::BrowserContext* browser_context, |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1539 | const GURL& effective_site_url) { |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1540 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1541 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1542 | if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess( |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1543 | browser_context, effective_site_url)) { |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1544 | return true; |
| 1545 | } |
| 1546 | #endif |
| 1547 | return false; |
| 1548 | } |
| 1549 | |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1550 | // TODO(creis, nick): https://crbug.com/160576 describes a weakness in our |
| 1551 | // origin-lock enforcement, where we don't have a way to efficiently know |
| 1552 | // effective URLs on the IO thread, and wind up killing processes that e.g. |
| 1553 | // request cookies for their actual URL. This whole function (and its |
| 1554 | // ExtensionsPart) should be removed once we add that ability to the IO thread. |
| 1555 | bool ChromeContentBrowserClient::ShouldLockToOrigin( |
| 1556 | content::BrowserContext* browser_context, |
| 1557 | const GURL& effective_site_url) { |
| 1558 | // Origin lock to the search scheme would kill processes upon legitimate |
| 1559 | // requests for cookies from the search engine's domain. |
| 1560 | if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme)) |
| 1561 | return false; |
| 1562 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1563 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1564 | if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin( |
| 1565 | browser_context, effective_site_url)) { |
| 1566 | return false; |
| 1567 | } |
| 1568 | #endif |
| 1569 | return true; |
creis | e5d6d173 | 2015-08-25 19:47:06 | [diff] [blame] | 1570 | } |
| 1571 | |
Lukasz Anforowicz | 05f356e | 2018-03-13 20:26:11 | [diff] [blame] | 1572 | const char* |
Lukasz Anforowicz | ce869f0b | 2018-08-06 18:33:37 | [diff] [blame] | 1573 | ChromeContentBrowserClient::GetInitiatorSchemeBypassingDocumentBlocking() { |
Charles Reis | 358baf47 | 2017-12-06 05:30:43 | [diff] [blame] | 1574 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | 05f356e | 2018-03-13 20:26:11 | [diff] [blame] | 1575 | // Don't block responses for extension processes or for content scripts. |
| 1576 | // TODO(creis): When every extension fetch (including content scripts) has |
| 1577 | // been made to go through an extension-specific URLLoaderFactory, this |
| 1578 | // mechanism ought to work by enumerating the host permissions from the |
| 1579 | // extension manifest, and forwarding them on to the network service while |
| 1580 | // brokering the URLLoaderFactory. |
| 1581 | return extensions::kExtensionScheme; |
| 1582 | #else |
| 1583 | return nullptr; |
Charles Reis | 358baf47 | 2017-12-06 05:30:43 | [diff] [blame] | 1584 | #endif |
Charles Reis | 358baf47 | 2017-12-06 05:30:43 | [diff] [blame] | 1585 | } |
| 1586 | |
Maks Orlovich | 0e23e31 | 2019-07-16 13:13:56 | [diff] [blame] | 1587 | bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel( |
| 1588 | base::StringPiece scheme) { |
| 1589 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1590 | return scheme == extensions::kExtensionScheme; |
| 1591 | #else |
| 1592 | return false; |
| 1593 | #endif |
| 1594 | } |
| 1595 | |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1596 | network::mojom::URLLoaderFactoryPtrInfo |
| 1597 | ChromeContentBrowserClient::CreateURLLoaderFactoryForNetworkRequests( |
| 1598 | content::RenderProcessHost* process, |
| 1599 | network::mojom::NetworkContext* network_context, |
Julie Jeongeun Kim | 47499a0c | 2019-08-28 07:23:18 | [diff] [blame] | 1600 | mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>* |
| 1601 | header_client, |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1602 | const url::Origin& request_initiator) { |
| 1603 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1604 | return ChromeContentBrowserClientExtensionsPart:: |
Clark DuVall | a5e25b75 | 2018-11-27 22:08:16 | [diff] [blame] | 1605 | CreateURLLoaderFactoryForNetworkRequests( |
| 1606 | process, network_context, header_client, request_initiator); |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1607 | #else |
| 1608 | return network::mojom::URLLoaderFactoryPtrInfo(); |
| 1609 | #endif |
| 1610 | } |
| 1611 | |
[email protected] | 73b718f | 2014-01-27 02:59:46 | [diff] [blame] | 1612 | // These are treated as WebUI schemes but do not get WebUI bindings. Also, |
| 1613 | // view-source is allowed for these schemes. |
[email protected] | 8f89dd41 | 2013-04-17 02:35:41 | [diff] [blame] | 1614 | void ChromeContentBrowserClient::GetAdditionalWebUISchemes( |
| 1615 | std::vector<std::string>* additional_schemes) { |
| 1616 | additional_schemes->push_back(chrome::kChromeSearchScheme); |
[email protected] | 474a5a3 | 2014-07-28 18:23:24 | [diff] [blame] | 1617 | additional_schemes->push_back(dom_distiller::kDomDistillerScheme); |
Andrey Kosyakov | 031e9e3 | 2017-08-18 21:00:35 | [diff] [blame] | 1618 | additional_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1619 | } |
| 1620 | |
alexmos | 94875b3b | 2017-03-16 22:19:01 | [diff] [blame] | 1621 | void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes( |
| 1622 | std::vector<std::string>* additional_schemes) { |
| 1623 | GetAdditionalWebUISchemes(additional_schemes); |
| 1624 | |
| 1625 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1626 | additional_schemes->push_back(extensions::kExtensionScheme); |
| 1627 | #endif |
| 1628 | } |
| 1629 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 1630 | bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) { |
dbeam | baee5bd | 2015-09-26 03:07:01 | [diff] [blame] | 1631 | return webui::LogWebUIUrl(web_ui_url); |
| 1632 | } |
| 1633 | |
John Abd-El-Malek | 04bfa853 | 2018-07-12 05:28:22 | [diff] [blame] | 1634 | bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests( |
| 1635 | const url::Origin& origin) { |
| 1636 | return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests( |
| 1637 | origin); |
| 1638 | } |
| 1639 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 1640 | bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { |
| 1641 | return ProfileIOData::IsHandledURL(url); |
| 1642 | } |
| 1643 | |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1644 | bool ChromeContentBrowserClient::CanCommitURL( |
| 1645 | content::RenderProcessHost* process_host, |
| 1646 | const GURL& url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1647 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1648 | return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host, |
| 1649 | url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1650 | #else |
| 1651 | return true; |
| 1652 | #endif |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1653 | } |
| 1654 | |
[email protected] | 9a60d160 | 2013-09-11 04:09:12 | [diff] [blame] | 1655 | bool ChromeContentBrowserClient::ShouldAllowOpenURL( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1656 | content::SiteInstance* site_instance, |
| 1657 | const GURL& url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1658 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1659 | bool result; |
| 1660 | if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL( |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1661 | site_instance, url, &result)) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1662 | return result; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1663 | #endif |
[email protected] | 879816a9 | 2014-04-29 00:53:54 | [diff] [blame] | 1664 | |
| 1665 | // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since |
| 1666 | // the signin page may host untrusted web content. |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1667 | GURL from_url = site_instance->GetSiteURL(); |
[email protected] | 879816a9 | 2014-04-29 00:53:54 | [diff] [blame] | 1668 | if (from_url.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL && |
| 1669 | url.SchemeIs(content::kChromeUIScheme) && |
brettw | b65cd5c | 2016-01-23 00:46:38 | [diff] [blame] | 1670 | url.host_piece() != chrome::kChromeUIChromeSigninHost) { |
[email protected] | 879816a9 | 2014-04-29 00:53:54 | [diff] [blame] | 1671 | VLOG(1) << "Blocked navigation to " << url.spec() << " from " |
| 1672 | << chrome::kChromeUIChromeSigninURL; |
| 1673 | return false; |
| 1674 | } |
| 1675 | |
[email protected] | 9a60d160 | 2013-09-11 04:09:12 | [diff] [blame] | 1676 | return true; |
| 1677 | } |
| 1678 | |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1679 | void ChromeContentBrowserClient::OverrideNavigationParams( |
| 1680 | SiteInstance* site_instance, |
| 1681 | ui::PageTransition* transition, |
| 1682 | bool* is_renderer_initiated, |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1683 | content::Referrer* referrer, |
| 1684 | base::Optional<url::Origin>* initiator_origin) { |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1685 | DCHECK(transition); |
| 1686 | DCHECK(is_renderer_initiated); |
| 1687 | DCHECK(referrer); |
Moe Ahmadi | 26e2f50 | 2019-07-16 02:34:47 | [diff] [blame] | 1688 | // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to |
| 1689 | // use for making security decisions 99.44% of the time, for detecting the NTP |
| 1690 | // it is reliable and the correct way. See http://crbug.com/624410. |
| 1691 | if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) && |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1692 | ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) { |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1693 | // Clicks on tiles of the new tab page should be treated as if a user |
| 1694 | // clicked on a bookmark. This is consistent with native implementations |
| 1695 | // like Android's. This also helps ensure that security features (like |
| 1696 | // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as |
| 1697 | // browser-initiated. |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1698 | *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK; |
| 1699 | *is_renderer_initiated = false; |
| 1700 | *referrer = content::Referrer(); |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1701 | *initiator_origin = base::nullopt; |
mastiz | a77db699 | 2016-06-30 09:48:42 | [diff] [blame] | 1702 | } |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1703 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1704 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1705 | ChromeContentBrowserClientExtensionsPart::OverrideNavigationParams( |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1706 | site_instance, transition, is_renderer_initiated, referrer, |
| 1707 | initiator_origin); |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1708 | #endif |
mastiz | a77db699 | 2016-06-30 09:48:42 | [diff] [blame] | 1709 | } |
| 1710 | |
Charles Reis | 29e9dd1 | 2017-09-28 00:59:15 | [diff] [blame] | 1711 | bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP( |
| 1712 | const GURL& url, |
| 1713 | SiteInstance* parent_site_instance) { |
Moe Ahmadi | 26e2f50 | 2019-07-16 02:34:47 | [diff] [blame] | 1714 | // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to |
| 1715 | // use for making security decisions 99.44% of the time, for detecting the NTP |
| 1716 | // it is reliable and the correct way. See http://crbug.com/624410. |
| 1717 | return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance && |
| 1718 | search::IsNTPURL(parent_site_instance->GetSiteURL()); |
Charles Reis | 29e9dd1 | 2017-09-28 00:59:15 | [diff] [blame] | 1719 | } |
| 1720 | |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1721 | bool ChromeContentBrowserClient::IsSuitableHost( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1722 | content::RenderProcessHost* process_host, |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1723 | const GURL& site_url) { |
| 1724 | Profile* profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1725 | Profile::FromBrowserContext(process_host->GetBrowserContext()); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1726 | // This may be nullptr during tests. In that case, just assume any site can |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1727 | // share any host. |
| 1728 | if (!profile) |
| 1729 | return true; |
| 1730 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1731 | #if !defined(OS_ANDROID) |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1732 | // Instant URLs should only be in the instant process and instant process |
| 1733 | // should only have Instant URLs. |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1734 | InstantService* instant_service = |
| 1735 | InstantServiceFactory::GetForProfile(profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1736 | if (instant_service) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1737 | bool is_instant_process = |
| 1738 | instant_service->IsInstantProcess(process_host->GetID()); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1739 | bool should_be_in_instant_process = |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1740 | search::ShouldAssignURLToInstantRenderer(site_url, profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1741 | if (is_instant_process || should_be_in_instant_process) |
| 1742 | return is_instant_process && should_be_in_instant_process; |
| 1743 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1744 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1745 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1746 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1747 | return ChromeContentBrowserClientExtensionsPart::IsSuitableHost( |
| 1748 | profile, process_host, site_url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1749 | #else |
| 1750 | return true; |
| 1751 | #endif |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1752 | } |
| 1753 | |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1754 | bool ChromeContentBrowserClient::MayReuseHost( |
| 1755 | content::RenderProcessHost* process_host) { |
| 1756 | // If there is currently a prerender in progress for the host provided, |
| 1757 | // it may not be shared. We require prerenders to be by themselves in a |
davidben | 879199c | 2015-03-06 00:55:04 | [diff] [blame] | 1758 | // separate process so that we can monitor their resource usage. |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1759 | prerender::PrerenderManager* prerender_manager = |
droger | c154315 | 2016-09-20 13:03:37 | [diff] [blame] | 1760 | prerender::PrerenderManagerFactory::GetForBrowserContext( |
| 1761 | process_host->GetBrowserContext()); |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1762 | if (prerender_manager && |
[email protected] | 2290af2 | 2014-05-26 15:44:49 | [diff] [blame] | 1763 | !prerender_manager->MayReuseProcessHost(process_host)) { |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1764 | return false; |
| 1765 | } |
| 1766 | |
| 1767 | return true; |
| 1768 | } |
| 1769 | |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1770 | bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1771 | content::BrowserContext* browser_context, |
| 1772 | const GURL& url) { |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1773 | // It has to be a valid URL for us to check for an extension. |
| 1774 | if (!url.is_valid()) |
| 1775 | return false; |
| 1776 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1777 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1778 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1779 | return ChromeContentBrowserClientExtensionsPart:: |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1780 | ShouldTryToUseExistingProcessHost(profile, url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1781 | #else |
| 1782 | return false; |
| 1783 | #endif |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1784 | } |
| 1785 | |
Alex Moshchuk | 9c9e388 | 2018-11-02 19:57:03 | [diff] [blame] | 1786 | bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess( |
| 1787 | content::RenderFrameHost* main_frame) { |
| 1788 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1789 | return ChromeContentBrowserClientExtensionsPart:: |
| 1790 | ShouldSubframesTryToReuseExistingProcess(main_frame); |
| 1791 | #else |
| 1792 | return true; |
| 1793 | #endif |
| 1794 | } |
| 1795 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1796 | void ChromeContentBrowserClient::SiteInstanceGotProcess( |
| 1797 | SiteInstance* site_instance) { |
| 1798 | CHECK(site_instance->HasProcess()); |
| 1799 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1800 | Profile* profile = |
| 1801 | Profile::FromBrowserContext(site_instance->GetBrowserContext()); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1802 | if (!profile) |
| 1803 | return; |
| 1804 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1805 | #if !defined(OS_ANDROID) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1806 | // Remember the ID of the Instant process to signal the renderer process |
| 1807 | // on startup in |AppendExtraCommandLineSwitches| below. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1808 | if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(), |
| 1809 | profile)) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1810 | InstantService* instant_service = |
| 1811 | InstantServiceFactory::GetForProfile(profile); |
| 1812 | if (instant_service) |
| 1813 | instant_service->AddInstantProcess(site_instance->GetProcess()->GetID()); |
| 1814 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1815 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1816 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1817 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1818 | extra_parts_[i]->SiteInstanceGotProcess(site_instance); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | void ChromeContentBrowserClient::SiteInstanceDeleting( |
| 1822 | SiteInstance* site_instance) { |
| 1823 | if (!site_instance->HasProcess()) |
| 1824 | return; |
| 1825 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1826 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1827 | extra_parts_[i]->SiteInstanceDeleting(site_instance); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1828 | } |
| 1829 | |
[email protected] | 453f543 | 2013-11-26 19:43:00 | [diff] [blame] | 1830 | bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation( |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1831 | SiteInstance* site_instance, |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1832 | const GURL& current_url, |
| 1833 | const GURL& new_url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1834 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1835 | return ChromeContentBrowserClientExtensionsPart:: |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1836 | ShouldSwapBrowsingInstancesForNavigation(site_instance, current_url, |
| 1837 | new_url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1838 | #else |
| 1839 | return false; |
| 1840 | #endif |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1841 | } |
| 1842 | |
Nasko Oskov | d83b571 | 2018-05-04 04:50:57 | [diff] [blame] | 1843 | bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) { |
| 1844 | // TODO(nasko): Consider supporting error page isolation in subframes if |
| 1845 | // Site Isolation is enabled. |
Nasko Oskov | 55d21e15 | 2018-06-27 23:59:38 | [diff] [blame] | 1846 | return in_main_frame; |
Nasko Oskov | d83b571 | 2018-05-04 04:50:57 | [diff] [blame] | 1847 | } |
| 1848 | |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 1849 | bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) { |
| 1850 | return !url.SchemeIs(chrome::kChromeNativeScheme); |
| 1851 | } |
| 1852 | |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1853 | std::vector<url::Origin> |
| 1854 | ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() { |
| 1855 | std::vector<url::Origin> isolated_origin_list; |
| 1856 | |
Alex Moshchuk | 89352a7 | 2017-10-25 20:25:59 | [diff] [blame] | 1857 | // Sign-in process isolation is not needed on Android, see |
| 1858 | // https://crbug.com/739418. |
| 1859 | #if !defined(OS_ANDROID) |
Alex Moshchuk | 81d2a29e | 2019-07-16 01:14:38 | [diff] [blame] | 1860 | isolated_origin_list.push_back( |
Alex Moshchuk | 36417aa | 2018-06-13 18:01:12 | [diff] [blame] | 1861 | url::Origin::Create(GaiaUrls::GetInstance()->gaia_url())); |
Alex Moshchuk | 89352a7 | 2017-10-25 20:25:59 | [diff] [blame] | 1862 | #endif |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1863 | |
Alex Moshchuk | 81d2a29e | 2019-07-16 01:14:38 | [diff] [blame] | 1864 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1865 | auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart:: |
| 1866 | GetOriginsRequiringDedicatedProcess(); |
| 1867 | std::move(std::begin(origins_from_extensions), |
| 1868 | std::end(origins_from_extensions), |
| 1869 | std::back_inserter(isolated_origin_list)); |
| 1870 | #endif |
| 1871 | |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1872 | return isolated_origin_list; |
| 1873 | } |
| 1874 | |
Lukasz Anforowicz | 5e201abd | 2018-03-24 00:41:06 | [diff] [blame] | 1875 | bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() { |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1876 | return base::FeatureList::IsEnabled(features::kSitePerProcess); |
| 1877 | } |
| 1878 | |
| 1879 | bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() { |
Lukasz Anforowicz | 0711a0f | 2019-03-28 18:15:31 | [diff] [blame] | 1880 | // Using 1077 rather than 1024 because 1) it helps ensure that devices with |
| 1881 | // exactly 1GB of RAM won't get included because of inaccuracies or off-by-one |
| 1882 | // errors and 2) this is the bucket boundary in Memory.Stats.Win.TotalPhys2. |
| 1883 | // See also https://crbug.com/844118. |
| 1884 | constexpr int kDefaultMemoryThresholdMb = 1077; |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1885 | |
| 1886 | // TODO(acolwell): Rename feature since it now affects more than just the |
| 1887 | // site-per-process case. |
Lukasz Anforowicz | 46275d9 | 2018-04-12 14:57:38 | [diff] [blame] | 1888 | if (base::FeatureList::IsEnabled( |
| 1889 | features::kSitePerProcessOnlyForHighMemoryClients)) { |
Lukasz Anforowicz | 46275d9 | 2018-04-12 14:57:38 | [diff] [blame] | 1890 | int memory_threshold_mb = base::GetFieldTrialParamByFeatureAsInt( |
| 1891 | features::kSitePerProcessOnlyForHighMemoryClients, |
| 1892 | features::kSitePerProcessOnlyForHighMemoryClientsParamName, |
| 1893 | kDefaultMemoryThresholdMb); |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1894 | return base::SysInfo::AmountOfPhysicalMemoryMB() <= memory_threshold_mb; |
Lukasz Anforowicz | 46275d9 | 2018-04-12 14:57:38 | [diff] [blame] | 1895 | } |
| 1896 | |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1897 | #if defined(OS_ANDROID) |
| 1898 | if (base::SysInfo::AmountOfPhysicalMemoryMB() <= kDefaultMemoryThresholdMb) { |
| 1899 | return true; |
| 1900 | } |
| 1901 | #endif |
| 1902 | |
| 1903 | return false; |
Lukasz Anforowicz | 5e201abd | 2018-03-24 00:41:06 | [diff] [blame] | 1904 | } |
| 1905 | |
Alex Moshchuk | 082b5f8 | 2019-03-14 01:34:16 | [diff] [blame] | 1906 | std::vector<std::string> |
| 1907 | ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() { |
| 1908 | if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled()) |
| 1909 | return {"Isolate Password Sites"}; |
| 1910 | else |
| 1911 | return {}; |
| 1912 | } |
| 1913 | |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 1914 | void ChromeContentBrowserClient::PersistIsolatedOrigin( |
| 1915 | content::BrowserContext* context, |
| 1916 | const url::Origin& origin) { |
| 1917 | DCHECK(!context->IsOffTheRecord()); |
| 1918 | Profile* profile = Profile::FromBrowserContext(context); |
| 1919 | ListPrefUpdate update(profile->GetPrefs(), |
| 1920 | prefs::kUserTriggeredIsolatedOrigins); |
| 1921 | base::ListValue* list = update.Get(); |
| 1922 | base::Value value(origin.Serialize()); |
Jan Wilken Dörrie | a8cb5630 | 2019-06-06 18:59:36 | [diff] [blame] | 1923 | if (!base::Contains(list->GetList(), value)) |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 1924 | list->GetList().push_back(std::move(value)); |
| 1925 | } |
| 1926 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 1927 | bool ChromeContentBrowserClient::IsFileAccessAllowed( |
| 1928 | const base::FilePath& path, |
| 1929 | const base::FilePath& absolute_path, |
| 1930 | const base::FilePath& profile_path) { |
| 1931 | return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path, |
| 1932 | profile_path); |
| 1933 | } |
| 1934 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1935 | namespace { |
| 1936 | |
| 1937 | bool IsAutoReloadEnabled() { |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 1938 | const base::CommandLine& browser_command_line = |
| 1939 | *base::CommandLine::ForCurrentProcess(); |
Elly Fong-Jones | 5f13ee1 | 2019-05-10 19:20:35 | [diff] [blame] | 1940 | if (browser_command_line.HasSwitch(switches::kEnableAutoReload)) |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1941 | return true; |
Elly Fong-Jones | 5f13ee1 | 2019-05-10 19:20:35 | [diff] [blame] | 1942 | if (browser_command_line.HasSwitch(switches::kDisableAutoReload)) |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1943 | return false; |
[email protected] | 9ef49b4 | 2014-08-07 16:44:24 | [diff] [blame] | 1944 | return true; |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1945 | } |
| 1946 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1947 | void MaybeAppendBlinkSettingsSwitchForFieldTrial( |
| 1948 | const base::CommandLine& browser_command_line, |
| 1949 | base::CommandLine* command_line) { |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1950 | // List of field trials that modify the blink-settings command line flag. No |
| 1951 | // two field trials in the list should specify the same keys, otherwise one |
| 1952 | // field trial may overwrite another. See Source/core/frame/Settings.in in |
| 1953 | // Blink for the list of valid keys. |
| 1954 | static const char* const kBlinkSettingsFieldTrials[] = { |
jkarlin | 3bddb7d | 2016-09-21 18:44:16 | [diff] [blame] | 1955 | // Keys: disallowFetchForDocWrittenScriptsInMainFrame |
| 1956 | // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections |
| 1957 | // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G |
| 1958 | "DisallowFetchForDocWrittenScriptsInMainFrame", |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1959 | }; |
| 1960 | |
| 1961 | std::vector<std::string> blink_settings; |
| 1962 | for (const char* field_trial_name : kBlinkSettingsFieldTrials) { |
| 1963 | // Each blink-settings field trial should include a forcing_flag group, |
| 1964 | // to make sure that clients that specify the blink-settings flag on the |
| 1965 | // command line are excluded from the experiment groups. To make |
| 1966 | // sure we assign clients that specify this flag to the forcing_flag |
| 1967 | // group, we must call GetVariationParams for each field trial first |
| 1968 | // (for example, before checking HasSwitch() and returning), since |
| 1969 | // GetVariationParams has the side-effect of assigning the client to |
| 1970 | // a field trial group. |
| 1971 | std::map<std::string, std::string> params; |
| 1972 | if (variations::GetVariationParams(field_trial_name, ¶ms)) { |
| 1973 | for (const auto& param : params) { |
| 1974 | blink_settings.push_back(base::StringPrintf( |
| 1975 | "%s=%s", param.first.c_str(), param.second.c_str())); |
| 1976 | } |
| 1977 | } |
| 1978 | } |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 1979 | |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1980 | if (blink_settings.empty()) { |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1981 | return; |
| 1982 | } |
| 1983 | |
| 1984 | if (browser_command_line.HasSwitch(switches::kBlinkSettings) || |
| 1985 | command_line->HasSwitch(switches::kBlinkSettings)) { |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 1986 | // The field trials should be configured to force users that specify the |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1987 | // blink-settings flag into a group with no params, and we return |
| 1988 | // above if no params were specified, so it's an error if we reach |
| 1989 | // this point. |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1990 | LOG(WARNING) << "Received field trial params, " |
| 1991 | "but blink-settings switch already specified."; |
| 1992 | return; |
| 1993 | } |
| 1994 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1995 | command_line->AppendSwitchASCII(switches::kBlinkSettings, |
brettw | d94a2214 | 2015-07-15 05:19:26 | [diff] [blame] | 1996 | base::JoinString(blink_settings, ",")); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1997 | } |
| 1998 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 1999 | #if defined(OS_ANDROID) |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 2000 | template <typename Interface> |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2001 | void ForwardToJavaFrameRegistry(mojo::InterfaceRequest<Interface> request, |
| 2002 | content::RenderFrameHost* render_frame_host) { |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 2003 | render_frame_host->GetJavaInterfaces()->GetInterface(std::move(request)); |
mgiuca | 3d9a196 | 2017-04-07 05:25:44 | [diff] [blame] | 2004 | } |
| 2005 | |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 2006 | template <typename Interface> |
| 2007 | void ForwardToJavaWebContentsRegistry( |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 2008 | mojo::InterfaceRequest<Interface> request, |
| 2009 | content::RenderFrameHost* render_frame_host) { |
| 2010 | content::WebContents* contents = |
| 2011 | content::WebContents::FromRenderFrameHost(render_frame_host); |
| 2012 | if (contents) |
| 2013 | contents->GetJavaInterfaces()->GetInterface(std::move(request)); |
sammc | 0285a44 | 2016-10-04 23:03:56 | [diff] [blame] | 2014 | } |
| 2015 | #endif |
| 2016 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 2017 | } // namespace |
| 2018 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2019 | void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 2020 | base::CommandLine* command_line, |
| 2021 | int child_process_id) { |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2022 | #if defined(OS_MACOSX) |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2023 | std::unique_ptr<metrics::ClientInfo> client_info = |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2024 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
| 2025 | if (client_info) { |
| 2026 | command_line->AppendSwitchASCII(switches::kMetricsClientID, |
| 2027 | client_info->client_id); |
| 2028 | } |
| 2029 | #elif defined(OS_POSIX) |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 2030 | #if defined(OS_ANDROID) |
| 2031 | bool enable_crash_reporter = true; |
| 2032 | #else |
| 2033 | bool enable_crash_reporter = breakpad::IsCrashReporterEnabled(); |
| 2034 | #endif |
| 2035 | if (enable_crash_reporter) { |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2036 | std::string switch_value; |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2037 | std::unique_ptr<metrics::ClientInfo> client_info = |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 2038 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2039 | if (client_info) |
| 2040 | switch_value = client_info->client_id; |
| 2041 | switch_value.push_back(','); |
Boris Vidolov | 8657801 | 2018-03-21 16:55:25 | [diff] [blame] | 2042 | switch_value.append(chrome::GetChannelName()); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2043 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2044 | switch_value); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2045 | } |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2046 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2047 | |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 2048 | if (logging::DialogsAreSuppressed()) |
| 2049 | command_line->AppendSwitch(switches::kNoErrorDialogs); |
| 2050 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2051 | std::string process_type = |
| 2052 | command_line->GetSwitchValueASCII(switches::kProcessType); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 2053 | const base::CommandLine& browser_command_line = |
| 2054 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 2055 | |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 2056 | static const char* const kCommonSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2057 | switches::kUserAgent, |
| 2058 | switches::kUserDataDir, // Make logs go to the right file. |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 2059 | }; |
| 2060 | command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2061 | base::size(kCommonSwitchNames)); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 2062 | |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2063 | static const char* const kDinosaurEasterEggSwitches[] = { |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 2064 | error_page::switches::kDisableDinosaurEasterEgg, |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 2065 | }; |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2066 | command_line->CopySwitchesFrom(browser_command_line, |
| 2067 | kDinosaurEasterEggSwitches, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2068 | base::size(kDinosaurEasterEggSwitches)); |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 2069 | |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2070 | #if defined(OS_CHROMEOS) |
[email protected] | 6bdc5227 | 2014-05-27 00:12:33 | [diff] [blame] | 2071 | // On Chrome OS need to pass primary user homedir (in multi-profiles session). |
| 2072 | base::FilePath homedir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 2073 | base::PathService::Get(base::DIR_HOME, &homedir); |
[email protected] | 6bdc5227 | 2014-05-27 00:12:33 | [diff] [blame] | 2074 | command_line->AppendSwitchASCII(chromeos::switches::kHomedir, |
| 2075 | homedir.value().c_str()); |
| 2076 | #endif |
| 2077 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 2078 | if (process_type == switches::kRendererProcess) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2079 | content::RenderProcessHost* process = |
| 2080 | content::RenderProcessHost::FromID(child_process_id); |
| 2081 | Profile* profile = |
| 2082 | process ? Profile::FromBrowserContext(process->GetBrowserContext()) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2083 | : nullptr; |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2084 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2085 | extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line, |
| 2086 | process, profile); |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2087 | } |
| 2088 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2089 | #if defined(OS_CHROMEOS) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2090 | const std::string& login_profile = browser_command_line.GetSwitchValueASCII( |
| 2091 | chromeos::switches::kLoginProfile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2092 | if (!login_profile.empty()) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2093 | command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, |
| 2094 | login_profile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2095 | #endif |
| 2096 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2097 | MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line, |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 2098 | chrome::GetChannel()); |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2099 | if (process) { |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2100 | PrefService* prefs = profile->GetPrefs(); |
| 2101 | // Currently this pref is only registered if applied via a policy. |
| 2102 | if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && |
| 2103 | prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 2104 | // Turn this policy into a command line switch. |
| 2105 | command_line->AppendSwitch(switches::kDisable3DAPIs); |
| 2106 | } |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 2107 | |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2108 | const base::ListValue* switches = |
| 2109 | prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures); |
| 2110 | if (switches) { |
| 2111 | // Enable any deprecated features that have been re-enabled by policy. |
jdoerrie | 601c715 | 2018-10-02 23:43:11 | [diff] [blame] | 2112 | for (auto it = switches->begin(); it != switches->end(); ++it) { |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2113 | std::string switch_to_enable; |
jdoerrie | a5676c6 | 2017-04-11 18:09:14 | [diff] [blame] | 2114 | if (it->GetAsString(&switch_to_enable)) |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2115 | command_line->AppendSwitch(switch_to_enable); |
| 2116 | } |
| 2117 | } |
| 2118 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2119 | // Disable client-side phishing detection in the renderer if it is |
| 2120 | // disabled in the Profile preferences or the browser process. |
| 2121 | if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) || |
| 2122 | !g_browser_process->safe_browsing_detection_service()) { |
| 2123 | command_line->AppendSwitch( |
| 2124 | switches::kDisableClientSidePhishingDetection); |
| 2125 | } |
[email protected] | 0045b0f4 | 2012-07-26 11:52:08 | [diff] [blame] | 2126 | |
vitalybuka | a7ae505 | 2014-09-26 04:11:13 | [diff] [blame] | 2127 | if (prefs->GetBoolean(prefs::kPrintPreviewDisabled)) |
| 2128 | command_line->AppendSwitch(switches::kDisablePrintPreview); |
| 2129 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 2130 | #if !defined(OS_ANDROID) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 2131 | InstantService* instant_service = |
| 2132 | InstantServiceFactory::GetForProfile(profile); |
| 2133 | if (instant_service && |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2134 | instant_service->IsInstantProcess(process->GetID())) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 2135 | command_line->AppendSwitch(switches::kInstantProcess); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2136 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 2137 | #endif |
fqj | ba8749c | 2015-10-29 15:33:07 | [diff] [blame] | 2138 | |
fqj | 38306f7b | 2015-11-02 16:59:06 | [diff] [blame] | 2139 | if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) && |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2140 | !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) { |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 2141 | command_line->AppendSwitch( |
| 2142 | error_page::switches::kDisableDinosaurEasterEgg); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2143 | } |
Daniel Vogelheim | 976f1c2 | 2017-11-22 16:26:03 | [diff] [blame] | 2144 | |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 2145 | MaybeAppendSecureOriginsAllowlistSwitch(command_line); |
| 2146 | |
Amr Aboelkher | b04cbf3 | 2019-04-29 15:17:10 | [diff] [blame] | 2147 | if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) && |
| 2148 | prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) { |
Avi Drissman | fb96126 | 2019-03-05 22:50:29 | [diff] [blame] | 2149 | command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload); |
Amr Aboelkher | b04cbf3 | 2019-04-29 15:17:10 | [diff] [blame] | 2150 | } |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2151 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2152 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 2153 | if (IsAutoReloadEnabled()) |
Elly Fong-Jones | 5f13ee1 | 2019-05-10 19:20:35 | [diff] [blame] | 2154 | command_line->AppendSwitch(switches::kEnableAutoReload); |
[email protected] | 28ee4e7 | 2014-03-28 19:29:04 | [diff] [blame] | 2155 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2156 | MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line, |
| 2157 | command_line); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2158 | |
mdjones | a6b9e17 | 2016-09-23 16:24:30 | [diff] [blame] | 2159 | #if defined(OS_ANDROID) |
| 2160 | // If the platform is Android, force the distillability service on. |
| 2161 | command_line->AppendSwitch(switches::kEnableDistillabilityService); |
| 2162 | #endif |
| 2163 | |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2164 | // Please keep this in alphabetical order. |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2165 | static const char* const kSwitchNames[] = { |
estade | 0ee9126 | 2014-10-23 19:29:19 | [diff] [blame] | 2166 | autofill::switches::kIgnoreAutocompleteOffForAutofill, |
kolos | ad36993 | 2017-02-23 13:29:41 | [diff] [blame] | 2167 | autofill::switches::kShowAutofillSignatures, |
Chris Mumford | 6b1696b | 2019-01-25 02:54:30 | [diff] [blame] | 2168 | #if defined(OS_CHROMEOS) |
| 2169 | switches::kShortMergeSessionTimeoutForTest, // For tests only. |
| 2170 | #endif |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2171 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 2172 | extensions::switches::kAllowHTTPBackgroundPage, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2173 | extensions::switches::kAllowLegacyExtensionManifests, |
Chris Mumford | 3f0eda9 | 2018-07-23 14:51:17 | [diff] [blame] | 2174 | extensions::switches::kDisableExtensionsHttpThrottling, |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 2175 | extensions::switches::kEnableExperimentalExtensionApis, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2176 | extensions::switches::kExtensionsOnChromeURLs, |
Chris Mumford | 3f0eda9 | 2018-07-23 14:51:17 | [diff] [blame] | 2177 | extensions::switches::kSetExtensionThrottleTestParams, // For tests only. |
[email protected] | a612eb3 | 2014-03-31 22:09:17 | [diff] [blame] | 2178 | extensions::switches::kWhitelistedExtensionID, |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 2179 | #endif |
estark | 4b003b33 | 2015-02-14 01:07:05 | [diff] [blame] | 2180 | switches::kAllowInsecureLocalhost, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2181 | switches::kAppsGalleryURL, |
[email protected] | 09cff7878 | 2014-04-20 22:04:48 | [diff] [blame] | 2182 | switches::kCloudPrintURL, |
[email protected] | 6f5c141a | 2014-04-15 21:44:51 | [diff] [blame] | 2183 | switches::kCloudPrintXmppEndpoint, |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 2184 | switches::kDisableBundledPpapiFlash, |
dslomov | a893e97 | 2014-12-05 09:39:57 | [diff] [blame] | 2185 | switches::kDisableJavaScriptHarmonyShipping, |
Kyle Milka | b5c048e | 2017-07-07 02:38:46 | [diff] [blame] | 2186 | variations::switches::kEnableBenchmarking, |
mdjones | a6b9e17 | 2016-09-23 16:24:30 | [diff] [blame] | 2187 | switches::kEnableDistillabilityService, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2188 | switches::kEnableNaCl, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2189 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | 1b4ec38 | 2014-03-07 02:32:24 | [diff] [blame] | 2190 | switches::kEnableNaClDebug, |
[email protected] | b2c73f4 | 2014-03-07 15:44:48 | [diff] [blame] | 2191 | switches::kEnableNaClNonSfiMode, |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 2192 | #endif |
[email protected] | ce304ce | 2013-02-22 21:54:45 | [diff] [blame] | 2193 | switches::kEnableNetBenchmarking, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2194 | #if BUILDFLAG(ENABLE_NACL) |
stichnot | 7040ac83 | 2016-02-24 23:40:59 | [diff] [blame] | 2195 | switches::kForcePNaClSubzero, |
| 2196 | #endif |
Marc Treib | ad33cf94 | 2017-08-24 11:19:00 | [diff] [blame] | 2197 | switches::kForceUIDirection, |
erikcorry | b251cb9 | 2014-09-25 23:48:51 | [diff] [blame] | 2198 | switches::kJavaScriptHarmony, |
Andreas Haas | b400d91 | 2019-08-28 18:54:10 | [diff] [blame] | 2199 | switches::kEnableExperimentalWebAssemblyFeatures, |
iclelland | 79237e9 | 2016-06-23 12:03:51 | [diff] [blame] | 2200 | switches::kOriginTrialDisabledFeatures, |
chasej | dfec22ae | 2017-03-16 20:58:55 | [diff] [blame] | 2201 | switches::kOriginTrialDisabledTokens, |
iclelland | ee4f4a7 | 2016-04-26 18:59:02 | [diff] [blame] | 2202 | switches::kOriginTrialPublicKey, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2203 | switches::kPpapiFlashArgs, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2204 | switches::kPpapiFlashPath, |
| 2205 | switches::kPpapiFlashVersion, |
wychen | e5568734 | 2015-11-13 20:17:03 | [diff] [blame] | 2206 | switches::kReaderModeHeuristics, |
[email protected] | 499e7c5 | 2013-10-04 16:03:09 | [diff] [blame] | 2207 | translate::switches::kTranslateSecurityOrigin, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2208 | }; |
| 2209 | |
| 2210 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2211 | base::size(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 2212 | } else if (process_type == switches::kUtilityProcess) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2213 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 2214 | static const char* const kSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2215 | extensions::switches::kAllowHTTPBackgroundPage, |
| 2216 | extensions::switches::kEnableExperimentalExtensionApis, |
| 2217 | extensions::switches::kExtensionsOnChromeURLs, |
| 2218 | extensions::switches::kWhitelistedExtensionID, |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 2219 | }; |
| 2220 | |
| 2221 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2222 | base::size(kSwitchNames)); |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 2223 | #endif |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 2224 | MaybeAppendSecureOriginsAllowlistSwitch(command_line); |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 2225 | } else if (process_type == service_manager::switches::kZygoteProcess) { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2226 | static const char* const kSwitchNames[] = { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2227 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 2228 | switches::kDisableBundledPpapiFlash, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2229 | #if BUILDFLAG(ENABLE_NACL) |
rickyz | 3638a21 | 2014-10-29 23:50:24 | [diff] [blame] | 2230 | switches::kEnableNaClDebug, |
[email protected] | a9a8e2f | 2014-05-13 23:32:58 | [diff] [blame] | 2231 | switches::kEnableNaClNonSfiMode, |
stichnot | 7040ac83 | 2016-02-24 23:40:59 | [diff] [blame] | 2232 | switches::kForcePNaClSubzero, |
[email protected] | 0b47034 | 2014-04-15 12:59:41 | [diff] [blame] | 2233 | switches::kNaClDangerousNoSandboxNonSfi, |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 2234 | #endif |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2235 | switches::kPpapiFlashPath, |
| 2236 | switches::kPpapiFlashVersion, |
| 2237 | }; |
| 2238 | |
| 2239 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2240 | base::size(kSwitchNames)); |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 2241 | } else if (process_type == switches::kGpuProcess) { |
| 2242 | // If --ignore-gpu-blacklist is passed in, don't send in crash reports |
| 2243 | // because GPU is expected to be unreliable. |
| 2244 | if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) && |
| 2245 | !command_line->HasSwitch(switches::kDisableBreakpad)) |
| 2246 | command_line->AppendSwitch(switches::kDisableBreakpad); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2247 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 2248 | |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2249 | #if defined(OS_CHROMEOS) |
Joshua Peraza | 30d8fc7 | 2019-08-19 17:24:30 | [diff] [blame] | 2250 | if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) { |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2251 | static const char* const kSwitchNames[] = { |
| 2252 | switches::kCrashLoopBefore, |
| 2253 | }; |
| 2254 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 2255 | base::size(kSwitchNames)); |
| 2256 | } |
| 2257 | #endif |
| 2258 | |
wittman | 832321f5 | 2016-10-10 18:18:38 | [diff] [blame] | 2259 | StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2260 | process_type, command_line); |
Andrew Comminos | 6605767 | 2019-05-01 00:03:34 | [diff] [blame] | 2261 | |
| 2262 | #if defined(OS_LINUX) |
| 2263 | // Processes may only query perf_event_open with the BPF sandbox disabled. |
| 2264 | if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) && |
| 2265 | command_line->HasSwitch(service_manager::switches::kNoSandbox)) { |
| 2266 | command_line->AppendSwitch(switches::kEnableThreadInstructionCount); |
| 2267 | } |
| 2268 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2269 | } |
| 2270 | |
Scott Violet | 776edf8 | 2017-09-29 02:03:01 | [diff] [blame] | 2271 | void ChromeContentBrowserClient::AdjustUtilityServiceProcessCommandLine( |
| 2272 | const service_manager::Identity& identity, |
| 2273 | base::CommandLine* command_line) { |
Guido Urdaneta | 191635e | 2018-05-09 16:00:53 | [diff] [blame] | 2274 | #if defined(OS_MACOSX) |
Ken Rockot | 2f8c1dd2 | 2019-07-23 21:56:02 | [diff] [blame] | 2275 | // On Mac, the audio service requires a CFRunLoop, provided by a UI message |
| 2276 | // loop, to run AVFoundation and CoreAudio code. See https://crbug.com/834581. |
| 2277 | if (identity.name() == audio::mojom::kServiceName) |
Guido Urdaneta | 191635e | 2018-05-09 16:00:53 | [diff] [blame] | 2278 | command_line->AppendSwitch(switches::kMessageLoopTypeUi); |
| 2279 | #endif |
Scott Violet | 776edf8 | 2017-09-29 02:03:01 | [diff] [blame] | 2280 | } |
| 2281 | |
Olivier Yiptong | 0daa93f | 2019-08-22 19:40:08 | [diff] [blame] | 2282 | std::string |
| 2283 | ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() { |
| 2284 | return std::string(chrome::kApplicationClientIDStringForAVScanning); |
| 2285 | } |
| 2286 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2287 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
[email protected] | e9a32a5 | 2012-06-14 23:32:43 | [diff] [blame] | 2288 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 2289 | return GetIOThreadApplicationLocale(); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2290 | return g_browser_process->GetApplicationLocale(); |
| 2291 | } |
| 2292 | |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 2293 | std::string ChromeContentBrowserClient::GetAcceptLangs( |
| 2294 | content::BrowserContext* context) { |
| 2295 | Profile* profile = Profile::FromBrowserContext(context); |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 2296 | return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 2297 | } |
| 2298 | |
Dana Fried | 34d58000 | 2019-04-24 20:05:48 | [diff] [blame] | 2299 | gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() { |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 2300 | ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
Dana Fried | 34d58000 | 2019-04-24 20:05:48 | [diff] [blame] | 2301 | return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia(); |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 2302 | } |
| 2303 | |
bengr | e8a146f | 2016-03-10 01:20:22 | [diff] [blame] | 2304 | bool ChromeContentBrowserClient::IsDataSaverEnabled( |
| 2305 | content::BrowserContext* browser_context) { |
Robert Ogden | c995d4fe | 2019-03-25 19:18:37 | [diff] [blame] | 2306 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2307 | return profile && data_reduction_proxy::DataReductionProxySettings:: |
| 2308 | IsDataSaverEnabledByUser(profile->GetPrefs()); |
bengr | e8a146f | 2016-03-10 01:20:22 | [diff] [blame] | 2309 | } |
| 2310 | |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 2311 | void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker( |
| 2312 | content::BrowserContext* browser_context, |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 2313 | blink::mojom::RendererPreferences* out_prefs) { |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 2314 | DCHECK(browser_context); |
| 2315 | DCHECK(out_prefs); |
| 2316 | renderer_preferences_util::UpdateFromSystemSettings( |
| 2317 | out_prefs, Profile::FromBrowserContext(browser_context)); |
| 2318 | } |
| 2319 | |
Clark DuVall | 5690e74 | 2019-07-17 18:26:17 | [diff] [blame] | 2320 | bool ChromeContentBrowserClient::AllowAppCache( |
| 2321 | const GURL& manifest_url, |
| 2322 | const GURL& first_party, |
| 2323 | content::BrowserContext* context) { |
| 2324 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2325 | return CookieSettingsFactory::GetForProfile( |
| 2326 | Profile::FromBrowserContext(context)) |
| 2327 | ->IsCookieAccessAllowed(manifest_url, first_party); |
| 2328 | } |
| 2329 | |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2330 | bool ChromeContentBrowserClient::AllowServiceWorkerOnIO( |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2331 | const GURL& scope, |
| 2332 | const GURL& first_party_url, |
David Bertoni | 3b3597d8 | 2019-06-22 02:29:36 | [diff] [blame] | 2333 | const GURL& script_url, |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2334 | content::ResourceContext* context, |
tzik | df81f14 | 2018-10-26 00:23:34 | [diff] [blame] | 2335 | base::RepeatingCallback<content::WebContents*()> wc_getter) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 2336 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2337 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2338 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2339 | // Check if this is an extension-related service worker, and, if so, if it's |
| 2340 | // allowed (this can return false if, e.g., the extension is disabled). |
| 2341 | // If it's not allowed, return immediately. We deliberately do *not* report |
| 2342 | // to the TabSpecificContentSettings, since the service worker is blocked |
| 2343 | // because of the extension, rather than because of the user's content |
| 2344 | // settings. |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2345 | if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO( |
David Bertoni | 3b3597d8 | 2019-06-22 02:29:36 | [diff] [blame] | 2346 | scope, first_party_url, script_url, context)) { |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2347 | return false; |
| 2348 | } |
| 2349 | #endif |
| 2350 | |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2351 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2352 | |
shimazu | ce8af8812 | 2016-10-06 23:49:21 | [diff] [blame] | 2353 | // Check if JavaScript is allowed. |
| 2354 | content_settings::SettingInfo info; |
| 2355 | std::unique_ptr<base::Value> value = |
| 2356 | io_data->GetHostContentSettingsMap()->GetWebsiteSetting( |
| 2357 | first_party_url, first_party_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 2358 | std::string(), &info); |
| 2359 | ContentSetting setting = content_settings::ValueToContentSetting(value.get()); |
| 2360 | bool allow_javascript = (setting == CONTENT_SETTING_ALLOW); |
| 2361 | |
| 2362 | // Check if cookies are allowed. |
| 2363 | bool allow_serviceworker = |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 2364 | io_data->GetCookieSettings()->IsCookieAccessAllowed(scope, |
| 2365 | first_party_url); |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2366 | // Record access to database for potential display in UI. |
yzshen | bc36c97 | 2016-12-21 21:39:24 | [diff] [blame] | 2367 | // Only post the task if this is for a specific tab. |
| 2368 | if (!wc_getter.is_null()) { |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 2369 | base::PostTask( |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 2370 | FROM_HERE, {BrowserThread::UI}, |
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 2371 | base::BindOnce(&TabSpecificContentSettings::ServiceWorkerAccessed, |
tzik | df81f14 | 2018-10-26 00:23:34 | [diff] [blame] | 2372 | std::move(wc_getter), scope, !allow_javascript, |
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 2373 | !allow_serviceworker)); |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2374 | } |
shimazu | ce8af8812 | 2016-10-06 23:49:21 | [diff] [blame] | 2375 | return allow_javascript && allow_serviceworker; |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2376 | } |
| 2377 | |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2378 | bool ChromeContentBrowserClient::AllowServiceWorkerOnUI( |
| 2379 | const GURL& scope, |
| 2380 | const GURL& first_party_url, |
| 2381 | const GURL& script_url, |
| 2382 | content::BrowserContext* context, |
| 2383 | base::RepeatingCallback<content::WebContents*()> wc_getter) { |
| 2384 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2385 | |
| 2386 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2387 | // Check if this is an extension-related service worker, and, if so, if it's |
| 2388 | // allowed (this can return false if, e.g., the extension is disabled). |
| 2389 | // If it's not allowed, return immediately. We deliberately do *not* report |
| 2390 | // to the TabSpecificContentSettings, since the service worker is blocked |
| 2391 | // because of the extension, rather than because of the user's content |
| 2392 | // settings. |
| 2393 | if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI( |
| 2394 | scope, first_party_url, script_url, context)) { |
| 2395 | return false; |
| 2396 | } |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2397 | #endif |
| 2398 | |
| 2399 | Profile* profile = Profile::FromBrowserContext(context); |
| 2400 | |
| 2401 | // Check if JavaScript is allowed. |
| 2402 | content_settings::SettingInfo info; |
| 2403 | std::unique_ptr<base::Value> value = |
| 2404 | HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting( |
| 2405 | first_party_url, first_party_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 2406 | std::string(), &info); |
| 2407 | ContentSetting setting = content_settings::ValueToContentSetting(value.get()); |
| 2408 | bool allow_javascript = (setting == CONTENT_SETTING_ALLOW); |
| 2409 | |
| 2410 | // Check if cookies are allowed. |
| 2411 | bool allow_cookies = |
| 2412 | CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed( |
| 2413 | scope, first_party_url); |
| 2414 | |
| 2415 | // Record access to database for potential display in UI. |
| 2416 | // Only post the task if this is for a specific tab. |
| 2417 | if (!wc_getter.is_null()) { |
| 2418 | TabSpecificContentSettings::ServiceWorkerAccessed( |
| 2419 | std::move(wc_getter), scope, !allow_javascript, !allow_cookies); |
| 2420 | } |
| 2421 | return allow_javascript && allow_cookies; |
| 2422 | } |
| 2423 | |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2424 | bool ChromeContentBrowserClient::AllowSharedWorker( |
| 2425 | const GURL& worker_url, |
| 2426 | const GURL& main_frame_url, |
| 2427 | const std::string& name, |
Hiroki Nakagawa | 018bb6d | 2017-11-30 03:31:37 | [diff] [blame] | 2428 | const url::Origin& constructor_origin, |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2429 | content::BrowserContext* context, |
| 2430 | int render_process_id, |
| 2431 | int render_frame_id) { |
| 2432 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2433 | |
| 2434 | // Check if cookies are allowed. |
| 2435 | bool allow = |
| 2436 | CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context)) |
| 2437 | ->IsCookieAccessAllowed(worker_url, main_frame_url); |
| 2438 | |
| 2439 | TabSpecificContentSettings::SharedWorkerAccessed( |
Hiroki Nakagawa | 018bb6d | 2017-11-30 03:31:37 | [diff] [blame] | 2440 | render_process_id, render_frame_id, worker_url, name, constructor_origin, |
| 2441 | !allow); |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2442 | return allow; |
| 2443 | } |
| 2444 | |
Clark DuVall | ab63d14 | 2019-07-23 04:24:36 | [diff] [blame] | 2445 | bool ChromeContentBrowserClient::AllowSignedExchange( |
| 2446 | content::BrowserContext* browser_context) { |
| 2447 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2448 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2449 | return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled); |
| 2450 | } |
| 2451 | |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2452 | void ChromeContentBrowserClient::AllowWorkerFileSystem( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2453 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2454 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2455 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2456 | base::OnceCallback<void(bool)> callback) { |
| 2457 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2458 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 2459 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2460 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2461 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2462 | GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2463 | #else |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2464 | FileSystemAccessed(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2465 | #endif |
| 2466 | } |
| 2467 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2468 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2469 | void ChromeContentBrowserClient::GuestPermissionRequestHelper( |
| 2470 | const GURL& url, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2471 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2472 | base::OnceCallback<void(bool)> callback, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2473 | bool allow) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2474 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2475 | std::map<int, int> process_map; |
| 2476 | std::map<int, int>::const_iterator it; |
| 2477 | bool has_web_view_guest = false; |
| 2478 | // Record access to file system for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2479 | for (const auto& it : render_frames) { |
| 2480 | if (process_map.find(it.child_id) != process_map.end()) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2481 | continue; |
| 2482 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2483 | 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] | 2484 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2485 | if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id)) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2486 | has_web_view_guest = true; |
| 2487 | } |
| 2488 | if (!has_web_view_guest) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2489 | FileSystemAccessed(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2490 | return; |
| 2491 | } |
[email protected] | dffb9fc | 2014-07-16 04:14:02 | [diff] [blame] | 2492 | DCHECK_EQ(1U, process_map.size()); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2493 | it = process_map.begin(); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2494 | |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 2495 | extensions::WebViewPermissionHelper* web_view_permission_helper = |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2496 | extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second); |
| 2497 | web_view_permission_helper->RequestFileSystemPermission( |
| 2498 | url, allow, |
| 2499 | base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed, |
| 2500 | weak_factory_.GetWeakPtr(), url, render_frames, |
| 2501 | std::move(callback))); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2502 | } |
| 2503 | #endif |
| 2504 | |
| 2505 | void ChromeContentBrowserClient::FileSystemAccessed( |
| 2506 | const GURL& url, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2507 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2508 | base::OnceCallback<void(bool)> callback, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2509 | bool allow) { |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 2510 | // Record access to file system for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2511 | for (const auto& it : render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2512 | TabSpecificContentSettings::FileSystemAccessed( |
| 2513 | it.child_id, it.frame_routing_id, url, !allow); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2514 | } |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2515 | std::move(callback).Run(allow); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2516 | } |
| 2517 | |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2518 | bool ChromeContentBrowserClient::AllowWorkerIndexedDB( |
| 2519 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2520 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2521 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2522 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2523 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
| 2524 | |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 2525 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2526 | |
| 2527 | // Record access to IndexedDB for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2528 | for (const auto& it : render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2529 | TabSpecificContentSettings::IndexedDBAccessed( |
| 2530 | it.child_id, it.frame_routing_id, url, !allow); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | return allow; |
| 2534 | } |
| 2535 | |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2536 | bool ChromeContentBrowserClient::AllowWorkerCacheStorage( |
| 2537 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2538 | content::BrowserContext* browser_context, |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2539 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2540 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2541 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2542 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
| 2543 | |
| 2544 | // Record access to CacheStorage for potential display in UI. |
| 2545 | for (const auto& it : render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2546 | TabSpecificContentSettings::CacheStorageAccessed( |
| 2547 | it.child_id, it.frame_routing_id, url, !allow); |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2548 | } |
| 2549 | |
| 2550 | return allow; |
| 2551 | } |
| 2552 | |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2553 | ChromeContentBrowserClient::AllowWebBluetoothResult |
| 2554 | ChromeContentBrowserClient::AllowWebBluetooth( |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2555 | content::BrowserContext* browser_context, |
| 2556 | const url::Origin& requesting_origin, |
| 2557 | const url::Origin& embedding_origin) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2558 | // TODO(crbug.com/598890): Don't disable if |
| 2559 | // base::CommandLine::ForCurrentProcess()-> |
| 2560 | // HasSwitch(switches::kEnableWebBluetooth) is true. |
| 2561 | if (variations::GetVariationParamValue( |
| 2562 | PermissionContextBase::kPermissionsKillSwitchFieldStudy, |
| 2563 | "Bluetooth") == |
| 2564 | PermissionContextBase::kPermissionsKillSwitchBlockedValue) { |
| 2565 | // The kill switch is enabled for this permission. Block requests. |
| 2566 | return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED; |
| 2567 | } |
| 2568 | |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2569 | const HostContentSettingsMap* const content_settings = |
| 2570 | HostContentSettingsMapFactory::GetForProfile( |
| 2571 | Profile::FromBrowserContext(browser_context)); |
| 2572 | |
csharrison | aec2c54 | 2016-10-12 19:40:36 | [diff] [blame] | 2573 | if (content_settings->GetContentSetting( |
| 2574 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
| 2575 | CONTENT_SETTINGS_TYPE_BLUETOOTH_GUARD, |
| 2576 | std::string()) == CONTENT_SETTING_BLOCK) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2577 | return AllowWebBluetoothResult::BLOCK_POLICY; |
| 2578 | } |
| 2579 | return AllowWebBluetoothResult::ALLOW; |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2580 | } |
| 2581 | |
beaufort.francois | 01135bf | 2016-11-23 14:37:36 | [diff] [blame] | 2582 | std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() { |
| 2583 | return variations::GetVariationParamValue("WebBluetoothBlocklist", |
| 2584 | "blocklist_additions"); |
scheib | 7425032 | 2016-04-07 03:32:21 | [diff] [blame] | 2585 | } |
| 2586 | |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 2587 | #if defined(OS_CHROMEOS) |
John Abd-El-Malek | a5b1a5d60 | 2018-11-05 19:20:52 | [diff] [blame] | 2588 | void ChromeContentBrowserClient::OnTrustAnchorUsed( |
John Abd-El-Malek | 35bfaa5 | 2019-08-20 16:22:07 | [diff] [blame] | 2589 | content::BrowserContext* browser_context) { |
| 2590 | user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 2591 | if (user_manager) { |
| 2592 | const user_manager::User* user = |
| 2593 | chromeos::ProfileHelper::Get()->GetUserByProfile( |
| 2594 | Profile::FromBrowserContext(browser_context)); |
| 2595 | if (user && !user->username_hash().empty()) { |
| 2596 | policy::PolicyCertServiceFactory::SetUsedPolicyCertificates( |
| 2597 | user->username_hash()); |
| 2598 | } |
| 2599 | } |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 2600 | } |
| 2601 | #endif |
| 2602 | |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2603 | scoped_refptr<network::SharedURLLoaderFactory> |
| 2604 | ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() { |
Min Qin | da0d55b | 2018-10-12 18:30:05 | [diff] [blame] | 2605 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 2606 | !BrowserThread::IsThreadInitialized(BrowserThread::UI)); |
| 2607 | |
| 2608 | if (!SystemNetworkContextManager::GetInstance()) |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2609 | return nullptr; |
| 2610 | |
Min Qin | da0d55b | 2018-10-12 18:30:05 | [diff] [blame] | 2611 | return SystemNetworkContextManager::GetInstance() |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2612 | ->GetSharedURLLoaderFactory(); |
Andrew Moylan | 8673dba | 2017-10-10 04:29:04 | [diff] [blame] | 2613 | } |
| 2614 | |
Sean Gilhuly | da1ee4b | 2018-11-13 21:56:09 | [diff] [blame] | 2615 | network::mojom::NetworkContext* |
| 2616 | ChromeContentBrowserClient::GetSystemNetworkContext() { |
| 2617 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2618 | DCHECK(g_browser_process->system_network_context_manager()); |
| 2619 | return g_browser_process->system_network_context_manager()->GetContext(); |
| 2620 | } |
| 2621 | |
Andrew Moylan | 17329fc | 2017-09-25 07:43:30 | [diff] [blame] | 2622 | std::string ChromeContentBrowserClient::GetGeolocationApiKey() { |
| 2623 | return google_apis::GetAPIKey(); |
| 2624 | } |
| 2625 | |
Ke He | 21ee87f | 2018-05-30 02:35:32 | [diff] [blame] | 2626 | #if defined(OS_ANDROID) |
| 2627 | bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() { |
| 2628 | // Indicate that Chrome uses the GMS core location provider. |
| 2629 | return true; |
| 2630 | } |
| 2631 | #endif |
| 2632 | |
Yeol | f3dc22ca | 2019-04-18 17:25:32 | [diff] [blame] | 2633 | scoped_refptr<content::QuotaPermissionContext> |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 2634 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
| 2635 | return new ChromeQuotaPermissionContext(); |
| 2636 | } |
| 2637 | |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 2638 | void ChromeContentBrowserClient::GetQuotaSettings( |
| 2639 | content::BrowserContext* context, |
| 2640 | content::StoragePartition* partition, |
tapted | e6d878e | 2017-06-24 01:53:45 | [diff] [blame] | 2641 | storage::OptionalQuotaSettingsCallback callback) { |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 2642 | if (g_default_quota_settings) { |
| 2643 | // For debugging tests harness can inject settings. |
tapted | e6d878e | 2017-06-24 01:53:45 | [diff] [blame] | 2644 | std::move(callback).Run(*g_default_quota_settings); |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 2645 | return; |
| 2646 | } |
tapted | e6d878e | 2017-06-24 01:53:45 | [diff] [blame] | 2647 | storage::GetNominalDynamicSettings( |
Jarryd | 451ab7b | 2019-02-12 06:39:06 | [diff] [blame] | 2648 | partition->GetPath(), context->IsOffTheRecord(), |
| 2649 | storage::GetDefaultDiskInfoHelper(), std::move(callback)); |
calamity | c96116b | 2015-11-03 04:30:51 | [diff] [blame] | 2650 | } |
| 2651 | |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 2652 | content::GeneratedCodeCacheSettings |
| 2653 | ChromeContentBrowserClient::GetGeneratedCodeCacheSettings( |
| 2654 | content::BrowserContext* context) { |
| 2655 | base::FilePath cache_path; |
| 2656 | chrome::GetUserCacheDirectory(context->GetPath(), &cache_path); |
| 2657 | // If we pass 0 for size, disk_cache will pick a default size using the |
| 2658 | // heuristics based on available disk size. These are implemented in |
| 2659 | // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc. |
Mythri A | b248657 | 2019-06-13 14:48:16 | [diff] [blame] | 2660 | int64_t size_in_bytes = 0; |
Greg Thompson | 8c922756 | 2019-08-05 17:47:13 | [diff] [blame] | 2661 | DCHECK(g_browser_process); |
| 2662 | PrefService* local_state = g_browser_process->local_state(); |
| 2663 | if (local_state) { |
| 2664 | size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize); |
| 2665 | base::FilePath disk_cache_dir = |
| 2666 | local_state->GetFilePath(prefs::kDiskCacheDir); |
| 2667 | if (!disk_cache_dir.empty()) |
| 2668 | cache_path = disk_cache_dir.Append(cache_path.BaseName()); |
| 2669 | } |
Mythri A | b248657 | 2019-06-13 14:48:16 | [diff] [blame] | 2670 | return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path); |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 2671 | } |
| 2672 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 2673 | void ChromeContentBrowserClient::AllowCertificateError( |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2674 | content::WebContents* web_contents, |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 2675 | int cert_error, |
| 2676 | const net::SSLInfo& ssl_info, |
| 2677 | const GURL& request_url, |
John Abd-El-Malek | c5b8df91 | 2019-05-07 17:02:23 | [diff] [blame] | 2678 | bool is_main_frame_request, |
[email protected] | d9be4770 | 2012-05-16 03:41:22 | [diff] [blame] | 2679 | bool strict_enforcement, |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2680 | const base::Callback<void(content::CertificateRequestResultType)>& |
| 2681 | callback) { |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2682 | DCHECK(web_contents); |
John Abd-El-Malek | c5b8df91 | 2019-05-07 17:02:23 | [diff] [blame] | 2683 | if (!is_main_frame_request) { |
irisu | 8452ddd6 | 2017-03-22 07:46:14 | [diff] [blame] | 2684 | // A sub-resource has a certificate error. The user doesn't really |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 2685 | // have a context for making the right decision, so block the |
| 2686 | // request hard, without an info bar to allow showing the insecure |
| 2687 | // content. |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2688 | if (!callback.is_null()) |
| 2689 | callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 2690 | return; |
| 2691 | } |
| 2692 | |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 2693 | // If the tab is being prerendered, cancel the prerender and the request. |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2694 | prerender::PrerenderContents* prerender_contents = |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2695 | prerender::PrerenderContents::FromWebContents(web_contents); |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2696 | if (prerender_contents) { |
| 2697 | prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR); |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2698 | if (!callback.is_null()) { |
| 2699 | callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL); |
| 2700 | } |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2701 | return; |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 2702 | } |
| 2703 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 2704 | callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
| 2705 | return; |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 2706 | } |
| 2707 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2708 | namespace { |
| 2709 | |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2710 | certificate_matching::CertificatePrincipalPattern |
| 2711 | ParseCertificatePrincipalPattern(const base::Value* pattern) { |
| 2712 | return certificate_matching::CertificatePrincipalPattern:: |
| 2713 | ParseFromOptionalDict(pattern, "CN", "L", "O", "OU"); |
| 2714 | } |
| 2715 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2716 | // Attempts to auto-select a client certificate according to the value of |
| 2717 | // |CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE| content setting for |
| 2718 | // |requesting_url|. If no certificate was auto-selected, returns nullptr. |
| 2719 | std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate( |
| 2720 | Profile* profile, |
| 2721 | const GURL& requesting_url, |
| 2722 | net::ClientCertIdentityList& client_certs) { |
| 2723 | HostContentSettingsMap* host_content_settings_map = |
| 2724 | HostContentSettingsMapFactory::GetForProfile(profile); |
| 2725 | std::unique_ptr<base::Value> setting = |
| 2726 | host_content_settings_map->GetWebsiteSetting( |
| 2727 | requesting_url, requesting_url, |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2728 | CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), |
| 2729 | nullptr); |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2730 | |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2731 | if (!setting || !setting->is_dict()) |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2732 | return nullptr; |
| 2733 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2734 | const base::Value* filters = |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2735 | setting->FindKeyOfType("filters", base::Value::Type::LIST); |
| 2736 | if (!filters) { |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2737 | // |setting_dict| has the wrong format (e.g. single filter instead of a |
| 2738 | // list of filters). This content setting is only provided by |
| 2739 | // the |PolicyProvider|, which should always set it to a valid format. |
| 2740 | // Therefore, delete the invalid value. |
| 2741 | host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 2742 | requesting_url, requesting_url, |
| 2743 | CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), nullptr); |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2744 | return nullptr; |
| 2745 | } |
| 2746 | |
| 2747 | for (const base::Value& filter : filters->GetList()) { |
| 2748 | DCHECK(filter.is_dict()); |
| 2749 | |
| 2750 | auto issuer_pattern = ParseCertificatePrincipalPattern( |
| 2751 | filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY)); |
| 2752 | auto subject_pattern = ParseCertificatePrincipalPattern( |
| 2753 | filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY)); |
| 2754 | // Use the first certificate that is matched by the filter. |
| 2755 | for (auto& client_cert : client_certs) { |
| 2756 | if (issuer_pattern.Matches(client_cert->certificate()->issuer()) && |
| 2757 | subject_pattern.Matches(client_cert->certificate()->subject())) { |
| 2758 | return std::move(client_cert); |
| 2759 | } |
| 2760 | } |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2761 | } |
| 2762 | |
| 2763 | return nullptr; |
| 2764 | } |
| 2765 | |
Eric Roman | a00cf68 | 2018-11-01 20:09:11 | [diff] [blame] | 2766 | void AddDataReductionProxyBinding( |
Clark DuVall | 812e07d | 2019-08-26 18:34:56 | [diff] [blame] | 2767 | int render_process_id, |
Eric Roman | a00cf68 | 2018-11-01 20:09:11 | [diff] [blame] | 2768 | data_reduction_proxy::mojom::DataReductionProxyRequest request) { |
Clark DuVall | 0e90172 | 2019-08-14 23:31:37 | [diff] [blame] | 2769 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Clark DuVall | 812e07d | 2019-08-26 18:34:56 | [diff] [blame] | 2770 | auto* rph = content::RenderProcessHost::FromID(render_process_id); |
| 2771 | if (!rph) |
| 2772 | return; |
| 2773 | |
Clark DuVall | 0e90172 | 2019-08-14 23:31:37 | [diff] [blame] | 2774 | auto* drp_settings = |
| 2775 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
Clark DuVall | 812e07d | 2019-08-26 18:34:56 | [diff] [blame] | 2776 | rph->GetBrowserContext()); |
Clark DuVall | 0e90172 | 2019-08-14 23:31:37 | [diff] [blame] | 2777 | if (!drp_settings) |
| 2778 | return; |
| 2779 | |
| 2780 | drp_settings->data_reduction_proxy_service()->Clone(std::move(request)); |
Eric Roman | a00cf68 | 2018-11-01 20:09:11 | [diff] [blame] | 2781 | } |
| 2782 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2783 | } // namespace |
| 2784 | |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2785 | base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate( |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2786 | content::WebContents* web_contents, |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 2787 | net::SSLCertRequestInfo* cert_request_info, |
mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 2788 | net::ClientCertIdentityList client_certs, |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2789 | std::unique_ptr<content::ClientCertificateDelegate> delegate) { |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 2790 | prerender::PrerenderContents* prerender_contents = |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2791 | prerender::PrerenderContents::FromWebContents(web_contents); |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 2792 | if (prerender_contents) { |
| 2793 | prerender_contents->Destroy( |
| 2794 | prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2795 | return base::OnceClosure(); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 2796 | } |
| 2797 | |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 2798 | GURL requesting_url("https://" + cert_request_info->host_and_port.ToString()); |
| 2799 | DCHECK(requesting_url.is_valid()) |
| 2800 | << "Invalid URL string: https://" |
| 2801 | << cert_request_info->host_and_port.ToString(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 2802 | |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2803 | bool may_show_cert_selection = true; |
| 2804 | |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2805 | Profile* profile = |
| 2806 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2807 | #if defined(OS_CHROMEOS) |
| 2808 | if (chromeos::ProfileHelper::IsSigninProfile(profile)) { |
| 2809 | // TODO(pmarko): crbug.com/723849: Set |may_show_cert_selection| to false |
| 2810 | // and remove the command-line flag after prototype phase when the |
| 2811 | // DeviceLoginScreenAutoSelectCertificateForUrls policy is live. |
| 2812 | may_show_cert_selection = |
| 2813 | chromeos::switches::IsSigninFrameClientCertUserSelectionEnabled(); |
| 2814 | |
| 2815 | content::StoragePartition* storage_partition = |
| 2816 | content::BrowserContext::GetStoragePartition( |
| 2817 | profile, web_contents->GetSiteInstance()); |
| 2818 | chromeos::login::SigninPartitionManager* signin_partition_manager = |
| 2819 | chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext( |
| 2820 | profile); |
| 2821 | |
| 2822 | // On the sign-in profile, only allow client certs in the context of the |
| 2823 | // sign-in frame. |
| 2824 | if (!signin_partition_manager->IsCurrentSigninStoragePartition( |
| 2825 | storage_partition)) { |
| 2826 | LOG(WARNING) |
| 2827 | << "Client cert requested in sign-in profile in wrong context."; |
| 2828 | // Continue without client certificate. We do this to mimic the case of no |
| 2829 | // client certificate being present in the profile's certificate store. |
| 2830 | delegate->ContinueWithCertificate(nullptr, nullptr); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2831 | return base::OnceClosure(); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2832 | } |
| 2833 | VLOG(1) << "Client cert requested in sign-in profile."; |
| 2834 | } |
| 2835 | #endif // defined(OS_CHROMEOS) |
| 2836 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2837 | std::unique_ptr<net::ClientCertIdentity> auto_selected_identity = |
| 2838 | AutoSelectCertificate(profile, requesting_url, client_certs); |
| 2839 | if (auto_selected_identity) { |
| 2840 | // The callback will own |auto_selected_identity| and |delegate|, keeping |
| 2841 | // them alive until after ContinueWithCertificate is called. |
| 2842 | scoped_refptr<net::X509Certificate> cert = |
| 2843 | auto_selected_identity->certificate(); |
| 2844 | net::ClientCertIdentity::SelfOwningAcquirePrivateKey( |
| 2845 | std::move(auto_selected_identity), |
David Benjamin | 0cda204 | 2019-04-08 23:00:58 | [diff] [blame] | 2846 | base::BindOnce( |
| 2847 | &content::ClientCertificateDelegate::ContinueWithCertificate, |
| 2848 | std::move(delegate), std::move(cert))); |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 2849 | LogClientAuthResult(ClientCertSelectionResult::kAutoSelect); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2850 | return base::OnceClosure(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 2851 | } |
| 2852 | |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2853 | if (!may_show_cert_selection) { |
| 2854 | LOG(WARNING) << "No client cert matched by policy and user selection is " |
| 2855 | "not allowed."; |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 2856 | LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2857 | // Continue without client certificate. We do this to mimic the case of no |
| 2858 | // client certificate being present in the profile's certificate store. |
| 2859 | delegate->ContinueWithCertificate(nullptr, nullptr); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2860 | return base::OnceClosure(); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2861 | } |
| 2862 | |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2863 | return chrome::ShowSSLClientCertificateSelector( |
| 2864 | web_contents, cert_request_info, std::move(client_certs), |
| 2865 | std::move(delegate)); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 2866 | } |
| 2867 | |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 2868 | content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { |
[email protected] | 11158e2d | 2013-02-01 02:31:56 | [diff] [blame] | 2869 | return MediaCaptureDevicesDispatcher::GetInstance(); |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 2870 | } |
| 2871 | |
peter | c26c6c6 | 2014-12-10 14:13:59 | [diff] [blame] | 2872 | content::PlatformNotificationService* |
Richard Knoll | d0eae96 | 2019-04-04 12:34:02 | [diff] [blame] | 2873 | ChromeContentBrowserClient::GetPlatformNotificationService( |
| 2874 | content::BrowserContext* browser_context) { |
| 2875 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2876 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2877 | return PlatformNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2878 | } |
| 2879 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2880 | bool ChromeContentBrowserClient::CanCreateWindow( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2881 | RenderFrameHost* opener, |
[email protected] | 2b751a1 | 2012-03-06 03:00:35 | [diff] [blame] | 2882 | const GURL& opener_url, |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 2883 | const GURL& opener_top_level_frame_url, |
Nasko Oskov | e9f1978 | 2019-01-04 18:32:35 | [diff] [blame] | 2884 | const url::Origin& source_origin, |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 2885 | content::mojom::WindowContainerType container_type, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2886 | const GURL& target_url, |
| 2887 | const content::Referrer& referrer, |
jochen | 67b271b | 2016-08-03 13:50:21 | [diff] [blame] | 2888 | const std::string& frame_name, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2889 | WindowOpenDisposition disposition, |
scottmg | 8e6c608 | 2017-02-13 23:15:48 | [diff] [blame] | 2890 | const blink::mojom::WindowFeatures& features, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2891 | bool user_gesture, |
| 2892 | bool opener_suppressed, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2893 | bool* no_javascript_access) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2894 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2895 | DCHECK(opener); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2896 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2897 | content::WebContents* web_contents = |
| 2898 | content::WebContents::FromRenderFrameHost(opener); |
| 2899 | Profile* profile = |
| 2900 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 2901 | DCHECK(profile); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2902 | *no_javascript_access = false; |
| 2903 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2904 | // If the opener is trying to create a background window but doesn't have |
| 2905 | // the appropriate permission, fail the attempt. |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 2906 | if (container_type == content::mojom::WindowContainerType::BACKGROUND) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2907 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2908 | auto* process_map = extensions::ProcessMap::Get(profile); |
| 2909 | auto* registry = extensions::ExtensionRegistry::Get(profile); |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 2910 | if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url, |
| 2911 | opener->GetProcess()->GetID())) { |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2912 | return false; |
| 2913 | } |
| 2914 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 2915 | // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may |
| 2916 | // return a recently installed Extension even if this CanCreateWindow call |
| 2917 | // 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] | 2918 | // because the permission check above would have caused an early return |
| 2919 | // already. We must use the full URL to find hosted apps, though, and not |
| 2920 | // just the origin. |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 2921 | const Extension* extension = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2922 | registry->enabled_extensions().GetExtensionOrAppByURL(opener_url); |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 2923 | if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2924 | *no_javascript_access = true; |
[email protected] | dffb9fc | 2014-07-16 04:14:02 | [diff] [blame] | 2925 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2926 | |
| 2927 | return true; |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2928 | } |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 2929 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2930 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 2931 | if (extensions::WebViewRendererState::GetInstance()->IsGuest( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2932 | opener->GetProcess()->GetID())) { |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2933 | return true; |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 2934 | } |
| 2935 | |
nick | 0fbc392 | 2016-12-16 20:52:07 | [diff] [blame] | 2936 | if (target_url.SchemeIs(extensions::kExtensionScheme)) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2937 | // Intentionally duplicating |registry| code from above because we want to |
| 2938 | // reduce calls to retrieve them as this function is a SYNC IPC handler. |
| 2939 | auto* registry = extensions::ExtensionRegistry::Get(profile); |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 2940 | const Extension* extension = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2941 | registry->enabled_extensions().GetExtensionOrAppByURL(target_url); |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 2942 | if (extension && extension->is_platform_app()) { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 2943 | UMA_HISTOGRAM_ENUMERATION( |
| 2944 | "Extensions.AppLoadedInTab", |
| 2945 | ClassifyAppLoadedInTabSource(opener_url, extension), |
| 2946 | APP_LOADED_IN_TAB_SOURCE_MAX); |
| 2947 | |
| 2948 | // window.open() may not be used to load v2 apps in a regular tab. |
lazyboy | 39585ed | 2016-12-06 19:30:16 | [diff] [blame] | 2949 | return false; |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 2950 | } |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 2951 | } |
[email protected] | 5940b0d | 2014-07-01 00:18:26 | [diff] [blame] | 2952 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2953 | |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 2954 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2955 | HostContentSettingsMap* content_settings = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2956 | HostContentSettingsMapFactory::GetForProfile(profile); |
tommycli | 61f6f0c | 2016-09-21 00:26:58 | [diff] [blame] | 2957 | if (FlashDownloadInterception::ShouldStopFlashDownloadAction( |
| 2958 | content_settings, opener_top_level_frame_url, target_url, |
| 2959 | user_gesture)) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2960 | FlashDownloadInterception::InterceptFlashDownloadNavigation( |
| 2961 | web_contents, opener_top_level_frame_url); |
tommycli | 61f6f0c | 2016-09-21 00:26:58 | [diff] [blame] | 2962 | return false; |
| 2963 | } |
| 2964 | #endif |
| 2965 | |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 2966 | // Don't let prerenders open popups. |
| 2967 | if (auto* prerender_contents = |
| 2968 | prerender::PrerenderContents::FromWebContents(web_contents)) { |
| 2969 | prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW); |
| 2970 | return false; |
| 2971 | } |
| 2972 | |
Nasko Oskov | e9f1978 | 2019-01-04 18:32:35 | [diff] [blame] | 2973 | BlockedWindowParams blocked_params(target_url, source_origin, referrer, |
| 2974 | frame_name, disposition, features, |
| 2975 | user_gesture, opener_suppressed); |
cm.sanchi | 2522bc9 | 2017-12-04 08:04:13 | [diff] [blame] | 2976 | NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents); |
Charlie Harrison | 804659a | 2018-10-16 16:43:38 | [diff] [blame] | 2977 | if (MaybeBlockPopup(web_contents, opener_top_level_frame_url, &nav_params, |
| 2978 | nullptr /*=open_url_params*/, |
| 2979 | blocked_params.features())) { |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 2980 | return false; |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2981 | } |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2982 | return true; |
| 2983 | } |
| 2984 | |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 2985 | content::SpeechRecognitionManagerDelegate* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2986 | ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() { |
[email protected] | 855e18b | 2013-07-08 21:02:00 | [diff] [blame] | 2987 | return new speech::ChromeSpeechRecognitionManagerDelegate(); |
[email protected] | 66cfec6 | 2012-02-24 17:57:51 | [diff] [blame] | 2988 | } |
| 2989 | |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 2990 | content::TtsControllerDelegate* |
| 2991 | ChromeContentBrowserClient::GetTtsControllerDelegate() { |
| 2992 | TtsControllerDelegateImpl* delegate = |
| 2993 | TtsControllerDelegateImpl::GetInstance(); |
| 2994 | #if !defined(OS_ANDROID) |
| 2995 | TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance(); |
| 2996 | delegate->SetTtsEngineDelegate(tts_extension_engine); |
| 2997 | #endif |
| 2998 | return delegate; |
| 2999 | } |
| 3000 | |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 3001 | content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() { |
| 3002 | #ifdef OS_CHROMEOS |
| 3003 | return TtsPlatformImplChromeOs::GetInstance(); |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 3004 | #else |
| 3005 | return nullptr; |
| 3006 | #endif |
| 3007 | } |
| 3008 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3009 | void ChromeContentBrowserClient::OverrideWebkitPrefs( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3010 | RenderViewHost* rvh, |
| 3011 | WebPreferences* web_prefs) { |
| 3012 | Profile* profile = |
| 3013 | Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3014 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3015 | |
aelias | 0df335a | 2017-03-02 23:43:51 | [diff] [blame] | 3016 | // Fill font preferences. These are not registered on Android |
| 3017 | // - http://crbug.com/308033, http://crbug.com/696364. |
[email protected] | 33b7954 | 2013-10-18 11:18:45 | [diff] [blame] | 3018 | #if !defined(OS_ANDROID) |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3019 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3020 | prefs::kWebKitStandardFontFamilyMap, |
| 3021 | &web_prefs->standard_font_family_map); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3022 | FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap, |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3023 | &web_prefs->fixed_font_family_map); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3024 | FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap, |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3025 | &web_prefs->serif_font_family_map); |
| 3026 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3027 | prefs::kWebKitSansSerifFontFamilyMap, |
| 3028 | &web_prefs->sans_serif_font_family_map); |
| 3029 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3030 | prefs::kWebKitCursiveFontFamilyMap, |
| 3031 | &web_prefs->cursive_font_family_map); |
| 3032 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3033 | prefs::kWebKitFantasyFontFamilyMap, |
| 3034 | &web_prefs->fantasy_font_family_map); |
| 3035 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3036 | prefs::kWebKitPictographFontFamilyMap, |
| 3037 | &web_prefs->pictograph_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3038 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3039 | web_prefs->default_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3040 | prefs->GetInteger(prefs::kWebKitDefaultFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3041 | web_prefs->default_fixed_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3042 | prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3043 | web_prefs->minimum_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3044 | prefs->GetInteger(prefs::kWebKitMinimumFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3045 | web_prefs->minimum_logical_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3046 | prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize); |
aelias | 0df335a | 2017-03-02 23:43:51 | [diff] [blame] | 3047 | #endif |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3048 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3049 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3050 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3051 | web_prefs->dom_paste_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3052 | prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); |
Joel Hockey | 08a6c84c | 2018-04-11 10:09:21 | [diff] [blame] | 3053 | web_prefs->javascript_can_access_clipboard = |
| 3054 | prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3055 | web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3056 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3057 | if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3058 | web_prefs->javascript_enabled = false; |
mkwst | a1f7749b | 2015-12-28 09:28:57 | [diff] [blame] | 3059 | |
Avi Drissman | 1aa6cb9 | 2019-01-23 15:58:38 | [diff] [blame] | 3060 | if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3061 | web_prefs->web_security_enabled = false; |
mkwst | a1f7749b | 2015-12-28 09:28:57 | [diff] [blame] | 3062 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3063 | if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3064 | web_prefs->plugins_enabled = false; |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3065 | web_prefs->loads_images_automatically = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3066 | prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3067 | |
Zhenyao Mo | a3fda997 | 2017-09-16 01:34:40 | [diff] [blame] | 3068 | if (prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 3069 | web_prefs->webgl1_enabled = false; |
| 3070 | web_prefs->webgl2_enabled = false; |
| 3071 | } |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3072 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3073 | web_prefs->allow_running_insecure_content = |
| 3074 | prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3075 | #if defined(OS_ANDROID) |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 3076 | web_prefs->font_scale_factor = |
| 3077 | static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor)); |
| 3078 | web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment(); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3079 | web_prefs->force_enable_zoom = |
| 3080 | prefs->GetBoolean(prefs::kWebKitForceEnableZoom); |
Aran Gilman | 5e9672bed | 2019-08-02 19:07:49 | [diff] [blame] | 3081 | #endif |
Becky Zhou | bbfbde3 | 2019-02-20 17:07:59 | [diff] [blame] | 3082 | web_prefs->force_dark_mode_enabled = |
| 3083 | prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled); |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 3084 | |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 3085 | #if defined(OS_ANDROID) |
| 3086 | web_prefs->password_echo_enabled = |
| 3087 | prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled); |
| 3088 | #else |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 3089 | web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled; |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 3090 | #endif |
| 3091 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3092 | web_prefs->text_areas_are_resizable = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3093 | prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3094 | web_prefs->hyperlink_auditing_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3095 | prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); |
| 3096 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3097 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 3098 | std::string image_animation_policy = |
| 3099 | prefs->GetString(prefs::kAnimationPolicy); |
| 3100 | if (image_animation_policy == kAnimationPolicyOnce) |
| 3101 | web_prefs->animation_policy = |
| 3102 | content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE; |
| 3103 | else if (image_animation_policy == kAnimationPolicyNone) |
| 3104 | web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION; |
| 3105 | else |
| 3106 | web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED; |
| 3107 | #endif |
| 3108 | |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3109 | // Make sure we will set the default_encoding with canonical encoding name. |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 3110 | web_prefs->default_encoding = |
| 3111 | base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3112 | if (web_prefs->default_encoding.empty()) { |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3113 | prefs->ClearPref(prefs::kDefaultCharset); |
| 3114 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3115 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3116 | DCHECK(!web_prefs->default_encoding.empty()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3117 | |
mkwst | 0554410 | 2015-01-10 20:26:16 | [diff] [blame] | 3118 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3119 | switches::kEnablePotentiallyAnnoyingSecurityFeatures)) { |
mkwst | 772ce814 | 2015-01-16 13:28:07 | [diff] [blame] | 3120 | web_prefs->disable_reading_from_canvas = true; |
mkwst | 0554410 | 2015-01-10 20:26:16 | [diff] [blame] | 3121 | web_prefs->strict_mixed_content_checking = true; |
| 3122 | web_prefs->strict_powerful_feature_restrictions = true; |
| 3123 | } |
| 3124 | |
Robert Ogden | cf2872d | 2019-03-19 18:59:37 | [diff] [blame] | 3125 | web_prefs->data_saver_enabled = IsDataSaverEnabled(profile); |
Ben Greenstein | 49878f5 | 2015-12-18 19:13:21 | [diff] [blame] | 3126 | |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 3127 | web_prefs->data_saver_holdback_web_api_enabled = |
| 3128 | base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback, |
| 3129 | "holdback_web", false); |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 3130 | |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3131 | auto* contents = content::WebContents::FromRenderViewHost(rvh); |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3132 | if (contents) { |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3133 | #if defined(OS_ANDROID) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3134 | auto* delegate = TabAndroid::FromWebContents(contents) |
| 3135 | ? static_cast<android::TabWebContentsDelegateAndroid*>( |
| 3136 | contents->GetDelegate()) |
| 3137 | : nullptr; |
| 3138 | if (delegate) { |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3139 | web_prefs->embedded_media_experience_enabled = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3140 | delegate->ShouldEnableEmbeddedMediaExperience(); |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3141 | |
Mounir Lamouri | 9c99a160 | 2018-07-05 15:01:44 | [diff] [blame] | 3142 | web_prefs->picture_in_picture_enabled = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3143 | delegate->IsPictureInPictureEnabled(); |
Rune Lillesveen | 17e4832 | 2019-04-15 23:12:38 | [diff] [blame] | 3144 | |
| 3145 | web_prefs->preferred_color_scheme = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3146 | delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark |
| 3147 | : blink::PreferredColorScheme::kLight; |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3148 | } |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3149 | #endif // defined(OS_ANDROID) |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3150 | |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3151 | // web_app_scope value is platform specific. |
| 3152 | #if defined(OS_ANDROID) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3153 | if (delegate) |
| 3154 | web_prefs->web_app_scope = delegate->GetManifestScope(); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3155 | #elif BUILDFLAG(ENABLE_EXTENSIONS) |
| 3156 | { |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3157 | web_prefs->web_app_scope = GURL(); |
| 3158 | // Set |web_app_scope| based on the app associated with the app window if |
| 3159 | // any. Note that the app associated with the window never changes, even |
| 3160 | // if the app navigates off scope. This is not a problem because we still |
| 3161 | // want to use the scope of the app associated with the window, not the |
| 3162 | // WebContents. |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3163 | Browser* browser = chrome::FindBrowserWithWebContents(contents); |
Alan Cutter | d0bd5190 | 2019-05-22 04:15:23 | [diff] [blame] | 3164 | if (browser && browser->app_controller() && |
Eric Willigers | e339c1e | 2019-05-13 19:22:44 | [diff] [blame] | 3165 | browser->app_controller()->CreatedForInstalledPwa()) { |
Yining Wang | 234ad327 | 2019-04-08 18:47:27 | [diff] [blame] | 3166 | // PWAs should be hosted apps. |
Eric Willigers | e339c1e | 2019-05-13 19:22:44 | [diff] [blame] | 3167 | DCHECK(browser->app_controller()->IsHostedApp()); |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3168 | // HostedApps that are PWAs are always created through WebAppProvider |
Alexey Baskakov | aca7a0c | 2019-07-29 07:34:05 | [diff] [blame] | 3169 | // for profiles that support them, so we should always be able to |
| 3170 | // retrieve a WebAppProvider from the Profile. |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3171 | // |
| 3172 | // 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] | 3173 | // so there is no need to test for has_value(). |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3174 | web_prefs->web_app_scope = |
| 3175 | web_app::WebAppProvider::Get(profile) |
| 3176 | ->registrar() |
Alan Cutter | f25cfe4 | 2019-07-16 02:40:12 | [diff] [blame] | 3177 | .GetAppScope(*browser->app_controller()->GetAppId()) |
| 3178 | .value(); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3179 | } |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3180 | } |
| 3181 | #endif |
| 3182 | |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3183 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 3184 | Browser* browser = chrome::FindBrowserWithWebContents(contents); |
Eric Willigers | e339c1e | 2019-05-13 19:22:44 | [diff] [blame] | 3185 | if (browser && browser->app_controller() && |
| 3186 | browser->app_controller()->CreatedForInstalledPwa()) { |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3187 | web_prefs->strict_mixed_content_checking = true; |
| 3188 | } |
| 3189 | #endif |
| 3190 | |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3191 | web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents); |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3192 | } |
zqzhang | 93e959d1 | 2017-03-16 13:10:20 | [diff] [blame] | 3193 | |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3194 | #if defined(OS_ANDROID) |
Ted Choc | 81c89fc5 | 2018-06-22 23:51:14 | [diff] [blame] | 3195 | web_prefs->video_fullscreen_detection_enabled = true; |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3196 | #endif // defined(OS_ANDROID) |
| 3197 | |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 3198 | if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) { |
| 3199 | // Obtain the maximum effective connection type at which the feature is |
| 3200 | // enabled. |
| 3201 | std::string effective_connection_type_param = |
| 3202 | base::GetFieldTrialParamValueByFeature( |
| 3203 | features::kLowPriorityIframes, |
| 3204 | "max_effective_connection_type_threshold"); |
| 3205 | |
| 3206 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3207 | net::GetEffectiveConnectionTypeForName(effective_connection_type_param); |
| 3208 | if (effective_connection_type) { |
| 3209 | web_prefs->low_priority_iframes_threshold = |
| 3210 | effective_connection_type.value(); |
| 3211 | } |
| 3212 | } |
| 3213 | |
rajendrant | 0521cee | 2019-07-29 06:09:26 | [diff] [blame] | 3214 | web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() || |
| 3215 | contents->GetDelegate()->ShouldAllowLazyLoad(); |
rajendrant | e87ed71 | 2018-11-30 01:55:00 | [diff] [blame] | 3216 | |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 3217 | if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) { |
| 3218 | const char* param_name = |
| 3219 | web_prefs->data_saver_enabled |
| 3220 | ? "lazy_frame_loading_distance_thresholds_px_by_ect" |
| 3221 | : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_" |
| 3222 | "saver_enabled"; |
| 3223 | |
| 3224 | base::StringPairs pairs; |
| 3225 | base::SplitStringIntoKeyValuePairs( |
| 3226 | base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading, |
| 3227 | param_name), |
| 3228 | ':', ',', &pairs); |
| 3229 | |
| 3230 | for (const auto& pair : pairs) { |
| 3231 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3232 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3233 | int value = 0; |
| 3234 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3235 | web_prefs->lazy_frame_loading_distance_thresholds_px |
| 3236 | [effective_connection_type.value()] = value; |
| 3237 | } |
| 3238 | } |
| 3239 | } |
| 3240 | |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 3241 | if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) { |
| 3242 | const char* param_name = |
| 3243 | web_prefs->data_saver_enabled |
| 3244 | ? "lazy_image_loading_distance_thresholds_px_by_ect" |
| 3245 | : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_" |
| 3246 | "saver_enabled"; |
| 3247 | |
| 3248 | base::StringPairs pairs; |
| 3249 | base::SplitStringIntoKeyValuePairs( |
| 3250 | base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading, |
| 3251 | param_name), |
| 3252 | ':', ',', &pairs); |
| 3253 | |
| 3254 | for (const auto& pair : pairs) { |
| 3255 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3256 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3257 | int value = 0; |
| 3258 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3259 | web_prefs->lazy_image_loading_distance_thresholds_px |
| 3260 | [effective_connection_type.value()] = value; |
| 3261 | } |
| 3262 | } |
| 3263 | } |
| 3264 | |
Tarun Bansal | d10f17a0 | 2018-09-13 00:23:17 | [diff] [blame] | 3265 | if (base::FeatureList::IsEnabled( |
| 3266 | features::kNetworkQualityEstimatorWebHoldback)) { |
| 3267 | std::string effective_connection_type_param = |
| 3268 | base::GetFieldTrialParamValueByFeature( |
| 3269 | features::kNetworkQualityEstimatorWebHoldback, |
| 3270 | "web_effective_connection_type_override"); |
| 3271 | |
| 3272 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3273 | net::GetEffectiveConnectionTypeForName(effective_connection_type_param); |
| 3274 | DCHECK(effective_connection_type_param.empty() || |
| 3275 | effective_connection_type); |
| 3276 | if (effective_connection_type) { |
| 3277 | DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 3278 | effective_connection_type.value()); |
| 3279 | web_prefs->network_quality_estimator_web_holdback = |
| 3280 | effective_connection_type.value(); |
| 3281 | } |
| 3282 | } |
| 3283 | |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 3284 | auto* native_theme = GetWebTheme(); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3285 | #if !defined(OS_ANDROID) |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 3286 | if (IsAutoplayAllowedByPolicy(contents, prefs)) { |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3287 | // If autoplay is allowed by policy then force the no user gesture required |
| 3288 | // autoplay policy. |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3289 | web_prefs->autoplay_policy = |
| 3290 | content::AutoplayPolicy::kNoUserGestureRequired; |
Mounir Lamouri | c2186808 | 2018-10-11 21:09:55 | [diff] [blame] | 3291 | } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) && |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3292 | web_prefs->autoplay_policy == |
| 3293 | content::AutoplayPolicy::kDocumentUserActivationRequired) { |
Mounir Lamouri | c2186808 | 2018-10-11 21:09:55 | [diff] [blame] | 3294 | // If the autoplay disable settings feature is enabled and the autoplay |
| 3295 | // policy is set to using the unified policy then set the default autoplay |
| 3296 | // policy based on user preference. |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3297 | web_prefs->autoplay_policy = |
| 3298 | UnifiedAutoplayConfig::ShouldBlockAutoplay(profile) |
| 3299 | ? content::AutoplayPolicy::kDocumentUserActivationRequired |
| 3300 | : content::AutoplayPolicy::kNoUserGestureRequired; |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3301 | } |
Alison Maher | 67fd4d9f | 2019-07-12 18:34:21 | [diff] [blame] | 3302 | #if !defined(OS_MACOSX) |
| 3303 | // 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] | 3304 | web_prefs->forced_colors = native_theme->UsesHighContrastColors() |
| 3305 | ? blink::ForcedColors::kActive |
| 3306 | : blink::ForcedColors::kNone; |
Alison Maher | 67fd4d9f | 2019-07-12 18:34:21 | [diff] [blame] | 3307 | #endif // !defined(OS_MACOSX) |
| 3308 | |
| 3309 | switch (native_theme->GetPreferredColorScheme()) { |
| 3310 | case ui::NativeTheme::PreferredColorScheme::kDark: |
| 3311 | web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark; |
| 3312 | break; |
| 3313 | case ui::NativeTheme::PreferredColorScheme::kLight: |
| 3314 | web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight; |
| 3315 | break; |
| 3316 | case ui::NativeTheme::PreferredColorScheme::kNoPreference: |
| 3317 | web_prefs->preferred_color_scheme = |
| 3318 | blink::PreferredColorScheme::kNoPreference; |
| 3319 | } |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3320 | #endif // !defined(OS_ANDROID) |
| 3321 | |
Dave Tapuska | c6627e1 | 2018-08-30 15:07:19 | [diff] [blame] | 3322 | web_prefs->translate_service_available = TranslateService::IsAvailable(prefs); |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3323 | |
Dan Beam | 836c02a | 2019-06-15 01:58:27 | [diff] [blame] | 3324 | // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is |
| 3325 | // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS |
| 3326 | // explicitly uses light (instead of not dark), which is why we don't reset |
| 3327 | // back to no-preference. https://crbug.com/965811 |
| 3328 | if (contents && !base::FeatureList::IsEnabled(features::kWebUIDarkMode)) { |
| 3329 | bool force_light = contents->GetURL().SchemeIs(content::kChromeUIScheme); |
| 3330 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 3331 | if (!force_light) { |
| 3332 | force_light = |
| 3333 | contents->GetURL().SchemeIs(extensions::kExtensionScheme) && |
| 3334 | contents->GetURL().host_piece() == extension_misc::kPdfExtensionId; |
| 3335 | } |
| 3336 | #endif |
| 3337 | if (force_light) |
| 3338 | web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight; |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 3339 | } |
| 3340 | |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3341 | // Apply native CaptionStyle parameters. |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3342 | base::Optional<ui::CaptionStyle> style; |
| 3343 | |
| 3344 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3345 | ::switches::kForceCaptionStyle)) { |
| 3346 | style = ui::CaptionStyle::FromSpec( |
| 3347 | base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 3348 | switches::kForceCaptionStyle)); |
| 3349 | } |
| 3350 | |
| 3351 | // Apply system caption style. |
| 3352 | if (!style) { |
| 3353 | style = native_theme->GetSystemCaptionStyle(); |
| 3354 | } |
| 3355 | |
| 3356 | // Apply caption style from preferences if system caption style is undefined. |
| 3357 | if (!style && base::FeatureList::IsEnabled(features::kCaptionSettings)) { |
evliu | bc2aa047 | 2019-08-09 20:19:19 | [diff] [blame] | 3358 | style = pref_names_util::GetCaptionStyleFromPrefs(prefs); |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | if (style) { |
| 3362 | web_prefs->text_track_background_color = style->background_color; |
| 3363 | web_prefs->text_track_text_color = style->text_color; |
| 3364 | web_prefs->text_track_text_size = style->text_size; |
| 3365 | web_prefs->text_track_text_shadow = style->text_shadow; |
| 3366 | web_prefs->text_track_font_family = style->font_family; |
| 3367 | web_prefs->text_track_font_variant = style->font_variant; |
Abigail Klein | 74de85bd | 2019-07-11 19:11:56 | [diff] [blame] | 3368 | web_prefs->text_track_window_color = style->window_color; |
| 3369 | web_prefs->text_track_window_padding = style->window_padding; |
| 3370 | web_prefs->text_track_window_radius = style->window_radius; |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3371 | } |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3372 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3373 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
creis | 7b2d3d1 | 2015-02-12 23:29:50 | [diff] [blame] | 3374 | extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 3375 | } |
| 3376 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3377 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 3378 | BrowserURLHandler* handler) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3379 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 3380 | extra_parts_[i]->BrowserURLHandlerCreated(handler); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3381 | |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 3382 | // about: handler. Must come before chrome: handler, since it will |
| 3383 | // rewrite about: urls to chrome: URLs and then expect chrome: to |
creis | 94a977f6 | 2015-02-18 23:51:05 | [diff] [blame] | 3384 | // actually handle them. Also relies on a preliminary fixup phase. |
| 3385 | handler->SetFixupHandler(&FixupBrowserAboutURL); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3386 | handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 3387 | BrowserURLHandler::null_handler()); |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3388 | |
mad | fbd1085 | 2017-01-20 03:15:33 | [diff] [blame] | 3389 | // The group policy NTP URL handler must be registered before the other NTP |
| 3390 | // URL handlers below. |
| 3391 | handler->AddHandlerPair(&HandleNewTabPageLocationOverride, |
| 3392 | BrowserURLHandler::null_handler()); |
| 3393 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 3394 | #if defined(OS_ANDROID) |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3395 | // Handler to rewrite chrome://newtab on Android. |
ianwen | 465e17b | 2015-01-20 18:32:35 | [diff] [blame] | 3396 | handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL, |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3397 | BrowserURLHandler::null_handler()); |
| 3398 | #else |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3399 | // Handler to rewrite chrome://newtab for InstantExtended. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 3400 | handler->AddHandlerPair(&search::HandleNewTabURLRewrite, |
| 3401 | &search::HandleNewTabURLReverseRewrite); |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3402 | #endif |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3403 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3404 | // chrome: & friends. |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 3405 | handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI, |
| 3406 | &ChromeContentBrowserClient::HandleWebUIReverse); |
Robert Ogden | e7fdca9 | 2018-10-12 17:53:06 | [diff] [blame] | 3407 | |
| 3408 | // Handler to rewrite Preview's Server Lite Page, to show the original URL to |
| 3409 | // the user. |
| 3410 | handler->AddHandlerPair(&HandlePreviewsLitePageURLRewrite, |
| 3411 | &HandlePreviewsLitePageURLRewriteReverse); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3412 | } |
| 3413 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3414 | base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 3415 | return DownloadPrefs::GetDefaultDownloadDirectory(); |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 3416 | } |
| 3417 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 3418 | std::string ChromeContentBrowserClient::GetDefaultDownloadName() { |
| 3419 | return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 3420 | } |
| 3421 | |
Dominik Röttsches | 4734783 | 2019-03-12 17:45:01 | [diff] [blame] | 3422 | base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() { |
| 3423 | base::FilePath user_data_dir; |
| 3424 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 3425 | DCHECK(!user_data_dir.empty()); |
| 3426 | return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache")); |
| 3427 | } |
| 3428 | |
jmadill | 57b52d4 | 2015-08-21 18:16:13 | [diff] [blame] | 3429 | base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() { |
| 3430 | base::FilePath user_data_dir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 3431 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
jmadill | 57b52d4 | 2015-08-21 18:16:13 | [diff] [blame] | 3432 | DCHECK(!user_data_dir.empty()); |
| 3433 | return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache")); |
| 3434 | } |
| 3435 | |
Khushal | 7ca0b78 | 2018-07-20 05:53:27 | [diff] [blame] | 3436 | base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() { |
| 3437 | base::FilePath user_data_dir; |
| 3438 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 3439 | DCHECK(!user_data_dir.empty()); |
| 3440 | return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache")); |
| 3441 | } |
| 3442 | |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 3443 | void ChromeContentBrowserClient::DidCreatePpapiPlugin( |
| 3444 | content::BrowserPpapiHost* browser_host) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3445 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 3446 | ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host); |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 3447 | #endif |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 3448 | } |
| 3449 | |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3450 | content::BrowserPpapiHost* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3451 | ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) { |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 3452 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 3453 | content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3454 | while (!iter.Done()) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3455 | nacl::NaClProcessHost* host = |
| 3456 | static_cast<nacl::NaClProcessHost*>(iter.GetDelegate()); |
| 3457 | if (host->process() && host->process()->GetData().id == plugin_process_id) { |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3458 | // Found the plugin. |
| 3459 | return host->browser_ppapi_host(); |
| 3460 | } |
| 3461 | ++iter; |
| 3462 | } |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 3463 | #endif |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3464 | return nullptr; |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3465 | } |
| 3466 | |
[email protected] | 38cd8f7f | 2012-06-15 22:06:07 | [diff] [blame] | 3467 | bool ChromeContentBrowserClient::AllowPepperSocketAPI( |
[email protected] | 157cc90 | 2012-11-02 06:31:58 | [diff] [blame] | 3468 | content::BrowserContext* browser_context, |
| 3469 | const GURL& url, |
[email protected] | dda5482 | 2013-06-15 01:26:39 | [diff] [blame] | 3470 | bool private_api, |
[email protected] | 8b92ed18 | 2013-09-21 04:47:12 | [diff] [blame] | 3471 | const content::SocketPermissionRequest* params) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3472 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 3473 | return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI( |
| 3474 | browser_context, url, private_api, params, allowed_socket_origins_); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 3475 | #else |
[email protected] | a658d45 | 2012-03-02 12:45:29 | [diff] [blame] | 3476 | return false; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 3477 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 3478 | } |
| 3479 | |
adrian.belgun | d54465ba | 2016-05-18 10:03:58 | [diff] [blame] | 3480 | bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed( |
| 3481 | content::BrowserContext* browser_context, |
| 3482 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3483 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
adrian.belgun | d54465ba | 2016-05-18 10:03:58 | [diff] [blame] | 3484 | return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed( |
| 3485 | browser_context, url); |
| 3486 | #else |
| 3487 | return false; |
| 3488 | #endif |
| 3489 | } |
| 3490 | |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 3491 | std::unique_ptr<content::VpnServiceProxy> |
| 3492 | ChromeContentBrowserClient::GetVpnServiceProxy( |
| 3493 | content::BrowserContext* browser_context) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3494 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 3495 | return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy( |
| 3496 | browser_context); |
| 3497 | #else |
| 3498 | return nullptr; |
| 3499 | #endif |
| 3500 | } |
| 3501 | |
Brett Wilson | 804e83c | 2017-08-18 22:57:33 | [diff] [blame] | 3502 | std::unique_ptr<ui::SelectFilePolicy> |
| 3503 | ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) { |
| 3504 | return std::make_unique<ChromeSelectFilePolicy>(web_contents); |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 3505 | } |
| 3506 | |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 3507 | void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 3508 | std::vector<std::string>* additional_allowed_schemes) { |
| 3509 | ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 3510 | additional_allowed_schemes); |
[email protected] | b3690f7 | 2014-02-17 00:32:48 | [diff] [blame] | 3511 | additional_allowed_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 3512 | additional_allowed_schemes->push_back(content::kChromeUIScheme); |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3513 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
| 3514 | extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem( |
| 3515 | additional_allowed_schemes); |
| 3516 | } |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 3517 | } |
| 3518 | |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 3519 | void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist( |
| 3520 | std::set<std::string>* schemes) { |
Daniel Vogelheim | 11e59b7 | 2017-11-22 15:44:04 | [diff] [blame] | 3521 | *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck(); |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 3522 | } |
| 3523 | |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 3524 | void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3525 | std::vector<storage::URLRequestAutoMountHandler>* handlers) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3526 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 3527 | extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers); |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 3528 | } |
| 3529 | |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 3530 | ::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() { |
| 3531 | return g_browser_process->rappor_service(); |
| 3532 | } |
| 3533 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 3534 | void ChromeContentBrowserClient::GetAdditionalFileSystemBackends( |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 3535 | content::BrowserContext* browser_context, |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 3536 | const base::FilePath& storage_partition_path, |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3537 | std::vector<std::unique_ptr<storage::FileSystemBackend>>* |
| 3538 | additional_backends) { |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3539 | #if defined(OS_CHROMEOS) |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3540 | storage::ExternalMountPoints* external_mount_points = |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 3541 | content::BrowserContext::GetMountPoints(browser_context); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3542 | DCHECK(external_mount_points); |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3543 | auto backend = std::make_unique<chromeos::FileSystemBackend>( |
| 3544 | std::make_unique<drive::FileSystemBackendDelegate>(), |
| 3545 | std::make_unique<chromeos::file_system_provider::BackendDelegate>(), |
| 3546 | std::make_unique<chromeos::MTPFileSystemBackendDelegate>( |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 3547 | storage_partition_path), |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3548 | std::make_unique<arc::ArcContentFileSystemBackendDelegate>(), |
| 3549 | std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(), |
Sam McNally | 47f2eac | 2018-08-28 06:45:05 | [diff] [blame] | 3550 | std::make_unique<drive::DriveFsFileSystemBackendDelegate>( |
| 3551 | Profile::FromBrowserContext(browser_context)), |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 3552 | external_mount_points, storage::ExternalMountPoints::GetSystemInstance()); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 3553 | backend->AddSystemMountPoints(); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3554 | DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal)); |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3555 | additional_backends->push_back(std::move(backend)); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3556 | #endif |
[email protected] | 445b7db | 2013-08-02 04:58:27 | [diff] [blame] | 3557 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3558 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
| 3559 | extra_parts_[i]->GetAdditionalFileSystemBackends( |
| 3560 | browser_context, storage_partition_path, additional_backends); |
| 3561 | } |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 3562 | } |
| 3563 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3564 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 3565 | void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 3566 | const base::CommandLine& command_line, |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3567 | int child_process_id, |
brettw | 3c98c7d3 | 2017-07-25 01:44:20 | [diff] [blame] | 3568 | PosixFileDescriptorInfo* mappings) { |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3569 | #if defined(OS_ANDROID) |
| 3570 | base::MemoryMappedFile::Region region; |
| 3571 | int fd = ui::GetMainAndroidPackFd(®ion); |
| 3572 | mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region); |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 3573 | |
Samuel Huang | 31eadf08 | 2019-08-28 19:50:43 | [diff] [blame] | 3574 | // For Android: Native resources for DFMs should only be used by the browser |
| 3575 | // process. Their file descriptors and memory mapped file regions are not |
| 3576 | // passed to child processes. |
| 3577 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3578 | fd = ui::GetCommonResourcesPackFd(®ion); |
| 3579 | mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region); |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 3580 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3581 | fd = ui::GetLocalePackFd(®ion); |
| 3582 | mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region); |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3583 | |
zpeng | 368afac8 | 2017-07-17 18:47:45 | [diff] [blame] | 3584 | // Optional secondary locale .pak file. |
| 3585 | fd = ui::GetSecondaryLocalePackFd(®ion); |
| 3586 | if (fd != -1) { |
| 3587 | mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region); |
| 3588 | } |
| 3589 | |
[email protected] | 09560f7f | 2014-06-10 18:40:28 | [diff] [blame] | 3590 | base::FilePath app_data_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 3591 | base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path); |
[email protected] | 09560f7f | 2014-06-10 18:40:28 | [diff] [blame] | 3592 | DCHECK(!app_data_path.empty()); |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 3593 | #endif // defined(OS_ANDROID) |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3594 | int crash_signal_fd = GetCrashSignalFD(command_line); |
| 3595 | if (crash_signal_fd >= 0) { |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 3596 | mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd); |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3597 | } |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3598 | } |
| 3599 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 3600 | |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 3601 | #if defined(OS_WIN) |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3602 | base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType( |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 3603 | int sandbox_type) { |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3604 | // TODO(wfh): Add support for more process types here. crbug.com/499523 |
| 3605 | switch (sandbox_type) { |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 3606 | case service_manager::SANDBOX_TYPE_RENDERER: |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 3607 | return base::string16(install_static::GetSandboxSidPrefix()) + |
| 3608 | L"129201922"; |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 3609 | case service_manager::SANDBOX_TYPE_UTILITY: |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3610 | return base::string16(); |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 3611 | case service_manager::SANDBOX_TYPE_GPU: |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3612 | return base::string16(); |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 3613 | case service_manager::SANDBOX_TYPE_PPAPI: |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 3614 | return base::string16(install_static::GetSandboxSidPrefix()) + |
| 3615 | L"129201925"; |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 3616 | #if BUILDFLAG(ENABLE_NACL) |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3617 | case PROCESS_TYPE_NACL_LOADER: |
| 3618 | return base::string16(); |
| 3619 | case PROCESS_TYPE_NACL_BROKER: |
| 3620 | return base::string16(); |
| 3621 | #endif |
| 3622 | } |
| 3623 | |
| 3624 | // Should never reach here. |
| 3625 | CHECK(0); |
| 3626 | return base::string16(); |
| 3627 | } |
| 3628 | |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3629 | bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy, |
| 3630 | RendererSpawnFlags flags) { |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 3631 | // Allow the server side of a pipe restricted to the "chrome.nacl." |
| 3632 | // namespace so that it cannot impersonate other system or other chrome |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3633 | // service pipes. This is also done in nacl_broker_listener.cc. |
| 3634 | sandbox::ResultCode result = |
| 3635 | policy->AddRule(sandbox::TargetPolicy::SUBSYS_NAMED_PIPES, |
| 3636 | sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY, |
| 3637 | L"\\\\.\\pipe\\chrome.nacl.*"); |
rickyz | 5010931 | 2015-11-11 00:37:08 | [diff] [blame] | 3638 | if (result != sandbox::SBOX_ALL_OK) |
| 3639 | return false; |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3640 | |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 3641 | // Does not work under component build because all the component DLLs would need |
| 3642 | // to be manually added and maintained. Does not work under ASAN build because |
| 3643 | // ASAN has not yet fully initialized its instrumentation by the time the CIG |
| 3644 | // intercepts run. |
| 3645 | #if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3646 | if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0) |
| 3647 | return true; |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3648 | if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity)) |
| 3649 | return true; |
| 3650 | |
| 3651 | // Only enable signing mitigation if launching from chrome.exe. |
| 3652 | base::FilePath exe_path; |
| 3653 | if (!base::PathService::Get(base::FILE_EXE, &exe_path)) |
| 3654 | return true; |
| 3655 | if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value()) |
| 3656 | return true; |
| 3657 | |
| 3658 | sandbox::MitigationFlags mitigations = policy->GetProcessMitigations(); |
| 3659 | mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS; |
| 3660 | result = policy->SetProcessMitigations(mitigations); |
| 3661 | if (result != sandbox::SBOX_ALL_OK) |
| 3662 | return false; |
| 3663 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3664 | // Allow loading Chrome's DLLs. The name of this depends on whether |
| 3665 | // is_multi_dll_chrome is defined or not. For multi-DLL Chrome, |
| 3666 | // chrome_child.dll is loaded, but for single-DLL Chrome, it would be the |
| 3667 | // same DLL as the browser process. |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3668 | #if defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 3669 | constexpr auto* child_dll_path = chrome::kChildDll; |
| 3670 | #else |
| 3671 | constexpr auto* child_dll_path = chrome::kBrowserResourcesDll; |
| 3672 | #endif |
| 3673 | for (const auto* dll : {child_dll_path, chrome::kElfDll}) { |
| 3674 | result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY, |
| 3675 | sandbox::TargetPolicy::SIGNED_ALLOW_LOAD, |
| 3676 | GetModulePath(dll).value().c_str()); |
| 3677 | if (result != sandbox::SBOX_ALL_OK) |
| 3678 | return false; |
| 3679 | } |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 3680 | #endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3681 | |
| 3682 | return true; |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 3683 | } |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3684 | |
| 3685 | bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() { |
| 3686 | PrefService* local_state = g_browser_process->local_state(); |
| 3687 | if (local_state && |
| 3688 | local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) && |
| 3689 | !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled)) |
| 3690 | return false; |
| 3691 | return true; |
| 3692 | } |
| 3693 | |
wfh | c91e967 | 2016-01-27 00:14:20 | [diff] [blame] | 3694 | #endif // defined(OS_WIN) |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 3695 | |
ben | d1dd50f5 | 2016-06-26 22:10:48 | [diff] [blame] | 3696 | void ChromeContentBrowserClient::ExposeInterfacesToRenderer( |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 3697 | service_manager::BinderRegistry* registry, |
Sam McNally | 52e5028 | 2017-11-29 00:54:02 | [diff] [blame] | 3698 | blink::AssociatedInterfaceRegistry* associated_registry, |
leon.han | 0b61879 | 2016-06-16 01:53:51 | [diff] [blame] | 3699 | content::RenderProcessHost* render_process_host) { |
nigeltao | beff0a10 | 2017-04-29 09:30:37 | [diff] [blame] | 3700 | // The CacheStatsRecorder is an associated binding, instead of a |
| 3701 | // non-associated one, because the sender (in the renderer process) posts the |
| 3702 | // message after a time delay, in order to rate limit. The association |
| 3703 | // protects against the render process host ID being recycled in that time |
| 3704 | // gap between the preparation and the execution of that IPC. |
| 3705 | associated_registry->AddInterface( |
| 3706 | base::Bind(&CacheStatsRecorder::Create, render_process_host->GetID())); |
| 3707 | |
ben | 5be0b913 | 2016-08-03 00:17:18 | [diff] [blame] | 3708 | scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner = |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 3709 | base::CreateSingleThreadTaskRunner({content::BrowserThread::UI}); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3710 | registry->AddInterface(base::Bind(&rappor::RapporRecorderImpl::Create, |
| 3711 | g_browser_process->rappor_service()), |
| 3712 | ui_task_runner); |
Sadrul Habib Chowdhury | 16b3a16 | 2018-02-03 01:43:18 | [diff] [blame] | 3713 | registry->AddInterface( |
Mike Wittman | 16fa536 | 2018-09-04 17:27:30 | [diff] [blame] | 3714 | base::BindRepeating(&metrics::CallStackProfileCollector::Create)); |
Sadrul Habib Chowdhury | 16b3a16 | 2018-02-03 01:43:18 | [diff] [blame] | 3715 | |
dvallet | 233f57ab | 2016-12-21 03:17:10 | [diff] [blame] | 3716 | if (NetBenchmarking::CheckBenchmarkingEnabled()) { |
| 3717 | Profile* profile = |
| 3718 | Profile::FromBrowserContext(render_process_host->GetBrowserContext()); |
Alexandr Ilin | 4909ec8 | 2018-06-06 10:22:48 | [diff] [blame] | 3719 | auto* loading_predictor = |
| 3720 | predictors::LoadingPredictorFactory::GetForProfile(profile); |
Robbie McElrath | b0f248c | 2018-07-24 19:44:16 | [diff] [blame] | 3721 | registry->AddInterface( |
| 3722 | base::BindRepeating( |
| 3723 | &NetBenchmarking::Create, |
| 3724 | loading_predictor ? loading_predictor->GetWeakPtr() : nullptr, |
Robbie McElrath | b0f248c | 2018-07-24 19:44:16 | [diff] [blame] | 3725 | render_process_host->GetID()), |
| 3726 | ui_task_runner); |
dvallet | 233f57ab | 2016-12-21 03:17:10 | [diff] [blame] | 3727 | } |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 3728 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 3729 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
Adam Rice | 41b8959 | 2017-07-28 10:33:44 | [diff] [blame] | 3730 | if (safe_browsing_service_) { |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 3731 | content::ResourceContext* resource_context = |
| 3732 | render_process_host->GetBrowserContext()->GetResourceContext(); |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 3733 | registry->AddInterface( |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 3734 | base::Bind( |
| 3735 | &safe_browsing::MojoSafeBrowsingImpl::MaybeCreate, |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 3736 | render_process_host->GetID(), resource_context, |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 3737 | base::Bind( |
| 3738 | &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate, |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 3739 | base::Unretained(this), resource_context)), |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 3740 | base::CreateSingleThreadTaskRunner({BrowserThread::IO})); |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 3741 | } |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 3742 | #endif |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 3743 | |
Eric Roman | a00cf68 | 2018-11-01 20:09:11 | [diff] [blame] | 3744 | if (data_reduction_proxy::params::IsEnabledWithNetworkService()) { |
Clark DuVall | 812e07d | 2019-08-26 18:34:56 | [diff] [blame] | 3745 | registry->AddInterface(base::BindRepeating(&AddDataReductionProxyBinding, |
| 3746 | render_process_host->GetID()), |
| 3747 | ui_task_runner); |
Eric Roman | a00cf68 | 2018-11-01 20:09:11 | [diff] [blame] | 3748 | } |
| 3749 | |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 3750 | #if defined(OS_WIN) |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3751 | // Add the ModuleEventSink interface. This is the interface used by renderer |
| 3752 | // processes to notify the browser of modules in their address space. The |
| 3753 | // process handle is not yet available at this point so pass in a callback |
| 3754 | // to allow to retrieve a duplicate at the time the interface is actually |
Ken Rockot | 15253a48 | 2019-08-23 17:44:59 | [diff] [blame] | 3755 | // created. |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3756 | auto get_process = base::BindRepeating( |
Ken Rockot | 15253a48 | 2019-08-23 17:44:59 | [diff] [blame] | 3757 | [](int id) -> base::Process { |
| 3758 | auto* host = content::RenderProcessHost::FromID(id); |
| 3759 | if (host) |
| 3760 | return host->GetProcess().Duplicate(); |
| 3761 | return base::Process(); |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3762 | }, |
Ken Rockot | 15253a48 | 2019-08-23 17:44:59 | [diff] [blame] | 3763 | render_process_host->GetID()); |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3764 | registry->AddInterface( |
Patrick Monette | aa2ec56 | 2019-03-20 23:37:45 | [diff] [blame] | 3765 | base::BindRepeating( |
| 3766 | &ModuleEventSinkImpl::Create, std::move(get_process), |
| 3767 | content::PROCESS_TYPE_RENDERER, |
| 3768 | base::BindRepeating(&ModuleDatabase::HandleModuleLoadEvent)), |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3769 | ui_task_runner); |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 3770 | #endif |
Dan Harrington | 964d48c | 2018-08-03 15:52:24 | [diff] [blame] | 3771 | #if defined(OS_ANDROID) |
Carlos Knippschild | 63b3f04 | 2018-11-20 22:55:04 | [diff] [blame] | 3772 | Profile* profile = |
| 3773 | Profile::FromBrowserContext(render_process_host->GetBrowserContext()); |
Dan Harrington | 964d48c | 2018-08-03 15:52:24 | [diff] [blame] | 3774 | registry->AddInterface( |
| 3775 | base::BindRepeating(&android::AvailableOfflineContentProvider::Create, |
Carlos Knippschild | 63b3f04 | 2018-11-20 22:55:04 | [diff] [blame] | 3776 | profile), |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 3777 | base::CreateSingleThreadTaskRunner({BrowserThread::UI})); |
Dan Harrington | 964d48c | 2018-08-03 15:52:24 | [diff] [blame] | 3778 | #endif |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 3779 | |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 3780 | for (auto* ep : extra_parts_) { |
| 3781 | ep->ExposeInterfacesToRenderer(registry, associated_registry, |
| 3782 | render_process_host); |
| 3783 | } |
sammc | 33584452 | 2016-06-09 10:15:59 | [diff] [blame] | 3784 | } |
| 3785 | |
ben | dd157e1a | 2016-07-22 03:15:57 | [diff] [blame] | 3786 | void ChromeContentBrowserClient::ExposeInterfacesToMediaService( |
ben | 8408b13 | 2017-05-01 23:48:50 | [diff] [blame] | 3787 | service_manager::BinderRegistry* registry, |
xhwang | 9ab9648 | 2015-05-11 22:02:33 | [diff] [blame] | 3788 | content::RenderFrameHost* render_frame_host) { |
Xiaohan Wang | 15303d0c | 2017-10-06 05:22:44 | [diff] [blame] | 3789 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
| 3790 | registry->AddInterface( |
| 3791 | base::Bind(&OutputProtectionImpl::Create, render_frame_host)); |
ben | 155ecf8 | 2016-06-21 22:43:26 | [diff] [blame] | 3792 | registry->AddInterface( |
John Rummell | 1b5da610 | 2017-11-02 02:15:45 | [diff] [blame] | 3793 | base::Bind(&PlatformVerificationImpl::Create, render_frame_host)); |
Xiaohan Wang | 15303d0c | 2017-10-06 05:22:44 | [diff] [blame] | 3794 | #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c86d76e4 | 2016-03-14 23:38:49 | [diff] [blame] | 3795 | |
xhwang | db24d60 | 2017-05-20 06:32:24 | [diff] [blame] | 3796 | #if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID) |
cm.sanchi | ad3f42a6 | 2017-11-07 11:33:35 | [diff] [blame] | 3797 | registry->AddInterface(base::Bind(&CreateMediaDrmStorage, render_frame_host)); |
xhwang | 116acb9 | 2017-04-03 18:27:20 | [diff] [blame] | 3798 | #endif |
xhwang | 9ab9648 | 2015-05-11 22:02:33 | [diff] [blame] | 3799 | } |
| 3800 | |
Oksana Zhuravlova | 4dd171e8 | 2019-08-16 20:54:00 | [diff] [blame] | 3801 | void ChromeContentBrowserClient::RegisterBrowserInterfaceBindersForFrame( |
| 3802 | service_manager::BinderMapWithContext<content::RenderFrameHost*>* map) { |
| 3803 | chrome::internal::PopulateChromeFrameBinders(map); |
| 3804 | } |
| 3805 | |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 3806 | void ChromeContentBrowserClient::BindInterfaceRequestFromFrame( |
| 3807 | content::RenderFrameHost* render_frame_host, |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 3808 | const std::string& interface_name, |
| 3809 | mojo::ScopedMessagePipeHandle interface_pipe) { |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 3810 | if (!frame_interfaces_ && !frame_interfaces_parameterized_ && |
| 3811 | !worker_interfaces_parameterized_) { |
| 3812 | InitWebContextInterfaces(); |
| 3813 | } |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 3814 | |
Ben Goodger | 272e063 | 2017-07-19 23:27:00 | [diff] [blame] | 3815 | if (!frame_interfaces_parameterized_->TryBindInterface( |
| 3816 | interface_name, &interface_pipe, render_frame_host)) { |
| 3817 | frame_interfaces_->TryBindInterface(interface_name, &interface_pipe); |
juncai | 1bf9f7c | 2016-03-22 20:46:56 | [diff] [blame] | 3818 | } |
rockot | 0fa66a8 | 2015-06-11 17:25:45 | [diff] [blame] | 3819 | } |
| 3820 | |
Mario Sanchez Prada | 39dee4a | 2019-07-09 07:15:40 | [diff] [blame] | 3821 | void ChromeContentBrowserClient::BindCredentialManagerReceiver( |
Oksana Zhuravlova | 23ecbb40 | 2019-03-29 19:44:11 | [diff] [blame] | 3822 | content::RenderFrameHost* render_frame_host, |
Mario Sanchez Prada | 39dee4a | 2019-07-09 07:15:40 | [diff] [blame] | 3823 | mojo::PendingReceiver<blink::mojom::CredentialManager> receiver) { |
| 3824 | ChromePasswordManagerClient::BindCredentialManager(std::move(receiver), |
Oksana Zhuravlova | 23ecbb40 | 2019-03-29 19:44:11 | [diff] [blame] | 3825 | render_frame_host); |
| 3826 | } |
| 3827 | |
Ken Rockot | 0aad7ec | 2018-07-31 15:58:44 | [diff] [blame] | 3828 | bool ChromeContentBrowserClient::BindAssociatedInterfaceRequestFromFrame( |
| 3829 | content::RenderFrameHost* render_frame_host, |
| 3830 | const std::string& interface_name, |
| 3831 | mojo::ScopedInterfaceEndpointHandle* handle) { |
| 3832 | if (interface_name == autofill::mojom::AutofillDriver::Name_) { |
| 3833 | autofill::ContentAutofillDriverFactory::BindAutofillDriver( |
Shimi Zhang | 6b72d29 | 2019-07-12 20:52:42 | [diff] [blame] | 3834 | mojo::PendingAssociatedReceiver<autofill::mojom::AutofillDriver>( |
| 3835 | std::move(*handle)), |
Ken Rockot | 0aad7ec | 2018-07-31 15:58:44 | [diff] [blame] | 3836 | render_frame_host); |
| 3837 | return true; |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3838 | } |
| 3839 | if (interface_name == autofill::mojom::PasswordManagerDriver::Name_) { |
Shimi Zhang | 6b72d29 | 2019-07-12 20:52:42 | [diff] [blame] | 3840 | password_manager::ContentPasswordManagerDriverFactory:: |
| 3841 | BindPasswordManagerDriver( |
| 3842 | autofill::mojom::PasswordManagerDriverAssociatedRequest( |
| 3843 | std::move(*handle)), |
| 3844 | render_frame_host); |
Dominic Battre | 97d5edf | 2019-03-26 13:41:38 | [diff] [blame] | 3845 | return true; |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3846 | } |
| 3847 | if (interface_name == content_capture::mojom::ContentCaptureReceiver::Name_) { |
Tao Bai | 02ab4dd4 | 2019-03-06 00:30:37 | [diff] [blame] | 3848 | content_capture::ContentCaptureReceiverManager::BindContentCaptureReceiver( |
Shimi Zhang | 8ee3233 | 2019-07-12 17:59:36 | [diff] [blame] | 3849 | mojo::PendingAssociatedReceiver< |
| 3850 | content_capture::mojom::ContentCaptureReceiver>(std::move(*handle)), |
Tao Bai | 02ab4dd4 | 2019-03-06 00:30:37 | [diff] [blame] | 3851 | render_frame_host); |
| 3852 | return true; |
Ken Rockot | 0aad7ec | 2018-07-31 15:58:44 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | return false; |
| 3856 | } |
| 3857 | |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 3858 | void ChromeContentBrowserClient::BindInterfaceRequestFromWorker( |
| 3859 | content::RenderProcessHost* render_process_host, |
| 3860 | const url::Origin& origin, |
| 3861 | const std::string& interface_name, |
| 3862 | mojo::ScopedMessagePipeHandle interface_pipe) { |
| 3863 | if (!frame_interfaces_ && !frame_interfaces_parameterized_ && |
| 3864 | !worker_interfaces_parameterized_) { |
| 3865 | InitWebContextInterfaces(); |
| 3866 | } |
| 3867 | |
| 3868 | worker_interfaces_parameterized_->BindInterface( |
| 3869 | interface_name, std::move(interface_pipe), render_process_host, origin); |
| 3870 | } |
| 3871 | |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 3872 | void ChromeContentBrowserClient::BindInterfaceRequest( |
ben | 2c36828d | 2017-05-02 04:09:01 | [diff] [blame] | 3873 | const service_manager::BindSourceInfo& source_info, |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 3874 | const std::string& interface_name, |
| 3875 | mojo::ScopedMessagePipeHandle* interface_pipe) { |
Ben Goodger | 272e063 | 2017-07-19 23:27:00 | [diff] [blame] | 3876 | if (source_info.identity.name() == content::mojom::kGpuServiceName) |
| 3877 | gpu_binder_registry_.TryBindInterface(interface_name, interface_pipe); |
wittman | 757af87 | 2016-08-16 00:13:46 | [diff] [blame] | 3878 | } |
| 3879 | |
Ken Rockot | c185b2a | 2019-08-01 22:19:48 | [diff] [blame] | 3880 | void ChromeContentBrowserClient::BindHostReceiverForRenderer( |
| 3881 | content::RenderProcessHost* render_process_host, |
| 3882 | mojo::GenericPendingReceiver receiver) { |
| 3883 | #if BUILDFLAG(ENABLE_SPELLCHECK) |
| 3884 | if (auto host_receiver = receiver.As<spellcheck::mojom::SpellCheckHost>()) { |
| 3885 | SpellCheckHostChromeImpl::Create(render_process_host->GetID(), |
| 3886 | std::move(host_receiver)); |
| 3887 | return; |
| 3888 | } |
| 3889 | |
| 3890 | #if BUILDFLAG(HAS_SPELLCHECK_PANEL) |
| 3891 | if (auto panel_host_receiver = |
| 3892 | receiver.As<spellcheck::mojom::SpellCheckPanelHost>()) { |
| 3893 | SpellCheckPanelHostImpl::Create(render_process_host->GetID(), |
| 3894 | std::move(panel_host_receiver)); |
| 3895 | return; |
| 3896 | } |
| 3897 | #endif // BUILDFLAG(HAS_SPELLCHECK_PANEL) |
| 3898 | #endif // BUILDFLAG(ENABLE_SPELLCHECK) |
| 3899 | } |
| 3900 | |
Ken Rockot | 7c6275b | 2019-08-02 20:00:23 | [diff] [blame] | 3901 | void ChromeContentBrowserClient::BindHostReceiverForRendererOnIOThread( |
| 3902 | int render_process_id, |
| 3903 | mojo::GenericPendingReceiver* receiver) { |
| 3904 | if (auto host_receiver = |
| 3905 | receiver->As<startup_metric_utils::mojom::StartupMetricHost>()) { |
| 3906 | startup_metric_utils::StartupMetricHostImpl::Create( |
| 3907 | std::move(host_receiver)); |
| 3908 | return; |
| 3909 | } |
| 3910 | } |
| 3911 | |
Ken Rockot | fa5d5711 | 2019-05-29 20:57:14 | [diff] [blame] | 3912 | void ChromeContentBrowserClient::WillStartServiceManager() { |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3913 | #if defined(OS_WIN) |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 3914 | if (startup_data_) { |
| 3915 | auto* chrome_feature_list_creator = |
| 3916 | startup_data_->chrome_feature_list_creator(); |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3917 | // This has to run very early before ServiceManagerContext is created. |
| 3918 | const base::Value* force_network_in_process_value = |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 3919 | chrome_feature_list_creator->browser_policy_connector() |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3920 | ->GetPolicyService() |
| 3921 | ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
| 3922 | std::string())) |
| 3923 | .GetValue(policy::key::kForceNetworkInProcess); |
| 3924 | bool force_network_in_process = false; |
| 3925 | if (force_network_in_process_value) |
| 3926 | force_network_in_process_value->GetAsBoolean(&force_network_in_process); |
| 3927 | if (force_network_in_process) |
| 3928 | content::ForceInProcessNetworkService(true); |
| 3929 | } |
| 3930 | #endif |
xhwang | 5e63046 | 2015-10-30 03:18:48 | [diff] [blame] | 3931 | } |
| 3932 | |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3933 | void ChromeContentBrowserClient::RunServiceInstance( |
| 3934 | const service_manager::Identity& identity, |
| 3935 | mojo::PendingReceiver<service_manager::mojom::Service>* receiver) { |
| 3936 | const std::string& service_name = identity.name(); |
Ken Rockot | 91c40da8 | 2019-08-12 20:07:11 | [diff] [blame] | 3937 | ALLOW_UNUSED_LOCAL(service_name); |
Ken Rockot | 3d8be74 | 2018-11-22 08:59:38 | [diff] [blame] | 3938 | #if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS) |
| 3939 | if (service_name == media::mojom::kMediaServiceName) { |
Ken Rockot | d80eb10 | 2018-11-29 14:55:16 | [diff] [blame] | 3940 | service_manager::Service::RunAsyncUntilTermination( |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3941 | media::CreateMediaService(std::move(*receiver))); |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3942 | return; |
Ken Rockot | 3d8be74 | 2018-11-22 08:59:38 | [diff] [blame] | 3943 | } |
| 3944 | #endif |
Ken Rockot | e116c20 | 2018-11-30 01:52:50 | [diff] [blame] | 3945 | |
| 3946 | #if defined(OS_CHROMEOS) |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3947 | auto service = ash_service_registry::HandleServiceRequest( |
| 3948 | service_name, std::move(*receiver)); |
Ken Rockot | c15f3499 | 2018-12-01 21:27:57 | [diff] [blame] | 3949 | if (service) |
| 3950 | service_manager::Service::RunAsyncUntilTermination(std::move(service)); |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3951 | #endif // defined(OS_CHROMEOS) |
Ken Rockot | 3d8be74 | 2018-11-22 08:59:38 | [diff] [blame] | 3952 | } |
| 3953 | |
Ken Rockot | 8f39a27 | 2018-12-21 23:38:35 | [diff] [blame] | 3954 | base::Optional<service_manager::Manifest> |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 3955 | ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) { |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3956 | if (name == content::mojom::kBrowserServiceName) |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 3957 | return GetChromeContentBrowserOverlayManifest(); |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3958 | if (name == content::mojom::kGpuServiceName) |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 3959 | return GetChromeContentGpuOverlayManifest(); |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3960 | if (name == content::mojom::kRendererServiceName) |
| 3961 | return GetChromeContentRendererOverlayManifest(); |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 3962 | return base::nullopt; |
ben | c70c0e3 | 2016-09-22 03:50:37 | [diff] [blame] | 3963 | } |
| 3964 | |
Ken Rockot | 69aade0 | 2019-01-23 21:19:51 | [diff] [blame] | 3965 | std::vector<service_manager::Manifest> |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 3966 | ChromeContentBrowserClient::GetExtraServiceManifests() { |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3967 | auto manifests = GetChromeBuiltinServiceManifests(); |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3968 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 3969 | #if BUILDFLAG(ENABLE_NACL) |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3970 | manifests.push_back(GetNaClLoaderManifest()); |
Ken Rockot | 69aade0 | 2019-01-23 21:19:51 | [diff] [blame] | 3971 | #if defined(OS_WIN) && defined(ARCH_CPU_X86) |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3972 | manifests.push_back(GetNaClBrokerManifest()); |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 3973 | #endif // defined(OS_WIN) |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 3974 | #endif // BUILDFLAG(ENABLE_NACL) |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3975 | |
| 3976 | return manifests; |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 3977 | } |
| 3978 | |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 3979 | void ChromeContentBrowserClient::OpenURL( |
Matt Falkenhagen | 18c5c5d | 2018-11-26 02:55:37 | [diff] [blame] | 3980 | content::SiteInstance* site_instance, |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 3981 | const content::OpenURLParams& params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 3982 | base::OnceCallback<void(content::WebContents*)> callback) { |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3983 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Matt Falkenhagen | 18c5c5d | 2018-11-26 02:55:37 | [diff] [blame] | 3984 | DCHECK(ShouldAllowOpenURL(site_instance, params.url)); |
| 3985 | |
| 3986 | content::BrowserContext* browser_context = site_instance->GetBrowserContext(); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3987 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 3988 | #if defined(OS_ANDROID) |
pkotwicz | aa289f0 | 2016-07-05 22:26:22 | [diff] [blame] | 3989 | ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 3990 | std::move(callback)); |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 3991 | #else |
cm.sanchi | 2522bc9 | 2017-12-04 08:04:13 | [diff] [blame] | 3992 | NavigateParams nav_params(Profile::FromBrowserContext(browser_context), |
| 3993 | params.url, params.transition); |
| 3994 | nav_params.FillNavigateParamsFromOpenURLParams(params); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 3995 | nav_params.user_gesture = params.user_gesture; |
| 3996 | |
| 3997 | Navigate(&nav_params); |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 3998 | std::move(callback).Run(nav_params.navigated_or_inserted_contents); |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 3999 | #endif |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 4000 | } |
| 4001 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 4002 | content::ControllerPresentationServiceDelegate* |
| 4003 | ChromeContentBrowserClient::GetControllerPresentationServiceDelegate( |
| 4004 | content::WebContents* web_contents) { |
mfoltz | 99bd44c | 2016-03-18 20:36:46 | [diff] [blame] | 4005 | if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) { |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 4006 | return media_router::PresentationServiceDelegateImpl:: |
| 4007 | GetOrCreateForWebContents(web_contents); |
| 4008 | } |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 4009 | return nullptr; |
| 4010 | } |
| 4011 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 4012 | content::ReceiverPresentationServiceDelegate* |
| 4013 | ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate( |
| 4014 | content::WebContents* web_contents) { |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 4015 | if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) { |
| 4016 | // ReceiverPresentationServiceDelegateImpl exists only for WebContents |
| 4017 | // created for offscreen presentations. The WebContents must belong to |
| 4018 | // an incognito profile. |
| 4019 | if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl:: |
| 4020 | FromWebContents(web_contents)) { |
| 4021 | DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord()); |
| 4022 | return impl; |
| 4023 | } |
| 4024 | } |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 4025 | return nullptr; |
| 4026 | } |
| 4027 | |
horo | 48d4d3e | 2015-02-27 03:04:00 | [diff] [blame] | 4028 | void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric, |
| 4029 | const GURL& url) { |
mathp | 46284f3 | 2015-03-11 13:06:41 | [diff] [blame] | 4030 | if (url.is_valid()) { |
| 4031 | rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
| 4032 | metric, url); |
| 4033 | } |
horo | 48d4d3e | 2015-02-27 03:04:00 | [diff] [blame] | 4034 | } |
| 4035 | |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 4036 | std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) { |
| 4037 | // Don't change these returned strings. They are written (in hashed form) into |
| 4038 | // UMA logs. If you add more strings, you must update histograms.xml and get |
| 4039 | // histograms review. Only Google domains should be here for privacy purposes. |
| 4040 | // TODO(falken): Ideally Chrome would log the relevant UMA directly and this |
| 4041 | // function could be removed. |
Matt Falkenhagen | 2c98ee29a | 2017-07-20 16:43:19 | [diff] [blame] | 4042 | if (page_load_metrics::IsGoogleSearchResultUrl(url)) |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 4043 | return "search"; |
Matt Falkenhagen | 2c98ee29a | 2017-07-20 16:43:19 | [diff] [blame] | 4044 | if (url.host() == "docs.google.com") |
| 4045 | return "docs"; |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 4046 | return std::string(); |
| 4047 | } |
| 4048 | |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 4049 | std::vector<std::unique_ptr<content::NavigationThrottle>> |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4050 | ChromeContentBrowserClient::CreateThrottlesForNavigation( |
| 4051 | content::NavigationHandle* handle) { |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 4052 | std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 4053 | |
bmcquade | b455655 | 2017-03-24 22:24:37 | [diff] [blame] | 4054 | // MetricsNavigationThrottle requires that it runs before NavigationThrottles |
| 4055 | // that may delay or cancel navigations, so only NavigationThrottles that |
| 4056 | // don't delay or cancel navigations (e.g. throttles that are only observing |
| 4057 | // callbacks without affecting navigation behavior) should be added before |
| 4058 | // MetricsNavigationThrottle. |
| 4059 | if (handle->IsInMainFrame()) { |
| 4060 | throttles.push_back( |
| 4061 | page_load_metrics::MetricsNavigationThrottle::Create(handle)); |
| 4062 | } |
| 4063 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4064 | #if BUILDFLAG(ENABLE_PLUGINS) |
tommycli | ae590f160 | 2016-11-02 03:59:23 | [diff] [blame] | 4065 | std::unique_ptr<content::NavigationThrottle> flash_url_throttle = |
| 4066 | FlashDownloadInterception::MaybeCreateThrottleFor(handle); |
| 4067 | if (flash_url_throttle) |
| 4068 | throttles.push_back(std::move(flash_url_throttle)); |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 4069 | #endif |
| 4070 | |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 4071 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 4072 | std::unique_ptr<content::NavigationThrottle> supervised_user_throttle = |
| 4073 | SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle); |
| 4074 | if (supervised_user_throttle) |
| 4075 | throttles.push_back(std::move(supervised_user_throttle)); |
| 4076 | #endif |
| 4077 | |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4078 | #if defined(OS_ANDROID) |
| 4079 | // TODO(davidben): This is insufficient to integrate with prerender properly. |
| 4080 | // https://crbug.com/370595 |
| 4081 | prerender::PrerenderContents* prerender_contents = |
| 4082 | prerender::PrerenderContents::FromWebContents(handle->GetWebContents()); |
| 4083 | if (!prerender_contents && handle->IsInMainFrame()) { |
| 4084 | throttles.push_back( |
| 4085 | navigation_interception::InterceptNavigationDelegate::CreateThrottleFor( |
Charlie Harrison | 3286ab7 | 2019-02-13 20:13:30 | [diff] [blame] | 4086 | handle, navigation_interception::SynchronyMode::kAsync)); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4087 | } |
Min Qin | 0ab0e16 | 2017-11-14 21:57:19 | [diff] [blame] | 4088 | throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle)); |
Giovanni Ortuño Urquidi | 7ae7fb0 | 2017-10-09 01:49:57 | [diff] [blame] | 4089 | #elif BUILDFLAG(ENABLE_EXTENSIONS) |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4090 | if (handle->IsInMainFrame()) { |
| 4091 | // Redirect some navigations to apps that have registered matching URL |
| 4092 | // handlers ('url_handlers' in the manifest). |
Giovanni Ortuño Urquidi | 7ae7fb0 | 2017-10-09 01:49:57 | [diff] [blame] | 4093 | auto url_to_app_throttle = |
| 4094 | PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4095 | if (url_to_app_throttle) |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 4096 | throttles.push_back(std::move(url_to_app_throttle)); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4097 | } |
| 4098 | #endif |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4099 | |
| 4100 | #if defined(OS_CHROMEOS) |
| 4101 | // Check if we need to add merge session throttle. This throttle will postpone |
| 4102 | // loading of main frames. |
| 4103 | if (handle->IsInMainFrame()) { |
| 4104 | // Add interstitial page while merge session process (cookie reconstruction |
| 4105 | // from OAuth2 refresh token in ChromeOS login) is still in progress while |
| 4106 | // we are attempting to load a google property. |
csharrison | dd06bab | 2016-07-22 14:15:02 | [diff] [blame] | 4107 | if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() && |
| 4108 | !merge_session_throttling_utils::AreAllSessionMergedAlready() && |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4109 | handle->GetURL().SchemeIsHTTPOrHTTPS()) { |
| 4110 | throttles.push_back(MergeSessionNavigationThrottle::Create(handle)); |
| 4111 | } |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4112 | } |
| 4113 | #endif |
djacobo | 21e56e0 | 2016-07-02 01:14:31 | [diff] [blame] | 4114 | |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4115 | #if !defined(OS_ANDROID) |
| 4116 | if (base::FeatureList::IsEnabled(features::kIntentPicker)) { |
Dominick Ng | 7c28994 | 2018-03-27 05:57:15 | [diff] [blame] | 4117 | auto url_to_apps_throttle = |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4118 | #if defined(OS_CHROMEOS) |
| 4119 | chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle); |
| 4120 | #else |
| 4121 | apps::AppsNavigationThrottle::MaybeCreate(handle); |
| 4122 | #endif |
Dominick Ng | 7c28994 | 2018-03-27 05:57:15 | [diff] [blame] | 4123 | if (url_to_apps_throttle) |
| 4124 | throttles.push_back(std::move(url_to_apps_throttle)); |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4125 | } |
| 4126 | #endif |
| 4127 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 4128 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 4129 | throttles.push_back( |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4130 | std::make_unique<extensions::ExtensionNavigationThrottle>(handle)); |
Clark DuVall | 2cf99249e | 2018-09-19 19:11:51 | [diff] [blame] | 4131 | |
| 4132 | std::unique_ptr<content::NavigationThrottle> user_script_throttle = |
| 4133 | extensions::ExtensionsBrowserClient::Get() |
| 4134 | ->GetUserScriptListener() |
| 4135 | ->CreateNavigationThrottle(handle); |
| 4136 | if (user_script_throttle) |
| 4137 | throttles.push_back(std::move(user_script_throttle)); |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 4138 | #endif |
| 4139 | |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 4140 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 4141 | std::unique_ptr<content::NavigationThrottle> supervised_user_nav_throttle = |
| 4142 | SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle); |
| 4143 | if (supervised_user_nav_throttle) |
| 4144 | throttles.push_back(std::move(supervised_user_nav_throttle)); |
| 4145 | #endif |
| 4146 | |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 4147 | content::WebContents* web_contents = handle->GetWebContents(); |
csharrison | 77bf834 | 2017-05-04 18:23:10 | [diff] [blame] | 4148 | if (auto* subresource_filter_client = |
| 4149 | ChromeSubresourceFilterClient::FromWebContents(web_contents)) { |
| 4150 | subresource_filter_client->MaybeAppendNavigationThrottles(handle, |
| 4151 | &throttles); |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 4152 | } |
| 4153 | |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 4154 | #if !defined(OS_ANDROID) |
| 4155 | // BackgroundTabNavigationThrottle is used by TabManager, which is only |
| 4156 | // enabled on non-Android platforms. |
| 4157 | std::unique_ptr<content::NavigationThrottle> |
| 4158 | background_tab_navigation_throttle = resource_coordinator:: |
| 4159 | BackgroundTabNavigationThrottle::MaybeCreateThrottleFor(handle); |
| 4160 | if (background_tab_navigation_throttle) |
| 4161 | throttles.push_back(std::move(background_tab_navigation_throttle)); |
| 4162 | #endif |
| 4163 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4164 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
Jialiu Lin | bdbb81d | 2017-10-11 21:29:09 | [diff] [blame] | 4165 | std::unique_ptr<content::NavigationThrottle> |
| 4166 | password_protection_navigation_throttle = |
| 4167 | safe_browsing::MaybeCreateNavigationThrottle(handle); |
| 4168 | if (password_protection_navigation_throttle) { |
| 4169 | throttles.push_back(std::move(password_protection_navigation_throttle)); |
| 4170 | } |
| 4171 | #endif |
| 4172 | |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 4173 | std::unique_ptr<content::NavigationThrottle> |
Mustafa Emre Acer | e14f626 | 2019-04-02 00:19:31 | [diff] [blame] | 4174 | lookalike_url_navigation_throttle = lookalikes:: |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 4175 | LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle); |
| 4176 | if (lookalike_url_navigation_throttle) |
| 4177 | throttles.push_back(std::move(lookalike_url_navigation_throttle)); |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 4178 | |
Amber Won | f56d8f4 | 2017-08-31 22:29:40 | [diff] [blame] | 4179 | std::unique_ptr<content::NavigationThrottle> pdf_iframe_throttle = |
| 4180 | PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle); |
| 4181 | if (pdf_iframe_throttle) |
| 4182 | throttles.push_back(std::move(pdf_iframe_throttle)); |
Amber Won | 6b5edc75 | 2017-08-17 19:23:54 | [diff] [blame] | 4183 | |
Charles Harrison | 6dd11d28 | 2017-10-03 06:14:51 | [diff] [blame] | 4184 | std::unique_ptr<content::NavigationThrottle> tab_under_throttle = |
| 4185 | TabUnderNavigationThrottle::MaybeCreate(handle); |
| 4186 | if (tab_under_throttle) |
| 4187 | throttles.push_back(std::move(tab_under_throttle)); |
| 4188 | |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4189 | throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>( |
Doug Turner | 9dcaf596 | 2017-12-21 04:38:53 | [diff] [blame] | 4190 | handle, handle->GetWebContents()->GetBrowserContext())); |
| 4191 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4192 | throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>( |
| 4193 | handle, |
| 4194 | std::make_unique<CertificateReportingServiceCertReporter>(web_contents), |
| 4195 | base::Bind(&SSLErrorHandler::HandleSSLError))); |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 4196 | |
Emily Stark | d6896cd3 | 2019-08-21 04:55:54 | [diff] [blame] | 4197 | throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle)); |
| 4198 | |
Christopher Thompson | 4137cec | 2017-12-19 05:34:23 | [diff] [blame] | 4199 | std::unique_ptr<content::NavigationThrottle> https_upgrade_timing_throttle = |
| 4200 | TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle); |
| 4201 | if (https_upgrade_timing_throttle) |
| 4202 | throttles.push_back(std::move(https_upgrade_timing_throttle)); |
| 4203 | |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 4204 | #if !defined(OS_ANDROID) |
| 4205 | std::unique_ptr<content::NavigationThrottle> devtools_throttle = |
| 4206 | DevToolsWindow::MaybeCreateNavigationThrottle(handle); |
| 4207 | if (devtools_throttle) |
| 4208 | throttles.push_back(std::move(devtools_throttle)); |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 4209 | |
| 4210 | std::unique_ptr<content::NavigationThrottle> new_tab_page_throttle = |
| 4211 | NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle); |
| 4212 | if (new_tab_page_throttle) |
| 4213 | throttles.push_back(std::move(new_tab_page_throttle)); |
jdoerrie | 4f9376f | 2018-12-12 18:26:20 | [diff] [blame] | 4214 | |
| 4215 | std::unique_ptr<content::NavigationThrottle> |
| 4216 | google_password_manager_throttle = |
| 4217 | GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor( |
| 4218 | handle); |
| 4219 | if (google_password_manager_throttle) |
| 4220 | throttles.push_back(std::move(google_password_manager_throttle)); |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 4221 | #endif |
| 4222 | |
Robert Ogden | afd250b | 2018-07-25 22:21:03 | [diff] [blame] | 4223 | std::unique_ptr<content::NavigationThrottle> previews_lite_page_throttle = |
| 4224 | PreviewsLitePageDecider::MaybeCreateThrottleFor(handle); |
| 4225 | if (previews_lite_page_throttle) |
| 4226 | throttles.push_back(std::move(previews_lite_page_throttle)); |
Carlos IL | 4ee307e | 2018-12-22 03:19:00 | [diff] [blame] | 4227 | if (base::FeatureList::IsEnabled(safe_browsing::kCommittedSBInterstitials)) { |
| 4228 | throttles.push_back( |
| 4229 | std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>( |
| 4230 | handle)); |
| 4231 | } |
Robert Ogden | afd250b | 2018-07-25 22:21:03 | [diff] [blame] | 4232 | |
Nicolas Ouellet-Payeur | bdcab009 | 2018-10-22 14:50:33 | [diff] [blame] | 4233 | #if defined(OS_WIN) || defined(OS_MACOSX) || \ |
| 4234 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
Nicolas Ouellet-Payeur | 995e777 | 2018-09-13 16:02:13 | [diff] [blame] | 4235 | std::unique_ptr<content::NavigationThrottle> browser_switcher_throttle = |
| 4236 | browser_switcher::BrowserSwitcherNavigationThrottle :: |
| 4237 | MaybeCreateThrottleFor(handle); |
| 4238 | if (browser_switcher_throttle) |
| 4239 | throttles.push_back(std::move(browser_switcher_throttle)); |
| 4240 | #endif |
| 4241 | |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 4242 | return throttles; |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4243 | } |
| 4244 | |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 4245 | std::unique_ptr<content::NavigationUIData> |
| 4246 | ChromeContentBrowserClient::GetNavigationUIData( |
| 4247 | content::NavigationHandle* navigation_handle) { |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4248 | return std::make_unique<ChromeNavigationUIData>(navigation_handle); |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 4249 | } |
| 4250 | |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4251 | void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps( |
| 4252 | const std::string& key_system, |
| 4253 | const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols, |
| 4254 | base::flat_set<media::VideoCodec>* video_codecs, |
| 4255 | base::flat_set<media::EncryptionMode>* encryption_schemes) { |
| 4256 | #if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \ |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 4257 | BUILDFLAG(ENABLE_WIDEVINE) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4258 | if (key_system == kWidevineKeySystem) { |
| 4259 | GetWidevineHardwareCaps(cdm_proxy_protocols, video_codecs, |
| 4260 | encryption_schemes); |
| 4261 | } |
| 4262 | #endif |
| 4263 | } |
| 4264 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4265 | content::DevToolsManagerDelegate* |
| 4266 | ChromeContentBrowserClient::GetDevToolsManagerDelegate() { |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 4267 | #if defined(OS_ANDROID) |
| 4268 | return new DevToolsManagerDelegateAndroid(); |
| 4269 | #else |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4270 | return new ChromeDevToolsManagerDelegate(); |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 4271 | #endif |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4272 | } |
| 4273 | |
Rayan Kanso | 411e84e | 2019-02-13 15:27:40 | [diff] [blame] | 4274 | void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration( |
| 4275 | content::BrowserContext* browser_context, |
| 4276 | int service, |
| 4277 | base::Time expiration_time) { |
| 4278 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4279 | DCHECK(profile); |
| 4280 | |
| 4281 | auto* pref_service = profile->GetPrefs(); |
| 4282 | DCHECK(pref_service); |
| 4283 | |
| 4284 | DictionaryPrefUpdate pref_update( |
| 4285 | pref_service, prefs::kDevToolsBackgroundServicesExpirationDict); |
| 4286 | base::DictionaryValue* exp_dict = pref_update.Get(); |
| 4287 | |
| 4288 | // Convert |expiration_time| to minutes since that is the most granular |
| 4289 | // option that returns an int. base::Value does not accept int64. |
| 4290 | int expiration_time_minutes = |
| 4291 | expiration_time.ToDeltaSinceWindowsEpoch().InMinutes(); |
| 4292 | exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes); |
| 4293 | } |
| 4294 | |
| 4295 | base::flat_map<int, base::Time> |
| 4296 | ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations( |
| 4297 | content::BrowserContext* browser_context) { |
| 4298 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4299 | DCHECK(profile); |
| 4300 | |
| 4301 | auto* pref_service = profile->GetPrefs(); |
| 4302 | DCHECK(pref_service); |
| 4303 | |
| 4304 | auto* expiration_dict = pref_service->GetDictionary( |
| 4305 | prefs::kDevToolsBackgroundServicesExpirationDict); |
| 4306 | DCHECK(expiration_dict); |
| 4307 | |
| 4308 | base::flat_map<int, base::Time> expiration_times; |
| 4309 | for (const auto& it : *expiration_dict) { |
| 4310 | // key. |
| 4311 | int service = 0; |
| 4312 | bool did_convert = base::StringToInt(it.first, &service); |
| 4313 | DCHECK(did_convert); |
| 4314 | |
| 4315 | // value. |
| 4316 | DCHECK(it.second->is_int()); |
| 4317 | base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt()); |
| 4318 | base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta); |
| 4319 | |
| 4320 | expiration_times[service] = expiration_time; |
| 4321 | } |
| 4322 | |
| 4323 | return expiration_times; |
| 4324 | } |
| 4325 | |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4326 | content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() { |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4327 | return new ChromeTracingDelegate(); |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4328 | } |
| 4329 | |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 4330 | bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle( |
| 4331 | content::BrowserContext* browser_context, |
| 4332 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4333 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 4334 | return ChromeContentBrowserClientPluginsPart:: |
| 4335 | IsPluginAllowedToCallRequestOSFileHandle(browser_context, url, |
| 4336 | allowed_file_handle_origins_); |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 4337 | #else |
| 4338 | return false; |
| 4339 | #endif |
| 4340 | } |
| 4341 | |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 4342 | bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs( |
| 4343 | content::BrowserContext* browser_context, |
| 4344 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4345 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 4346 | return ChromeContentBrowserClientPluginsPart:: |
| 4347 | IsPluginAllowedToUseDevChannelAPIs(browser_context, url, |
| 4348 | allowed_dev_channel_origins_); |
[email protected] | 8ddc6b7c | 2013-12-12 20:42:06 | [diff] [blame] | 4349 | #else |
| 4350 | return false; |
| 4351 | #endif |
| 4352 | } |
| 4353 | |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4354 | void ChromeContentBrowserClient::OverridePageVisibilityState( |
xzhan96 | cf0a3c54 | 2017-11-17 04:33:01 | [diff] [blame] | 4355 | RenderFrameHost* render_frame_host, |
danakj | 0018a29a | 2018-12-01 01:03:43 | [diff] [blame] | 4356 | content::PageVisibilityState* visibility_state) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 4357 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4358 | |
| 4359 | WebContents* web_contents = |
| 4360 | WebContents::FromRenderFrameHost(render_frame_host); |
| 4361 | DCHECK(web_contents); |
| 4362 | |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4363 | prerender::PrerenderManager* prerender_manager = |
droger | c154315 | 2016-09-20 13:03:37 | [diff] [blame] | 4364 | prerender::PrerenderManagerFactory::GetForBrowserContext( |
| 4365 | web_contents->GetBrowserContext()); |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4366 | if (prerender_manager && |
| 4367 | prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) { |
danakj | 0018a29a | 2018-12-01 01:03:43 | [diff] [blame] | 4368 | *visibility_state = content::PageVisibilityState::kPrerender; |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4369 | } |
| 4370 | } |
| 4371 | |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 4372 | void ChromeContentBrowserClient::InitWebContextInterfaces() { |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4373 | frame_interfaces_ = std::make_unique<service_manager::BinderRegistry>(); |
| 4374 | frame_interfaces_parameterized_ = std::make_unique< |
Ben Goodger | 21ada1e | 2017-07-19 14:53:01 | [diff] [blame] | 4375 | service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>(); |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 4376 | worker_interfaces_parameterized_ = |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4377 | std::make_unique<service_manager::BinderRegistryWithArgs< |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 4378 | content::RenderProcessHost*, const url::Origin&>>(); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4379 | |
Michael Martis | 4a542f5 | 2017-07-28 01:51:44 | [diff] [blame] | 4380 | // Register mojo ContentTranslateDriver interface only for main frame. |
Anthony Vallee-Dubois | e2432137a | 2019-01-17 20:06:01 | [diff] [blame] | 4381 | frame_interfaces_parameterized_->AddInterface( |
| 4382 | base::BindRepeating(&language::BindContentTranslateDriver)); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4383 | |
| 4384 | frame_interfaces_parameterized_->AddInterface( |
Ken Rockot | d480bee | 2019-08-27 18:54:48 | [diff] [blame] | 4385 | base::BindRepeating(&InsecureSensitiveInputDriverFactory::BindDriver)); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4386 | |
| 4387 | #if defined(OS_ANDROID) |
| 4388 | frame_interfaces_parameterized_->AddInterface(base::Bind( |
Matt Giuca | ee4aefb | 2017-08-04 03:11:55 | [diff] [blame] | 4389 | &ForwardToJavaFrameRegistry<blink::mojom::InstalledAppProvider>)); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4390 | frame_interfaces_parameterized_->AddInterface( |
| 4391 | base::Bind(&ForwardToJavaFrameRegistry<payments::mojom::PaymentRequest>)); |
Kim Paulhamus | 3d33e44 | 2018-03-29 23:04:14 | [diff] [blame] | 4392 | frame_interfaces_parameterized_->AddInterface( |
Amos Lim | dddb699 | 2018-07-19 22:14:32 | [diff] [blame] | 4393 | base::Bind(&ForwardToJavaFrameRegistry<blink::mojom::Authenticator>)); |
Michael Thiessen | 909ba03 | 2019-03-26 23:47:43 | [diff] [blame] | 4394 | #if defined(BROWSER_MEDIA_CONTROLS_MENU) |
| 4395 | frame_interfaces_parameterized_->AddInterface(base::Bind( |
| 4396 | &ForwardToJavaFrameRegistry<blink::mojom::MediaControlsMenuHost>)); |
| 4397 | #endif |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4398 | #else |
| 4399 | if (base::FeatureList::IsEnabled(features::kWebPayments)) { |
| 4400 | frame_interfaces_parameterized_->AddInterface( |
| 4401 | base::Bind(&payments::CreatePaymentRequest)); |
| 4402 | } |
| 4403 | #endif |
| 4404 | |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4405 | #if defined(OS_ANDROID) |
Matt Giuca | 00e99360 | 2017-06-23 05:17:54 | [diff] [blame] | 4406 | frame_interfaces_parameterized_->AddInterface(base::Bind( |
| 4407 | &ForwardToJavaWebContentsRegistry<blink::mojom::ShareService>)); |
Michael Thiessen | 07c444c | 2019-04-26 03:53:11 | [diff] [blame] | 4408 | #if defined(ENABLE_SPATIAL_NAVIGATION_HOST) |
| 4409 | frame_interfaces_parameterized_->AddInterface(base::Bind( |
| 4410 | &ForwardToJavaWebContentsRegistry<blink::mojom::SpatialNavigationHost>)); |
| 4411 | #endif |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4412 | #endif |
Reilly Grant | 8e5c85c | 2017-07-07 16:35:06 | [diff] [blame] | 4413 | |
Jay Harris | 5a42aa21b | 2018-11-28 01:23:55 | [diff] [blame] | 4414 | #if !defined(OS_ANDROID) |
Eric Stevenson | 1d074a97 | 2018-12-07 14:16:45 | [diff] [blame] | 4415 | frame_interfaces_parameterized_->AddInterface( |
Ken Rockot | d480bee | 2019-08-27 18:54:48 | [diff] [blame] | 4416 | base::BindRepeating(&badging::BadgeManager::BindRequest)); |
Eric Stevenson | c3b1805 | 2018-10-01 22:22:00 | [diff] [blame] | 4417 | #endif |
| 4418 | |
Reilly Grant | 8e5c85c | 2017-07-07 16:35:06 | [diff] [blame] | 4419 | frame_interfaces_parameterized_->AddInterface( |
Lu Chen | 5bec7a30 | 2018-06-26 18:52:32 | [diff] [blame] | 4420 | base::BindRepeating(&NavigationPredictor::Create)); |
Dan Harrington | bc87c06 | 2018-10-31 15:21:24 | [diff] [blame] | 4421 | |
| 4422 | #if defined(OS_ANDROID) |
| 4423 | frame_interfaces_parameterized_->AddInterface( |
| 4424 | base::BindRepeating(&offline_pages::OfflinePageAutoFetcher::Create), |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 4425 | base::CreateSingleThreadTaskRunner({BrowserThread::UI})); |
Dan Harrington | bc87c06 | 2018-10-31 15:21:24 | [diff] [blame] | 4426 | #endif |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4427 | } |
| 4428 | |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 4429 | void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() { |
| 4430 | base::FilePath user_data_dir; |
| 4431 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 4432 | DCHECK(!user_data_dir.empty()); |
| 4433 | network_contexts_parent_directory_.push_back(user_data_dir); |
| 4434 | |
| 4435 | base::FilePath cache_dir; |
| 4436 | chrome::GetUserCacheDirectory(user_data_dir, &cache_dir); |
| 4437 | DCHECK(!cache_dir.empty()); |
| 4438 | // On some platforms, the cache is a child of the user_data_dir so only |
| 4439 | // return the one path. |
| 4440 | if (!user_data_dir.IsParent(cache_dir)) |
| 4441 | network_contexts_parent_directory_.push_back(cache_dir); |
| 4442 | |
| 4443 | // If the cache location has been overridden by a switch or preference, |
| 4444 | // include that as well. |
| 4445 | if (auto* local_state = g_browser_process->local_state()) { |
| 4446 | base::FilePath pref_cache_dir = |
| 4447 | local_state->GetFilePath(prefs::kDiskCacheDir); |
| 4448 | if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir)) |
| 4449 | network_contexts_parent_directory_.push_back(pref_cache_dir); |
| 4450 | } |
| 4451 | } |
| 4452 | |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4453 | void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 4454 | base::CommandLine* to_command_line, |
| 4455 | const base::CommandLine& from_command_line, |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4456 | version_info::Channel channel) { |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4457 | #if defined(OS_ANDROID) |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4458 | const version_info::Channel kMaxDisableEncryptionChannel = |
| 4459 | version_info::Channel::BETA; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4460 | #else |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4461 | const version_info::Channel kMaxDisableEncryptionChannel = |
| 4462 | version_info::Channel::DEV; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4463 | #endif |
| 4464 | if (channel <= kMaxDisableEncryptionChannel) { |
| 4465 | static const char* const kWebRtcDevSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 4466 | switches::kDisableWebRtcEncryption, |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4467 | }; |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 4468 | to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames, |
| 4469 | base::size(kWebRtcDevSwitchNames)); |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4470 | } |
| 4471 | } |
bashi | 93362955 | 2016-10-13 23:32:40 | [diff] [blame] | 4472 | |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4473 | #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 4474 | void ChromeContentBrowserClient::CreateMediaRemoter( |
| 4475 | content::RenderFrameHost* render_frame_host, |
| 4476 | media::mojom::RemotingSourcePtr source, |
| 4477 | media::mojom::RemoterRequest request) { |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4478 | CastRemotingConnector::CreateMediaRemoter( |
| 4479 | render_frame_host, std::move(source), std::move(request)); |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4480 | } |
| 4481 | #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING) |
robliao | bf5a32e | 2016-12-09 03:35:46 | [diff] [blame] | 4482 | |
Michael Giuffrida | 6802ffe | 2017-09-29 03:40:25 | [diff] [blame] | 4483 | base::FilePath ChromeContentBrowserClient::GetLoggingFileName( |
| 4484 | const base::CommandLine& command_line) { |
| 4485 | return logging::GetLogFileName(command_line); |
kerrnel | a67fad5 | 2017-06-14 20:18:16 | [diff] [blame] | 4486 | } |
| 4487 | |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4488 | namespace { |
| 4489 | // TODO(jam): move this to a separate file. |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4490 | class ProtocolHandlerThrottle : public blink::URLLoaderThrottle { |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4491 | public: |
| 4492 | explicit ProtocolHandlerThrottle( |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4493 | ProtocolHandlerRegistry* protocol_handler_registry) |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4494 | : protocol_handler_registry_(protocol_handler_registry) {} |
| 4495 | ~ProtocolHandlerThrottle() override = default; |
| 4496 | |
| 4497 | void WillStartRequest(network::ResourceRequest* request, |
| 4498 | bool* defer) override { |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4499 | TranslateUrl(&request->url); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4500 | } |
| 4501 | |
| 4502 | void WillRedirectRequest(net::RedirectInfo* redirect_info, |
| 4503 | const network::ResourceResponseHead& response_head, |
| 4504 | bool* defer, |
| 4505 | std::vector<std::string>* to_be_removed_headers, |
| 4506 | net::HttpRequestHeaders* modified_headers) override { |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4507 | TranslateUrl(&redirect_info->new_url); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4508 | } |
| 4509 | |
| 4510 | private: |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4511 | void TranslateUrl(GURL* url) { |
| 4512 | if (!protocol_handler_registry_->IsHandledProtocol(url->scheme())) |
| 4513 | return; |
| 4514 | GURL translated_url = protocol_handler_registry_->Translate(*url); |
| 4515 | if (!translated_url.is_empty()) |
| 4516 | *url = translated_url; |
| 4517 | } |
| 4518 | |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4519 | ProtocolHandlerRegistry* protocol_handler_registry_; |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4520 | }; |
| 4521 | } // namespace |
| 4522 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4523 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4524 | ChromeContentBrowserClient::CreateURLLoaderThrottles( |
| 4525 | const network::ResourceRequest& request, |
| 4526 | content::BrowserContext* browser_context, |
| 4527 | const base::RepeatingCallback<content::WebContents*()>& wc_getter, |
| 4528 | content::NavigationUIData* navigation_ui_data, |
| 4529 | int frame_tree_node_id) { |
| 4530 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 4531 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4532 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result; |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4533 | |
| 4534 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4535 | |
| 4536 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4537 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4538 | |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 4539 | auto* drp_settings = |
| 4540 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 4541 | browser_context); |
| 4542 | if (chrome_navigation_ui_data && !profile->IsIncognitoProfile() && |
| 4543 | data_reduction_proxy::params::IsEnabledWithNetworkService() && |
| 4544 | drp_settings) { |
| 4545 | if (!data_reduction_proxy_throttle_manager_) { |
| 4546 | data_reduction_proxy_throttle_manager_ = std::unique_ptr< |
| 4547 | data_reduction_proxy::DataReductionProxyThrottleManager, |
| 4548 | base::OnTaskRunnerDeleter>( |
| 4549 | new data_reduction_proxy::DataReductionProxyThrottleManager( |
| 4550 | drp_settings->data_reduction_proxy_service(), |
| 4551 | data_reduction_proxy::DataReductionProxyThrottleManager:: |
Clark DuVall | 0e90172 | 2019-08-14 23:31:37 | [diff] [blame] | 4552 | CreateConfig(drp_settings->data_reduction_proxy_service() |
| 4553 | ->config() |
| 4554 | ->GetProxiesForHttp())), |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 4555 | base::OnTaskRunnerDeleter(base::SequencedTaskRunnerHandle::Get())); |
| 4556 | } |
| 4557 | net::HttpRequestHeaders headers; |
| 4558 | data_reduction_proxy::DataReductionProxyRequestOptions:: |
| 4559 | AddPageIDRequestHeader( |
| 4560 | &headers, |
| 4561 | chrome_navigation_ui_data->data_reduction_proxy_page_id()); |
| 4562 | result.push_back(std::make_unique< |
| 4563 | data_reduction_proxy::DataReductionProxyURLLoaderThrottle>( |
| 4564 | headers, data_reduction_proxy_throttle_manager_.get())); |
| 4565 | } |
| 4566 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4567 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4568 | bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy( |
| 4569 | request.url, *profile->GetPrefs()); |
| 4570 | if (!matches_enterprise_whitelist) { |
| 4571 | result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create( |
| 4572 | base::BindOnce( |
| 4573 | &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate, |
| 4574 | base::Unretained(this)), |
| 4575 | wc_getter, frame_tree_node_id, profile->GetResourceContext())); |
| 4576 | } |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4577 | #endif |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4578 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4579 | if (chrome_navigation_ui_data && |
| 4580 | chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) { |
| 4581 | result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>( |
| 4582 | chrome_navigation_ui_data->prerender_mode(), |
| 4583 | chrome_navigation_ui_data->prerender_histogram_prefix(), |
| 4584 | base::BindOnce(GetPrerenderCanceller, wc_getter), |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 4585 | base::CreateSingleThreadTaskRunner({BrowserThread::UI}))); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | bool is_off_the_record = profile->IsOffTheRecord(); |
| 4589 | bool is_signed_in = !is_off_the_record && |
| 4590 | !profile->GetPrefs() |
| 4591 | ->GetString(prefs::kGoogleServicesUserAccountId) |
| 4592 | .empty(); |
| 4593 | |
| 4594 | chrome::mojom::DynamicParams dynamic_params = { |
| 4595 | profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch), |
| 4596 | profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict), |
| 4597 | profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps), |
| 4598 | variations::VariationsHttpHeaderProvider::GetInstance() |
| 4599 | ->GetClientDataHeader(is_signed_in)}; |
| 4600 | result.push_back(std::make_unique<GoogleURLLoaderThrottle>( |
| 4601 | is_off_the_record, std::move(dynamic_params))); |
| 4602 | |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4603 | result.push_back(std::make_unique<ProtocolHandlerThrottle>( |
| 4604 | ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context))); |
Clark DuVall | 8512cee6 | 2019-06-26 01:14:21 | [diff] [blame] | 4605 | |
Clark DuVall | 39c2cfc | 2019-06-25 21:49:28 | [diff] [blame] | 4606 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 4607 | result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>( |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 4608 | request.resource_type, frame_tree_node_id)); |
Clark DuVall | 39c2cfc | 2019-06-25 21:49:28 | [diff] [blame] | 4609 | #endif |
| 4610 | |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 4611 | auto delegate = |
| 4612 | std::make_unique<signin::HeaderModificationDelegateOnUIThreadImpl>( |
| 4613 | profile); |
| 4614 | auto signin_throttle = signin::URLLoaderThrottle::MaybeCreate( |
| 4615 | std::move(delegate), navigation_ui_data, wc_getter); |
| 4616 | if (signin_throttle) |
| 4617 | result.push_back(std::move(signin_throttle)); |
| 4618 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4619 | return result; |
| 4620 | } |
| 4621 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4622 | void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4623 | int frame_tree_node_id, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4624 | NonNetworkURLLoaderFactoryMap* factories) { |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4625 | #if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4626 | content::WebContents* web_contents = |
| 4627 | content::WebContents::FromFrameTreeNodeId(frame_tree_node_id); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4628 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4629 | factories->emplace( |
| 4630 | extensions::kExtensionScheme, |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 4631 | extensions::CreateExtensionNavigationURLLoaderFactory( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4632 | web_contents->GetBrowserContext(), |
| 4633 | !!extensions::WebViewGuest::FromWebContents(web_contents))); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4634 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 4635 | #if defined(OS_CHROMEOS) |
| 4636 | Profile* profile = |
| 4637 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Robbie McElrath | 89cc933 | 2019-03-05 02:12:30 | [diff] [blame] | 4638 | factories->emplace(content::kExternalFileScheme, |
| 4639 | std::make_unique<chromeos::ExternalFileURLLoaderFactory>( |
| 4640 | profile, content::ChildProcessHost::kInvalidUniqueID)); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4641 | #endif // defined(OS_CHROMEOS) |
| 4642 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4643 | } |
| 4644 | |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4645 | void ChromeContentBrowserClient:: |
| 4646 | RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories( |
| 4647 | content::BrowserContext* browser_context, |
| 4648 | NonNetworkURLLoaderFactoryMap* factories) { |
| 4649 | #if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
| 4650 | DCHECK(browser_context); |
| 4651 | DCHECK(factories); |
| 4652 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4653 | factories->emplace( |
| 4654 | extensions::kExtensionScheme, |
| 4655 | extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory( |
| 4656 | browser_context)); |
| 4657 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 4658 | #if defined(OS_CHROMEOS) |
| 4659 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4660 | factories->emplace(content::kExternalFileScheme, |
| 4661 | std::make_unique<chromeos::ExternalFileURLLoaderFactory>( |
| 4662 | profile, content::ChildProcessHost::kInvalidUniqueID)); |
| 4663 | #endif // defined(OS_CHROMEOS) |
| 4664 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
| 4665 | } |
| 4666 | |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4667 | namespace { |
| 4668 | |
| 4669 | // The FileURLLoaderFactory provided to the extension background pages. |
| 4670 | // Checks with the ChildProcessSecurityPolicy to validate the file access. |
| 4671 | class FileURLLoaderFactory : public network::mojom::URLLoaderFactory { |
| 4672 | public: |
| 4673 | explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {} |
| 4674 | |
| 4675 | private: |
| 4676 | // network::mojom::URLLoaderFactory: |
| 4677 | void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader, |
| 4678 | int32_t routing_id, |
| 4679 | int32_t request_id, |
| 4680 | uint32_t options, |
| 4681 | const network::ResourceRequest& request, |
| 4682 | network::mojom::URLLoaderClientPtr client, |
| 4683 | const net::MutableNetworkTrafficAnnotationTag& |
| 4684 | traffic_annotation) override { |
| 4685 | if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL( |
| 4686 | child_id_, request.url)) { |
| 4687 | client->OnComplete( |
| 4688 | network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED)); |
| 4689 | return; |
| 4690 | } |
| 4691 | content::CreateFileURLLoader(request, std::move(loader), std::move(client), |
John Abd-El-Malek | 916f2b8 | 2019-02-19 23:49:45 | [diff] [blame] | 4692 | /*observer=*/nullptr, |
| 4693 | /* allow_directory_listing */ true); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4694 | } |
| 4695 | |
| 4696 | void Clone(network::mojom::URLLoaderFactoryRequest loader) override { |
| 4697 | bindings_.AddBinding(this, std::move(loader)); |
| 4698 | } |
| 4699 | |
| 4700 | int child_id_; |
| 4701 | mojo::BindingSet<network::mojom::URLLoaderFactory> bindings_; |
| 4702 | DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory); |
| 4703 | }; |
| 4704 | |
| 4705 | } // namespace |
| 4706 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4707 | void ChromeContentBrowserClient:: |
| 4708 | RegisterNonNetworkSubresourceURLLoaderFactories( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4709 | int render_process_id, |
| 4710 | int render_frame_id, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4711 | NonNetworkURLLoaderFactoryMap* factories) { |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4712 | #if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS) |
| 4713 | content::RenderFrameHost* frame_host = |
| 4714 | RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 4715 | WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host); |
| 4716 | #endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS) |
| 4717 | |
| 4718 | #if defined(OS_CHROMEOS) |
| 4719 | if (web_contents) { |
| 4720 | Profile* profile = |
| 4721 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Robbie McElrath | 89cc933 | 2019-03-05 02:12:30 | [diff] [blame] | 4722 | factories->emplace(content::kExternalFileScheme, |
| 4723 | std::make_unique<chromeos::ExternalFileURLLoaderFactory>( |
| 4724 | profile, render_process_id)); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4725 | } |
| 4726 | #endif // defined(OS_CHROMEOS) |
| 4727 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4728 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4729 | auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id, |
| 4730 | render_frame_id); |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4731 | if (factory) |
| 4732 | factories->emplace(extensions::kExtensionScheme, std::move(factory)); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4733 | |
| 4734 | // This logic should match |
| 4735 | // ChromeExtensionWebContentsObserver::RenderFrameCreated. |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4736 | if (!web_contents) |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4737 | return; |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4738 | |
| 4739 | Profile* profile = |
| 4740 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 4741 | InstantService* instant_service = |
| 4742 | InstantServiceFactory::GetForProfile(profile); |
| 4743 | // The test below matches what's done by ShouldServiceRequestIOThread in |
| 4744 | // local_ntp_source.cc. |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4745 | if (instant_service->IsInstantProcess(render_process_id)) { |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4746 | factories->emplace( |
| 4747 | chrome::kChromeSearchScheme, |
| 4748 | content::CreateWebUIURLLoader( |
| 4749 | frame_host, chrome::kChromeSearchScheme, |
| 4750 | /*allowed_webui_hosts=*/base::flat_set<std::string>())); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4751 | } |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4752 | |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4753 | extensions::ChromeExtensionWebContentsObserver* web_observer = |
| 4754 | extensions::ChromeExtensionWebContentsObserver::FromWebContents( |
| 4755 | web_contents); |
| 4756 | |
Karan Bhatia | 9192857 | 2018-03-06 01:18:07 | [diff] [blame] | 4757 | // There is nothing to do if no ChromeExtensionWebContentsObserver is attached |
| 4758 | // to the |web_contents|. |
| 4759 | if (!web_observer) |
| 4760 | return; |
| 4761 | |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4762 | const Extension* extension = |
| 4763 | web_observer->GetExtensionFromFrame(frame_host, false); |
| 4764 | if (!extension) |
| 4765 | return; |
| 4766 | |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4767 | std::vector<std::string> allowed_webui_hosts; |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4768 | // Support for chrome:// scheme if appropriate. |
| 4769 | if ((extension->is_extension() || extension->is_platform_app()) && |
| 4770 | Manifest::IsComponentLocation(extension->location())) { |
| 4771 | // Components of chrome that are implemented as extensions or platform apps |
| 4772 | // are allowed to use chrome://resources/ and chrome://theme/ URLs. |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4773 | allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost); |
| 4774 | allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost); |
| 4775 | } |
| 4776 | if (extension->is_extension() || extension->is_legacy_packaged_app() || |
| 4777 | (extension->is_platform_app() && |
| 4778 | Manifest::IsComponentLocation(extension->location()))) { |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4779 | // Extensions, legacy packaged apps, and component platform apps are allowed |
Lucas Tenório | 3dd8092 | 2019-03-27 03:51:02 | [diff] [blame] | 4780 | // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon |
| 4781 | // URLs. Hosted apps are not allowed because they are served via web servers |
| 4782 | // (and are generally never given access to Chrome APIs). |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4783 | allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost); |
| 4784 | allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost); |
Lucas Tenório | 3dd8092 | 2019-03-27 03:51:02 | [diff] [blame] | 4785 | allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost); |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4786 | } |
| 4787 | if (!allowed_webui_hosts.empty()) { |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4788 | factories->emplace( |
| 4789 | content::kChromeUIScheme, |
| 4790 | content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme, |
| 4791 | std::move(allowed_webui_hosts))); |
| 4792 | } |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4793 | |
| 4794 | // Extension with a background page get file access that gets approval from |
| 4795 | // ChildProcessSecurityPolicy. |
| 4796 | extensions::ExtensionHost* host = |
| 4797 | extensions::ProcessManager::Get(web_contents->GetBrowserContext()) |
| 4798 | ->GetBackgroundHostForExtension(extension->id()); |
| 4799 | if (host) { |
| 4800 | factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>( |
| 4801 | render_process_id)); |
| 4802 | } |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4803 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4804 | } |
| 4805 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4806 | bool ChromeContentBrowserClient::WillCreateURLLoaderFactory( |
Ken Rockot | 428b1d6 | 2018-06-06 17:12:21 | [diff] [blame] | 4807 | content::BrowserContext* browser_context, |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4808 | content::RenderFrameHost* frame, |
Kenichi Ishibashi | 09ee5e7 | 2018-11-27 07:12:38 | [diff] [blame] | 4809 | int render_process_id, |
Karan Bhatia | 4a834b3 | 2019-08-16 22:26:44 | [diff] [blame] | 4810 | URLLoaderFactoryType type, |
Lukasz Anforowicz | 76273365 | 2018-09-28 14:48:26 | [diff] [blame] | 4811 | const url::Origin& request_initiator, |
Dominic Farolino | 1be897a | 2019-07-20 08:11:42 | [diff] [blame] | 4812 | mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver, |
Julie Jeongeun Kim | 47499a0c | 2019-08-28 07:23:18 | [diff] [blame] | 4813 | mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>* |
| 4814 | header_client, |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4815 | bool* bypass_redirect_checks) { |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4816 | bool use_proxy = false; |
| 4817 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4818 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4819 | auto* web_request_api = |
| 4820 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
Ken Rockot | 428b1d6 | 2018-06-06 17:12:21 | [diff] [blame] | 4821 | browser_context); |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4822 | |
| 4823 | // NOTE: Some unit test environments do not initialize |
| 4824 | // BrowserContextKeyedAPI factories for e.g. WebRequest. |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4825 | if (web_request_api) { |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4826 | bool use_proxy_for_web_request = |
Kenichi Ishibashi | 09ee5e7 | 2018-11-27 07:12:38 | [diff] [blame] | 4827 | web_request_api->MaybeProxyURLLoaderFactory( |
Karan Bhatia | 4a834b3 | 2019-08-16 22:26:44 | [diff] [blame] | 4828 | browser_context, frame, render_process_id, type, factory_receiver, |
| 4829 | header_client); |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4830 | if (bypass_redirect_checks) |
| 4831 | *bypass_redirect_checks = use_proxy_for_web_request; |
| 4832 | use_proxy |= use_proxy_for_web_request; |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4833 | } |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4834 | #endif |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4835 | |
Reilly Grant | cc22e60 | 2018-09-07 15:25:20 | [diff] [blame] | 4836 | use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest( |
Karan Bhatia | 4a834b3 | 2019-08-16 22:26:44 | [diff] [blame] | 4837 | frame, type == URLLoaderFactoryType::kNavigation, request_initiator, |
| 4838 | factory_receiver); |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4839 | |
| 4840 | return use_proxy; |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4841 | } |
| 4842 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4843 | std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> |
| 4844 | ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors( |
| 4845 | content::NavigationUIData* navigation_ui_data, |
Ryan Sturm | 27d93f41 | 2019-02-15 21:30:14 | [diff] [blame] | 4846 | int frame_tree_node_id, |
| 4847 | const scoped_refptr<network::SharedURLLoaderFactory>& |
| 4848 | network_loader_factory) { |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4849 | std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> |
| 4850 | interceptors; |
| 4851 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 4852 | interceptors.push_back( |
| 4853 | std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>( |
| 4854 | navigation_ui_data, frame_tree_node_id)); |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4855 | #endif |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 4856 | |
Robert Ogden | 3d5d5b4 | 2019-04-22 05:13:11 | [diff] [blame] | 4857 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4858 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4859 | |
Ryan Sturm | 27d93f41 | 2019-02-15 21:30:14 | [diff] [blame] | 4860 | // TODO(ryansturm): Once this is on the UI thread, stop passing |
| 4861 | // |network_loader_factory| and have interceptors create one themselves. |
| 4862 | // https://crbug.com/931786 |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 4863 | if (base::FeatureList::IsEnabled( |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 4864 | previews::features::kHTTPSServerPreviewsUsingURLLoader)) { |
| 4865 | interceptors.push_back( |
| 4866 | std::make_unique<previews::PreviewsLitePageURLLoaderInterceptor>( |
Robert Ogden | 3d5d5b4 | 2019-04-22 05:13:11 | [diff] [blame] | 4867 | network_loader_factory, |
| 4868 | chrome_navigation_ui_data->data_reduction_proxy_page_id(), |
| 4869 | frame_tree_node_id)); |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 4870 | } |
| 4871 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4872 | return interceptors; |
| 4873 | } |
| 4874 | |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4875 | bool ChromeContentBrowserClient::WillInterceptWebSocket( |
| 4876 | content::RenderFrameHost* frame) { |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4877 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4878 | if (!frame) { |
| 4879 | return false; |
| 4880 | } |
| 4881 | const auto* web_request_api = |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4882 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
| 4883 | frame->GetProcess()->GetBrowserContext()); |
| 4884 | |
| 4885 | // NOTE: Some unit test environments do not initialize |
| 4886 | // BrowserContextKeyedAPI factories for e.g. WebRequest. |
| 4887 | if (!web_request_api) |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4888 | return false; |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4889 | |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4890 | return web_request_api->MayHaveProxies(); |
| 4891 | #else |
| 4892 | return false; |
| 4893 | #endif |
| 4894 | } |
| 4895 | |
| 4896 | void ChromeContentBrowserClient::CreateWebSocket( |
| 4897 | content::RenderFrameHost* frame, |
| 4898 | WebSocketFactory factory, |
| 4899 | const GURL& url, |
| 4900 | const GURL& site_for_cookies, |
| 4901 | const base::Optional<std::string>& user_agent, |
Julie Jeongeun Kim | 3e973f9 | 2019-08-22 08:02:40 | [diff] [blame] | 4902 | mojo::PendingRemote<network::mojom::WebSocketHandshakeClient> |
| 4903 | handshake_client) { |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4904 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4905 | if (!frame) { |
| 4906 | return; |
| 4907 | } |
| 4908 | auto* web_request_api = |
| 4909 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
| 4910 | frame->GetProcess()->GetBrowserContext()); |
| 4911 | |
| 4912 | DCHECK(web_request_api); |
| 4913 | web_request_api->ProxyWebSocket(frame, std::move(factory), url, |
| 4914 | site_for_cookies, user_agent, |
| 4915 | std::move(handshake_client)); |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4916 | #endif |
| 4917 | } |
| 4918 | |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4919 | bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager( |
Maks Orlovich | e7db7a2 | 2019-07-25 01:47:46 | [diff] [blame] | 4920 | network::mojom::RestrictedCookieManagerRole role, |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4921 | content::BrowserContext* browser_context, |
| 4922 | const url::Origin& origin, |
| 4923 | bool is_service_worker, |
| 4924 | int process_id, |
| 4925 | int routing_id, |
Julie Jeongeun Kim | d20f64b | 2019-08-26 04:13:03 | [diff] [blame] | 4926 | mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) { |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4927 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 4928 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4929 | if (origin.scheme() == extensions::kExtensionScheme) { |
Maks Orlovich | e7db7a2 | 2019-07-25 01:47:46 | [diff] [blame] | 4930 | DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role); |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4931 | extensions::ChromeExtensionCookies::Get(browser_context) |
Julie Jeongeun Kim | d20f64b | 2019-08-26 04:13:03 | [diff] [blame] | 4932 | ->CreateRestrictedCookieManager(origin, std::move(*receiver)); |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4933 | return true; |
| 4934 | } |
| 4935 | #endif |
| 4936 | return false; |
| 4937 | } |
| 4938 | |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 4939 | void ChromeContentBrowserClient::OnNetworkServiceCreated( |
| 4940 | network::mojom::NetworkService* network_service) { |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4941 | PrefService* local_state; |
| 4942 | if (g_browser_process) { |
| 4943 | DCHECK(g_browser_process->local_state()); |
| 4944 | local_state = g_browser_process->local_state(); |
| 4945 | } else { |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 4946 | DCHECK(startup_data_->chrome_feature_list_creator()->local_state()); |
| 4947 | local_state = startup_data_->chrome_feature_list_creator()->local_state(); |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4948 | } |
| 4949 | |
| 4950 | if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance()) |
| 4951 | data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state); |
| 4952 | |
Henrique Nakashima | a3b1c5d | 2019-07-03 19:25:49 | [diff] [blame] | 4953 | // Create SystemNetworkContextManager if it has not been created yet. We need |
| 4954 | // to set up global NetworkService state before anything else uses it and this |
| 4955 | // is the first opportunity to initialize SystemNetworkContextManager with the |
| 4956 | // NetworkService. |
| 4957 | if (!SystemNetworkContextManager::HasInstance()) |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4958 | SystemNetworkContextManager::CreateInstance(local_state); |
John Abd-El-Malek | 897374f4 | 2019-05-30 03:58:07 | [diff] [blame] | 4959 | |
Min Qin | 8caab1d | 2018-10-03 17:28:13 | [diff] [blame] | 4960 | SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated( |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 4961 | network_service); |
| 4962 | } |
| 4963 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4964 | network::mojom::NetworkContextPtr |
| 4965 | ChromeContentBrowserClient::CreateNetworkContext( |
| 4966 | content::BrowserContext* context, |
| 4967 | bool in_memory, |
| 4968 | const base::FilePath& relative_partition_path) { |
John Abd-El-Malek | cc0b2a6 | 2018-03-20 19:32:50 | [diff] [blame] | 4969 | Profile* profile = Profile::FromBrowserContext(context); |
Matt Menke | d38efd9 | 2018-08-14 20:39:45 | [diff] [blame] | 4970 | return profile->CreateNetworkContext(in_memory, relative_partition_path); |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4971 | } |
| 4972 | |
Robert Sesek | 34f68f31 | 2019-01-14 20:25:11 | [diff] [blame] | 4973 | std::vector<base::FilePath> |
| 4974 | ChromeContentBrowserClient::GetNetworkContextsParentDirectory() { |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 4975 | DCHECK(!network_contexts_parent_directory_.empty()); |
| 4976 | return network_contexts_parent_directory_; |
Robert Sesek | 34f68f31 | 2019-01-14 20:25:11 | [diff] [blame] | 4977 | } |
| 4978 | |
Min Qin | 75ed6df | 2017-12-01 20:39:15 | [diff] [blame] | 4979 | bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp( |
Min Qin | 30a78a1 | 2017-12-06 01:29:13 | [diff] [blame] | 4980 | content::NavigationUIData* navigation_ui_data) { |
Min Qin | 75ed6df | 2017-12-01 20:39:15 | [diff] [blame] | 4981 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 4982 | // It is OK to load the saved offline copy, in MHTML format. |
| 4983 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4984 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4985 | if (!chrome_navigation_ui_data) |
| 4986 | return false; |
| 4987 | offline_pages::OfflinePageNavigationUIData* offline_page_data = |
| 4988 | chrome_navigation_ui_data->GetOfflinePageNavigationUIData(); |
| 4989 | return offline_page_data && offline_page_data->is_offline_page(); |
| 4990 | #else |
| 4991 | return false; |
| 4992 | #endif |
| 4993 | } |
| 4994 | |
Min Qin | 30a78a1 | 2017-12-06 01:29:13 | [diff] [blame] | 4995 | bool ChromeContentBrowserClient::ShouldForceDownloadResource( |
| 4996 | const GURL& url, |
| 4997 | const std::string& mime_type) { |
| 4998 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4999 | // Special-case user scripts to get downloaded instead of viewed. |
| 5000 | return extensions::UserScript::IsURLUserScript(url, mime_type); |
| 5001 | #else |
| 5002 | return false; |
| 5003 | #endif |
| 5004 | } |
| 5005 | |
Donna Wu | 838ac36 | 2018-08-10 10:36:33 | [diff] [blame] | 5006 | void ChromeContentBrowserClient::CreateWebUsbService( |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5007 | content::RenderFrameHost* render_frame_host, |
Miyoung Shin | 6262215 | 2019-08-27 05:13:04 | [diff] [blame] | 5008 | mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) { |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5009 | if (!base::FeatureList::IsEnabled(features::kWebUsb)) |
| 5010 | return; |
| 5011 | |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5012 | WebContents* web_contents = |
| 5013 | WebContents::FromRenderFrameHost(render_frame_host); |
| 5014 | if (!web_contents) { |
| 5015 | NOTREACHED(); |
| 5016 | return; |
| 5017 | } |
| 5018 | |
| 5019 | UsbTabHelper* tab_helper = |
| 5020 | UsbTabHelper::GetOrCreateForWebContents(web_contents); |
Miyoung Shin | 6262215 | 2019-08-27 05:13:04 | [diff] [blame] | 5021 | tab_helper->CreateWebUsbService(render_frame_host, std::move(receiver)); |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5022 | } |
| 5023 | |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 5024 | #if !defined(OS_ANDROID) |
| 5025 | content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() { |
| 5026 | if (!serial_delegate_) |
| 5027 | serial_delegate_ = std::make_unique<ChromeSerialDelegate>(); |
| 5028 | return serial_delegate_.get(); |
| 5029 | } |
Matt Reynolds | 93616f9b | 2019-06-07 01:28:52 | [diff] [blame] | 5030 | |
| 5031 | content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() { |
| 5032 | if (!hid_delegate_) |
| 5033 | hid_delegate_ = std::make_unique<ChromeHidDelegate>(); |
| 5034 | return hid_delegate_.get(); |
| 5035 | } |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 5036 | |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 5037 | std::unique_ptr<content::AuthenticatorRequestClientDelegate> |
| 5038 | ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate( |
Adam Langley | eeac87e | 2019-04-13 22:58:22 | [diff] [blame] | 5039 | content::RenderFrameHost* render_frame_host, |
| 5040 | const std::string& relying_party_id) { |
| 5041 | return AuthenticatorRequestScheduler::CreateRequestDelegate(render_frame_host, |
| 5042 | relying_party_id); |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 5043 | } |
Nina Satragno | 8c832df | 2019-07-29 15:59:39 | [diff] [blame] | 5044 | #endif |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 5045 | |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 5046 | std::unique_ptr<net::ClientCertStore> |
| 5047 | ChromeContentBrowserClient::CreateClientCertStore( |
| 5048 | content::ResourceContext* resource_context) { |
| 5049 | if (!resource_context) |
| 5050 | return nullptr; |
| 5051 | return ProfileIOData::FromResourceContext(resource_context) |
| 5052 | ->CreateClientCertStore(); |
| 5053 | } |
| 5054 | |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 5055 | std::unique_ptr<content::LoginDelegate> |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5056 | ChromeContentBrowserClient::CreateLoginDelegate( |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5057 | const net::AuthChallengeInfo& auth_info, |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 5058 | content::WebContents* web_contents, |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5059 | const content::GlobalRequestID& request_id, |
Jun Cai | 8e165d2 | 2018-05-14 19:21:24 | [diff] [blame] | 5060 | bool is_request_for_main_frame, |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5061 | const GURL& url, |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5062 | scoped_refptr<net::HttpResponseHeaders> response_headers, |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5063 | bool first_auth_attempt, |
Mark Pilgrim | 7cfcd11 | 2018-05-08 00:07:56 | [diff] [blame] | 5064 | LoginAuthRequiredCallback auth_required_callback) { |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5065 | return CreateLoginPrompt( |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 5066 | auth_info, web_contents, request_id, is_request_for_main_frame, url, |
Emily Stark | c5f1579 | 2019-05-19 17:24:20 | [diff] [blame] | 5067 | std::move(response_headers), LoginHandler::PRE_COMMIT, |
| 5068 | std::move(auth_required_callback)); |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5069 | } |
| 5070 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5071 | bool ChromeContentBrowserClient::HandleExternalProtocol( |
| 5072 | const GURL& url, |
John Abd-El-Malek | 92bf360 | 2019-07-31 02:25:48 | [diff] [blame] | 5073 | content::WebContents::Getter web_contents_getter, |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5074 | int child_id, |
| 5075 | content::NavigationUIData* navigation_data, |
| 5076 | bool is_main_frame, |
| 5077 | ui::PageTransition page_transition, |
Tim Volodine | b24393f3 | 2018-11-16 18:45:45 | [diff] [blame] | 5078 | bool has_user_gesture, |
Clark DuVall | b6042ed3 | 2019-07-15 17:20:45 | [diff] [blame] | 5079 | network::mojom::URLLoaderFactoryPtr* out_factory) { |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5080 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5081 | // External protocols are disabled for guests. An exception is made for the |
| 5082 | // "mailto" protocol, so that pages that utilize it work properly in a |
| 5083 | // WebView. |
| 5084 | ChromeNavigationUIData* chrome_data = |
| 5085 | static_cast<ChromeNavigationUIData*>(navigation_data); |
| 5086 | if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) || |
| 5087 | (chrome_data && |
| 5088 | chrome_data->GetExtensionNavigationUIData()->is_web_view())) && |
| 5089 | !url.SchemeIs(url::kMailToScheme)) { |
| 5090 | return false; |
| 5091 | } |
| 5092 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 5093 | |
| 5094 | #if defined(OS_ANDROID) |
| 5095 | // Main frame external protocols are handled by |
| 5096 | // InterceptNavigationResourceThrottle. |
| 5097 | if (is_main_frame) |
| 5098 | return false; |
| 5099 | #endif // defined(ANDROID) |
| 5100 | |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 5101 | base::PostTask(FROM_HERE, {BrowserThread::UI}, |
| 5102 | base::BindOnce(&LaunchURL, url, web_contents_getter, |
| 5103 | page_transition, has_user_gesture)); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5104 | return true; |
| 5105 | } |
| 5106 | |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5107 | std::unique_ptr<content::OverlayWindow> |
Jennifer Apacible | 6010b023 | 2018-04-12 23:35:28 | [diff] [blame] | 5108 | ChromeContentBrowserClient::CreateWindowForPictureInPicture( |
| 5109 | content::PictureInPictureWindowController* controller) { |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5110 | // Note: content::OverlayWindow::Create() is defined by platform-specific |
| 5111 | // implementation in chrome/browser/ui/views. This layering hack, which goes |
| 5112 | // through //content and ContentBrowserClient, allows us to work around the |
| 5113 | // dependency constraints that disallow directly calling |
| 5114 | // chrome/browser/ui/views code either from here or from other code in |
| 5115 | // chrome/browser. |
Jennifer Apacible | 6010b023 | 2018-04-12 23:35:28 | [diff] [blame] | 5116 | return content::OverlayWindow::Create(controller); |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5117 | } |
| 5118 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 5119 | bool ChromeContentBrowserClient::IsSafeRedirectTarget( |
| 5120 | const GURL& url, |
| 5121 | content::BrowserContext* context) { |
| 5122 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5123 | if (url.SchemeIs(extensions::kExtensionScheme)) { |
| 5124 | const Extension* extension = extensions::ExtensionRegistry::Get(context) |
| 5125 | ->enabled_extensions() |
| 5126 | .GetByID(url.host()); |
| 5127 | if (!extension) |
| 5128 | return false; |
| 5129 | return extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible( |
| 5130 | extension, url.path()); |
| 5131 | } |
| 5132 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 5133 | return true; |
| 5134 | } |
| 5135 | |
Kunihiko Sakamoto | 19aa708 | 2019-02-25 03:14:43 | [diff] [blame] | 5136 | void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher( |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5137 | content::BrowserContext* browser_context, |
Julie Jeongeun Kim | 6d8b749 | 2019-08-20 19:24:11 | [diff] [blame] | 5138 | mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) { |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5139 | Profile* profile = Profile::FromBrowserContext(browser_context); |
Kunihiko Sakamoto | 19aa708 | 2019-02-25 03:14:43 | [diff] [blame] | 5140 | PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher( |
| 5141 | std::move(watcher)); |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5142 | } |
| 5143 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5144 | // Static; handles rewriting Web UI URLs. |
| 5145 | bool ChromeContentBrowserClient::HandleWebUI( |
| 5146 | GURL* url, |
| 5147 | content::BrowserContext* browser_context) { |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 5148 | // Rewrite chrome://help to chrome://settings/help. |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5149 | if (url->SchemeIs(content::kChromeUIScheme) && |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 5150 | url->host() == chrome::kChromeUIHelpHost) { |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5151 | *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost, |
| 5152 | chrome::kChromeUIHelpHost); |
| 5153 | return true; // Return true to update the displayed URL. |
| 5154 | } |
| 5155 | |
| 5156 | if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 5157 | browser_context, *url)) { |
| 5158 | return false; |
| 5159 | } |
| 5160 | |
| 5161 | #if defined(OS_CHROMEOS) |
| 5162 | // Special case : in ChromeOS in Guest mode bookmarks and history are |
| 5163 | // disabled for security reasons. New tab page explains the reasons, so |
| 5164 | // we redirect user to new tab page. |
| 5165 | if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { |
| 5166 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 5167 | (url->DomainIs(chrome::kChromeUIBookmarksHost) || |
| 5168 | url->DomainIs(chrome::kChromeUIHistoryHost))) { |
| 5169 | // Rewrite with new tab URL |
| 5170 | *url = GURL(chrome::kChromeUINewTabURL); |
| 5171 | } |
| 5172 | } |
| 5173 | #endif |
| 5174 | |
| 5175 | return true; |
| 5176 | } |
| 5177 | |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 5178 | bool ChromeContentBrowserClient::ShowPaymentHandlerWindow( |
| 5179 | content::BrowserContext* browser_context, |
| 5180 | const GURL& url, |
Anthony Vallee-Dubois | 98befeaa | 2018-01-18 16:31:32 | [diff] [blame] | 5181 | base::OnceCallback<void(bool, int, int)> callback) { |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 5182 | #if defined(OS_ANDROID) |
| 5183 | return false; |
| 5184 | #else |
| 5185 | payments::PaymentRequestDisplayManagerFactory::GetInstance() |
| 5186 | ->GetForBrowserContext(browser_context) |
| 5187 | ->ShowPaymentHandlerWindow(url, std::move(callback)); |
| 5188 | return true; |
| 5189 | #endif |
| 5190 | } |
| 5191 | |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 5192 | // static |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5193 | bool ChromeContentBrowserClient::HandleWebUIReverse( |
| 5194 | GURL* url, |
| 5195 | content::BrowserContext* browser_context) { |
| 5196 | // No need to actually reverse-rewrite the URL, but return true to update the |
| 5197 | // displayed URL when rewriting chrome://help to chrome://settings/help. |
| 5198 | return url->SchemeIs(content::kChromeUIScheme) && |
| 5199 | url->host() == chrome::kChromeUISettingsHost; |
| 5200 | } |
| 5201 | |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 5202 | const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const { |
| 5203 | return ui::NativeTheme::GetInstanceForWeb(); |
| 5204 | } |
| 5205 | |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 5206 | // static |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 5207 | void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( |
| 5208 | const storage::QuotaSettings* settings) { |
| 5209 | g_default_quota_settings = settings; |
| 5210 | } |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5211 | |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 5212 | scoped_refptr<safe_browsing::UrlCheckerDelegate> |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 5213 | ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate( |
| 5214 | content::ResourceContext* resource_context) { |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5215 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 5216 | |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 5217 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 5218 | if (!io_data->safe_browsing_enabled()->GetValue()) |
| 5219 | return nullptr; |
| 5220 | |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5221 | // |safe_browsing_service_| may be unavailable in tests. |
| 5222 | if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) { |
| 5223 | safe_browsing_url_checker_delegate_ = |
Jialiu Lin | 0de6756c | 2018-03-22 00:57:43 | [diff] [blame] | 5224 | base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>( |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5225 | safe_browsing_service_->database_manager(), |
Jialiu Lin | 0de6756c | 2018-03-22 00:57:43 | [diff] [blame] | 5226 | safe_browsing_service_->ui_manager()); |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5227 | } |
| 5228 | |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 5229 | return safe_browsing_url_checker_delegate_; |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5230 | } |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 5231 | |
| 5232 | base::Optional<std::string> |
| 5233 | ChromeContentBrowserClient::GetOriginPolicyErrorPage( |
Andy Paicu | 8b6f871 | 2019-07-16 15:02:26 | [diff] [blame] | 5234 | network::OriginPolicyState error_reason, |
Daniel Vogelheim | 7badd0d | 2019-02-04 14:42:18 | [diff] [blame] | 5235 | content::NavigationHandle* handle) { |
| 5236 | return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML( |
| 5237 | error_reason, handle); |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 5238 | } |
Kunihiko Sakamoto | 73b803d | 2018-10-05 09:09:52 | [diff] [blame] | 5239 | |
Takashi Toyoshima | 5af383aa | 2019-07-22 15:24:22 | [diff] [blame] | 5240 | bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() { |
Kunihiko Sakamoto | 73b803d | 2018-10-05 09:09:52 | [diff] [blame] | 5241 | // We require --user-data-dir flag too so that no dangerous changes are made |
| 5242 | // in the user's regular profile. |
| 5243 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 5244 | switches::kUserDataDir); |
| 5245 | } |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 5246 | |
| 5247 | void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate( |
| 5248 | int32_t network_traffic_annotation_id_hash, |
| 5249 | int64_t recv_bytes, |
| 5250 | int64_t sent_bytes) { |
Min Qin | cafb27b | 2018-10-30 18:02:03 | [diff] [blame] | 5251 | if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) { |
| 5252 | data_use_measurement::ChromeDataUseMeasurement::GetInstance() |
| 5253 | ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash, |
| 5254 | recv_bytes, sent_bytes); |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 5255 | } |
| 5256 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5257 | |
| 5258 | content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews( |
| 5259 | content::PreviewsState initial_state, |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5260 | content::NavigationHandle* navigation_handle, |
| 5261 | const GURL& current_navigation_url) { |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5262 | content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback( |
| 5263 | initial_state, navigation_handle, current_navigation_url); |
| 5264 | |
| 5265 | return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle); |
| 5266 | } |
| 5267 | |
| 5268 | content::PreviewsState |
| 5269 | ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback( |
| 5270 | content::PreviewsState initial_state, |
| 5271 | content::NavigationHandle* navigation_handle, |
| 5272 | const GURL& current_navigation_url) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5273 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
Tarun Bansal | b89c1d5 | 2019-01-16 06:56:29 | [diff] [blame] | 5274 | DCHECK(!navigation_handle->HasCommitted()); |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5275 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5276 | // If this is not a main frame, return the initial state. If there are no |
| 5277 | // previews in the state, return the state as is. |
| 5278 | if (!navigation_handle->IsInMainFrame() || |
| 5279 | navigation_handle->IsSameDocument()) { |
| 5280 | return initial_state; |
| 5281 | } |
| 5282 | |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5283 | if (!current_navigation_url.SchemeIsHTTPOrHTTPS()) |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5284 | return content::PREVIEWS_OFF; |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5285 | |
Doug Arnett | b3b99bc | 2019-08-09 16:55:56 | [diff] [blame] | 5286 | // Check if initial state specifies no previews should be considered. |
| 5287 | if (initial_state == content::PREVIEWS_OFF) |
| 5288 | return initial_state; |
| 5289 | |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5290 | // Do not allow previews on POST navigations since the primary opt-out |
| 5291 | // mechanism is to reload the page. Because POST navigations are not |
| 5292 | // idempotent, we do not want to show a preview on a POST navigation where |
| 5293 | // opting out would cause another navigation, i.e.: a reload. |
| 5294 | if (navigation_handle->IsPost()) |
| 5295 | return content::PREVIEWS_OFF; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5296 | |
| 5297 | content::WebContents* web_contents = navigation_handle->GetWebContents(); |
| 5298 | content::WebContentsDelegate* delegate = web_contents->GetDelegate(); |
| 5299 | |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5300 | auto* browser_context = web_contents->GetBrowserContext(); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5301 | |
| 5302 | PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile( |
| 5303 | Profile::FromBrowserContext(browser_context)); |
| 5304 | auto* data_reduction_proxy_settings = |
| 5305 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 5306 | browser_context); |
| 5307 | // If the profile does not support previews or Data Saver, do not turn on |
| 5308 | // Previews. |
| 5309 | if (!previews_service || !previews_service->previews_ui_service() || |
Owen Min | 08a7289 | 2019-07-31 20:03:35 | [diff] [blame] | 5310 | !data_reduction_proxy_settings) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5311 | return content::PREVIEWS_OFF; |
| 5312 | } |
| 5313 | |
| 5314 | PreviewsUITabHelper* ui_tab_helper = |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5315 | PreviewsUITabHelper::FromWebContents(web_contents); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5316 | // If this tab does not have a PreviewsUITabHelper, no preview should be |
| 5317 | // served. |
| 5318 | if (!ui_tab_helper) |
| 5319 | return content::PREVIEWS_OFF; |
| 5320 | |
| 5321 | DCHECK(!browser_context->IsOffTheRecord()); |
| 5322 | |
| 5323 | // Other previews objects should all exist and be initialized if we have made |
| 5324 | // it past earlier checks. |
| 5325 | previews::PreviewsDeciderImpl* previews_decider_impl = |
| 5326 | previews_service->previews_ui_service()->previews_decider_impl(); |
| 5327 | DCHECK(previews_decider_impl); |
| 5328 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5329 | // Start with an unspecified state. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5330 | content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED; |
| 5331 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5332 | previews::PreviewsUserData* previews_data = |
| 5333 | ui_tab_helper->GetPreviewsUserData(navigation_handle); |
| 5334 | |
| 5335 | // Certain PreviewsStates are used within URLLoaders (Offline, server |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5336 | // previews) and cannot re-evaluate PreviewsState once previews triggering |
| 5337 | // logic has already been run, so they should not change. Assume that |
| 5338 | // previews triggering logic has run when PreviewsUserData already exists and |
| 5339 | // a Lite Page Redirect preview is not being attempted, since it may also |
| 5340 | // create a previews_data before this point. |
| 5341 | bool previews_triggering_logic_already_ran = false; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5342 | if (previews_data) { |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5343 | previews_triggering_logic_already_ran = |
| 5344 | !previews_data->server_lite_page_info(); |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5345 | } else { |
| 5346 | previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle( |
| 5347 | navigation_handle, previews_decider_impl->GeneratePageId()); |
| 5348 | } |
| 5349 | |
| 5350 | DCHECK(previews_data); |
| 5351 | |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 5352 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 5353 | previews::switches::kForceEnablePreviews)) { |
Sophie Chang | acd9e2d | 2019-08-22 22:05:09 | [diff] [blame] | 5354 | previews_decider_impl->LoadPageHints(navigation_handle); |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 5355 | return content::ALL_SUPPORTED_PREVIEWS; |
| 5356 | } |
| 5357 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5358 | bool is_reload = |
| 5359 | navigation_handle->GetReloadType() != content::ReloadType::NONE; |
| 5360 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5361 | content::PreviewsState server_previews_enabled_state = |
Robert Ogden | 54bb4ff | 2019-06-19 01:31:51 | [diff] [blame] | 5362 | content::SERVER_LITE_PAGE_ON; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5363 | |
| 5364 | // For now, treat server previews types as a single decision, and do not |
| 5365 | // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT |
| 5366 | // header, nor does the plumbing exist to modify the PreviewsState within the |
| 5367 | // URLLoader. |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5368 | if (previews_triggering_logic_already_ran) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5369 | // Copy the server state that was used before the redirect for the initial |
| 5370 | // URL. |
Robert Ogden | 869986f | 2019-06-20 19:12:05 | [diff] [blame] | 5371 | previews_state |= |
| 5372 | (previews_data->AllowedPreviewsState() & server_previews_enabled_state); |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5373 | } else { |
Doug Arnett | a3dc7158 | 2018-11-08 00:25:10 | [diff] [blame] | 5374 | if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart( |
Sophie Chang | ff1fc38 | 2019-08-21 16:30:21 | [diff] [blame] | 5375 | previews_data, navigation_handle, is_reload, |
Doug Arnett | d5a6003 | 2018-11-12 19:37:30 | [diff] [blame] | 5376 | previews::PreviewsType::LITE_PAGE)) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5377 | previews_state |= server_previews_enabled_state; |
| 5378 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5379 | } |
| 5380 | |
Robert Ogden | 198d657 | 2019-06-26 15:15:33 | [diff] [blame] | 5381 | // Evaluate Offline, NoScript, and ResourceBlocking previews. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5382 | previews_state |= previews::DetermineAllowedClientPreviewsState( |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5383 | previews_data, previews_triggering_logic_already_ran, |
Owen Min | 08a7289 | 2019-07-31 20:03:35 | [diff] [blame] | 5384 | data_reduction_proxy_settings->IsDataReductionProxyEnabled(), |
| 5385 | previews_decider_impl, navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5386 | |
| 5387 | if (previews_state & content::PREVIEWS_OFF) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5388 | previews_data->set_allowed_previews_state(content::PREVIEWS_OFF); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5389 | return content::PREVIEWS_OFF; |
| 5390 | } |
| 5391 | |
| 5392 | if (previews_state & content::PREVIEWS_NO_TRANSFORM) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5393 | previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5394 | return content::PREVIEWS_NO_TRANSFORM; |
| 5395 | } |
| 5396 | |
| 5397 | // At this point, if no Preview is allowed, don't allow previews. |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5398 | if (previews_state == content::PREVIEWS_UNSPECIFIED) { |
| 5399 | previews_data->set_allowed_previews_state(content::PREVIEWS_OFF); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5400 | return content::PREVIEWS_OFF; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5401 | } |
| 5402 | |
| 5403 | content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED; |
| 5404 | if (delegate) { |
| 5405 | delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state); |
| 5406 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5407 | |
| 5408 | // If the allowed previews are limited by the embedder, ensure previews honors |
| 5409 | // those limits. |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5410 | if (embedder_state != content::PREVIEWS_UNSPECIFIED) { |
| 5411 | previews_state = previews_state & embedder_state; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5412 | // If no valid previews are left, set the state explicitly to PREVIEWS_OFF. |
| 5413 | if (previews_state == content::PREVIEWS_UNSPECIFIED) |
| 5414 | previews_state = content::PREVIEWS_OFF; |
| 5415 | } |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5416 | previews_data->set_allowed_previews_state(previews_state); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5417 | return previews_state; |
| 5418 | } |
| 5419 | |
| 5420 | // static |
| 5421 | content::PreviewsState |
| 5422 | ChromeContentBrowserClient::DetermineCommittedPreviewsForURL( |
| 5423 | const GURL& url, |
| 5424 | data_reduction_proxy::DataReductionProxyData* drp_data, |
| 5425 | previews::PreviewsUserData* previews_user_data, |
| 5426 | const previews::PreviewsDecider* previews_decider, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5427 | content::PreviewsState initial_state, |
| 5428 | content::NavigationHandle* navigation_handle) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5429 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 5430 | if (!previews::HasEnabledPreviews(initial_state)) |
| 5431 | return content::PREVIEWS_OFF; |
| 5432 | |
| 5433 | // Check if the server sent a preview directive. |
| 5434 | content::PreviewsState previews_state = |
Clark DuVall | 0ec5214 | 2019-06-06 19:53:55 | [diff] [blame] | 5435 | previews::DetermineCommittedServerPreviewsState(drp_data, initial_state); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5436 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5437 | // Check the various other client previews types. |
| 5438 | return previews::DetermineCommittedClientPreviewsState( |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5439 | previews_user_data, url, previews_state, previews_decider, |
| 5440 | navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5441 | } |
| 5442 | |
| 5443 | content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews( |
| 5444 | content::PreviewsState initial_state, |
| 5445 | content::NavigationHandle* navigation_handle, |
| 5446 | const net::HttpResponseHeaders* response_headers) { |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5447 | content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback( |
| 5448 | initial_state, navigation_handle, response_headers); |
| 5449 | |
| 5450 | return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle); |
| 5451 | } |
| 5452 | |
| 5453 | content::PreviewsState |
| 5454 | ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback( |
| 5455 | content::PreviewsState initial_state, |
| 5456 | content::NavigationHandle* navigation_handle, |
| 5457 | const net::HttpResponseHeaders* response_headers) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5458 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 5459 | // Only support HTTP and HTTPS. |
| 5460 | if (navigation_handle->IsErrorPage() || |
| 5461 | !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) { |
| 5462 | return content::PREVIEWS_OFF; |
| 5463 | } |
| 5464 | |
| 5465 | // If this is not a main frame, return the initial state. If there are no |
| 5466 | // previews in the state, return the state as is. |
| 5467 | if (!previews::HasEnabledPreviews(initial_state) || |
| 5468 | !navigation_handle->IsInMainFrame() || |
| 5469 | navigation_handle->IsSameDocument()) { |
| 5470 | return initial_state; |
| 5471 | } |
| 5472 | |
| 5473 | // WebContents that don't have a PreviewsUITabHelper are not supported. |
| 5474 | PreviewsUITabHelper* ui_tab_helper = |
| 5475 | PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents()); |
| 5476 | if (!ui_tab_helper) |
| 5477 | return content::PREVIEWS_OFF; |
| 5478 | |
| 5479 | // If we did not previously create a PreviewsUserData, do not go any further. |
| 5480 | previews::PreviewsUserData* previews_user_data = |
| 5481 | ui_tab_helper->GetPreviewsUserData(navigation_handle); |
| 5482 | if (!previews_user_data) |
| 5483 | return content::PREVIEWS_OFF; |
| 5484 | |
| 5485 | PreviewsService* previews_service = |
| 5486 | PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext( |
| 5487 | navigation_handle->GetWebContents()->GetBrowserContext())); |
| 5488 | |
| 5489 | if (!previews_service || !previews_service->previews_ui_service()) |
| 5490 | return content::PREVIEWS_OFF; |
| 5491 | |
| 5492 | // Check if offline previews are being used and set it in the user data. |
| 5493 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 5494 | offline_pages::OfflinePageTabHelper* tab_helper = |
| 5495 | offline_pages::OfflinePageTabHelper::FromWebContents( |
| 5496 | navigation_handle->GetWebContents()); |
| 5497 | |
Ryan Sturm | fc7d92f | 2019-02-12 02:24:23 | [diff] [blame] | 5498 | bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage(); |
| 5499 | bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem(); |
| 5500 | |
| 5501 | // If this is an offline page, but not a preview, then we should not attempt |
| 5502 | // any previews or surface the previews UI. |
| 5503 | if (is_offline_page && !is_offline_preview) |
| 5504 | return content::PREVIEWS_OFF; |
| 5505 | |
| 5506 | previews_user_data->set_offline_preview_used(is_offline_preview); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5507 | #endif // BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 5508 | |
| 5509 | // Annotate request if no-transform directive found in response headers. |
| 5510 | if (response_headers && |
| 5511 | response_headers->HasHeaderValue("cache-control", "no-transform")) { |
Jered Gray | ba1da12 | 2018-10-31 23:06:26 | [diff] [blame] | 5512 | previews_user_data->set_cache_control_no_transform_directive(); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5513 | } |
| 5514 | |
| 5515 | previews::PreviewsDeciderImpl* previews_decider_impl = |
| 5516 | previews_service->previews_ui_service()->previews_decider_impl(); |
| 5517 | DCHECK(previews_decider_impl); |
| 5518 | |
Clark DuVall | 9c5a72cc | 2018-10-25 01:29:21 | [diff] [blame] | 5519 | std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data; |
| 5520 | auto* settings = |
| 5521 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 5522 | navigation_handle->GetWebContents()->GetBrowserContext()); |
| 5523 | if (settings) { |
| 5524 | // TODO(898326): |drp_data| may be incomplete because |navigation_handle| |
| 5525 | // does not yet have all the response information. |
| 5526 | drp_data = settings->CreateDataFromNavigationHandle(navigation_handle, |
| 5527 | response_headers); |
| 5528 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5529 | |
| 5530 | // Determine effective PreviewsState for this committed main frame response. |
| 5531 | content::PreviewsState committed_state = DetermineCommittedPreviewsForURL( |
Clark DuVall | 9c5a72cc | 2018-10-25 01:29:21 | [diff] [blame] | 5532 | navigation_handle->GetURL(), drp_data.get(), previews_user_data, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5533 | previews_decider_impl, initial_state, navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5534 | |
| 5535 | // Double check that we never serve a preview when we have a |
| 5536 | // cache-control:no-transform directive. |
| 5537 | DCHECK(!previews_user_data->cache_control_no_transform_directive() || |
| 5538 | !previews::HasEnabledPreviews(committed_state)); |
| 5539 | |
Robert Ogden | ded292c6f | 2019-05-03 22:44:51 | [diff] [blame] | 5540 | // TODO(robertogden): Consider moving this to after the holdback logic. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5541 | previews_user_data->set_committed_previews_state(committed_state); |
| 5542 | |
| 5543 | previews::PreviewsType committed_type = |
| 5544 | previews::GetMainFramePreviewsType(committed_state); |
| 5545 | |
| 5546 | // Capture committed previews type, if any, in PreviewsUserData. |
| 5547 | // Note: this is for the subset of previews types that are decided upon |
| 5548 | // navigation commit. Previews types that are determined prior to |
| 5549 | // navigation (such as for offline pages or for redirecting to another |
| 5550 | // url), are not set here. |
| 5551 | previews_user_data->SetCommittedPreviewsType(committed_type); |
| 5552 | |
| 5553 | // Log the commit decision. |
| 5554 | std::vector<previews::PreviewsEligibilityReason> passed_reasons; |
| 5555 | previews_decider_impl->LogPreviewDecisionMade( |
| 5556 | (previews_user_data->cache_control_no_transform_directive() |
| 5557 | ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM |
| 5558 | : previews::PreviewsEligibilityReason::COMMITTED), |
| 5559 | navigation_handle->GetURL(), base::Time::Now(), |
Robert Ogden | 869986f | 2019-06-20 19:12:05 | [diff] [blame] | 5560 | previews_user_data->CommittedPreviewsType(), std::move(passed_reasons), |
Robert Ogden | 33e3631 | 2019-05-06 19:17:05 | [diff] [blame] | 5561 | previews_user_data); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5562 | |
| 5563 | return committed_state; |
| 5564 | } |
Charlie Harrison | 650e1142 | 2018-12-04 00:37:26 | [diff] [blame] | 5565 | |
| 5566 | void ChromeContentBrowserClient::LogWebFeatureForCurrentPage( |
| 5567 | content::RenderFrameHost* render_frame_host, |
| 5568 | blink::mojom::WebFeature feature) { |
| 5569 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 5570 | page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {}); |
| 5571 | page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage( |
| 5572 | render_frame_host, new_features); |
| 5573 | } |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5574 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5575 | std::string ChromeContentBrowserClient::GetProduct() { |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5576 | return ::GetProduct(); |
| 5577 | } |
| 5578 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5579 | std::string ChromeContentBrowserClient::GetUserAgent() { |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5580 | return ::GetUserAgent(); |
| 5581 | } |
Sam McNally | d54e23f9 | 2019-01-16 04:42:39 | [diff] [blame] | 5582 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5583 | blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() { |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 5584 | return ::GetUserAgentMetadata(); |
| 5585 | } |
| 5586 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5587 | base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() { |
Austin Orion | e250d01 | 2019-05-29 02:56:27 | [diff] [blame] | 5588 | // This icon is available on Android, but adds 19KiB to the APK. Since it |
| 5589 | // isn't used on Android we exclude it to avoid bloat. |
| 5590 | #if !defined(OS_ANDROID) |
| 5591 | return base::Optional<gfx::ImageSkia>( |
| 5592 | *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 5593 | IDR_PRODUCT_LOGO_256)); |
| 5594 | #else |
| 5595 | return base::nullopt; |
| 5596 | #endif |
| 5597 | } |
| 5598 | |
Sam McNally | d54e23f9 | 2019-01-16 04:42:39 | [diff] [blame] | 5599 | bool ChromeContentBrowserClient::IsBuiltinComponent( |
| 5600 | content::BrowserContext* browser_context, |
| 5601 | const url::Origin& origin) { |
| 5602 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5603 | return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent( |
| 5604 | browser_context, origin); |
| 5605 | #else |
| 5606 | return false; |
| 5607 | #endif |
| 5608 | } |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 5609 | |
| 5610 | bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted( |
| 5611 | const GURL& url, |
| 5612 | content::BrowserContext* context) { |
| 5613 | PolicyBlacklistService* service = |
| 5614 | PolicyBlacklistFactory::GetForBrowserContext(context); |
| 5615 | |
| 5616 | using URLBlacklistState = policy::URLBlacklist::URLBlacklistState; |
| 5617 | URLBlacklistState blacklist_state = service->GetURLBlacklistState(url); |
| 5618 | return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST; |
| 5619 | } |
Dominic Mazzoni | 21fb028 | 2019-02-13 18:32:47 | [diff] [blame] | 5620 | |
| 5621 | ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext( |
| 5622 | content::BrowserContext* browser_context) { |
| 5623 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 5624 | return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode(); |
| 5625 | } |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5626 | |
| 5627 | #if defined(OS_ANDROID) |
| 5628 | content::ContentBrowserClient::WideColorGamutHeuristic |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5629 | ChromeContentBrowserClient::GetWideColorGamutHeuristic() { |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5630 | if (features::UseDisplayWideColorGamut()) { |
| 5631 | return WideColorGamutHeuristic::kUseDisplay; |
| 5632 | } |
| 5633 | return WideColorGamutHeuristic::kNone; |
| 5634 | } |
| 5635 | #endif |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5636 | |
| 5637 | base::flat_set<std::string> |
Ehsan Karamad | 466529d | 2019-05-24 03:24:43 | [diff] [blame] | 5638 | ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers( |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 5639 | content::BrowserContext* browser_context) { |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5640 | base::flat_set<std::string> mime_types; |
| 5641 | #if BUILDFLAG(ENABLE_PLUGINS) |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 5642 | auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context); |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5643 | for (const auto& pair : map) |
| 5644 | mime_types.insert(pair.first); |
| 5645 | #endif |
| 5646 | return mime_types; |
| 5647 | } |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5648 | |
| 5649 | void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy( |
| 5650 | const content::WebContents* web_contents, |
| 5651 | const content::RenderFrameHost* frame_host, |
| 5652 | bool user_gesture, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5653 | content::NavigationDownloadPolicy* download_policy) { |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5654 | const ChromeSubresourceFilterClient* client = |
| 5655 | ChromeSubresourceFilterClient::FromWebContents(web_contents); |
| 5656 | if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) { |
Yao Xiao | f6064666 | 2019-07-25 07:25:04 | [diff] [blame] | 5657 | download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame); |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5658 | if (!user_gesture) { |
| 5659 | if (base::FeatureList::IsEnabled( |
| 5660 | blink::features:: |
| 5661 | kBlockingDownloadsInAdFrameWithoutUserActivation)) { |
| 5662 | download_policy->SetDisallowed( |
| 5663 | content::NavigationDownloadType::kAdFrameNoGesture); |
| 5664 | } else { |
| 5665 | download_policy->SetAllowed( |
| 5666 | content::NavigationDownloadType::kAdFrameNoGesture); |
| 5667 | } |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5668 | } |
| 5669 | } |
| 5670 | } |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5671 | |
| 5672 | bool ChromeContentBrowserClient::IsBluetoothScanningBlocked( |
| 5673 | content::BrowserContext* browser_context, |
| 5674 | const url::Origin& requesting_origin, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5675 | const url::Origin& embedding_origin) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5676 | const HostContentSettingsMap* const content_settings = |
| 5677 | HostContentSettingsMapFactory::GetForProfile( |
| 5678 | Profile::FromBrowserContext(browser_context)); |
| 5679 | |
| 5680 | if (content_settings->GetContentSetting( |
| 5681 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
| 5682 | CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING, |
| 5683 | std::string()) == CONTENT_SETTING_BLOCK) { |
| 5684 | return true; |
| 5685 | } |
| 5686 | |
| 5687 | return false; |
| 5688 | } |
| 5689 | |
| 5690 | void ChromeContentBrowserClient::BlockBluetoothScanning( |
| 5691 | content::BrowserContext* browser_context, |
| 5692 | const url::Origin& requesting_origin, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5693 | const url::Origin& embedding_origin) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5694 | HostContentSettingsMap* const content_settings = |
| 5695 | HostContentSettingsMapFactory::GetForProfile( |
| 5696 | Profile::FromBrowserContext(browser_context)); |
| 5697 | |
| 5698 | content_settings->SetContentSettingDefaultScope( |
| 5699 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
| 5700 | CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING, std::string(), |
| 5701 | CONTENT_SETTING_BLOCK); |
| 5702 | } |