From aaf2af359e8eb9fa3641decc582d745e88a7de19 Mon Sep 17 00:00:00 2001 From: Sebastian Hengst Date: Wed, 5 Oct 2016 17:11:01 +0200 Subject: [PATCH] Backed out changeset 4fa21c0bcb63 (bug 1307009) --- devtools/server/actors/css-properties.js | 14 +++++++++++++- devtools/shared/fronts/css-properties.js | 15 ++++++++++++--- devtools/shared/specs/css-properties.js | 6 ++++-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/devtools/server/actors/css-properties.js b/devtools/server/actors/css-properties.js index d24c133d4206..276a7a4fafc1 100644 --- a/devtools/server/actors/css-properties.js +++ b/devtools/server/actors/css-properties.js @@ -10,6 +10,10 @@ loader.lazyGetter(this, "DOMUtils", () => { return Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils); }); +loader.lazyGetter(this, "appInfo", () => { + return Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo); +}); + const protocol = require("devtools/shared/protocol"); const { ActorClassWithSpec, Actor } = protocol; const { cssPropertiesSpec } = require("devtools/shared/specs/css-properties"); @@ -28,7 +32,15 @@ exports.CssPropertiesActor = ActorClassWithSpec(cssPropertiesSpec, { Actor.prototype.destroy.call(this); }, - getCSSDatabase() { + getCSSDatabase(clientBrowserVersion) { + // If the client and server are both the same version of Firefox, do not return a + // database, use the client-side css-properties-db.js. + const serverBrowserVersion = appInfo.platformVersion.match(/^\d+/)[0]; + + if (clientBrowserVersion !== 0 && clientBrowserVersion === serverBrowserVersion) { + return {}; + } + const properties = generateCssProperties(); const pseudoElements = DOMUtils.getCSSPseudoElementNames(); diff --git a/devtools/shared/fronts/css-properties.js b/devtools/shared/fronts/css-properties.js index f8e3fd44790a..996ad2897666 100644 --- a/devtools/shared/fronts/css-properties.js +++ b/devtools/shared/fronts/css-properties.js @@ -205,10 +205,9 @@ const initCssProperties = Task.async(function* (toolbox) { // Get the list dynamically if the cssProperties actor exists. if (toolbox.target.hasActor("cssProperties")) { front = CssPropertiesFront(client, toolbox.target.form); - const serverDB = yield front.getCSSDatabase(); + const serverDB = yield front.getCSSDatabase(getClientBrowserVersion(toolbox)); - // Ensure the database was returned in a format that is understood. - // Older versions of the protocol could return a blank database. + // The serverDB will be blank if the browser versions match, so use the static list. if (!serverDB.properties && !serverDB.margin) { db = CSS_PROPERTIES_DB; } else { @@ -250,6 +249,16 @@ function getClientCssProperties() { return new CssProperties(normalizeCssData(CSS_PROPERTIES_DB)); } +/** + * Get the current browser version. + * @returns {string} The browser version. + */ +function getClientBrowserVersion(toolbox) { + const regexResult = toolbox.win.navigator + .userAgent.match(/Firefox\/(\d+)\.\d/); + return Array.isArray(regexResult) ? regexResult[1] : "0"; +} + /** * Even if the target has the cssProperties actor, the returned data may not be in the * same shape or have all of the data we need. This normalizes the data and fills in diff --git a/devtools/shared/specs/css-properties.js b/devtools/shared/specs/css-properties.js index 76c85bd748bb..f265872aa4f9 100644 --- a/devtools/shared/specs/css-properties.js +++ b/devtools/shared/specs/css-properties.js @@ -3,14 +3,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; -const { RetVal, generateActorSpec } = require("devtools/shared/protocol"); +const { Arg, RetVal, generateActorSpec } = require("devtools/shared/protocol"); const cssPropertiesSpec = generateActorSpec({ typeName: "cssProperties", methods: { getCSSDatabase: { - request: {}, + request: { + clientBrowserVersion: Arg(0, "string"), + }, response: RetVal("json"), }