зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1651774: Update mozilla/use-services rule for native Services implementation. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D93858
This commit is contained in:
Родитель
cdc37b8d23
Коммит
7ae9faa46f
|
@ -24,9 +24,7 @@
|
|||
|
||||
var winLowerThanVista = navigator.platform.indexOf("Win") == 0;
|
||||
if (winLowerThanVista) {
|
||||
var version = Cc["@mozilla.org/system-info;1"]
|
||||
.getService(Ci.nsIPropertyBag2)
|
||||
.getProperty("version");
|
||||
var version = Services.sysinfo.getProperty("version");
|
||||
version = parseFloat(version);
|
||||
winLowerThanVista = !(version >= 6.0);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
function test() {
|
||||
var isWin7OrHigher = false;
|
||||
try {
|
||||
let version = Cc["@mozilla.org/system-info;1"]
|
||||
.getService(Ci.nsIPropertyBag2)
|
||||
.getProperty("version");
|
||||
let version = Services.sysinfo.getProperty("version");
|
||||
isWin7OrHigher = parseFloat(version) >= 6.1;
|
||||
} catch (ex) {}
|
||||
|
||||
|
|
|
@ -56,10 +56,6 @@ XPCOMUtils.defineLazyGetter(this, "converter", () => {
|
|||
return conv;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "sysInfo", () => {
|
||||
return Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
|
||||
});
|
||||
|
||||
var logging = Services.prefs.getBoolPref("devtools.discovery.log");
|
||||
function log(msg) {
|
||||
if (logging) {
|
||||
|
@ -162,7 +158,7 @@ LocalDevice.prototype = {
|
|||
if (Services.appinfo.widgetToolkit == "android") {
|
||||
// For Firefox for Android, use the device's model name.
|
||||
// TODO: Bug 1180997: Find the right way to expose an editable name
|
||||
this.name = sysInfo.get("device");
|
||||
this.name = Services.sysinfo.get("device");
|
||||
} else {
|
||||
this.name = Cc["@mozilla.org/network/dns-service;1"].getService(
|
||||
Ci.nsIDNSService
|
||||
|
|
|
@ -882,9 +882,7 @@ if (
|
|||
manifestNavigator().userAgent.includes("Mobile") ||
|
||||
manifestNavigator().userAgent.includes("Tablet")
|
||||
) {
|
||||
androidVersion = SpecialPowers.Cc["@mozilla.org/system-info;1"]
|
||||
.getService(SpecialPowers.Ci.nsIPropertyBag2)
|
||||
.getProperty("version");
|
||||
androidVersion = SpecialPowers.Services.sysinfo.getProperty("version");
|
||||
}
|
||||
|
||||
function getAndroidVersion() {
|
||||
|
|
|
@ -14,8 +14,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1274663
|
|||
<script>
|
||||
var importObj = {};
|
||||
|
||||
var sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
|
||||
|
||||
var windows = SpecialPowers.Services.ww.getWindowEnumerator();
|
||||
var windowutils;
|
||||
while (windows.hasMoreElements()) {
|
||||
|
|
|
@ -28,7 +28,7 @@ function runTest() {
|
|||
var Cc = SpecialPowers.Cc;
|
||||
var Ci = SpecialPowers.Ci;
|
||||
|
||||
var sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
|
||||
var sysInfo = SpecialPowers.Services.sysinfo;
|
||||
var xr = SpecialPowers.Services.appinfo;
|
||||
|
||||
var windows = SpecialPowers.Services.ww.getWindowEnumerator();
|
||||
|
|
|
@ -2141,9 +2141,7 @@ function getAndroidSdk() {
|
|||
var versionString = nav.userAgent.includes("Android")
|
||||
? "version"
|
||||
: "sdk_version";
|
||||
gAndroidSdk = SpecialPowers.Cc["@mozilla.org/system-info;1"]
|
||||
.getService(SpecialPowers.Ci.nsIPropertyBag2)
|
||||
.getProperty(versionString);
|
||||
gAndroidSdk = SpecialPowers.Services.sysinfo.getProperty(versionString);
|
||||
}
|
||||
document.documentElement.removeChild(iframe);
|
||||
}
|
||||
|
|
|
@ -27,9 +27,7 @@
|
|||
file.append("test_sqliteMultiReporter-fake-DB-tmp.sqlite");
|
||||
|
||||
// Open and close the DB.
|
||||
let storage = Cc["@mozilla.org/storage/service;1"].
|
||||
getService(Ci.mozIStorageService);
|
||||
let db = storage.openDatabase(file);
|
||||
let db = SpecialPowers.Services.storage.openDatabase(file);
|
||||
db.close();
|
||||
|
||||
// Invoke all the reporters. The SQLite multi-reporter is among
|
||||
|
|
|
@ -48,13 +48,11 @@ function nsURLFormatterService() {
|
|||
|
||||
XPCOMUtils.defineLazyGetter(this, "OSVersion", function UFS_OSVersion() {
|
||||
let OSVersion = "default";
|
||||
let sysInfo = Cc["@mozilla.org/system-info;1"].getService(
|
||||
Ci.nsIPropertyBag2
|
||||
);
|
||||
let { sysinfo } = Services;
|
||||
try {
|
||||
OSVersion =
|
||||
sysInfo.getProperty("name") + " " + sysInfo.getProperty("version");
|
||||
OSVersion += " (" + sysInfo.getProperty("secondaryLibrary") + ")";
|
||||
sysinfo.getProperty("name") + " " + sysinfo.getProperty("version");
|
||||
OSVersion += ` (${sysinfo.getProperty("secondaryLibrary")})`;
|
||||
} catch (e) {}
|
||||
|
||||
return encodeURIComponent(OSVersion);
|
||||
|
|
|
@ -21,20 +21,18 @@
|
|||
<script type="application/javascript"><![CDATA[
|
||||
const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
||||
const {BrowserTestUtils} = ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
|
||||
|
||||
var gPrefsvc = SpecialPowers.Services.prefs.nsIPrefBranch;
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const SAMPLE_URL = "http://www.mozilla.org/";
|
||||
const SAMPLE_TEXT = "Some text in a text field.";
|
||||
const SEARCH_TEXT = "Text Test (δοκιμή)";
|
||||
const NOT_FOUND_TEXT = "This text is not on the page."
|
||||
const ITERATOR_TIMEOUT = gPrefsvc.getIntPref("findbar.iteratorTimeout");
|
||||
const ITERATOR_TIMEOUT = Services.prefs.getIntPref("findbar.iteratorTimeout");
|
||||
|
||||
var gFindBar = null;
|
||||
var gBrowser;
|
||||
|
||||
var gClipboard = Cc["@mozilla.org/widget/clipboard;1"].getService(Ci.nsIClipboard);
|
||||
var gHasFindClipboard = gClipboard.supportsFindClipboard();
|
||||
var gHasFindClipboard = Services.clipboard.supportsFindClipboard();
|
||||
|
||||
var gStatusText;
|
||||
var gXULBrowserWindow = {
|
||||
|
@ -662,7 +660,7 @@
|
|||
gFindBar.clear();
|
||||
|
||||
// Case-insensitive should already be the current value.
|
||||
gPrefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 0);
|
||||
Services.prefs.setIntPref("accessibility.typeaheadfind.casesensitive", 0);
|
||||
|
||||
await enterStringIntoFindField("t");
|
||||
await SpecialPowers.spawn(gBrowser, [], async function() {
|
||||
|
@ -679,7 +677,7 @@
|
|||
// 1. Do a search that fails with case sensitivity but matches with no case sensitivity.
|
||||
// 2. Uncheck case sensitivity button to match the string.
|
||||
async function testFailedStringReset() {
|
||||
gPrefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", 1);
|
||||
Services.prefs.setIntPref("accessibility.typeaheadfind.casesensitive", 1);
|
||||
|
||||
let promise = promiseFindResult(gBrowser.hasAttribute("remote") ? SEARCH_TEXT.toUpperCase() : "");
|
||||
await enterStringIntoFindField(SEARCH_TEXT.toUpperCase(), false);
|
||||
|
@ -765,7 +763,7 @@
|
|||
|
||||
function changeCase(value) {
|
||||
let promise = gBrowser.hasAttribute("remote") ? promiseFindResult() : Promise.resolve();
|
||||
gPrefsvc.setIntPref("accessibility.typeaheadfind.casesensitive", value);
|
||||
Services.prefs.setIntPref("accessibility.typeaheadfind.casesensitive", value);
|
||||
return promise;
|
||||
}
|
||||
]]></script>
|
||||
|
|
|
@ -11,12 +11,14 @@
|
|||
|
||||
<script>
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var gBlockShowing = true;
|
||||
var gBlockHiding = true;
|
||||
var gShownNotAllowed = true;
|
||||
var gHiddenNotAllowed = true;
|
||||
|
||||
var fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
|
||||
var fm = Services.focus;
|
||||
|
||||
var is = function(l, r, v) { window.arguments[0].SimpleTest.is(l, r, v); }
|
||||
var isnot = function(l, r, v) { window.arguments[0].SimpleTest.isnot(l, r, v); }
|
||||
|
|
|
@ -322,10 +322,6 @@ var dataProviders = {
|
|||
securitySoftware: function securitySoftware(done) {
|
||||
let data = {};
|
||||
|
||||
let sysInfo = Cc["@mozilla.org/system-info;1"].getService(
|
||||
Ci.nsIPropertyBag2
|
||||
);
|
||||
|
||||
const keys = [
|
||||
"registeredAntiVirus",
|
||||
"registeredAntiSpyware",
|
||||
|
@ -334,7 +330,7 @@ var dataProviders = {
|
|||
for (let key of keys) {
|
||||
let prop = "";
|
||||
try {
|
||||
prop = sysInfo.getProperty(key);
|
||||
prop = Services.sysinfo.getProperty(key);
|
||||
} catch (e) {}
|
||||
|
||||
data[key] = prop;
|
||||
|
|
|
@ -78,6 +78,10 @@ module.exports = {
|
|||
return gModules;
|
||||
},
|
||||
|
||||
get servicesData() {
|
||||
return require("./services.json");
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the abstract syntax tree (AST) of the JavaScript source code contained
|
||||
* in sourceText. This matches the results for an eslint parser, see
|
||||
|
@ -841,6 +845,16 @@ module.exports = {
|
|||
return require("./rules/saved-rules-data.json").rulesData[rule];
|
||||
},
|
||||
|
||||
getBuildEnvironment() {
|
||||
var { execFileSync } = require("child_process");
|
||||
var output = execFileSync(
|
||||
path.join(this.rootDir, "mach"),
|
||||
["environment", "--format=json"],
|
||||
{ silent: true }
|
||||
);
|
||||
return JSON.parse(output);
|
||||
},
|
||||
|
||||
/**
|
||||
* Extract the path of require (and require-like) helpers used in DevTools.
|
||||
*/
|
||||
|
|
|
@ -8,133 +8,8 @@
|
|||
|
||||
"use strict";
|
||||
const helpers = require("../helpers");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
/**
|
||||
* An object that is used to help parse the AST of Services.jsm to extract
|
||||
* the services that it caches.
|
||||
*
|
||||
* It is specifically built around the current structure of the Services.jsm
|
||||
* file.
|
||||
*/
|
||||
var servicesASTParser = {
|
||||
identifiers: {},
|
||||
// These interfaces are difficult/not possible to get via processing.
|
||||
result: {
|
||||
nsIPrefBranch: "prefs",
|
||||
nsIPrefService: "prefs",
|
||||
nsIXULRuntime: "appinfo",
|
||||
nsIXULAppInfo: "appinfo",
|
||||
nsIDirectoryService: "dirsvc",
|
||||
nsIProperties: "dirsvc",
|
||||
nsIIOService: "io",
|
||||
nsISpeculativeConnect: "io",
|
||||
nsICookieManager: "cookies",
|
||||
nsIBlocklistService: "blocklist",
|
||||
},
|
||||
|
||||
/**
|
||||
* This looks for any global variable declarations that are being initialised
|
||||
* with objects, and records the assumed interface definitions.
|
||||
*/
|
||||
VariableDeclaration(node, parents) {
|
||||
if (
|
||||
node.declarations.length === 1 &&
|
||||
node.declarations[0].id &&
|
||||
helpers.getIsGlobalScope(parents) &&
|
||||
node.declarations[0].init.type === "ObjectExpression"
|
||||
) {
|
||||
let name = node.declarations[0].id.name;
|
||||
let interfaces = {};
|
||||
|
||||
for (let property of node.declarations[0].init.properties) {
|
||||
if (property.value.elements.length > 1) {
|
||||
interfaces[property.key.name] = property.value.elements[1].value;
|
||||
}
|
||||
}
|
||||
|
||||
this.identifiers[name] = interfaces;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* This looks for any additions to the global variable declarations, and adds
|
||||
* them to the identifier tables created by the VariableDeclaration calls.
|
||||
*/
|
||||
AssignmentExpression(node, parents) {
|
||||
if (
|
||||
node.left.type === "MemberExpression" &&
|
||||
node.right.type === "ArrayExpression" &&
|
||||
helpers.getIsGlobalScope(parents)
|
||||
) {
|
||||
let variableName = node.left.object.name;
|
||||
if (variableName in this.identifiers) {
|
||||
let servicesPropName = node.left.property.name;
|
||||
this.identifiers[variableName][servicesPropName] =
|
||||
node.right.elements[1].value;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* This looks for any XPCOMUtils.defineLazyServiceGetters calls, and looks
|
||||
* into the arguments they are called with to work out the interfaces that
|
||||
* Services.jsm is caching.
|
||||
*/
|
||||
CallExpression(node) {
|
||||
if (
|
||||
node.callee.object &&
|
||||
node.callee.object.name === "XPCOMUtils" &&
|
||||
node.callee.property &&
|
||||
node.callee.property.name === "defineLazyServiceGetters" &&
|
||||
node.arguments.length >= 2
|
||||
) {
|
||||
// The second argument has the getters name.
|
||||
let gettersVarName = node.arguments[1].name;
|
||||
if (!(gettersVarName in this.identifiers)) {
|
||||
throw new Error(`Could not find definition for ${gettersVarName}`);
|
||||
}
|
||||
|
||||
for (let name of Object.keys(this.identifiers[gettersVarName])) {
|
||||
this.result[this.identifiers[gettersVarName][name]] = name;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function getInterfacesFromServicesFile() {
|
||||
let filePath = path.join(
|
||||
helpers.rootDir,
|
||||
"toolkit",
|
||||
"modules",
|
||||
"Services.jsm"
|
||||
);
|
||||
|
||||
let content = fs.readFileSync(filePath, "utf8");
|
||||
|
||||
// Parse the content into an AST
|
||||
let { ast, visitorKeys } = helpers.parseCode(content);
|
||||
|
||||
helpers.walkAST(ast, visitorKeys, (type, node, parents) => {
|
||||
if (type in servicesASTParser) {
|
||||
servicesASTParser[type](node, parents);
|
||||
}
|
||||
});
|
||||
|
||||
// nsISupports is used for multiple services, so we can't really warn for it.
|
||||
delete servicesASTParser.result.nsISupports;
|
||||
|
||||
// nsIPropertyBag2 is used for system-info, but it is also used for other
|
||||
// services and items as well, so we can't really warn for it.
|
||||
delete servicesASTParser.result.nsIPropertyBag2;
|
||||
|
||||
return servicesASTParser.result;
|
||||
}
|
||||
|
||||
let getServicesInterfaceMap = helpers.isMozillaCentralBased()
|
||||
? getInterfacesFromServicesFile()
|
||||
: helpers.getSavedRuleData("use-services.js");
|
||||
let servicesInterfaceMap = helpers.servicesData;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
|
@ -144,14 +19,6 @@ module.exports = function(context) {
|
|||
// Public
|
||||
// --------------------------------------------------------------------------
|
||||
return {
|
||||
// ESLint assumes that items returned here are going to be a listener
|
||||
// for part of the rule. We want to export the servicesInterfaceArray for
|
||||
// the purposes of createExports, so we return it via a function which
|
||||
// makes everything happy.
|
||||
getServicesInterfaceMap() {
|
||||
return getServicesInterfaceMap;
|
||||
},
|
||||
|
||||
CallExpression(node) {
|
||||
if (
|
||||
!node.callee ||
|
||||
|
@ -162,13 +29,12 @@ module.exports = function(context) {
|
|||
!node.arguments[0].property ||
|
||||
node.arguments[0].property.type != "Identifier" ||
|
||||
!node.arguments[0].property.name ||
|
||||
!(node.arguments[0].property.name in getServicesInterfaceMap)
|
||||
!(node.arguments[0].property.name in servicesInterfaceMap)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
let serviceName =
|
||||
getServicesInterfaceMap[node.arguments[0].property.name];
|
||||
let serviceName = servicesInterfaceMap[node.arguments[0].property.name];
|
||||
|
||||
context.report(
|
||||
node,
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
{
|
||||
"mozIJSSubScriptLoader": "scriptloader",
|
||||
"mozILocaleService": "locale",
|
||||
"mozIMozIntl": "intl",
|
||||
"mozIStorageService": "storage",
|
||||
"nsIAppShellService": "appShell",
|
||||
"nsIAppStartup": "startup",
|
||||
"nsICacheStorageService": "cache2",
|
||||
"nsICategoryManager": "catMan",
|
||||
"nsIClearDataService": "clearData",
|
||||
"nsIClipboard": "clipboard",
|
||||
"nsIConsoleService": "console",
|
||||
"nsICookieManager": "cookies",
|
||||
"nsIDOMRequestService": "DOMRequest",
|
||||
"nsIDOMStorageManager": "domStorageManager",
|
||||
"nsIDirectoryService": "dirsvc",
|
||||
"nsIDroppedLinkHandler": "droppedLinkHandler",
|
||||
"nsIEffectiveTLDService": "eTLD",
|
||||
"nsIEnterprisePolicies": "policies",
|
||||
"nsIEventListenerService": "els",
|
||||
"nsIFocusManager": "focus",
|
||||
"nsIIOService": "io",
|
||||
"nsILoadContextInfoFactory": "loadContextInfo",
|
||||
"nsILocalStorageManager": "domStorageManager",
|
||||
"nsILoginManager": "logins",
|
||||
"nsINetUtil": "io",
|
||||
"nsIObserverService": "obs",
|
||||
"nsIPermissionManager": "perms",
|
||||
"nsIPrefBranch": "prefs",
|
||||
"nsIPrefService": "prefs",
|
||||
"nsIProfiler": "profiler",
|
||||
"nsIPromptService": "prompt",
|
||||
"nsIProperties": "dirsvc",
|
||||
"nsIPropertyBag2": "sysinfo",
|
||||
"nsIQuotaManagerService": "qms",
|
||||
"nsIScriptSecurityManager": "scriptSecurityManager",
|
||||
"nsISearchService": "search",
|
||||
"nsISpeculativeConnect": "io",
|
||||
"nsIStringBundleService": "strings",
|
||||
"nsISystemInfo": "sysinfo",
|
||||
"nsITelemetry": "telemetry",
|
||||
"nsITextToSubURI": "textToSubURI",
|
||||
"nsIThreadManager": "tm",
|
||||
"nsIURLFormatter": "urlFormatter",
|
||||
"nsIVersionComparator": "vc",
|
||||
"nsIWindowMediator": "wm",
|
||||
"nsIWindowWatcher": "ww",
|
||||
"nsIXULAppInfo": "appinfo",
|
||||
"nsIXULRuntime": "appinfo"
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "eslint-plugin-mozilla",
|
||||
"version": "2.9.0",
|
||||
"version": "2.9.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "eslint-plugin-mozilla",
|
||||
"version": "2.9.0",
|
||||
"version": "2.9.1",
|
||||
"description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.",
|
||||
"keywords": [
|
||||
"eslint",
|
||||
|
|
|
@ -39,6 +39,25 @@ const shipModulesFile = path.join(
|
|||
|
||||
fs.writeFileSync(shipModulesFile, fs.readFileSync(modulesFile));
|
||||
|
||||
console.log("Copying services.json");
|
||||
|
||||
const env = helpers.getBuildEnvironment();
|
||||
|
||||
const servicesFile = path.join(
|
||||
env.topobjdir,
|
||||
"xpcom",
|
||||
"components",
|
||||
"services.json"
|
||||
);
|
||||
const shipServicesFile = path.join(
|
||||
eslintDir,
|
||||
"eslint-plugin-mozilla",
|
||||
"lib",
|
||||
"services.json"
|
||||
);
|
||||
|
||||
fs.writeFileSync(shipServicesFile, fs.readFileSync(servicesFile));
|
||||
|
||||
console.log("Generating globals file");
|
||||
|
||||
// Export the environments.
|
||||
|
@ -56,10 +75,7 @@ return fs.writeFile(
|
|||
console.log("Globals file generation complete");
|
||||
|
||||
console.log("Creating rules data file");
|
||||
// Also export data for the use-services.js rule
|
||||
let rulesData = {
|
||||
"use-services.js": require("../lib/rules/use-services.js")().getServicesInterfaceMap(),
|
||||
};
|
||||
let rulesData = {};
|
||||
|
||||
return fs.writeFile(rulesFile, JSON.stringify({ rulesData }), err1 => {
|
||||
if (err1) {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
var rule = require("../lib/rules/use-services");
|
||||
var RuleTester = require("eslint").RuleTester;
|
||||
|
||||
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Tests
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
function invalidCode(code, name) {
|
||||
let message = `Use Services.${name} rather than getService().`;
|
||||
return { code, errors: [{ message, type: "CallExpression" }] };
|
||||
}
|
||||
|
||||
ruleTester.run("use-services", rule, {
|
||||
valid: [
|
||||
'Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator)',
|
||||
'Components.classes["@mozilla.org/uuid-generator;1"].getService(Components.interfaces.nsIUUIDGenerator)',
|
||||
"Services.wm.addListener()",
|
||||
],
|
||||
invalid: [
|
||||
invalidCode(
|
||||
'Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);',
|
||||
"wm"
|
||||
),
|
||||
invalidCode(
|
||||
'Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(Components.interfaces.nsIAppStartup);',
|
||||
"startup"
|
||||
),
|
||||
],
|
||||
});
|
|
@ -11,15 +11,13 @@
|
|||
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
let taskbar = Cc["@mozilla.org/windows-taskbar;1"].getService(Ci.nsIWinTaskbar);
|
||||
|
||||
function IsWin7OrHigher() {
|
||||
try {
|
||||
var sysInfo = Cc["@mozilla.org/system-info;1"].
|
||||
getService(Ci.nsIPropertyBag2);
|
||||
var ver = parseFloat(sysInfo.getProperty("version"));
|
||||
var ver = parseFloat(Services.sysinfo.getProperty("version"));
|
||||
if (ver >= 6.1)
|
||||
return true;
|
||||
} catch (ex) { }
|
||||
|
@ -49,8 +47,7 @@
|
|||
get wrappedJSObject() { return this; }
|
||||
}
|
||||
// HACK from mconnor:
|
||||
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
||||
let win = wm.getMostRecentWindow("navigator:browser");
|
||||
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
let docShell = win.gBrowser.docShell;
|
||||
|
||||
let winPreview = taskbar.getTaskbarWindowPreview(docShell);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
<script type="application/javascript"><![CDATA[
|
||||
const {BrowserTestUtils} = ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
|
@ -40,9 +41,7 @@
|
|||
}
|
||||
|
||||
function setGlobals() {
|
||||
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
||||
getService(Ci.nsIWindowMediator);
|
||||
let chromeWindow = wm.getMostRecentWindow("navigator:browser");
|
||||
let chromeWindow = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
// For some reason, a global <key> element's oncommand handler only gets
|
||||
// invoked if the focus is outside both of the <browser> elements
|
||||
// (tab1browser and tab2browser). So, to make sure we can see a
|
||||
|
|
|
@ -24,9 +24,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=429954
|
|||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
SimpleTest.waitForFocus(function () {
|
||||
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
||||
getService(Ci.nsIWindowMediator);
|
||||
var win = wm.getMostRecentWindow("navigator:browser");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var win = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
win.maximize();
|
||||
var maxX = win.screenX, maxY = win.screenY;
|
||||
var maxWidth = win.outerWidth, maxHeight = win.outerHeight;
|
||||
|
|
|
@ -31,9 +31,8 @@ SimpleTest.waitForFocus(function () {
|
|||
return;
|
||||
}
|
||||
|
||||
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
|
||||
getService(Ci.nsIWindowMediator);
|
||||
var win = wm.getMostRecentWindow("navigator:browser");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
var win = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
var oldWidth = win.outerWidth, oldHeight = win.outerHeight;
|
||||
win.maximize();
|
||||
var newWidth = win.outerWidth, newHeight = win.outerHeight;
|
||||
|
|
|
@ -17,8 +17,7 @@ function getLoadContext() {
|
|||
return window.docShell.QueryInterface(Ci.nsILoadContext);
|
||||
}
|
||||
|
||||
var clipboard = Cc["@mozilla.org/widget/clipboard;1"]
|
||||
.getService(Ci.nsIClipboard);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var transferable = Cc['@mozilla.org/widget/transferable;1']
|
||||
.createInstance(Ci.nsITransferable);
|
||||
|
@ -27,7 +26,7 @@ transferable.init(getLoadContext());
|
|||
transferable.addDataFlavor("text/unicode");
|
||||
transferable.setTransferData("text/unicode", document, 4);
|
||||
|
||||
clipboard.setData(transferable, null, Ci.nsIClipboard.kGlobalClipboard);
|
||||
Services.clipboard.setData(transferable, null, Ci.nsIClipboard.kGlobalClipboard);
|
||||
|
||||
transferable.setTransferData("text/unicode", null, 0);
|
||||
|
||||
|
|
|
@ -52,8 +52,9 @@ var nativeHandle = baseWindow.nativeHandle;
|
|||
// eslint-disable-next-line no-unsanitized/property
|
||||
$("display").innerHTML = "found nativeHandle for this window: "+nativeHandle;
|
||||
|
||||
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
||||
var win = wm.getMostRecentWindow("navigator:browser");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var win = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
let docShell = getBaseWindowInterfaceFromDocShell(win);
|
||||
|
||||
ok(
|
||||
|
|
|
@ -51,20 +51,19 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=948065
|
|||
}
|
||||
|
||||
function initAndRunTests() {
|
||||
let clipboard = Cc['@mozilla.org/widget/clipboard;1']
|
||||
.getService(Ci.nsIClipboard);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Test copy.
|
||||
const data = "random number: " + Math.random();
|
||||
let helper = Cc['@mozilla.org/widget/clipboardhelper;1']
|
||||
.getService(Ci.nsIClipboardHelper);
|
||||
helper.copyString(data);
|
||||
is(paste(clipboard), data, 'Data was successfully copied.');
|
||||
is(paste(Services.clipboard), data, 'Data was successfully copied.');
|
||||
|
||||
// Test emptyClipboard, disabled for OSX because bug 666254
|
||||
if (!kIsMac) {
|
||||
clipboard.emptyClipboard(Ci.nsIClipboard.kGlobalClipboard);
|
||||
is(paste(clipboard), '', 'Data was successfully cleared.');
|
||||
Services.clipboard.emptyClipboard(Ci.nsIClipboard.kGlobalClipboard);
|
||||
is(paste(Services.clipboard), '', 'Data was successfully cleared.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
SimpleTest.waitForExplicitFinish();
|
||||
SimpleTest.waitForFocus(runTests, window);
|
||||
|
||||
var fm = Cc["@mozilla.org/focus-manager;1"].
|
||||
getService(Ci.nsIFocusManager);
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var textarea = document.getElementById("textarea");
|
||||
var otherWindow;
|
||||
var timer;
|
||||
|
@ -33,8 +33,8 @@ var timer;
|
|||
function runTests()
|
||||
{
|
||||
textarea.focus();
|
||||
is(fm.focusedElement, textarea, "we're deactive");
|
||||
if (fm.focusedElement != textarea) {
|
||||
is(Services.focus.focusedElement, textarea, "we're deactive");
|
||||
if (Services.focus.focusedElement != textarea) {
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ function runTests()
|
|||
function startTests()
|
||||
{
|
||||
clearTimeout(timer);
|
||||
isnot(fm.focusedWindow, window, "we're not deactive");
|
||||
if (fm.focusedWindow == window) {
|
||||
isnot(Services.focus.focusedWindow, window, "we're not deactive");
|
||||
if (Services.focus.focusedWindow == window) {
|
||||
otherWindow.close();
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
|
|
|
@ -46,13 +46,12 @@
|
|||
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const IS_MAC = navigator.platform.indexOf("Mac") == 0;
|
||||
const IS_WIN = navigator.platform.indexOf("Win") == 0;
|
||||
const OS_VERSION =
|
||||
IS_WIN ? parseFloat(Cc["@mozilla.org/system-info;1"]
|
||||
.getService(Ci.nsIPropertyBag2)
|
||||
.getProperty("version")) : 0;
|
||||
IS_WIN ? parseFloat(Services.sysinfo.getProperty("version")) : 0;
|
||||
const WIN7 = 6.1;
|
||||
const WIN8 = 6.2;
|
||||
|
||||
|
|
|
@ -9,15 +9,13 @@
|
|||
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
let TP = Ci.nsITaskbarProgress;
|
||||
|
||||
function IsWin7OrHigher() {
|
||||
try {
|
||||
var sysInfo = Cc["@mozilla.org/system-info;1"].
|
||||
getService(Ci.nsIPropertyBag2);
|
||||
var ver = parseFloat(sysInfo.getProperty("version"));
|
||||
var ver = parseFloat(Services.sysinfo.getProperty("version"));
|
||||
if (ver >= 6.1)
|
||||
return true;
|
||||
} catch (ex) { }
|
||||
|
@ -37,8 +35,7 @@
|
|||
return null;
|
||||
|
||||
// HACK from mconnor:
|
||||
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
||||
let win = wm.getMostRecentWindow("navigator:browser");
|
||||
let win = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
let docShell = win.docShell;
|
||||
|
||||
let progress = taskbar.getTaskbarProgress(docShell);
|
||||
|
|
|
@ -248,10 +248,7 @@ async function test_jumplist() {
|
|||
|
||||
// Win7 and up only
|
||||
try {
|
||||
var sysInfo = Cc["@mozilla.org/system-info;1"].getService(
|
||||
Ci.nsIPropertyBag2
|
||||
);
|
||||
var ver = parseFloat(sysInfo.getProperty("version"));
|
||||
var ver = parseFloat(Services.sysinfo.getProperty("version"));
|
||||
if (ver < 6.1) {
|
||||
Assert.ok(!builder.available);
|
||||
return;
|
||||
|
|
|
@ -18,13 +18,12 @@
|
|||
<script type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
function onLoad() {
|
||||
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
|
||||
var win = wm.getMostRecentWindow("navigator:browser");
|
||||
var win = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
|
||||
/*
|
||||
switch(win.windowState) {
|
||||
|
|
|
@ -708,6 +708,11 @@ def gen_substs(manifests):
|
|||
list(js_services.values()), PHF_SIZE, key=lambda entry: entry.js_name
|
||||
)
|
||||
|
||||
js_services_json = {}
|
||||
for entry in js_services.values():
|
||||
for iface in entry.interfaces:
|
||||
js_services_json[iface] = entry.js_name
|
||||
|
||||
substs = {}
|
||||
|
||||
gen_categories(substs, categories)
|
||||
|
@ -771,6 +776,8 @@ def gen_substs(manifests):
|
|||
key_length="aKey.Length()",
|
||||
)
|
||||
|
||||
substs["js_services_json"] = json.dumps(js_services_json, sort_keys=True, indent=4)
|
||||
|
||||
# Do this only after everything else has been emitted so we're sure the
|
||||
# string table is complete.
|
||||
substs["strings"] = strings.to_cxx()
|
||||
|
@ -932,4 +939,7 @@ namespace components {
|
|||
% substs
|
||||
)
|
||||
|
||||
with open_output("services.json") as fh:
|
||||
fh.write(substs["js_services_json"])
|
||||
|
||||
return deps
|
||||
|
|
|
@ -42,6 +42,7 @@ if CONFIG["COMPILE_ENVIRONMENT"]:
|
|||
"Components.h",
|
||||
"StaticComponentData.h",
|
||||
"StaticComponents.cpp",
|
||||
"services.json",
|
||||
script="gen_static_components.py",
|
||||
inputs=["!manifest-lists.json", "StaticComponents.cpp.in"],
|
||||
)
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function run_test() {
|
||||
const PROPERTIES = [
|
||||
"name",
|
||||
|
@ -12,7 +14,7 @@ function run_test() {
|
|||
"memmapalign",
|
||||
"memsize",
|
||||
];
|
||||
let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
|
||||
let sysInfo = Services.sysinfo;
|
||||
|
||||
PROPERTIES.forEach(function(aPropertyName) {
|
||||
print("Testing property: " + aPropertyName);
|
||||
|
|
Загрузка…
Ссылка в новой задаче