зеркало из https://github.com/mozilla/gecko-dev.git
Relative URLs specified for window.location.href are now resolved relative to the calling location.
This commit is contained in:
Родитель
0767a5bbcd
Коммит
5104a33513
|
@ -18,6 +18,7 @@
|
|||
|
||||
nsIDOMWindow.h
|
||||
nsIDOMLocation.h
|
||||
nsIDOMNSLocation.h
|
||||
nsIDOMNavigator.h
|
||||
nsIDOMWindowCollection.h
|
||||
nsIDOMScreen.h
|
||||
|
|
|
@ -28,6 +28,7 @@ EXPORTS = \
|
|||
nsIDOMWindow.h \
|
||||
nsIDOMNavigator.h \
|
||||
nsIDOMLocation.h \
|
||||
nsIDOMNSLocation.h \
|
||||
nsIDOMWindowCollection.h \
|
||||
nsIDOMScreen.h \
|
||||
nsIDOMHistory.h \
|
||||
|
|
|
@ -19,7 +19,7 @@ DEPTH=..\..\..
|
|||
IGNORE_MANIFEST=1
|
||||
|
||||
DEFINES=-D_IMPL_NS_DOM
|
||||
EXPORTS=nsIDOMWindow.h nsIDOMNavigator.h nsIDOMLocation.h \
|
||||
EXPORTS=nsIDOMWindow.h nsIDOMNavigator.h nsIDOMLocation.h nsIDOMNSLocation.h \
|
||||
nsIDOMWindowCollection.h nsIDOMScreen.h nsIDOMHistory.h \
|
||||
nsIDOMMimeType.h nsIDOMMimeTypeArray.h \
|
||||
nsIDOMPlugin.h nsIDOMPluginArray.h nsIDOMBarProp.h
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "jsapi.h"
|
||||
|
||||
|
||||
#define NS_IDOMLOCATION_IID \
|
||||
|
@ -58,7 +57,7 @@ public:
|
|||
NS_IMETHOD GetSearch(nsString& aSearch)=0;
|
||||
NS_IMETHOD SetSearch(const nsString& aSearch)=0;
|
||||
|
||||
NS_IMETHOD Reload(JSContext *cx, jsval *argv, PRUint32 argc)=0;
|
||||
NS_IMETHOD Reload(PRBool aForceget)=0;
|
||||
|
||||
NS_IMETHOD Replace(const nsString& aUrl)=0;
|
||||
|
||||
|
@ -83,7 +82,7 @@ public:
|
|||
NS_IMETHOD SetProtocol(const nsString& aProtocol); \
|
||||
NS_IMETHOD GetSearch(nsString& aSearch); \
|
||||
NS_IMETHOD SetSearch(const nsString& aSearch); \
|
||||
NS_IMETHOD Reload(JSContext *cx, jsval *argv, PRUint32 argc); \
|
||||
NS_IMETHOD Reload(PRBool aForceget); \
|
||||
NS_IMETHOD Replace(const nsString& aUrl); \
|
||||
NS_IMETHOD ToString(nsString& aReturn); \
|
||||
|
||||
|
@ -106,7 +105,7 @@ public:
|
|||
NS_IMETHOD SetProtocol(const nsString& aProtocol) { return _to SetProtocol(aProtocol); } \
|
||||
NS_IMETHOD GetSearch(nsString& aSearch) { return _to GetSearch(aSearch); } \
|
||||
NS_IMETHOD SetSearch(const nsString& aSearch) { return _to SetSearch(aSearch); } \
|
||||
NS_IMETHOD Reload(JSContext *cx, jsval *argv, PRUint32 argc) { return _to Reload(cx, argv, argc); } \
|
||||
NS_IMETHOD Reload(PRBool aForceget) { return _to Reload(aForceget); } \
|
||||
NS_IMETHOD Replace(const nsString& aUrl) { return _to Replace(aUrl); } \
|
||||
NS_IMETHOD ToString(nsString& aReturn) { return _to ToString(aReturn); } \
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
/* AUTO-GENERATED. DO NOT EDIT!!! */
|
||||
|
||||
#ifndef nsIDOMNSLocation_h__
|
||||
#define nsIDOMNSLocation_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "jsapi.h"
|
||||
|
||||
|
||||
#define NS_IDOMNSLOCATION_IID \
|
||||
{ 0xa6cf9108, 0x15b3, 0x11d2, \
|
||||
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
|
||||
|
||||
class nsIDOMNSLocation : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IDOMNSLOCATION_IID; return iid; }
|
||||
|
||||
NS_IMETHOD Reload(JSContext *cx, jsval *argv, PRUint32 argc)=0;
|
||||
|
||||
NS_IMETHOD Replace(JSContext *cx, jsval *argv, PRUint32 argc)=0;
|
||||
};
|
||||
|
||||
|
||||
#define NS_DECL_IDOMNSLOCATION \
|
||||
NS_IMETHOD Reload(JSContext *cx, jsval *argv, PRUint32 argc); \
|
||||
NS_IMETHOD Replace(JSContext *cx, jsval *argv, PRUint32 argc); \
|
||||
|
||||
|
||||
|
||||
#define NS_FORWARD_IDOMNSLOCATION(_to) \
|
||||
NS_IMETHOD Reload(JSContext *cx, jsval *argv, PRUint32 argc) { return _to Reload(cx, argv, argc); } \
|
||||
NS_IMETHOD Replace(JSContext *cx, jsval *argv, PRUint32 argc) { return _to Replace(cx, argv, argc); } \
|
||||
|
||||
|
||||
#endif // nsIDOMNSLocation_h__
|
|
@ -5,14 +5,21 @@
|
|||
attribute wstring hash;
|
||||
attribute wstring host;
|
||||
attribute wstring hostname;
|
||||
attribute wstring href;
|
||||
noscript attribute wstring href;
|
||||
attribute wstring pathname;
|
||||
attribute wstring port;
|
||||
attribute wstring protocol;
|
||||
attribute wstring search;
|
||||
|
||||
void reload(/* ... */);
|
||||
noscript void reload(in boolean forceget);
|
||||
void replace(in wstring url);
|
||||
|
||||
wstring toString();
|
||||
};
|
||||
|
||||
interface NSLocation {
|
||||
/* IID: { 0xa6cf9108, 0x15b3, 0x11d2, \
|
||||
{ 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } */
|
||||
void reload(/* ... */);
|
||||
void replace(/* ... */);
|
||||
};
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
* It is used by the script runtime to collect information about an object
|
||||
*/
|
||||
class nsIJSScriptObject : public nsISupports {
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IJSSCRIPTOBJECT_IID; return iid; }
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IJSSCRIPTOBJECT_IID; return iid; }
|
||||
virtual PRBool AddProperty(JSContext *aContext, jsval aID,
|
||||
jsval *aVp) = 0;
|
||||
virtual PRBool DeleteProperty(JSContext *aContext, jsval aID,
|
||||
|
|
|
@ -2591,37 +2591,33 @@ GlobalWindowImpl::GetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
|||
PRBool
|
||||
GlobalWindowImpl::SetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
PRBool result = PR_TRUE;
|
||||
if (JS_TypeOfValue(aContext, *aVp) == JSTYPE_FUNCTION && JSVAL_IS_STRING(aID)) {
|
||||
nsString mPropName;
|
||||
nsAutoString mPrefix;
|
||||
mPropName.SetString(JS_GetStringChars(JS_ValueToString(aContext, aID)));
|
||||
mPrefix.SetString(mPropName.GetUnicode(), 2);
|
||||
if (mPrefix == "on") {
|
||||
return CheckForEventListener(aContext, mPropName);
|
||||
result = CheckForEventListener(aContext, mPropName);
|
||||
}
|
||||
}
|
||||
else if (JSVAL_IS_STRING(aID)) {
|
||||
char* cString = JS_GetStringBytes(JS_ValueToString(aContext, aID));
|
||||
|
||||
if (PL_strcmp("location", cString) == 0) {
|
||||
JSString *jsstring = JS_ValueToString(aContext, *aVp);
|
||||
|
||||
if (nsnull != jsstring) {
|
||||
nsIDOMLocation *location;
|
||||
nsAutoString locationStr;
|
||||
nsCOMPtr<nsIDOMLocation> location;
|
||||
|
||||
locationStr.SetString(JS_GetStringChars(jsstring));
|
||||
if (NS_OK == GetLocation(&location)) {
|
||||
if (NS_OK != location->SetHref(locationStr)) {
|
||||
NS_RELEASE(location);
|
||||
return PR_FALSE;
|
||||
}
|
||||
NS_RELEASE(location);
|
||||
}
|
||||
else {
|
||||
return PR_FALSE;
|
||||
if (NS_OK == GetLocation(getter_AddRefs(location))) {
|
||||
nsCOMPtr<nsIJSScriptObject> scriptObj = do_QueryInterface(location);
|
||||
JSString* str = JS_NewStringCopyZ(aContext, "href");
|
||||
|
||||
if (scriptObj && str) {
|
||||
result = scriptObj->SetProperty(aContext, STRING_TO_JSVAL(str), aVp);
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = PR_FALSE;
|
||||
}
|
||||
}
|
||||
else if (PL_strcmp("title", cString) == 0) {
|
||||
if (mWebShell) {
|
||||
|
@ -2633,17 +2629,20 @@ GlobalWindowImpl::SetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
|||
if (NS_OK == GetBrowserWindowInterface(*getter_AddRefs(browser)) && browser) {
|
||||
// We got a browser window interface
|
||||
JSString *jsString = JS_ValueToString(aContext, *aVp);
|
||||
if (!jsString)
|
||||
return PR_FALSE;
|
||||
const PRUnichar* uniTitle = JS_GetStringChars(jsString);
|
||||
browser->SetTitle(uniTitle);
|
||||
if (!jsString) {
|
||||
result = PR_FALSE;
|
||||
}
|
||||
else {
|
||||
const PRUnichar* uniTitle = JS_GetStringChars(jsString);
|
||||
browser->SetTitle(uniTitle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMNavigator.h"
|
||||
#include "nsIDOMLocation.h"
|
||||
#include "nsIDOMNSLocation.h"
|
||||
#include "nsIDOMScreen.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsIJSScriptObject.h"
|
||||
|
@ -330,7 +331,11 @@ protected:
|
|||
|
||||
class nsIURI;
|
||||
|
||||
class LocationImpl : public nsIScriptObjectOwner, public nsIDOMLocation {
|
||||
class LocationImpl : public nsIScriptObjectOwner,
|
||||
public nsIDOMLocation,
|
||||
public nsIDOMNSLocation,
|
||||
public nsIJSScriptObject
|
||||
{
|
||||
|
||||
protected:
|
||||
public:
|
||||
|
@ -344,6 +349,7 @@ public:
|
|||
|
||||
NS_IMETHOD_(void) SetWebShell(nsIWebShell *aWebShell);
|
||||
|
||||
// nsIDOMLocation
|
||||
NS_IMETHOD GetHash(nsString& aHash);
|
||||
NS_IMETHOD SetHash(const nsString& aHash);
|
||||
NS_IMETHOD GetHost(nsString& aHost);
|
||||
|
@ -360,12 +366,31 @@ public:
|
|||
NS_IMETHOD SetProtocol(const nsString& aProtocol);
|
||||
NS_IMETHOD GetSearch(nsString& aSearch);
|
||||
NS_IMETHOD SetSearch(const nsString& aSearch);
|
||||
NS_IMETHOD Reload(JSContext *cx, jsval *argv, PRUint32 argc);
|
||||
NS_IMETHOD Reload(PRBool aForceget);
|
||||
NS_IMETHOD Replace(const nsString& aUrl);
|
||||
NS_IMETHOD ToString(nsString& aReturn);
|
||||
|
||||
// nsIDOMNSLocation
|
||||
NS_IMETHOD Reload(JSContext *cx, jsval *argv, PRUint32 argc);
|
||||
NS_IMETHOD Replace(JSContext *cx, jsval *argv, PRUint32 argc);
|
||||
|
||||
// nsIJSScriptObject
|
||||
virtual PRBool AddProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool GetProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool SetProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool EnumerateProperty(JSContext *aContext);
|
||||
virtual PRBool Resolve(JSContext *aContext, jsval aID);
|
||||
virtual PRBool Convert(JSContext *aContext, jsval aID);
|
||||
virtual void Finalize(JSContext *aContext);
|
||||
|
||||
protected:
|
||||
nsresult SetURL(nsIURI* aURL);
|
||||
nsresult SetHrefWithBase(const nsString& aHref,
|
||||
nsIURI* aBase,
|
||||
PRBool aReplace);
|
||||
nsresult GetSourceURL(JSContext* cx,
|
||||
nsIURI** sourceURL);
|
||||
|
||||
nsIWebShell *mWebShell;
|
||||
void *mScriptObject;
|
||||
|
|
|
@ -28,14 +28,17 @@
|
|||
#include "nsIPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIDOMLocation.h"
|
||||
#include "nsIDOMNSLocation.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
|
||||
static NS_DEFINE_IID(kILocationIID, NS_IDOMLOCATION_IID);
|
||||
static NS_DEFINE_IID(kINSLocationIID, NS_IDOMNSLOCATION_IID);
|
||||
|
||||
NS_DEF_PTR(nsIDOMLocation);
|
||||
NS_DEF_PTR(nsIDOMNSLocation);
|
||||
|
||||
//
|
||||
// Location property ids
|
||||
|
@ -44,11 +47,10 @@ enum Location_slots {
|
|||
LOCATION_HASH = -1,
|
||||
LOCATION_HOST = -2,
|
||||
LOCATION_HOSTNAME = -3,
|
||||
LOCATION_HREF = -4,
|
||||
LOCATION_PATHNAME = -5,
|
||||
LOCATION_PORT = -6,
|
||||
LOCATION_PROTOCOL = -7,
|
||||
LOCATION_SEARCH = -8
|
||||
LOCATION_PATHNAME = -4,
|
||||
LOCATION_PORT = -5,
|
||||
LOCATION_PROTOCOL = -6,
|
||||
LOCATION_SEARCH = -7
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
|
@ -121,22 +123,6 @@ GetLocationProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case LOCATION_HREF:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "location.href", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
if (NS_OK == a->GetHref(prop)) {
|
||||
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LOCATION_PATHNAME:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "location.pathname", &ok);
|
||||
|
@ -277,20 +263,6 @@ SetLocationProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
|
||||
break;
|
||||
}
|
||||
case LOCATION_HREF:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "location.href", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
nsAutoString prop;
|
||||
nsJSUtils::nsConvertJSValToString(prop, cx, *vp);
|
||||
|
||||
a->SetHref(prop);
|
||||
|
||||
break;
|
||||
}
|
||||
case LOCATION_PATHNAME:
|
||||
{
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "location.pathname", &ok);
|
||||
|
@ -390,53 +362,6 @@ ResolveLocation(JSContext *cx, JSObject *obj, jsval id)
|
|||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method Reload
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
LocationReload(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMLocation *nativeThis = (nsIDOMLocation*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "location.reload", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 0) {
|
||||
|
||||
if (NS_OK != nativeThis->Reload(cx, argv+0, argc-0)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function reload requires 0 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method Replace
|
||||
//
|
||||
|
@ -535,6 +460,112 @@ LocationToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *r
|
|||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method Reload
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
NSLocationReload(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMLocation *privateThis = (nsIDOMLocation*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
nsIDOMNSLocation *nativeThis = nsnull;
|
||||
if (NS_OK != privateThis->QueryInterface(kINSLocationIID, (void **)&nativeThis)) {
|
||||
JS_ReportError(cx, "Object must be of type NSLocation");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nslocation.reload", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 0) {
|
||||
|
||||
if (NS_OK != nativeThis->Reload(cx, argv+0, argc-0)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function reload requires 0 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method Replace
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
NSLocationReplace(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMLocation *privateThis = (nsIDOMLocation*)nsJSUtils::nsGetNativeThis(cx, obj);
|
||||
nsIDOMNSLocation *nativeThis = nsnull;
|
||||
if (NS_OK != privateThis->QueryInterface(kINSLocationIID, (void **)&nativeThis)) {
|
||||
JS_ReportError(cx, "Object must be of type NSLocation");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
nsIScriptContext *scriptCX = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
nsIScriptSecurityManager *secMan;
|
||||
if (NS_OK == scriptCX->GetSecurityManager(&secMan)) {
|
||||
PRBool ok;
|
||||
secMan->CheckScriptAccess(scriptCX, obj, "nslocation.replace", &ok);
|
||||
if (!ok) {
|
||||
//Need to throw error here
|
||||
return JS_FALSE;
|
||||
}
|
||||
NS_RELEASE(secMan);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 0) {
|
||||
|
||||
if (NS_OK != nativeThis->Replace(cx, argv+0, argc-0)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function replace requires 0 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// class for Location
|
||||
|
@ -561,7 +592,6 @@ static JSPropertySpec LocationProperties[] =
|
|||
{"hash", LOCATION_HASH, JSPROP_ENUMERATE},
|
||||
{"host", LOCATION_HOST, JSPROP_ENUMERATE},
|
||||
{"hostname", LOCATION_HOSTNAME, JSPROP_ENUMERATE},
|
||||
{"href", LOCATION_HREF, JSPROP_ENUMERATE},
|
||||
{"pathname", LOCATION_PATHNAME, JSPROP_ENUMERATE},
|
||||
{"port", LOCATION_PORT, JSPROP_ENUMERATE},
|
||||
{"protocol", LOCATION_PROTOCOL, JSPROP_ENUMERATE},
|
||||
|
@ -575,9 +605,10 @@ static JSPropertySpec LocationProperties[] =
|
|||
//
|
||||
static JSFunctionSpec LocationMethods[] =
|
||||
{
|
||||
{"reload", LocationReload, 0},
|
||||
{"replace", LocationReplace, 1},
|
||||
{"toString", LocationToString, 0},
|
||||
{"reload", NSLocationReload, 0},
|
||||
{"replace", NSLocationReplace, 0},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
@ -28,10 +28,13 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
|||
#endif // NECKO
|
||||
#include "plstr.h"
|
||||
#include "prmem.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsJSUtils.h"
|
||||
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDOMLocationIID, NS_IDOMLOCATION_IID);
|
||||
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
||||
|
||||
LocationImpl::LocationImpl(nsIWebShell *aWebShell)
|
||||
{
|
||||
|
@ -65,6 +68,11 @@ LocationImpl::QueryInterface(const nsIID& aIID,
|
|||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIJSScriptObjectIID)) {
|
||||
*aInstancePtrResult = (void*)(nsISupports*)(nsIJSScriptObject*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
|
||||
AddRef();
|
||||
|
@ -354,8 +362,8 @@ LocationImpl::GetHref(nsString& aHref)
|
|||
NS_IMETHODIMP
|
||||
LocationImpl::SetHref(const nsString& aHref)
|
||||
{
|
||||
nsAutoString oldHref, newHref;
|
||||
nsIURI *oldUrl, *newUrl;
|
||||
nsAutoString oldHref;
|
||||
nsIURI *oldUrl;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
result = GetHref(oldHref);
|
||||
|
@ -366,34 +374,48 @@ LocationImpl::SetHref(const nsString& aHref)
|
|||
result = NS_NewURI(&oldUrl, oldHref);
|
||||
#endif // NECKO
|
||||
if (NS_OK == result) {
|
||||
#ifndef NECKO
|
||||
result = NS_NewURL(&newUrl, aHref, oldUrl);
|
||||
#else
|
||||
result = NS_NewURI(&newUrl, aHref, oldUrl);
|
||||
#endif // NECKO
|
||||
if (NS_OK == result) {
|
||||
#ifdef NECKO
|
||||
char* spec;
|
||||
#else
|
||||
const char* spec;
|
||||
#endif
|
||||
result = newUrl->GetSpec(&spec);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
newHref.SetString(spec);
|
||||
#ifdef NECKO
|
||||
nsCRT::free(spec);
|
||||
#endif
|
||||
}
|
||||
NS_RELEASE(newUrl);
|
||||
}
|
||||
result = SetHrefWithBase(aHref, oldUrl, PR_TRUE);
|
||||
NS_RELEASE(oldUrl);
|
||||
}
|
||||
}
|
||||
|
||||
if ((NS_OK == result) && (nsnull != mWebShell)) {
|
||||
return mWebShell->LoadURL(newHref.GetUnicode(), nsnull, PR_TRUE);
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
LocationImpl::SetHrefWithBase(const nsString& aHref,
|
||||
nsIURI* aBase,
|
||||
PRBool aReplace)
|
||||
{
|
||||
nsresult result;
|
||||
nsIURI* newUrl;
|
||||
nsAutoString newHref;
|
||||
|
||||
#ifndef NECKO
|
||||
result = NS_NewURL(&newUrl, aHref, aBase);
|
||||
#else
|
||||
result = NS_NewURI(&newUrl, aHref, aBase);
|
||||
#endif // NECKO
|
||||
if (NS_OK == result) {
|
||||
#ifdef NECKO
|
||||
char* spec;
|
||||
#else
|
||||
const char* spec;
|
||||
#endif
|
||||
result = newUrl->GetSpec(&spec);
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
newHref.SetString(spec);
|
||||
#ifdef NECKO
|
||||
nsCRT::free(spec);
|
||||
#endif
|
||||
}
|
||||
NS_RELEASE(newUrl);
|
||||
}
|
||||
|
||||
if ((NS_OK == result) && (nsnull != mWebShell)) {
|
||||
result = mWebShell->LoadURL(newHref.GetUnicode(), nsnull, aReplace);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -681,7 +703,7 @@ LocationImpl::SetSearch(const nsString& aSearch)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocationImpl::Reload(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
LocationImpl::Reload(PRBool aForceget)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
|
@ -699,11 +721,63 @@ LocationImpl::Reload(JSContext *cx, jsval *argv, PRUint32 argc)
|
|||
NS_IMETHODIMP
|
||||
LocationImpl::Replace(const nsString& aUrl)
|
||||
{
|
||||
if (nsnull != mWebShell) {
|
||||
return mWebShell->LoadURL(aUrl.GetUnicode(), nsnull, PR_FALSE);
|
||||
nsAutoString oldHref;
|
||||
nsIURI *oldUrl;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
result = GetHref(oldHref);
|
||||
if (NS_OK == result) {
|
||||
#ifndef NECKO
|
||||
result = NS_NewURL(&oldUrl, oldHref);
|
||||
#else
|
||||
result = NS_NewURI(&oldUrl, oldHref);
|
||||
#endif // NECKO
|
||||
if (NS_OK == result) {
|
||||
result = SetHrefWithBase(aUrl, oldUrl, PR_FALSE);
|
||||
NS_RELEASE(oldUrl);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocationImpl::Reload(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
{
|
||||
// XXX Security manager needs to be called
|
||||
nsresult result = NS_OK;
|
||||
JSBool force = JS_FALSE;
|
||||
|
||||
if (argc > 0) {
|
||||
JS_ValueToBoolean(cx, argv[0], &force);
|
||||
}
|
||||
|
||||
return Reload(force ? PR_TRUE : PR_FALSE);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
LocationImpl::Replace(JSContext *cx, jsval *argv, PRUint32 argc)
|
||||
{
|
||||
// XXX Security manager needs to be called
|
||||
nsresult result = NS_OK;
|
||||
|
||||
if (argc > 0) {
|
||||
nsIURI* base;
|
||||
nsAutoString href;
|
||||
|
||||
// Get the parameter passed in
|
||||
nsJSUtils::nsConvertJSValToString(href, cx, argv[0]);
|
||||
|
||||
// Get the source of the caller
|
||||
result = GetSourceURL(cx, &base);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = SetHrefWithBase(href, base, PR_FALSE);
|
||||
NS_RELEASE(base);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -712,3 +786,135 @@ LocationImpl::ToString(nsString& aReturn)
|
|||
return GetHref(aReturn);
|
||||
}
|
||||
|
||||
nsresult
|
||||
LocationImpl::GetSourceURL(JSContext* cx,
|
||||
nsIURI** sourceURL)
|
||||
{
|
||||
// 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.
|
||||
nsresult result = NS_OK;
|
||||
nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx);
|
||||
|
||||
if (nsnull != context) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> global;
|
||||
|
||||
global = dont_AddRef(context->GetGlobalObject());
|
||||
if (global) {
|
||||
nsCOMPtr<nsIWebShell> webShell;
|
||||
|
||||
global->GetWebShell(getter_AddRefs(webShell));
|
||||
if (webShell) {
|
||||
const PRUnichar* url;
|
||||
|
||||
// XXX Ughh - incorrect ownership rules for url?
|
||||
webShell->GetURL(&url);
|
||||
#ifndef NECKO
|
||||
result = NS_NewURL(sourceURL, url);
|
||||
#else
|
||||
result = NS_NewURI(sourceURL, url);
|
||||
#endif // NECKO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool
|
||||
LocationImpl::AddProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
LocationImpl::DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
LocationImpl::GetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
PRBool result = PR_TRUE;
|
||||
|
||||
// XXX Security manager needs to be called
|
||||
if (JSVAL_IS_STRING(aID)) {
|
||||
char* cString = JS_GetStringBytes(JS_ValueToString(aContext, aID));
|
||||
if (PL_strcmp("href", cString) == 0) {
|
||||
nsAutoString href;
|
||||
|
||||
if (NS_SUCCEEDED(GetHref(href))) {
|
||||
const PRUnichar* bytes = href.GetUnicode();
|
||||
JSString* str = JS_NewUCStringCopyZ(aContext, (const jschar*)bytes);
|
||||
if (str) {
|
||||
*aVp = STRING_TO_JSVAL(str);
|
||||
}
|
||||
else {
|
||||
result = PR_FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = PR_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool
|
||||
LocationImpl::SetProperty(JSContext *aContext, jsval aID, jsval *aVp)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
// XXX Security manager needs to be called
|
||||
if (JSVAL_IS_STRING(aID)) {
|
||||
char* cString = JS_GetStringBytes(JS_ValueToString(aContext, aID));
|
||||
|
||||
if (PL_strcmp("href", cString) == 0) {
|
||||
nsIURI* base;
|
||||
nsAutoString href;
|
||||
|
||||
// Get the parameter passed in
|
||||
nsJSUtils::nsConvertJSValToString(href, aContext, *aVp);
|
||||
|
||||
// Get the source of the caller
|
||||
result = GetSourceURL(aContext, &base);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
result = SetHrefWithBase(href, base, PR_TRUE);
|
||||
NS_RELEASE(base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_SUCCEEDED(result);
|
||||
}
|
||||
|
||||
PRBool
|
||||
LocationImpl::EnumerateProperty(JSContext *aContext)
|
||||
{
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
LocationImpl::Resolve(JSContext *aContext, jsval aID)
|
||||
{
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
LocationImpl::Convert(JSContext *aContext, jsval aID)
|
||||
{
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
LocationImpl::Finalize(JSContext *aContext)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -557,6 +557,8 @@ IdlAttribute* IdlParser::MaybeParseAttribute(IdlSpecification &aSpecification, i
|
|||
if ((token->id != READONLY_TOKEN) && (token->id != ATTRIBUTE_TOKEN)) {
|
||||
return NULL;
|
||||
}
|
||||
mScanner->NextToken();
|
||||
aTokenID = token->id;
|
||||
}
|
||||
|
||||
return ParseAttribute(aSpecification, aTokenID, isNoScript);
|
||||
|
|
Загрузка…
Ссылка в новой задаче