Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Unified Diff: third_party/WebKit/Source/modules/sensor/Sensor.cpp

Issue 2384273004: [Sensors] 'onerror' event implementation (Closed)
Patch Set: updated global-interface-listing-expected.txt Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 a87b8be19f01c7b23dd3bab04323acdaa27be36c..ca613f9e1e8670fb65e75c1ba499ec3b0a9a2004 100644
--- a/third_party/WebKit/Source/modules/sensor/Sensor.cpp
+++ b/third_party/WebKit/Source/modules/sensor/Sensor.cpp
@@ -168,8 +168,10 @@ void Sensor::onSensorReadingChanged() {
m_polling->onSensorReadingChanged();
}
-void Sensor::onSensorError() {
- reportError();
+void Sensor::onSensorError(ExceptionCode code,
+ const String& sanitizedMessage,
+ const String& unsanitizedMessage) {
+ reportError(code, sanitizedMessage, unsanitizedMessage);
}
void Sensor::onStartRequestCompleted(bool result) {
@@ -177,7 +179,9 @@ void Sensor::onStartRequestCompleted(bool result) {
return;
if (!result) {
- reportError();
+ reportError(
+ OperationError,
+ "start() call has failed possibly due to inappropriate options.");
return;
}
@@ -196,7 +200,7 @@ void Sensor::onStopRequestCompleted(bool result) {
return;
if (!result)
- reportError();
+ reportError(OperationError);
DCHECK(m_sensorProxy);
m_sensorProxy->removeObserver(this);
@@ -293,9 +297,18 @@ void Sensor::updateState(Sensor::SensorState newState) {
updatePollingStatus();
}
-void Sensor::reportError() {
+void Sensor::reportError(ExceptionCode code,
+ const String& sanitizedMessage,
+ const String& unsanitizedMessage) {
updateState(Sensor::SensorState::ERRORED);
- // TODO(Mikhail) : Dispatch Sensor Error event.
+ if (getExecutionContext()) {
+ auto error =
+ DOMException::create(code, sanitizedMessage, unsanitizedMessage);
+ getExecutionContext()->postTask(
+ BLINK_FROM_HERE,
+ createSameThreadTask(&Sensor::notifyError, wrapWeakPersistent(this),
+ wrapPersistent(error)));
+ }
}
void Sensor::updatePollingStatus() {
@@ -319,4 +332,9 @@ void Sensor::notifyStateChanged() {
dispatchEvent(Event::create(EventTypeNames::statechange));
}
+void Sensor::notifyError(DOMException* error) {
+ dispatchEvent(
+ SensorErrorEvent::create(EventTypeNames::error, std::move(error)));
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/sensor/Sensor.h ('k') | third_party/WebKit/Source/modules/sensor/SensorErrorEvent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698