From c1382146f9e7c8206aea8680520e02dbc12d8d3f Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Tue, 19 Aug 2014 12:02:07 -0700 Subject: [PATCH] Bug 796938 - Switch nsLocation::GetSourceBaseURL to GetEntryDocument. r=smaug --- dom/base/nsLocation.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/dom/base/nsLocation.cpp b/dom/base/nsLocation.cpp index ab0da0498148..e04b9703a2ac 100644 --- a/dom/base/nsLocation.cpp +++ b/dom/base/nsLocation.cpp @@ -1013,22 +1013,20 @@ nsLocation::ValueOf(nsIDOMLocation** aReturn) nsresult nsLocation::GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL) { - *sourceURL = nullptr; - nsCOMPtr sgo = nsJSUtils::GetDynamicScriptGlobal(cx); - // If this JS context doesn't have an associated DOM window, we effectively - // have no script entry point stack. This doesn't generally happen with the DOM, + nsIDocument* doc = GetEntryDocument(); + // If there's no entry document, we either have no Script Entry Point or one + // that isn't a DOM Window. This doesn't generally happen with the DOM, // but can sometimes happen with extension code in certain IPC configurations. // If this happens, try falling back on the current document associated with // the docshell. If that fails, just return null and hope that the caller passed // an absolute URI. - if (!sgo && GetDocShell()) { - sgo = GetDocShell()->GetScriptGlobalObject(); + if (!doc && GetDocShell()) { + nsCOMPtr docShellWin = do_QueryInterface(GetDocShell()->GetScriptGlobalObject()); + if (docShellWin) { + doc = docShellWin->GetDoc(); + } } - NS_ENSURE_TRUE(sgo, NS_OK); - nsCOMPtr window = do_QueryInterface(sgo); - NS_ENSURE_TRUE(window, NS_ERROR_UNEXPECTED); - nsIDocument* doc = window->GetDoc(); NS_ENSURE_TRUE(doc, NS_OK); *sourceURL = doc->GetBaseURI().take(); return NS_OK;