Bug 1624269 - P4. Not using permission manager to sync HasStorageAccess. r=timhuang,baku

We already have an architecture to sync the storage access granted
result to all 3rd-party frames with the same tracking origin.
We use the same way to sync HasStorageAccess flag instead of relying
on permission manager update permissions to child processes.

Differential Revision: https://phabricator.services.mozilla.com/D73711
This commit is contained in:
Dimi Lee 2020-05-18 11:04:48 +00:00
Родитель 3cd4188086
Коммит 267aee84fa
4 изменённых файлов: 13 добавлений и 66 удалений

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

@ -17,8 +17,6 @@
#include "nsHistory.h"
#include "nsDOMNavigationTiming.h"
#include "nsIDOMStorageManager.h"
#include "nsIPermission.h"
#include "nsIPermissionManager.h"
#include "nsISecureBrowserUI.h"
#include "nsIWebProgressListener.h"
#include "mozilla/AntiTrackingUtils.h"
@ -1467,11 +1465,6 @@ nsGlobalWindowOuter::~nsGlobalWindowOuter() {
nsCOMPtr<nsIDeviceSensors> ac = do_GetService(NS_DEVICE_SENSORS_CONTRACTID);
if (ac) ac->RemoveWindowAsListener(this);
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->RemoveObserver(this, PERM_CHANGE_NOTIFICATION);
}
nsLayoutStatics::Release();
}
@ -1543,7 +1536,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGlobalWindowOuter)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIDOMChromeWindow, IsChromeWindow())
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsGlobalWindowOuter)
@ -6853,49 +6845,6 @@ nsGlobalWindowOuter::GetInterface(const nsIID& aIID, void** aSink) {
return rv;
}
//*****************************************************************************
// nsGlobalWindowOuter::nsIObserver
//*****************************************************************************
NS_IMETHODIMP
nsGlobalWindowOuter::Observe(nsISupports* aSupports, const char* aTopic,
const char16_t* aData) {
if (!nsCRT::strcmp(aTopic, PERM_CHANGE_NOTIFICATION)) {
nsCOMPtr<nsIPermission> permission = do_QueryInterface(aSupports);
if (!permission) {
return NS_OK;
}
nsIPrincipal* principal = GetPrincipal();
if (!principal) {
return NS_OK;
}
if (!AntiTrackingUtils::IsStorageAccessPermission(permission, principal)) {
return NS_OK;
}
if (!nsCRT::strcmp(aData, u"deleted")) {
// The storage access permission was deleted.
mHasStorageAccess = false;
return NS_OK;
}
if (!nsCRT::strcmp(aData, u"added") || !nsCRT::strcmp(aData, u"changed")) {
// The storage access permission was granted or modified.
uint32_t expireType = 0;
int64_t expireTime = 0;
MOZ_ALWAYS_SUCCEEDS(permission->GetExpireType(&expireType));
MOZ_ALWAYS_SUCCEEDS(permission->GetExpireTime(&expireTime));
if ((expireType == nsIPermissionManager::EXPIRE_TIME &&
expireTime >= PR_Now() / 1000) ||
(expireType == nsIPermissionManager::EXPIRE_SESSION &&
expireTime != 0)) {
// Permission hasn't expired yet.
mHasStorageAccess = true;
return NS_OK;
}
}
}
return NS_OK;
}
bool nsGlobalWindowOuter::IsSuspended() const {
MOZ_ASSERT(NS_IsMainThread());
// No inner means we are effectively suspended
@ -7620,15 +7569,6 @@ already_AddRefed<nsGlobalWindowOuter> nsGlobalWindowOuter::Create(
window->SetDocShell(aDocShell);
window->InitWasOffline();
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
// Delay calling AddObserver until we hit the event loop, in case we may be
// in the middle of modifying the observer list somehow.
NS_DispatchToMainThread(
NS_NewRunnableFunction("PermChangeDelayRunnable", [obs, window] {
obs->AddObserver(window, PERM_CHANGE_NOTIFICATION, true);
}));
}
return window.forget();
}

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

@ -26,7 +26,6 @@
#include "nsIBrowserDOMWindow.h"
#include "nsIInterfaceRequestor.h"
#include "nsIDOMChromeWindow.h"
#include "nsIObserver.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptObjectPrincipal.h"
#include "mozilla/EventListenerManager.h"
@ -163,8 +162,7 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
public nsIScriptObjectPrincipal,
public nsSupportsWeakReference,
public nsIInterfaceRequestor,
public PRCListStr,
public nsIObserver {
public PRCListStr {
public:
typedef nsDataHashtable<nsUint64HashKey, nsGlobalWindowOuter*>
OuterWindowByIdTable;
@ -352,9 +350,6 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
// nsIInterfaceRequestor
NS_DECL_NSIINTERFACEREQUESTOR
// nsIObserver
NS_DECL_NSIOBSERVER
mozilla::dom::Nullable<mozilla::dom::WindowProxyHolder> IndexedGetterOuter(
uint32_t aIndex);

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

@ -459,6 +459,12 @@ mozilla::ipc::IPCResult WindowGlobalChild::RecvSaveStorageAccessGranted() {
inner->SaveStorageAccessGranted();
}
nsCOMPtr<nsPIDOMWindowOuter> outer =
nsPIDOMWindowOuter::GetFromCurrentInner(inner);
if (outer) {
nsGlobalWindowOuter::Cast(outer)->SetHasStorageAccess(true);
}
return IPC_OK();
}

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

@ -722,6 +722,12 @@ void ContentBlocking::UpdateAllowAccessOnCurrentProcess(
if (inner) {
inner->SaveStorageAccessGranted();
}
nsCOMPtr<nsPIDOMWindowOuter> outer =
nsPIDOMWindowOuter::GetFromCurrentInner(inner);
if (outer) {
nsGlobalWindowOuter::Cast(outer)->SetHasStorageAccess(true);
}
}
}
});