From 8247519187dca976123e733ef15f333cc22b618c Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Thu, 30 Nov 2017 20:09:30 -0800 Subject: [PATCH] #451: M1410106 (thanks to Andrew Sutherland) --- dom/indexedDB/ActorsParent.cpp | 34 +++++++++++++++++++++++----------- dom/indexedDB/IDBFactory.cpp | 25 ++++++++++++++++++------- dom/indexedDB/IDBFactory.h | 11 +++++++---- dom/workers/WorkerScope.cpp | 3 ++- 4 files changed, 50 insertions(+), 23 deletions(-) diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index 9feac61786..3d688ec9ad 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -19407,20 +19407,32 @@ FactoryOp::CheckPermission(ContentParent* aContentParent, MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mState == State::Initial || mState == State::PermissionRetry); + // TenFourFox issue 451 for Mozilla bug 1410106 const PrincipalInfo& principalInfo = mCommonParams.principalInfo(); - if (principalInfo.type() != PrincipalInfo::TSystemPrincipalInfo && - NS_WARN_IF(!Preferences::GetBool(kPrefIndexedDBEnabled, false))) { - if (aContentParent) { - // The DOM in the other process should have kept us from receiving any - // indexedDB messages so assume that the child is misbehaving. - aContentParent->KillHard("IndexedDB CheckPermission 1"); + if (principalInfo.type() != PrincipalInfo::TSystemPrincipalInfo) { + if (principalInfo.type() != PrincipalInfo::TContentPrincipalInfo) { + if (aContentParent) { + // We just want ContentPrincipalInfo or SystemPrincipalInfo. + aContentParent->KillHard("IndexedDB CheckPermission 0"); + } + + return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; } - return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; - } - if (NS_WARN_IF(mCommonParams.privateBrowsingMode())) { - // XXX This is only temporary. - return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; + if (NS_WARN_IF(!Preferences::GetBool(kPrefIndexedDBEnabled, false))) { + if (aContentParent) { + // The DOM in the other process should have kept us from receiving any + // indexedDB messages so assume that the child is misbehaving. + aContentParent->KillHard("IndexedDB CheckPermission 1"); + } + + return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; + } + + if (NS_WARN_IF(mCommonParams.privateBrowsingMode())) { + // IndexedDB is currently disabled in privateBrowsing. + return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR; + } } mFileHandleDisabled = !Preferences::GetBool(kPrefFileHandleEnabled); diff --git a/dom/indexedDB/IDBFactory.cpp b/dom/indexedDB/IDBFactory.cpp index 80e30b6add..58a6a52d8c 100644 --- a/dom/indexedDB/IDBFactory.cpp +++ b/dom/indexedDB/IDBFactory.cpp @@ -199,7 +199,10 @@ IDBFactory::CreateForMainThreadJS(JSContext* aCx, return rv; } - rv = CreateForMainThreadJSInternal(aCx, aOwningObject, principalInfo, aFactory); + rv = CreateForMainThreadJSInternal(aCx, aOwningObject, principalInfo, aFactory, + /* Only IndexedDatabaseManager::DefineIndexedDB + can call this, which is always chrome, thus ... */ + /* aIsPrivateBrowsing */ false); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } @@ -224,7 +227,9 @@ IDBFactory::CreateForDatastore(JSContext* aCx, new PrincipalInfo(SystemPrincipalInfo())); nsresult rv = - CreateForMainThreadJSInternal(aCx, aOwningObject, principalInfo, aFactory); + CreateForMainThreadJSInternal(aCx, aOwningObject, principalInfo, aFactory, + /* Only chrome can get here, therefore ... */ + /* aIsPrivateBrowsing */ false); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } @@ -240,7 +245,8 @@ IDBFactory::CreateForWorker(JSContext* aCx, JS::Handle aOwningObject, const PrincipalInfo& aPrincipalInfo, uint64_t aInnerWindowID, - IDBFactory** aFactory) + IDBFactory** aFactory, + bool aIsPrivateBrowsing) { MOZ_ASSERT(!NS_IsMainThread()); MOZ_ASSERT(aPrincipalInfo.type() != PrincipalInfo::T__None); @@ -252,7 +258,8 @@ IDBFactory::CreateForWorker(JSContext* aCx, aOwningObject, principalInfo, aInnerWindowID, - aFactory); + aFactory, + aIsPrivateBrowsing); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } @@ -268,7 +275,8 @@ IDBFactory::CreateForMainThreadJSInternal( JSContext* aCx, JS::Handle aOwningObject, nsAutoPtr& aPrincipalInfo, - IDBFactory** aFactory) + IDBFactory** aFactory, + bool aIsPrivateBrowsing) { MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(aPrincipalInfo); @@ -290,7 +298,8 @@ IDBFactory::CreateForMainThreadJSInternal( aOwningObject, aPrincipalInfo, /* aInnerWindowID */ 0, - aFactory); + aFactory, + aIsPrivateBrowsing); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } @@ -304,7 +313,8 @@ IDBFactory::CreateForJSInternal(JSContext* aCx, JS::Handle aOwningObject, nsAutoPtr& aPrincipalInfo, uint64_t aInnerWindowID, - IDBFactory** aFactory) + IDBFactory** aFactory, + bool aIsPrivateBrowsing) { MOZ_ASSERT(aCx); MOZ_ASSERT(aOwningObject); @@ -327,6 +337,7 @@ IDBFactory::CreateForJSInternal(JSContext* aCx, factory->mOwningObject = aOwningObject; mozilla::HoldJSObjects(factory.get()); factory->mInnerWindowID = aInnerWindowID; + factory->mPrivateBrowsingMode = aIsPrivateBrowsing; factory.forget(aFactory); return NS_OK; diff --git a/dom/indexedDB/IDBFactory.h b/dom/indexedDB/IDBFactory.h index f7614de433..98c806f799 100644 --- a/dom/indexedDB/IDBFactory.h +++ b/dom/indexedDB/IDBFactory.h @@ -70,7 +70,7 @@ class IDBFactory final nsTArray> mPendingRequests; BackgroundFactoryChild* mBackgroundActor; - + #ifdef DEBUG PRThread* mOwningThread; #endif @@ -100,7 +100,8 @@ class IDBFactory final JS::Handle aOwningObject, const PrincipalInfo& aPrincipalInfo, uint64_t aInnerWindowID, - IDBFactory** aFactory); + IDBFactory** aFactory, + bool aIsPrivateBrowsing); static bool AllowedForWindow(nsPIDOMWindow* aWindow); @@ -217,14 +218,16 @@ class IDBFactory final CreateForMainThreadJSInternal(JSContext* aCx, JS::Handle aOwningObject, nsAutoPtr& aPrincipalInfo, - IDBFactory** aFactory); + IDBFactory** aFactory, + bool aIsPrivateBrowsing); static nsresult CreateForJSInternal(JSContext* aCx, JS::Handle aOwningObject, nsAutoPtr& aPrincipalInfo, uint64_t aInnerWindowID, - IDBFactory** aFactory); + IDBFactory** aFactory, + bool aIsPrivateBrowsing); static nsresult AllowedForWindowInternal(nsPIDOMWindow* aWindow, diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index cc6c7fe70d..cf58fcc82f 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -379,7 +379,8 @@ WorkerGlobalScope::GetIndexedDB(ErrorResult& aErrorResult) owningObject, principalInfo, mWorkerPrivate->WindowID(), - getter_AddRefs(indexedDB)); + getter_AddRefs(indexedDB), + mWorkerPrivate->IsInPrivateBrowsing()); if (NS_WARN_IF(NS_FAILED(rv))) { aErrorResult = rv; return nullptr;