Bug 1116269 - Crypto/SubtleCrypto only depend on nsIGlobalObject, r=rbarnes
authorMartin Thomson <martin.thomson@gmail.com>
Fri, 09 Jan 2015 10:55:44 -0800
changeset 248884 b206ea15cb59f9b0ae591404e811d0eff9e7a459
parent 248883 9c5d2d742c546526989c455ebb7022b19dcfda46
child 248885 da03d6aff37d92878b0c19897fd759db92600f59
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarnes
bugs1116269
milestone37.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 1116269 - Crypto/SubtleCrypto only depend on nsIGlobalObject, r=rbarnes
dom/base/Crypto.cpp
dom/base/Crypto.h
dom/base/SubtleCrypto.cpp
dom/base/SubtleCrypto.h
dom/interfaces/base/nsIDOMCrypto.idl
--- a/dom/base/Crypto.cpp
+++ b/dom/base/Crypto.cpp
@@ -1,16 +1,15 @@
 /* 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/. */
 #include "Crypto.h"
 #include "jsfriendapi.h"
 #include "nsCOMPtr.h"
 #include "nsIRandomGenerator.h"
-#include "nsPIDOMWindow.h"
 #include "MainThreadUtils.h"
 #include "nsXULAppAPI.h"
 
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/CryptoBinding.h"
 #include "nsServiceManagerUtils.h"
 
 using mozilla::dom::ContentChild;
@@ -22,45 +21,45 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
   NS_INTERFACE_MAP_ENTRY(nsIDOMCrypto)
 NS_INTERFACE_MAP_END
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(Crypto)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(Crypto)
 
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Crypto, mWindow, mSubtle)
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Crypto, mParent, mSubtle)
 
 Crypto::Crypto()
 {
   MOZ_COUNT_CTOR(Crypto);
 }
 
 Crypto::~Crypto()
 {
   MOZ_COUNT_DTOR(Crypto);
 }
 
 void
-Crypto::Init(nsIDOMWindow* aWindow)
+Crypto::Init(nsIGlobalObject* aParent)
 {
-  mWindow = do_QueryInterface(aWindow);
-  MOZ_ASSERT(mWindow);
+  mParent = do_QueryInterface(aParent);
+  MOZ_ASSERT(mParent);
 }
 
 /* virtual */ JSObject*
 Crypto::WrapObject(JSContext* aCx)
 {
   return CryptoBinding::Wrap(aCx, this);
 }
 
 void
 Crypto::GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray,
