Bug 1553867 - Reduce the number of ClonePrincipalForPermission() call in CookieSettings, r=Ehsan

Differential Revision: https://phabricator.services.mozilla.com/D32364

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-05-24 19:05:35 +00:00
Родитель 52816e049d
Коммит c926d65d2f
3 изменённых файлов: 28 добавлений и 4 удалений

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

@ -112,8 +112,19 @@ nsPermission::Matches(nsIPrincipal* aPrincipal, bool aExactHost,
return NS_OK;
}
return MatchesPrincipalForPermission(principal, aExactHost, aMatches);
}
NS_IMETHODIMP
nsPermission::MatchesPrincipalForPermission(nsIPrincipal* aPrincipal,
bool aExactHost, bool* aMatches) {
NS_ENSURE_ARG_POINTER(aPrincipal);
NS_ENSURE_ARG_POINTER(aMatches);
*aMatches = false;
// If the principals are equal, then they match.
if (mPrincipal->Equals(principal)) {
if (mPrincipal->Equals(aPrincipal)) {
*aMatches = true;
return NS_OK;
}
@ -126,7 +137,7 @@ nsPermission::Matches(nsIPrincipal* aPrincipal, bool aExactHost,
// Compare their OriginAttributes
const mozilla::OriginAttributes& theirAttrs =
principal->OriginAttributesRef();
aPrincipal->OriginAttributesRef();
const mozilla::OriginAttributes& ourAttrs = mPrincipal->OriginAttributesRef();
if (theirAttrs != ourAttrs) {
@ -134,7 +145,7 @@ nsPermission::Matches(nsIPrincipal* aPrincipal, bool aExactHost,
}
nsCOMPtr<nsIURI> theirURI;
nsresult rv = principal->GetURI(getter_AddRefs(theirURI));
nsresult rv = aPrincipal->GetURI(getter_AddRefs(theirURI));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIURI> ourURI;

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

@ -67,6 +67,13 @@ interface nsIPermission : nsISupports
boolean matches(in nsIPrincipal principal,
in boolean exactHost);
/**
* Similar to matches() but the principal's URI should be just an origin
* (no path, no queryString, etc).
*/
[noscript] boolean matchesPrincipalForPermission(in nsIPrincipal principal,
in boolean exactHost);
/**
* Test whether a URI would be affected by this permission.
* NOTE: This performs matches with default origin attribute values.

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

@ -115,10 +115,16 @@ CookieSettings::CookiePermission(nsIPrincipal* aPrincipal,
nsresult rv;
nsCOMPtr<nsIPrincipal> principal =
nsPermission::ClonePrincipalForPermission(aPrincipal);
if (NS_WARN_IF(!principal)) {
return NS_ERROR_FAILURE;
}
// Let's see if we know this permission.
for (const RefPtr<nsIPermission>& permission : mCookiePermissions) {
bool match = false;
rv = permission->Matches(aPrincipal, false, &match);
rv = permission->MatchesPrincipalForPermission(aPrincipal, false, &match);
if (NS_WARN_IF(NS_FAILED(rv)) || !match) {
continue;
}