Bug 1049199 - Style editor should show XBL stylesheets. r=pbrosset

This commit is contained in:
Gijs Kruitbosch 2015-02-23 21:55:30 +00:00
parent 7d266e31e6
commit f3aabd0305
14 changed files with 84 additions and 33 deletions

View File

@ -447,13 +447,15 @@ StyleEditorUI.prototype = {
* Editor to create UI for.
*/
_sourceLoaded: function(editor) {
let ordinal = editor.styleSheet.styleSheetIndex;
ordinal = ordinal == -1 ? Number.MAX_SAFE_INTEGER : ordinal;
// add new sidebar item and editor to the UI
this._view.appendTemplatedItem(STYLE_EDITOR_TEMPLATE, {
data: {
editor: editor
},
disableAnimations: this._alwaysDisableAnimations,
ordinal: editor.styleSheet.styleSheetIndex,
ordinal: ordinal,
onCreate: function(summary, details, data) {
let editor = data.editor;
editor.summary = summary;

View File

@ -15,6 +15,7 @@ const require = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devt
const Editor = require("devtools/sourceeditor/editor");
const {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
const {CssLogic} = require("devtools/styleinspector/css-logic");
const {console} = require("resource://gre/modules/devtools/Console.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/FileUtils.jsm");
@ -251,11 +252,27 @@ StyleSheetEditor.prototype = {
callback(source);
}
return source;
}, e => {
if (this._isDestroyed) {
console.warn("Could not fetch the source for " +
this.styleSheet.href +
", the editor was destroyed");
Cu.reportError(e);
} else {
throw e;
}
});
}, e => {
this.emit("error", { key: LOAD_ERROR, append: this.styleSheet.href });
throw e;
})
if (this._isDestroyed) {
console.warn("Could not fetch the source for " +
this.styleSheet.href +
", the editor was destroyed");
Cu.reportError(e);
} else {
this.emit("error", { key: LOAD_ERROR, append: this.styleSheet.href });
throw e;
}
});
},
/**
@ -712,6 +729,7 @@ StyleSheetEditor.prototype = {
this.cssSheet.off("property-change", this._onPropertyChange);
this.cssSheet.off("media-rules-changed", this._onMediaRulesChanged);
this.styleSheet.off("error", this._onError);
this._isDestroyed = true;
}
}

View File

@ -9,7 +9,7 @@
//
thisTestLeaksUncaughtRejectionsAndShouldBeFixed("Error: Unknown sheet source");
const TESTCASE_URI = TEST_BASE + "autocomplete.html";
const TESTCASE_URI = TEST_BASE_HTTP + "autocomplete.html";
const MAX_SUGGESTIONS = 15;
// Pref which decides if CSS autocompletion is enabled in Style Editor or not.

View File

@ -8,7 +8,7 @@
//
thisTestLeaksUncaughtRejectionsAndShouldBeFixed("Error: Unknown sheet source");
const TESTCASE_URI = TEST_BASE + "four.html";
const TESTCASE_URI = TEST_BASE_HTTP + "four.html";
let gUI;

View File

@ -2,8 +2,8 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TESTCASE_URI_HTML = TEST_BASE + "simple.html";
const TESTCASE_URI_CSS = TEST_BASE + "simple.css";
const TESTCASE_URI_HTML = TEST_BASE_HTTP + "simple.html";
const TESTCASE_URI_CSS = TEST_BASE_HTTP + "simple.css";
const Cc = Components.classes;
const Ci = Components.interfaces;

View File

@ -9,7 +9,7 @@
//
thisTestLeaksUncaughtRejectionsAndShouldBeFixed("TypeError: summary is undefined");
const TESTCASE_URI = TEST_BASE + "simple.html";
const TESTCASE_URI = TEST_BASE_HTTP + "simple.html";
let gUI;

View File

@ -11,8 +11,8 @@ thisTestLeaksUncaughtRejectionsAndShouldBeFixed("Error: Unknown sheet source");
let gUI;
const FIRST_TEST_PAGE = TEST_BASE + "inline-1.html"
const SECOND_TEST_PAGE = TEST_BASE + "inline-2.html"
const FIRST_TEST_PAGE = TEST_BASE_HTTP + "inline-1.html"
const SECOND_TEST_PAGE = TEST_BASE_HTTP + "inline-2.html"
const SAVE_PATH = "test.css";
function test()

View File

@ -9,7 +9,7 @@
//
thisTestLeaksUncaughtRejectionsAndShouldBeFixed("Error: Unknown sheet source");
const TESTCASE_URI = TEST_BASE + "simple.html";
const TESTCASE_URI = TEST_BASE_HTTP + "simple.html";
let TESTCASE_CSS_SOURCE = "body{background-color:red;";

View File

@ -2,7 +2,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TESTCASE_URI = TEST_BASE + "nostyle.html";
const TESTCASE_URI = TEST_BASE_HTTP + "nostyle.html";
function test()

View File

@ -9,7 +9,7 @@
//
thisTestLeaksUncaughtRejectionsAndShouldBeFixed("Error: Unknown sheet source");
const TESTCASE_URI = TEST_BASE + "minified.html";
const TESTCASE_URI = TEST_BASE_HTTP + "minified.html";
let gUI;

View File

@ -6,11 +6,11 @@ Components.utils.import("resource://gre/modules/Task.jsm");
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
let {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
const TESTCASE_URI_HTML = TEST_BASE + "sourcemaps-watching.html";
const TESTCASE_URI_CSS = TEST_BASE + "sourcemap-css/sourcemaps.css";
const TESTCASE_URI_REG_CSS = TEST_BASE + "simple.css";
const TESTCASE_URI_SCSS = TEST_BASE + "sourcemap-sass/sourcemaps.scss";
const TESTCASE_URI_MAP = TEST_BASE + "sourcemap-css/sourcemaps.css.map";
const TESTCASE_URI_HTML = TEST_BASE_HTTP + "sourcemaps-watching.html";
const TESTCASE_URI_CSS = TEST_BASE_HTTP + "sourcemap-css/sourcemaps.css";
const TESTCASE_URI_REG_CSS = TEST_BASE_HTTP + "simple.css";
const TESTCASE_URI_SCSS = TEST_BASE_HTTP + "sourcemap-sass/sourcemaps.scss";
const TESTCASE_URI_MAP = TEST_BASE_HTTP + "sourcemap-css/sourcemaps.css.map";
const TESTCASE_SCSS_NAME = "sourcemaps.scss";
const TRANSITIONS_PREF = "devtools.styleeditor.transitions";

View File

@ -9,7 +9,7 @@
//
thisTestLeaksUncaughtRejectionsAndShouldBeFixed("Error: Unknown sheet source");
const TESTCASE_URI = TEST_BASE + "four.html";
const TESTCASE_URI = TEST_BASE_HTTP + "four.html";
let gUI;

View File

@ -2,7 +2,7 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const TESTCASE_URI = TEST_BASE + "simple.html";
const TESTCASE_URI = TEST_BASE_HTTP + "simple.html";
let gOriginalWidth; // these are set by runTests()
let gOriginalHeight;

View File

@ -104,11 +104,11 @@ let StyleSheetsActor = exports.StyleSheetsActor = protocol.ActorClass({
let actors = [];
for (let doc of documents) {
let sheets = yield this._addStyleSheets(doc.styleSheets);
let sheets = yield this._addStyleSheets(doc);
actors = actors.concat(sheets);
// Recursively handle style sheets of the documents in iframes.
for (let iframe of doc.getElementsByTagName("iframe")) {
for (let iframe of doc.querySelectorAll("iframe, browser, frame")) {
if (iframe.contentDocument) {
// Sometimes, iframes don't have any document, like the
// one that are over deeply nested (bug 285395)
@ -121,25 +121,54 @@ let StyleSheetsActor = exports.StyleSheetsActor = protocol.ActorClass({
},
/**
* Add all the stylesheets to the map and create an actor for each one
* if not already created.
* Check if we should be showing this stylesheet.
*
* @param {[DOMStyleSheet]} styleSheets
* Stylesheets to add
* @param {Document} doc
* Document for which we're checking
* @param {DOMCSSStyleSheet} sheet
* Stylesheet we're interested in
*
* @return boolean
* Whether the stylesheet should be listed.
*/
_shouldListSheet: function(doc, sheet) {
// Special case about:PreferenceStyleSheet, as it is generated on the
// fly and the URI is not registered with the about: handler.
// https://bugzilla.mozilla.org/show_bug.cgi?id=935803#c37
if (sheet.href && sheet.href.toLowerCase() == "about:preferencestylesheet") {
return false;
}
return true;
},
/**
* Add all the stylesheets for this document to the map and create an actor
* for each one if not already created.
*
* @param {Document} doc
* Document for which to add stylesheets
*
* @return {Promise}
* Promise that resolves to an array of StyleSheetActors
*/
_addStyleSheets: function(styleSheets)
_addStyleSheets: function(doc)
{
return Task.spawn(function*() {
let isChrome = Services.scriptSecurityManager.isSystemPrincipal(doc.nodePrincipal);
let styleSheets = isChrome ? DOMUtils.getAllStyleSheets(doc) : doc.styleSheets;
let actors = [];
for (let i = 0; i < styleSheets.length; i++) {
let actor = this.parentActor.createStyleSheetActor(styleSheets[i]);
let sheet = styleSheets[i];
if (!this._shouldListSheet(doc, sheet)) {
continue;
}
let actor = this.parentActor.createStyleSheetActor(sheet);
actors.push(actor);
// Get all sheets, including imported ones
let imports = yield this._getImported(actor);
let imports = yield this._getImported(doc, actor);
actors = actors.concat(imports);
}
return actors;
@ -149,12 +178,14 @@ let StyleSheetsActor = exports.StyleSheetsActor = protocol.ActorClass({
/**
* Get all the stylesheets @imported from a stylesheet.
*
* @param {Document} doc
* The document including the stylesheet
* @param {DOMStyleSheet} styleSheet
* Style sheet to search
* @return {Promise}
* A promise that resolves with an array of StyleSheetActors
*/
_getImported: function(styleSheet) {
_getImported: function(doc, styleSheet) {
return Task.spawn(function*() {
let rules = yield styleSheet.getCSSRules();
let imported = [];
@ -164,14 +195,14 @@ let StyleSheetsActor = exports.StyleSheetsActor = protocol.ActorClass({
if (rule.type == Ci.nsIDOMCSSRule.IMPORT_RULE) {
// Associated styleSheet may be null if it has already been seen due
// to duplicate @imports for the same URL.
if (!rule.styleSheet) {
if (!rule.styleSheet || !this._shouldListSheet(doc, rule.styleSheet)) {
continue;
}
let actor = this.parentActor.createStyleSheetActor(rule.styleSheet);
imported.push(actor);
// recurse imports in this stylesheet as well
let children = yield this._getImported(actor);
let children = yield this._getImported(doc, actor);
imported = imported.concat(children);
}
else if (rule.type != Ci.nsIDOMCSSRule.CHARSET_RULE) {