Skip to content

Commit 6c807dc

Browse files
committed
add _id field to callbacks
1 parent 29e33dc commit 6c807dc

File tree

3 files changed

+25
-33
lines changed

3 files changed

+25
-33
lines changed

extension/API/libwebpg/nativeMessaging.js

+16-24
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,18 @@ webpg.nativeMessaging = {
172172
let func = result.func || result.type || undefined;
173173
if (func === "onkeygencomplete")
174174
func = "onkeygenprogress";
175+
let _id = result._id || func;
176+
175177
if (func !== undefined) {
176-
let cb = port.callbacks[func] || undefined;
178+
let cb = port.callbacks[func][_id] || port.callbacks[func] || undefined;
179+
177180
delete result.func;
178-
if (cb) {
181+
delete result._id;
182+
183+
if (cb && typeof(cb) === "function") {
179184
cb(result);
180185
if (func !== "onstatusprogress" && (func !== "onkeygenprogress" && result.type !== "onkeygencomplete"))
181-
delete port.callbacks[func];
186+
delete port.callbacks[func][_id]
182187
}
183188
}
184189
};
@@ -274,28 +279,15 @@ webpg.nativeMessaging = {
274279
)
275280
) ? "onkeygenprogress" : func
276281

277-
port.callbacks[func] = callback;
282+
// generate a unique id for this invocation if one isn't provided
283+
if (args._id == undefined)
284+
args._id = (func.search("progress") > -1) ? func : new Date().getTime() + parseInt(Math.random()*0xffffffff);
285+
286+
port.callbacks[func] = port.callbacks[func] || {};
287+
port.callbacks[func][args._id] = callback;
288+
278289
port.postMessage(args);
279-
/*return;
280-
if (callback && (args.async===true || (args.params && args.params.async))) {
281-
var port = webpg.nativeMessaging.port();
282-
webpg.nativeMessaging.addListener(port, callback);
283-
port.postMessage(args);
284-
} else {
285-
webpg.nativeMessaging.sendMessage(args,
286-
function(res) {
287-
if (callback && typeof(callback) === "function") {
288-
if (webpg.utils.detectedBrowser.product === "chrome" && chrome.runtime.lastError)
289-
callback(chrome.runtime.lastError);
290-
else
291-
callback(res);
292-
return res;
293-
} else {
294-
return res;
295-
}
296-
}
297-
);
298-
}*/
290+
299291
},
300292

301293
getFunctionName: function() {

extension/background.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -588,9 +588,9 @@ webpg.background = {
588588
}
589589
};
590590
if (request.temp_context) {
591-
webpg.plugin.getTemporaryPath(function(temp_path) {
592-
temp_path = temp_path.result || temp_path || "/tmp/.gnupg";
593-
webpg.plugin.gpgSetHomeDir(temp_path, attemptImport);
591+
webpg.plugin.getTemporaryPath(function(path) {
592+
path = path.result || path || "/tmp/.gnupg";
593+
webpg.plugin.gpgSetHomeDir(path, attemptImport);
594594
});
595595
} else {
596596
attemptImport();
@@ -720,7 +720,7 @@ webpg.background = {
720720
case 'getNamedKey':
721721
webpg.utils.info("getNamedKey requested");
722722
request.bypassSendResult = true;
723-
function getNamedKey() {
723+
var getNamedKey = function() {
724724
webpg.plugin.getNamedKey(request.key_id, false, false, function(response) {
725725
if (request.temp_context) {
726726
webpg.plugin.gpgSetHomeDir(gnupghome, function() {
@@ -741,10 +741,9 @@ webpg.background = {
741741
});
742742
}
743743
if (request.temp_context) {
744-
webpg.plugin.getTemporaryPath(function(temp_path) {
745-
if (!temp_path)
746-
temp_path = "/tmp/.gnupg";
747-
webpg.plugin.gpgSetHomeDir(temp_path, function() {
744+
webpg.plugin.getTemporaryPath(function(path) {
745+
path = path.result || temp_path || "/tmp/.gnupg";
746+
webpg.plugin.gpgSetHomeDir(path, function() {
748747
getNamedKey();
749748
});
750749
});
@@ -872,6 +871,7 @@ webpg.background = {
872871
break;
873872

874873
}
874+
875875
// Return the response and let the connection be cleaned up.
876876
if (request.bypassSendResult !== true)
877877
sendResponse({'result': response});

extension/webpg_results.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ webpg.inline_results = {
395395
for (var imported in import_status.imports) {
396396
if (import_status.imports[imported].fingerprint != "unknown"
397397
&& import_status.imports[imported].result === "Success") {
398-
key_id = import_status.imports[imported].fingerprint;
398+
var key_id = import_status.imports[imported].fingerprint;
399399
webpg.utils.sendRequest({
400400
'msg': "getNamedKey",
401401
'key_id': key_id,

0 commit comments

Comments
 (0)