Index: content/child/permissions/permission_dispatcher.cc |
diff --git a/content/child/permissions/permission_dispatcher.cc b/content/child/permissions/permission_dispatcher.cc |
index afa829d723eb7d7f8d3cfb1b8ca39100523ec74b..1a8c15cc08fec96d63fb569bf5c23264cd797d8e 100644 |
--- a/content/child/permissions/permission_dispatcher.cc |
+++ b/content/child/permissions/permission_dispatcher.cc |
@@ -77,30 +77,6 @@ bool PermissionDispatcher::IsObservable(blink::WebPermissionType type) { |
type == blink::WebPermissionTypeMidiSysEx; |
} |
-PermissionDispatcher::CallbackInformation::CallbackInformation( |
- blink::WebPermissionCallback* callback, |
- int worker_thread_id) |
- : callback_(callback), |
- worker_thread_id_(worker_thread_id) { |
-} |
- |
-blink::WebPermissionCallback* |
-PermissionDispatcher::CallbackInformation::callback() const { |
- return callback_.get(); |
-} |
- |
-int PermissionDispatcher::CallbackInformation::worker_thread_id() const { |
- return worker_thread_id_; |
-} |
- |
-blink::WebPermissionCallback* |
-PermissionDispatcher::CallbackInformation::ReleaseCallback() { |
- return callback_.release(); |
-} |
- |
-PermissionDispatcher::CallbackInformation::~CallbackInformation() { |
-} |
- |
PermissionDispatcher::PermissionDispatcher(ServiceRegistry* service_registry) |
: service_registry_(service_registry) { |
} |
@@ -124,6 +100,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, |
@@ -173,6 +157,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, |
@@ -224,6 +216,15 @@ void PermissionDispatcher::RunCallbackOnWorkerThread( |
delete callback; |
} |
+void PermissionDispatcher::RunMultiCallbackOnWorkerThread( |
+ blink::WebPermissionsCallback* callback, |
+ scoped_ptr<blink::WebVector<blink::WebPermissionStatus>> statuses) { |
+ callback->onSuccess( |
+ blink::adoptWebPtr<blink::WebVector<blink::WebPermissionStatus>>( |
+ statuses.release())); |
+ delete callback; |
+} |
+ |
PermissionServicePtr& PermissionDispatcher::GetPermissionServicePtr() { |
if (!permission_service_.get()) { |
service_registry_->ConnectToRemoteService( |
@@ -242,7 +243,8 @@ void PermissionDispatcher::QueryPermissionInternal( |
// |permission_service_| pipe will be destroyed too so OnQueryPermission will |
// not be called. |
int request_id = pending_callbacks_.Add( |
- new CallbackInformation(callback, worker_thread_id)); |
+ new CallbackInformation<blink::WebPermissionCallback>( |
+ callback, worker_thread_id)); |
GetPermissionServicePtr()->HasPermission( |
GetPermissionName(type), |
origin, |
@@ -261,7 +263,7 @@ void PermissionDispatcher::RequestPermissionInternal( |
// |permission_service_| pipe will be destroyed too so OnQueryPermission will |
// not be called. |
int request_id = pending_callbacks_.Add( |
- new CallbackInformation(callback, worker_thread_id)); |
+ new SingleCallbackInfo(callback, worker_thread_id)); |
GetPermissionServicePtr()->RequestPermission( |
GetPermissionName(type), |
origin, |
@@ -271,6 +273,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 MultiCallbackInfo(callback, worker_thread_id)); |
+ |
+ mojo::Array<PermissionName> names(types.size()); |
+ for (size_t i = 0; i < types.size(); ++i) { |
+ names[i] = GetPermissionName(types[i]); |
+ } |
mlamouri (slow - plz ping)
2015/08/18 13:37:15
nit: no { }
Lalit Maganti
2015/08/20 14:23:30
Done.
|
+ |
+ 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, |
@@ -281,7 +309,7 @@ void PermissionDispatcher::RevokePermissionInternal( |
// |permission_service_| pipe will be destroyed too so OnQueryPermission will |
// not be called. |
int request_id = pending_callbacks_.Add( |
- new CallbackInformation(callback, worker_thread_id)); |
+ new SingleCallbackInfo(callback, worker_thread_id)); |
GetPermissionServicePtr()->RevokePermission( |
GetPermissionName(type), |
origin, |
@@ -292,7 +320,7 @@ void PermissionDispatcher::RevokePermissionInternal( |
void PermissionDispatcher::OnPermissionResponse(int request_id, |
PermissionStatus result) { |
- CallbackInformation* callback_information = |
+ SingleCallbackInfo* callback_information = |
pending_callbacks_.Lookup(request_id); |
DCHECK(callback_information && callback_information->callback()); |
scoped_ptr<blink::WebPermissionStatus> status( |
@@ -318,6 +346,41 @@ void PermissionDispatcher::OnPermissionResponse(int request_id, |
pending_callbacks_.Remove(request_id); |
} |
+void PermissionDispatcher::OnPermissionsResponse( |
+ int request_id, |
+ const mojo::Array<PermissionStatus>& result) { |
+ MultiCallbackInfo* callback_information = |
+ multiple_pending_callbacks_.Lookup(request_id); |
+ DCHECK(callback_information && callback_information->callback()); |
+ |
+ scoped_ptr<blink::WebVector<blink::WebPermissionStatus>> status( |
mlamouri (slow - plz ping)
2015/08/18 13:37:15
nit: statuses
Lalit Maganti
2015/08/20 14:23:30
Done.
|
+ new blink::WebVector<blink::WebPermissionStatus>(result.size())); |
+ for (size_t i = 0; i < result.size(); i++) { |
+ (*status)[i] = GetWebPermissionStatus(result[i]); |
+ } |
mlamouri (slow - plz ping)
2015/08/18 13:37:15
nit: remove { }
Lalit Maganti
2015/08/20 14:23:30
Done.
|
+ |
+ 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( |
+ blink::adoptWebPtr<blink::WebVector<blink::WebPermissionStatus>>( |
+ status.release())); |
mlamouri (slow - plz ping)
2015/08/18 13:37:15
wouldn't status.release be enough?
Lalit Maganti
2015/08/20 14:23:30
Although that would make so much sense, WebPtrs do
|
+ multiple_pending_callbacks_.Remove(request_id); |
+} |
+ |
void PermissionDispatcher::OnPermissionChanged( |
blink::WebPermissionType type, |
const std::string& origin, |