Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(624)

Unified Diff: content/browser/permissions/permission_service_impl.cc

Issue 1260193009: renderer: implement multiple permission requesting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permissions-request-multiple
Patch Set: Rebase on top of other change Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..cc8d7067acef1379a781a0cf10de1145e4d771db 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,73 @@ 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()) {
mlamouri (slow - plz ping) 2015/08/21 10:24:41 When would that happen?
Lalit Maganti 2015/08/21 12:56:00 Compromised renderer process is the only thing I c
+ 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));
+ }
mlamouri (slow - plz ping) 2015/08/21 10:24:41 style: remove { }
Lalit Maganti 2015/08/25 16:58:27 Done.
+ 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;
+ }
mlamouri (slow - plz ping) 2015/08/21 10:24:41 ditto
Lalit Maganti 2015/08/25 16:58:27 Done.
+ 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 +163,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 +186,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();

Powered by Google App Engine
This is Rietveld 408576698