mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1197461 - Implement Permissions.revoke. r=poiru,baku
This commit is contained in:
parent
1019054310
commit
16da4bf742
@ -121,5 +121,58 @@ Permissions::Query(JSContext* aCx,
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
Permissions::Revoke(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aPermission,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);
|
||||
if (!global) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PermissionDescriptor permission;
|
||||
JS::Rooted<JS::Value> value(aCx, JS::ObjectOrNullValue(aPermission));
|
||||
if (NS_WARN_IF(!permission.Init(aCx, value))) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> document = mWindow->GetExtantDoc();
|
||||
if (!document) {
|
||||
promise->MaybeReject(NS_ERROR_UNEXPECTED);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
|
||||
if (NS_WARN_IF(!permMgr)) {
|
||||
promise->MaybeReject(NS_ERROR_FAILURE);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
nsresult rv = permMgr->RemoveFromPrincipal(document->NodePrincipal(), PermissionNameToType(permission.mName));
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
promise->MaybeReject(rv);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
RefPtr<PermissionStatus> status =
|
||||
CreatePermissionStatus(aCx, aPermission, mWindow, aRv);
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
MOZ_ASSERT(!status);
|
||||
promise->MaybeReject(aRv);
|
||||
} else {
|
||||
MOZ_ASSERT(status);
|
||||
promise->MaybeResolve(status);
|
||||
}
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -38,6 +38,10 @@ public:
|
||||
JS::Handle<JSObject*> aPermission,
|
||||
ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<Promise> Revoke(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aPermission,
|
||||
ErrorResult& aRv);
|
||||
|
||||
private:
|
||||
~Permissions();
|
||||
|
||||
|
@ -26,4 +26,6 @@ dictionary PushPermissionDescriptor : PermissionDescriptor {
|
||||
interface Permissions {
|
||||
[Throws]
|
||||
Promise<PermissionStatus> query(object permission);
|
||||
[Throws]
|
||||
Promise<PermissionStatus> revoke(object permission);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user