зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1526542 - Improve the efficiency of CreatePermissionKey(); r=baku
There are two changes being made here: * In call sites where we know both origin arguments are equal, we will call a specialized version of the function which avoids the origin equality check. * We avoid calling into the generic printf structure and build the result string manually. Differential Revision: https://phabricator.services.mozilla.com/D19245 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
3f4f286ad1
Коммит
f32cd1cf0a
|
@ -121,17 +121,36 @@ bool GetParentPrincipalAndTrackingOrigin(
|
|||
return true;
|
||||
};
|
||||
|
||||
void CreatePermissionKey(const nsCString& aTrackingOrigin,
|
||||
nsACString& aPermissionKey) {
|
||||
MOZ_ASSERT(aPermissionKey.IsEmpty());
|
||||
|
||||
static const nsLiteralCString prefix =
|
||||
NS_LITERAL_CSTRING(ANTITRACKING_PERM_KEY "^");
|
||||
|
||||
aPermissionKey.SetCapacity(prefix.Length() + aTrackingOrigin.Length());
|
||||
aPermissionKey.Append(prefix);
|
||||
aPermissionKey.Append(aTrackingOrigin);
|
||||
}
|
||||
|
||||
void CreatePermissionKey(const nsCString& aTrackingOrigin,
|
||||
const nsCString& aGrantedOrigin,
|
||||
nsACString& aPermissionKey) {
|
||||
MOZ_ASSERT(aPermissionKey.IsEmpty());
|
||||
|
||||
if (aTrackingOrigin == aGrantedOrigin) {
|
||||
aPermissionKey =
|
||||
nsPrintfCString(ANTITRACKING_PERM_KEY "^%s", aTrackingOrigin.get());
|
||||
CreatePermissionKey(aTrackingOrigin, aPermissionKey);
|
||||
return;
|
||||
}
|
||||
|
||||
aPermissionKey = nsPrintfCString(ANTITRACKING_PERM_KEY "^%s^%s",
|
||||
aTrackingOrigin.get(), aGrantedOrigin.get());
|
||||
static const nsLiteralCString prefix =
|
||||
NS_LITERAL_CSTRING(ANTITRACKING_PERM_KEY "^");
|
||||
|
||||
aPermissionKey.SetCapacity(prefix.Length() + 1 + aTrackingOrigin.Length());
|
||||
aPermissionKey.Append(prefix);
|
||||
aPermissionKey.Append(aTrackingOrigin);
|
||||
aPermissionKey.AppendLiteral("^");
|
||||
aPermissionKey.Append(aGrantedOrigin);
|
||||
}
|
||||
|
||||
// This internal method returns ACCESS_DENY if the access is denied,
|
||||
|
@ -1021,7 +1040,7 @@ bool AntiTrackingCommon::IsStorageAccessPermission(nsIPermission* aPermission,
|
|||
// shorter permission key and will then do a prefix match on the type of the
|
||||
// input permission to see if it is a storage access permission or not.
|
||||
nsAutoCString permissionKey;
|
||||
CreatePermissionKey(origin, origin, permissionKey);
|
||||
CreatePermissionKey(origin, permissionKey);
|
||||
|
||||
nsAutoCString type;
|
||||
rv = aPermission->GetType(type);
|
||||
|
@ -1545,7 +1564,7 @@ bool AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(
|
|||
}
|
||||
|
||||
nsAutoCString type;
|
||||
CreatePermissionKey(origin, origin, type);
|
||||
CreatePermissionKey(origin, type);
|
||||
|
||||
nsPermissionManager* permManager = nsPermissionManager::GetInstance();
|
||||
if (NS_WARN_IF(!permManager)) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче