[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" |
leon.han | 952ea325 | 2016-04-13 02:44:56 | [diff] [blame] | 84 | #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 85 | #include "chrome/browser/payments/payment_request_display_manager_factory.h" |
Sigurdur Asgeirsson | 54b7270 | 2019-04-12 14:18:54 | [diff] [blame] | 86 | #include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h" |
Sigurdur Asgeirsson | 7069667 | 2019-02-08 16:14:51 | [diff] [blame] | 87 | #include "chrome/browser/performance_manager/chrome_content_browser_client_performance_manager_part.h" |
Adam Langley | 85339f6 | 2018-02-12 22:03:56 | [diff] [blame] | 88 | #include "chrome/browser/permissions/attestation_permission_request.h" |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 89 | #include "chrome/browser/permissions/permission_context_base.h" |
Adam Langley | 85339f6 | 2018-02-12 22:03:56 | [diff] [blame] | 90 | #include "chrome/browser/permissions/permission_request_manager.h" |
[email protected] | 0609b17f | 2011-05-31 20:13:42 | [diff] [blame] | 91 | #include "chrome/browser/platform_util.h" |
Amber Won | 94afd811 | 2017-08-23 17:30:11 | [diff] [blame] | 92 | #include "chrome/browser/plugins/pdf_iframe_navigation_throttle.h" |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 93 | #include "chrome/browser/plugins/plugin_utils.h" |
Alexandr Ilin | 4909ec8 | 2018-06-06 10:22:48 | [diff] [blame] | 94 | #include "chrome/browser/predictors/loading_predictor.h" |
| 95 | #include "chrome/browser/predictors/loading_predictor_factory.h" |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 96 | #include "chrome/browser/prerender/prerender_final_status.h" |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 97 | #include "chrome/browser/prerender/prerender_manager.h" |
[email protected] | 3085c50 | 2011-10-05 17:50:50 | [diff] [blame] | 98 | #include "chrome/browser/prerender/prerender_manager_factory.h" |
[email protected] | 2736c03 | 2012-05-11 18:06:07 | [diff] [blame] | 99 | #include "chrome/browser/prerender/prerender_message_filter.h" |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 100 | #include "chrome/browser/prerender/prerender_util.h" |
Ryan Sturm | cc5071be | 2019-02-16 02:15:19 | [diff] [blame] | 101 | #include "chrome/browser/previews/previews_content_util.h" |
Robert Ogden | afd250b | 2018-07-25 22:21:03 | [diff] [blame] | 102 | #include "chrome/browser/previews/previews_lite_page_decider.h" |
Robert Ogden | e7fdca9 | 2018-10-12 17:53:06 | [diff] [blame] | 103 | #include "chrome/browser/previews/previews_lite_page_navigation_throttle.h" |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 104 | #include "chrome/browser/previews/previews_lite_page_url_loader_interceptor.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 105 | #include "chrome/browser/previews/previews_service.h" |
| 106 | #include "chrome/browser/previews/previews_service_factory.h" |
| 107 | #include "chrome/browser/previews/previews_ui_tab_helper.h" |
[email protected] | 7e75e4a | 2013-05-17 17:20:03 | [diff] [blame] | 108 | #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 109 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 110 | #include "chrome/browser/profiles/profile_io_data.h" |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 111 | #include "chrome/browser/profiles/renderer_updater.h" |
| 112 | #include "chrome/browser/profiles/renderer_updater_factory.h" |
Erik Chen | 49bbfa2 | 2017-08-18 08:49:56 | [diff] [blame] | 113 | #include "chrome/browser/profiling_host/chrome_browser_main_extra_parts_profiling.h" |
| 114 | #include "chrome/browser/profiling_host/profiling_process_host.h" |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 115 | #include "chrome/browser/renderer_host/chrome_navigation_ui_data.h" |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 116 | #include "chrome/browser/renderer_host/chrome_render_message_filter.h" |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 117 | #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory.h" |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 118 | #include "chrome/browser/renderer_preferences_util.h" |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 119 | #include "chrome/browser/resource_coordinator/background_tab_navigation_throttle.h" |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 120 | #include "chrome/browser/safe_browsing/certificate_reporting_service.h" |
| 121 | #include "chrome/browser/safe_browsing/certificate_reporting_service_factory.h" |
Carlos IL | 4ee307e | 2018-12-22 03:19:00 | [diff] [blame] | 122 | #include "chrome/browser/safe_browsing/safe_browsing_navigation_throttle.h" |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 123 | #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 124 | #include "chrome/browser/safe_browsing/ui_manager.h" |
| 125 | #include "chrome/browser/safe_browsing/url_checker_delegate_impl.h" |
[email protected] | a7b8e43d | 2013-03-18 18:52:43 | [diff] [blame] | 126 | #include "chrome/browser/search/search.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 127 | #include "chrome/browser/sessions/session_tab_helper.h" |
Reilly Grant | cc22e60 | 2018-09-07 15:25:20 | [diff] [blame] | 128 | #include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h" |
Reilly Grant | 3787780 | 2018-08-18 00:58:35 | [diff] [blame] | 129 | #include "chrome/browser/signin/chrome_signin_url_loader_throttle.h" |
Robbie McElrath | 38f47af | 2019-09-19 21:51:40 | [diff] [blame] | 130 | #include "chrome/browser/signin/header_modification_delegate_impl.h" |
David Roger | e8e83f3c | 2019-09-12 10:56:23 | [diff] [blame] | 131 | #include "chrome/browser/signin/identity_manager_factory.h" |
Lukasz Anforowicz | fd30af3 | 2019-03-28 17:33:28 | [diff] [blame] | 132 | #include "chrome/browser/site_isolation/site_isolation_policy.h" |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 133 | #include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h" |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 134 | #include "chrome/browser/speech/tts_controller_delegate_impl.h" |
Eric Lawrence | d0acf2a7c | 2017-07-20 18:02:48 | [diff] [blame] | 135 | #include "chrome/browser/ssl/insecure_sensitive_input_driver_factory.h" |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 136 | #include "chrome/browser/ssl/ssl_blocking_page.h" |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 137 | #include "chrome/browser/ssl/ssl_cert_reporter.h" |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 138 | #include "chrome/browser/ssl/ssl_client_auth_metrics.h" |
[email protected] | 25af6ec | 2014-06-06 19:35:07 | [diff] [blame] | 139 | #include "chrome/browser/ssl/ssl_client_certificate_selector.h" |
meacer | 4ef065e | 2015-01-09 03:21:35 | [diff] [blame] | 140 | #include "chrome/browser/ssl/ssl_error_handler.h" |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 141 | #include "chrome/browser/ssl/ssl_error_navigation_throttle.h" |
Christopher Thompson | 4137cec | 2017-12-19 05:34:23 | [diff] [blame] | 142 | #include "chrome/browser/ssl/typed_navigation_timing_throttle.h" |
csharrison | 77bf834 | 2017-05-04 18:23:10 | [diff] [blame] | 143 | #include "chrome/browser/subresource_filter/chrome_subresource_filter_client.h" |
meacer | 4ef065e | 2015-01-09 03:21:35 | [diff] [blame] | 144 | #include "chrome/browser/sync_file_system/local/sync_file_system_backend.h" |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 145 | #include "chrome/browser/tab_contents/tab_util.h" |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 146 | #include "chrome/browser/tracing/chrome_tracing_delegate.h" |
Dave Tapuska | c6627e1 | 2018-08-30 15:07:19 | [diff] [blame] | 147 | #include "chrome/browser/translate/translate_service.h" |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 148 | #include "chrome/browser/ui/blocked_content/blocked_window_params.h" |
Charlie Harrison | 804659a | 2018-10-16 16:43:38 | [diff] [blame] | 149 | #include "chrome/browser/ui/blocked_content/popup_blocker.h" |
Charles Harrison | 6dd11d28 | 2017-10-03 06:14:51 | [diff] [blame] | 150 | #include "chrome/browser/ui/blocked_content/tab_under_navigation_throttle.h" |
thestig | e8082124 | 2015-09-30 23:46:08 | [diff] [blame] | 151 | #include "chrome/browser/ui/browser_navigator.h" |
| 152 | #include "chrome/browser/ui/browser_navigator_params.h" |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 153 | #include "chrome/browser/ui/chrome_select_file_policy.h" |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 154 | #include "chrome/browser/ui/login/login_handler.h" |
Emily Stark | d6896cd3 | 2019-08-21 04:55:54 | [diff] [blame] | 155 | #include "chrome/browser/ui/login/login_navigation_throttle.h" |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 156 | #include "chrome/browser/ui/prefs/pref_watcher.h" |
[email protected] | 329ac97 | 2013-06-21 15:24:25 | [diff] [blame] | 157 | #include "chrome/browser/ui/sync/sync_promo_ui.h" |
[email protected] | b5d7342 | 2012-06-02 23:46:44 | [diff] [blame] | 158 | #include "chrome/browser/ui/tab_contents/chrome_web_contents_view_delegate.h" |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 159 | #include "chrome/browser/ui/ui_features.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 160 | #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
dbeam | baee5bd | 2015-09-26 03:07:01 | [diff] [blame] | 161 | #include "chrome/browser/ui/webui/log_web_ui_url.h" |
reillyg | 3ff4532 | 2015-10-23 21:16:25 | [diff] [blame] | 162 | #include "chrome/browser/usb/usb_tab_helper.h" |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 163 | #include "chrome/browser/vr/vr_tab_helper.h" |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 164 | #include "chrome/browser/web_applications/components/app_registrar.h" |
| 165 | #include "chrome/browser/web_applications/web_app_provider.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 166 | #include "chrome/common/buildflags.h" |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 167 | #include "chrome/common/channel_info.h" |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 168 | #include "chrome/common/chrome_constants.h" |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 169 | #include "chrome/common/chrome_features.h" |
[email protected] | a7944aa | 2012-10-15 10:12:14 | [diff] [blame] | 170 | #include "chrome/common/chrome_paths.h" |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 171 | #include "chrome/common/chrome_paths_internal.h" |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 172 | #include "chrome/common/chrome_switches.h" |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 173 | #include "chrome/common/env_vars.h" |
John Abd-El-Malek | 9fb6049 | 2018-08-02 04:28:50 | [diff] [blame] | 174 | #include "chrome/common/google_url_loader_throttle.h" |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 175 | #include "chrome/common/logging_chrome.h" |
[email protected] | 9d45049 | 2013-06-13 23:08:37 | [diff] [blame] | 176 | #include "chrome/common/pepper_permission_util.h" |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 177 | #include "chrome/common/pref_names.h" |
evliu | bc2aa047 | 2019-08-09 20:19:19 | [diff] [blame] | 178 | #include "chrome/common/pref_names_util.h" |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 179 | #include "chrome/common/prerender_url_loader_throttle.h" |
Egor Pasko | d52474c3 | 2018-06-19 12:03:22 | [diff] [blame] | 180 | #include "chrome/common/prerender_util.h" |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 181 | #include "chrome/common/render_messages.h" |
nigeltao | 7cd8d558 | 2016-12-12 06:05:28 | [diff] [blame] | 182 | #include "chrome/common/renderer_configuration.mojom.h" |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 183 | #include "chrome/common/secure_origin_whitelist.h" |
wittman | 832321f5 | 2016-10-10 18:18:38 | [diff] [blame] | 184 | #include "chrome/common/stack_sampling_configuration.h" |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 185 | #include "chrome/common/url_constants.h" |
Peter Boström | 8e9b163 | 2019-08-22 23:12:47 | [diff] [blame] | 186 | #include "chrome/common/webui_url_constants.h" |
ben | c70c0e3 | 2016-09-22 03:50:37 | [diff] [blame] | 187 | #include "chrome/grit/browser_resources.h" |
[email protected] | af39f00 | 2014-08-22 10:18:18 | [diff] [blame] | 188 | #include "chrome/grit/generated_resources.h" |
[email protected] | 264c0acac | 2013-10-01 13:33:30 | [diff] [blame] | 189 | #include "chrome/installer/util/google_update_settings.h" |
leon.han | 04b276e | 2016-06-01 01:34:16 | [diff] [blame] | 190 | #include "components/autofill/content/browser/content_autofill_driver_factory.h" |
brettw | f195891 | 2015-10-07 19:43:12 | [diff] [blame] | 191 | #include "components/autofill/core/common/autofill_switches.h" |
msramek | 1c8e19d | 2017-01-04 20:04:53 | [diff] [blame] | 192 | #include "components/browsing_data/core/browsing_data_utils.h" |
[email protected] | 649b5727 | 2014-05-09 14:54:44 | [diff] [blame] | 193 | #include "components/cdm/browser/cdm_message_filter_android.h" |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 194 | #include "components/certificate_matching/certificate_principal_pattern.h" |
[email protected] | 09cff7878 | 2014-04-20 22:04:48 | [diff] [blame] | 195 | #include "components/cloud_devices/common/cloud_devices_switches.h" |
Tao Bai | 02ab4dd4 | 2019-03-06 00:30:37 | [diff] [blame] | 196 | #include "components/content_capture/browser/content_capture_receiver_manager.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 197 | #include "components/content_settings/core/browser/content_settings_utils.h" |
droger | b171697 | 2015-06-30 09:04:09 | [diff] [blame] | 198 | #include "components/content_settings/core/browser/cookie_settings.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 199 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 200 | #include "components/content_settings/core/common/content_settings.h" |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 201 | #include "components/content_settings/core/common/content_settings_types.h" |
tbansal | 08a0e3e | 2017-06-30 21:30:08 | [diff] [blame] | 202 | #include "components/content_settings/core/common/content_settings_utils.h" |
Daniel Vogelheim | 976f1c2 | 2017-11-22 16:26:03 | [diff] [blame] | 203 | #include "components/content_settings/core/common/pref_names.h" |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 204 | #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] | 205 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h" |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 206 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h" |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 207 | #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h" |
rajendrant | 4319407 | 2019-04-15 22:13:43 | [diff] [blame] | 208 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h" |
Clark DuVall | 9233584 | 2018-10-10 16:49:09 | [diff] [blame] | 209 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h" |
Wojciech Dzierżanowski | 4538080 | 2019-04-29 14:50:32 | [diff] [blame] | 210 | #include "components/data_reduction_proxy/core/common/data_reduction_proxy_throttle_manager.h" |
wychen | e5568734 | 2015-11-13 20:17:03 | [diff] [blame] | 211 | #include "components/dom_distiller/core/dom_distiller_switches.h" |
[email protected] | 474a5a3 | 2014-07-28 18:23:24 | [diff] [blame] | 212 | #include "components/dom_distiller/core/url_constants.h" |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 213 | #include "components/error_page/common/error_page_switches.h" |
khushalsagar | c5447db2 | 2017-08-22 17:53:01 | [diff] [blame] | 214 | #include "components/feature_engagement/public/feature_constants.h" |
| 215 | #include "components/feature_engagement/public/feature_list.h" |
John Abd-El-Malek | 9cf3d7f0 | 2018-07-27 02:40:39 | [diff] [blame] | 216 | #include "components/google/core/common/google_util.h" |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 217 | #include "components/language/core/browser/pref_names.h" |
wittman | e16da278 | 2016-09-21 16:43:04 | [diff] [blame] | 218 | #include "components/metrics/call_stack_profile_collector.h" |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 219 | #include "components/metrics/client_info.h" |
Scott Violet | 9ae8289 | 2018-03-01 18:38:12 | [diff] [blame] | 220 | #include "components/nacl/common/buildflags.h" |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 221 | #include "components/nacl/common/nacl_constants.h" |
droger | c690e880 | 2015-09-21 14:29:16 | [diff] [blame] | 222 | #include "components/net_log/chrome_net_log.h" |
Tao Bai | b827b20 | 2019-09-19 21:22:12 | [diff] [blame] | 223 | #include "components/page_load_metrics/browser/metrics_navigation_throttle.h" |
| 224 | #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" |
| 225 | #include "components/page_load_metrics/browser/page_load_metrics_util.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" |
David Roger | e8e83f3c | 2019-09-12 10:56:23 | [diff] [blame] | 255 | #include "components/signin/public/identity_manager/identity_manager.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] | 5bc61cad | 2014-07-08 05:05:08 | [diff] [blame] | 383 | #include "chrome/browser/chromeos/file_manager/app_id.h" |
[email protected] | 43420a1 | 2014-04-21 03:20:48 | [diff] [blame] | 384 | #include "chrome/browser/chromeos/file_system_provider/fileapi/backend_delegate.h" |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 385 | #include "chrome/browser/chromeos/fileapi/external_file_url_loader_factory.h" |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 386 | #include "chrome/browser/chromeos/fileapi/file_system_backend.h" |
[email protected] | bee0df31 | 2014-04-28 06:59:58 | [diff] [blame] | 387 | #include "chrome/browser/chromeos/fileapi/mtp_file_system_backend_delegate.h" |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 388 | #include "chrome/browser/chromeos/login/signin/merge_session_navigation_throttle.h" |
| 389 | #include "chrome/browser/chromeos/login/signin/merge_session_throttling_utils.h" |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 390 | #include "chrome/browser/chromeos/login/signin_partition_manager.h" |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 391 | #include "chrome/browser/chromeos/login/startup_utils.h" |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 392 | #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 393 | #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 394 | #include "chrome/browser/chromeos/profiles/profile_helper.h" |
[email protected] | c94ac69 | 2013-07-27 00:50:10 | [diff] [blame] | 395 | #include "chrome/browser/chromeos/system/input_device_settings.h" |
Katie D | b2d0709 | 2018-12-04 18:59:36 | [diff] [blame] | 396 | #include "chrome/browser/speech/tts_chromeos.h" |
Steven Bennetts | 81d07be | 2018-01-08 20:45:27 | [diff] [blame] | 397 | #include "chrome/browser/ui/ash/chrome_browser_main_extra_parts_ash.h" |
djacobo | 21e56e0 | 2016-07-02 01:14:31 | [diff] [blame] | 398 | #include "chrome/browser/ui/browser_dialogs.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 399 | #include "chromeos/constants/chromeos_constants.h" |
Kyle Horimoto | 1d6a679f | 2019-04-16 23:24:21 | [diff] [blame] | 400 | #include "chromeos/constants/chromeos_features.h" |
Steven Bennetts | 38e9bde2 | 2019-01-03 17:31:10 | [diff] [blame] | 401 | #include "chromeos/constants/chromeos_switches.h" |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 402 | #include "components/crash/content/app/breakpad_linux.h" |
John Abd-El-Malek | 35bfaa5 | 2019-08-20 16:22:07 | [diff] [blame] | 403 | #include "components/user_manager/user.h" |
[email protected] | 4d39078 | 2014-08-15 09:22:58 | [diff] [blame] | 404 | #include "components/user_manager/user_manager.h" |
Ken Rockot | 543f5e3 | 2018-02-04 02:13:50 | [diff] [blame] | 405 | #include "services/service_manager/public/mojom/interface_provider_spec.mojom.h" |
[email protected] | 81ce2c4 | 2012-03-24 01:43:26 | [diff] [blame] | 406 | #elif defined(OS_LINUX) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 407 | #include "chrome/browser/chrome_browser_main_linux.h" |
[email protected] | 81054f81 | 2012-08-30 00:47:09 | [diff] [blame] | 408 | #elif defined(OS_ANDROID) |
Bo Liu | 4ade6b1b2 | 2017-11-28 02:26:35 | [diff] [blame] | 409 | #include "base/android/application_status_listener.h" |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 410 | #include "chrome/android/features/dev_ui/buildflags.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" |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 433 | #if BUILDFLAG(DFMIFY_DEV_UI) |
| 434 | #include "chrome/browser/android/dev_ui/dev_ui_url_handler.h" |
| 435 | #endif // BUILDFLAG(DFMIFY_DEV_UI) |
[email protected] | b48c918 | 2011-10-26 18:03:30 | [diff] [blame] | 436 | #elif defined(OS_POSIX) |
| 437 | #include "chrome/browser/chrome_browser_main_posix.h" |
| 438 | #endif |
| 439 | |
tmartino | fb34188 | 2017-02-10 19:36:53 | [diff] [blame] | 440 | #if !defined(OS_ANDROID) |
Jay Harris | 1ddcffa | 2019-07-09 03:07:40 | [diff] [blame] | 441 | #include "chrome/browser/badging/badge_manager.h" |
Scott Violet | ef765b9 | 2017-06-09 21:26:36 | [diff] [blame] | 442 | #include "chrome/browser/devtools/chrome_devtools_manager_delegate.h" |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 443 | #include "chrome/browser/devtools/devtools_window.h" |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 444 | #include "chrome/browser/media/unified_autoplay_config.h" |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 445 | #include "chrome/browser/payments/payment_request_factory.h" |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 446 | #include "chrome/browser/search/instant_service.h" |
| 447 | #include "chrome/browser/search/instant_service_factory.h" |
Reilly Grant | 2814fb7 | 2019-03-19 17:04:46 | [diff] [blame] | 448 | #include "chrome/browser/serial/chrome_serial_delegate.h" |
Collin Baker | 8a21755 | 2019-05-29 19:47:51 | [diff] [blame] | 449 | #include "chrome/browser/ui/browser.h" |
| 450 | #include "chrome/browser/ui/browser_finder.h" |
| 451 | #include "chrome/browser/ui/browser_list.h" |
| 452 | #include "chrome/browser/ui/browser_window.h" |
jdoerrie | 4f9376f | 2018-12-12 18:26:20 | [diff] [blame] | 453 | #include "chrome/browser/ui/passwords/google_password_manager_navigation_throttle.h" |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 454 | #include "chrome/browser/ui/search/new_tab_page_navigation_throttle.h" |
Nina Satragno | 8c832df | 2019-07-29 15:59:39 | [diff] [blame] | 455 | #include "chrome/browser/webauthn/authenticator_request_scheduler.h" |
| 456 | #include "chrome/browser/webauthn/chrome_authenticator_request_delegate.h" |
Jay Civelli | 4d53be9b | 2017-08-31 22:01:43 | [diff] [blame] | 457 | #include "chrome/common/importer/profile_import.mojom.h" |
Austin Orion | e250d01 | 2019-05-29 02:56:27 | [diff] [blame] | 458 | #include "chrome/grit/chrome_unscaled_resources.h" |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 459 | #endif // !defined(OS_ANDROID) |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 460 | |
Nicolas Ouellet-Payeur | bdcab009 | 2018-10-22 14:50:33 | [diff] [blame] | 461 | #if defined(OS_WIN) || defined(OS_MACOSX) || \ |
| 462 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
Nicolas Ouellet-Payeur | 4b840a9 | 2018-09-18 14:46:52 | [diff] [blame] | 463 | #include "chrome/browser/browser_switcher/browser_switcher_navigation_throttle.h" |
| 464 | #endif |
| 465 | |
[email protected] | a220b593 | 2013-09-21 03:47:44 | [diff] [blame] | 466 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 467 | #if !defined(OS_ANDROID) |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 468 | #include "base/debug/leak_annotations.h" |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 469 | #include "components/crash/content/app/breakpad_linux.h" |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 470 | #endif // !defined(OS_ANDROID) |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 471 | #include "components/crash/content/browser/crash_handler_host_linux.h" |
[email protected] | 1fd5302c | 2011-05-28 04:06:43 | [diff] [blame] | 472 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 473 | |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 474 | // TODO(crbug.com/939205): Once the upcoming App Service is available, use a |
| 475 | // single navigation throttle to display the intent picker on all platforms. |
| 476 | #if !defined(OS_ANDROID) |
| 477 | #if defined(OS_CHROMEOS) |
| 478 | #include "chrome/browser/chromeos/apps/intent_helper/chromeos_apps_navigation_throttle.h" |
| 479 | #else |
| 480 | #include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h" |
| 481 | #endif |
| 482 | #endif |
| 483 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 484 | #if defined(TOOLKIT_VIEWS) |
| 485 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views.h" |
| 486 | #endif |
| 487 | |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 488 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 489 | #if defined(USE_X11) |
| 490 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux_x11.h" |
| 491 | #else |
estade | d3aa0e8 | 2016-02-17 22:55:21 | [diff] [blame] | 492 | #include "chrome/browser/ui/views/chrome_browser_main_extra_parts_views_linux.h" |
Maksim Sisov | 1f2f2e6 | 2019-05-08 07:56:22 | [diff] [blame] | 493 | #endif // USE_X11 |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 494 | #endif |
| 495 | |
Mohsen Izadi | f1958f2 | 2019-01-18 20:29:31 | [diff] [blame] | 496 | #if defined(USE_OZONE) |
| 497 | #include "ui/ozone/public/ozone_platform.h" |
| 498 | #endif |
| 499 | |
[email protected] | e8b6ca0 | 2013-07-10 18:00:51 | [diff] [blame] | 500 | #if defined(USE_X11) |
| 501 | #include "chrome/browser/chrome_browser_main_extra_parts_x11.h" |
| 502 | #endif |
| 503 | |
brettw | ab78fef | 2016-10-12 02:56:05 | [diff] [blame] | 504 | #if BUILDFLAG(ENABLE_CAPTIVE_PORTAL_DETECTION) |
[email protected] | 7a2a6d80 | 2014-06-06 13:39:19 | [diff] [blame] | 505 | #include "chrome/browser/captive_portal/captive_portal_tab_helper.h" |
| 506 | #endif |
| 507 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 508 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 509 | #include "components/nacl/browser/nacl_browser.h" |
| 510 | #include "components/nacl/browser/nacl_host_message_filter.h" |
| 511 | #include "components/nacl/browser/nacl_process_host.h" |
| 512 | #include "components/nacl/common/nacl_process_type.h" |
| 513 | #include "components/nacl/common/nacl_switches.h" |
| 514 | #endif |
| 515 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 516 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 517 | #include "chrome/browser/accessibility/animation_policy_prefs.h" |
Dominick Ng | 6ff5105 | 2018-07-06 05:30:20 | [diff] [blame] | 518 | #include "chrome/browser/apps/platform_apps/platform_app_navigation_redirector.h" |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 519 | #include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h" |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 520 | #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" |
Pavol Marko | 41c37b1 | 2019-08-07 10:56:32 | [diff] [blame] | 521 | #include "chrome/browser/extensions/extension_util.h" |
Clark DuVall | 2cf99249e | 2018-09-19 19:11:51 | [diff] [blame] | 522 | #include "chrome/browser/extensions/user_script_listener.h" |
| 523 | #include "chrome/browser/media/cast_transport_host_filter.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 524 | #include "chrome/browser/speech/extension_api/tts_engine_extension_api.h" |
Eric Willigers | 007ef30 | 2019-08-29 09:58:46 | [diff] [blame] | 525 | #include "chrome/browser/ui/web_applications/app_browser_controller.h" |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 526 | #include "components/guest_view/browser/guest_view_base.h" |
| 527 | #include "components/guest_view/browser/guest_view_manager.h" |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 528 | #include "extensions/browser/api/web_request/web_request_api.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 529 | #include "extensions/browser/extension_host.h" |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 530 | #include "extensions/browser/extension_navigation_throttle.h" |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 531 | #include "extensions/browser/extension_protocols.h" |
reillyg | a3acbc1 | 2014-11-11 23:17:12 | [diff] [blame] | 532 | #include "extensions/browser/extension_registry.h" |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 533 | #include "extensions/browser/extension_system.h" |
hanxi | 0d0a1e9 | 2014-08-26 18:39:48 | [diff] [blame] | 534 | #include "extensions/browser/guest_view/web_view/web_view_guest.h" |
| 535 | #include "extensions/browser/guest_view/web_view/web_view_permission_helper.h" |
| 536 | #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 537 | #include "extensions/browser/process_manager.h" |
Dan Beam | 836c02a | 2019-06-15 01:58:27 | [diff] [blame] | 538 | #include "extensions/common/constants.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 539 | #include "extensions/common/extension.h" |
| 540 | #include "extensions/common/extension_set.h" |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 541 | #include "extensions/common/manifest_handlers/background_info.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 542 | #include "extensions/common/manifest_handlers/shared_module_info.h" |
Clark DuVall | bf7722f | 2018-08-03 18:03:33 | [diff] [blame] | 543 | #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 544 | #include "extensions/common/permissions/permissions_data.h" |
| 545 | #include "extensions/common/permissions/socket_permission.h" |
| 546 | #include "extensions/common/switches.h" |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 547 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
merkin | db10455e | 2017-02-28 13:16:25 | [diff] [blame] | 548 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 549 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 550 | #include "chrome/browser/plugins/chrome_content_browser_client_plugins_part.h" |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 551 | #include "chrome/browser/plugins/flash_download_interception.h" |
John Abd-El-Malek | ecc6f5f | 2018-03-02 18:47:39 | [diff] [blame] | 552 | #include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h" |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 553 | #endif |
| 554 | |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 555 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 556 | #include "chrome/browser/supervised_user/supervised_user_google_auth_navigation_throttle.h" |
| 557 | #endif |
| 558 | |
thakis | 678822e | 2017-04-20 17:20:34 | [diff] [blame] | 559 | #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 560 | #include "chrome/browser/media/cast_remoting_connector.h" |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 561 | #endif |
| 562 | |
weili | fabbf757 | 2017-05-22 19:05:16 | [diff] [blame] | 563 | #if BUILDFLAG(ENABLE_PRINTING) |
Lei Zhang | a2fa14c | 2018-05-15 00:05:21 | [diff] [blame] | 564 | #include "chrome/browser/printing/printing_message_filter.h" |
weili | fabbf757 | 2017-05-22 19:05:16 | [diff] [blame] | 565 | #endif |
Lei Zhang | a2fa14c | 2018-05-15 00:05:21 | [diff] [blame] | 566 | |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 567 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c86d76e4 | 2016-03-14 23:38:49 | [diff] [blame] | 568 | #include "chrome/browser/media/output_protection_impl.h" |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 569 | #include "chrome/browser/media/platform_verification_impl.h" |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 570 | #if defined(OS_WIN) && BUILDFLAG(ENABLE_WIDEVINE) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 571 | #include "chrome/browser/media/widevine_hardware_caps_win.h" |
| 572 | #include "third_party/widevine/cdm/widevine_cdm_common.h" |
| 573 | #endif |
| 574 | #endif |
| 575 | |
xhwang | db24d60 | 2017-05-20 06:32:24 | [diff] [blame] | 576 | #if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID) |
xhwang | 116acb9 | 2017-04-03 18:27:20 | [diff] [blame] | 577 | #include "chrome/browser/media/android/cdm/media_drm_storage_factory.h" |
| 578 | #endif |
xhwang | c86d76e4 | 2016-03-14 23:38:49 | [diff] [blame] | 579 | |
xhwang | db24d60 | 2017-05-20 06:32:24 | [diff] [blame] | 580 | #if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 581 | #include "media/mojo/mojom/constants.mojom.h" // nogncheck |
xhwang | b1d65fd | 2016-10-19 20:55:52 | [diff] [blame] | 582 | #include "media/mojo/services/media_service_factory.h" // nogncheck |
alokp | 6ecb238 | 2016-01-27 00:40:00 | [diff] [blame] | 583 | #endif |
| 584 | |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 585 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 586 | #include "chrome/browser/supervised_user/supervised_user_navigation_throttle.h" |
| 587 | #endif |
| 588 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 589 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
Daniel Rubery | a1611e3 | 2019-04-24 21:38:35 | [diff] [blame] | 590 | #include "chrome/browser/safe_browsing/chrome_password_protection_service.h" |
| 591 | #endif |
| 592 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 593 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 594 | #include "chrome/browser/offline_pages/offline_page_tab_helper.h" |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 595 | #include "chrome/browser/offline_pages/offline_page_url_loader_request_interceptor.h" |
| 596 | #endif |
| 597 | |
Will Cassella | 40837ba | 2019-07-01 21:32:00 | [diff] [blame] | 598 | #if BUILDFLAG(ENABLE_VR) && !defined(OS_ANDROID) |
Bill Orr | eb42922 | 2018-08-08 21:14:43 | [diff] [blame] | 599 | #include "device/vr/public/mojom/isolated_xr_service.mojom.h" |
| 600 | #endif |
| 601 | |
Ken Rockot | c185b2a | 2019-08-01 22:19:48 | [diff] [blame] | 602 | #if BUILDFLAG(ENABLE_SPELLCHECK) |
| 603 | #include "chrome/browser/spellchecker/spell_check_host_chrome_impl.h" |
| 604 | #include "components/spellcheck/common/spellcheck.mojom.h" |
| 605 | #if BUILDFLAG(HAS_SPELLCHECK_PANEL) |
| 606 | #include "chrome/browser/spellchecker/spell_check_panel_host_impl.h" |
| 607 | #endif |
| 608 | #endif |
| 609 | |
Michael Thiessen | 909ba03 | 2019-03-26 23:47:43 | [diff] [blame] | 610 | #if defined(BROWSER_MEDIA_CONTROLS_MENU) |
| 611 | #include "third_party/blink/public/mojom/media_controls/touchless/media_controls.mojom.h" |
| 612 | #endif |
| 613 | |
Michael Thiessen | 07c444c | 2019-04-26 03:53:11 | [diff] [blame] | 614 | #if defined(ENABLE_SPATIAL_NAVIGATION_HOST) |
| 615 | #include "third_party/blink/public/mojom/page/spatial_navigation.mojom.h" |
| 616 | #endif |
| 617 | |
[email protected] | c7abd42 | 2012-09-25 00:20:08 | [diff] [blame] | 618 | using base::FileDescriptor; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 619 | using content::BrowserThread; |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 620 | using content::BrowserURLHandler; |
msramek | a3c7cfd | 2017-02-03 13:34:13 | [diff] [blame] | 621 | using content::BrowsingDataFilterBuilder; |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 622 | using content::ChildProcessSecurityPolicy; |
[email protected] | 9f9749a | 2012-03-02 19:37:00 | [diff] [blame] | 623 | using content::QuotaPermissionContext; |
[email protected] | 2626d14 | 2014-04-22 17:24:02 | [diff] [blame] | 624 | using content::RenderFrameHost; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 625 | using content::RenderViewHost; |
[email protected] | 7491ad0 | 2014-07-05 19:10:07 | [diff] [blame] | 626 | using content::ResourceType; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 627 | using content::SiteInstance; |
[email protected] | 83ff91c | 2012-01-05 20:54:13 | [diff] [blame] | 628 | using content::WebContents; |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 629 | using content::WebPreferences; |
[email protected] | 593d2a7 | 2013-07-26 08:48:38 | [diff] [blame] | 630 | using message_center::NotifierId; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 631 | |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 632 | #if defined(OS_POSIX) |
brettw | 3c98c7d3 | 2017-07-25 01:44:20 | [diff] [blame] | 633 | using content::PosixFileDescriptorInfo; |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 634 | #endif |
| 635 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 636 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 637 | using extensions::APIPermission; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 638 | using extensions::ChromeContentBrowserClientExtensionsPart; |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 639 | using extensions::Extension; |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 640 | using extensions::Manifest; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 641 | #endif |
| 642 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 643 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 644 | using plugins::ChromeContentBrowserClientPluginsPart; |
| 645 | #endif |
| 646 | |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 647 | namespace { |
| 648 | |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 649 | const storage::QuotaSettings* g_default_quota_settings; |
| 650 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 651 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 652 | // TODO(teravest): Add renderer-side API-specific checking for these APIs so |
| 653 | // that blanket permission isn't granted to all dev channel APIs for these. |
| 654 | // http://crbug.com/386743 |
| 655 | const char* const kPredefinedAllowedDevChannelOrigins[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 656 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/383937 |
| 657 | "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/383937 |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 658 | }; |
| 659 | |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 660 | const char* const kPredefinedAllowedFileHandleOrigins[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 661 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", // see crbug.com/234789 |
| 662 | "4EB74897CB187C7633357C2FE832E0AD6A44883A" // see crbug.com/234789 |
[email protected] | 10c3922 | 2013-11-13 20:09:25 | [diff] [blame] | 663 | }; |
| 664 | |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 665 | const char* const kPredefinedAllowedSocketOrigins[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 666 | "okddffdblfhhnmhodogpojmfkjmhinfp", // Secure Shell App (dev) |
| 667 | "pnhechapfaindjhompbnflcldabbghjo", // Secure Shell App (stable) |
| 668 | "algkcnfjnajfhgimadimbjhmpaeohhln", // Secure Shell Extension (dev) |
| 669 | "iodihamcpbpeioajjeobimgagajmlibd", // Secure Shell Extension (stable) |
| 670 | "bglhmjfplikpjnfoegeomebmfnkjomhe", // see crbug.com/122126 |
| 671 | "gbchcmhmhahfdphkhkmpfmihenigjmpp", // Chrome Remote Desktop |
| 672 | "kgngmbheleoaphbjbaiobfdepmghbfah", // Pre-release Chrome Remote Desktop |
| 673 | "odkaodonbgfohohmklejpjiejmcipmib", // Dogfood Chrome Remote Desktop |
| 674 | "ojoimpklfciegopdfgeenehpalipignm", // Chromoting canary |
| 675 | "cbkkbcmdlboombapidmoeolnmdacpkch", // see crbug.com/129089 |
| 676 | "hhnbmknkdabfoieppbbljkhkfjcmcbjh", // see crbug.com/134099 |
| 677 | "mablfbjkhmhkmefkjjacnbaikjkipphg", // see crbug.com/134099 |
| 678 | "pdeelgamlgannhelgoegilelnnojegoh", // see crbug.com/134099 |
| 679 | "cabapfdbkniadpollkckdnedaanlciaj", // see crbug.com/134099 |
| 680 | "mapljbgnjledlpdmlchihnmeclmefbba", // see crbug.com/134099 |
| 681 | "ghbfeebgmiidnnmeobbbaiamklmpbpii", // see crbug.com/134099 |
| 682 | "jdfhpkjeckflbbleddjlpimecpbjdeep", // see crbug.com/142514 |
| 683 | "iabmpiboiopbgfabjmgeedhcmjenhbla", // see crbug.com/165080 |
| 684 | "B7CF8A292249681AF81771650BA4CEEAF19A4560", // see crbug.com/165080 |
| 685 | "7525AF4F66763A70A883C4700529F647B470E4D2", // see crbug.com/238084 |
| 686 | "0B549507088E1564D672F7942EB87CA4DAD73972", // see crbug.com/238084 |
| 687 | "864288364E239573E777D3E0E36864E590E95C74" // see crbug.com/238084 |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 688 | }; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 689 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 690 | |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 691 | #if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 692 | // Enables pre-launch Code Integrity Guard (CIG) for Chrome renderers, when |
| 693 | // running on Windows 10 1511 and above. See |
| 694 | // https://blogs.windows.com/blog/tag/code-integrity-guard/. |
| 695 | const base::Feature kRendererCodeIntegrity{"RendererCodeIntegrity", |
Will Harris | 6dd1f84 | 2019-08-05 21:01:33 | [diff] [blame] | 696 | base::FEATURE_ENABLED_BY_DEFAULT}; |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 697 | #endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) && |
| 698 | // !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 699 | |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 700 | enum AppLoadedInTabSource { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 701 | // 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] | 702 | APP_LOADED_IN_TAB_SOURCE_APP = 0, |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 703 | |
| 704 | // 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] | 705 | APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE, |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 706 | |
| 707 | // An extension or app tried to load a resource of a different platform app in |
| 708 | // a tab. |
| 709 | APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION, |
| 710 | |
| 711 | // A non-app and non-extension page tried to load a platform app in a tab. |
| 712 | APP_LOADED_IN_TAB_SOURCE_OTHER, |
| 713 | |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 714 | APP_LOADED_IN_TAB_SOURCE_MAX |
| 715 | }; |
| 716 | |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 717 | // Cached version of the locale so we can return the locale on the I/O |
| 718 | // thread. |
| 719 | std::string& GetIOThreadApplicationLocale() { |
| 720 | static base::NoDestructor<std::string> s; |
| 721 | return *s; |
| 722 | } |
| 723 | |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 724 | // Returns a copy of the given url with its host set to given host and path set |
| 725 | // to given path. Other parts of the url will be the same. |
| 726 | GURL ReplaceURLHostAndPath(const GURL& url, |
| 727 | const std::string& host, |
| 728 | const std::string& path) { |
[email protected] | b4533450 | 2014-04-30 19:44:05 | [diff] [blame] | 729 | url::Replacements<char> replacements; |
| 730 | replacements.SetHost(host.c_str(), url::Component(0, host.length())); |
| 731 | replacements.SetPath(path.c_str(), url::Component(0, path.length())); |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 732 | return url.ReplaceComponents(replacements); |
| 733 | } |
| 734 | |
mad | fbd1085 | 2017-01-20 03:15:33 | [diff] [blame] | 735 | // Handles the rewriting of the new tab page URL based on group policy. |
| 736 | bool HandleNewTabPageLocationOverride( |
| 737 | GURL* url, |
| 738 | content::BrowserContext* browser_context) { |
| 739 | if (!url->SchemeIs(content::kChromeUIScheme) || |
| 740 | url->host() != chrome::kChromeUINewTabHost) |
| 741 | return false; |
| 742 | |
| 743 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 744 | std::string ntp_location = |
| 745 | profile->GetPrefs()->GetString(prefs::kNewTabPageLocationOverride); |
| 746 | if (ntp_location.empty()) |
| 747 | return false; |
| 748 | |
| 749 | *url = GURL(ntp_location); |
| 750 | return true; |
| 751 | } |
| 752 | |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 753 | #if !defined(OS_ANDROID) |
| 754 | // Check if the current url is whitelisted based on a list of whitelisted urls. |
| 755 | bool IsURLWhitelisted(const GURL& current_url, |
Jan Wilken Dörrie | 53e009b | 2019-09-09 14:17:41 | [diff] [blame] | 756 | base::span<const base::Value> whitelisted_urls) { |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 757 | // Only check on HTTP and HTTPS pages. |
| 758 | if (!current_url.SchemeIsHTTPOrHTTPS()) |
| 759 | return false; |
| 760 | |
| 761 | for (auto const& value : whitelisted_urls) { |
| 762 | ContentSettingsPattern pattern = |
| 763 | ContentSettingsPattern::FromString(value.GetString()); |
| 764 | if (pattern == ContentSettingsPattern::Wildcard() || !pattern.IsValid()) |
| 765 | continue; |
| 766 | if (pattern.Matches(current_url)) |
| 767 | return true; |
| 768 | } |
| 769 | |
| 770 | return false; |
| 771 | } |
| 772 | |
| 773 | // Check if autoplay is allowed by policy configuration. |
| 774 | bool IsAutoplayAllowedByPolicy(content::WebContents* contents, |
| 775 | PrefService* prefs) { |
| 776 | DCHECK(prefs); |
| 777 | |
| 778 | // Check if we have globally allowed autoplay by policy. |
| 779 | if (prefs->GetBoolean(prefs::kAutoplayAllowed) && |
| 780 | prefs->IsManagedPreference(prefs::kAutoplayAllowed)) { |
| 781 | return true; |
| 782 | } |
| 783 | |
| 784 | if (!contents) |
| 785 | return false; |
| 786 | |
| 787 | // Check if the current URL matches a URL pattern on the whitelist. |
| 788 | const base::ListValue* autoplay_whitelist = |
| 789 | prefs->GetList(prefs::kAutoplayWhitelist); |
| 790 | return autoplay_whitelist && |
| 791 | prefs->IsManagedPreference(prefs::kAutoplayWhitelist) && |
| 792 | IsURLWhitelisted(contents->GetURL(), autoplay_whitelist->GetList()); |
| 793 | } |
| 794 | #endif |
| 795 | |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 796 | #if defined(OS_ANDROID) |
| 797 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
| 798 | return crashpad::CrashHandlerHost::Get()->GetDeathSignalSocket(); |
| 799 | } |
| 800 | #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 801 | breakpad::CrashHandlerHostLinux* CreateCrashHandlerHost( |
| 802 | const std::string& process_type) { |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 803 | base::FilePath dumps_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 804 | base::PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 805 | { |
| 806 | ANNOTATE_SCOPED_MEMORY_LEAK; |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 807 | bool upload = !getenv(env_vars::kHeadless); |
[email protected] | 0b818f7 | 2013-10-22 00:11:03 | [diff] [blame] | 808 | breakpad::CrashHandlerHostLinux* crash_handler = |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 809 | new breakpad::CrashHandlerHostLinux(process_type, dumps_path, upload); |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 810 | crash_handler->StartUploaderThread(); |
| 811 | return crash_handler; |
| 812 | } |
| 813 | } |
| 814 | |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 815 | int GetCrashSignalFD(const base::CommandLine& command_line) { |
[email protected] | 9de4da5 | 2014-05-24 12:26:50 | [diff] [blame] | 816 | // Extensions have the same process type as renderers. |
[email protected] | cd0f7af | 2014-01-16 23:50:39 | [diff] [blame] | 817 | if (command_line.HasSwitch(extensions::switches::kExtensionProcess)) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 818 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 819 | if (!crash_handler) |
| 820 | crash_handler = CreateCrashHandlerHost("extension"); |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 821 | return crash_handler->GetDeathSignalSocket(); |
| 822 | } |
| 823 | |
| 824 | std::string process_type = |
| 825 | command_line.GetSwitchValueASCII(switches::kProcessType); |
| 826 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 827 | if (process_type == switches::kRendererProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 828 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 829 | if (!crash_handler) |
| 830 | crash_handler = CreateCrashHandlerHost(process_type); |
| 831 | return crash_handler->GetDeathSignalSocket(); |
| 832 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 833 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 834 | if (process_type == switches::kPpapiPluginProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 835 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 836 | if (!crash_handler) |
| 837 | crash_handler = CreateCrashHandlerHost(process_type); |
| 838 | return crash_handler->GetDeathSignalSocket(); |
| 839 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 840 | |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 841 | if (process_type == switches::kGpuProcess) { |
Lei Zhang | 74f3dd3f | 2019-04-10 00:16:31 | [diff] [blame] | 842 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
[email protected] | 779dd28 | 2013-10-19 15:57:02 | [diff] [blame] | 843 | if (!crash_handler) |
| 844 | crash_handler = CreateCrashHandlerHost(process_type); |
| 845 | return crash_handler->GetDeathSignalSocket(); |
| 846 | } |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 847 | |
James Cook | 9207cc1 | 2017-10-19 17:08:39 | [diff] [blame] | 848 | if (process_type == switches::kUtilityProcess) { |
| 849 | static breakpad::CrashHandlerHostLinux* crash_handler = nullptr; |
| 850 | if (!crash_handler) |
| 851 | crash_handler = CreateCrashHandlerHost(process_type); |
| 852 | return crash_handler->GetDeathSignalSocket(); |
| 853 | } |
| 854 | |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 855 | return -1; |
| 856 | } |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 857 | #endif // defined(OS_ANDROID) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 858 | |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 859 | void SetApplicationLocaleOnIOThread(const std::string& locale) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 860 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 861 | GetIOThreadApplicationLocale() = locale; |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 862 | } |
| 863 | |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 864 | // An implementation of the SSLCertReporter interface used by |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 865 | // SSLErrorHandler. Uses CertificateReportingService to send reports. The |
| 866 | // service handles queueing and re-sending of failed reports. Each certificate |
| 867 | // error creates a new instance of this class. |
| 868 | class CertificateReportingServiceCertReporter : public SSLCertReporter { |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 869 | public: |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 870 | explicit CertificateReportingServiceCertReporter( |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 871 | content::WebContents* web_contents) |
| 872 | : service_(CertificateReportingServiceFactory::GetForBrowserContext( |
| 873 | web_contents->GetBrowserContext())) {} |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 874 | ~CertificateReportingServiceCertReporter() override {} |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 875 | |
| 876 | // SSLCertReporter implementation |
estark | 4282f117 | 2015-05-13 22:01:55 | [diff] [blame] | 877 | void ReportInvalidCertificateChain( |
| 878 | const std::string& serialized_report) override { |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 879 | service_->Send(serialized_report); |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | private: |
meacer | f43117a | 2016-12-27 21:02:31 | [diff] [blame] | 883 | CertificateReportingService* service_; |
| 884 | |
| 885 | DISALLOW_COPY_AND_ASSIGN(CertificateReportingServiceCertReporter); |
estark | 3ba1113 | 2015-04-10 01:38:33 | [diff] [blame] | 886 | }; |
| 887 | |
bshe | 4f53ce4 | 2015-11-30 16:56:31 | [diff] [blame] | 888 | #if defined(OS_ANDROID) |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 889 | float GetDeviceScaleAdjustment() { |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 890 | static const float kMinFSM = 1.05f; |
| 891 | static const int kWidthForMinFSM = 320; |
| 892 | static const float kMaxFSM = 1.3f; |
| 893 | static const int kWidthForMaxFSM = 800; |
| 894 | |
boliu | 21c5afa | 2017-01-11 19:34:23 | [diff] [blame] | 895 | int minWidth = chrome::android::ChromeContextUtil::GetSmallestDIPWidth(); |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 896 | |
| 897 | if (minWidth <= kWidthForMinFSM) |
| 898 | return kMinFSM; |
| 899 | if (minWidth >= kWidthForMaxFSM) |
| 900 | return kMaxFSM; |
| 901 | |
| 902 | // The font scale multiplier varies linearly between kMinFSM and kMaxFSM. |
| 903 | float ratio = static_cast<float>(minWidth - kWidthForMinFSM) / |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 904 | (kWidthForMaxFSM - kWidthForMinFSM); |
[email protected] | b255a8e0e8 | 2013-10-22 04:03:59 | [diff] [blame] | 905 | return ratio * (kMaxFSM - kMinFSM) + kMinFSM; |
| 906 | } |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 907 | |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 908 | #endif // defined(OS_ANDROID) |
| 909 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 910 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 911 | |
| 912 | AppLoadedInTabSource ClassifyAppLoadedInTabSource( |
| 913 | const GURL& opener_url, |
| 914 | const extensions::Extension* target_platform_app) { |
| 915 | if (opener_url.SchemeIs(extensions::kExtensionScheme)) { |
| 916 | if (opener_url.host_piece() == target_platform_app->id()) { |
| 917 | // This platform app was trying to window.open() one of its own URLs. |
| 918 | if (opener_url == |
| 919 | extensions::BackgroundInfo::GetBackgroundURL(target_platform_app)) { |
| 920 | // Source was the background page. |
| 921 | return APP_LOADED_IN_TAB_SOURCE_BACKGROUND_PAGE; |
| 922 | } else { |
| 923 | // Source was a different page inside the app. |
| 924 | return APP_LOADED_IN_TAB_SOURCE_APP; |
| 925 | } |
| 926 | } |
| 927 | // The forbidden app URL was being opened by a different app or extension. |
| 928 | return APP_LOADED_IN_TAB_SOURCE_OTHER_EXTENSION; |
| 929 | } |
| 930 | // The forbidden app URL was being opened by a non-extension page (e.g. http). |
| 931 | return APP_LOADED_IN_TAB_SOURCE_OTHER; |
| 932 | } |
[email protected] | 9c765638 | 2014-08-08 21:02:30 | [diff] [blame] | 933 | |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 934 | // Returns true if there is is an extension matching |url| in |
| 935 | // |opener_render_process_id| with APIPermission::kBackground. |
| 936 | // |
| 937 | // Note that GetExtensionOrAppByURL requires a full URL in order to match with a |
| 938 | // hosted app, even though normal extensions just use the host. |
| 939 | bool URLHasExtensionBackgroundPermission( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 940 | extensions::ProcessMap* process_map, |
| 941 | extensions::ExtensionRegistry* registry, |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 942 | const GURL& url, |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 943 | int opener_render_process_id) { |
| 944 | // Note: includes web URLs that are part of an extension's web extent. |
| 945 | const Extension* extension = |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 946 | registry->enabled_extensions().GetExtensionOrAppByURL(url); |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 947 | return extension && |
| 948 | extension->permissions_data()->HasAPIPermission( |
| 949 | APIPermission::kBackground) && |
| 950 | process_map->Contains(extension->id(), opener_render_process_id); |
| 951 | } |
Kevin Marshall | 32f99d7e | 2017-07-11 23:17:46 | [diff] [blame] | 952 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 953 | #endif |
| 954 | |
John Abd-El-Malek | d237798 | 2018-01-08 22:23:12 | [diff] [blame] | 955 | chrome::mojom::PrerenderCanceler* GetPrerenderCanceller( |
| 956 | const base::Callback<content::WebContents*()>& wc_getter) { |
| 957 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 958 | auto* web_contents = wc_getter.Run(); |
| 959 | if (!web_contents) |
| 960 | return nullptr; |
| 961 | |
| 962 | return prerender::PrerenderContents::FromWebContents(web_contents); |
| 963 | } |
| 964 | |
John Abd-El-Malek | 92bf360 | 2019-07-31 02:25:48 | [diff] [blame] | 965 | void LaunchURL(const GURL& url, |
| 966 | const content::WebContents::Getter& web_contents_getter, |
| 967 | ui::PageTransition page_transition, |
| 968 | bool has_user_gesture) { |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 969 | // If there is no longer a WebContents, the request may have raced with tab |
| 970 | // closing. Don't fire the external request. (It may have been a prerender.) |
| 971 | content::WebContents* web_contents = web_contents_getter.Run(); |
| 972 | if (!web_contents) |
| 973 | return; |
| 974 | |
| 975 | // Do not launch external requests attached to unswapped prerenders. |
| 976 | prerender::PrerenderContents* prerender_contents = |
| 977 | prerender::PrerenderContents::FromWebContents(web_contents); |
| 978 | if (prerender_contents) { |
| 979 | prerender_contents->Destroy(prerender::FINAL_STATUS_UNSUPPORTED_SCHEME); |
| 980 | prerender::ReportPrerenderExternalURL(); |
| 981 | return; |
| 982 | } |
| 983 | |
Robbie McElrath | 1294d24 | 2019-05-31 20:46:22 | [diff] [blame] | 984 | // Do not launch external requests for schemes that have a handler registered. |
| 985 | ProtocolHandlerRegistry* protocol_handler_registry = |
| 986 | ProtocolHandlerRegistryFactory::GetForBrowserContext( |
| 987 | web_contents->GetBrowserContext()); |
| 988 | if (protocol_handler_registry && |
| 989 | protocol_handler_registry->IsHandledProtocol(url.scheme())) |
| 990 | return; |
| 991 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 992 | bool is_whitelisted = false; |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 993 | PolicyBlacklistService* service = |
Oleg Davydov | 5cfe7ab | 2019-02-01 12:27:19 | [diff] [blame] | 994 | PolicyBlacklistFactory::GetForBrowserContext( |
| 995 | web_contents->GetBrowserContext()); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 996 | if (service) { |
| 997 | const policy::URLBlacklist::URLBlacklistState url_state = |
| 998 | service->GetURLBlacklistState(url); |
| 999 | is_whitelisted = |
| 1000 | url_state == policy::URLBlacklist::URLBlacklistState::URL_IN_WHITELIST; |
| 1001 | } |
| 1002 | |
| 1003 | // If the URL is in whitelist, we launch it without asking the user and |
| 1004 | // without any additional security checks. Since the URL is whitelisted, |
| 1005 | // we assume it can be executed. |
| 1006 | if (is_whitelisted) { |
| 1007 | ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents); |
| 1008 | } else { |
| 1009 | ExternalProtocolHandler::LaunchUrl( |
| 1010 | url, web_contents->GetRenderViewHost()->GetProcess()->GetID(), |
| 1011 | web_contents->GetRenderViewHost()->GetRoutingID(), page_transition, |
| 1012 | has_user_gesture); |
| 1013 | } |
| 1014 | } |
| 1015 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1016 | std::string GetProduct() { |
| 1017 | return version_info::GetProductNameAndVersionForUserAgent(); |
| 1018 | } |
| 1019 | |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 1020 | void MaybeAppendSecureOriginsAllowlistSwitch(base::CommandLine* cmdline) { |
| 1021 | // |allowlist| combines pref/policy + cmdline switch in the browser process. |
| 1022 | // For renderer and utility (e.g. NetworkService) processes the switch is the |
| 1023 | // only available source, so below the combined (pref/policy + cmdline) |
| 1024 | // allowlist of secure origins is injected into |cmdline| for these other |
| 1025 | // processes. |
| 1026 | std::vector<std::string> allowlist = |
| 1027 | network::SecureOriginAllowlist::GetInstance().GetCurrentAllowlist(); |
| 1028 | if (!allowlist.empty()) { |
| 1029 | cmdline->AppendSwitchASCII( |
| 1030 | network::switches::kUnsafelyTreatInsecureOriginAsSecure, |
| 1031 | base::JoinString(allowlist, ",")); |
| 1032 | } |
| 1033 | } |
| 1034 | |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 1035 | #if defined(OS_WIN) && !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 1036 | // Returns the full path to |module_name|. Both dev builds (where |module_name| |
| 1037 | // is in the current executable's directory) and proper installs (where |
| 1038 | // |module_name| is in a versioned sub-directory of the current executable's |
| 1039 | // directory) are supported. The identified file is not guaranteed to exist. |
| 1040 | base::FilePath GetModulePath(base::StringPiece16 module_name) { |
| 1041 | base::FilePath exe_dir; |
| 1042 | const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir); |
| 1043 | DCHECK(has_path); |
| 1044 | |
| 1045 | // Look for the module in a versioned sub-directory of the current |
| 1046 | // executable's directory and return the path if it can be read. This is the |
| 1047 | // expected location of modules for proper installs. |
| 1048 | const base::FilePath module_path = |
| 1049 | exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name); |
| 1050 | if (base::PathExists(module_path)) |
| 1051 | return module_path; |
| 1052 | |
| 1053 | // Otherwise, return the path to the module in the current executable's |
| 1054 | // directory. This is the expected location of modules for dev builds. |
| 1055 | return exe_dir.Append(module_name); |
| 1056 | } |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 1057 | #endif // defined(OS_WIN) && !defined(COMPONENT_BUILD) && |
| 1058 | // !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 1059 | |
[email protected] | 9dbfff1 | 2011-07-01 19:37:07 | [diff] [blame] | 1060 | } // namespace |
[email protected] | c5dbef0 | 2011-05-13 05:06:09 | [diff] [blame] | 1061 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1062 | std::string GetUserAgent() { |
| 1063 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 1064 | if (command_line->HasSwitch(switches::kUserAgent)) { |
| 1065 | std::string ua = command_line->GetSwitchValueASCII(switches::kUserAgent); |
| 1066 | if (net::HttpUtil::IsValidHeaderValue(ua)) |
| 1067 | return ua; |
| 1068 | LOG(WARNING) << "Ignored invalid value for flag --" << switches::kUserAgent; |
| 1069 | } |
| 1070 | |
John Delaney | ac24e57 | 2019-04-30 19:47:02 | [diff] [blame] | 1071 | if (base::FeatureList::IsEnabled(blink::features::kFreezeUserAgent)) { |
| 1072 | return content::GetFrozenUserAgent( |
| 1073 | command_line->HasSwitch(switches::kUseMobileUserAgent)) |
| 1074 | .as_string(); |
| 1075 | } |
| 1076 | |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 1077 | std::string product = GetProduct(); |
| 1078 | #if defined(OS_ANDROID) |
| 1079 | if (command_line->HasSwitch(switches::kUseMobileUserAgent)) |
| 1080 | product += " Mobile"; |
| 1081 | #endif |
| 1082 | return content::BuildUserAgentFromProduct(product); |
| 1083 | } |
| 1084 | |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1085 | blink::UserAgentMetadata GetUserAgentMetadata() { |
| 1086 | blink::UserAgentMetadata metadata; |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1087 | metadata.brand = version_info::GetProductName(); |
Mike West | e555be86 | 2019-02-20 16:17:30 | [diff] [blame] | 1088 | metadata.full_version = version_info::GetVersionNumber(); |
| 1089 | metadata.major_version = version_info::GetMajorVersionNumber(); |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 1090 | metadata.platform = version_info::GetOSType(); |
| 1091 | |
| 1092 | // TODO(mkwst): Poke at BuildUserAgentFromProduct to split out these pieces. |
| 1093 | metadata.architecture = ""; |
| 1094 | metadata.model = ""; |
| 1095 | |
| 1096 | return metadata; |
| 1097 | } |
| 1098 | |
Ran Ji | a96d43d4 | 2018-05-02 17:14:53 | [diff] [blame] | 1099 | ChromeContentBrowserClient::ChromeContentBrowserClient( |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 1100 | StartupData* startup_data) |
Wojciech Dzierżanowski | 4538080 | 2019-04-29 14:50:32 | [diff] [blame] | 1101 | : data_reduction_proxy_throttle_manager_( |
| 1102 | nullptr, |
| 1103 | base::OnTaskRunnerDeleter(nullptr)), |
Jeremy Roman | 495db68 | 2019-07-12 16:03:24 | [diff] [blame] | 1104 | startup_data_(startup_data) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1105 | #if BUILDFLAG(ENABLE_PLUGINS) |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 1106 | for (size_t i = 0; i < base::size(kPredefinedAllowedDevChannelOrigins); ++i) |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 1107 | allowed_dev_channel_origins_.insert(kPredefinedAllowedDevChannelOrigins[i]); |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 1108 | for (size_t i = 0; i < base::size(kPredefinedAllowedFileHandleOrigins); ++i) |
[email protected] | 10c3922 | 2013-11-13 20:09:25 | [diff] [blame] | 1109 | allowed_file_handle_origins_.insert(kPredefinedAllowedFileHandleOrigins[i]); |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 1110 | for (size_t i = 0; i < base::size(kPredefinedAllowedSocketOrigins); ++i) |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 1111 | allowed_socket_origins_.insert(kPredefinedAllowedSocketOrigins[i]); |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 1112 | |
| 1113 | extra_parts_.push_back(new ChromeContentBrowserClientPluginsPart); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 1114 | #endif |
[email protected] | 1deace2 | 2013-05-22 06:14:46 | [diff] [blame] | 1115 | |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 1116 | #if defined(OS_CHROMEOS) |
| 1117 | extra_parts_.push_back(new ChromeContentBrowserClientChromeOsPart); |
| 1118 | #endif // defined(OS_CHROMEOS) |
| 1119 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1120 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1121 | extra_parts_.push_back(new ChromeContentBrowserClientExtensionsPart); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1122 | #endif |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 1123 | |
Sigurdur Asgeirsson | 7069667 | 2019-02-08 16:14:51 | [diff] [blame] | 1124 | extra_parts_.push_back(new ChromeContentBrowserClientPerformanceManagerPart); |
[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)); |
Darin Fisher | 8c84328c | 2019-07-23 02:50:00 | [diff] [blame] | 1389 | |
Darin Fisher | 09aa722 | 2019-08-29 09:27:36 | [diff] [blame] | 1390 | WebRtcLoggingController::AttachToRenderProcessHost( |
Darin Fisher | 8c84328c | 2019-07-23 02:50:00 | [diff] [blame] | 1391 | host, g_browser_process->webrtc_log_uploader()); |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1392 | |
grunell | 086a411 | 2017-03-02 09:23:04 | [diff] [blame] | 1393 | // The audio manager outlives the host, so it's safe to hand a raw pointer to |
| 1394 | // it to the AudioDebugRecordingsHandler, which is owned by the host. |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1395 | AudioDebugRecordingsHandler* audio_debug_recordings_handler = |
Marina Ciocea | 741a4fb1 | 2018-01-27 09:55:12 | [diff] [blame] | 1396 | new AudioDebugRecordingsHandler(profile); |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1397 | host->SetUserData( |
| 1398 | AudioDebugRecordingsHandler::kAudioDebugRecordingsHandlerKey, |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 1399 | std::make_unique<base::UserDataAdapter<AudioDebugRecordingsHandler>>( |
terelius | fa159cc | 2016-04-13 15:13:02 | [diff] [blame] | 1400 | audio_debug_recordings_handler)); |
| 1401 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 1402 | #if BUILDFLAG(ENABLE_NACL) |
Helen Li | 8897b02 | 2018-05-03 13:29:03 | [diff] [blame] | 1403 | host->AddFilter(new nacl::NaClHostMessageFilter(id, profile->IsOffTheRecord(), |
| 1404 | profile->GetPath())); |
[email protected] | 01e5975 | 2013-06-18 00:17:35 | [diff] [blame] | 1405 | #endif |
jeremyim | 364ac118 | 2015-03-03 18:49:43 | [diff] [blame] | 1406 | |
Xiaohan Wang | 9b34281b | 2017-09-08 23:48:33 | [diff] [blame] | 1407 | #if defined(OS_ANDROID) |
| 1408 | // Data cannot be persisted if the profile is off the record. |
| 1409 | host->AddFilter( |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 1410 | new cdm::CdmMessageFilterAndroid(!profile->IsOffTheRecord(), false)); |
Yuzu Saijo | 2d12ef9 | 2018-08-21 04:52:07 | [diff] [blame] | 1411 | |
| 1412 | // Register CrashMemoryMetricsCollector to report oom related metrics. |
| 1413 | host->SetUserData( |
| 1414 | CrashMemoryMetricsCollector::kCrashMemoryMetricsCollectorKey, |
| 1415 | std::make_unique<CrashMemoryMetricsCollector>(host)); |
Xiaohan Wang | 9b34281b | 2017-09-08 23:48:33 | [diff] [blame] | 1416 | #endif |
| 1417 | |
Jun Cai | db3f93cc | 2018-07-09 21:54:55 | [diff] [blame] | 1418 | Profile* original_profile = profile->GetOriginalProfile(); |
John Abd-El-Malek | 1f7fc91 | 2018-07-26 02:48:06 | [diff] [blame] | 1419 | RendererUpdaterFactory::GetForProfile(original_profile) |
| 1420 | ->InitializeRenderer(host); |
[email protected] | 39a5b53 | 2011-10-22 01:47:07 | [diff] [blame] | 1421 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1422 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1423 | extra_parts_[i]->RenderProcessWillLaunch(host); |
[email protected] | 05fcf98 | 2011-04-19 00:44:14 | [diff] [blame] | 1424 | } |
| 1425 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1426 | GURL ChromeContentBrowserClient::GetEffectiveURL( |
Alex Moshchuk | bb99a33 | 2017-11-22 04:49:57 | [diff] [blame] | 1427 | content::BrowserContext* browser_context, |
Alex Moshchuk | a31c788 | 2018-01-17 00:57:30 | [diff] [blame] | 1428 | const GURL& url) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1429 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1430 | if (!profile) |
| 1431 | return url; |
| 1432 | |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1433 | #if !defined(OS_ANDROID) |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 1434 | // If the input |url| should be assigned to the Instant renderer, make its |
| 1435 | // effective URL distinct from other URLs on the search provider's domain. |
Alex Moshchuk | ca17137 | 2017-11-28 16:11:31 | [diff] [blame] | 1436 | // This needs to happen even if |url| corresponds to an isolated origin; see |
| 1437 | // https://crbug.com/755595. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1438 | if (search::ShouldAssignURLToInstantRenderer(url, profile)) |
| 1439 | return search::GetEffectiveURLForInstant(url, profile); |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1440 | #endif |
[email protected] | b3cb3a3 | 2013-07-31 01:32:29 | [diff] [blame] | 1441 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1442 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Alex Moshchuk | a31c788 | 2018-01-17 00:57:30 | [diff] [blame] | 1443 | return ChromeContentBrowserClientExtensionsPart::GetEffectiveURL(profile, |
| 1444 | url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1445 | #else |
| 1446 | return url; |
| 1447 | #endif |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 1448 | } |
| 1449 | |
Alexander Yashkin | 6aedc6e | 2018-08-15 08:58:45 | [diff] [blame] | 1450 | bool ChromeContentBrowserClient:: |
| 1451 | ShouldCompareEffectiveURLsForSiteInstanceSelection( |
| 1452 | content::BrowserContext* browser_context, |
| 1453 | content::SiteInstance* candidate_site_instance, |
| 1454 | bool is_main_frame, |
| 1455 | const GURL& candidate_url, |
| 1456 | const GURL& destination_url) { |
| 1457 | DCHECK(browser_context); |
| 1458 | DCHECK(candidate_site_instance); |
| 1459 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1460 | return ChromeContentBrowserClientExtensionsPart:: |
| 1461 | ShouldCompareEffectiveURLsForSiteInstanceSelection( |
| 1462 | browser_context, candidate_site_instance, is_main_frame, |
| 1463 | candidate_url, destination_url); |
| 1464 | #else |
| 1465 | return true; |
| 1466 | #endif |
| 1467 | } |
| 1468 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 1469 | bool ChromeContentBrowserClient::ShouldUseMobileFlingCurve() { |
Ahmed Fakhry | e6a2c64 | 2018-06-20 02:58:41 | [diff] [blame] | 1470 | #if defined(OS_ANDROID) |
| 1471 | return true; |
| 1472 | #elif defined(OS_CHROMEOS) |
Xiyuan Xia | fc9f3813 | 2019-08-02 00:51:42 | [diff] [blame] | 1473 | return ash::TabletMode::Get() && ash::TabletMode::Get()->InTabletMode(); |
Ahmed Fakhry | e6a2c64 | 2018-06-20 02:58:41 | [diff] [blame] | 1474 | #else |
| 1475 | return false; |
| 1476 | #endif // defined(OS_ANDROID) |
| 1477 | } |
| 1478 | |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1479 | bool ChromeContentBrowserClient::ShouldUseProcessPerSite( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1480 | content::BrowserContext* browser_context, |
| 1481 | const GURL& effective_url) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1482 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1483 | if (!profile) |
| 1484 | return false; |
| 1485 | |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1486 | // NTP should use process-per-site. This is a performance optimization to |
| 1487 | // reduce process count associated with NTP tabs. |
| 1488 | if (effective_url == GURL(chrome::kChromeUINewTabURL)) |
| 1489 | return true; |
Peter Boström | 8e9b163 | 2019-08-22 23:12:47 | [diff] [blame] | 1490 | |
| 1491 | // The web footer experiment should share its renderer to not effectively |
| 1492 | // instantiate one per window. See https://crbug.com/993502. |
| 1493 | if (effective_url == GURL(chrome::kChromeUIWebFooterExperimentURL)) |
| 1494 | return true; |
| 1495 | |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1496 | #if !defined(OS_ANDROID) |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1497 | if (search::ShouldUseProcessPerSiteForInstantURL(effective_url, profile)) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1498 | return true; |
Marc Treib | 7d467b79 | 2017-12-04 13:31:03 | [diff] [blame] | 1499 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1500 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1501 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1502 | if (ChromeContentBrowserClientExtensionsPart::ShouldUseProcessPerSite( |
| 1503 | profile, effective_url)) |
| 1504 | return true; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1505 | #endif |
Lukasz Anforowicz | fec6b9a | 2019-07-16 21:02:30 | [diff] [blame] | 1506 | |
| 1507 | // Non-extension, non-NTP URLs should generally use process-per-site-instance |
| 1508 | // (rather than process-per-site). |
| 1509 | return false; |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 1510 | } |
| 1511 | |
Lukasz Anforowicz | 32d2712 | 2018-04-09 21:48:33 | [diff] [blame] | 1512 | bool ChromeContentBrowserClient::ShouldUseSpareRenderProcessHost( |
| 1513 | content::BrowserContext* browser_context, |
| 1514 | const GURL& site_url) { |
| 1515 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 1516 | if (!profile) |
| 1517 | return false; |
| 1518 | |
| 1519 | #if !defined(OS_ANDROID) |
| 1520 | // Instant renderers should not use a spare process, because they require |
| 1521 | // passing switches::kInstantProcess to the renderer process when it |
| 1522 | // launches. A spare process is launched earlier, before it is known which |
| 1523 | // navigation will use it, so it lacks this flag. |
| 1524 | if (search::ShouldAssignURLToInstantRenderer(site_url, profile)) |
| 1525 | return false; |
| 1526 | #endif |
| 1527 | |
| 1528 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1529 | return ChromeContentBrowserClientExtensionsPart:: |
| 1530 | ShouldUseSpareRenderProcessHost(profile, site_url); |
| 1531 | #else |
| 1532 | return true; |
| 1533 | #endif |
| 1534 | } |
| 1535 | |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1536 | bool ChromeContentBrowserClient::DoesSiteRequireDedicatedProcess( |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1537 | content::BrowserContext* browser_context, |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1538 | const GURL& effective_site_url) { |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1539 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1540 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1541 | if (ChromeContentBrowserClientExtensionsPart::DoesSiteRequireDedicatedProcess( |
Clark DuVall | 4e1f0a7 | 2019-08-07 22:41:42 | [diff] [blame] | 1542 | browser_context, effective_site_url)) { |
nick | cc0d914 | 2015-10-14 16:27:10 | [diff] [blame] | 1543 | return true; |
| 1544 | } |
| 1545 | #endif |
| 1546 | return false; |
| 1547 | } |
| 1548 | |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1549 | // TODO(creis, nick): https://crbug.com/160576 describes a weakness in our |
| 1550 | // origin-lock enforcement, where we don't have a way to efficiently know |
| 1551 | // effective URLs on the IO thread, and wind up killing processes that e.g. |
| 1552 | // request cookies for their actual URL. This whole function (and its |
| 1553 | // ExtensionsPart) should be removed once we add that ability to the IO thread. |
| 1554 | bool ChromeContentBrowserClient::ShouldLockToOrigin( |
| 1555 | content::BrowserContext* browser_context, |
| 1556 | const GURL& effective_site_url) { |
| 1557 | // Origin lock to the search scheme would kill processes upon legitimate |
| 1558 | // requests for cookies from the search engine's domain. |
| 1559 | if (effective_site_url.SchemeIs(chrome::kChromeSearchScheme)) |
| 1560 | return false; |
| 1561 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1562 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
nick | 7d0984c | 2015-08-29 00:13:46 | [diff] [blame] | 1563 | if (!ChromeContentBrowserClientExtensionsPart::ShouldLockToOrigin( |
| 1564 | browser_context, effective_site_url)) { |
| 1565 | return false; |
| 1566 | } |
| 1567 | #endif |
| 1568 | return true; |
creis | e5d6d173 | 2015-08-25 19:47:06 | [diff] [blame] | 1569 | } |
| 1570 | |
Lukasz Anforowicz | 05f356e | 2018-03-13 20:26:11 | [diff] [blame] | 1571 | const char* |
Lukasz Anforowicz | ce869f0b | 2018-08-06 18:33:37 | [diff] [blame] | 1572 | ChromeContentBrowserClient::GetInitiatorSchemeBypassingDocumentBlocking() { |
Charles Reis | 358baf47 | 2017-12-06 05:30:43 | [diff] [blame] | 1573 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Lukasz Anforowicz | 05f356e | 2018-03-13 20:26:11 | [diff] [blame] | 1574 | // Don't block responses for extension processes or for content scripts. |
| 1575 | // TODO(creis): When every extension fetch (including content scripts) has |
| 1576 | // been made to go through an extension-specific URLLoaderFactory, this |
| 1577 | // mechanism ought to work by enumerating the host permissions from the |
| 1578 | // extension manifest, and forwarding them on to the network service while |
| 1579 | // brokering the URLLoaderFactory. |
| 1580 | return extensions::kExtensionScheme; |
| 1581 | #else |
| 1582 | return nullptr; |
Charles Reis | 358baf47 | 2017-12-06 05:30:43 | [diff] [blame] | 1583 | #endif |
Charles Reis | 358baf47 | 2017-12-06 05:30:43 | [diff] [blame] | 1584 | } |
| 1585 | |
Maks Orlovich | 0e23e31 | 2019-07-16 13:13:56 | [diff] [blame] | 1586 | bool ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel( |
| 1587 | base::StringPiece scheme) { |
| 1588 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1589 | return scheme == extensions::kExtensionScheme; |
| 1590 | #else |
| 1591 | return false; |
| 1592 | #endif |
| 1593 | } |
| 1594 | |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1595 | network::mojom::URLLoaderFactoryPtrInfo |
| 1596 | ChromeContentBrowserClient::CreateURLLoaderFactoryForNetworkRequests( |
| 1597 | content::RenderProcessHost* process, |
| 1598 | network::mojom::NetworkContext* network_context, |
Julie Jeongeun Kim | 47499a0c | 2019-08-28 07:23:18 | [diff] [blame] | 1599 | mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>* |
| 1600 | header_client, |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1601 | const url::Origin& request_initiator) { |
| 1602 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1603 | return ChromeContentBrowserClientExtensionsPart:: |
Clark DuVall | a5e25b75 | 2018-11-27 22:08:16 | [diff] [blame] | 1604 | CreateURLLoaderFactoryForNetworkRequests( |
| 1605 | process, network_context, header_client, request_initiator); |
Lukasz Anforowicz | 2f81016 | 2018-10-03 21:38:07 | [diff] [blame] | 1606 | #else |
| 1607 | return network::mojom::URLLoaderFactoryPtrInfo(); |
| 1608 | #endif |
| 1609 | } |
| 1610 | |
[email protected] | 73b718f | 2014-01-27 02:59:46 | [diff] [blame] | 1611 | // These are treated as WebUI schemes but do not get WebUI bindings. Also, |
| 1612 | // view-source is allowed for these schemes. |
[email protected] | 8f89dd41 | 2013-04-17 02:35:41 | [diff] [blame] | 1613 | void ChromeContentBrowserClient::GetAdditionalWebUISchemes( |
| 1614 | std::vector<std::string>* additional_schemes) { |
| 1615 | additional_schemes->push_back(chrome::kChromeSearchScheme); |
[email protected] | 474a5a3 | 2014-07-28 18:23:24 | [diff] [blame] | 1616 | additional_schemes->push_back(dom_distiller::kDomDistillerScheme); |
Andrey Kosyakov | 031e9e3 | 2017-08-18 21:00:35 | [diff] [blame] | 1617 | additional_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 1618 | } |
| 1619 | |
alexmos | 94875b3b | 2017-03-16 22:19:01 | [diff] [blame] | 1620 | void ChromeContentBrowserClient::GetAdditionalViewSourceSchemes( |
| 1621 | std::vector<std::string>* additional_schemes) { |
| 1622 | GetAdditionalWebUISchemes(additional_schemes); |
| 1623 | |
| 1624 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1625 | additional_schemes->push_back(extensions::kExtensionScheme); |
| 1626 | #endif |
| 1627 | } |
| 1628 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 1629 | bool ChromeContentBrowserClient::LogWebUIUrl(const GURL& web_ui_url) { |
dbeam | baee5bd | 2015-09-26 03:07:01 | [diff] [blame] | 1630 | return webui::LogWebUIUrl(web_ui_url); |
| 1631 | } |
| 1632 | |
John Abd-El-Malek | 04bfa853 | 2018-07-12 05:28:22 | [diff] [blame] | 1633 | bool ChromeContentBrowserClient::IsWebUIAllowedToMakeNetworkRequests( |
| 1634 | const url::Origin& origin) { |
| 1635 | return ChromeWebUIControllerFactory::IsWebUIAllowedToMakeNetworkRequests( |
| 1636 | origin); |
| 1637 | } |
| 1638 | |
[email protected] | 46fb944 | 2011-12-09 17:57:47 | [diff] [blame] | 1639 | bool ChromeContentBrowserClient::IsHandledURL(const GURL& url) { |
| 1640 | return ProfileIOData::IsHandledURL(url); |
| 1641 | } |
| 1642 | |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1643 | bool ChromeContentBrowserClient::CanCommitURL( |
| 1644 | content::RenderProcessHost* process_host, |
| 1645 | const GURL& url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1646 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1647 | return ChromeContentBrowserClientExtensionsPart::CanCommitURL(process_host, |
| 1648 | url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1649 | #else |
| 1650 | return true; |
| 1651 | #endif |
[email protected] | c4365fa4 | 2013-05-14 01:08:24 | [diff] [blame] | 1652 | } |
| 1653 | |
[email protected] | 9a60d160 | 2013-09-11 04:09:12 | [diff] [blame] | 1654 | bool ChromeContentBrowserClient::ShouldAllowOpenURL( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1655 | content::SiteInstance* site_instance, |
| 1656 | const GURL& url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1657 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1658 | bool result; |
| 1659 | if (ChromeContentBrowserClientExtensionsPart::ShouldAllowOpenURL( |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1660 | site_instance, url, &result)) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1661 | return result; |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1662 | #endif |
[email protected] | 879816a9 | 2014-04-29 00:53:54 | [diff] [blame] | 1663 | |
| 1664 | // Do not allow chrome://chrome-signin navigate to other chrome:// URLs, since |
| 1665 | // the signin page may host untrusted web content. |
alexmos | 1c3da4f | 2016-11-03 06:06:11 | [diff] [blame] | 1666 | GURL from_url = site_instance->GetSiteURL(); |
[email protected] | 879816a9 | 2014-04-29 00:53:54 | [diff] [blame] | 1667 | if (from_url.GetOrigin().spec() == chrome::kChromeUIChromeSigninURL && |
| 1668 | url.SchemeIs(content::kChromeUIScheme) && |
brettw | b65cd5c | 2016-01-23 00:46:38 | [diff] [blame] | 1669 | url.host_piece() != chrome::kChromeUIChromeSigninHost) { |
[email protected] | 879816a9 | 2014-04-29 00:53:54 | [diff] [blame] | 1670 | VLOG(1) << "Blocked navigation to " << url.spec() << " from " |
| 1671 | << chrome::kChromeUIChromeSigninURL; |
| 1672 | return false; |
| 1673 | } |
| 1674 | |
[email protected] | 9a60d160 | 2013-09-11 04:09:12 | [diff] [blame] | 1675 | return true; |
| 1676 | } |
| 1677 | |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1678 | void ChromeContentBrowserClient::OverrideNavigationParams( |
| 1679 | SiteInstance* site_instance, |
| 1680 | ui::PageTransition* transition, |
| 1681 | bool* is_renderer_initiated, |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1682 | content::Referrer* referrer, |
| 1683 | base::Optional<url::Origin>* initiator_origin) { |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1684 | DCHECK(transition); |
| 1685 | DCHECK(is_renderer_initiated); |
| 1686 | DCHECK(referrer); |
Moe Ahmadi | 26e2f50 | 2019-07-16 02:34:47 | [diff] [blame] | 1687 | // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to |
| 1688 | // use for making security decisions 99.44% of the time, for detecting the NTP |
| 1689 | // it is reliable and the correct way. See http://crbug.com/624410. |
| 1690 | if (site_instance && search::IsNTPURL(site_instance->GetSiteURL()) && |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1691 | ui::PageTransitionCoreTypeIs(*transition, ui::PAGE_TRANSITION_LINK)) { |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1692 | // Clicks on tiles of the new tab page should be treated as if a user |
| 1693 | // clicked on a bookmark. This is consistent with native implementations |
| 1694 | // like Android's. This also helps ensure that security features (like |
| 1695 | // Sec-Fetch-Site and SameSite-cookies) will treat the navigation as |
| 1696 | // browser-initiated. |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1697 | *transition = ui::PAGE_TRANSITION_AUTO_BOOKMARK; |
| 1698 | *is_renderer_initiated = false; |
| 1699 | *referrer = content::Referrer(); |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1700 | *initiator_origin = base::nullopt; |
mastiz | a77db699 | 2016-06-30 09:48:42 | [diff] [blame] | 1701 | } |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1702 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1703 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1704 | ChromeContentBrowserClientExtensionsPart::OverrideNavigationParams( |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 1705 | site_instance, transition, is_renderer_initiated, referrer, |
| 1706 | initiator_origin); |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 1707 | #endif |
mastiz | a77db699 | 2016-06-30 09:48:42 | [diff] [blame] | 1708 | } |
| 1709 | |
Charles Reis | 29e9dd1 | 2017-09-28 00:59:15 | [diff] [blame] | 1710 | bool ChromeContentBrowserClient::ShouldStayInParentProcessForNTP( |
| 1711 | const GURL& url, |
| 1712 | SiteInstance* parent_site_instance) { |
Moe Ahmadi | 26e2f50 | 2019-07-16 02:34:47 | [diff] [blame] | 1713 | // While using SiteInstance::GetSiteURL() is unreliable and the wrong thing to |
| 1714 | // use for making security decisions 99.44% of the time, for detecting the NTP |
| 1715 | // it is reliable and the correct way. See http://crbug.com/624410. |
| 1716 | return url.SchemeIs(chrome::kChromeSearchScheme) && parent_site_instance && |
| 1717 | search::IsNTPURL(parent_site_instance->GetSiteURL()); |
Charles Reis | 29e9dd1 | 2017-09-28 00:59:15 | [diff] [blame] | 1718 | } |
| 1719 | |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1720 | bool ChromeContentBrowserClient::IsSuitableHost( |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1721 | content::RenderProcessHost* process_host, |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1722 | const GURL& site_url) { |
| 1723 | Profile* profile = |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1724 | Profile::FromBrowserContext(process_host->GetBrowserContext()); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1725 | // 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] | 1726 | // share any host. |
| 1727 | if (!profile) |
| 1728 | return true; |
| 1729 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1730 | #if !defined(OS_ANDROID) |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1731 | // Instant URLs should only be in the instant process and instant process |
| 1732 | // should only have Instant URLs. |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1733 | InstantService* instant_service = |
| 1734 | InstantServiceFactory::GetForProfile(profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1735 | if (instant_service) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1736 | bool is_instant_process = |
| 1737 | instant_service->IsInstantProcess(process_host->GetID()); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1738 | bool should_be_in_instant_process = |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1739 | search::ShouldAssignURLToInstantRenderer(site_url, profile); |
[email protected] | d43f99fe | 2013-04-03 00:20:14 | [diff] [blame] | 1740 | if (is_instant_process || should_be_in_instant_process) |
| 1741 | return is_instant_process && should_be_in_instant_process; |
| 1742 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1743 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1744 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1745 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1746 | return ChromeContentBrowserClientExtensionsPart::IsSuitableHost( |
| 1747 | profile, process_host, site_url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1748 | #else |
| 1749 | return true; |
| 1750 | #endif |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 1751 | } |
| 1752 | |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1753 | bool ChromeContentBrowserClient::MayReuseHost( |
| 1754 | content::RenderProcessHost* process_host) { |
| 1755 | // If there is currently a prerender in progress for the host provided, |
| 1756 | // it may not be shared. We require prerenders to be by themselves in a |
davidben | 879199c | 2015-03-06 00:55:04 | [diff] [blame] | 1757 | // separate process so that we can monitor their resource usage. |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1758 | prerender::PrerenderManager* prerender_manager = |
droger | c154315 | 2016-09-20 13:03:37 | [diff] [blame] | 1759 | prerender::PrerenderManagerFactory::GetForBrowserContext( |
| 1760 | process_host->GetBrowserContext()); |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1761 | if (prerender_manager && |
[email protected] | 2290af2 | 2014-05-26 15:44:49 | [diff] [blame] | 1762 | !prerender_manager->MayReuseProcessHost(process_host)) { |
[email protected] | 28c5d0b7 | 2014-05-13 08:19:59 | [diff] [blame] | 1763 | return false; |
| 1764 | } |
| 1765 | |
| 1766 | return true; |
| 1767 | } |
| 1768 | |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1769 | bool ChromeContentBrowserClient::ShouldTryToUseExistingProcessHost( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1770 | content::BrowserContext* browser_context, |
| 1771 | const GURL& url) { |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1772 | // It has to be a valid URL for us to check for an extension. |
| 1773 | if (!url.is_valid()) |
| 1774 | return false; |
| 1775 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1776 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1777 | Profile* profile = Profile::FromBrowserContext(browser_context); |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1778 | return ChromeContentBrowserClientExtensionsPart:: |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1779 | ShouldTryToUseExistingProcessHost(profile, url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1780 | #else |
| 1781 | return false; |
| 1782 | #endif |
[email protected] | 76411f41 | 2012-02-22 18:56:06 | [diff] [blame] | 1783 | } |
| 1784 | |
Alex Moshchuk | 9c9e388 | 2018-11-02 19:57:03 | [diff] [blame] | 1785 | bool ChromeContentBrowserClient::ShouldSubframesTryToReuseExistingProcess( |
| 1786 | content::RenderFrameHost* main_frame) { |
| 1787 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1788 | return ChromeContentBrowserClientExtensionsPart:: |
| 1789 | ShouldSubframesTryToReuseExistingProcess(main_frame); |
| 1790 | #else |
| 1791 | return true; |
| 1792 | #endif |
| 1793 | } |
| 1794 | |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1795 | void ChromeContentBrowserClient::SiteInstanceGotProcess( |
| 1796 | SiteInstance* site_instance) { |
| 1797 | CHECK(site_instance->HasProcess()); |
| 1798 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1799 | Profile* profile = |
| 1800 | Profile::FromBrowserContext(site_instance->GetBrowserContext()); |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1801 | if (!profile) |
| 1802 | return; |
| 1803 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1804 | #if !defined(OS_ANDROID) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1805 | // Remember the ID of the Instant process to signal the renderer process |
| 1806 | // on startup in |AppendExtraCommandLineSwitches| below. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 1807 | if (search::ShouldAssignURLToInstantRenderer(site_instance->GetSiteURL(), |
| 1808 | profile)) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1809 | InstantService* instant_service = |
| 1810 | InstantServiceFactory::GetForProfile(profile); |
| 1811 | if (instant_service) |
| 1812 | instant_service->AddInstantProcess(site_instance->GetProcess()->GetID()); |
| 1813 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 1814 | #endif |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 1815 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1816 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1817 | extra_parts_[i]->SiteInstanceGotProcess(site_instance); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | void ChromeContentBrowserClient::SiteInstanceDeleting( |
| 1821 | SiteInstance* site_instance) { |
| 1822 | if (!site_instance->HasProcess()) |
| 1823 | return; |
| 1824 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 1825 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 1826 | extra_parts_[i]->SiteInstanceDeleting(site_instance); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 1827 | } |
| 1828 | |
[email protected] | 453f543 | 2013-11-26 19:43:00 | [diff] [blame] | 1829 | bool ChromeContentBrowserClient::ShouldSwapBrowsingInstancesForNavigation( |
[email protected] | e9841fbd | 2013-02-22 23:12:14 | [diff] [blame] | 1830 | SiteInstance* site_instance, |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1831 | const GURL& current_url, |
| 1832 | const GURL& new_url) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 1833 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f7daaa3 | 2014-08-02 07:58:13 | [diff] [blame] | 1834 | return ChromeContentBrowserClientExtensionsPart:: |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 1835 | ShouldSwapBrowsingInstancesForNavigation(site_instance, current_url, |
| 1836 | new_url); |
[email protected] | d5a74be | 2014-08-08 01:01:27 | [diff] [blame] | 1837 | #else |
| 1838 | return false; |
| 1839 | #endif |
[email protected] | e3daf3c | 2011-10-05 21:17:08 | [diff] [blame] | 1840 | } |
| 1841 | |
Nasko Oskov | d83b571 | 2018-05-04 04:50:57 | [diff] [blame] | 1842 | bool ChromeContentBrowserClient::ShouldIsolateErrorPage(bool in_main_frame) { |
| 1843 | // TODO(nasko): Consider supporting error page isolation in subframes if |
| 1844 | // Site Isolation is enabled. |
Nasko Oskov | 55d21e15 | 2018-06-27 23:59:38 | [diff] [blame] | 1845 | return in_main_frame; |
Nasko Oskov | d83b571 | 2018-05-04 04:50:57 | [diff] [blame] | 1846 | } |
| 1847 | |
[email protected] | 3d83199 | 2013-07-04 01:13:29 | [diff] [blame] | 1848 | bool ChromeContentBrowserClient::ShouldAssignSiteForURL(const GURL& url) { |
| 1849 | return !url.SchemeIs(chrome::kChromeNativeScheme); |
| 1850 | } |
| 1851 | |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1852 | std::vector<url::Origin> |
| 1853 | ChromeContentBrowserClient::GetOriginsRequiringDedicatedProcess() { |
| 1854 | std::vector<url::Origin> isolated_origin_list; |
| 1855 | |
Alex Moshchuk | 89352a7 | 2017-10-25 20:25:59 | [diff] [blame] | 1856 | // Sign-in process isolation is not needed on Android, see |
| 1857 | // https://crbug.com/739418. |
| 1858 | #if !defined(OS_ANDROID) |
Alex Moshchuk | 81d2a29e | 2019-07-16 01:14:38 | [diff] [blame] | 1859 | isolated_origin_list.push_back( |
Alex Moshchuk | 36417aa | 2018-06-13 18:01:12 | [diff] [blame] | 1860 | url::Origin::Create(GaiaUrls::GetInstance()->gaia_url())); |
Alex Moshchuk | 89352a7 | 2017-10-25 20:25:59 | [diff] [blame] | 1861 | #endif |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1862 | |
Alex Moshchuk | 81d2a29e | 2019-07-16 01:14:38 | [diff] [blame] | 1863 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1864 | auto origins_from_extensions = ChromeContentBrowserClientExtensionsPart:: |
| 1865 | GetOriginsRequiringDedicatedProcess(); |
| 1866 | std::move(std::begin(origins_from_extensions), |
| 1867 | std::end(origins_from_extensions), |
| 1868 | std::back_inserter(isolated_origin_list)); |
| 1869 | #endif |
| 1870 | |
Alex Moshchuk | d252c19 | 2017-07-17 22:03:48 | [diff] [blame] | 1871 | return isolated_origin_list; |
| 1872 | } |
| 1873 | |
Lukasz Anforowicz | 5e201abd | 2018-03-24 00:41:06 | [diff] [blame] | 1874 | bool ChromeContentBrowserClient::ShouldEnableStrictSiteIsolation() { |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1875 | return base::FeatureList::IsEnabled(features::kSitePerProcess); |
| 1876 | } |
| 1877 | |
| 1878 | bool ChromeContentBrowserClient::ShouldDisableSiteIsolation() { |
Lukasz Anforowicz | 0711a0f | 2019-03-28 18:15:31 | [diff] [blame] | 1879 | // Using 1077 rather than 1024 because 1) it helps ensure that devices with |
| 1880 | // exactly 1GB of RAM won't get included because of inaccuracies or off-by-one |
| 1881 | // errors and 2) this is the bucket boundary in Memory.Stats.Win.TotalPhys2. |
| 1882 | // See also https://crbug.com/844118. |
| 1883 | constexpr int kDefaultMemoryThresholdMb = 1077; |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1884 | |
| 1885 | // TODO(acolwell): Rename feature since it now affects more than just the |
| 1886 | // site-per-process case. |
Lukasz Anforowicz | 46275d9 | 2018-04-12 14:57:38 | [diff] [blame] | 1887 | if (base::FeatureList::IsEnabled( |
| 1888 | features::kSitePerProcessOnlyForHighMemoryClients)) { |
Lukasz Anforowicz | 46275d9 | 2018-04-12 14:57:38 | [diff] [blame] | 1889 | int memory_threshold_mb = base::GetFieldTrialParamByFeatureAsInt( |
| 1890 | features::kSitePerProcessOnlyForHighMemoryClients, |
| 1891 | features::kSitePerProcessOnlyForHighMemoryClientsParamName, |
| 1892 | kDefaultMemoryThresholdMb); |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1893 | return base::SysInfo::AmountOfPhysicalMemoryMB() <= memory_threshold_mb; |
Lukasz Anforowicz | 46275d9 | 2018-04-12 14:57:38 | [diff] [blame] | 1894 | } |
| 1895 | |
Aaron Colwell | 25617f7 | 2018-11-27 20:56:34 | [diff] [blame] | 1896 | #if defined(OS_ANDROID) |
| 1897 | if (base::SysInfo::AmountOfPhysicalMemoryMB() <= kDefaultMemoryThresholdMb) { |
| 1898 | return true; |
| 1899 | } |
| 1900 | #endif |
| 1901 | |
| 1902 | return false; |
Lukasz Anforowicz | 5e201abd | 2018-03-24 00:41:06 | [diff] [blame] | 1903 | } |
| 1904 | |
Alex Moshchuk | 082b5f8 | 2019-03-14 01:34:16 | [diff] [blame] | 1905 | std::vector<std::string> |
| 1906 | ChromeContentBrowserClient::GetAdditionalSiteIsolationModes() { |
| 1907 | if (SiteIsolationPolicy::IsIsolationForPasswordSitesEnabled()) |
| 1908 | return {"Isolate Password Sites"}; |
| 1909 | else |
| 1910 | return {}; |
| 1911 | } |
| 1912 | |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 1913 | void ChromeContentBrowserClient::PersistIsolatedOrigin( |
| 1914 | content::BrowserContext* context, |
| 1915 | const url::Origin& origin) { |
| 1916 | DCHECK(!context->IsOffTheRecord()); |
| 1917 | Profile* profile = Profile::FromBrowserContext(context); |
| 1918 | ListPrefUpdate update(profile->GetPrefs(), |
| 1919 | prefs::kUserTriggeredIsolatedOrigins); |
| 1920 | base::ListValue* list = update.Get(); |
| 1921 | base::Value value(origin.Serialize()); |
Jan Wilken Dörrie | a8cb5630 | 2019-06-06 18:59:36 | [diff] [blame] | 1922 | if (!base::Contains(list->GetList(), value)) |
Jan Wilken Dörrie | 91e4ef0 | 2019-09-11 08:22:12 | [diff] [blame] | 1923 | list->Append(std::move(value)); |
Alex Moshchuk | e256d56 | 2019-04-26 21:43:57 | [diff] [blame] | 1924 | } |
| 1925 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 1926 | bool ChromeContentBrowserClient::IsFileAccessAllowed( |
| 1927 | const base::FilePath& path, |
| 1928 | const base::FilePath& absolute_path, |
| 1929 | const base::FilePath& profile_path) { |
| 1930 | return ChromeNetworkDelegate::IsAccessAllowed(path, absolute_path, |
| 1931 | profile_path); |
| 1932 | } |
| 1933 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1934 | namespace { |
| 1935 | |
| 1936 | bool IsAutoReloadEnabled() { |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 1937 | const base::CommandLine& browser_command_line = |
| 1938 | *base::CommandLine::ForCurrentProcess(); |
Elly Fong-Jones | 5f13ee1 | 2019-05-10 19:20:35 | [diff] [blame] | 1939 | if (browser_command_line.HasSwitch(switches::kEnableAutoReload)) |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1940 | return true; |
Elly Fong-Jones | 5f13ee1 | 2019-05-10 19:20:35 | [diff] [blame] | 1941 | if (browser_command_line.HasSwitch(switches::kDisableAutoReload)) |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1942 | return false; |
[email protected] | 9ef49b4 | 2014-08-07 16:44:24 | [diff] [blame] | 1943 | return true; |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 1944 | } |
| 1945 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1946 | void MaybeAppendBlinkSettingsSwitchForFieldTrial( |
| 1947 | const base::CommandLine& browser_command_line, |
| 1948 | base::CommandLine* command_line) { |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1949 | // List of field trials that modify the blink-settings command line flag. No |
| 1950 | // two field trials in the list should specify the same keys, otherwise one |
| 1951 | // field trial may overwrite another. See Source/core/frame/Settings.in in |
| 1952 | // Blink for the list of valid keys. |
| 1953 | static const char* const kBlinkSettingsFieldTrials[] = { |
jkarlin | 3bddb7d | 2016-09-21 18:44:16 | [diff] [blame] | 1954 | // Keys: disallowFetchForDocWrittenScriptsInMainFrame |
| 1955 | // disallowFetchForDocWrittenScriptsInMainFrameOnSlowConnections |
| 1956 | // disallowFetchForDocWrittenScriptsInMainFrameIfEffectively2G |
| 1957 | "DisallowFetchForDocWrittenScriptsInMainFrame", |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1958 | }; |
| 1959 | |
| 1960 | std::vector<std::string> blink_settings; |
| 1961 | for (const char* field_trial_name : kBlinkSettingsFieldTrials) { |
| 1962 | // Each blink-settings field trial should include a forcing_flag group, |
| 1963 | // to make sure that clients that specify the blink-settings flag on the |
| 1964 | // command line are excluded from the experiment groups. To make |
| 1965 | // sure we assign clients that specify this flag to the forcing_flag |
| 1966 | // group, we must call GetVariationParams for each field trial first |
| 1967 | // (for example, before checking HasSwitch() and returning), since |
| 1968 | // GetVariationParams has the side-effect of assigning the client to |
| 1969 | // a field trial group. |
| 1970 | std::map<std::string, std::string> params; |
| 1971 | if (variations::GetVariationParams(field_trial_name, ¶ms)) { |
| 1972 | for (const auto& param : params) { |
| 1973 | blink_settings.push_back(base::StringPrintf( |
| 1974 | "%s=%s", param.first.c_str(), param.second.c_str())); |
| 1975 | } |
| 1976 | } |
| 1977 | } |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 1978 | |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1979 | if (blink_settings.empty()) { |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1980 | return; |
| 1981 | } |
| 1982 | |
| 1983 | if (browser_command_line.HasSwitch(switches::kBlinkSettings) || |
| 1984 | command_line->HasSwitch(switches::kBlinkSettings)) { |
pmeenan | 9ac66968 | 2015-08-17 14:57:03 | [diff] [blame] | 1985 | // The field trials should be configured to force users that specify the |
bmcquade | 9dd54cc | 2015-06-22 16:56:52 | [diff] [blame] | 1986 | // blink-settings flag into a group with no params, and we return |
| 1987 | // above if no params were specified, so it's an error if we reach |
| 1988 | // this point. |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1989 | LOG(WARNING) << "Received field trial params, " |
| 1990 | "but blink-settings switch already specified."; |
| 1991 | return; |
| 1992 | } |
| 1993 | |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1994 | command_line->AppendSwitchASCII(switches::kBlinkSettings, |
brettw | d94a2214 | 2015-07-15 05:19:26 | [diff] [blame] | 1995 | base::JoinString(blink_settings, ",")); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 1996 | } |
| 1997 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 1998 | #if defined(OS_ANDROID) |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 1999 | template <typename Interface> |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2000 | void ForwardToJavaFrameRegistry(mojo::InterfaceRequest<Interface> request, |
| 2001 | content::RenderFrameHost* render_frame_host) { |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 2002 | render_frame_host->GetJavaInterfaces()->GetInterface(std::move(request)); |
mgiuca | 3d9a196 | 2017-04-07 05:25:44 | [diff] [blame] | 2003 | } |
| 2004 | |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 2005 | template <typename Interface> |
| 2006 | void ForwardToJavaWebContentsRegistry( |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 2007 | mojo::InterfaceRequest<Interface> request, |
| 2008 | content::RenderFrameHost* render_frame_host) { |
| 2009 | content::WebContents* contents = |
| 2010 | content::WebContents::FromRenderFrameHost(render_frame_host); |
| 2011 | if (contents) |
| 2012 | contents->GetJavaInterfaces()->GetInterface(std::move(request)); |
sammc | 0285a44 | 2016-10-04 23:03:56 | [diff] [blame] | 2013 | } |
| 2014 | #endif |
| 2015 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 2016 | } // namespace |
| 2017 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2018 | void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 2019 | base::CommandLine* command_line, |
| 2020 | int child_process_id) { |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2021 | #if defined(OS_MACOSX) |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2022 | std::unique_ptr<metrics::ClientInfo> client_info = |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2023 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
| 2024 | if (client_info) { |
| 2025 | command_line->AppendSwitchASCII(switches::kMetricsClientID, |
| 2026 | client_info->client_id); |
| 2027 | } |
| 2028 | #elif defined(OS_POSIX) |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 2029 | #if defined(OS_ANDROID) |
| 2030 | bool enable_crash_reporter = true; |
| 2031 | #else |
| 2032 | bool enable_crash_reporter = breakpad::IsCrashReporterEnabled(); |
| 2033 | #endif |
| 2034 | if (enable_crash_reporter) { |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2035 | std::string switch_value; |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2036 | std::unique_ptr<metrics::ClientInfo> client_info = |
[email protected] | 8e885de | 2014-07-22 23:36:53 | [diff] [blame] | 2037 | GoogleUpdateSettings::LoadMetricsClientInfo(); |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2038 | if (client_info) |
| 2039 | switch_value = client_info->client_id; |
| 2040 | switch_value.push_back(','); |
Boris Vidolov | 8657801 | 2018-03-21 16:55:25 | [diff] [blame] | 2041 | switch_value.append(chrome::GetChannelName()); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2042 | command_line->AppendSwitchASCII(switches::kEnableCrashReporter, |
thestig | cb7a59a | 2016-01-26 02:43:51 | [diff] [blame] | 2043 | switch_value); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2044 | } |
Mark Mentovai | c67fa64f | 2015-03-24 14:00:06 | [diff] [blame] | 2045 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2046 | |
[email protected] | f193379 | 2011-06-14 00:49:34 | [diff] [blame] | 2047 | if (logging::DialogsAreSuppressed()) |
| 2048 | command_line->AppendSwitch(switches::kNoErrorDialogs); |
| 2049 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2050 | std::string process_type = |
| 2051 | command_line->GetSwitchValueASCII(switches::kProcessType); |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 2052 | const base::CommandLine& browser_command_line = |
| 2053 | *base::CommandLine::ForCurrentProcess(); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 2054 | |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 2055 | static const char* const kCommonSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2056 | switches::kUserAgent, |
| 2057 | switches::kUserDataDir, // Make logs go to the right file. |
[email protected] | 7c9b6f9 | 2013-09-10 18:11:35 | [diff] [blame] | 2058 | }; |
| 2059 | command_line->CopySwitchesFrom(browser_command_line, kCommonSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2060 | base::size(kCommonSwitchNames)); |
[email protected] | 9206f2a0 | 2013-03-20 01:10:32 | [diff] [blame] | 2061 | |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2062 | static const char* const kDinosaurEasterEggSwitches[] = { |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 2063 | error_page::switches::kDisableDinosaurEasterEgg, |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 2064 | }; |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2065 | command_line->CopySwitchesFrom(browser_command_line, |
| 2066 | kDinosaurEasterEggSwitches, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2067 | base::size(kDinosaurEasterEggSwitches)); |
edwardjung | 7db1c9e | 2015-03-25 15:44:31 | [diff] [blame] | 2068 | |
fqj | 15ff3f7 | 2015-10-09 19:20:02 | [diff] [blame] | 2069 | #if defined(OS_CHROMEOS) |
[email protected] | 6bdc5227 | 2014-05-27 00:12:33 | [diff] [blame] | 2070 | // On Chrome OS need to pass primary user homedir (in multi-profiles session). |
| 2071 | base::FilePath homedir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 2072 | base::PathService::Get(base::DIR_HOME, &homedir); |
[email protected] | 6bdc5227 | 2014-05-27 00:12:33 | [diff] [blame] | 2073 | command_line->AppendSwitchASCII(chromeos::switches::kHomedir, |
| 2074 | homedir.value().c_str()); |
| 2075 | #endif |
| 2076 | |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 2077 | if (process_type == switches::kRendererProcess) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2078 | content::RenderProcessHost* process = |
| 2079 | content::RenderProcessHost::FromID(child_process_id); |
| 2080 | Profile* profile = |
| 2081 | process ? Profile::FromBrowserContext(process->GetBrowserContext()) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2082 | : nullptr; |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2083 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2084 | extra_parts_[i]->AppendExtraRendererCommandLineSwitches(command_line, |
| 2085 | process, profile); |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 2086 | } |
| 2087 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2088 | #if defined(OS_CHROMEOS) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2089 | const std::string& login_profile = browser_command_line.GetSwitchValueASCII( |
| 2090 | chromeos::switches::kLoginProfile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2091 | if (!login_profile.empty()) |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2092 | command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, |
| 2093 | login_profile); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2094 | #endif |
| 2095 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2096 | MaybeCopyDisableWebRtcEncryptionSwitch(command_line, browser_command_line, |
sdefresne | 9fb6769 | 2015-08-03 18:48:22 | [diff] [blame] | 2097 | chrome::GetChannel()); |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2098 | if (process) { |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2099 | PrefService* prefs = profile->GetPrefs(); |
| 2100 | // Currently this pref is only registered if applied via a policy. |
| 2101 | if (prefs->HasPrefPath(prefs::kDisable3DAPIs) && |
| 2102 | prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 2103 | // Turn this policy into a command line switch. |
| 2104 | command_line->AppendSwitch(switches::kDisable3DAPIs); |
| 2105 | } |
[email protected] | 718eab6 | 2011-10-05 21:16:52 | [diff] [blame] | 2106 | |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2107 | const base::ListValue* switches = |
| 2108 | prefs->GetList(prefs::kEnableDeprecatedWebPlatformFeatures); |
| 2109 | if (switches) { |
| 2110 | // Enable any deprecated features that have been re-enabled by policy. |
jdoerrie | 601c715 | 2018-10-02 23:43:11 | [diff] [blame] | 2111 | for (auto it = switches->begin(); it != switches->end(); ++it) { |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2112 | std::string switch_to_enable; |
jdoerrie | a5676c6 | 2017-04-11 18:09:14 | [diff] [blame] | 2113 | if (it->GetAsString(&switch_to_enable)) |
[email protected] | 1733b78 | 2014-06-19 18:51:55 | [diff] [blame] | 2114 | command_line->AppendSwitch(switch_to_enable); |
| 2115 | } |
| 2116 | } |
| 2117 | |
[email protected] | a8d851f8 | 2011-12-21 00:32:37 | [diff] [blame] | 2118 | // Disable client-side phishing detection in the renderer if it is |
| 2119 | // disabled in the Profile preferences or the browser process. |
| 2120 | if (!prefs->GetBoolean(prefs::kSafeBrowsingEnabled) || |
| 2121 | !g_browser_process->safe_browsing_detection_service()) { |
| 2122 | command_line->AppendSwitch( |
| 2123 | switches::kDisableClientSidePhishingDetection); |
| 2124 | } |
[email protected] | 0045b0f4 | 2012-07-26 11:52:08 | [diff] [blame] | 2125 | |
vitalybuka | a7ae505 | 2014-09-26 04:11:13 | [diff] [blame] | 2126 | if (prefs->GetBoolean(prefs::kPrintPreviewDisabled)) |
| 2127 | command_line->AppendSwitch(switches::kDisablePrintPreview); |
| 2128 | |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 2129 | #if !defined(OS_ANDROID) |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 2130 | InstantService* instant_service = |
| 2131 | InstantServiceFactory::GetForProfile(profile); |
| 2132 | if (instant_service && |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2133 | instant_service->IsInstantProcess(process->GetID())) { |
[email protected] | c5dec629 | 2013-01-25 04:54:52 | [diff] [blame] | 2134 | command_line->AppendSwitch(switches::kInstantProcess); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2135 | } |
Marc Treib | 7895941d | 2017-11-28 12:37:02 | [diff] [blame] | 2136 | #endif |
fqj | ba8749c | 2015-10-29 15:33:07 | [diff] [blame] | 2137 | |
fqj | 38306f7b | 2015-11-02 16:59:06 | [diff] [blame] | 2138 | if (prefs->HasPrefPath(prefs::kAllowDinosaurEasterEgg) && |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2139 | !prefs->GetBoolean(prefs::kAllowDinosaurEasterEgg)) { |
blundell | a5e3240a | 2016-01-05 11:30:43 | [diff] [blame] | 2140 | command_line->AppendSwitch( |
| 2141 | error_page::switches::kDisableDinosaurEasterEgg); |
Chris Palmer | ac7d7564 | 2017-11-22 20:12:54 | [diff] [blame] | 2142 | } |
Daniel Vogelheim | 976f1c2 | 2017-11-22 16:26:03 | [diff] [blame] | 2143 | |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 2144 | MaybeAppendSecureOriginsAllowlistSwitch(command_line); |
| 2145 | |
Amr Aboelkher | b04cbf3 | 2019-04-29 15:17:10 | [diff] [blame] | 2146 | if (prefs->HasPrefPath(prefs::kAllowPopupsDuringPageUnload) && |
| 2147 | prefs->GetBoolean(prefs::kAllowPopupsDuringPageUnload)) { |
Avi Drissman | fb96126 | 2019-03-05 22:50:29 | [diff] [blame] | 2148 | command_line->AppendSwitch(switches::kAllowPopupsDuringPageUnload); |
Amr Aboelkher | b04cbf3 | 2019-04-29 15:17:10 | [diff] [blame] | 2149 | } |
Katie Dillon | c25ee5c9 | 2019-09-12 17:05:42 | [diff] [blame] | 2150 | |
| 2151 | if (prefs->HasPrefPath(prefs::kAllowSyncXHRInPageDismissal) && |
| 2152 | prefs->GetBoolean(prefs::kAllowSyncXHRInPageDismissal)) { |
| 2153 | command_line->AppendSwitch(switches::kAllowSyncXHRInPageDismissal); |
| 2154 | } |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2155 | } |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2156 | |
[email protected] | d2e1a0a | 2014-06-16 15:49:37 | [diff] [blame] | 2157 | if (IsAutoReloadEnabled()) |
Elly Fong-Jones | 5f13ee1 | 2019-05-10 19:20:35 | [diff] [blame] | 2158 | command_line->AppendSwitch(switches::kEnableAutoReload); |
[email protected] | 28ee4e7 | 2014-03-28 19:29:04 | [diff] [blame] | 2159 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2160 | MaybeAppendBlinkSettingsSwitchForFieldTrial(browser_command_line, |
| 2161 | command_line); |
bmcquade | 5d2d9cf3 | 2015-06-19 17:42:28 | [diff] [blame] | 2162 | |
mdjones | a6b9e17 | 2016-09-23 16:24:30 | [diff] [blame] | 2163 | #if defined(OS_ANDROID) |
| 2164 | // If the platform is Android, force the distillability service on. |
| 2165 | command_line->AppendSwitch(switches::kEnableDistillabilityService); |
| 2166 | #endif |
| 2167 | |
[email protected] | 47c7ec8 | 2012-01-18 03:29:21 | [diff] [blame] | 2168 | // Please keep this in alphabetical order. |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2169 | static const char* const kSwitchNames[] = { |
estade | 0ee9126 | 2014-10-23 19:29:19 | [diff] [blame] | 2170 | autofill::switches::kIgnoreAutocompleteOffForAutofill, |
kolos | ad36993 | 2017-02-23 13:29:41 | [diff] [blame] | 2171 | autofill::switches::kShowAutofillSignatures, |
Chris Mumford | 6b1696b | 2019-01-25 02:54:30 | [diff] [blame] | 2172 | #if defined(OS_CHROMEOS) |
| 2173 | switches::kShortMergeSessionTimeoutForTest, // For tests only. |
| 2174 | #endif |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2175 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 558878cc8 | 2013-11-09 01:25:51 | [diff] [blame] | 2176 | extensions::switches::kAllowHTTPBackgroundPage, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2177 | extensions::switches::kAllowLegacyExtensionManifests, |
Chris Mumford | 3f0eda9 | 2018-07-23 14:51:17 | [diff] [blame] | 2178 | extensions::switches::kDisableExtensionsHttpThrottling, |
[email protected] | c8d0299 | 2013-07-31 22:16:51 | [diff] [blame] | 2179 | extensions::switches::kEnableExperimentalExtensionApis, |
[email protected] | 49d9b14 | 2013-07-19 08:50:27 | [diff] [blame] | 2180 | extensions::switches::kExtensionsOnChromeURLs, |
Chris Mumford | 3f0eda9 | 2018-07-23 14:51:17 | [diff] [blame] | 2181 | extensions::switches::kSetExtensionThrottleTestParams, // For tests only. |
[email protected] | a612eb3 | 2014-03-31 22:09:17 | [diff] [blame] | 2182 | extensions::switches::kWhitelistedExtensionID, |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 2183 | #endif |
estark | 4b003b33 | 2015-02-14 01:07:05 | [diff] [blame] | 2184 | switches::kAllowInsecureLocalhost, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2185 | switches::kAppsGalleryURL, |
[email protected] | 09cff7878 | 2014-04-20 22:04:48 | [diff] [blame] | 2186 | switches::kCloudPrintURL, |
[email protected] | 6f5c141a | 2014-04-15 21:44:51 | [diff] [blame] | 2187 | switches::kCloudPrintXmppEndpoint, |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 2188 | switches::kDisableBundledPpapiFlash, |
dslomov | a893e97 | 2014-12-05 09:39:57 | [diff] [blame] | 2189 | switches::kDisableJavaScriptHarmonyShipping, |
Kyle Milka | b5c048e | 2017-07-07 02:38:46 | [diff] [blame] | 2190 | variations::switches::kEnableBenchmarking, |
mdjones | a6b9e17 | 2016-09-23 16:24:30 | [diff] [blame] | 2191 | switches::kEnableDistillabilityService, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2192 | switches::kEnableNaCl, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2193 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | 1b4ec38 | 2014-03-07 02:32:24 | [diff] [blame] | 2194 | switches::kEnableNaClDebug, |
[email protected] | b2c73f4 | 2014-03-07 15:44:48 | [diff] [blame] | 2195 | switches::kEnableNaClNonSfiMode, |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 2196 | #endif |
[email protected] | ce304ce | 2013-02-22 21:54:45 | [diff] [blame] | 2197 | switches::kEnableNetBenchmarking, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2198 | #if BUILDFLAG(ENABLE_NACL) |
stichnot | 7040ac83 | 2016-02-24 23:40:59 | [diff] [blame] | 2199 | switches::kForcePNaClSubzero, |
| 2200 | #endif |
Marc Treib | ad33cf94 | 2017-08-24 11:19:00 | [diff] [blame] | 2201 | switches::kForceUIDirection, |
erikcorry | b251cb9 | 2014-09-25 23:48:51 | [diff] [blame] | 2202 | switches::kJavaScriptHarmony, |
Andreas Haas | b400d91 | 2019-08-28 18:54:10 | [diff] [blame] | 2203 | switches::kEnableExperimentalWebAssemblyFeatures, |
iclelland | 79237e9 | 2016-06-23 12:03:51 | [diff] [blame] | 2204 | switches::kOriginTrialDisabledFeatures, |
chasej | dfec22ae | 2017-03-16 20:58:55 | [diff] [blame] | 2205 | switches::kOriginTrialDisabledTokens, |
iclelland | ee4f4a7 | 2016-04-26 18:59:02 | [diff] [blame] | 2206 | switches::kOriginTrialPublicKey, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2207 | switches::kPpapiFlashArgs, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2208 | switches::kPpapiFlashPath, |
| 2209 | switches::kPpapiFlashVersion, |
wychen | e5568734 | 2015-11-13 20:17:03 | [diff] [blame] | 2210 | switches::kReaderModeHeuristics, |
[email protected] | 499e7c5 | 2013-10-04 16:03:09 | [diff] [blame] | 2211 | translate::switches::kTranslateSecurityOrigin, |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2212 | }; |
| 2213 | |
| 2214 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2215 | base::size(kSwitchNames)); |
[email protected] | 3cb054e6 | 2011-06-13 05:21:17 | [diff] [blame] | 2216 | } else if (process_type == switches::kUtilityProcess) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2217 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 2218 | static const char* const kSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2219 | extensions::switches::kAllowHTTPBackgroundPage, |
| 2220 | extensions::switches::kEnableExperimentalExtensionApis, |
| 2221 | extensions::switches::kExtensionsOnChromeURLs, |
| 2222 | extensions::switches::kWhitelistedExtensionID, |
[email protected] | a446534d | 2012-02-09 00:07:38 | [diff] [blame] | 2223 | }; |
| 2224 | |
| 2225 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2226 | base::size(kSwitchNames)); |
thestig | 2dbee717e | 2014-09-05 14:54:28 | [diff] [blame] | 2227 | #endif |
Lukasz Anforowicz | 60d1253d | 2019-05-08 16:31:37 | [diff] [blame] | 2228 | MaybeAppendSecureOriginsAllowlistSwitch(command_line); |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 2229 | } else if (process_type == service_manager::switches::kZygoteProcess) { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2230 | static const char* const kSwitchNames[] = { |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2231 | // Load (in-process) Pepper plugins in-process in the zygote pre-sandbox. |
[email protected] | 382fb0d | 2012-02-25 00:19:50 | [diff] [blame] | 2232 | switches::kDisableBundledPpapiFlash, |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 2233 | #if BUILDFLAG(ENABLE_NACL) |
rickyz | 3638a21 | 2014-10-29 23:50:24 | [diff] [blame] | 2234 | switches::kEnableNaClDebug, |
[email protected] | a9a8e2f | 2014-05-13 23:32:58 | [diff] [blame] | 2235 | switches::kEnableNaClNonSfiMode, |
stichnot | 7040ac83 | 2016-02-24 23:40:59 | [diff] [blame] | 2236 | switches::kForcePNaClSubzero, |
[email protected] | 0b47034 | 2014-04-15 12:59:41 | [diff] [blame] | 2237 | switches::kNaClDangerousNoSandboxNonSfi, |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 2238 | #endif |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 2239 | switches::kPpapiFlashPath, |
| 2240 | switches::kPpapiFlashVersion, |
| 2241 | }; |
| 2242 | |
| 2243 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 2244 | base::size(kSwitchNames)); |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 2245 | } else if (process_type == switches::kGpuProcess) { |
| 2246 | // If --ignore-gpu-blacklist is passed in, don't send in crash reports |
| 2247 | // because GPU is expected to be unreliable. |
| 2248 | if (browser_command_line.HasSwitch(switches::kIgnoreGpuBlacklist) && |
| 2249 | !command_line->HasSwitch(switches::kDisableBreakpad)) |
| 2250 | command_line->AppendSwitch(switches::kDisableBreakpad); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2251 | } |
[email protected] | 6f08af8 | 2011-09-15 01:19:03 | [diff] [blame] | 2252 | |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2253 | #if defined(OS_CHROMEOS) |
Joshua Peraza | 30d8fc7 | 2019-08-19 17:24:30 | [diff] [blame] | 2254 | if (ChromeCrashReporterClient::ShouldPassCrashLoopBefore(process_type)) { |
Ian Barkley-Yeung | 550aae05 | 2019-07-11 00:11:11 | [diff] [blame] | 2255 | static const char* const kSwitchNames[] = { |
| 2256 | switches::kCrashLoopBefore, |
| 2257 | }; |
| 2258 | command_line->CopySwitchesFrom(browser_command_line, kSwitchNames, |
| 2259 | base::size(kSwitchNames)); |
| 2260 | } |
| 2261 | #endif |
| 2262 | |
wittman | 832321f5 | 2016-10-10 18:18:38 | [diff] [blame] | 2263 | StackSamplingConfiguration::Get()->AppendCommandLineSwitchForChildProcess( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2264 | process_type, command_line); |
Andrew Comminos | 6605767 | 2019-05-01 00:03:34 | [diff] [blame] | 2265 | |
| 2266 | #if defined(OS_LINUX) |
| 2267 | // Processes may only query perf_event_open with the BPF sandbox disabled. |
| 2268 | if (browser_command_line.HasSwitch(switches::kEnableThreadInstructionCount) && |
| 2269 | command_line->HasSwitch(service_manager::switches::kNoSandbox)) { |
| 2270 | command_line->AppendSwitch(switches::kEnableThreadInstructionCount); |
| 2271 | } |
| 2272 | #endif |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2273 | } |
| 2274 | |
Scott Violet | 776edf8 | 2017-09-29 02:03:01 | [diff] [blame] | 2275 | void ChromeContentBrowserClient::AdjustUtilityServiceProcessCommandLine( |
| 2276 | const service_manager::Identity& identity, |
| 2277 | base::CommandLine* command_line) { |
Guido Urdaneta | 191635e | 2018-05-09 16:00:53 | [diff] [blame] | 2278 | #if defined(OS_MACOSX) |
Ken Rockot | 2f8c1dd2 | 2019-07-23 21:56:02 | [diff] [blame] | 2279 | // On Mac, the audio service requires a CFRunLoop, provided by a UI message |
| 2280 | // loop, to run AVFoundation and CoreAudio code. See https://crbug.com/834581. |
| 2281 | if (identity.name() == audio::mojom::kServiceName) |
Guido Urdaneta | 191635e | 2018-05-09 16:00:53 | [diff] [blame] | 2282 | command_line->AppendSwitch(switches::kMessageLoopTypeUi); |
| 2283 | #endif |
Scott Violet | 776edf8 | 2017-09-29 02:03:01 | [diff] [blame] | 2284 | } |
| 2285 | |
Olivier Yiptong | 0daa93f | 2019-08-22 19:40:08 | [diff] [blame] | 2286 | std::string |
| 2287 | ChromeContentBrowserClient::GetApplicationClientGUIDForQuarantineCheck() { |
| 2288 | return std::string(chrome::kApplicationClientIDStringForAVScanning); |
| 2289 | } |
| 2290 | |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2291 | std::string ChromeContentBrowserClient::GetApplicationLocale() { |
[email protected] | e9a32a5 | 2012-06-14 23:32:43 | [diff] [blame] | 2292 | if (BrowserThread::CurrentlyOn(BrowserThread::IO)) |
Lei Zhang | 2cfceac | 2018-11-14 19:36:33 | [diff] [blame] | 2293 | return GetIOThreadApplicationLocale(); |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 2294 | return g_browser_process->GetApplicationLocale(); |
| 2295 | } |
| 2296 | |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 2297 | std::string ChromeContentBrowserClient::GetAcceptLangs( |
| 2298 | content::BrowserContext* context) { |
| 2299 | Profile* profile = Profile::FromBrowserContext(context); |
Alexandre Frechette | 572755b | 2019-02-13 22:30:20 | [diff] [blame] | 2300 | return profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 2301 | } |
| 2302 | |
Dana Fried | 34d58000 | 2019-04-24 20:05:48 | [diff] [blame] | 2303 | gfx::ImageSkia ChromeContentBrowserClient::GetDefaultFavicon() { |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 2304 | ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
Dana Fried | 34d58000 | 2019-04-24 20:05:48 | [diff] [blame] | 2305 | return rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).AsImageSkia(); |
[email protected] | ac55e29 | 2011-06-24 05:16:08 | [diff] [blame] | 2306 | } |
| 2307 | |
bengr | e8a146f | 2016-03-10 01:20:22 | [diff] [blame] | 2308 | bool ChromeContentBrowserClient::IsDataSaverEnabled( |
| 2309 | content::BrowserContext* browser_context) { |
Robert Ogden | c995d4fe | 2019-03-25 19:18:37 | [diff] [blame] | 2310 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2311 | return profile && data_reduction_proxy::DataReductionProxySettings:: |
| 2312 | IsDataSaverEnabledByUser(profile->GetPrefs()); |
bengr | e8a146f | 2016-03-10 01:20:22 | [diff] [blame] | 2313 | } |
| 2314 | |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 2315 | void ChromeContentBrowserClient::UpdateRendererPreferencesForWorker( |
| 2316 | content::BrowserContext* browser_context, |
Leon Han | c819dc6 | 2019-01-28 04:30:19 | [diff] [blame] | 2317 | blink::mojom::RendererPreferences* out_prefs) { |
Kenichi Ishibashi | 4632987 | 2018-07-17 09:43:40 | [diff] [blame] | 2318 | DCHECK(browser_context); |
| 2319 | DCHECK(out_prefs); |
| 2320 | renderer_preferences_util::UpdateFromSystemSettings( |
| 2321 | out_prefs, Profile::FromBrowserContext(browser_context)); |
| 2322 | } |
| 2323 | |
Clark DuVall | 5690e74 | 2019-07-17 18:26:17 | [diff] [blame] | 2324 | bool ChromeContentBrowserClient::AllowAppCache( |
| 2325 | const GURL& manifest_url, |
| 2326 | const GURL& first_party, |
| 2327 | content::BrowserContext* context) { |
| 2328 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2329 | return CookieSettingsFactory::GetForProfile( |
| 2330 | Profile::FromBrowserContext(context)) |
| 2331 | ->IsCookieAccessAllowed(manifest_url, first_party); |
| 2332 | } |
| 2333 | |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2334 | bool ChromeContentBrowserClient::AllowServiceWorkerOnIO( |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2335 | const GURL& scope, |
| 2336 | const GURL& first_party_url, |
David Bertoni | 3b3597d8 | 2019-06-22 02:29:36 | [diff] [blame] | 2337 | const GURL& script_url, |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2338 | content::ResourceContext* context, |
tzik | df81f14 | 2018-10-26 00:23:34 | [diff] [blame] | 2339 | base::RepeatingCallback<content::WebContents*()> wc_getter) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 2340 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2341 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2342 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2343 | // Check if this is an extension-related service worker, and, if so, if it's |
| 2344 | // allowed (this can return false if, e.g., the extension is disabled). |
| 2345 | // If it's not allowed, return immediately. We deliberately do *not* report |
| 2346 | // to the TabSpecificContentSettings, since the service worker is blocked |
| 2347 | // because of the extension, rather than because of the user's content |
| 2348 | // settings. |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2349 | if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnIO( |
David Bertoni | 3b3597d8 | 2019-06-22 02:29:36 | [diff] [blame] | 2350 | scope, first_party_url, script_url, context)) { |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2351 | return false; |
| 2352 | } |
| 2353 | #endif |
| 2354 | |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2355 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(context); |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2356 | |
shimazu | ce8af8812 | 2016-10-06 23:49:21 | [diff] [blame] | 2357 | // Check if JavaScript is allowed. |
| 2358 | content_settings::SettingInfo info; |
| 2359 | std::unique_ptr<base::Value> value = |
| 2360 | io_data->GetHostContentSettingsMap()->GetWebsiteSetting( |
| 2361 | first_party_url, first_party_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 2362 | std::string(), &info); |
| 2363 | ContentSetting setting = content_settings::ValueToContentSetting(value.get()); |
| 2364 | bool allow_javascript = (setting == CONTENT_SETTING_ALLOW); |
| 2365 | |
| 2366 | // Check if cookies are allowed. |
| 2367 | bool allow_serviceworker = |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 2368 | io_data->GetCookieSettings()->IsCookieAccessAllowed(scope, |
| 2369 | first_party_url); |
falken | 4a22dce | 2015-04-30 08:25:20 | [diff] [blame] | 2370 | // Record access to database for potential display in UI. |
yzshen | bc36c97 | 2016-12-21 21:39:24 | [diff] [blame] | 2371 | // Only post the task if this is for a specific tab. |
| 2372 | if (!wc_getter.is_null()) { |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 2373 | base::PostTask( |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 2374 | FROM_HERE, {BrowserThread::UI}, |
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 2375 | base::BindOnce(&TabSpecificContentSettings::ServiceWorkerAccessed, |
tzik | df81f14 | 2018-10-26 00:23:34 | [diff] [blame] | 2376 | std::move(wc_getter), scope, !allow_javascript, |
tzik | 29ea5c7 | 2017-04-20 02:16:51 | [diff] [blame] | 2377 | !allow_serviceworker)); |
rdevlin.cronin | f5863da | 2015-09-10 19:21:45 | [diff] [blame] | 2378 | } |
shimazu | ce8af8812 | 2016-10-06 23:49:21 | [diff] [blame] | 2379 | return allow_javascript && allow_serviceworker; |
falken | 3dbc36e | 2014-10-10 16:48:07 | [diff] [blame] | 2380 | } |
| 2381 | |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2382 | bool ChromeContentBrowserClient::AllowServiceWorkerOnUI( |
| 2383 | const GURL& scope, |
| 2384 | const GURL& first_party_url, |
| 2385 | const GURL& script_url, |
| 2386 | content::BrowserContext* context, |
| 2387 | base::RepeatingCallback<content::WebContents*()> wc_getter) { |
| 2388 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2389 | |
| 2390 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Matt Falkenhagen | a59e1cce | 2019-08-22 23:45:02 | [diff] [blame] | 2391 | // Check if this is an extension-related service worker, and, if so, if it's |
| 2392 | // allowed (this can return false if, e.g., the extension is disabled). |
| 2393 | // If it's not allowed, return immediately. We deliberately do *not* report |
| 2394 | // to the TabSpecificContentSettings, since the service worker is blocked |
| 2395 | // because of the extension, rather than because of the user's content |
| 2396 | // settings. |
| 2397 | if (!ChromeContentBrowserClientExtensionsPart::AllowServiceWorkerOnUI( |
| 2398 | scope, first_party_url, script_url, context)) { |
| 2399 | return false; |
| 2400 | } |
Matt Falkenhagen | 7b509e5 | 2019-08-15 23:11:41 | [diff] [blame] | 2401 | #endif |
| 2402 | |
| 2403 | Profile* profile = Profile::FromBrowserContext(context); |
| 2404 | |
| 2405 | // Check if JavaScript is allowed. |
| 2406 | content_settings::SettingInfo info; |
| 2407 | std::unique_ptr<base::Value> value = |
| 2408 | HostContentSettingsMapFactory::GetForProfile(profile)->GetWebsiteSetting( |
| 2409 | first_party_url, first_party_url, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 2410 | std::string(), &info); |
| 2411 | ContentSetting setting = content_settings::ValueToContentSetting(value.get()); |
| 2412 | bool allow_javascript = (setting == CONTENT_SETTING_ALLOW); |
| 2413 | |
| 2414 | // Check if cookies are allowed. |
| 2415 | bool allow_cookies = |
| 2416 | CookieSettingsFactory::GetForProfile(profile)->IsCookieAccessAllowed( |
| 2417 | scope, first_party_url); |
| 2418 | |
| 2419 | // Record access to database for potential display in UI. |
| 2420 | // Only post the task if this is for a specific tab. |
| 2421 | if (!wc_getter.is_null()) { |
| 2422 | TabSpecificContentSettings::ServiceWorkerAccessed( |
| 2423 | std::move(wc_getter), scope, !allow_javascript, !allow_cookies); |
| 2424 | } |
| 2425 | return allow_javascript && allow_cookies; |
| 2426 | } |
| 2427 | |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2428 | bool ChromeContentBrowserClient::AllowSharedWorker( |
| 2429 | const GURL& worker_url, |
| 2430 | const GURL& main_frame_url, |
| 2431 | const std::string& name, |
Hiroki Nakagawa | 018bb6d | 2017-11-30 03:31:37 | [diff] [blame] | 2432 | const url::Origin& constructor_origin, |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2433 | content::BrowserContext* context, |
| 2434 | int render_process_id, |
| 2435 | int render_frame_id) { |
| 2436 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2437 | |
| 2438 | // Check if cookies are allowed. |
| 2439 | bool allow = |
| 2440 | CookieSettingsFactory::GetForProfile(Profile::FromBrowserContext(context)) |
| 2441 | ->IsCookieAccessAllowed(worker_url, main_frame_url); |
| 2442 | |
| 2443 | TabSpecificContentSettings::SharedWorkerAccessed( |
Hiroki Nakagawa | 018bb6d | 2017-11-30 03:31:37 | [diff] [blame] | 2444 | render_process_id, render_frame_id, worker_url, name, constructor_origin, |
| 2445 | !allow); |
Jochen Eisinger | 0ff7645c | 2017-11-28 08:11:26 | [diff] [blame] | 2446 | return allow; |
| 2447 | } |
| 2448 | |
Patrick Monette | 6cb099a | 2019-09-18 19:31:27 | [diff] [blame] | 2449 | bool ChromeContentBrowserClient::DoesSchemeAllowCrossOriginSharedWorker( |
| 2450 | const std::string& scheme) { |
| 2451 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 2452 | // Extensions are allowed to start cross-origin shared workers. |
| 2453 | if (scheme == extensions::kExtensionScheme) |
| 2454 | return true; |
| 2455 | #endif |
| 2456 | |
| 2457 | return false; |
| 2458 | } |
| 2459 | |
Clark DuVall | ab63d14 | 2019-07-23 04:24:36 | [diff] [blame] | 2460 | bool ChromeContentBrowserClient::AllowSignedExchange( |
| 2461 | content::BrowserContext* browser_context) { |
| 2462 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2463 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2464 | return profile->GetPrefs()->GetBoolean(prefs::kSignedHTTPExchangeEnabled); |
| 2465 | } |
| 2466 | |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2467 | void ChromeContentBrowserClient::AllowWorkerFileSystem( |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2468 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2469 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2470 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2471 | base::OnceCallback<void(bool)> callback) { |
| 2472 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2473 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 2474 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2475 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2476 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2477 | GuestPermissionRequestHelper(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2478 | #else |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2479 | FileSystemAccessed(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2480 | #endif |
| 2481 | } |
| 2482 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2483 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2484 | void ChromeContentBrowserClient::GuestPermissionRequestHelper( |
| 2485 | const GURL& url, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2486 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2487 | base::OnceCallback<void(bool)> callback, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2488 | bool allow) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2489 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2490 | std::map<int, int> process_map; |
| 2491 | std::map<int, int>::const_iterator it; |
| 2492 | bool has_web_view_guest = false; |
| 2493 | // Record access to file system for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2494 | for (const auto& it : render_frames) { |
| 2495 | if (process_map.find(it.child_id) != process_map.end()) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2496 | continue; |
| 2497 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2498 | 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] | 2499 | |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2500 | if (extensions::WebViewRendererState::GetInstance()->IsGuest(it.child_id)) |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2501 | has_web_view_guest = true; |
| 2502 | } |
| 2503 | if (!has_web_view_guest) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2504 | FileSystemAccessed(url, render_frames, std::move(callback), allow); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2505 | return; |
| 2506 | } |
[email protected] | dffb9fc | 2014-07-16 04:14:02 | [diff] [blame] | 2507 | DCHECK_EQ(1U, process_map.size()); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2508 | it = process_map.begin(); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2509 | |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 2510 | extensions::WebViewPermissionHelper* web_view_permission_helper = |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2511 | extensions::WebViewPermissionHelper::FromFrameID(it->first, it->second); |
| 2512 | web_view_permission_helper->RequestFileSystemPermission( |
| 2513 | url, allow, |
| 2514 | base::BindOnce(&ChromeContentBrowserClient::FileSystemAccessed, |
| 2515 | weak_factory_.GetWeakPtr(), url, render_frames, |
| 2516 | std::move(callback))); |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2517 | } |
| 2518 | #endif |
| 2519 | |
| 2520 | void ChromeContentBrowserClient::FileSystemAccessed( |
| 2521 | const GURL& url, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2522 | const std::vector<content::GlobalFrameRoutingId>& render_frames, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2523 | base::OnceCallback<void(bool)> callback, |
[email protected] | f917df2 | 2014-07-10 07:45:49 | [diff] [blame] | 2524 | bool allow) { |
[email protected] | 6215105 | 2012-02-01 18:40:48 | [diff] [blame] | 2525 | // Record access to file system for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2526 | for (const auto& it : render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2527 | TabSpecificContentSettings::FileSystemAccessed( |
| 2528 | it.child_id, it.frame_routing_id, url, !allow); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2529 | } |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2530 | std::move(callback).Run(allow); |
[email protected] | 5c5a88e | 2011-11-12 00:45:35 | [diff] [blame] | 2531 | } |
| 2532 | |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2533 | bool ChromeContentBrowserClient::AllowWorkerIndexedDB( |
| 2534 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2535 | content::BrowserContext* browser_context, |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2536 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2537 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2538 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
| 2539 | |
falken | 7169140 | 2017-01-27 03:38:00 | [diff] [blame] | 2540 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2541 | |
| 2542 | // Record access to IndexedDB for potential display in UI. |
Lukasz Anforowicz | 09060bdf7 | 2018-08-23 15:53:17 | [diff] [blame] | 2543 | for (const auto& it : render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2544 | TabSpecificContentSettings::IndexedDBAccessed( |
| 2545 | it.child_id, it.frame_routing_id, url, !allow); |
[email protected] | 7c5ff9a | 2012-03-02 07:42:49 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | return allow; |
| 2549 | } |
| 2550 | |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2551 | bool ChromeContentBrowserClient::AllowWorkerCacheStorage( |
| 2552 | const GURL& url, |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2553 | content::BrowserContext* browser_context, |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2554 | const std::vector<content::GlobalFrameRoutingId>& render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2555 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2556 | auto cookie_settings = CookieSettingsFactory::GetForProfile(profile); |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2557 | bool allow = cookie_settings->IsCookieAccessAllowed(url, url); |
| 2558 | |
| 2559 | // Record access to CacheStorage for potential display in UI. |
| 2560 | for (const auto& it : render_frames) { |
John Abd-El-Malek | 2a18d98d | 2019-08-08 04:31:57 | [diff] [blame] | 2561 | TabSpecificContentSettings::CacheStorageAccessed( |
| 2562 | it.child_id, it.frame_routing_id, url, !allow); |
Ben Kelly | 6b2e61c | 2019-03-14 16:06:29 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | return allow; |
| 2566 | } |
| 2567 | |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2568 | ChromeContentBrowserClient::AllowWebBluetoothResult |
| 2569 | ChromeContentBrowserClient::AllowWebBluetooth( |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2570 | content::BrowserContext* browser_context, |
| 2571 | const url::Origin& requesting_origin, |
| 2572 | const url::Origin& embedding_origin) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2573 | // TODO(crbug.com/598890): Don't disable if |
| 2574 | // base::CommandLine::ForCurrentProcess()-> |
| 2575 | // HasSwitch(switches::kEnableWebBluetooth) is true. |
| 2576 | if (variations::GetVariationParamValue( |
| 2577 | PermissionContextBase::kPermissionsKillSwitchFieldStudy, |
| 2578 | "Bluetooth") == |
| 2579 | PermissionContextBase::kPermissionsKillSwitchBlockedValue) { |
| 2580 | // The kill switch is enabled for this permission. Block requests. |
| 2581 | return AllowWebBluetoothResult::BLOCK_GLOBALLY_DISABLED; |
| 2582 | } |
| 2583 | |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2584 | const HostContentSettingsMap* const content_settings = |
| 2585 | HostContentSettingsMapFactory::GetForProfile( |
| 2586 | Profile::FromBrowserContext(browser_context)); |
| 2587 | |
csharrison | aec2c54 | 2016-10-12 19:40:36 | [diff] [blame] | 2588 | if (content_settings->GetContentSetting( |
| 2589 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
| 2590 | CONTENT_SETTINGS_TYPE_BLUETOOTH_GUARD, |
| 2591 | std::string()) == CONTENT_SETTING_BLOCK) { |
jyasskin | c993ce8d | 2016-03-31 00:38:34 | [diff] [blame] | 2592 | return AllowWebBluetoothResult::BLOCK_POLICY; |
| 2593 | } |
| 2594 | return AllowWebBluetoothResult::ALLOW; |
jyasskin | 98bdd399 | 2016-02-26 20:25:45 | [diff] [blame] | 2595 | } |
| 2596 | |
beaufort.francois | 01135bf | 2016-11-23 14:37:36 | [diff] [blame] | 2597 | std::string ChromeContentBrowserClient::GetWebBluetoothBlocklist() { |
| 2598 | return variations::GetVariationParamValue("WebBluetoothBlocklist", |
| 2599 | "blocklist_additions"); |
scheib | 7425032 | 2016-04-07 03:32:21 | [diff] [blame] | 2600 | } |
| 2601 | |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 2602 | #if defined(OS_CHROMEOS) |
John Abd-El-Malek | a5b1a5d60 | 2018-11-05 19:20:52 | [diff] [blame] | 2603 | void ChromeContentBrowserClient::OnTrustAnchorUsed( |
John Abd-El-Malek | 35bfaa5 | 2019-08-20 16:22:07 | [diff] [blame] | 2604 | content::BrowserContext* browser_context) { |
| 2605 | user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 2606 | if (user_manager) { |
| 2607 | const user_manager::User* user = |
| 2608 | chromeos::ProfileHelper::Get()->GetUserByProfile( |
| 2609 | Profile::FromBrowserContext(browser_context)); |
| 2610 | if (user && !user->username_hash().empty()) { |
| 2611 | policy::PolicyCertServiceFactory::SetUsedPolicyCertificates( |
| 2612 | user->username_hash()); |
| 2613 | } |
| 2614 | } |
John Abd-El-Malek | 21bca7c | 2018-10-26 22:13:33 | [diff] [blame] | 2615 | } |
| 2616 | #endif |
| 2617 | |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2618 | scoped_refptr<network::SharedURLLoaderFactory> |
| 2619 | ChromeContentBrowserClient::GetSystemSharedURLLoaderFactory() { |
Min Qin | da0d55b | 2018-10-12 18:30:05 | [diff] [blame] | 2620 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 2621 | !BrowserThread::IsThreadInitialized(BrowserThread::UI)); |
| 2622 | |
| 2623 | if (!SystemNetworkContextManager::GetInstance()) |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2624 | return nullptr; |
| 2625 | |
Min Qin | da0d55b | 2018-10-12 18:30:05 | [diff] [blame] | 2626 | return SystemNetworkContextManager::GetInstance() |
Reilly Grant | 19aaccd | 2018-07-16 22:06:37 | [diff] [blame] | 2627 | ->GetSharedURLLoaderFactory(); |
Andrew Moylan | 8673dba | 2017-10-10 04:29:04 | [diff] [blame] | 2628 | } |
| 2629 | |
Sean Gilhuly | da1ee4b | 2018-11-13 21:56:09 | [diff] [blame] | 2630 | network::mojom::NetworkContext* |
| 2631 | ChromeContentBrowserClient::GetSystemNetworkContext() { |
| 2632 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2633 | DCHECK(g_browser_process->system_network_context_manager()); |
| 2634 | return g_browser_process->system_network_context_manager()->GetContext(); |
| 2635 | } |
| 2636 | |
Andrew Moylan | 17329fc | 2017-09-25 07:43:30 | [diff] [blame] | 2637 | std::string ChromeContentBrowserClient::GetGeolocationApiKey() { |
| 2638 | return google_apis::GetAPIKey(); |
| 2639 | } |
| 2640 | |
Ke He | 21ee87f | 2018-05-30 02:35:32 | [diff] [blame] | 2641 | #if defined(OS_ANDROID) |
| 2642 | bool ChromeContentBrowserClient::ShouldUseGmsCoreGeolocationProvider() { |
| 2643 | // Indicate that Chrome uses the GMS core location provider. |
| 2644 | return true; |
| 2645 | } |
| 2646 | #endif |
| 2647 | |
Yeol | f3dc22ca | 2019-04-18 17:25:32 | [diff] [blame] | 2648 | scoped_refptr<content::QuotaPermissionContext> |
[email protected] | 317f96c9 | 2011-05-31 06:53:41 | [diff] [blame] | 2649 | ChromeContentBrowserClient::CreateQuotaPermissionContext() { |
| 2650 | return new ChromeQuotaPermissionContext(); |
| 2651 | } |
| 2652 | |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 2653 | void ChromeContentBrowserClient::GetQuotaSettings( |
| 2654 | content::BrowserContext* context, |
| 2655 | content::StoragePartition* partition, |
tapted | e6d878e | 2017-06-24 01:53:45 | [diff] [blame] | 2656 | storage::OptionalQuotaSettingsCallback callback) { |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 2657 | if (g_default_quota_settings) { |
| 2658 | // For debugging tests harness can inject settings. |
tapted | e6d878e | 2017-06-24 01:53:45 | [diff] [blame] | 2659 | std::move(callback).Run(*g_default_quota_settings); |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 2660 | return; |
| 2661 | } |
tapted | e6d878e | 2017-06-24 01:53:45 | [diff] [blame] | 2662 | storage::GetNominalDynamicSettings( |
Jarryd | 451ab7b | 2019-02-12 06:39:06 | [diff] [blame] | 2663 | partition->GetPath(), context->IsOffTheRecord(), |
| 2664 | storage::GetDefaultDiskInfoHelper(), std::move(callback)); |
calamity | c96116b | 2015-11-03 04:30:51 | [diff] [blame] | 2665 | } |
| 2666 | |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 2667 | content::GeneratedCodeCacheSettings |
| 2668 | ChromeContentBrowserClient::GetGeneratedCodeCacheSettings( |
| 2669 | content::BrowserContext* context) { |
| 2670 | base::FilePath cache_path; |
| 2671 | chrome::GetUserCacheDirectory(context->GetPath(), &cache_path); |
| 2672 | // If we pass 0 for size, disk_cache will pick a default size using the |
| 2673 | // heuristics based on available disk size. These are implemented in |
| 2674 | // disk_cache::PreferredCacheSize in net/disk_cache/cache_util.cc. |
Mythri A | b248657 | 2019-06-13 14:48:16 | [diff] [blame] | 2675 | int64_t size_in_bytes = 0; |
Greg Thompson | 8c922756 | 2019-08-05 17:47:13 | [diff] [blame] | 2676 | DCHECK(g_browser_process); |
| 2677 | PrefService* local_state = g_browser_process->local_state(); |
| 2678 | if (local_state) { |
| 2679 | size_in_bytes = local_state->GetInteger(prefs::kDiskCacheSize); |
| 2680 | base::FilePath disk_cache_dir = |
| 2681 | local_state->GetFilePath(prefs::kDiskCacheDir); |
| 2682 | if (!disk_cache_dir.empty()) |
| 2683 | cache_path = disk_cache_dir.Append(cache_path.BaseName()); |
| 2684 | } |
Mythri A | b248657 | 2019-06-13 14:48:16 | [diff] [blame] | 2685 | return content::GeneratedCodeCacheSettings(true, size_in_bytes, cache_path); |
Mythri Alle | 0b8de0d | 2018-10-22 11:06:22 | [diff] [blame] | 2686 | } |
| 2687 | |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 2688 | void ChromeContentBrowserClient::AllowCertificateError( |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2689 | content::WebContents* web_contents, |
[email protected] | 4cf611e3 | 2012-02-13 16:06:17 | [diff] [blame] | 2690 | int cert_error, |
| 2691 | const net::SSLInfo& ssl_info, |
| 2692 | const GURL& request_url, |
John Abd-El-Malek | c5b8df91 | 2019-05-07 17:02:23 | [diff] [blame] | 2693 | bool is_main_frame_request, |
[email protected] | d9be4770 | 2012-05-16 03:41:22 | [diff] [blame] | 2694 | bool strict_enforcement, |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2695 | const base::Callback<void(content::CertificateRequestResultType)>& |
| 2696 | callback) { |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2697 | DCHECK(web_contents); |
John Abd-El-Malek | c5b8df91 | 2019-05-07 17:02:23 | [diff] [blame] | 2698 | if (!is_main_frame_request) { |
irisu | 8452ddd6 | 2017-03-22 07:46:14 | [diff] [blame] | 2699 | // A sub-resource has a certificate error. The user doesn't really |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 2700 | // have a context for making the right decision, so block the |
| 2701 | // request hard, without an info bar to allow showing the insecure |
| 2702 | // content. |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2703 | if (!callback.is_null()) |
| 2704 | callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
[email protected] | a2f7688 | 2013-02-25 21:36:02 | [diff] [blame] | 2705 | return; |
| 2706 | } |
| 2707 | |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 2708 | // If the tab is being prerendered, cancel the prerender and the request. |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2709 | prerender::PrerenderContents* prerender_contents = |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 2710 | prerender::PrerenderContents::FromWebContents(web_contents); |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2711 | if (prerender_contents) { |
| 2712 | prerender_contents->Destroy(prerender::FINAL_STATUS_SSL_ERROR); |
estark | 719dde5 | 2016-08-09 03:14:27 | [diff] [blame] | 2713 | if (!callback.is_null()) { |
| 2714 | callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL); |
| 2715 | } |
[email protected] | 09667f0 | 2014-01-06 15:37:57 | [diff] [blame] | 2716 | return; |
[email protected] | f9034cf | 2011-07-21 12:43:41 | [diff] [blame] | 2717 | } |
| 2718 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 2719 | callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY); |
| 2720 | return; |
[email protected] | 848dd04 | 2011-06-04 18:24:03 | [diff] [blame] | 2721 | } |
| 2722 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2723 | namespace { |
| 2724 | |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2725 | certificate_matching::CertificatePrincipalPattern |
| 2726 | ParseCertificatePrincipalPattern(const base::Value* pattern) { |
| 2727 | return certificate_matching::CertificatePrincipalPattern:: |
| 2728 | ParseFromOptionalDict(pattern, "CN", "L", "O", "OU"); |
| 2729 | } |
| 2730 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2731 | // Attempts to auto-select a client certificate according to the value of |
| 2732 | // |CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE| content setting for |
| 2733 | // |requesting_url|. If no certificate was auto-selected, returns nullptr. |
| 2734 | std::unique_ptr<net::ClientCertIdentity> AutoSelectCertificate( |
| 2735 | Profile* profile, |
| 2736 | const GURL& requesting_url, |
| 2737 | net::ClientCertIdentityList& client_certs) { |
| 2738 | HostContentSettingsMap* host_content_settings_map = |
| 2739 | HostContentSettingsMapFactory::GetForProfile(profile); |
| 2740 | std::unique_ptr<base::Value> setting = |
| 2741 | host_content_settings_map->GetWebsiteSetting( |
| 2742 | requesting_url, requesting_url, |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 2743 | CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), |
| 2744 | nullptr); |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2745 | |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2746 | if (!setting || !setting->is_dict()) |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2747 | return nullptr; |
| 2748 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2749 | const base::Value* filters = |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2750 | setting->FindKeyOfType("filters", base::Value::Type::LIST); |
| 2751 | if (!filters) { |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2752 | // |setting_dict| has the wrong format (e.g. single filter instead of a |
| 2753 | // list of filters). This content setting is only provided by |
| 2754 | // the |PolicyProvider|, which should always set it to a valid format. |
| 2755 | // Therefore, delete the invalid value. |
| 2756 | host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 2757 | requesting_url, requesting_url, |
| 2758 | CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), nullptr); |
Pavol Marko | b211ab2 | 2019-01-23 20:03:04 | [diff] [blame] | 2759 | return nullptr; |
| 2760 | } |
| 2761 | |
| 2762 | for (const base::Value& filter : filters->GetList()) { |
| 2763 | DCHECK(filter.is_dict()); |
| 2764 | |
| 2765 | auto issuer_pattern = ParseCertificatePrincipalPattern( |
| 2766 | filter.FindKeyOfType("ISSUER", base::Value::Type::DICTIONARY)); |
| 2767 | auto subject_pattern = ParseCertificatePrincipalPattern( |
| 2768 | filter.FindKeyOfType("SUBJECT", base::Value::Type::DICTIONARY)); |
| 2769 | // Use the first certificate that is matched by the filter. |
| 2770 | for (auto& client_cert : client_certs) { |
| 2771 | if (issuer_pattern.Matches(client_cert->certificate()->issuer()) && |
| 2772 | subject_pattern.Matches(client_cert->certificate()->subject())) { |
| 2773 | return std::move(client_cert); |
| 2774 | } |
| 2775 | } |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | return nullptr; |
| 2779 | } |
| 2780 | |
Julie Jeongeun Kim | aaf568f | 2019-09-20 03:33:18 | [diff] [blame] | 2781 | void AddDataReductionProxyReceiver( |
Clark DuVall | 812e07d | 2019-08-26 18:34:56 | [diff] [blame] | 2782 | int render_process_id, |
Julie Jeongeun Kim | aaf568f | 2019-09-20 03:33:18 | [diff] [blame] | 2783 | mojo::PendingReceiver<data_reduction_proxy::mojom::DataReductionProxy> |
| 2784 | receiver) { |
Clark DuVall | 0e90172 | 2019-08-14 23:31:37 | [diff] [blame] | 2785 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Clark DuVall | 812e07d | 2019-08-26 18:34:56 | [diff] [blame] | 2786 | auto* rph = content::RenderProcessHost::FromID(render_process_id); |
| 2787 | if (!rph) |
| 2788 | return; |
| 2789 | |
Clark DuVall | 0e90172 | 2019-08-14 23:31:37 | [diff] [blame] | 2790 | auto* drp_settings = |
| 2791 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
Clark DuVall | 812e07d | 2019-08-26 18:34:56 | [diff] [blame] | 2792 | rph->GetBrowserContext()); |
Clark DuVall | 0e90172 | 2019-08-14 23:31:37 | [diff] [blame] | 2793 | if (!drp_settings) |
| 2794 | return; |
| 2795 | |
Julie Jeongeun Kim | aaf568f | 2019-09-20 03:33:18 | [diff] [blame] | 2796 | drp_settings->data_reduction_proxy_service()->Clone(std::move(receiver)); |
Eric Roman | a00cf68 | 2018-11-01 20:09:11 | [diff] [blame] | 2797 | } |
| 2798 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2799 | } // namespace |
| 2800 | |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2801 | base::OnceClosure ChromeContentBrowserClient::SelectClientCertificate( |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2802 | content::WebContents* web_contents, |
[email protected] | 7a593db | 2012-02-13 21:19:40 | [diff] [blame] | 2803 | net::SSLCertRequestInfo* cert_request_info, |
mattm | 436ccfe | 2017-06-19 20:24:08 | [diff] [blame] | 2804 | net::ClientCertIdentityList client_certs, |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 2805 | std::unique_ptr<content::ClientCertificateDelegate> delegate) { |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 2806 | prerender::PrerenderContents* prerender_contents = |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2807 | prerender::PrerenderContents::FromWebContents(web_contents); |
[email protected] | 294084d | 2014-01-06 22:22:02 | [diff] [blame] | 2808 | if (prerender_contents) { |
| 2809 | prerender_contents->Destroy( |
| 2810 | prerender::FINAL_STATUS_SSL_CLIENT_CERTIFICATE_REQUESTED); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2811 | return base::OnceClosure(); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 2812 | } |
| 2813 | |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 2814 | GURL requesting_url("https://" + cert_request_info->host_and_port.ToString()); |
| 2815 | DCHECK(requesting_url.is_valid()) |
| 2816 | << "Invalid URL string: https://" |
| 2817 | << cert_request_info->host_and_port.ToString(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 2818 | |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2819 | bool may_show_cert_selection = true; |
| 2820 | |
davidben | 3b8455ae7 | 2015-03-11 19:42:19 | [diff] [blame] | 2821 | Profile* profile = |
| 2822 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2823 | #if defined(OS_CHROMEOS) |
| 2824 | if (chromeos::ProfileHelper::IsSigninProfile(profile)) { |
| 2825 | // TODO(pmarko): crbug.com/723849: Set |may_show_cert_selection| to false |
| 2826 | // and remove the command-line flag after prototype phase when the |
| 2827 | // DeviceLoginScreenAutoSelectCertificateForUrls policy is live. |
| 2828 | may_show_cert_selection = |
| 2829 | chromeos::switches::IsSigninFrameClientCertUserSelectionEnabled(); |
| 2830 | |
| 2831 | content::StoragePartition* storage_partition = |
| 2832 | content::BrowserContext::GetStoragePartition( |
| 2833 | profile, web_contents->GetSiteInstance()); |
| 2834 | chromeos::login::SigninPartitionManager* signin_partition_manager = |
| 2835 | chromeos::login::SigninPartitionManager::Factory::GetForBrowserContext( |
| 2836 | profile); |
| 2837 | |
| 2838 | // On the sign-in profile, only allow client certs in the context of the |
| 2839 | // sign-in frame. |
| 2840 | if (!signin_partition_manager->IsCurrentSigninStoragePartition( |
| 2841 | storage_partition)) { |
| 2842 | LOG(WARNING) |
| 2843 | << "Client cert requested in sign-in profile in wrong context."; |
| 2844 | // Continue without client certificate. We do this to mimic the case of no |
| 2845 | // client certificate being present in the profile's certificate store. |
| 2846 | delegate->ContinueWithCertificate(nullptr, nullptr); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2847 | return base::OnceClosure(); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2848 | } |
| 2849 | VLOG(1) << "Client cert requested in sign-in profile."; |
| 2850 | } |
| 2851 | #endif // defined(OS_CHROMEOS) |
| 2852 | |
Alexander Hendrich | bcf2616e | 2018-05-18 08:21:10 | [diff] [blame] | 2853 | std::unique_ptr<net::ClientCertIdentity> auto_selected_identity = |
| 2854 | AutoSelectCertificate(profile, requesting_url, client_certs); |
| 2855 | if (auto_selected_identity) { |
| 2856 | // The callback will own |auto_selected_identity| and |delegate|, keeping |
| 2857 | // them alive until after ContinueWithCertificate is called. |
| 2858 | scoped_refptr<net::X509Certificate> cert = |
| 2859 | auto_selected_identity->certificate(); |
| 2860 | net::ClientCertIdentity::SelfOwningAcquirePrivateKey( |
| 2861 | std::move(auto_selected_identity), |
David Benjamin | 0cda204 | 2019-04-08 23:00:58 | [diff] [blame] | 2862 | base::BindOnce( |
| 2863 | &content::ClientCertificateDelegate::ContinueWithCertificate, |
| 2864 | std::move(delegate), std::move(cert))); |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 2865 | LogClientAuthResult(ClientCertSelectionResult::kAutoSelect); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2866 | return base::OnceClosure(); |
[email protected] | 6786bf40 | 2011-12-03 15:19:45 | [diff] [blame] | 2867 | } |
| 2868 | |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2869 | if (!may_show_cert_selection) { |
| 2870 | LOG(WARNING) << "No client cert matched by policy and user selection is " |
| 2871 | "not allowed."; |
Joe DeBlasio | 9b99629 | 2019-01-31 05:09:32 | [diff] [blame] | 2872 | LogClientAuthResult(ClientCertSelectionResult::kNoSelectionAllowed); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2873 | // Continue without client certificate. We do this to mimic the case of no |
| 2874 | // client certificate being present in the profile's certificate store. |
| 2875 | delegate->ContinueWithCertificate(nullptr, nullptr); |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2876 | return base::OnceClosure(); |
Pavol Marko | 230ea2c9 | 2017-12-03 22:35:44 | [diff] [blame] | 2877 | } |
| 2878 | |
Daniel McArdle | 85735f5 | 2019-06-25 03:27:06 | [diff] [blame] | 2879 | return chrome::ShowSSLClientCertificateSelector( |
| 2880 | web_contents, cert_request_info, std::move(client_certs), |
| 2881 | std::move(delegate)); |
[email protected] | 8ec2647 | 2011-06-06 16:52:45 | [diff] [blame] | 2882 | } |
| 2883 | |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 2884 | content::MediaObserver* ChromeContentBrowserClient::GetMediaObserver() { |
[email protected] | 11158e2d | 2013-02-01 02:31:56 | [diff] [blame] | 2885 | return MediaCaptureDevicesDispatcher::GetInstance(); |
[email protected] | dc73a7b | 2012-03-25 15:27:18 | [diff] [blame] | 2886 | } |
| 2887 | |
peter | c26c6c6 | 2014-12-10 14:13:59 | [diff] [blame] | 2888 | content::PlatformNotificationService* |
Richard Knoll | d0eae96 | 2019-04-04 12:34:02 | [diff] [blame] | 2889 | ChromeContentBrowserClient::GetPlatformNotificationService( |
| 2890 | content::BrowserContext* browser_context) { |
| 2891 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2892 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 2893 | return PlatformNotificationServiceFactory::GetForProfile(profile); |
[email protected] | 941623e | 2011-06-07 23:06:04 | [diff] [blame] | 2894 | } |
| 2895 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2896 | bool ChromeContentBrowserClient::CanCreateWindow( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2897 | RenderFrameHost* opener, |
[email protected] | 2b751a1 | 2012-03-06 03:00:35 | [diff] [blame] | 2898 | const GURL& opener_url, |
[email protected] | 931bc92 | 2013-09-11 21:42:57 | [diff] [blame] | 2899 | const GURL& opener_top_level_frame_url, |
Nasko Oskov | e9f1978 | 2019-01-04 18:32:35 | [diff] [blame] | 2900 | const url::Origin& source_origin, |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 2901 | content::mojom::WindowContainerType container_type, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2902 | const GURL& target_url, |
| 2903 | const content::Referrer& referrer, |
jochen | 67b271b | 2016-08-03 13:50:21 | [diff] [blame] | 2904 | const std::string& frame_name, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2905 | WindowOpenDisposition disposition, |
scottmg | 8e6c608 | 2017-02-13 23:15:48 | [diff] [blame] | 2906 | const blink::mojom::WindowFeatures& features, |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2907 | bool user_gesture, |
| 2908 | bool opener_suppressed, |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2909 | bool* no_javascript_access) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2910 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2911 | DCHECK(opener); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2912 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2913 | content::WebContents* web_contents = |
| 2914 | content::WebContents::FromRenderFrameHost(opener); |
| 2915 | Profile* profile = |
| 2916 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 2917 | DCHECK(profile); |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2918 | *no_javascript_access = false; |
| 2919 | |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2920 | // If the opener is trying to create a background window but doesn't have |
| 2921 | // the appropriate permission, fail the attempt. |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 2922 | if (container_type == content::mojom::WindowContainerType::BACKGROUND) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2923 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2924 | auto* process_map = extensions::ProcessMap::Get(profile); |
| 2925 | auto* registry = extensions::ExtensionRegistry::Get(profile); |
Charles Harrison | 34f6786 | 2017-08-22 01:04:17 | [diff] [blame] | 2926 | if (!URLHasExtensionBackgroundPermission(process_map, registry, opener_url, |
| 2927 | opener->GetProcess()->GetID())) { |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2928 | return false; |
| 2929 | } |
| 2930 | |
[email protected] | 7b54ca0 | 2012-03-02 18:06:53 | [diff] [blame] | 2931 | // Note: this use of GetExtensionOrAppByURL is safe but imperfect. It may |
| 2932 | // return a recently installed Extension even if this CanCreateWindow call |
| 2933 | // 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] | 2934 | // because the permission check above would have caused an early return |
| 2935 | // already. We must use the full URL to find hosted apps, though, and not |
| 2936 | // just the origin. |
[email protected] | be9915fb | 2013-07-18 09:28:55 | [diff] [blame] | 2937 | const Extension* extension = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2938 | registry->enabled_extensions().GetExtensionOrAppByURL(opener_url); |
[email protected] | 9367eabc | 2013-03-01 01:29:29 | [diff] [blame] | 2939 | if (extension && !extensions::BackgroundInfo::AllowJSAccess(extension)) |
[email protected] | 03b6d55 | 2012-03-29 04:03:01 | [diff] [blame] | 2940 | *no_javascript_access = true; |
[email protected] | dffb9fc | 2014-07-16 04:14:02 | [diff] [blame] | 2941 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2942 | |
| 2943 | return true; |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2944 | } |
[email protected] | 056efdc | 2013-04-06 00:14:53 | [diff] [blame] | 2945 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 2946 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 2947 | if (extensions::WebViewRendererState::GetInstance()->IsGuest( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2948 | opener->GetProcess()->GetID())) { |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2949 | return true; |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 2950 | } |
| 2951 | |
nick | 0fbc392 | 2016-12-16 20:52:07 | [diff] [blame] | 2952 | if (target_url.SchemeIs(extensions::kExtensionScheme)) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2953 | // Intentionally duplicating |registry| code from above because we want to |
| 2954 | // reduce calls to retrieve them as this function is a SYNC IPC handler. |
| 2955 | auto* registry = extensions::ExtensionRegistry::Get(profile); |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 2956 | const Extension* extension = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2957 | registry->enabled_extensions().GetExtensionOrAppByURL(target_url); |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 2958 | if (extension && extension->is_platform_app()) { |
nick | b6ae0bd3 | 2017-04-18 20:53:53 | [diff] [blame] | 2959 | UMA_HISTOGRAM_ENUMERATION( |
| 2960 | "Extensions.AppLoadedInTab", |
| 2961 | ClassifyAppLoadedInTabSource(opener_url, extension), |
| 2962 | APP_LOADED_IN_TAB_SOURCE_MAX); |
| 2963 | |
| 2964 | // window.open() may not be used to load v2 apps in a regular tab. |
lazyboy | 39585ed | 2016-12-06 19:30:16 | [diff] [blame] | 2965 | return false; |
lazyboy | 5d5fede0 | 2016-03-10 04:10:14 | [diff] [blame] | 2966 | } |
lazyboy | 04b75d3 | 2016-02-25 03:12:18 | [diff] [blame] | 2967 | } |
[email protected] | 5940b0d | 2014-07-01 00:18:26 | [diff] [blame] | 2968 | #endif |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2969 | |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 2970 | #if BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | 190e5e2 | 2013-07-27 05:59:23 | [diff] [blame] | 2971 | HostContentSettingsMap* content_settings = |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2972 | HostContentSettingsMapFactory::GetForProfile(profile); |
tommycli | 61f6f0c | 2016-09-21 00:26:58 | [diff] [blame] | 2973 | if (FlashDownloadInterception::ShouldStopFlashDownloadAction( |
| 2974 | content_settings, opener_top_level_frame_url, target_url, |
| 2975 | user_gesture)) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2976 | FlashDownloadInterception::InterceptFlashDownloadNavigation( |
| 2977 | web_contents, opener_top_level_frame_url); |
tommycli | 61f6f0c | 2016-09-21 00:26:58 | [diff] [blame] | 2978 | return false; |
| 2979 | } |
| 2980 | #endif |
| 2981 | |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 2982 | // Don't let prerenders open popups. |
| 2983 | if (auto* prerender_contents = |
| 2984 | prerender::PrerenderContents::FromWebContents(web_contents)) { |
| 2985 | prerender_contents->Destroy(prerender::FINAL_STATUS_CREATE_NEW_WINDOW); |
| 2986 | return false; |
| 2987 | } |
| 2988 | |
Nasko Oskov | e9f1978 | 2019-01-04 18:32:35 | [diff] [blame] | 2989 | BlockedWindowParams blocked_params(target_url, source_origin, referrer, |
| 2990 | frame_name, disposition, features, |
| 2991 | user_gesture, opener_suppressed); |
cm.sanchi | 2522bc9 | 2017-12-04 08:04:13 | [diff] [blame] | 2992 | NavigateParams nav_params = blocked_params.CreateNavigateParams(web_contents); |
Charlie Harrison | 804659a | 2018-10-16 16:43:38 | [diff] [blame] | 2993 | if (MaybeBlockPopup(web_contents, opener_top_level_frame_url, &nav_params, |
| 2994 | nullptr /*=open_url_params*/, |
| 2995 | blocked_params.features())) { |
Charles Harrison | af2acd0 | 2017-08-18 22:46:02 | [diff] [blame] | 2996 | return false; |
[email protected] | 916615b | 2013-09-11 18:19:44 | [diff] [blame] | 2997 | } |
[email protected] | 9f3fba5 | 2011-06-08 20:37:19 | [diff] [blame] | 2998 | return true; |
| 2999 | } |
| 3000 | |
[email protected] | c52b289 | 2012-03-07 11:01:02 | [diff] [blame] | 3001 | content::SpeechRecognitionManagerDelegate* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3002 | ChromeContentBrowserClient::CreateSpeechRecognitionManagerDelegate() { |
[email protected] | 855e18b | 2013-07-08 21:02:00 | [diff] [blame] | 3003 | return new speech::ChromeSpeechRecognitionManagerDelegate(); |
[email protected] | 66cfec6 | 2012-02-24 17:57:51 | [diff] [blame] | 3004 | } |
| 3005 | |
Katie D | 840d953 | 2018-11-27 06:20:48 | [diff] [blame] | 3006 | content::TtsControllerDelegate* |
| 3007 | ChromeContentBrowserClient::GetTtsControllerDelegate() { |
| 3008 | TtsControllerDelegateImpl* delegate = |
| 3009 | TtsControllerDelegateImpl::GetInstance(); |
| 3010 | #if !defined(OS_ANDROID) |
| 3011 | TtsExtensionEngine* tts_extension_engine = TtsExtensionEngine::GetInstance(); |
| 3012 | delegate->SetTtsEngineDelegate(tts_extension_engine); |
| 3013 | #endif |
| 3014 | return delegate; |
| 3015 | } |
| 3016 | |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 3017 | content::TtsPlatform* ChromeContentBrowserClient::GetTtsPlatform() { |
| 3018 | #ifdef OS_CHROMEOS |
| 3019 | return TtsPlatformImplChromeOs::GetInstance(); |
Katie D | 4713ee4 | 2018-11-30 01:48:27 | [diff] [blame] | 3020 | #else |
| 3021 | return nullptr; |
| 3022 | #endif |
| 3023 | } |
| 3024 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3025 | void ChromeContentBrowserClient::OverrideWebkitPrefs( |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3026 | RenderViewHost* rvh, |
| 3027 | WebPreferences* web_prefs) { |
| 3028 | Profile* profile = |
| 3029 | Profile::FromBrowserContext(rvh->GetProcess()->GetBrowserContext()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3030 | PrefService* prefs = profile->GetPrefs(); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3031 | |
aelias | 0df335a | 2017-03-02 23:43:51 | [diff] [blame] | 3032 | // Fill font preferences. These are not registered on Android |
| 3033 | // - http://crbug.com/308033, http://crbug.com/696364. |
[email protected] | 33b7954 | 2013-10-18 11:18:45 | [diff] [blame] | 3034 | #if !defined(OS_ANDROID) |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3035 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3036 | prefs::kWebKitStandardFontFamilyMap, |
| 3037 | &web_prefs->standard_font_family_map); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3038 | FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitFixedFontFamilyMap, |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3039 | &web_prefs->fixed_font_family_map); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3040 | FontFamilyCache::FillFontFamilyMap(profile, prefs::kWebKitSerifFontFamilyMap, |
[email protected] | 354de9e | 2014-08-07 03:27:19 | [diff] [blame] | 3041 | &web_prefs->serif_font_family_map); |
| 3042 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3043 | prefs::kWebKitSansSerifFontFamilyMap, |
| 3044 | &web_prefs->sans_serif_font_family_map); |
| 3045 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3046 | prefs::kWebKitCursiveFontFamilyMap, |
| 3047 | &web_prefs->cursive_font_family_map); |
| 3048 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3049 | prefs::kWebKitFantasyFontFamilyMap, |
| 3050 | &web_prefs->fantasy_font_family_map); |
| 3051 | FontFamilyCache::FillFontFamilyMap(profile, |
| 3052 | prefs::kWebKitPictographFontFamilyMap, |
| 3053 | &web_prefs->pictograph_font_family_map); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3054 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3055 | web_prefs->default_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3056 | prefs->GetInteger(prefs::kWebKitDefaultFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3057 | web_prefs->default_fixed_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3058 | prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3059 | web_prefs->minimum_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3060 | prefs->GetInteger(prefs::kWebKitMinimumFontSize); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3061 | web_prefs->minimum_logical_font_size = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3062 | prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize); |
aelias | 0df335a | 2017-03-02 23:43:51 | [diff] [blame] | 3063 | #endif |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3064 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3065 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3066 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3067 | web_prefs->dom_paste_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3068 | prefs->GetBoolean(prefs::kWebKitDomPasteEnabled); |
Joel Hockey | 08a6c84c | 2018-04-11 10:09:21 | [diff] [blame] | 3069 | web_prefs->javascript_can_access_clipboard = |
| 3070 | prefs->GetBoolean(prefs::kWebKitJavascriptCanAccessClipboard); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3071 | web_prefs->tabs_to_links = prefs->GetBoolean(prefs::kWebkitTabsToLinks); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3072 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3073 | if (!prefs->GetBoolean(prefs::kWebKitJavascriptEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3074 | web_prefs->javascript_enabled = false; |
mkwst | a1f7749b | 2015-12-28 09:28:57 | [diff] [blame] | 3075 | |
Avi Drissman | 1aa6cb9 | 2019-01-23 15:58:38 | [diff] [blame] | 3076 | if (!prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3077 | web_prefs->web_security_enabled = false; |
mkwst | a1f7749b | 2015-12-28 09:28:57 | [diff] [blame] | 3078 | |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3079 | if (!prefs->GetBoolean(prefs::kWebKitPluginsEnabled)) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3080 | web_prefs->plugins_enabled = false; |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3081 | web_prefs->loads_images_automatically = |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3082 | prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3083 | |
Zhenyao Mo | a3fda997 | 2017-09-16 01:34:40 | [diff] [blame] | 3084 | if (prefs->GetBoolean(prefs::kDisable3DAPIs)) { |
| 3085 | web_prefs->webgl1_enabled = false; |
| 3086 | web_prefs->webgl2_enabled = false; |
| 3087 | } |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3088 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3089 | web_prefs->allow_running_insecure_content = |
| 3090 | prefs->GetBoolean(prefs::kWebKitAllowRunningInsecureContent); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3091 | #if defined(OS_ANDROID) |
[email protected] | ded00dc | 2013-11-01 00:37:05 | [diff] [blame] | 3092 | web_prefs->font_scale_factor = |
| 3093 | static_cast<float>(prefs->GetDouble(prefs::kWebKitFontScaleFactor)); |
| 3094 | web_prefs->device_scale_adjustment = GetDeviceScaleAdjustment(); |
[email protected] | d3b935f | 2012-10-19 23:14:32 | [diff] [blame] | 3095 | web_prefs->force_enable_zoom = |
| 3096 | prefs->GetBoolean(prefs::kWebKitForceEnableZoom); |
Aran Gilman | 5e9672bed | 2019-08-02 19:07:49 | [diff] [blame] | 3097 | #endif |
Becky Zhou | bbfbde3 | 2019-02-20 17:07:59 | [diff] [blame] | 3098 | web_prefs->force_dark_mode_enabled = |
| 3099 | prefs->GetBoolean(prefs::kWebKitForceDarkModeEnabled); |
[email protected] | 5c91525 | 2013-05-07 13:15:39 | [diff] [blame] | 3100 | |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 3101 | #if defined(OS_ANDROID) |
| 3102 | web_prefs->password_echo_enabled = |
| 3103 | prefs->GetBoolean(prefs::kWebKitPasswordEchoEnabled); |
| 3104 | #else |
[email protected] | 9d06d88d | 2012-02-23 22:37:08 | [diff] [blame] | 3105 | web_prefs->password_echo_enabled = browser_defaults::kPasswordEchoEnabled; |
[email protected] | af4256d5 | 2013-06-04 20:39:07 | [diff] [blame] | 3106 | #endif |
| 3107 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3108 | web_prefs->text_areas_are_resizable = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3109 | prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3110 | web_prefs->hyperlink_auditing_enabled = |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3111 | prefs->GetBoolean(prefs::kEnableHyperlinkAuditing); |
| 3112 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3113 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
je_julie.kim | 7fbb5a1a | 2015-02-09 17:26:05 | [diff] [blame] | 3114 | std::string image_animation_policy = |
| 3115 | prefs->GetString(prefs::kAnimationPolicy); |
| 3116 | if (image_animation_policy == kAnimationPolicyOnce) |
| 3117 | web_prefs->animation_policy = |
| 3118 | content::IMAGE_ANIMATION_POLICY_ANIMATION_ONCE; |
| 3119 | else if (image_animation_policy == kAnimationPolicyNone) |
| 3120 | web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_NO_ANIMATION; |
| 3121 | else |
| 3122 | web_prefs->animation_policy = content::IMAGE_ANIMATION_POLICY_ALLOWED; |
| 3123 | #endif |
| 3124 | |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3125 | // Make sure we will set the default_encoding with canonical encoding name. |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 3126 | web_prefs->default_encoding = |
| 3127 | base::GetCanonicalEncodingNameByAliasName(web_prefs->default_encoding); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3128 | if (web_prefs->default_encoding.empty()) { |
[email protected] | ddf7214 | 2012-05-22 04:52:40 | [diff] [blame] | 3129 | prefs->ClearPref(prefs::kDefaultCharset); |
| 3130 | web_prefs->default_encoding = prefs->GetString(prefs::kDefaultCharset); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3131 | } |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 3132 | DCHECK(!web_prefs->default_encoding.empty()); |
[email protected] | f3986f8 | 2012-01-03 20:00:06 | [diff] [blame] | 3133 | |
mkwst | 0554410 | 2015-01-10 20:26:16 | [diff] [blame] | 3134 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3135 | switches::kEnablePotentiallyAnnoyingSecurityFeatures)) { |
mkwst | 772ce814 | 2015-01-16 13:28:07 | [diff] [blame] | 3136 | web_prefs->disable_reading_from_canvas = true; |
mkwst | 0554410 | 2015-01-10 20:26:16 | [diff] [blame] | 3137 | web_prefs->strict_mixed_content_checking = true; |
| 3138 | web_prefs->strict_powerful_feature_restrictions = true; |
| 3139 | } |
| 3140 | |
Robert Ogden | cf2872d | 2019-03-19 18:59:37 | [diff] [blame] | 3141 | web_prefs->data_saver_enabled = IsDataSaverEnabled(profile); |
Ben Greenstein | 49878f5 | 2015-12-18 19:13:21 | [diff] [blame] | 3142 | |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 3143 | web_prefs->data_saver_holdback_web_api_enabled = |
| 3144 | base::GetFieldTrialParamByFeatureAsBool(features::kDataSaverHoldback, |
| 3145 | "holdback_web", false); |
Tarun Bansal | 333819e | 2018-05-15 16:38:42 | [diff] [blame] | 3146 | |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3147 | auto* contents = content::WebContents::FromRenderViewHost(rvh); |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3148 | if (contents) { |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3149 | #if defined(OS_ANDROID) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3150 | auto* delegate = TabAndroid::FromWebContents(contents) |
| 3151 | ? static_cast<android::TabWebContentsDelegateAndroid*>( |
| 3152 | contents->GetDelegate()) |
| 3153 | : nullptr; |
| 3154 | if (delegate) { |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3155 | web_prefs->embedded_media_experience_enabled = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3156 | delegate->ShouldEnableEmbeddedMediaExperience(); |
shaktisahu | f97f753 | 2017-02-24 22:46:13 | [diff] [blame] | 3157 | |
Mounir Lamouri | 9c99a160 | 2018-07-05 15:01:44 | [diff] [blame] | 3158 | web_prefs->picture_in_picture_enabled = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3159 | delegate->IsPictureInPictureEnabled(); |
Rune Lillesveen | 17e4832 | 2019-04-15 23:12:38 | [diff] [blame] | 3160 | |
| 3161 | web_prefs->preferred_color_scheme = |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3162 | delegate->IsNightModeEnabled() ? blink::PreferredColorScheme::kDark |
| 3163 | : blink::PreferredColorScheme::kLight; |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3164 | } |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3165 | #endif // defined(OS_ANDROID) |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3166 | |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3167 | // web_app_scope value is platform specific. |
| 3168 | #if defined(OS_ANDROID) |
Jinsuk Kim | a3d393ce | 2019-05-27 00:57:42 | [diff] [blame] | 3169 | if (delegate) |
| 3170 | web_prefs->web_app_scope = delegate->GetManifestScope(); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3171 | #elif BUILDFLAG(ENABLE_EXTENSIONS) |
| 3172 | { |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3173 | web_prefs->web_app_scope = GURL(); |
| 3174 | // Set |web_app_scope| based on the app associated with the app window if |
| 3175 | // any. Note that the app associated with the window never changes, even |
| 3176 | // if the app navigates off scope. This is not a problem because we still |
| 3177 | // want to use the scope of the app associated with the window, not the |
| 3178 | // WebContents. |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3179 | Browser* browser = chrome::FindBrowserWithWebContents(contents); |
Alan Cutter | d0bd5190 | 2019-05-22 04:15:23 | [diff] [blame] | 3180 | if (browser && browser->app_controller() && |
Eric Willigers | e339c1e | 2019-05-13 19:22:44 | [diff] [blame] | 3181 | browser->app_controller()->CreatedForInstalledPwa()) { |
Yining Wang | 234ad327 | 2019-04-08 18:47:27 | [diff] [blame] | 3182 | // PWAs should be hosted apps. |
Eric Willigers | e339c1e | 2019-05-13 19:22:44 | [diff] [blame] | 3183 | DCHECK(browser->app_controller()->IsHostedApp()); |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3184 | // HostedApps that are PWAs are always created through WebAppProvider |
Alexey Baskakov | aca7a0c | 2019-07-29 07:34:05 | [diff] [blame] | 3185 | // for profiles that support them, so we should always be able to |
| 3186 | // retrieve a WebAppProvider from the Profile. |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3187 | // |
| 3188 | // 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] | 3189 | // so there is no need to test for has_value(). |
Giovanni Ortuño Urquidi | dcd3885 | 2019-03-07 08:08:25 | [diff] [blame] | 3190 | web_prefs->web_app_scope = |
| 3191 | web_app::WebAppProvider::Get(profile) |
| 3192 | ->registrar() |
Alan Cutter | f25cfe4 | 2019-07-16 02:40:12 | [diff] [blame] | 3193 | .GetAppScope(*browser->app_controller()->GetAppId()) |
| 3194 | .value(); |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3195 | } |
Mounir Lamouri | 6926107f | 2019-01-31 18:17:43 | [diff] [blame] | 3196 | } |
| 3197 | #endif |
| 3198 | |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3199 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 3200 | Browser* browser = chrome::FindBrowserWithWebContents(contents); |
Eric Willigers | e339c1e | 2019-05-13 19:22:44 | [diff] [blame] | 3201 | if (browser && browser->app_controller() && |
| 3202 | browser->app_controller()->CreatedForInstalledPwa()) { |
Giovanni Ortuño Urquidi | d231ca3 | 2018-05-14 04:20:53 | [diff] [blame] | 3203 | web_prefs->strict_mixed_content_checking = true; |
| 3204 | } |
| 3205 | #endif |
| 3206 | |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3207 | web_prefs->immersive_mode_enabled = vr::VrTabHelper::IsInVr(contents); |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3208 | } |
zqzhang | 93e959d1 | 2017-03-16 13:10:20 | [diff] [blame] | 3209 | |
Ian Vollick | 6243dfe0 | 2018-03-08 01:08:53 | [diff] [blame] | 3210 | #if defined(OS_ANDROID) |
Ted Choc | 81c89fc5 | 2018-06-22 23:51:14 | [diff] [blame] | 3211 | web_prefs->video_fullscreen_detection_enabled = true; |
zqzhang | 183dc82 | 2017-02-15 17:04:11 | [diff] [blame] | 3212 | #endif // defined(OS_ANDROID) |
| 3213 | |
Tarun Bansal | 73d67f0 | 2018-01-17 05:56:25 | [diff] [blame] | 3214 | if (base::FeatureList::IsEnabled(features::kLowPriorityIframes)) { |
| 3215 | // Obtain the maximum effective connection type at which the feature is |
| 3216 | // enabled. |
| 3217 | std::string effective_connection_type_param = |
| 3218 | base::GetFieldTrialParamValueByFeature( |
| 3219 | features::kLowPriorityIframes, |
| 3220 | "max_effective_connection_type_threshold"); |
| 3221 | |
| 3222 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3223 | net::GetEffectiveConnectionTypeForName(effective_connection_type_param); |
| 3224 | if (effective_connection_type) { |
| 3225 | web_prefs->low_priority_iframes_threshold = |
| 3226 | effective_connection_type.value(); |
| 3227 | } |
| 3228 | } |
| 3229 | |
rajendrant | 0521cee | 2019-07-29 06:09:26 | [diff] [blame] | 3230 | web_prefs->lazy_load_enabled = !contents || !contents->GetDelegate() || |
| 3231 | contents->GetDelegate()->ShouldAllowLazyLoad(); |
rajendrant | e87ed71 | 2018-11-30 01:55:00 | [diff] [blame] | 3232 | |
Scott Little | 878f7d670 | 2018-05-31 22:09:06 | [diff] [blame] | 3233 | if (base::FeatureList::IsEnabled(features::kLazyFrameLoading)) { |
| 3234 | const char* param_name = |
| 3235 | web_prefs->data_saver_enabled |
| 3236 | ? "lazy_frame_loading_distance_thresholds_px_by_ect" |
| 3237 | : "lazy_frame_loading_distance_thresholds_px_by_ect_with_data_" |
| 3238 | "saver_enabled"; |
| 3239 | |
| 3240 | base::StringPairs pairs; |
| 3241 | base::SplitStringIntoKeyValuePairs( |
| 3242 | base::GetFieldTrialParamValueByFeature(features::kLazyFrameLoading, |
| 3243 | param_name), |
| 3244 | ':', ',', &pairs); |
| 3245 | |
| 3246 | for (const auto& pair : pairs) { |
| 3247 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3248 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3249 | int value = 0; |
| 3250 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3251 | web_prefs->lazy_frame_loading_distance_thresholds_px |
| 3252 | [effective_connection_type.value()] = value; |
| 3253 | } |
| 3254 | } |
| 3255 | } |
| 3256 | |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 3257 | if (base::FeatureList::IsEnabled(features::kLazyImageLoading)) { |
| 3258 | const char* param_name = |
| 3259 | web_prefs->data_saver_enabled |
| 3260 | ? "lazy_image_loading_distance_thresholds_px_by_ect" |
| 3261 | : "lazy_image_loading_distance_thresholds_px_by_ect_with_data_" |
| 3262 | "saver_enabled"; |
| 3263 | |
| 3264 | base::StringPairs pairs; |
| 3265 | base::SplitStringIntoKeyValuePairs( |
| 3266 | base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading, |
| 3267 | param_name), |
| 3268 | ':', ',', &pairs); |
| 3269 | |
| 3270 | for (const auto& pair : pairs) { |
| 3271 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3272 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3273 | int value = 0; |
| 3274 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3275 | web_prefs->lazy_image_loading_distance_thresholds_px |
| 3276 | [effective_connection_type.value()] = value; |
| 3277 | } |
| 3278 | } |
rajendrant | 3daeae29 | 2019-09-20 07:57:54 | [diff] [blame^] | 3279 | |
| 3280 | pairs.clear(); |
| 3281 | base::SplitStringIntoKeyValuePairs( |
| 3282 | base::GetFieldTrialParamValueByFeature(features::kLazyImageLoading, |
| 3283 | "lazy_image_first_k_fully_load"), |
| 3284 | ':', ',', &pairs); |
| 3285 | |
| 3286 | for (const auto& pair : pairs) { |
| 3287 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3288 | net::GetEffectiveConnectionTypeForName(pair.first); |
| 3289 | int value = 0; |
| 3290 | if (effective_connection_type && base::StringToInt(pair.second, &value)) { |
| 3291 | web_prefs |
| 3292 | ->lazy_image_first_k_fully_load[effective_connection_type.value()] = |
| 3293 | value; |
| 3294 | } |
| 3295 | } |
rajendrant | d802634 | 2018-08-29 08:08:39 | [diff] [blame] | 3296 | } |
| 3297 | |
Tarun Bansal | d10f17a0 | 2018-09-13 00:23:17 | [diff] [blame] | 3298 | if (base::FeatureList::IsEnabled( |
| 3299 | features::kNetworkQualityEstimatorWebHoldback)) { |
| 3300 | std::string effective_connection_type_param = |
| 3301 | base::GetFieldTrialParamValueByFeature( |
| 3302 | features::kNetworkQualityEstimatorWebHoldback, |
| 3303 | "web_effective_connection_type_override"); |
| 3304 | |
| 3305 | base::Optional<net::EffectiveConnectionType> effective_connection_type = |
| 3306 | net::GetEffectiveConnectionTypeForName(effective_connection_type_param); |
| 3307 | DCHECK(effective_connection_type_param.empty() || |
| 3308 | effective_connection_type); |
| 3309 | if (effective_connection_type) { |
| 3310 | DCHECK_NE(net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN, |
| 3311 | effective_connection_type.value()); |
| 3312 | web_prefs->network_quality_estimator_web_holdback = |
| 3313 | effective_connection_type.value(); |
| 3314 | } |
| 3315 | } |
| 3316 | |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 3317 | auto* native_theme = GetWebTheme(); |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3318 | #if !defined(OS_ANDROID) |
Becca Hughes | fe8c32c | 2018-03-21 13:36:56 | [diff] [blame] | 3319 | if (IsAutoplayAllowedByPolicy(contents, prefs)) { |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3320 | // If autoplay is allowed by policy then force the no user gesture required |
| 3321 | // autoplay policy. |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3322 | web_prefs->autoplay_policy = |
| 3323 | content::AutoplayPolicy::kNoUserGestureRequired; |
Mounir Lamouri | c2186808 | 2018-10-11 21:09:55 | [diff] [blame] | 3324 | } else if (base::FeatureList::IsEnabled(media::kAutoplayDisableSettings) && |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3325 | web_prefs->autoplay_policy == |
| 3326 | content::AutoplayPolicy::kDocumentUserActivationRequired) { |
Mounir Lamouri | c2186808 | 2018-10-11 21:09:55 | [diff] [blame] | 3327 | // If the autoplay disable settings feature is enabled and the autoplay |
| 3328 | // policy is set to using the unified policy then set the default autoplay |
| 3329 | // policy based on user preference. |
Becca Hughes | 7d2bbb8 | 2018-08-07 22:56:59 | [diff] [blame] | 3330 | web_prefs->autoplay_policy = |
| 3331 | UnifiedAutoplayConfig::ShouldBlockAutoplay(profile) |
| 3332 | ? content::AutoplayPolicy::kDocumentUserActivationRequired |
| 3333 | : content::AutoplayPolicy::kNoUserGestureRequired; |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3334 | } |
Alison Maher | 67fd4d9f | 2019-07-12 18:34:21 | [diff] [blame] | 3335 | #if !defined(OS_MACOSX) |
| 3336 | // 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] | 3337 | web_prefs->forced_colors = native_theme->UsesHighContrastColors() |
| 3338 | ? blink::ForcedColors::kActive |
| 3339 | : blink::ForcedColors::kNone; |
Alison Maher | 67fd4d9f | 2019-07-12 18:34:21 | [diff] [blame] | 3340 | #endif // !defined(OS_MACOSX) |
| 3341 | |
| 3342 | switch (native_theme->GetPreferredColorScheme()) { |
| 3343 | case ui::NativeTheme::PreferredColorScheme::kDark: |
| 3344 | web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kDark; |
| 3345 | break; |
| 3346 | case ui::NativeTheme::PreferredColorScheme::kLight: |
| 3347 | web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight; |
| 3348 | break; |
| 3349 | case ui::NativeTheme::PreferredColorScheme::kNoPreference: |
| 3350 | web_prefs->preferred_color_scheme = |
| 3351 | blink::PreferredColorScheme::kNoPreference; |
| 3352 | } |
François Beaufort | 4f8107d | 2018-03-05 12:12:10 | [diff] [blame] | 3353 | #endif // !defined(OS_ANDROID) |
| 3354 | |
Dave Tapuska | c6627e1 | 2018-08-30 15:07:19 | [diff] [blame] | 3355 | web_prefs->translate_service_available = TranslateService::IsAvailable(prefs); |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3356 | |
Dan Beam | 836c02a | 2019-06-15 01:58:27 | [diff] [blame] | 3357 | // Force a light preferred color scheme on certain URLs if kWebUIDarkMode is |
| 3358 | // disabled; some of the UI is not yet correctly themed. Note: the WebUI CSS |
| 3359 | // explicitly uses light (instead of not dark), which is why we don't reset |
| 3360 | // back to no-preference. https://crbug.com/965811 |
| 3361 | if (contents && !base::FeatureList::IsEnabled(features::kWebUIDarkMode)) { |
| 3362 | bool force_light = contents->GetURL().SchemeIs(content::kChromeUIScheme); |
| 3363 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 3364 | if (!force_light) { |
| 3365 | force_light = |
| 3366 | contents->GetURL().SchemeIs(extensions::kExtensionScheme) && |
| 3367 | contents->GetURL().host_piece() == extension_misc::kPdfExtensionId; |
| 3368 | } |
| 3369 | #endif |
| 3370 | if (force_light) |
| 3371 | web_prefs->preferred_color_scheme = blink::PreferredColorScheme::kLight; |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 3372 | } |
| 3373 | |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3374 | // Apply native CaptionStyle parameters. |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3375 | base::Optional<ui::CaptionStyle> style; |
| 3376 | |
| 3377 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3378 | ::switches::kForceCaptionStyle)) { |
| 3379 | style = ui::CaptionStyle::FromSpec( |
| 3380 | base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 3381 | switches::kForceCaptionStyle)); |
| 3382 | } |
| 3383 | |
| 3384 | // Apply system caption style. |
| 3385 | if (!style) { |
| 3386 | style = native_theme->GetSystemCaptionStyle(); |
| 3387 | } |
| 3388 | |
| 3389 | // Apply caption style from preferences if system caption style is undefined. |
| 3390 | if (!style && base::FeatureList::IsEnabled(features::kCaptionSettings)) { |
evliu | bc2aa047 | 2019-08-09 20:19:19 | [diff] [blame] | 3391 | style = pref_names_util::GetCaptionStyleFromPrefs(prefs); |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | if (style) { |
| 3395 | web_prefs->text_track_background_color = style->background_color; |
| 3396 | web_prefs->text_track_text_color = style->text_color; |
| 3397 | web_prefs->text_track_text_size = style->text_size; |
| 3398 | web_prefs->text_track_text_shadow = style->text_shadow; |
| 3399 | web_prefs->text_track_font_family = style->font_family; |
| 3400 | web_prefs->text_track_font_variant = style->font_variant; |
Abigail Klein | 74de85bd | 2019-07-11 19:11:56 | [diff] [blame] | 3401 | web_prefs->text_track_window_color = style->window_color; |
| 3402 | web_prefs->text_track_window_padding = style->window_padding; |
| 3403 | web_prefs->text_track_window_radius = style->window_radius; |
Evan Liu | 7cdbf887 | 2019-06-19 16:47:21 | [diff] [blame] | 3404 | } |
Elly Fong-Jones | f9289739 | 2019-01-24 16:05:49 | [diff] [blame] | 3405 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3406 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
creis | 7b2d3d1 | 2015-02-12 23:29:50 | [diff] [blame] | 3407 | extra_parts_[i]->OverrideWebkitPrefs(rvh, web_prefs); |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 3408 | } |
| 3409 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3410 | void ChromeContentBrowserClient::BrowserURLHandlerCreated( |
| 3411 | BrowserURLHandler* handler) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3412 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 3413 | extra_parts_[i]->BrowserURLHandlerCreated(handler); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3414 | |
[email protected] | b3adbd0 | 2011-11-30 22:23:27 | [diff] [blame] | 3415 | // about: handler. Must come before chrome: handler, since it will |
| 3416 | // rewrite about: urls to chrome: URLs and then expect chrome: to |
creis | 94a977f6 | 2015-02-18 23:51:05 | [diff] [blame] | 3417 | // actually handle them. Also relies on a preliminary fixup phase. |
| 3418 | handler->SetFixupHandler(&FixupBrowserAboutURL); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3419 | handler->AddHandlerPair(&WillHandleBrowserAboutURL, |
| 3420 | BrowserURLHandler::null_handler()); |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3421 | |
mad | fbd1085 | 2017-01-20 03:15:33 | [diff] [blame] | 3422 | // The group policy NTP URL handler must be registered before the other NTP |
| 3423 | // URL handlers below. |
| 3424 | handler->AddHandlerPair(&HandleNewTabPageLocationOverride, |
| 3425 | BrowserURLHandler::null_handler()); |
| 3426 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 3427 | #if defined(OS_ANDROID) |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3428 | // Handler to rewrite chrome://newtab on Android. |
ianwen | 465e17b | 2015-01-20 18:32:35 | [diff] [blame] | 3429 | handler->AddHandlerPair(&chrome::android::HandleAndroidNativePageURL, |
[email protected] | 4bd78e9 | 2014-03-28 18:54:03 | [diff] [blame] | 3430 | BrowserURLHandler::null_handler()); |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 3431 | #if BUILDFLAG(DFMIFY_DEV_UI) |
| 3432 | // Handler to rewrite chrome:// URLs in the DevUI DFM, if not installed. |
| 3433 | handler->AddHandlerPair(&chrome::android::HandleDfmifiedDevUiPageURL, |
| 3434 | BrowserURLHandler::null_handler()); |
| 3435 | #endif // BUILDFLAG(DFMIFY_DEV_UI) |
| 3436 | |
| 3437 | #else // defined(OS_ANDROID) |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3438 | // Handler to rewrite chrome://newtab for InstantExtended. |
sdefresne | 51bbec7b | 2015-08-03 14:18:13 | [diff] [blame] | 3439 | handler->AddHandlerPair(&search::HandleNewTabURLRewrite, |
| 3440 | &search::HandleNewTabURLReverseRewrite); |
Samuel Huang | e63048d | 2019-09-03 20:35:45 | [diff] [blame] | 3441 | #endif // defined(OS_ANDROID) |
[email protected] | 231dba2 | 2013-07-25 23:53:03 | [diff] [blame] | 3442 | |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3443 | // chrome: & friends. |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 3444 | handler->AddHandlerPair(&ChromeContentBrowserClient::HandleWebUI, |
| 3445 | &ChromeContentBrowserClient::HandleWebUIReverse); |
Robert Ogden | e7fdca9 | 2018-10-12 17:53:06 | [diff] [blame] | 3446 | |
| 3447 | // Handler to rewrite Preview's Server Lite Page, to show the original URL to |
| 3448 | // the user. |
| 3449 | handler->AddHandlerPair(&HandlePreviewsLitePageURLRewrite, |
| 3450 | &HandlePreviewsLitePageURLRewriteReverse); |
[email protected] | b8148ac | 2011-07-13 22:03:25 | [diff] [blame] | 3451 | } |
| 3452 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 3453 | base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() { |
[email protected] | b1d9727 | 2013-08-17 13:38:49 | [diff] [blame] | 3454 | return DownloadPrefs::GetDefaultDownloadDirectory(); |
[email protected] | e1d16eb9 | 2011-08-18 23:19:32 | [diff] [blame] | 3455 | } |
| 3456 | |
[email protected] | c9b6eb6 | 2011-10-18 20:49:39 | [diff] [blame] | 3457 | std::string ChromeContentBrowserClient::GetDefaultDownloadName() { |
| 3458 | return l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME); |
| 3459 | } |
| 3460 | |
Dominik Röttsches | 4734783 | 2019-03-12 17:45:01 | [diff] [blame] | 3461 | base::FilePath ChromeContentBrowserClient::GetFontLookupTableCacheDir() { |
| 3462 | base::FilePath user_data_dir; |
| 3463 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 3464 | DCHECK(!user_data_dir.empty()); |
| 3465 | return user_data_dir.Append(FILE_PATH_LITERAL("FontLookupTableCache")); |
| 3466 | } |
| 3467 | |
jmadill | 57b52d4 | 2015-08-21 18:16:13 | [diff] [blame] | 3468 | base::FilePath ChromeContentBrowserClient::GetShaderDiskCacheDirectory() { |
| 3469 | base::FilePath user_data_dir; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 3470 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
jmadill | 57b52d4 | 2015-08-21 18:16:13 | [diff] [blame] | 3471 | DCHECK(!user_data_dir.empty()); |
| 3472 | return user_data_dir.Append(FILE_PATH_LITERAL("ShaderCache")); |
| 3473 | } |
| 3474 | |
Khushal | 7ca0b78 | 2018-07-20 05:53:27 | [diff] [blame] | 3475 | base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() { |
| 3476 | base::FilePath user_data_dir; |
| 3477 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 3478 | DCHECK(!user_data_dir.empty()); |
| 3479 | return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache")); |
| 3480 | } |
| 3481 | |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 3482 | void ChromeContentBrowserClient::DidCreatePpapiPlugin( |
| 3483 | content::BrowserPpapiHost* browser_host) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3484 | #if BUILDFLAG(ENABLE_PLUGINS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 3485 | ChromeContentBrowserClientPluginsPart::DidCreatePpapiPlugin(browser_host); |
[email protected] | 6d17f639 | 2012-12-05 05:24:54 | [diff] [blame] | 3486 | #endif |
[email protected] | b7631cc | 2012-09-15 05:08:38 | [diff] [blame] | 3487 | } |
| 3488 | |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3489 | content::BrowserPpapiHost* |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3490 | ChromeContentBrowserClient::GetExternalBrowserPpapiHost(int plugin_process_id) { |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 3491 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 3492 | content::BrowserChildProcessHostIterator iter(PROCESS_TYPE_NACL_LOADER); |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3493 | while (!iter.Done()) { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3494 | nacl::NaClProcessHost* host = |
| 3495 | static_cast<nacl::NaClProcessHost*>(iter.GetDelegate()); |
| 3496 | if (host->process() && host->process()->GetData().id == plugin_process_id) { |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3497 | // Found the plugin. |
| 3498 | return host->browser_ppapi_host(); |
| 3499 | } |
| 3500 | ++iter; |
| 3501 | } |
[email protected] | a56f832 | 2014-07-16 21:13:55 | [diff] [blame] | 3502 | #endif |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3503 | return nullptr; |
[email protected] | 0c719374 | 2012-11-07 19:05:03 | [diff] [blame] | 3504 | } |
| 3505 | |
[email protected] | 38cd8f7f | 2012-06-15 22:06:07 | [diff] [blame] | 3506 | bool ChromeContentBrowserClient::AllowPepperSocketAPI( |
[email protected] | 157cc90 | 2012-11-02 06:31:58 | [diff] [blame] | 3507 | content::BrowserContext* browser_context, |
| 3508 | const GURL& url, |
[email protected] | dda5482 | 2013-06-15 01:26:39 | [diff] [blame] | 3509 | bool private_api, |
[email protected] | 8b92ed18 | 2013-09-21 04:47:12 | [diff] [blame] | 3510 | const content::SocketPermissionRequest* params) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3511 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 3512 | return ChromeContentBrowserClientPluginsPart::AllowPepperSocketAPI( |
| 3513 | browser_context, url, private_api, params, allowed_socket_origins_); |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 3514 | #else |
[email protected] | a658d45 | 2012-03-02 12:45:29 | [diff] [blame] | 3515 | return false; |
[email protected] | 93f7206 | 2013-05-29 20:29:40 | [diff] [blame] | 3516 | #endif |
[email protected] | e461da2f | 2012-02-16 19:06:40 | [diff] [blame] | 3517 | } |
| 3518 | |
adrian.belgun | d54465ba | 2016-05-18 10:03:58 | [diff] [blame] | 3519 | bool ChromeContentBrowserClient::IsPepperVpnProviderAPIAllowed( |
| 3520 | content::BrowserContext* browser_context, |
| 3521 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 3522 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
adrian.belgun | d54465ba | 2016-05-18 10:03:58 | [diff] [blame] | 3523 | return ChromeContentBrowserClientPluginsPart::IsPepperVpnProviderAPIAllowed( |
| 3524 | browser_context, url); |
| 3525 | #else |
| 3526 | return false; |
| 3527 | #endif |
| 3528 | } |
| 3529 | |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 3530 | std::unique_ptr<content::VpnServiceProxy> |
| 3531 | ChromeContentBrowserClient::GetVpnServiceProxy( |
| 3532 | content::BrowserContext* browser_context) { |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 3533 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
adrian.belgun | 5b341c7 | 2016-06-22 22:24:08 | [diff] [blame] | 3534 | return ChromeContentBrowserClientExtensionsPart::GetVpnServiceProxy( |
| 3535 | browser_context); |
| 3536 | #else |
| 3537 | return nullptr; |
| 3538 | #endif |
| 3539 | } |
| 3540 | |
Brett Wilson | 804e83c | 2017-08-18 22:57:33 | [diff] [blame] | 3541 | std::unique_ptr<ui::SelectFilePolicy> |
| 3542 | ChromeContentBrowserClient::CreateSelectFilePolicy(WebContents* web_contents) { |
| 3543 | return std::make_unique<ChromeSelectFilePolicy>(web_contents); |
[email protected] | a28e330 | 2013-02-03 03:50:43 | [diff] [blame] | 3544 | } |
| 3545 | |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 3546 | void ChromeContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 3547 | std::vector<std::string>* additional_allowed_schemes) { |
| 3548 | ContentBrowserClient::GetAdditionalAllowedSchemesForFileSystem( |
| 3549 | additional_allowed_schemes); |
[email protected] | b3690f7 | 2014-02-17 00:32:48 | [diff] [blame] | 3550 | additional_allowed_schemes->push_back(content::kChromeDevToolsScheme); |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 3551 | additional_allowed_schemes->push_back(content::kChromeUIScheme); |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3552 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
| 3553 | extra_parts_[i]->GetAdditionalAllowedSchemesForFileSystem( |
| 3554 | additional_allowed_schemes); |
| 3555 | } |
[email protected] | 7d942470 | 2013-04-14 13:14:16 | [diff] [blame] | 3556 | } |
| 3557 | |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 3558 | void ChromeContentBrowserClient::GetSchemesBypassingSecureContextCheckWhitelist( |
| 3559 | std::set<std::string>* schemes) { |
Daniel Vogelheim | 11e59b7 | 2017-11-22 15:44:04 | [diff] [blame] | 3560 | *schemes = secure_origin_whitelist::GetSchemesBypassingSecureContextCheck(); |
falken | ad18509 | 2016-06-16 06:10:02 | [diff] [blame] | 3561 | } |
| 3562 | |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 3563 | void ChromeContentBrowserClient::GetURLRequestAutoMountHandlers( |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3564 | std::vector<storage::URLRequestAutoMountHandler>* handlers) { |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3565 | for (size_t i = 0; i < extra_parts_.size(); ++i) |
| 3566 | extra_parts_[i]->GetURLRequestAutoMountHandlers(handlers); |
[email protected] | c79859b8 | 2014-03-20 22:43:55 | [diff] [blame] | 3567 | } |
| 3568 | |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 3569 | ::rappor::RapporService* ChromeContentBrowserClient::GetRapporService() { |
| 3570 | return g_browser_process->rappor_service(); |
| 3571 | } |
| 3572 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 3573 | void ChromeContentBrowserClient::GetAdditionalFileSystemBackends( |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 3574 | content::BrowserContext* browser_context, |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 3575 | const base::FilePath& storage_partition_path, |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3576 | std::vector<std::unique_ptr<storage::FileSystemBackend>>* |
| 3577 | additional_backends) { |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3578 | #if defined(OS_CHROMEOS) |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3579 | storage::ExternalMountPoints* external_mount_points = |
[email protected] | 0ff5eb5 | 2013-07-10 20:35:31 | [diff] [blame] | 3580 | content::BrowserContext::GetMountPoints(browser_context); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3581 | DCHECK(external_mount_points); |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3582 | auto backend = std::make_unique<chromeos::FileSystemBackend>( |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3583 | std::make_unique<chromeos::file_system_provider::BackendDelegate>(), |
| 3584 | std::make_unique<chromeos::MTPFileSystemBackendDelegate>( |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 3585 | storage_partition_path), |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 3586 | std::make_unique<arc::ArcContentFileSystemBackendDelegate>(), |
| 3587 | std::make_unique<arc::ArcDocumentsProviderBackendDelegate>(), |
Sam McNally | 47f2eac | 2018-08-28 06:45:05 | [diff] [blame] | 3588 | std::make_unique<drive::DriveFsFileSystemBackendDelegate>( |
| 3589 | Profile::FromBrowserContext(browser_context)), |
hashimoto | a53e7e8 | 2016-10-26 06:30:47 | [diff] [blame] | 3590 | external_mount_points, storage::ExternalMountPoints::GetSystemInstance()); |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 3591 | backend->AddSystemMountPoints(); |
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 3592 | DCHECK(backend->CanHandleType(storage::kFileSystemTypeExternal)); |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 3593 | additional_backends->push_back(std::move(backend)); |
[email protected] | b40015c | 2013-06-26 08:13:31 | [diff] [blame] | 3594 | #endif |
[email protected] | 445b7db | 2013-08-02 04:58:27 | [diff] [blame] | 3595 | |
[email protected] | a48ab711 | 2014-08-01 16:48:03 | [diff] [blame] | 3596 | for (size_t i = 0; i < extra_parts_.size(); ++i) { |
| 3597 | extra_parts_[i]->GetAdditionalFileSystemBackends( |
| 3598 | browser_context, storage_partition_path, additional_backends); |
| 3599 | } |
[email protected] | 0225095 | 2013-04-24 23:52:53 | [diff] [blame] | 3600 | } |
| 3601 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3602 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | a1733df | 2012-06-22 11:24:18 | [diff] [blame] | 3603 | void ChromeContentBrowserClient::GetAdditionalMappedFilesForChildProcess( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 3604 | const base::CommandLine& command_line, |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3605 | int child_process_id, |
brettw | 3c98c7d3 | 2017-07-25 01:44:20 | [diff] [blame] | 3606 | PosixFileDescriptorInfo* mappings) { |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3607 | #if defined(OS_ANDROID) |
| 3608 | base::MemoryMappedFile::Region region; |
| 3609 | int fd = ui::GetMainAndroidPackFd(®ion); |
| 3610 | mappings->ShareWithRegion(kAndroidUIResourcesPakDescriptor, fd, region); |
agrieve | 05398f5 | 2015-06-24 18:59:00 | [diff] [blame] | 3611 | |
Samuel Huang | 31eadf08 | 2019-08-28 19:50:43 | [diff] [blame] | 3612 | // For Android: Native resources for DFMs should only be used by the browser |
| 3613 | // process. Their file descriptors and memory mapped file regions are not |
| 3614 | // passed to child processes. |
| 3615 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3616 | fd = ui::GetCommonResourcesPackFd(®ion); |
| 3617 | mappings->ShareWithRegion(kAndroidChrome100PercentPakDescriptor, fd, region); |
[email protected] | 29699c2 | 2012-10-03 23:57:39 | [diff] [blame] | 3618 | |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3619 | fd = ui::GetLocalePackFd(®ion); |
| 3620 | mappings->ShareWithRegion(kAndroidLocalePakDescriptor, fd, region); |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3621 | |
zpeng | 368afac8 | 2017-07-17 18:47:45 | [diff] [blame] | 3622 | // Optional secondary locale .pak file. |
| 3623 | fd = ui::GetSecondaryLocalePackFd(®ion); |
| 3624 | if (fd != -1) { |
| 3625 | mappings->ShareWithRegion(kAndroidSecondaryLocalePakDescriptor, fd, region); |
| 3626 | } |
| 3627 | |
[email protected] | 09560f7f | 2014-06-10 18:40:28 | [diff] [blame] | 3628 | base::FilePath app_data_path; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 3629 | base::PathService::Get(base::DIR_ANDROID_APP_DATA, &app_data_path); |
[email protected] | 09560f7f | 2014-06-10 18:40:28 | [diff] [blame] | 3630 | DCHECK(!app_data_path.empty()); |
Joshua Peraza | f890e4b | 2019-01-03 19:19:02 | [diff] [blame] | 3631 | #endif // defined(OS_ANDROID) |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3632 | int crash_signal_fd = GetCrashSignalFD(command_line); |
| 3633 | if (crash_signal_fd >= 0) { |
Jay Civelli | 668c097f | 2018-05-16 20:44:13 | [diff] [blame] | 3634 | mappings->Share(service_manager::kCrashDumpSignal, crash_signal_fd); |
[email protected] | 40da3e0c | 2012-10-24 22:03:38 | [diff] [blame] | 3635 | } |
jcivelli | e6f55074 | 2017-01-06 19:29:12 | [diff] [blame] | 3636 | } |
| 3637 | #endif // defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | b80f6843 | 2011-05-02 17:22:30 | [diff] [blame] | 3638 | |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 3639 | #if defined(OS_WIN) |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3640 | base::string16 ChromeContentBrowserClient::GetAppContainerSidForSandboxType( |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 3641 | int sandbox_type) { |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3642 | // TODO(wfh): Add support for more process types here. crbug.com/499523 |
| 3643 | switch (sandbox_type) { |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 3644 | case service_manager::SANDBOX_TYPE_RENDERER: |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 3645 | return base::string16(install_static::GetSandboxSidPrefix()) + |
| 3646 | L"129201922"; |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 3647 | case service_manager::SANDBOX_TYPE_UTILITY: |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3648 | return base::string16(); |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 3649 | case service_manager::SANDBOX_TYPE_GPU: |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3650 | return base::string16(); |
Tom Sepez | 15d4e520 | 2017-09-27 23:59:05 | [diff] [blame] | 3651 | case service_manager::SANDBOX_TYPE_PPAPI: |
Jerry Lin | a0de7ce | 2018-06-22 15:18:36 | [diff] [blame] | 3652 | return base::string16(install_static::GetSandboxSidPrefix()) + |
| 3653 | L"129201925"; |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 3654 | #if BUILDFLAG(ENABLE_NACL) |
wfh | 182da09c | 2015-06-24 19:23:03 | [diff] [blame] | 3655 | case PROCESS_TYPE_NACL_LOADER: |
| 3656 | return base::string16(); |
| 3657 | case PROCESS_TYPE_NACL_BROKER: |
| 3658 | return base::string16(); |
| 3659 | #endif |
| 3660 | } |
| 3661 | |
| 3662 | // Should never reach here. |
| 3663 | CHECK(0); |
| 3664 | return base::string16(); |
| 3665 | } |
| 3666 | |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3667 | bool ChromeContentBrowserClient::PreSpawnRenderer(sandbox::TargetPolicy* policy, |
| 3668 | RendererSpawnFlags flags) { |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 3669 | // Allow the server side of a pipe restricted to the "chrome.nacl." |
| 3670 | // namespace so that it cannot impersonate other system or other chrome |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3671 | // service pipes. This is also done in nacl_broker_listener.cc. |
| 3672 | sandbox::ResultCode result = |
| 3673 | policy->AddRule(sandbox::TargetPolicy::SUBSYS_NAMED_PIPES, |
| 3674 | sandbox::TargetPolicy::NAMEDPIPES_ALLOW_ANY, |
| 3675 | L"\\\\.\\pipe\\chrome.nacl.*"); |
rickyz | 5010931 | 2015-11-11 00:37:08 | [diff] [blame] | 3676 | if (result != sandbox::SBOX_ALL_OK) |
| 3677 | return false; |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3678 | |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 3679 | // Does not work under component build because all the component DLLs would need |
| 3680 | // to be manually added and maintained. Does not work under ASAN build because |
| 3681 | // ASAN has not yet fully initialized its instrumentation by the time the CIG |
| 3682 | // intercepts run. |
| 3683 | #if !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3684 | if ((flags & RendererSpawnFlags::RENDERER_CODE_INTEGRITY) == 0) |
| 3685 | return true; |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3686 | if (!base::FeatureList::IsEnabled(kRendererCodeIntegrity)) |
| 3687 | return true; |
| 3688 | |
| 3689 | // Only enable signing mitigation if launching from chrome.exe. |
| 3690 | base::FilePath exe_path; |
| 3691 | if (!base::PathService::Get(base::FILE_EXE, &exe_path)) |
| 3692 | return true; |
| 3693 | if (chrome::kBrowserProcessExecutableName != exe_path.BaseName().value()) |
| 3694 | return true; |
| 3695 | |
| 3696 | sandbox::MitigationFlags mitigations = policy->GetProcessMitigations(); |
| 3697 | mitigations |= sandbox::MITIGATION_FORCE_MS_SIGNED_BINS; |
| 3698 | result = policy->SetProcessMitigations(mitigations); |
| 3699 | if (result != sandbox::SBOX_ALL_OK) |
| 3700 | return false; |
| 3701 | |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3702 | // Allow loading Chrome's DLLs. The name of this depends on whether |
| 3703 | // is_multi_dll_chrome is defined or not. For multi-DLL Chrome, |
| 3704 | // chrome_child.dll is loaded, but for single-DLL Chrome, it would be the |
| 3705 | // same DLL as the browser process. |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3706 | #if defined(CHROME_MULTIPLE_DLL_BROWSER) |
| 3707 | constexpr auto* child_dll_path = chrome::kChildDll; |
| 3708 | #else |
| 3709 | constexpr auto* child_dll_path = chrome::kBrowserResourcesDll; |
| 3710 | #endif |
| 3711 | for (const auto* dll : {child_dll_path, chrome::kElfDll}) { |
| 3712 | result = policy->AddRule(sandbox::TargetPolicy::SUBSYS_SIGNED_BINARY, |
| 3713 | sandbox::TargetPolicy::SIGNED_ALLOW_LOAD, |
| 3714 | GetModulePath(dll).value().c_str()); |
| 3715 | if (result != sandbox::SBOX_ALL_OK) |
| 3716 | return false; |
| 3717 | } |
Will Harris | 1b9b415 | 2019-08-21 22:33:50 | [diff] [blame] | 3718 | #endif // !defined(COMPONENT_BUILD) && !defined(ADDRESS_SANITIZER) |
Will Harris | c196ed94 | 2019-08-03 03:45:30 | [diff] [blame] | 3719 | |
| 3720 | return true; |
[email protected] | 34f4868 | 2013-03-20 00:30:18 | [diff] [blame] | 3721 | } |
Will Harris | 956e0ca | 2019-08-23 20:47:39 | [diff] [blame] | 3722 | |
| 3723 | bool ChromeContentBrowserClient::IsRendererCodeIntegrityEnabled() { |
| 3724 | PrefService* local_state = g_browser_process->local_state(); |
| 3725 | if (local_state && |
| 3726 | local_state->HasPrefPath(prefs::kRendererCodeIntegrityEnabled) && |
| 3727 | !local_state->GetBoolean(prefs::kRendererCodeIntegrityEnabled)) |
| 3728 | return false; |
| 3729 | return true; |
| 3730 | } |
| 3731 | |
wfh | c91e967 | 2016-01-27 00:14:20 | [diff] [blame] | 3732 | #endif // defined(OS_WIN) |
[email protected] | 4a65826d | 2011-08-25 16:04:01 | [diff] [blame] | 3733 | |
ben | d1dd50f5 | 2016-06-26 22:10:48 | [diff] [blame] | 3734 | void ChromeContentBrowserClient::ExposeInterfacesToRenderer( |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 3735 | service_manager::BinderRegistry* registry, |
Sam McNally | 52e5028 | 2017-11-29 00:54:02 | [diff] [blame] | 3736 | blink::AssociatedInterfaceRegistry* associated_registry, |
leon.han | 0b61879 | 2016-06-16 01:53:51 | [diff] [blame] | 3737 | content::RenderProcessHost* render_process_host) { |
nigeltao | beff0a10 | 2017-04-29 09:30:37 | [diff] [blame] | 3738 | // The CacheStatsRecorder is an associated binding, instead of a |
| 3739 | // non-associated one, because the sender (in the renderer process) posts the |
| 3740 | // message after a time delay, in order to rate limit. The association |
| 3741 | // protects against the render process host ID being recycled in that time |
| 3742 | // gap between the preparation and the execution of that IPC. |
| 3743 | associated_registry->AddInterface( |
| 3744 | base::Bind(&CacheStatsRecorder::Create, render_process_host->GetID())); |
| 3745 | |
ben | 5be0b913 | 2016-08-03 00:17:18 | [diff] [blame] | 3746 | scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner = |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 3747 | base::CreateSingleThreadTaskRunner({content::BrowserThread::UI}); |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 3748 | registry->AddInterface(base::Bind(&rappor::RapporRecorderImpl::Create, |
| 3749 | g_browser_process->rappor_service()), |
| 3750 | ui_task_runner); |
Sadrul Habib Chowdhury | 16b3a16 | 2018-02-03 01:43:18 | [diff] [blame] | 3751 | registry->AddInterface( |
Mike Wittman | 16fa536 | 2018-09-04 17:27:30 | [diff] [blame] | 3752 | base::BindRepeating(&metrics::CallStackProfileCollector::Create)); |
Sadrul Habib Chowdhury | 16b3a16 | 2018-02-03 01:43:18 | [diff] [blame] | 3753 | |
dvallet | 233f57ab | 2016-12-21 03:17:10 | [diff] [blame] | 3754 | if (NetBenchmarking::CheckBenchmarkingEnabled()) { |
| 3755 | Profile* profile = |
| 3756 | Profile::FromBrowserContext(render_process_host->GetBrowserContext()); |
Alexandr Ilin | 4909ec8 | 2018-06-06 10:22:48 | [diff] [blame] | 3757 | auto* loading_predictor = |
| 3758 | predictors::LoadingPredictorFactory::GetForProfile(profile); |
Robbie McElrath | b0f248c | 2018-07-24 19:44:16 | [diff] [blame] | 3759 | registry->AddInterface( |
| 3760 | base::BindRepeating( |
| 3761 | &NetBenchmarking::Create, |
| 3762 | loading_predictor ? loading_predictor->GetWeakPtr() : nullptr, |
Robbie McElrath | b0f248c | 2018-07-24 19:44:16 | [diff] [blame] | 3763 | render_process_host->GetID()), |
| 3764 | ui_task_runner); |
dvallet | 233f57ab | 2016-12-21 03:17:10 | [diff] [blame] | 3765 | } |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 3766 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 3767 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
Adam Rice | 41b8959 | 2017-07-28 10:33:44 | [diff] [blame] | 3768 | if (safe_browsing_service_) { |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 3769 | content::ResourceContext* resource_context = |
| 3770 | render_process_host->GetBrowserContext()->GetResourceContext(); |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 3771 | registry->AddInterface( |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 3772 | base::Bind( |
| 3773 | &safe_browsing::MojoSafeBrowsingImpl::MaybeCreate, |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 3774 | render_process_host->GetID(), resource_context, |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 3775 | base::Bind( |
| 3776 | &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate, |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 3777 | base::Unretained(this), resource_context)), |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 3778 | base::CreateSingleThreadTaskRunner({BrowserThread::IO})); |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 3779 | } |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 3780 | #endif |
yzshen | 2d8fb42 | 2017-06-01 20:29:40 | [diff] [blame] | 3781 | |
Eric Roman | a00cf68 | 2018-11-01 20:09:11 | [diff] [blame] | 3782 | if (data_reduction_proxy::params::IsEnabledWithNetworkService()) { |
Julie Jeongeun Kim | aaf568f | 2019-09-20 03:33:18 | [diff] [blame] | 3783 | registry->AddInterface(base::BindRepeating(&AddDataReductionProxyReceiver, |
Clark DuVall | 812e07d | 2019-08-26 18:34:56 | [diff] [blame] | 3784 | render_process_host->GetID()), |
| 3785 | ui_task_runner); |
Eric Roman | a00cf68 | 2018-11-01 20:09:11 | [diff] [blame] | 3786 | } |
| 3787 | |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 3788 | #if defined(OS_WIN) |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3789 | // Add the ModuleEventSink interface. This is the interface used by renderer |
| 3790 | // processes to notify the browser of modules in their address space. The |
| 3791 | // process handle is not yet available at this point so pass in a callback |
| 3792 | // to allow to retrieve a duplicate at the time the interface is actually |
Ken Rockot | 15253a48 | 2019-08-23 17:44:59 | [diff] [blame] | 3793 | // created. |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3794 | auto get_process = base::BindRepeating( |
Ken Rockot | 15253a48 | 2019-08-23 17:44:59 | [diff] [blame] | 3795 | [](int id) -> base::Process { |
| 3796 | auto* host = content::RenderProcessHost::FromID(id); |
| 3797 | if (host) |
| 3798 | return host->GetProcess().Duplicate(); |
| 3799 | return base::Process(); |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3800 | }, |
Ken Rockot | 15253a48 | 2019-08-23 17:44:59 | [diff] [blame] | 3801 | render_process_host->GetID()); |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3802 | registry->AddInterface( |
Patrick Monette | aa2ec56 | 2019-03-20 23:37:45 | [diff] [blame] | 3803 | base::BindRepeating( |
| 3804 | &ModuleEventSinkImpl::Create, std::move(get_process), |
| 3805 | content::PROCESS_TYPE_RENDERER, |
| 3806 | base::BindRepeating(&ModuleDatabase::HandleModuleLoadEvent)), |
Patrick Monette | 9a10ae2 | 2018-06-14 22:18:18 | [diff] [blame] | 3807 | ui_task_runner); |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 3808 | #endif |
Dan Harrington | 964d48c | 2018-08-03 15:52:24 | [diff] [blame] | 3809 | #if defined(OS_ANDROID) |
Carlos Knippschild | 63b3f04 | 2018-11-20 22:55:04 | [diff] [blame] | 3810 | Profile* profile = |
| 3811 | Profile::FromBrowserContext(render_process_host->GetBrowserContext()); |
Dan Harrington | 964d48c | 2018-08-03 15:52:24 | [diff] [blame] | 3812 | registry->AddInterface( |
| 3813 | base::BindRepeating(&android::AvailableOfflineContentProvider::Create, |
Carlos Knippschild | 63b3f04 | 2018-11-20 22:55:04 | [diff] [blame] | 3814 | profile), |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 3815 | base::CreateSingleThreadTaskRunner({BrowserThread::UI})); |
Dan Harrington | 964d48c | 2018-08-03 15:52:24 | [diff] [blame] | 3816 | #endif |
chrisha | 927d8fe | 2017-01-18 23:09:51 | [diff] [blame] | 3817 | |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 3818 | for (auto* ep : extra_parts_) { |
| 3819 | ep->ExposeInterfacesToRenderer(registry, associated_registry, |
| 3820 | render_process_host); |
| 3821 | } |
sammc | 33584452 | 2016-06-09 10:15:59 | [diff] [blame] | 3822 | } |
| 3823 | |
ben | dd157e1a | 2016-07-22 03:15:57 | [diff] [blame] | 3824 | void ChromeContentBrowserClient::ExposeInterfacesToMediaService( |
ben | 8408b13 | 2017-05-01 23:48:50 | [diff] [blame] | 3825 | service_manager::BinderRegistry* registry, |
xhwang | 9ab9648 | 2015-05-11 22:02:33 | [diff] [blame] | 3826 | content::RenderFrameHost* render_frame_host) { |
Xiaohan Wang | 15303d0c | 2017-10-06 05:22:44 | [diff] [blame] | 3827 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) |
| 3828 | registry->AddInterface( |
| 3829 | base::Bind(&OutputProtectionImpl::Create, render_frame_host)); |
ben | 155ecf8 | 2016-06-21 22:43:26 | [diff] [blame] | 3830 | registry->AddInterface( |
John Rummell | 1b5da610 | 2017-11-02 02:15:45 | [diff] [blame] | 3831 | base::Bind(&PlatformVerificationImpl::Create, render_frame_host)); |
Xiaohan Wang | 15303d0c | 2017-10-06 05:22:44 | [diff] [blame] | 3832 | #endif // BUILDFLAG(ENABLE_LIBRARY_CDMS) |
xhwang | c86d76e4 | 2016-03-14 23:38:49 | [diff] [blame] | 3833 | |
xhwang | db24d60 | 2017-05-20 06:32:24 | [diff] [blame] | 3834 | #if BUILDFLAG(ENABLE_MOJO_CDM) && defined(OS_ANDROID) |
cm.sanchi | ad3f42a6 | 2017-11-07 11:33:35 | [diff] [blame] | 3835 | registry->AddInterface(base::Bind(&CreateMediaDrmStorage, render_frame_host)); |
xhwang | 116acb9 | 2017-04-03 18:27:20 | [diff] [blame] | 3836 | #endif |
xhwang | 9ab9648 | 2015-05-11 22:02:33 | [diff] [blame] | 3837 | } |
| 3838 | |
Oksana Zhuravlova | 4dd171e8 | 2019-08-16 20:54:00 | [diff] [blame] | 3839 | void ChromeContentBrowserClient::RegisterBrowserInterfaceBindersForFrame( |
| 3840 | service_manager::BinderMapWithContext<content::RenderFrameHost*>* map) { |
| 3841 | chrome::internal::PopulateChromeFrameBinders(map); |
| 3842 | } |
| 3843 | |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 3844 | void ChromeContentBrowserClient::BindInterfaceRequestFromFrame( |
| 3845 | content::RenderFrameHost* render_frame_host, |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 3846 | const std::string& interface_name, |
| 3847 | mojo::ScopedMessagePipeHandle interface_pipe) { |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 3848 | if (!frame_interfaces_ && !frame_interfaces_parameterized_ && |
| 3849 | !worker_interfaces_parameterized_) { |
| 3850 | InitWebContextInterfaces(); |
| 3851 | } |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 3852 | |
Ben Goodger | 272e063 | 2017-07-19 23:27:00 | [diff] [blame] | 3853 | if (!frame_interfaces_parameterized_->TryBindInterface( |
| 3854 | interface_name, &interface_pipe, render_frame_host)) { |
| 3855 | frame_interfaces_->TryBindInterface(interface_name, &interface_pipe); |
juncai | 1bf9f7c | 2016-03-22 20:46:56 | [diff] [blame] | 3856 | } |
rockot | 0fa66a8 | 2015-06-11 17:25:45 | [diff] [blame] | 3857 | } |
| 3858 | |
Mario Sanchez Prada | 39dee4a | 2019-07-09 07:15:40 | [diff] [blame] | 3859 | void ChromeContentBrowserClient::BindCredentialManagerReceiver( |
Oksana Zhuravlova | 23ecbb40 | 2019-03-29 19:44:11 | [diff] [blame] | 3860 | content::RenderFrameHost* render_frame_host, |
Mario Sanchez Prada | 39dee4a | 2019-07-09 07:15:40 | [diff] [blame] | 3861 | mojo::PendingReceiver<blink::mojom::CredentialManager> receiver) { |
| 3862 | ChromePasswordManagerClient::BindCredentialManager(std::move(receiver), |
Oksana Zhuravlova | 23ecbb40 | 2019-03-29 19:44:11 | [diff] [blame] | 3863 | render_frame_host); |
| 3864 | } |
| 3865 | |
Julie Jeongeun Kim | db52a62 | 2019-09-18 00:20:20 | [diff] [blame] | 3866 | bool ChromeContentBrowserClient::BindAssociatedReceiverFromFrame( |
Ken Rockot | 0aad7ec | 2018-07-31 15:58:44 | [diff] [blame] | 3867 | content::RenderFrameHost* render_frame_host, |
| 3868 | const std::string& interface_name, |
| 3869 | mojo::ScopedInterfaceEndpointHandle* handle) { |
| 3870 | if (interface_name == autofill::mojom::AutofillDriver::Name_) { |
| 3871 | autofill::ContentAutofillDriverFactory::BindAutofillDriver( |
Shimi Zhang | 6b72d29 | 2019-07-12 20:52:42 | [diff] [blame] | 3872 | mojo::PendingAssociatedReceiver<autofill::mojom::AutofillDriver>( |
| 3873 | std::move(*handle)), |
Ken Rockot | 0aad7ec | 2018-07-31 15:58:44 | [diff] [blame] | 3874 | render_frame_host); |
| 3875 | return true; |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3876 | } |
| 3877 | if (interface_name == autofill::mojom::PasswordManagerDriver::Name_) { |
Shimi Zhang | 6b72d29 | 2019-07-12 20:52:42 | [diff] [blame] | 3878 | password_manager::ContentPasswordManagerDriverFactory:: |
| 3879 | BindPasswordManagerDriver( |
Julie Jeongeun Kim | db52a62 | 2019-09-18 00:20:20 | [diff] [blame] | 3880 | mojo::PendingAssociatedReceiver< |
| 3881 | autofill::mojom::PasswordManagerDriver>(std::move(*handle)), |
Shimi Zhang | 6b72d29 | 2019-07-12 20:52:42 | [diff] [blame] | 3882 | render_frame_host); |
Dominic Battre | 97d5edf | 2019-03-26 13:41:38 | [diff] [blame] | 3883 | return true; |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3884 | } |
| 3885 | if (interface_name == content_capture::mojom::ContentCaptureReceiver::Name_) { |
Tao Bai | 02ab4dd4 | 2019-03-06 00:30:37 | [diff] [blame] | 3886 | content_capture::ContentCaptureReceiverManager::BindContentCaptureReceiver( |
Shimi Zhang | 8ee3233 | 2019-07-12 17:59:36 | [diff] [blame] | 3887 | mojo::PendingAssociatedReceiver< |
| 3888 | content_capture::mojom::ContentCaptureReceiver>(std::move(*handle)), |
Tao Bai | 02ab4dd4 | 2019-03-06 00:30:37 | [diff] [blame] | 3889 | render_frame_host); |
| 3890 | return true; |
Ken Rockot | 0aad7ec | 2018-07-31 15:58:44 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | return false; |
| 3894 | } |
| 3895 | |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 3896 | void ChromeContentBrowserClient::BindInterfaceRequestFromWorker( |
| 3897 | content::RenderProcessHost* render_process_host, |
| 3898 | const url::Origin& origin, |
| 3899 | const std::string& interface_name, |
| 3900 | mojo::ScopedMessagePipeHandle interface_pipe) { |
| 3901 | if (!frame_interfaces_ && !frame_interfaces_parameterized_ && |
| 3902 | !worker_interfaces_parameterized_) { |
| 3903 | InitWebContextInterfaces(); |
| 3904 | } |
| 3905 | |
| 3906 | worker_interfaces_parameterized_->BindInterface( |
| 3907 | interface_name, std::move(interface_pipe), render_process_host, origin); |
| 3908 | } |
| 3909 | |
Ken Rockot | 251bc6e0 | 2019-09-17 21:46:33 | [diff] [blame] | 3910 | void ChromeContentBrowserClient::BindGpuHostReceiver( |
| 3911 | mojo::GenericPendingReceiver receiver) { |
| 3912 | if (auto r = receiver.As<metrics::mojom::CallStackProfileCollector>()) |
| 3913 | metrics::CallStackProfileCollector::Create(std::move(r)); |
wittman | 757af87 | 2016-08-16 00:13:46 | [diff] [blame] | 3914 | } |
| 3915 | |
Ken Rockot | c185b2a | 2019-08-01 22:19:48 | [diff] [blame] | 3916 | void ChromeContentBrowserClient::BindHostReceiverForRenderer( |
| 3917 | content::RenderProcessHost* render_process_host, |
| 3918 | mojo::GenericPendingReceiver receiver) { |
| 3919 | #if BUILDFLAG(ENABLE_SPELLCHECK) |
| 3920 | if (auto host_receiver = receiver.As<spellcheck::mojom::SpellCheckHost>()) { |
| 3921 | SpellCheckHostChromeImpl::Create(render_process_host->GetID(), |
| 3922 | std::move(host_receiver)); |
| 3923 | return; |
| 3924 | } |
| 3925 | |
| 3926 | #if BUILDFLAG(HAS_SPELLCHECK_PANEL) |
| 3927 | if (auto panel_host_receiver = |
| 3928 | receiver.As<spellcheck::mojom::SpellCheckPanelHost>()) { |
| 3929 | SpellCheckPanelHostImpl::Create(render_process_host->GetID(), |
| 3930 | std::move(panel_host_receiver)); |
| 3931 | return; |
| 3932 | } |
| 3933 | #endif // BUILDFLAG(HAS_SPELLCHECK_PANEL) |
| 3934 | #endif // BUILDFLAG(ENABLE_SPELLCHECK) |
| 3935 | } |
| 3936 | |
Ken Rockot | 7c6275b | 2019-08-02 20:00:23 | [diff] [blame] | 3937 | void ChromeContentBrowserClient::BindHostReceiverForRendererOnIOThread( |
| 3938 | int render_process_id, |
| 3939 | mojo::GenericPendingReceiver* receiver) { |
| 3940 | if (auto host_receiver = |
| 3941 | receiver->As<startup_metric_utils::mojom::StartupMetricHost>()) { |
| 3942 | startup_metric_utils::StartupMetricHostImpl::Create( |
| 3943 | std::move(host_receiver)); |
| 3944 | return; |
| 3945 | } |
| 3946 | } |
| 3947 | |
Ken Rockot | fa5d5711 | 2019-05-29 20:57:14 | [diff] [blame] | 3948 | void ChromeContentBrowserClient::WillStartServiceManager() { |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3949 | #if defined(OS_WIN) |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 3950 | if (startup_data_) { |
| 3951 | auto* chrome_feature_list_creator = |
| 3952 | startup_data_->chrome_feature_list_creator(); |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3953 | // This has to run very early before ServiceManagerContext is created. |
| 3954 | const base::Value* force_network_in_process_value = |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 3955 | chrome_feature_list_creator->browser_policy_connector() |
John Abd-El-Malek | 27b3ebd2 | 2019-02-12 18:59:18 | [diff] [blame] | 3956 | ->GetPolicyService() |
| 3957 | ->GetPolicies(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
| 3958 | std::string())) |
| 3959 | .GetValue(policy::key::kForceNetworkInProcess); |
| 3960 | bool force_network_in_process = false; |
| 3961 | if (force_network_in_process_value) |
| 3962 | force_network_in_process_value->GetAsBoolean(&force_network_in_process); |
| 3963 | if (force_network_in_process) |
| 3964 | content::ForceInProcessNetworkService(true); |
| 3965 | } |
| 3966 | #endif |
xhwang | 5e63046 | 2015-10-30 03:18:48 | [diff] [blame] | 3967 | } |
| 3968 | |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3969 | void ChromeContentBrowserClient::RunServiceInstance( |
| 3970 | const service_manager::Identity& identity, |
| 3971 | mojo::PendingReceiver<service_manager::mojom::Service>* receiver) { |
| 3972 | const std::string& service_name = identity.name(); |
Ken Rockot | 91c40da8 | 2019-08-12 20:07:11 | [diff] [blame] | 3973 | ALLOW_UNUSED_LOCAL(service_name); |
Ken Rockot | 3d8be74 | 2018-11-22 08:59:38 | [diff] [blame] | 3974 | #if BUILDFLAG(ENABLE_MOJO_MEDIA_IN_BROWSER_PROCESS) |
| 3975 | if (service_name == media::mojom::kMediaServiceName) { |
Ken Rockot | d80eb10 | 2018-11-29 14:55:16 | [diff] [blame] | 3976 | service_manager::Service::RunAsyncUntilTermination( |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3977 | media::CreateMediaService(std::move(*receiver))); |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3978 | return; |
Ken Rockot | 3d8be74 | 2018-11-22 08:59:38 | [diff] [blame] | 3979 | } |
| 3980 | #endif |
Ken Rockot | e116c20 | 2018-11-30 01:52:50 | [diff] [blame] | 3981 | |
| 3982 | #if defined(OS_CHROMEOS) |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 3983 | auto service = ash_service_registry::HandleServiceRequest( |
| 3984 | service_name, std::move(*receiver)); |
Ken Rockot | c15f3499 | 2018-12-01 21:27:57 | [diff] [blame] | 3985 | if (service) |
| 3986 | service_manager::Service::RunAsyncUntilTermination(std::move(service)); |
Lei Zhang | 194fcd3 | 2019-05-23 16:19:41 | [diff] [blame] | 3987 | #endif // defined(OS_CHROMEOS) |
Ken Rockot | 3d8be74 | 2018-11-22 08:59:38 | [diff] [blame] | 3988 | } |
| 3989 | |
Ken Rockot | 8f39a27 | 2018-12-21 23:38:35 | [diff] [blame] | 3990 | base::Optional<service_manager::Manifest> |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 3991 | ChromeContentBrowserClient::GetServiceManifestOverlay(base::StringPiece name) { |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3992 | if (name == content::mojom::kBrowserServiceName) |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 3993 | return GetChromeContentBrowserOverlayManifest(); |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3994 | if (name == content::mojom::kGpuServiceName) |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 3995 | return GetChromeContentGpuOverlayManifest(); |
Lei Zhang | 5b3f81f | 2019-04-10 00:54:58 | [diff] [blame] | 3996 | if (name == content::mojom::kRendererServiceName) |
| 3997 | return GetChromeContentRendererOverlayManifest(); |
Ken Rockot | 341089f | 2019-01-11 23:11:58 | [diff] [blame] | 3998 | return base::nullopt; |
ben | c70c0e3 | 2016-09-22 03:50:37 | [diff] [blame] | 3999 | } |
| 4000 | |
Ken Rockot | 69aade0 | 2019-01-23 21:19:51 | [diff] [blame] | 4001 | std::vector<service_manager::Manifest> |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 4002 | ChromeContentBrowserClient::GetExtraServiceManifests() { |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 4003 | auto manifests = GetChromeBuiltinServiceManifests(); |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 4004 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 4005 | #if BUILDFLAG(ENABLE_NACL) |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 4006 | manifests.push_back(GetNaClLoaderManifest()); |
Ken Rockot | 69aade0 | 2019-01-23 21:19:51 | [diff] [blame] | 4007 | #if defined(OS_WIN) && defined(ARCH_CPU_X86) |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 4008 | manifests.push_back(GetNaClBrokerManifest()); |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 4009 | #endif // defined(OS_WIN) |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 4010 | #endif // BUILDFLAG(ENABLE_NACL) |
Ken Rockot | 06fd283 | 2019-05-24 17:24:44 | [diff] [blame] | 4011 | |
| 4012 | return manifests; |
sammc | 2b0375b | 2016-12-22 01:26:17 | [diff] [blame] | 4013 | } |
| 4014 | |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 4015 | void ChromeContentBrowserClient::OpenURL( |
Matt Falkenhagen | 18c5c5d | 2018-11-26 02:55:37 | [diff] [blame] | 4016 | content::SiteInstance* site_instance, |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 4017 | const content::OpenURLParams& params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 4018 | base::OnceCallback<void(content::WebContents*)> callback) { |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 4019 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Matt Falkenhagen | 18c5c5d | 2018-11-26 02:55:37 | [diff] [blame] | 4020 | DCHECK(ShouldAllowOpenURL(site_instance, params.url)); |
| 4021 | |
| 4022 | content::BrowserContext* browser_context = site_instance->GetBrowserContext(); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 4023 | |
zpeng | db4a58e | 2017-01-10 17:40:32 | [diff] [blame] | 4024 | #if defined(OS_ANDROID) |
pkotwicz | aa289f0 | 2016-07-05 22:26:22 | [diff] [blame] | 4025 | ServiceTabLauncher::GetInstance()->LaunchTab(browser_context, params, |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 4026 | std::move(callback)); |
jam | 1c5a9149 | 2016-02-24 20:47:53 | [diff] [blame] | 4027 | #else |
cm.sanchi | 2522bc9 | 2017-12-04 08:04:13 | [diff] [blame] | 4028 | NavigateParams nav_params(Profile::FromBrowserContext(browser_context), |
| 4029 | params.url, params.transition); |
| 4030 | nav_params.FillNavigateParamsFromOpenURLParams(params); |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 4031 | nav_params.user_gesture = params.user_gesture; |
| 4032 | |
| 4033 | Navigate(&nav_params); |
danakj | a9fe91c | 2019-05-01 19:02:29 | [diff] [blame] | 4034 | std::move(callback).Run(nav_params.navigated_or_inserted_contents); |
peter | bbcccc1 | 2015-02-11 22:23:33 | [diff] [blame] | 4035 | #endif |
mlamouri | eb40d55 | 2015-02-05 00:57:08 | [diff] [blame] | 4036 | } |
| 4037 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 4038 | content::ControllerPresentationServiceDelegate* |
| 4039 | ChromeContentBrowserClient::GetControllerPresentationServiceDelegate( |
| 4040 | content::WebContents* web_contents) { |
mfoltz | 99bd44c | 2016-03-18 20:36:46 | [diff] [blame] | 4041 | if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) { |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 4042 | return media_router::PresentationServiceDelegateImpl:: |
| 4043 | GetOrCreateForWebContents(web_contents); |
| 4044 | } |
haibinlu | 9e605a9 | 2015-06-06 03:45:09 | [diff] [blame] | 4045 | return nullptr; |
| 4046 | } |
| 4047 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 4048 | content::ReceiverPresentationServiceDelegate* |
| 4049 | ChromeContentBrowserClient::GetReceiverPresentationServiceDelegate( |
| 4050 | content::WebContents* web_contents) { |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 4051 | if (media_router::MediaRouterEnabled(web_contents->GetBrowserContext())) { |
| 4052 | // ReceiverPresentationServiceDelegateImpl exists only for WebContents |
| 4053 | // created for offscreen presentations. The WebContents must belong to |
| 4054 | // an incognito profile. |
| 4055 | if (auto* impl = media_router::ReceiverPresentationServiceDelegateImpl:: |
| 4056 | FromWebContents(web_contents)) { |
| 4057 | DCHECK(web_contents->GetBrowserContext()->IsOffTheRecord()); |
| 4058 | return impl; |
| 4059 | } |
| 4060 | } |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 4061 | return nullptr; |
| 4062 | } |
| 4063 | |
horo | 48d4d3e | 2015-02-27 03:04:00 | [diff] [blame] | 4064 | void ChromeContentBrowserClient::RecordURLMetric(const std::string& metric, |
| 4065 | const GURL& url) { |
mathp | 46284f3 | 2015-03-11 13:06:41 | [diff] [blame] | 4066 | if (url.is_valid()) { |
| 4067 | rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), |
| 4068 | metric, url); |
| 4069 | } |
horo | 48d4d3e | 2015-02-27 03:04:00 | [diff] [blame] | 4070 | } |
| 4071 | |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 4072 | std::string ChromeContentBrowserClient::GetMetricSuffixForURL(const GURL& url) { |
| 4073 | // Don't change these returned strings. They are written (in hashed form) into |
| 4074 | // UMA logs. If you add more strings, you must update histograms.xml and get |
| 4075 | // histograms review. Only Google domains should be here for privacy purposes. |
| 4076 | // TODO(falken): Ideally Chrome would log the relevant UMA directly and this |
| 4077 | // function could be removed. |
Matt Falkenhagen | 2c98ee29a | 2017-07-20 16:43:19 | [diff] [blame] | 4078 | if (page_load_metrics::IsGoogleSearchResultUrl(url)) |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 4079 | return "search"; |
Matt Falkenhagen | 2c98ee29a | 2017-07-20 16:43:19 | [diff] [blame] | 4080 | if (url.host() == "docs.google.com") |
| 4081 | return "docs"; |
Matt Falkenhagen | 8479b20 | 2017-07-14 04:35:31 | [diff] [blame] | 4082 | return std::string(); |
| 4083 | } |
| 4084 | |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 4085 | std::vector<std::unique_ptr<content::NavigationThrottle>> |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4086 | ChromeContentBrowserClient::CreateThrottlesForNavigation( |
| 4087 | content::NavigationHandle* handle) { |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 4088 | std::vector<std::unique_ptr<content::NavigationThrottle>> throttles; |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 4089 | |
bmcquade | b455655 | 2017-03-24 22:24:37 | [diff] [blame] | 4090 | // MetricsNavigationThrottle requires that it runs before NavigationThrottles |
| 4091 | // that may delay or cancel navigations, so only NavigationThrottles that |
| 4092 | // don't delay or cancel navigations (e.g. throttles that are only observing |
| 4093 | // callbacks without affecting navigation behavior) should be added before |
| 4094 | // MetricsNavigationThrottle. |
| 4095 | if (handle->IsInMainFrame()) { |
| 4096 | throttles.push_back( |
| 4097 | page_load_metrics::MetricsNavigationThrottle::Create(handle)); |
| 4098 | } |
| 4099 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4100 | #if BUILDFLAG(ENABLE_PLUGINS) |
tommycli | ae590f160 | 2016-11-02 03:59:23 | [diff] [blame] | 4101 | std::unique_ptr<content::NavigationThrottle> flash_url_throttle = |
| 4102 | FlashDownloadInterception::MaybeCreateThrottleFor(handle); |
| 4103 | if (flash_url_throttle) |
| 4104 | throttles.push_back(std::move(flash_url_throttle)); |
trizzofo | 8ddaeb7 | 2016-09-01 23:18:27 | [diff] [blame] | 4105 | #endif |
| 4106 | |
mmenke | db2637ff | 2017-03-30 23:59:42 | [diff] [blame] | 4107 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 4108 | std::unique_ptr<content::NavigationThrottle> supervised_user_throttle = |
| 4109 | SupervisedUserNavigationThrottle::MaybeCreateThrottleFor(handle); |
| 4110 | if (supervised_user_throttle) |
| 4111 | throttles.push_back(std::move(supervised_user_throttle)); |
| 4112 | #endif |
| 4113 | |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4114 | #if defined(OS_ANDROID) |
| 4115 | // TODO(davidben): This is insufficient to integrate with prerender properly. |
| 4116 | // https://crbug.com/370595 |
| 4117 | prerender::PrerenderContents* prerender_contents = |
| 4118 | prerender::PrerenderContents::FromWebContents(handle->GetWebContents()); |
| 4119 | if (!prerender_contents && handle->IsInMainFrame()) { |
| 4120 | throttles.push_back( |
| 4121 | navigation_interception::InterceptNavigationDelegate::CreateThrottleFor( |
Charlie Harrison | 3286ab7 | 2019-02-13 20:13:30 | [diff] [blame] | 4122 | handle, navigation_interception::SynchronyMode::kAsync)); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4123 | } |
Min Qin | 0ab0e16 | 2017-11-14 21:57:19 | [diff] [blame] | 4124 | throttles.push_back(InterceptOMADownloadNavigationThrottle::Create(handle)); |
Giovanni Ortuño Urquidi | 7ae7fb0 | 2017-10-09 01:49:57 | [diff] [blame] | 4125 | #elif BUILDFLAG(ENABLE_EXTENSIONS) |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4126 | if (handle->IsInMainFrame()) { |
| 4127 | // Redirect some navigations to apps that have registered matching URL |
| 4128 | // handlers ('url_handlers' in the manifest). |
Giovanni Ortuño Urquidi | 7ae7fb0 | 2017-10-09 01:49:57 | [diff] [blame] | 4129 | auto url_to_app_throttle = |
| 4130 | PlatformAppNavigationRedirector::MaybeCreateThrottleFor(handle); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4131 | if (url_to_app_throttle) |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 4132 | throttles.push_back(std::move(url_to_app_throttle)); |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4133 | } |
| 4134 | #endif |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4135 | |
| 4136 | #if defined(OS_CHROMEOS) |
| 4137 | // Check if we need to add merge session throttle. This throttle will postpone |
| 4138 | // loading of main frames. |
| 4139 | if (handle->IsInMainFrame()) { |
| 4140 | // Add interstitial page while merge session process (cookie reconstruction |
| 4141 | // from OAuth2 refresh token in ChromeOS login) is still in progress while |
| 4142 | // we are attempting to load a google property. |
csharrison | dd06bab | 2016-07-22 14:15:02 | [diff] [blame] | 4143 | if (merge_session_throttling_utils::ShouldAttachNavigationThrottle() && |
| 4144 | !merge_session_throttling_utils::AreAllSessionMergedAlready() && |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4145 | handle->GetURL().SchemeIsHTTPOrHTTPS()) { |
| 4146 | throttles.push_back(MergeSessionNavigationThrottle::Create(handle)); |
| 4147 | } |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4148 | } |
| 4149 | #endif |
djacobo | 21e56e0 | 2016-07-02 01:14:31 | [diff] [blame] | 4150 | |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4151 | #if !defined(OS_ANDROID) |
| 4152 | if (base::FeatureList::IsEnabled(features::kIntentPicker)) { |
Dominick Ng | 7c28994 | 2018-03-27 05:57:15 | [diff] [blame] | 4153 | auto url_to_apps_throttle = |
Maggie Cai | a2f03f5 | 2019-04-02 02:13:28 | [diff] [blame] | 4154 | #if defined(OS_CHROMEOS) |
| 4155 | chromeos::ChromeOsAppsNavigationThrottle::MaybeCreate(handle); |
| 4156 | #else |
| 4157 | apps::AppsNavigationThrottle::MaybeCreate(handle); |
| 4158 | #endif |
Dominick Ng | 7c28994 | 2018-03-27 05:57:15 | [diff] [blame] | 4159 | if (url_to_apps_throttle) |
| 4160 | throttles.push_back(std::move(url_to_apps_throttle)); |
clamy | 4967831 | 2015-10-22 21:59:00 | [diff] [blame] | 4161 | } |
| 4162 | #endif |
| 4163 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 4164 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 4165 | throttles.push_back( |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4166 | std::make_unique<extensions::ExtensionNavigationThrottle>(handle)); |
Clark DuVall | 2cf99249e | 2018-09-19 19:11:51 | [diff] [blame] | 4167 | |
| 4168 | std::unique_ptr<content::NavigationThrottle> user_script_throttle = |
| 4169 | extensions::ExtensionsBrowserClient::Get() |
| 4170 | ->GetUserScriptListener() |
| 4171 | ->CreateNavigationThrottle(handle); |
| 4172 | if (user_script_throttle) |
| 4173 | throttles.push_back(std::move(user_script_throttle)); |
nasko | b9164c4 | 2016-06-07 01:21:35 | [diff] [blame] | 4174 | #endif |
| 4175 | |
bauerb | 8f9c3774 | 2017-03-30 15:04:12 | [diff] [blame] | 4176 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 4177 | std::unique_ptr<content::NavigationThrottle> supervised_user_nav_throttle = |
| 4178 | SupervisedUserGoogleAuthNavigationThrottle::MaybeCreate(handle); |
| 4179 | if (supervised_user_nav_throttle) |
| 4180 | throttles.push_back(std::move(supervised_user_nav_throttle)); |
| 4181 | #endif |
| 4182 | |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 4183 | content::WebContents* web_contents = handle->GetWebContents(); |
csharrison | 77bf834 | 2017-05-04 18:23:10 | [diff] [blame] | 4184 | if (auto* subresource_filter_client = |
| 4185 | ChromeSubresourceFilterClient::FromWebContents(web_contents)) { |
| 4186 | subresource_filter_client->MaybeAppendNavigationThrottles(handle, |
| 4187 | &throttles); |
csharrison | e985ebc | 2017-04-04 17:05:03 | [diff] [blame] | 4188 | } |
| 4189 | |
zhenw | 6edd49c | 2017-07-12 05:49:45 | [diff] [blame] | 4190 | #if !defined(OS_ANDROID) |
| 4191 | // BackgroundTabNavigationThrottle is used by TabManager, which is only |
| 4192 | // enabled on non-Android platforms. |
| 4193 | std::unique_ptr<content::NavigationThrottle> |
| 4194 | background_tab_navigation_throttle = resource_coordinator:: |
| 4195 | BackgroundTabNavigationThrottle::MaybeCreateThrottleFor(handle); |
| 4196 | if (background_tab_navigation_throttle) |
| 4197 | throttles.push_back(std::move(background_tab_navigation_throttle)); |
| 4198 | #endif |
| 4199 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4200 | #if BUILDFLAG(FULL_SAFE_BROWSING) |
Jialiu Lin | bdbb81d | 2017-10-11 21:29:09 | [diff] [blame] | 4201 | std::unique_ptr<content::NavigationThrottle> |
| 4202 | password_protection_navigation_throttle = |
| 4203 | safe_browsing::MaybeCreateNavigationThrottle(handle); |
| 4204 | if (password_protection_navigation_throttle) { |
| 4205 | throttles.push_back(std::move(password_protection_navigation_throttle)); |
| 4206 | } |
| 4207 | #endif |
| 4208 | |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 4209 | std::unique_ptr<content::NavigationThrottle> |
Mustafa Emre Acer | e14f626 | 2019-04-02 00:19:31 | [diff] [blame] | 4210 | lookalike_url_navigation_throttle = lookalikes:: |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 4211 | LookalikeUrlNavigationThrottle::MaybeCreateNavigationThrottle(handle); |
| 4212 | if (lookalike_url_navigation_throttle) |
| 4213 | throttles.push_back(std::move(lookalike_url_navigation_throttle)); |
Joe DeBlasio | 6e8409a | 2019-02-20 23:08:27 | [diff] [blame] | 4214 | |
Amber Won | f56d8f4 | 2017-08-31 22:29:40 | [diff] [blame] | 4215 | std::unique_ptr<content::NavigationThrottle> pdf_iframe_throttle = |
| 4216 | PDFIFrameNavigationThrottle::MaybeCreateThrottleFor(handle); |
| 4217 | if (pdf_iframe_throttle) |
| 4218 | throttles.push_back(std::move(pdf_iframe_throttle)); |
Amber Won | 6b5edc75 | 2017-08-17 19:23:54 | [diff] [blame] | 4219 | |
Charles Harrison | 6dd11d28 | 2017-10-03 06:14:51 | [diff] [blame] | 4220 | std::unique_ptr<content::NavigationThrottle> tab_under_throttle = |
| 4221 | TabUnderNavigationThrottle::MaybeCreate(handle); |
| 4222 | if (tab_under_throttle) |
| 4223 | throttles.push_back(std::move(tab_under_throttle)); |
| 4224 | |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4225 | throttles.push_back(std::make_unique<PolicyBlacklistNavigationThrottle>( |
Doug Turner | 9dcaf596 | 2017-12-21 04:38:53 | [diff] [blame] | 4226 | handle, handle->GetWebContents()->GetBrowserContext())); |
| 4227 | |
Carlos IL | 5a9e751 | 2019-06-13 22:35:28 | [diff] [blame] | 4228 | throttles.push_back(std::make_unique<SSLErrorNavigationThrottle>( |
| 4229 | handle, |
| 4230 | std::make_unique<CertificateReportingServiceCertReporter>(web_contents), |
| 4231 | base::Bind(&SSLErrorHandler::HandleSSLError))); |
Lucas Garron | 94b1605 | 2017-11-11 01:58:12 | [diff] [blame] | 4232 | |
Emily Stark | d6896cd3 | 2019-08-21 04:55:54 | [diff] [blame] | 4233 | throttles.push_back(std::make_unique<LoginNavigationThrottle>(handle)); |
| 4234 | |
Christopher Thompson | 4137cec | 2017-12-19 05:34:23 | [diff] [blame] | 4235 | std::unique_ptr<content::NavigationThrottle> https_upgrade_timing_throttle = |
| 4236 | TypedNavigationTimingThrottle::MaybeCreateThrottleFor(handle); |
| 4237 | if (https_upgrade_timing_throttle) |
| 4238 | throttles.push_back(std::move(https_upgrade_timing_throttle)); |
| 4239 | |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 4240 | #if !defined(OS_ANDROID) |
| 4241 | std::unique_ptr<content::NavigationThrottle> devtools_throttle = |
| 4242 | DevToolsWindow::MaybeCreateNavigationThrottle(handle); |
| 4243 | if (devtools_throttle) |
| 4244 | throttles.push_back(std::move(devtools_throttle)); |
Conley Owens | aafcf12 | 2018-02-26 18:53:51 | [diff] [blame] | 4245 | |
| 4246 | std::unique_ptr<content::NavigationThrottle> new_tab_page_throttle = |
| 4247 | NewTabPageNavigationThrottle::MaybeCreateThrottleFor(handle); |
| 4248 | if (new_tab_page_throttle) |
| 4249 | throttles.push_back(std::move(new_tab_page_throttle)); |
jdoerrie | 4f9376f | 2018-12-12 18:26:20 | [diff] [blame] | 4250 | |
| 4251 | std::unique_ptr<content::NavigationThrottle> |
| 4252 | google_password_manager_throttle = |
| 4253 | GooglePasswordManagerNavigationThrottle::MaybeCreateThrottleFor( |
| 4254 | handle); |
| 4255 | if (google_password_manager_throttle) |
| 4256 | throttles.push_back(std::move(google_password_manager_throttle)); |
Dmitry Gozman | 57b92ce | 2017-12-28 22:24:54 | [diff] [blame] | 4257 | #endif |
| 4258 | |
Carlos IL | 4ee307e | 2018-12-22 03:19:00 | [diff] [blame] | 4259 | if (base::FeatureList::IsEnabled(safe_browsing::kCommittedSBInterstitials)) { |
| 4260 | throttles.push_back( |
| 4261 | std::make_unique<safe_browsing::SafeBrowsingNavigationThrottle>( |
| 4262 | handle)); |
| 4263 | } |
Robert Ogden | afd250b | 2018-07-25 22:21:03 | [diff] [blame] | 4264 | |
Nicolas Ouellet-Payeur | bdcab009 | 2018-10-22 14:50:33 | [diff] [blame] | 4265 | #if defined(OS_WIN) || defined(OS_MACOSX) || \ |
| 4266 | (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
Nicolas Ouellet-Payeur | 995e777 | 2018-09-13 16:02:13 | [diff] [blame] | 4267 | std::unique_ptr<content::NavigationThrottle> browser_switcher_throttle = |
Robert Ogden | 4308eb1 | 2019-09-18 18:42:37 | [diff] [blame] | 4268 | browser_switcher::BrowserSwitcherNavigationThrottle:: |
Nicolas Ouellet-Payeur | 995e777 | 2018-09-13 16:02:13 | [diff] [blame] | 4269 | MaybeCreateThrottleFor(handle); |
| 4270 | if (browser_switcher_throttle) |
| 4271 | throttles.push_back(std::move(browser_switcher_throttle)); |
| 4272 | #endif |
| 4273 | |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 4274 | return throttles; |
clamy | 40c9e14 | 2015-09-29 11:18:47 | [diff] [blame] | 4275 | } |
| 4276 | |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 4277 | std::unique_ptr<content::NavigationUIData> |
| 4278 | ChromeContentBrowserClient::GetNavigationUIData( |
| 4279 | content::NavigationHandle* navigation_handle) { |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4280 | return std::make_unique<ChromeNavigationUIData>(navigation_handle); |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 4281 | } |
| 4282 | |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4283 | void ChromeContentBrowserClient::GetHardwareSecureDecryptionCaps( |
| 4284 | const std::string& key_system, |
| 4285 | const base::flat_set<media::CdmProxy::Protocol>& cdm_proxy_protocols, |
| 4286 | base::flat_set<media::VideoCodec>* video_codecs, |
| 4287 | base::flat_set<media::EncryptionMode>* encryption_schemes) { |
| 4288 | #if defined(OS_WIN) && BUILDFLAG(ENABLE_LIBRARY_CDMS) && \ |
Xiaohan Wang | f170c73 | 2018-09-27 05:45:26 | [diff] [blame] | 4289 | BUILDFLAG(ENABLE_WIDEVINE) |
Xiaohan Wang | a4e4184 | 2018-06-26 18:45:10 | [diff] [blame] | 4290 | if (key_system == kWidevineKeySystem) { |
| 4291 | GetWidevineHardwareCaps(cdm_proxy_protocols, video_codecs, |
| 4292 | encryption_schemes); |
| 4293 | } |
| 4294 | #endif |
| 4295 | } |
| 4296 | |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4297 | content::DevToolsManagerDelegate* |
| 4298 | ChromeContentBrowserClient::GetDevToolsManagerDelegate() { |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 4299 | #if defined(OS_ANDROID) |
| 4300 | return new DevToolsManagerDelegateAndroid(); |
| 4301 | #else |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4302 | return new ChromeDevToolsManagerDelegate(); |
Pavel Feldman | 43f56b7c | 2016-08-30 00:04:35 | [diff] [blame] | 4303 | #endif |
[email protected] | 487974a | 2014-06-13 16:49:01 | [diff] [blame] | 4304 | } |
| 4305 | |
Rayan Kanso | 411e84e | 2019-02-13 15:27:40 | [diff] [blame] | 4306 | void ChromeContentBrowserClient::UpdateDevToolsBackgroundServiceExpiration( |
| 4307 | content::BrowserContext* browser_context, |
| 4308 | int service, |
| 4309 | base::Time expiration_time) { |
| 4310 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4311 | DCHECK(profile); |
| 4312 | |
| 4313 | auto* pref_service = profile->GetPrefs(); |
| 4314 | DCHECK(pref_service); |
| 4315 | |
| 4316 | DictionaryPrefUpdate pref_update( |
| 4317 | pref_service, prefs::kDevToolsBackgroundServicesExpirationDict); |
| 4318 | base::DictionaryValue* exp_dict = pref_update.Get(); |
| 4319 | |
| 4320 | // Convert |expiration_time| to minutes since that is the most granular |
| 4321 | // option that returns an int. base::Value does not accept int64. |
| 4322 | int expiration_time_minutes = |
| 4323 | expiration_time.ToDeltaSinceWindowsEpoch().InMinutes(); |
| 4324 | exp_dict->SetInteger(base::NumberToString(service), expiration_time_minutes); |
| 4325 | } |
| 4326 | |
| 4327 | base::flat_map<int, base::Time> |
| 4328 | ChromeContentBrowserClient::GetDevToolsBackgroundServiceExpirations( |
| 4329 | content::BrowserContext* browser_context) { |
| 4330 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4331 | DCHECK(profile); |
| 4332 | |
| 4333 | auto* pref_service = profile->GetPrefs(); |
| 4334 | DCHECK(pref_service); |
| 4335 | |
| 4336 | auto* expiration_dict = pref_service->GetDictionary( |
| 4337 | prefs::kDevToolsBackgroundServicesExpirationDict); |
| 4338 | DCHECK(expiration_dict); |
| 4339 | |
| 4340 | base::flat_map<int, base::Time> expiration_times; |
| 4341 | for (const auto& it : *expiration_dict) { |
| 4342 | // key. |
| 4343 | int service = 0; |
| 4344 | bool did_convert = base::StringToInt(it.first, &service); |
| 4345 | DCHECK(did_convert); |
| 4346 | |
| 4347 | // value. |
| 4348 | DCHECK(it.second->is_int()); |
| 4349 | base::TimeDelta delta = base::TimeDelta::FromMinutes(it.second->GetInt()); |
| 4350 | base::Time expiration_time = base::Time::FromDeltaSinceWindowsEpoch(delta); |
| 4351 | |
| 4352 | expiration_times[service] = expiration_time; |
| 4353 | } |
| 4354 | |
| 4355 | return expiration_times; |
| 4356 | } |
| 4357 | |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4358 | content::TracingDelegate* ChromeContentBrowserClient::GetTracingDelegate() { |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4359 | return new ChromeTracingDelegate(); |
oysteine | c563c58 | 2015-02-13 19:19:52 | [diff] [blame] | 4360 | } |
| 4361 | |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 4362 | bool ChromeContentBrowserClient::IsPluginAllowedToCallRequestOSFileHandle( |
| 4363 | content::BrowserContext* browser_context, |
| 4364 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4365 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 4366 | return ChromeContentBrowserClientPluginsPart:: |
| 4367 | IsPluginAllowedToCallRequestOSFileHandle(browser_context, url, |
| 4368 | allowed_file_handle_origins_); |
[email protected] | a6868c2 | 2013-10-09 02:50:29 | [diff] [blame] | 4369 | #else |
| 4370 | return false; |
| 4371 | #endif |
| 4372 | } |
| 4373 | |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 4374 | bool ChromeContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs( |
| 4375 | content::BrowserContext* browser_context, |
| 4376 | const GURL& url) { |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4377 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
jitendra.ks | 42e889a | 2014-12-05 09:05:55 | [diff] [blame] | 4378 | return ChromeContentBrowserClientPluginsPart:: |
| 4379 | IsPluginAllowedToUseDevChannelAPIs(browser_context, url, |
| 4380 | allowed_dev_channel_origins_); |
[email protected] | 8ddc6b7c | 2013-12-12 20:42:06 | [diff] [blame] | 4381 | #else |
| 4382 | return false; |
| 4383 | #endif |
| 4384 | } |
| 4385 | |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4386 | void ChromeContentBrowserClient::OverridePageVisibilityState( |
xzhan96 | cf0a3c54 | 2017-11-17 04:33:01 | [diff] [blame] | 4387 | RenderFrameHost* render_frame_host, |
danakj | 0018a29a | 2018-12-01 01:03:43 | [diff] [blame] | 4388 | content::PageVisibilityState* visibility_state) { |
thestig | 00844cea | 2015-09-08 21:44:52 | [diff] [blame] | 4389 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4390 | |
| 4391 | WebContents* web_contents = |
| 4392 | WebContents::FromRenderFrameHost(render_frame_host); |
| 4393 | DCHECK(web_contents); |
| 4394 | |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4395 | prerender::PrerenderManager* prerender_manager = |
droger | c154315 | 2016-09-20 13:03:37 | [diff] [blame] | 4396 | prerender::PrerenderManagerFactory::GetForBrowserContext( |
| 4397 | web_contents->GetBrowserContext()); |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4398 | if (prerender_manager && |
| 4399 | prerender_manager->IsWebContentsPrerendering(web_contents, nullptr)) { |
danakj | 0018a29a | 2018-12-01 01:03:43 | [diff] [blame] | 4400 | *visibility_state = content::PageVisibilityState::kPrerender; |
mlamouri | f8c23a200 | 2015-01-27 13:10:10 | [diff] [blame] | 4401 | } |
| 4402 | } |
| 4403 | |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 4404 | void ChromeContentBrowserClient::InitWebContextInterfaces() { |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4405 | frame_interfaces_ = std::make_unique<service_manager::BinderRegistry>(); |
| 4406 | frame_interfaces_parameterized_ = std::make_unique< |
Ben Goodger | 21ada1e | 2017-07-19 14:53:01 | [diff] [blame] | 4407 | service_manager::BinderRegistryWithArgs<content::RenderFrameHost*>>(); |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 4408 | worker_interfaces_parameterized_ = |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 4409 | std::make_unique<service_manager::BinderRegistryWithArgs< |
Sam McNally | faf9a40 | 2017-10-31 03:06:31 | [diff] [blame] | 4410 | content::RenderProcessHost*, const url::Origin&>>(); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4411 | |
Michael Martis | 4a542f5 | 2017-07-28 01:51:44 | [diff] [blame] | 4412 | // Register mojo ContentTranslateDriver interface only for main frame. |
Anthony Vallee-Dubois | e2432137a | 2019-01-17 20:06:01 | [diff] [blame] | 4413 | frame_interfaces_parameterized_->AddInterface( |
| 4414 | base::BindRepeating(&language::BindContentTranslateDriver)); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4415 | |
| 4416 | frame_interfaces_parameterized_->AddInterface( |
Ken Rockot | d480bee | 2019-08-27 18:54:48 | [diff] [blame] | 4417 | base::BindRepeating(&InsecureSensitiveInputDriverFactory::BindDriver)); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4418 | |
| 4419 | #if defined(OS_ANDROID) |
| 4420 | frame_interfaces_parameterized_->AddInterface(base::Bind( |
Matt Giuca | ee4aefb | 2017-08-04 03:11:55 | [diff] [blame] | 4421 | &ForwardToJavaFrameRegistry<blink::mojom::InstalledAppProvider>)); |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4422 | frame_interfaces_parameterized_->AddInterface( |
| 4423 | base::Bind(&ForwardToJavaFrameRegistry<payments::mojom::PaymentRequest>)); |
Kim Paulhamus | 3d33e44 | 2018-03-29 23:04:14 | [diff] [blame] | 4424 | frame_interfaces_parameterized_->AddInterface( |
Amos Lim | dddb699 | 2018-07-19 22:14:32 | [diff] [blame] | 4425 | base::Bind(&ForwardToJavaFrameRegistry<blink::mojom::Authenticator>)); |
Michael Thiessen | 909ba03 | 2019-03-26 23:47:43 | [diff] [blame] | 4426 | #if defined(BROWSER_MEDIA_CONTROLS_MENU) |
| 4427 | frame_interfaces_parameterized_->AddInterface(base::Bind( |
| 4428 | &ForwardToJavaFrameRegistry<blink::mojom::MediaControlsMenuHost>)); |
| 4429 | #endif |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4430 | #else |
| 4431 | if (base::FeatureList::IsEnabled(features::kWebPayments)) { |
| 4432 | frame_interfaces_parameterized_->AddInterface( |
| 4433 | base::Bind(&payments::CreatePaymentRequest)); |
| 4434 | } |
| 4435 | #endif |
| 4436 | |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4437 | #if defined(OS_ANDROID) |
Matt Giuca | 00e99360 | 2017-06-23 05:17:54 | [diff] [blame] | 4438 | frame_interfaces_parameterized_->AddInterface(base::Bind( |
| 4439 | &ForwardToJavaWebContentsRegistry<blink::mojom::ShareService>)); |
Michael Thiessen | 07c444c | 2019-04-26 03:53:11 | [diff] [blame] | 4440 | #if defined(ENABLE_SPATIAL_NAVIGATION_HOST) |
| 4441 | frame_interfaces_parameterized_->AddInterface(base::Bind( |
| 4442 | &ForwardToJavaWebContentsRegistry<blink::mojom::SpatialNavigationHost>)); |
| 4443 | #endif |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4444 | #endif |
Reilly Grant | 8e5c85c | 2017-07-07 16:35:06 | [diff] [blame] | 4445 | |
Jay Harris | 5a42aa21b | 2018-11-28 01:23:55 | [diff] [blame] | 4446 | #if !defined(OS_ANDROID) |
Eric Stevenson | 1d074a97 | 2018-12-07 14:16:45 | [diff] [blame] | 4447 | frame_interfaces_parameterized_->AddInterface( |
Ken Rockot | d480bee | 2019-08-27 18:54:48 | [diff] [blame] | 4448 | base::BindRepeating(&badging::BadgeManager::BindRequest)); |
Eric Stevenson | c3b1805 | 2018-10-01 22:22:00 | [diff] [blame] | 4449 | #endif |
| 4450 | |
Reilly Grant | 8e5c85c | 2017-07-07 16:35:06 | [diff] [blame] | 4451 | frame_interfaces_parameterized_->AddInterface( |
Lu Chen | 5bec7a30 | 2018-06-26 18:52:32 | [diff] [blame] | 4452 | base::BindRepeating(&NavigationPredictor::Create)); |
Dan Harrington | bc87c06 | 2018-10-31 15:21:24 | [diff] [blame] | 4453 | |
| 4454 | #if defined(OS_ANDROID) |
| 4455 | frame_interfaces_parameterized_->AddInterface( |
Dan Harrington | f60bd50 | 2019-09-05 17:30:33 | [diff] [blame] | 4456 | base::BindRepeating(&offline_pages::OfflinePageAutoFetcher::Create)); |
Dan Harrington | bc87c06 | 2018-10-31 15:21:24 | [diff] [blame] | 4457 | #endif |
Ben Goodger | 6a695c01 | 2017-06-20 20:21:20 | [diff] [blame] | 4458 | } |
| 4459 | |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 4460 | void ChromeContentBrowserClient::InitNetworkContextsParentDirectory() { |
| 4461 | base::FilePath user_data_dir; |
| 4462 | base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 4463 | DCHECK(!user_data_dir.empty()); |
| 4464 | network_contexts_parent_directory_.push_back(user_data_dir); |
| 4465 | |
| 4466 | base::FilePath cache_dir; |
| 4467 | chrome::GetUserCacheDirectory(user_data_dir, &cache_dir); |
| 4468 | DCHECK(!cache_dir.empty()); |
| 4469 | // On some platforms, the cache is a child of the user_data_dir so only |
| 4470 | // return the one path. |
| 4471 | if (!user_data_dir.IsParent(cache_dir)) |
| 4472 | network_contexts_parent_directory_.push_back(cache_dir); |
| 4473 | |
| 4474 | // If the cache location has been overridden by a switch or preference, |
| 4475 | // include that as well. |
| 4476 | if (auto* local_state = g_browser_process->local_state()) { |
| 4477 | base::FilePath pref_cache_dir = |
| 4478 | local_state->GetFilePath(prefs::kDiskCacheDir); |
| 4479 | if (!pref_cache_dir.empty() && !user_data_dir.IsParent(cache_dir)) |
| 4480 | network_contexts_parent_directory_.push_back(pref_cache_dir); |
| 4481 | } |
| 4482 | } |
| 4483 | |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4484 | void ChromeContentBrowserClient::MaybeCopyDisableWebRtcEncryptionSwitch( |
avi | 3ef9ec9e | 2014-12-22 22:50:17 | [diff] [blame] | 4485 | base::CommandLine* to_command_line, |
| 4486 | const base::CommandLine& from_command_line, |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4487 | version_info::Channel channel) { |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4488 | #if defined(OS_ANDROID) |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4489 | const version_info::Channel kMaxDisableEncryptionChannel = |
| 4490 | version_info::Channel::BETA; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4491 | #else |
sdefresne | 6e883e4 | 2015-07-30 08:05:54 | [diff] [blame] | 4492 | const version_info::Channel kMaxDisableEncryptionChannel = |
| 4493 | version_info::Channel::DEV; |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4494 | #endif |
| 4495 | if (channel <= kMaxDisableEncryptionChannel) { |
| 4496 | static const char* const kWebRtcDevSwitchNames[] = { |
Aran Gilman | f010bdd | 2019-08-28 19:55:44 | [diff] [blame] | 4497 | switches::kDisableWebRtcEncryption, |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4498 | }; |
Avi Drissman | d251e91 | 2018-12-26 15:46:37 | [diff] [blame] | 4499 | to_command_line->CopySwitchesFrom(from_command_line, kWebRtcDevSwitchNames, |
| 4500 | base::size(kWebRtcDevSwitchNames)); |
[email protected] | 30335fdf0 | 2014-02-26 19:51:27 | [diff] [blame] | 4501 | } |
| 4502 | } |
bashi | 93362955 | 2016-10-13 23:32:40 | [diff] [blame] | 4503 | |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4504 | #if BUILDFLAG(ENABLE_MEDIA_REMOTING) |
| 4505 | void ChromeContentBrowserClient::CreateMediaRemoter( |
| 4506 | content::RenderFrameHost* render_frame_host, |
| 4507 | media::mojom::RemotingSourcePtr source, |
| 4508 | media::mojom::RemoterRequest request) { |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4509 | CastRemotingConnector::CreateMediaRemoter( |
| 4510 | render_frame_host, std::move(source), std::move(request)); |
miu | 54dca6c | 2016-11-17 10:59:38 | [diff] [blame] | 4511 | } |
| 4512 | #endif // BUILDFLAG(ENABLE_MEDIA_REMOTING) |
robliao | bf5a32e | 2016-12-09 03:35:46 | [diff] [blame] | 4513 | |
Michael Giuffrida | 6802ffe | 2017-09-29 03:40:25 | [diff] [blame] | 4514 | base::FilePath ChromeContentBrowserClient::GetLoggingFileName( |
| 4515 | const base::CommandLine& command_line) { |
| 4516 | return logging::GetLogFileName(command_line); |
kerrnel | a67fad5 | 2017-06-14 20:18:16 | [diff] [blame] | 4517 | } |
| 4518 | |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4519 | namespace { |
| 4520 | // TODO(jam): move this to a separate file. |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4521 | class ProtocolHandlerThrottle : public blink::URLLoaderThrottle { |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4522 | public: |
| 4523 | explicit ProtocolHandlerThrottle( |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4524 | ProtocolHandlerRegistry* protocol_handler_registry) |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4525 | : protocol_handler_registry_(protocol_handler_registry) {} |
| 4526 | ~ProtocolHandlerThrottle() override = default; |
| 4527 | |
| 4528 | void WillStartRequest(network::ResourceRequest* request, |
| 4529 | bool* defer) override { |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4530 | TranslateUrl(&request->url); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4531 | } |
| 4532 | |
| 4533 | void WillRedirectRequest(net::RedirectInfo* redirect_info, |
| 4534 | const network::ResourceResponseHead& response_head, |
| 4535 | bool* defer, |
| 4536 | std::vector<std::string>* to_be_removed_headers, |
| 4537 | net::HttpRequestHeaders* modified_headers) override { |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4538 | TranslateUrl(&redirect_info->new_url); |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4539 | } |
| 4540 | |
| 4541 | private: |
Robbie McElrath | 16aaed6c | 2019-06-04 00:50:29 | [diff] [blame] | 4542 | void TranslateUrl(GURL* url) { |
| 4543 | if (!protocol_handler_registry_->IsHandledProtocol(url->scheme())) |
| 4544 | return; |
| 4545 | GURL translated_url = protocol_handler_registry_->Translate(*url); |
| 4546 | if (!translated_url.is_empty()) |
| 4547 | *url = translated_url; |
| 4548 | } |
| 4549 | |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4550 | ProtocolHandlerRegistry* protocol_handler_registry_; |
John Abd-El-Malek | 8efa11f | 2019-01-06 00:51:53 | [diff] [blame] | 4551 | }; |
| 4552 | } // namespace |
| 4553 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4554 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4555 | ChromeContentBrowserClient::CreateURLLoaderThrottles( |
| 4556 | const network::ResourceRequest& request, |
| 4557 | content::BrowserContext* browser_context, |
| 4558 | const base::RepeatingCallback<content::WebContents*()>& wc_getter, |
| 4559 | content::NavigationUIData* navigation_ui_data, |
| 4560 | int frame_tree_node_id) { |
| 4561 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 4562 | |
Minggang Wang | f6840ecf | 2019-07-29 05:15:02 | [diff] [blame] | 4563 | std::vector<std::unique_ptr<blink::URLLoaderThrottle>> result; |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4564 | |
| 4565 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 4566 | |
| 4567 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4568 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4569 | |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 4570 | auto* drp_settings = |
| 4571 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 4572 | browser_context); |
| 4573 | if (chrome_navigation_ui_data && !profile->IsIncognitoProfile() && |
| 4574 | data_reduction_proxy::params::IsEnabledWithNetworkService() && |
| 4575 | drp_settings) { |
| 4576 | if (!data_reduction_proxy_throttle_manager_) { |
| 4577 | data_reduction_proxy_throttle_manager_ = std::unique_ptr< |
| 4578 | data_reduction_proxy::DataReductionProxyThrottleManager, |
| 4579 | base::OnTaskRunnerDeleter>( |
| 4580 | new data_reduction_proxy::DataReductionProxyThrottleManager( |
| 4581 | drp_settings->data_reduction_proxy_service(), |
| 4582 | data_reduction_proxy::DataReductionProxyThrottleManager:: |
Clark DuVall | 0e90172 | 2019-08-14 23:31:37 | [diff] [blame] | 4583 | CreateConfig(drp_settings->data_reduction_proxy_service() |
| 4584 | ->config() |
| 4585 | ->GetProxiesForHttp())), |
Clark DuVall | 68eb997f | 2019-06-28 05:42:28 | [diff] [blame] | 4586 | base::OnTaskRunnerDeleter(base::SequencedTaskRunnerHandle::Get())); |
| 4587 | } |
| 4588 | net::HttpRequestHeaders headers; |
| 4589 | data_reduction_proxy::DataReductionProxyRequestOptions:: |
| 4590 | AddPageIDRequestHeader( |
| 4591 | &headers, |
| 4592 | chrome_navigation_ui_data->data_reduction_proxy_page_id()); |
| 4593 | result.push_back(std::make_unique< |
| 4594 | data_reduction_proxy::DataReductionProxyURLLoaderThrottle>( |
| 4595 | headers, data_reduction_proxy_throttle_manager_.get())); |
| 4596 | } |
| 4597 | |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4598 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4599 | bool matches_enterprise_whitelist = safe_browsing::IsURLWhitelistedByPolicy( |
| 4600 | request.url, *profile->GetPrefs()); |
| 4601 | if (!matches_enterprise_whitelist) { |
| 4602 | result.push_back(safe_browsing::BrowserURLLoaderThrottle::Create( |
| 4603 | base::BindOnce( |
| 4604 | &ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate, |
| 4605 | base::Unretained(this)), |
| 4606 | wc_getter, frame_tree_node_id, profile->GetResourceContext())); |
| 4607 | } |
Nico Weber | bc5b06f | 2019-07-26 14:00:13 | [diff] [blame] | 4608 | #endif |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 4609 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4610 | if (chrome_navigation_ui_data && |
| 4611 | chrome_navigation_ui_data->prerender_mode() != prerender::NO_PRERENDER) { |
| 4612 | result.push_back(std::make_unique<prerender::PrerenderURLLoaderThrottle>( |
| 4613 | chrome_navigation_ui_data->prerender_mode(), |
| 4614 | chrome_navigation_ui_data->prerender_histogram_prefix(), |
| 4615 | base::BindOnce(GetPrerenderCanceller, wc_getter), |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 4616 | base::CreateSingleThreadTaskRunner({BrowserThread::UI}))); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4617 | } |
| 4618 | |
David Roger | e8e83f3c | 2019-09-12 10:56:23 | [diff] [blame] | 4619 | signin::IdentityManager* identity_manager = |
| 4620 | IdentityManagerFactory::GetForProfile(profile); |
| 4621 | bool is_signed_in = identity_manager && identity_manager->HasPrimaryAccount(); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4622 | |
| 4623 | chrome::mojom::DynamicParams dynamic_params = { |
| 4624 | profile->GetPrefs()->GetBoolean(prefs::kForceGoogleSafeSearch), |
| 4625 | profile->GetPrefs()->GetInteger(prefs::kForceYouTubeRestrict), |
| 4626 | profile->GetPrefs()->GetString(prefs::kAllowedDomainsForApps), |
| 4627 | variations::VariationsHttpHeaderProvider::GetInstance() |
| 4628 | ->GetClientDataHeader(is_signed_in)}; |
| 4629 | result.push_back(std::make_unique<GoogleURLLoaderThrottle>( |
David Roger | e8e83f3c | 2019-09-12 10:56:23 | [diff] [blame] | 4630 | profile->IsOffTheRecord(), std::move(dynamic_params))); |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4631 | |
Clark DuVall | a411bda | 2019-08-02 03:09:17 | [diff] [blame] | 4632 | result.push_back(std::make_unique<ProtocolHandlerThrottle>( |
| 4633 | ProtocolHandlerRegistryFactory::GetForBrowserContext(browser_context))); |
Clark DuVall | 8512cee6 | 2019-06-26 01:14:21 | [diff] [blame] | 4634 | |
Clark DuVall | 39c2cfc | 2019-06-25 21:49:28 | [diff] [blame] | 4635 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 4636 | result.push_back(std::make_unique<PluginResponseInterceptorURLLoaderThrottle>( |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 4637 | request.resource_type, frame_tree_node_id)); |
Clark DuVall | 39c2cfc | 2019-06-25 21:49:28 | [diff] [blame] | 4638 | #endif |
| 4639 | |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 4640 | auto delegate = |
Robbie McElrath | 38f47af | 2019-09-19 21:51:40 | [diff] [blame] | 4641 | std::make_unique<signin::HeaderModificationDelegateImpl>(profile); |
Robbie McElrath | 127ad2b | 2019-07-22 22:38:11 | [diff] [blame] | 4642 | auto signin_throttle = signin::URLLoaderThrottle::MaybeCreate( |
| 4643 | std::move(delegate), navigation_ui_data, wc_getter); |
| 4644 | if (signin_throttle) |
| 4645 | result.push_back(std::move(signin_throttle)); |
| 4646 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 4647 | return result; |
| 4648 | } |
| 4649 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4650 | void ChromeContentBrowserClient::RegisterNonNetworkNavigationURLLoaderFactories( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4651 | int frame_tree_node_id, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4652 | NonNetworkURLLoaderFactoryMap* factories) { |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4653 | #if BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4654 | content::WebContents* web_contents = |
| 4655 | content::WebContents::FromFrameTreeNodeId(frame_tree_node_id); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4656 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4657 | factories->emplace( |
| 4658 | extensions::kExtensionScheme, |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 4659 | extensions::CreateExtensionNavigationURLLoaderFactory( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4660 | web_contents->GetBrowserContext(), |
| 4661 | !!extensions::WebViewGuest::FromWebContents(web_contents))); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4662 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 4663 | #if defined(OS_CHROMEOS) |
| 4664 | Profile* profile = |
| 4665 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Robbie McElrath | 89cc933 | 2019-03-05 02:12:30 | [diff] [blame] | 4666 | factories->emplace(content::kExternalFileScheme, |
| 4667 | std::make_unique<chromeos::ExternalFileURLLoaderFactory>( |
| 4668 | profile, content::ChildProcessHost::kInvalidUniqueID)); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4669 | #endif // defined(OS_CHROMEOS) |
| 4670 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) || defined(OS_CHROMEOS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4671 | } |
| 4672 | |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4673 | void ChromeContentBrowserClient:: |
| 4674 | RegisterNonNetworkServiceWorkerUpdateURLLoaderFactories( |
| 4675 | content::BrowserContext* browser_context, |
| 4676 | NonNetworkURLLoaderFactoryMap* factories) { |
Hiroki Nakagawa | d5e7e89d8 | 2019-09-11 09:42:11 | [diff] [blame] | 4677 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4678 | DCHECK(browser_context); |
| 4679 | DCHECK(factories); |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4680 | factories->emplace( |
| 4681 | extensions::kExtensionScheme, |
| 4682 | extensions::CreateExtensionServiceWorkerScriptURLLoaderFactory( |
| 4683 | browser_context)); |
| 4684 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Ting Shao | 2dc6058 | 2019-07-15 04:43:36 | [diff] [blame] | 4685 | } |
| 4686 | |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4687 | namespace { |
| 4688 | |
| 4689 | // The FileURLLoaderFactory provided to the extension background pages. |
| 4690 | // Checks with the ChildProcessSecurityPolicy to validate the file access. |
| 4691 | class FileURLLoaderFactory : public network::mojom::URLLoaderFactory { |
| 4692 | public: |
| 4693 | explicit FileURLLoaderFactory(int child_id) : child_id_(child_id) {} |
| 4694 | |
| 4695 | private: |
| 4696 | // network::mojom::URLLoaderFactory: |
| 4697 | void CreateLoaderAndStart(network::mojom::URLLoaderRequest loader, |
| 4698 | int32_t routing_id, |
| 4699 | int32_t request_id, |
| 4700 | uint32_t options, |
| 4701 | const network::ResourceRequest& request, |
| 4702 | network::mojom::URLLoaderClientPtr client, |
| 4703 | const net::MutableNetworkTrafficAnnotationTag& |
| 4704 | traffic_annotation) override { |
| 4705 | if (!content::ChildProcessSecurityPolicy::GetInstance()->CanRequestURL( |
| 4706 | child_id_, request.url)) { |
| 4707 | client->OnComplete( |
| 4708 | network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED)); |
| 4709 | return; |
| 4710 | } |
| 4711 | content::CreateFileURLLoader(request, std::move(loader), std::move(client), |
John Abd-El-Malek | 916f2b8 | 2019-02-19 23:49:45 | [diff] [blame] | 4712 | /*observer=*/nullptr, |
| 4713 | /* allow_directory_listing */ true); |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | void Clone(network::mojom::URLLoaderFactoryRequest loader) override { |
| 4717 | bindings_.AddBinding(this, std::move(loader)); |
| 4718 | } |
| 4719 | |
| 4720 | int child_id_; |
| 4721 | mojo::BindingSet<network::mojom::URLLoaderFactory> bindings_; |
| 4722 | DISALLOW_COPY_AND_ASSIGN(FileURLLoaderFactory); |
| 4723 | }; |
| 4724 | |
| 4725 | } // namespace |
| 4726 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4727 | void ChromeContentBrowserClient:: |
| 4728 | RegisterNonNetworkSubresourceURLLoaderFactories( |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4729 | int render_process_id, |
| 4730 | int render_frame_id, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4731 | NonNetworkURLLoaderFactoryMap* factories) { |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4732 | #if defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS) |
| 4733 | content::RenderFrameHost* frame_host = |
| 4734 | RenderFrameHost::FromID(render_process_id, render_frame_id); |
| 4735 | WebContents* web_contents = WebContents::FromRenderFrameHost(frame_host); |
| 4736 | #endif // defined(OS_CHROMEOS) || BUILDFLAG(ENABLE_EXTENSIONS) |
| 4737 | |
| 4738 | #if defined(OS_CHROMEOS) |
| 4739 | if (web_contents) { |
| 4740 | Profile* profile = |
| 4741 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
Robbie McElrath | 89cc933 | 2019-03-05 02:12:30 | [diff] [blame] | 4742 | factories->emplace(content::kExternalFileScheme, |
| 4743 | std::make_unique<chromeos::ExternalFileURLLoaderFactory>( |
| 4744 | profile, render_process_id)); |
Robbie McElrath | 6a45ea6 | 2018-12-05 06:53:41 | [diff] [blame] | 4745 | } |
| 4746 | #endif // defined(OS_CHROMEOS) |
| 4747 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4748 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4749 | auto factory = extensions::CreateExtensionURLLoaderFactory(render_process_id, |
| 4750 | render_frame_id); |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4751 | if (factory) |
| 4752 | factories->emplace(extensions::kExtensionScheme, std::move(factory)); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4753 | |
| 4754 | // This logic should match |
| 4755 | // ChromeExtensionWebContentsObserver::RenderFrameCreated. |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4756 | if (!web_contents) |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4757 | return; |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4758 | |
| 4759 | Profile* profile = |
| 4760 | Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 4761 | InstantService* instant_service = |
| 4762 | InstantServiceFactory::GetForProfile(profile); |
| 4763 | // The test below matches what's done by ShouldServiceRequestIOThread in |
| 4764 | // local_ntp_source.cc. |
John Abd-El-Malek | ea00630 | 2018-05-10 05:50:46 | [diff] [blame] | 4765 | if (instant_service->IsInstantProcess(render_process_id)) { |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4766 | factories->emplace( |
| 4767 | chrome::kChromeSearchScheme, |
| 4768 | content::CreateWebUIURLLoader( |
| 4769 | frame_host, chrome::kChromeSearchScheme, |
| 4770 | /*allowed_webui_hosts=*/base::flat_set<std::string>())); |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4771 | } |
Jay Civelli | c9bbf72d | 2018-03-24 01:58:31 | [diff] [blame] | 4772 | |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4773 | extensions::ChromeExtensionWebContentsObserver* web_observer = |
| 4774 | extensions::ChromeExtensionWebContentsObserver::FromWebContents( |
| 4775 | web_contents); |
| 4776 | |
Karan Bhatia | 9192857 | 2018-03-06 01:18:07 | [diff] [blame] | 4777 | // There is nothing to do if no ChromeExtensionWebContentsObserver is attached |
| 4778 | // to the |web_contents|. |
| 4779 | if (!web_observer) |
| 4780 | return; |
| 4781 | |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4782 | const Extension* extension = |
| 4783 | web_observer->GetExtensionFromFrame(frame_host, false); |
| 4784 | if (!extension) |
| 4785 | return; |
| 4786 | |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4787 | std::vector<std::string> allowed_webui_hosts; |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4788 | // Support for chrome:// scheme if appropriate. |
| 4789 | if ((extension->is_extension() || extension->is_platform_app()) && |
| 4790 | Manifest::IsComponentLocation(extension->location())) { |
| 4791 | // Components of chrome that are implemented as extensions or platform apps |
| 4792 | // are allowed to use chrome://resources/ and chrome://theme/ URLs. |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4793 | allowed_webui_hosts.emplace_back(content::kChromeUIResourcesHost); |
| 4794 | allowed_webui_hosts.emplace_back(chrome::kChromeUIThemeHost); |
| 4795 | } |
| 4796 | if (extension->is_extension() || extension->is_legacy_packaged_app() || |
| 4797 | (extension->is_platform_app() && |
| 4798 | Manifest::IsComponentLocation(extension->location()))) { |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4799 | // Extensions, legacy packaged apps, and component platform apps are allowed |
Lucas Tenório | 3dd8092 | 2019-03-27 03:51:02 | [diff] [blame] | 4800 | // to use chrome://favicon/, chrome://extension-icon/ and chrome://app-icon |
| 4801 | // URLs. Hosted apps are not allowed because they are served via web servers |
| 4802 | // (and are generally never given access to Chrome APIs). |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4803 | allowed_webui_hosts.emplace_back(chrome::kChromeUIExtensionIconHost); |
| 4804 | allowed_webui_hosts.emplace_back(chrome::kChromeUIFaviconHost); |
Lucas Tenório | 3dd8092 | 2019-03-27 03:51:02 | [diff] [blame] | 4805 | allowed_webui_hosts.emplace_back(chrome::kChromeUIAppIconHost); |
Sam McNally | 7414eeb7 | 2018-09-03 04:05:30 | [diff] [blame] | 4806 | } |
| 4807 | if (!allowed_webui_hosts.empty()) { |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4808 | factories->emplace( |
| 4809 | content::kChromeUIScheme, |
| 4810 | content::CreateWebUIURLLoader(frame_host, content::kChromeUIScheme, |
| 4811 | std::move(allowed_webui_hosts))); |
| 4812 | } |
Jay Civelli | 2578ebe | 2018-06-05 18:44:31 | [diff] [blame] | 4813 | |
| 4814 | // Extension with a background page get file access that gets approval from |
| 4815 | // ChildProcessSecurityPolicy. |
| 4816 | extensions::ExtensionHost* host = |
| 4817 | extensions::ProcessManager::Get(web_contents->GetBrowserContext()) |
| 4818 | ->GetBackgroundHostForExtension(extension->id()); |
| 4819 | if (host) { |
| 4820 | factories->emplace(url::kFileScheme, std::make_unique<FileURLLoaderFactory>( |
| 4821 | render_process_id)); |
| 4822 | } |
Chris Mumford | bae8a74 | 2018-03-01 23:02:23 | [diff] [blame] | 4823 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 4824 | } |
| 4825 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4826 | bool ChromeContentBrowserClient::WillCreateURLLoaderFactory( |
Ken Rockot | 428b1d6 | 2018-06-06 17:12:21 | [diff] [blame] | 4827 | content::BrowserContext* browser_context, |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4828 | content::RenderFrameHost* frame, |
Kenichi Ishibashi | 09ee5e7 | 2018-11-27 07:12:38 | [diff] [blame] | 4829 | int render_process_id, |
Karan Bhatia | 4a834b3 | 2019-08-16 22:26:44 | [diff] [blame] | 4830 | URLLoaderFactoryType type, |
Lukasz Anforowicz | 76273365 | 2018-09-28 14:48:26 | [diff] [blame] | 4831 | const url::Origin& request_initiator, |
Dominic Farolino | 1be897a | 2019-07-20 08:11:42 | [diff] [blame] | 4832 | mojo::PendingReceiver<network::mojom::URLLoaderFactory>* factory_receiver, |
Julie Jeongeun Kim | 47499a0c | 2019-08-28 07:23:18 | [diff] [blame] | 4833 | mojo::PendingRemote<network::mojom::TrustedURLLoaderHeaderClient>* |
| 4834 | header_client, |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4835 | bool* bypass_redirect_checks) { |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4836 | bool use_proxy = false; |
| 4837 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4838 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4839 | auto* web_request_api = |
| 4840 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
Ken Rockot | 428b1d6 | 2018-06-06 17:12:21 | [diff] [blame] | 4841 | browser_context); |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4842 | |
| 4843 | // NOTE: Some unit test environments do not initialize |
| 4844 | // BrowserContextKeyedAPI factories for e.g. WebRequest. |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4845 | if (web_request_api) { |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4846 | bool use_proxy_for_web_request = |
Kenichi Ishibashi | 09ee5e7 | 2018-11-27 07:12:38 | [diff] [blame] | 4847 | web_request_api->MaybeProxyURLLoaderFactory( |
Karan Bhatia | 4a834b3 | 2019-08-16 22:26:44 | [diff] [blame] | 4848 | browser_context, frame, render_process_id, type, factory_receiver, |
| 4849 | header_client); |
Clark DuVall | 8dc4e50 | 2018-09-07 01:51:12 | [diff] [blame] | 4850 | if (bypass_redirect_checks) |
| 4851 | *bypass_redirect_checks = use_proxy_for_web_request; |
| 4852 | use_proxy |= use_proxy_for_web_request; |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4853 | } |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4854 | #endif |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4855 | |
Reilly Grant | cc22e60 | 2018-09-07 15:25:20 | [diff] [blame] | 4856 | use_proxy |= signin::ProxyingURLLoaderFactory::MaybeProxyRequest( |
Karan Bhatia | 4a834b3 | 2019-08-16 22:26:44 | [diff] [blame] | 4857 | frame, type == URLLoaderFactoryType::kNavigation, request_initiator, |
| 4858 | factory_receiver); |
Reilly Grant | 24bf833 | 2018-08-27 21:55:01 | [diff] [blame] | 4859 | |
| 4860 | return use_proxy; |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4861 | } |
| 4862 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4863 | std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> |
| 4864 | ChromeContentBrowserClient::WillCreateURLLoaderRequestInterceptors( |
| 4865 | content::NavigationUIData* navigation_ui_data, |
Ryan Sturm | 27d93f41 | 2019-02-15 21:30:14 | [diff] [blame] | 4866 | int frame_tree_node_id, |
| 4867 | const scoped_refptr<network::SharedURLLoaderFactory>& |
| 4868 | network_loader_factory) { |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4869 | std::vector<std::unique_ptr<content::URLLoaderRequestInterceptor>> |
| 4870 | interceptors; |
| 4871 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 4872 | interceptors.push_back( |
| 4873 | std::make_unique<offline_pages::OfflinePageURLLoaderRequestInterceptor>( |
| 4874 | navigation_ui_data, frame_tree_node_id)); |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4875 | #endif |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 4876 | |
Robert Ogden | 3d5d5b4 | 2019-04-22 05:13:11 | [diff] [blame] | 4877 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 4878 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 4879 | |
Ryan Sturm | 27d93f41 | 2019-02-15 21:30:14 | [diff] [blame] | 4880 | // TODO(ryansturm): Once this is on the UI thread, stop passing |
| 4881 | // |network_loader_factory| and have interceptors create one themselves. |
| 4882 | // https://crbug.com/931786 |
John Abd-El-Malek | 7577f26 | 2019-06-10 21:23:23 | [diff] [blame] | 4883 | if (base::FeatureList::IsEnabled( |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 4884 | previews::features::kHTTPSServerPreviewsUsingURLLoader)) { |
| 4885 | interceptors.push_back( |
| 4886 | std::make_unique<previews::PreviewsLitePageURLLoaderInterceptor>( |
Robert Ogden | 3d5d5b4 | 2019-04-22 05:13:11 | [diff] [blame] | 4887 | network_loader_factory, |
| 4888 | chrome_navigation_ui_data->data_reduction_proxy_page_id(), |
| 4889 | frame_tree_node_id)); |
Ryan Sturm | af52374 | 2019-01-16 00:15:45 | [diff] [blame] | 4890 | } |
| 4891 | |
Jian Li | de7b4379 | 2018-06-01 23:22:13 | [diff] [blame] | 4892 | return interceptors; |
| 4893 | } |
| 4894 | |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4895 | bool ChromeContentBrowserClient::WillInterceptWebSocket( |
| 4896 | content::RenderFrameHost* frame) { |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4897 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4898 | if (!frame) { |
| 4899 | return false; |
| 4900 | } |
| 4901 | const auto* web_request_api = |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4902 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
| 4903 | frame->GetProcess()->GetBrowserContext()); |
| 4904 | |
| 4905 | // NOTE: Some unit test environments do not initialize |
| 4906 | // BrowserContextKeyedAPI factories for e.g. WebRequest. |
| 4907 | if (!web_request_api) |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4908 | return false; |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4909 | |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4910 | return web_request_api->MayHaveProxies(); |
| 4911 | #else |
| 4912 | return false; |
| 4913 | #endif |
| 4914 | } |
| 4915 | |
| 4916 | void ChromeContentBrowserClient::CreateWebSocket( |
| 4917 | content::RenderFrameHost* frame, |
| 4918 | WebSocketFactory factory, |
| 4919 | const GURL& url, |
| 4920 | const GURL& site_for_cookies, |
| 4921 | const base::Optional<std::string>& user_agent, |
Julie Jeongeun Kim | 3e973f9 | 2019-08-22 08:02:40 | [diff] [blame] | 4922 | mojo::PendingRemote<network::mojom::WebSocketHandshakeClient> |
| 4923 | handshake_client) { |
Yutaka Hirano | 8e0b4d43 | 2019-07-04 07:12:38 | [diff] [blame] | 4924 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4925 | if (!frame) { |
| 4926 | return; |
| 4927 | } |
| 4928 | auto* web_request_api = |
| 4929 | extensions::BrowserContextKeyedAPIFactory<extensions::WebRequestAPI>::Get( |
| 4930 | frame->GetProcess()->GetBrowserContext()); |
| 4931 | |
| 4932 | DCHECK(web_request_api); |
| 4933 | web_request_api->ProxyWebSocket(frame, std::move(factory), url, |
| 4934 | site_for_cookies, user_agent, |
| 4935 | std::move(handshake_client)); |
Yutaka Hirano | 36c9495 | 2018-05-30 21:33:33 | [diff] [blame] | 4936 | #endif |
| 4937 | } |
| 4938 | |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4939 | bool ChromeContentBrowserClient::WillCreateRestrictedCookieManager( |
Maks Orlovich | e7db7a2 | 2019-07-25 01:47:46 | [diff] [blame] | 4940 | network::mojom::RestrictedCookieManagerRole role, |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4941 | content::BrowserContext* browser_context, |
| 4942 | const url::Origin& origin, |
| 4943 | bool is_service_worker, |
| 4944 | int process_id, |
| 4945 | int routing_id, |
Julie Jeongeun Kim | d20f64b | 2019-08-26 04:13:03 | [diff] [blame] | 4946 | mojo::PendingReceiver<network::mojom::RestrictedCookieManager>* receiver) { |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4947 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 4948 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 4949 | if (origin.scheme() == extensions::kExtensionScheme) { |
Maks Orlovich | e7db7a2 | 2019-07-25 01:47:46 | [diff] [blame] | 4950 | DCHECK_EQ(network::mojom::RestrictedCookieManagerRole::SCRIPT, role); |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4951 | extensions::ChromeExtensionCookies::Get(browser_context) |
Julie Jeongeun Kim | d20f64b | 2019-08-26 04:13:03 | [diff] [blame] | 4952 | ->CreateRestrictedCookieManager(origin, std::move(*receiver)); |
Maks Orlovich | 710d5e3 | 2019-07-09 20:16:45 | [diff] [blame] | 4953 | return true; |
| 4954 | } |
| 4955 | #endif |
| 4956 | return false; |
| 4957 | } |
| 4958 | |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 4959 | void ChromeContentBrowserClient::OnNetworkServiceCreated( |
| 4960 | network::mojom::NetworkService* network_service) { |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4961 | PrefService* local_state; |
| 4962 | if (g_browser_process) { |
| 4963 | DCHECK(g_browser_process->local_state()); |
| 4964 | local_state = g_browser_process->local_state(); |
| 4965 | } else { |
Xi Han | 85079c2 | 2019-04-18 21:43:05 | [diff] [blame] | 4966 | DCHECK(startup_data_->chrome_feature_list_creator()->local_state()); |
| 4967 | local_state = startup_data_->chrome_feature_list_creator()->local_state(); |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4968 | } |
| 4969 | |
| 4970 | if (!data_use_measurement::ChromeDataUseMeasurement::GetInstance()) |
| 4971 | data_use_measurement::ChromeDataUseMeasurement::CreateInstance(local_state); |
| 4972 | |
Henrique Nakashima | a3b1c5d | 2019-07-03 19:25:49 | [diff] [blame] | 4973 | // Create SystemNetworkContextManager if it has not been created yet. We need |
| 4974 | // to set up global NetworkService state before anything else uses it and this |
| 4975 | // is the first opportunity to initialize SystemNetworkContextManager with the |
| 4976 | // NetworkService. |
| 4977 | if (!SystemNetworkContextManager::HasInstance()) |
Henrique Nakashima | 8941aad | 2018-11-29 23:01:53 | [diff] [blame] | 4978 | SystemNetworkContextManager::CreateInstance(local_state); |
John Abd-El-Malek | 897374f4 | 2019-05-30 03:58:07 | [diff] [blame] | 4979 | |
Min Qin | 8caab1d | 2018-10-03 17:28:13 | [diff] [blame] | 4980 | SystemNetworkContextManager::GetInstance()->OnNetworkServiceCreated( |
Matt Menke | ae4fdb1 | 2018-06-02 06:32:54 | [diff] [blame] | 4981 | network_service); |
| 4982 | } |
| 4983 | |
Julie Jeongeun Kim | 5984e99 | 2019-09-11 11:00:46 | [diff] [blame] | 4984 | mojo::Remote<network::mojom::NetworkContext> |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4985 | ChromeContentBrowserClient::CreateNetworkContext( |
| 4986 | content::BrowserContext* context, |
| 4987 | bool in_memory, |
| 4988 | const base::FilePath& relative_partition_path) { |
John Abd-El-Malek | cc0b2a6 | 2018-03-20 19:32:50 | [diff] [blame] | 4989 | Profile* profile = Profile::FromBrowserContext(context); |
Matt Menke | d38efd9 | 2018-08-14 20:39:45 | [diff] [blame] | 4990 | return profile->CreateNetworkContext(in_memory, relative_partition_path); |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 4991 | } |
| 4992 | |
Robert Sesek | 34f68f31 | 2019-01-14 20:25:11 | [diff] [blame] | 4993 | std::vector<base::FilePath> |
| 4994 | ChromeContentBrowserClient::GetNetworkContextsParentDirectory() { |
Robert Sesek | 466e43e | 2019-08-19 22:02:02 | [diff] [blame] | 4995 | DCHECK(!network_contexts_parent_directory_.empty()); |
| 4996 | return network_contexts_parent_directory_; |
Robert Sesek | 34f68f31 | 2019-01-14 20:25:11 | [diff] [blame] | 4997 | } |
| 4998 | |
Min Qin | 75ed6df | 2017-12-01 20:39:15 | [diff] [blame] | 4999 | bool ChromeContentBrowserClient::AllowRenderingMhtmlOverHttp( |
Min Qin | 30a78a1 | 2017-12-06 01:29:13 | [diff] [blame] | 5000 | content::NavigationUIData* navigation_ui_data) { |
Min Qin | 75ed6df | 2017-12-01 20:39:15 | [diff] [blame] | 5001 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 5002 | // It is OK to load the saved offline copy, in MHTML format. |
| 5003 | ChromeNavigationUIData* chrome_navigation_ui_data = |
| 5004 | static_cast<ChromeNavigationUIData*>(navigation_ui_data); |
| 5005 | if (!chrome_navigation_ui_data) |
| 5006 | return false; |
| 5007 | offline_pages::OfflinePageNavigationUIData* offline_page_data = |
| 5008 | chrome_navigation_ui_data->GetOfflinePageNavigationUIData(); |
| 5009 | return offline_page_data && offline_page_data->is_offline_page(); |
| 5010 | #else |
| 5011 | return false; |
| 5012 | #endif |
| 5013 | } |
| 5014 | |
Min Qin | 30a78a1 | 2017-12-06 01:29:13 | [diff] [blame] | 5015 | bool ChromeContentBrowserClient::ShouldForceDownloadResource( |
| 5016 | const GURL& url, |
| 5017 | const std::string& mime_type) { |
| 5018 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5019 | // Special-case user scripts to get downloaded instead of viewed. |
| 5020 | return extensions::UserScript::IsURLUserScript(url, mime_type); |
| 5021 | #else |
| 5022 | return false; |
| 5023 | #endif |
| 5024 | } |
| 5025 | |
Donna Wu | 838ac36 | 2018-08-10 10:36:33 | [diff] [blame] | 5026 | void ChromeContentBrowserClient::CreateWebUsbService( |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5027 | content::RenderFrameHost* render_frame_host, |
Miyoung Shin | 6262215 | 2019-08-27 05:13:04 | [diff] [blame] | 5028 | mojo::PendingReceiver<blink::mojom::WebUsbService> receiver) { |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5029 | if (!base::FeatureList::IsEnabled(features::kWebUsb)) |
| 5030 | return; |
| 5031 | |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5032 | WebContents* web_contents = |
| 5033 | WebContents::FromRenderFrameHost(render_frame_host); |
| 5034 | if (!web_contents) { |
| 5035 | NOTREACHED(); |
| 5036 | return; |
| 5037 | } |
| 5038 | |
| 5039 | UsbTabHelper* tab_helper = |
| 5040 | UsbTabHelper::GetOrCreateForWebContents(web_contents); |
Miyoung Shin | 6262215 | 2019-08-27 05:13:04 | [diff] [blame] | 5041 | tab_helper->CreateWebUsbService(render_frame_host, std::move(receiver)); |
Reilly Grant | c31b819 | 2017-12-15 19:54:34 | [diff] [blame] | 5042 | } |
| 5043 | |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 5044 | #if !defined(OS_ANDROID) |
| 5045 | content::SerialDelegate* ChromeContentBrowserClient::GetSerialDelegate() { |
| 5046 | if (!serial_delegate_) |
| 5047 | serial_delegate_ = std::make_unique<ChromeSerialDelegate>(); |
| 5048 | return serial_delegate_.get(); |
| 5049 | } |
Matt Reynolds | 93616f9b | 2019-06-07 01:28:52 | [diff] [blame] | 5050 | |
| 5051 | content::HidDelegate* ChromeContentBrowserClient::GetHidDelegate() { |
| 5052 | if (!hid_delegate_) |
| 5053 | hid_delegate_ = std::make_unique<ChromeHidDelegate>(); |
| 5054 | return hid_delegate_.get(); |
| 5055 | } |
Reilly Grant | 0d28232 | 2019-01-29 02:42:58 | [diff] [blame] | 5056 | |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 5057 | std::unique_ptr<content::AuthenticatorRequestClientDelegate> |
| 5058 | ChromeContentBrowserClient::GetWebAuthenticationRequestDelegate( |
Adam Langley | eeac87e | 2019-04-13 22:58:22 | [diff] [blame] | 5059 | content::RenderFrameHost* render_frame_host, |
| 5060 | const std::string& relying_party_id) { |
| 5061 | return AuthenticatorRequestScheduler::CreateRequestDelegate(render_frame_host, |
| 5062 | relying_party_id); |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 5063 | } |
Nina Satragno | 8c832df | 2019-07-29 15:59:39 | [diff] [blame] | 5064 | #endif |
Balazs Engedy | a7ff7098 | 2018-06-04 18:14:47 | [diff] [blame] | 5065 | |
Jun Cai | 9409ded | 2018-01-30 00:19:46 | [diff] [blame] | 5066 | std::unique_ptr<net::ClientCertStore> |
| 5067 | ChromeContentBrowserClient::CreateClientCertStore( |
| 5068 | content::ResourceContext* resource_context) { |
| 5069 | if (!resource_context) |
| 5070 | return nullptr; |
| 5071 | return ProfileIOData::FromResourceContext(resource_context) |
| 5072 | ->CreateClientCertStore(); |
| 5073 | } |
| 5074 | |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 5075 | std::unique_ptr<content::LoginDelegate> |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5076 | ChromeContentBrowserClient::CreateLoginDelegate( |
Emily Stark | f2c9bbd | 2019-04-09 17:08:58 | [diff] [blame] | 5077 | const net::AuthChallengeInfo& auth_info, |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 5078 | content::WebContents* web_contents, |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5079 | const content::GlobalRequestID& request_id, |
Jun Cai | 8e165d2 | 2018-05-14 19:21:24 | [diff] [blame] | 5080 | bool is_request_for_main_frame, |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5081 | const GURL& url, |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5082 | scoped_refptr<net::HttpResponseHeaders> response_headers, |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5083 | bool first_auth_attempt, |
Mark Pilgrim | 7cfcd11 | 2018-05-08 00:07:56 | [diff] [blame] | 5084 | LoginAuthRequiredCallback auth_required_callback) { |
Ken Rockot | 5f734e3 | 2018-06-13 01:41:03 | [diff] [blame] | 5085 | return CreateLoginPrompt( |
David Benjamin | eced01fc | 2019-02-27 18:29:02 | [diff] [blame] | 5086 | auth_info, web_contents, request_id, is_request_for_main_frame, url, |
Emily Stark | c5f1579 | 2019-05-19 17:24:20 | [diff] [blame] | 5087 | std::move(response_headers), LoginHandler::PRE_COMMIT, |
| 5088 | std::move(auth_required_callback)); |
Jun Cai | bc561f41 | 2018-02-28 18:41:39 | [diff] [blame] | 5089 | } |
| 5090 | |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5091 | bool ChromeContentBrowserClient::HandleExternalProtocol( |
| 5092 | const GURL& url, |
John Abd-El-Malek | 92bf360 | 2019-07-31 02:25:48 | [diff] [blame] | 5093 | content::WebContents::Getter web_contents_getter, |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5094 | int child_id, |
| 5095 | content::NavigationUIData* navigation_data, |
| 5096 | bool is_main_frame, |
| 5097 | ui::PageTransition page_transition, |
Tim Volodine | b24393f3 | 2018-11-16 18:45:45 | [diff] [blame] | 5098 | bool has_user_gesture, |
Clark DuVall | b6042ed3 | 2019-07-15 17:20:45 | [diff] [blame] | 5099 | network::mojom::URLLoaderFactoryPtr* out_factory) { |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5100 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5101 | // External protocols are disabled for guests. An exception is made for the |
| 5102 | // "mailto" protocol, so that pages that utilize it work properly in a |
| 5103 | // WebView. |
| 5104 | ChromeNavigationUIData* chrome_data = |
| 5105 | static_cast<ChromeNavigationUIData*>(navigation_data); |
| 5106 | if ((extensions::WebViewRendererState::GetInstance()->IsGuest(child_id) || |
| 5107 | (chrome_data && |
| 5108 | chrome_data->GetExtensionNavigationUIData()->is_web_view())) && |
| 5109 | !url.SchemeIs(url::kMailToScheme)) { |
| 5110 | return false; |
| 5111 | } |
| 5112 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 5113 | |
| 5114 | #if defined(OS_ANDROID) |
| 5115 | // Main frame external protocols are handled by |
| 5116 | // InterceptNavigationResourceThrottle. |
| 5117 | if (is_main_frame) |
| 5118 | return false; |
| 5119 | #endif // defined(ANDROID) |
| 5120 | |
Sami Kyostila | 5e1306d | 2019-08-14 11:01:29 | [diff] [blame] | 5121 | base::PostTask(FROM_HERE, {BrowserThread::UI}, |
| 5122 | base::BindOnce(&LaunchURL, url, web_contents_getter, |
| 5123 | page_transition, has_user_gesture)); |
John Abd-El-Malek | a67add8 | 2018-03-09 18:22:01 | [diff] [blame] | 5124 | return true; |
| 5125 | } |
| 5126 | |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5127 | std::unique_ptr<content::OverlayWindow> |
Jennifer Apacible | 6010b023 | 2018-04-12 23:35:28 | [diff] [blame] | 5128 | ChromeContentBrowserClient::CreateWindowForPictureInPicture( |
| 5129 | content::PictureInPictureWindowController* controller) { |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5130 | // Note: content::OverlayWindow::Create() is defined by platform-specific |
| 5131 | // implementation in chrome/browser/ui/views. This layering hack, which goes |
| 5132 | // through //content and ContentBrowserClient, allows us to work around the |
| 5133 | // dependency constraints that disallow directly calling |
| 5134 | // chrome/browser/ui/views code either from here or from other code in |
| 5135 | // chrome/browser. |
Jennifer Apacible | 6010b023 | 2018-04-12 23:35:28 | [diff] [blame] | 5136 | return content::OverlayWindow::Create(controller); |
Jennifer Apacible | 4f854a8 | 2018-04-06 22:22:11 | [diff] [blame] | 5137 | } |
| 5138 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 5139 | bool ChromeContentBrowserClient::IsSafeRedirectTarget( |
| 5140 | const GURL& url, |
| 5141 | content::BrowserContext* context) { |
| 5142 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5143 | if (url.SchemeIs(extensions::kExtensionScheme)) { |
| 5144 | const Extension* extension = extensions::ExtensionRegistry::Get(context) |
| 5145 | ->enabled_extensions() |
| 5146 | .GetByID(url.host()); |
| 5147 | if (!extension) |
| 5148 | return false; |
| 5149 | return extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible( |
| 5150 | extension, url.path()); |
| 5151 | } |
| 5152 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 5153 | return true; |
| 5154 | } |
| 5155 | |
Kunihiko Sakamoto | 19aa708 | 2019-02-25 03:14:43 | [diff] [blame] | 5156 | void ChromeContentBrowserClient::RegisterRendererPreferenceWatcher( |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5157 | content::BrowserContext* browser_context, |
Julie Jeongeun Kim | 6d8b749 | 2019-08-20 19:24:11 | [diff] [blame] | 5158 | mojo::PendingRemote<blink::mojom::RendererPreferenceWatcher> watcher) { |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5159 | Profile* profile = Profile::FromBrowserContext(browser_context); |
Kunihiko Sakamoto | 19aa708 | 2019-02-25 03:14:43 | [diff] [blame] | 5160 | PrefWatcher::Get(profile)->RegisterRendererPreferenceWatcher( |
| 5161 | std::move(watcher)); |
Makoto Shimazu | c750293 | 2018-08-15 02:12:56 | [diff] [blame] | 5162 | } |
| 5163 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5164 | // Static; handles rewriting Web UI URLs. |
| 5165 | bool ChromeContentBrowserClient::HandleWebUI( |
| 5166 | GURL* url, |
| 5167 | content::BrowserContext* browser_context) { |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 5168 | // Rewrite chrome://help to chrome://settings/help. |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5169 | if (url->SchemeIs(content::kChromeUIScheme) && |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 5170 | url->host() == chrome::kChromeUIHelpHost) { |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5171 | *url = ReplaceURLHostAndPath(*url, chrome::kChromeUISettingsHost, |
| 5172 | chrome::kChromeUIHelpHost); |
| 5173 | return true; // Return true to update the displayed URL. |
| 5174 | } |
| 5175 | |
Hector Carmona | 566a20b | 2019-09-13 22:44:42 | [diff] [blame] | 5176 | #if defined(OS_WIN) |
| 5177 | // TODO(crbug.com/1003960): Remove when issue is resolved. |
| 5178 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 5179 | url->host() == chrome::kChromeUIWelcomeWin10Host) { |
| 5180 | url::Replacements<char> replacements; |
| 5181 | replacements.SetHost( |
| 5182 | chrome::kChromeUIWelcomeHost, |
| 5183 | url::Component(0, strlen(chrome::kChromeUIWelcomeHost))); |
| 5184 | *url = url->ReplaceComponents(replacements); |
| 5185 | return true; |
| 5186 | } |
| 5187 | #endif // defined(OS_WIN) |
| 5188 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5189 | if (!ChromeWebUIControllerFactory::GetInstance()->UseWebUIForURL( |
| 5190 | browser_context, *url)) { |
| 5191 | return false; |
| 5192 | } |
| 5193 | |
| 5194 | #if defined(OS_CHROMEOS) |
| 5195 | // Special case : in ChromeOS in Guest mode bookmarks and history are |
| 5196 | // disabled for security reasons. New tab page explains the reasons, so |
| 5197 | // we redirect user to new tab page. |
| 5198 | if (user_manager::UserManager::Get()->IsLoggedInAsGuest()) { |
| 5199 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 5200 | (url->DomainIs(chrome::kChromeUIBookmarksHost) || |
| 5201 | url->DomainIs(chrome::kChromeUIHistoryHost))) { |
| 5202 | // Rewrite with new tab URL |
| 5203 | *url = GURL(chrome::kChromeUINewTabURL); |
| 5204 | } |
| 5205 | } |
| 5206 | #endif |
| 5207 | |
| 5208 | return true; |
| 5209 | } |
| 5210 | |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 5211 | bool ChromeContentBrowserClient::ShowPaymentHandlerWindow( |
| 5212 | content::BrowserContext* browser_context, |
| 5213 | const GURL& url, |
Anthony Vallee-Dubois | 98befeaa | 2018-01-18 16:31:32 | [diff] [blame] | 5214 | base::OnceCallback<void(bool, int, int)> callback) { |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 5215 | #if defined(OS_ANDROID) |
| 5216 | return false; |
| 5217 | #else |
| 5218 | payments::PaymentRequestDisplayManagerFactory::GetInstance() |
| 5219 | ->GetForBrowserContext(browser_context) |
| 5220 | ->ShowPaymentHandlerWindow(url, std::move(callback)); |
| 5221 | return true; |
| 5222 | #endif |
| 5223 | } |
| 5224 | |
Dan Beam | 141c4893 | 2019-08-22 02:29:39 | [diff] [blame] | 5225 | // static |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5226 | bool ChromeContentBrowserClient::HandleWebUIReverse( |
| 5227 | GURL* url, |
| 5228 | content::BrowserContext* browser_context) { |
Hector Carmona | 566a20b | 2019-09-13 22:44:42 | [diff] [blame] | 5229 | #if defined(OS_WIN) |
| 5230 | // TODO(crbug.com/1003960): Remove when issue is resolved. |
| 5231 | // No need to actually reverse-rewrite the URL, but return true to update the |
| 5232 | // displayed URL when rewriting chrome://welcome-win10 to chrome://welcome. |
| 5233 | if (url->SchemeIs(content::kChromeUIScheme) && |
| 5234 | url->host() == chrome::kChromeUIWelcomeHost) { |
| 5235 | return true; |
| 5236 | } |
| 5237 | #endif // defined(OS_WIN) |
| 5238 | |
dbeam | 25472e0c | 2017-06-23 19:02:31 | [diff] [blame] | 5239 | // No need to actually reverse-rewrite the URL, but return true to update the |
| 5240 | // displayed URL when rewriting chrome://help to chrome://settings/help. |
| 5241 | return url->SchemeIs(content::kChromeUIScheme) && |
| 5242 | url->host() == chrome::kChromeUISettingsHost; |
| 5243 | } |
| 5244 | |
Dan Beam | f0a7e11 | 2019-06-07 18:40:58 | [diff] [blame] | 5245 | const ui::NativeTheme* ChromeContentBrowserClient::GetWebTheme() const { |
| 5246 | return ui::NativeTheme::GetInstanceForWeb(); |
| 5247 | } |
| 5248 | |
scottmg | de42fb9 | 2017-02-10 17:56:03 | [diff] [blame] | 5249 | // static |
michaeln | 10e5fc35 | 2017-02-07 02:07:58 | [diff] [blame] | 5250 | void ChromeContentBrowserClient::SetDefaultQuotaSettingsForTesting( |
| 5251 | const storage::QuotaSettings* settings) { |
| 5252 | g_default_quota_settings = settings; |
| 5253 | } |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5254 | |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 5255 | scoped_refptr<safe_browsing::UrlCheckerDelegate> |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 5256 | ChromeContentBrowserClient::GetSafeBrowsingUrlCheckerDelegate( |
| 5257 | content::ResourceContext* resource_context) { |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5258 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 5259 | |
Yuzhu Shen | cb3011f6 | 2018-02-08 02:51:50 | [diff] [blame] | 5260 | ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context); |
| 5261 | if (!io_data->safe_browsing_enabled()->GetValue()) |
| 5262 | return nullptr; |
| 5263 | |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5264 | // |safe_browsing_service_| may be unavailable in tests. |
| 5265 | if (safe_browsing_service_ && !safe_browsing_url_checker_delegate_) { |
| 5266 | safe_browsing_url_checker_delegate_ = |
Jialiu Lin | 0de6756c | 2018-03-22 00:57:43 | [diff] [blame] | 5267 | base::MakeRefCounted<safe_browsing::UrlCheckerDelegateImpl>( |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5268 | safe_browsing_service_->database_manager(), |
Jialiu Lin | 0de6756c | 2018-03-22 00:57:43 | [diff] [blame] | 5269 | safe_browsing_service_->ui_manager()); |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5270 | } |
| 5271 | |
Clark DuVall | 5497288d | 2019-07-17 00:17:56 | [diff] [blame] | 5272 | return safe_browsing_url_checker_delegate_; |
Yuzhu Shen | 44094e2 | 2017-07-18 22:52:35 | [diff] [blame] | 5273 | } |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 5274 | |
| 5275 | base::Optional<std::string> |
| 5276 | ChromeContentBrowserClient::GetOriginPolicyErrorPage( |
Andy Paicu | 8b6f871 | 2019-07-16 15:02:26 | [diff] [blame] | 5277 | network::OriginPolicyState error_reason, |
Daniel Vogelheim | 7badd0d | 2019-02-04 14:42:18 | [diff] [blame] | 5278 | content::NavigationHandle* handle) { |
| 5279 | return security_interstitials::OriginPolicyUI::GetErrorPageAsHTML( |
| 5280 | error_reason, handle); |
Daniel Vogelheim | 6008f57 | 2018-09-24 14:35:14 | [diff] [blame] | 5281 | } |
Kunihiko Sakamoto | 73b803d | 2018-10-05 09:09:52 | [diff] [blame] | 5282 | |
Takashi Toyoshima | 5af383aa | 2019-07-22 15:24:22 | [diff] [blame] | 5283 | bool ChromeContentBrowserClient::CanAcceptUntrustedExchangesIfNeeded() { |
Kunihiko Sakamoto | 73b803d | 2018-10-05 09:09:52 | [diff] [blame] | 5284 | // We require --user-data-dir flag too so that no dangerous changes are made |
| 5285 | // in the user's regular profile. |
| 5286 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 5287 | switches::kUserDataDir); |
| 5288 | } |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 5289 | |
| 5290 | void ChromeContentBrowserClient::OnNetworkServiceDataUseUpdate( |
| 5291 | int32_t network_traffic_annotation_id_hash, |
| 5292 | int64_t recv_bytes, |
| 5293 | int64_t sent_bytes) { |
Min Qin | cafb27b | 2018-10-30 18:02:03 | [diff] [blame] | 5294 | if (data_use_measurement::ChromeDataUseMeasurement::GetInstance()) { |
| 5295 | data_use_measurement::ChromeDataUseMeasurement::GetInstance() |
| 5296 | ->ReportNetworkServiceDataUse(network_traffic_annotation_id_hash, |
| 5297 | recv_bytes, sent_bytes); |
rajendrant | feea859 | 2018-10-19 18:26:06 | [diff] [blame] | 5298 | } |
| 5299 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5300 | |
| 5301 | content::PreviewsState ChromeContentBrowserClient::DetermineAllowedPreviews( |
| 5302 | content::PreviewsState initial_state, |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5303 | content::NavigationHandle* navigation_handle, |
| 5304 | const GURL& current_navigation_url) { |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5305 | content::PreviewsState state = DetermineAllowedPreviewsWithoutHoldback( |
| 5306 | initial_state, navigation_handle, current_navigation_url); |
| 5307 | |
| 5308 | return previews::MaybeCoinFlipHoldbackBeforeCommit(state, navigation_handle); |
| 5309 | } |
| 5310 | |
| 5311 | content::PreviewsState |
| 5312 | ChromeContentBrowserClient::DetermineAllowedPreviewsWithoutHoldback( |
| 5313 | content::PreviewsState initial_state, |
| 5314 | content::NavigationHandle* navigation_handle, |
| 5315 | const GURL& current_navigation_url) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5316 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
Tarun Bansal | b89c1d5 | 2019-01-16 06:56:29 | [diff] [blame] | 5317 | DCHECK(!navigation_handle->HasCommitted()); |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5318 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5319 | // If this is not a main frame, return the initial state. If there are no |
| 5320 | // previews in the state, return the state as is. |
| 5321 | if (!navigation_handle->IsInMainFrame() || |
| 5322 | navigation_handle->IsSameDocument()) { |
| 5323 | return initial_state; |
| 5324 | } |
| 5325 | |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5326 | if (!current_navigation_url.SchemeIsHTTPOrHTTPS()) |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5327 | return content::PREVIEWS_OFF; |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5328 | |
Doug Arnett | b3b99bc | 2019-08-09 16:55:56 | [diff] [blame] | 5329 | // Check if initial state specifies no previews should be considered. |
| 5330 | if (initial_state == content::PREVIEWS_OFF) |
| 5331 | return initial_state; |
| 5332 | |
Robert Ogden | a994eb4 | 2019-02-14 19:15:08 | [diff] [blame] | 5333 | // Do not allow previews on POST navigations since the primary opt-out |
| 5334 | // mechanism is to reload the page. Because POST navigations are not |
| 5335 | // idempotent, we do not want to show a preview on a POST navigation where |
| 5336 | // opting out would cause another navigation, i.e.: a reload. |
| 5337 | if (navigation_handle->IsPost()) |
| 5338 | return content::PREVIEWS_OFF; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5339 | |
| 5340 | content::WebContents* web_contents = navigation_handle->GetWebContents(); |
| 5341 | content::WebContentsDelegate* delegate = web_contents->GetDelegate(); |
| 5342 | |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5343 | auto* browser_context = web_contents->GetBrowserContext(); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5344 | |
| 5345 | PreviewsService* previews_service = PreviewsServiceFactory::GetForProfile( |
| 5346 | Profile::FromBrowserContext(browser_context)); |
| 5347 | auto* data_reduction_proxy_settings = |
| 5348 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 5349 | browser_context); |
| 5350 | // If the profile does not support previews or Data Saver, do not turn on |
| 5351 | // Previews. |
| 5352 | if (!previews_service || !previews_service->previews_ui_service() || |
Owen Min | 08a7289 | 2019-07-31 20:03:35 | [diff] [blame] | 5353 | !data_reduction_proxy_settings) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5354 | return content::PREVIEWS_OFF; |
| 5355 | } |
| 5356 | |
| 5357 | PreviewsUITabHelper* ui_tab_helper = |
Ryan Sturm | da2a0e0 | 2018-10-25 01:52:21 | [diff] [blame] | 5358 | PreviewsUITabHelper::FromWebContents(web_contents); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5359 | // If this tab does not have a PreviewsUITabHelper, no preview should be |
| 5360 | // served. |
| 5361 | if (!ui_tab_helper) |
| 5362 | return content::PREVIEWS_OFF; |
| 5363 | |
| 5364 | DCHECK(!browser_context->IsOffTheRecord()); |
| 5365 | |
| 5366 | // Other previews objects should all exist and be initialized if we have made |
| 5367 | // it past earlier checks. |
| 5368 | previews::PreviewsDeciderImpl* previews_decider_impl = |
| 5369 | previews_service->previews_ui_service()->previews_decider_impl(); |
| 5370 | DCHECK(previews_decider_impl); |
| 5371 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5372 | // Start with an unspecified state. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5373 | content::PreviewsState previews_state = content::PREVIEWS_UNSPECIFIED; |
| 5374 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5375 | previews::PreviewsUserData* previews_data = |
| 5376 | ui_tab_helper->GetPreviewsUserData(navigation_handle); |
| 5377 | |
| 5378 | // Certain PreviewsStates are used within URLLoaders (Offline, server |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5379 | // previews) and cannot re-evaluate PreviewsState once previews triggering |
| 5380 | // logic has already been run, so they should not change. Assume that |
| 5381 | // previews triggering logic has run when PreviewsUserData already exists and |
| 5382 | // a Lite Page Redirect preview is not being attempted, since it may also |
| 5383 | // create a previews_data before this point. |
| 5384 | bool previews_triggering_logic_already_ran = false; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5385 | if (previews_data) { |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5386 | previews_triggering_logic_already_ran = |
| 5387 | !previews_data->server_lite_page_info(); |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5388 | } else { |
| 5389 | previews_data = ui_tab_helper->CreatePreviewsUserDataForNavigationHandle( |
| 5390 | navigation_handle, previews_decider_impl->GeneratePageId()); |
| 5391 | } |
| 5392 | |
| 5393 | DCHECK(previews_data); |
| 5394 | |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 5395 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 5396 | previews::switches::kForceEnablePreviews)) { |
Sophie Chang | acd9e2d | 2019-08-22 22:05:09 | [diff] [blame] | 5397 | previews_decider_impl->LoadPageHints(navigation_handle); |
Robert Ogden | 01770b36 | 2019-05-22 17:36:43 | [diff] [blame] | 5398 | return content::ALL_SUPPORTED_PREVIEWS; |
| 5399 | } |
| 5400 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5401 | bool is_reload = |
| 5402 | navigation_handle->GetReloadType() != content::ReloadType::NONE; |
| 5403 | |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5404 | content::PreviewsState server_previews_enabled_state = |
Robert Ogden | 54bb4ff | 2019-06-19 01:31:51 | [diff] [blame] | 5405 | content::SERVER_LITE_PAGE_ON; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5406 | |
| 5407 | // For now, treat server previews types as a single decision, and do not |
| 5408 | // re-evaluate upon redirect. Plumbing does not exist to modify the CPAT |
| 5409 | // header, nor does the plumbing exist to modify the PreviewsState within the |
| 5410 | // URLLoader. |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5411 | if (previews_triggering_logic_already_ran) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5412 | // Copy the server state that was used before the redirect for the initial |
| 5413 | // URL. |
Robert Ogden | 869986f | 2019-06-20 19:12:05 | [diff] [blame] | 5414 | previews_state |= |
| 5415 | (previews_data->AllowedPreviewsState() & server_previews_enabled_state); |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5416 | } else { |
Doug Arnett | a3dc7158 | 2018-11-08 00:25:10 | [diff] [blame] | 5417 | if (previews_decider_impl->ShouldAllowPreviewAtNavigationStart( |
Sophie Chang | ff1fc38 | 2019-08-21 16:30:21 | [diff] [blame] | 5418 | previews_data, navigation_handle, is_reload, |
Doug Arnett | d5a6003 | 2018-11-12 19:37:30 | [diff] [blame] | 5419 | previews::PreviewsType::LITE_PAGE)) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5420 | previews_state |= server_previews_enabled_state; |
| 5421 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5422 | } |
| 5423 | |
Robert Ogden | 198d657 | 2019-06-26 15:15:33 | [diff] [blame] | 5424 | // Evaluate Offline, NoScript, and ResourceBlocking previews. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5425 | previews_state |= previews::DetermineAllowedClientPreviewsState( |
Sean | ac57e9b9 | 2019-04-29 19:19:31 | [diff] [blame] | 5426 | previews_data, previews_triggering_logic_already_ran, |
Owen Min | 08a7289 | 2019-07-31 20:03:35 | [diff] [blame] | 5427 | data_reduction_proxy_settings->IsDataReductionProxyEnabled(), |
| 5428 | previews_decider_impl, navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5429 | |
| 5430 | if (previews_state & content::PREVIEWS_OFF) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5431 | previews_data->set_allowed_previews_state(content::PREVIEWS_OFF); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5432 | return content::PREVIEWS_OFF; |
| 5433 | } |
| 5434 | |
| 5435 | if (previews_state & content::PREVIEWS_NO_TRANSFORM) { |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5436 | previews_data->set_allowed_previews_state(content::PREVIEWS_NO_TRANSFORM); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5437 | return content::PREVIEWS_NO_TRANSFORM; |
| 5438 | } |
| 5439 | |
| 5440 | // At this point, if no Preview is allowed, don't allow previews. |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5441 | if (previews_state == content::PREVIEWS_UNSPECIFIED) { |
| 5442 | previews_data->set_allowed_previews_state(content::PREVIEWS_OFF); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5443 | return content::PREVIEWS_OFF; |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5444 | } |
| 5445 | |
| 5446 | content::PreviewsState embedder_state = content::PREVIEWS_UNSPECIFIED; |
| 5447 | if (delegate) { |
| 5448 | delegate->AdjustPreviewsStateForNavigation(web_contents, &embedder_state); |
| 5449 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5450 | |
| 5451 | // If the allowed previews are limited by the embedder, ensure previews honors |
| 5452 | // those limits. |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5453 | if (embedder_state != content::PREVIEWS_UNSPECIFIED) { |
| 5454 | previews_state = previews_state & embedder_state; |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5455 | // If no valid previews are left, set the state explicitly to PREVIEWS_OFF. |
| 5456 | if (previews_state == content::PREVIEWS_UNSPECIFIED) |
| 5457 | previews_state = content::PREVIEWS_OFF; |
| 5458 | } |
Ryan Sturm | 647d1d9 | 2018-11-07 15:41:39 | [diff] [blame] | 5459 | previews_data->set_allowed_previews_state(previews_state); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5460 | return previews_state; |
| 5461 | } |
| 5462 | |
| 5463 | // static |
| 5464 | content::PreviewsState |
| 5465 | ChromeContentBrowserClient::DetermineCommittedPreviewsForURL( |
| 5466 | const GURL& url, |
| 5467 | data_reduction_proxy::DataReductionProxyData* drp_data, |
| 5468 | previews::PreviewsUserData* previews_user_data, |
| 5469 | const previews::PreviewsDecider* previews_decider, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5470 | content::PreviewsState initial_state, |
| 5471 | content::NavigationHandle* navigation_handle) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5472 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 5473 | if (!previews::HasEnabledPreviews(initial_state)) |
| 5474 | return content::PREVIEWS_OFF; |
| 5475 | |
| 5476 | // Check if the server sent a preview directive. |
| 5477 | content::PreviewsState previews_state = |
Clark DuVall | 0ec5214 | 2019-06-06 19:53:55 | [diff] [blame] | 5478 | previews::DetermineCommittedServerPreviewsState(drp_data, initial_state); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5479 | |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5480 | // Check the various other client previews types. |
| 5481 | return previews::DetermineCommittedClientPreviewsState( |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5482 | previews_user_data, url, previews_state, previews_decider, |
| 5483 | navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | content::PreviewsState ChromeContentBrowserClient::DetermineCommittedPreviews( |
| 5487 | content::PreviewsState initial_state, |
| 5488 | content::NavigationHandle* navigation_handle, |
| 5489 | const net::HttpResponseHeaders* response_headers) { |
Robert Ogden | 30bbc9d | 2019-04-30 20:15:13 | [diff] [blame] | 5490 | content::PreviewsState state = DetermineCommittedPreviewsWithoutHoldback( |
| 5491 | initial_state, navigation_handle, response_headers); |
| 5492 | |
| 5493 | return previews::MaybeCoinFlipHoldbackAfterCommit(state, navigation_handle); |
| 5494 | } |
| 5495 | |
| 5496 | content::PreviewsState |
| 5497 | ChromeContentBrowserClient::DetermineCommittedPreviewsWithoutHoldback( |
| 5498 | content::PreviewsState initial_state, |
| 5499 | content::NavigationHandle* navigation_handle, |
| 5500 | const net::HttpResponseHeaders* response_headers) { |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5501 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 5502 | // Only support HTTP and HTTPS. |
| 5503 | if (navigation_handle->IsErrorPage() || |
| 5504 | !navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()) { |
| 5505 | return content::PREVIEWS_OFF; |
| 5506 | } |
| 5507 | |
| 5508 | // If this is not a main frame, return the initial state. If there are no |
| 5509 | // previews in the state, return the state as is. |
| 5510 | if (!previews::HasEnabledPreviews(initial_state) || |
| 5511 | !navigation_handle->IsInMainFrame() || |
| 5512 | navigation_handle->IsSameDocument()) { |
| 5513 | return initial_state; |
| 5514 | } |
| 5515 | |
| 5516 | // WebContents that don't have a PreviewsUITabHelper are not supported. |
| 5517 | PreviewsUITabHelper* ui_tab_helper = |
| 5518 | PreviewsUITabHelper::FromWebContents(navigation_handle->GetWebContents()); |
| 5519 | if (!ui_tab_helper) |
| 5520 | return content::PREVIEWS_OFF; |
| 5521 | |
| 5522 | // If we did not previously create a PreviewsUserData, do not go any further. |
| 5523 | previews::PreviewsUserData* previews_user_data = |
| 5524 | ui_tab_helper->GetPreviewsUserData(navigation_handle); |
| 5525 | if (!previews_user_data) |
| 5526 | return content::PREVIEWS_OFF; |
| 5527 | |
| 5528 | PreviewsService* previews_service = |
| 5529 | PreviewsServiceFactory::GetForProfile(Profile::FromBrowserContext( |
| 5530 | navigation_handle->GetWebContents()->GetBrowserContext())); |
| 5531 | |
| 5532 | if (!previews_service || !previews_service->previews_ui_service()) |
| 5533 | return content::PREVIEWS_OFF; |
| 5534 | |
| 5535 | // Check if offline previews are being used and set it in the user data. |
| 5536 | #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 5537 | offline_pages::OfflinePageTabHelper* tab_helper = |
| 5538 | offline_pages::OfflinePageTabHelper::FromWebContents( |
| 5539 | navigation_handle->GetWebContents()); |
| 5540 | |
Ryan Sturm | fc7d92f | 2019-02-12 02:24:23 | [diff] [blame] | 5541 | bool is_offline_page = tab_helper && tab_helper->IsLoadingOfflinePage(); |
| 5542 | bool is_offline_preview = tab_helper && tab_helper->GetOfflinePreviewItem(); |
| 5543 | |
| 5544 | // If this is an offline page, but not a preview, then we should not attempt |
| 5545 | // any previews or surface the previews UI. |
| 5546 | if (is_offline_page && !is_offline_preview) |
| 5547 | return content::PREVIEWS_OFF; |
| 5548 | |
| 5549 | previews_user_data->set_offline_preview_used(is_offline_preview); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5550 | #endif // BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 5551 | |
| 5552 | // Annotate request if no-transform directive found in response headers. |
| 5553 | if (response_headers && |
| 5554 | response_headers->HasHeaderValue("cache-control", "no-transform")) { |
Jered Gray | ba1da12 | 2018-10-31 23:06:26 | [diff] [blame] | 5555 | previews_user_data->set_cache_control_no_transform_directive(); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5556 | } |
| 5557 | |
| 5558 | previews::PreviewsDeciderImpl* previews_decider_impl = |
| 5559 | previews_service->previews_ui_service()->previews_decider_impl(); |
| 5560 | DCHECK(previews_decider_impl); |
| 5561 | |
Clark DuVall | 9c5a72cc | 2018-10-25 01:29:21 | [diff] [blame] | 5562 | std::unique_ptr<data_reduction_proxy::DataReductionProxyData> drp_data; |
| 5563 | auto* settings = |
| 5564 | DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 5565 | navigation_handle->GetWebContents()->GetBrowserContext()); |
| 5566 | if (settings) { |
| 5567 | // TODO(898326): |drp_data| may be incomplete because |navigation_handle| |
| 5568 | // does not yet have all the response information. |
| 5569 | drp_data = settings->CreateDataFromNavigationHandle(navigation_handle, |
| 5570 | response_headers); |
| 5571 | } |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5572 | |
| 5573 | // Determine effective PreviewsState for this committed main frame response. |
| 5574 | content::PreviewsState committed_state = DetermineCommittedPreviewsForURL( |
Clark DuVall | 9c5a72cc | 2018-10-25 01:29:21 | [diff] [blame] | 5575 | navigation_handle->GetURL(), drp_data.get(), previews_user_data, |
Ryan Sturm | 737bd1d | 2019-02-28 01:38:05 | [diff] [blame] | 5576 | previews_decider_impl, initial_state, navigation_handle); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5577 | |
| 5578 | // Double check that we never serve a preview when we have a |
| 5579 | // cache-control:no-transform directive. |
| 5580 | DCHECK(!previews_user_data->cache_control_no_transform_directive() || |
| 5581 | !previews::HasEnabledPreviews(committed_state)); |
| 5582 | |
Robert Ogden | ded292c6f | 2019-05-03 22:44:51 | [diff] [blame] | 5583 | // TODO(robertogden): Consider moving this to after the holdback logic. |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5584 | previews_user_data->set_committed_previews_state(committed_state); |
| 5585 | |
| 5586 | previews::PreviewsType committed_type = |
| 5587 | previews::GetMainFramePreviewsType(committed_state); |
| 5588 | |
| 5589 | // Capture committed previews type, if any, in PreviewsUserData. |
| 5590 | // Note: this is for the subset of previews types that are decided upon |
| 5591 | // navigation commit. Previews types that are determined prior to |
| 5592 | // navigation (such as for offline pages or for redirecting to another |
| 5593 | // url), are not set here. |
| 5594 | previews_user_data->SetCommittedPreviewsType(committed_type); |
| 5595 | |
| 5596 | // Log the commit decision. |
| 5597 | std::vector<previews::PreviewsEligibilityReason> passed_reasons; |
| 5598 | previews_decider_impl->LogPreviewDecisionMade( |
| 5599 | (previews_user_data->cache_control_no_transform_directive() |
| 5600 | ? previews::PreviewsEligibilityReason::CACHE_CONTROL_NO_TRANSFORM |
| 5601 | : previews::PreviewsEligibilityReason::COMMITTED), |
| 5602 | navigation_handle->GetURL(), base::Time::Now(), |
Robert Ogden | 869986f | 2019-06-20 19:12:05 | [diff] [blame] | 5603 | previews_user_data->CommittedPreviewsType(), std::move(passed_reasons), |
Robert Ogden | 33e3631 | 2019-05-06 19:17:05 | [diff] [blame] | 5604 | previews_user_data); |
Ryan Sturm | aa05092f | 2018-10-21 03:56:54 | [diff] [blame] | 5605 | |
| 5606 | return committed_state; |
| 5607 | } |
Charlie Harrison | 650e1142 | 2018-12-04 00:37:26 | [diff] [blame] | 5608 | |
| 5609 | void ChromeContentBrowserClient::LogWebFeatureForCurrentPage( |
| 5610 | content::RenderFrameHost* render_frame_host, |
| 5611 | blink::mojom::WebFeature feature) { |
| 5612 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 5613 | page_load_metrics::mojom::PageLoadFeatures new_features({feature}, {}, {}); |
| 5614 | page_load_metrics::MetricsWebContentsObserver::RecordFeatureUsage( |
| 5615 | render_frame_host, new_features); |
| 5616 | } |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5617 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5618 | std::string ChromeContentBrowserClient::GetProduct() { |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5619 | return ::GetProduct(); |
| 5620 | } |
| 5621 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5622 | std::string ChromeContentBrowserClient::GetUserAgent() { |
Yutaka Hirano | 968d625 | 2018-12-04 05:09:31 | [diff] [blame] | 5623 | return ::GetUserAgent(); |
| 5624 | } |
Sam McNally | d54e23f9 | 2019-01-16 04:42:39 | [diff] [blame] | 5625 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5626 | blink::UserAgentMetadata ChromeContentBrowserClient::GetUserAgentMetadata() { |
Mike West | 6e4cbb3 | 2019-02-13 09:40:17 | [diff] [blame] | 5627 | return ::GetUserAgentMetadata(); |
| 5628 | } |
| 5629 | |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5630 | base::Optional<gfx::ImageSkia> ChromeContentBrowserClient::GetProductLogo() { |
Austin Orion | e250d01 | 2019-05-29 02:56:27 | [diff] [blame] | 5631 | // This icon is available on Android, but adds 19KiB to the APK. Since it |
| 5632 | // isn't used on Android we exclude it to avoid bloat. |
| 5633 | #if !defined(OS_ANDROID) |
| 5634 | return base::Optional<gfx::ImageSkia>( |
| 5635 | *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 5636 | IDR_PRODUCT_LOGO_256)); |
| 5637 | #else |
| 5638 | return base::nullopt; |
| 5639 | #endif |
| 5640 | } |
| 5641 | |
Sam McNally | d54e23f9 | 2019-01-16 04:42:39 | [diff] [blame] | 5642 | bool ChromeContentBrowserClient::IsBuiltinComponent( |
| 5643 | content::BrowserContext* browser_context, |
| 5644 | const url::Origin& origin) { |
| 5645 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 5646 | return ChromeContentBrowserClientExtensionsPart::IsBuiltinComponent( |
| 5647 | browser_context, origin); |
| 5648 | #else |
| 5649 | return false; |
| 5650 | #endif |
| 5651 | } |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 5652 | |
| 5653 | bool ChromeContentBrowserClient::IsRendererDebugURLBlacklisted( |
| 5654 | const GURL& url, |
| 5655 | content::BrowserContext* context) { |
| 5656 | PolicyBlacklistService* service = |
| 5657 | PolicyBlacklistFactory::GetForBrowserContext(context); |
| 5658 | |
| 5659 | using URLBlacklistState = policy::URLBlacklist::URLBlacklistState; |
| 5660 | URLBlacklistState blacklist_state = service->GetURLBlacklistState(url); |
| 5661 | return blacklist_state == URLBlacklistState::URL_IN_BLACKLIST; |
| 5662 | } |
Dominic Mazzoni | 21fb028 | 2019-02-13 18:32:47 | [diff] [blame] | 5663 | |
| 5664 | ui::AXMode ChromeContentBrowserClient::GetAXModeForBrowserContext( |
| 5665 | content::BrowserContext* browser_context) { |
| 5666 | Profile* profile = Profile::FromBrowserContext(browser_context); |
| 5667 | return AccessibilityLabelsServiceFactory::GetForProfile(profile)->GetAXMode(); |
| 5668 | } |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5669 | |
| 5670 | #if defined(OS_ANDROID) |
| 5671 | content::ContentBrowserClient::WideColorGamutHeuristic |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5672 | ChromeContentBrowserClient::GetWideColorGamutHeuristic() { |
Eric Karl | d6cd75b | 2019-03-14 22:01:36 | [diff] [blame] | 5673 | if (features::UseDisplayWideColorGamut()) { |
| 5674 | return WideColorGamutHeuristic::kUseDisplay; |
| 5675 | } |
| 5676 | return WideColorGamutHeuristic::kNone; |
| 5677 | } |
| 5678 | #endif |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5679 | |
| 5680 | base::flat_set<std::string> |
Ehsan Karamad | 466529d | 2019-05-24 03:24:43 | [diff] [blame] | 5681 | ChromeContentBrowserClient::GetPluginMimeTypesWithExternalHandlers( |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 5682 | content::BrowserContext* browser_context) { |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5683 | base::flat_set<std::string> mime_types; |
| 5684 | #if BUILDFLAG(ENABLE_PLUGINS) |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 5685 | auto map = PluginUtils::GetMimeTypeToExtensionIdMap(browser_context); |
Ehsan Karamad | 91413d7 | 2019-03-22 16:37:48 | [diff] [blame] | 5686 | for (const auto& pair : map) |
| 5687 | mime_types.insert(pair.first); |
| 5688 | #endif |
| 5689 | return mime_types; |
| 5690 | } |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5691 | |
| 5692 | void ChromeContentBrowserClient::AugmentNavigationDownloadPolicy( |
| 5693 | const content::WebContents* web_contents, |
| 5694 | const content::RenderFrameHost* frame_host, |
| 5695 | bool user_gesture, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5696 | content::NavigationDownloadPolicy* download_policy) { |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5697 | const ChromeSubresourceFilterClient* client = |
| 5698 | ChromeSubresourceFilterClient::FromWebContents(web_contents); |
| 5699 | if (client && client->GetThrottleManager()->IsFrameTaggedAsAd(frame_host)) { |
Yao Xiao | f6064666 | 2019-07-25 07:25:04 | [diff] [blame] | 5700 | download_policy->SetAllowed(content::NavigationDownloadType::kAdFrame); |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5701 | if (!user_gesture) { |
| 5702 | if (base::FeatureList::IsEnabled( |
| 5703 | blink::features:: |
| 5704 | kBlockingDownloadsInAdFrameWithoutUserActivation)) { |
| 5705 | download_policy->SetDisallowed( |
| 5706 | content::NavigationDownloadType::kAdFrameNoGesture); |
| 5707 | } else { |
| 5708 | download_policy->SetAllowed( |
| 5709 | content::NavigationDownloadType::kAdFrameNoGesture); |
| 5710 | } |
Yao Xiao | d06607b | 2019-05-02 23:16:36 | [diff] [blame] | 5711 | } |
| 5712 | } |
| 5713 | } |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5714 | |
| 5715 | bool ChromeContentBrowserClient::IsBluetoothScanningBlocked( |
| 5716 | content::BrowserContext* browser_context, |
| 5717 | const url::Origin& requesting_origin, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5718 | const url::Origin& embedding_origin) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5719 | const HostContentSettingsMap* const content_settings = |
| 5720 | HostContentSettingsMapFactory::GetForProfile( |
| 5721 | Profile::FromBrowserContext(browser_context)); |
| 5722 | |
| 5723 | if (content_settings->GetContentSetting( |
| 5724 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
| 5725 | CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING, |
| 5726 | std::string()) == CONTENT_SETTING_BLOCK) { |
| 5727 | return true; |
| 5728 | } |
| 5729 | |
| 5730 | return false; |
| 5731 | } |
| 5732 | |
| 5733 | void ChromeContentBrowserClient::BlockBluetoothScanning( |
| 5734 | content::BrowserContext* browser_context, |
| 5735 | const url::Origin& requesting_origin, |
Lucas Furukawa Gadani | 4909f3c | 2019-06-18 22:36:52 | [diff] [blame] | 5736 | const url::Origin& embedding_origin) { |
Jun Cai | 732a05e3 | 2019-05-29 19:34:19 | [diff] [blame] | 5737 | HostContentSettingsMap* const content_settings = |
| 5738 | HostContentSettingsMapFactory::GetForProfile( |
| 5739 | Profile::FromBrowserContext(browser_context)); |
| 5740 | |
| 5741 | content_settings->SetContentSettingDefaultScope( |
| 5742 | requesting_origin.GetURL(), embedding_origin.GetURL(), |
| 5743 | CONTENT_SETTINGS_TYPE_BLUETOOTH_SCANNING, std::string(), |
| 5744 | CONTENT_SETTING_BLOCK); |
| 5745 | } |