Bug 940273 - Part 5 - Expose Service Worker Cache as window.caches when pref is enabled. r=ehsan

This commit is contained in:
Ben Kelly 2015-03-02 14:22:00 +01:00
Родитель f9064fc636
Коммит bc355cdce2
4 изменённых файлов: 31 добавлений и 0 удалений

Просмотреть файл

@ -207,6 +207,7 @@
#include "mozilla/dom/AudioContext.h"
#include "mozilla/dom/BlobBinding.h"
#include "mozilla/dom/BrowserElementDictionariesBinding.h"
#include "mozilla/dom/cache/CacheStorage.h"
#include "mozilla/dom/Console.h"
#include "mozilla/dom/Fetch.h"
#include "mozilla/dom/FunctionBinding.h"
@ -260,6 +261,7 @@ using namespace mozilla::dom;
using namespace mozilla::dom::ipc;
using mozilla::TimeStamp;
using mozilla::TimeDuration;
using mozilla::dom::cache::CacheStorage;
using mozilla::dom::indexedDB::IDBFactory;
nsGlobalWindow::WindowByIdTable *nsGlobalWindow::sWindowsById = nullptr;
@ -1786,6 +1788,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGlobalWindow)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepads)
#endif
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mCacheStorage)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRDevices)
// Traverse stuff from nsPIDOMWindow
@ -1849,6 +1852,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGamepads)
#endif
NS_IMPL_CYCLE_COLLECTION_UNLINK(mCacheStorage)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mVRDevices)
// Unlink stuff from nsPIDOMWindow
@ -10719,6 +10723,18 @@ nsGlobalWindow::GetInterface(JSContext* aCx, nsIJSID* aIID,
dom::GetInterface(aCx, this, aIID, aRetval, aError);
}
already_AddRefed<CacheStorage>
nsGlobalWindow::GetCaches(ErrorResult& aRv)
{
if (!mCacheStorage) {
mCacheStorage = CacheStorage::CreateOnMainThread(cache::DEFAULT_NAMESPACE,
this, GetPrincipal(), aRv);
}
nsRefPtr<CacheStorage> ref = mCacheStorage;
return ref.forget();
}
void
nsGlobalWindow::FireOfflineStatusEventIfChanged()
{

Просмотреть файл

@ -115,6 +115,9 @@ class RequestOrUSVString;
class Selection;
class SpeechSynthesis;
class WakeLock;
namespace cache {
class CacheStorage;
} // namespace cache
namespace indexedDB {
class IDBFactory;
} // namespace indexedDB
@ -878,6 +881,7 @@ protected:
public:
void Alert(mozilla::ErrorResult& aError);
void Alert(const nsAString& aMessage, mozilla::ErrorResult& aError);
already_AddRefed<mozilla::dom::cache::CacheStorage> GetCaches(mozilla::ErrorResult& aRv);
bool Confirm(const nsAString& aMessage, mozilla::ErrorResult& aError);
already_AddRefed<mozilla::dom::Promise> Fetch(const mozilla::dom::RequestOrUSVString& aInput,
const mozilla::dom::RequestInit& aInit,
@ -1552,6 +1556,7 @@ protected:
nsString mDefaultStatus;
nsGlobalWindowObserver* mObserver; // Inner windows only.
nsRefPtr<mozilla::dom::Crypto> mCrypto;
nsRefPtr<mozilla::dom::cache::CacheStorage> mCacheStorage;
nsRefPtr<mozilla::dom::Console> mConsole;
// We need to store an nsISupports pointer to this object because the
// mozilla::dom::External class doesn't exist on b2g and using the type

Просмотреть файл

@ -196,6 +196,10 @@ var interfaceNamesInGlobalScope =
{name: "BoxObject", xbl: true},
// 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!
{name: "CallEvent", b2g: true, pref: "dom.telephony.enabled"},
// IMPORTANT: Do not change this list without review from a DOM peer!

Просмотреть файл

@ -250,6 +250,12 @@ interface WindowModal {
};
Window implements WindowModal;
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#self-caches
partial interface Window {
[Throws, Func="mozilla::dom::cache::CacheStorage::PrefEnabled"]
readonly attribute CacheStorage caches;
};
// Mozilla-specific stuff
partial interface Window {
//[NewObject, Throws] CSSStyleDeclaration getDefaultComputedStyle(Element elt, optional DOMString pseudoElt = "");