Index: content/child/permissions/permission_dispatcher.cc |
diff --git a/content/child/permissions/permission_dispatcher.cc b/content/child/permissions/permission_dispatcher.cc |
index a0ba93912f6df0729c2a71101be0c8dc65e764cb..2d15691c727bf169274030e8e0dbe152d82d2192 100644 |
--- a/content/child/permissions/permission_dispatcher.cc |
+++ b/content/child/permissions/permission_dispatcher.cc |
@@ -102,6 +102,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, |
@@ -151,6 +159,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, |
@@ -202,6 +218,13 @@ void PermissionDispatcher::RunCallbackOnWorkerThread( |
delete callback; |
} |
+void PermissionDispatcher::RunMultiCallbackOnWorkerThread( |
+ blink::WebPermissionsCallback* callback, |
+ scoped_ptr<blink::WebVector<blink::WebPermissionStatus>> statuses) { |
+ callback->onSuccess(blink::adoptWebPtr(statuses.release())); |
+ delete callback; |
+} |
+ |
PermissionServicePtr& PermissionDispatcher::GetPermissionServicePtr() { |
if (!permission_service_.get()) { |
service_registry_->ConnectToRemoteService( |
@@ -221,7 +244,6 @@ void PermissionDispatcher::QueryPermissionInternal( |
// will not be called. |
PendingCallbackVector::iterator iterator = |
pending_callbacks_.insert(pending_callbacks_.end(), callback); |
- |
mlamouri (slow - plz ping)
2015/08/21 10:24:41
nit: revert that change
Lalit Maganti
2015/08/25 16:58:27
Done.
|
GetPermissionServicePtr()->HasPermission( |
GetPermissionName(type), |
origin, |
@@ -242,7 +264,6 @@ void PermissionDispatcher::RequestPermissionInternal( |
// will not be called. |
PendingCallbackVector::iterator iterator = |
pending_callbacks_.insert(pending_callbacks_.end(), callback); |
- |
mlamouri (slow - plz ping)
2015/08/21 10:24:41
ditto
Lalit Maganti
2015/08/25 16:58:27
Done.
|
GetPermissionServicePtr()->RequestPermission( |
GetPermissionName(type), |
origin, |
@@ -253,6 +274,32 @@ void PermissionDispatcher::RequestPermissionInternal( |
iterator)); |
} |
+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 ScopedVector 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. |
+ PendingBatchCallbackVector::iterator iterator = |
+ batch_pending_callbacks_.insert(batch_pending_callbacks_.end(), callback); |
mlamouri (slow - plz ping)
2015/08/21 10:24:41
I guess this needs to be rebased.
Lalit Maganti
2015/08/25 16:58:27
Done.
|
+ |
+ mojo::Array<PermissionName> names(types.size()); |
+ for (size_t i = 0; i < types.size(); ++i) |
+ names[i] = GetPermissionName(types[i]); |
+ |
+ GetPermissionServicePtr()->RequestBatchPermission( |
+ names.Pass(), |
+ origin, |
+ blink::WebUserGestureIndicator::isProcessingUserGesture(), |
+ base::Bind(&PermissionDispatcher::OnPermissionsResponse, |
+ base::Unretained(this), |
+ worker_thread_id, |
+ iterator)); |
+} |
+ |
void PermissionDispatcher::RevokePermissionInternal( |
blink::WebPermissionType type, |
const std::string& origin, |
@@ -264,7 +311,6 @@ void PermissionDispatcher::RevokePermissionInternal( |
// will not be called. |
PendingCallbackVector::iterator iterator = |
pending_callbacks_.insert(pending_callbacks_.end(), callback); |
- |
GetPermissionServicePtr()->RevokePermission( |
GetPermissionName(type), |
origin, |
@@ -299,6 +345,34 @@ void PermissionDispatcher::OnPermissionResponse( |
pending_callbacks_.erase(callback_iterator); |
} |
+void PermissionDispatcher::OnPermissionsResponse( |
+ int worker_thread_id, |
+ PendingBatchCallbackVector::iterator callback_iterator, |
+ const mojo::Array<PermissionStatus>& result) { |
+ blink::WebPermissionsCallback* callback = *callback_iterator; |
+ scoped_ptr<blink::WebVector<blink::WebPermissionStatus>> statuses( |
+ new blink::WebVector<blink::WebPermissionStatus>(result.size())); |
+ |
+ for (size_t i = 0; i < result.size(); i++) |
+ statuses->operator[](i) = GetWebPermissionStatus(result[i]); |
+ |
+ if (worker_thread_id != kNoWorkerThread) { |
+ batch_pending_callbacks_.weak_erase(callback_iterator); |
+ |
+ // 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(&statuses))); |
+ return; |
+ } |
+ |
+ callback->onSuccess(blink::adoptWebPtr(statuses.release())); |
+ batch_pending_callbacks_.erase(callback_iterator); |
+} |
+ |
void PermissionDispatcher::OnPermissionChanged( |
blink::WebPermissionType type, |
const std::string& origin, |