Bug 1278823 - styleeditor: fix csscoverage report creation;r=jryans

The sheetToUrl function in csscoverage is only used to create ids for the
csscoverage map of knownRules. Instead of asking the UI to format stylesheet
URLs using the same logic as the server, StyleEditor.jsm now sends the
stylesheet actor to create the report. The csscoverage actor can then compute
the stylesheet URL on the server.

MozReview-Commit-ID: GDtWhbi2ScW

--HG--
extra : rebase_source : bfc8dc7c680523ff8d67e8ffd5d1b1b7af862333
This commit is contained in:
Julian Descottes 2016-06-28 11:18:39 +02:00
parent 7e1c46f37f
commit 34e58925be
3 changed files with 24 additions and 11 deletions

View File

@ -616,19 +616,19 @@ StyleEditorUI.prototype = {
return;
}
let href = csscoverage.sheetToUrl(showEditor.styleSheet);
let reportData = yield usage.createEditorReport(href);
let sheet = showEditor.styleSheet;
let {reports} = yield usage.createEditorReportForSheet(sheet);
showEditor.removeAllUnusedRegions();
if (reportData.reports.length > 0) {
if (reports.length > 0) {
// Only apply if this file isn't compressed. We detect a
// compressed file if there are more rules than lines.
let editorText = showEditor.sourceEditor.getText();
let lineCount = editorText.split("\n").length;
let ruleCount = showEditor.styleSheet.ruleCount;
if (lineCount >= ruleCount) {
showEditor.addUnusedRegions(reportData.reports);
showEditor.addUnusedRegions(reports);
} else {
this.emit("error", { key: "error-compressed", level: "info" });
}

View File

@ -339,6 +339,18 @@ var CSSUsageActor = protocol.ActorClassWithSpec(cssUsageSpec, {
return { reports: reports };
},
/**
* Compute the stylesheet URL and delegate the report creation to createEditorReport.
* See createEditorReport documentation.
*
* @param {StyleSheetActor} stylesheetActor
* the stylesheet actor for which the coverage report should be generated.
*/
createEditorReportForSheet: function (stylesheetActor) {
let url = sheetToUrl(stylesheetActor.rawSheet);
return this.createEditorReport(url);
},
/**
* Returns a JSONable structure designed for the page report which shows
* the recommended changes to a page.
@ -694,9 +706,9 @@ exports.SEL_ALL = [
/**
* Find a URL for a given stylesheet
* @param stylesheet {StyleSheet|StyleSheetActor}
* @param {StyleSheet} stylesheet raw stylesheet
*/
const sheetToUrl = exports.sheetToUrl = function (stylesheet) {
const sheetToUrl = function (stylesheet) {
// For <link> elements
if (stylesheet.href) {
return stylesheet.href;
@ -710,10 +722,5 @@ const sheetToUrl = exports.sheetToUrl = function (stylesheet) {
return getURL(document) + " → <style> index " + index;
}
// When `stylesheet` is a StyleSheetActor, we don't have access to ownerNode
if (stylesheet.nodeHref) {
return stylesheet.nodeHref + " → <style> index " + stylesheet.styleSheetIndex;
}
throw new Error("Unknown sheet source");
};

View File

@ -5,6 +5,8 @@
const {Arg, RetVal, generateActorSpec} = require("devtools/shared/protocol");
require("devtools/shared/specs/stylesheets");
const cssUsageSpec = generateActorSpec({
typeName: "cssUsage",
@ -26,6 +28,10 @@ const cssUsageSpec = generateActorSpec({
request: { url: Arg(0, "string") },
response: { reports: RetVal("array:json") }
},
createEditorReportForSheet: {
request: { url: Arg(0, "stylesheet") },
response: { reports: RetVal("array:json") }
},
createPageReport: {
response: RetVal("json")
},