blob: 466827c1e7b752f7c31e32aae946415183b13a7f [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2019 The Chromium Authors
Oksana Zhuravlovafee097c2019-07-26 17:01:302// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_BROWSER_INTERFACE_BINDERS_H_
6#define CONTENT_BROWSER_BROWSER_INTERFACE_BINDERS_H_
7
Avi Drissmanadac21992023-01-11 23:46:398#include "base/functional/callback.h"
Ken Rockot05499cf2019-12-12 05:22:549#include "content/common/content_export.h"
François Doray869d4bf2025-06-30 21:20:1110#include "mojo/public/cpp/bindings/receiver.h"
Johann165093e32020-11-18 04:25:3011#include "services/device/public/mojom/battery_monitor.mojom-forward.h"
Ken Rockot05499cf2019-12-12 05:22:5412#include "services/device/public/mojom/vibration_manager.mojom-forward.h"
Nina Satragnoe8cffbb2025-01-17 16:15:0213#include "third_party/blink/public/mojom/webauthn/authenticator.mojom-forward.h"
Oksana Zhuravlovaceb2cef52019-08-09 01:09:5914#include "url/origin.h"
Oksana Zhuravlovafee097c2019-07-26 17:01:3015
François Doray869d4bf2025-06-30 21:20:1116namespace mojo {
17class BinderMap;
18template <typename>
19class BinderMapWithContext;
20} // namespace mojo
21
Oksana Zhuravlovafee097c2019-07-26 17:01:3022namespace content {
23
Oksana Zhuravlovaceb2cef52019-08-09 01:09:5924class RenderFrameHost;
Oksana Zhuravlovafee097c2019-07-26 17:01:3025class RenderFrameHostImpl;
26class DedicatedWorkerHost;
Oksana Zhuravlovaceb2cef52019-08-09 01:09:5927class SharedWorkerHost;
Yao Xiao94203f52024-09-13 17:35:5728class SharedStorageWorkletHost;
Hiroki Nakagawa593b6f52020-05-25 03:10:2529class ServiceWorkerHost;
Hans Wennborg2141eeb822021-05-27 11:17:2930struct ServiceWorkerVersionInfo;
Julie Jeongeun Kime58b0f42021-04-22 05:33:2831struct ServiceWorkerVersionBaseInfo;
Oksana Zhuravlovafee097c2019-07-26 17:01:3032
33namespace internal {
34
35// PopulateBinderMap() registers BrowserInterfaceBroker's GetInterface()
36// handler callbacks for different execution context types.
37// An implementation of BrowserInterfaceBroker calls the relevant
38// PopulateBinderMap() function passing its host execution context instance
39// as the first argument and its interface name to handler map as the
40// second one.
41// This mechanism will replace interface registries and binders used for
42// handling InterfaceProvider's GetInterface() calls (see crbug.com/718652).
43
44// Registers the handlers for interfaces requested by frames.
Robert Sesek5a5fbb82020-05-04 16:18:2845void PopulateBinderMap(RenderFrameHostImpl* host, mojo::BinderMap* map);
Oksana Zhuravlovaceb2cef52019-08-09 01:09:5946void PopulateBinderMapWithContext(
Oksana Zhuravlovad4bbeec2019-08-13 21:43:5747 RenderFrameHostImpl* host,
Robert Sesek5a5fbb82020-05-04 16:18:2848 mojo::BinderMapWithContext<RenderFrameHost*>* map);
Oksana Zhuravlovad4bbeec2019-08-13 21:43:5749RenderFrameHost* GetContextForHost(RenderFrameHostImpl* host);
Oksana Zhuravlovafee097c2019-07-26 17:01:3050
51// Registers the handlers for interfaces requested by dedicated workers.
Robert Sesek5a5fbb82020-05-04 16:18:2852void PopulateBinderMap(DedicatedWorkerHost* host, mojo::BinderMap* map);
Oksana Zhuravlovaceb2cef52019-08-09 01:09:5953void PopulateBinderMapWithContext(
Oksana Zhuravlovad4bbeec2019-08-13 21:43:5754 DedicatedWorkerHost* host,
Robert Sesek5a5fbb82020-05-04 16:18:2855 mojo::BinderMapWithContext<const url::Origin&>* map);
Oksana Zhuravlovad4bbeec2019-08-13 21:43:5756const url::Origin& GetContextForHost(DedicatedWorkerHost* host);
Oksana Zhuravlovaceb2cef52019-08-09 01:09:5957
58// Registers the handlers for interfaces requested by shared workers.
Robert Sesek5a5fbb82020-05-04 16:18:2859void PopulateBinderMap(SharedWorkerHost* host, mojo::BinderMap* map);
Oksana Zhuravlovaceb2cef52019-08-09 01:09:5960void PopulateBinderMapWithContext(
Oksana Zhuravlovad4bbeec2019-08-13 21:43:5761 SharedWorkerHost* host,
Robert Sesek5a5fbb82020-05-04 16:18:2862 mojo::BinderMapWithContext<const url::Origin&>* map);
Oksana Zhuravlovad4bbeec2019-08-13 21:43:5763url::Origin GetContextForHost(SharedWorkerHost* host);
64
Yao Xiao94203f52024-09-13 17:35:5765// Registers the handlers for interfaces requested by shared storage worklets.
66void PopulateBinderMap(SharedStorageWorkletHost* host, mojo::BinderMap* map);
67void PopulateBinderMapWithContext(
68 SharedStorageWorkletHost* host,
69 mojo::BinderMapWithContext<SharedStorageWorkletHost*>* map);
70SharedStorageWorkletHost* GetContextForHost(SharedStorageWorkletHost* host);
71
Oksana Zhuravlovad4bbeec2019-08-13 21:43:5772// Registers the handlers for interfaces requested by service workers.
Hiroki Nakagawa593b6f52020-05-25 03:10:2573void PopulateBinderMap(ServiceWorkerHost* host, mojo::BinderMap* map);
Oksana Zhuravlovad4bbeec2019-08-13 21:43:5774void PopulateBinderMapWithContext(
Hiroki Nakagawa593b6f52020-05-25 03:10:2575 ServiceWorkerHost* host,
Julie Jeongeun Kime58b0f42021-04-22 05:33:2876 mojo::BinderMapWithContext<const ServiceWorkerVersionBaseInfo&>* map);
Hiroki Nakagawa593b6f52020-05-25 03:10:2577ServiceWorkerVersionInfo GetContextForHost(ServiceWorkerHost* host);
Oksana Zhuravlovafee097c2019-07-26 17:01:3078
79} // namespace internal
Ken Rockot05499cf2019-12-12 05:22:5480
Johann165093e32020-11-18 04:25:3081// Allows tests to override how frame hosts bind BatteryMonitor receivers.
82using BatteryMonitorBinder = base::RepeatingCallback<void(
83 mojo::PendingReceiver<device::mojom::BatteryMonitor>)>;
84CONTENT_EXPORT void OverrideBatteryMonitorBinderForTesting(
85 BatteryMonitorBinder binder);
86
Ken Rockot05499cf2019-12-12 05:22:5487// Allows tests to override how frame hosts bind VibrationManager receivers.
88using VibrationManagerBinder = base::RepeatingCallback<void(
Seung Jae Limc16c5e12024-05-10 23:30:0089 mojo::PendingReceiver<device::mojom::VibrationManager>,
90 mojo::PendingRemote<device::mojom::VibrationManagerListener>)>;
Ken Rockot05499cf2019-12-12 05:22:5491CONTENT_EXPORT void OverrideVibrationManagerBinderForTesting(
92 VibrationManagerBinder binder);
93
Oksana Zhuravlovafee097c2019-07-26 17:01:3094} // namespace content
95
96#endif // CONTENT_BROWSER_BROWSER_INTERFACE_BINDERS_H_