Bug 1206252 - Part 1: Add a function to get all permissions by URI to nsIPermissionManager. r=jdm
MozReview-Commit-ID: KxnlBbmNJFZ
--- a/extensions/cookie/nsPermissionManager.cpp
+++ b/extensions/cookie/nsPermissionManager.cpp
@@ -2240,16 +2240,46 @@ NS_IMETHODIMP nsPermissionManager::GetEn
permEntry.mExpireType,
permEntry.mExpireTime));
}
}
return NS_NewArrayEnumerator(aEnum, array);
}
+NS_IMETHODIMP nsPermissionManager::GetAllForURI(nsIURI* aURI, nsISimpleEnumerator **aEnum)
+{
+ nsCOMArray<nsIPermission> array;
+
+ nsCOMPtr<nsIPrincipal> principal;
+ nsresult rv = GetPrincipal(aURI, getter_AddRefs(principal));
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ RefPtr<PermissionKey> key = new PermissionKey(principal);
+ PermissionHashKey* entry = mPermissionTable.GetEntry(key);
+
+ if (entry) {
+ for (const auto& permEntry : entry->GetPermissions()) {
+ // Only return custom permissions
+ if (permEntry.mPermission == nsIPermissionManager::UNKNOWN_ACTION) {
+ continue;
+ }
+
+ array.AppendObject(
+ new nsPermission(principal,
+ mTypeArray.ElementAt(permEntry.mType),
+ permEntry.mPermission,
+ permEntry.mExpireType,
+ permEntry.mExpireTime));
+ }
+ }
+
+ return NS_NewArrayEnumerator(aEnum, array);
+}
+
NS_IMETHODIMP nsPermissionManager::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *someData)
{
ENSURE_NOT_CHILD_PROCESS;
if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
// The profile is about to change,
// or is going away because the application is shutting down.
mIsShuttingDown = true;
--- a/netwerk/base/nsIPermissionManager.idl
+++ b/netwerk/base/nsIPermissionManager.idl
@@ -89,16 +89,25 @@ interface nsIPermissionManager : nsISupp
*/
void add(in nsIURI uri,
in string type,
in uint32_t permission,
[optional] in uint32_t expireType,
[optional] in int64_t expireTime);
/**
+ * Get all custom permissions for a given URI. This will return
+ * an enumerator of all permissions which are not set to default
+ * and which belong to the matching prinicpal of the given URI.
+ *
+ * @param uri the URI to get all permissions for
+ */
+ nsISimpleEnumerator getAllForURI(in nsIURI uri);
+
+ /**
* Add permission information for a given principal.
* It is internally calling the other add() method using the nsIURI from the
* principal.
* Passing a system principal will be a no-op because they will always be
* granted permissions.
*/
void addFromPrincipal(in nsIPrincipal principal, in string typed,
in uint32_t permission,