Index: content/browser/permissions/permission_service_impl.cc |
diff --git a/content/browser/permissions/permission_service_impl.cc b/content/browser/permissions/permission_service_impl.cc |
index 61ca3a1517a698c37fdf331778d2a849855ca342..d65311a7d3b1c828bb8bb863566dbd996ca3a01d 100644 |
--- a/content/browser/permissions/permission_service_impl.cc |
+++ b/content/browser/permissions/permission_service_impl.cc |
@@ -5,6 +5,7 @@ |
#include "content/browser/permissions/permission_service_impl.h" |
#include "base/bind.h" |
+#include "content/browser/permissions/permission_pending_request.h" |
#include "content/public/browser/browser_context.h" |
#include "content/public/browser/permission_manager.h" |
#include "content/public/browser/permission_type.h" |
@@ -35,21 +36,14 @@ PermissionType PermissionNameToPermissionType(PermissionName name) { |
return PermissionType::NUM; |
} |
-} // anonymous namespace |
- |
-PermissionServiceImpl::PendingRequest::PendingRequest( |
- PermissionType permission, |
- const GURL& origin, |
- const PermissionStatusCallback& callback) |
- : permission(permission), |
- origin(origin), |
- callback(callback) { |
+void PermissionRequestResponseCallbackWrapper( |
+ const mojo::Callback<void(PermissionStatus)>& callback, |
+ const mojo::Array<PermissionStatus>& vector) { |
+ DCHECK(vector.size() == 1); |
+ callback.Run(vector[0]); |
} |
-PermissionServiceImpl::PendingRequest::~PendingRequest() { |
- if (!callback.is_null()) |
- callback.Run(PERMISSION_STATUS_ASK); |
-} |
+} // anonymous namespace |
PermissionServiceImpl::PendingSubscription::PendingSubscription( |
PermissionType permission, |
@@ -91,33 +85,71 @@ void PermissionServiceImpl::RequestPermission( |
const mojo::String& origin, |
bool user_gesture, |
const PermissionStatusCallback& callback) { |
+ mojo::Array<PermissionName> permissions = mojo::Array<PermissionName>::New(1); |
+ permissions[0] = permission; |
+ |
+ RequestPermissionInternal( |
+ permissions.Pass(), |
+ origin, |
+ user_gesture, |
+ base::Bind(&PermissionRequestResponseCallbackWrapper, |
+ callback)); |
+} |
+ |
+void PermissionServiceImpl::RequestBatchPermission( |
+ mojo::Array<PermissionName> permissions, |
+ const mojo::String& origin, |
+ bool user_gesture, |
+ const BatchPermissionStatusCallback& callback) { |
+ RequestPermissionInternal(permissions.Pass(), origin, user_gesture, callback); |
+} |
+ |
+void PermissionServiceImpl::RequestPermissionInternal( |
+ mojo::Array<PermissionName> permissions, |
+ const mojo::String& origin, |
+ bool user_gesture, |
+ const BatchPermissionStatusCallback& callback) { |
+ if (permissions.is_null()) { |
+ callback.Run(mojo::Array<PermissionStatus>()); |
+ return; |
+ } |
+ |
// This condition is valid if the call is coming from a ChildThread instead of |
// a RenderFrame. Some consumers of the service run in Workers and some in |
// Frames. In the context of a Worker, it is not possible to show a |
// permission prompt because there is no tab. In the context of a Frame, we |
// can. Even if the call comes from a context where it is not possible to show |
// any UI, we want to still return something relevant so the current |
- // permission status is returned. |
+ // permission status is returned for each permission. |
if (!context_->render_frame_host()) { |
- // There is no way to show a UI so the call will simply return the current |
- // permission. |
- HasPermission(permission, origin, callback); |
+ mojo::Array<PermissionStatus> result(permissions.size()); |
+ for (size_t i = 0; i < permissions.size(); ++i) |
+ result[i] = GetPermissionStatusFromName(permissions[i], GURL(origin)); |
+ callback.Run(result.Pass()); |
return; |
} |
BrowserContext* browser_context = context_->GetBrowserContext(); |
DCHECK(browser_context); |
if (!browser_context->GetPermissionManager()) { |
- callback.Run(content::PERMISSION_STATUS_DENIED); |
+ mojo::Array<PermissionStatus> result(permissions.size()); |
+ for (size_t i = 0; i < permissions.size(); ++i) |
+ result[i] = PERMISSION_STATUS_DENIED; |
+ callback.Run(result.Pass()); |
return; |
} |
- PermissionType permission_type = PermissionNameToPermissionType(permission); |
+ std::vector<PermissionType> permission_types; |
+ permission_types.reserve(permissions.size()); |
+ for (size_t i = 0; i < permissions.size(); ++i) { |
+ permission_types.push_back( |
+ PermissionNameToPermissionType(permissions[i])); |
+ } |
int request_id = pending_requests_.Add( |
- new PendingRequest(permission_type, GURL(origin), callback)); |
+ new PermissionPendingRequest(callback, permissions.size())); |
browser_context->GetPermissionManager()->RequestPermission( |
- permission_type, |
+ permission_types, |
context_->render_frame_host(), |
request_id, |
GURL(origin), |
@@ -129,12 +161,17 @@ void PermissionServiceImpl::RequestPermission( |
void PermissionServiceImpl::OnRequestPermissionResponse( |
int request_id, |
- PermissionStatus status) { |
- PendingRequest* request = pending_requests_.Lookup(request_id); |
- PermissionStatusCallback callback(request->callback); |
- request->callback.reset(); |
+ const std::vector<PermissionStatus>& status) { |
+ PermissionPendingRequest* request = pending_requests_.Lookup(request_id); |
+ BatchPermissionStatusCallback callback(request->callback()); |
+ |
+ request->callback().reset(); |
pending_requests_.Remove(request_id); |
- callback.Run(status); |
+ |
+ mojo::Array<PermissionStatus> status_array(status.size()); |
+ for (size_t i = 0; i < status.size(); i++) |
+ status_array[i] = status[i]; |
+ callback.Run(status_array.Pass()); |
} |
void PermissionServiceImpl::CancelPendingOperations() { |
@@ -147,13 +184,10 @@ void PermissionServiceImpl::CancelPendingOperations() { |
return; |
// Cancel pending requests. |
- for (RequestsMap::Iterator<PendingRequest> it(&pending_requests_); |
+ for (RequestsMap::Iterator<PermissionPendingRequest> it(&pending_requests_); |
!it.IsAtEnd(); it.Advance()) { |
- permission_manager->CancelPermissionRequest( |
- it.GetCurrentValue()->permission, |
- context_->render_frame_host(), |
- it.GetCurrentKey(), |
- it.GetCurrentValue()->origin); |
+ permission_manager->CancelPermissionRequest(context_->render_frame_host(), |
+ it.GetCurrentKey()); |
} |
pending_requests_.Clear(); |