2015-03-02 13:20:00 +00: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: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_cache_CacheStorage_h
|
|
|
|
#define mozilla_dom_cache_CacheStorage_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/cache/Types.h"
|
|
|
|
#include "mozilla/dom/cache/TypeUtils.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
|
|
|
|
class nsIGlobalObject;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
|
|
|
namespace ipc {
|
|
|
|
class PrincipalInfo;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace ipc
|
2015-03-02 13:20:00 +00:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2017-01-12 01:23:37 +00:00
|
|
|
enum class CacheStorageNamespace : uint8_t;
|
2015-03-02 13:20:00 +00:00
|
|
|
class Promise;
|
2018-01-31 07:24:08 +00:00
|
|
|
class WorkerPrivate;
|
2015-03-02 13:20:00 +00:00
|
|
|
|
|
|
|
namespace cache {
|
|
|
|
|
|
|
|
class CacheStorageChild;
|
2016-06-23 08:53:14 +00:00
|
|
|
class CacheWorkerHolder;
|
2015-03-02 13:20:00 +00:00
|
|
|
|
2017-10-24 10:02:40 +00:00
|
|
|
class CacheStorage final : public nsISupports
|
2015-03-22 06:52:12 +00:00
|
|
|
, public nsWrapperCache
|
|
|
|
, public TypeUtils
|
2015-03-02 13:20:00 +00:00
|
|
|
{
|
|
|
|
typedef mozilla::ipc::PBackgroundChild PBackgroundChild;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static already_AddRefed<CacheStorage>
|
|
|
|
CreateOnMainThread(Namespace aNamespace, nsIGlobalObject* aGlobal,
|
2015-07-15 21:02:17 +00:00
|
|
|
nsIPrincipal* aPrincipal, bool aStorageDisabled,
|
2015-06-28 03:19:24 +00:00
|
|
|
bool aForceTrustedOrigin, ErrorResult& aRv);
|
2015-03-02 13:20:00 +00:00
|
|
|
|
|
|
|
static already_AddRefed<CacheStorage>
|
|
|
|
CreateOnWorker(Namespace aNamespace, nsIGlobalObject* aGlobal,
|
2018-01-31 07:24:08 +00:00
|
|
|
WorkerPrivate* aWorkerPrivate, ErrorResult& aRv);
|
2015-03-02 13:20:00 +00:00
|
|
|
|
2015-08-31 21:26:30 +00:00
|
|
|
static bool
|
|
|
|
DefineCaches(JSContext* aCx, JS::Handle<JSObject*> aGlobal);
|
|
|
|
|
2015-03-02 13:20:00 +00:00
|
|
|
// webidl interface methods
|
2017-08-11 01:04:55 +00:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
Match(JSContext* aCx, const RequestOrUSVString& aRequest,
|
|
|
|
const CacheQueryOptions& aOptions, ErrorResult& aRv);
|
2015-03-02 13:20:00 +00:00
|
|
|
already_AddRefed<Promise> Has(const nsAString& aKey, ErrorResult& aRv);
|
|
|
|
already_AddRefed<Promise> Open(const nsAString& aKey, ErrorResult& aRv);
|
|
|
|
already_AddRefed<Promise> Delete(const nsAString& aKey, ErrorResult& aRv);
|
|
|
|
already_AddRefed<Promise> Keys(ErrorResult& aRv);
|
|
|
|
|
2015-05-05 22:45:36 +00:00
|
|
|
// chrome-only webidl interface methods
|
|
|
|
static already_AddRefed<CacheStorage>
|
|
|
|
Constructor(const GlobalObject& aGlobal, CacheStorageNamespace aNamespace,
|
|
|
|
nsIPrincipal* aPrincipal, ErrorResult& aRv);
|
|
|
|
|
2015-03-02 13:20:00 +00:00
|
|
|
// binding methods
|
|
|
|
nsISupports* GetParentObject() const;
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aContext, JS::Handle<JSObject*> aGivenProto) override;
|
2015-03-02 13:20:00 +00:00
|
|
|
|
|
|
|
// Called when CacheStorageChild actor is being destroyed
|
|
|
|
void DestroyInternal(CacheStorageChild* aActor);
|
|
|
|
|
|
|
|
// TypeUtils methods
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsIGlobalObject* GetGlobalObject() const override;
|
2015-03-02 13:20:00 +00:00
|
|
|
#ifdef DEBUG
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void AssertOwningThread() const override;
|
2015-03-02 13:20:00 +00:00
|
|
|
#endif
|
|
|
|
|
2016-05-15 17:32:09 +00:00
|
|
|
virtual mozilla::ipc::PBackgroundChild*
|
|
|
|
GetIPCManager() override;
|
2015-03-22 06:52:12 +00:00
|
|
|
|
2015-03-02 13:20:00 +00:00
|
|
|
private:
|
|
|
|
CacheStorage(Namespace aNamespace, nsIGlobalObject* aGlobal,
|
2016-06-23 08:53:14 +00:00
|
|
|
const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
|
|
|
|
CacheWorkerHolder* aWorkerHolder);
|
2015-06-27 02:36:39 +00:00
|
|
|
explicit CacheStorage(nsresult aFailureResult);
|
2015-03-02 13:20:00 +00:00
|
|
|
~CacheStorage();
|
|
|
|
|
2017-10-24 10:02:40 +00:00
|
|
|
struct Entry;
|
|
|
|
void RunRequest(nsAutoPtr<Entry>&& aEntry);
|
2015-03-02 13:20:00 +00:00
|
|
|
|
2017-09-15 19:25:41 +00:00
|
|
|
OpenMode
|
|
|
|
GetOpenMode() const;
|
|
|
|
|
2015-03-02 13:20:00 +00:00
|
|
|
const Namespace mNamespace;
|
|
|
|
nsCOMPtr<nsIGlobalObject> mGlobal;
|
|
|
|
UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
|
2015-04-16 19:00:15 +00:00
|
|
|
|
|
|
|
// weak ref cleared in DestroyInternal
|
2015-03-02 13:20:00 +00:00
|
|
|
CacheStorageChild* mActor;
|
2015-04-16 19:00:15 +00:00
|
|
|
|
2015-06-27 02:36:39 +00:00
|
|
|
nsresult mStatus;
|
2015-03-02 13:20:00 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2017-10-24 10:02:40 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CacheStorage)
|
2015-03-02 13:20:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cache
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_cache_CacheStorage_h
|