Skip to content

Commit

Permalink
sensors: Make Blink Mojo requests go through a new WebSensorProvider …
Browse files Browse the repository at this point in the history
…interface

This is being done in preparation for adding the concept of "virtual
sensors" that implement the Automation section of the Generic Sensor
spec.

Virtual sensors manipulation is a privileged operation that should not
be exposed to Blink, so we now add a blink.mojom.WebSensorProvider
interface that it is supposed to use instead of
device.mojom.SensorProvider. FrameSensorProviderProxy in //content is
responsible for receiving WebSensorProvider requests and translating
them into SensorProvider ones that reach //services via
WebContentsSensorProviderProxy.

At the moment, both Mojo interfaces expose the same GetSensor() method,
but the idea is for SensorProvider to have extra virtual sensor methods
that WebSensorProvider will not.

Bug: 1278377
Change-Id: I96ea78f66cd6219cb46a49b90791dd17fde2d085
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4916233
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Reviewed-by: Alex Moshchuk <alexmos@chromium.org>
Reviewed-by: Emily Stark <estark@chromium.org>
Commit-Queue: Raphael Kubo Da Costa <raphael.kubo.da.costa@intel.com>
Reviewed-by: Ben Pastene <bpastene@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1206683}
  • Loading branch information
rakuco authored and pull[bot] committed Oct 12, 2023
1 parent 53ad4d3 commit 1001438
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions resources/chromium/generic_sensor_mocks.js
@@ -1,5 +1,6 @@
import {ReportingMode, Sensor, SensorClientRemote, SensorReceiver, SensorRemote, SensorType} from '/gen/services/device/public/mojom/sensor.mojom.m.js';
import {SensorCreationResult, SensorInitParams_READ_BUFFER_SIZE_FOR_TESTS, SensorProvider, SensorProviderReceiver} from '/gen/services/device/public/mojom/sensor_provider.mojom.m.js';
import {SensorCreationResult, SensorInitParams_READ_BUFFER_SIZE_FOR_TESTS} from '/gen/services/device/public/mojom/sensor_provider.mojom.m.js';
import {WebSensorProvider, WebSensorProviderReceiver} from '/gen/third_party/blink/public/mojom/sensor/web_sensor_provider.mojom.m.js';

// A "sliding window" that iterates over |data| and returns one item at a
// time, advancing and wrapping around as needed. |data| must be an array of
Expand Down Expand Up @@ -287,8 +288,8 @@ self.GenericSensorTest = (() => {
}
}

// Class that mocks SensorProvider interface defined in
// https://cs.chromium.org/chromium/src/services/device/public/mojom/sensor_provider.mojom
// Class that mocks the WebSensorProvider interface defined in
// https://cs.chromium.org/chromium/src/third_party/blink/public/mojom/sensor/web_sensor_provider.mojom
class MockSensorProvider {
constructor() {
this.readingSizeInBytes_ =
Expand Down Expand Up @@ -334,10 +335,10 @@ self.GenericSensorTest = (() => {
SensorType.RELATIVE_ORIENTATION_EULER_ANGLES],
['ProximitySensor', SensorType.PROXIMITY]
]);
this.receiver_ = new SensorProviderReceiver(this);
this.receiver_ = new WebSensorProviderReceiver(this);

this.interceptor_ =
new MojoInterfaceInterceptor(SensorProvider.$interfaceName);
new MojoInterfaceInterceptor(WebSensorProvider.$interfaceName);
this.interceptor_.oninterfacerequest = e => {
this.bindToPipe(e.handle);
};
Expand Down

0 comments on commit 1001438

Please sign in to comment.