Bug 1187584 - Don't use the hidden window for creating value nodes in the rule view. r=mratcliffe
authorSimon Lindholm <simon.lindholm10@gmail.com>
Tue, 28 Jul 2015 09:36:00 -0400
changeset 286847 2c18a7c06a48eae0b381ca60d707429eab177b6d
parent 286846 d149368338aa3b80bb425653f0844da2d9a57fed
child 286848 da180640c3f6085352f03d75e7aa0e696e80e023
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmratcliffe
bugs1187584
milestone42.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 1187584 - Don't use the hidden window for creating value nodes in the rule view. r=mratcliffe
browser/devtools/shared/test/browser_outputparser.js
browser/devtools/styleinspector/computed-view.js
browser/devtools/styleinspector/rule-view.js
browser/devtools/styleinspector/test/browser_styleinspector_output-parser.js
toolkit/devtools/output-parser.js
--- a/browser/devtools/shared/test/browser_outputparser.js
+++ b/browser/devtools/shared/test/browser_outputparser.js
@@ -13,17 +13,17 @@ add_task(function*() {
   yield performTest();
   gBrowser.removeCurrentTab();
 });
 
 function* performTest() {
   let [host, , doc] = yield createHost("bottom", "data:text/html," +
     "<h1>browser_outputParser.js</h1><div></div>");
 
-  let parser = new OutputParser();
+  let parser = new OutputParser(doc);
   testParseCssProperty(doc, parser);
   testParseCssVar(doc, parser);
 
   host.destroy();
 }
 
 // Class name used in color swatch.
 let COLOR_TEST_CLASS = "test-class";
--- a/browser/devtools/styleinspector/computed-view.js
+++ b/browser/devtools/styleinspector/computed-view.js
@@ -132,17 +132,17 @@ UpdateProcess.prototype = {
 function CssComputedView(inspector, document, pageStyle) {
   this.inspector = inspector;
   this.styleDocument = document;
   this.styleWindow = this.styleDocument.defaultView;
   this.pageStyle = pageStyle;
 
   this.propertyViews = [];
 
-  this._outputParser = new OutputParser();
+  this._outputParser = new OutputParser(document);
 
   let chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
     .getService(Ci.nsIXULChromeRegistry);
   this.getRTLAttr = chromeReg.isLocaleRTL("global") ? "rtl" : "ltr";
 
   // Create bound methods.
   this.focusWindow = this.focusWindow.bind(this);
   this._onKeypress = this._onKeypress.bind(this);
--- a/browser/devtools/styleinspector/rule-view.js
+++ b/browser/devtools/styleinspector/rule-view.js
@@ -1156,17 +1156,17 @@ TextProperty.prototype = {
  */
 function CssRuleView(inspector, document, aStore, aPageStyle) {
   this.inspector = inspector;
   this.styleDocument = document;
   this.styleWindow = this.styleDocument.defaultView;
   this.store = aStore || {};
   this.pageStyle = aPageStyle;
 
-  this._outputParser = new OutputParser();
+  this._outputParser = new OutputParser(document);
 
   this._onKeypress = this._onKeypress.bind(this);
   this._onAddRule = this._onAddRule.bind(this);
   this._onContextMenu = this._onContextMenu.bind(this);
   this._onCopy = this._onCopy.bind(this);
   this._onFilterStyles = this._onFilterStyles.bind(this);
   this._onFilterKeyPress = this._onFilterKeyPress.bind(this);
   this._onClearSearch = this._onClearSearch.bind(this);
--- a/browser/devtools/styleinspector/test/browser_styleinspector_output-parser.js
+++ b/browser/devtools/styleinspector/test/browser_styleinspector_output-parser.js
@@ -305,17 +305,17 @@ function test() {
       name: "background",
       value: "rgb(255, var(--g-value, 0), 192)",
       test: fragment => {
 	is(fragment.textContent, "rgb(255, var(--g-value, 0), 192)");
       }
     }
   ];
 
-  let parser = new OutputParser();
+  let parser = new OutputParser(document);
   for (let i = 0; i < testData.length; i ++) {
     let data = testData[i];
     info("Output-parser test data " + i + ". {" + data.name + " : " + data.value + ";}");
     data.test(parser.parseCssProperty(data.name, data.value, {
       colorClass: COLOR_CLASS,
       urlClass: URL_CLASS,
       bezierClass: CUBIC_BEZIER_CLASS,
       defaultColorType: false
--- a/toolkit/devtools/output-parser.js
+++ b/toolkit/devtools/output-parser.js
@@ -39,22 +39,23 @@ loader.lazyGetter(this, "DOMUtils", func
  * adding doorhanger previews where possible (images, angles, lengths,
  * border radius, cubic-bezier etc.).
  *
  * Usage:
  *   const {devtools} =
  *      Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
  *   const {OutputParser} = devtools.require("devtools/output-parser");
  *
- *   let parser = new OutputParser();
+ *   let parser = new OutputParser(document);
  *
  *   parser.parseCssProperty("color", "red"); // Returns document fragment.
  */
-function OutputParser() {
+function OutputParser(document) {
   this.parsed = [];
+  this.doc = document;
   this.colorSwatches = new WeakMap();
   this._onSwatchMouseDown = this._onSwatchMouseDown.bind(this);
 }
 
 exports.OutputParser = OutputParser;
 
 OutputParser.prototype = {
   /**
@@ -437,32 +438,30 @@ OutputParser.prototype = {
    *
    * @param  {String} tagName
    *         Tag type e.g. "div"
    * @param  {Object} attributes
    *         e.g. {class: "someClass", style: "cursor:pointer"};
    * @param  {String} [value]
    *         If a value is included it will be appended as a text node inside
    *         the tag. This is useful e.g. for span tags.
-   * @return {Node} Newly created Node.
+   * @return {Node} Newly created Node.
    */
   _createNode: function(tagName, attributes, value="") {
-    let win = Services.appShell.hiddenDOMWindow;
-    let doc = win.document;
-    let node = doc.createElementNS(HTML_NS, tagName);
+    let node = this.doc.createElementNS(HTML_NS, tagName);
     let attrs = Object.getOwnPropertyNames(attributes);
 
     for (let attr of attrs) {
       if (attributes[attr]) {
         node.setAttribute(attr, attributes[attr]);
       }
     }
 
     if (value) {
-      let textNode = doc.createTextNode(value);
+      let textNode = this.doc.createTextNode(value);
       node.appendChild(textNode);
     }
 
     return node;
   },
 
   /**
    * Append a node to the output.
@@ -498,23 +497,21 @@ OutputParser.prototype = {
 
   /**
    * Take all output and append it into a single DocumentFragment.
    *
    * @return {DocumentFragment}
    *         Document Fragment
    */
   _toDOM: function() {
-    let win = Services.appShell.hiddenDOMWindow;
-    let doc = win.document;
-    let frag = doc.createDocumentFragment();
+    let frag = this.doc.createDocumentFragment();
 
     for (let item of this.parsed) {
       if (typeof item === "string") {
-        frag.appendChild(doc.createTextNode(item));
+        frag.appendChild(this.doc.createTextNode(item));
       } else {
         frag.appendChild(item);
       }
     }
 
     this.parsed.length = 0;
     return frag;
   },