Bug 1206252 - Part 1: Add a function to get all permissions by URI to nsIPermissionManager. r=jdm

MozReview-Commit-ID: KxnlBbmNJFZ

--HG--
extra : rebase_source : c931b331ea311c21adc8dcac9dbb88fee3a4a05f
This commit is contained in:
Johann Hofmann 2016-07-07 16:27:10 +02:00
Родитель 0aa659b7d2
Коммит 261d220621
2 изменённых файлов: 39 добавлений и 0 удалений

Просмотреть файл

@ -2245,6 +2245,36 @@ NS_IMETHODIMP nsPermissionManager::GetEnumerator(nsISimpleEnumerator **aEnum)
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;

Просмотреть файл

@ -93,6 +93,15 @@ interface nsIPermissionManager : nsISupports
[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