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