Bug 481318. Don't serialize then reparse the URI on anchor property mutations. r+sr=jst

This commit is contained in:
Boris Zbarsky 2009-03-09 22:32:09 -04:00
Родитель 1fa7eaa3b7
Коммит 7acb4b919c
5 изменённых файлов: 201 добавлений и 676 удалений

Просмотреть файл

@ -883,10 +883,18 @@ nsContentSink::PrefetchDNS(const nsAString &aHref)
if (StringBeginsWith(aHref, NS_LITERAL_STRING("//"))) {
hostname = Substring(aHref, 2);
}
else
nsGenericHTMLElement::GetHostnameFromHrefString(aHref, hostname);
else {
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), aHref);
if (!uri) {
return;
}
nsCAutoString host;
uri->GetHost(host);
CopyUTF8toUTF16(host, hostname);
}
if (nsHTMLDNSPrefetch::IsAllowed(mDocument)) {
if (!hostname.IsEmpty() && nsHTMLDNSPrefetch::IsAllowed(mDocument)) {
nsHTMLDNSPrefetch::PrefetchLow(hostname);
}
}

Просмотреть файл

@ -3098,17 +3098,23 @@ nsGenericHTMLElement::PerformAccesskey(PRBool aKeyCausesActivation,
}
}
// static
nsresult
nsGenericHTMLElement::SetProtocolInHrefString(const nsAString &aHref,
const nsAString &aProtocol,
nsAString &aResult)
void
nsGenericHTMLElement::SetHrefToURI(nsIURI* aURI)
{
nsCAutoString newHref;
aURI->GetSpec(newHref);
SetAttrHelper(nsGkAtoms::href, NS_ConvertUTF8toUTF16(newHref));
}
nsresult
nsGenericHTMLElement::SetProtocolInHrefURI(const nsAString &aProtocol)
{
aResult.Truncate();
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
if (NS_FAILED(rv))
return rv;
GetHrefURIForAnchors(getter_AddRefs(uri));
if (!uri) {
// Ignore failures to be compatible with NS4
return NS_OK;
}
nsAString::const_iterator start, end;
aProtocol.BeginReading(start);
@ -3116,237 +3122,169 @@ nsGenericHTMLElement::SetProtocolInHrefString(const nsAString &aHref,
nsAString::const_iterator iter(start);
FindCharInReadable(':', iter, end);
uri->SetScheme(NS_ConvertUTF16toUTF8(Substring(start, iter)));
nsCAutoString newHref;
uri->GetSpec(newHref);
CopyUTF8toUTF16(newHref, aResult);
SetHrefToURI(uri);
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::SetHostnameInHrefString(const nsAString &aHref,
const nsAString &aHostname,
nsAString &aResult)
nsGenericHTMLElement::SetHostnameInHrefURI(const nsAString &aHostname)
{
aResult.Truncate();
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
if (NS_FAILED(rv))
return rv;
GetHrefURIForAnchors(getter_AddRefs(uri));
if (!uri) {
// Ignore failures to be compatible with NS4
return NS_OK;
}
uri->SetHost(NS_ConvertUTF16toUTF8(aHostname));
nsCAutoString newHref;
uri->GetSpec(newHref);
CopyUTF8toUTF16(newHref, aResult);
SetHrefToURI(uri);
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::SetPathnameInHrefString(const nsAString &aHref,
const nsAString &aPathname,
nsAString &aResult)
nsGenericHTMLElement::SetPathnameInHrefURI(const nsAString &aPathname)
{
aResult.Truncate();
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIURL> url(do_QueryInterface(uri, &rv));
if (NS_FAILED(rv))
return rv;
GetHrefURIForAnchors(getter_AddRefs(uri));
nsCOMPtr<nsIURL> url = do_QueryInterface(uri);
if (!url) {
// Ignore failures to be compatible with NS4
return NS_OK;
}
url->SetFilePath(NS_ConvertUTF16toUTF8(aPathname));
nsCAutoString newHref;
uri->GetSpec(newHref);
CopyUTF8toUTF16(newHref, aResult);
SetHrefToURI(uri);
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::SetHostInHrefString(const nsAString &aHref,
const nsAString &aHost,
nsAString &aResult)
nsGenericHTMLElement::SetHostInHrefURI(const nsAString &aHost)
{
// Can't simply call nsURI::SetHost, because that would treat the name as an
// IPv6 address (like http://[server:443]/)
aResult.Truncate();
// And can't call SetHostPort, because that's not implemented. Very sad.
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
if (NS_FAILED(rv))
return rv;
nsCAutoString scheme, userpass, path;
uri->GetScheme(scheme);
uri->GetUserPass(userpass);
uri->GetPath(path);
CopyASCIItoUTF16(scheme, aResult);
aResult.AppendLiteral("://");
if (!userpass.IsEmpty()) {
AppendUTF8toUTF16(userpass, aResult);
aResult.Append(PRUnichar('@'));
GetHrefURIForAnchors(getter_AddRefs(uri));
if (!uri) {
// Ignore failures to be compatible with NS4
return NS_OK;
}
aResult.Append(aHost);
AppendUTF8toUTF16(path, aResult);
nsAString::const_iterator start, end;
aHost.BeginReading(start);
aHost.EndReading(end);
nsAString::const_iterator iter(start);
FindCharInReadable(':', iter, end);
uri->SetHost(NS_ConvertUTF16toUTF8(Substring(start, iter)));
if (iter != end) {
++iter;
if (iter != end) {
nsAutoString portStr(Substring(iter, end));
nsresult rv;
PRInt32 port;
port = portStr.ToInteger((PRInt32*)&rv);
if (NS_SUCCEEDED(rv)) {
uri->SetPort(port);
}
}
}
SetHrefToURI(uri);
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::SetSearchInHrefString(const nsAString &aHref,
const nsAString &aSearch,
nsAString &aResult)
nsGenericHTMLElement::SetSearchInHrefURI(const nsAString &aSearch)
{
aResult.Truncate();
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIURL> url(do_QueryInterface(uri, &rv));
if (NS_FAILED(rv))
return rv;
GetHrefURIForAnchors(getter_AddRefs(uri));
nsCOMPtr<nsIURL> url = do_QueryInterface(uri);
if (!url) {
// Ignore failures to be compatible with NS4
return NS_OK;
}
url->SetQuery(NS_ConvertUTF16toUTF8(aSearch));
nsCAutoString newHref;
uri->GetSpec(newHref);
CopyUTF8toUTF16(newHref, aResult);
SetHrefToURI(uri);
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::SetHashInHrefString(const nsAString &aHref,
const nsAString &aHash,
nsAString &aResult)
nsGenericHTMLElement::SetHashInHrefURI(const nsAString &aHash)
{
aResult.Truncate();
nsCOMPtr<nsIURI> uri;
GetHrefURIForAnchors(getter_AddRefs(uri));
nsCOMPtr<nsIURL> url = do_QueryInterface(uri);
if (!url) {
// Ignore failures to be compatible with NS4
return NS_OK;
}
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIURL> url(do_QueryInterface(uri, &rv));
if (NS_FAILED(rv))
return rv;
rv = url->SetRef(NS_ConvertUTF16toUTF8(aHash));
nsCAutoString newHref;
uri->GetSpec(newHref);
CopyUTF8toUTF16(newHref, aResult);
url->SetRef(NS_ConvertUTF16toUTF8(aHash));
SetHrefToURI(uri);
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::SetPortInHrefString(const nsAString &aHref,
const nsAString &aPort,
nsAString &aResult)
nsGenericHTMLElement::SetPortInHrefURI(const nsAString &aPort)
{
aResult.Truncate();
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
GetHrefURIForAnchors(getter_AddRefs(uri));
if (!uri) {
// Ignore failures to be compatible with NS4
return NS_OK;
}
nsresult rv;
PRInt32 port = nsString(aPort).ToInteger((PRInt32*)&rv);
if (NS_FAILED(rv))
return rv;
PRInt32 port;
port = nsString(aPort).ToInteger((PRInt32*)&rv);
if (NS_FAILED(rv))
return rv;
return NS_OK;
uri->SetPort(port);
nsCAutoString newHref;
uri->GetSpec(newHref);
CopyUTF8toUTF16(newHref, aResult);
SetHrefToURI(uri);
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::GetProtocolFromHrefString(const nsAString& aHref,
nsAString& aProtocol,
nsIDocument *aDocument)
nsGenericHTMLElement::GetProtocolFromHrefURI(nsAString& aProtocol)
{
aProtocol.Truncate();
nsCOMPtr<nsIURI> uri;
GetHrefURIForAnchors(getter_AddRefs(uri));
nsIIOService* ioService = nsContentUtils::GetIOService();
NS_ENSURE_TRUE(ioService, NS_ERROR_FAILURE);
nsCAutoString protocol;
nsresult rv =
ioService->ExtractScheme(NS_ConvertUTF16toUTF8(aHref), protocol);
if (NS_SUCCEEDED(rv)) {
CopyASCIItoUTF16(protocol, aProtocol);
if (!uri) {
aProtocol.AssignLiteral("http");
} else {
// set the protocol to the protocol of the base URI.
if (aDocument) {
nsIURI *uri = aDocument->GetBaseURI();
if (uri) {
uri->GetScheme(protocol);
}
}
if (protocol.IsEmpty()) {
// set the protocol to http since it is the most likely protocol
// to be used.
aProtocol.AssignLiteral("http");
} else {
CopyASCIItoUTF16(protocol, aProtocol);
}
nsCAutoString scheme;
uri->GetScheme(scheme);
CopyASCIItoUTF16(scheme, aProtocol);
}
aProtocol.Append(PRUnichar(':'));
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::GetHostFromHrefString(const nsAString& aHref,
nsAString& aHost)
nsGenericHTMLElement::GetHostFromHrefURI(nsAString& aHost)
{
aHost.Truncate();
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
if (NS_FAILED(rv)) {
if (rv == NS_ERROR_MALFORMED_URI) {
// Don't throw from these methods! Not a valid URI means return
// empty string.
rv = NS_OK;
}
return rv;
GetHrefURIForAnchors(getter_AddRefs(uri));
if (!uri) {
// Don't throw from these methods! Not a valid URI means return
// empty string.
return NS_OK;
}
nsCAutoString hostport;
rv = uri->GetHostPort(hostport);
nsresult rv = uri->GetHostPort(hostport);
// Failure to get the hostport from the URI isn't necessarily an
// error. Some URI's just don't have a hostport.
@ -3358,25 +3296,20 @@ nsGenericHTMLElement::GetHostFromHrefString(const nsAString& aHref,
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::GetHostnameFromHrefString(const nsAString& aHref,
nsAString& aHostname)
nsGenericHTMLElement::GetHostnameFromHrefURI(nsAString& aHostname)
{
aHostname.Truncate();
nsCOMPtr<nsIURI> url;
nsresult rv = NS_NewURI(getter_AddRefs(url), aHref);
if (NS_FAILED(rv)) {
if (rv == NS_ERROR_MALFORMED_URI) {
// Don't throw from these methods! Not a valid URI means return
// empty string.
rv = NS_OK;
}
return rv;
nsCOMPtr<nsIURI> uri;
GetHrefURIForAnchors(getter_AddRefs(uri));
if (!uri) {
// Don't throw from these methods! Not a valid URI means return
// empty string.
return NS_OK;
}
nsCAutoString host;
rv = url->GetHost(host);
nsresult rv = uri->GetHost(host);
if (NS_SUCCEEDED(rv)) {
// Failure to get the host from the URI isn't necessarily an
@ -3388,20 +3321,17 @@ nsGenericHTMLElement::GetHostnameFromHrefString(const nsAString& aHref,
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::GetPathnameFromHrefString(const nsAString& aHref,
nsAString& aPathname)
nsGenericHTMLElement::GetPathnameFromHrefURI(nsAString& aPathname)
{
aPathname.Truncate();
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
if (NS_FAILED(rv)) {
if (rv == NS_ERROR_MALFORMED_URI) {
rv = NS_OK;
}
return rv;
nsCOMPtr<nsIURI> uri;
GetHrefURIForAnchors(getter_AddRefs(uri));
if (!uri) {
// Don't throw from these methods! Not a valid URI means return
// empty string.
return NS_OK;
}
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
@ -3413,7 +3343,7 @@ nsGenericHTMLElement::GetPathnameFromHrefString(const nsAString& aHref,
}
nsCAutoString file;
rv = url->GetFilePath(file);
nsresult rv = url->GetFilePath(file);
if (NS_FAILED(rv))
return rv;
@ -3422,34 +3352,23 @@ nsGenericHTMLElement::GetPathnameFromHrefString(const nsAString& aHref,
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::GetSearchFromHrefString(const nsAString& aHref,
nsAString& aSearch)
nsGenericHTMLElement::GetSearchFromHrefURI(nsAString& aSearch)
{
aSearch.Truncate();
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
if (NS_FAILED(rv)) {
if (rv == NS_ERROR_MALFORMED_URI) {
rv = NS_OK;
}
return rv;
}
GetHrefURIForAnchors(getter_AddRefs(uri));
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
if (!url) {
// If this is not a URL, we can't get the query from the URI
// Don't throw from these methods! Not a valid URI means return
// empty string.
return NS_OK;
}
nsCAutoString search;
rv = url->GetQuery(search);
nsresult rv = url->GetQuery(search);
if (NS_FAILED(rv))
return rv;
return NS_OK;
if (!search.IsEmpty()) {
CopyUTF8toUTF16(NS_LITERAL_CSTRING("?") + search, aSearch);
@ -3458,23 +3377,20 @@ nsGenericHTMLElement::GetSearchFromHrefString(const nsAString& aHref,
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::GetPortFromHrefString(const nsAString& aHref,
nsAString& aPort)
nsGenericHTMLElement::GetPortFromHrefURI(nsAString& aPort)
{
aPort.Truncate();
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
if (NS_FAILED(rv)) {
if (rv == NS_ERROR_MALFORMED_URI) {
rv = NS_OK;
}
return rv;
GetHrefURIForAnchors(getter_AddRefs(uri));
if (!uri) {
// Don't throw from these methods! Not a valid URI means return
// empty string.
return NS_OK;
}
PRInt32 port;
rv = uri->GetPort(&port);
nsresult rv = uri->GetPort(&port);
if (NS_SUCCEEDED(rv)) {
// Failure to get the port from the URI isn't necessarily an
@ -3492,39 +3408,28 @@ nsGenericHTMLElement::GetPortFromHrefString(const nsAString& aHref,
return NS_OK;
}
// static
nsresult
nsGenericHTMLElement::GetHashFromHrefString(const nsAString& aHref,
nsAString& aHash)
nsGenericHTMLElement::GetHashFromHrefURI(nsAString& aHash)
{
aHash.Truncate();
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHref);
if (NS_FAILED(rv)) {
if (rv == NS_ERROR_MALFORMED_URI) {
rv = NS_OK;
}
return rv;
}
GetHrefURIForAnchors(getter_AddRefs(uri));
nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
if (!url) {
// If this is not a URL, we can't get the hash part from the URI
// Don't throw from these methods! Not a valid URI means return
// empty string.
return NS_OK;
}
nsCAutoString ref;
rv = url->GetRef(ref);
nsresult rv = url->GetRef(ref);
if (NS_FAILED(rv))
return rv;
return NS_OK;
NS_UnescapeURL(ref); // XXX may result in random non-ASCII bytes!
if (!ref.IsEmpty()) {
aHash.Assign(PRUnichar('#'));
AppendASCIItoUTF16(ref, aHash);
AppendUTF8toUTF16(ref, aHash);
}
return NS_OK;
}

Просмотреть файл

@ -201,7 +201,6 @@ public:
PRBool IsHTMLLink(nsIURI** aURI) const;
// Used by A, AREA, LINK, and STYLE.
// Callers must hold a reference to nsHTMLUtils's global reference count.
nsresult GetHrefURIForAnchors(nsIURI** aURI) const;
// HTML element methods
@ -520,55 +519,22 @@ public:
static PRBool InNavQuirksMode(nsIDocument* aDoc);
// Helper functions for <a> and <area>
static nsresult SetProtocolInHrefString(const nsAString &aHref,
const nsAString &aProtocol,
nsAString &aResult);
void SetHrefToURI(nsIURI* aURI);
nsresult SetProtocolInHrefURI(const nsAString &aProtocol);
nsresult SetHostInHrefURI(const nsAString &aHost);
nsresult SetHostnameInHrefURI(const nsAString &aHostname);
nsresult SetPathnameInHrefURI(const nsAString &aPathname);
nsresult SetSearchInHrefURI(const nsAString &aSearch);
nsresult SetPortInHrefURI(const nsAString &aPort);
nsresult SetHashInHrefURI(const nsAString &aHash);
static nsresult SetHostInHrefString(const nsAString &aHref,
const nsAString &aHost,
nsAString &aResult);
static nsresult SetHostnameInHrefString(const nsAString &aHref,
const nsAString &aHostname,
nsAString &aResult);
static nsresult SetPathnameInHrefString(const nsAString &aHref,
const nsAString &aHostname,
nsAString &aResult);
static nsresult SetSearchInHrefString(const nsAString &aHref,
const nsAString &aSearch,
nsAString &aResult);
static nsresult SetHashInHrefString(const nsAString &aHref,
const nsAString &aHash,
nsAString &aResult);
static nsresult SetPortInHrefString(const nsAString &aHref,
const nsAString &aPort,
nsAString &aResult);
static nsresult GetProtocolFromHrefString(const nsAString &aHref,
nsAString& aProtocol,
nsIDocument *aDocument);
static nsresult GetHostFromHrefString(const nsAString &aHref,
nsAString& aHost);
static nsresult GetHostnameFromHrefString(const nsAString &aHref,
nsAString& aHostname);
static nsresult GetPathnameFromHrefString(const nsAString &aHref,
nsAString& aPathname);
static nsresult GetSearchFromHrefString(const nsAString &aHref,
nsAString& aSearch);
static nsresult GetPortFromHrefString(const nsAString &aHref,
nsAString& aPort);
static nsresult GetHashFromHrefString(const nsAString &aHref,
nsAString& aHash);
nsresult GetProtocolFromHrefURI(nsAString& aProtocol);
nsresult GetHostFromHrefURI(nsAString& aHost);
nsresult GetHostnameFromHrefURI(nsAString& aHostname);
nsresult GetPathnameFromHrefURI(nsAString& aPathname);
nsresult GetSearchFromHrefURI(nsAString& aSearch);
nsresult GetPortFromHrefURI(nsAString& aPort);
nsresult GetHashFromHrefURI(nsAString& aHash);
/**
* Locate an nsIEditor rooted at this content node, if there is one.

Просмотреть файл

@ -358,204 +358,27 @@ nsHTMLAnchorElement::SetTarget(const nsAString& aValue)
return SetAttr(kNameSpaceID_None, nsGkAtoms::target, aValue, PR_TRUE);
}
NS_IMETHODIMP
nsHTMLAnchorElement::GetProtocol(nsAString& aProtocol)
{
nsAutoString href;
#define IMPL_URI_PART(_part) \
NS_IMETHODIMP \
nsHTMLAnchorElement::Get##_part(nsAString& a##_part) \
{ \
return Get##_part##FromHrefURI(a##_part); \
} \
NS_IMETHODIMP \
nsHTMLAnchorElement::Set##_part(const nsAString& a##_part) \
{ \
return Set##_part##InHrefURI(a##_part); \
}
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
IMPL_URI_PART(Protocol)
IMPL_URI_PART(Host)
IMPL_URI_PART(Hostname)
IMPL_URI_PART(Pathname)
IMPL_URI_PART(Search)
IMPL_URI_PART(Port)
IMPL_URI_PART(Hash)
// XXX this should really use GetHrefURI and not do so much string stuff
return GetProtocolFromHrefString(href, aProtocol, GetOwnerDoc());
}
NS_IMETHODIMP
nsHTMLAnchorElement::SetProtocol(const nsAString& aProtocol)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetProtocolInHrefString(href, aProtocol, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
NS_IMETHODIMP
nsHTMLAnchorElement::GetHost(nsAString& aHost)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
return GetHostFromHrefString(href, aHost);
}
NS_IMETHODIMP
nsHTMLAnchorElement::SetHost(const nsAString& aHost)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetHostInHrefString(href, aHost, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
NS_IMETHODIMP
nsHTMLAnchorElement::GetHostname(nsAString& aHostname)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
return GetHostnameFromHrefString(href, aHostname);
}
NS_IMETHODIMP
nsHTMLAnchorElement::SetHostname(const nsAString& aHostname)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetHostnameInHrefString(href, aHostname, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
NS_IMETHODIMP
nsHTMLAnchorElement::GetPathname(nsAString& aPathname)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
return GetPathnameFromHrefString(href, aPathname);
}
NS_IMETHODIMP
nsHTMLAnchorElement::SetPathname(const nsAString& aPathname)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetPathnameInHrefString(href, aPathname, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
NS_IMETHODIMP
nsHTMLAnchorElement::GetSearch(nsAString& aSearch)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
return GetSearchFromHrefString(href, aSearch);
}
NS_IMETHODIMP
nsHTMLAnchorElement::SetSearch(const nsAString& aSearch)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetSearchInHrefString(href, aSearch, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
NS_IMETHODIMP
nsHTMLAnchorElement::GetPort(nsAString& aPort)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
return GetPortFromHrefString(href, aPort);
}
NS_IMETHODIMP
nsHTMLAnchorElement::SetPort(const nsAString& aPort)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetPortInHrefString(href, aPort, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
NS_IMETHODIMP
nsHTMLAnchorElement::GetHash(nsAString& aHash)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
return GetHashFromHrefString(href, aHash);
}
NS_IMETHODIMP
nsHTMLAnchorElement::SetHash(const nsAString& aHash)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetHashInHrefString(href, aHash, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
#undef IMPL_URI_PART
NS_IMETHODIMP
nsHTMLAnchorElement::GetText(nsAString& aText)

Просмотреть файл

@ -297,204 +297,27 @@ nsHTMLAreaElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
return nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute, aNotify);
}
NS_IMETHODIMP
nsHTMLAreaElement::GetProtocol(nsAString& aProtocol)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
#define IMPL_URI_PART(_part) \
NS_IMETHODIMP \
nsHTMLAreaElement::Get##_part(nsAString& a##_part) \
{ \
return Get##_part##FromHrefURI(a##_part); \
} \
NS_IMETHODIMP \
nsHTMLAreaElement::Set##_part(const nsAString& a##_part) \
{ \
return Set##_part##InHrefURI(a##_part); \
}
// XXX this should really use GetHrefURI and not do so much string stuff
return GetProtocolFromHrefString(href, aProtocol, GetOwnerDoc());
}
IMPL_URI_PART(Protocol)
IMPL_URI_PART(Host)
IMPL_URI_PART(Hostname)
IMPL_URI_PART(Pathname)
IMPL_URI_PART(Search)
IMPL_URI_PART(Port)
IMPL_URI_PART(Hash)
NS_IMETHODIMP
nsHTMLAreaElement::SetProtocol(const nsAString& aProtocol)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetProtocolInHrefString(href, aProtocol, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
NS_IMETHODIMP
nsHTMLAreaElement::GetHost(nsAString& aHost)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
return GetHostFromHrefString(href, aHost);
}
NS_IMETHODIMP
nsHTMLAreaElement::SetHost(const nsAString& aHost)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetHostInHrefString(href, aHost, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
NS_IMETHODIMP
nsHTMLAreaElement::GetHostname(nsAString& aHostname)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
return GetHostnameFromHrefString(href, aHostname);
}
NS_IMETHODIMP
nsHTMLAreaElement::SetHostname(const nsAString& aHostname)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetHostnameInHrefString(href, aHostname, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
NS_IMETHODIMP
nsHTMLAreaElement::GetPathname(nsAString& aPathname)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
return GetPathnameFromHrefString(href, aPathname);
}
NS_IMETHODIMP
nsHTMLAreaElement::SetPathname(const nsAString& aPathname)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetPathnameInHrefString(href, aPathname, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
NS_IMETHODIMP
nsHTMLAreaElement::GetSearch(nsAString& aSearch)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
return GetSearchFromHrefString(href, aSearch);
}
NS_IMETHODIMP
nsHTMLAreaElement::SetSearch(const nsAString& aSearch)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetSearchInHrefString(href, aSearch, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
NS_IMETHODIMP
nsHTMLAreaElement::GetPort(nsAString& aPort)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
return GetPortFromHrefString(href, aPort);
}
NS_IMETHODIMP
nsHTMLAreaElement::SetPort(const nsAString& aPort)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetPortInHrefString(href, aPort, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
NS_IMETHODIMP
nsHTMLAreaElement::GetHash(nsAString& aHash)
{
nsAutoString href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
return GetHashFromHrefString(href, aHash);
}
NS_IMETHODIMP
nsHTMLAreaElement::SetHash(const nsAString& aHash)
{
nsAutoString href, new_href;
nsresult rv = GetHref(href);
if (NS_FAILED(rv))
return rv;
rv = SetHashInHrefString(href, aHash, new_href);
if (NS_FAILED(rv))
// Ignore failures to be compatible with NS4
return NS_OK;
return SetHref(new_href);
}
#undef IMPL_URI_PART
NS_IMETHODIMP
nsHTMLAreaElement::ToString(nsAString& aSource)