Bug 1287626,1288279 - Make IDs unique across processes draft
authorRob Wu <rob@robwu.nl>
Wed, 10 Aug 2016 16:23:56 -0700
changeset 399727 7239bc97516f687087ed4d9d268afdea3394b11e
parent 399726 eefc54070780f56f0db8f788488d94cb14e1c5b7
child 528040 f4f7d9b3c1619c08e8192d60eac3a30ba0cc780b
push id25961
push userbmo:rob@robwu.nl
push dateThu, 11 Aug 2016 22:59:27 +0000
bugs1287626, 1288279
milestone51.0a1
Bug 1287626,1288279 - Make IDs unique across processes MozReview-Commit-ID: 78xgt8wqbng
toolkit/components/extensions/ExtensionUtils.jsm
toolkit/components/extensions/MessageChannel.jsm
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -144,17 +144,17 @@ class SpreadArgs extends Array {
 
 let gContextId = 0;
 
 class BaseContext {
   constructor(extensionId) {
     this.onClose = new Set();
     this.checkedLastError = false;
     this._lastError = null;
-    this.contextId = ++gContextId;
+    this.contextId = `${++gContextId}${Services.appinfo.uniqueProcessID}`;
     this.unloaded = false;
     this.extensionId = extensionId;
     this.jsonSandbox = null;
     this.active = true;
   }
 
   get cloneScope() {
     throw new Error("Not implemented");
@@ -1269,18 +1269,17 @@ Messenger.prototype = {
       MessageChannel.addListener(this.messageManagers, "Extension:Message", listener);
       return () => {
         MessageChannel.removeListener(this.messageManagers, "Extension:Message", listener);
       };
     }).api();
   },
 
   connect(messageManager, name, recipient) {
-    // TODO(robwu): Use a process ID instead of the process type. bugzil.la/1287626
-    let portId = `${gNextPortId++}-${Services.appinfo.processType}`;
+    let portId = `${gNextPortId++}${Services.appinfo.uniqueProcessID}`;
     let port = new Port(this.context, messageManager, name, portId, null);
     let msg = {name, portId};
     this._sendMessage(messageManager, "Extension:Connect", msg, recipient)
       .catch(e => port.disconnectByOtherEnd());
     return port.api();
   },
 
   onConnect(name) {
--- a/toolkit/components/extensions/MessageChannel.jsm
+++ b/toolkit/components/extensions/MessageChannel.jsm
@@ -492,17 +492,17 @@ this.MessageChannel = {
    *    contents for details.
    * @returns {Promise}
    */
   sendMessage(target, messageName, data, options = {}) {
     let sender = options.sender || {};
     let recipient = options.recipient || {};
     let responseType = options.responseType || this.RESPONSE_SINGLE;
 
-    let channelId = gChannelId++;
+    let channelId = `${gChannelId++}${Services.appinfo.uniqueProcessID}`;
     let message = {messageName, channelId, sender, recipient, data, responseType};
 
     let deferred = PromiseUtils.defer();
     deferred.sender = recipient;
     deferred.messageManager = target;
 
     this._addPendingResponse(deferred);