chrome_content_browser_client_binder_policies.cc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "chrome/browser/chrome_content_browser_client_binder_policies.h"
  5. #include "chrome/browser/ui/webui/bluetooth_internals/bluetooth_internals.mojom.h"
  6. #include "components/autofill/content/common/mojom/autofill_driver.mojom.h"
  7. #include "components/page_load_metrics/common/page_load_metrics.mojom.h"
  8. #include "components/subresource_filter/content/mojom/subresource_filter.mojom.h"
  9. #include "extensions/buildflags/buildflags.h"
  10. #include "third_party/blink/public/common/features.h"
  11. #if BUILDFLAG(ENABLE_EXTENSIONS)
  12. #include "extensions/common/mojom/frame.mojom.h"
  13. #endif
  14. namespace {
  15. // Registers policies for interfaces registered in
  16. // `RegisterBrowserInterfaceBindersForFrame()`.
  17. void RegisterPoliciesForNonAssociatedInterfaces(
  18. content::MojoBinderPolicyMap& policy_map) {
  19. // Prerendering does not happen for WebUI pages, so set kUnexpected as the
  20. // policy for interfaces registered by WebUI.
  21. policy_map.SetNonAssociatedPolicy<::mojom::BluetoothInternalsHandler>(
  22. content::MojoBinderNonAssociatedPolicy::kUnexpected);
  23. }
  24. // Registers policies for channel-associated interfaces registered in
  25. // `RegisterAssociatedInterfaceBindersForRenderFrameHost()`.
  26. void RegisterPoliciesForChannelAssociatedInterfaces(
  27. content::MojoBinderPolicyMap& policy_map) {
  28. policy_map.SetAssociatedPolicy<page_load_metrics::mojom::PageLoadMetrics>(
  29. content::MojoBinderAssociatedPolicy::kGrant);
  30. policy_map
  31. .SetAssociatedPolicy<subresource_filter::mojom::SubresourceFilterHost>(
  32. content::MojoBinderAssociatedPolicy::kGrant);
  33. #if BUILDFLAG(ENABLE_EXTENSIONS)
  34. // LocalFrameHost supports content scripts related APIs, which are
  35. // RequestScriptInjectionPermission, GetInstallState, SendRequestIPC, and
  36. // notifying CSS selector updates. These APIs are used by Chrome Extensions
  37. // under proper permission managements beyond the page boundaries.
  38. if (blink::features::IsPrerender2Enabled()) {
  39. policy_map.SetAssociatedPolicy<extensions::mojom::LocalFrameHost>(
  40. content::MojoBinderAssociatedPolicy::kGrant);
  41. }
  42. #endif
  43. }
  44. } // namespace
  45. void RegisterChromeMojoBinderPoliciesForSameOriginPrerendering(
  46. content::MojoBinderPolicyMap& policy_map) {
  47. RegisterPoliciesForNonAssociatedInterfaces(policy_map);
  48. RegisterPoliciesForChannelAssociatedInterfaces(policy_map);
  49. }