2001-09-25 22:43:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-08-13 04:34:53 +00:00
|
|
|
*
|
2001-09-25 22:43:09 +00:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1998-08-13 04:34:53 +00:00
|
|
|
*
|
2001-09-25 22:43:09 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-08-13 04:34:53 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-25 22:43:09 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2000-02-08 13:40:10 +00:00
|
|
|
* Contributor(s):
|
2001-01-09 01:16:36 +00:00
|
|
|
* Travis Bogard <travis@netscape.com>
|
2000-01-11 20:49:15 +00:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-25 22:43:09 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-08-13 04:34:53 +00:00
|
|
|
|
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsIWebShell.h"
|
2000-02-08 13:40:10 +00:00
|
|
|
#include "nsIDocShell.h"
|
2000-03-30 22:38:32 +00:00
|
|
|
#include "nsIDocShellLoadInfo.h"
|
2000-02-24 03:57:32 +00:00
|
|
|
#include "nsIWebNavigation.h"
|
2002-12-12 15:48:30 +00:00
|
|
|
#include "nsCDefaultURIFixup.h"
|
|
|
|
#include "nsIURIFixup.h"
|
1998-08-13 04:34:53 +00:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
1999-11-30 04:50:42 +00:00
|
|
|
#include "nsNetUtil.h"
|
1998-08-13 04:34:53 +00:00
|
|
|
#include "plstr.h"
|
2000-08-23 17:27:06 +00:00
|
|
|
#include "prprf.h"
|
1998-08-13 04:34:53 +00:00
|
|
|
#include "prmem.h"
|
1999-08-03 23:16:48 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2002-03-06 07:48:55 +00:00
|
|
|
#include "nsEscape.h"
|
1999-08-03 23:16:48 +00:00
|
|
|
#include "nsJSUtils.h"
|
1999-08-20 09:51:02 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2000-02-10 04:56:56 +00:00
|
|
|
#include "nsICodebasePrincipal.h"
|
2000-01-15 02:02:27 +00:00
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
1999-09-07 02:54:19 +00:00
|
|
|
#include "nsIJSContextStack.h"
|
2000-02-10 04:56:56 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2000-02-11 04:18:39 +00:00
|
|
|
#include "nsDOMError.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
#include "nsDOMClassInfo.h"
|
2002-05-15 18:55:21 +00:00
|
|
|
#include "nsCRT.h"
|
2003-03-05 22:23:47 +00:00
|
|
|
#include "nsIProtocolHandler.h"
|
2001-11-14 23:45:23 +00:00
|
|
|
|
2002-08-13 23:26:05 +00:00
|
|
|
static nsresult GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString& aCharset)
|
2001-11-14 23:45:23 +00:00
|
|
|
{
|
2002-08-13 23:26:05 +00:00
|
|
|
aCharset.Truncate();
|
2001-11-14 23:45:23 +00:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
JSContext *cx;
|
|
|
|
|
|
|
|
rv = stack->Peek(&cx);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> nativeGlob;
|
|
|
|
nsJSUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(nativeGlob));
|
|
|
|
NS_ENSURE_TRUE(nativeGlob, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(nativeGlob);
|
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
rv = window->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!domDoc)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
|
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
|
|
|
|
2003-06-17 16:40:34 +00:00
|
|
|
rv = doc->GetDocumentCharacterSet(aCharset);
|
2001-11-14 23:45:23 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
|
2000-02-08 13:40:10 +00:00
|
|
|
LocationImpl::LocationImpl(nsIDocShell *aDocShell)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2000-02-08 13:40:10 +00:00
|
|
|
mDocShell = aDocShell; // Weak Reference
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
LocationImpl::~LocationImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
// QueryInterface implementation for LocationImpl
|
|
|
|
NS_INTERFACE_MAP_BEGIN(LocationImpl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNSLocation)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMLocation)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMLocation)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Location)
|
|
|
|
NS_INTERFACE_MAP_END
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
NS_IMPL_ADDREF(LocationImpl)
|
|
|
|
NS_IMPL_RELEASE(LocationImpl)
|
1998-08-13 04:34:53 +00:00
|
|
|
|
2000-02-08 13:40:10 +00:00
|
|
|
NS_IMETHODIMP_(void) LocationImpl::SetDocShell(nsIDocShell *aDocShell)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2000-02-08 13:40:10 +00:00
|
|
|
mDocShell = aDocShell; // Weak Reference
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
nsresult
|
|
|
|
LocationImpl::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo)
|
1999-09-07 02:54:19 +00:00
|
|
|
{
|
2002-07-24 20:42:22 +00:00
|
|
|
*aLoadInfo = nsnull;
|
|
|
|
|
1999-09-07 02:54:19 +00:00
|
|
|
nsresult result;
|
|
|
|
// Get JSContext from stack.
|
2001-01-09 01:16:36 +00:00
|
|
|
nsCOMPtr<nsIJSContextStack>
|
|
|
|
stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &result));
|
|
|
|
|
1999-09-07 02:54:19 +00:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1999-09-07 02:54:19 +00:00
|
|
|
JSContext *cx;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1999-09-07 02:54:19 +00:00
|
|
|
if (NS_FAILED(stack->Peek(&cx)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2002-07-24 20:42:22 +00:00
|
|
|
if (!cx) {
|
|
|
|
// No cx means that there's no JS running, or at least no JS that
|
|
|
|
// was run through code that properly pushed a context onto the
|
|
|
|
// context stack (as all code that runs JS off of web pages
|
|
|
|
// does). Going further from here will crash, so lets not do
|
|
|
|
// that...
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-07 02:54:19 +00:00
|
|
|
// Get security manager.
|
2001-01-09 01:16:36 +00:00
|
|
|
nsCOMPtr<nsIScriptSecurityManager>
|
|
|
|
secMan(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &result));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
1999-09-07 02:54:19 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Check to see if URI is allowed.
|
2001-01-09 01:16:36 +00:00
|
|
|
result = secMan->CheckLoadURIFromScript(cx, aURI);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
1999-11-16 05:07:31 +00:00
|
|
|
return result;
|
1999-09-07 02:54:19 +00:00
|
|
|
|
2000-08-11 04:31:08 +00:00
|
|
|
// Create load info
|
|
|
|
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
|
|
|
|
mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
|
|
|
|
NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
|
|
|
|
|
2000-08-31 05:53:32 +00:00
|
|
|
// Now get the principal to use when loading the URI
|
2000-02-10 04:56:56 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
2000-08-11 04:31:08 +00:00
|
|
|
if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal))) ||
|
|
|
|
!principal)
|
2000-02-10 04:56:56 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-08-11 04:31:08 +00:00
|
|
|
nsCOMPtr<nsISupports> owner = do_QueryInterface(principal);
|
|
|
|
loadInfo->SetOwner(owner);
|
|
|
|
|
2001-11-17 17:26:18 +00:00
|
|
|
// now set the referrer on the loadinfo
|
|
|
|
nsCOMPtr<nsIURI> sourceURI;
|
|
|
|
GetSourceURL(cx, getter_AddRefs(sourceURI));
|
|
|
|
if (sourceURI) {
|
|
|
|
loadInfo->SetReferrer(sourceURI);
|
|
|
|
}
|
|
|
|
|
2000-08-11 04:31:08 +00:00
|
|
|
*aLoadInfo = loadInfo.get();
|
|
|
|
NS_ADDREF(*aLoadInfo);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1999-09-07 02:54:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-05 22:23:47 +00:00
|
|
|
// Walk up the docshell hierarchy and find a usable base URI. Basically
|
|
|
|
// anything that would allow a relative uri.
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
LocationImpl::FindUsableBaseURI(nsIURI * aBaseURI, nsIDocShell * aParent, nsIURI ** aUsableURI)
|
|
|
|
{
|
|
|
|
if (!aBaseURI || !aParent)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
NS_ENSURE_ARG_POINTER(aUsableURI);
|
|
|
|
|
|
|
|
*aUsableURI = nsnull;
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIDocShell> parentDS = aParent;
|
|
|
|
nsCOMPtr<nsIURI> baseURI = aBaseURI;
|
|
|
|
nsCOMPtr<nsIIOService> ioService(do_GetService(NS_IOSERVICE_CONTRACTID, &rv));
|
|
|
|
|
|
|
|
while(NS_SUCCEEDED(rv) && baseURI && ioService) {
|
|
|
|
// Check if the current base uri supports relative uris.
|
|
|
|
// We make this check by looking at the protocol flags of
|
|
|
|
// the protocol handler. If the protocol flags has URI_NORELATIVE,
|
|
|
|
// it means that the base uri does not support relative uris.
|
|
|
|
nsCAutoString scheme;
|
|
|
|
baseURI->GetScheme(scheme);
|
|
|
|
nsCOMPtr<nsIProtocolHandler> protocolHandler;
|
|
|
|
// Get the protocol handler for the base uri.
|
|
|
|
ioService->GetProtocolHandler(scheme.get(), getter_AddRefs(protocolHandler));
|
|
|
|
if (!protocolHandler)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
PRUint32 pFlags; // Is there a default value for the protocol flags?
|
|
|
|
protocolHandler->GetProtocolFlags(&pFlags);
|
|
|
|
if (!(pFlags & nsIProtocolHandler::URI_NORELATIVE)) {
|
|
|
|
*aUsableURI = baseURI;
|
|
|
|
NS_ADDREF(*aUsableURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the same type parent docshell
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsTreeItem(do_QueryInterface(parentDS));
|
|
|
|
if (!docShellAsTreeItem)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentDSTreeItem;
|
|
|
|
docShellAsTreeItem->GetSameTypeParent(getter_AddRefs(parentDSTreeItem));
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(parentDSTreeItem));
|
|
|
|
|
|
|
|
// Get the parent docshell's uri
|
|
|
|
if (webNav) {
|
|
|
|
rv = webNav->GetCurrentURI(getter_AddRefs(baseURI));
|
|
|
|
parentDS = do_QueryInterface(parentDSTreeItem);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
} // while
|
|
|
|
|
2003-03-11 04:31:44 +00:00
|
|
|
return rv;
|
2003-03-05 22:23:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsresult
|
|
|
|
LocationImpl::GetURI(nsIURI** aURI)
|
|
|
|
{
|
2002-03-23 00:48:40 +00:00
|
|
|
*aURI = nsnull;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell, &rv));
|
2002-03-23 00:48:40 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2002-03-06 07:48:55 +00:00
|
|
|
|
2002-12-12 15:48:30 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = webNav->GetCurrentURI(getter_AddRefs(uri));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2003-01-05 06:34:53 +00:00
|
|
|
// It is valid for docshell to return a null URI. Don't try to fixup
|
|
|
|
// if this happens.
|
|
|
|
if (!uri) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-12-12 15:48:30 +00:00
|
|
|
nsCOMPtr<nsIURIFixup> urifixup(do_GetService(NS_URIFIXUP_CONTRACTID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return urifixup->CreateExposableURI(uri, aURI);
|
2002-03-06 07:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
LocationImpl::GetWritableURI(nsIURI** aURI)
|
|
|
|
{
|
2002-03-23 00:48:40 +00:00
|
|
|
*aURI = nsnull;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
nsresult rv = GetURI(getter_AddRefs(uri));
|
2002-03-23 00:48:40 +00:00
|
|
|
if (NS_FAILED(rv) || !uri) {
|
|
|
|
return rv;
|
|
|
|
}
|
2002-03-06 07:48:55 +00:00
|
|
|
|
|
|
|
return uri->Clone(aURI);
|
|
|
|
}
|
1999-09-07 02:54:19 +00:00
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
nsresult
|
2002-03-06 07:48:55 +00:00
|
|
|
LocationImpl::SetURI(nsIURI* aURI)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2000-02-08 13:40:10 +00:00
|
|
|
if (mDocShell) {
|
2000-03-30 22:38:32 +00:00
|
|
|
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
|
2001-08-14 04:46:20 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if(NS_FAILED(CheckURL(aURI, getter_AddRefs(loadInfo))))
|
1999-09-07 02:54:19 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-08-14 04:46:20 +00:00
|
|
|
webNav->Stop(nsIWebNavigation::STOP_CONTENT);
|
2001-01-09 01:16:36 +00:00
|
|
|
return mDocShell->LoadURI(aURI, loadInfo,
|
2002-03-02 01:49:30 +00:00
|
|
|
nsIWebNavigation::LOAD_FLAGS_NONE, PR_TRUE);
|
1998-11-23 01:09:27 +00:00
|
|
|
}
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::GetHash(nsAString& aHash)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-23 00:48:40 +00:00
|
|
|
aHash.SetLength(0);
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult result = NS_OK;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetURI(getter_AddRefs(uri));
|
1999-06-18 17:34:08 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
|
|
|
|
if (url) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString ref;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
result = url->GetRef(ref);
|
|
|
|
// XXX danger... this may result in non-ASCII octets!
|
|
|
|
NS_UnescapeURL(ref);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
if (NS_SUCCEEDED(result) && !ref.IsEmpty()) {
|
|
|
|
aHash.Assign(NS_LITERAL_STRING("#") + NS_ConvertASCIItoUCS2(ref));
|
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::SetHash(const nsAString& aHash)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (url) {
|
|
|
|
url->SetRef(NS_ConvertUCS2toUTF8(aHash));
|
2002-01-07 10:13:08 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (mDocShell) {
|
|
|
|
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(CheckURL(url, getter_AddRefs(loadInfo))))
|
|
|
|
// We're not calling nsIWebNavigation->Stop, we don't want to
|
|
|
|
// stop the load when we're just scrolling to a named anchor
|
|
|
|
// in the document. See bug 114975.
|
|
|
|
mDocShell->LoadURI(url, loadInfo,
|
|
|
|
nsIWebNavigation::LOAD_FLAGS_NONE, PR_TRUE);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::GetHost(nsAString& aHost)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-23 00:48:40 +00:00
|
|
|
aHost.SetLength(0);
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult result;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString hostport;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = uri->GetHostPort(hostport);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2002-03-06 07:48:55 +00:00
|
|
|
aHost = NS_ConvertUTF8toUCS2(hostport);
|
2002-03-23 00:48:40 +00:00
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::SetHost(const nsAString& aHost)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult result;
|
1998-08-13 04:34:53 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
uri->SetHostPort(NS_ConvertUCS2toUTF8(aHost));
|
|
|
|
SetURI(uri);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::GetHostname(nsAString& aHostname)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-23 00:48:40 +00:00
|
|
|
aHostname.SetLength(0);
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult result;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString host;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = uri->GetHost(host);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2002-03-06 07:48:55 +00:00
|
|
|
aHostname = NS_ConvertUTF8toUCS2(host);
|
2002-03-23 00:48:40 +00:00
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::SetHostname(const nsAString& aHostname)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult result;
|
1998-08-13 04:34:53 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
uri->SetHost(NS_ConvertUCS2toUTF8(aHostname));
|
|
|
|
SetURI(uri);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::GetHref(nsAString& aHref)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-23 00:48:40 +00:00
|
|
|
aHref.SetLength(0);
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult result;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString uriString;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = uri->GetSpec(uriString);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2002-03-06 07:48:55 +00:00
|
|
|
aHref = NS_ConvertUTF8toUCS2(uriString);
|
2002-03-23 00:48:40 +00:00
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::SetHref(const nsAString& aHref)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
1999-08-03 23:16:48 +00:00
|
|
|
nsAutoString oldHref;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-11-23 01:09:27 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
// Get JSContext from stack.
|
|
|
|
nsCOMPtr<nsIJSContextStack>
|
|
|
|
stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
JSContext *cx;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
if (NS_FAILED(stack->Peek(&cx)))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (cx) {
|
2001-05-15 20:58:31 +00:00
|
|
|
rv = SetHrefWithContext(cx, aHref, PR_FALSE);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
} else {
|
|
|
|
rv = GetHref(oldHref);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIURI> oldUri;
|
|
|
|
|
|
|
|
rv = NS_NewURI(getter_AddRefs(oldUri), oldHref);
|
|
|
|
|
|
|
|
if (oldUri) {
|
|
|
|
rv = SetHrefWithBase(aHref, oldUri, PR_FALSE);
|
|
|
|
}
|
1999-08-03 23:16:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
return rv;
|
1999-08-03 23:16:48 +00:00
|
|
|
}
|
|
|
|
|
2000-08-29 00:14:23 +00:00
|
|
|
nsresult
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::SetHrefWithContext(JSContext* cx, const nsAString& aHref,
|
2001-05-15 20:58:31 +00:00
|
|
|
PRBool aReplace)
|
2000-08-29 00:14:23 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> base;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2000-08-29 00:14:23 +00:00
|
|
|
// Get the source of the caller
|
2001-11-17 17:26:18 +00:00
|
|
|
nsresult result = GetSourceBaseURL(cx, getter_AddRefs(base));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2000-08-29 00:14:23 +00:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-05-15 20:58:31 +00:00
|
|
|
return SetHrefWithBase(aHref, base, aReplace);
|
2001-01-09 01:16:36 +00:00
|
|
|
}
|
2000-08-29 00:14:23 +00:00
|
|
|
|
1999-08-03 23:16:48 +00:00
|
|
|
nsresult
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::SetHrefWithBase(const nsAString& aHref,
|
2001-01-09 01:16:36 +00:00
|
|
|
nsIURI* aBase, PRBool aReplace)
|
1999-08-03 23:16:48 +00:00
|
|
|
{
|
|
|
|
nsresult result;
|
2003-03-05 22:23:47 +00:00
|
|
|
nsCOMPtr<nsIURI> newUri, baseURI;
|
|
|
|
|
2003-03-11 04:31:44 +00:00
|
|
|
// Try to make sure the base url is something that will be useful.
|
2003-03-05 22:23:47 +00:00
|
|
|
result = FindUsableBaseURI(aBase, mDocShell, getter_AddRefs(baseURI));
|
2003-03-11 04:31:44 +00:00
|
|
|
if (!baseURI) {
|
|
|
|
// If nothing useful was found, just use what you have.
|
|
|
|
baseURI = aBase;
|
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
|
2002-08-13 23:26:05 +00:00
|
|
|
nsCAutoString docCharset;
|
|
|
|
if (NS_SUCCEEDED(GetDocumentCharacterSetForURI(aHref, docCharset)))
|
2003-03-05 22:23:47 +00:00
|
|
|
result = NS_NewURI(getter_AddRefs(newUri), aHref, docCharset.get(), baseURI);
|
2001-11-14 23:45:23 +00:00
|
|
|
else
|
2003-03-05 22:23:47 +00:00
|
|
|
result = NS_NewURI(getter_AddRefs(newUri), aHref, nsnull, baseURI);
|
1999-09-01 00:54:35 +00:00
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
if (newUri && mDocShell) {
|
2000-03-30 22:38:32 +00:00
|
|
|
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
|
2001-08-14 04:46:20 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
|
1999-08-20 09:51:02 +00:00
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
nsresult rv = CheckURL(newUri, getter_AddRefs(loadInfo));
|
|
|
|
|
|
|
|
if(NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-05-15 22:26:19 +00:00
|
|
|
|
|
|
|
/* Check with the scriptContext if it is currently processing a script tag.
|
|
|
|
* If so, this must be a <script> tag with a location.href in it.
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
PRBool inScriptTag=PR_FALSE;
|
|
|
|
// Get JSContext from stack.
|
|
|
|
nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &result));
|
|
|
|
|
|
|
|
if (stack) {
|
|
|
|
JSContext *cx;
|
|
|
|
|
|
|
|
result = stack->Peek(&cx);
|
|
|
|
if (cx) {
|
|
|
|
nsIScriptContext* scriptCX = (nsIScriptContext*)JS_GetContextPrivate(cx);
|
|
|
|
|
|
|
|
if (scriptCX) {
|
|
|
|
scriptCX->GetProcessingScriptTag(&inScriptTag);
|
|
|
|
}
|
|
|
|
} //cx
|
|
|
|
} // stack
|
|
|
|
|
|
|
|
if (aReplace || inScriptTag) {
|
2000-06-22 07:22:23 +00:00
|
|
|
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadNormalReplace);
|
2001-01-09 01:16:36 +00:00
|
|
|
}
|
2000-03-30 22:38:32 +00:00
|
|
|
|
2001-08-14 04:46:20 +00:00
|
|
|
webNav->Stop(nsIWebNavigation::STOP_CONTENT);
|
2001-01-09 01:16:36 +00:00
|
|
|
return mDocShell->LoadURI(newUri, loadInfo,
|
2002-03-02 01:49:30 +00:00
|
|
|
nsIWebNavigation::LOAD_FLAGS_NONE, PR_TRUE);
|
1998-11-23 01:09:27 +00:00
|
|
|
}
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1998-11-23 01:09:27 +00:00
|
|
|
return result;
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::GetPathname(nsAString& aPathname)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-23 00:48:40 +00:00
|
|
|
aPathname.SetLength(0);
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult result = NS_OK;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
if (url) {
|
|
|
|
nsCAutoString file;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
result = url->GetFilePath(file);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
aPathname = NS_ConvertUTF8toUCS2(file);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::SetPathname(const nsAString& aPathname)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
uri->SetPath(NS_ConvertUCS2toUTF8(aPathname));
|
|
|
|
SetURI(uri);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::GetPort(nsAString& aPort)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-23 00:48:40 +00:00
|
|
|
aPort.SetLength(0);
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult result = NS_OK;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
PRInt32 port;
|
|
|
|
uri->GetPort(&port);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
if (-1 != port) {
|
|
|
|
nsAutoString portStr;
|
|
|
|
portStr.AppendInt(port);
|
|
|
|
aPort.Append(portStr);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::SetPort(const nsAString& aPort)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
// perhaps use nsReadingIterators at some point?
|
|
|
|
NS_ConvertUCS2toUTF8 portStr(aPort);
|
|
|
|
const char *buf = portStr.get();
|
|
|
|
PRInt32 port = -1;
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
if (*buf == ':') {
|
|
|
|
port = atol(buf+1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
port = atol(buf);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-23 00:48:40 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
uri->SetPort(port);
|
|
|
|
SetURI(uri);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::GetProtocol(nsAString& aProtocol)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-23 00:48:40 +00:00
|
|
|
aProtocol.SetLength(0);
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult result = NS_OK;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString protocol;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = uri->GetScheme(protocol);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
aProtocol.Assign(NS_ConvertASCIItoUCS2(protocol));
|
|
|
|
aProtocol.Append(PRUnichar(':'));
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::SetProtocol(const nsAString& aProtocol)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
if (uri) {
|
2002-03-06 07:48:55 +00:00
|
|
|
uri->SetScheme(NS_ConvertUCS2toUTF8(aProtocol));
|
|
|
|
SetURI(uri);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::GetSearch(nsAString& aSearch)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-23 00:48:40 +00:00
|
|
|
aSearch.SetLength(0);
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
|
|
|
|
if (url) {
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCAutoString search;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
result = url->GetQuery(search);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
if (NS_SUCCEEDED(result) && !search.IsEmpty()) {
|
|
|
|
aSearch.Assign(NS_LITERAL_STRING("?") + NS_ConvertUTF8toUCS2(search));
|
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
2000-07-15 00:14:02 +00:00
|
|
|
return NS_OK;
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::SetSearch(const nsAString& aSearch)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2002-03-06 07:48:55 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 04:34:53 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
result = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2002-03-23 00:48:40 +00:00
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
if (url) {
|
|
|
|
result = url->SetQuery(NS_ConvertUCS2toUTF8(aSearch));
|
|
|
|
SetURI(uri);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
1999-08-03 23:16:48 +00:00
|
|
|
LocationImpl::Reload(PRBool aForceget)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
2001-10-09 05:02:25 +00:00
|
|
|
nsresult rv;
|
2001-01-09 01:16:36 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
|
1998-08-13 04:34:53 +00:00
|
|
|
|
2001-10-09 05:02:25 +00:00
|
|
|
if (webNav) {
|
|
|
|
PRUint32 reloadFlags = nsIWebNavigation::LOAD_FLAGS_NONE;
|
1998-08-13 04:34:53 +00:00
|
|
|
|
2001-10-09 05:02:25 +00:00
|
|
|
if (aForceget) {
|
|
|
|
reloadFlags = nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE |
|
|
|
|
nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY;
|
|
|
|
}
|
|
|
|
rv = webNav->Reload(reloadFlags);
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(0, "nsIWebNavigation interface is not available!");
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
LocationImpl::Reload()
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-08-03 23:16:48 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
nsCOMPtr<nsIXPCNativeCallContext> ncc;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
rv = xpc->GetCurrentNativeCallContext(getter_AddRefs(ncc));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
if (!ncc)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
PRBool force_get = PR_FALSE;
|
|
|
|
|
|
|
|
PRUint32 argc;
|
|
|
|
|
|
|
|
ncc->GetArgc(&argc);
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
jsval *argv = nsnull;
|
|
|
|
|
|
|
|
ncc->GetArgvPtr(&argv);
|
|
|
|
NS_ENSURE_TRUE(argv, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
JSContext *cx = nsnull;
|
|
|
|
|
|
|
|
rv = ncc->GetJSContext(&cx);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
JS_ValueToBoolean(cx, argv[0], &force_get);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
return Reload(force_get);
|
1999-08-03 23:16:48 +00:00
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::Replace(const nsAString& aUrl)
|
2000-09-08 07:29:54 +00:00
|
|
|
{
|
2001-05-15 20:58:31 +00:00
|
|
|
nsresult rv = NS_OK;
|
2000-09-08 07:29:54 +00:00
|
|
|
|
2001-05-15 20:58:31 +00:00
|
|
|
// Get JSContext from stack.
|
|
|
|
nsCOMPtr<nsIJSContextStack>
|
2001-05-15 22:26:19 +00:00
|
|
|
stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2001-05-15 20:58:31 +00:00
|
|
|
if (stack) {
|
|
|
|
JSContext *cx;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2001-05-15 20:58:31 +00:00
|
|
|
rv = stack->Peek(&cx);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (cx) {
|
|
|
|
return SetHrefWithContext(cx, aUrl, PR_TRUE);
|
2000-09-08 07:29:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-15 20:58:31 +00:00
|
|
|
nsAutoString oldHref;
|
|
|
|
|
|
|
|
rv = GetHref(oldHref);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> oldUri;
|
|
|
|
|
|
|
|
rv = NS_NewURI(getter_AddRefs(oldUri), oldHref);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return SetHrefWithBase(aUrl, oldUri, PR_TRUE);
|
2000-09-08 07:29:54 +00:00
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::Assign(const nsAString& aUrl)
|
1999-08-03 23:16:48 +00:00
|
|
|
{
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
nsAutoString oldHref;
|
1999-08-03 23:16:48 +00:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
result = GetHref(oldHref);
|
1999-08-03 23:16:48 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> oldUri;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
result = NS_NewURI(getter_AddRefs(oldUri), oldHref);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
if (oldUri) {
|
|
|
|
result = SetHrefWithBase(aUrl, oldUri, PR_FALSE);
|
1999-08-03 23:16:48 +00:00
|
|
|
}
|
|
|
|
}
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1999-08-03 23:16:48 +00:00
|
|
|
return result;
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
1999-01-06 17:22:34 +00:00
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 00:16:18 +00:00
|
|
|
LocationImpl::ToString(nsAString& aReturn)
|
1999-01-06 17:22:34 +00:00
|
|
|
{
|
|
|
|
return GetHref(aReturn);
|
|
|
|
}
|
|
|
|
|
1999-08-03 23:16:48 +00:00
|
|
|
nsresult
|
2001-11-17 17:26:18 +00:00
|
|
|
LocationImpl::GetSourceDocument(JSContext* cx, nsIDocument** aDocument)
|
1999-08-03 23:16:48 +00:00
|
|
|
{
|
|
|
|
// XXX Code duplicated from nsHTMLDocument
|
|
|
|
// XXX Tom said this reminded him of the "Six Degrees of
|
|
|
|
// Kevin Bacon" game. We try to get from here to there using
|
|
|
|
// whatever connections possible. The problem is that this
|
|
|
|
// could break if any of the connections along the way change.
|
|
|
|
// I wish there were a better way.
|
|
|
|
|
1999-12-18 20:29:29 +00:00
|
|
|
nsresult result = NS_ERROR_FAILURE;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
// We need to use the dynamically scoped global and assume that the
|
1999-12-18 20:29:29 +00:00
|
|
|
// current JSContext is a DOM context with a nsIScriptGlobalObject so
|
|
|
|
// that we can get the url of the caller.
|
|
|
|
// XXX This will fail on non-DOM contexts :(
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> nativeGlob;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
nsJSUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(nativeGlob));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1999-12-18 20:29:29 +00:00
|
|
|
if (nativeGlob) {
|
2001-11-17 17:26:18 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(nativeGlob, &result);
|
1999-12-18 20:29:29 +00:00
|
|
|
|
2000-01-15 02:02:27 +00:00
|
|
|
if (window) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
result = window->GetDocument(getter_AddRefs(domDoc));
|
2001-11-17 17:26:18 +00:00
|
|
|
if (domDoc) {
|
|
|
|
return CallQueryInterface(domDoc, aDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*aDocument = nsnull;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2000-01-15 02:02:27 +00:00
|
|
|
|
2001-11-17 17:26:18 +00:00
|
|
|
nsresult
|
|
|
|
LocationImpl::GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
nsresult rv = GetSourceDocument(cx, getter_AddRefs(doc));
|
|
|
|
if (doc) {
|
2003-06-13 20:10:01 +00:00
|
|
|
rv = doc->GetBaseURL(sourceURL);
|
2000-01-15 02:02:27 +00:00
|
|
|
|
2001-11-17 17:26:18 +00:00
|
|
|
if (!*sourceURL) {
|
|
|
|
doc->GetDocumentURL(sourceURL);
|
1999-08-03 23:16:48 +00:00
|
|
|
}
|
2001-11-17 17:26:18 +00:00
|
|
|
} else {
|
|
|
|
*sourceURL = nsnull;
|
1999-08-03 23:16:48 +00:00
|
|
|
}
|
2001-11-17 17:26:18 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1999-08-03 23:16:48 +00:00
|
|
|
|
2001-11-17 17:26:18 +00:00
|
|
|
nsresult
|
|
|
|
LocationImpl::GetSourceURL(JSContext* cx, nsIURI** sourceURL)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
nsresult rv = GetSourceDocument(cx, getter_AddRefs(doc));
|
|
|
|
if (doc) {
|
|
|
|
doc->GetDocumentURL(sourceURL);
|
|
|
|
} else {
|
|
|
|
*sourceURL = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2001-05-08 19:28:46 +00:00
|
|
|
}
|