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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
9 #include "content/public/browser/permission_manager.h" | 9 #include "content/public/browser/permission_manager.h" |
10 #include "content/public/browser/permission_type.h" | 10 #include "content/public/browser/permission_type.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 NOTREACHED(); | 38 NOTREACHED(); |
39 return PermissionType::NUM; | 39 return PermissionType::NUM; |
40 } | 40 } |
41 | 41 |
42 } // anonymous namespace | 42 } // anonymous namespace |
43 | 43 |
44 PermissionServiceImpl::PendingRequest::PendingRequest( | 44 PermissionServiceImpl::PendingRequest::PendingRequest( |
45 PermissionType permission, | 45 PermissionType permission, |
46 const GURL& origin, | 46 const GURL& origin, |
47 const PermissionStatusCallback& callback) | 47 const PermissionStatusCallback& callback) |
48 : permission(permission), | 48 : id(PermissionManager::kNoPendingOperation), |
| 49 permission(permission), |
49 origin(origin), | 50 origin(origin), |
50 callback(callback) { | 51 callback(callback) { |
51 } | 52 } |
52 | 53 |
53 PermissionServiceImpl::PendingRequest::~PendingRequest() { | 54 PermissionServiceImpl::PendingRequest::~PendingRequest() { |
54 if (!callback.is_null()) | 55 if (!callback.is_null()) |
55 callback.Run(PERMISSION_STATUS_ASK); | 56 callback.Run(PERMISSION_STATUS_ASK); |
56 } | 57 } |
57 | 58 |
58 PermissionServiceImpl::PendingSubscription::PendingSubscription( | 59 PermissionServiceImpl::PendingSubscription::PendingSubscription( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 111 } |
111 | 112 |
112 BrowserContext* browser_context = context_->GetBrowserContext(); | 113 BrowserContext* browser_context = context_->GetBrowserContext(); |
113 DCHECK(browser_context); | 114 DCHECK(browser_context); |
114 if (!browser_context->GetPermissionManager()) { | 115 if (!browser_context->GetPermissionManager()) { |
115 callback.Run(content::PERMISSION_STATUS_DENIED); | 116 callback.Run(content::PERMISSION_STATUS_DENIED); |
116 return; | 117 return; |
117 } | 118 } |
118 | 119 |
119 PermissionType permission_type = PermissionNameToPermissionType(permission); | 120 PermissionType permission_type = PermissionNameToPermissionType(permission); |
120 int request_id = pending_requests_.Add( | 121 int pending_request_id = pending_requests_.Add( |
121 new PendingRequest(permission_type, GURL(origin), callback)); | 122 new PendingRequest(permission_type, GURL(origin), callback)); |
122 | 123 |
123 browser_context->GetPermissionManager()->RequestPermission( | 124 int id = browser_context->GetPermissionManager()->RequestPermission( |
124 permission_type, | 125 permission_type, |
125 context_->render_frame_host(), | 126 context_->render_frame_host(), |
126 request_id, | |
127 GURL(origin), | 127 GURL(origin), |
128 user_gesture, // TODO(mlamouri): should be removed (crbug.com/423770) | 128 user_gesture, // TODO(mlamouri): should be removed (crbug.com/423770) |
129 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, | 129 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, |
130 weak_factory_.GetWeakPtr(), | 130 weak_factory_.GetWeakPtr(), |
131 request_id)); | 131 pending_request_id)); |
| 132 |
| 133 // Check if the request still exists. It might have been removed by the |
| 134 // callback if it was run synchronously. |
| 135 PendingRequest* pending_request = pending_requests_.Lookup( |
| 136 pending_request_id); |
| 137 if (!pending_request) |
| 138 return; |
| 139 pending_request->id = id; |
132 } | 140 } |
133 | 141 |
134 void PermissionServiceImpl::RequestPermissions( | 142 void PermissionServiceImpl::RequestPermissions( |
135 mojo::Array<PermissionName> permissions, | 143 mojo::Array<PermissionName> permissions, |
136 const mojo::String& origin, | 144 const mojo::String& origin, |
137 bool user_gesture, | 145 bool user_gesture, |
138 const PermissionsStatusCallback& callback) { | 146 const PermissionsStatusCallback& callback) { |
139 // TODO(lalitm,mlamouri): this is returning the current permission statuses | 147 // TODO(lalitm,mlamouri): this is returning the current permission statuses |
140 // in order for the call to successfully return. It will be changed later. | 148 // in order for the call to successfully return. It will be changed later. |
141 // See https://crbug.com/516626 | 149 // See https://crbug.com/516626 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 311 |
304 PermissionStatusCallback callback = subscription->callback; | 312 PermissionStatusCallback callback = subscription->callback; |
305 | 313 |
306 subscription->callback.reset(); | 314 subscription->callback.reset(); |
307 pending_subscriptions_.Remove(pending_subscription_id); | 315 pending_subscriptions_.Remove(pending_subscription_id); |
308 | 316 |
309 callback.Run(status); | 317 callback.Run(status); |
310 } | 318 } |
311 | 319 |
312 } // namespace content | 320 } // namespace content |
OLD | NEW |