зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1322316 - Split SessionStorage and LocalStorage implementation - part 10 - Move IsSessionOnly() in Storage class, r=asuth
This commit is contained in:
Родитель
44f653e013
Коммит
ea8fdbd1e1
|
@ -11120,7 +11120,7 @@ nsGlobalWindow::GetSessionStorage(ErrorResult& aError)
|
|||
if (mSessionStorage) {
|
||||
MOZ_LOG(gDOMLeakPRLog, LogLevel::Debug,
|
||||
("nsGlobalWindow %p has %p sessionStorage", this, mSessionStorage.get()));
|
||||
bool canAccess = mSessionStorage->CanAccess(principal);
|
||||
bool canAccess = principal->Subsumes(mSessionStorage->Principal());
|
||||
NS_ASSERTION(canAccess,
|
||||
"This window owned sessionStorage "
|
||||
"that could not be accessed!");
|
||||
|
|
|
@ -54,7 +54,6 @@ LocalStorage::LocalStorage(nsPIDOMWindowInner* aWindow,
|
|||
, mCache(aCache)
|
||||
, mDocumentURI(aDocumentURI)
|
||||
, mIsPrivate(aIsPrivate)
|
||||
, mIsSessionOnly(false)
|
||||
{
|
||||
mCache->Preload();
|
||||
}
|
||||
|
@ -249,28 +248,6 @@ LocalStorage::ApplyEvent(StorageEvent* aStorageEvent)
|
|||
static const char kPermissionType[] = "cookie";
|
||||
static const char kStorageEnabled[] = "dom.storage.enabled";
|
||||
|
||||
bool
|
||||
LocalStorage::CanUseStorage(nsIPrincipal& aSubjectPrincipal)
|
||||
{
|
||||
// This method is responsible for correct setting of mIsSessionOnly.
|
||||
// It doesn't work with mIsPrivate flag at all, since it is checked
|
||||
// regardless mIsSessionOnly flag in DOMLocalStorageCache code.
|
||||
|
||||
if (!mozilla::Preferences::GetBool(kStorageEnabled)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsContentUtils::StorageAccess access =
|
||||
nsContentUtils::StorageAllowedForPrincipal(Principal());
|
||||
|
||||
if (access == nsContentUtils::StorageAccess::eDeny) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mIsSessionOnly = access <= nsContentUtils::StorageAccess::eSessionScoped;
|
||||
return CanAccess(&aSubjectPrincipal);
|
||||
}
|
||||
|
||||
bool
|
||||
LocalStorage::PrincipalEquals(nsIPrincipal* aPrincipal)
|
||||
{
|
||||
|
|
|
@ -76,7 +76,6 @@ public:
|
|||
ErrorResult& aRv) override;
|
||||
|
||||
bool IsPrivate() const { return mIsPrivate; }
|
||||
bool IsSessionOnly() const override { return mIsSessionOnly; }
|
||||
|
||||
// aStorage can be null if this method is called by ContentChild.
|
||||
//
|
||||
|
@ -99,16 +98,6 @@ public:
|
|||
void
|
||||
ApplyEvent(StorageEvent* aStorageEvent);
|
||||
|
||||
protected:
|
||||
// The method checks whether the caller can use a storage.
|
||||
// CanUseStorage is called before any DOM initiated operation
|
||||
// on a storage is about to happen and ensures that the storage's
|
||||
// session-only flag is properly set according the current settings.
|
||||
// It is an optimization since the privileges check and session only
|
||||
// state determination are complex and share the code (comes hand in
|
||||
// hand together).
|
||||
bool CanUseStorage(nsIPrincipal& aSubjectPrincipal);
|
||||
|
||||
private:
|
||||
~LocalStorage();
|
||||
|
||||
|
@ -126,11 +115,6 @@ private:
|
|||
// Whether this storage is running in private-browsing window.
|
||||
bool mIsPrivate : 1;
|
||||
|
||||
// Whether storage is set to persist data only per session, may change
|
||||
// dynamically and is set by CanUseStorage function that is called
|
||||
// before any operation on the storage.
|
||||
bool mIsSessionOnly : 1;
|
||||
|
||||
void BroadcastChangeNotification(const nsSubstring& aKey,
|
||||
const nsSubstring& aOldValue,
|
||||
const nsSubstring& aNewValue);
|
||||
|
|
|
@ -167,27 +167,6 @@ SessionStorage::Clear(nsIPrincipal& aSubjectPrincipal,
|
|||
BroadcastChangeNotification(NullString(), NullString(), NullString());
|
||||
}
|
||||
|
||||
bool
|
||||
SessionStorage::CanUseStorage(nsIPrincipal& aSubjectPrincipal)
|
||||
{
|
||||
// This method is responsible for correct setting of mIsSessionOnly.
|
||||
// It doesn't work with mIsPrivate flag at all, since it is checked
|
||||
// regardless mIsSessionOnly flag in LocalStorageCache code.
|
||||
|
||||
if (!mozilla::Preferences::GetBool("dom.storage.enabled")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsContentUtils::StorageAccess access =
|
||||
nsContentUtils::StorageAllowedForPrincipal(Principal());
|
||||
|
||||
if (access == nsContentUtils::StorageAccess::eDeny) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return CanAccess(&aSubjectPrincipal);
|
||||
}
|
||||
|
||||
void
|
||||
SessionStorage::BroadcastChangeNotification(const nsAString& aKey,
|
||||
const nsAString& aOldValue,
|
||||
|
|
|
@ -68,13 +68,9 @@ public:
|
|||
void Clear(nsIPrincipal& aSubjectPrincipal,
|
||||
ErrorResult& aRv) override;
|
||||
|
||||
bool IsSessionOnly() const override { return true; }
|
||||
|
||||
private:
|
||||
~SessionStorage();
|
||||
|
||||
bool CanUseStorage(nsIPrincipal& aSubjectPrincipal);
|
||||
|
||||
bool ProcessUsageDelta(int64_t aDelta);
|
||||
|
||||
void
|
||||
|
|
|
@ -27,6 +27,7 @@ NS_INTERFACE_MAP_END
|
|||
Storage::Storage(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal)
|
||||
: mWindow(aWindow)
|
||||
, mPrincipal(aPrincipal)
|
||||
, mIsSessionOnly(false)
|
||||
{
|
||||
MOZ_ASSERT(aPrincipal);
|
||||
}
|
||||
|
@ -35,9 +36,23 @@ Storage::~Storage()
|
|||
{}
|
||||
|
||||
bool
|
||||
Storage::CanAccess(nsIPrincipal* aPrincipal)
|
||||
Storage::CanUseStorage(nsIPrincipal& aSubjectPrincipal)
|
||||
{
|
||||
return !aPrincipal || aPrincipal->Subsumes(mPrincipal);
|
||||
// This method is responsible for correct setting of mIsSessionOnly.
|
||||
if (!mozilla::Preferences::GetBool(kStorageEnabled)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsContentUtils::StorageAccess access =
|
||||
nsContentUtils::StorageAllowedForPrincipal(Principal());
|
||||
|
||||
if (access == nsContentUtils::StorageAccess::eDeny) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mIsSessionOnly = access <= nsContentUtils::StorageAccess::eSessionScoped;
|
||||
|
||||
return aSubjectPrincipal.Subsumes(mPrincipal);
|
||||
}
|
||||
|
||||
/* virtual */ JSObject*
|
||||
|
|
|
@ -43,8 +43,6 @@ public:
|
|||
|
||||
virtual int64_t GetOriginQuotaUsage() const = 0;
|
||||
|
||||
virtual bool CanAccess(nsIPrincipal* aPrincipal);
|
||||
|
||||
nsIPrincipal*
|
||||
Principal() const
|
||||
{
|
||||
|
@ -109,7 +107,7 @@ public:
|
|||
virtual void
|
||||
Clear(nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) = 0;
|
||||
|
||||
virtual bool IsSessionOnly() const = 0;
|
||||
bool IsSessionOnly() const { return mIsSessionOnly; }
|
||||
|
||||
static void
|
||||
NotifyChange(Storage* aStorage, nsIPrincipal* aPrincipal,
|
||||
|
@ -121,9 +119,23 @@ public:
|
|||
protected:
|
||||
virtual ~Storage();
|
||||
|
||||
// The method checks whether the caller can use a storage.
|
||||
// CanUseStorage is called before any DOM initiated operation
|
||||
// on a storage is about to happen and ensures that the storage's
|
||||
// session-only flag is properly set according the current settings.
|
||||
// It is an optimization since the privileges check and session only
|
||||
// state determination are complex and share the code (comes hand in
|
||||
// hand together).
|
||||
bool CanUseStorage(nsIPrincipal& aSubjectPrincipal);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
|
||||
// Whether storage is set to persist data only per session, may change
|
||||
// dynamically and is set by CanUseStorage function that is called
|
||||
// before any operation on the storage.
|
||||
bool mIsSessionOnly : 1;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
Загрузка…
Ссылка в новой задаче