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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 BrowserContext* browser_context = context_->GetBrowserContext(); | 112 BrowserContext* browser_context = context_->GetBrowserContext(); |
113 DCHECK(browser_context); | 113 DCHECK(browser_context); |
114 if (!browser_context->GetPermissionManager()) { | 114 if (!browser_context->GetPermissionManager()) { |
115 callback.Run(content::PERMISSION_STATUS_DENIED); | 115 callback.Run(content::PERMISSION_STATUS_DENIED); |
116 return; | 116 return; |
117 } | 117 } |
118 | 118 |
119 PermissionType permission_type = PermissionNameToPermissionType(permission); | 119 PermissionType permission_type = PermissionNameToPermissionType(permission); |
120 int request_id = pending_requests_.Add( | 120 int request_id = pending_requests_.Add( |
121 new PendingRequest(permission_type, GURL(origin), callback)); | 121 new PendingRequest(permission_type, GURL(origin), callback)); |
122 | 122 int manager_id = browser_context->GetPermissionManager()->RequestPermission( |
123 browser_context->GetPermissionManager()->RequestPermission( | |
124 permission_type, | 123 permission_type, |
125 context_->render_frame_host(), | 124 context_->render_frame_host(), |
126 request_id, | |
127 GURL(origin), | 125 GURL(origin), |
128 user_gesture, // TODO(mlamouri): should be removed (crbug.com/423770) | 126 user_gesture, // TODO(mlamouri): should be removed (crbug.com/423770) |
129 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, | 127 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, |
130 weak_factory_.GetWeakPtr(), | 128 weak_factory_.GetWeakPtr(), |
131 request_id)); | 129 request_id)); |
| 130 |
| 131 // Check if the request still exists. It may have been removed by the |
| 132 // the response callback. |
| 133 PendingRequest* pending_request = pending_requests_.Lookup(request_id); |
| 134 if (!pending_request) |
| 135 return; |
| 136 pending_request->manager_id = manager_id; |
132 } | 137 } |
133 | 138 |
134 void PermissionServiceImpl::RequestPermissions( | 139 void PermissionServiceImpl::RequestPermissions( |
135 mojo::Array<PermissionName> permissions, | 140 mojo::Array<PermissionName> permissions, |
136 const mojo::String& origin, | 141 const mojo::String& origin, |
137 bool user_gesture, | 142 bool user_gesture, |
138 const PermissionsStatusCallback& callback) { | 143 const PermissionsStatusCallback& callback) { |
139 NOTIMPLEMENTED(); | 144 NOTIMPLEMENTED(); |
140 | 145 |
141 // TODO(lalitm,mlamouri): this is returning the current permission statuses | 146 // TODO(lalitm,mlamouri): this is returning the current permission statuses |
(...skipping 21 matching lines...) Expand all Loading... |
163 | 168 |
164 PermissionManager* permission_manager = | 169 PermissionManager* permission_manager = |
165 context_->GetBrowserContext()->GetPermissionManager(); | 170 context_->GetBrowserContext()->GetPermissionManager(); |
166 if (!permission_manager) | 171 if (!permission_manager) |
167 return; | 172 return; |
168 | 173 |
169 // Cancel pending requests. | 174 // Cancel pending requests. |
170 for (RequestsMap::Iterator<PendingRequest> it(&pending_requests_); | 175 for (RequestsMap::Iterator<PendingRequest> it(&pending_requests_); |
171 !it.IsAtEnd(); it.Advance()) { | 176 !it.IsAtEnd(); it.Advance()) { |
172 permission_manager->CancelPermissionRequest( | 177 permission_manager->CancelPermissionRequest( |
173 it.GetCurrentValue()->permission, | |
174 context_->render_frame_host(), | 178 context_->render_frame_host(), |
175 it.GetCurrentKey(), | 179 it.GetCurrentValue()->manager_id); |
176 it.GetCurrentValue()->origin); | |
177 } | 180 } |
178 pending_requests_.Clear(); | 181 pending_requests_.Clear(); |
179 | 182 |
180 // Cancel pending subscriptions. | 183 // Cancel pending subscriptions. |
181 for (SubscriptionsMap::Iterator<PendingSubscription> | 184 for (SubscriptionsMap::Iterator<PendingSubscription> |
182 it(&pending_subscriptions_); !it.IsAtEnd(); it.Advance()) { | 185 it(&pending_subscriptions_); !it.IsAtEnd(); it.Advance()) { |
183 it.GetCurrentValue()->callback.Run(GetPermissionStatusFromType( | 186 it.GetCurrentValue()->callback.Run(GetPermissionStatusFromType( |
184 it.GetCurrentValue()->permission, it.GetCurrentValue()->origin)); | 187 it.GetCurrentValue()->permission, it.GetCurrentValue()->origin)); |
185 it.GetCurrentValue()->callback.reset(); | 188 it.GetCurrentValue()->callback.reset(); |
186 permission_manager->UnsubscribePermissionStatusChange( | 189 permission_manager->UnsubscribePermissionStatusChange( |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 308 |
306 PermissionStatusCallback callback = subscription->callback; | 309 PermissionStatusCallback callback = subscription->callback; |
307 | 310 |
308 subscription->callback.reset(); | 311 subscription->callback.reset(); |
309 pending_subscriptions_.Remove(pending_subscription_id); | 312 pending_subscriptions_.Remove(pending_subscription_id); |
310 | 313 |
311 callback.Run(status); | 314 callback.Run(status); |
312 } | 315 } |
313 | 316 |
314 } // namespace content | 317 } // namespace content |
OLD | NEW |