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 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 } | 75 } |
76 | 76 |
77 PermissionServiceImpl::PendingRequest::~PendingRequest() { | 77 PermissionServiceImpl::PendingRequest::~PendingRequest() { |
78 if (callback.is_null()) | 78 if (callback.is_null()) |
79 return; | 79 return; |
80 | 80 |
81 std::vector<PermissionStatus> result(request_count, PermissionStatus::DENIED); | 81 std::vector<PermissionStatus> result(request_count, PermissionStatus::DENIED); |
82 callback.Run(result); | 82 callback.Run(result); |
83 } | 83 } |
84 | 84 |
85 PermissionServiceImpl::PermissionServiceImpl( | 85 PermissionServiceImpl::PermissionServiceImpl(PermissionServiceContext* context) |
86 PermissionServiceContext* context, | 86 : context_(context), weak_factory_(this) {} |
87 mojo::InterfaceRequest<blink::mojom::PermissionService> request) | |
88 : context_(context), | |
89 binding_(this, std::move(request)), | |
90 weak_factory_(this) { | |
91 binding_.set_connection_error_handler( | |
92 base::Bind(&PermissionServiceImpl::OnConnectionError, | |
93 base::Unretained(this))); | |
94 } | |
95 | 87 |
96 PermissionServiceImpl::~PermissionServiceImpl() { | 88 PermissionServiceImpl::~PermissionServiceImpl() { |
97 DCHECK(pending_requests_.IsEmpty()); | 89 DCHECK(context_->GetBrowserContext()); |
98 } | |
99 | 90 |
100 void PermissionServiceImpl::OnConnectionError() { | 91 PermissionManager* permission_manager = |
101 CancelPendingOperations(); | 92 context_->GetBrowserContext()->GetPermissionManager(); |
102 context_->ServiceHadConnectionError(this); | 93 if (!permission_manager) |
103 // After that call, |this| will be deleted. | 94 return; |
| 95 |
| 96 // Cancel pending requests. |
| 97 for (RequestsMap::Iterator<PendingRequest> it(&pending_requests_); |
| 98 !it.IsAtEnd(); it.Advance()) { |
| 99 permission_manager->CancelPermissionRequest(it.GetCurrentValue()->id); |
| 100 } |
| 101 pending_requests_.Clear(); |
104 } | 102 } |
105 | 103 |
106 void PermissionServiceImpl::RequestPermission( | 104 void PermissionServiceImpl::RequestPermission( |
107 PermissionDescriptorPtr permission, | 105 PermissionDescriptorPtr permission, |
108 const url::Origin& origin, | 106 const url::Origin& origin, |
109 bool user_gesture, | 107 bool user_gesture, |
110 const PermissionStatusCallback& callback) { | 108 const PermissionStatusCallback& callback) { |
111 // This condition is valid if the call is coming from a ChildThread instead of | 109 // 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 | 110 // 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 | 111 // Frames. In the context of a Worker, it is not possible to show a |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 void PermissionServiceImpl::OnRequestPermissionsResponse( | 192 void PermissionServiceImpl::OnRequestPermissionsResponse( |
195 int pending_request_id, | 193 int pending_request_id, |
196 const std::vector<PermissionStatus>& result) { | 194 const std::vector<PermissionStatus>& result) { |
197 PendingRequest* request = pending_requests_.Lookup(pending_request_id); | 195 PendingRequest* request = pending_requests_.Lookup(pending_request_id); |
198 RequestPermissionsCallback callback(request->callback); | 196 RequestPermissionsCallback callback(request->callback); |
199 request->callback.Reset(); | 197 request->callback.Reset(); |
200 pending_requests_.Remove(pending_request_id); | 198 pending_requests_.Remove(pending_request_id); |
201 callback.Run(result); | 199 callback.Run(result); |
202 } | 200 } |
203 | 201 |
204 void PermissionServiceImpl::CancelPendingOperations() { | |
205 DCHECK(context_->GetBrowserContext()); | |
206 | |
207 PermissionManager* permission_manager = | |
208 context_->GetBrowserContext()->GetPermissionManager(); | |
209 if (!permission_manager) | |
210 return; | |
211 | |
212 // Cancel pending requests. | |
213 for (RequestsMap::Iterator<PendingRequest> it(&pending_requests_); | |
214 !it.IsAtEnd(); it.Advance()) { | |
215 permission_manager->CancelPermissionRequest( | |
216 it.GetCurrentValue()->id); | |
217 } | |
218 pending_requests_.Clear(); | |
219 } | |
220 | |
221 void PermissionServiceImpl::HasPermission( | 202 void PermissionServiceImpl::HasPermission( |
222 PermissionDescriptorPtr permission, | 203 PermissionDescriptorPtr permission, |
223 const url::Origin& origin, | 204 const url::Origin& origin, |
224 const PermissionStatusCallback& callback) { | 205 const PermissionStatusCallback& callback) { |
225 callback.Run(GetPermissionStatus(permission, origin)); | 206 callback.Run(GetPermissionStatus(permission, origin)); |
226 } | 207 } |
227 | 208 |
228 void PermissionServiceImpl::RevokePermission( | 209 void PermissionServiceImpl::RevokePermission( |
229 PermissionDescriptorPtr permission, | 210 PermissionDescriptorPtr permission, |
230 const url::Origin& origin, | 211 const url::Origin& origin, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 274 |
294 GURL requesting_origin(origin.Serialize()); | 275 GURL requesting_origin(origin.Serialize()); |
295 // If the embedding_origin is empty we'll use |origin| instead. | 276 // If the embedding_origin is empty we'll use |origin| instead. |
296 GURL embedding_origin = context_->GetEmbeddingOrigin(); | 277 GURL embedding_origin = context_->GetEmbeddingOrigin(); |
297 browser_context->GetPermissionManager()->ResetPermission( | 278 browser_context->GetPermissionManager()->ResetPermission( |
298 type, requesting_origin, | 279 type, requesting_origin, |
299 embedding_origin.is_empty() ? requesting_origin : embedding_origin); | 280 embedding_origin.is_empty() ? requesting_origin : embedding_origin); |
300 } | 281 } |
301 | 282 |
302 } // namespace content | 283 } // namespace content |
OLD | NEW |