diff --git a/browser/components/about/AboutRedirector.cpp b/browser/components/about/AboutRedirector.cpp index f1f65e8a25ad..3f7d4128814f 100644 --- a/browser/components/about/AboutRedirector.cpp +++ b/browser/components/about/AboutRedirector.cpp @@ -9,6 +9,7 @@ #include "nsNetUtil.h" #include "nsIScriptSecurityManager.h" #include "mozilla/ArrayUtils.h" +#include "nsDOMString.h" namespace mozilla { namespace browser { @@ -19,6 +20,7 @@ struct RedirEntry { const char* id; const char* url; uint32_t flags; + const char* idbOriginPostfix; }; /* @@ -78,7 +80,8 @@ static RedirEntry kRedirMap[] = { #endif { "home", "chrome://browser/content/abouthome/aboutHome.xhtml", nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | - nsIAboutModule::ALLOW_SCRIPT }, + nsIAboutModule::ALLOW_SCRIPT | + nsIAboutModule::ENABLE_INDEXED_DB }, { "newtab", "chrome://browser/content/newtab/newTab.xul", nsIAboutModule::ALLOW_SCRIPT }, { "permissions", "chrome://browser/content/preferences/aboutPermissions.xul", @@ -101,11 +104,15 @@ static RedirEntry kRedirMap[] = { { "loopconversation", "chrome://browser/content/loop/conversation.html", nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | nsIAboutModule::ALLOW_SCRIPT | - nsIAboutModule::HIDE_FROM_ABOUTABOUT }, + nsIAboutModule::HIDE_FROM_ABOUTABOUT | + nsIAboutModule::ENABLE_INDEXED_DB }, { "looppanel", "chrome://browser/content/loop/panel.html", nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | nsIAboutModule::ALLOW_SCRIPT | - nsIAboutModule::HIDE_FROM_ABOUTABOUT }, + nsIAboutModule::HIDE_FROM_ABOUTABOUT | + nsIAboutModule::ENABLE_INDEXED_DB, + // Shares an IndexedDB origin with about:loopconversation. + "loopconversation" }, #endif }; static const int kRedirTotal = ArrayLength(kRedirMap); @@ -174,6 +181,29 @@ AboutRedirector::GetURIFlags(nsIURI *aURI, uint32_t *result) return NS_ERROR_ILLEGAL_VALUE; } +NS_IMETHODIMP +AboutRedirector::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result) +{ + NS_ENSURE_ARG_POINTER(aURI); + + nsAutoCString name = GetAboutModuleName(aURI); + + for (int i = 0; i < kRedirTotal; i++) { + if (name.Equals(kRedirMap[i].id)) { + const char* postfix = kRedirMap[i].idbOriginPostfix; + if (!postfix) { + break; + } + + result.AssignASCII(postfix); + return NS_OK; + } + } + + SetDOMStringToNull(result); + return NS_ERROR_ILLEGAL_VALUE; +} + nsresult AboutRedirector::Create(nsISupports *aOuter, REFNSIID aIID, void **result) { diff --git a/docshell/base/nsAboutRedirector.cpp b/docshell/base/nsAboutRedirector.cpp index ff233ee1c11b..bc62441bf5b7 100644 --- a/docshell/base/nsAboutRedirector.cpp +++ b/docshell/base/nsAboutRedirector.cpp @@ -8,6 +8,7 @@ #include "nsNetUtil.h" #include "nsAboutProtocolUtils.h" #include "mozilla/ArrayUtils.h" +#include "nsDOMString.h" NS_IMPL_ISUPPORTS(nsAboutRedirector, nsIAboutModule) @@ -136,6 +137,13 @@ nsAboutRedirector::GetURIFlags(nsIURI *aURI, uint32_t *result) return NS_ERROR_ILLEGAL_VALUE; } +NS_IMETHODIMP +nsAboutRedirector::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result) +{ + SetDOMStringToNull(result); + return NS_ERROR_NOT_IMPLEMENTED; +} + nsresult nsAboutRedirector::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) { diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index f12f6c2fa4eb..50a38a519afc 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -68,6 +68,7 @@ #include "mozilla/MouseEvents.h" #include "AudioChannelService.h" #include "MessageEvent.h" +#include "nsAboutProtocolUtils.h" // Interfaces Needed #include "nsIFrame.h" @@ -10511,6 +10512,20 @@ nsGlobalWindow::GetLocalStorage(nsIDOMStorage ** aLocalStorage) return rv.ErrorCode(); } +static bool +GetIndexedDBEnabledForAboutURI(nsIURI *aURI) +{ + nsCOMPtr module; + nsresult rv = NS_GetAboutModule(aURI, getter_AddRefs(module)); + NS_ENSURE_SUCCESS(rv, false); + + uint32_t flags; + rv = module->GetURIFlags(aURI, &flags); + NS_ENSURE_SUCCESS(rv, false); + + return flags & nsIAboutModule::ENABLE_INDEXED_DB; +} + indexedDB::IDBFactory* nsGlobalWindow::GetIndexedDB(ErrorResult& aError) { @@ -10531,11 +10546,12 @@ nsGlobalWindow::GetIndexedDB(ErrorResult& aError) if (principal) { nsCOMPtr uri; principal->GetURI(getter_AddRefs(uri)); - bool isAbout = false; - if (uri && NS_SUCCEEDED(uri->SchemeIs("about", &isAbout)) && isAbout) { - nsAutoCString path; - skipThirdPartyCheck = NS_SUCCEEDED(uri->GetPath(path)) && - path.EqualsLiteral("home"); + + if (uri) { + bool isAbout = false; + if (NS_SUCCEEDED(uri->SchemeIs("about", &isAbout)) && isAbout) { + skipThirdPartyCheck = GetIndexedDBEnabledForAboutURI(uri); + } } } diff --git a/dom/quota/QuotaManager.cpp b/dom/quota/QuotaManager.cpp index 92d61d6b7d81..74813d55d1c0 100644 --- a/dom/quota/QuotaManager.cpp +++ b/dom/quota/QuotaManager.cpp @@ -36,6 +36,7 @@ #include "mozilla/Services.h" #include "nsAppDirectoryServiceDefs.h" #include "nsComponentManagerUtils.h" +#include "nsAboutProtocolUtils.h" #include "nsContentUtils.h" #include "nsCRTGlue.h" #include "nsDirectoryServiceUtils.h" @@ -2013,6 +2014,64 @@ QuotaManager::GetInfoFromURI(nsIURI* aURI, return NS_OK; } +static nsresult +TryGetInfoForAboutURI(nsIPrincipal* aPrincipal, + nsACString& aGroup, + nsACString& aASCIIOrigin, + StoragePrivilege* aPrivilege, + PersistenceType* aDefaultPersistenceType) +{ + NS_ASSERTION(aPrincipal, "Don't hand me a null principal!"); + + nsCOMPtr uri; + nsresult rv = aPrincipal->GetURI(getter_AddRefs(uri)); + NS_ENSURE_SUCCESS(rv, rv); + if (!uri) { + return NS_ERROR_NOT_AVAILABLE; + } + + bool isAbout; + rv = uri->SchemeIs("about", &isAbout); + NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && isAbout, NS_ERROR_FAILURE); + + nsCOMPtr module; + rv = NS_GetAboutModule(uri, getter_AddRefs(module)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr inner = NS_GetInnermostURI(uri); + NS_ENSURE_TRUE(inner, NS_ERROR_FAILURE); + + nsAutoString postfix; + rv = module->GetIndexedDBOriginPostfix(uri, postfix); + NS_ENSURE_SUCCESS(rv, rv); + + nsCString origin; + if (DOMStringIsNull(postfix)) { + rv = inner->GetSpec(origin); + NS_ENSURE_SUCCESS(rv, rv); + } else { + nsAutoCString scheme; + rv = inner->GetScheme(scheme); + NS_ENSURE_SUCCESS(rv, rv); + + origin = scheme + NS_LITERAL_CSTRING(":") + NS_ConvertUTF16toUTF8(postfix); + } + + ToLowerCase(origin); + aGroup.Assign(origin); + aASCIIOrigin.Assign(origin); + + if (aPrivilege) { + *aPrivilege = Content; + } + + if (aDefaultPersistenceType) { + *aDefaultPersistenceType = PERSISTENCE_TYPE_PERSISTENT; + } + + return NS_OK; +} + // static nsresult QuotaManager::GetInfoFromPrincipal(nsIPrincipal* aPrincipal, @@ -2024,6 +2083,14 @@ QuotaManager::GetInfoFromPrincipal(nsIPrincipal* aPrincipal, NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); NS_ASSERTION(aPrincipal, "Don't hand me a null principal!"); + if (aGroup && aASCIIOrigin) { + nsresult rv = TryGetInfoForAboutURI(aPrincipal, *aGroup, *aASCIIOrigin, + aPrivilege, aDefaultPersistenceType); + if (NS_SUCCEEDED(rv)) { + return NS_OK; + } + } + if (nsContentUtils::IsSystemPrincipal(aPrincipal)) { GetInfoForChrome(aGroup, aASCIIOrigin, aPrivilege, aDefaultPersistenceType); return NS_OK; diff --git a/netwerk/protocol/about/nsAboutBlank.cpp b/netwerk/protocol/about/nsAboutBlank.cpp index 85d1fb92b736..95cb51862d81 100644 --- a/netwerk/protocol/about/nsAboutBlank.cpp +++ b/netwerk/protocol/about/nsAboutBlank.cpp @@ -5,6 +5,7 @@ #include "nsAboutBlank.h" #include "nsStringStream.h" +#include "nsDOMString.h" #include "nsNetUtil.h" NS_IMPL_ISUPPORTS(nsAboutBlank, nsIAboutModule) @@ -36,6 +37,13 @@ nsAboutBlank::GetURIFlags(nsIURI *aURI, uint32_t *result) return NS_OK; } +NS_IMETHODIMP +nsAboutBlank::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result) +{ + SetDOMStringToNull(result); + return NS_ERROR_NOT_IMPLEMENTED; +} + nsresult nsAboutBlank::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) { diff --git a/netwerk/protocol/about/nsAboutBloat.cpp b/netwerk/protocol/about/nsAboutBloat.cpp index b997853ac404..ba1a95d53b1b 100644 --- a/netwerk/protocol/about/nsAboutBloat.cpp +++ b/netwerk/protocol/about/nsAboutBloat.cpp @@ -10,6 +10,7 @@ #include "nsAboutBloat.h" #include "nsStringStream.h" +#include "nsDOMString.h" #include "nsIURI.h" #include "nsCOMPtr.h" #include "nsNetUtil.h" @@ -124,6 +125,13 @@ nsAboutBloat::GetURIFlags(nsIURI *aURI, uint32_t *result) return NS_OK; } +NS_IMETHODIMP +nsAboutBloat::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result) +{ + SetDOMStringToNull(result); + return NS_ERROR_NOT_IMPLEMENTED; +} + nsresult nsAboutBloat::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) { diff --git a/netwerk/protocol/about/nsAboutCache.cpp b/netwerk/protocol/about/nsAboutCache.cpp index 2e5df23acb6c..7f1ca35f0b2f 100644 --- a/netwerk/protocol/about/nsAboutCache.cpp +++ b/netwerk/protocol/about/nsAboutCache.cpp @@ -12,6 +12,7 @@ #include "nsEscape.h" #include "nsAboutProtocolUtils.h" #include "nsPrintfCString.h" +#include "nsDOMString.h" #include "nsICacheStorageService.h" #include "nsICacheStorage.h" @@ -485,6 +486,13 @@ nsAboutCache::GetURIFlags(nsIURI *aURI, uint32_t *result) return NS_OK; } +NS_IMETHODIMP +nsAboutCache::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result) +{ + SetDOMStringToNull(result); + return NS_ERROR_NOT_IMPLEMENTED; +} + // static nsresult nsAboutCache::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) diff --git a/netwerk/protocol/about/nsAboutCacheEntry.cpp b/netwerk/protocol/about/nsAboutCacheEntry.cpp index c8c88c89fd86..74ae0f291579 100644 --- a/netwerk/protocol/about/nsAboutCacheEntry.cpp +++ b/netwerk/protocol/about/nsAboutCacheEntry.cpp @@ -7,6 +7,7 @@ #include "nsAboutCache.h" #include "nsICacheStorage.h" #include "CacheObserver.h" +#include "nsDOMString.h" #include "nsNetUtil.h" #include "prprf.h" #include "nsEscape.h" @@ -108,6 +109,13 @@ nsAboutCacheEntry::GetURIFlags(nsIURI *aURI, uint32_t *result) return NS_OK; } +NS_IMETHODIMP +nsAboutCacheEntry::GetIndexedDBOriginPostfix(nsIURI *aURI, nsAString &result) +{ + SetDOMStringToNull(result); + return NS_ERROR_NOT_IMPLEMENTED; +} + //----------------------------------------------------------------------------- // nsAboutCacheEntry diff --git a/netwerk/protocol/about/nsIAboutModule.idl b/netwerk/protocol/about/nsIAboutModule.idl index 7213ed32ffac..744dfbed567a 100644 --- a/netwerk/protocol/about/nsIAboutModule.idl +++ b/netwerk/protocol/about/nsIAboutModule.idl @@ -8,7 +8,7 @@ interface nsIURI; interface nsIChannel; -[scriptable, uuid(9575693c-60d9-4332-b6b8-6c29289339cb)] +[scriptable, uuid(1d5992c3-28b0-4ec1-9dbb-f5fde7f72199)] interface nsIAboutModule : nsISupports { /** @@ -41,12 +41,24 @@ interface nsIAboutModule : nsISupports */ const unsigned long HIDE_FROM_ABOUTABOUT = (1 << 2); + /** + * A flag that indicates whether this about: URI wants Indexed DB enabled. + */ + const unsigned long ENABLE_INDEXED_DB = (1 << 3); + /** * A method to get the flags that apply to a given about: URI. The URI * passed in is guaranteed to be one of the URIs that this module * registered to deal with. */ unsigned long getURIFlags(in nsIURI aURI); + + /** + * Returns the Indexed DB origin's postfix used for the given about: URI. + * If the postfix returned is null then the URI's path (e.g. "home" for + * about:home) will be used to construct the origin. + */ + DOMString getIndexedDBOriginPostfix(in nsIURI aURI); }; %{C++