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

Side by Side Diff: third_party/WebKit/Source/modules/sensor/SensorProxy.h

Issue 2458453002: [sensors] Add Permission guard to the generic sensor apis.
Patch Set: Remove resetPermission + Rebase Created 4 years 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 unified diff | Download patch
OLDNEW
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 #ifndef SensorProxy_h 5 #ifndef SensorProxy_h
6 #define SensorProxy_h 6 #define SensorProxy_h
7 7
8 #include "core/dom/ExceptionCode.h" 8 #include "core/dom/ExceptionCode.h"
9 #include "core/page/PageVisibilityObserver.h" 9 #include "core/page/PageVisibilityObserver.h"
10 #include "device/generic_sensor/public/cpp/sensor_reading.h" 10 #include "device/generic_sensor/public/cpp/sensor_reading.h"
11 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" 11 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h"
12 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" 12 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h"
13 #include "mojo/public/cpp/bindings/binding.h" 13 #include "mojo/public/cpp/bindings/binding.h"
14 #include "platform/Supplementable.h" 14 #include "platform/Supplementable.h"
15 #include "platform/Timer.h" 15 #include "platform/Timer.h"
16 #include "platform/heap/Handle.h" 16 #include "platform/heap/Handle.h"
17 #include "public/platform/modules/permissions/permission.mojom-blink.h"
18 #include "public/platform/modules/permissions/permission_status.mojom-blink.h"
17 #include "wtf/Vector.h" 19 #include "wtf/Vector.h"
18 20
19 namespace blink { 21 namespace blink {
20 22
21 class SensorProviderProxy; 23 class SensorProviderProxy;
22 class SensorReading; 24 class SensorReading;
23 class SensorReadingFactory; 25 class SensorReadingFactory;
26 class SecurityOrigin;
24 27
25 // This class wraps 'Sensor' mojo interface and used by multiple 28 // This class wraps 'Sensor' mojo interface and used by multiple
26 // JS sensor instances of the same type (within a single frame). 29 // JS sensor instances of the same type (within a single frame).
27 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, 30 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>,
28 public device::mojom::blink::SensorClient, 31 public device::mojom::blink::SensorClient,
29 public PageVisibilityObserver { 32 public PageVisibilityObserver {
30 USING_GARBAGE_COLLECTED_MIXIN(SensorProxy); 33 USING_GARBAGE_COLLECTED_MIXIN(SensorProxy);
31 USING_PRE_FINALIZER(SensorProxy, dispose); 34 USING_PRE_FINALIZER(SensorProxy, dispose);
32 WTF_MAKE_NONCOPYABLE(SensorProxy); 35 WTF_MAKE_NONCOPYABLE(SensorProxy);
33 36
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 80
78 const device::mojom::blink::SensorConfiguration* defaultConfig() const; 81 const device::mojom::blink::SensorConfiguration* defaultConfig() const;
79 82
80 double maximumFrequency() const { return m_maximumFrequency; } 83 double maximumFrequency() const { return m_maximumFrequency; }
81 84
82 DECLARE_VIRTUAL_TRACE(); 85 DECLARE_VIRTUAL_TRACE();
83 86
84 private: 87 private:
85 friend class SensorProviderProxy; 88 friend class SensorProviderProxy;
86 SensorProxy(device::mojom::blink::SensorType, 89 SensorProxy(device::mojom::blink::SensorType,
90 mojom::blink::PermissionService*,
91 RefPtr<SecurityOrigin>,
87 SensorProviderProxy*, 92 SensorProviderProxy*,
88 Page*, 93 Page*,
89 std::unique_ptr<SensorReadingFactory>); 94 std::unique_ptr<SensorReadingFactory>);
90 // Returns true if this instance is using polling timer to 95 // Returns true if this instance is using polling timer to
91 // periodically fetch reading data from shared buffer. 96 // periodically fetch reading data from shared buffer.
92 bool usesPollingTimer() const; 97 bool usesPollingTimer() const;
93 98
94 // Updates sensor reading from shared buffer. 99 // Updates sensor reading from shared buffer.
95 void updateSensorReading(); 100 void updateSensorReading();
96 101
(...skipping 15 matching lines...) Expand all
112 void onAddConfigurationCompleted( 117 void onAddConfigurationCompleted(
113 double frequency, 118 double frequency,
114 std::unique_ptr<Function<void(bool)>> callback, 119 std::unique_ptr<Function<void(bool)>> callback,
115 bool result); 120 bool result);
116 void onRemoveConfigurationCompleted(double frequency, bool result); 121 void onRemoveConfigurationCompleted(double frequency, bool result);
117 122
118 bool tryReadFromBuffer(device::SensorReading& result); 123 bool tryReadFromBuffer(device::SensorReading& result);
119 void updatePollingStatus(); 124 void updatePollingStatus();
120 void onTimerFired(TimerBase*); 125 void onTimerFired(TimerBase*);
121 126
127 void onPermissionUpdate(mojom::blink::PermissionStatus);
128
122 device::mojom::blink::SensorType m_type; 129 device::mojom::blink::SensorType m_type;
123 device::mojom::blink::ReportingMode m_mode; 130 device::mojom::blink::ReportingMode m_mode;
124 Member<SensorProviderProxy> m_provider; 131 Member<SensorProviderProxy> m_provider;
125 using ObserversSet = HeapHashSet<WeakMember<Observer>>; 132 using ObserversSet = HeapHashSet<WeakMember<Observer>>;
126 ObserversSet m_observers; 133 ObserversSet m_observers;
127 134
128 device::mojom::blink::SensorPtr m_sensor; 135 device::mojom::blink::SensorPtr m_sensor;
129 device::mojom::blink::SensorConfigurationPtr m_defaultConfig; 136 device::mojom::blink::SensorConfigurationPtr m_defaultConfig;
130 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding; 137 mojo::Binding<device::mojom::blink::SensorClient> m_clientBinding;
131 138
132 enum State { Uninitialized, Initializing, Initialized }; 139 enum State { Uninitialized, Initializing, Initialized };
133 State m_state; 140 State m_state;
134 mojo::ScopedSharedBufferHandle m_sharedBufferHandle; 141 mojo::ScopedSharedBufferHandle m_sharedBufferHandle;
135 mojo::ScopedSharedBufferMapping m_sharedBuffer; 142 mojo::ScopedSharedBufferMapping m_sharedBuffer;
136 bool m_suspended; 143 bool m_suspended;
137 Member<SensorReading> m_reading; 144 Member<SensorReading> m_reading;
138 std::unique_ptr<SensorReadingFactory> m_readingFactory; 145 std::unique_ptr<SensorReadingFactory> m_readingFactory;
139 double m_maximumFrequency; 146 double m_maximumFrequency;
140 147
141 // Used for continious reporting mode. 148 // Used for continious reporting mode.
142 Timer<SensorProxy> m_timer; 149 Timer<SensorProxy> m_timer;
143 WTF::Vector<double> m_frequenciesUsed; 150 WTF::Vector<double> m_frequenciesUsed;
144 151
145 using ReadingBuffer = device::SensorReadingSharedBuffer; 152 using ReadingBuffer = device::SensorReadingSharedBuffer;
146 static_assert( 153 static_assert(
147 sizeof(ReadingBuffer) == 154 sizeof(ReadingBuffer) ==
148 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests, 155 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests,
149 "Check reading buffer size for tests"); 156 "Check reading buffer size for tests");
157
158 mojom::blink::PermissionStatus m_permissionStatus;
159 mojom::blink::PermissionService* m_permissionService;
160 RefPtr<SecurityOrigin> m_securityOrigin;
150 }; 161 };
151 162
152 } // namespace blink 163 } // namespace blink
153 164
154 #endif // SensorProxy_h 165 #endif // SensorProxy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698