Bug 861529 - Remove nsDOMEventTargetHelper::Init, ,r=khuey
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Mon, 22 Apr 2013 20:24:48 +0300
changeset 129496 5804803f172a479d79ccbe40b6c1a4579493658e
parent 129494 dfc1cd702c6e7acb25e5f38af7f0c54ae9ffe2c3
child 129497 dbb625a4a0e38f158698c4306e553fb2e724fc83
push idunknown
push userunknown
push dateunknown
reviewerskhuey
bugs861529
milestone23.0a1
Bug 861529 - Remove nsDOMEventTargetHelper::Init, ,r=khuey
content/base/src/nsDOMDataChannel.cpp
content/base/src/nsDOMFileReader.cpp
content/events/src/nsDOMEventTargetHelper.cpp
content/events/src/nsDOMEventTargetHelper.h
--- a/content/base/src/nsDOMDataChannel.cpp
+++ b/content/base/src/nsDOMDataChannel.cpp
@@ -137,18 +137,16 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
 
 nsresult
 nsDOMDataChannel::Init(nsPIDOMWindow* aDOMWindow)
 {
   nsresult rv;
   nsAutoString urlParam;
 
-  nsDOMEventTargetHelper::Init();
-
   MOZ_ASSERT(mDataChannel);
   mDataChannel->SetListener(this, nullptr);
 
   // Now grovel through the objects to get a usable origin for onMessage
   nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aDOMWindow);
   NS_ENSURE_STATE(sgo);
   nsCOMPtr<nsIScriptContext> scriptContext = sgo->GetContext();
   NS_ENSURE_STATE(scriptContext);
--- a/content/base/src/nsDOMFileReader.cpp
+++ b/content/base/src/nsDOMFileReader.cpp
@@ -113,30 +113,35 @@ nsDOMFileReader::nsDOMFileReader()
 
 nsDOMFileReader::~nsDOMFileReader()
 {
   FreeFileData();
 
   nsLayoutStatics::Release();
 }
 
+
+/**
+ * This Init method is called from the factory constructor.
+ */
 nsresult
 nsDOMFileReader::Init()
 {
-  nsDOMEventTargetHelper::Init();
-
-  nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
-  nsCOMPtr<nsIPrincipal> subjectPrincipal;
+  nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
+  nsCOMPtr<nsIPrincipal> principal;
   if (secMan) {
-    nsresult rv = secMan->GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));
-    NS_ENSURE_SUCCESS(rv, rv);
+    secMan->GetSystemPrincipal(getter_AddRefs(principal));
   }
-  NS_ENSURE_STATE(subjectPrincipal);
-  mPrincipal.swap(subjectPrincipal);
+  NS_ENSURE_STATE(principal);
+  mPrincipal.swap(principal);
 
+  // Instead of grabbing some random global from the context stack,
+  // let's use the default one (junk drawer) for now.
+  // We should move away from this Init...
+  BindToOwner(xpc::GetNativeForGlobal(xpc::GetJunkScope()));
   return NS_OK;
 }
 
 /* static */ already_AddRefed<nsDOMFileReader>
 nsDOMFileReader::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
 {
   nsRefPtr<nsDOMFileReader> fileReader = new nsDOMFileReader();
 
--- a/content/events/src/nsDOMEventTargetHelper.cpp
+++ b/content/events/src/nsDOMEventTargetHelper.cpp
@@ -358,32 +358,8 @@ nsDOMEventTargetHelper::GetContextForEve
   if (NS_FAILED(*aRv)) {
     return nullptr;
   }
   nsPIDOMWindow* owner = GetOwner();
   return owner ? static_cast<nsGlobalWindow*>(owner)->GetContextInternal()
                : nullptr;
 }
 
-void
-nsDOMEventTargetHelper::Init(JSContext* aCx)
-{
-  JSContext* cx = aCx;
-  if (!cx) {
-    nsIJSContextStack* stack = nsContentUtils::ThreadJSContextStack();
-
-    if (!stack)
-      return;
-
-    if (NS_FAILED(stack->Peek(&cx)) || !cx)
-      return;
-  }
-
-  NS_ASSERTION(cx, "Should have returned earlier ...");
-  nsIScriptContext* context = GetScriptContextFromJSContext(cx);
-  if (context) {
-    nsCOMPtr<nsPIDOMWindow> window =
-      do_QueryInterface(context->GetGlobalObject());
-    if (window) {
-      BindToOwner(window->GetCurrentInnerWindow());
-    }
-  }
-}
--- a/content/events/src/nsDOMEventTargetHelper.h
+++ b/content/events/src/nsDOMEventTargetHelper.h
@@ -63,18 +63,16 @@ public:
       // nsISupports pointer. That must be fixed, or we'll crash...
       NS_ASSERTION(target_qi == target, "Uh, fix QI!");
     }
 #endif
 
     return static_cast<nsDOMEventTargetHelper*>(target);
   }
 
-  void Init(JSContext* aCx = nullptr);
-
   bool HasListenersFor(nsIAtom* aTypeWithOn)
   {
     return mListenerManager && mListenerManager->HasListenersFor(aTypeWithOn);
   }
 
   nsresult SetEventHandler(nsIAtom* aType,
                            JSContext* aCx,
                            const JS::Value& aValue);