# HG changeset patch
# User Michael Layzell
# Date 1436994062 14400
# Node ID cc93773031259aecc93d38e2e69efab68d39a644
# Parent d67c4fd50c16f587c7e2b27a953ff8ffbf26234f
Bug 1147821 - Update IndexedDB to use common StorageAllowedForWindow logic, r=khuey
diff --git a/dom/indexedDB/IDBFactory.cpp b/dom/indexedDB/IDBFactory.cpp
--- a/dom/indexedDB/IDBFactory.cpp
+++ b/dom/indexedDB/IDBFactory.cpp
@@ -357,77 +357,61 @@ IDBFactory::AllowedForWindowInternal(nsP
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aWindow);
MOZ_ASSERT(aWindow->IsInnerWindow());
if (NS_WARN_IF(!IndexedDatabaseManager::GetOrCreate())) {
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
}
- nsIDocument* document = aWindow->GetExtantDoc();
- if (document->GetSandboxFlags() & SANDBOXED_ORIGIN) {
+ nsContentUtils::StorageAccess access =
+ nsContentUtils::StorageAllowedForWindow(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) {
return NS_ERROR_DOM_SECURITY_ERR;
}
nsCOMPtr sop = do_QueryInterface(aWindow);
MOZ_ASSERT(sop);
nsCOMPtr principal = sop->GetPrincipal();
if (NS_WARN_IF(!principal)) {
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
+
}
- bool isSystemPrincipal;
- if (!AllowedForPrincipal(principal, &isSystemPrincipal)) {
- return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
- }
-
- if (isSystemPrincipal) {
+ if (nsContentUtils::IsSystemPrincipal(principal)) {
principal.forget(aPrincipal);
return NS_OK;
}
- // Whitelist about:home, since it doesn't have a base domain it would not
- // pass the ThirdPartyUtil check, though it should be able to use indexedDB.
- bool skipThirdPartyCheck = false;
-
+ // About URIs shouldn't be able to access IndexedDB unless they have the
+ // nsIAboutModule::ENABLE_INDEXED_DB flag set on them.
nsCOMPtr uri;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(principal->GetURI(getter_AddRefs(uri))));
+ MOZ_ASSERT(uri);
- bool isAbout;
+ bool isAbout = false;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(uri->SchemeIs("about", &isAbout)));
if (isAbout) {
nsCOMPtr module;
if (NS_SUCCEEDED(NS_GetAboutModule(uri, getter_AddRefs(module)))) {
uint32_t flags;
if (NS_SUCCEEDED(module->GetURIFlags(uri, &flags))) {
- skipThirdPartyCheck = flags & nsIAboutModule::ENABLE_INDEXED_DB;
+ if (!(flags & nsIAboutModule::ENABLE_INDEXED_DB)) {
+ return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
+ }
} else {
- NS_WARNING("GetURIFlags failed!");
+ return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
} else {
- NS_WARNING("NS_GetAboutModule failed!");
- }
- }
-
- if (!skipThirdPartyCheck) {
- nsCOMPtr thirdPartyUtil =
- do_GetService(THIRDPARTYUTIL_CONTRACTID);
- MOZ_ASSERT(thirdPartyUtil);
-
- bool isThirdParty;
- if (NS_WARN_IF(NS_FAILED(
- thirdPartyUtil->IsThirdPartyWindow(aWindow,
- nullptr,
- &isThirdParty)))) {
- return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
- }
-
- if (isThirdParty) {
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
}
principal.forget(aPrincipal);
return NS_OK;
}
diff --git a/dom/indexedDB/test/test_third_party.html b/dom/indexedDB/test/test_third_party.html
--- a/dom/indexedDB/test/test_third_party.html
+++ b/dom/indexedDB/test/test_third_party.html
@@ -5,21 +5,41 @@
Aquileo | Indexed Database Test