зеркало из https://github.com/mozilla/gecko-dev.git
Bug 940273 - Part 6 - Expose Service Worker Cache on workers as self.caches. r=ehsan
This commit is contained in:
Родитель
bc355cdce2
Коммит
8bf704b7d2
|
@ -36,6 +36,12 @@ partial interface WorkerGlobalScope {
|
|||
readonly attribute WorkerNavigator navigator;
|
||||
};
|
||||
|
||||
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#self-caches
|
||||
partial interface WorkerGlobalScope {
|
||||
[Throws, Func="mozilla::dom::cache::CacheStorage::PrefEnabled"]
|
||||
readonly attribute CacheStorage caches;
|
||||
};
|
||||
|
||||
WorkerGlobalScope implements WindowTimers;
|
||||
WorkerGlobalScope implements WindowBase64;
|
||||
WorkerGlobalScope implements GlobalFetch;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
|
||||
#include "mozilla/dom/SharedWorkerGlobalScopeBinding.h"
|
||||
#include "mozilla/dom/cache/CacheStorage.h"
|
||||
#include "mozilla/dom/indexedDB/IDBFactory.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
@ -45,6 +46,7 @@ using namespace mozilla;
|
|||
using namespace mozilla::dom;
|
||||
USING_WORKERS_NAMESPACE
|
||||
|
||||
using mozilla::dom::cache::CacheStorage;
|
||||
using mozilla::dom::indexedDB::IDBFactory;
|
||||
using mozilla::ipc::PrincipalInfo;
|
||||
|
||||
|
@ -71,6 +73,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(WorkerGlobalScope,
|
|||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLocation)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mNavigator)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mIndexedDB)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCacheStorage)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(WorkerGlobalScope,
|
||||
|
@ -81,6 +84,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(WorkerGlobalScope,
|
|||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLocation)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mNavigator)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mIndexedDB)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCacheStorage)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(WorkerGlobalScope,
|
||||
|
@ -116,6 +120,19 @@ WorkerGlobalScope::GetConsole()
|
|||
return mConsole;
|
||||
}
|
||||
|
||||
already_AddRefed<CacheStorage>
|
||||
WorkerGlobalScope::GetCaches(ErrorResult& aRv)
|
||||
{
|
||||
if (!mCacheStorage) {
|
||||
MOZ_ASSERT(mWorkerPrivate);
|
||||
mCacheStorage = CacheStorage::CreateOnWorker(cache::DEFAULT_NAMESPACE, this,
|
||||
mWorkerPrivate, aRv);
|
||||
}
|
||||
|
||||
nsRefPtr<CacheStorage> ref = mCacheStorage;
|
||||
return ref.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<WorkerLocation>
|
||||
WorkerGlobalScope::Location()
|
||||
{
|
||||
|
|
|
@ -20,6 +20,12 @@ class Function;
|
|||
class Promise;
|
||||
class RequestOrUSVString;
|
||||
|
||||
namespace cache {
|
||||
|
||||
class CacheStorage;
|
||||
|
||||
} // namespace cache
|
||||
|
||||
namespace indexedDB {
|
||||
|
||||
class IDBFactory;
|
||||
|
@ -48,6 +54,7 @@ class WorkerGlobalScope : public DOMEventTargetHelper,
|
|||
nsRefPtr<WorkerNavigator> mNavigator;
|
||||
nsRefPtr<Performance> mPerformance;
|
||||
nsRefPtr<IDBFactory> mIndexedDB;
|
||||
nsRefPtr<cache::CacheStorage> mCacheStorage;
|
||||
|
||||
protected:
|
||||
WorkerPrivate* mWorkerPrivate;
|
||||
|
@ -141,6 +148,9 @@ public:
|
|||
|
||||
already_AddRefed<IDBFactory>
|
||||
GetIndexedDB(ErrorResult& aErrorResult);
|
||||
|
||||
already_AddRefed<cache::CacheStorage>
|
||||
GetCaches(ErrorResult& aRv);
|
||||
};
|
||||
|
||||
class DedicatedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope
|
||||
|
|
|
@ -84,6 +84,10 @@ var interfaceNamesInGlobalScope =
|
|||
"Blob",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{ name: "BroadcastChannel", pref: "dom.broadcastChannel.enabled" },
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{ name: "Cache", pref: "dom.caches.enabled" },
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
{ name: "CacheStorage", pref: "dom.caches.enabled" },
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
"DedicatedWorkerGlobalScope",
|
||||
// IMPORTANT: Do not change this list without review from a DOM peer!
|
||||
|
|
Загрузка…
Ссылка в новой задаче