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
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#include "nsIIPCBackgroundChildCreateCallback.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;
|
|
|
|
|
|
|
|
namespace workers {
|
|
|
|
class WorkerPrivate;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace workers
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
namespace cache {
|
|
|
|
|
|
|
|
class CacheStorageChild;
|
2016-06-23 11:53:14 +03:00
|
|
|
class CacheWorkerHolder;
|
2015-03-02 16:20:00 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class CacheStorage final : public nsIIPCBackgroundChildCreateCallback
|
2015-03-22 09:52:12 +03:00
|
|
|
, public nsWrapperCache
|
|
|
|
, public TypeUtils
|
2015-03-02 16:20:00 +03:00
|
|
|
{
|
|
|
|
typedef mozilla::ipc::PBackgroundChild PBackgroundChild;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static already_AddRefed<CacheStorage>
|
|
|
|
CreateOnMainThread(Namespace aNamespace, nsIGlobalObject* aGlobal,
|
2015-07-16 00:02:17 +03:00
|
|
|
nsIPrincipal* aPrincipal, bool aStorageDisabled,
|
2015-06-28 06:19:24 +03:00
|
|
|
bool aForceTrustedOrigin, ErrorResult& aRv);
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
static already_AddRefed<CacheStorage>
|
|
|
|
CreateOnWorker(Namespace aNamespace, nsIGlobalObject* aGlobal,
|
|
|
|
workers::WorkerPrivate* aWorkerPrivate, ErrorResult& aRv);
|
|
|
|
|
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
|
|
|
|
already_AddRefed<Promise> Match(const RequestOrUSVString& aRequest,
|
|
|
|
const CacheQueryOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
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
|
|
|
|
static bool PrefEnabled(JSContext* aCx, JSObject* aObj);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
// nsIIPCbackgroundChildCreateCallback methods
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ActorCreated(PBackgroundChild* aActor) override;
|
|
|
|
virtual void ActorFailed() 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,
|
|
|
|
CacheWorkerHolder* aWorkerHolder);
|
2015-06-27 05:36:39 +03:00
|
|
|
explicit CacheStorage(nsresult aFailureResult);
|
2015-03-02 16:20:00 +03:00
|
|
|
~CacheStorage();
|
|
|
|
|
|
|
|
void MaybeRunPendingRequests();
|
|
|
|
|
|
|
|
const Namespace mNamespace;
|
|
|
|
nsCOMPtr<nsIGlobalObject> mGlobal;
|
|
|
|
UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
|
2016-06-23 11:53:14 +03:00
|
|
|
RefPtr<CacheWorkerHolder> mWorkerHolder;
|
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
|
|
|
|
|
|
|
struct Entry;
|
|
|
|
nsTArray<nsAutoPtr<Entry>> mPendingRequests;
|
|
|
|
|
2015-06-27 05:36:39 +03:00
|
|
|
nsresult mStatus;
|
2015-03-02 16:20:00 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(CacheStorage,
|
|
|
|
nsIIPCBackgroundChildCreateCallback)
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cache
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_cache_CacheStorage_h
|