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
--- 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;
});