Bug 1427419 - Part 9: Move inIDOMUtils.getCSSValuesForProperty to InspectorUtils. r=bz
authorCameron McCormack <cam@mcc.id.au>
Thu, 11 Jan 2018 12:38:00 +0800
changeset 450471 3fab386062a12015871508c849ad398c3ef38cd5
parent 450470 19ea76feea126b988c60c5e19d9c832bc41c05a7
child 450472 b7386d96d8b2a219c922bc8e08fda5ccd051557a
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1427419
milestone59.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 1427419 - Part 9: Move inIDOMUtils.getCSSValuesForProperty to InspectorUtils. r=bz MozReview-Commit-ID: D3jf42KI7kO
devtools/client/shared/test/unit/test_cssColorDatabase.js
devtools/server/actors/css-properties.js
dom/webidl/InspectorUtils.webidl
layout/inspector/InspectorUtils.h
layout/inspector/inDOMUtils.cpp
layout/inspector/inIDOMUtils.idl
layout/inspector/tests/test_bug877690.html
layout/inspector/tests/test_is_valid_css_color.html
--- a/devtools/client/shared/test/unit/test_cssColorDatabase.js
+++ b/devtools/client/shared/test/unit/test_cssColorDatabase.js
@@ -10,16 +10,17 @@ var Ci = Components.interfaces;
 var Cc = Components.classes;
 
 var {require} = Cu.import("resource://devtools/shared/Loader.jsm", {});
 
 const DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
 
 const {colorUtils} = require("devtools/shared/css/color");
 const {cssColors} = require("devtools/shared/css/color-db");
+const InspectorUtils = require("InspectorUtils");
 
 function isValid(colorName) {
   ok(colorUtils.isValidCSSColor(colorName),
      colorName + " is valid in database");
   ok(DOMUtils.isValidCSSColor(colorName),
      colorName + " is valid in DOMUtils");
 }
 
@@ -47,17 +48,17 @@ function checkOne(colorName, checkName) 
 function run_test() {
   for (let name in cssColors) {
     checkOne(name, true);
   }
   checkOne("transparent", false);
 
   // Now check that platform didn't add a new name when we weren't
   // looking.
-  let names = DOMUtils.getCSSValuesForProperty("background-color");
+  let names = InspectorUtils.getCSSValuesForProperty("background-color");
   for (let name of names) {
     if (name !== "hsl" && name !== "hsla" &&
         name !== "rgb" && name !== "rgba" &&
         name !== "inherit" && name !== "initial" && name !== "unset") {
       checkOne(name, true);
     }
   }
 }
