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"
|
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"
|
|
|
|
#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"
|
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
|
|
|
{
|
1999-02-04 19:06:11 +00:00
|
|
|
NS_INIT_REFCNT();
|
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
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
nsresult
|
|
|
|
LocationImpl::SetURL(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,
|
|
|
|
nsIWebNavigation::LOAD_FLAGS_NONE);
|
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
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::GetHash(nsAWritableString& aHash)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
result = GetHref(href);
|
1999-06-18 17:34:08 +00:00
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
nsXPIDLCString ref;
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
result = url->GetRef(getter_Copies(ref));
|
1999-06-23 06:12:02 +00:00
|
|
|
}
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result) && ref && *ref) {
|
2000-08-23 17:27:06 +00:00
|
|
|
aHash.Assign(NS_LITERAL_STRING("#"));
|
|
|
|
aHash.Append(NS_ConvertASCIItoUCS2(ref));
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aHash.SetLength(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::SetHash(const nsAReadableString& aHash)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri, &result));
|
|
|
|
|
|
|
|
if (url) {
|
2001-03-08 08:05:05 +00:00
|
|
|
url->SetRef(NS_ConvertUCS2toUTF8(aHash).get());
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1998-12-16 05:40:20 +00:00
|
|
|
SetURL(url);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::GetHost(nsAWritableString& aHost)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
|
|
|
nsXPIDLCString host;
|
|
|
|
|
|
|
|
result = uri->GetHost(getter_Copies(host));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
1999-06-23 03:29:44 +00:00
|
|
|
PRInt32 port;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2001-05-19 11:27:30 +00:00
|
|
|
CopyASCIItoUCS2(nsDependentCString(host), aHost);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
uri->GetPort(&port);
|
|
|
|
|
|
|
|
if (port != -1) {
|
|
|
|
aHost.Append(PRUnichar(':'));
|
2000-08-23 17:27:06 +00:00
|
|
|
|
|
|
|
nsAutoString tmpHost;
|
|
|
|
tmpHost.AppendInt(port);
|
|
|
|
|
|
|
|
aHost.Append(tmpHost);
|
1998-12-16 05:40:20 +00:00
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::SetHost(const nsAReadableString& aHost)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
2001-03-08 08:05:05 +00:00
|
|
|
uri->SetHost(NS_ConvertUCS2toUTF8(aHost).get());
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
SetURL(uri);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::GetHostname(nsAWritableString& aHostname)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
|
|
|
nsXPIDLCString host;
|
|
|
|
|
|
|
|
result = uri->GetHost(getter_Copies(host));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2001-05-19 11:27:30 +00:00
|
|
|
CopyASCIItoUCS2(nsDependentCString(host), aHostname);
|
1999-06-23 03:29:44 +00:00
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::SetHostname(const nsAReadableString& aHostname)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
2001-03-08 08:05:05 +00:00
|
|
|
uri->SetHost(NS_ConvertUCS2toUTF8(aHostname).get());
|
2001-01-09 01:16:36 +00:00
|
|
|
SetURL(uri);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::GetHref(nsAWritableString& aHref)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2000-08-30 11:37:06 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2000-08-30 11:37:06 +00:00
|
|
|
if (webNav) {
|
2000-03-11 02:57:39 +00:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2000-08-30 11:37:06 +00:00
|
|
|
result = webNav->GetCurrentURI(getter_AddRefs(uri));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2000-04-28 06:17:47 +00:00
|
|
|
if (NS_SUCCEEDED(result) && uri) {
|
2000-08-23 17:27:06 +00:00
|
|
|
nsXPIDLCString uriString;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
result = uri->GetSpec(getter_Copies(uriString));
|
2001-01-09 01:16:36 +00:00
|
|
|
|
2000-08-23 17:27:06 +00:00
|
|
|
if (NS_SUCCEEDED(result))
|
2001-05-19 11:27:30 +00:00
|
|
|
CopyASCIItoUCS2(nsDependentCString(uriString), aHref);
|
2000-03-11 02:57:39 +00:00
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::SetHref(const nsAReadableString& 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
|
2001-05-15 20:58:31 +00:00
|
|
|
LocationImpl::SetHrefWithContext(JSContext* cx, const nsAReadableString& aHref,
|
|
|
|
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
|
|
|
|
nsresult result = GetSourceURL(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
|
2001-01-09 01:16:36 +00:00
|
|
|
LocationImpl::SetHrefWithBase(const nsAReadableString& aHref,
|
|
|
|
nsIURI* aBase, PRBool aReplace)
|
1999-08-03 23:16:48 +00:00
|
|
|
{
|
|
|
|
nsresult result;
|
2001-01-09 01:16:36 +00:00
|
|
|
nsCOMPtr<nsIURI> newUri;
|
1998-08-13 04:34:53 +00:00
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
result = NS_NewURI(getter_AddRefs(newUri), aHref, aBase);
|
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,
|
|
|
|
nsIWebNavigation::LOAD_FLAGS_NONE);
|
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
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::GetPathname(nsAWritableString& aPathname)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
aPathname.Truncate();
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
|
2000-04-14 03:14:53 +00:00
|
|
|
if (url) {
|
2001-01-09 01:16:36 +00:00
|
|
|
nsXPIDLCString file;
|
|
|
|
result = url->GetFilePath(getter_Copies(file));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2001-05-19 11:27:30 +00:00
|
|
|
CopyASCIItoUCS2(nsDependentCString(file), aPathname);
|
2000-04-14 03:14:53 +00:00
|
|
|
}
|
1999-06-23 03:29:44 +00:00
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::SetPathname(const nsAReadableString& aPathname)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
2001-03-08 08:05:05 +00:00
|
|
|
uri->SetPath(NS_ConvertUCS2toUTF8(aPathname).get());
|
2001-01-09 01:16:36 +00:00
|
|
|
SetURL(uri);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::GetPort(nsAWritableString& aPort)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
1998-08-13 04:34:53 +00:00
|
|
|
aPort.SetLength(0);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1999-06-23 03:29:44 +00:00
|
|
|
PRInt32 port;
|
2001-01-09 01:16:36 +00:00
|
|
|
uri->GetPort(&port);
|
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
if (-1 != port) {
|
2000-08-23 17:27:06 +00:00
|
|
|
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
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::SetPort(const nsAReadableString& aPort)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
2001-03-08 13:57:08 +00:00
|
|
|
// perhaps use nsReadingIterators at some point?
|
|
|
|
NS_ConvertUCS2toUTF8 portStr(aPort);
|
|
|
|
const char *buf = portStr.get();
|
1998-08-13 04:34:53 +00:00
|
|
|
PRInt32 port = -1;
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
if (*buf == ':') {
|
|
|
|
port = atol(buf+1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
port = atol(buf);
|
|
|
|
}
|
|
|
|
}
|
2001-01-09 01:16:36 +00:00
|
|
|
uri->SetPort(port);
|
|
|
|
SetURL(uri);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::GetProtocol(nsAWritableString& aProtocol)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
2001-01-09 01:16:36 +00:00
|
|
|
|
1998-08-13 04:34:53 +00:00
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
|
|
|
nsXPIDLCString protocol;
|
|
|
|
|
|
|
|
result = uri->GetScheme(getter_Copies(protocol));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2000-08-23 17:27:06 +00:00
|
|
|
aProtocol.Assign(NS_ConvertASCIItoUCS2(protocol));
|
2001-01-09 01:16:36 +00:00
|
|
|
aProtocol.Append(PRUnichar(':'));
|
1998-12-16 05:40:20 +00:00
|
|
|
}
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::SetProtocol(const nsAReadableString& aProtocol)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
2001-03-08 08:05:05 +00:00
|
|
|
uri->SetScheme(NS_ConvertUCS2toUTF8(aProtocol).get());
|
2001-01-09 01:16:36 +00:00
|
|
|
SetURL(uri);
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::GetSearch(nsAWritableString& aSearch)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
|
|
|
nsXPIDLCString search;
|
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
|
|
|
|
if (url) {
|
|
|
|
result = url->GetEscapedQuery(getter_Copies(search));
|
1999-06-23 06:12:02 +00:00
|
|
|
}
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result) && search && *search) {
|
2000-08-23 17:27:06 +00:00
|
|
|
aSearch.Assign(NS_LITERAL_STRING("?"));
|
|
|
|
aSearch.Append(NS_ConvertASCIItoUCS2(search));
|
1998-08-13 04:34:53 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aSearch.SetLength(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::SetSearch(const nsAReadableString& aSearch)
|
1998-08-13 04:34:53 +00:00
|
|
|
{
|
|
|
|
nsAutoString href;
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
result = GetHref(href);
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
result = NS_NewURI(getter_AddRefs(uri), href);
|
|
|
|
|
|
|
|
if (uri) {
|
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri, &result));
|
|
|
|
|
|
|
|
if (url) {
|
2001-03-08 08:05:05 +00:00
|
|
|
result = url->SetQuery(NS_ConvertUCS2toUTF8(aSearch).get());
|
2001-01-09 01:16:36 +00:00
|
|
|
|
|
|
|
SetURL(uri);
|
1999-06-23 06:12:02 +00:00
|
|
|
}
|
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-01-09 01:16:36 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mDocShell));
|
|
|
|
NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE);
|
1998-08-13 04:34:53 +00:00
|
|
|
|
2001-01-09 01:16:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(webNav->Reload(nsIWebNavigation::LOAD_FLAGS_NONE),
|
|
|
|
NS_ERROR_FAILURE);
|
1998-08-13 04:34:53 +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
|
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
|
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::Replace(const nsAReadableString& 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
|
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::Assign(const nsAReadableString& 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
|
2000-08-23 17:27:06 +00:00
|
|
|
LocationImpl::ToString(nsAWritableString& aReturn)
|
1999-01-06 17:22:34 +00:00
|
|
|
{
|
|
|
|
return GetHref(aReturn);
|
|
|
|
}
|
|
|
|
|
1999-08-03 23:16:48 +00:00
|
|
|
nsresult
|
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::GetSourceURL(JSContext* cx, nsIURI** sourceURI)
|
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) {
|
2000-01-15 02:02:27 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(nativeGlob);
|
1999-12-18 20:29:29 +00:00
|
|
|
|
2000-01-15 02:02:27 +00:00
|
|
|
if (window) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
1999-12-18 20:29:29 +00:00
|
|
|
|
2000-01-15 02:02:27 +00:00
|
|
|
result = window->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2001-01-09 01:16:36 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
|
2000-01-15 02:02:27 +00:00
|
|
|
|
|
|
|
if (doc) {
|
2001-01-09 01:16:36 +00:00
|
|
|
result = doc->GetBaseURL(*sourceURI);
|
2000-01-15 02:02:27 +00:00
|
|
|
|
2001-03-22 07:11:49 +00:00
|
|
|
if (!*sourceURI) {
|
2001-06-20 03:27:48 +00:00
|
|
|
doc->GetDocumentURL(sourceURI);
|
2001-03-22 07:11:49 +00:00
|
|
|
}
|
2000-01-15 02:02:27 +00:00
|
|
|
}
|
|
|
|
}
|
1999-08-03 23:16:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2001-05-08 19:28:46 +00:00
|
|
|
}
|