Bug 1497301 part 1. Remove the JSContext arg of Location::GetSourceBaseURL. r=farre
It's unused. Also, this function never fails, so there's no reason to have the
nsresult return type.
--- a/dom/base/Location.cpp
+++ b/dom/base/Location.cpp
@@ -455,24 +455,18 @@ Location::SetHref(const nsAString& aHref
return;
}
}
nsresult
Location::SetHrefWithContext(JSContext* cx, const nsAString& aHref,
bool aReplace)
{
- nsCOMPtr<nsIURI> base;
-
// Get the source of the caller
- nsresult result = GetSourceBaseURL(cx, getter_AddRefs(base));
-
- if (NS_FAILED(result)) {
- return result;
- }
+ nsCOMPtr<nsIURI> base = GetSourceBaseURL();
return SetHrefWithBase(aHref, base, aReplace);
}
nsresult
Location::SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
bool aReplace)
{
@@ -934,38 +928,36 @@ Location::Assign(const nsAString& aUrl,
return;
}
if (oldUri) {
aRv = SetHrefWithBase(aUrl, oldUri, false);
}
}
-nsresult
-Location::GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL)
+already_AddRefed<nsIURI>
+Location::GetSourceBaseURL()
{
- *sourceURL = nullptr;
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.
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
if (!doc && docShell) {
nsCOMPtr<nsPIDOMWindowOuter> docShellWin =
do_QueryInterface(docShell->GetScriptGlobalObject());
if (docShellWin) {
doc = docShellWin->GetDoc();
}
}
- NS_ENSURE_TRUE(doc, NS_OK);
- *sourceURL = doc->GetBaseURI().take();
- return NS_OK;
+ NS_ENSURE_TRUE(doc, nullptr);
+ return doc->GetBaseURI();
}
bool
Location::CallerSubsumes(nsIPrincipal* aSubjectPrincipal)
{
MOZ_ASSERT(aSubjectPrincipal);
// Get the principal associated with the location object. Note that this is
--- a/dom/base/Location.h
+++ b/dom/base/Location.h
@@ -167,17 +167,19 @@ protected:
// if the docShell is null.
nsresult GetURI(nsIURI** aURL, bool aGetInnermostURI = false);
nsresult SetURI(nsIURI* aURL, bool aReplace = false);
nsresult SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
bool aReplace);
nsresult SetHrefWithContext(JSContext* cx, const nsAString& aHref,
bool aReplace);
- nsresult GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL);
+ // Get the base URL we should be using for our relative URL
+ // resolution for SetHref/Assign/Replace.
+ already_AddRefed<nsIURI> GetSourceBaseURL();
nsresult CheckURL(nsIURI *url, nsDocShellLoadInfo** aLoadInfo);
bool CallerSubsumes(nsIPrincipal* aSubjectPrincipal);
nsString mCachedHash;
nsCOMPtr<nsPIDOMWindowInner> mInnerWindow;
nsWeakPtr mDocShell;
};