diff --git a/dom/permission/Permissions.cpp b/dom/permission/Permissions.cpp index 18b7503f336..546f01fc78a 100644 --- a/dom/permission/Permissions.cpp +++ b/dom/permission/Permissions.cpp @@ -121,5 +121,58 @@ Permissions::Query(JSContext* aCx, return promise.forget(); } +already_AddRefed +Permissions::Revoke(JSContext* aCx, + JS::Handle aPermission, + ErrorResult& aRv) +{ + nsCOMPtr global = do_QueryInterface(mWindow); + if (!global) { + aRv.Throw(NS_ERROR_UNEXPECTED); + return nullptr; + } + + RefPtr promise = Promise::Create(global, aRv); + if (NS_WARN_IF(aRv.Failed())) { + return nullptr; + } + + PermissionDescriptor permission; + JS::Rooted value(aCx, JS::ObjectOrNullValue(aPermission)); + if (NS_WARN_IF(!permission.Init(aCx, value))) { + promise->MaybeReject(NS_ERROR_UNEXPECTED); + return promise.forget(); + } + + nsCOMPtr document = mWindow->GetExtantDoc(); + if (!document) { + promise->MaybeReject(NS_ERROR_UNEXPECTED); + return promise.forget(); + } + + nsCOMPtr 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 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 diff --git a/dom/permission/Permissions.h b/dom/permission/Permissions.h index d643599b4c4..521b9cbf468 100644 --- a/dom/permission/Permissions.h +++ b/dom/permission/Permissions.h @@ -38,6 +38,10 @@ public: JS::Handle aPermission, ErrorResult& aRv); + already_AddRefed Revoke(JSContext* aCx, + JS::Handle aPermission, + ErrorResult& aRv); + private: ~Permissions(); diff --git a/dom/webidl/Permissions.webidl b/dom/webidl/Permissions.webidl index 17574c75e59..29b3fa1922b 100644 --- a/dom/webidl/Permissions.webidl +++ b/dom/webidl/Permissions.webidl @@ -26,4 +26,6 @@ dictionary PushPermissionDescriptor : PermissionDescriptor { interface Permissions { [Throws] Promise query(object permission); + [Throws] + Promise revoke(object permission); };