OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SensorProxy_h | 5 #ifndef SensorProxy_h |
6 #define SensorProxy_h | 6 #define SensorProxy_h |
7 | 7 |
8 #include "core/dom/ExceptionCode.h" | 8 #include "core/dom/ExceptionCode.h" |
9 #include "core/page/PageVisibilityObserver.h" | 9 #include "core/page/PageVisibilityObserver.h" |
10 #include "device/generic_sensor/public/cpp/sensor_reading.h" | 10 #include "device/generic_sensor/public/cpp/sensor_reading.h" |
11 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" | 11 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" |
12 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" | 12 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" |
13 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
14 #include "platform/Supplementable.h" | 14 #include "platform/Supplementable.h" |
15 #include "platform/heap/Handle.h" | 15 #include "platform/heap/Handle.h" |
| 16 #include "public/platform/modules/permissions/permission.mojom-blink.h" |
| 17 #include "public/platform/modules/permissions/permission_status.mojom-blink.h" |
16 #include "wtf/Vector.h" | 18 #include "wtf/Vector.h" |
17 | 19 |
18 namespace blink { | 20 namespace blink { |
19 | 21 |
20 class SensorProviderProxy; | 22 class SensorProviderProxy; |
21 class SensorReading; | 23 class SensorReading; |
22 class SensorReadingUpdater; | 24 class SensorReadingUpdater; |
| 25 class SecurityOrigin; |
23 | 26 |
24 // This class wraps 'Sensor' mojo interface and used by multiple | 27 // This class wraps 'Sensor' mojo interface and used by multiple |
25 // JS sensor instances of the same type (within a single frame). | 28 // JS sensor instances of the same type (within a single frame). |
26 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, | 29 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, |
27 public device::mojom::blink::SensorClient, | 30 public device::mojom::blink::SensorClient, |
| 31 public mojom::blink::PermissionObserver, |
28 public PageVisibilityObserver { | 32 public PageVisibilityObserver { |
29 USING_GARBAGE_COLLECTED_MIXIN(SensorProxy); | 33 USING_GARBAGE_COLLECTED_MIXIN(SensorProxy); |
30 USING_PRE_FINALIZER(SensorProxy, Dispose); | 34 USING_PRE_FINALIZER(SensorProxy, Dispose); |
31 WTF_MAKE_NONCOPYABLE(SensorProxy); | 35 WTF_MAKE_NONCOPYABLE(SensorProxy); |
32 | 36 |
33 public: | 37 public: |
34 class Observer : public GarbageCollectedMixin { | 38 class Observer : public GarbageCollectedMixin { |
35 public: | 39 public: |
36 // Has valid 'Sensor' binding, {add, remove}Configuration() | 40 // Has valid 'Sensor' binding, {add, remove}Configuration() |
37 // methods can be called. | 41 // methods can be called. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const WTF::Vector<double>& FrequenciesUsed() const { | 100 const WTF::Vector<double>& FrequenciesUsed() const { |
97 return frequencies_used_; | 101 return frequencies_used_; |
98 } | 102 } |
99 | 103 |
100 DECLARE_VIRTUAL_TRACE(); | 104 DECLARE_VIRTUAL_TRACE(); |
101 | 105 |
102 private: | 106 private: |
103 friend class SensorProviderProxy; | 107 friend class SensorProviderProxy; |
104 friend class SensorReadingUpdaterContinuous; | 108 friend class SensorReadingUpdaterContinuous; |
105 friend class SensorReadingUpdaterOnChange; | 109 friend class SensorReadingUpdaterOnChange; |
106 SensorProxy(device::mojom::blink::SensorType, SensorProviderProxy*, Page*); | 110 SensorProxy(device::mojom::blink::SensorType, |
| 111 RefPtr<SecurityOrigin>, |
| 112 SensorProviderProxy*, |
| 113 Page*); |
107 | 114 |
108 // Updates sensor reading from shared buffer. | 115 // Updates sensor reading from shared buffer. |
109 void UpdateSensorReading(); | 116 void UpdateSensorReading(); |
110 void NotifySensorChanged(double timestamp); | 117 void NotifySensorChanged(double timestamp); |
111 | 118 |
112 // device::mojom::blink::SensorClient overrides. | 119 // device::mojom::blink::SensorClient overrides. |
113 void RaiseError() override; | 120 void RaiseError() override; |
114 void SensorReadingChanged() override; | 121 void SensorReadingChanged() override; |
115 | 122 |
116 // PageVisibilityObserver overrides. | 123 // PageVisibilityObserver overrides. |
117 void PageVisibilityChanged() override; | 124 void PageVisibilityChanged() override; |
118 | 125 |
119 // Generic handler for a fatal error. | 126 // Generic handler for a fatal error. |
120 void HandleSensorError(); | 127 void HandleSensorError(); |
121 | 128 |
122 // mojo call callbacks. | 129 // mojo call callbacks. |
123 void OnSensorCreated(device::mojom::blink::SensorInitParamsPtr, | 130 void OnSensorCreated(device::mojom::blink::SensorInitParamsPtr, |
124 device::mojom::blink::SensorClientRequest); | 131 device::mojom::blink::SensorClientRequest); |
125 void OnAddConfigurationCompleted( | 132 void OnAddConfigurationCompleted( |
126 double frequency, | 133 double frequency, |
127 std::unique_ptr<Function<void(bool)>> callback, | 134 std::unique_ptr<Function<void(bool)>> callback, |
128 bool result); | 135 bool result); |
129 void OnRemoveConfigurationCompleted(double frequency, bool result); | 136 void OnRemoveConfigurationCompleted(double frequency, bool result); |
130 | 137 |
131 bool TryReadFromBuffer(device::SensorReading& result); | 138 bool TryReadFromBuffer(device::SensorReading& result); |
132 void OnAnimationFrame(double timestamp); | 139 void OnAnimationFrame(double timestamp); |
133 | 140 |
| 141 // PermissionObserver override. |
| 142 void OnPermissionStatusChange(mojom::blink::PermissionStatus); |
| 143 |
134 device::mojom::blink::SensorType type_; | 144 device::mojom::blink::SensorType type_; |
135 device::mojom::blink::ReportingMode mode_; | 145 device::mojom::blink::ReportingMode mode_; |
136 Member<SensorProviderProxy> provider_; | 146 Member<SensorProviderProxy> provider_; |
| 147 |
137 using ObserversSet = HeapHashSet<WeakMember<Observer>>; | 148 using ObserversSet = HeapHashSet<WeakMember<Observer>>; |
138 ObserversSet observers_; | 149 ObserversSet observers_; |
139 | 150 |
140 device::mojom::blink::SensorPtr sensor_; | 151 device::mojom::blink::SensorPtr sensor_; |
141 device::mojom::blink::SensorConfigurationPtr default_config_; | 152 device::mojom::blink::SensorConfigurationPtr default_config_; |
142 mojo::Binding<device::mojom::blink::SensorClient> client_binding_; | 153 mojo::Binding<device::mojom::blink::SensorClient> client_binding_; |
143 | 154 |
144 enum State { kUninitialized, kInitializing, kInitialized }; | 155 enum State { kUninitialized, kInitializing, kInitialized }; |
145 State state_; | 156 State state_; |
146 mojo::ScopedSharedBufferHandle shared_buffer_handle_; | 157 mojo::ScopedSharedBufferHandle shared_buffer_handle_; |
147 mojo::ScopedSharedBufferMapping shared_buffer_; | 158 mojo::ScopedSharedBufferMapping shared_buffer_; |
148 bool suspended_; | 159 bool suspended_; |
149 device::SensorReading reading_; | 160 device::SensorReading reading_; |
150 std::pair<double, double> frequency_limits_; | 161 std::pair<double, double> frequency_limits_; |
151 | 162 |
152 Member<SensorReadingUpdater> reading_updater_; | 163 Member<SensorReadingUpdater> reading_updater_; |
153 WTF::Vector<double> frequencies_used_; | 164 WTF::Vector<double> frequencies_used_; |
154 double last_raf_timestamp_; | 165 double last_raf_timestamp_; |
155 | 166 |
156 using ReadingBuffer = device::SensorReadingSharedBuffer; | 167 using ReadingBuffer = device::SensorReadingSharedBuffer; |
157 static_assert( | 168 static_assert( |
158 sizeof(ReadingBuffer) == | 169 sizeof(ReadingBuffer) == |
159 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests, | 170 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests, |
160 "Check reading buffer size for tests"); | 171 "Check reading buffer size for tests"); |
| 172 |
| 173 RefPtr<SecurityOrigin> security_origin_; |
| 174 mojo::Binding<mojom::blink::PermissionObserver> binding_; |
| 175 bool permission_subscribed_; |
161 }; | 176 }; |
162 | 177 |
163 } // namespace blink | 178 } // namespace blink |
164 | 179 |
165 #endif // SensorProxy_h | 180 #endif // SensorProxy_h |
OLD | NEW |