Bug 1160138 P2 Add a [ChromeConstructor] to CacheStorage to support devtools. r=ehsan

This commit is contained in:
Ben Kelly 2015-05-05 15:45:36 -07:00
parent 6b203358e4
commit 125fa562ef
3 changed files with 38 additions and 1 deletions

View File

@ -314,6 +314,30 @@ CacheStorage::PrefEnabled(JSContext* aCx, JSObject* aObj)
return Cache::PrefEnabled(aCx, aObj);
}
// static
already_AddRefed<CacheStorage>
CacheStorage::Constructor(const GlobalObject& aGlobal,
CacheStorageNamespace aNamespace,
nsIPrincipal* aPrincipal, ErrorResult& aRv)
{
if (NS_WARN_IF(!NS_IsMainThread())) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
// TODO: remove Namespace in favor of CacheStorageNamespace
static_assert(DEFAULT_NAMESPACE == (uint32_t)CacheStorageNamespace::Content,
"Default namespace should match webidl Content enum");
static_assert(CHROME_ONLY_NAMESPACE == (uint32_t)CacheStorageNamespace::Chrome,
"Chrome namespace should match webidl Chrome enum");
static_assert(NUMBER_OF_NAMESPACES == (uint32_t)CacheStorageNamespace::EndGuard_,
"Number of namespace should match webidl endguard enum");
Namespace ns = static_cast<Namespace>(aNamespace);
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
return CreateOnMainThread(ns, global, aPrincipal, aRv);
}
nsISupports*
CacheStorage::GetParentObject() const
{

View File

@ -7,7 +7,6 @@
#ifndef mozilla_dom_cache_CacheStorage_h
#define mozilla_dom_cache_CacheStorage_h
#include "mozilla/dom/CacheBinding.h"
#include "mozilla/dom/cache/Types.h"
#include "mozilla/dom/cache/TypeUtils.h"
#include "nsAutoPtr.h"
@ -29,6 +28,7 @@ namespace ipc {
namespace dom {
enum class CacheStorageNamespace : uint32_t;
class Promise;
namespace workers {
@ -64,6 +64,11 @@ public:
already_AddRefed<Promise> Delete(const nsAString& aKey, ErrorResult& aRv);
already_AddRefed<Promise> Keys(ErrorResult& aRv);
// chrome-only webidl interface methods
static already_AddRefed<CacheStorage>
Constructor(const GlobalObject& aGlobal, CacheStorageNamespace aNamespace,
nsIPrincipal* aPrincipal, ErrorResult& aRv);
// binding methods
static bool PrefEnabled(JSContext* aCx, JSObject* aObj);

View File

@ -10,7 +10,10 @@
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#cache-storage
interface Principal;
[Exposed=(Window,Worker),
ChromeConstructor(CacheStorageNamespace namespace, Principal principal),
Func="mozilla::dom::cache::CacheStorage::PrefEnabled"]
interface CacheStorage {
[NewObject]
@ -24,3 +27,8 @@ interface CacheStorage {
[NewObject]
Promise<sequence<DOMString>> keys();
};
// chrome-only, gecko specific extension
enum CacheStorageNamespace {
"content", "chrome"
};