--- a/devtools/server/actors/css-properties.js
+++ b/devtools/server/actors/css-properties.js
@@ -54,17 +54,17 @@ function generateCssProperties() {
     let supports = [];
     for (let type in CSS_TYPES) {
       if (safeCssPropertySupportsType(name, DOMUtils["TYPE_" + type])) {
         supports.push(CSS_TYPES[type]);
       }
     }
 
     // Don't send colors over RDP, these will be re-attached by the front.
-    let values = DOMUtils.getCSSValuesForProperty(name);
+    let values = InspectorUtils.getCSSValuesForProperty(name);
     if (values.includes("aliceblue")) {
       values = values.filter(x => !colors.includes(x));
       values.unshift("COLOR");
     }
 
     let subproperties = DOMUtils.getSubpropertiesForCSSProperty(name);
 
     properties[name] = {
--- a/dom/webidl/InspectorUtils.webidl
+++ b/dom/webidl/InspectorUtils.webidl
@@ -26,16 +26,17 @@ namespace InspectorUtils {
                                              unsigned long selectorIndex);
   [Throws] boolean selectorMatchesElement(
       Element element,
       CSSStyleRule rule,
       unsigned long selectorIndex,
       [TreatNullAs=EmptyString] optional DOMString pseudo = "");
   boolean isInheritedProperty(DOMString property);
   sequence<DOMString> getCSSPropertyNames(optional PropertyNamesOptions options);
+  [Throws] sequence<DOMString> getCSSValuesForProperty(DOMString property);
 };
 
 dictionary PropertyNamesOptions {
   boolean includeAliases = false;
 };
 
 dictionary InspectorRGBTriple {
   /*
--- a/layout/inspector/InspectorUtils.h
+++ b/layout/inspector/InspectorUtils.h
@@ -104,16 +104,22 @@ public:
                                   const nsAString& aPropertyName);
 
   // Get a list of all our supported property names.  Optionally
   // property aliases included.
   static void GetCSSPropertyNames(GlobalObject& aGlobal,
                                   const PropertyNamesOptions& aOptions,
                                   nsTArray<nsString>& aResult);
 
+  // Get a list of all valid keywords and colors for aProperty.
+  static void GetCSSValuesForProperty(GlobalObject& aGlobal,
+                                      const nsAString& aPropertyName,
+                                      nsTArray<nsString>& aResult,
+                                      ErrorResult& aRv);
+
 private:
   static already_AddRefed<nsStyleContext>
     GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);
 };
 
 } // namespace dom
 } // namespace mozilla
 
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -799,71 +799,69 @@ inDOMUtils::CssPropertySupportsType(cons
     // Unknown type
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   *_retval = PropertySupportsVariant(propertyID, variant);
   return NS_OK;
 }
 
-NS_IMETHODIMP
-inDOMUtils::GetCSSValuesForProperty(const nsAString& aProperty,
-                                    uint32_t* aLength,
-                                    char16_t*** aValues)
+namespace mozilla {
+namespace dom {
+
+/* static */ void
+InspectorUtils::GetCSSValuesForProperty(GlobalObject& aGlobalObject,
+                                        const nsAString& aProperty,
+                                        nsTArray<nsString>& aResult,
+                                        ErrorResult& aRv)
 {
   nsCSSPropertyID propertyID = nsCSSProps::
     LookupProperty(aProperty, CSSEnabledState::eForAllContent);
   if (propertyID == eCSSProperty_UNKNOWN) {
-    return NS_ERROR_FAILURE;
+    aRv.Throw(NS_ERROR_FAILURE);
+    return;
   }
 
-  nsTArray<nsString> array;
-  // We start collecting the values, BUT colors need to go in first, because array
+  // We start collecting the values, BUT colors need to go in first, because aResult
   // needs to stay sorted, and the colors are sorted, so we just append them.
   if (propertyID == eCSSPropertyExtra_variable) {
     // No other values we can report.
   } else if (!nsCSSProps::IsShorthand(propertyID)) {
     // Property is longhand.
     uint32_t propertyParserVariant = nsCSSProps::ParserVariant(propertyID);
     // Get colors first.
-    GetColorsForProperty(propertyParserVariant, array);
-    GetKeywordsForProperty(propertyID, array);
-    GetOtherValuesForProperty(propertyParserVariant, array);
+    GetColorsForProperty(propertyParserVariant, aResult);
+    GetKeywordsForProperty(propertyID, aResult);
+    GetOtherValuesForProperty(propertyParserVariant, aResult);
   } else {
     // Property is shorthand.
     CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID,
                                          CSSEnabledState::eForAllContent) {
       // Get colors (once) first.
       uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
       if (propertyParserVariant & VARIANT_COLOR) {
-        GetColorsForProperty(propertyParserVariant, array);
+        GetColorsForProperty(propertyParserVariant, aResult);
         break;
       }
     }
     CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID,
                                          CSSEnabledState::eForAllContent) {
       uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
-      GetKeywordsForProperty(*subproperty, array);
-      GetOtherValuesForProperty(propertyParserVariant, array);
+      GetKeywordsForProperty(*subproperty, aResult);
+      GetOtherValuesForProperty(propertyParserVariant, aResult);
     }
   }
   // All CSS properties take initial, inherit and unset.
-  InsertNoDuplicates(array, NS_LITERAL_STRING("initial"));
-  InsertNoDuplicates(array, NS_LITERAL_STRING("inherit"));
-  InsertNoDuplicates(array, NS_LITERAL_STRING("unset"));
+  InsertNoDuplicates(aResult, NS_LITERAL_STRING("initial"));
+  InsertNoDuplicates(aResult, NS_LITERAL_STRING("inherit"));
+  InsertNoDuplicates(aResult, NS_LITERAL_STRING("unset"));
+}
 
