| 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/dom/ExecutionContext.h" |
| 9 #include "device/generic_sensor/public/cpp/sensor_reading.h" | 10 #include "device/generic_sensor/public/cpp/sensor_reading.h" |
| 10 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" | 11 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" |
| 11 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" | 12 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" |
| 12 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 13 #include "platform/Supplementable.h" | 14 #include "platform/Supplementable.h" |
| 14 #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" |
| 15 | 18 |
| 16 namespace blink { | 19 namespace blink { |
| 17 | 20 |
| 18 class SensorProviderProxy; | 21 class SensorProviderProxy; |
| 19 | 22 |
| 20 // This class wraps 'Sensor' mojo interface and used by multiple | 23 // This class wraps 'Sensor' mojo interface and used by multiple |
| 21 // JS sensor instances of the same type (within a single frame). | 24 // JS sensor instances of the same type (within a single frame). |
| 22 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, | 25 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, |
| 23 public device::mojom::blink::SensorClient { | 26 public device::mojom::blink::SensorClient { |
| 24 USING_PRE_FINALIZER(SensorProxy, dispose); | 27 USING_PRE_FINALIZER(SensorProxy, dispose); |
| 25 WTF_MAKE_NONCOPYABLE(SensorProxy); | 28 WTF_MAKE_NONCOPYABLE(SensorProxy); |
| 26 | 29 |
| 27 public: | 30 public: |
| 28 class Observer : public GarbageCollectedMixin { | 31 class Observer : public GarbageCollectedMixin { |
| 29 public: | 32 public: |
| 30 // Has valid 'Sensor' binding, {add, remove}Configuration() | 33 // Has valid 'Sensor' binding, {add, remove}Configuration() |
| 31 // methods can be called. | 34 // methods can be called. |
| 32 virtual void onSensorInitialized() {} | 35 virtual void onSensorInitialized() {} |
| 33 // Platfrom sensort reading has changed (for 'ONCHANGE' reporting mode). | 36 // Platfrom sensort reading has changed (for 'ONCHANGE' reporting mode). |
| 34 virtual void onSensorReadingChanged() {} | 37 virtual void onSensorReadingChanged() {} |
| 35 // An error has occurred. | 38 // An error has occurred. |
| 36 virtual void onSensorError(ExceptionCode, | 39 virtual void onSensorError(ExceptionCode, |
| 37 const String& sanitizedMessage, | 40 const String& sanitizedMessage, |
| 38 const String& unsanitizedMessage) {} | 41 const String& unsanitizedMessage) {} |
| 42 // Permission for sensor has changed. |
| 43 virtual void onSensorPermissionChanged() {} |
| 39 }; | 44 }; |
| 40 | 45 |
| 41 ~SensorProxy(); | 46 ~SensorProxy(); |
| 42 | 47 |
| 43 void dispose(); | 48 void dispose(); |
| 44 | 49 |
| 45 void addObserver(Observer*); | 50 void addObserver(Observer*); |
| 46 void removeObserver(Observer*); | 51 void removeObserver(Observer*); |
| 47 | 52 |
| 48 void initialize(); | 53 void initialize(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 63 | 68 |
| 64 using Reading = device::SensorReading; | 69 using Reading = device::SensorReading; |
| 65 | 70 |
| 66 const Reading& reading() const { return m_reading; } | 71 const Reading& reading() const { return m_reading; } |
| 67 | 72 |
| 68 const device::mojom::blink::SensorConfiguration* defaultConfig() const; | 73 const device::mojom::blink::SensorConfiguration* defaultConfig() const; |
| 69 | 74 |
| 70 // Updates internal reading from shared buffer. | 75 // Updates internal reading from shared buffer. |
| 71 void updateInternalReading(); | 76 void updateInternalReading(); |
| 72 | 77 |
| 78 mojom::blink::PermissionService* getPermissionService(ExecutionContext*); |
| 79 void resetPermissionService(); |
| 80 void permissionServiceConnectionError(); |
| 81 void onPermissionUpdate(mojom::blink::PermissionStatus); |
| 82 void getNextPermissionChange(ExecutionContext*, |
| 83 mojom::blink::PermissionStatus); |
| 84 void requestPermission(ExecutionContext*, mojom::blink::PermissionStatus); |
| 85 mojom::blink::PermissionStatus getPermissionStatus() const { |
| 86 return m_sensorPermission; |
| 87 }; |
| 88 |
| 73 DECLARE_VIRTUAL_TRACE(); | 89 DECLARE_VIRTUAL_TRACE(); |
| 74 | 90 |
| 75 private: | 91 private: |
| 76 friend class SensorProviderProxy; | 92 friend class SensorProviderProxy; |
| 77 SensorProxy(device::mojom::blink::SensorType, SensorProviderProxy*); | 93 SensorProxy(device::mojom::blink::SensorType, |
| 94 ExecutionContext*, |
| 95 SensorProviderProxy*); |
| 78 | 96 |
| 79 // device::mojom::blink::SensorClient overrides. | 97 // device::mojom::blink::SensorClient overrides. |
| 80 void RaiseError() override; | 98 void RaiseError() override; |
| 81 void SensorReadingChanged() override; | 99 void SensorReadingChanged() override; |
| 82 | 100 |
| 101 void SensorPermissionChanged(); |
| 102 |
| 83 // Generic handler for a fatal error. | 103 // Generic handler for a fatal error. |
| 84 void handleSensorError(ExceptionCode = UnknownError, | 104 void handleSensorError(ExceptionCode = UnknownError, |
| 85 const String& sanitizedMessage = String(), | 105 const String& sanitizedMessage = String(), |
| 86 const String& unsanitizedMessage = String()); | 106 const String& unsanitizedMessage = String()); |
| 87 | 107 |
| 88 void onSensorCreated(device::mojom::blink::SensorInitParamsPtr, | 108 void onSensorCreated(device::mojom::blink::SensorInitParamsPtr, |
| 89 device::mojom::blink::SensorClientRequest); | 109 device::mojom::blink::SensorClientRequest); |
| 90 | 110 |
| 91 bool tryReadFromBuffer(); | 111 bool tryReadFromBuffer(); |
| 92 | 112 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 104 State m_state; | 124 State m_state; |
| 105 mojo::ScopedSharedBufferHandle m_sharedBufferHandle; | 125 mojo::ScopedSharedBufferHandle m_sharedBufferHandle; |
| 106 mojo::ScopedSharedBufferMapping m_sharedBuffer; | 126 mojo::ScopedSharedBufferMapping m_sharedBuffer; |
| 107 Reading m_reading; | 127 Reading m_reading; |
| 108 bool m_suspended; | 128 bool m_suspended; |
| 109 using ReadingBuffer = device::SensorReadingSharedBuffer; | 129 using ReadingBuffer = device::SensorReadingSharedBuffer; |
| 110 static_assert( | 130 static_assert( |
| 111 sizeof(ReadingBuffer) == | 131 sizeof(ReadingBuffer) == |
| 112 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests, | 132 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests, |
| 113 "Check reading buffer size for tests"); | 133 "Check reading buffer size for tests"); |
| 134 |
| 135 mojom::blink::PermissionStatus m_sensorPermission; |
| 136 mojom::blink::PermissionServicePtr m_permissionService; |
| 137 Member<ExecutionContext> m_executionContext; |
| 114 }; | 138 }; |
| 115 | 139 |
| 116 } // namespace blink | 140 } // namespace blink |
| 117 | 141 |
| 118 #endif // SensorProxy_h | 142 #endif // SensorProxy_h |
| OLD | NEW |