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

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

Issue 2458453002: [sensors] Add Permission guard to the generic sensor apis.
Patch Set: Fix comments Created 4 years, 1 month 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/SensorProviderProxy.cpp
diff --git a/third_party/WebKit/Source/modules/sensor/SensorProviderProxy.cpp b/third_party/WebKit/Source/modules/sensor/SensorProviderProxy.cpp
index 243c8f567abd3b83ac192d914e82462333631f7b..1f9113ee9fa6859a36c9f30314185776767b7645 100644
--- a/third_party/WebKit/Source/modules/sensor/SensorProviderProxy.cpp
+++ b/third_party/WebKit/Source/modules/sensor/SensorProviderProxy.cpp
@@ -4,6 +4,8 @@
#include "modules/sensor/SensorProviderProxy.h"
+#include "core/dom/ExecutionContext.h"
+#include "modules/permissions/PermissionUtils.h"
#include "modules/sensor/SensorProxy.h"
#include "modules/sensor/SensorReading.h"
#include "platform/mojo/MojoHelper.h"
@@ -42,12 +44,44 @@ DEFINE_TRACE(SensorProviderProxy) {
Supplement<LocalFrame>::trace(visitor);
}
+void SensorProviderProxy::onPermissionServiceConnectionError() {
+ if (!Platform::current()) {
+ // TODO(rockot): Clean this up once renderer shutdown sequence is fixed.
+ return;
+ }
+
+ m_permissionService.reset();
+ for (SensorProxy* sensor : m_sensors) {
+ sensor->handleSensorError(SecurityError,
+ "Permission service not available.");
+ }
+}
+
SensorProxy* SensorProviderProxy::createSensor(
shalamov 2016/11/16 19:03:49 I think we should rename it to createSensorProxy.
device::mojom::blink::SensorType type,
+ ExecutionContext* context,
std::unique_ptr<SensorReadingFactory> readingFactory) {
DCHECK(!getSensor(type));
- SensorProxy* sensor = new SensorProxy(type, this, std::move(readingFactory));
+ // Get permission service.
+ if (connectToPermissionService(context,
+ mojo::GetProxy(&m_permissionService))) {
+ m_permissionService.set_connection_error_handler(convertToBaseCallback(
+ WTF::bind(&SensorProviderProxy::onPermissionServiceConnectionError,
+ wrapWeakPersistent(this))));
+ }
+ if (!m_permissionService) {
+ for (SensorProxy* sensor : m_sensors) {
+ sensor->handleSensorError(
shalamov 2016/11/16 19:03:49 Two comments: 1. At this point, m_sensors is empt
+ SecurityError,
+ "In its current state, the global scope can't request permissions");
+ }
+ }
+
+ RefPtr<SecurityOrigin> origin = context->getSecurityOrigin();
+ DCHECK(origin);
+ SensorProxy* sensor = new SensorProxy(type, m_permissionService.get(), origin,
+ this, std::move(readingFactory));
m_sensors.add(sensor);
return sensor;

Powered by Google App Engine
This is Rietveld 408576698