Bug 1287007 - Move part of browserAction and pageAction to child r=billm
authorRob Wu <rob@robwu.nl>
Sun, 11 Sep 2016 04:18:35 -0700
changeset 428720 4c43afedf60f8852f0a1729123af998da103f50b
parent 428719 09fa6078095c96453fb793ee97755cc3c66a986c
child 428721 f2f75e6e2d607e8a123e2444c2fd9fe9a4e276c8
push id33405
push userbcampen@mozilla.com
push dateMon, 24 Oct 2016 15:32:53 +0000
reviewersbillm
bugs1287007
milestone52.0a1
Bug 1287007 - Move part of browserAction and pageAction to child r=billm And remove redundant `Promise.resolve()` because it is the default for async functions. setIcon is not supported on Android, so there was no need to change mobile/android/components/extensions/ext-pageAction.js. MozReview-Commit-ID: 94ebaJFxLAi
browser/components/extensions/ext-browserAction.js
browser/components/extensions/ext-c-browserAction.js
browser/components/extensions/ext-c-pageAction.js
browser/components/extensions/ext-pageAction.js
browser/components/extensions/extensions-browser.manifest
browser/components/extensions/jar.mn
toolkit/components/extensions/Extension.jsm
toolkit/components/extensions/ExtensionContent.jsm
--- a/browser/components/extensions/ext-browserAction.js
+++ b/browser/components/extensions/ext-browserAction.js
@@ -454,16 +454,19 @@ extensions.registerSchemaAPI("browserAct
 
         let title = BrowserAction.for(extension).getProperty(tab, "title");
         return Promise.resolve(title);
       },
 
       setIcon: function(details) {
         let tab = details.tabId !== null ? TabManager.getTab(details.tabId, context) : null;
 
+        // Note: the caller in the child process has already normalized
+        // `details` to not contain an `imageData` property, so the icon can
+        // safely be normalized here without errors.
         let icon = IconDetails.normalize(details, extension, context);
         BrowserAction.for(extension).setProperty(tab, "icon", icon);
       },
 
       setBadgeText: function(details) {
         let tab = details.tabId !== null ? TabManager.getTab(details.tabId, context) : null;
 
         BrowserAction.for(extension).setProperty(tab, "badgeText", details.text);
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/ext-c-browserAction.js
@@ -0,0 +1,26 @@
+/* -*- 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 {
+  IconDetails,
+} = ExtensionUtils;
+
+extensions.registerSchemaAPI("browserAction", "addon_child", context => {
+  return {
+    browserAction: {
+      setIcon: function(details) {
+        // This needs to run in the addon process because normalization requires
+        // the use of <canvas>.
+        let normalizedDetails = {
+          tabId: details.tabId,
+          path: IconDetails.normalize(details, context.extension, context),
+        };
+        return context.childManager.callParentAsyncFunction("browserAction.setIcon", [
+          normalizedDetails,
+        ]);
+      },
+    },
+  };
+});
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/ext-c-pageAction.js
@@ -0,0 +1,26 @@
+/* -*- 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 {
+  IconDetails,
+} = ExtensionUtils;
+
+extensions.registerSchemaAPI("pageAction", "addon_child", context => {
+  return {
+    pageAction: {
+      setIcon: function(details) {
+        // This needs to run in the addon process because normalization requires
+        // the use of <canvas>.
+        let normalizedDetails = {
+          tabId: details.tabId,
+          path: IconDetails.normalize(details, context.extension, context),
+        };
+        return context.childManager.callParentAsyncFunction("pageAction.setIcon", [
+          normalizedDetails,
+        ]);
+      },
+    },
+  };
+});
--- a/browser/components/extensions/ext-pageAction.js
+++ b/browser/components/extensions/ext-pageAction.js
@@ -231,23 +231,21 @@ extensions.registerSchemaAPI("pageAction
         return () => {
           pageAction.off("click", listener);
         };
       }).api(),
 
       show(tabId) {
         let tab = TabManager.getTab(tabId, context);
         PageAction.for(extension).setProperty(tab, "show", true);
-        return Promise.resolve();
       },
 
       hide(tabId) {
         let tab = TabManager.getTab(tabId, context);
         PageAction.for(extension).setProperty(tab, "show", false);
-        return Promise.resolve();
       },
 
       setTitle(details) {
         let tab = TabManager.getTab(details.tabId, context);
 
         // Clear the tab-specific title when given a null string.
         PageAction.for(extension).setProperty(tab, "title", details.title || null);
       },
@@ -257,19 +255,21 @@ extensions.registerSchemaAPI("pageAction
 
         let title = PageAction.for(extension).getProperty(tab, "title");
         return Promise.resolve(title);
       },
 
       setIcon(details) {
         let tab = TabManager.getTab(details.tabId, context);
 
+        // Note: the caller in the child process has already normalized
+        // `details` to not contain an `imageData` property, so the icon can
+        // safely be normalized here without errors.
         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, context);
 
         // Note: Chrome resolves arguments to setIcon relative to the calling
         // context, but resolves arguments to setPopup relative to the extension
         // root.
--- a/browser/components/extensions/extensions-browser.manifest
+++ b/browser/components/extensions/extensions-browser.manifest
@@ -6,16 +6,18 @@ category webextension-scripts contextMen
 category webextension-scripts desktop-runtime chrome://browser/content/ext-desktop-runtime.js
 category webextension-scripts history chrome://browser/content/ext-history.js
 category webextension-scripts pageAction chrome://browser/content/ext-pageAction.js
 category webextension-scripts tabs chrome://browser/content/ext-tabs.js
 category webextension-scripts utils chrome://browser/content/ext-utils.js
 category webextension-scripts windows chrome://browser/content/ext-windows.js
 
 # scripts that must run in the same process as addon code.
+category webextension-scripts-addon browserAction chrome://browser/content/ext-c-browserAction.js
+category webextension-scripts-addon pageAction chrome://browser/content/ext-c-pageAction.js
 category webextension-scripts-addon tabs chrome://browser/content/ext-c-tabs.js
 
 # schemas
 category webextension-schemas bookmarks chrome://browser/content/schemas/bookmarks.json
 category webextension-schemas browser_action chrome://browser/content/schemas/browser_action.json
 category webextension-schemas commands chrome://browser/content/schemas/commands.json
 category webextension-schemas context_menus chrome://browser/content/schemas/context_menus.json
 category webextension-schemas context_menus_internal chrome://browser/content/schemas/context_menus_internal.json
--- a/browser/components/extensions/jar.mn
+++ b/browser/components/extensions/jar.mn
@@ -17,9 +17,11 @@ browser.jar:
     content/browser/ext-commands.js
     content/browser/ext-contextMenus.js
     content/browser/ext-desktop-runtime.js
     content/browser/ext-history.js
     content/browser/ext-pageAction.js
     content/browser/ext-tabs.js
     content/browser/ext-utils.js
     content/browser/ext-windows.js
+    content/browser/ext-c-browserAction.js
+    content/browser/ext-c-pageAction.js
     content/browser/ext-c-tabs.js
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -1490,16 +1490,17 @@ this.Extension = class extends Extension
       manifest: this.manifest,
       resourceURL: this.addonData.resourceURI.spec,
       baseURL: this.baseURI.spec,
       content_scripts: this.manifest.content_scripts || [],  // eslint-disable-line camelcase
       webAccessibleResources: this.webAccessibleResources.serialize(),
       whiteListedHosts: this.whiteListedHosts.serialize(),
       localeData: this.localeData.serialize(),
       permissions: this.permissions,
+      principal: this.principal,
     };
   }
 
   broadcast(msg, data) {
     return new Promise(resolve => {
       let count = Services.ppmm.childCount;
       Services.ppmm.addMessageListener(msg + "Complete", function listener() {
         count--;
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -691,16 +691,17 @@ DocumentManager = {
 function BrowserExtensionContent(data) {
   this.id = data.id;
   this.uuid = data.uuid;
   this.data = data;
   this.scripts = data.content_scripts.map(scriptData => new Script(this, scriptData));
   this.webAccessibleResources = new MatchGlobs(data.webAccessibleResources);
   this.whiteListedHosts = new MatchPattern(data.whiteListedHosts);
   this.permissions = data.permissions;
+  this.principal = data.principal;
 
   this.localeData = new LocaleData(data.localeData);
 
   this.manifest = data.manifest;
   this.baseURI = Services.io.newURI(data.baseURL, null, null);
 
   // Only used in addon processes.
   this.views = new Set();