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;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2015-05-06 01:45:36 +03:00
|
|
|
enum class CacheStorageNamespace : uint32_t;
|
2015-03-02 16:20:00 +03:00
|
|
|
class Promise;
|
|
|
|
|
|
|
|
namespace workers {
|
|
|
|
class WorkerPrivate;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace cache {
|
|
|
|
|
|
|
|
class CacheStorageChild;
|
|
|
|
class Feature;
|
|
|
|
|
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-06-27 05:36:40 +03:00
|
|
|
nsIPrincipal* aPrincipal, bool aPrivateBrowsing,
|
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);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2015-03-22 09:52:12 +03:00
|
|
|
virtual CachePushStreamChild*
|
|
|
|
CreatePushStream(nsIAsyncInputStream* aStream) override;
|
|
|
|
|
2015-03-02 16:20:00 +03:00
|
|
|
private:
|
|
|
|
CacheStorage(Namespace aNamespace, nsIGlobalObject* aGlobal,
|
|
|
|
const mozilla::ipc::PrincipalInfo& aPrincipalInfo, Feature* aFeature);
|
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;
|
|
|
|
nsRefPtr<Feature> mFeature;
|
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
|