diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index 4a362a43adf..221ab3ea66c 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -338,7 +338,7 @@ protected: PRBool aReplace); nsresult GetSourceURL(JSContext* cx, nsIURI** sourceURL); - nsresult CheckURL(nsIURI *url, nsString &aReferrerResult); + nsresult CheckURL(nsIURI *url, nsIURI** aReferrer); nsIDocShell *mDocShell; // Weak Reference void *mScriptObject; diff --git a/dom/src/base/nsLocation.cpp b/dom/src/base/nsLocation.cpp index c243b8e259d..de913107a00 100644 --- a/dom/src/base/nsLocation.cpp +++ b/dom/src/base/nsLocation.cpp @@ -103,7 +103,7 @@ NS_IMETHODIMP_(void) LocationImpl::SetDocShell(nsIDocShell *aDocShell) } nsresult -LocationImpl::CheckURL(nsIURI* aURL, nsString &aReferrerResult) +LocationImpl::CheckURL(nsIURI* aURL, nsIURI** aReferrer) { nsresult result; // Get JSContext from stack. @@ -131,13 +131,8 @@ LocationImpl::CheckURL(nsIURI* aURL, nsString &aReferrerResult) return NS_ERROR_FAILURE; nsCOMPtr codebase = do_QueryInterface(principal); if (codebase) { - nsCOMPtr codebaseURI; - if (NS_FAILED(result = codebase->GetURI(getter_AddRefs(codebaseURI)))) + if (NS_FAILED(result = codebase->GetURI(aReferrer))) return result; - nsXPIDLCString spec; - if (NS_FAILED(result = codebaseURI->GetSpec(getter_Copies(spec)))) - return result; - aReferrerResult = spec; } return NS_OK; @@ -148,21 +143,11 @@ nsresult LocationImpl::SetURL(nsIURI* aURL) { if (mDocShell) { - char* spec; - aURL->GetSpec(&spec); - nsAutoString s = spec; - nsCRT::free(spec); - - nsAutoString referrer; - if (NS_FAILED(CheckURL(aURL, referrer))) + nsCOMPtr referrer; + if(NS_FAILED(CheckURL(aURL, getter_AddRefs(referrer)))) return NS_ERROR_FAILURE; - nsCOMPtr webShell(do_QueryInterface(mDocShell)); - return webShell->LoadURL(s.GetUnicode(), nsnull, PR_TRUE, - nsIChannel::LOAD_NORMAL, 0, nsnull, - referrer.Length() > 0 - ? referrer.GetUnicode() - : nsnull); + return mDocShell->LoadURI(aURL, referrer); } else { return NS_OK; @@ -386,16 +371,20 @@ LocationImpl::SetHrefWithBase(const nsString& aHref, if ((NS_OK == result) && (mDocShell)) { - nsAutoString referrer; - if (NS_FAILED(CheckURL(newUrl, referrer))) + nsCOMPtr referrer; + if (NS_FAILED(CheckURL(newUrl, getter_AddRefs(referrer)))) return NS_ERROR_FAILURE; + nsXPIDLCString referrerCSpec; + referrer->GetSpec(getter_Copies(referrerCSpec)); + nsAutoString referrerSpec = referrerCSpec; + // Load new URI. nsCOMPtr webShell(do_QueryInterface(mDocShell)); result = webShell->LoadURL(newHref.GetUnicode(), nsnull, aReplace, nsIChannel::LOAD_NORMAL, 0, nsnull, - referrer.Length() > 0 - ? referrer.GetUnicode() + referrerSpec.Length() > 0 + ? referrerSpec.GetUnicode() : nsnull); }