Index: third_party/WebKit/Source/modules/sensor/Sensor.cpp |
diff --git a/third_party/WebKit/Source/modules/sensor/Sensor.cpp b/third_party/WebKit/Source/modules/sensor/Sensor.cpp |
index d5f1b0421b799ab73d20664171a2d3c7b609c7ee..e0f7f31f1146d45f0ef669607a5376bb909452c4 100644 |
--- a/third_party/WebKit/Source/modules/sensor/Sensor.cpp |
+++ b/third_party/WebKit/Source/modules/sensor/Sensor.cpp |
@@ -6,6 +6,7 @@ |
#include "core/dom/Document.h" |
#include "core/dom/ExceptionCode.h" |
+#include "core/dom/ExecutionContextTask.h" |
#include "core/inspector/ConsoleMessage.h" |
#include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" |
#include "modules/sensor/SensorErrorEvent.h" |
@@ -263,8 +264,10 @@ void Sensor::pollForData() |
m_sensorProxy->updateInternalReading(); |
DCHECK(m_sensorReading); |
- if (m_sensorReading->isReadingUpdated(m_storedData)) |
- dispatchEvent(SensorReadingEvent::create(EventTypeNames::change, m_sensorReading)); |
+ if (getExecutionContext() && m_sensorReading->isReadingUpdated(m_storedData)) { |
+ getExecutionContext()->postTask(BLINK_FROM_HERE, |
+ createSameThreadTask(&Sensor::notifySensorReadingChanged, wrapWeakPersistent(this))); |
haraken
2016/09/30 13:26:45
wrapWeakPersistent means that the event may not be
shalamov
2016/09/30 13:51:44
Yes, that was intentional. If sensor goes out of s
|
+ } |
m_storedData = m_sensorProxy->reading(); |
} |
@@ -274,7 +277,11 @@ void Sensor::updateState(Sensor::SensorState newState) |
if (newState == m_state) |
return; |
m_state = newState; |
- dispatchEvent(Event::create(EventTypeNames::statechange)); |
+ if (getExecutionContext()) { |
+ getExecutionContext()->postTask(BLINK_FROM_HERE, |
+ createSameThreadTask(&Sensor::notifyStateChanged, wrapWeakPersistent(this))); |
+ } |
+ |
updatePollingStatus(); |
} |
@@ -297,4 +304,14 @@ void Sensor::updatePollingStatus() |
} |
} |
+void Sensor::notifySensorReadingChanged() |
+{ |
+ dispatchEvent(SensorReadingEvent::create(EventTypeNames::change, m_sensorReading)); |
+} |
+ |
+void Sensor::notifyStateChanged() |
+{ |
+ dispatchEvent(Event::create(EventTypeNames::statechange)); |
+} |
+ |
} // namespace blink |