| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/browser/permissions/permission_service_impl.h" | 5 #include "content/browser/permissions/permission_service_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 return PermissionType::BACKGROUND_SYNC; | 43 return PermissionType::BACKGROUND_SYNC; |
| 44 } | 44 } |
| 45 | 45 |
| 46 NOTREACHED(); | 46 NOTREACHED(); |
| 47 return PermissionType::NUM; | 47 return PermissionType::NUM; |
| 48 } | 48 } |
| 49 | 49 |
| 50 // This function allows the usage of the the multiple request map | 50 // This function allows the usage of the the multiple request map |
| 51 // with single requests. | 51 // with single requests. |
| 52 void PermissionRequestResponseCallbackWrapper( | 52 void PermissionRequestResponseCallbackWrapper( |
| 53 const mojo::Callback<void(PermissionStatus)>& callback, | 53 const base::Callback<void(PermissionStatus)>& callback, |
| 54 mojo::Array<PermissionStatus> vector) { | 54 mojo::Array<PermissionStatus> vector) { |
| 55 DCHECK_EQ(vector.size(), 1ul); | 55 DCHECK_EQ(vector.size(), 1ul); |
| 56 callback.Run(vector[0]); | 56 callback.Run(vector[0]); |
| 57 } | 57 } |
| 58 | 58 |
| 59 } // anonymous namespace | 59 } // anonymous namespace |
| 60 | 60 |
| 61 PermissionServiceImpl::PendingRequest::PendingRequest( | 61 PermissionServiceImpl::PendingRequest::PendingRequest( |
| 62 const PermissionsStatusCallback& callback, | 62 const RequestPermissionsCallback& callback, |
| 63 int request_count) | 63 int request_count) |
| 64 : callback(callback), | 64 : callback(callback), |
| 65 request_count(request_count) { | 65 request_count(request_count) { |
| 66 } | 66 } |
| 67 | 67 |
| 68 PermissionServiceImpl::PendingRequest::~PendingRequest() { | 68 PermissionServiceImpl::PendingRequest::~PendingRequest() { |
| 69 if (callback.is_null()) | 69 if (callback.is_null()) |
| 70 return; | 70 return; |
| 71 | 71 |
| 72 mojo::Array<PermissionStatus> result = | 72 mojo::Array<PermissionStatus> result = |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 int pending_request_id, | 155 int pending_request_id, |
| 156 PermissionStatus status) { | 156 PermissionStatus status) { |
| 157 OnRequestPermissionsResponse(pending_request_id, | 157 OnRequestPermissionsResponse(pending_request_id, |
| 158 std::vector<PermissionStatus>(1, status)); | 158 std::vector<PermissionStatus>(1, status)); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void PermissionServiceImpl::RequestPermissions( | 161 void PermissionServiceImpl::RequestPermissions( |
| 162 mojo::Array<PermissionName> permissions, | 162 mojo::Array<PermissionName> permissions, |
| 163 const mojo::String& origin, | 163 const mojo::String& origin, |
| 164 bool user_gesture, | 164 bool user_gesture, |
| 165 const PermissionsStatusCallback& callback) { | 165 const RequestPermissionsCallback& callback) { |
| 166 if (permissions.is_null()) { | 166 if (permissions.is_null()) { |
| 167 callback.Run(mojo::Array<PermissionStatus>()); | 167 callback.Run(mojo::Array<PermissionStatus>()); |
| 168 return; | 168 return; |
| 169 } | 169 } |
| 170 | 170 |
| 171 // This condition is valid if the call is coming from a ChildThread instead of | 171 // This condition is valid if the call is coming from a ChildThread instead of |
| 172 // a RenderFrame. Some consumers of the service run in Workers and some in | 172 // a RenderFrame. Some consumers of the service run in Workers and some in |
| 173 // Frames. In the context of a Worker, it is not possible to show a | 173 // Frames. In the context of a Worker, it is not possible to show a |
| 174 // permission prompt because there is no tab. In the context of a Frame, we | 174 // permission prompt because there is no tab. In the context of a Frame, we |
| 175 // can. Even if the call comes from a context where it is not possible to show | 175 // can. Even if the call comes from a context where it is not possible to show |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 pending_request_id); | 208 pending_request_id); |
| 209 if (!pending_request) | 209 if (!pending_request) |
| 210 return; | 210 return; |
| 211 pending_request->id = id; | 211 pending_request->id = id; |
| 212 } | 212 } |
| 213 | 213 |
| 214 void PermissionServiceImpl::OnRequestPermissionsResponse( | 214 void PermissionServiceImpl::OnRequestPermissionsResponse( |
| 215 int pending_request_id, | 215 int pending_request_id, |
| 216 const std::vector<PermissionStatus>& result) { | 216 const std::vector<PermissionStatus>& result) { |
| 217 PendingRequest* request = pending_requests_.Lookup(pending_request_id); | 217 PendingRequest* request = pending_requests_.Lookup(pending_request_id); |
| 218 PermissionsStatusCallback callback(request->callback); | 218 RequestPermissionsCallback callback(request->callback); |
| 219 request->callback.Reset(); | 219 request->callback.Reset(); |
| 220 pending_requests_.Remove(pending_request_id); | 220 pending_requests_.Remove(pending_request_id); |
| 221 callback.Run(mojo::Array<PermissionStatus>::From(result)); | 221 callback.Run(mojo::Array<PermissionStatus>::From(result)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 void PermissionServiceImpl::CancelPendingOperations() { | 224 void PermissionServiceImpl::CancelPendingOperations() { |
| 225 DCHECK(context_->GetBrowserContext()); | 225 DCHECK(context_->GetBrowserContext()); |
| 226 | 226 |
| 227 PermissionManager* permission_manager = | 227 PermissionManager* permission_manager = |
| 228 context_->GetBrowserContext()->GetPermissionManager(); | 228 context_->GetBrowserContext()->GetPermissionManager(); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 367 |
| 368 PermissionStatusCallback callback = subscription->callback; | 368 PermissionStatusCallback callback = subscription->callback; |
| 369 | 369 |
| 370 subscription->callback.Reset(); | 370 subscription->callback.Reset(); |
| 371 pending_subscriptions_.Remove(pending_subscription_id); | 371 pending_subscriptions_.Remove(pending_subscription_id); |
| 372 | 372 |
| 373 callback.Run(status); | 373 callback.Run(status); |
| 374 } | 374 } |
| 375 | 375 |
| 376 } // namespace content | 376 } // namespace content |
| OLD | NEW |