Bug 1234020: Part 2h - [webext] Return promises from the pageAction API. r=rpl draft
authorKris Maglione <maglione.k@gmail.com>
Mon, 01 Feb 2016 18:16:00 -0800
changeset 328979 bce3ef2ff299cc79e068eb81500086cbc8cd22fd
parent 328978 83846197d4562d443e2fda56b4f0ab3132e6dd2b
child 328980 085c449680592a756fec6a812a65ce7d7bb40084
push id10445
push usermaglione.k@gmail.com
push dateThu, 04 Feb 2016 21:38:16 +0000
reviewersrpl
bugs1234020
milestone47.0a1
Bug 1234020: Part 2h - [webext] Return promises from the pageAction API. r=rpl
browser/components/extensions/ext-pageAction.js
browser/components/extensions/schemas/page_action.json
browser/components/extensions/test/browser/browser_ext_pageAction_context.js
--- 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,