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

Unified Diff: content/child/permissions/permission_dispatcher.cc

Issue 1260193009: renderer: implement multiple permission requesting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permissions-request-multiple
Patch Set: Merge patches 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/child/permissions/permission_dispatcher.cc
diff --git a/content/child/permissions/permission_dispatcher.cc b/content/child/permissions/permission_dispatcher.cc
index 4fa87ebb30c53c11381c95c935286ddd670f5016..40054a7bc17ec44121341d3b13aab888f4261c77 100644
--- a/content/child/permissions/permission_dispatcher.cc
+++ b/content/child/permissions/permission_dispatcher.cc
@@ -99,6 +99,32 @@ PermissionDispatcher::CallbackInformation::ReleaseCallback() {
PermissionDispatcher::CallbackInformation::~CallbackInformation() {
}
+PermissionDispatcher::MultipleCallbackInformation::MultipleCallbackInformation(
Lalit Maganti (personal) 2015/08/03 23:10:26 Consider merging this with the Callback informatio
+ blink::WebPermissionsCallback* callback,
+ int worker_thread_id)
+ : callback_(callback),
+ worker_thread_id_(worker_thread_id) {
+}
+
+blink::WebPermissionsCallback*
+PermissionDispatcher::MultipleCallbackInformation::callback() const {
+ return callback_.get();
+}
+
+int
+PermissionDispatcher::MultipleCallbackInformation::worker_thread_id() const {
+ return worker_thread_id_;
+}
+
+blink::WebPermissionsCallback*
+PermissionDispatcher::MultipleCallbackInformation::ReleaseCallback() {
+ return callback_.release();
+}
+
+PermissionDispatcher::
+MultipleCallbackInformation::~MultipleCallbackInformation() {
+}
+
PermissionDispatcher::PermissionDispatcher(ServiceRegistry* service_registry)
: service_registry_(service_registry) {
}
@@ -122,6 +148,14 @@ void PermissionDispatcher::requestPermission(
type, origin.string().utf8(), callback, kNoWorkerThread);
}
+void PermissionDispatcher::requestPermissions(
+ const blink::WebVector<blink::WebPermissionType>& types,
+ const blink::WebURL& origin,
+ blink::WebPermissionsCallback* callback) {
+ RequestPermissionsInternal(
+ types, origin.string().utf8(), callback, kNoWorkerThread);
+}
+
void PermissionDispatcher::revokePermission(
blink::WebPermissionType type,
const blink::WebURL& origin,
@@ -171,6 +205,14 @@ void PermissionDispatcher::RequestPermissionForWorker(
RequestPermissionInternal(type, origin, callback, worker_thread_id);
}
+void PermissionDispatcher::RequestPermissionsForWorker(
+ const blink::WebVector<blink::WebPermissionType>& types,
+ const std::string& origin,
+ blink::WebPermissionsCallback* callback,
+ int worker_thread_id) {
+ RequestPermissionsInternal(types, origin, callback, worker_thread_id);
+}
+
void PermissionDispatcher::RevokePermissionForWorker(
blink::WebPermissionType type,
const std::string& origin,
@@ -222,6 +264,13 @@ void PermissionDispatcher::RunCallbackOnWorkerThread(
delete callback;
}
+void PermissionDispatcher::RunMultiCallbackOnWorkerThread(
Lalit Maganti (personal) 2015/08/03 23:10:26 Template method?
+ blink::WebPermissionsCallback* callback,
+ scoped_ptr<blink::WebVector<blink::WebPermissionStatus>> statuses) {
+ callback->onSuccess(statuses.release());
+ delete callback;
+}
+
PermissionServicePtr& PermissionDispatcher::GetPermissionServicePtr() {
if (!permission_service_.get()) {
service_registry_->ConnectToRemoteService(
@@ -269,6 +318,32 @@ void PermissionDispatcher::RequestPermissionInternal(
request_id));
}
+void PermissionDispatcher::RequestPermissionsInternal(
+ const blink::WebVector<blink::WebPermissionType>& types,
+ const std::string& origin,
+ blink::WebPermissionsCallback* callback,
+ int worker_thread_id) {
+ // We need to save the |callback| in an IDMap so if |this| gets deleted, the
+ // callback will not leak. In the case of |this| gets deleted, the
+ // |permission_service_| pipe will be destroyed too so OnQueryPermission will
+ // not be called.
+ int request_id = multiple_pending_callbacks_.Add(
+ new MultipleCallbackInformation(callback, worker_thread_id));
+
+ mojo::Array<PermissionName> names(types.size());
+ for (size_t i = 0; i < types.size(); ++i) {
+ names[i] = GetPermissionName(types[i]);
+ }
+
+ GetPermissionServicePtr()->RequestPermissions(
+ names.Pass(),
+ origin,
+ blink::WebUserGestureIndicator::isProcessingUserGesture(),
+ base::Bind(&PermissionDispatcher::OnPermissionsResponse,
+ base::Unretained(this),
+ request_id));
+}
+
void PermissionDispatcher::RevokePermissionInternal(
blink::WebPermissionType type,
const std::string& origin,
@@ -316,6 +391,39 @@ void PermissionDispatcher::OnPermissionResponse(int request_id,
pending_callbacks_.Remove(request_id);
}
+void PermissionDispatcher::OnPermissionsResponse(
+ int request_id,
+ const mojo::Array<PermissionStatus>& result) {
+ MultipleCallbackInformation* callback_information =
+ multiple_pending_callbacks_.Lookup(request_id);
+ DCHECK(callback_information && callback_information->callback());
+
+ scoped_ptr<blink::WebVector<blink::WebPermissionStatus>> status(
+ new blink::WebVector<blink::WebPermissionStatus>(result.size()));
+ for (size_t i = 0; i < result.size(); i++) {
+ (*status)[i] = GetWebPermissionStatus(result[i]);
+ }
+
+ if (callback_information->worker_thread_id() != kNoWorkerThread) {
+ blink::WebPermissionsCallback* callback =
+ callback_information->ReleaseCallback();
+ int worker_thread_id = callback_information->worker_thread_id();
+ multiple_pending_callbacks_.Remove(request_id);
+
+ // If the worker is no longer running, ::PostTask() will return false and
+ // gracefully fail, destroying the callback too.
+ WorkerTaskRunner::Instance()->PostTask(
+ worker_thread_id,
+ base::Bind(&PermissionDispatcher::RunMultiCallbackOnWorkerThread,
+ base::Unretained(callback),
+ base::Passed(&status)));
+ return;
+ }
+
+ callback_information->callback()->onSuccess(status.release());
+ multiple_pending_callbacks_.Remove(request_id);
+}
+
void PermissionDispatcher::OnPermissionChanged(
blink::WebPermissionType type,
const std::string& origin,

Powered by Google App Engine
This is Rietveld 408576698