Bug 796938 - Switch to GetEntryGlobal in nsLocation::SetHrefWithBase. r=smaug
authorBobby Holley <bobbyholley@gmail.com>
Tue, 19 Aug 2014 12:02:08 -0700
changeset 214765 129edf96797ef4ddec4a72e35a0d62a64ebe8e99
parent 214764 9b57ef374bfee5ff35de111d90dd12e48bfda6b8
child 214766 25fff355894f5c443be8e13ecb8428836b563ac2
push idunknown
push userunknown
push dateunknown
reviewerssmaug
bugs796938
milestone34.0a1
Bug 796938 - Switch to GetEntryGlobal in nsLocation::SetHrefWithBase. r=smaug We leave this flag on the script context for now - we can move it somewhere else later.
dom/base/nsLocation.cpp
--- a/dom/base/nsLocation.cpp
+++ b/dom/base/nsLocation.cpp
@@ -23,16 +23,17 @@
 #include "nsIPresShell.h"
 #include "nsPresContext.h"
 #include "nsError.h"
 #include "nsDOMClassInfoID.h"
 #include "nsReadableUtils.h"
 #include "nsITextToSubURI.h"
 #include "nsJSUtils.h"
 #include "nsContentUtils.h"
+#include "nsGlobalWindow.h"
 #include "mozilla/Likely.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsNullPrincipal.h"
 #include "ScriptSettings.h"
 #include "mozilla/dom/LocationBinding.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
@@ -533,33 +534,33 @@ nsLocation::SetHrefWithBase(const nsAStr
      * we want to do a replace load, in such a situation. 
      * In other cases, for example if a event handler or a JS timer
      * had a location.href in it, we want to do a normal load,
      * so that the new url will be appended to Session History.
      * This solution is tricky. Hopefully it isn't going to bite
      * anywhere else. This is part of solution for bug # 39938, 72197
      * 
      */
-    bool inScriptTag=false;
-    JSContext *cx = nsContentUtils::GetCurrentJSContext();
-    if (cx) {
-      nsIScriptContext *scriptContext =
-        nsJSUtils::GetDynamicScriptContext(cx);
+    bool inScriptTag = false;
+    nsIScriptContext* scriptContext = nullptr;
+    nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(GetEntryGlobal());
+    if (win) {
+      scriptContext = static_cast<nsGlobalWindow*>(win.get())->GetContextInternal();
+    }
 
-      if (scriptContext) {
-        if (scriptContext->GetProcessingScriptTag()) {
-          // Now check to make sure that the script is running in our window,
-          // since we only want to replace if the location is set by a
-          // <script> tag in the same window.  See bug 178729.
-          nsCOMPtr<nsIScriptGlobalObject> ourGlobal =
-            docShell ? docShell->GetScriptGlobalObject() : nullptr;
-          inScriptTag = (ourGlobal == scriptContext->GetGlobalObject());
-        }
-      }  
-    } //cx
+    if (scriptContext) {
+      if (scriptContext->GetProcessingScriptTag()) {
+        // Now check to make sure that the script is running in our window,
+        // since we only want to replace if the location is set by a
+        // <script> tag in the same window.  See bug 178729.
+        nsCOMPtr<nsIScriptGlobalObject> ourGlobal =
+          docShell ? docShell->GetScriptGlobalObject() : nullptr;
+        inScriptTag = (ourGlobal == scriptContext->GetGlobalObject());
+      }
+    }
 
     return SetURI(newUri, aReplace || inScriptTag);
   }
 
   return result;
 }
 
 NS_IMETHODIMP