Bug 1509132 - Inform the 3rd party tracker window when the storage permission is granted, r=ehsan

This is needed for the LocalStorage Next-Generation project which sends storage
notifications only to content processes with an existing LocalStorage object.

I cannot write a test for this, because the current localStorage all works fine.
This commit is contained in:
Andrea Marchesini 2018-11-23 08:12:02 +01:00
parent b9f5f08c7f
commit 5368c7288c
3 changed files with 27 additions and 0 deletions

View File

@ -7986,6 +7986,25 @@ nsGlobalWindowInner::ForgetSharedWorker(SharedWorker* aSharedWorker)
mSharedWorkers.RemoveElement(aSharedWorker);
}
void
nsGlobalWindowInner::StorageAccessGranted()
{
// If we have a partitioned localStorage, it's time to replace it with a real
// one in order to receive notifications.
if (mLocalStorage &&
mLocalStorage->Type() == Storage::ePartitionedLocalStorage) {
IgnoredErrorResult error;
GetLocalStorage(error);
if (NS_WARN_IF(error.Failed())) {
return;
}
MOZ_ASSERT(mLocalStorage &&
mLocalStorage->Type() == Storage::eLocalStorage);
}
}
mozilla::dom::TabGroup*
nsPIDOMWindowInner::TabGroup()
{

View File

@ -1241,6 +1241,11 @@ public:
// area.
nsIPrincipal* GetTopLevelStorageAreaPrincipal();
// This method is called if this window loads a 3rd party tracking resource
// and the storage is just been granted. The window can reset the partitioned
// storage objects and switch to the first party cookie jar.
void StorageAccessGranted();
protected:
static void NotifyDOMWindowDestroyed(nsGlobalWindowInner* aWindow);
void NotifyWindowIDDestroyed(const char* aTopic);

View File

@ -536,6 +536,9 @@ AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor(nsIPrincipal* aPrincipa
// Let's store the permission in the current parent window.
topInnerWindow->SaveStorageAccessGranted(permissionKey);
// Let's inform the parent window.
parentWindow->StorageAccessGranted();
nsIChannel* channel =
pwin->GetCurrentInnerWindow()->GetExtantDoc()->GetChannel();