| 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 permission_manager->CancelPermissionRequest(it.GetCurrentValue()->id); | 99 permission_manager->CancelPermissionRequest(it.GetCurrentValue()->id); |
| 100 } | 100 } |
| 101 pending_requests_.Clear(); | 101 pending_requests_.Clear(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void PermissionServiceImpl::RequestPermission( | 104 void PermissionServiceImpl::RequestPermission( |
| 105 PermissionDescriptorPtr permission, | 105 PermissionDescriptorPtr permission, |
| 106 const url::Origin& origin, | 106 const url::Origin& origin, |
| 107 bool user_gesture, | 107 bool user_gesture, |
| 108 const PermissionStatusCallback& callback) { | 108 const PermissionStatusCallback& callback) { |
| 109 // This condition is valid if the call is coming from a ChildThread instead of | 109 std::vector<PermissionDescriptorPtr> permissions; |
| 110 // a RenderFrame. Some consumers of the service run in Workers and some in | 110 permissions.push_back(std::move(permission)); |
| 111 // Frames. In the context of a Worker, it is not possible to show a | 111 RequestPermissions( |
| 112 // permission prompt because there is no tab. In the context of a Frame, we | 112 std::move(permissions), origin, user_gesture, |
| 113 // can. Even if the call comes from a context where it is not possible to show | 113 base::Bind(&PermissionRequestResponseCallbackWrapper, callback)); |
| 114 // any UI, we want to still return something relevant so the current | |
| 115 // permission status is returned. | |
| 116 BrowserContext* browser_context = context_->GetBrowserContext(); | |
| 117 DCHECK(browser_context); | |
| 118 if (!context_->render_frame_host() || | |
| 119 !browser_context->GetPermissionManager()) { | |
| 120 callback.Run(GetPermissionStatus(permission, origin)); | |
| 121 return; | |
| 122 } | |
| 123 | |
| 124 int pending_request_id = | |
| 125 pending_requests_.Add(base::MakeUnique<PendingRequest>( | |
| 126 base::Bind(&PermissionRequestResponseCallbackWrapper, callback), 1)); | |
| 127 int id = browser_context->GetPermissionManager()->RequestPermission( | |
| 128 PermissionDescriptorToPermissionType(permission), | |
| 129 context_->render_frame_host(), origin.GetURL(), user_gesture, | |
| 130 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, | |
| 131 weak_factory_.GetWeakPtr(), 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; | |
| 140 } | |
| 141 | |
| 142 void PermissionServiceImpl::OnRequestPermissionResponse( | |
| 143 int pending_request_id, | |
| 144 PermissionStatus status) { | |
| 145 OnRequestPermissionsResponse(pending_request_id, | |
| 146 std::vector<PermissionStatus>(1, status)); | |
| 147 } | 114 } |
| 148 | 115 |
| 149 void PermissionServiceImpl::RequestPermissions( | 116 void PermissionServiceImpl::RequestPermissions( |
| 150 std::vector<PermissionDescriptorPtr> permissions, | 117 std::vector<PermissionDescriptorPtr> permissions, |
| 151 const url::Origin& origin, | 118 const url::Origin& origin, |
| 152 bool user_gesture, | 119 bool user_gesture, |
| 153 const RequestPermissionsCallback& callback) { | 120 const RequestPermissionsCallback& callback) { |
| 154 // This condition is valid if the call is coming from a ChildThread instead of | 121 // This condition is valid if the call is coming from a ChildThread instead of |
| 155 // a RenderFrame. Some consumers of the service run in Workers and some in | 122 // a RenderFrame. Some consumers of the service run in Workers and some in |
| 156 // Frames. In the context of a Worker, it is not possible to show a | 123 // Frames. In the context of a Worker, it is not possible to show a |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 241 |
| 275 GURL requesting_origin(origin.Serialize()); | 242 GURL requesting_origin(origin.Serialize()); |
| 276 // If the embedding_origin is empty we'll use |origin| instead. | 243 // If the embedding_origin is empty we'll use |origin| instead. |
| 277 GURL embedding_origin = context_->GetEmbeddingOrigin(); | 244 GURL embedding_origin = context_->GetEmbeddingOrigin(); |
| 278 browser_context->GetPermissionManager()->ResetPermission( | 245 browser_context->GetPermissionManager()->ResetPermission( |
| 279 type, requesting_origin, | 246 type, requesting_origin, |
| 280 embedding_origin.is_empty() ? requesting_origin : embedding_origin); | 247 embedding_origin.is_empty() ? requesting_origin : embedding_origin); |
| 281 } | 248 } |
| 282 | 249 |
| 283 } // namespace content | 250 } // namespace content |
| OLD | NEW |