зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1374237 - Part 3: Declare all top-level functions in browser API files files via const., r=mixedpuppy
Also changed some function names to attempt to guarantee uniqueness across API files. MozReview-Commit-ID: FU5JU1lRHzn --HG-- extra : rebase_source : 4fdda100649f1bf604f6d5445aa04ce561859964
This commit is contained in:
Родитель
29414a264f
Коммит
460568b25e
|
@ -8,7 +8,7 @@ XPCOMUtils.defineLazyModuleGetter(global, "EventEmitter",
|
|||
|
||||
// This function is pretty tightly tied to Extension.jsm.
|
||||
// Its job is to fill in the |tab| property of the sender.
|
||||
function getSender(extension, target, sender) {
|
||||
const getSender = (extension, target, sender) => {
|
||||
let tabId;
|
||||
if ("tabId" in sender) {
|
||||
// The message came from a privileged extension page running in a tab. In
|
||||
|
@ -26,7 +26,7 @@ function getSender(extension, target, sender) {
|
|||
sender.tab = tab.convert();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Used by Extension.jsm
|
||||
global.tabGetSender = getSender;
|
||||
|
|
|
@ -43,14 +43,14 @@ const POPUP_RESULT_HISTOGRAM = "WEBEXT_BROWSERACTION_POPUP_PRELOAD_RESULT_COUNT"
|
|||
|
||||
var XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
|
||||
function isAncestorOrSelf(target, node) {
|
||||
const isAncestorOrSelf = (target, node) => {
|
||||
for (; node; node = node.parentNode) {
|
||||
if (node === target) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// WeakMap[Extension -> BrowserAction]
|
||||
const browserActionMap = new WeakMap();
|
||||
|
|
|
@ -32,18 +32,18 @@ XPCOMUtils.defineLazyGetter(this, "sanitizer", () => {
|
|||
return sanitizer;
|
||||
});
|
||||
|
||||
function makeRange(options) {
|
||||
const makeRange = options => {
|
||||
return (options.since == null) ?
|
||||
null :
|
||||
[PlacesUtils.toPRTime(options.since), PlacesUtils.toPRTime(Date.now())];
|
||||
}
|
||||
};
|
||||
|
||||
function clearCache() {
|
||||
const clearCache = () => {
|
||||
// Clearing the cache does not support timestamps.
|
||||
return sanitizer.items.cache.clear();
|
||||
}
|
||||
};
|
||||
|
||||
let clearCookies = async function(options) {
|
||||
const clearCookies = async function(options) {
|
||||
let cookieMgr = Services.cookies;
|
||||
// This code has been borrowed from sanitize.js.
|
||||
let yieldCounter = 0;
|
||||
|
@ -70,19 +70,19 @@ let clearCookies = async function(options) {
|
|||
}
|
||||
};
|
||||
|
||||
function clearDownloads(options) {
|
||||
const clearDownloads = options => {
|
||||
return sanitizer.items.downloads.clear(makeRange(options));
|
||||
}
|
||||
};
|
||||
|
||||
function clearFormData(options) {
|
||||
const clearFormData = options => {
|
||||
return sanitizer.items.formdata.clear(makeRange(options));
|
||||
}
|
||||
};
|
||||
|
||||
function clearHistory(options) {
|
||||
const clearHistory = options => {
|
||||
return sanitizer.items.history.clear(makeRange(options));
|
||||
}
|
||||
};
|
||||
|
||||
let clearPasswords = async function(options) {
|
||||
const clearPasswords = async function(options) {
|
||||
let loginManager = Services.logins;
|
||||
let yieldCounter = 0;
|
||||
|
||||
|
@ -104,11 +104,11 @@ let clearPasswords = async function(options) {
|
|||
}
|
||||
};
|
||||
|
||||
function clearPluginData(options) {
|
||||
const clearPluginData = options => {
|
||||
return sanitizer.items.pluginData.clear(makeRange(options));
|
||||
}
|
||||
};
|
||||
|
||||
let clearServiceWorkers = async function() {
|
||||
const clearServiceWorkers = async function() {
|
||||
// Clearing service workers does not support timestamps.
|
||||
let yieldCounter = 0;
|
||||
|
||||
|
@ -124,7 +124,7 @@ let clearServiceWorkers = async function() {
|
|||
}
|
||||
};
|
||||
|
||||
function doRemoval(options, dataToRemove, extension) {
|
||||
const doRemoval = (options, dataToRemove, extension) => {
|
||||
if (options.originTypes &&
|
||||
(options.originTypes.protectedWeb || options.originTypes.extension)) {
|
||||
return Promise.reject(
|
||||
|
@ -170,7 +170,7 @@ function doRemoval(options, dataToRemove, extension) {
|
|||
`Firefox does not support dataTypes: ${invalidDataTypes.toString()}.`);
|
||||
}
|
||||
return Promise.all(removalPromises);
|
||||
}
|
||||
};
|
||||
|
||||
this.browsingData = class extends ExtensionAPI {
|
||||
getAPI(context) {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
XPCOMUtils.defineLazyModuleGetter(this, "ExtensionPreferencesManager",
|
||||
"resource://gre/modules/ExtensionPreferencesManager.jsm");
|
||||
|
||||
function searchInitialized() {
|
||||
const searchInitialized = () => {
|
||||
return new Promise(resolve => {
|
||||
if (Services.search.isInitialized) {
|
||||
resolve();
|
||||
|
@ -22,7 +22,7 @@ function searchInitialized() {
|
|||
resolve();
|
||||
}, SEARCH_SERVICE_TOPIC);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.chrome_settings_overrides = class extends ExtensionAPI {
|
||||
async onManifestEntry(entryName) {
|
||||
|
|
|
@ -22,7 +22,7 @@ var {
|
|||
ExtensionError,
|
||||
} = ExtensionUtils;
|
||||
|
||||
function parseSym(data) {
|
||||
const parseSym = data => {
|
||||
const worker = new ChromeWorker("resource://app/modules/ParseSymbols-worker.js");
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
worker.onmessage = (e) => {
|
||||
|
@ -35,7 +35,7 @@ function parseSym(data) {
|
|||
});
|
||||
worker.postMessage(data);
|
||||
return promise;
|
||||
}
|
||||
};
|
||||
|
||||
class NMParser {
|
||||
constructor() {
|
||||
|
@ -120,14 +120,14 @@ class CppFiltParser {
|
|||
}
|
||||
}
|
||||
|
||||
async function readAllData(pipe, processData) {
|
||||
const readAllData = async function(pipe, processData) {
|
||||
let data;
|
||||
while ((data = await pipe.readString())) {
|
||||
processData(data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
async function spawnProcess(name, cmdArgs, processData, stdin = null) {
|
||||
const spawnProcess = async function(name, cmdArgs, processData, stdin = null) {
|
||||
const opts = {
|
||||
command: await Subprocess.pathSearch(name),
|
||||
arguments: cmdArgs,
|
||||
|
@ -141,9 +141,9 @@ async function spawnProcess(name, cmdArgs, processData, stdin = null) {
|
|||
}
|
||||
|
||||
await readAllData(proc.stdout, processData);
|
||||
}
|
||||
};
|
||||
|
||||
async function getSymbolsFromNM(path, arch) {
|
||||
const getSymbolsFromNM = async function(path, arch) {
|
||||
const parser = new NMParser();
|
||||
|
||||
const args = [path];
|
||||
|
@ -173,20 +173,20 @@ async function getSymbolsFromNM(path, arch) {
|
|||
}
|
||||
|
||||
return ParseSymbols.convertSymsMapToExpectedSymFormat(syms, approximateLength);
|
||||
}
|
||||
};
|
||||
|
||||
function pathComponentsForSymbolFile(debugName, breakpadId) {
|
||||
const pathComponentsForSymbolFile = (debugName, breakpadId) => {
|
||||
const symName = debugName.replace(/(\.pdb)?$/, ".sym");
|
||||
return [debugName, breakpadId, symName];
|
||||
}
|
||||
};
|
||||
|
||||
function urlForSymFile(debugName, breakpadId) {
|
||||
const urlForSymFile = (debugName, breakpadId) => {
|
||||
const profilerSymbolsURL = Services.prefs.getCharPref(PREF_SYMBOLS_URL,
|
||||
"http://symbols.mozilla.org/");
|
||||
return profilerSymbolsURL + pathComponentsForSymbolFile(debugName, breakpadId).join("/");
|
||||
}
|
||||
};
|
||||
|
||||
function getContainingObjdirDist(path) {
|
||||
const getContainingObjdirDist = path => {
|
||||
let curPath = path;
|
||||
let curPathBasename = OS.Path.basename(curPath);
|
||||
while (curPathBasename) {
|
||||
|
@ -201,9 +201,9 @@ function getContainingObjdirDist(path) {
|
|||
curPathBasename = OS.Path.basename(curPath);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
function filePathForSymFileInObjDir(binaryPath, debugName, breakpadId) {
|
||||
const filePathForSymFileInObjDir = (binaryPath, debugName, breakpadId) => {
|
||||
// `mach buildsymbols` generates symbol files located
|
||||
// at /path/to/objdir/dist/crashreporter-symbols/.
|
||||
const objDirDist = getContainingObjdirDist(binaryPath);
|
||||
|
@ -213,15 +213,15 @@ function filePathForSymFileInObjDir(binaryPath, debugName, breakpadId) {
|
|||
return OS.Path.join(objDirDist,
|
||||
"crashreporter-symbols",
|
||||
...pathComponentsForSymbolFile(debugName, breakpadId));
|
||||
}
|
||||
};
|
||||
|
||||
const symbolCache = new Map();
|
||||
|
||||
function primeSymbolStore(libs) {
|
||||
const primeSymbolStore = libs => {
|
||||
for (const {debugName, breakpadId, path, arch} of libs) {
|
||||
symbolCache.set(urlForSymFile(debugName, breakpadId), {path, arch});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const isRunningObserver = {
|
||||
_observers: new Set(),
|
||||
|
|
|
@ -28,7 +28,7 @@ for (let [transition, transitionType] of TRANSITION_TO_TRANSITION_TYPES_MAP) {
|
|||
TRANSITION_TYPE_TO_TRANSITIONS_MAP.set(transitionType, transition);
|
||||
}
|
||||
|
||||
function getTransitionType(transition) {
|
||||
const getTransitionType = transition => {
|
||||
// cannot set a default value for the transition argument as the framework sets it to null
|
||||
transition = transition || "link";
|
||||
let transitionType = TRANSITION_TO_TRANSITION_TYPES_MAP.get(transition);
|
||||
|
@ -36,18 +36,18 @@ function getTransitionType(transition) {
|
|||
throw new Error(`|${transition}| is not a supported transition for history`);
|
||||
}
|
||||
return transitionType;
|
||||
}
|
||||
};
|
||||
|
||||
function getTransition(transitionType) {
|
||||
const getTransition = transitionType => {
|
||||
return TRANSITION_TYPE_TO_TRANSITIONS_MAP.get(transitionType) || "link";
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Converts a nsINavHistoryResultNode into a HistoryItem
|
||||
*
|
||||
* https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsINavHistoryResultNode
|
||||
*/
|
||||
function convertNodeToHistoryItem(node) {
|
||||
const convertNodeToHistoryItem = node => {
|
||||
return {
|
||||
id: node.pageGuid,
|
||||
url: node.uri,
|
||||
|
@ -55,14 +55,14 @@ function convertNodeToHistoryItem(node) {
|
|||
lastVisitTime: PlacesUtils.toDate(node.time).getTime(),
|
||||
visitCount: node.accessCount,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Converts a nsINavHistoryResultNode into a VisitItem
|
||||
*
|
||||
* https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsINavHistoryResultNode
|
||||
*/
|
||||
function convertNodeToVisitItem(node) {
|
||||
const convertNodeToVisitItem = node => {
|
||||
return {
|
||||
id: node.pageGuid,
|
||||
visitId: node.visitId,
|
||||
|
@ -70,14 +70,14 @@ function convertNodeToVisitItem(node) {
|
|||
referringVisitId: node.fromVisitId,
|
||||
transition: getTransition(node.visitType),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Converts a nsINavHistoryContainerResultNode into an array of objects
|
||||
*
|
||||
* https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsINavHistoryContainerResultNode
|
||||
*/
|
||||
function convertNavHistoryContainerResultNode(container, converter) {
|
||||
const convertNavHistoryContainerResultNode = (container, converter) => {
|
||||
let results = [];
|
||||
container.containerOpen = true;
|
||||
for (let i = 0; i < container.childCount; i++) {
|
||||
|
@ -86,11 +86,11 @@ function convertNavHistoryContainerResultNode(container, converter) {
|
|||
}
|
||||
container.containerOpen = false;
|
||||
return results;
|
||||
}
|
||||
};
|
||||
|
||||
var _observer;
|
||||
|
||||
function getObserver() {
|
||||
const getHistoryObserver = () => {
|
||||
if (!_observer) {
|
||||
_observer = {
|
||||
onDeleteURI: function(uri, guid, reason) {
|
||||
|
@ -126,7 +126,7 @@ function getObserver() {
|
|||
PlacesUtils.history.addObserver(_observer);
|
||||
}
|
||||
return _observer;
|
||||
}
|
||||
};
|
||||
|
||||
this.history = class extends ExtensionAPI {
|
||||
getAPI(context) {
|
||||
|
@ -224,9 +224,9 @@ this.history = class extends ExtensionAPI {
|
|||
fire.sync(data);
|
||||
};
|
||||
|
||||
getObserver().on("visited", listener);
|
||||
getHistoryObserver().on("visited", listener);
|
||||
return () => {
|
||||
getObserver().off("visited", listener);
|
||||
getHistoryObserver().off("visited", listener);
|
||||
};
|
||||
}).api(),
|
||||
|
||||
|
@ -235,9 +235,9 @@ this.history = class extends ExtensionAPI {
|
|||
fire.sync(data);
|
||||
};
|
||||
|
||||
getObserver().on("visitRemoved", listener);
|
||||
getHistoryObserver().on("visitRemoved", listener);
|
||||
return () => {
|
||||
getObserver().off("visitRemoved", listener);
|
||||
getHistoryObserver().off("visitRemoved", listener);
|
||||
};
|
||||
}).api(),
|
||||
|
||||
|
@ -246,9 +246,9 @@ this.history = class extends ExtensionAPI {
|
|||
fire.sync(data);
|
||||
};
|
||||
|
||||
getObserver().on("titleChanged", listener);
|
||||
getHistoryObserver().on("titleChanged", listener);
|
||||
return () => {
|
||||
getObserver().off("titleChanged", listener);
|
||||
getHistoryObserver().off("titleChanged", listener);
|
||||
};
|
||||
}).api(),
|
||||
},
|
||||
|
|
|
@ -298,7 +298,7 @@ global.actionContextMenu = function(contextData) {
|
|||
gMenuBuilder.buildActionContextMenu(contextData);
|
||||
};
|
||||
|
||||
function getContexts(contextData) {
|
||||
const getMenuContexts = contextData => {
|
||||
let contexts = new Set();
|
||||
|
||||
if (contextData.inFrame) {
|
||||
|
@ -355,7 +355,7 @@ function getContexts(contextData) {
|
|||
}
|
||||
|
||||
return contexts;
|
||||
}
|
||||
};
|
||||
|
||||
function MenuItem(extension, createProperties, isRoot = false) {
|
||||
this.extension = extension;
|
||||
|
@ -546,7 +546,7 @@ MenuItem.prototype = {
|
|||
},
|
||||
|
||||
enabledForContext(contextData) {
|
||||
let contexts = getContexts(contextData);
|
||||
let contexts = getMenuContexts(contextData);
|
||||
if (!this.contexts.some(n => contexts.has(n))) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "SessionStore",
|
|||
|
||||
const SS_ON_CLOSED_OBJECTS_CHANGED = "sessionstore-closed-objects-changed";
|
||||
|
||||
function getRecentlyClosed(maxResults, extension) {
|
||||
const getRecentlyClosed = (maxResults, extension) => {
|
||||
let recentlyClosed = [];
|
||||
|
||||
// Get closed windows
|
||||
|
@ -39,9 +39,9 @@ function getRecentlyClosed(maxResults, extension) {
|
|||
// Sort windows and tabs
|
||||
recentlyClosed.sort((a, b) => b.lastModified - a.lastModified);
|
||||
return recentlyClosed.slice(0, maxResults);
|
||||
}
|
||||
};
|
||||
|
||||
async function createSession(restored, extension, sessionId) {
|
||||
const createSession = async function createSession(restored, extension, sessionId) {
|
||||
if (!restored) {
|
||||
throw new ExtensionError(`Could not restore object using sessionId ${sessionId}.`);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ async function createSession(restored, extension, sessionId) {
|
|||
}
|
||||
sessionObj.tab = extension.tabManager.convert(restored);
|
||||
return sessionObj;
|
||||
}
|
||||
};
|
||||
|
||||
this.sessions = class extends ExtensionAPI {
|
||||
getAPI(context) {
|
||||
|
|
|
@ -17,9 +17,9 @@ var {
|
|||
promiseObserved,
|
||||
} = ExtensionUtils;
|
||||
|
||||
function onXULFrameLoaderCreated({target}) {
|
||||
const onXULFrameLoaderCreated = ({target}) => {
|
||||
target.messageManager.sendAsyncMessage("AllowScriptsToClose", {});
|
||||
}
|
||||
};
|
||||
|
||||
this.windows = class extends ExtensionAPI {
|
||||
getAPI(context) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче