Bug 1312742 - Match spec/other browsers for ping reflection draft
authorAryeh Gregor <ayg@aryeh.name>
Wed, 26 Oct 2016 21:24:15 +0300
changeset 431512 67385c8dc1e8726419cd006e274496e95bf4784e
parent 429179 c6ccd71126ff514bfc44b53e2217562e29a0cc38
child 535414 e680120c4fa514b9c228f39dd6a932a2f2ba528f
push id34053
push userayg@aryeh.name
push dateSat, 29 Oct 2016 19:25:40 +0000
bugs1312742
milestone52.0a1
Bug 1312742 - Match spec/other browsers for ping reflection The spec used to say that getting the .ping property on HTMLAnchorElement or HTMLAreaElement should return a DOMTokenList of parsed URLs, but it now says to return a plain string. All other UAs that implement ping match the new spec, and it's hopefully unlikely that any sites depend on our old behavior. Discussion: https://github.com/whatwg/html/issues/1780 MozReview-Commit-ID: LpmH8ANNT9g
dom/html/HTMLAnchorElement.cpp
dom/html/HTMLAreaElement.cpp
dom/html/nsGenericHTMLElement.cpp
dom/html/nsGenericHTMLElement.h
testing/web-platform/tests/html/dom/elements-embedded.js
testing/web-platform/tests/html/dom/elements-text.js
--- a/dom/html/HTMLAnchorElement.cpp
+++ b/dom/html/HTMLAnchorElement.cpp
@@ -342,20 +342,21 @@ HTMLAnchorElement::SetText(const nsAStri
 }
 
 NS_IMETHODIMP
 HTMLAnchorElement::ToString(nsAString& aSource)
 {
   return GetHref(aSource);
 }
 
