Bug 1234020: Part 2h - [webext] Return promises from the pageAction API. r=rpl
--- a/browser/components/extensions/ext-pageAction.js
+++ b/browser/components/extensions/ext-pageAction.js
@@ -1,16 +1,15 @@
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
var {
EventManager,
- runSafe,
} = ExtensionUtils;
// WeakMap[Extension -> PageAction]
var pageActionMap = new WeakMap();
// Handles URL bar icons, including the |page_action| manifest entry
// and associated API.
@@ -218,39 +217,40 @@ extensions.registerSchemaAPI("pageAction
setTitle(details) {
let tab = TabManager.getTab(details.tabId);
// Clear the tab-specific title when given a null string.
PageAction.for(extension).setProperty(tab, "title", details.title || null);
},
- getTitle(details, callback) {
+ getTitle(details) {
let tab = TabManager.getTab(details.tabId);
let title = PageAction.for(extension).getProperty(tab, "title");
- runSafe(context, callback, title);
+ return Promise.resolve(title);
},
- setIcon(details, callback) {
+ setIcon(details) {
let tab = TabManager.getTab(details.tabId);
let icon = IconDetails.normalize(details, extension, context);
PageAction.for(extension).setProperty(tab, "icon", icon);
+ return Promise.resolve();
},
setPopup(details) {
let tab = TabManager.getTab(details.tabId);
// Note: Chrome resolves arguments to setIcon relative to the calling
// context, but resolves arguments to setPopup relative to the extension
// root.
// For internal consistency, we currently resolve both relative to the
// calling context.
let url = details.popup && context.uri.resolve(details.popup);
PageAction.for(extension).setProperty(tab, "popup", url);
},
- getPopup(details, callback) {
+ getPopup(details) {
let tab = TabManager.getTab(details.tabId);
let popup = PageAction.for(extension).getProperty(tab, "popup");
- runSafe(context, callback, popup);
+ return Promise.resolve(popup);
},
},
};
});
--- a/browser/components/extensions/schemas/page_action.json
+++ b/browser/components/extensions/schemas/page_action.json
@@ -65,16 +65,17 @@
}
}
]
},
{
"name": "getTitle",
"type": "function",
"description": "Gets the title of the page action.",
+ "async": "callback",
"parameters": [
{
"name": "details",
"type": "object",
"properties": {
"tabId": {
"type": "integer",
"description": "Specify the tab to get the title from."
@@ -92,16 +93,17 @@
]
}
]
},
{
"name": "setIcon",
"type": "function",
"description": "Sets the icon for the page action. The icon can be specified either as the path to an image file or as the pixel data from a canvas element, or as dictionary of either one of those. Either the <b>path</b> or the <b>imageData</b> property must be specified.",
+ "async": "callback",
"parameters": [
{
"name": "details",
"type": "object",
"properties": {
"tabId": {"type": "integer", "minimum": 0, "description": "The id of the tab for which you want to modify the page action."},
"imageData": {
"choices": [
@@ -152,16 +154,17 @@
}
}
]
},
{
"name": "getPopup",
"type": "function",
"description": "Gets the html document set as the popup for this page action.",
+ "async": "callback",
"parameters": [
{
"name": "details",
"type": "object",
"properties": {
"tabId": {
"type": "integer",
"description": "Specify the tab to get the popup from."
--- a/browser/components/extensions/test/browser/browser_ext_pageAction_context.js
+++ b/browser/components/extensions/test/browser/browser_ext_pageAction_context.js
@@ -11,18 +11,18 @@ function* runTests(options) {
// promise that resolves to an object containing them.
function getDetails() {
return new Promise(resolve => {
return browser.tabs.query({ active: true, currentWindow: true }, resolve);
}).then(([tab]) => {
let tabId = tab.id;
browser.test.log(`Get details: tab={id: ${tabId}, url: ${JSON.stringify(tab.url)}}`);
return Promise.all([
- new Promise(resolve => browser.pageAction.getTitle({tabId}, resolve)),
- new Promise(resolve => browser.pageAction.getPopup({tabId}, resolve))]);
+ browser.pageAction.getTitle({tabId}),
+ browser.pageAction.getPopup({tabId})]);
}).then(details => {
return Promise.resolve({ title: details[0],
popup: details[1] });
});
}
// Runs the next test in the `tests` array, checks the results,