Bug 887364 - Update URLUtils interface. r=ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 04 Sep 2013 13:05:10 -0400
changeset 158376 907989350527f6f73e5b107cce519453afd34006
parent 158375 7850adf40329e17565cab0a26e7f93e1f7ef3100
child 158377 f2199d73aef6c7d68fe54ba360a676d2b2108b3f
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs887364
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 887364 - Update URLUtils interface. r=ehsan
content/base/src/Link.cpp
content/base/src/Link.h
content/html/content/src/HTMLAnchorElement.h
content/html/content/src/HTMLAreaElement.h
dom/webidl/HTMLAnchorElement.webidl
dom/webidl/HTMLAreaElement.webidl
dom/webidl/Location.webidl
dom/webidl/URLUtils.webidl
--- a/content/base/src/Link.cpp
+++ b/content/base/src/Link.cpp
@@ -142,16 +142,42 @@ Link::SetProtocol(const nsAString &aProt
   nsAString::const_iterator iter(start);
   (void)FindCharInReadable(':', iter, end);
   (void)uri->SetScheme(NS_ConvertUTF16toUTF8(Substring(start, iter)));
 
   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)
 {
   nsCOMPtr<nsIURI> uri(GetURIToMutate());
   if (!uri) {
     // Ignore failures to be compatible with NS4.
     return;
   }
 
@@ -255,32 +281,83 @@ Link::SetHash(const nsAString &aHash)
     return;
   }
 
   (void)uri->SetRef(NS_ConvertUTF16toUTF8(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)
 {
   nsCOMPtr<nsIURI> uri(GetURI());
   if (!uri) {
     _protocol.AssignLiteral("http");
   }
   else {
     nsAutoCString scheme;
     (void)uri->GetScheme(scheme);
     CopyASCIItoUTF16(scheme, _protocol);
   }
   _protocol.Append(PRUnichar(':'));
   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)
 {
   _host.Truncate();
 
   nsCOMPtr<nsIURI> uri(GetURI());
   if (!uri) {
     // Do not throw!  Not having a valid URI should result in an empty string.
     return;
--- a/content/base/src/Link.h
+++ b/content/base/src/Link.h
@@ -49,23 +49,28 @@ public:
   virtual nsIURI* GetURIExternal() const {
     return GetURI();
   }
 
   /**
    * 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);
   void GetSearch(nsAString &_search);
   void GetPort(nsAString &_port);
   void GetHash(nsAString &_hash);
 
   /**
--- a/content/html/content/src/HTMLAnchorElement.h
+++ b/content/html/content/src/HTMLAnchorElement.h
@@ -129,16 +129,41 @@ public:
   {
     SetHTMLAttr(nsGkAtoms::type, aValue, rv);
   }
   // The XPCOM GetText is OK for us
   void SetText(const nsAString& aValue, mozilla::ErrorResult& rv)
   {
     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)
   {
     GetHTMLAttr(nsGkAtoms::coords, aValue);
   }
   void SetCoords(const nsAString& aValue, mozilla::ErrorResult& rv)
   {
     SetHTMLAttr(nsGkAtoms::coords, aValue, rv);
--- a/content/html/content/src/HTMLAreaElement.h
+++ b/content/html/content/src/HTMLAreaElement.h
@@ -103,19 +103,44 @@ public:
   }
 
   // The XPCOM GetPing is OK for us
   void SetPing(const nsAString& aPing, ErrorResult& aError)
   {
     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
 
   // The XPCOM GetHostname is OK for us
   // The XPCOM SetHostname is OK for us
 
   // The XPCOM GetPort is OK for us
   // The XPCOM SetPort is OK for us
--- a/dom/webidl/HTMLAnchorElement.webidl
+++ b/dom/webidl/HTMLAnchorElement.webidl
@@ -8,23 +8,18 @@
  * http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis
  * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
  * Opera Software ASA. You are granted a license to use, reproduce
  * and create derivative works of this document.
  */
 
 // 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]
            attribute DOMString download;
            [SetterThrows]
            attribute DOMString ping;
            [SetterThrows]
            attribute DOMString rel;
   // relList not supported yet
--- a/dom/webidl/HTMLAreaElement.webidl
+++ b/dom/webidl/HTMLAreaElement.webidl
@@ -9,28 +9,23 @@
  &
  * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
  * Opera Software ASA. You are granted a license to use, reproduce
  * and create derivative works of this document.
  */
 
 // 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]
            attribute DOMString download;
            [SetterThrows]
            attribute DOMString ping;
 
   // not implemented.
--- a/dom/webidl/Location.webidl
+++ b/dom/webidl/Location.webidl
@@ -9,14 +9,13 @@
  * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
  * Opera Software ASA. You are granted a license to use, reproduce
  * and create derivative works of this document.
  */
 
 // No support for [Unforgeable] on interfaces yet
 //[Unforgeable]
 interface Location {
-  stringifier attribute DOMString href;
   void assign(DOMString url);
   void replace(DOMString url);
   void reload();
 };
 Location implements URLUtils;
--- a/dom/webidl/URLUtils.webidl
+++ b/dom/webidl/URLUtils.webidl
@@ -10,23 +10,23 @@
  * and related or neighboring rights to this work. In addition, as of 17
  * February 2013, the editors have made this specification available under
  * the Open Web Foundation Agreement Version 1.0, which is available at
  * http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
  */
 
 [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;
            attribute DOMString pathname;
            attribute DOMString search;
            // attribute URLQuery? query;
            attribute DOMString hash;
 };