summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorPale Moon <git-repo@palemoon.org>2016-03-18 23:15:09 +0100
committerPale Moon <git-repo@palemoon.org>2016-03-18 23:15:09 +0100
commit7461f0ad1bf86b283e2cd0254c70457ec22ebee8 (patch)
tree27b6c64056beb4bfd41a7d5abeaa217921efacf9 /content
parent3e00734c1360a755cf20005f10aaf4decd726a44 (diff)
parent3fd594ed2752aa531797371fbd50520d4b312c60 (diff)
downloadpalemoon-gre-7461f0ad1bf86b283e2cd0254c70457ec22ebee8.tar.gz
Merge branch 'URL_API-work'
Diffstat (limited to 'content')
-rw-r--r--content/base/public/nsContentUtils.h1
-rw-r--r--content/base/src/Link.cpp96
-rw-r--r--content/base/src/Link.h5
-rw-r--r--content/base/src/nsContentUtils.cpp13
-rw-r--r--content/html/content/src/HTMLAnchorElement.h25
-rw-r--r--content/html/content/src/HTMLAreaElement.h25
6 files changed, 140 insertions, 25 deletions
diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h
index dfcd3f5fb..afe986722 100644
--- a/content/base/public/nsContentUtils.h
+++ b/content/base/public/nsContentUtils.h
@@ -1607,6 +1607,7 @@ public:
static nsresult GetUTFOrigin(nsIPrincipal* aPrincipal,
nsString& aOrigin);
static nsresult GetUTFOrigin(nsIURI* aURI, nsString& aOrigin);
+ static void GetUTFNonNullOrigin(nsIURI* aURI, nsString& aOrigin);
/**
* This method creates and dispatches "command" event, which implements
diff --git a/content/base/src/Link.cpp b/content/base/src/Link.cpp
index f3299250b..d289b53d5 100644
--- a/content/base/src/Link.cpp
+++ b/content/base/src/Link.cpp
@@ -153,7 +153,7 @@ Link::SetProtocol(const nsAString &aProtocol)
}
void
-Link::SetHost(const nsAString &aHost)
+Link::SetPassword(const nsAString &aPassword)
{
nsCOMPtr<nsIURI> uri(GetURIToMutate());
if (!uri) {
@@ -161,32 +161,33 @@ Link::SetHost(const nsAString &aHost)
return;
}
- // We cannot simply call nsIURI::SetHost because that would treat the name as
- // an IPv6 address (like http:://[server:443]/). We also cannot call
- // nsIURI::SetHostPort because that isn't implemented. Sadfaces.
+ uri->SetPassword(NS_ConvertUTF16toUTF8(aPassword));
+ SetHrefAttribute(uri);
+}
- // First set the hostname.
- nsAString::const_iterator start, end;
- aHost.BeginReading(start);
- aHost.EndReading(end);
- nsAString::const_iterator iter(start);
- (void)FindCharInReadable(':', iter, end);
- NS_ConvertUTF16toUTF8 host(Substring(start, iter));
- (void)uri->SetHost(host);
-
- // Also set the port if needed.
- if (iter != end) {
- iter++;
- if (iter != end) {
- nsAutoString portStr(Substring(iter, end));
- nsresult rv;
- int32_t port = portStr.ToInteger(&rv);
- if (NS_SUCCEEDED(rv)) {
- (void)uri->SetPort(port);
- }
- }
- };
+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)
+{
+ nsCOMPtr<nsIURI> uri(GetURIToMutate());
+ if (!uri) {
+ // Ignore failures to be compatible with NS4.
+ return;
+ }
+ (void)uri->SetHostPort(NS_ConvertUTF16toUTF8(aHost));
SetHrefAttribute(uri);
return;
}
@@ -266,6 +267,21 @@ Link::SetHash(const nsAString &aHash)
}
void
+Link::GetOrigin(nsAString &aOrigin)
+{
+ aOrigin.Truncate();
+
+ nsCOMPtr<nsIURI> uri(GetURI());
+ if (!uri) {
+ return;
+ }
+
+ nsString origin;
+ nsContentUtils::GetUTFNonNullOrigin(uri, origin);
+ aOrigin.Assign(origin);
+}
+
+void
Link::GetProtocol(nsAString &_protocol)
{
nsCOMPtr<nsIURI> uri(GetURI());
@@ -282,6 +298,36 @@ Link::GetProtocol(nsAString &_protocol)
}
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)
{
_host.Truncate();
diff --git a/content/base/src/Link.h b/content/base/src/Link.h
index a07408ad4..72a6c8e36 100644
--- a/content/base/src/Link.h
+++ b/content/base/src/Link.h
@@ -53,13 +53,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);
diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp
index 8d21a908f..8eb116652 100644
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -5498,6 +5498,19 @@ nsContentUtils::GetUTFOrigin(nsIURI* aURI, nsString& aOrigin)
}
/* static */
+void
+nsContentUtils::GetUTFNonNullOrigin(nsIURI* aURI, nsString& aOrigin)
+{
+ aOrigin.Truncate();
+
+ nsString origin;
+ nsresult rv = GetUTFOrigin(aURI, origin);
+ if (NS_SUCCEEDED(rv) && !origin.EqualsLiteral("null")) {
+ aOrigin.Assign(origin);
+ }
+}
+
+/* static */
already_AddRefed<nsIDocument>
nsContentUtils::GetDocumentFromScriptContext(nsIScriptContext *aScriptContext)
{
diff --git a/content/html/content/src/HTMLAnchorElement.h b/content/html/content/src/HTMLAnchorElement.h
index a88f17685..94edd0be4 100644
--- a/content/html/content/src/HTMLAnchorElement.h
+++ b/content/html/content/src/HTMLAnchorElement.h
@@ -153,6 +153,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)
{
diff --git a/content/html/content/src/HTMLAreaElement.h b/content/html/content/src/HTMLAreaElement.h
index f07ef3442..720aeb065 100644
--- a/content/html/content/src/HTMLAreaElement.h
+++ b/content/html/content/src/HTMLAreaElement.h
@@ -125,9 +125,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