| 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/browser/permissions/permission_service_context.h" |
| 8 #include "content/public/browser/browser_context.h" | 9 #include "content/public/browser/browser_context.h" |
| 9 #include "content/public/browser/permission_manager.h" | 10 #include "content/public/browser/permission_manager.h" |
| 10 #include "content/public/browser/permission_type.h" | 11 #include "content/public/browser/permission_type.h" |
| 11 | 12 |
| 12 namespace content { | 13 namespace content { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 PermissionType PermissionNameToPermissionType(PermissionName name) { | 17 PermissionType PermissionNameToPermissionType(PermissionName name) { |
| 17 switch(name) { | 18 switch(name) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 permission(permission), | 77 permission(permission), |
| 77 origin(origin), | 78 origin(origin), |
| 78 callback(callback) { | 79 callback(callback) { |
| 79 } | 80 } |
| 80 | 81 |
| 81 PermissionServiceImpl::PendingSubscription::~PendingSubscription() { | 82 PermissionServiceImpl::PendingSubscription::~PendingSubscription() { |
| 82 if (!callback.is_null()) | 83 if (!callback.is_null()) |
| 83 callback.Run(PERMISSION_STATUS_ASK); | 84 callback.Run(PERMISSION_STATUS_ASK); |
| 84 } | 85 } |
| 85 | 86 |
| 86 PermissionServiceImpl::PermissionServiceImpl( | 87 PermissionServiceImpl::PermissionServiceImpl(PermissionServiceContext* context) |
| 87 PermissionServiceContext* context, | 88 : context_(context), weak_factory_(this) { |
| 88 mojo::InterfaceRequest<PermissionService> request) | |
| 89 : context_(context), | |
| 90 binding_(this, request.Pass()), | |
| 91 weak_factory_(this) { | |
| 92 binding_.set_connection_error_handler( | |
| 93 base::Bind(&PermissionServiceImpl::OnConnectionError, | |
| 94 base::Unretained(this))); | |
| 95 } | 89 } |
| 96 | 90 |
| 97 PermissionServiceImpl::~PermissionServiceImpl() { | 91 PermissionServiceImpl::~PermissionServiceImpl() { |
| 98 DCHECK(pending_requests_.IsEmpty()); | 92 DCHECK(pending_requests_.IsEmpty()); |
| 99 } | 93 } |
| 100 | 94 |
| 101 void PermissionServiceImpl::OnConnectionError() { | |
| 102 context_->ServiceHadConnectionError(this); | |
| 103 // After that call, |this| will be deleted. | |
| 104 } | |
| 105 | |
| 106 void PermissionServiceImpl::RequestPermission( | 95 void PermissionServiceImpl::RequestPermission( |
| 107 PermissionName permission, | 96 PermissionName permission, |
| 108 const mojo::String& origin, | 97 const mojo::String& origin, |
| 109 bool user_gesture, | 98 bool user_gesture, |
| 110 const PermissionStatusCallback& callback) { | 99 const PermissionStatusCallback& callback) { |
| 111 // This condition is valid if the call is coming from a ChildThread instead of | 100 // This condition is valid if the call is coming from a ChildThread instead of |
| 112 // a RenderFrame. Some consumers of the service run in Workers and some in | 101 // a RenderFrame. Some consumers of the service run in Workers and some in |
| 113 // Frames. In the context of a Worker, it is not possible to show a | 102 // Frames. In the context of a Worker, it is not possible to show a |
| 114 // permission prompt because there is no tab. In the context of a Frame, we | 103 // permission prompt because there is no tab. In the context of a Frame, we |
| 115 // can. Even if the call comes from a context where it is not possible to show | 104 // can. Even if the call comes from a context where it is not possible to show |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 345 |
| 357 PermissionStatusCallback callback = subscription->callback; | 346 PermissionStatusCallback callback = subscription->callback; |
| 358 | 347 |
| 359 subscription->callback.reset(); | 348 subscription->callback.reset(); |
| 360 pending_subscriptions_.Remove(pending_subscription_id); | 349 pending_subscriptions_.Remove(pending_subscription_id); |
| 361 | 350 |
| 362 callback.Run(status); | 351 callback.Run(status); |
| 363 } | 352 } |
| 364 | 353 |
| 365 } // namespace content | 354 } // namespace content |
| OLD | NEW |