diff --git a/mozilla/dom/public/base/nsIDOMLocation.h b/mozilla/dom/public/base/nsIDOMLocation.h index 26e0d74be05..1cf230de15a 100644 --- a/mozilla/dom/public/base/nsIDOMLocation.h +++ b/mozilla/dom/public/base/nsIDOMLocation.h @@ -65,6 +65,8 @@ public: NS_IMETHOD Replace(const nsAReadableString& aUrl)=0; + NS_IMETHOD Assign(const nsAReadableString& aUrl)=0; + NS_IMETHOD ToString(nsAWritableString& aReturn)=0; }; @@ -88,6 +90,7 @@ public: NS_IMETHOD SetSearch(const nsAReadableString& aSearch); \ NS_IMETHOD Reload(PRBool aForceget); \ NS_IMETHOD Replace(const nsAReadableString& aUrl); \ + NS_IMETHOD Assign(const nsAReadableString& aUrl); \ NS_IMETHOD ToString(nsAWritableString& aReturn); \ @@ -111,6 +114,7 @@ public: NS_IMETHOD SetSearch(const nsAReadableString& aSearch) { return _to SetSearch(aSearch); } \ NS_IMETHOD Reload(PRBool aForceget) { return _to Reload(aForceget); } \ NS_IMETHOD Replace(const nsAReadableString& aUrl) { return _to Replace(aUrl); } \ + NS_IMETHOD Assign(const nsAReadableString& aUrl) { return _to Assign(aUrl); } \ NS_IMETHOD ToString(nsAWritableString& aReturn) { return _to ToString(aReturn); } \ diff --git a/mozilla/dom/public/idl/base/Location.idl b/mozilla/dom/public/idl/base/Location.idl index c076a00dd1e..8f53af251ca 100644 --- a/mozilla/dom/public/idl/base/Location.idl +++ b/mozilla/dom/public/idl/base/Location.idl @@ -1,25 +1,26 @@ - interface Location { +interface Location { /* IID: { 0xa6cf906d, 0x15b3, 0x11d2, \ { 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } */ - attribute wstring hash; + attribute wstring hash; attribute wstring host; - attribute wstring hostname; + attribute wstring hostname; noscript attribute wstring href; attribute wstring pathname; attribute wstring port; attribute wstring protocol; attribute wstring search; - noscript void reload(in boolean forceget); + noscript void reload(in boolean forceget); noscript void replace(in wstring url); + void assign(in wstring url); - wstring toString(); - }; + wstring toString(); +}; - interface NSLocation { +interface NSLocation { /* IID: { 0xa6cf9108, 0x15b3, 0x11d2, \ { 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } */ void reload(/* ... */); void replace(/* ... */); - }; +}; diff --git a/mozilla/dom/public/nsDOMPropEnums.h b/mozilla/dom/public/nsDOMPropEnums.h index fd259c72361..959eb962ee3 100644 --- a/mozilla/dom/public/nsDOMPropEnums.h +++ b/mozilla/dom/public/nsDOMPropEnums.h @@ -677,6 +677,7 @@ enum nsDOMProp { NS_DOM_PROP_KEYEVENT_METAKEY, NS_DOM_PROP_KEYEVENT_SHIFTKEY, NS_DOM_PROP_LINKSTYLE_SHEET, + NS_DOM_PROP_LOCATION_ASSIGN, NS_DOM_PROP_LOCATION_HASH, NS_DOM_PROP_LOCATION_HOST, NS_DOM_PROP_LOCATION_HOSTNAME, diff --git a/mozilla/dom/public/nsDOMPropNames.h b/mozilla/dom/public/nsDOMPropNames.h index 423cd40cfd6..89f107d1f8e 100644 --- a/mozilla/dom/public/nsDOMPropNames.h +++ b/mozilla/dom/public/nsDOMPropNames.h @@ -675,6 +675,7 @@ "keyevent.metakey", \ "keyevent.shiftkey", \ "linkstyle.sheet", \ + "location.assign", \ "location.hash", \ "location.host", \ "location.hostname", \ diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index 52d44e491ce..677a9d76282 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -348,6 +348,7 @@ public: NS_IMETHOD SetSearch(const nsAReadableString& aSearch); NS_IMETHOD Reload(PRBool aForceget); NS_IMETHOD Replace(const nsAReadableString& aUrl); + NS_IMETHOD Assign(const nsAReadableString& aUrl); NS_IMETHOD ToString(nsAWritableString& aReturn); // nsIDOMNSLocation diff --git a/mozilla/dom/src/base/nsJSLocation.cpp b/mozilla/dom/src/base/nsJSLocation.cpp index e1482cd9d66..b9f4a12e707 100644 --- a/mozilla/dom/src/base/nsJSLocation.cpp +++ b/mozilla/dom/src/base/nsJSLocation.cpp @@ -322,6 +322,47 @@ ResolveLocation(JSContext *cx, JSObject *obj, jsval id) } +// +// Native method Assign +// +PR_STATIC_CALLBACK(JSBool) +LocationAssign(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMLocation *nativeThis = (nsIDOMLocation*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_LOCATION_ASSIGN, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->Assign(b0); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + + // // Native method ToString // @@ -479,6 +520,7 @@ static JSPropertySpec LocationProperties[] = // static JSFunctionSpec LocationMethods[] = { + {"assign", LocationAssign, 1}, {"toString", LocationToString, 0}, {"reload", NSLocationReload, 0}, {"replace", NSLocationReplace, 0}, diff --git a/mozilla/dom/src/base/nsLocation.cpp b/mozilla/dom/src/base/nsLocation.cpp index f86b7af3ae7..3d3d6d8ab86 100644 --- a/mozilla/dom/src/base/nsLocation.cpp +++ b/mozilla/dom/src/base/nsLocation.cpp @@ -639,6 +639,24 @@ LocationImpl::Replace(const nsAReadableString& aUrl) return result; } +NS_IMETHODIMP +LocationImpl::Assign(const nsAReadableString& aUrl) +{ + nsAutoString oldHref; + nsCOMPtr oldUrl; + nsresult result = NS_OK; + + result = GetHref(oldHref); + if (NS_SUCCEEDED(result)) { + result = NS_NewURI(getter_AddRefs(oldUrl), oldHref); + if (NS_SUCCEEDED(result)) { + result = SetHrefWithBase(aUrl, oldUrl, PR_FALSE); + } + } + + return result; +} + NS_IMETHODIMP LocationImpl::Reload(JSContext *cx, jsval *argv, PRUint32 argc) {