зеркало из https://github.com/mozilla/pjs.git
bug 370802, nsIPermissionManager: Add ability for exact hostname testing
r/sr=cbiesinger
This commit is contained in:
Родитель
3d65d3b277
Коммит
e992f34c9e
|
@ -337,7 +337,7 @@ nsPermissionManager::Remove(const nsACString &aHost,
|
|||
// so just return NS_OK
|
||||
if (typeIndex == -1) return NS_OK;
|
||||
|
||||
nsHostEntry *entry = GetHostEntry(PromiseFlatCString(aHost), typeIndex);
|
||||
nsHostEntry *entry = GetHostEntry(PromiseFlatCString(aHost), typeIndex, PR_FALSE);
|
||||
if (entry) {
|
||||
// cache the old permission before we delete it, to notify observers
|
||||
PRUint32 oldPermission = entry->GetPermission(typeIndex);
|
||||
|
@ -371,10 +371,27 @@ nsPermissionManager::RemoveAll()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPermissionManager::TestExactPermission(nsIURI *aURI,
|
||||
const char *aType,
|
||||
PRUint32 *aPermission)
|
||||
{
|
||||
return CommonTestPermission(aURI, aType, aPermission, PR_TRUE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPermissionManager::TestPermission(nsIURI *aURI,
|
||||
const char *aType,
|
||||
PRUint32 *aPermission)
|
||||
{
|
||||
return CommonTestPermission(aURI, aType, aPermission, PR_FALSE);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPermissionManager::CommonTestPermission(nsIURI *aURI,
|
||||
const char *aType,
|
||||
PRUint32 *aPermission,
|
||||
PRBool aExactHostMatch)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURI);
|
||||
NS_ENSURE_ARG_POINTER(aType);
|
||||
|
@ -392,7 +409,7 @@ nsPermissionManager::TestPermission(nsIURI *aURI,
|
|||
// so just return NS_OK
|
||||
if (typeIndex == -1) return NS_OK;
|
||||
|
||||
nsHostEntry *entry = GetHostEntry(host, typeIndex);
|
||||
nsHostEntry *entry = GetHostEntry(host, typeIndex, aExactHostMatch);
|
||||
if (entry)
|
||||
*aPermission = entry->GetPermission(typeIndex);
|
||||
|
||||
|
@ -404,7 +421,8 @@ nsPermissionManager::TestPermission(nsIURI *aURI,
|
|||
// return null if nothing found.
|
||||
nsHostEntry *
|
||||
nsPermissionManager::GetHostEntry(const nsAFlatCString &aHost,
|
||||
PRUint32 aType)
|
||||
PRUint32 aType,
|
||||
PRBool aExactHostMatch)
|
||||
{
|
||||
PRUint32 offset = 0;
|
||||
nsHostEntry *entry;
|
||||
|
@ -417,6 +435,9 @@ nsPermissionManager::GetHostEntry(const nsAFlatCString &aHost,
|
|||
// reset entry, to be able to return null on failure
|
||||
entry = nsnull;
|
||||
}
|
||||
if (aExactHostMatch)
|
||||
break; // do not try super domains
|
||||
|
||||
offset = aHost.FindChar('.', offset) + 1;
|
||||
|
||||
// walk up the domaintree (we stop as soon as we find a match,
|
||||
|
|
|
@ -168,7 +168,13 @@ private:
|
|||
PRBool aAdd);
|
||||
|
||||
nsHostEntry *GetHostEntry(const nsAFlatCString &aHost,
|
||||
PRUint32 aType);
|
||||
PRUint32 aType,
|
||||
PRBool aExactHostMatch);
|
||||
|
||||
nsresult CommonTestPermission(nsIURI *aURI,
|
||||
const char *aType,
|
||||
PRUint32 *aPermission,
|
||||
PRBool aExactHostMatch);
|
||||
|
||||
// Use LazyWrite to save the permissions file on a timer. It will write
|
||||
// the file only once if repeatedly hammered quickly.
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
interface nsIURI;
|
||||
interface nsIObserver;
|
||||
|
||||
[scriptable, uuid(4F6B5E00-0C36-11d5-A535-0010A401EB10)]
|
||||
[scriptable, uuid(00708302-684c-42d6-a5a3-995d51b1d17c)]
|
||||
interface nsIPermissionManager : nsISupports
|
||||
{
|
||||
/**
|
||||
|
@ -128,6 +128,17 @@ interface nsIPermissionManager : nsISupports
|
|||
PRUint32 testPermission(in nsIURI uri,
|
||||
in string type);
|
||||
|
||||
/**
|
||||
* Test whether a website has permission to perform the given action.
|
||||
* This requires an exact hostname match, subdomains are not a match.
|
||||
* @param uri the uri to be tested
|
||||
* @param type a case-sensitive ASCII string, identifying the consumer
|
||||
* @param return see add(), param permission. returns UNKNOWN_ACTION when
|
||||
* there is no stored permission for this uri and / or type.
|
||||
*/
|
||||
PRUint32 testExactPermission(in nsIURI uri,
|
||||
in string type);
|
||||
|
||||
/**
|
||||
* Allows enumeration of all stored permissions
|
||||
* @return an nsISimpleEnumerator interface that allows access to
|
||||
|
|
Загрузка…
Ссылка в новой задаче