Bug 1307852 - Pass ID of calling add-on to native messaging app draft
authorRob Wu <rob@robwu.nl>
Thu, 01 Jun 2017 19:08:02 +0200
changeset 587795 0c499438936dafa6ad0fb082c875918c1e72cea3
parent 586049 34ac1a5d6576d6775491c8a882710a1520551da6
child 631363 ce0aaaf647acd63ad05867e56ec70749d8733b49
push id61807
push userbmo:rob@robwu.nl
push dateThu, 01 Jun 2017 17:11:45 +0000
bugs1307852
milestone55.0a1
Bug 1307852 - Pass ID of calling add-on to native messaging app This allows native messaging binaries to identify the add-on that invoked the native messaging app, in case more than one add-on is allowed to launch the native messaging app. MozReview-Commit-ID: GgjwfJDbBkW
toolkit/components/extensions/NativeMessaging.jsm
toolkit/components/extensions/test/xpcshell/test_ext_native_messaging.js
--- a/toolkit/components/extensions/NativeMessaging.jsm
+++ b/toolkit/components/extensions/NativeMessaging.jsm
@@ -193,17 +193,17 @@ this.NativeApp = class extends EventEmit
           // OS.Path.join() ignores anything before the last absolute path
           // it sees, so if command is already absolute, it remains unchanged
           // here.  If it is relative, we get the proper absolute path here.
           command = OS.Path.join(OS.Path.dirname(hostInfo.path), command);
         }
 
         let subprocessOpts = {
           command: command,
-          arguments: [hostInfo.path],
+          arguments: [hostInfo.path, context.extension.id],
           workdir: OS.Path.dirname(command),
           stderr: "pipe",
         };
         return Subprocess.call(subprocessOpts);
       }).then(proc => {
         this.startupPromise = null;
         this.proc = proc;
         this._startRead();
--- a/toolkit/components/extensions/test/xpcshell/test_ext_native_messaging.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_native_messaging.js
@@ -430,18 +430,19 @@ add_task(async function test_child_proce
       applications: {gecko: {id: ID}},
       permissions: ["nativeMessaging"],
     },
   });
 
   await extension.startup();
 
   let msg = await extension.awaitMessage("result");
-  equal(msg.args.length, 2, "Received one command line argument");
+  equal(msg.args.length, 3, "Received two command line arguments");
   equal(msg.args[1], getPath("info.json"), "Command line argument is the path to the native host manifest");
+  equal(msg.args[2], ID, "Second command line argument is the ID of the calling extension");
   equal(msg.cwd.replace(/^\/private\//, "/"), tmpDir.path,
         "Working directory is the directory containing the native appliation");
 
   let exitPromise = waitForSubprocessExit();
   await extension.unload();
   await exitPromise;
 });