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.
--- 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