Bug 1234020: Part 2d - [webext] Return promises from the runtime API. r=rpl
--- a/toolkit/components/extensions/ext-runtime.js
+++ b/toolkit/components/extensions/ext-runtime.js
@@ -5,17 +5,16 @@ var { classes: Cc, interfaces: Ci, utils
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
"resource://gre/modules/AppConstants.jsm");
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
var {
EventManager,
ignoreEvent,
- runSafe,
} = ExtensionUtils;
extensions.registerSchemaAPI("runtime", null, (extension, context) => {
return {
runtime: {
onStartup: new EventManager(context, "runtime.onStartup", fire => {
extension.onStartup = fire;
return () => {
@@ -64,28 +63,28 @@ extensions.registerSchemaAPI("runtime",
},
id: extension.id,
getURL: function(url) {
return extension.baseURI.resolve(url);
},
- getPlatformInfo: function(callback) {
+ getPlatformInfo: function() {
let os = AppConstants.platform;
if (os == "macosx") {
os = "mac";
}
let abi = Services.appinfo.XPCOMABI;
let [arch] = abi.split("-");
if (arch == "x86") {
arch = "x86-32";
} else if (arch == "x86_64") {
arch = "x86-64";
}
let info = {os, arch};
- runSafe(context, callback, info);
+ return Promise.resolve(info);
},
},
};
});
--- a/toolkit/components/extensions/schemas/runtime.json
+++ b/toolkit/components/extensions/schemas/runtime.json
@@ -132,16 +132,17 @@
}
]
},
{
"name": "openOptionsPage",
"unsupported": true,
"type": "function",
"description": "<p>Open your Extension's options page, if possible.</p><p>The precise behavior may depend on your manifest's <code>$(topic:optionsV2)[options_ui]</code> or <code>$(topic:options)[options_page]</code> key, or what the browser happens to support at the time.</p><p>If your Extension does not declare an options page, or the browser failed to create one for some other reason, the callback will set $(ref:lastError).</p>",
+ "async": "callback",
"parameters": [{
"type": "function",
"name": "callback",
"parameters": [],
"optional": true
}]
},
{
@@ -172,16 +173,17 @@
"description": "The fully-qualified URL to the resource."
}
},
{
"name": "setUninstallURL",
"unsupported": true,
"type": "function",
"description": "Sets the URL to be visited upon uninstallation. This may be used to clean up server-side data, do analytics, and implement surveys. Maximum 255 characters.",
+ "async": "callback",
"parameters": [
{
"type": "string",
"name": "url",
"maxLength": 255,
"description": "URL to be opened after the extension is uninstalled. This URL must have an http: or https: scheme. Set an empty string to not open a new tab upon uninstallation."
},
{
@@ -200,16 +202,17 @@
"type": "function",
"parameters": []
},
{
"name": "requestUpdateCheck",
"unsupported": true,
"type": "function",
"description": "Requests an update check for this app/extension.",
+ "async": "callback",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "status",
"$ref": "RequestUpdateCheckStatus",
@@ -338,16 +341,17 @@
]
}
]
},
{
"name": "getPlatformInfo",
"type": "function",
"description": "Returns information about the current platform.",
+ "async": "callback",
"parameters": [
{
"type": "function",
"name": "callback",
"description": "Called with results",
"parameters": [
{
"name": "platformInfo",
@@ -357,16 +361,17 @@
}
]
},
{
"name": "getPackageDirectoryEntry",
"unsupported": true,
"type": "function",
"description": "Returns a DirectoryEntry for the package directory.",
+ "async": "callback",
"parameters": [
{
"type": "function",
"name": "callback",
"parameters": [
{
"name": "directoryEntry",
"type": "object",