-NS_IMETHODIMP    
+NS_IMETHODIMP
 HTMLAnchorElement::GetPing(nsAString& aValue)
 {
-  return GetURIListAttr(nsGkAtoms::ping, aValue);
+  GetAttr(kNameSpaceID_None, nsGkAtoms::ping, aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLAnchorElement::SetPing(const nsAString& aValue)
 {
   return SetAttr(kNameSpaceID_None, nsGkAtoms::ping, aValue, true);
 }
 
--- a/dom/html/HTMLAreaElement.cpp
+++ b/dom/html/HTMLAreaElement.cpp
@@ -216,20 +216,21 @@ IMPL_URI_PART(Hash)
 #undef IMPL_URI_PART
 
 NS_IMETHODIMP
 HTMLAreaElement::ToString(nsAString& aSource)
 {
   return GetHref(aSource);
 }
 
-NS_IMETHODIMP    
+NS_IMETHODIMP
 HTMLAreaElement::GetPing(nsAString& aValue)
 {
-  return GetURIListAttr(nsGkAtoms::ping, aValue);
+  GetAttr(kNameSpaceID_None, nsGkAtoms::ping, aValue);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 HTMLAreaElement::SetPing(const nsAString& aValue)
 {
   return SetAttr(kNameSpaceID_None, nsGkAtoms::ping, aValue, true);
 }
 
--- a/dom/html/nsGenericHTMLElement.cpp
+++ b/dom/html/nsGenericHTMLElement.cpp
@@ -1674,78 +1674,16 @@ nsGenericHTMLElement::GetURIAttr(nsIAtom
 /* static */ bool
 nsGenericHTMLElement::IsScrollGrabAllowed(JSContext*, JSObject*)
 {
   // Only allow scroll grabbing in chrome
   nsIPrincipal* prin = nsContentUtils::SubjectPrincipal();
   return nsContentUtils::IsSystemPrincipal(prin);
 }
 
-nsresult
-nsGenericHTMLElement::GetURIListAttr(nsIAtom* aAttr, nsAString& aResult)
-{
-  aResult.Truncate();
-
-  nsAutoString value;
-  if (!GetAttr(kNameSpaceID_None, aAttr, value))
-    return NS_OK;
-
-  nsIDocument* doc = OwnerDoc(); 
-  nsCOMPtr<nsIURI> baseURI = GetBaseURI();
-
-  nsString::const_iterator end;
-  value.EndReading(end);
-
-  nsAString::const_iterator iter;
-  value.BeginReading(iter);
-
-  while (iter != end) {
-    while (*iter == ' ' && iter != end) {
-      ++iter;
-    }
-
-    if (iter == end) {
-      break;
-    }
-
-    nsAString::const_iterator start = iter;
-
-    while (iter != end && *iter != ' ') {
-      ++iter;
-    }
-
-    if (!aResult.IsEmpty()) {
-      aResult.Append(NS_LITERAL_STRING(" "));
-    }
-
-    const nsSubstring& uriPart = Substring(start, iter);
-    nsCOMPtr<nsIURI> attrURI;
-    nsresult rv =
-      nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(attrURI),
-                                                uriPart, doc, baseURI);
-    if (NS_FAILED(rv)) {
-      aResult.Append(uriPart);
-      continue;
-    }
-
-    MOZ_ASSERT(attrURI);
-
-    nsAutoCString spec;
-    rv = attrURI->GetSpec(spec);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      aResult.Append(uriPart);
-      continue;
-    }
-
-    AppendUTF8toUTF16(spec, aResult);
-  }
-
-  return NS_OK;
-}
-
 HTMLMenuElement*
 nsGenericHTMLElement::GetContextMenu() const
 {
   nsAutoString value;
   GetHTMLAttr(nsGkAtoms::contextmenu, value);
   if (!value.IsEmpty()) {
     //XXXsmaug How should this work in Shadow DOM?
     nsIDocument* doc = GetUncomposedDoc();
--- a/dom/html/nsGenericHTMLElement.h
+++ b/dom/html/nsGenericHTMLElement.h
@@ -1058,30 +1058,16 @@ protected:
   {
     nsAutoString value;
     value.AppendFloat(aValue);
 
     SetHTMLAttr(aAttr, value, aRv);
   }
 
   /**
-   * This method works like GetURIAttr, except that it supports multiple
-   * URIs separated by whitespace (one or more U+0020 SPACE characters).
-   *
-   * Gets the absolute URI values of an attribute, by resolving any relative
-   * URIs in the attribute against the baseuri of the element. If a substring
-   * isn't a relative URI, the substring is returned as is. Only works for
-   * attributes in null namespace.
-   *
-   * @param aAttr    name of attribute.
-   * @param aResult  result value [out]
-   */
-  nsresult GetURIListAttr(nsIAtom* aAttr, nsAString& aResult);
-
-  /**
    * Locates the nsIEditor associated with this node.  In general this is
    * equivalent to GetEditorInternal(), but for designmode or contenteditable,
    * this may need to get an editor that's not actually on this element's
    * associated TextControlFrame.  This is used by the spellchecking routines
    * to get the editor affected by changing the spellcheck attribute on this
    * node.
    */
   virtual already_AddRefed<nsIEditor> GetAssociatedEditor();
--- a/testing/web-platform/tests/html/dom/elements-embedded.js
+++ b/testing/web-platform/tests/html/dom/elements-embedded.js
@@ -130,17 +130,17 @@ var embeddedElements = {
   },
   area: {
     // Conforming
     alt: "string",
     coords: "string",
     shape: "string",
     target: "string",
     download: "string",
-    ping: "urls",
+    ping: "string",
     rel: "string",
     relList: {type: "tokenlist", domAttrName: "rel"},
     hreflang: "string",
     type: "string",
 
     // HTMLHyperlinkElementUtils
     href: "url",
 
--- a/testing/web-platform/tests/html/dom/elements-text.js
+++ b/testing/web-platform/tests/html/dom/elements-text.js
@@ -1,15 +1,15 @@
 // Up-to-date as of 2013-04-19.
 var textElements = {
   a: {
     // Conforming
     target: "string",
     download: "string",
-    ping: "urls",
+    ping: "string",
     rel: "string",
     relList: {type: "tokenlist", domAttrName: "rel"},
     hreflang: "string",
     type: "string",
 
     // HTMLHyperlinkElementUtils
     href: "url",