-  *aLength = array.Length();
-  char16_t** ret =
-    static_cast<char16_t**>(moz_xmalloc(*aLength * sizeof(char16_t*)));
-  for (uint32_t i = 0; i < *aLength; ++i) {
-    ret[i] = ToNewUnicode(array[i]);
-  }
-  *aValues = ret;
-  return NS_OK;
-}
+} // namespace dom
+} // namespace mozilla
 
 NS_IMETHODIMP
 inDOMUtils::ColorNameToRGB(const nsAString& aColorName, JSContext* aCx,
                            JS::MutableHandle<JS::Value> aValue)
 {
   nscolor color;
   if (!NS_ColorNameToRGB(aColorName, &color)) {
     return NS_ERROR_INVALID_ARG;
--- a/layout/inspector/inIDOMUtils.idl
+++ b/layout/inspector/inIDOMUtils.idl
@@ -15,21 +15,16 @@ interface nsIDOMNode;
 interface nsIDOMNodeList;
 interface nsIDOMFontFaceList;
 interface nsIDOMRange;
 interface nsIDOMCSSStyleSheet;
 
 [scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
 interface inIDOMUtils : nsISupports
 {
-  // Get a list of all valid keywords and colors for aProperty.
-  void getCSSValuesForProperty(in AString aProperty,
-                               [optional] out unsigned long aLength,
-                               [array, size_is(aLength), retval] out wstring aValues);
-
   // Utilities for working with CSS colors
   [implicit_jscontext]
   jsval colorNameToRGB(in DOMString aColorName);
   AString rgbToColorName(in octet aR, in octet aG, in octet aB);
 
   // Convert a given CSS color string to rgba. Returns null on failure or an
   // InspectorRGBATuple on success.
   //
--- a/layout/inspector/tests/test_bug877690.html
+++ b/layout/inspector/tests/test_bug877690.html
@@ -7,16 +7,18 @@ https://bugzilla.mozilla.org/show_bug.cg
 <meta charset="utf-8">
 <title>Test for Bug 877690</title>
 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 <script type="application/javascript">
 
 /** Test for Bug 877690 **/
 
+const InspectorUtils = SpecialPowers.InspectorUtils;
+
 // Returns true if values contains all and only the expected values. False otherwise.
 function testValues(values, expected) {
   values.sort();
   expected.sort();
 
   if (values.length !== expected.length) {
     return false;
   }
@@ -25,26 +27,19 @@ function testValues(values, expected) {
     if (values[i] !== expected[i]) {
       return false;
     }
   }
   return true;
 }
 
 function do_test() {
-  var utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
-    .getService(SpecialPowers.Ci.inIDOMUtils);
-
-  var getCSSValuesForProperty = function(prop) {
-    return Array.from(utils.getCSSValuesForProperty(prop));
-  }
-
   // test a property with keywords and colors
   var prop = "color";
-  var values = getCSSValuesForProperty(prop);
+  var values = InspectorUtils.getCSSValuesForProperty(prop);
   var expected = [ "initial", "inherit", "unset", "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure",
       "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood",
       "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "currentColor",
       "cyan", "darkblue", "darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkgrey",
       "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred",
       "darksalmon", "darkseagreen", "darkslateblue", "darkslategray", "darkslategrey",
       "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray", "dimgrey", "dodgerblue",
       "firebrick", "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold",
@@ -60,17 +55,17 @@ function do_test() {
       "purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen",
       "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", "slategrey", "snow", "springgreen",
       "steelblue", "tan", "teal", "thistle", "tomato", "transparent", "turquoise", "violet", "wheat",
       "white", "whitesmoke", "yellow", "yellowgreen", "rgb", "hsl", "rgba", "hsla" ];
   ok(testValues(values, expected), "property color's values.");
 
   // test a shorthand property
   var prop = "background";
-  var values = getCSSValuesForProperty(prop);
+  var values = InspectorUtils.getCSSValuesForProperty(prop);
   var expected = [ "initial", "inherit", "unset", "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure",
       "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue",
       "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "currentColor", "cyan", "darkblue",
       "darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkgrey", "darkkhaki", "darkmagenta",
       "darkolivegreen", "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", "darkslateblue",
       "darkslategray", "darkslategrey", "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray",
       "dimgrey", "dodgerblue", "firebrick", "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite",
       "gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew", "hotpink", "indianred",
@@ -89,17 +84,17 @@ function do_test() {
       "repeat-x", "repeat-y", "space", "round", "fixed", "scroll", "local", "center", "top", "bottom", "left", "right",
       "border-box", "padding-box", "content-box", "text", "contain",
       "cover", "rgb", "hsl", "rgba", "hsla", "none", "-moz-element", "-moz-image-rect", "url", "linear-gradient",
       "radial-gradient", "repeating-linear-gradient", "repeating-radial-gradient", "-moz-linear-gradient",
       "-moz-radial-gradient", "-moz-repeating-linear-gradient", "-moz-repeating-radial-gradient" ];
   ok(testValues(values, expected), "Shorthand property values.");
 
   var prop = "border";
-  var values = getCSSValuesForProperty(prop);
+  var values = InspectorUtils.getCSSValuesForProperty(prop);
   var expected = [ "initial", "unset", "aliceblue",
       "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet",
       "brown", "burlywood", "cadetblue", "calc", "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk",
       "crimson", "currentColor", "cyan", "darkblue", "darkcyan", "darkgoldenrod", "darkgray", "darkgreen", "darkgrey", "darkkhaki",
       "darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",
       "darkslateblue", "darkslategray", "darkslategrey", "darkturquoise", "darkviolet", "dashed", "deeppink",
       "deepskyblue", "dimgray", "dimgrey", "dodgerblue", "dotted", "double", "fill", "firebrick", "floralwhite",
       "forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold", "goldenrod", "gray", "grey", "green", "greenyellow",
@@ -118,17 +113,17 @@ function do_test() {
       "transparent", "turquoise", "-moz-element", "-moz-image-rect", "url", "violet", "wheat", "white", "whitesmoke",
       "yellow", "yellowgreen", "linear-gradient", "radial-gradient", "repeating-linear-gradient",
       "repeating-radial-gradient", "-moz-linear-gradient", "-moz-radial-gradient", "-moz-repeating-linear-gradient",
       "-moz-repeating-radial-gradient" ]
   ok(testValues(values, expected), "Shorthand property values.");
 
   // test keywords only
   var prop = "border-top";
-  var values = getCSSValuesForProperty(prop);
+  var values = InspectorUtils.getCSSValuesForProperty(prop);
   var expected = [ "initial", "inherit", "unset", "thin", "medium", "thick", "none", "hidden", "dotted",
       "dashed", "solid", "double", "groove", "ridge", "inset", "outset",
       "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black",
       "blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue", "chartreuse",
       "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "currentColor", "cyan", "darkblue", "darkcyan",
       "darkgoldenrod", "darkgray", "darkgreen", "darkgrey", "darkkhaki", "darkmagenta", "darkolivegreen",
       "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", "darkslateblue", "darkslategray",
       "darkslategrey", "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray", "dimgrey",
@@ -145,79 +140,79 @@ function do_test() {
       "purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen",
       "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", "slategrey", "snow", "springgreen",
       "steelblue", "tan", "teal", "thistle", "tomato", "transparent", "turquoise", "violet", "wheat", "white",
       "whitesmoke", "yellow", "yellowgreen", "calc", "rgb", "hsl", "rgba", "hsla" ];
   ok(testValues(values, expected), "property border-top's values.");
 
   // tests no keywords or colors
   var prop = "padding-bottom";
-  var values = getCSSValuesForProperty(prop);
+  var values = InspectorUtils.getCSSValuesForProperty(prop);
   var expected = [ "initial", "inherit", "unset", "calc" ];
   ok(testValues(values, expected), "property padding-bottom's values.");
 
   // test proprety
   var prop = "display";
-  var values = getCSSValuesForProperty(prop);
+  var values = InspectorUtils.getCSSValuesForProperty(prop);
   var expected = [ "initial", "inherit", "unset", "none", "inline", "block", "inline-block", "list-item",
       "table", "inline-table", "table-row-group", "table-header-group", "table-footer-group", "table-row",
       "table-column-group", "table-column", "table-cell", "table-caption", "-moz-box", "-moz-inline-box",
       "-moz-grid", "-moz-inline-grid", "-moz-grid-group", "-moz-grid-line", "-moz-stack", "-moz-inline-stack",
       "-moz-deck", "-moz-popup", "-moz-groupbox",
       "flex", "inline-flex", "-webkit-box", "-webkit-inline-box",
       "-webkit-flex", "-webkit-inline-flex",
       "grid", "inline-grid",
       "ruby", "ruby-base", "ruby-base-container", "ruby-text", "ruby-text-container",
       "contents", "flow-root" ];
   ok(testValues(values, expected), "property display's values.");
 
   // test property
   var prop = "float";
-  var values = getCSSValuesForProperty(prop);
+  var values = InspectorUtils.getCSSValuesForProperty(prop);
   var expected = [ "initial", "inherit", "unset", "none", "left", "right", "inline-start", "inline-end" ];
   ok(testValues(values, expected), "property float's values.");
 
   // Test property with "auto"
   var prop = "margin";
-  var values = getCSSValuesForProperty(prop);
+  var values = InspectorUtils.getCSSValuesForProperty(prop);
   var expected = [ "initial", "unset", "auto", "calc", "inherit" ];
   ok(testValues(values, expected), "property margin's values.");
 
   // Test property with "normal"
   var prop = "font-style";
-  var values = getCSSValuesForProperty(prop);
+  var values = InspectorUtils.getCSSValuesForProperty(prop);
   var expected = [ "initial", "inherit", "unset", "italic", "normal", "oblique" ];
   ok(testValues(values, expected), "property font-style's values.");
 
   // Test property with "cubic-bezier" and "step".
   var prop = "-moz-transition";
-  var values = getCSSValuesForProperty(prop);
+  var values = InspectorUtils.getCSSValuesForProperty(prop);
   var expected = [ "initial", "all", "unset", "cubic-bezier", "ease", "ease-in", "ease-in-out",
                    "ease-out", "inherit", "linear", "none", "step-end", "step-start",
                    "steps" ];
   ok(testValues(values, expected), "property -moz-transition's values.");
 
   // test invalid property
   var prop = "invalidProperty";
   try {
-    getCSSValuesForProperty(prop);
+    InspectorUtils.getCSSValuesForProperty(prop);
     ok(false, "invalid property should throw an exception");
   }
   catch(e) {
     // test passed
   }
 
   // test border-image property, for bug 973345
   var prop = "border-image";
-  var values = getCSSValuesForProperty(prop);
+  var values = InspectorUtils.getCSSValuesForProperty(prop);
   var expected = [ "inherit", "initial", "unset", "repeat", "stretch", "-moz-element", "-moz-image-rect", "url",             "linear-gradient", "radial-gradient", "repeating-linear-gradient", "repeating-radial-gradient", "-moz-linear-gradient", "-moz-radial-gradient", "-moz-repeating-linear-gradient", "-moz-repeating-radial-gradient", "fill", "none", "round", "space" ];
   ok(testValues(values, expected), "property border-image's values.");
 
   var prop = "background-size"
-  var values = getCSSValuesForProperty(prop);
+  var values = InspectorUtils.getCSSValuesForProperty(prop);
   var expected = [ "inherit", "initial", "unset", "contain", "cover" ];
   ok(testValues(values, expected), "property background-size's values.");
 
   SimpleTest.finish();
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(do_test);
--- a/layout/inspector/tests/test_is_valid_css_color.html
+++ b/layout/inspector/tests/test_is_valid_css_color.html
@@ -1,21 +1,22 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <meta charset="utf-8">
   <title>Test inDOMUtils::isValidCSSColor</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
+  const InspectorUtils = SpecialPowers.InspectorUtils;
   let utils = SpecialPowers.Cc["@mozilla.org/inspector/dom-utils;1"]
                            .getService(SpecialPowers.Ci.inIDOMUtils);
 
   // Color names
-  let colors = utils.getCSSValuesForProperty("color");
+  let colors = InspectorUtils.getCSSValuesForProperty("color");
   let notColor = ["hsl", "hsla", "inherit", "initial", "rgb", "rgba",
                   "unset", "transparent", "currentColor"];
   for (let color of colors) {
     if (notColor.indexOf(color) !== -1) {
       continue;
     }
     ok(utils.isValidCSSColor(color), color + " is a valid color");
     ok(!utils.isValidCSSColor("xxx" + color), "xxx" + color + " is not a valid color");