| 1 | // Copyright 2012 The Chromium Authors |
| 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/renderer/chrome_content_renderer_client.h" |
| 6 | |
| 7 | #include <functional> |
| 8 | #include <memory> |
| 9 | #include <string_view> |
| 10 | #include <utility> |
| 11 | |
| 12 | #include "base/check_op.h" |
| 13 | #include "base/command_line.h" |
| 14 | #include "base/debug/crash_logging.h" |
| 15 | #include "base/functional/bind.h" |
| 16 | #include "base/metrics/histogram_functions.h" |
| 17 | #include "base/metrics/histogram_macros.h" |
| 18 | #include "base/metrics/user_metrics_action.h" |
| 19 | #include "base/no_destructor.h" |
| 20 | #include "base/notreached.h" |
| 21 | #include "base/process/current_process.h" |
| 22 | #include "base/strings/string_number_conversions.h" |
| 23 | #include "base/strings/string_util.h" |
| 24 | #include "base/strings/utf_string_conversions.h" |
| 25 | #include "base/task/single_thread_task_runner.h" |
| 26 | #include "base/time/time.h" |
| 27 | #include "base/values.h" |
| 28 | #include "build/build_config.h" |
| 29 | #include "build/chromeos_buildflags.h" |
| 30 | #include "chrome/common/buildflags.h" |
| 31 | #include "chrome/common/channel_info.h" |
| 32 | #include "chrome/common/chrome_content_client.h" |
| 33 | #include "chrome/common/chrome_features.h" |
| 34 | #include "chrome/common/chrome_isolated_world_ids.h" |
| 35 | #include "chrome/common/chrome_paths.h" |
| 36 | #include "chrome/common/chrome_switches.h" |
| 37 | #include "chrome/common/crash_keys.h" |
| 38 | #include "chrome/common/pdf_util.h" |
| 39 | #include "chrome/common/pepper_permission_util.h" |
| 40 | #include "chrome/common/ppapi_utils.h" |
| 41 | #include "chrome/common/profiler/thread_profiler.h" |
| 42 | #include "chrome/common/profiler/unwind_util.h" |
| 43 | #include "chrome/common/secure_origin_allowlist.h" |
| 44 | #include "chrome/common/url_constants.h" |
| 45 | #include "chrome/common/webui_url_constants.h" |
| 46 | #include "chrome/grit/branded_strings.h" |
| 47 | #include "chrome/grit/generated_resources.h" |
| 48 | #include "chrome/grit/renderer_resources.h" |
| 49 | #include "chrome/renderer/benchmarking_extension.h" |
| 50 | #include "chrome/renderer/browser_exposed_renderer_interfaces.h" |
| 51 | #include "chrome/renderer/cart/commerce_hint_agent.h" |
| 52 | #include "chrome/renderer/chrome_content_settings_agent_delegate.h" |
| 53 | #include "chrome/renderer/chrome_render_frame_observer.h" |
| 54 | #include "chrome/renderer/chrome_render_thread_observer.h" |
| 55 | #include "chrome/renderer/controlled_frame/controlled_frame_extensions_renderer_api_provider.h" |
| 56 | #include "chrome/renderer/google_accounts_private_api_extension.h" |
| 57 | #include "chrome/renderer/loadtimes_extension_bindings.h" |
| 58 | #include "chrome/renderer/media/flash_embed_rewrite.h" |
| 59 | #include "chrome/renderer/media/webrtc_logging_agent_impl.h" |
| 60 | #include "chrome/renderer/net/net_error_helper.h" |
| 61 | #include "chrome/renderer/net_benchmarking_extension.h" |
| 62 | #include "chrome/renderer/plugins/non_loadable_plugin_placeholder.h" |
| 63 | #include "chrome/renderer/plugins/pdf_plugin_placeholder.h" |
| 64 | #include "chrome/renderer/plugins/plugin_uma.h" |
| 65 | #include "chrome/renderer/trusted_vault_encryption_keys_extension.h" |
| 66 | #include "chrome/renderer/url_loader_throttle_provider_impl.h" |
| 67 | #include "chrome/renderer/v8_unwinder.h" |
| 68 | #include "chrome/renderer/websocket_handshake_throttle_provider_impl.h" |
| 69 | #include "chrome/renderer/worker_content_settings_client.h" |
| 70 | #include "chrome/services/speech/buildflags/buildflags.h" |
| 71 | #include "components/autofill/content/renderer/autofill_agent.h" |
| 72 | #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 73 | #include "components/autofill/content/renderer/password_generation_agent.h" |
| 74 | #include "components/autofill/core/common/autofill_features.h" |
| 75 | #include "components/commerce/content/renderer/commerce_web_extractor.h" |
| 76 | #include "components/commerce/core/commerce_feature_list.h" |
| 77 | #include "components/content_capture/common/content_capture_features.h" |
| 78 | #include "components/content_capture/renderer/content_capture_sender.h" |
| 79 | #include "components/content_settings/core/common/content_settings_pattern.h" |
| 80 | #include "components/continuous_search/renderer/search_result_extractor_impl.h" |
| 81 | #include "components/dom_distiller/content/renderer/distillability_agent.h" |
| 82 | #include "components/dom_distiller/content/renderer/distiller_js_render_frame_observer.h" |
| 83 | #include "components/dom_distiller/core/dom_distiller_features.h" |
| 84 | #include "components/dom_distiller/core/dom_distiller_switches.h" |
| 85 | #include "components/dom_distiller/core/url_constants.h" |
| 86 | #include "components/error_page/common/error.h" |
| 87 | #include "components/error_page/common/localized_error.h" |
| 88 | #include "components/feed/buildflags.h" |
| 89 | #include "components/grit/components_scaled_resources.h" |
| 90 | #include "components/heap_profiling/in_process/heap_profiler_controller.h" |
| 91 | #include "components/history_clusters/core/config.h" |
| 92 | #include "components/metrics/call_stacks/call_stack_profile_builder.h" |
| 93 | #include "components/network_hints/renderer/web_prescient_networking_impl.h" |
| 94 | #include "components/no_state_prefetch/renderer/no_state_prefetch_client.h" |
| 95 | #include "components/no_state_prefetch/renderer/no_state_prefetch_helper.h" |
| 96 | #include "components/no_state_prefetch/renderer/no_state_prefetch_utils.h" |
| 97 | #include "components/no_state_prefetch/renderer/prerender_render_frame_observer.h" |
| 98 | #include "components/optimization_guide/core/optimization_guide_features.h" |
| 99 | #include "components/page_load_metrics/renderer/metrics_render_frame_observer.h" |
| 100 | #include "components/paint_preview/buildflags/buildflags.h" |
| 101 | #include "components/password_manager/core/common/password_manager_features.h" |
| 102 | #include "components/pdf/common/constants.h" |
| 103 | #include "components/permissions/features.h" |
| 104 | #include "components/safe_browsing/buildflags.h" |
| 105 | #include "components/safe_browsing/content/renderer/threat_dom_details.h" |
| 106 | #include "components/spellcheck/spellcheck_buildflags.h" |
| 107 | #include "components/subresource_filter/content/renderer/subresource_filter_agent.h" |
| 108 | #include "components/subresource_filter/content/renderer/unverified_ruleset_dealer.h" |
| 109 | #include "components/subresource_filter/core/common/common_features.h" |
| 110 | #include "components/supervised_user/core/common/buildflags.h" |
| 111 | #include "components/variations/net/variations_http_headers.h" |
| 112 | #include "components/variations/variations_switches.h" |
| 113 | #include "components/version_info/version_info.h" |
| 114 | #include "components/visitedlink/renderer/visitedlink_reader.h" |
| 115 | #include "components/web_cache/renderer/web_cache_impl.h" |
| 116 | #include "components/webapps/renderer/web_page_metadata_agent.h" |
| 117 | #include "content/public/common/content_constants.h" |
| 118 | #include "content/public/common/content_switches.h" |
| 119 | #include "content/public/common/page_visibility_state.h" |
| 120 | #include "content/public/common/url_constants.h" |
| 121 | #include "content/public/common/webplugininfo.h" |
| 122 | #include "content/public/renderer/render_frame.h" |
| 123 | #include "content/public/renderer/render_frame_visitor.h" |
| 124 | #include "extensions/buildflags/buildflags.h" |
| 125 | #include "extensions/renderer/extensions_renderer_api_provider.h" |
| 126 | #include "extensions/renderer/worker_script_context_set.h" |
| 127 | #include "ipc/ipc_sync_channel.h" |
| 128 | #include "media/base/media_switches.h" |
| 129 | #include "media/media_buildflags.h" |
| 130 | #include "mojo/public/cpp/bindings/generic_pending_receiver.h" |
| 131 | #include "mojo/public/cpp/bindings/remote.h" |
| 132 | #include "net/base/net_errors.h" |
| 133 | #include "pdf/buildflags.h" |
| 134 | #include "ppapi/buildflags/buildflags.h" |
| 135 | #include "printing/buildflags/buildflags.h" |
| 136 | #include "services/network/public/cpp/is_potentially_trustworthy.h" |
| 137 | #include "services/service_manager/public/cpp/interface_provider.h" |
| 138 | #include "services/tracing/public/cpp/stack_sampling/tracing_sampler_profiler.h" |
| 139 | #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" |
| 140 | #include "third_party/blink/public/common/features.h" |
| 141 | #include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-shared.h" |
| 142 | #include "third_party/blink/public/mojom/page/page_visibility_state.mojom.h" |
| 143 | #include "third_party/blink/public/platform/platform.h" |
| 144 | #include "third_party/blink/public/platform/scheduler/web_renderer_process_type.h" |
| 145 | #include "third_party/blink/public/platform/url_conversion.h" |
| 146 | #include "third_party/blink/public/platform/web_cache.h" |
| 147 | #include "third_party/blink/public/platform/web_content_security_policy_struct.h" |
| 148 | #include "third_party/blink/public/platform/web_runtime_features.h" |
| 149 | #include "third_party/blink/public/platform/web_security_origin.h" |
| 150 | #include "third_party/blink/public/platform/web_string.h" |
| 151 | #include "third_party/blink/public/platform/web_url.h" |
| 152 | #include "third_party/blink/public/platform/web_url_error.h" |
| 153 | #include "third_party/blink/public/platform/web_url_request.h" |
| 154 | #include "third_party/blink/public/platform/web_url_response.h" |
| 155 | #include "third_party/blink/public/web/web_document.h" |
| 156 | #include "third_party/blink/public/web/web_element.h" |
| 157 | #include "third_party/blink/public/web/web_heap.h" |
| 158 | #include "third_party/blink/public/web/web_local_frame.h" |
| 159 | #include "third_party/blink/public/web/web_origin_trials.h" |
| 160 | #include "third_party/blink/public/web/web_plugin.h" |
| 161 | #include "third_party/blink/public/web/web_plugin_container.h" |
| 162 | #include "third_party/blink/public/web/web_plugin_params.h" |
| 163 | #include "third_party/blink/public/web/web_script_controller.h" |
| 164 | #include "third_party/blink/public/web/web_security_policy.h" |
| 165 | #include "third_party/blink/public/web/web_view.h" |
| 166 | #include "ui/base/l10n/l10n_util.h" |
| 167 | #include "ui/base/resource/resource_bundle.h" |
| 168 | #include "ui/base/webui/jstemplate_builder.h" |
| 169 | #include "url/origin.h" |
| 170 | #include "v8/include/v8-isolate.h" |
| 171 | |
| 172 | #if BUILDFLAG(IS_ANDROID) |
| 173 | #include "chrome/renderer/sandbox_status_extension_android.h" |
| 174 | #include "chrome/renderer/wallet/boarding_pass_extractor.h" |
| 175 | #include "components/facilitated_payments/content/renderer/facilitated_payments_agent.h" |
| 176 | #include "components/facilitated_payments/core/features/features.h" |
| 177 | #else |
| 178 | #include "chrome/renderer/searchbox/searchbox.h" |
| 179 | #include "chrome/renderer/searchbox/searchbox_extension.h" |
| 180 | #include "components/search/ntp_features.h" // nogncheck |
| 181 | #endif |
| 182 | |
| 183 | #if BUILDFLAG(ENABLE_SPEECH_SERVICE) |
| 184 | #include "chrome/renderer/media/chrome_speech_recognition_client.h" |
| 185 | #endif // BUILDFLAG(ENABLE_SPEECH_SERVICE) |
| 186 | |
| 187 | #if BUILDFLAG(IS_WIN) |
| 188 | #include "chrome/renderer/render_frame_font_family_accessor.h" |
| 189 | #endif |
| 190 | |
| 191 | #if BUILDFLAG(ENABLE_FEED_V2) |
| 192 | #include "components/feed/content/renderer/rss_link_reader.h" |
| 193 | #include "components/feed/feed_feature_list.h" |
| 194 | #endif |
| 195 | |
| 196 | #if BUILDFLAG(ENABLE_NACL) |
| 197 | #include "components/nacl/common/nacl_constants.h" |
| 198 | #include "components/nacl/renderer/nacl_helper.h" |
| 199 | #endif |
| 200 | |
| 201 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 202 | #include "chrome/common/controlled_frame/controlled_frame.h" |
| 203 | #include "chrome/common/initialize_extensions_client.h" |
| 204 | #include "chrome/renderer/extensions/chrome_extensions_renderer_client.h" |
| 205 | #include "extensions/common/constants.h" |
| 206 | #include "extensions/common/context_data.h" |
| 207 | #include "extensions/common/extension_urls.h" |
| 208 | #include "extensions/common/manifest_handlers/csp_info.h" |
| 209 | #include "extensions/common/manifest_handlers/web_accessible_resources_info.h" |
| 210 | #include "extensions/common/switches.h" |
| 211 | #include "extensions/renderer/dispatcher.h" |
| 212 | #include "extensions/renderer/guest_view/mime_handler_view/mime_handler_view_container_manager.h" |
| 213 | #include "extensions/renderer/renderer_extension_registry.h" |
| 214 | #include "third_party/blink/public/mojom/css/preferred_color_scheme.mojom.h" |
| 215 | #include "third_party/blink/public/web/web_settings.h" |
| 216 | #endif |
| 217 | |
| 218 | #if BUILDFLAG(ENABLE_PDF) |
| 219 | #include "chrome/renderer/pdf/chrome_pdf_internal_plugin_delegate.h" |
| 220 | #include "components/pdf/renderer/internal_plugin_renderer_helpers.h" |
| 221 | #endif // BUILDFLAG(ENABLE_PDF) |
| 222 | |
| 223 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 224 | #include "chrome/renderer/plugins/chrome_plugin_placeholder.h" |
| 225 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
| 226 | |
| 227 | #if BUILDFLAG(ENABLE_PPAPI) |
| 228 | #include "chrome/renderer/pepper/pepper_helper.h" |
| 229 | #include "ppapi/shared_impl/ppapi_switches.h" // nogncheck crbug.com/1125897 |
| 230 | #endif |
| 231 | |
| 232 | #if BUILDFLAG(ENABLE_PRINTING) |
| 233 | #include "chrome/renderer/printing/chrome_print_render_frame_helper_delegate.h" |
| 234 | #include "components/printing/renderer/print_render_frame_helper.h" // nogncheck |
| 235 | #include "printing/metafile_agent.h" // nogncheck |
| 236 | #endif |
| 237 | |
| 238 | #if BUILDFLAG(ENABLE_PAINT_PREVIEW) |
| 239 | #include "components/paint_preview/renderer/paint_preview_recorder_impl.h" // nogncheck |
| 240 | #endif |
| 241 | |
| 242 | #if BUILDFLAG(ENABLE_SPELLCHECK) |
| 243 | #include "components/spellcheck/renderer/spellcheck.h" |
| 244 | #include "components/spellcheck/renderer/spellcheck_provider.h" |
| 245 | |
| 246 | #if BUILDFLAG(HAS_SPELLCHECK_PANEL) |
| 247 | #include "components/spellcheck/renderer/spellcheck_panel.h" |
| 248 | #endif // BUILDFLAG(HAS_SPELLCHECK_PANEL) |
| 249 | #endif // BUILDFLAG(ENABLE_SPELLCHECK) |
| 250 | |
| 251 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 252 | #include "chrome/renderer/supervised_user/supervised_user_error_page_controller_delegate_impl.h" |
| 253 | #endif |
| 254 | |
| 255 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID) |
| 256 | #include "chrome/renderer/media/chrome_key_systems.h" |
| 257 | #endif |
| 258 | |
| 259 | #if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS) |
| 260 | #include "chrome/renderer/cco/multiline_detector.h" |
| 261 | #endif |
| 262 | |
| 263 | using autofill::AutofillAgent; |
| 264 | using autofill::PasswordAutofillAgent; |
| 265 | using autofill::PasswordGenerationAgent; |
| 266 | using base::ASCIIToUTF16; |
| 267 | using base::UserMetricsAction; |
| 268 | using blink::WebCache; |
| 269 | using blink::WebConsoleMessage; |
| 270 | using blink::WebDocument; |
| 271 | using blink::WebFrame; |
| 272 | using blink::WebLocalFrame; |
| 273 | using blink::WebPlugin; |
| 274 | using blink::WebPluginParams; |
| 275 | using blink::WebSecurityOrigin; |
| 276 | using blink::WebSecurityPolicy; |
| 277 | using blink::WebString; |
| 278 | using blink::WebURL; |
| 279 | using blink::WebURLError; |
| 280 | using blink::WebURLRequest; |
| 281 | using blink::WebURLResponse; |
| 282 | using blink::WebVector; |
| 283 | using blink::mojom::FetchCacheMode; |
| 284 | using content::RenderFrame; |
| 285 | using content::RenderThread; |
| 286 | using content::WebPluginInfo; |
| 287 | using content::WebPluginMimeType; |
| 288 | using ExtractAllDatalists = autofill::AutofillAgent::ExtractAllDatalists; |
| 289 | using FocusRequiresScroll = autofill::AutofillAgent::FocusRequiresScroll; |
| 290 | using QueryPasswordSuggestions = |
| 291 | autofill::AutofillAgent::QueryPasswordSuggestions; |
| 292 | using SecureContextRequired = autofill::AutofillAgent::SecureContextRequired; |
| 293 | using UserGestureRequired = autofill::AutofillAgent::UserGestureRequired; |
| 294 | using UsesKeyboardAccessoryForSuggestions = |
| 295 | autofill::AutofillAgent::UsesKeyboardAccessoryForSuggestions; |
| 296 | |
| 297 | namespace { |
| 298 | |
| 299 | // Allow PPAPI for Android Runtime for Chromium. (See crbug.com/383937) |
| 300 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 301 | const char* const kPredefinedAllowedCameraDeviceOrigins[] = { |
| 302 | "6EAED1924DB611B6EEF2A664BD077BE7EAD33B8F", |
| 303 | "4EB74897CB187C7633357C2FE832E0AD6A44883A"}; |
| 304 | #endif |
| 305 | |
| 306 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 307 | void AppendParams( |
| 308 | const std::vector<WebPluginMimeType::Param>& additional_params, |
| 309 | WebVector<WebString>* existing_names, |
| 310 | WebVector<WebString>* existing_values) { |
| 311 | DCHECK(existing_names->size() == existing_values->size()); |
| 312 | size_t existing_size = existing_names->size(); |
| 313 | size_t total_size = existing_size + additional_params.size(); |
| 314 | |
| 315 | WebVector<WebString> names(total_size); |
| 316 | WebVector<WebString> values(total_size); |
| 317 | |
| 318 | for (size_t i = 0; i < existing_size; ++i) { |
| 319 | names[i] = (*existing_names)[i]; |
| 320 | values[i] = (*existing_values)[i]; |
| 321 | } |
| 322 | |
| 323 | for (size_t i = 0; i < additional_params.size(); ++i) { |
| 324 | names[existing_size + i] = WebString::FromUTF16(additional_params[i].name); |
| 325 | values[existing_size + i] = |
| 326 | WebString::FromUTF16(additional_params[i].value); |
| 327 | } |
| 328 | |
| 329 | existing_names->swap(names); |
| 330 | existing_values->swap(values); |
| 331 | } |
| 332 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
| 333 | |
| 334 | bool IsStandaloneContentExtensionProcess() { |
| 335 | #if !BUILDFLAG(ENABLE_EXTENSIONS) |
| 336 | return false; |
| 337 | #else |
| 338 | return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 339 | extensions::switches::kExtensionProcess); |
| 340 | #endif |
| 341 | } |
| 342 | |
| 343 | std::unique_ptr<base::Unwinder> CreateV8Unwinder(v8::Isolate* isolate) { |
| 344 | return std::make_unique<V8Unwinder>(isolate); |
| 345 | } |
| 346 | |
| 347 | // Web Share is conditionally enabled here in chrome/, to avoid it being |
| 348 | // made available in other clients of content/ that do not have a Web Share |
| 349 | // Mojo implementation (e.g. WebView). |
| 350 | void MaybeEnableWebShare() { |
| 351 | #if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) |
| 352 | if (base::FeatureList::IsEnabled(features::kWebShare)) |
| 353 | #endif |
| 354 | #if BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || \ |
| 355 | BUILDFLAG(IS_ANDROID) |
| 356 | blink::WebRuntimeFeatures::EnableWebShare(true); |
| 357 | #endif |
| 358 | } |
| 359 | |
| 360 | #if BUILDFLAG(ENABLE_NACL) && BUILDFLAG(ENABLE_EXTENSIONS) && \ |
| 361 | BUILDFLAG(IS_CHROMEOS_ASH) |
| 362 | bool IsTerminalSystemWebAppNaClPage(GURL url) { |
| 363 | GURL::Replacements replacements; |
| 364 | replacements.ClearQuery(); |
| 365 | replacements.ClearRef(); |
| 366 | url = url.ReplaceComponents(replacements); |
| 367 | return url == "chrome-untrusted://terminal/html/terminal_ssh.html"; |
| 368 | } |
| 369 | #endif |
| 370 | |
| 371 | } // namespace |
| 372 | |
| 373 | ChromeContentRendererClient::ChromeContentRendererClient() |
| 374 | : |
| 375 | #if BUILDFLAG(IS_WIN) |
| 376 | remote_module_watcher_(nullptr, base::OnTaskRunnerDeleter(nullptr)), |
| 377 | #endif |
| 378 | main_thread_profiler_( |
| 379 | #if BUILDFLAG(IS_CHROMEOS) |
| 380 | // The profiler can't start before the sandbox is initialized on |
| 381 | // ChromeOS due to ChromeOS's sandbox initialization code's use of |
| 382 | // AssertSingleThreaded(). |
| 383 | nullptr |
| 384 | #else |
| 385 | ThreadProfiler::CreateAndStartOnMainThread() |
| 386 | #endif |
| 387 | ) { |
| 388 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 389 | EnsureExtensionsClientInitialized( |
| 390 | controlled_frame::CreateAvailabilityCheckMap()); |
| 391 | extensions::ExtensionsRendererClient::Set( |
| 392 | ChromeExtensionsRendererClient::GetInstance()); |
| 393 | #endif |
| 394 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 395 | for (const char* origin : kPredefinedAllowedCameraDeviceOrigins) |
| 396 | allowed_camera_device_origins_.insert(origin); |
| 397 | #endif |
| 398 | } |
| 399 | |
| 400 | ChromeContentRendererClient::~ChromeContentRendererClient() {} |
| 401 | |
| 402 | void ChromeContentRendererClient::RenderThreadStarted() { |
| 403 | RenderThread* thread = RenderThread::Get(); |
| 404 | |
| 405 | main_thread_profiler_->SetAuxUnwinderFactory(base::BindRepeating( |
| 406 | &CreateV8Unwinder, base::Unretained(v8::Isolate::GetCurrent()))); |
| 407 | |
| 408 | // In the case of single process mode, the v8 unwinding will not work. |
| 409 | tracing::TracingSamplerProfiler::SetAuxUnwinderFactoryOnMainThread( |
| 410 | base::BindRepeating(&CreateV8Unwinder, |
| 411 | base::Unretained(v8::Isolate::GetCurrent()))); |
| 412 | |
| 413 | const bool is_extension = IsStandaloneContentExtensionProcess(); |
| 414 | |
| 415 | thread->SetRendererProcessType( |
| 416 | is_extension |
| 417 | ? blink::scheduler::WebRendererProcessType::kExtensionRenderer |
| 418 | : blink::scheduler::WebRendererProcessType::kRenderer); |
| 419 | |
| 420 | if (is_extension) { |
| 421 | // The process name was set to "Renderer" in RendererMain(). Update it to |
| 422 | // "Extension Renderer" to highlight that it's hosting an extension. |
| 423 | base::CurrentProcess::GetInstance().SetProcessType( |
| 424 | base::CurrentProcessType::PROCESS_RENDERER_EXTENSION); |
| 425 | } |
| 426 | |
| 427 | #if BUILDFLAG(IS_WIN) |
| 428 | mojo::PendingRemote<mojom::ModuleEventSink> module_event_sink; |
| 429 | thread->BindHostReceiver(module_event_sink.InitWithNewPipeAndPassReceiver()); |
| 430 | remote_module_watcher_ = RemoteModuleWatcher::Create( |
| 431 | thread->GetIOTaskRunner(), std::move(module_event_sink)); |
| 432 | #endif |
| 433 | |
| 434 | browser_interface_broker_ = |
| 435 | blink::Platform::Current()->GetBrowserInterfaceBroker(); |
| 436 | |
| 437 | chrome_observer_ = std::make_unique<ChromeRenderThreadObserver>(); |
| 438 | web_cache_impl_ = std::make_unique<web_cache::WebCacheImpl>(); |
| 439 | |
| 440 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 441 | ChromeExtensionsRendererClient* chrome_extensions_renderer_client = |
| 442 | ChromeExtensionsRendererClient::GetInstance(); |
| 443 | chrome_extensions_renderer_client->AddAPIProvider( |
| 444 | std::make_unique< |
| 445 | controlled_frame::ControlledFrameExtensionsRendererAPIProvider>()); |
| 446 | chrome_extensions_renderer_client->RenderThreadStarted(); |
| 447 | WebSecurityPolicy::RegisterURLSchemeAsExtension( |
| 448 | WebString::FromASCII(extensions::kExtensionScheme)); |
| 449 | WebSecurityPolicy::RegisterURLSchemeAsCodeCacheWithHashing( |
| 450 | WebString::FromASCII(extensions::kExtensionScheme)); |
| 451 | #endif |
| 452 | |
| 453 | #if BUILDFLAG(ENABLE_SPELLCHECK) |
| 454 | if (!spellcheck_) |
| 455 | InitSpellCheck(); |
| 456 | #endif |
| 457 | |
| 458 | subresource_filter_ruleset_dealer_ = |
| 459 | std::make_unique<subresource_filter::UnverifiedRulesetDealer>(); |
| 460 | |
| 461 | phishing_model_setter_ = |
| 462 | std::make_unique<safe_browsing::PhishingModelSetterImpl>(); |
| 463 | |
| 464 | thread->AddObserver(chrome_observer_.get()); |
| 465 | thread->AddObserver(subresource_filter_ruleset_dealer_.get()); |
| 466 | thread->AddObserver(phishing_model_setter_.get()); |
| 467 | |
| 468 | blink::WebScriptController::RegisterExtension( |
| 469 | extensions_v8::LoadTimesExtension::Get()); |
| 470 | |
| 471 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 472 | if (command_line->HasSwitch(variations::switches::kEnableBenchmarking)) { |
| 473 | blink::WebScriptController::RegisterExtension( |
| 474 | extensions_v8::BenchmarkingExtension::Get()); |
| 475 | } |
| 476 | |
| 477 | if (command_line->HasSwitch(switches::kEnableNetBenchmarking)) { |
| 478 | blink::WebScriptController::RegisterExtension( |
| 479 | extensions_v8::NetBenchmarkingExtension::Get()); |
| 480 | } |
| 481 | |
| 482 | // chrome: is also to be permitted to embeds https:// things and have them |
| 483 | // treated as first-party. |
| 484 | // See |
| 485 | // ChromeContentBrowserClient::ShouldTreatURLSchemeAsFirstPartyWhenTopLevel |
| 486 | WebString chrome_scheme(WebString::FromASCII(content::kChromeUIScheme)); |
| 487 | WebSecurityPolicy::RegisterURLSchemeAsFirstPartyWhenTopLevelEmbeddingSecure( |
| 488 | chrome_scheme); |
| 489 | |
| 490 | // chrome-native: is a scheme used for placeholder navigations that allow |
| 491 | // UIs to be drawn with platform native widgets instead of HTML. These pages |
| 492 | // should not be accessible. No code should be runnable in these pages, |
| 493 | // so it should not need to access anything nor should it allow javascript |
| 494 | // URLs since it should never be visible to the user. |
| 495 | // See also ChromeContentClient::AddAdditionalSchemes that adds it as an |
| 496 | // empty document scheme. |
| 497 | WebString native_scheme(WebString::FromASCII(chrome::kChromeNativeScheme)); |
| 498 | WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(native_scheme); |
| 499 | WebSecurityPolicy::RegisterURLSchemeAsNotAllowingJavascriptURLs( |
| 500 | native_scheme); |
| 501 | |
| 502 | // chrome-search: and chrome-distiller: pages should not be accessible by |
| 503 | // normal content, and should also be unable to script anything but themselves |
| 504 | // (to help limit the damage that a corrupt page could cause). |
| 505 | WebString chrome_search_scheme( |
| 506 | WebString::FromASCII(chrome::kChromeSearchScheme)); |
| 507 | |
| 508 | // IWAs can be enabled by either the feature flag or by enterprise |
| 509 | // policy. In either case the kEnableIsolatedWebAppsInRenderer flag is passed |
| 510 | // to the renderer process. |
| 511 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 512 | switches::kEnableIsolatedWebAppsInRenderer)) { |
| 513 | // isolated-app: is the scheme used for Isolated Web Apps, which are web |
| 514 | // applications packaged in Signed Web Bundles. |
| 515 | WebString isolated_app_scheme( |
| 516 | WebString::FromASCII(chrome::kIsolatedAppScheme)); |
| 517 | // Resources contained in Isolated Web Apps are HTTP-like and safe to expose |
| 518 | // to the fetch API. |
| 519 | WebSecurityPolicy::RegisterURLSchemeAsSupportingFetchAPI( |
| 520 | isolated_app_scheme); |
| 521 | WebSecurityPolicy::RegisterURLSchemeAsAllowingServiceWorkers( |
| 522 | isolated_app_scheme); |
| 523 | WebSecurityPolicy::RegisterURLSchemeAsAllowedForReferrer( |
| 524 | isolated_app_scheme); |
| 525 | } |
| 526 | |
| 527 | // The Instant process can only display the content but not read it. Other |
| 528 | // processes can't display it or read it. |
| 529 | if (!command_line->HasSwitch(switches::kInstantProcess)) |
| 530 | WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(chrome_search_scheme); |
| 531 | |
| 532 | WebString dom_distiller_scheme( |
| 533 | WebString::FromASCII(dom_distiller::kDomDistillerScheme)); |
| 534 | // TODO(nyquist): Add test to ensure this happens when the flag is set. |
| 535 | WebSecurityPolicy::RegisterURLSchemeAsDisplayIsolated(dom_distiller_scheme); |
| 536 | |
| 537 | #if BUILDFLAG(IS_ANDROID) |
| 538 | WebSecurityPolicy::RegisterURLSchemeAsAllowedForReferrer( |
| 539 | WebString::FromUTF8(content::kAndroidAppScheme)); |
| 540 | #endif |
| 541 | |
| 542 | // chrome-search: pages should not be accessible by bookmarklets |
| 543 | // or javascript: URLs typed in the omnibox. |
| 544 | WebSecurityPolicy::RegisterURLSchemeAsNotAllowingJavascriptURLs( |
| 545 | chrome_search_scheme); |
| 546 | |
| 547 | for (auto& scheme : |
| 548 | secure_origin_allowlist::GetSchemesBypassingSecureContextCheck()) { |
| 549 | WebSecurityPolicy::AddSchemeToSecureContextSafelist( |
| 550 | WebString::FromASCII(scheme)); |
| 551 | } |
| 552 | |
| 553 | // This doesn't work in single-process mode. |
| 554 | if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 555 | switches::kSingleProcess)) { |
| 556 | using HeapProfilerController = heap_profiling::HeapProfilerController; |
| 557 | // The HeapProfilerController should have been created in |
| 558 | // ChromeMainDelegate::PostEarlyInitialization. |
| 559 | DCHECK_NE(HeapProfilerController::GetProfilingEnabled(), |
| 560 | HeapProfilerController::ProfilingEnabled::kNoController); |
| 561 | if (ThreadProfiler::ShouldCollectProfilesForChildProcess() || |
| 562 | HeapProfilerController::GetProfilingEnabled() == |
| 563 | HeapProfilerController::ProfilingEnabled::kEnabled) { |
| 564 | ThreadProfiler::SetMainThreadTaskRunner( |
| 565 | base::SingleThreadTaskRunner::GetCurrentDefault()); |
| 566 | mojo::PendingRemote<metrics::mojom::CallStackProfileCollector> collector; |
| 567 | thread->BindHostReceiver(collector.InitWithNewPipeAndPassReceiver()); |
| 568 | metrics::CallStackProfileBuilder:: |
| 569 | SetParentProfileCollectorForChildProcess(std::move(collector)); |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | void ChromeContentRendererClient::ExposeInterfacesToBrowser( |
| 575 | mojo::BinderMap* binders) { |
| 576 | // NOTE: Do not add binders directly within this method. Instead, modify the |
| 577 | // definition of |ExposeChromeRendererInterfacesToBrowser()| to ensure |
| 578 | // security review coverage. |
| 579 | ExposeChromeRendererInterfacesToBrowser(this, binders); |
| 580 | } |
| 581 | |
| 582 | void ChromeContentRendererClient::RenderFrameCreated( |
| 583 | content::RenderFrame* render_frame) { |
| 584 | ChromeRenderFrameObserver* render_frame_observer = |
| 585 | new ChromeRenderFrameObserver(render_frame, web_cache_impl_.get()); |
| 586 | service_manager::BinderRegistry* registry = render_frame_observer->registry(); |
| 587 | |
| 588 | new prerender::PrerenderRenderFrameObserver(render_frame); |
| 589 | |
| 590 | bool should_allow_for_content_settings = |
| 591 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 592 | switches::kInstantProcess); |
| 593 | auto content_settings_delegate = |
| 594 | std::make_unique<ChromeContentSettingsAgentDelegate>(render_frame); |
| 595 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 596 | content_settings_delegate->SetExtensionDispatcher( |
| 597 | ChromeExtensionsRendererClient::GetInstance()->extension_dispatcher()); |
| 598 | #endif |
| 599 | content_settings::ContentSettingsAgentImpl* content_settings = |
| 600 | new content_settings::ContentSettingsAgentImpl( |
| 601 | render_frame, should_allow_for_content_settings, |
| 602 | std::move(content_settings_delegate)); |
| 603 | if (chrome_observer_.get()) { |
| 604 | if (chrome_observer_->content_settings_manager()) { |
| 605 | mojo::Remote<content_settings::mojom::ContentSettingsManager> manager; |
| 606 | chrome_observer_->content_settings_manager()->Clone( |
| 607 | manager.BindNewPipeAndPassReceiver()); |
| 608 | content_settings->SetContentSettingsManager(std::move(manager)); |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 613 | ChromeExtensionsRendererClient::GetInstance()->RenderFrameCreated( |
| 614 | render_frame, registry); |
| 615 | #endif |
| 616 | |
| 617 | #if BUILDFLAG(ENABLE_PPAPI) |
| 618 | new PepperHelper(render_frame); |
| 619 | #endif |
| 620 | |
| 621 | #if BUILDFLAG(ENABLE_NACL) |
| 622 | new nacl::NaClHelper(render_frame); |
| 623 | #endif |
| 624 | |
| 625 | #if BUILDFLAG(SAFE_BROWSING_DB_LOCAL) || BUILDFLAG(SAFE_BROWSING_DB_REMOTE) |
| 626 | safe_browsing::ThreatDOMDetails::Create(render_frame, registry); |
| 627 | #endif |
| 628 | |
| 629 | #if BUILDFLAG(ENABLE_PRINTING) |
| 630 | new printing::PrintRenderFrameHelper( |
| 631 | render_frame, std::make_unique<ChromePrintRenderFrameHelperDelegate>()); |
| 632 | #endif |
| 633 | |
| 634 | #if BUILDFLAG(ENABLE_PAINT_PREVIEW) |
| 635 | new paint_preview::PaintPreviewRecorderImpl(render_frame); |
| 636 | #endif |
| 637 | |
| 638 | #if BUILDFLAG(IS_ANDROID) |
| 639 | SandboxStatusExtension::Create(render_frame); |
| 640 | #endif |
| 641 | |
| 642 | TrustedVaultEncryptionKeysExtension::Create(render_frame); |
| 643 | GoogleAccountsPrivateApiExtension::Create(render_frame); |
| 644 | |
| 645 | if (render_frame->IsMainFrame()) |
| 646 | new webapps::WebPageMetadataAgent(render_frame); |
| 647 | |
| 648 | const bool search_result_extractor_enabled = |
| 649 | render_frame->IsMainFrame() && |
| 650 | optimization_guide::features::IsPageContentAnnotationEnabled(); |
| 651 | if (search_result_extractor_enabled) { |
| 652 | continuous_search::SearchResultExtractorImpl::Create(render_frame); |
| 653 | } |
| 654 | |
| 655 | new NetErrorHelper(render_frame); |
| 656 | |
| 657 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 658 | new SupervisedUserErrorPageControllerDelegateImpl(render_frame); |
| 659 | #endif |
| 660 | |
| 661 | if (!render_frame->IsMainFrame()) { |
| 662 | auto* main_frame_no_state_prefetch_helper = |
| 663 | prerender::NoStatePrefetchHelper::Get( |
| 664 | render_frame->GetMainRenderFrame()); |
| 665 | if (main_frame_no_state_prefetch_helper) { |
| 666 | // Avoid any race conditions from having the browser tell subframes that |
| 667 | // they're no-state prefetching. |
| 668 | new prerender::NoStatePrefetchHelper( |
| 669 | render_frame, |
| 670 | main_frame_no_state_prefetch_helper->histogram_prefix()); |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | // Set up a render frame observer to test if this page is a distiller page. |
| 675 | new dom_distiller::DistillerJsRenderFrameObserver( |
| 676 | render_frame, ISOLATED_WORLD_ID_CHROME_INTERNAL); |
| 677 | |
| 678 | if (dom_distiller::ShouldStartDistillabilityService()) { |
| 679 | // Create DistillabilityAgent to send distillability updates to |
| 680 | // DistillabilityDriver in the browser process. |
| 681 | new dom_distiller::DistillabilityAgent(render_frame, DCHECK_IS_ON()); |
| 682 | } |
| 683 | |
| 684 | blink::AssociatedInterfaceRegistry* associated_interfaces = |
| 685 | render_frame_observer->associated_interfaces(); |
| 686 | |
| 687 | if (!render_frame->IsInFencedFrameTree() || |
| 688 | base::FeatureList::IsEnabled(blink::features::kFencedFramesAPIChanges)) { |
| 689 | auto password_autofill_agent = std::make_unique<PasswordAutofillAgent>( |
| 690 | render_frame, associated_interfaces); |
| 691 | auto password_generation_agent = std::make_unique<PasswordGenerationAgent>( |
| 692 | render_frame, password_autofill_agent.get(), associated_interfaces); |
| 693 | new AutofillAgent( |
| 694 | render_frame, |
| 695 | {ExtractAllDatalists(false), FocusRequiresScroll(true), |
| 696 | QueryPasswordSuggestions(false), SecureContextRequired(false), |
| 697 | UserGestureRequired(true), |
| 698 | UsesKeyboardAccessoryForSuggestions(BUILDFLAG(IS_ANDROID))}, |
| 699 | std::move(password_autofill_agent), |
| 700 | std::move(password_generation_agent), associated_interfaces); |
| 701 | |
| 702 | #if BUILDFLAG(IS_ANDROID) |
| 703 | if (render_frame->IsMainFrame() && |
| 704 | base::FeatureList::IsEnabled( |
| 705 | payments::facilitated::kEnablePixDetection)) { |
| 706 | new payments::facilitated::FacilitatedPaymentsAgent( |
| 707 | render_frame, associated_interfaces); |
| 708 | } |
| 709 | #endif |
| 710 | } |
| 711 | |
| 712 | if (content_capture::features::IsContentCaptureEnabled()) { |
| 713 | new content_capture::ContentCaptureSender(render_frame, |
| 714 | associated_interfaces); |
| 715 | } |
| 716 | |
| 717 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 718 | associated_interfaces |
| 719 | ->AddInterface<extensions::mojom::MimeHandlerViewContainerManager>( |
| 720 | base::BindRepeating( |
| 721 | &extensions::MimeHandlerViewContainerManager::BindReceiver, |
| 722 | base::Unretained(render_frame))); |
| 723 | #endif |
| 724 | |
| 725 | // Owned by |render_frame|. |
| 726 | new page_load_metrics::MetricsRenderFrameObserver(render_frame); |
| 727 | // There is no render thread, thus no UnverifiedRulesetDealer in |
| 728 | // ChromeRenderViewTests. |
| 729 | if (subresource_filter_ruleset_dealer_) { |
| 730 | auto* subresource_filter_agent = |
| 731 | new subresource_filter::SubresourceFilterAgent( |
| 732 | render_frame, subresource_filter_ruleset_dealer_.get()); |
| 733 | subresource_filter_agent->Initialize(); |
| 734 | } |
| 735 | |
| 736 | #if !BUILDFLAG(IS_ANDROID) |
| 737 | base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 738 | if (command_line->HasSwitch(switches::kInstantProcess) && |
| 739 | render_frame->IsMainFrame()) { |
| 740 | new SearchBox(render_frame); |
| 741 | } |
| 742 | #endif |
| 743 | |
| 744 | // We should create CommerceHintAgent only for a main frame except a fenced |
| 745 | // frame that is the main frame as well, so we should check if |render_frame| |
| 746 | // is the fenced frame. |
| 747 | #if !BUILDFLAG(IS_ANDROID) |
| 748 | if (command_line->HasSwitch(commerce::switches::kEnableChromeCart) && |
| 749 | #else |
| 750 | if (base::FeatureList::IsEnabled(commerce::kCommerceHintAndroid) && |
| 751 | #endif // !BUILDFLAG(IS_ANDROID) |
| 752 | render_frame->GetWebFrame()->IsOutermostMainFrame()) { |
| 753 | new cart::CommerceHintAgent(render_frame); |
| 754 | } |
| 755 | |
| 756 | #if BUILDFLAG(ENABLE_SPELLCHECK) |
| 757 | new SpellCheckProvider(render_frame, spellcheck_.get()); |
| 758 | |
| 759 | #if BUILDFLAG(HAS_SPELLCHECK_PANEL) |
| 760 | new SpellCheckPanel(render_frame, registry, this); |
| 761 | #endif // BUILDFLAG(HAS_SPELLCHECK_PANEL) |
| 762 | #endif |
| 763 | #if BUILDFLAG(ENABLE_FEED_V2) |
| 764 | if (render_frame->IsMainFrame() && |
| 765 | base::FeatureList::IsEnabled(feed::kWebFeed)) { |
| 766 | new feed::RssLinkReader(render_frame, registry); |
| 767 | } |
| 768 | #endif |
| 769 | |
| 770 | #if BUILDFLAG(IS_WIN) |
| 771 | if (render_frame->IsMainFrame()) { |
| 772 | associated_interfaces |
| 773 | ->AddInterface<chrome::mojom::RenderFrameFontFamilyAccessor>( |
| 774 | base::BindRepeating(&RenderFrameFontFamilyAccessor::Bind, |
| 775 | render_frame)); |
| 776 | } |
| 777 | #endif |
| 778 | |
| 779 | #if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_CHROMEOS) |
| 780 | MultilineDetector::InstallIfNecessary(render_frame); |
| 781 | #endif |
| 782 | |
| 783 | if (render_frame->IsMainFrame()) { |
| 784 | new commerce::CommerceWebExtractor(render_frame, registry); |
| 785 | } |
| 786 | |
| 787 | #if BUILDFLAG(IS_ANDROID) |
| 788 | if (base::FeatureList::IsEnabled(features::kBoardingPassDetector) && |
| 789 | render_frame->IsMainFrame()) { |
| 790 | new wallet::BoardingPassExtractor(render_frame, registry); |
| 791 | } |
| 792 | #endif |
| 793 | } |
| 794 | |
| 795 | void ChromeContentRendererClient::WebViewCreated( |
| 796 | blink::WebView* web_view, |
| 797 | bool was_created_by_renderer, |
| 798 | const url::Origin* outermost_origin) { |
| 799 | new prerender::NoStatePrefetchClient(web_view); |
| 800 | |
| 801 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 802 | ChromeExtensionsRendererClient::GetInstance()->WebViewCreated( |
| 803 | web_view, outermost_origin); |
| 804 | #endif |
| 805 | } |
| 806 | |
| 807 | SkBitmap* ChromeContentRendererClient::GetSadPluginBitmap() { |
| 808 | return const_cast<SkBitmap*>(ui::ResourceBundle::GetSharedInstance() |
| 809 | .GetImageNamed(IDR_SAD_PLUGIN) |
| 810 | .ToSkBitmap()); |
| 811 | } |
| 812 | |
| 813 | SkBitmap* ChromeContentRendererClient::GetSadWebViewBitmap() { |
| 814 | return const_cast<SkBitmap*>(ui::ResourceBundle::GetSharedInstance() |
| 815 | .GetImageNamed(IDR_SAD_WEBVIEW) |
| 816 | .ToSkBitmap()); |
| 817 | } |
| 818 | |
| 819 | bool ChromeContentRendererClient::IsPluginHandledExternally( |
| 820 | content::RenderFrame* render_frame, |
| 821 | const blink::WebElement& plugin_element, |
| 822 | const GURL& original_url, |
| 823 | const std::string& mime_type) { |
| 824 | #if BUILDFLAG(ENABLE_EXTENSIONS) && BUILDFLAG(ENABLE_PLUGINS) |
| 825 | DCHECK(plugin_element.HasHTMLTagName("object") || |
| 826 | plugin_element.HasHTMLTagName("embed")); |
| 827 | |
| 828 | mojo::AssociatedRemote<chrome::mojom::PluginInfoHost> plugin_info_host; |
| 829 | render_frame->GetRemoteAssociatedInterfaces()->GetInterface( |
| 830 | &plugin_info_host); |
| 831 | // Blink will next try to load a WebPlugin which would end up in |
| 832 | // OverrideCreatePlugin, sending another IPC only to find out the plugin is |
| 833 | // not supported. Here it suffices to return false but there should perhaps be |
| 834 | // a more unified approach to avoid sending the IPC twice. |
| 835 | chrome::mojom::PluginInfoPtr plugin_info = chrome::mojom::PluginInfo::New(); |
| 836 | plugin_info_host->GetPluginInfo( |
| 837 | original_url, render_frame->GetWebFrame()->Top()->GetSecurityOrigin(), |
| 838 | mime_type, &plugin_info); |
| 839 | // TODO(ekaramad): Not continuing here due to a disallowed status should take |
| 840 | // us to CreatePlugin. See if more in depths investigation of |status| is |
| 841 | // necessary here (see https://crbug.com/965747). For now, returning false |
| 842 | // should take us to CreatePlugin after HTMLPlugInElement which is called |
| 843 | // through HTMLPlugInElement::LoadPlugin code path. |
| 844 | if (plugin_info->status != chrome::mojom::PluginStatus::kAllowed && |
| 845 | plugin_info->status != |
| 846 | chrome::mojom::PluginStatus::kPlayImportantContent) { |
| 847 | // We could get here when a MimeHandlerView is loaded inside a <webview> |
| 848 | // which is using permissions API (see WebViewPluginTests). |
| 849 | ChromeExtensionsRendererClient::DidBlockMimeHandlerViewForDisallowedPlugin( |
| 850 | plugin_element); |
| 851 | return false; |
| 852 | } |
| 853 | #if BUILDFLAG(ENABLE_PDF) |
| 854 | if (plugin_info->actual_mime_type == pdf::kInternalPluginMimeType) { |
| 855 | // Only actually treat the internal PDF plugin as externally handled if |
| 856 | // used within an origin allowed to create the internal PDF plugin; |
| 857 | // otherwise, let Blink try to create the in-process PDF plugin. |
| 858 | if (IsPdfInternalPluginAllowedOrigin( |
| 859 | render_frame->GetWebFrame()->GetSecurityOrigin())) { |
| 860 | return true; |
| 861 | } |
| 862 | } |
| 863 | #endif // BUILDFLAG(ENABLE_PDF) |
| 864 | return ChromeExtensionsRendererClient::MaybeCreateMimeHandlerView( |
| 865 | plugin_element, original_url, plugin_info->actual_mime_type, |
| 866 | plugin_info->plugin); |
| 867 | #else // !(BUILDFLAG(ENABLE_EXTENSIONS) && BUILDFLAG(ENABLE_PLUGINS)) |
| 868 | return false; |
| 869 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) && BUILDFLAG(ENABLE_PLUGINS) |
| 870 | } |
| 871 | |
| 872 | v8::Local<v8::Object> ChromeContentRendererClient::GetScriptableObject( |
| 873 | const blink::WebElement& plugin_element, |
| 874 | v8::Isolate* isolate) { |
| 875 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 876 | return ChromeExtensionsRendererClient::GetInstance()->GetScriptableObject( |
| 877 | plugin_element, isolate); |
| 878 | #else |
| 879 | return v8::Local<v8::Object>(); |
| 880 | #endif |
| 881 | } |
| 882 | |
| 883 | bool ChromeContentRendererClient::OverrideCreatePlugin( |
| 884 | content::RenderFrame* render_frame, |
| 885 | const WebPluginParams& params, |
| 886 | WebPlugin** plugin) { |
| 887 | std::string orig_mime_type = params.mime_type.Utf8(); |
| 888 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 889 | if (!ChromeExtensionsRendererClient::GetInstance()->OverrideCreatePlugin( |
| 890 | render_frame, params)) { |
| 891 | return false; |
| 892 | } |
| 893 | #endif |
| 894 | |
| 895 | GURL url(params.url); |
| 896 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 897 | mojo::AssociatedRemote<chrome::mojom::PluginInfoHost> plugin_info_host; |
| 898 | render_frame->GetRemoteAssociatedInterfaces()->GetInterface( |
| 899 | &plugin_info_host); |
| 900 | |
| 901 | chrome::mojom::PluginInfoPtr plugin_info = chrome::mojom::PluginInfo::New(); |
| 902 | plugin_info_host->GetPluginInfo( |
| 903 | url, render_frame->GetWebFrame()->Top()->GetSecurityOrigin(), |
| 904 | orig_mime_type, &plugin_info); |
| 905 | *plugin = CreatePlugin(render_frame, params, *plugin_info); |
| 906 | #else // !BUILDFLAG(ENABLE_PLUGINS) |
| 907 | PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type, url); |
| 908 | if (orig_mime_type == pdf::kPDFMimeType) { |
| 909 | ReportPDFLoadStatus( |
| 910 | PDFLoadStatus::kShowedDisabledPluginPlaceholderForEmbeddedPdf); |
| 911 | |
| 912 | PDFPluginPlaceholder* placeholder = |
| 913 | PDFPluginPlaceholder::CreatePDFPlaceholder(render_frame, params); |
| 914 | *plugin = placeholder->plugin(); |
| 915 | return true; |
| 916 | } |
| 917 | auto* placeholder = NonLoadablePluginPlaceholder::CreateNotSupportedPlugin( |
| 918 | render_frame, params); |
| 919 | *plugin = placeholder->plugin(); |
| 920 | |
| 921 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
| 922 | return true; |
| 923 | } |
| 924 | |
| 925 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 926 | WebPlugin* ChromeContentRendererClient::CreatePluginReplacement( |
| 927 | content::RenderFrame* render_frame, |
| 928 | const base::FilePath& plugin_path) { |
| 929 | auto* placeholder = NonLoadablePluginPlaceholder::CreateErrorPlugin( |
| 930 | render_frame, plugin_path); |
| 931 | return placeholder->plugin(); |
| 932 | } |
| 933 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
| 934 | |
| 935 | bool ChromeContentRendererClient::DeferMediaLoad( |
| 936 | content::RenderFrame* render_frame, |
| 937 | bool has_played_media_before, |
| 938 | base::OnceClosure closure) { |
| 939 | return prerender::DeferMediaLoad(render_frame, has_played_media_before, |
| 940 | std::move(closure)); |
| 941 | } |
| 942 | |
| 943 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 944 | |
| 945 | // static |
| 946 | WebPlugin* ChromeContentRendererClient::CreatePlugin( |
| 947 | content::RenderFrame* render_frame, |
| 948 | const WebPluginParams& original_params, |
| 949 | const chrome::mojom::PluginInfo& plugin_info) { |
| 950 | const WebPluginInfo& info = plugin_info.plugin; |
| 951 | const std::string& actual_mime_type = plugin_info.actual_mime_type; |
| 952 | const std::u16string& group_name = plugin_info.group_name; |
| 953 | const std::string& identifier = plugin_info.group_identifier; |
| 954 | chrome::mojom::PluginStatus status = plugin_info.status; |
| 955 | GURL url(original_params.url); |
| 956 | std::string orig_mime_type = original_params.mime_type.Utf8(); |
| 957 | ChromePluginPlaceholder* placeholder = nullptr; |
| 958 | |
| 959 | // If the browser plugin is to be enabled, this should be handled by the |
| 960 | // renderer, so the code won't reach here due to the early exit in |
| 961 | // OverrideCreatePlugin. |
| 962 | if (status == chrome::mojom::PluginStatus::kNotFound || |
| 963 | orig_mime_type == content::kBrowserPluginMimeType) { |
| 964 | // Flash has been thoroughly removed in M88+, so we need to have a special |
| 965 | // case here to display a deprecated message instead of a generic |
| 966 | // plugin-missing message. |
| 967 | if (orig_mime_type == "application/x-shockwave-flash" || |
| 968 | orig_mime_type == "application/futuresplash") { |
| 969 | return NonLoadablePluginPlaceholder::CreateFlashDeprecatedPlaceholder( |
| 970 | render_frame, original_params) |
| 971 | ->plugin(); |
| 972 | } else { |
| 973 | PluginUMAReporter::GetInstance()->ReportPluginMissing(orig_mime_type, |
| 974 | url); |
| 975 | placeholder = ChromePluginPlaceholder::CreateLoadableMissingPlugin( |
| 976 | render_frame, original_params); |
| 977 | } |
| 978 | } else { |
| 979 | // TODO(bauerb): This should be in content/. |
| 980 | WebPluginParams params(original_params); |
| 981 | for (const auto& mime_type : info.mime_types) { |
| 982 | if (mime_type.mime_type == actual_mime_type) { |
| 983 | AppendParams(mime_type.additional_params, ¶ms.attribute_names, |
| 984 | ¶ms.attribute_values); |
| 985 | break; |
| 986 | } |
| 987 | } |
| 988 | if (params.mime_type.IsNull() && (actual_mime_type.size() > 0)) { |
| 989 | // Webkit might say that mime type is null while we already know the |
| 990 | // actual mime type via ChromeViewHostMsg_GetPluginInfo. In that case |
| 991 | // we should use what we know since WebpluginDelegateProxy does some |
| 992 | // specific initializations based on this information. |
| 993 | params.mime_type = WebString::FromUTF8(actual_mime_type); |
| 994 | } |
| 995 | |
| 996 | auto* content_settings_agent = |
| 997 | content_settings::ContentSettingsAgentImpl::Get(render_frame); |
| 998 | auto* content_settings_agent_delegate = |
| 999 | ChromeContentSettingsAgentDelegate::Get(render_frame); |
| 1000 | |
| 1001 | const ContentSettingsType content_type = ContentSettingsType::JAVASCRIPT; |
| 1002 | |
| 1003 | if ((status == chrome::mojom::PluginStatus::kUnauthorized || |
| 1004 | status == chrome::mojom::PluginStatus::kBlocked) && |
| 1005 | content_settings_agent_delegate->IsPluginTemporarilyAllowed( |
| 1006 | identifier)) { |
| 1007 | status = chrome::mojom::PluginStatus::kAllowed; |
| 1008 | } |
| 1009 | |
| 1010 | auto create_blocked_plugin = [&render_frame, ¶ms, &info, &identifier, |
| 1011 | &group_name](int template_id, |
| 1012 | const std::u16string& message) { |
| 1013 | return ChromePluginPlaceholder::CreateBlockedPlugin( |
| 1014 | render_frame, params, info, identifier, group_name, template_id, |
| 1015 | message); |
| 1016 | }; |
| 1017 | switch (status) { |
| 1018 | case chrome::mojom::PluginStatus::kNotFound: { |
| 1019 | NOTREACHED(); |
| 1020 | break; |
| 1021 | } |
| 1022 | case chrome::mojom::PluginStatus::kAllowed: |
| 1023 | case chrome::mojom::PluginStatus::kPlayImportantContent: { |
| 1024 | #if BUILDFLAG(ENABLE_NACL) && BUILDFLAG(ENABLE_EXTENSIONS) |
| 1025 | WebLocalFrame* frame = render_frame->GetWebFrame(); |
| 1026 | const bool is_nacl_plugin = |
| 1027 | info.name == ASCIIToUTF16(nacl::kNaClPluginName); |
| 1028 | const bool is_nacl_mime_type = |
| 1029 | actual_mime_type == nacl::kNaClPluginMimeType; |
| 1030 | const bool is_pnacl_mime_type = |
| 1031 | actual_mime_type == nacl::kPnaclPluginMimeType; |
| 1032 | if (is_nacl_plugin || is_nacl_mime_type || is_pnacl_mime_type) { |
| 1033 | bool has_enable_nacl_switch = |
| 1034 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1035 | switches::kEnableNaCl); |
| 1036 | bool is_nacl_unrestricted = |
| 1037 | has_enable_nacl_switch || is_pnacl_mime_type; |
| 1038 | GURL manifest_url; |
| 1039 | GURL app_url; |
| 1040 | if (is_nacl_mime_type || is_pnacl_mime_type) { |
| 1041 | // Normal NaCl/PNaCl embed. The app URL is the page URL. |
| 1042 | manifest_url = url; |
| 1043 | app_url = frame->GetDocument().Url(); |
| 1044 | } else { |
| 1045 | // NaCl is being invoked as a content handler. Look up the NaCl |
| 1046 | // module using the MIME type. The app URL is the manifest URL. |
| 1047 | manifest_url = GetNaClContentHandlerURL(actual_mime_type, info); |
| 1048 | app_url = manifest_url; |
| 1049 | } |
| 1050 | bool is_module_allowed = false; |
| 1051 | const extensions::Extension* extension = |
| 1052 | extensions::RendererExtensionRegistry::Get() |
| 1053 | ->GetExtensionOrAppByURL(manifest_url); |
| 1054 | if (IsNaclAllowed()) { |
| 1055 | if (extension) { |
| 1056 | is_module_allowed = |
| 1057 | IsNativeNaClAllowed(app_url, is_nacl_unrestricted, extension); |
| 1058 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
| 1059 | // Allow Terminal System App to load the SSH extension NaCl |
| 1060 | // module. |
| 1061 | } else if (IsTerminalSystemWebAppNaClPage(app_url)) { |
| 1062 | is_module_allowed = true; |
| 1063 | #endif |
| 1064 | } else { |
| 1065 | WebDocument document = frame->GetDocument(); |
| 1066 | is_module_allowed = |
| 1067 | has_enable_nacl_switch || |
| 1068 | (is_pnacl_mime_type && |
| 1069 | blink::WebOriginTrials::isTrialEnabled(&document, "PNaCl")); |
| 1070 | } |
| 1071 | } |
| 1072 | if (!is_module_allowed) { |
| 1073 | WebString error_message; |
| 1074 | if (!IsNaclAllowed()) { |
| 1075 | error_message = "NaCl is disabled."; |
| 1076 | } else if (is_nacl_mime_type) { |
| 1077 | error_message = |
| 1078 | "Only unpacked extensions and apps installed from the Chrome " |
| 1079 | "Web Store can load NaCl modules without enabling Native " |
| 1080 | "Client in about:flags."; |
| 1081 | } else if (is_pnacl_mime_type) { |
| 1082 | error_message = |
| 1083 | "PNaCl modules can only be used on the open web (non-app/" |
| 1084 | "extension) when the PNaCl Origin Trial is enabled"; |
| 1085 | } |
| 1086 | frame->AddMessageToConsole(WebConsoleMessage( |
| 1087 | blink::mojom::ConsoleMessageLevel::kError, error_message)); |
| 1088 | placeholder = create_blocked_plugin( |
| 1089 | IDR_BLOCKED_PLUGIN_HTML, |
| 1090 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
| 1091 | l10n_util::GetStringUTF16(IDS_NACL_PLUGIN_BLOCKED)); |
| 1092 | #else |
| 1093 | l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name)); |
| 1094 | #endif |
| 1095 | break; |
| 1096 | } |
| 1097 | ReportNaClAppType(is_pnacl_mime_type, extension); |
| 1098 | } |
| 1099 | #endif // BUILDFLAG(ENABLE_NACL) && BUILDFLAG(ENABLE_EXTENSIONS) |
| 1100 | |
| 1101 | if (info.path.value() == ChromeContentClient::kPDFExtensionPluginPath) { |
| 1102 | // Report PDF load metrics. Since the PDF plugin is comprised of an |
| 1103 | // extension that loads a second plugin, avoid double counting by |
| 1104 | // ignoring the creation of the second plugin. |
| 1105 | bool is_main_frame_plugin_document = |
| 1106 | render_frame->IsMainFrame() && |
| 1107 | render_frame->GetWebFrame()->GetDocument().IsPluginDocument(); |
| 1108 | ReportPDFLoadStatus( |
| 1109 | is_main_frame_plugin_document |
| 1110 | ? PDFLoadStatus::kLoadedFullPagePdfWithPdfium |
| 1111 | : PDFLoadStatus::kLoadedEmbeddedPdfWithPdfium); |
| 1112 | } |
| 1113 | |
| 1114 | // Delay loading plugins if no-state prefetching. |
| 1115 | // TODO(mmenke): In the case of NoStatePrefetch, feed into |
| 1116 | // ChromeContentRendererClient::CreatePlugin instead, to |
| 1117 | // reduce the chance of future regressions. |
| 1118 | bool is_no_state_prefetching = |
| 1119 | prerender::NoStatePrefetchHelper::IsPrefetching(render_frame); |
| 1120 | |
| 1121 | if (is_no_state_prefetching) { |
| 1122 | placeholder = ChromePluginPlaceholder::CreateBlockedPlugin( |
| 1123 | render_frame, params, info, identifier, group_name, |
| 1124 | IDR_BLOCKED_PLUGIN_HTML, |
| 1125 | l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name)); |
| 1126 | placeholder->set_blocked_for_prerendering(is_no_state_prefetching); |
| 1127 | placeholder->AllowLoading(); |
| 1128 | break; |
| 1129 | } |
| 1130 | |
| 1131 | #if BUILDFLAG(ENABLE_PDF) |
| 1132 | if (info.path.value() == ChromeContentClient::kPDFInternalPluginPath) { |
| 1133 | return pdf::CreateInternalPlugin( |
| 1134 | std::move(params), render_frame, |
| 1135 | std::make_unique<ChromePdfInternalPluginDelegate>()); |
| 1136 | } |
| 1137 | #endif // BUILDFLAG(ENABLE_PDF) |
| 1138 | |
| 1139 | return render_frame->CreatePlugin(info, params); |
| 1140 | } |
| 1141 | case chrome::mojom::PluginStatus::kDisabled: { |
| 1142 | PluginUMAReporter::GetInstance()->ReportPluginDisabled(orig_mime_type, |
| 1143 | url); |
| 1144 | if (info.path.value() == ChromeContentClient::kPDFExtensionPluginPath) { |
| 1145 | ReportPDFLoadStatus( |
| 1146 | PDFLoadStatus::kShowedDisabledPluginPlaceholderForEmbeddedPdf); |
| 1147 | |
| 1148 | return PDFPluginPlaceholder::CreatePDFPlaceholder(render_frame, |
| 1149 | params) |
| 1150 | ->plugin(); |
| 1151 | } |
| 1152 | |
| 1153 | placeholder = create_blocked_plugin( |
| 1154 | IDR_DISABLED_PLUGIN_HTML, |
| 1155 | l10n_util::GetStringFUTF16(IDS_PLUGIN_DISABLED, group_name)); |
| 1156 | break; |
| 1157 | } |
| 1158 | case chrome::mojom::PluginStatus::kUnauthorized: { |
| 1159 | placeholder = create_blocked_plugin( |
| 1160 | IDR_BLOCKED_PLUGIN_HTML, |
| 1161 | l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, group_name)); |
| 1162 | placeholder->AllowLoading(); |
| 1163 | mojo::AssociatedRemote<chrome::mojom::PluginAuthHost> plugin_auth_host; |
| 1164 | render_frame->GetRemoteAssociatedInterfaces()->GetInterface( |
| 1165 | plugin_auth_host.BindNewEndpointAndPassReceiver()); |
| 1166 | plugin_auth_host->BlockedUnauthorizedPlugin(group_name, identifier); |
| 1167 | content_settings_agent->DidBlockContentType(content_type); |
| 1168 | break; |
| 1169 | } |
| 1170 | case chrome::mojom::PluginStatus::kBlocked: { |
| 1171 | placeholder = create_blocked_plugin( |
| 1172 | IDR_BLOCKED_PLUGIN_HTML, |
| 1173 | l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED, group_name)); |
| 1174 | placeholder->AllowLoading(); |
| 1175 | RenderThread::Get()->RecordAction(UserMetricsAction("Plugin_Blocked")); |
| 1176 | content_settings_agent->DidBlockContentType(content_type); |
| 1177 | break; |
| 1178 | } |
| 1179 | case chrome::mojom::PluginStatus::kBlockedByPolicy: { |
| 1180 | placeholder = create_blocked_plugin( |
| 1181 | IDR_BLOCKED_PLUGIN_HTML, |
| 1182 | l10n_util::GetStringFUTF16(IDS_PLUGIN_BLOCKED_BY_POLICY, |
| 1183 | group_name)); |
| 1184 | RenderThread::Get()->RecordAction( |
| 1185 | UserMetricsAction("Plugin_BlockedByPolicy")); |
| 1186 | content_settings_agent->DidBlockContentType(content_type); |
| 1187 | break; |
| 1188 | } |
| 1189 | } |
| 1190 | } |
| 1191 | placeholder->SetStatus(status); |
| 1192 | return placeholder->plugin(); |
| 1193 | } |
| 1194 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
| 1195 | |
| 1196 | // For NaCl content handling plugins, the NaCl manifest is stored in an |
| 1197 | // additional 'nacl' param associated with the MIME type. |
| 1198 | // static |
| 1199 | GURL ChromeContentRendererClient::GetNaClContentHandlerURL( |
| 1200 | const std::string& actual_mime_type, |
| 1201 | const content::WebPluginInfo& plugin) { |
| 1202 | // Look for the manifest URL among the MIME type's additional parameters. |
| 1203 | for (const auto& mime_type : plugin.mime_types) { |
| 1204 | if (mime_type.mime_type == actual_mime_type) { |
| 1205 | for (const auto& p : mime_type.additional_params) { |
| 1206 | if (p.name == u"nacl") |
| 1207 | return GURL(p.value); |
| 1208 | } |
| 1209 | break; |
| 1210 | } |
| 1211 | } |
| 1212 | return GURL(); |
| 1213 | } |
| 1214 | |
| 1215 | void ChromeContentRendererClient::GetInterface( |
| 1216 | const std::string& interface_name, |
| 1217 | mojo::ScopedMessagePipeHandle interface_pipe) { |
| 1218 | // TODO(crbug.com/977637): Get rid of the use of this implementation of |
| 1219 | // |service_manager::LocalInterfaceProvider|. This was done only to avoid |
| 1220 | // churning spellcheck code while eliminting the "chrome" and |
| 1221 | // "chrome_renderer" services. Spellcheck is (and should remain) the only |
| 1222 | // consumer of this implementation. |
| 1223 | RenderThread::Get()->BindHostReceiver( |
| 1224 | mojo::GenericPendingReceiver(interface_name, std::move(interface_pipe))); |
| 1225 | } |
| 1226 | |
| 1227 | #if BUILDFLAG(ENABLE_NACL) |
| 1228 | // static |
| 1229 | bool ChromeContentRendererClient::IsNativeNaClAllowed( |
| 1230 | const GURL& app_url, |
| 1231 | bool is_nacl_unrestricted, |
| 1232 | const extensions::Extension* extension) { |
| 1233 | bool is_invoked_by_webstore_installed_extension = false; |
| 1234 | bool is_extension_unrestricted = false; |
| 1235 | bool is_extension_force_installed = false; |
| 1236 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1237 | bool is_extension_from_webstore = extension && extension->from_webstore(); |
| 1238 | |
| 1239 | bool is_invoked_by_extension = app_url.SchemeIs(extensions::kExtensionScheme); |
| 1240 | bool is_invoked_by_hosted_app = extension && extension->is_hosted_app() && |
| 1241 | extension->web_extent().MatchesURL(app_url); |
| 1242 | |
| 1243 | is_invoked_by_webstore_installed_extension = |
| 1244 | is_extension_from_webstore && |
| 1245 | (is_invoked_by_extension || is_invoked_by_hosted_app); |
| 1246 | |
| 1247 | // Allow built-in extensions and developer mode extensions. |
| 1248 | is_extension_unrestricted = |
| 1249 | extension && |
| 1250 | (extensions::Manifest::IsUnpackedLocation(extension->location()) || |
| 1251 | extensions::Manifest::IsComponentLocation(extension->location())); |
| 1252 | // Allow extensions force installed by admin policy. |
| 1253 | is_extension_force_installed = |
| 1254 | extension && |
| 1255 | extensions::Manifest::IsPolicyLocation(extension->location()); |
| 1256 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 1257 | |
| 1258 | // Allow NaCl under any of the following circumstances: |
| 1259 | // 1) An extension is loaded unpacked or built-in (component) to Chrome. |
| 1260 | // 2) An extension is force installed by policy. |
| 1261 | // 3) An extension is installed from the webstore, and invoked in that |
| 1262 | // context (hosted app URL or chrome-extension:// scheme). |
| 1263 | // 4) --enable-nacl is set. |
| 1264 | bool is_nacl_allowed_by_location = is_extension_unrestricted || |
| 1265 | is_extension_force_installed || |
| 1266 | is_invoked_by_webstore_installed_extension; |
| 1267 | bool is_nacl_allowed = is_nacl_allowed_by_location || is_nacl_unrestricted; |
| 1268 | return is_nacl_allowed; |
| 1269 | } |
| 1270 | |
| 1271 | // static |
| 1272 | void ChromeContentRendererClient::ReportNaClAppType( |
| 1273 | bool is_pnacl, |
| 1274 | const extensions::Extension* extension) { |
| 1275 | // These values are persisted to logs. Entries should not be renumbered and |
| 1276 | // numeric values should never be reused. |
| 1277 | enum class NaClAppType { |
| 1278 | kPNaClOpenWeb = 0, |
| 1279 | kPNaClHostedApp = 1, |
| 1280 | kPNaClPlatformApp = 2, |
| 1281 | kPNaClLegacyPackagedApp = 3, |
| 1282 | kPNaClMv2Extension = 4, |
| 1283 | kPNaClMv3Extension = 5, |
| 1284 | kPNaClLoginScreenMv2Extension = 6, |
| 1285 | kPNaClLoginScreenMv3Extension = 7, |
| 1286 | kNaClOpenWeb = 8, |
| 1287 | kNaClHostedApp = 9, |
| 1288 | kNaClPlatformApp = 10, |
| 1289 | kNaClLegacyPackagedApp = 11, |
| 1290 | kNaClMv2Extension = 12, |
| 1291 | kNaClMv3Extension = 13, |
| 1292 | kNaClLoginScreenMv2Extension = 14, |
| 1293 | kNaClLoginScreenMv3Extension = 15, |
| 1294 | kMaxValue = kNaClLoginScreenMv3Extension |
| 1295 | }; |
| 1296 | |
| 1297 | // Not all combinations are allowed by default (e.g. kNaClOpenWeb), but they |
| 1298 | // can be used with the --enable-nacl flag. |
| 1299 | NaClAppType app_type = |
| 1300 | is_pnacl ? NaClAppType::kPNaClOpenWeb : NaClAppType::kNaClOpenWeb; |
| 1301 | if (extension) { |
| 1302 | if (extension->is_extension()) { |
| 1303 | if (extension->manifest_version() >= 3) { |
| 1304 | app_type = is_pnacl ? NaClAppType::kPNaClMv3Extension |
| 1305 | : NaClAppType::kNaClMv3Extension; |
| 1306 | } else { |
| 1307 | app_type = is_pnacl ? NaClAppType::kPNaClMv2Extension |
| 1308 | : NaClAppType::kNaClMv2Extension; |
| 1309 | } |
| 1310 | } else if (extension->is_hosted_app()) { |
| 1311 | app_type = |
| 1312 | is_pnacl ? NaClAppType::kPNaClHostedApp : NaClAppType::kNaClHostedApp; |
| 1313 | } else if (extension->is_legacy_packaged_app()) { |
| 1314 | app_type = is_pnacl ? NaClAppType::kPNaClLegacyPackagedApp |
| 1315 | : NaClAppType::kNaClLegacyPackagedApp; |
| 1316 | } else if (extension->is_platform_app()) { |
| 1317 | app_type = is_pnacl ? NaClAppType::kPNaClPlatformApp |
| 1318 | : NaClAppType::kNaClPlatformApp; |
| 1319 | } else if (extension->is_login_screen_extension()) { |
| 1320 | if (extension->manifest_version() >= 3) { |
| 1321 | app_type = is_pnacl ? NaClAppType::kPNaClLoginScreenMv3Extension |
| 1322 | : NaClAppType::kNaClLoginScreenMv3Extension; |
| 1323 | } else { |
| 1324 | app_type = is_pnacl ? NaClAppType::kPNaClLoginScreenMv2Extension |
| 1325 | : NaClAppType::kNaClLoginScreenMv2Extension; |
| 1326 | } |
| 1327 | } else { |
| 1328 | // We found an extension that is not covered by any metric |
| 1329 | NOTREACHED() << "Invalid NaCl usage in extension. Extension name: " |
| 1330 | << extension->name() << ", type: " << extension->GetType(); |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | base::UmaHistogramEnumeration("NaCl.EmbedderType", app_type); |
| 1335 | } |
| 1336 | #endif // BUILDFLAG(ENABLE_NACL) |
| 1337 | |
| 1338 | void ChromeContentRendererClient::PrepareErrorPage( |
| 1339 | content::RenderFrame* render_frame, |
| 1340 | const blink::WebURLError& web_error, |
| 1341 | const std::string& http_method, |
| 1342 | content::mojom::AlternativeErrorPageOverrideInfoPtr |
| 1343 | alternative_error_page_info, |
| 1344 | std::string* error_html) { |
| 1345 | NetErrorHelper::Get(render_frame) |
| 1346 | ->PrepareErrorPage( |
| 1347 | error_page::Error::NetError( |
| 1348 | web_error.url(), web_error.reason(), web_error.extended_reason(), |
| 1349 | web_error.resolve_error_info(), web_error.has_copy_in_cache()), |
| 1350 | http_method == "POST", std::move(alternative_error_page_info), |
| 1351 | error_html); |
| 1352 | |
| 1353 | #if BUILDFLAG(ENABLE_SUPERVISED_USERS) |
| 1354 | SupervisedUserErrorPageControllerDelegateImpl::Get(render_frame) |
| 1355 | ->PrepareForErrorPage(); |
| 1356 | #endif |
| 1357 | } |
| 1358 | |
| 1359 | void ChromeContentRendererClient::PrepareErrorPageForHttpStatusError( |
| 1360 | content::RenderFrame* render_frame, |
| 1361 | const blink::WebURLError& error, |
| 1362 | const std::string& http_method, |
| 1363 | int http_status, |
| 1364 | content::mojom::AlternativeErrorPageOverrideInfoPtr |
| 1365 | alternative_error_page_info, |
| 1366 | std::string* error_html) { |
| 1367 | NetErrorHelper::Get(render_frame) |
| 1368 | ->PrepareErrorPage(error_page::Error::HttpError(error.url(), http_status), |
| 1369 | http_method == "POST", |
| 1370 | std::move(alternative_error_page_info), error_html); |
| 1371 | } |
| 1372 | |
| 1373 | void ChromeContentRendererClient::PostSandboxInitialized() { |
| 1374 | #if BUILDFLAG(IS_CHROMEOS) |
| 1375 | DCHECK(!main_thread_profiler_); |
| 1376 | main_thread_profiler_ = ThreadProfiler::CreateAndStartOnMainThread(); |
| 1377 | #endif // BUILDFLAG(IS_CHROMEOS) |
| 1378 | } |
| 1379 | |
| 1380 | void ChromeContentRendererClient::PostIOThreadCreated( |
| 1381 | base::SingleThreadTaskRunner* io_thread_task_runner) { |
| 1382 | io_thread_task_runner->PostTask( |
| 1383 | FROM_HERE, base::BindOnce(&ThreadProfiler::StartOnChildThread, |
| 1384 | metrics::CallStackProfileParams::Thread::kIo)); |
| 1385 | } |
| 1386 | |
| 1387 | void ChromeContentRendererClient::PostCompositorThreadCreated( |
| 1388 | base::SingleThreadTaskRunner* compositor_thread_task_runner) { |
| 1389 | compositor_thread_task_runner->PostTask( |
| 1390 | FROM_HERE, |
| 1391 | base::BindOnce(&ThreadProfiler::StartOnChildThread, |
| 1392 | metrics::CallStackProfileParams::Thread::kCompositor)); |
| 1393 | // Enable stack sampling for tracing. |
| 1394 | // We pass in CreateCoreUnwindersFactory here since it lives in the chrome/ |
| 1395 | // layer while TracingSamplerProfiler is outside of chrome/. |
| 1396 | compositor_thread_task_runner->PostTask( |
| 1397 | FROM_HERE, |
| 1398 | base::BindOnce(&tracing::TracingSamplerProfiler:: |
| 1399 | CreateOnChildThreadWithCustomUnwinders, |
| 1400 | #if BUILDFLAG(IS_ANDROID) |
| 1401 | base::BindRepeating(&CreateCoreUnwindersFactory, false))); |
| 1402 | #else |
| 1403 | base::BindRepeating(&CreateCoreUnwindersFactory))); |
| 1404 | #endif // BUILDFLAG(IS_ANDROID) |
| 1405 | } |
| 1406 | |
| 1407 | bool ChromeContentRendererClient::RunIdleHandlerWhenWidgetsHidden() { |
| 1408 | return !IsStandaloneContentExtensionProcess(); |
| 1409 | } |
| 1410 | |
| 1411 | bool ChromeContentRendererClient::AllowPopup() { |
| 1412 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1413 | return ChromeExtensionsRendererClient::GetInstance()->AllowPopup(); |
| 1414 | #else |
| 1415 | return false; |
| 1416 | #endif |
| 1417 | } |
| 1418 | |
| 1419 | bool ChromeContentRendererClient::ShouldNotifyServiceWorkerOnWebSocketActivity( |
| 1420 | v8::Local<v8::Context> context) { |
| 1421 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1422 | extensions::ScriptContext* script_context = |
| 1423 | ChromeExtensionsRendererClient::GetInstance() |
| 1424 | ->extension_dispatcher() |
| 1425 | ->GetWorkerScriptContextSet() |
| 1426 | ->GetContextByV8Context(context); |
| 1427 | // Only notify on web socket activity if the service worker is the background |
| 1428 | // service worker for an extension. |
| 1429 | return script_context && |
| 1430 | ChromeExtensionsRendererClient::GetInstance() |
| 1431 | ->ExtensionAPIEnabledForServiceWorkerScript( |
| 1432 | script_context->service_worker_scope(), script_context->url()); |
| 1433 | #else |
| 1434 | return false; |
| 1435 | #endif |
| 1436 | } |
| 1437 | |
| 1438 | blink::ProtocolHandlerSecurityLevel |
| 1439 | ChromeContentRendererClient::GetProtocolHandlerSecurityLevel( |
| 1440 | const url::Origin& origin) { |
| 1441 | if (origin.scheme() == chrome::kIsolatedAppScheme) { |
| 1442 | return blink::ProtocolHandlerSecurityLevel::kSameOrigin; |
| 1443 | } |
| 1444 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1445 | return ChromeExtensionsRendererClient::GetInstance() |
| 1446 | ->GetProtocolHandlerSecurityLevel(); |
| 1447 | #else |
| 1448 | return blink::ProtocolHandlerSecurityLevel::kStrict; |
| 1449 | #endif |
| 1450 | } |
| 1451 | |
| 1452 | void ChromeContentRendererClient::WillSendRequest( |
| 1453 | WebLocalFrame* frame, |
| 1454 | ui::PageTransition transition_type, |
| 1455 | const blink::WebURL& url, |
| 1456 | const net::SiteForCookies& site_for_cookies, |
| 1457 | const url::Origin* initiator_origin, |
| 1458 | GURL* new_url) { |
| 1459 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1460 | // Check whether the request should be allowed. If not allowed, we reset the |
| 1461 | // URL to something invalid to prevent the request and cause an error. |
| 1462 | ChromeExtensionsRendererClient::GetInstance()->WillSendRequest( |
| 1463 | frame, transition_type, url, site_for_cookies, initiator_origin, new_url); |
| 1464 | if (!new_url->is_empty()) |
| 1465 | return; |
| 1466 | #endif |
| 1467 | |
| 1468 | if (!url.ProtocolIs(chrome::kChromeSearchScheme)) |
| 1469 | return; |
| 1470 | |
| 1471 | #if !BUILDFLAG(IS_ANDROID) |
| 1472 | SearchBox* search_box = |
| 1473 | SearchBox::Get(content::RenderFrame::FromWebFrame(frame->LocalRoot())); |
| 1474 | if (search_box) { |
| 1475 | // Note: this GURL copy could be avoided if host() were added to WebURL. |
| 1476 | GURL gurl(url); |
| 1477 | if (gurl.host_piece() == chrome::kChromeUIFaviconHost) |
| 1478 | search_box->GenerateImageURLFromTransientURL(url, new_url); |
| 1479 | } |
| 1480 | #endif // !BUILDFLAG(IS_ANDROID) |
| 1481 | } |
| 1482 | |
| 1483 | bool ChromeContentRendererClient::IsPrefetchOnly( |
| 1484 | content::RenderFrame* render_frame) { |
| 1485 | return prerender::NoStatePrefetchHelper::IsPrefetching(render_frame); |
| 1486 | } |
| 1487 | |
| 1488 | uint64_t ChromeContentRendererClient::VisitedLinkHash( |
| 1489 | std::string_view canonical_url) { |
| 1490 | return chrome_observer_->visited_link_reader()->ComputeURLFingerprint( |
| 1491 | canonical_url); |
| 1492 | } |
| 1493 | |
| 1494 | bool ChromeContentRendererClient::IsLinkVisited(uint64_t link_hash) { |
| 1495 | return chrome_observer_->visited_link_reader()->IsVisited(link_hash); |
| 1496 | } |
| 1497 | |
| 1498 | std::unique_ptr<blink::WebPrescientNetworking> |
| 1499 | ChromeContentRendererClient::CreatePrescientNetworking( |
| 1500 | content::RenderFrame* render_frame) { |
| 1501 | return std::make_unique<network_hints::WebPrescientNetworkingImpl>( |
| 1502 | render_frame); |
| 1503 | } |
| 1504 | |
| 1505 | bool ChromeContentRendererClient::IsExternalPepperPlugin( |
| 1506 | const std::string& module_name) { |
| 1507 | // TODO(bbudge) remove this when the trusted NaCl plugin has been removed. |
| 1508 | // We must defer certain plugin events for NaCl instances since we switch |
| 1509 | // from the in-process to the out-of-process proxy after instantiating them. |
| 1510 | return module_name == "Native Client"; |
| 1511 | } |
| 1512 | |
| 1513 | bool ChromeContentRendererClient::IsOriginIsolatedPepperPlugin( |
| 1514 | const base::FilePath& plugin_path) { |
| 1515 | // Hosting plugins in-process is inherently incompatible with attempting to |
| 1516 | // process-isolate plugins from different origins. |
| 1517 | auto* cmdline = base::CommandLine::ForCurrentProcess(); |
| 1518 | if (cmdline->HasSwitch(switches::kPpapiInProcess)) { |
| 1519 | // The kPpapiInProcess switch should only be used by tests. In particular, |
| 1520 | // we expect that the PDF plugin should always be isolated in the product |
| 1521 | // (and that the switch won't interfere with PDF isolation). |
| 1522 | CHECK_NE(ChromeContentClient::kPDFInternalPluginPath, plugin_path.value()); |
| 1523 | |
| 1524 | return false; |
| 1525 | } |
| 1526 | |
| 1527 | #if BUILDFLAG(ENABLE_NACL) |
| 1528 | // Don't isolate the NaCl plugin (preserving legacy behavior). |
| 1529 | if (plugin_path.value() == nacl::kInternalNaClPluginFileName) |
| 1530 | return false; |
| 1531 | #endif |
| 1532 | |
| 1533 | // Isolate all the other plugins (including the PDF plugin + test plugins). |
| 1534 | return true; |
| 1535 | } |
| 1536 | |
| 1537 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
| 1538 | bool ChromeContentRendererClient::IsExtensionOrSharedModuleAllowed( |
| 1539 | const GURL& url, |
| 1540 | const std::set<std::string>& allowlist) { |
| 1541 | const extensions::ExtensionSet* extension_set = |
| 1542 | extensions::RendererExtensionRegistry::Get()->GetMainThreadExtensionSet(); |
| 1543 | return ::IsExtensionOrSharedModuleAllowed(url, extension_set, allowlist); |
| 1544 | } |
| 1545 | #endif |
| 1546 | |
| 1547 | #if BUILDFLAG(ENABLE_SPELLCHECK) |
| 1548 | void ChromeContentRendererClient::InitSpellCheck() { |
| 1549 | spellcheck_ = std::make_unique<SpellCheck>(this); |
| 1550 | } |
| 1551 | #endif |
| 1552 | |
| 1553 | ChromeRenderThreadObserver* ChromeContentRendererClient::GetChromeObserver() |
| 1554 | const { |
| 1555 | return chrome_observer_.get(); |
| 1556 | } |
| 1557 | |
| 1558 | web_cache::WebCacheImpl* ChromeContentRendererClient::GetWebCache() { |
| 1559 | return web_cache_impl_.get(); |
| 1560 | } |
| 1561 | |
| 1562 | chrome::WebRtcLoggingAgentImpl* |
| 1563 | ChromeContentRendererClient::GetWebRtcLoggingAgent() { |
| 1564 | if (!webrtc_logging_agent_impl_) { |
| 1565 | webrtc_logging_agent_impl_ = |
| 1566 | std::make_unique<chrome::WebRtcLoggingAgentImpl>(); |
| 1567 | } |
| 1568 | return webrtc_logging_agent_impl_.get(); |
| 1569 | } |
| 1570 | |
| 1571 | #if BUILDFLAG(ENABLE_SPELLCHECK) |
| 1572 | SpellCheck* ChromeContentRendererClient::GetSpellCheck() { |
| 1573 | return spellcheck_.get(); |
| 1574 | } |
| 1575 | #endif // BUILDFLAG(ENABLE_SPELLCHECK) |
| 1576 | |
| 1577 | std::unique_ptr<blink::WebSocketHandshakeThrottleProvider> |
| 1578 | ChromeContentRendererClient::CreateWebSocketHandshakeThrottleProvider() { |
| 1579 | return std::make_unique<WebSocketHandshakeThrottleProviderImpl>( |
| 1580 | browser_interface_broker_.get()); |
| 1581 | } |
| 1582 | |
| 1583 | void ChromeContentRendererClient::GetSupportedKeySystems( |
| 1584 | media::GetSupportedKeySystemsCB cb) { |
| 1585 | #if BUILDFLAG(ENABLE_LIBRARY_CDMS) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_ANDROID) |
| 1586 | GetChromeKeySystems(std::move(cb)); |
| 1587 | #else |
| 1588 | std::move(cb).Run({}); |
| 1589 | #endif |
| 1590 | } |
| 1591 | |
| 1592 | bool ChromeContentRendererClient::ShouldReportDetailedMessageForSource( |
| 1593 | const std::u16string& source) { |
| 1594 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1595 | return extensions::IsSourceFromAnExtension(source); |
| 1596 | #else |
| 1597 | return false; |
| 1598 | #endif |
| 1599 | } |
| 1600 | |
| 1601 | std::unique_ptr<blink::WebContentSettingsClient> |
| 1602 | ChromeContentRendererClient::CreateWorkerContentSettingsClient( |
| 1603 | content::RenderFrame* render_frame) { |
| 1604 | return std::make_unique<WorkerContentSettingsClient>(render_frame); |
| 1605 | } |
| 1606 | |
| 1607 | #if BUILDFLAG(ENABLE_SPEECH_SERVICE) |
| 1608 | std::unique_ptr<media::SpeechRecognitionClient> |
| 1609 | ChromeContentRendererClient::CreateSpeechRecognitionClient( |
| 1610 | content::RenderFrame* render_frame) { |
| 1611 | return std::make_unique<ChromeSpeechRecognitionClient>(render_frame); |
| 1612 | } |
| 1613 | #endif // BUILDFLAG(ENABLE_SPEECH_SERVICE) |
| 1614 | |
| 1615 | bool ChromeContentRendererClient::IsPluginAllowedToUseCameraDeviceAPI( |
| 1616 | const GURL& url) { |
| 1617 | #if BUILDFLAG(ENABLE_PLUGINS) && BUILDFLAG(ENABLE_EXTENSIONS) |
| 1618 | #if BUILDFLAG(ENABLE_PPAPI) |
| 1619 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1620 | switches::kEnablePepperTesting)) |
| 1621 | return true; |
| 1622 | #endif // BUILDFLAG(ENABLE_PPAPI) |
| 1623 | |
| 1624 | if (IsExtensionOrSharedModuleAllowed(url, allowed_camera_device_origins_)) |
| 1625 | return true; |
| 1626 | #endif |
| 1627 | |
| 1628 | return false; |
| 1629 | } |
| 1630 | |
| 1631 | void ChromeContentRendererClient::RunScriptsAtDocumentStart( |
| 1632 | content::RenderFrame* render_frame) { |
| 1633 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1634 | ChromeExtensionsRendererClient::GetInstance()->RunScriptsAtDocumentStart( |
| 1635 | render_frame); |
| 1636 | // |render_frame| might be dead by now. |
| 1637 | #endif |
| 1638 | } |
| 1639 | |
| 1640 | void ChromeContentRendererClient::RunScriptsAtDocumentEnd( |
| 1641 | content::RenderFrame* render_frame) { |
| 1642 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1643 | ChromeExtensionsRendererClient::GetInstance()->RunScriptsAtDocumentEnd( |
| 1644 | render_frame); |
| 1645 | // |render_frame| might be dead by now. |
| 1646 | #endif |
| 1647 | } |
| 1648 | |
| 1649 | void ChromeContentRendererClient::RunScriptsAtDocumentIdle( |
| 1650 | content::RenderFrame* render_frame) { |
| 1651 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1652 | ChromeExtensionsRendererClient::GetInstance()->RunScriptsAtDocumentIdle( |
| 1653 | render_frame); |
| 1654 | // |render_frame| might be dead by now. |
| 1655 | #endif |
| 1656 | } |
| 1657 | |
| 1658 | void ChromeContentRendererClient:: |
| 1659 | SetRuntimeFeaturesDefaultsBeforeBlinkInitialization() { |
| 1660 | // The performance manager service interfaces are provided by the chrome |
| 1661 | // embedder only. |
| 1662 | blink::WebRuntimeFeatures::EnablePerformanceManagerInstrumentation(true); |
| 1663 | |
| 1664 | MaybeEnableWebShare(); |
| 1665 | |
| 1666 | if (base::FeatureList::IsEnabled( |
| 1667 | autofill::features::kAutofillSharedAutofill)) { |
| 1668 | blink::WebRuntimeFeatures::EnableSharedAutofill(true); |
| 1669 | } |
| 1670 | |
| 1671 | if (base::FeatureList::IsEnabled(subresource_filter::kAdTagging)) |
| 1672 | blink::WebRuntimeFeatures::EnableAdTagging(true); |
| 1673 | |
| 1674 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1675 | // WebHID and WebUSB on service workers is only available in extensions. |
| 1676 | if (IsStandaloneContentExtensionProcess()) { |
| 1677 | if (base::FeatureList::IsEnabled( |
| 1678 | features::kEnableWebUsbOnExtensionServiceWorker)) { |
| 1679 | blink::WebRuntimeFeatures::EnableWebUSBOnServiceWorkers(true); |
| 1680 | } |
| 1681 | #if !BUILDFLAG(IS_ANDROID) |
| 1682 | if (base::FeatureList::IsEnabled( |
| 1683 | features::kEnableWebHidOnExtensionServiceWorker)) { |
| 1684 | blink::WebRuntimeFeatures::EnableWebHIDOnServiceWorkers(true); |
| 1685 | } |
| 1686 | #endif // !BUILDFLAG(IS_ANDROID) |
| 1687 | } |
| 1688 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 1689 | } |
| 1690 | |
| 1691 | bool ChromeContentRendererClient::AllowScriptExtensionForServiceWorker( |
| 1692 | const url::Origin& script_origin) { |
| 1693 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1694 | return script_origin.scheme() == extensions::kExtensionScheme; |
| 1695 | #else |
| 1696 | return false; |
| 1697 | #endif |
| 1698 | } |
| 1699 | |
| 1700 | void ChromeContentRendererClient:: |
| 1701 | WillInitializeServiceWorkerContextOnWorkerThread() { |
| 1702 | // This is called on the service worker thread. |
| 1703 | ThreadProfiler::StartOnChildThread( |
| 1704 | metrics::CallStackProfileParams::Thread::kServiceWorker); |
| 1705 | } |
| 1706 | |
| 1707 | void ChromeContentRendererClient:: |
| 1708 | DidInitializeServiceWorkerContextOnWorkerThread( |
| 1709 | blink::WebServiceWorkerContextProxy* context_proxy, |
| 1710 | const GURL& service_worker_scope, |
| 1711 | const GURL& script_url) { |
| 1712 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1713 | ChromeExtensionsRendererClient::GetInstance() |
| 1714 | ->extension_dispatcher() |
| 1715 | ->DidInitializeServiceWorkerContextOnWorkerThread( |
| 1716 | context_proxy, service_worker_scope, script_url); |
| 1717 | #endif |
| 1718 | } |
| 1719 | |
| 1720 | void ChromeContentRendererClient::WillEvaluateServiceWorkerOnWorkerThread( |
| 1721 | blink::WebServiceWorkerContextProxy* context_proxy, |
| 1722 | v8::Local<v8::Context> v8_context, |
| 1723 | int64_t service_worker_version_id, |
| 1724 | const GURL& service_worker_scope, |
| 1725 | const GURL& script_url) { |
| 1726 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1727 | ChromeExtensionsRendererClient::GetInstance() |
| 1728 | ->extension_dispatcher() |
| 1729 | ->WillEvaluateServiceWorkerOnWorkerThread( |
| 1730 | context_proxy, v8_context, service_worker_version_id, |
| 1731 | service_worker_scope, script_url); |
| 1732 | #endif |
| 1733 | } |
| 1734 | |
| 1735 | void ChromeContentRendererClient::DidStartServiceWorkerContextOnWorkerThread( |
| 1736 | int64_t service_worker_version_id, |
| 1737 | const GURL& service_worker_scope, |
| 1738 | const GURL& script_url) { |
| 1739 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1740 | ChromeExtensionsRendererClient::GetInstance() |
| 1741 | ->extension_dispatcher() |
| 1742 | ->DidStartServiceWorkerContextOnWorkerThread( |
| 1743 | service_worker_version_id, service_worker_scope, script_url); |
| 1744 | #endif |
| 1745 | } |
| 1746 | |
| 1747 | void ChromeContentRendererClient::WillDestroyServiceWorkerContextOnWorkerThread( |
| 1748 | v8::Local<v8::Context> context, |
| 1749 | int64_t service_worker_version_id, |
| 1750 | const GURL& service_worker_scope, |
| 1751 | const GURL& script_url) { |
| 1752 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1753 | ChromeExtensionsRendererClient::GetInstance() |
| 1754 | ->extension_dispatcher() |
| 1755 | ->WillDestroyServiceWorkerContextOnWorkerThread( |
| 1756 | context, service_worker_version_id, service_worker_scope, script_url); |
| 1757 | #endif |
| 1758 | } |
| 1759 | |
| 1760 | // If we're in an extension, there is no need disabling multiple routes as |
| 1761 | // chrome.system.network.getNetworkInterfaces provides the same |
| 1762 | // information. Also, the enforcement of sending and binding UDP is already done |
| 1763 | // by chrome extension permission model. |
| 1764 | bool ChromeContentRendererClient::ShouldEnforceWebRTCRoutingPreferences() { |
| 1765 | return !IsStandaloneContentExtensionProcess(); |
| 1766 | } |
| 1767 | |
| 1768 | GURL ChromeContentRendererClient::OverrideFlashEmbedWithHTML(const GURL& url) { |
| 1769 | if (!url.is_valid()) |
| 1770 | return GURL(); |
| 1771 | |
| 1772 | return FlashEmbedRewrite::RewriteFlashEmbedURL(url); |
| 1773 | } |
| 1774 | |
| 1775 | std::unique_ptr<blink::URLLoaderThrottleProvider> |
| 1776 | ChromeContentRendererClient::CreateURLLoaderThrottleProvider( |
| 1777 | blink::URLLoaderThrottleProviderType provider_type) { |
| 1778 | return URLLoaderThrottleProviderImpl::Create(provider_type, this, |
| 1779 | browser_interface_broker_.get()); |
| 1780 | } |
| 1781 | |
| 1782 | blink::WebFrame* ChromeContentRendererClient::FindFrame( |
| 1783 | blink::WebLocalFrame* relative_to_frame, |
| 1784 | const std::string& name) { |
| 1785 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1786 | return ChromeExtensionsRendererClient::FindFrame(relative_to_frame, name); |
| 1787 | #else |
| 1788 | return nullptr; |
| 1789 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 1790 | } |
| 1791 | |
| 1792 | bool ChromeContentRendererClient::IsSafeRedirectTarget(const GURL& from_url, |
| 1793 | const GURL& to_url) { |
| 1794 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1795 | if (to_url.SchemeIs(extensions::kExtensionScheme)) { |
| 1796 | const extensions::Extension* extension = |
| 1797 | extensions::RendererExtensionRegistry::Get()->GetByID(to_url.host()); |
| 1798 | if (!extension) |
| 1799 | return false; |
| 1800 | // TODO(solomonkinard): Use initiator_origin and add tests. |
| 1801 | if (extensions::WebAccessibleResourcesInfo::IsResourceWebAccessible( |
| 1802 | extension, to_url.path(), nullptr)) { |
| 1803 | return true; |
| 1804 | } |
| 1805 | return extension->guid() == from_url.host(); |
| 1806 | } |
| 1807 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
| 1808 | return true; |
| 1809 | } |
| 1810 | |
| 1811 | void ChromeContentRendererClient::DidSetUserAgent( |
| 1812 | const std::string& user_agent) { |
| 1813 | #if BUILDFLAG(ENABLE_PRINTING) |
| 1814 | printing::SetAgent(user_agent); |
| 1815 | #endif |
| 1816 | } |
| 1817 | |
| 1818 | void ChromeContentRendererClient::AppendContentSecurityPolicy( |
| 1819 | const blink::WebURL& url, |
| 1820 | blink::WebVector<blink::WebContentSecurityPolicyHeader>* csp) { |
| 1821 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 1822 | #if BUILDFLAG(ENABLE_PDF) |
| 1823 | // Don't apply default CSP to PDF renderers. |
| 1824 | // TODO(crbug.com/1252096): Lock down the CSP once style and script are no |
| 1825 | // longer injected inline by `pdf::PluginResponseWriter`. That class may be a |
| 1826 | // better place to define such CSP, or we may continue doing so here. |
| 1827 | if (pdf::IsPdfRenderer()) |
| 1828 | return; |
| 1829 | #endif // BUILDFLAG(ENABLE_PDF) |
| 1830 | |
| 1831 | DCHECK(csp); |
| 1832 | GURL gurl(url); |
| 1833 | const extensions::Extension* extension = |
| 1834 | extensions::RendererExtensionRegistry::Get()->GetExtensionOrAppByURL( |
| 1835 | gurl); |
| 1836 | if (!extension) |
| 1837 | return; |
| 1838 | |
| 1839 | // Append a minimum CSP to ensure the extension can't relax the default |
| 1840 | // applied CSP through means like Service Worker. |
| 1841 | const std::string* default_csp = |
| 1842 | extensions::CSPInfo::GetMinimumCSPToAppend(*extension, gurl.path()); |
| 1843 | if (!default_csp) |
| 1844 | return; |
| 1845 | |
| 1846 | csp->push_back({blink::WebString::FromUTF8(*default_csp), |
| 1847 | network::mojom::ContentSecurityPolicyType::kEnforce, |
| 1848 | network::mojom::ContentSecurityPolicySource::kHTTP}); |
| 1849 | #endif |
| 1850 | } |