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 |
| 9 #include <memory> |
8 #include <utility> | 10 #include <utility> |
9 | 11 |
10 #include "base/bind.h" | 12 #include "base/bind.h" |
11 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
12 #include "content/public/browser/permission_manager.h" | 14 #include "content/public/browser/permission_manager.h" |
13 #include "content/public/browser/permission_type.h" | 15 #include "content/public/browser/permission_type.h" |
14 | 16 |
15 using blink::mojom::PermissionDescriptorPtr; | 17 using blink::mojom::PermissionDescriptorPtr; |
16 using blink::mojom::PermissionName; | 18 using blink::mojom::PermissionName; |
17 using blink::mojom::PermissionStatus; | 19 using blink::mojom::PermissionStatus; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // any UI, we want to still return something relevant so the current | 125 // any UI, we want to still return something relevant so the current |
124 // permission status is returned. | 126 // permission status is returned. |
125 BrowserContext* browser_context = context_->GetBrowserContext(); | 127 BrowserContext* browser_context = context_->GetBrowserContext(); |
126 DCHECK(browser_context); | 128 DCHECK(browser_context); |
127 if (!context_->render_frame_host() || | 129 if (!context_->render_frame_host() || |
128 !browser_context->GetPermissionManager()) { | 130 !browser_context->GetPermissionManager()) { |
129 callback.Run(GetPermissionStatus(permission, origin)); | 131 callback.Run(GetPermissionStatus(permission, origin)); |
130 return; | 132 return; |
131 } | 133 } |
132 | 134 |
133 int pending_request_id = pending_requests_.Add(new PendingRequest( | 135 int pending_request_id = pending_requests_.Add( |
134 base::Bind(&PermissionRequestResponseCallbackWrapper, callback), 1)); | 136 base::MakeUnique<PendingRequest>( |
| 137 base::Bind(&PermissionRequestResponseCallbackWrapper, callback), 1)); |
135 int id = browser_context->GetPermissionManager()->RequestPermission( | 138 int id = browser_context->GetPermissionManager()->RequestPermission( |
136 PermissionDescriptorToPermissionType(permission), | 139 PermissionDescriptorToPermissionType(permission), |
137 context_->render_frame_host(), origin.GetURL(), user_gesture, | 140 context_->render_frame_host(), origin.GetURL(), user_gesture, |
138 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, | 141 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, |
139 weak_factory_.GetWeakPtr(), pending_request_id)); | 142 weak_factory_.GetWeakPtr(), pending_request_id)); |
140 | 143 |
141 // Check if the request still exists. It might have been removed by the | 144 // Check if the request still exists. It might have been removed by the |
142 // callback if it was run synchronously. | 145 // callback if it was run synchronously. |
143 PendingRequest* pending_request = pending_requests_.Lookup( | 146 PendingRequest* pending_request = pending_requests_.Lookup( |
144 pending_request_id); | 147 pending_request_id); |
(...skipping 30 matching lines...) Expand all Loading... |
175 result[i] = GetPermissionStatus(permissions[i], origin); | 178 result[i] = GetPermissionStatus(permissions[i], origin); |
176 callback.Run(result); | 179 callback.Run(result); |
177 return; | 180 return; |
178 } | 181 } |
179 | 182 |
180 std::vector<PermissionType> types(permissions.size()); | 183 std::vector<PermissionType> types(permissions.size()); |
181 for (size_t i = 0; i < types.size(); ++i) | 184 for (size_t i = 0; i < types.size(); ++i) |
182 types[i] = PermissionDescriptorToPermissionType(permissions[i]); | 185 types[i] = PermissionDescriptorToPermissionType(permissions[i]); |
183 | 186 |
184 int pending_request_id = pending_requests_.Add( | 187 int pending_request_id = pending_requests_.Add( |
185 new PendingRequest(callback, permissions.size())); | 188 base::MakeUnique<PendingRequest>(callback, permissions.size())); |
186 int id = browser_context->GetPermissionManager()->RequestPermissions( | 189 int id = browser_context->GetPermissionManager()->RequestPermissions( |
187 types, context_->render_frame_host(), origin.GetURL(), user_gesture, | 190 types, context_->render_frame_host(), origin.GetURL(), user_gesture, |
188 base::Bind(&PermissionServiceImpl::OnRequestPermissionsResponse, | 191 base::Bind(&PermissionServiceImpl::OnRequestPermissionsResponse, |
189 weak_factory_.GetWeakPtr(), pending_request_id)); | 192 weak_factory_.GetWeakPtr(), pending_request_id)); |
190 | 193 |
191 // Check if the request still exists. It may have been removed by the | 194 // Check if the request still exists. It may have been removed by the |
192 // the response callback. | 195 // the response callback. |
193 PendingRequest* pending_request = pending_requests_.Lookup( | 196 PendingRequest* pending_request = pending_requests_.Lookup( |
194 pending_request_id); | 197 pending_request_id); |
195 if (!pending_request) | 198 if (!pending_request) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 } | 285 } |
283 | 286 |
284 PermissionType permission_type = | 287 PermissionType permission_type = |
285 PermissionDescriptorToPermissionType(permission); | 288 PermissionDescriptorToPermissionType(permission); |
286 | 289 |
287 // We need to pass the id of PendingSubscription in pending_subscriptions_ | 290 // We need to pass the id of PendingSubscription in pending_subscriptions_ |
288 // to the callback but SubscribePermissionStatusChange() will also return an | 291 // to the callback but SubscribePermissionStatusChange() will also return an |
289 // id which is different. | 292 // id which is different. |
290 PendingSubscription* subscription = | 293 PendingSubscription* subscription = |
291 new PendingSubscription(permission_type, origin, callback); | 294 new PendingSubscription(permission_type, origin, callback); |
292 int pending_subscription_id = pending_subscriptions_.Add(subscription); | 295 int pending_subscription_id = pending_subscriptions_.Add( |
| 296 std::unique_ptr<PendingSubscription>(subscription)); |
293 | 297 |
294 GURL requesting_origin(origin.Serialize()); | 298 GURL requesting_origin(origin.Serialize()); |
295 GURL embedding_origin = context_->GetEmbeddingOrigin(); | 299 GURL embedding_origin = context_->GetEmbeddingOrigin(); |
296 subscription->id = | 300 subscription->id = |
297 browser_context->GetPermissionManager()->SubscribePermissionStatusChange( | 301 browser_context->GetPermissionManager()->SubscribePermissionStatusChange( |
298 permission_type, requesting_origin, | 302 permission_type, requesting_origin, |
299 // If the embedding_origin is empty, we,ll use the |origin| instead. | 303 // If the embedding_origin is empty, we,ll use the |origin| instead. |
300 embedding_origin.is_empty() ? requesting_origin : embedding_origin, | 304 embedding_origin.is_empty() ? requesting_origin : embedding_origin, |
301 base::Bind(&PermissionServiceImpl::OnPermissionStatusChanged, | 305 base::Bind(&PermissionServiceImpl::OnPermissionStatusChanged, |
302 weak_factory_.GetWeakPtr(), pending_subscription_id)); | 306 weak_factory_.GetWeakPtr(), pending_subscription_id)); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 359 |
356 PermissionStatusCallback callback = subscription->callback; | 360 PermissionStatusCallback callback = subscription->callback; |
357 | 361 |
358 subscription->callback.Reset(); | 362 subscription->callback.Reset(); |
359 pending_subscriptions_.Remove(pending_subscription_id); | 363 pending_subscriptions_.Remove(pending_subscription_id); |
360 | 364 |
361 callback.Run(status); | 365 callback.Run(status); |
362 } | 366 } |
363 | 367 |
364 } // namespace content | 368 } // namespace content |
OLD | NEW |