| 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 Sensor_h | 5 #ifndef Sensor_h |
| 6 #define Sensor_h | 6 #define Sensor_h |
| 7 | 7 |
| 8 #include "bindings/core/v8/ActiveScriptWrappable.h" | 8 #include "bindings/core/v8/ActiveScriptWrappable.h" |
| 9 #include "bindings/core/v8/ScriptWrappable.h" | 9 #include "bindings/core/v8/ScriptWrappable.h" |
| 10 #include "core/dom/ContextLifecycleObserver.h" | 10 #include "core/dom/ContextLifecycleObserver.h" |
| 11 #include "core/dom/DOMHighResTimeStamp.h" |
| 12 #include "core/dom/DOMTimeStamp.h" |
| 11 #include "core/dom/SuspendableObject.h" | 13 #include "core/dom/SuspendableObject.h" |
| 12 #include "core/frame/PlatformEventController.h" | 14 #include "core/frame/PlatformEventController.h" |
| 13 #include "modules/EventTargetModules.h" | 15 #include "modules/EventTargetModules.h" |
| 14 #include "modules/sensor/SensorOptions.h" | 16 #include "modules/sensor/SensorOptions.h" |
| 15 #include "modules/sensor/SensorProxy.h" | 17 #include "modules/sensor/SensorProxy.h" |
| 16 #include "platform/heap/Handle.h" | 18 #include "platform/heap/Handle.h" |
| 17 | 19 |
| 18 namespace blink { | 20 namespace blink { |
| 19 | 21 |
| 20 class ExceptionState; | 22 class ExceptionState; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 // EventTarget overrides. | 41 // EventTarget overrides. |
| 40 const AtomicString& interfaceName() const override { | 42 const AtomicString& interfaceName() const override { |
| 41 return EventTargetNames::Sensor; | 43 return EventTargetNames::Sensor; |
| 42 } | 44 } |
| 43 ExecutionContext* getExecutionContext() const override { | 45 ExecutionContext* getExecutionContext() const override { |
| 44 return ContextLifecycleObserver::getExecutionContext(); | 46 return ContextLifecycleObserver::getExecutionContext(); |
| 45 } | 47 } |
| 46 | 48 |
| 47 // Getters | 49 // Getters |
| 48 String state() const; | 50 String state() const; |
| 49 // TODO(riju): crbug.com/614797 . | 51 DOMHighResTimeStamp timestamp(ScriptState*, bool& isNull) const; |
| 50 SensorReading* reading() const; | |
| 51 | 52 |
| 52 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); | 53 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); |
| 53 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); | 54 DEFINE_ATTRIBUTE_EVENT_LISTENER(change); |
| 54 DEFINE_ATTRIBUTE_EVENT_LISTENER(activate); | 55 DEFINE_ATTRIBUTE_EVENT_LISTENER(activate); |
| 55 | 56 |
| 56 // ActiveScriptWrappable overrides. | 57 // ActiveScriptWrappable overrides. |
| 57 bool hasPendingActivity() const override; | 58 bool hasPendingActivity() const override; |
| 58 | 59 |
| 59 DECLARE_VIRTUAL_TRACE(); | 60 DECLARE_VIRTUAL_TRACE(); |
| 60 | 61 |
| 61 protected: | 62 protected: |
| 62 Sensor(ExecutionContext*, | 63 Sensor(ExecutionContext*, |
| 63 const SensorOptions&, | 64 const SensorOptions&, |
| 64 ExceptionState&, | 65 ExceptionState&, |
| 65 device::mojom::blink::SensorType); | 66 device::mojom::blink::SensorType); |
| 66 virtual std::unique_ptr<SensorReadingFactory> | |
| 67 createSensorReadingFactory() = 0; | |
| 68 | 67 |
| 69 using SensorConfigurationPtr = device::mojom::blink::SensorConfigurationPtr; | 68 using SensorConfigurationPtr = device::mojom::blink::SensorConfigurationPtr; |
| 70 using SensorConfiguration = device::mojom::blink::SensorConfiguration; | 69 using SensorConfiguration = device::mojom::blink::SensorConfiguration; |
| 71 | 70 |
| 72 // The default implementation will init frequency configuration parameter, | 71 // The default implementation will init frequency configuration parameter, |
| 73 // concrete sensor implementations can override this method to handle other | 72 // concrete sensor implementations can override this method to handle other |
| 74 // parameters if needed. | 73 // parameters if needed. |
| 75 virtual SensorConfigurationPtr createSensorConfig(); | 74 virtual SensorConfigurationPtr createSensorConfig(); |
| 75 double readingValue(int index, bool& isNull) const; |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 void initSensorProxyIfNeeded(); | 78 void initSensorProxyIfNeeded(); |
| 79 | 79 |
| 80 // ContextLifecycleObserver overrides. | 80 // ContextLifecycleObserver overrides. |
| 81 void contextDestroyed(ExecutionContext*) override; | 81 void contextDestroyed(ExecutionContext*) override; |
| 82 | 82 |
| 83 // SensorController::Observer overrides. | 83 // SensorController::Observer overrides. |
| 84 void onSensorInitialized() override; | 84 void onSensorInitialized() override; |
| 85 void onSensorReadingChanged(double timestamp) override; | 85 void onSensorReadingChanged(double timestamp) override; |
| 86 void onSensorError(ExceptionCode, | 86 void onSensorError(ExceptionCode, |
| 87 const String& sanitizedMessage, | 87 const String& sanitizedMessage, |
| 88 const String& unsanitizedMessage) override; | 88 const String& unsanitizedMessage) override; |
| 89 | 89 |
| 90 void onStartRequestCompleted(bool); | 90 void onStartRequestCompleted(bool); |
| 91 void onStopRequestCompleted(bool); | 91 void onStopRequestCompleted(bool); |
| 92 | 92 |
| 93 void startListening(); | 93 void startListening(); |
| 94 void stopListening(); | 94 void stopListening(); |
| 95 | 95 |
| 96 void updateState(SensorState newState); | 96 void updateState(SensorState newState); |
| 97 void reportError(ExceptionCode = UnknownError, | 97 void reportError(ExceptionCode = UnknownError, |
| 98 const String& sanitizedMessage = String(), | 98 const String& sanitizedMessage = String(), |
| 99 const String& unsanitizedMessage = String()); | 99 const String& unsanitizedMessage = String()); |
| 100 | 100 |
| 101 void notifySensorReadingChanged(); | 101 void notifySensorReadingChanged(); |
| 102 void notifyOnActivate(); | 102 void notifyOnActivate(); |
| 103 void notifyError(DOMException* error); | 103 void notifyError(DOMException* error); |
| 104 | 104 |
| 105 bool canReturnReadings() const; |
| 106 |
| 105 private: | 107 private: |
| 106 SensorOptions m_sensorOptions; | 108 SensorOptions m_sensorOptions; |
| 107 device::mojom::blink::SensorType m_type; | 109 device::mojom::blink::SensorType m_type; |
| 108 SensorState m_state; | 110 SensorState m_state; |
| 109 Member<SensorProxy> m_sensorProxy; | 111 Member<SensorProxy> m_sensorProxy; |
| 110 device::SensorReading m_storedData; | 112 device::SensorReading m_storedData; |
| 111 SensorConfigurationPtr m_configuration; | 113 SensorConfigurationPtr m_configuration; |
| 112 double m_lastUpdateTimestamp; | 114 double m_lastUpdateTimestamp; |
| 113 }; | 115 }; |
| 114 | 116 |
| 115 } // namespace blink | 117 } // namespace blink |
| 116 | 118 |
| 117 #endif // Sensor_h | 119 #endif // Sensor_h |
| OLD | NEW |