Skip to content

Commit

Permalink
Changes for v0.9.4
Browse files Browse the repository at this point in the history
* Added translations status to about page
* Fixed some issues in Conkeror
* Changes to key selection when signing/encrypting; work towards #76 and #77
* Fixed notification icon
* Improved GMAIL parsing of PGP messages
* Improved Thunderbird parsing of PGP messages
* Added option to set the inline parsing display mode
* Added more default inline parsing blacklist entries
  • Loading branch information
kylehuff committed Apr 18, 2013
1 parent fc88ce7 commit 70f6301
Show file tree
Hide file tree
Showing 13 changed files with 520 additions and 188 deletions.
5 changes: 4 additions & 1 deletion extension/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@
<span class="webpg-info assuan-version-label"></span>: <span class="webpg-info assuan-version"></span><br/>
</div><br/>
</span>
<div id="translation-status" style="min-width: 700px;">
<input type='button' id='translation-status-link' value="Translation Status"/>
</div>
<div id="window_functions" style="width:100%; text-align:right; clear:left;">
<br/><br/><input type='button' id='close' value='Finished'>
<br/><br/><input type='button' id='close' value='Finished'/>
</div>
</div>
</div>
Expand Down
41 changes: 33 additions & 8 deletions extension/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ webpg.about = {
browserString = "SeaMonkey";
document.getElementById("webpg-info-browser").innerHTML += browserString;
if (!browserWindow) {
webpg.plugin = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow).webpg.plugin;
} else {
webpg.plugin = browserWindow.webpg.plugin;
var browserWindow = webpg.utils.mozilla.getChromeWindow();
}
webpg.plugin = browserWindow.webpg.plugin;
} else if (navigator.userAgent.toLowerCase().search("chrome") > -1) {
browserString = "Chrome";
document.getElementById("webpg-info-browser").innerHTML += browserString;
Expand Down Expand Up @@ -152,6 +146,37 @@ webpg.about = {

webpg.jq('#close').button().button("option", "label", _("Finished"))
.click(function(e) { window.top.close(); });

webpg.jq('#translation-status-link').click(function() {
webpg.jq('#translation-status')
.load('https://translations.launchpad.net/webpg-chrome/trunk/+pots/webpg #language-chart',
function(responseText, status, xhrObject) {
if (status == "success") {
webpg.jq("#language-chart").find('tr').find('td:gt(2), th:gt(2)').hide();
webpg.jq("#language-chart").find('tr').find('td:gt(4), th:gt(4)').show();
webpg.jq("#language-chart").find('a').each(function() {
this.href = this.href.replace(/.*?\:\/\/.*?\//, "https://translations.launchpad.net/")
});
webpg.jq("#language-chart").find('img').each(function() {
this.src = this.src.replace(/.*?\:\/\/.*?\//, "https://translations.launchpad.net/")
});
webpg.jq("#language-chart").find('.sortkey').each(function() {
if (!webpg.jq(this).next()[0]) {
webpg.jq(this.nextSibling).remove();
} else {
if (webpg.jq(this).next()[0].nodeName == 'IMG')
webpg.jq(this).remove();
else
webpg.jq(this).next().remove();
}
})
webpg.jq("#language-chart").css({
'text-align': 'left',
'color': '#fff',
}).find('th').css({'border': '1px solid #F22'});
}
});
}).button().button("option", "label", _("Translation Status"));
}
}

Expand Down
67 changes: 41 additions & 26 deletions extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ webpg.background = {

if (webpg.utils.detectedBrowser['vendor'] == 'mozilla'
&& webpg.utils.detectedBrowser['product'] != 'thunderbird') {
var tabID = gBrowser.getBrowserForDocument(sender.defaultView.top.content.document)._webpgTabID;

try {
if (webpg.utils.detectedBrowser['product'] == 'conkeror')
var tabID = window.buffers.current.browser._webpgTabID;
else
var tabID = gBrowser.getBrowserForDocument(sender.defaultView.top.content.document)._webpgTabID;
} catch (err) {
}

sender.tab = {
'id': tabID,
'selected': true,
Expand Down Expand Up @@ -183,13 +191,11 @@ webpg.background = {
break;

case 'updateStatusBar':
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var winType = (webpg.utils.detectedBrowser['product'] == "thunderbird") ?
"mail:3pane" : "navigator:browser";
var browserWindow = wm.getMostRecentWindow(winType);
browserWindow.document.getElementById("webpg-results-trusted-hover").value = request.statusText;
browserWindow.document.getElementById("webpg-results-trusted-hover").style.display = (request.statusText.length > 0) ? '' : 'none';
var browserWindow = webpg.utils.mozilla.getChromeWindow();
if (browserWindow.document.getElementById("webpg-results-trusted-hover")) {
browserWindow.document.getElementById("webpg-results-trusted-hover").value = request.statusText;
browserWindow.document.getElementById("webpg-results-trusted-hover").style.display = (request.statusText.length > 0) ? '' : 'none';
}
break;

case 'decrypt':
Expand Down Expand Up @@ -220,6 +226,15 @@ webpg.background = {
break;

case 'verify':
if (request.data && request.data.length > 0) {
content = request.data;
lowerBlock = content.match(/(-----BEGIN PGP.*?)\n.*?\n\n/gim);
if (lowerBlock && lowerBlock.length > 1) {
content.substr(0, content.indexOf(lowerBlock[1]) + lowerBlock[1].length)
+ content.substr(content.indexOf(lowerBlock[1]) + lowerBlock[1].length, content.length).replace(/\n\n/gim, "\n");
}
request.data = content;
}
if (request.message_event && request.message_event == "context") {
var content = (request.data) ? request.data :
request.selectionData.selectionText;
Expand Down Expand Up @@ -427,22 +442,24 @@ webpg.background = {
break;

case 'getNamedKeys':
var keyResults = {};
var userKeys = {};
var users = request.users;
for (var u in users) {
keyResults[users[u]] = webpg.plugin.getNamedKey(users[u]);
var i = -1;
for (i in keyResults[users[u]]) {
// nothing
}
if (i < 0) {
var group_result = webpg.preferences.group.get(users[u]);
for (var group in group_result) {
keyResults[users[u]] = webpg.plugin.getNamedKey(group_result[group]);
}
var key;
for (var u=0; u < users.length; u++) {
// Pull keys by named user
userKeys[users[u]] = [];
key = webpg.plugin.getNamedKey(users[u]);
if (JSON.stringify(key) !== "{}")
userKeys[users[u]] = userKeys[users[u]].concat(key);
// Pull keys by named group
var group_result = webpg.preferences.group.get(users[u]);
for (var group=0; group < group_result.length; group++) {
key = webpg.plugin.getNamedKey(group_result[group]);
if (JSON.stringify(key) !== "{}")
userKeys[users[u]] = userKeys[users[u]].concat(key);
}
}
response = {'keys': keyResults};
response = {'keys': userKeys};
break;

case 'export':
Expand Down Expand Up @@ -570,9 +587,7 @@ webpg.background = {

// Notify the user
if (webpg.utils.detectedBrowser['vendor'] == "mozilla") {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var browserWindow = wm.getMostRecentWindow("navigator:browser");
var browserWindow = webpg.utils.mozilla.getChromeWindow();
var message = (valid) ? 'WebPG - ' + _("Key Generation Complete") + '!' :
"WebPG " + _("Key Generation") + " " + data;
var nb = browserWindow.getNotificationBox(browserWindow.content);
Expand All @@ -593,15 +608,15 @@ webpg.background = {
}] : [];
var priority = nb.PRIORITY_INFO_MEDIUM;
nb.appendNotification(message, 'keygen-complete',
'chrome://webpg-firefox/skin/images/webpg-32.png',
'chrome://webpg-firefox/skin/images/badges/32x32/webpg.png',
priority, buttons);
} else if (webpg.utils.detectedBrowser['product'] == "chrome") {
var title = (valid) ? "WebPG - " + _("Key Generation Complete") + "!" :
_("WebPG Key Generation Failed") + "!";
var message = (valid) ? _("The generation of your new key is now complete") + "." :
_("Key Generation") + " " + data;
var notification = webkitNotifications.createNotification(
'skin/images/webpg-48.png',
'skin/images/badges/48x48/webpg.png',
title,
message
);
Expand Down
7 changes: 1 addition & 6 deletions extension/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ webpg.error = {
if (webpg.utils.detectedBrowser['product'] == "chrome") {
webpg.background = chrome.extension.getBackgroundPage().webpg;
} else {
webpg.background = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow).webpg;
webpg.background = webpg.utils.mozilla.getChromeWindow().webpg;
}

var error_map = webpg.background.plugin.webpg_status;
Expand Down
67 changes: 50 additions & 17 deletions extension/gmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ webpg.gmail = {
// the email.
webpg.gmail.checkRecipients(function(recipKeys) {
var users = [];
for (var key in recipKeys) {
users.push(recipKeys[key].fingerprint.substr(-16));
for (var keyItem in recipKeys) {
for (var key in recipKeys[keyItem]) {
users.push(recipKeys[keyItem][key].fingerprint.substr(-16));
}
}
if (message.search("-----BEGIN PGP") == 0) {
var send = confirm(_("This message already contains PGP data")
Expand Down Expand Up @@ -233,8 +235,12 @@ webpg.gmail = {
return;
}
webpg.gmail.checkRecipients(function(recipKeys) {
// TODO: Check that the keys are good for this operation
var users = webpg.gmail.getRecipients();
var users = [];
for (var keyItem in recipKeys) {
for (var key in recipKeys[keyItem]) {
users.push(recipKeys[keyItem][key].fingerprint.substr(-16));
}
}
webpg.utils.sendRequest({'msg': 'encryptSign',
'data': message,
'recipients': users,
Expand Down Expand Up @@ -301,28 +307,53 @@ webpg.gmail = {
var _ = webpg.utils.i18n.gettext;
webpg.gmail.removeStatusLine();
var users = webpg.gmail.getRecipients();
// Get the keys for the named users/groups
webpg.utils.sendRequest({'msg': 'getNamedKeys',
'users': users
}, function(response) {
var recipKeys = {};
var keys = response.result.keys;
for (var u in keys) {
for (var k in keys[u]) {
recipKeys[u] = keys[u][k];
recipKeys[u] = [];
for (var i in keys[u]) {
for (var k in keys[u][i]) {
if (!keys[u][i][k].disabled)
recipKeys[u] = recipKeys[u].concat(keys[u][i][k]);
}
}
}
var notAllKeys = false;
var missingKeys = [];
for (var u in users) {
if (!(users[u] in recipKeys)) {
if (!(users[u] in recipKeys) || recipKeys[users[u]].length < 1) {
notAllKeys = true;
missingKeys.push(users[u]);
}
}
// Check for expired keys that are not disabled and inform the user
var expiredKeys = []
for (var u in keys) {
for (var i in keys[u]) {
for (var k in keys[u][i]) {
if (!keys[u][i][k].disabled && keys[u][i][k].expired) {
expiredKeys.push(u);
notAllKeys = true;
}
}
}
}

if (notAllKeys) {
var status = _("You do not have any keys for") + " " +
missingKeys.toString().
replace(/((,))/g, "<br/>" + _("or") + " ").replace(",", " ");
status = "";
if (missingKeys.length > 0) {
status += _("You do not have any keys for") + " <br/><div style='padding-left:12px;'>" +
missingKeys.toString().
replace(/((,))/g, "<br/>" + _("or") + " ").replace(",", " ") + "</div>";
}
if (expiredKeys.length > 0) {
status += _("Expired keys found for") + ":<br/><div style='padding-left:12px;'>" + expiredKeys.toString().
replace(/((,))/g, "<br/>" + _("and") + " ").replace(",", " ") + "</div>";
}
webpg.gmail.displayStatusLine(status);
} else {
if (callback)
Expand All @@ -341,21 +372,23 @@ webpg.gmail = {
displayStatusLine: function(message) {
var canvasFrame = webpg.gmail.getCanvasFrame();
var status_line = (webpg.gmail.gmailComposeType == "inline") ?
canvasFrame.find(".Hp") : canvasFrame.find(".fN");
canvasFrame.find(".Hp, .aDk") : canvasFrame.find(".fN");

if (!status_line.length > 0) {
canvasFrame.find(".webpg-status-line-holder").remove();
status_line = webpg.jq("<span style='margin-top:10px;' class='webpg-status-line-holder'></span>").insertBefore(webpg.gmail.getCanvasFrameDocument().querySelector("div>.nH.nH .ip.adB .I5 form"));
status_line = webpg.jq("<span class='webpg-status-line-holder'></span>").insertBefore(webpg.gmail.getCanvasFrameDocument().querySelector("div>.nH.nH .ip.adB .I5 form"));
}
canvasFrame.find(".webpg-status-line").remove();
var status_msg = webpg.gmail.getCanvasFrameDocument().createElement("span");
var cssClass = (webpg.gmail.gmailComposeType == "inline") ?
"webpg-gmail-inline-status-line" :
"webpg-gmail-status-line";
status_msg.setAttribute("class", "webpg-status-line " + cssClass);
webpg.jq(status_msg).html("WebPG:<br/>" + webpg.descript(message));
webpg.jq(status_msg).html("<div style='margin-top:4px; max-height: 64px; overflow: auto; width: 100%;'>WebPG -- " + webpg.descript(message) + "</div>");
if (webpg.gmail.gmailComposeType == "inline") {
var new_status = status_line.clone().addClass("webpg-status-line")
.addClass("webpg-gmail-status-line");
new_status.css({'width': '100%'});
new_status.html(status_msg);
status_line.parent().append(new_status);
} else {
Expand Down Expand Up @@ -690,7 +723,7 @@ webpg.gmail = {
})
}
if (msg_container.length > 0) {
// Determine if we are in plaintext mode in inline mode
// Determine if we are in plaintext mode or inline mode
var plaintext = (webpg.gmail.getCanvasFrame().contents().find('form').find("input[name=ishtml]").val() != "1");
console.log((plaintext) ? "plaintext" : "richtext");
if (msg_container[0].nodeName == "TEXTAREA") {
Expand All @@ -707,7 +740,7 @@ webpg.gmail = {
}
} else {
//console.log("RICHTEXT");
msg_container.html(message);
msg_container.html(message.replace(/\n/gim, "<br>"));
}
}
}
Expand Down Expand Up @@ -825,7 +858,7 @@ webpg.utils.sendRequest({
function(aEvent) {
// We need to filter based on the URL for mozilla, as we do
// not have the option to set the overlay by URL
if (content.location.host == "mail.google.com") {
if (aEvent.originalTarget.location.host == "mail.google.com") {
webpg.gmail.getCanvasFrameDocument()
.addEventListener("DOMSubtreeModified",
webpg.gmail.gmailChanges, false
Expand Down Expand Up @@ -857,7 +890,7 @@ webpg.utils.sendRequest({
function(aEvent) {
// We need to filter based on the URL for mozilla, as we do
// not have the option to set the overlay by URL
if (content.location.host == "mail.google.com") {
if (aEvent.originalTarget.location.host == "mail.google.com") {
observer.observe(webpg.gmail.getCanvasFrameDocument(), config);
}
},
Expand Down
Loading

0 comments on commit 70f6301

Please sign in to comment.