Skip to content

Commit 833c45d

Browse files
committed
implement nativeMessaging API in chrome and child_process in FF
1 parent 5ec91df commit 833c45d

15 files changed

+858
-1107
lines changed

extension/API/libwebpg/ctypes.js

-594
This file was deleted.

extension/API/libwebpg/nativeMessaging.js

+309-59
Large diffs are not rendered by default.

extension/XULContent/firefoxOverlay.xul

+1-7
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
</script>
9393
<script src="../constants.js"/>
9494
<script src="../utils.js"/>
95-
<!-- <script src="../API/libwebpg/ctypes.js"/>-->
95+
<script src="../API/libwebpg/nativeMessaging.js"/>
9696
<script src="../preferences.js"/>
9797
<script src="../background.js"/>
9898
<script src="../inline.js"/>
@@ -158,10 +158,4 @@
158158
</statusbarpanel>
159159
</statusbar>
160160
<!-- Status bar -->
161-
162-
<window id="main-window">
163-
<vbox collapsed="true">
164-
<html:object id="webpgPlugin" type="application/x-webpg" height="1" width="1" style="visibility:hidden;"></html:object>
165-
</vbox>
166-
</window>
167161
</overlay>

extension/background.js

+161-153
Large diffs are not rendered by default.

extension/buttonbar.js

