Bug 1145744 - Update CacheStorage to use common StorageAllowedForWindow logic, r=bkelly

This commit is contained in:
Michael Layzell 2015-07-15 17:02:17 -04:00
Родитель 492771d764
Коммит f8dabc3197
3 изменённых файлов: 18 добавлений и 5 удалений

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

@ -11073,9 +11073,16 @@ nsGlobalWindow::GetCaches(ErrorResult& aRv)
bool forceTrustedOrigin =
GetOuterWindowInternal()->GetServiceWorkersTestingEnabled();
nsContentUtils::StorageAccess access =
nsContentUtils::StorageAllowedForWindow(this);
// We don't block the cache API when being told to only allow storage for the
// current session.
bool storageBlocked = access <= nsContentUtils::StorageAccess::ePrivateBrowsing;
mCacheStorage = CacheStorage::CreateOnMainThread(cache::DEFAULT_NAMESPACE,
this, GetPrincipal(),
IsPrivateBrowsing(),
storageBlocked,
forceTrustedOrigin, aRv);
}

12
dom/cache/CacheStorage.cpp поставляемый
Просмотреть файл

@ -145,15 +145,15 @@ IsTrusted(const PrincipalInfo& aPrincipalInfo, bool aTestingPrefEnabled)
// static
already_AddRefed<CacheStorage>
CacheStorage::CreateOnMainThread(Namespace aNamespace, nsIGlobalObject* aGlobal,
nsIPrincipal* aPrincipal, bool aPrivateBrowsing,
nsIPrincipal* aPrincipal, bool aStorageDisabled,
bool aForceTrustedOrigin, ErrorResult& aRv)
{
MOZ_ASSERT(aGlobal);
MOZ_ASSERT(aPrincipal);
MOZ_ASSERT(NS_IsMainThread());
if (aPrivateBrowsing) {
NS_WARNING("CacheStorage not supported during private browsing.");
if (aStorageDisabled) {
NS_WARNING("CacheStorage has been disabled.");
nsRefPtr<CacheStorage> ref = new CacheStorage(NS_ERROR_DOM_SECURITY_ERR);
return ref.forget();
}
@ -189,6 +189,12 @@ CacheStorage::CreateOnWorker(Namespace aNamespace, nsIGlobalObject* aGlobal,
MOZ_ASSERT(aWorkerPrivate);
aWorkerPrivate->AssertIsOnWorkerThread();
if (!aWorkerPrivate->IsStorageAllowed()) {
NS_WARNING("CacheStorage is not allowed.");
nsRefPtr<CacheStorage> ref = new CacheStorage(NS_ERROR_DOM_SECURITY_ERR);
return ref.forget();
}
if (aWorkerPrivate->IsInPrivateBrowsing()) {
NS_WARNING("CacheStorage not supported during private browsing.");
nsRefPtr<CacheStorage> ref = new CacheStorage(NS_ERROR_DOM_SECURITY_ERR);

2
dom/cache/CacheStorage.h поставляемый
Просмотреть файл

@ -49,7 +49,7 @@ class CacheStorage final : public nsIIPCBackgroundChildCreateCallback
public:
static already_AddRefed<CacheStorage>
CreateOnMainThread(Namespace aNamespace, nsIGlobalObject* aGlobal,
nsIPrincipal* aPrincipal, bool aPrivateBrowsing,
nsIPrincipal* aPrincipal, bool aStorageDisabled,
bool aForceTrustedOrigin, ErrorResult& aRv);
static already_AddRefed<CacheStorage>