Bug 887364 - Update URLUtils interface. r=ehsan

This commit is contained in:
Andrea Marchesini 2013-09-04 13:05:10 -04:00
parent 4d4fd26659
commit 517dec0b94
8 changed files with 138 additions and 17 deletions

View File

@ -146,6 +146,32 @@ Link::SetProtocol(const nsAString &aProtocol)
SetHrefAttribute(uri);
}
void
Link::SetPassword(const nsAString &aPassword)
{
nsCOMPtr<nsIURI> uri(GetURIToMutate());
if (!uri) {
// Ignore failures to be compatible with NS4.
return;
}
uri->SetPassword(NS_ConvertUTF16toUTF8(aPassword));
SetHrefAttribute(uri);
}
void
Link::SetUsername(const nsAString &aUsername)
{
nsCOMPtr<nsIURI> uri(GetURIToMutate());
if (!uri) {
// Ignore failures to be compatible with NS4.
return;
}
uri->SetUsername(NS_ConvertUTF16toUTF8(aUsername));
SetHrefAttribute(uri);
}
void
Link::SetHost(const nsAString &aHost)
{
@ -259,6 +285,27 @@ Link::SetHash(const nsAString &aHash)
SetHrefAttribute(uri);
}
void
Link::GetOrigin(nsAString &aOrigin)
{
aOrigin.Truncate();
nsCOMPtr<nsIURI> uri(GetURI());
if (!uri) {
return;
}
nsString origin;
nsresult rv = nsContentUtils::GetUTFOrigin(uri, origin);
if (NS_FAILED(rv)) {
return;
}
if (!aOrigin.EqualsLiteral("null")) {
aOrigin.Assign(origin);
}
}
void
Link::GetProtocol(nsAString &_protocol)
{
@ -275,6 +322,36 @@ Link::GetProtocol(nsAString &_protocol)
return;
}
void
Link::GetUsername(nsAString& aUsername)
{
aUsername.Truncate();
nsCOMPtr<nsIURI> uri(GetURI());
if (!uri) {
return;
}
nsAutoCString username;
uri->GetUsername(username);
CopyASCIItoUTF16(username, aUsername);
}
void
Link::GetPassword(nsAString &aPassword)
{
aPassword.Truncate();
nsCOMPtr<nsIURI> uri(GetURI());
if (!uri) {
return;
}
nsAutoCString password;
uri->GetPassword(password);
CopyASCIItoUTF16(password, aPassword);
}
void
Link::GetHost(nsAString &_host)
{

View File

@ -54,13 +54,18 @@ public:
* Helper methods for modifying and obtaining parts of the URI of the Link.
*/
void SetProtocol(const nsAString &aProtocol);
void SetUsername(const nsAString &aUsername);
void SetPassword(const nsAString &aPassword);
void SetHost(const nsAString &aHost);
void SetHostname(const nsAString &aHostname);
void SetPathname(const nsAString &aPathname);
void SetSearch(const nsAString &aSearch);
void SetPort(const nsAString &aPort);
void SetHash(const nsAString &aHash);
void GetOrigin(nsAString &aOrigin);
void GetProtocol(nsAString &_protocol);
void GetUsername(nsAString &aUsername);
void GetPassword(nsAString &aPassword);
void GetHost(nsAString &_host);
void GetHostname(nsAString &_hostname);
void GetPathname(nsAString &_pathname);

View File

@ -134,6 +134,31 @@ public:
{
rv = SetText(aValue);
}
void GetOrigin(nsAString& aOrigin)
{
Link::GetOrigin(aOrigin);
}
void GetUsername(nsAString& aUsername)
{
Link::GetUsername(aUsername);
}
void SetUsername(const nsAString& aUsername)
{
Link::SetUsername(aUsername);
}
void GetPassword(nsAString& aPassword)
{
Link::GetPassword(aPassword);
}
void SetPassword(const nsAString& aPassword)
{
Link::SetPassword(aPassword);
}
// The XPCOM URI decomposition attributes are fine for us
void GetCoords(nsString& aValue)
{

View File

@ -108,9 +108,34 @@ public:
SetHTMLAttr(nsGkAtoms::ping, aPing, aError);
}
void GetOrigin(nsAString &aOrigin)
{
Link::GetOrigin(aOrigin);
}
// The XPCOM GetProtocol is OK for us
// The XPCOM SetProtocol is OK for us
void GetUsername(nsAString& aUsername)
{
Link::GetUsername(aUsername);
}
void SetUsername(const nsAString& aUsername)
{
Link::SetUsername(aUsername);
}
void GetPassword(nsAString& aPassword)
{
Link::GetPassword(aPassword);
}
void SetPassword(const nsAString& aPassword)
{
Link::SetPassword(aPassword);
}
// The XPCOM GetHost is OK for us
// The XPCOM SetHost is OK for us

View File

@ -13,12 +13,7 @@
// http://www.whatwg.org/specs/web-apps/current-work/#the-a-element
interface HTMLAnchorElement : HTMLElement {
// No support for stringifier attributes yet
//[SetterThrows]
//stringifier attribute DOMString href;
stringifier;
[SetterThrows]
attribute DOMString href;
[SetterThrows]
attribute DOMString target;
[SetterThrows]

View File

@ -14,18 +14,13 @@
// http://www.whatwg.org/specs/web-apps/current-work/#the-area-element
interface HTMLAreaElement : HTMLElement {
stringifier;
[SetterThrows]
attribute DOMString alt;
[SetterThrows]
attribute DOMString coords;
[SetterThrows]
attribute DOMString shape;
// No support for stringifier attributes yet
//[SetterThrows]
//stringifier attribute DOMString href;
stringifier;
[SetterThrows]
attribute DOMString href;
[SetterThrows]
attribute DOMString target;
[SetterThrows]

View File

@ -14,7 +14,6 @@
// No support for [Unforgeable] on interfaces yet
//[Unforgeable]
interface Location {
stringifier attribute DOMString href;
void assign(DOMString url);
void replace(DOMString url);
void reload();

View File

@ -15,13 +15,13 @@
[NoInterfaceObject]
interface URLUtils {
// [SetterThrows]
// stringifier attribute DOMString href;
// readonly attribute DOMString origin;
[SetterThrows]
stringifier attribute DOMString href;
readonly attribute DOMString origin;
attribute DOMString protocol;
// attribute DOMString username;
// attribute DOMString password;
attribute DOMString username;
attribute DOMString password;
attribute DOMString host;
attribute DOMString hostname;
attribute DOMString port;