Bug 1160138 P2 Add a [ChromeConstructor] to CacheStorage to support devtools. r=ehsan
authorBen Kelly <ben@wanderview.com>
Tue, 05 May 2015 15:45:36 -0700
changeset 273862 9c174e93d6203fc5097f0a754747dfaf056ae411
parent 273861 4cf7a121e011ceceea23b095089753fbafc0f8f7
child 273863 e89d092c5f473fa9ab4eba57244da1a59d314a55
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1160138
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1160138 P2 Add a [ChromeConstructor] to CacheStorage to support devtools. r=ehsan
dom/cache/CacheStorage.cpp
dom/cache/CacheStorage.h
dom/webidl/CacheStorage.webidl
--- a/dom/cache/CacheStorage.cpp
+++ b/dom/cache/CacheStorage.cpp
@@ -309,16 +309,40 @@ CacheStorage::Keys(ErrorResult& aRv)
 
 // static
 bool
 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
 {
   return mGlobal;
 }
 
 JSObject*
 CacheStorage::WrapObject(JSContext* aContext, JS::Handle<JSObject*> aGivenProto)
--- a/dom/cache/CacheStorage.h
+++ b/dom/cache/CacheStorage.h
@@ -2,17 +2,16 @@
 /* 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/CacheBinding.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"
@@ -24,16 +23,17 @@ namespace mozilla {
 class ErrorResult;
 
 namespace ipc {
   class PrincipalInfo;
 }
 
 namespace dom {
 
+enum class CacheStorageNamespace : uint32_t;
 class Promise;
 
 namespace workers {
   class WorkerPrivate;
 }
 
 namespace cache {
 
@@ -59,16 +59,21 @@ public:
   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);
 
+  // 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);
 
   nsISupports* GetParentObject() const;
   virtual JSObject* WrapObject(JSContext* aContext, JS::Handle<JSObject*> aGivenProto) override;
 
   // nsIIPCbackgroundChildCreateCallback methods
   virtual void ActorCreated(PBackgroundChild* aActor) override;
--- a/dom/webidl/CacheStorage.webidl
+++ b/dom/webidl/CacheStorage.webidl
@@ -5,22 +5,30 @@
  *
  * The origin of this IDL file is
  * http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
  *
  */
 
 // 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]
   Promise<Response> match(RequestInfo request, optional CacheQueryOptions options);
   [NewObject]
   Promise<boolean> has(DOMString cacheName);
   [NewObject]
   Promise<Cache> open(DOMString cacheName);
   [NewObject]
   Promise<boolean> delete(DOMString cacheName);
   [NewObject]
   Promise<sequence<DOMString>> keys();
 };
+
+// chrome-only, gecko specific extension
+enum CacheStorageNamespace {
+  "content", "chrome"
+};