+24-23
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ webpg.jq(function() {
103103
webpg.jq(form)[0].style.display = "none";
104104
webpg.jq("#genkey-dialog")[0].style.height = "20";
105105
webpg.jq("#genkey-dialog")[0].style.display = "none";
106-
response = webpg.plugin.gpgGenKey(
106+
webpg.plugin.gpgGenKey(
107107
form.publicKey_algo.value,
108108
form.publicKey_size.value,
109109
form.subKey_algo.value,
@@ -115,7 +115,7 @@ webpg.jq(function() {
115115
form.passphrase.value,
116116
webpg.keymanager.progressMsg
117117
);
118-
webpg.jq("#genkey-dialog").dialog("option", "buttons", [{
118+
webpg.jq("#genkey-dialog").dialog("option", "buttons", [{
119119
'text': _("Close"),
120120
'click': function() {
121121
webpg.jq("#genkey-dialog").dialog("close");
@@ -197,30 +197,31 @@ webpg.jq(function() {
197197
if (e.target.result.substr(0,15) != "-----BEGIN PGP")
198198
e.target.error = true;
199199
if (e.target.error) {
200-
webpg.jq("#import-list").html("<ul><li><strong><span class='error-text' style='padding-right:12px;'>" +
201-
_("Error") + ":</span>" +
202-
_("There was an error parsing this PGP file") +
200+
webpg.jq("#import-list").html("<ul><li><strong><span class='error-text' style='padding-right:12px;'>" +
201+
_("Error") + ":</span>" +
202+
_("There was an error parsing this PGP file") +
203203
"</strong></li></ul>"
204204
);
205205
return false;
206206
}
207207
var result = {'error': true};
208-
result = webpg.plugin.gpgImportKey(e.target.result);
209-
if (result.considered < 1) {
210-
webpg.utils.log("INFO")(result);
211-
msg = ["<ul><li><strong><span class='error-text' style='padding-right:12px;'>",
212-
_("Error"), ":</span>", _("There was an error importing any keys in this file"),
213-
"</strong></li>"];
214-
msg.push("</ul>");
215-
webpg.jq("#import-list").html(msg.join(''));
216-
} else {
217-
webpg.jq("#importkey_name")[0].value = '';
218-
webpg.jq("#importkey-dialog").dialog("destroy");
219-
webpg.private_scope.search();
220-
webpg.private_scope.$apply();
221-
webpg.public_scope.search();
222-
webpg.public_scope.$apply();
223-
}
208+
webpg.plugin.gpgImportKey(e.target.result, function(result) {
209+
if (result.considered < 1) {
210+
webpg.utils.log("INFO")(result);
211+
msg = ["<ul><li><strong><span class='error-text' style='padding-right:12px;'>",
212+
_("Error"), ":</span>", _("There was an error importing any keys in this file"),
213+
"</strong></li>"];
214+
msg.push("</ul>");
215+
webpg.jq("#import-list").html(msg.join(''));
216+
} else {
217+
webpg.jq("#importkey_name")[0].value = '';
218+
webpg.jq("#importkey-dialog").dialog("destroy");
219+
webpg.private_scope.search();
220+
webpg.private_scope.$apply();
221+
webpg.public_scope.search();
222+
webpg.public_scope.$apply();
223+
}
224+
});
224225
};
225226
})(f);
226227
reader.readAsBinaryString(f);
@@ -237,8 +238,8 @@ webpg.jq(function() {
237238
.parent()
238239
.animate({"opacity": 1.0}, 1, function() {
239240
webpg.jq("#importkey_button").attr("disabled", true);
240-
webpg.jq(this).find("#import-list").html("<ul><li><strong>" +
241-
_("Please use the button above to open a key file (.asc/.txt)") +
241+
webpg.jq(this).find("#import-list").html("<ul><li><strong>" +
242+
_("Please use the button above to open a key file (.asc/.txt)") +
242243
"</strong></li></ul>"
243244
);
244245
webpg.jq(this).find("#importkey_name")[0].addEventListener('change', function(e) {

extension/constants.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/* <![CDATA[ */
22
if (typeof(webpg)=='undefined') { webpg = {}; }
33

4+
/*
5+
Used to identify global variables added to the window object
6+
*/
47
webpg.globalTester = (function(){
58
var fields = {};
69
var before = function(w){
@@ -12,7 +15,7 @@ webpg.globalTester = (function(){
1215
var after = function(w){
1316
for(var field in w){
1417
if(!fields[field]){
15-
console.log(field + " has been added");
18+
console.debug(field, window[field]);
1619
}
1720
};
1821

@@ -28,14 +31,14 @@ webpg.globalTester.before(window);
2831
*/
2932
webpg.constants = {
3033

31-
debug: {
32-
LOG: true
33-
},
34+
LOG_LEVEL: 10,
3435

35-
LOG_LEVEL: {
36-
INFO: 'INFO',
37-
WARN: 'WARN',
38-
ERROR: 'ERROR'
36+
LOG_LEVELS: {
37+
TRACE: 20,
38+
DEBUG: 15,
39+
INFO: 10,
40+
WARN: 5,
41+
ERROR: 1
3942
},
4043

4144
/*

extension/dialog.html

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<script type="text/javascript" src="inline.js"></script>
1313
<script type="text/javascript" src="dialog.js"></script>
1414
<style>
15+
.ui-widget-overlay.ui-front {
16+
visibility: hidden;
17+
}
1518
.webpg-keylist-ul {
1619
padding:0px;
1720
margin:0px;

extension/dialog.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ webpg.dialog = {
138138
'threaded': true,
139139
'iframe_id': window.name});
140140
} else if (webpg.dialog.qs.dialog_type === "export") {
141-
webpg.pubkeylist = webpg.background.webpg.plugin.getPrivateKeyList();
141+
webpg.pubkeylist = webpg.background.webpg.secret_keys;
142142
} else if (webpg.dialog.qs.dialog_type === "import") {
143143
var import_data = unescape(webpg.dialog.qs.import_data);
144144
var pubkeys = import_data.split(webpg.constants.PGPTags.PGP_KEY_END);
@@ -159,14 +159,13 @@ webpg.dialog = {
159159
webpg.inline.PGPDataSearch(document, false, false, webpg.jq("#keylist_form")[0]);
160160
}
161161
webpg.keymanager.keylistprogress(webpg.pubkeylist);
162-
} else if (webpg.utils.detectedBrowser.product === "chrome") {
162+
} else if (webpg.utils.detectedBrowser.product === "chrome" || webpg.utils.detectedBrowser.product === "firefox") {
163163
if (webpg.dialog.qs.dialog_type === "encrypt" || webpg.dialog.qs.dialog_type === "encryptsign") {
164164
webpg.utils.sendRequest({
165165
"msg": "public_keylist",
166166
'fastlistmode': true,
167167
'threaded': true
168-
}
169-
);
168+
});
170169
} else if (webpg.dialog.qs.dialog_type === "export") {
171170
webpg.utils.sendRequest({"msg": "private_keylist"}, function(response) {
172171
webpg.pubkeylist = response.result;
@@ -199,12 +198,15 @@ webpg.dialog = {
199198
var post_selection = unescape(webpg.dialog.qs.post_selection) || "";
200199

201200
var iframe_id = window.name;
202-
203-
var signers = (webpg.dialog.qs.signers!==undefined &&
201+
202+
var signers = (webpg.dialog.qs.dialog_type==="encryptsign" &&
203+
webpg.dialog.qs.signers!==undefined &&
204204
unescape(webpg.dialog.qs.signers)!==null) ?
205205
[unescape(webpg.dialog.qs.signers)] : null;
206206

207-
webpg.utils.sendRequest({"msg": "encrypt",
207+
var msg = (webpg.dialog.qs.dialog_type === "encryptsign") ? "encryptSign" : "encrypt";
208+
209+
webpg.utils.sendRequest({"msg": msg,
208210
"data": unescape(webpg.dialog.qs.encrypt_data),
209211
"pre_selection": pre_selection,
210212
"post_selection": post_selection,
@@ -273,19 +275,20 @@ webpg.keymanager = {
273275
data = (data.hasOwnProperty('data')) ? data.data : data;
274276
if (data.status && data.status === "complete")
275277
return;
278+
276279
// Check if we recieved a key, or a key list
277280
// keylists need to be converted to individual keys and recall this
278281
// this method.
279282
if (webpg.utils.detectedBrowser.vendor === "mozilla") {
280283
if (data.detail !== undefined &&
281284
data.detail.type === "key") {
282285
port = "port";
283-
data = data.detail;
284-
} else if (typeof(data) === "object" &&
285-
Object.keys(data).length < 2) {
286-
return;
286+
data = data.detail.data;
287+
} else if (data.protocol && data.protocol === "OpenPGP") {
288+
port = "port";
287289
}
288290
}
291+
289292
if (port === undefined) {
290293
webpg.jq("ul#keylist").empty();
291294
for (var idx in data) {

extension/inline.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ webpg.inline = {
660660
'data': scontent,
661661
'target_id': results_frame.id },
662662
function(response) {
663-
webpg.utils.log("DEBUG")(response);
664663
if (response.result.signatures && response.result.data)
665664
blockType = webpg.constants.PGPBlocks.PGP_SIGNED_MSG;
666665
else
@@ -1061,7 +1060,7 @@ webpg.inline = {
10611060
"border: 1px solid gainsboro; clear: left; line-height: 12px;" +
10621061
"left: -1px; text-shadow: none; text-decoration: none; overflow: visible;" +
10631062
"box-sizing: content-box !important; -moz-box-sizing: content-box !important;" +
1064-
"-webkit-box-sizing: content-box !important; white-space: normal; z-index: 999;");
1063+
"-webkit-box-sizing: content-box !important; white-space: normal; z-index: 10;");
10651064

10661065
toolbar.setAttribute("class", "webpg-toolbar");
10671066
var offset = (element.scrollHeight < element.offsetHeight) ?
@@ -1114,7 +1113,7 @@ webpg.inline = {
11141113
'&nbsp;' +
11151114
'</span>' +
11161115
'</span>' +
1117-
'<span style="z-index:4; font: inherit;">' +
1116+
'<span style="z-index:20; font: inherit;">' +
11181117
'<ul class="webpg-action-list">' +
11191118
'<li class="webpg-action-btn" style="font: inherit;">' +
11201119
'<a class="webpg-toolbar-encrypt">' +
@@ -1294,8 +1293,13 @@ webpg.inline = {
12941293
var element_value = null;
12951294

12961295
if (element.offsetLeft != toolbar.offsetLeft && element.style.display !== 'none') {
1297-
if (webpg.jq(element).css('position') === 'relative')
1298-
toolbar.style.zIndex = webpg.jq(element).css('z-index') + 1;
1296+
if (webpg.jq(element).css('position') === 'relative') {
1297+
var zindex = webpg.jq(element).css('z-index');
1298+
if (!parseInt(zindex))
1299+
zindex = 1;
1300+
webpg.jq(element).css('z-index', zindex)
1301+
toolbar.style.zIndex = zindex + 1;
1302+
}
12991303

13001304
if (webpg.jq(element).parent().css('position') === 'relative')
13011305
toolbar.style.marginLeft = element.offsetLeft + 1;

0 commit comments

Comments
 (0)