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 "modules/sensor/SensorProxy.h" | 7 #include "modules/sensor/SensorProxy.h" |
8 #include "modules/sensor/SensorReading.h" | 8 #include "modules/sensor/SensorReading.h" |
9 #include "platform/mojo/MojoHelper.h" | 9 #include "platform/mojo/MojoHelper.h" |
10 #include "public/platform/InterfaceProvider.h" | 10 #include "public/platform/InterfaceProvider.h" |
11 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 // SensorProviderProxy | 15 // SensorProviderProxy |
16 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) { | 16 SensorProviderProxy::SensorProviderProxy(LocalFrame* frame) { |
17 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_sensorProvider)); | 17 frame->interfaceProvider()->getInterface(mojo::GetProxy(&m_sensorProvider)); |
18 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( | 18 m_sensorProvider.set_connection_error_handler(convertToBaseCallback( |
19 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, | 19 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, |
20 wrapWeakPersistent(this)))); | 20 wrapWeakPersistent(this)))); |
| 21 |
| 22 // Get permission service. |
| 23 frame->interfaceProvider()->getInterface( |
| 24 mojo::GetProxy(&m_permissionService)); |
| 25 m_permissionService.set_connection_error_handler(convertToBaseCallback( |
| 26 WTF::bind(&SensorProviderProxy::onSensorProviderConnectionError, |
| 27 wrapWeakPersistent(this)))); |
21 } | 28 } |
22 | 29 |
23 const char* SensorProviderProxy::supplementName() { | 30 const char* SensorProviderProxy::supplementName() { |
24 return "SensorProvider"; | 31 return "SensorProvider"; |
25 } | 32 } |
26 | 33 |
27 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { | 34 SensorProviderProxy* SensorProviderProxy::from(LocalFrame* frame) { |
28 DCHECK(frame); | 35 DCHECK(frame); |
29 SensorProviderProxy* result = static_cast<SensorProviderProxy*>( | 36 SensorProviderProxy* result = static_cast<SensorProviderProxy*>( |
30 Supplement<LocalFrame>::from(*frame, supplementName())); | 37 Supplement<LocalFrame>::from(*frame, supplementName())); |
31 if (!result) { | 38 if (!result) { |
32 result = new SensorProviderProxy(frame); | 39 result = new SensorProviderProxy(frame); |
33 Supplement<LocalFrame>::provideTo(*frame, supplementName(), result); | 40 Supplement<LocalFrame>::provideTo(*frame, supplementName(), result); |
34 } | 41 } |
35 return result; | 42 return result; |
36 } | 43 } |
37 | 44 |
38 SensorProviderProxy::~SensorProviderProxy() {} | 45 SensorProviderProxy::~SensorProviderProxy() {} |
39 | 46 |
40 DEFINE_TRACE(SensorProviderProxy) { | 47 DEFINE_TRACE(SensorProviderProxy) { |
41 visitor->trace(m_sensorProxies); | 48 visitor->trace(m_sensorProxies); |
42 Supplement<LocalFrame>::trace(visitor); | 49 Supplement<LocalFrame>::trace(visitor); |
43 } | 50 } |
44 | 51 |
45 SensorProxy* SensorProviderProxy::createSensorProxy( | 52 SensorProxy* SensorProviderProxy::createSensorProxy( |
46 device::mojom::blink::SensorType type, | 53 device::mojom::blink::SensorType type, |
47 Page* page, | 54 Page* page, |
| 55 RefPtr<SecurityOrigin> origin, |
48 std::unique_ptr<SensorReadingFactory> readingFactory) { | 56 std::unique_ptr<SensorReadingFactory> readingFactory) { |
49 DCHECK(!getSensorProxy(type)); | 57 DCHECK(!getSensorProxy(type)); |
50 | 58 |
51 SensorProxy* sensor = | 59 SensorProxy* sensor = |
52 new SensorProxy(type, this, page, std::move(readingFactory)); | 60 new SensorProxy(type, m_permissionService.get(), std::move(origin), this, |
| 61 page, std::move(readingFactory)); |
53 m_sensorProxies.add(sensor); | 62 m_sensorProxies.add(sensor); |
54 | 63 |
55 return sensor; | 64 return sensor; |
56 } | 65 } |
57 | 66 |
58 SensorProxy* SensorProviderProxy::getSensorProxy( | 67 SensorProxy* SensorProviderProxy::getSensorProxy( |
59 device::mojom::blink::SensorType type) { | 68 device::mojom::blink::SensorType type) { |
60 for (SensorProxy* sensor : m_sensorProxies) { | 69 for (SensorProxy* sensor : m_sensorProxies) { |
61 // TODO(Mikhail) : Hash sensors by type for efficiency. | 70 // TODO(Mikhail) : Hash sensors by type for efficiency. |
62 if (sensor->type() == type) | 71 if (sensor->type() == type) |
63 return sensor; | 72 return sensor; |
64 } | 73 } |
65 | 74 |
66 return nullptr; | 75 return nullptr; |
67 } | 76 } |
68 | 77 |
69 void SensorProviderProxy::onSensorProviderConnectionError() { | 78 void SensorProviderProxy::onSensorProviderConnectionError() { |
70 if (!Platform::current()) { | 79 if (!Platform::current()) { |
71 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. | 80 // TODO(rockot): Clean this up once renderer shutdown sequence is fixed. |
72 return; | 81 return; |
73 } | 82 } |
74 | 83 |
| 84 m_permissionService.reset(); |
75 m_sensorProvider.reset(); | 85 m_sensorProvider.reset(); |
76 for (SensorProxy* sensor : m_sensorProxies) | 86 for (SensorProxy* sensor : m_sensorProxies) |
77 sensor->handleSensorError(); | 87 sensor->handleSensorError(); |
78 } | 88 } |
79 | 89 |
80 } // namespace blink | 90 } // namespace blink |
OLD | NEW |