| 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 "content/public/browser/content_browser_client.h" | 7 #include "content/public/browser/content_browser_client.h" |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 case PERMISSION_NAME_PROTECTED_MEDIA_IDENTIFIER: | 23 case PERMISSION_NAME_PROTECTED_MEDIA_IDENTIFIER: |
| 24 return PERMISSION_PROTECTED_MEDIA_IDENTIFIER; | 24 return PERMISSION_PROTECTED_MEDIA_IDENTIFIER; |
| 25 } | 25 } |
| 26 | 26 |
| 27 NOTREACHED(); | 27 NOTREACHED(); |
| 28 return PERMISSION_NUM; | 28 return PERMISSION_NUM; |
| 29 } | 29 } |
| 30 | 30 |
| 31 } // anonymous namespace | 31 } // anonymous namespace |
| 32 | 32 |
| 33 PermissionServiceImpl::PendingRequest::PendingRequest(PermissionType permission, | 33 PermissionServiceImpl::PendingRequest::PendingRequest( |
| 34 const GURL& origin) | 34 PermissionType permission, |
| 35 const GURL& origin, |
| 36 const mojo::Callback<void(PermissionStatus)>& callback) |
| 35 : permission(permission), | 37 : permission(permission), |
| 36 origin(origin) { | 38 origin(origin), |
| 39 callback(callback) { |
| 40 } |
| 41 |
| 42 PermissionServiceImpl::PendingRequest::~PendingRequest() { |
| 43 if (!callback.is_null()) { |
| 44 callback.Run(PERMISSION_STATUS_ASK); |
| 45 } |
| 37 } | 46 } |
| 38 | 47 |
| 39 PermissionServiceImpl::PermissionServiceImpl(PermissionServiceContext* context) | 48 PermissionServiceImpl::PermissionServiceImpl(PermissionServiceContext* context) |
| 40 : context_(context), | 49 : context_(context), |
| 41 weak_factory_(this) { | 50 weak_factory_(this) { |
| 42 } | 51 } |
| 43 | 52 |
| 44 PermissionServiceImpl::~PermissionServiceImpl() { | 53 PermissionServiceImpl::~PermissionServiceImpl() { |
| 45 } | 54 } |
| 46 | 55 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 63 // permission status is returned. | 72 // permission status is returned. |
| 64 if (!context_->web_contents()) { | 73 if (!context_->web_contents()) { |
| 65 // There is no way to show a UI so the call will simply return the current | 74 // There is no way to show a UI so the call will simply return the current |
| 66 // permission. | 75 // permission. |
| 67 HasPermission(permission, origin, callback); | 76 HasPermission(permission, origin, callback); |
| 68 return; | 77 return; |
| 69 } | 78 } |
| 70 | 79 |
| 71 PermissionType permission_type = PermissionNameToPermissionType(permission); | 80 PermissionType permission_type = PermissionNameToPermissionType(permission); |
| 72 int request_id = pending_requests_.Add( | 81 int request_id = pending_requests_.Add( |
| 73 new PendingRequest(permission_type, GURL(origin))); | 82 new PendingRequest(permission_type, GURL(origin), callback)); |
| 74 | 83 |
| 75 GetContentClient()->browser()->RequestPermission( | 84 GetContentClient()->browser()->RequestPermission( |
| 76 permission_type, | 85 permission_type, |
| 77 context_->web_contents(), | 86 context_->web_contents(), |
| 78 request_id, | 87 request_id, |
| 79 GURL(origin), | 88 GURL(origin), |
| 80 user_gesture, // TODO(mlamouri): should be removed (crbug.com/423770) | 89 user_gesture, // TODO(mlamouri): should be removed (crbug.com/423770) |
| 81 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, | 90 base::Bind(&PermissionServiceImpl::OnRequestPermissionResponse, |
| 82 weak_factory_.GetWeakPtr(), | 91 weak_factory_.GetWeakPtr(), |
| 83 callback, | |
| 84 request_id)); | 92 request_id)); |
| 85 } | 93 } |
| 86 | 94 |
| 87 void PermissionServiceImpl::OnRequestPermissionResponse( | 95 void PermissionServiceImpl::OnRequestPermissionResponse( |
| 88 const mojo::Callback<void(PermissionStatus)>& callback, | |
| 89 int request_id, | 96 int request_id, |
| 90 PermissionStatus status) { | 97 PermissionStatus status) { |
| 98 PendingRequest* request = pending_requests_.Lookup(request_id); |
| 99 mojo::Callback<void(PermissionStatus)> callback(request->callback); |
| 100 request->callback.reset(); |
| 91 pending_requests_.Remove(request_id); | 101 pending_requests_.Remove(request_id); |
| 92 | |
| 93 callback.Run(status); | 102 callback.Run(status); |
| 94 } | 103 } |
| 95 | 104 |
| 96 void PermissionServiceImpl::CancelPendingRequests() { | 105 void PermissionServiceImpl::CancelPendingRequests() { |
| 97 DCHECK(context_->web_contents()); | 106 DCHECK(context_->web_contents()); |
| 98 | 107 |
| 99 for (RequestsMap::Iterator<PendingRequest> it(&pending_requests_); | 108 for (RequestsMap::Iterator<PendingRequest> it(&pending_requests_); |
| 100 !it.IsAtEnd(); it.Advance()) { | 109 !it.IsAtEnd(); it.Advance()) { |
| 101 GetContentClient()->browser()->CancelPermissionRequest( | 110 GetContentClient()->browser()->CancelPermissionRequest( |
| 102 it.GetCurrentValue()->permission, | 111 it.GetCurrentValue()->permission, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 void PermissionServiceImpl::ResetPermissionStatus(PermissionType type, | 159 void PermissionServiceImpl::ResetPermissionStatus(PermissionType type, |
| 151 GURL origin) { | 160 GURL origin) { |
| 152 // If the embedding_origin is empty we'll use |origin| instead. | 161 // If the embedding_origin is empty we'll use |origin| instead. |
| 153 GURL embedding_origin = context_->GetEmbeddingOrigin(); | 162 GURL embedding_origin = context_->GetEmbeddingOrigin(); |
| 154 GetContentClient()->browser()->ResetPermission( | 163 GetContentClient()->browser()->ResetPermission( |
| 155 type, context_->GetBrowserContext(), origin, | 164 type, context_->GetBrowserContext(), origin, |
| 156 embedding_origin.is_empty() ? origin : embedding_origin); | 165 embedding_origin.is_empty() ? origin : embedding_origin); |
| 157 } | 166 } |
| 158 | 167 |
| 159 } // namespace content | 168 } // namespace content |
| OLD | NEW |