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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // a RenderFrame. Some consumers of the service run in Workers and some in | 115 // a RenderFrame. Some consumers of the service run in Workers and some in |
116 // Frames. In the context of a Worker, it is not possible to show a | 116 // Frames. In the context of a Worker, it is not possible to show a |
117 // permission prompt because there is no tab. In the context of a Frame, we | 117 // permission prompt because there is no tab. In the context of a Frame, we |
118 // can. Even if the call comes from a context where it is not possible to show | 118 // can. Even if the call comes from a context where it is not possible to show |
119 // any UI, we want to still return something relevant so the current | 119 // any UI, we want to still return something relevant so the current |
120 // permission status is returned. | 120 // permission status is returned. |
121 BrowserContext* browser_context = context_->GetBrowserContext(); | 121 BrowserContext* browser_context = context_->GetBrowserContext(); |
122 DCHECK(browser_context); | 122 DCHECK(browser_context); |
123 if (!context_->render_frame_host() || | 123 if (!context_->render_frame_host() || |
124 !browser_context->GetPermissionManager()) { | 124 !browser_context->GetPermissionManager()) { |
125 callback.Run(GetPermissionStatusFromName(permission, GURL(origin))); | 125 callback.Run(GetPermissionStatusFromName(permission, GURL(origin.get()))); |
126 return; | 126 return; |
127 } | 127 } |
128 | 128 |
129 int pending_request_id = pending_requests_.Add(new PendingRequest( | 129 int pending_request_id = pending_requests_.Add(new PendingRequest( |
130 base::Bind(&PermissionRequestResponseCallbackWrapper, callback), 1)); | 130 base::Bind(&PermissionRequestResponseCallbackWrapper, callback), 1)); |
131 int id = browser_context->GetPermissionManager()->RequestPermission( | 131 int id = browser_context->GetPermissionManager()->RequestPermission( |
132 PermissionNameToPermissionType(permission), | 132 PermissionNameToPermissionType(permission), |
133 context_->render_frame_host(), | 133 context_->render_frame_host(), |
134 GURL(origin), | 134 GURL(origin.get()), |
135 user_gesture, // TODO(mlamouri): should be removed (crbug.com/423770) | 135 user_gesture, // TODO(mlamouri): should be removed (crbug.com/423770) |
136 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, | 136 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, |
137 weak_factory_.GetWeakPtr(), | 137 weak_factory_.GetWeakPtr(), |
138 pending_request_id)); | 138 pending_request_id)); |
139 | 139 |
140 // Check if the request still exists. It might have been removed by the | 140 // Check if the request still exists. It might have been removed by the |
141 // callback if it was run synchronously. | 141 // callback if it was run synchronously. |
142 PendingRequest* pending_request = pending_requests_.Lookup( | 142 PendingRequest* pending_request = pending_requests_.Lookup( |
143 pending_request_id); | 143 pending_request_id); |
144 if (!pending_request) | 144 if (!pending_request) |
(...skipping 23 matching lines...) Expand all Loading... |
168 // Frames. In the context of a Worker, it is not possible to show a | 168 // Frames. In the context of a Worker, it is not possible to show a |
169 // permission prompt because there is no tab. In the context of a Frame, we | 169 // permission prompt because there is no tab. In the context of a Frame, we |
170 // can. Even if the call comes from a context where it is not possible to show | 170 // can. Even if the call comes from a context where it is not possible to show |
171 // any UI, we want to still return something relevant so the current | 171 // any UI, we want to still return something relevant so the current |
172 // permission status is returned for each permission. | 172 // permission status is returned for each permission. |
173 BrowserContext* browser_context = context_->GetBrowserContext(); | 173 BrowserContext* browser_context = context_->GetBrowserContext(); |
174 DCHECK(browser_context); | 174 DCHECK(browser_context); |
175 if (!context_->render_frame_host() || | 175 if (!context_->render_frame_host() || |
176 !browser_context->GetPermissionManager()) { | 176 !browser_context->GetPermissionManager()) { |
177 mojo::Array<PermissionStatus> result(permissions.size()); | 177 mojo::Array<PermissionStatus> result(permissions.size()); |
178 for (size_t i = 0; i < permissions.size(); ++i) | 178 for (size_t i = 0; i < permissions.size(); ++i) { |
179 result[i] = GetPermissionStatusFromName(permissions[i], GURL(origin)); | 179 result[i] = |
| 180 GetPermissionStatusFromName(permissions[i], GURL(origin.get())); |
| 181 } |
180 callback.Run(std::move(result)); | 182 callback.Run(std::move(result)); |
181 return; | 183 return; |
182 } | 184 } |
183 | 185 |
184 std::vector<PermissionType> types(permissions.size()); | 186 std::vector<PermissionType> types(permissions.size()); |
185 for (size_t i = 0; i < types.size(); ++i) | 187 for (size_t i = 0; i < types.size(); ++i) |
186 types[i] = PermissionNameToPermissionType(permissions[i]); | 188 types[i] = PermissionNameToPermissionType(permissions[i]); |
187 | 189 |
188 int pending_request_id = pending_requests_.Add( | 190 int pending_request_id = pending_requests_.Add( |
189 new PendingRequest(callback, permissions.size())); | 191 new PendingRequest(callback, permissions.size())); |
190 int id = browser_context->GetPermissionManager()->RequestPermissions( | 192 int id = browser_context->GetPermissionManager()->RequestPermissions( |
191 types, | 193 types, |
192 context_->render_frame_host(), | 194 context_->render_frame_host(), |
193 GURL(origin), | 195 GURL(origin.get()), |
194 user_gesture, // TODO(mlamouri): should be removed (crbug.com/423770) | 196 user_gesture, // TODO(mlamouri): should be removed (crbug.com/423770) |
195 base::Bind(&PermissionServiceImpl::OnRequestPermissionsResponse, | 197 base::Bind(&PermissionServiceImpl::OnRequestPermissionsResponse, |
196 weak_factory_.GetWeakPtr(), | 198 weak_factory_.GetWeakPtr(), |
197 pending_request_id)); | 199 pending_request_id)); |
198 | 200 |
199 // Check if the request still exists. It may have been removed by the | 201 // Check if the request still exists. It may have been removed by the |
200 // the response callback. | 202 // the response callback. |
201 PendingRequest* pending_request = pending_requests_.Lookup( | 203 PendingRequest* pending_request = pending_requests_.Lookup( |
202 pending_request_id); | 204 pending_request_id); |
203 if (!pending_request) | 205 if (!pending_request) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 permission_manager->UnsubscribePermissionStatusChange( | 242 permission_manager->UnsubscribePermissionStatusChange( |
241 it.GetCurrentValue()->id); | 243 it.GetCurrentValue()->id); |
242 } | 244 } |
243 pending_subscriptions_.Clear(); | 245 pending_subscriptions_.Clear(); |
244 } | 246 } |
245 | 247 |
246 void PermissionServiceImpl::HasPermission( | 248 void PermissionServiceImpl::HasPermission( |
247 PermissionName permission, | 249 PermissionName permission, |
248 const mojo::String& origin, | 250 const mojo::String& origin, |
249 const PermissionStatusCallback& callback) { | 251 const PermissionStatusCallback& callback) { |
250 callback.Run(GetPermissionStatusFromName(permission, GURL(origin))); | 252 callback.Run(GetPermissionStatusFromName(permission, GURL(origin.get()))); |
251 } | 253 } |
252 | 254 |
253 void PermissionServiceImpl::RevokePermission( | 255 void PermissionServiceImpl::RevokePermission( |
254 PermissionName permission, | 256 PermissionName permission, |
255 const mojo::String& origin, | 257 const mojo::String& origin, |
256 const PermissionStatusCallback& callback) { | 258 const PermissionStatusCallback& callback) { |
257 GURL origin_url(origin); | 259 GURL origin_url(origin.get()); |
258 PermissionType permission_type = PermissionNameToPermissionType(permission); | 260 PermissionType permission_type = PermissionNameToPermissionType(permission); |
259 PermissionStatus status = GetPermissionStatusFromType(permission_type, | 261 PermissionStatus status = GetPermissionStatusFromType(permission_type, |
260 origin_url); | 262 origin_url); |
261 | 263 |
262 // Resetting the permission should only be possible if the permission is | 264 // Resetting the permission should only be possible if the permission is |
263 // already granted. | 265 // already granted. |
264 if (status != PERMISSION_STATUS_GRANTED) { | 266 if (status != PERMISSION_STATUS_GRANTED) { |
265 callback.Run(status); | 267 callback.Run(status); |
266 return; | 268 return; |
267 } | 269 } |
268 | 270 |
269 ResetPermissionStatus(permission_type, origin_url); | 271 ResetPermissionStatus(permission_type, origin_url); |
270 | 272 |
271 callback.Run(GetPermissionStatusFromType(permission_type, origin_url)); | 273 callback.Run(GetPermissionStatusFromType(permission_type, origin_url)); |
272 } | 274 } |
273 | 275 |
274 void PermissionServiceImpl::GetNextPermissionChange( | 276 void PermissionServiceImpl::GetNextPermissionChange( |
275 PermissionName permission, | 277 PermissionName permission, |
276 const mojo::String& mojo_origin, | 278 const mojo::String& mojo_origin, |
277 PermissionStatus last_known_status, | 279 PermissionStatus last_known_status, |
278 const PermissionStatusCallback& callback) { | 280 const PermissionStatusCallback& callback) { |
279 GURL origin(mojo_origin); | 281 GURL origin(mojo_origin.get()); |
280 PermissionStatus current_status = | 282 PermissionStatus current_status = |
281 GetPermissionStatusFromName(permission, origin); | 283 GetPermissionStatusFromName(permission, origin); |
282 if (current_status != last_known_status) { | 284 if (current_status != last_known_status) { |
283 callback.Run(current_status); | 285 callback.Run(current_status); |
284 return; | 286 return; |
285 } | 287 } |
286 | 288 |
287 BrowserContext* browser_context = context_->GetBrowserContext(); | 289 BrowserContext* browser_context = context_->GetBrowserContext(); |
288 DCHECK(browser_context); | 290 DCHECK(browser_context); |
289 if (!browser_context->GetPermissionManager()) { | 291 if (!browser_context->GetPermissionManager()) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 361 |
360 PermissionStatusCallback callback = subscription->callback; | 362 PermissionStatusCallback callback = subscription->callback; |
361 | 363 |
362 subscription->callback.reset(); | 364 subscription->callback.reset(); |
363 pending_subscriptions_.Remove(pending_subscription_id); | 365 pending_subscriptions_.Remove(pending_subscription_id); |
364 | 366 |
365 callback.Run(status); | 367 callback.Run(status); |
366 } | 368 } |
367 | 369 |
368 } // namespace content | 370 } // namespace content |
OLD | NEW |