2001-09-26 02:43:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2005-10-17 22:47:13 +04:00
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2001-09-26 02:43:09 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-08-13 08:34:53 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
1998-08-13 08:34:53 +04:00
|
|
|
*
|
2001-09-26 02:43:09 +04: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 08:34:53 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-26 02:43:09 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2000-02-08 16:40:10 +03:00
|
|
|
* Contributor(s):
|
2001-01-09 04:16:36 +03:00
|
|
|
* Travis Bogard <travis@netscape.com>
|
2000-01-11 23:49:15 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-26 02:43:09 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of 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"),
|
2001-09-26 02:43:09 +04:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-26 02:43:09 +04:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-26 02:43:09 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1998-08-13 08:34:53 +04:00
|
|
|
|
|
|
|
#include "nsGlobalWindow.h"
|
2003-06-26 04:41:23 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIScriptContext.h"
|
2000-02-08 16:40:10 +03:00
|
|
|
#include "nsIDocShell.h"
|
2000-03-31 02:38:32 +04:00
|
|
|
#include "nsIDocShellLoadInfo.h"
|
2000-02-24 06:57:32 +03:00
|
|
|
#include "nsIWebNavigation.h"
|
2002-12-12 18:48:30 +03:00
|
|
|
#include "nsCDefaultURIFixup.h"
|
|
|
|
#include "nsIURIFixup.h"
|
1998-08-13 08:34:53 +04:00
|
|
|
#include "nsIURL.h"
|
2004-04-24 20:09:31 +04:00
|
|
|
#include "nsIJARURI.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsIServiceManager.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1998-08-13 08:34:53 +04:00
|
|
|
#include "plstr.h"
|
2000-08-23 21:27:06 +04:00
|
|
|
#include "prprf.h"
|
1998-08-13 08:34:53 +04:00
|
|
|
#include "prmem.h"
|
1999-08-04 03:16:48 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2002-03-06 10:48:55 +03:00
|
|
|
#include "nsEscape.h"
|
1999-08-04 03:16:48 +04:00
|
|
|
#include "nsJSUtils.h"
|
2000-01-15 05:02:27 +03:00
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
2004-10-20 06:19:57 +04:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsPresContext.h"
|
1999-09-07 06:54:19 +04:00
|
|
|
#include "nsIJSContextStack.h"
|
2000-02-10 07:56:56 +03:00
|
|
|
#include "nsXPIDLString.h"
|
2000-02-11 07:18:39 +03: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 21:42:36 +04:00
|
|
|
#include "nsDOMClassInfo.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2003-03-06 01:23:47 +03:00
|
|
|
#include "nsIProtocolHandler.h"
|
2003-12-23 18:41:10 +03:00
|
|
|
#include "nsReadableUtils.h"
|
2004-05-21 04:53:40 +04:00
|
|
|
#include "nsITextToSubURI.h"
|
2004-09-01 20:50:12 +04:00
|
|
|
#include "nsContentUtils.h"
|
2001-11-15 02:45:23 +03:00
|
|
|
|
2005-10-17 22:47:13 +04:00
|
|
|
static nsresult
|
|
|
|
GetContextFromStack(nsIJSContextStack *aStack, JSContext **aContext)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIJSContextStackIterator>
|
2005-10-18 21:17:12 +04:00
|
|
|
iterator(do_CreateInstance("@mozilla.org/js/xpc/ContextStackIterator;1"));
|
2005-10-17 22:47:13 +04:00
|
|
|
NS_ENSURE_TRUE(iterator, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsresult rv = iterator->Reset(aStack);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-06-07 21:15:51 +04:00
|
|
|
|
2005-10-17 22:47:13 +04:00
|
|
|
PRBool done;
|
|
|
|
while (NS_SUCCEEDED(iterator->Done(&done)) && !done) {
|
|
|
|
rv = iterator->Prev(aContext);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Broken iterator implementation");
|
|
|
|
|
2006-06-07 21:15:51 +04:00
|
|
|
// Consider a null context the end of the line.
|
|
|
|
if (!*aContext) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-10-17 22:47:13 +04:00
|
|
|
if (nsJSUtils::GetDynamicScriptContext(*aContext)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aContext = nsnull;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
static nsresult
|
|
|
|
GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString& aCharset)
|
2001-11-15 02:45:23 +03:00
|
|
|
{
|
2002-08-14 03:26:05 +04:00
|
|
|
aCharset.Truncate();
|
2001-11-15 02:45:23 +03:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
JSContext *cx;
|
|
|
|
|
2005-10-17 22:47:13 +04:00
|
|
|
rv = GetContextFromStack(stack, &cx);
|
2001-11-15 02:45:23 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2004-03-03 21:13:00 +03:00
|
|
|
if (cx) {
|
|
|
|
nsCOMPtr<nsIDOMWindow> window =
|
|
|
|
do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx));
|
|
|
|
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
2001-11-15 02:45:23 +03:00
|
|
|
|
2004-03-03 21:13:00 +03:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
rv = window->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
|
2001-11-15 02:45:23 +03:00
|
|
|
|
2004-03-03 21:13:00 +03:00
|
|
|
if (doc) {
|
|
|
|
aCharset = doc->GetDocumentCharacterSet();
|
|
|
|
}
|
|
|
|
}
|
2001-11-15 02:45:23 +03:00
|
|
|
|
2003-10-22 10:09:48 +04:00
|
|
|
return NS_OK;
|
2001-11-15 02:45:23 +03:00
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::nsLocation(nsIDocShell *aDocShell)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2006-06-20 22:56:03 +04:00
|
|
|
mDocShell = do_GetWeakReference(aDocShell);
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::~nsLocation()
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-01-12 16:08:43 +03:00
|
|
|
DOMCI_DATA(Location, nsLocation)
|
1998-08-13 08:34:53 +04:00
|
|
|
|
2004-12-10 22:48:22 +03:00
|
|
|
// QueryInterface implementation for nsLocation
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsLocation)
|
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 21:42:36 +04:00
|
|
|
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 04:16:36 +03:00
|
|
|
|
|
|
|
|
2004-12-10 22:48:22 +03:00
|
|
|
NS_IMPL_ADDREF(nsLocation)
|
|
|
|
NS_IMPL_RELEASE(nsLocation)
|
1998-08-13 08:34:53 +04:00
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
void
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::SetDocShell(nsIDocShell *aDocShell)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2006-06-20 22:56:03 +04:00
|
|
|
mDocShell = do_GetWeakReference(aDocShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocShell *
|
|
|
|
nsLocation::GetDocShell()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShell> docshell(do_QueryReferent(mDocShell));
|
|
|
|
return docshell;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
nsresult
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo)
|
1999-09-07 06:54:19 +04:00
|
|
|
{
|
2002-07-25 00:42:22 +04:00
|
|
|
*aLoadInfo = nsnull;
|
|
|
|
|
2006-06-20 22:56:03 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
|
|
|
|
if (!docShell) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
1999-09-07 06:54:19 +04:00
|
|
|
nsresult result;
|
|
|
|
// Get JSContext from stack.
|
2001-01-09 04:16:36 +03:00
|
|
|
nsCOMPtr<nsIJSContextStack>
|
|
|
|
stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &result));
|
|
|
|
|
1999-09-07 06:54:19 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
1999-09-07 06:54:19 +04:00
|
|
|
JSContext *cx;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2005-10-17 22:47:13 +04:00
|
|
|
if (NS_FAILED(GetContextFromStack(stack, &cx)))
|
1999-09-07 06:54:19 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2005-02-24 23:19:58 +03:00
|
|
|
nsCOMPtr<nsISupports> owner;
|
|
|
|
|
|
|
|
if (cx) {
|
2002-07-25 00:42:22 +04:00
|
|
|
// 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
|
2005-02-24 23:19:58 +03:00
|
|
|
// does). We won't bother with security checks in this case, but
|
|
|
|
// we need to create the loadinfo etc.
|
2002-07-25 00:42:22 +04:00
|
|
|
|
2005-02-24 23:19:58 +03:00
|
|
|
// Get security manager.
|
|
|
|
nsCOMPtr<nsIScriptSecurityManager>
|
|
|
|
secMan(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &result));
|
2002-07-25 00:42:22 +04:00
|
|
|
|
2005-02-24 23:19:58 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2005-02-24 23:19:58 +03:00
|
|
|
// Check to see if URI is allowed.
|
|
|
|
result = secMan->CheckLoadURIFromScript(cx, aURI);
|
1999-09-07 06:54:19 +04:00
|
|
|
|
2005-02-24 23:19:58 +03:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2005-02-24 23:19:58 +03:00
|
|
|
// Now get the principal to use when loading the URI
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
|
|
if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal))) ||
|
|
|
|
!principal)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
owner = do_QueryInterface(principal);
|
|
|
|
}
|
1999-09-07 06:54:19 +04:00
|
|
|
|
2000-08-11 08:31:08 +04:00
|
|
|
// Create load info
|
|
|
|
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
|
2006-06-20 22:56:03 +04:00
|
|
|
docShell->CreateLoadInfo(getter_AddRefs(loadInfo));
|
2000-08-11 08:31:08 +04:00
|
|
|
NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
loadInfo->SetOwner(owner);
|
|
|
|
|
2009-09-01 20:45:05 +04:00
|
|
|
// Now set the referrer on the loadinfo. We need to do this in order to get
|
|
|
|
// the correct referrer URI from a document which was pushStated.
|
|
|
|
nsCOMPtr<nsIURI> sourceURI;
|
|
|
|
result = GetURI(getter_AddRefs(sourceURI));
|
|
|
|
if (NS_SUCCEEDED(result))
|
2001-11-17 20:26:18 +03:00
|
|
|
loadInfo->SetReferrer(sourceURI);
|
2005-02-24 23:19:58 +03:00
|
|
|
|
|
|
|
loadInfo.swap(*aLoadInfo);
|
2001-01-09 04:16:36 +03:00
|
|
|
|
1999-09-07 06:54:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsresult
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::GetURI(nsIURI** aURI, PRBool aGetInnermostURI)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
2002-03-23 03:48:40 +03:00
|
|
|
*aURI = nsnull;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsresult rv;
|
2006-06-20 22:56:03 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell, &rv));
|
2002-03-23 03:48:40 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2002-12-12 18:48:30 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = webNav->GetCurrentURI(getter_AddRefs(uri));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2003-01-05 09:34:53 +03:00
|
|
|
// It is valid for docshell to return a null URI. Don't try to fixup
|
|
|
|
// if this happens.
|
|
|
|
if (!uri) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-24 20:09:31 +04:00
|
|
|
if (aGetInnermostURI) {
|
|
|
|
nsCOMPtr<nsIJARURI> jarURI(do_QueryInterface(uri));
|
|
|
|
while (jarURI) {
|
|
|
|
jarURI->GetJARFile(getter_AddRefs(uri));
|
|
|
|
jarURI = do_QueryInterface(uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(uri, "nsJARURI screwed up?");
|
|
|
|
|
2002-12-12 18:48:30 +03:00
|
|
|
nsCOMPtr<nsIURIFixup> urifixup(do_GetService(NS_URIFIXUP_CONTRACTID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return urifixup->CreateExposableURI(uri, aURI);
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::GetWritableURI(nsIURI** aURI)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
2002-03-23 03:48:40 +03:00
|
|
|
*aURI = nsnull;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
|
|
|
|
nsresult rv = GetURI(getter_AddRefs(uri));
|
2002-03-23 03:48:40 +03:00
|
|
|
if (NS_FAILED(rv) || !uri) {
|
|
|
|
return rv;
|
|
|
|
}
|
2002-03-06 10:48:55 +03:00
|
|
|
|
|
|
|
return uri->Clone(aURI);
|
|
|
|
}
|
1999-09-07 06:54:19 +04:00
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
nsresult
|
2005-01-20 19:57:04 +03:00
|
|
|
nsLocation::SetURI(nsIURI* aURI, PRBool aReplace)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2006-06-20 22:56:03 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
|
|
|
|
if (docShell) {
|
2000-03-31 02:38:32 +04:00
|
|
|
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
|
2006-06-20 22:56:03 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
|
|
|
if(NS_FAILED(CheckURL(aURI, getter_AddRefs(loadInfo))))
|
1999-09-07 06:54:19 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2005-01-20 19:57:04 +03:00
|
|
|
if (aReplace) {
|
|
|
|
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadStopContentAndReplace);
|
|
|
|
} else {
|
|
|
|
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadStopContent);
|
|
|
|
}
|
|
|
|
|
2006-06-20 22:56:03 +04:00
|
|
|
return docShell->LoadURI(aURI, loadInfo,
|
|
|
|
nsIWebNavigation::LOAD_FLAGS_NONE, PR_TRUE);
|
1998-11-23 04:09:27 +03:00
|
|
|
}
|
2001-01-09 04:16:36 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::GetHash(nsAString& aHash)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2002-03-23 03:48:40 +03:00
|
|
|
aHash.SetLength(0);
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2004-05-21 04:53:40 +04:00
|
|
|
nsresult rv = GetURI(getter_AddRefs(uri));
|
1999-06-18 21:34:08 +04:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
|
|
|
|
if (url) {
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString ref;
|
2004-05-21 04:53:40 +04:00
|
|
|
nsAutoString unicodeRef;
|
|
|
|
|
|
|
|
rv = url->GetRef(ref);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsITextToSubURI> textToSubURI(
|
|
|
|
do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCAutoString charset;
|
|
|
|
url->GetOriginCharset(charset);
|
|
|
|
|
|
|
|
rv = textToSubURI->UnEscapeURIForUI(charset, ref, unicodeRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Oh, well. No intl here!
|
|
|
|
NS_UnescapeURL(ref);
|
2004-05-21 04:55:10 +04:00
|
|
|
CopyASCIItoUTF16(ref, unicodeRef);
|
2004-05-21 04:53:40 +04:00
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
}
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2004-05-21 04:53:40 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && !unicodeRef.IsEmpty()) {
|
2003-12-23 18:41:10 +03:00
|
|
|
aHash.Assign(PRUnichar('#'));
|
2004-05-21 04:53:40 +04:00
|
|
|
aHash.Append(unicodeRef);
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2004-05-21 04:53:40 +04:00
|
|
|
return rv;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::SetHash(const nsAString& aHash)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2007-05-04 10:42:28 +04:00
|
|
|
nsresult rv = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
if (url) {
|
2008-11-27 00:52:54 +03:00
|
|
|
NS_ConvertUTF16toUTF8 hash(aHash);
|
|
|
|
if (hash.IsEmpty() || hash.First() != PRUnichar('#')) {
|
|
|
|
hash.Insert(PRUnichar('#'), 0);
|
|
|
|
}
|
|
|
|
rv = url->SetRef(hash);
|
2007-05-04 10:42:28 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
SetURI(url);
|
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2007-05-04 10:42:28 +04:00
|
|
|
return rv;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::GetHost(nsAString& aHost)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2003-12-23 18:41:10 +03:00
|
|
|
aHost.Truncate();
|
2002-03-23 03:48:40 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult result;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2004-04-24 20:09:31 +04:00
|
|
|
result = GetURI(getter_AddRefs(uri), PR_TRUE);
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (uri) {
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString hostport;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
result = uri->GetHostPort(hostport);
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2003-12-23 18:41:10 +03:00
|
|
|
AppendUTF8toUTF16(hostport, aHost);
|
2002-03-23 03:48:40 +03:00
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2010-08-07 11:11:43 +04:00
|
|
|
return NS_OK;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::SetHost(const nsAString& aHost)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2007-05-04 10:42:28 +04:00
|
|
|
nsresult rv = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (uri) {
|
2007-05-04 10:42:28 +04:00
|
|
|
rv = uri->SetHostPort(NS_ConvertUTF16toUTF8(aHost));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
SetURI(uri);
|
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2007-05-04 10:42:28 +04:00
|
|
|
return rv;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::GetHostname(nsAString& aHostname)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2003-12-23 18:41:10 +03:00
|
|
|
aHostname.Truncate();
|
2002-03-23 03:48:40 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult result;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2004-04-24 20:09:31 +04:00
|
|
|
result = GetURI(getter_AddRefs(uri), PR_TRUE);
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (uri) {
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString host;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
result = uri->GetHost(host);
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2003-12-23 18:41:10 +03:00
|
|
|
AppendUTF8toUTF16(host, aHostname);
|
2002-03-23 03:48:40 +03:00
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2010-08-07 11:11:43 +04:00
|
|
|
return NS_OK;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::SetHostname(const nsAString& aHostname)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2007-05-04 10:42:28 +04:00
|
|
|
nsresult rv = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (uri) {
|
2007-05-04 10:42:28 +04:00
|
|
|
rv = uri->SetHost(NS_ConvertUTF16toUTF8(aHostname));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
SetURI(uri);
|
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2007-05-04 10:42:28 +04:00
|
|
|
return rv;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::GetHref(nsAString& aHref)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2003-12-23 18:41:10 +03:00
|
|
|
aHref.Truncate();
|
2002-03-23 03:48:40 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult result;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
result = GetURI(getter_AddRefs(uri));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (uri) {
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString uriString;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
result = uri->GetSpec(uriString);
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2003-12-23 18:41:10 +03:00
|
|
|
AppendUTF8toUTF16(uriString, aHref);
|
2002-03-23 03:48:40 +03:00
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::SetHref(const nsAString& aHref)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
1999-08-04 03:16:48 +04: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 21:42:36 +04:00
|
|
|
nsresult rv = NS_OK;
|
1998-11-23 04:09:27 +03: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 21:42:36 +04:00
|
|
|
// Get JSContext from stack.
|
|
|
|
nsCOMPtr<nsIJSContextStack>
|
|
|
|
stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv));
|
2001-01-09 04:16:36 +03: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 21:42:36 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_ERROR_FAILURE;
|
2001-01-09 04:16:36 +03: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 21:42:36 +04:00
|
|
|
JSContext *cx;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2005-10-17 22:47:13 +04:00
|
|
|
if (NS_FAILED(GetContextFromStack(stack, &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 21:42:36 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (cx) {
|
2001-05-16 00:58:31 +04: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 21:42:36 +04: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-04 03:16:48 +04: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 21:42:36 +04:00
|
|
|
return rv;
|
1999-08-04 03:16:48 +04:00
|
|
|
}
|
|
|
|
|
2000-08-29 04:14:23 +04:00
|
|
|
nsresult
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::SetHrefWithContext(JSContext* cx, const nsAString& aHref,
|
|
|
|
PRBool aReplace)
|
2000-08-29 04:14:23 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> base;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2000-08-29 04:14:23 +04:00
|
|
|
// Get the source of the caller
|
2001-11-17 20:26:18 +03:00
|
|
|
nsresult result = GetSourceBaseURL(cx, getter_AddRefs(base));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2000-08-29 04:14:23 +04:00
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-05-16 00:58:31 +04:00
|
|
|
return SetHrefWithBase(aHref, base, aReplace);
|
2001-01-09 04:16:36 +03:00
|
|
|
}
|
2000-08-29 04:14:23 +04:00
|
|
|
|
1999-08-04 03:16:48 +04:00
|
|
|
nsresult
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::SetHrefWithBase(const nsAString& aHref, nsIURI* aBase,
|
|
|
|
PRBool aReplace)
|
1999-08-04 03:16:48 +04:00
|
|
|
{
|
|
|
|
nsresult result;
|
2009-03-25 04:52:24 +03:00
|
|
|
nsCOMPtr<nsIURI> newUri;
|
2003-03-06 01:23:47 +03:00
|
|
|
|
2006-06-20 22:56:03 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
|
|
|
|
|
2002-08-14 03:26:05 +04:00
|
|
|
nsCAutoString docCharset;
|
|
|
|
if (NS_SUCCEEDED(GetDocumentCharacterSetForURI(aHref, docCharset)))
|
2009-03-25 04:52:24 +03:00
|
|
|
result = NS_NewURI(getter_AddRefs(newUri), aHref, docCharset.get(), aBase);
|
2001-11-15 02:45:23 +03:00
|
|
|
else
|
2009-03-25 04:52:24 +03:00
|
|
|
result = NS_NewURI(getter_AddRefs(newUri), aHref, nsnull, aBase);
|
1999-09-01 04:54:35 +04:00
|
|
|
|
2005-01-20 19:57:04 +03:00
|
|
|
if (newUri) {
|
2001-05-16 02:26:19 +04: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;
|
|
|
|
|
2005-10-17 22:47:13 +04:00
|
|
|
result = GetContextFromStack(stack, &cx);
|
2001-05-16 02:26:19 +04:00
|
|
|
if (cx) {
|
2004-02-10 01:48:53 +03:00
|
|
|
nsIScriptContext *scriptContext =
|
|
|
|
nsJSUtils::GetDynamicScriptContext(cx);
|
2003-06-25 01:43:01 +04:00
|
|
|
|
|
|
|
if (scriptContext) {
|
2004-06-01 19:18:32 +04:00
|
|
|
if (scriptContext->GetProcessingScriptTag()) {
|
|
|
|
// Now check to make sure that the script is running in our window,
|
|
|
|
// since we only want to replace if the location is set by a
|
|
|
|
// <script> tag in the same window. See bug 178729.
|
2006-06-20 22:56:03 +04:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> ourGlobal(do_GetInterface(docShell));
|
2004-06-01 19:18:32 +04:00
|
|
|
inScriptTag = (ourGlobal == scriptContext->GetGlobalObject());
|
|
|
|
}
|
2001-05-16 02:26:19 +04:00
|
|
|
}
|
|
|
|
} //cx
|
|
|
|
} // stack
|
|
|
|
|
2005-01-20 19:57:04 +03:00
|
|
|
return SetURI(newUri, aReplace || inScriptTag);
|
1998-11-23 04:09:27 +03:00
|
|
|
}
|
2001-01-09 04:16:36 +03:00
|
|
|
|
1998-11-23 04:09:27 +03:00
|
|
|
return result;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::GetPathname(nsAString& aPathname)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2003-12-23 18:41:10 +03:00
|
|
|
aPathname.Truncate();
|
2002-03-23 03:48:40 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 08:34:53 +04:00
|
|
|
nsresult result = NS_OK;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
result = GetURI(getter_AddRefs(uri));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
if (url) {
|
|
|
|
nsCAutoString file;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
result = url->GetFilePath(file);
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2003-12-23 18:41:10 +03:00
|
|
|
AppendUTF8toUTF16(file, aPathname);
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::SetPathname(const nsAString& aPathname)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2007-05-04 10:42:28 +04:00
|
|
|
nsresult rv = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (uri) {
|
2007-05-04 10:42:28 +04:00
|
|
|
rv = uri->SetPath(NS_ConvertUTF16toUTF8(aPathname));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
SetURI(uri);
|
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2007-05-04 10:42:28 +04:00
|
|
|
return rv;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::GetPort(nsAString& aPort)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2002-03-23 03:48:40 +03:00
|
|
|
aPort.SetLength(0);
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 08:34:53 +04:00
|
|
|
nsresult result = NS_OK;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2004-04-24 20:09:31 +04:00
|
|
|
result = GetURI(getter_AddRefs(uri), PR_TRUE);
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (uri) {
|
2002-03-06 10:48:55 +03:00
|
|
|
PRInt32 port;
|
2005-07-20 01:12:18 +04:00
|
|
|
result = uri->GetPort(&port);
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2005-07-20 01:12:18 +04:00
|
|
|
if (NS_SUCCEEDED(result) && -1 != port) {
|
2002-03-06 10:48:55 +03:00
|
|
|
nsAutoString portStr;
|
|
|
|
portStr.AppendInt(port);
|
|
|
|
aPort.Append(portStr);
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
2005-07-20 01:12:18 +04:00
|
|
|
|
|
|
|
// Don't propagate this exception to caller
|
|
|
|
result = NS_OK;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::SetPort(const nsAString& aPort)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2007-05-04 10:42:28 +04:00
|
|
|
nsresult rv = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (uri) {
|
2002-03-06 10:48:55 +03:00
|
|
|
// perhaps use nsReadingIterators at some point?
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertUTF16toUTF8 portStr(aPort);
|
2002-03-06 10:48:55 +03:00
|
|
|
const char *buf = portStr.get();
|
|
|
|
PRInt32 port = -1;
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
if (*buf == ':') {
|
|
|
|
port = atol(buf+1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
port = atol(buf);
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
}
|
2002-03-23 03:48:40 +03:00
|
|
|
|
2007-05-04 10:42:28 +04:00
|
|
|
rv = uri->SetPort(port);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
SetURI(uri);
|
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2007-05-04 10:42:28 +04:00
|
|
|
return rv;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::GetProtocol(nsAString& aProtocol)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2002-03-23 03:48:40 +03:00
|
|
|
aProtocol.SetLength(0);
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 08:34:53 +04:00
|
|
|
nsresult result = NS_OK;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
result = GetURI(getter_AddRefs(uri));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (uri) {
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString protocol;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
result = uri->GetScheme(protocol);
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
2003-12-23 18:41:10 +03:00
|
|
|
CopyASCIItoUTF16(protocol, aProtocol);
|
2002-03-06 10:48:55 +03:00
|
|
|
aProtocol.Append(PRUnichar(':'));
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::SetProtocol(const nsAString& aProtocol)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2007-05-04 10:42:28 +04:00
|
|
|
nsresult rv = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
if (uri) {
|
2007-05-04 10:42:28 +04:00
|
|
|
rv = uri->SetScheme(NS_ConvertUTF16toUTF8(aProtocol));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
SetURI(uri);
|
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2007-05-04 10:42:28 +04:00
|
|
|
return rv;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::GetSearch(nsAString& aSearch)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2002-03-23 03:48:40 +03:00
|
|
|
aSearch.SetLength(0);
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
1998-08-13 08:34:53 +04:00
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
result = GetURI(getter_AddRefs(uri));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
|
|
|
|
if (url) {
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString search;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
result = url->GetQuery(search);
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
if (NS_SUCCEEDED(result) && !search.IsEmpty()) {
|
2003-12-23 18:41:10 +03:00
|
|
|
aSearch.Assign(PRUnichar('?'));
|
|
|
|
AppendUTF8toUTF16(search, aSearch);
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2000-07-15 04:14:02 +04:00
|
|
|
return NS_OK;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::SetSearch(const nsAString& aSearch)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2007-05-04 10:42:28 +04:00
|
|
|
nsresult rv = GetWritableURI(getter_AddRefs(uri));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2002-03-23 03:48:40 +03:00
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
|
|
|
|
if (url) {
|
2007-05-04 10:42:28 +04:00
|
|
|
rv = url->SetQuery(NS_ConvertUTF16toUTF8(aSearch));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
SetURI(uri);
|
|
|
|
}
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2007-05-04 10:42:28 +04:00
|
|
|
return rv;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::Reload(PRBool aForceget)
|
1998-08-13 08:34:53 +04:00
|
|
|
{
|
2001-10-09 09:02:25 +04:00
|
|
|
nsresult rv;
|
2006-06-20 22:56:03 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell));
|
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(docShell));
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window(do_GetInterface(docShell));
|
2004-10-20 06:19:57 +04:00
|
|
|
|
|
|
|
if (window && window->IsHandlingResizeEvent()) {
|
|
|
|
// location.reload() was called on a window that is handling a
|
|
|
|
// resize event. Sites do this since Netscape 4.x needed it, but
|
|
|
|
// we don't, and it's a horrible experience for nothing. In stead
|
|
|
|
// of reloading the page, just clear style data and reflow the
|
|
|
|
// page since some sites may use this trick to work around gecko
|
|
|
|
// reflow bugs, and this should have the same effect.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc(do_QueryInterface(window->GetExtantDocument()));
|
|
|
|
|
|
|
|
nsIPresShell *shell;
|
|
|
|
nsPresContext *pcx;
|
2010-06-25 17:59:57 +04:00
|
|
|
if (doc && (shell = doc->GetShell()) && (pcx = shell->GetPresContext())) {
|
2008-02-08 22:52:46 +03:00
|
|
|
pcx->RebuildAllStyleData(NS_STYLE_HINT_REFLOW);
|
2004-10-20 06:19:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-09-06 01:54:53 +04:00
|
|
|
if (webNav) {
|
|
|
|
PRUint32 reloadFlags = nsIWebNavigation::LOAD_FLAGS_NONE;
|
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 21:42:36 +04:00
|
|
|
|
2008-09-06 01:54:53 +04:00
|
|
|
if (aForceget) {
|
|
|
|
reloadFlags = nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE |
|
|
|
|
nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY;
|
|
|
|
}
|
|
|
|
rv = webNav->Reload(reloadFlags);
|
|
|
|
if (rv == NS_BINDING_ABORTED) {
|
|
|
|
// This happens when we attempt to reload a POST result and the user says
|
|
|
|
// no at the "do you want to reload?" prompt. Don't propagate this one
|
|
|
|
// back to callers.
|
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
|
|
|
|
2008-09-06 01:54:53 +04:00
|
|
|
return rv;
|
1999-08-04 03:16:48 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::Replace(const nsAString& aUrl)
|
2000-09-08 11:29:54 +04:00
|
|
|
{
|
2001-05-16 00:58:31 +04:00
|
|
|
nsresult rv = NS_OK;
|
2000-09-08 11:29:54 +04:00
|
|
|
|
2001-05-16 00:58:31 +04:00
|
|
|
// Get JSContext from stack.
|
|
|
|
nsCOMPtr<nsIJSContextStack>
|
2001-05-16 02:26:19 +04:00
|
|
|
stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
|
2001-01-09 04:16:36 +03:00
|
|
|
|
2001-05-16 00:58:31 +04: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 21:42:36 +04:00
|
|
|
|
2005-10-17 22:47:13 +04:00
|
|
|
rv = GetContextFromStack(stack, &cx);
|
2001-05-16 00:58:31 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (cx) {
|
|
|
|
return SetHrefWithContext(cx, aUrl, PR_TRUE);
|
2000-09-08 11:29:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-16 00:58:31 +04: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 11:29:54 +04:00
|
|
|
}
|
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::Assign(const nsAString& aUrl)
|
1999-08-04 03:16:48 +04: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 21:42:36 +04:00
|
|
|
nsAutoString oldHref;
|
1999-08-04 03:16:48 +04: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 21:42:36 +04:00
|
|
|
result = GetHref(oldHref);
|
1999-08-04 03:16:48 +04: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 21:42:36 +04:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCOMPtr<nsIURI> oldUri;
|
2001-01-09 04:16:36 +03: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 21:42:36 +04:00
|
|
|
result = NS_NewURI(getter_AddRefs(oldUri), oldHref);
|
2001-01-09 04:16:36 +03: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 21:42:36 +04:00
|
|
|
if (oldUri) {
|
|
|
|
result = SetHrefWithBase(aUrl, oldUri, PR_FALSE);
|
1999-08-04 03:16:48 +04:00
|
|
|
}
|
|
|
|
}
|
2001-01-09 04:16:36 +03:00
|
|
|
|
1999-08-04 03:16:48 +04:00
|
|
|
return result;
|
1998-08-13 08:34:53 +04:00
|
|
|
}
|
1999-01-06 20:22:34 +03:00
|
|
|
|
2001-01-09 04:16:36 +03:00
|
|
|
NS_IMETHODIMP
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::ToString(nsAString& aReturn)
|
1999-01-06 20:22:34 +03:00
|
|
|
{
|
|
|
|
return GetHref(aReturn);
|
|
|
|
}
|
|
|
|
|
1999-08-04 03:16:48 +04:00
|
|
|
nsresult
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::GetSourceDocument(JSContext* cx, nsIDocument** aDocument)
|
1999-08-04 03:16:48 +04: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.
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2001-01-09 04:16:36 +03:00
|
|
|
|
|
|
|
// We need to use the dynamically scoped global and assume that the
|
1999-12-18 23:29:29 +03: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 :(
|
|
|
|
|
2004-02-10 01:48:53 +03:00
|
|
|
nsCOMPtr<nsIDOMWindow> window =
|
|
|
|
do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx), &rv);
|
1999-12-18 23:29:29 +03:00
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
if (window) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
rv = window->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
if (domDoc) {
|
|
|
|
return CallQueryInterface(domDoc, aDocument);
|
2001-11-17 20:26:18 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*aDocument = nsnull;
|
|
|
|
}
|
2004-01-10 02:54:21 +03:00
|
|
|
|
|
|
|
return rv;
|
2001-11-17 20:26:18 +03:00
|
|
|
}
|
2000-01-15 05:02:27 +03:00
|
|
|
|
2001-11-17 20:26:18 +03:00
|
|
|
nsresult
|
2004-12-10 22:48:22 +03:00
|
|
|
nsLocation::GetSourceBaseURL(JSContext* cx, nsIURI** sourceURL)
|
2001-11-17 20:26:18 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
nsresult rv = GetSourceDocument(cx, getter_AddRefs(doc));
|
|
|
|
if (doc) {
|
2010-04-19 19:40:15 +04:00
|
|
|
*sourceURL = doc->GetBaseURI().get();
|
2004-01-10 02:54:21 +03:00
|
|
|
} else {
|
|
|
|
*sourceURL = nsnull;
|
1999-08-04 03:16:48 +04:00
|
|
|
}
|
2003-07-03 06:45:34 +04:00
|
|
|
|
2001-11-17 20:26:18 +03:00
|
|
|
return rv;
|
|
|
|
}
|