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 = bool forceTrustedOrigin =
GetOuterWindowInternal()->GetServiceWorkersTestingEnabled(); 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, mCacheStorage = CacheStorage::CreateOnMainThread(cache::DEFAULT_NAMESPACE,
this, GetPrincipal(), this, GetPrincipal(),
IsPrivateBrowsing(), storageBlocked,
forceTrustedOrigin, aRv); forceTrustedOrigin, aRv);
} }

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

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