Bug 1374237 - Part 2: Declare all top-level functions in toolkit API files files via const., r=mixedpuppy

Also changed some function names to attempt to guarantee uniqueness across API files.

MozReview-Commit-ID: GnwWwTADF3a

--HG--
extra : rebase_source : 2d51f3de2958089de97ce98ed1f01c68ec0ed74a
This commit is contained in:
Bob Silverberg 2017-06-21 14:29:37 -04:00
Родитель bb1231853d
Коммит 29414a264f
11 изменённых файлов: 70 добавлений и 70 удалений

Просмотреть файл

@ -7,7 +7,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "Preferences",
Cu.import("resource://gre/modules/ExtensionPreferencesManager.jsm");
function getAPI(extension, name, callback) {
const getSettingsAPI = (extension, name, callback) => {
return {
async get(details) {
return {
@ -26,7 +26,7 @@ function getAPI(extension, name, callback) {
return ExtensionPreferencesManager.removeSetting(extension, name);
},
};
}
};
// Add settings objects for supported APIs to the preferences manager.
ExtensionPreferencesManager.addSetting("cacheEnabled", {
@ -49,7 +49,7 @@ this.browserSettings = class extends ExtensionAPI {
let {extension} = context;
return {
browserSettings: {
cacheEnabled: getAPI(extension,
cacheEnabled: getSettingsAPI(extension,
"cacheEnabled",
() => {
return Preferences.get("browser.cache.disk.enable") &&

Просмотреть файл

@ -19,14 +19,14 @@ var {
promiseDocumentLoaded,
} = ExtensionUtils;
function computeHash(str) {
const computeHash = str => {
let byteArr = new TextEncoder().encode(str);
let hash = new CryptoHash("sha1");
hash.update(byteArr, byteArr.length);
return CommonUtils.bytesAsHex(hash.finish(false));
}
};
function checkRedirected(url, redirectURI) {
const checkRedirected = (url, redirectURI) => {
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.open("HEAD", url);
@ -57,9 +57,9 @@ function checkRedirected(url, redirectURI) {
};
xhr.send();
});
}
};
function openOAuthWindow(details, redirectURI) {
const openOAuthWindow = (details, redirectURI) => {
let args = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
let supportsStringPrefURL = Cc["@mozilla.org/supports-string;1"]
.createInstance(Ci.nsISupportsString);
@ -101,7 +101,7 @@ function openOAuthWindow(details, redirectURI) {
window.addEventListener("unload", unloadlistener);
});
});
}
};
this.identity = class extends ExtensionAPI {
getAPI(context) {

Просмотреть файл

@ -21,7 +21,7 @@
* @returns {boolean}
* True if the error matches the expected error.
*/
function errorMatches(error, expectedError, context) {
const errorMatches = (error, expectedError, context) => {
if (expectedError === null) {
return true;
}
@ -46,7 +46,7 @@ function errorMatches(error, expectedError, context) {
}
return false;
}
};
/**
* Calls .toSource() on the given value, but handles null, undefined,
@ -55,7 +55,7 @@ function errorMatches(error, expectedError, context) {
* @param {*} value
* @returns {string}
*/
function toSource(value) {
const toSource = value => {
if (value === null) {
return "null";
}
@ -71,7 +71,7 @@ function toSource(value) {
} catch (e) {
return "<unknown>";
}
}
};
this.test = class extends ExtensionAPI {
getAPI(context) {

Просмотреть файл

@ -8,7 +8,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "ContextualIdentityService",
XPCOMUtils.defineLazyPreferenceGetter(this, "containersEnabled",
"privacy.userContext.enabled");
function convert(identity) {
const convertIdentity = identity => {
let result = {
name: ContextualIdentityService.getUserContextLabel(identity.userContextId),
icon: identity.icon,
@ -17,7 +17,7 @@ function convert(identity) {
};
return result;
}
};
this.contextualIdentities = class extends ExtensionAPI {
getAPI(context) {
@ -34,7 +34,7 @@ this.contextualIdentities = class extends ExtensionAPI {
}
let identity = ContextualIdentityService.getPublicIdentityFromId(containerId);
return Promise.resolve(convert(identity));
return Promise.resolve(convertIdentity(identity));
},
query(details) {
@ -49,7 +49,7 @@ this.contextualIdentities = class extends ExtensionAPI {
return;
}
identities.push(convert(identity));
identities.push(convertIdentity(identity));
});
return Promise.resolve(identities);
@ -63,7 +63,7 @@ this.contextualIdentities = class extends ExtensionAPI {
let identity = ContextualIdentityService.create(details.name,
details.icon,
details.color);
return Promise.resolve(convert(identity));
return Promise.resolve(convertIdentity(identity));
},
update(cookieStoreId, details) {
@ -99,7 +99,7 @@ this.contextualIdentities = class extends ExtensionAPI {
return Promise.resolve(null);
}
return Promise.resolve(convert(identity));
return Promise.resolve(convertIdentity(identity));
},
remove(cookieStoreId) {
@ -118,7 +118,7 @@ this.contextualIdentities = class extends ExtensionAPI {
}
// We have to create the identity object before removing it.
let convertedIdentity = convert(identity);
let convertedIdentity = convertIdentity(identity);
if (!ContextualIdentityService.remove(identity.userContextId)) {
return Promise.resolve(null);

Просмотреть файл

@ -235,7 +235,7 @@ const DownloadMap = {
// Create a callable function that filters a DownloadItem based on a
// query object of the type passed to search() or erase().
function downloadQuery(query) {
const downloadQuery = query => {
let queryTerms = [];
let queryNegativeTerms = [];
if (query.query != null) {
@ -337,9 +337,9 @@ function downloadQuery(query) {
return true;
};
}
};
function queryHelper(query) {
const queryHelper = query => {
let matchFn;
try {
matchFn = downloadQuery(query);
@ -390,7 +390,7 @@ function queryHelper(query) {
}
return results;
});
}
};
this.downloads = class extends ExtensionAPI {
getAPI(context) {

Просмотреть файл

@ -12,7 +12,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "idleService",
// WeakMap[Extension -> Object]
let observersMap = new WeakMap();
function getObserverInfo(extension, context) {
const getIdleObserverInfo = (extension, context) => {
let observerInfo = observersMap.get(extension);
if (!observerInfo) {
observerInfo = {
@ -31,10 +31,10 @@ function getObserverInfo(extension, context) {
});
}
return observerInfo;
}
};
function getObserver(extension, context) {
let observerInfo = getObserverInfo(extension, context);
const getIdleObserver = (extension, context) => {
let observerInfo = getIdleObserverInfo(extension, context);
let {observer, detectionInterval} = observerInfo;
if (!observer) {
observer = {
@ -50,17 +50,17 @@ function getObserver(extension, context) {
observerInfo.detectionInterval = detectionInterval;
}
return observer;
}
};
function setDetectionInterval(extension, context, newInterval) {
let observerInfo = getObserverInfo(extension, context);
const setDetectionInterval = (extension, context, newInterval) => {
let observerInfo = getIdleObserverInfo(extension, context);
let {observer, detectionInterval} = observerInfo;
if (observer) {
idleService.removeIdleObserver(observer, detectionInterval);
idleService.addIdleObserver(observer, newInterval);
}
observerInfo.detectionInterval = newInterval;
}
};
this.idle = class extends ExtensionAPI {
getAPI(context) {
@ -81,9 +81,9 @@ this.idle = class extends ExtensionAPI {
fire.sync(data);
};
getObserver(extension, context).on("stateChanged", listener);
getIdleObserver(extension, context).on("stateChanged", listener);
return () => {
getObserver(extension, context).off("stateChanged", listener);
getIdleObserver(extension, context).off("stateChanged", listener);
};
}).api(),
},

Просмотреть файл

@ -26,14 +26,14 @@ var {
ExtensionError,
} = ExtensionUtils;
function _(key, ...args) {
const _ = (key, ...args) => {
if (args.length) {
return strBundle.formatStringFromName(key, args, args.length);
}
return strBundle.GetStringFromName(key);
}
};
function installType(addon) {
const installType = addon => {
if (addon.temporarilyInstalled) {
return "development";
} else if (addon.foreignInstall) {
@ -42,9 +42,9 @@ function installType(addon) {
return "other";
}
return "normal";
}
};
function getExtensionInfoForAddon(extension, addon) {
const getExtensionInfoForAddon = (extension, addon) => {
let extInfo = {
id: addon.id,
name: addon.name,
@ -85,7 +85,7 @@ function getExtensionInfoForAddon(extension, addon) {
extInfo.updateUrl = addon.updateURL;
}
return extInfo;
}
};
const listenerMap = new WeakMap();
// Some management APIs are intentionally limited.
@ -141,7 +141,7 @@ class AddonListener {
let addonListener;
function getListener(extension, context) {
const getManagementListener = (extension, context) => {
if (!listenerMap.has(extension)) {
if (!addonListener) {
addonListener = new AddonListener();
@ -158,7 +158,7 @@ function getListener(extension, context) {
});
}
return addonListener;
}
};
this.management = class extends ExtensionAPI {
getAPI(context) {
@ -229,9 +229,9 @@ this.management = class extends ExtensionAPI {
fire.async(data);
};
getListener(extension, context).on("onDisabled", listener);
getManagementListener(extension, context).on("onDisabled", listener);
return () => {
getListener(extension, context).off("onDisabled", listener);
getManagementListener(extension, context).off("onDisabled", listener);
};
}).api(),
@ -240,9 +240,9 @@ this.management = class extends ExtensionAPI {
fire.async(data);
};
getListener(extension, context).on("onEnabled", listener);
getManagementListener(extension, context).on("onEnabled", listener);
return () => {
getListener(extension, context).off("onEnabled", listener);
getManagementListener(extension, context).off("onEnabled", listener);
};
}).api(),
@ -251,9 +251,9 @@ this.management = class extends ExtensionAPI {
fire.async(data);
};
getListener(extension, context).on("onInstalled", listener);
getManagementListener(extension, context).on("onInstalled", listener);
return () => {
getListener(extension, context).off("onInstalled", listener);
getManagementListener(extension, context).off("onInstalled", listener);
};
}).api(),
@ -262,9 +262,9 @@ this.management = class extends ExtensionAPI {
fire.async(data);
};
getListener(extension, context).on("onUninstalled", listener);
getManagementListener(extension, context).on("onUninstalled", listener);
return () => {
getListener(extension, context).off("onUninstalled", listener);
getManagementListener(extension, context).off("onUninstalled", listener);
};
}).api(),

Просмотреть файл

@ -10,14 +10,14 @@ var {
ExtensionError,
} = ExtensionUtils;
function checkScope(scope) {
const checkScope = scope => {
if (scope && scope !== "regular") {
throw new ExtensionError(
`Firefox does not support the ${scope} settings scope.`);
}
}
};
function getAPI(extension, name, callback) {
const getPrivacyAPI = (extension, name, callback) => {
return {
async get(details) {
return {
@ -39,7 +39,7 @@ function getAPI(extension, name, callback) {
extension, name);
},
};
}
};
// Add settings objects for supported APIs to the preferences manager.
ExtensionPreferencesManager.addSetting("network.networkPredictionEnabled", {
@ -144,7 +144,7 @@ this.privacy = class extends ExtensionAPI {
return {
privacy: {
network: {
networkPredictionEnabled: getAPI(extension,
networkPredictionEnabled: getPrivacyAPI(extension,
"network.networkPredictionEnabled",
() => {
return Preferences.get("network.predictor.enabled") &&
@ -152,12 +152,12 @@ this.privacy = class extends ExtensionAPI {
Preferences.get("network.http.speculative-parallel-limit") > 0 &&
!Preferences.get("network.dns.disablePrefetch");
}),
peerConnectionEnabled: getAPI(extension,
peerConnectionEnabled: getPrivacyAPI(extension,
"network.peerConnectionEnabled",
() => {
return Preferences.get("media.peerconnection.enabled");
}),
webRTCIPHandlingPolicy: getAPI(extension,
webRTCIPHandlingPolicy: getPrivacyAPI(extension,
"network.webRTCIPHandlingPolicy",
() => {
if (Preferences.get("media.peerconnection.ice.proxy_only")) {
@ -178,7 +178,7 @@ this.privacy = class extends ExtensionAPI {
},
services: {
passwordSavingEnabled: getAPI(extension,
passwordSavingEnabled: getPrivacyAPI(extension,
"services.passwordSavingEnabled",
() => {
return Preferences.get("signon.rememberSignons");
@ -186,12 +186,12 @@ this.privacy = class extends ExtensionAPI {
},
websites: {
hyperlinkAuditingEnabled: getAPI(extension,
hyperlinkAuditingEnabled: getPrivacyAPI(extension,
"websites.hyperlinkAuditingEnabled",
() => {
return Preferences.get("browser.send_pings");
}),
referrersEnabled: getAPI(extension,
referrersEnabled: getPrivacyAPI(extension,
"websites.referrersEnabled",
() => {
return Preferences.get("network.http.sendRefererHeader") !== 0;

Просмотреть файл

@ -10,7 +10,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "protocolService",
"nsIExternalProtocolService");
Cu.importGlobalProperties(["URL"]);
function hasHandlerApp(handlerConfig) {
const hasHandlerApp = handlerConfig => {
let protoInfo = protocolService.getProtocolHandlerInfo(handlerConfig.protocol);
let appHandlers = protoInfo.possibleApplicationHandlers;
for (let i = 0; i < appHandlers.length; i++) {
@ -21,7 +21,7 @@ function hasHandlerApp(handlerConfig) {
}
}
return false;
}
};
this.protocolHandlers = class extends ExtensionAPI {
onManifestEntry(entryName) {

Просмотреть файл

@ -14,7 +14,7 @@ var {
ExtensionError,
} = ExtensionUtils;
function enforceNoTemporaryAddon(extensionId) {
const enforceNoTemporaryAddon = extensionId => {
const EXCEPTION_MESSAGE =
"The storage API will not work with a temporary addon ID. " +
"Please add an explicit addon ID to your manifest. " +
@ -22,7 +22,7 @@ function enforceNoTemporaryAddon(extensionId) {
if (AddonManagerPrivate.isTemporaryInstallID(extensionId)) {
throw new ExtensionError(EXCEPTION_MESSAGE);
}
}
};
this.storage = class extends ExtensionAPI {
getAPI(context) {

Просмотреть файл

@ -36,11 +36,11 @@ const tabTransitions = {
},
};
function isTopLevelFrame({frameId, parentFrameId}) {
const isTopLevelFrame = ({frameId, parentFrameId}) => {
return frameId == 0 && parentFrameId == -1;
}
};
function fillTransitionProperties(eventName, src, dst) {
const fillTransitionProperties = (eventName, src, dst) => {
if (eventName == "onCommitted" ||
eventName == "onHistoryStateUpdated" ||
eventName == "onReferenceFragmentUpdated") {
@ -90,7 +90,7 @@ function fillTransitionProperties(eventName, src, dst) {
dst.transitionType = transitionType;
dst.transitionQualifiers = transitionQualifiers;
}
}
};
// Similar to WebRequestEventManager but for WebNavigation.
function WebNavigationEventManager(context, eventName) {
@ -149,7 +149,7 @@ function WebNavigationEventManager(context, eventName) {
WebNavigationEventManager.prototype = Object.create(SingletonEventManager.prototype);
function convertGetFrameResult(tabId, data) {
const convertGetFrameResult = (tabId, data) => {
return {
errorOccurred: data.errorOccurred,
url: data.url,
@ -157,7 +157,7 @@ function convertGetFrameResult(tabId, data) {
frameId: data.frameId,
parentFrameId: data.parentFrameId,
};
}
};
this.webNavigation = class extends ExtensionAPI {
getAPI(context) {