Bug 1427419 - Part 20: Move inIDOMUtils.getBindingURLs to InspectorUtils. r?bz draft
authorCameron McCormack <cam@mcc.id.au>
Sat, 06 Jan 2018 15:08:15 +0800
changeset 716765 27cf48b312e9fe5256c612ea4b0cf0d57c96c43a
parent 716764 32871dcf0c52d69278e2e1fd9e3ef285397e28d8
child 716766 6fa77e224bdfef2295110e92aa07cc952f9d3c89
push id94496
push userbmo:cam@mcc.id.au
push dateSat, 06 Jan 2018 07:08:40 +0000
reviewersbz
bugs1427419
milestone59.0a1
Bug 1427419 - Part 20: Move inIDOMUtils.getBindingURLs to InspectorUtils. r?bz This is unused in mozilla-central but still used by comm-central. The only consumer of this API really just wants the URL strings, so we return a sequence<DOMString> instead of an array of nsIURI objects. MozReview-Commit-ID: ITcEe42shHw
dom/webidl/InspectorUtils.webidl
layout/inspector/InspectorUtils.h
layout/inspector/inDOMUtils.cpp
layout/inspector/inIDOMUtils.idl
layout/inspector/tests/mochitest.ini
layout/inspector/tests/test_bug462787.html
layout/inspector/tests/test_bug462789.html
layout/inspector/tests/test_bug806192.html
--- a/dom/webidl/InspectorUtils.webidl
+++ b/dom/webidl/InspectorUtils.webidl
@@ -51,16 +51,17 @@ namespace InspectorUtils {
   const unsigned long TYPE_IMAGE_RECT = 9;
   const unsigned long TYPE_NUMBER = 10;
   [Throws] boolean cssPropertySupportsType(DOMString property, unsigned long type);
 
   boolean isIgnorableWhitespace(CharacterData dataNode);
   Node? getParentForNode(Node node, boolean showingAnonymousContent);
   [NewObject] NodeList getChildrenForNode(Node node,
                                           boolean showingAnonymousContent);
+  sequence<DOMString> getBindingURLs(Element element);
 };
 
 dictionary PropertyNamesOptions {
   boolean includeAliases = false;
 };
 
 dictionary InspectorRGBATuple {
   /*
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -185,16 +185,20 @@ public:
       bool aShowingAnonymousContent)
   {
     return GetChildrenForNode(aNode, aShowingAnonymousContent);
   }
   static already_AddRefed<nsINodeList> GetChildrenForNode(
       nsINode& aNode,
       bool aShowingAnonymousContent);
 
+  static void GetBindingURLs(GlobalObject& aGlobal,
+                             Element& aElement,
+                             nsTArray<nsString>& aResult);
+
 private:
   static already_AddRefed<nsStyleContext>
     GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);
 };
 
 } // namespace dom
 } // namespace mozilla
 
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -871,45 +871,37 @@ InspectorUtils::IsValidCSSColor(GlobalOb
   return ServoCSSParser::IsValidCSSColor(aColorString);
 #else
   nsCSSParser cssParser;
   nsCSSValue cssValue;
   return cssParser.ParseColorString(aColorString, nullptr, 0, cssValue, true);
 #endif
 }
 
+void
+InspectorUtils::GetBindingURLs(GlobalObject& aGlobalObject,
+                               Element& aElement,
+                               nsTArray<nsString>& aResult)
+{
+  nsXBLBinding* binding = aElement.GetXBLBinding();
+
+  while (binding) {
+    nsCString spec;
+    nsCOMPtr<nsIURI> bindingURI = binding->PrototypeBinding()->BindingURI();
+    bindingURI->GetSpec(spec);
+    nsString* resultURI = aResult.AppendElement();
+    CopyASCIItoUTF16(spec, *resultURI);
+    binding = binding->GetBaseBinding();
+  }
+}
+
 } // namespace dom
 } // namespace mozilla
 
 NS_IMETHODIMP
-inDOMUtils::GetBindingURLs(nsIDOMElement *aElement, nsIArray **_retval)
-{
-  NS_ENSURE_ARG_POINTER(aElement);
-
-  *_retval = nullptr;
-
-  nsCOMPtr<nsIMutableArray> urls = do_CreateInstance(NS_ARRAY_CONTRACTID);
-  if (!urls)
-    return NS_ERROR_FAILURE;
-
-  nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
-  NS_ENSURE_ARG_POINTER(content);
-
-  nsXBLBinding *binding = content->GetXBLBinding();
-
-  while (binding) {
-    urls->AppendElement(binding->PrototypeBinding()->BindingURI());
-    binding = binding->GetBaseBinding();
-  }
-
-  urls.forget(_retval);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 inDOMUtils::SetContentState(nsIDOMElement* aElement,
                             EventStates::InternalType aState,
                             bool* aRetVal)
 {
   NS_ENSURE_ARG_POINTER(aElement);
 
   RefPtr<EventStateManager> esm =
     inLayoutUtils::GetEventStateManagerFor(aElement);
--- a/layout/inspector/inIDOMUtils.idl
+++ b/layout/inspector/inIDOMUtils.idl
@@ -15,19 +15,16 @@ interface nsIDOMNode;
 interface nsIDOMNodeList;
 interface nsIDOMFontFaceList;
 interface nsIDOMRange;
 interface nsIDOMCSSStyleSheet;
 
 [scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
 interface inIDOMUtils : nsISupports
 {
-  // XBL utilities
-  nsIArray getBindingURLs(in nsIDOMElement aElement);
-
   // content state utilities
   unsigned long long getContentState(in nsIDOMElement aElement);
   /**
    * Setting and removing content state on an element. Both these functions
    * calling EventStateManager::SetContentState internally, the difference is
    * that for the remove case we simply pass in nullptr for the element.
    * Use them accordingly.
    *
--- a/layout/inspector/tests/mochitest.ini
+++ b/layout/inspector/tests/mochitest.ini
@@ -7,17 +7,16 @@ support-files =
 
 [test_bug462787.html]
 [test_bug462789.html]
 [test_bug522601.xhtml]
 [test_bug536379.html]
 [test_bug536379-2.html]
 [test_bug557726.html]
 [test_bug609549.xhtml]
-[test_bug806192.html]
 [test_bug856317.html]
 [test_bug877690.html]
 [test_bug1006595.html]
 [test_color_to_rgba.html]
 [test_css_property_is_shorthand.html]
 [test_getCSSStyleRules.html]
 support-files =
   file_getCSSStyleRules-default.html
--- a/layout/inspector/tests/test_bug462787.html
+++ b/layout/inspector/tests/test_bug462787.html
@@ -59,17 +59,17 @@ function do_test() {
   }
 
   try {
     utils.getBindingURLs(null); 
     ok(false, "expected an exception"); 
   }
   catch(e) {
     e = SpecialPowers.wrap(e);
-    is(e.result, INVALID_POINTER, "got the expected exception");
+    is(e.name, "TypeError", "got the expected exception");
   }
 
   try {
     utils.getContentState(null); 
     ok(false, "expected an exception"); 
   }
   catch(e) {
     e = SpecialPowers.wrap(e);
--- a/layout/inspector/tests/test_bug462789.html
+++ b/layout/inspector/tests/test_bug462789.html
@@ -58,18 +58,18 @@ function do_test() {
     var res = InspectorUtils.getParentForNode(docElement, true);
     is(res.nodeType, DOCUMENT_NODE_TYPE, "getParentForNode(docElement, true)");
     res = InspectorUtils.getParentForNode(text, true);
     is(res.tagName, "BODY", "getParentForNode(text, true)");
   }
   catch(e) { ok(false, "got an unexpected exception:" + e); }
 
   try {
-    var res = utils.getBindingURLs(docElement);
-    ok(SpecialPowers.call_Instanceof(res, SpecialPowers.Ci["nsIArray"]), "getBindingURLs result type");
+    var res = InspectorUtils.getBindingURLs(docElement);
+    ok(Array.isArray(SpecialPowers.unwrap(res)), "getBindingURLs result type");
     is(res.length, 0, "getBindingURLs array length");
   }
   catch(e) { ok(false, "got an unexpected exception:" + e); }
 
   try {
     utils.getContentState(docElement);
     ok(true, "Should not throw"); 
   }
deleted file mode 100644
--- a/layout/inspector/tests/test_bug806192.html
+++ /dev/null
@@ -1,26 +0,0 @@
-<!DOCTYPE HTML>
-<html>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=806192
--->
-<head>
-  <title>Test for Bug 806192</title>
-  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-</head>
-<body>
-<pre id="test">
-<script type="application/javascript">
-
-const utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
-.getService(SpecialPowers.Ci.inIDOMUtils);
-
-try {
-    var res = utils.getBindingURLs({});
-    ok(false, "didn't get error");
-}
-catch(e) { ok(true, "got expected exception"); }
-</script>
-</pre>
-</body>
-</html>