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

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: Fix comments + rebase 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 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/dom/ExecutionContext.h"
9 #include "device/generic_sensor/public/cpp/sensor_reading.h" 10 #include "device/generic_sensor/public/cpp/sensor_reading.h"
10 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h" 11 #include "device/generic_sensor/public/interfaces/sensor.mojom-blink.h"
11 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h" 12 #include "device/generic_sensor/public/interfaces/sensor_provider.mojom-blink.h"
12 #include "mojo/public/cpp/bindings/binding.h" 13 #include "mojo/public/cpp/bindings/binding.h"
13 #include "platform/Supplementable.h" 14 #include "platform/Supplementable.h"
14 #include "platform/heap/Handle.h" 15 #include "platform/heap/Handle.h"
16 #include "public/platform/modules/permissions/permission.mojom-blink.h"
17 #include "public/platform/modules/permissions/permission_status.mojom-blink.h"
15 18
16 namespace blink { 19 namespace blink {
17 20
18 class SensorProviderProxy; 21 class SensorProviderProxy;
19 class SensorReading; 22 class SensorReading;
20 class SensorReadingFactory; 23 class SensorReadingFactory;
21 24
22 // This class wraps 'Sensor' mojo interface and used by multiple 25 // This class wraps 'Sensor' mojo interface and used by multiple
23 // JS sensor instances of the same type (within a single frame). 26 // JS sensor instances of the same type (within a single frame).
24 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>, 27 class SensorProxy final : public GarbageCollectedFinalized<SensorProxy>,
25 public device::mojom::blink::SensorClient { 28 public device::mojom::blink::SensorClient {
26 USING_PRE_FINALIZER(SensorProxy, dispose); 29 USING_PRE_FINALIZER(SensorProxy, dispose);
27 WTF_MAKE_NONCOPYABLE(SensorProxy); 30 WTF_MAKE_NONCOPYABLE(SensorProxy);
28 31
29 public: 32 public:
30 class Observer : public GarbageCollectedMixin { 33 class Observer : public GarbageCollectedMixin {
31 public: 34 public:
32 // Has valid 'Sensor' binding, {add, remove}Configuration() 35 // Has valid 'Sensor' binding, {add, remove}Configuration()
33 // methods can be called. 36 // methods can be called.
34 virtual void onSensorInitialized() {} 37 virtual void onSensorInitialized() {}
35 // Platfrom sensort reading has changed (for 'ONCHANGE' reporting mode). 38 // Platfrom sensort reading has changed (for 'ONCHANGE' reporting mode).
36 virtual void onSensorReadingChanged() {} 39 virtual void onSensorReadingChanged() {}
37 // An error has occurred. 40 // An error has occurred.
38 virtual void onSensorError(ExceptionCode, 41 virtual void onSensorError(ExceptionCode,
39 const String& sanitizedMessage, 42 const String& sanitizedMessage,
40 const String& unsanitizedMessage) {} 43 const String& unsanitizedMessage) {}
44 // Permission for sensor has changed.
45 virtual void onSensorPermissionChanged() {}
41 }; 46 };
42 47
43 ~SensorProxy(); 48 ~SensorProxy();
44 49
45 void dispose(); 50 void dispose();
46 51
47 void addObserver(Observer*); 52 void addObserver(Observer*);
48 void removeObserver(Observer*); 53 void removeObserver(Observer*);
49 54
50 void initialize(); 55 void initialize();
(...skipping 15 matching lines...) Expand all
66 // The |SensorReading| instance which is shared between sensor instances 71 // The |SensorReading| instance which is shared between sensor instances
67 // of the same type. 72 // of the same type.
68 // Note: the returned value is reset after updateSensorReading() call. 73 // Note: the returned value is reset after updateSensorReading() call.
69 SensorReading* sensorReading() const { return m_reading; } 74 SensorReading* sensorReading() const { return m_reading; }
70 75
71 const device::mojom::blink::SensorConfiguration* defaultConfig() const; 76 const device::mojom::blink::SensorConfiguration* defaultConfig() const;
72 77
73 // Updates sensor reading from shared buffer. 78 // Updates sensor reading from shared buffer.
74 void updateSensorReading(); 79 void updateSensorReading();
75 80
81 mojom::blink::PermissionService* getPermissionService(ExecutionContext*);
Mikhail 2016/11/10 09:30:48 1) permissionService() 2) why pass |ExecutionConte
riju_ 2016/11/14 14:00:07 Done.
82 void resetPermissionService();
83 void permissionServiceConnectionError();
Mikhail 2016/11/10 09:30:48 name of this function looks like a getter, it's un
riju_ 2016/11/14 14:00:07 Removing it.
84 void onPermissionUpdate(mojom::blink::PermissionStatus);
Mikhail 2016/11/10 09:30:48 does it need to be public? (same comment allies to
riju_ 2016/11/14 14:00:07 Done.
85 void getNextPermissionChange(ExecutionContext*,
86 mojom::blink::PermissionStatus);
87 void requestPermission(ExecutionContext*, mojom::blink::PermissionStatus);
88 mojom::blink::PermissionStatus getPermissionStatus() const {
Mikhail 2016/11/10 09:30:48 permissionStatus()
riju_ 2016/11/14 14:00:07 removing it.
89 return m_sensorPermission;
90 };
91 bool getStartPendingPermission() const { return m_startPendingPermission; }
Mikhail 2016/11/10 09:30:48 bool pendingPermissionRequest() const ?
riju_ 2016/11/14 14:00:07 Not needed now. removing it.
92 void setStartPendingPermission(bool value) {
93 m_startPendingPermission = value;
94 }
95
76 DECLARE_VIRTUAL_TRACE(); 96 DECLARE_VIRTUAL_TRACE();
77 97
78 private: 98 private:
79 friend class SensorProviderProxy; 99 friend class SensorProviderProxy;
80 SensorProxy(device::mojom::blink::SensorType, 100 SensorProxy(device::mojom::blink::SensorType,
101 ExecutionContext*,
81 SensorProviderProxy*, 102 SensorProviderProxy*,
82 std::unique_ptr<SensorReadingFactory>); 103 std::unique_ptr<SensorReadingFactory>);
83 104
84 // device::mojom::blink::SensorClient overrides. 105 // device::mojom::blink::SensorClient overrides.
85 void RaiseError() override; 106 void RaiseError() override;
86 void SensorReadingChanged() override; 107 void SensorReadingChanged() override;
87 108
109 void SensorPermissionChanged();
110
88 // Generic handler for a fatal error. 111 // Generic handler for a fatal error.
89 // String parameters are intentionally copied. 112 // String parameters are intentionally copied.
90 void handleSensorError(ExceptionCode = UnknownError, 113 void handleSensorError(ExceptionCode = UnknownError,
91 String sanitizedMessage = String(), 114 String sanitizedMessage = String(),
92 String unsanitizedMessage = String()); 115 String unsanitizedMessage = String());
93 116
94 void onSensorCreated(device::mojom::blink::SensorInitParamsPtr, 117 void onSensorCreated(device::mojom::blink::SensorInitParamsPtr,
95 device::mojom::blink::SensorClientRequest); 118 device::mojom::blink::SensorClientRequest);
96 119
97 bool tryReadFromBuffer(device::SensorReading& result); 120 bool tryReadFromBuffer(device::SensorReading& result);
(...skipping 14 matching lines...) Expand all
112 mojo::ScopedSharedBufferMapping m_sharedBuffer; 135 mojo::ScopedSharedBufferMapping m_sharedBuffer;
113 bool m_suspended; 136 bool m_suspended;
114 Member<SensorReading> m_reading; 137 Member<SensorReading> m_reading;
115 std::unique_ptr<SensorReadingFactory> m_readingFactory; 138 std::unique_ptr<SensorReadingFactory> m_readingFactory;
116 139
117 using ReadingBuffer = device::SensorReadingSharedBuffer; 140 using ReadingBuffer = device::SensorReadingSharedBuffer;
118 static_assert( 141 static_assert(
119 sizeof(ReadingBuffer) == 142 sizeof(ReadingBuffer) ==
120 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests, 143 device::mojom::blink::SensorInitParams::kReadBufferSizeForTests,
121 "Check reading buffer size for tests"); 144 "Check reading buffer size for tests");
145
146 mojom::blink::PermissionStatus m_sensorPermission;
Mikhail 2016/11/10 09:30:48 m_permissionStatus
riju_ 2016/11/14 14:00:07 Done.
147 mojom::blink::PermissionServicePtr m_permissionService;
148 Member<ExecutionContext> m_executionContext;
149 bool m_startPendingPermission;
122 }; 150 };
123 151
124 } // namespace blink 152 } // namespace blink
125 153
126 #endif // SensorProxy_h 154 #endif // SensorProxy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698