зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1525208 - Part 7: Devirtualize accesses to nsPermissionManager in the anti-tracking backend; r=baku
Depends on D18648 Differential Revision: https://phabricator.services.mozilla.com/D18649 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
385a0977d4
Коммит
385db59f90
|
@ -47,8 +47,10 @@
|
|||
#include "nsPrintfCString.h"
|
||||
#include "mozilla/AbstractThread.h"
|
||||
#include "ExpandedPrincipal.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
|
||||
static nsPermissionManager* gPermissionManager = nullptr;
|
||||
static mozilla::StaticRefPtr<nsPermissionManager> gPermissionManager;
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
@ -978,12 +980,23 @@ nsPermissionManager::GetXPCOMSingleton() {
|
|||
if (NS_SUCCEEDED(permManager->Init())) {
|
||||
// Note: This is cleared in the nsPermissionManager destructor.
|
||||
gPermissionManager = permManager.get();
|
||||
ClearOnShutdown(&gPermissionManager);
|
||||
return permManager.forget();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// static
|
||||
nsPermissionManager* nsPermissionManager::GetInstance() {
|
||||
if (!gPermissionManager) {
|
||||
// Hand off the creation of the permission manager to GetXPCOMSingleton.
|
||||
nsCOMPtr<nsIPermissionManager> permManager = GetXPCOMSingleton();
|
||||
}
|
||||
|
||||
return gPermissionManager;
|
||||
}
|
||||
|
||||
nsresult nsPermissionManager::Init() {
|
||||
// If the 'permissions.memory_only' pref is set to true, then don't write any
|
||||
// permission settings to disk, but keep them in a memory-only database.
|
||||
|
|
|
@ -148,6 +148,7 @@ class nsPermissionManager final : public nsIPermissionManager,
|
|||
|
||||
nsPermissionManager();
|
||||
static already_AddRefed<nsIPermissionManager> GetXPCOMSingleton();
|
||||
static nsPermissionManager* GetInstance();
|
||||
nsresult Init();
|
||||
|
||||
// enums for AddInternal()
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "nsIIOService.h"
|
||||
#include "nsIParentChannel.h"
|
||||
#include "nsIPermission.h"
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsPermissionManager.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsIURI.h"
|
||||
|
@ -457,7 +457,7 @@ class TemporaryAccessGrantObserver final : public nsIObserver {
|
|||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
static void Create(nsIPermissionManager* aPM, nsIPrincipal* aPrincipal,
|
||||
static void Create(nsPermissionManager* aPM, nsIPrincipal* aPrincipal,
|
||||
const nsACString& aType) {
|
||||
nsCOMPtr<nsITimer> timer;
|
||||
RefPtr<TemporaryAccessGrantObserver> observer =
|
||||
|
@ -483,7 +483,7 @@ class TemporaryAccessGrantObserver final : public nsIObserver {
|
|||
}
|
||||
|
||||
private:
|
||||
TemporaryAccessGrantObserver(nsIPermissionManager* aPM,
|
||||
TemporaryAccessGrantObserver(nsPermissionManager* aPM,
|
||||
nsIPrincipal* aPrincipal,
|
||||
const nsACString& aType)
|
||||
: mPM(aPM), mPrincipal(aPrincipal), mType(aType) {
|
||||
|
@ -496,7 +496,7 @@ class TemporaryAccessGrantObserver final : public nsIObserver {
|
|||
|
||||
private:
|
||||
nsCOMPtr<nsITimer> mTimer;
|
||||
nsCOMPtr<nsIPermissionManager> mPM;
|
||||
RefPtr<nsPermissionManager> mPM;
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
nsCString mType;
|
||||
};
|
||||
|
@ -761,8 +761,8 @@ AntiTrackingCommon::SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(
|
|||
__func__);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPermissionManager> pm = services::GetPermissionManager();
|
||||
if (NS_WARN_IF(!pm)) {
|
||||
nsPermissionManager* permManager = nsPermissionManager::GetInstance();
|
||||
if (NS_WARN_IF(!permManager)) {
|
||||
LOG(("Permission manager is null, bailing out early"));
|
||||
return FirstPartyStorageAccessGrantPromise::CreateAndReject(false,
|
||||
__func__);
|
||||
|
@ -790,9 +790,9 @@ AntiTrackingCommon::SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(
|
|||
"permission manager",
|
||||
expirationTime));
|
||||
|
||||
rv = pm->AddFromPrincipal(aTrackingPrincipal, "cookie",
|
||||
nsICookiePermission::ACCESS_ALLOW, expirationType,
|
||||
when);
|
||||
rv = permManager->AddFromPrincipal(aTrackingPrincipal, "cookie",
|
||||
nsICookiePermission::ACCESS_ALLOW,
|
||||
expirationType, when);
|
||||
} else {
|
||||
uint32_t privateBrowsingId = 0;
|
||||
rv = aParentPrincipal->GetPrivateBrowsingId(&privateBrowsingId);
|
||||
|
@ -813,13 +813,13 @@ AntiTrackingCommon::SaveFirstPartyStorageAccessGrantedForOriginOnParentProcess(
|
|||
"permission manager",
|
||||
type.get(), expirationTime));
|
||||
|
||||
rv = pm->AddFromPrincipal(aParentPrincipal, type.get(),
|
||||
nsIPermissionManager::ALLOW_ACTION,
|
||||
expirationType, when);
|
||||
rv = permManager->AddFromPrincipal(aParentPrincipal, type.get(),
|
||||
nsIPermissionManager::ALLOW_ACTION,
|
||||
expirationType, when);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && (aAllowMode == eAllowAutoGrant)) {
|
||||
// Make sure temporary access grants do not survive more than 24 hours.
|
||||
TemporaryAccessGrantObserver::Create(pm, aParentPrincipal, type);
|
||||
TemporaryAccessGrantObserver::Create(permManager, aParentPrincipal, type);
|
||||
}
|
||||
}
|
||||
Unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
|
@ -1033,14 +1033,15 @@ bool AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(
|
|||
return true;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPermissionManager> pm = services::GetPermissionManager();
|
||||
if (NS_WARN_IF(!pm)) {
|
||||
nsPermissionManager* permManager = nsPermissionManager::GetInstance();
|
||||
if (NS_WARN_IF(!permManager)) {
|
||||
LOG(("Failed to obtain the permission manager"));
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t result = 0;
|
||||
rv = pm->TestPermissionFromPrincipal(parentPrincipal, type.get(), &result);
|
||||
rv = permManager->TestPermissionFromPrincipal(parentPrincipal, type.get(),
|
||||
&result);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
LOG(("Failed to test the permission"));
|
||||
return false;
|
||||
|
@ -1280,14 +1281,15 @@ bool AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(
|
|||
nsAutoCString type;
|
||||
CreatePermissionKey(trackingOrigin, origin, type);
|
||||
|
||||
nsCOMPtr<nsIPermissionManager> pm = services::GetPermissionManager();
|
||||
if (NS_WARN_IF(!pm)) {
|
||||
nsPermissionManager* permManager = nsPermissionManager::GetInstance();
|
||||
if (NS_WARN_IF(!permManager)) {
|
||||
LOG(("Failed to obtain the permission manager"));
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t result = 0;
|
||||
rv = pm->TestPermissionFromPrincipal(parentPrincipal, type.get(), &result);
|
||||
rv = permManager->TestPermissionFromPrincipal(parentPrincipal, type.get(),
|
||||
&result);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
LOG(("Failed to test the permission"));
|
||||
return false;
|
||||
|
@ -1375,14 +1377,15 @@ bool AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(
|
|||
nsAutoCString type;
|
||||
CreatePermissionKey(origin, origin, type);
|
||||
|
||||
nsCOMPtr<nsIPermissionManager> pm = services::GetPermissionManager();
|
||||
if (NS_WARN_IF(!pm)) {
|
||||
nsPermissionManager* permManager = nsPermissionManager::GetInstance();
|
||||
if (NS_WARN_IF(!permManager)) {
|
||||
LOG(("Failed to obtain the permission manager"));
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t result = 0;
|
||||
rv = pm->TestPermissionFromPrincipal(parentPrincipal, type.get(), &result);
|
||||
rv = permManager->TestPermissionFromPrincipal(parentPrincipal, type.get(),
|
||||
&result);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
LOG(("Failed to test the permission"));
|
||||
return false;
|
||||
|
@ -1441,8 +1444,8 @@ nsresult AntiTrackingCommon::IsOnContentBlockingAllowList(
|
|||
}
|
||||
escaped.Append(temp);
|
||||
|
||||
nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
|
||||
NS_ENSURE_TRUE(permMgr, NS_ERROR_FAILURE);
|
||||
nsPermissionManager* permManager = nsPermissionManager::GetInstance();
|
||||
NS_ENSURE_TRUE(permManager, NS_ERROR_FAILURE);
|
||||
|
||||
// Check both the normal mode and private browsing mode user override
|
||||
// permissions.
|
||||
|
@ -1456,8 +1459,8 @@ nsresult AntiTrackingCommon::IsOnContentBlockingAllowList(
|
|||
}
|
||||
|
||||
uint32_t permissions = nsIPermissionManager::UNKNOWN_ACTION;
|
||||
rv = permMgr->TestPermissionOriginNoSuffix(topWinURI, types[i].first(),
|
||||
&permissions);
|
||||
rv = permManager->TestPermissionOriginNoSuffix(topWinURI, types[i].first(),
|
||||
&permissions);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (permissions == nsIPermissionManager::ALLOW_ACTION) {
|
||||
|
@ -1597,8 +1600,8 @@ nsresult AntiTrackingCommon::IsOnContentBlockingAllowList(
|
|||
Unused << aPrincipal->GetURI(getter_AddRefs(uri));
|
||||
LOG_SPEC(("Saving the userInteraction for %s", _spec), uri);
|
||||
|
||||
nsCOMPtr<nsIPermissionManager> pm = services::GetPermissionManager();
|
||||
if (NS_WARN_IF(!pm)) {
|
||||
nsPermissionManager* permManager = nsPermissionManager::GetInstance();
|
||||
if (NS_WARN_IF(!permManager)) {
|
||||
LOG(("Permission manager is null, bailing out early"));
|
||||
return;
|
||||
}
|
||||
|
@ -1618,9 +1621,9 @@ nsresult AntiTrackingCommon::IsOnContentBlockingAllowList(
|
|||
when = 0;
|
||||
}
|
||||
|
||||
rv = pm->AddFromPrincipal(aPrincipal, USER_INTERACTION_PERM,
|
||||
nsIPermissionManager::ALLOW_ACTION,
|
||||
expirationType, when);
|
||||
rv = permManager->AddFromPrincipal(aPrincipal, USER_INTERACTION_PERM,
|
||||
nsIPermissionManager::ALLOW_ACTION,
|
||||
expirationType, when);
|
||||
Unused << NS_WARN_IF(NS_FAILED(rv));
|
||||
return;
|
||||
}
|
||||
|
@ -1638,14 +1641,14 @@ nsresult AntiTrackingCommon::IsOnContentBlockingAllowList(
|
|||
|
||||
/* static */ bool AntiTrackingCommon::HasUserInteraction(
|
||||
nsIPrincipal* aPrincipal) {
|
||||
nsCOMPtr<nsIPermissionManager> pm = services::GetPermissionManager();
|
||||
if (NS_WARN_IF(!pm)) {
|
||||
nsPermissionManager* permManager = nsPermissionManager::GetInstance();
|
||||
if (NS_WARN_IF(!permManager)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t result = 0;
|
||||
nsresult rv = pm->TestPermissionFromPrincipal(aPrincipal,
|
||||
USER_INTERACTION_PERM, &result);
|
||||
nsresult rv = permManager->TestPermissionFromPrincipal(
|
||||
aPrincipal, USER_INTERACTION_PERM, &result);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,10 @@ UNIFIED_SOURCES += [
|
|||
'AntiTrackingCommon.cpp',
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'/extensions/cookie',
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
|
Загрузка…
Ссылка в новой задаче