From 5125ca9fad2086969033c8170a00b6d081ab197e Mon Sep 17 00:00:00 2001 From: William Chen Date: Mon, 18 Mar 2013 06:24:53 -0700 Subject: [PATCH] Bug 782211 - Part 4: Add function to remote test for permission in nsIPermissionManager. r=cjones --- dom/ipc/ContentParent.cpp | 17 +++++++++++++++++ dom/ipc/ContentParent.h | 4 ++++ dom/ipc/PContent.ipdl | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index e0198eb0c15b..a8e53dfdfeae 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -2272,6 +2272,23 @@ ContentParent::RecvCloseAlert(const nsString& aName) return true; } +bool +ContentParent::RecvTestPermissionFromPrincipal(const IPC::Principal& aPrincipal, + const nsCString& aType, + uint32_t* permission) +{ + nsCOMPtr permissionManager = + do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); + NS_ENSURE_TRUE(permissionManager, false); + + nsresult rv = permissionManager->TestPermissionFromPrincipal(aPrincipal, + aType.get(), + permission); + NS_ENSURE_SUCCESS(rv, false); + + return true; +} + bool ContentParent::RecvSyncMessage(const nsString& aMsg, const ClonedMessageData& aData, diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 4a3481272970..4fca19c320ed 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -333,6 +333,10 @@ private: virtual bool RecvCloseAlert(const nsString& aName); + virtual bool RecvTestPermissionFromPrincipal(const IPC::Principal& aPrincipal, + const nsCString& aType, + uint32_t* permission); + virtual bool RecvLoadURIExternal(const URIParams& uri); virtual bool RecvSyncMessage(const nsString& aMsg, diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index ed7e4b479587..bad54717e07d 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -433,6 +433,22 @@ parent: CloseAlert(nsString name); + /** + * Tests permission for a provided principal using the permission + * manager. + * + * @param principal + * The principal to test for the permissions. + * @param type + * The type of permission to for the principal. + * + * NOTE: The principal is untrusted in the parent process. Only + * principals that can live in the content process should + * be provided. + */ + sync TestPermissionFromPrincipal(Principal principal, nsCString type) + returns (uint32_t permission); + PExternalHelperApp(OptionalURIParams uri, nsCString aMimeContentType, nsCString aContentDisposition, bool aForceSave, int64_t aContentLength, OptionalURIParams aReferrer);