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 #include "content/child/permissions/permission_dispatcher.h" | 5 #include "content/child/permissions/permission_dispatcher.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "content/child/worker_task_runner.h" | 8 #include "content/child/worker_task_runner.h" |
9 #include "content/public/common/service_registry.h" | 9 #include "content/public/common/service_registry.h" |
10 #include "third_party/WebKit/public/platform/WebURL.h" | 10 #include "third_party/WebKit/public/platform/WebURL.h" |
11 #include "third_party/WebKit/public/platform/modules/permissions/WebPermissionOb
server.h" | 11 #include "third_party/WebKit/public/platform/modules/permissions/WebPermissionOb
server.h" |
| 12 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
12 | 13 |
13 using blink::WebPermissionObserver; | 14 using blink::WebPermissionObserver; |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 PermissionName GetPermissionName(blink::WebPermissionType type) { | 20 PermissionName GetPermissionName(blink::WebPermissionType type) { |
20 switch (type) { | 21 switch (type) { |
21 case blink::WebPermissionTypeGeolocation: | 22 case blink::WebPermissionTypeGeolocation: |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 } | 107 } |
107 | 108 |
108 void PermissionDispatcher::queryPermission( | 109 void PermissionDispatcher::queryPermission( |
109 blink::WebPermissionType type, | 110 blink::WebPermissionType type, |
110 const blink::WebURL& origin, | 111 const blink::WebURL& origin, |
111 blink::WebPermissionCallback* callback) { | 112 blink::WebPermissionCallback* callback) { |
112 QueryPermissionInternal( | 113 QueryPermissionInternal( |
113 type, origin.string().utf8(), callback, kNoWorkerThread); | 114 type, origin.string().utf8(), callback, kNoWorkerThread); |
114 } | 115 } |
115 | 116 |
| 117 void PermissionDispatcher::requestPermission( |
| 118 blink::WebPermissionType type, |
| 119 const blink::WebURL& origin, |
| 120 blink::WebPermissionCallback* callback) { |
| 121 RequestPermissionInternal( |
| 122 type, origin.string().utf8(), callback, kNoWorkerThread); |
| 123 } |
| 124 |
116 void PermissionDispatcher::revokePermission( | 125 void PermissionDispatcher::revokePermission( |
117 blink::WebPermissionType type, | 126 blink::WebPermissionType type, |
118 const blink::WebURL& origin, | 127 const blink::WebURL& origin, |
119 blink::WebPermissionCallback* callback) { | 128 blink::WebPermissionCallback* callback) { |
120 RevokePermissionInternal( | 129 RevokePermissionInternal( |
121 type, origin.string().utf8(), callback, kNoWorkerThread); | 130 type, origin.string().utf8(), callback, kNoWorkerThread); |
122 } | 131 } |
123 | 132 |
124 void PermissionDispatcher::startListening( | 133 void PermissionDispatcher::startListening( |
125 blink::WebPermissionType type, | 134 blink::WebPermissionType type, |
(...skipping 21 matching lines...) Expand all Loading... |
147 } | 156 } |
148 | 157 |
149 void PermissionDispatcher::QueryPermissionForWorker( | 158 void PermissionDispatcher::QueryPermissionForWorker( |
150 blink::WebPermissionType type, | 159 blink::WebPermissionType type, |
151 const std::string& origin, | 160 const std::string& origin, |
152 blink::WebPermissionCallback* callback, | 161 blink::WebPermissionCallback* callback, |
153 int worker_thread_id) { | 162 int worker_thread_id) { |
154 QueryPermissionInternal(type, origin, callback, worker_thread_id); | 163 QueryPermissionInternal(type, origin, callback, worker_thread_id); |
155 } | 164 } |
156 | 165 |
| 166 void PermissionDispatcher::RequestPermissionForWorker( |
| 167 blink::WebPermissionType type, |
| 168 const std::string& origin, |
| 169 blink::WebPermissionCallback* callback, |
| 170 int worker_thread_id) { |
| 171 RequestPermissionInternal(type, origin, callback, worker_thread_id); |
| 172 } |
| 173 |
157 void PermissionDispatcher::RevokePermissionForWorker( | 174 void PermissionDispatcher::RevokePermissionForWorker( |
158 blink::WebPermissionType type, | 175 blink::WebPermissionType type, |
159 const std::string& origin, | 176 const std::string& origin, |
160 blink::WebPermissionCallback* callback, | 177 blink::WebPermissionCallback* callback, |
161 int worker_thread_id) { | 178 int worker_thread_id) { |
162 RevokePermissionInternal(type, origin, callback, worker_thread_id); | 179 RevokePermissionInternal(type, origin, callback, worker_thread_id); |
163 } | 180 } |
164 | 181 |
165 void PermissionDispatcher::StartListeningForWorker( | 182 void PermissionDispatcher::StartListeningForWorker( |
166 blink::WebPermissionType type, | 183 blink::WebPermissionType type, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 int request_id = pending_callbacks_.Add( | 242 int request_id = pending_callbacks_.Add( |
226 new CallbackInformation(callback, worker_thread_id)); | 243 new CallbackInformation(callback, worker_thread_id)); |
227 GetPermissionServicePtr()->HasPermission( | 244 GetPermissionServicePtr()->HasPermission( |
228 GetPermissionName(type), | 245 GetPermissionName(type), |
229 origin, | 246 origin, |
230 base::Bind(&PermissionDispatcher::OnPermissionResponse, | 247 base::Bind(&PermissionDispatcher::OnPermissionResponse, |
231 base::Unretained(this), | 248 base::Unretained(this), |
232 request_id)); | 249 request_id)); |
233 } | 250 } |
234 | 251 |
| 252 void PermissionDispatcher::RequestPermissionInternal( |
| 253 blink::WebPermissionType type, |
| 254 const std::string& origin, |
| 255 blink::WebPermissionCallback* callback, |
| 256 int worker_thread_id) { |
| 257 // We need to save the |callback| in an IDMap so if |this| gets deleted, the |
| 258 // callback will not leak. In the case of |this| gets deleted, the |
| 259 // |permission_service_| pipe will be destroyed too so OnQueryPermission will |
| 260 // not be called. |
| 261 int request_id = pending_callbacks_.Add( |
| 262 new CallbackInformation(callback, worker_thread_id)); |
| 263 GetPermissionServicePtr()->RequestPermission( |
| 264 GetPermissionName(type), |
| 265 origin, |
| 266 blink::WebUserGestureIndicator::isProcessingUserGesture(), |
| 267 base::Bind(&PermissionDispatcher::OnPermissionResponse, |
| 268 base::Unretained(this), |
| 269 request_id)); |
| 270 } |
| 271 |
235 void PermissionDispatcher::RevokePermissionInternal( | 272 void PermissionDispatcher::RevokePermissionInternal( |
236 blink::WebPermissionType type, | 273 blink::WebPermissionType type, |
237 const std::string& origin, | 274 const std::string& origin, |
238 blink::WebPermissionCallback* callback, | 275 blink::WebPermissionCallback* callback, |
239 int worker_thread_id) { | 276 int worker_thread_id) { |
240 // We need to save the |callback| in an IDMap so if |this| gets deleted, the | 277 // We need to save the |callback| in an IDMap so if |this| gets deleted, the |
241 // callback will not leak. In the case of |this| gets deleted, the | 278 // callback will not leak. In the case of |this| gets deleted, the |
242 // |permission_service_| pipe will be destroyed too so OnQueryPermission will | 279 // |permission_service_| pipe will be destroyed too so OnQueryPermission will |
243 // not be called. | 280 // not be called. |
244 int request_id = pending_callbacks_.Add( | 281 int request_id = pending_callbacks_.Add( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 origin, | 349 origin, |
313 current_status, | 350 current_status, |
314 base::Bind(&PermissionDispatcher::OnPermissionChanged, | 351 base::Bind(&PermissionDispatcher::OnPermissionChanged, |
315 base::Unretained(this), | 352 base::Unretained(this), |
316 type, | 353 type, |
317 origin, | 354 origin, |
318 base::Unretained(observer))); | 355 base::Unretained(observer))); |
319 } | 356 } |
320 | 357 |
321 } // namespace content | 358 } // namespace content |
OLD | NEW |