| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "content/public/child/worker_thread.h" | 11 #include "content/public/child/worker_thread.h" |
| 12 #include "content/public/common/service_registry.h" | 12 #include "content/public/common/service_registry.h" |
| 13 #include "third_party/WebKit/public/platform/WebURL.h" | 13 #include "third_party/WebKit/public/platform/WebURL.h" |
| 14 #include "third_party/WebKit/public/platform/modules/permissions/WebPermissionOb
server.h" | 14 #include "third_party/WebKit/public/platform/modules/permissions/WebPermissionOb
server.h" |
| 15 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 15 | 16 |
| 16 using blink::WebPermissionObserver; | 17 using blink::WebPermissionObserver; |
| 17 using blink::mojom::PermissionName; | 18 using blink::mojom::PermissionName; |
| 18 using blink::mojom::PermissionStatus; | 19 using blink::mojom::PermissionStatus; |
| 19 | 20 |
| 20 namespace content { | 21 namespace content { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 PermissionName GetPermissionName(blink::WebPermissionType type) { | 25 PermissionName GetPermissionName(blink::WebPermissionType type) { |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // deleted, the callback will not leak. In the case of |this| gets deleted, | 267 // deleted, the callback will not leak. In the case of |this| gets deleted, |
| 267 // the |permission_service_| pipe will be destroyed too so OnQueryPermission | 268 // the |permission_service_| pipe will be destroyed too so OnQueryPermission |
| 268 // will not be called. | 269 // will not be called. |
| 269 uintptr_t callback_key = reinterpret_cast<uintptr_t>(callback); | 270 uintptr_t callback_key = reinterpret_cast<uintptr_t>(callback); |
| 270 permission_callbacks_.add( | 271 permission_callbacks_.add( |
| 271 callback_key, std::unique_ptr<blink::WebPermissionCallback>(callback)); | 272 callback_key, std::unique_ptr<blink::WebPermissionCallback>(callback)); |
| 272 | 273 |
| 273 GetPermissionServicePtr()->RequestPermission( | 274 GetPermissionServicePtr()->RequestPermission( |
| 274 GetPermissionName(type), | 275 GetPermissionName(type), |
| 275 origin, | 276 origin, |
| 277 blink::WebUserGestureIndicator::isProcessingUserGesture(), |
| 276 base::Bind(&PermissionDispatcher::OnPermissionResponse, | 278 base::Bind(&PermissionDispatcher::OnPermissionResponse, |
| 277 base::Unretained(this), | 279 base::Unretained(this), |
| 278 worker_thread_id, | 280 worker_thread_id, |
| 279 callback_key)); | 281 callback_key)); |
| 280 } | 282 } |
| 281 | 283 |
| 282 void PermissionDispatcher::RequestPermissionsInternal( | 284 void PermissionDispatcher::RequestPermissionsInternal( |
| 283 const blink::WebVector<blink::WebPermissionType>& types, | 285 const blink::WebVector<blink::WebPermissionType>& types, |
| 284 const std::string& origin, | 286 const std::string& origin, |
| 285 blink::WebPermissionsCallback* callback, | 287 blink::WebPermissionsCallback* callback, |
| 286 int worker_thread_id) { | 288 int worker_thread_id) { |
| 287 // We need to save the |callback| in an ScopedVector so if |this| gets | 289 // We need to save the |callback| in an ScopedVector so if |this| gets |
| 288 // deleted, the callback will not leak. In the case of |this| gets deleted, | 290 // deleted, the callback will not leak. In the case of |this| gets deleted, |
| 289 // the |permission_service_| pipe will be destroyed too so OnQueryPermission | 291 // the |permission_service_| pipe will be destroyed too so OnQueryPermission |
| 290 // will not be called. | 292 // will not be called. |
| 291 uintptr_t callback_key = reinterpret_cast<uintptr_t>(callback); | 293 uintptr_t callback_key = reinterpret_cast<uintptr_t>(callback); |
| 292 permissions_callbacks_.add( | 294 permissions_callbacks_.add( |
| 293 callback_key, std::unique_ptr<blink::WebPermissionsCallback>(callback)); | 295 callback_key, std::unique_ptr<blink::WebPermissionsCallback>(callback)); |
| 294 | 296 |
| 295 mojo::Array<PermissionName> names(types.size()); | 297 mojo::Array<PermissionName> names(types.size()); |
| 296 for (size_t i = 0; i < types.size(); ++i) | 298 for (size_t i = 0; i < types.size(); ++i) |
| 297 names[i] = GetPermissionName(types[i]); | 299 names[i] = GetPermissionName(types[i]); |
| 298 | 300 |
| 299 GetPermissionServicePtr()->RequestPermissions( | 301 GetPermissionServicePtr()->RequestPermissions( |
| 300 std::move(names), origin, | 302 std::move(names), origin, |
| 303 blink::WebUserGestureIndicator::isProcessingUserGesture(), |
| 301 base::Bind(&PermissionDispatcher::OnRequestPermissionsResponse, | 304 base::Bind(&PermissionDispatcher::OnRequestPermissionsResponse, |
| 302 base::Unretained(this), worker_thread_id, callback_key)); | 305 base::Unretained(this), worker_thread_id, callback_key)); |
| 303 } | 306 } |
| 304 | 307 |
| 305 void PermissionDispatcher::RevokePermissionInternal( | 308 void PermissionDispatcher::RevokePermissionInternal( |
| 306 blink::WebPermissionType type, | 309 blink::WebPermissionType type, |
| 307 const std::string& origin, | 310 const std::string& origin, |
| 308 blink::WebPermissionCallback* callback, | 311 blink::WebPermissionCallback* callback, |
| 309 int worker_thread_id) { | 312 int worker_thread_id) { |
| 310 // We need to save the |callback| in an ScopedPtrHashMap so if |this| gets | 313 // We need to save the |callback| in an ScopedPtrHashMap so if |this| gets |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 origin, | 404 origin, |
| 402 current_status, | 405 current_status, |
| 403 base::Bind(&PermissionDispatcher::OnPermissionChanged, | 406 base::Bind(&PermissionDispatcher::OnPermissionChanged, |
| 404 base::Unretained(this), | 407 base::Unretained(this), |
| 405 type, | 408 type, |
| 406 origin, | 409 origin, |
| 407 base::Unretained(observer))); | 410 base::Unretained(observer))); |
| 408 } | 411 } |
| 409 | 412 |
| 410 } // namespace content | 413 } // namespace content |
| OLD | NEW |