2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2013-04-15 16:38:48 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
#ifndef mozilla_dom_Storage_h
|
|
|
|
#define mozilla_dom_Storage_h
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2013-06-05 20:15:48 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-07-23 09:07:12 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2016-10-03 17:10:27 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-04-15 16:38:48 +04:00
|
|
|
#include "nsIDOMStorage.h"
|
2014-07-23 09:07:12 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsWeakReference.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
|
|
|
|
class nsIPrincipal;
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowInner;
|
2013-04-15 16:38:48 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2017-05-17 08:01:12 +03:00
|
|
|
class Storage : public nsIDOMStorage
|
|
|
|
, public nsWrapperCache
|
2013-04-15 16:38:48 +04:00
|
|
|
{
|
2014-07-23 09:07:12 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2017-01-04 16:53:01 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Storage,
|
2014-07-23 09:07:12 +04:00
|
|
|
nsIDOMStorage)
|
|
|
|
|
2017-05-17 08:01:12 +03:00
|
|
|
Storage(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal);
|
2014-07-23 09:07:12 +04:00
|
|
|
|
2017-05-17 08:01:14 +03:00
|
|
|
enum StorageType {
|
|
|
|
eSessionStorage,
|
|
|
|
eLocalStorage,
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual StorageType Type() const = 0;
|
|
|
|
|
2017-05-17 08:01:14 +03:00
|
|
|
virtual bool IsForkOf(const Storage* aStorage) const = 0;
|
|
|
|
|
2017-05-17 08:01:12 +03:00
|
|
|
virtual int64_t GetOriginQuotaUsage() const = 0;
|
2014-07-23 09:07:12 +04:00
|
|
|
|
2017-05-17 08:01:14 +03:00
|
|
|
nsIPrincipal*
|
|
|
|
Principal() const
|
|
|
|
{
|
|
|
|
return mPrincipal;
|
|
|
|
}
|
|
|
|
|
2014-07-23 09:07:12 +04:00
|
|
|
// WebIDL
|
2017-01-04 16:53:01 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2014-07-23 09:07:12 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* GetParentObject() const
|
2014-07-23 09:07:12 +04:00
|
|
|
{
|
|
|
|
return mWindow;
|
|
|
|
}
|
|
|
|
|
2017-05-17 08:01:12 +03:00
|
|
|
virtual uint32_t
|
|
|
|
GetLength(nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) = 0;
|
2017-05-04 15:29:36 +03:00
|
|
|
|
2017-05-17 08:01:12 +03:00
|
|
|
virtual void
|
|
|
|
Key(uint32_t aIndex, nsAString& aResult,
|
|
|
|
nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) = 0;
|
2014-07-23 09:07:12 +04:00
|
|
|
|
2017-05-17 08:01:12 +03:00
|
|
|
virtual void
|
|
|
|
GetItem(const nsAString& aKey, nsAString& aResult,
|
|
|
|
nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) = 0;
|
2014-07-23 09:07:12 +04:00
|
|
|
|
2017-05-17 08:01:12 +03:00
|
|
|
virtual void
|
|
|
|
GetSupportedNames(nsTArray<nsString>& aKeys) = 0;
|
2014-07-23 09:07:12 +04:00
|
|
|
|
|
|
|
void NamedGetter(const nsAString& aKey, bool& aFound, nsAString& aResult,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2015-05-03 22:32:33 +03:00
|
|
|
ErrorResult& aRv)
|
2014-07-23 09:07:12 +04:00
|
|
|
{
|
2016-10-03 17:10:27 +03:00
|
|
|
GetItem(aKey, aResult, aSubjectPrincipal, aRv);
|
2014-07-23 09:07:12 +04:00
|
|
|
aFound = !aResult.IsVoid();
|
|
|
|
}
|
|
|
|
|
2017-05-17 08:01:12 +03:00
|
|
|
virtual void
|
|
|
|
SetItem(const nsAString& aKey, const nsAString& aValue,
|
|
|
|
nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) = 0;
|
2014-07-23 09:07:12 +04:00
|
|
|
|
|
|
|
void NamedSetter(const nsAString& aKey, const nsAString& aValue,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2014-07-23 09:07:12 +04:00
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
2016-10-03 17:10:27 +03:00
|
|
|
SetItem(aKey, aValue, aSubjectPrincipal, aRv);
|
2014-07-23 09:07:12 +04:00
|
|
|
}
|
|
|
|
|
2017-05-17 08:01:12 +03:00
|
|
|
virtual void
|
|
|
|
RemoveItem(const nsAString& aKey, nsIPrincipal& aSubjectPrincipal,
|
|
|
|
ErrorResult& aRv) = 0;
|
2014-07-23 09:07:12 +04:00
|
|
|
|
2016-10-03 17:10:27 +03:00
|
|
|
void NamedDeleter(const nsAString& aKey, bool& aFound,
|
2016-10-11 04:07:48 +03:00
|
|
|
nsIPrincipal& aSubjectPrincipal,
|
2016-10-03 17:10:27 +03:00
|
|
|
ErrorResult& aRv)
|
2014-07-23 09:07:12 +04:00
|
|
|
{
|
2016-10-03 17:10:27 +03:00
|
|
|
RemoveItem(aKey, aSubjectPrincipal, aRv);
|
2014-07-23 09:07:12 +04:00
|
|
|
|
2015-04-27 16:18:52 +03:00
|
|
|
aFound = !aRv.ErrorCodeIs(NS_SUCCESS_DOM_NO_OPERATION);
|
2014-07-23 09:07:12 +04:00
|
|
|
}
|
|
|
|
|
2017-05-17 08:01:12 +03:00
|
|
|
virtual void
|
|
|
|
Clear(nsIPrincipal& aSubjectPrincipal, ErrorResult& aRv) = 0;
|
|
|
|
|
2017-05-17 08:01:15 +03:00
|
|
|
bool IsSessionOnly() const { return mIsSessionOnly; }
|
2017-05-17 08:01:12 +03:00
|
|
|
|
2017-05-17 08:01:14 +03:00
|
|
|
static void
|
|
|
|
NotifyChange(Storage* aStorage, nsIPrincipal* aPrincipal,
|
|
|
|
const nsAString& aKey, const nsAString& aOldValue,
|
|
|
|
const nsAString& aNewValue, const char16_t* aStorageType,
|
|
|
|
const nsAString& aDocumentURI, bool aIsPrivate,
|
|
|
|
bool aImmediateDispatch);
|
|
|
|
|
2017-05-17 08:01:12 +03:00
|
|
|
protected:
|
|
|
|
virtual ~Storage();
|
|
|
|
|
2017-05-17 08:01:15 +03:00
|
|
|
// 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);
|
|
|
|
|
2017-05-17 08:01:12 +03:00
|
|
|
private:
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2017-05-17 08:01:15 +03:00
|
|
|
|
|
|
|
// 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;
|
2017-05-17 08:01:12 +03:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2013-04-15 16:38:48 +04:00
|
|
|
|
2017-01-04 16:53:01 +03:00
|
|
|
#endif // mozilla_dom_Storage_h
|