OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_H_ | 5 #ifndef CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_H_ |
6 #define CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_H_ | 6 #define CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 explicit PermissionDispatcher(ServiceRegistry* service_registry); | 36 explicit PermissionDispatcher(ServiceRegistry* service_registry); |
37 virtual ~PermissionDispatcher(); | 37 virtual ~PermissionDispatcher(); |
38 | 38 |
39 // blink::WebPermissionClient implementation. | 39 // blink::WebPermissionClient implementation. |
40 virtual void queryPermission(blink::WebPermissionType type, | 40 virtual void queryPermission(blink::WebPermissionType type, |
41 const blink::WebURL& origin, | 41 const blink::WebURL& origin, |
42 blink::WebPermissionCallback* callback); | 42 blink::WebPermissionCallback* callback); |
43 virtual void requestPermission(blink::WebPermissionType, | 43 virtual void requestPermission(blink::WebPermissionType, |
44 const blink::WebURL& origin, | 44 const blink::WebURL& origin, |
45 blink::WebPermissionCallback* callback); | 45 blink::WebPermissionCallback* callback); |
| 46 virtual void requestPermissions( |
| 47 const blink::WebVector<blink::WebPermissionType>& types, |
| 48 const blink::WebURL& origin, |
| 49 blink::WebPermissionsCallback* callback); |
46 virtual void revokePermission(blink::WebPermissionType, | 50 virtual void revokePermission(blink::WebPermissionType, |
47 const blink::WebURL& origin, | 51 const blink::WebURL& origin, |
48 blink::WebPermissionCallback* callback); | 52 blink::WebPermissionCallback* callback); |
49 virtual void startListening(blink::WebPermissionType type, | 53 virtual void startListening(blink::WebPermissionType type, |
50 const blink::WebURL& origin, | 54 const blink::WebURL& origin, |
51 blink::WebPermissionObserver* observer); | 55 blink::WebPermissionObserver* observer); |
52 virtual void stopListening(blink::WebPermissionObserver* observer); | 56 virtual void stopListening(blink::WebPermissionObserver* observer); |
53 | 57 |
54 // The following methods must be called by workers on the main thread. | 58 // The following methods must be called by workers on the main thread. |
55 void QueryPermissionForWorker(blink::WebPermissionType type, | 59 void QueryPermissionForWorker(blink::WebPermissionType type, |
56 const std::string& origin, | 60 const std::string& origin, |
57 blink::WebPermissionCallback* callback, | 61 blink::WebPermissionCallback* callback, |
58 int worker_thread_id); | 62 int worker_thread_id); |
59 void RequestPermissionForWorker(blink::WebPermissionType type, | 63 void RequestPermissionForWorker(blink::WebPermissionType type, |
60 const std::string& origin, | 64 const std::string& origin, |
61 blink::WebPermissionCallback* callback, | 65 blink::WebPermissionCallback* callback, |
62 int worker_thread_id); | 66 int worker_thread_id); |
| 67 void RequestPermissionsForWorker( |
| 68 const blink::WebVector<blink::WebPermissionType>& types, |
| 69 const std::string& origin, |
| 70 blink::WebPermissionsCallback* callback, |
| 71 int worker_thread_id); |
63 void RevokePermissionForWorker(blink::WebPermissionType type, | 72 void RevokePermissionForWorker(blink::WebPermissionType type, |
64 const std::string& origin, | 73 const std::string& origin, |
65 blink::WebPermissionCallback* callback, | 74 blink::WebPermissionCallback* callback, |
66 int worker_thread_id); | 75 int worker_thread_id); |
67 void StartListeningForWorker( | 76 void StartListeningForWorker( |
68 blink::WebPermissionType type, | 77 blink::WebPermissionType type, |
69 const std::string& origin, | 78 const std::string& origin, |
70 int worker_thread_id, | 79 int worker_thread_id, |
71 const base::Callback<void(blink::WebPermissionStatus)>& callback); | 80 const base::Callback<void(blink::WebPermissionStatus)>& callback); |
72 void GetNextPermissionChangeForWorker( | 81 void GetNextPermissionChangeForWorker( |
73 blink::WebPermissionType type, | 82 blink::WebPermissionType type, |
74 const std::string& origin, | 83 const std::string& origin, |
75 blink::WebPermissionStatus status, | 84 blink::WebPermissionStatus status, |
76 int worker_thread_id, | 85 int worker_thread_id, |
77 const base::Callback<void(blink::WebPermissionStatus)>& callback); | 86 const base::Callback<void(blink::WebPermissionStatus)>& callback); |
78 | 87 |
79 private: | 88 private: |
80 // Runs the given |callback| with |status| as a parameter. It has to be run | 89 // Runs the given |callback| with |status| as a parameter. It has to be run |
81 // on a worker thread. | 90 // on a worker thread. |
82 static void RunCallbackOnWorkerThread( | 91 static void RunCallbackOnWorkerThread( |
83 blink::WebPermissionCallback* callback, | 92 blink::WebPermissionCallback* callback, |
84 scoped_ptr<blink::WebPermissionStatus> status); | 93 scoped_ptr<blink::WebPermissionStatus> status); |
| 94 static void RunMultiCallbackOnWorkerThread( |
| 95 blink::WebPermissionsCallback* callback, |
| 96 scoped_ptr<blink::WebVector<blink::WebPermissionStatus>> statuses); |
85 | 97 |
86 // Helper method that returns an initialized PermissionServicePtr. | 98 // Helper method that returns an initialized PermissionServicePtr. |
87 PermissionServicePtr& GetPermissionServicePtr(); | 99 PermissionServicePtr& GetPermissionServicePtr(); |
88 | 100 |
89 void QueryPermissionInternal(blink::WebPermissionType type, | 101 void QueryPermissionInternal(blink::WebPermissionType type, |
90 const std::string& origin, | 102 const std::string& origin, |
91 blink::WebPermissionCallback* callback, | 103 blink::WebPermissionCallback* callback, |
92 int worker_thread_id); | 104 int worker_thread_id); |
93 void RequestPermissionInternal(blink::WebPermissionType type, | 105 void RequestPermissionInternal(blink::WebPermissionType type, |
94 const std::string& origin, | 106 const std::string& origin, |
95 blink::WebPermissionCallback* callback, | 107 blink::WebPermissionCallback* callback, |
96 int worker_thread_id); | 108 int worker_thread_id); |
| 109 void RequestPermissionsInternal( |
| 110 const blink::WebVector<blink::WebPermissionType>& types, |
| 111 const std::string& origin, |
| 112 blink::WebPermissionsCallback* callback, |
| 113 int worker_thread_id); |
97 void RevokePermissionInternal(blink::WebPermissionType type, | 114 void RevokePermissionInternal(blink::WebPermissionType type, |
98 const std::string& origin, | 115 const std::string& origin, |
99 blink::WebPermissionCallback* callback, | 116 blink::WebPermissionCallback* callback, |
100 int worker_thread_id); | 117 int worker_thread_id); |
101 | 118 |
102 // This is the callback function used for query and revoke | 119 // This is the callback function used for query and revoke |
103 void OnPermissionResponse(int request_id, | 120 void OnPermissionResponse(int request_id, |
104 PermissionStatus status); | 121 PermissionStatus status); |
| 122 void OnPermissionsResponse(int request_id, |
| 123 const mojo::Array<PermissionStatus>& status); |
105 void OnPermissionChanged(blink::WebPermissionType type, | 124 void OnPermissionChanged(blink::WebPermissionType type, |
106 const std::string& origin, | 125 const std::string& origin, |
107 blink::WebPermissionObserver* observer, | 126 blink::WebPermissionObserver* observer, |
108 PermissionStatus status); | 127 PermissionStatus status); |
109 void OnPermissionChangedForWorker( | 128 void OnPermissionChangedForWorker( |
110 int worker_thread_id, | 129 int worker_thread_id, |
111 const base::Callback<void(blink::WebPermissionStatus)>& callback, | 130 const base::Callback<void(blink::WebPermissionStatus)>& callback, |
112 PermissionStatus status); | 131 PermissionStatus status); |
113 | 132 |
114 void GetNextPermissionChange(blink::WebPermissionType type, | 133 void GetNextPermissionChange(blink::WebPermissionType type, |
(...skipping 16 matching lines...) Expand all Loading... |
131 | 150 |
132 private: | 151 private: |
133 scoped_ptr<blink::WebPermissionCallback> callback_; | 152 scoped_ptr<blink::WebPermissionCallback> callback_; |
134 int worker_thread_id_; | 153 int worker_thread_id_; |
135 | 154 |
136 DISALLOW_COPY_AND_ASSIGN(CallbackInformation); | 155 DISALLOW_COPY_AND_ASSIGN(CallbackInformation); |
137 }; | 156 }; |
138 using CallbackMap = IDMap<CallbackInformation, IDMapOwnPointer>; | 157 using CallbackMap = IDMap<CallbackInformation, IDMapOwnPointer>; |
139 CallbackMap pending_callbacks_; | 158 CallbackMap pending_callbacks_; |
140 | 159 |
| 160 // Saves some basic information about the callback in order to be able to run |
| 161 // it in the right thread. |
| 162 class MultipleCallbackInformation { |
| 163 public: |
| 164 MultipleCallbackInformation(blink::WebPermissionsCallback* callback, |
| 165 int worker_thread_id); |
| 166 ~MultipleCallbackInformation(); |
| 167 |
| 168 blink::WebPermissionsCallback* callback() const; |
| 169 int worker_thread_id() const; |
| 170 |
| 171 blink::WebPermissionsCallback* ReleaseCallback(); |
| 172 |
| 173 private: |
| 174 scoped_ptr<blink::WebPermissionsCallback> callback_; |
| 175 int worker_thread_id_; |
| 176 |
| 177 DISALLOW_COPY_AND_ASSIGN(MultipleCallbackInformation); |
| 178 }; |
| 179 using MultipleCallbackMap = |
| 180 IDMap<MultipleCallbackInformation, IDMapOwnPointer>; |
| 181 MultipleCallbackMap multiple_pending_callbacks_; |
| 182 |
141 ServiceRegistry* service_registry_; | 183 ServiceRegistry* service_registry_; |
142 PermissionServicePtr permission_service_; | 184 PermissionServicePtr permission_service_; |
143 | 185 |
144 DISALLOW_COPY_AND_ASSIGN(PermissionDispatcher); | 186 DISALLOW_COPY_AND_ASSIGN(PermissionDispatcher); |
145 }; | 187 }; |
146 | 188 |
147 } // namespace content | 189 } // namespace content |
148 | 190 |
149 #endif // CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_H_ | 191 #endif // CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_H_ |
OLD | NEW |