-			JS::MutableHandle<JSObject*> aRetval,
-			ErrorResult& aRv)
+                        JS::MutableHandle<JSObject*> aRetval,
+                        ErrorResult& aRv)
 {
   NS_ABORT_IF_FALSE(NS_IsMainThread(), "Called on the wrong thread");
 
   JS::Rooted<JSObject*> view(aCx, aArray.Obj());
 
   // Throw if the wrong type of ArrayBufferView is passed in
   // (Part of the Web Crypto API spec)
   switch (JS_GetArrayBufferViewType(view)) {
--- a/dom/base/Crypto.h
+++ b/dom/base/Crypto.h
@@ -1,17 +1,17 @@
 /* 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_Crypto_h
 #define mozilla_dom_Crypto_h
 
 #include "nsIDOMCrypto.h"
 #include "mozilla/dom/SubtleCrypto.h"
-#include "nsPIDOMWindow.h"
+#include "nsIGlobalObject.h"
 
 #include "nsWrapperCache.h"
 #include "mozilla/dom/TypedArray.h"
 #define NS_DOMCRYPTO_CID \
   {0x929d9320, 0x251e, 0x11d4, { 0x8a, 0x7c, 0x00, 0x60, 0x08, 0xc8, 0x44, 0xc3} }
 
 namespace mozilla {
 
@@ -30,37 +30,37 @@ public:
 
   NS_DECL_NSIDOMCRYPTO
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Crypto)
 
   void
   GetRandomValues(JSContext* aCx, const ArrayBufferView& aArray,
-		  JS::MutableHandle<JSObject*> aRetval,
-		  ErrorResult& aRv);
+                  JS::MutableHandle<JSObject*> aRetval,
+                  ErrorResult& aRv);
 
   SubtleCrypto*
   Subtle();
 
   // WebIDL
 
-  nsPIDOMWindow*
+  nsIGlobalObject*
   GetParentObject() const
   {
-    return mWindow;
+    return mParent;
   }
 
   virtual JSObject*
   WrapObject(JSContext* aCx) MOZ_OVERRIDE;
 
   static uint8_t*
   GetRandomValues(uint32_t aLength);
 
 private:
-  nsCOMPtr<nsPIDOMWindow> mWindow;
+  nsCOMPtr<nsIGlobalObject> mParent;
   nsRefPtr<SubtleCrypto> mSubtle;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_Crypto_h
--- a/dom/base/SubtleCrypto.cpp
+++ b/dom/base/SubtleCrypto.cpp
@@ -8,41 +8,40 @@
 
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/SubtleCryptoBinding.h"
 #include "mozilla/dom/WebCryptoTask.h"
 
 namespace mozilla {
 namespace dom {
 
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(SubtleCrypto, mWindow)
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(SubtleCrypto, mParent)
 NS_IMPL_CYCLE_COLLECTING_ADDREF(SubtleCrypto)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(SubtleCrypto)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SubtleCrypto)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 
 
-SubtleCrypto::SubtleCrypto(nsPIDOMWindow* aWindow)
-  : mWindow(aWindow)
+SubtleCrypto::SubtleCrypto(nsIGlobalObject* aParent)
+  : mParent(aParent)
 {
 }
 
 JSObject*
 SubtleCrypto::WrapObject(JSContext* aCx)
 {
   return SubtleCryptoBinding::Wrap(aCx, this);
 }
 
 #define SUBTLECRYPTO_METHOD_BODY(Operation, aRv, ...)                   \
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);        \
-  MOZ_ASSERT(global);                                                   \
-  nsRefPtr<Promise> p = Promise::Create(global, aRv);                   \
+  MOZ_ASSERT(mParent);                                                  \
+  nsRefPtr<Promise> p = Promise::Create(mParent, aRv);                  \
   if (aRv.Failed()) {                                                   \
     return nullptr;                                                     \
   }                                                                     \
   nsRefPtr<WebCryptoTask> task = WebCryptoTask::Create ## Operation ## Task(__VA_ARGS__); \
   task->DispatchWithPromise(p); \
   return p.forget();
 
 already_AddRefed<Promise>
--- a/dom/base/SubtleCrypto.h
+++ b/dom/base/SubtleCrypto.h
@@ -4,17 +4,17 @@
  * 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_SubtleCrypto_h
 #define mozilla_dom_SubtleCrypto_h
 
 #include "nsCycleCollectionParticipant.h"
 #include "nsWrapperCache.h"
-#include "nsPIDOMWindow.h"
+#include "nsIGlobalObject.h"
 #include "mozilla/dom/CryptoKey.h"
 #include "js/TypeDecls.h"
 
 namespace mozilla {
 namespace dom {
 
 class ObjectOrString;
 class Promise;
@@ -26,21 +26,21 @@ class SubtleCrypto MOZ_FINAL : public ns
 {
   ~SubtleCrypto() {}
 
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(SubtleCrypto)
 
 public:
-  explicit SubtleCrypto(nsPIDOMWindow* aWindow);
+  explicit SubtleCrypto(nsIGlobalObject* aParent);
 
-  nsPIDOMWindow* GetParentObject() const
+  nsIGlobalObject* GetParentObject() const
   {
-    return mWindow;
+    return mParent;
   }
 
   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
 
   already_AddRefed<Promise> Encrypt(JSContext* cx,
                                     const ObjectOrString& algorithm,
                                     CryptoKey& key,
                                     const CryptoOperationData& data,
@@ -114,15 +114,15 @@ public:
                                       CryptoKey& unwrappingKey,
                                       const ObjectOrString& unwrapAlgorithm,
                                       const ObjectOrString& unwrappedKeyAlgorithm,
                                       bool extractable,
                                       const Sequence<nsString>& keyUsages,
                                       ErrorResult& aRv);
 
 private:
-  nsCOMPtr<nsPIDOMWindow> mWindow;
+  nsCOMPtr<nsIGlobalObject> mParent;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_SubtleCrypto_h
--- a/dom/interfaces/base/nsIDOMCrypto.idl
+++ b/dom/interfaces/base/nsIDOMCrypto.idl
@@ -1,14 +1,14 @@
 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "nsISupports.idl"
 
-interface nsIDOMWindow;
+interface nsIGlobalObject;
 
-[uuid(729cfcad-11b4-4338-b97e-5c023ae295fa)]
+[uuid(48d7f7fd-bb85-4c04-9b8b-5cd9131acdef)]
 interface nsIDOMCrypto : nsISupports
 {
-  [notxpcom] void init(in nsIDOMWindow window);
+  [notxpcom] void init(in nsIGlobalObject parent);
 };