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 #include "modules/sensor/SensorProviderProxy.h" | 5 #include "modules/sensor/SensorProviderProxy.h" |
6 | 6 |
7 #include "core/dom/ExecutionContext.h" | |
8 #include "modules/permissions/PermissionUtils.h" | |
7 #include "modules/sensor/SensorProxy.h" | 9 #include "modules/sensor/SensorProxy.h" |
8 #include "modules/sensor/SensorReading.h" | 10 #include "modules/sensor/SensorReading.h" |
9 #include "platform/mojo/MojoHelper.h" | 11 #include "platform/mojo/MojoHelper.h" |
10 #include "public/platform/InterfaceProvider.h" | 12 #include "public/platform/InterfaceProvider.h" |
11 #include "public/platform/Platform.h" | 13 #include "public/platform/Platform.h" |
12 | 14 |
13 namespace blink { | 15 namespace blink { |
14 | 16 |
15 // SensorProviderProxy | 17 // SensorProviderProxy |
16 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) { | 18 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) { |
(...skipping 18 matching lines...) Expand all Loading... | |
35 return result; | 37 return result; |
36 } | 38 } |
37 | 39 |
38 SensorProviderProxy::~SensorProviderProxy() {} | 40 SensorProviderProxy::~SensorProviderProxy() {} |
39 | 41 |
40 DEFINE_TRACE(SensorProviderProxy) { | 42 DEFINE_TRACE(SensorProviderProxy) { |
41 visitor->trace(m_sensors); | 43 visitor->trace(m_sensors); |
42 Supplement<LocalFrame>::trace(visitor); | 44 Supplement<LocalFrame>::trace(visitor); |
43 } | 45 } |
44 | 46 |
47 void SensorProviderProxy::onPermissionServiceConnectionError() { | |
48 if (!Platform::current()) { | |
49 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | |
50 return; | |
51 } | |
52 | |
53 m_permissionService.reset(); | |
shalamov
2016/11/14 14:40:06
If you reset it here, and access it on initialize
riju_
2016/11/16 12:38:25
Yes, I am removing from initialize() now.
| |
54 for (SensorProxy* sensor : m_sensors) { | |
55 sensor->handleSensorError(SecurityError, | |
56 "Permission service not available."); | |
57 } | |
58 } | |
59 | |
45 SensorProxy* SensorProviderProxy::createSensor( | 60 SensorProxy* SensorProviderProxy::createSensor( |
46 device::mojom::blink::SensorType type, | 61 device::mojom::blink::SensorType type, |
62 ExecutionContext* context, | |
47 std::unique_ptr<SensorReadingFactory> readingFactory) { | 63 std::unique_ptr<SensorReadingFactory> readingFactory) { |
48 DCHECK(!getSensor(type)); | 64 DCHECK(!getSensor(type)); |
49 | 65 |
50 SensorProxy* sensor = new SensorProxy(type, this, std::move(readingFactory)); | 66 // Get permission service. |
67 if (connectToPermissionService(context, | |
68 mojo::GetProxy(&m_permissionService))) { | |
69 m_permissionService.set_connection_error_handler(convertToBaseCallback( | |
70 WTF::bind(&SensorProviderProxy::onPermissionServiceConnectionError, | |
71 wrapWeakPersistent(this)))); | |
72 } | |
73 if (!m_permissionService) { | |
74 for (SensorProxy* sensor : m_sensors) { | |
75 sensor->handleSensorError( | |
76 SecurityError, | |
77 "In its current state, the global scope can't request permissions"); | |
78 } | |
79 } | |
80 | |
81 RefPtr<SecurityOrigin> origin = context->getSecurityOrigin(); | |
82 DCHECK(origin); | |
83 SensorProxy* sensor = new SensorProxy(type, m_permissionService.get(), origin, | |
84 this, std::move(readingFactory)); | |
51 m_sensors.add(sensor); | 85 m_sensors.add(sensor); |
52 | 86 |
53 return sensor; | 87 return sensor; |
54 } | 88 } |
55 | 89 |
56 SensorProxy* SensorProviderProxy::getSensor( | 90 SensorProxy* SensorProviderProxy::getSensor( |
57 device::mojom::blink::SensorType type) { | 91 device::mojom::blink::SensorType type) { |
58 for (SensorProxy* sensor : m_sensors) { | 92 for (SensorProxy* sensor : m_sensors) { |
59 // TODO(Mikhail) : Hash sensors by type for efficiency. | 93 // TODO(Mikhail) : Hash sensors by type for efficiency. |
60 if (sensor->type() == type) | 94 if (sensor->type() == type) |
61 return sensor; | 95 return sensor; |
62 } | 96 } |
63 | 97 |
64 return nullptr; | 98 return nullptr; |
65 } | 99 } |
66 | 100 |
67 void SensorProviderProxy::onSensorProviderConnectionError() { | 101 void SensorProviderProxy::onSensorProviderConnectionError() { |
68 if (!Platform::current()) { | 102 if (!Platform::current()) { |
69 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | 103 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. |
70 return; | 104 return; |
71 } | 105 } |
72 | 106 |
73 m_sensorProvider.reset(); | 107 m_sensorProvider.reset(); |
74 for (SensorProxy* sensor : m_sensors) | 108 for (SensorProxy* sensor : m_sensors) |
75 sensor->handleSensorError(); | 109 sensor->handleSensorError(); |
76 } | 110 } |
77 | 111 |
78 } // namespace blink | 112 } // namespace blink |
OLD | NEW |