Bug 1536411 - StoragePrincipal - part 3 - IDBFactory, r=Ehsan

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2019-04-11 16:27:53 +00:00
Родитель dfe371cba0
Коммит d0cbc4e278
5 изменённых файлов: 33 добавлений и 5 удалений

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

@ -6897,6 +6897,9 @@ void nsGlobalWindowInner::StorageAccessGranted() {
object->EnsureObserver();
}
}
// Reset the IndexedDB factory.
mIndexedDB = nullptr;
}
mozilla::dom::TabGroup* nsPIDOMWindowInner::TabGroup() {

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

@ -301,14 +301,19 @@ nsresult IDBFactory::AllowedForWindowInternal(nsPIDOMWindowInner* aWindow,
// the factory callsite records whether the browser is in private browsing.
// and thus we don't have to respect that setting here. IndexedDB has no
// concept of session-local storage, and thus ignores it.
if (access <= nsContentUtils::StorageAccess::eDeny) {
if (access == nsContentUtils::StorageAccess::eDeny) {
return NS_ERROR_DOM_SECURITY_ERR;
}
if (access == nsContentUtils::StorageAccess::ePartitionedOrDeny &&
!StaticPrefs::privacy_storagePrincipal_enabledForTrackers()) {
return NS_ERROR_DOM_SECURITY_ERR;
}
nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(aWindow);
MOZ_ASSERT(sop);
nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
nsCOMPtr<nsIPrincipal> principal = sop->GetEffectiveStoragePrincipal();
if (NS_WARN_IF(!principal)) {
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}

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

@ -3360,6 +3360,11 @@ void WorkerPrivate::PropagateFirstPartyStorageAccessGrantedInternal() {
mLoadInfo.mFirstPartyStorageAccessGranted = true;
WorkerGlobalScope* globalScope = GlobalScope();
if (globalScope) {
globalScope->FirstPartyStorageAccessGranted();
}
for (uint32_t index = 0; index < data->mChildWorkers.Length(); index++) {
data->mChildWorkers[index]->PropagateFirstPartyStorageAccessGranted();
}

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

@ -393,14 +393,23 @@ already_AddRefed<IDBFactory> WorkerGlobalScope::GetIndexedDB(
RefPtr<IDBFactory> indexedDB = mIndexedDB;
if (!indexedDB) {
if (mWorkerPrivate->StorageAccess() <=
nsContentUtils::StorageAccess::eDeny) {
nsContentUtils::StorageAccess access = mWorkerPrivate->StorageAccess();
if (access == nsContentUtils::StorageAccess::eDeny) {
NS_WARNING("IndexedDB is not allowed in this worker!");
aErrorResult = NS_ERROR_DOM_SECURITY_ERR;
return nullptr;
}
const PrincipalInfo& principalInfo = mWorkerPrivate->GetPrincipalInfo();
if (access == nsContentUtils::StorageAccess::ePartitionedOrDeny &&
!StaticPrefs::privacy_storagePrincipal_enabledForTrackers()) {
NS_WARNING("IndexedDB is not allowed in this worker!");
aErrorResult = NS_ERROR_DOM_SECURITY_ERR;
return nullptr;
}
const PrincipalInfo& principalInfo =
mWorkerPrivate->GetEffectiveStoragePrincipalInfo();
nsresult rv = IDBFactory::CreateForWorker(this, principalInfo,
mWorkerPrivate->WindowID(),
@ -488,6 +497,10 @@ WorkerGlobalScope::GetOrCreateServiceWorkerRegistration(
return ref.forget();
}
void WorkerGlobalScope::FirstPartyStorageAccessGranted() {
mIndexedDB = nullptr;
}
DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope(
WorkerPrivate* aWorkerPrivate, const nsString& aName)
: WorkerGlobalScope(aWorkerPrivate), mName(aName) {}

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

@ -190,6 +190,8 @@ class WorkerGlobalScope : public DOMEventTargetHelper,
RefPtr<mozilla::dom::ServiceWorkerRegistration>
GetOrCreateServiceWorkerRegistration(
const ServiceWorkerRegistrationDescriptor& aDescriptor) override;
void FirstPartyStorageAccessGranted();
};
class DedicatedWorkerGlobalScope final : public WorkerGlobalScope {