forked from mailvelope/mailvelope
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major refactoring and Firefox support
- Loading branch information
Thomas Oberndörfer
committed
Oct 12, 2012
1 parent
574c9d3
commit 2039f03
Showing
511 changed files
with
8,618 additions
and
5,923 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
*~ | ||
.directory | ||
*.sublime* | ||
.svn | ||
.svn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "dep/chrome/openpgpjs"] | ||
path = dep/chrome/openpgpjs | ||
url = git://github.com/toberndo/openpgpjs.git | ||
[submodule "firefox/packages/ppg-api"] | ||
path = firefox/packages/ppg-api | ||
url = git://github.com/invi/ppg-api.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,54 @@ | ||
|
||
PROFILEDIR = ~/dev/firefox/mailvelope | ||
|
||
default: help | ||
|
||
help: | ||
@echo "pack - concatenate content script files" | ||
@echo "minify - minify content script files" | ||
@echo "build-cs - pack & minify content script files" | ||
@echo "copy-common - copy common folder to Chrome and Firefox directories" | ||
@echo "copy-dep - copy openpgp.js library to Chrome directory" | ||
@echo "test-build - pack content scripts and copy common folder" | ||
@echo "build - build content scripts and copy common folder" | ||
@echo "start-ff - run addon in Firefox" | ||
@echo "test-ff - do test-build & run addon in Firefox" | ||
|
||
pack: | ||
@echo Concatenate content script files... | ||
@cat src/lib/jquery-1.8.custom.js src/content_scripts/decryptFrame.js src/content_scripts/encryptFrame.js src/content_scripts/main-cs.js > src/content_scripts/build/cs-mailvelope.js | ||
@cat common/dep/jquery.js common/ui/inline/mvelo.js common/ui/inline/main-cs.js common/ui/inline/decryptFrame.js common/ui/inline/encryptFrame.js > common/ui/inline/build/cs-mailvelope.js | ||
@echo Appending //@ sourceURL=cs-mailvelope.js... | ||
@echo '//@ sourceURL=cs-mailvelope.js' >> src/content_scripts/build/cs-mailvelope.js | ||
@echo '//@ sourceURL=cs-mailvelope.js' >> common/ui/inline/build/cs-mailvelope.js | ||
|
||
compile: | ||
minify: | ||
@echo Running http://code.google.com/closure/compiler/... | ||
@java -jar res/closure-compiler/compiler.jar --js=src/lib/jquery-1.8.custom.js --js=src/content_scripts/decryptFrame.js --js=src/content_scripts/encryptFrame.js --js=src/content_scripts/main-cs.js --js_output_file=src/content_scripts/build/cs-mailvelope.min.js | ||
@java -jar res/closure-compiler/compiler.jar --js=common/dep/jquery.js --js=common/ui/inline/mvelo.js --js=common/ui/inline/main-cs.js --js=common/ui/inline/decryptFrame.js --js=common/ui/inline/encryptFrame.js --js_output_file=common/ui/inline/build/cs-mailvelope.min.js | ||
@echo Appending //@ sourceURL=cs-mailvelope.min.js... | ||
@echo '//@ sourceURL=cs-mailvelope.min.js' >> src/content_scripts/build/cs-mailvelope.min.js | ||
@echo '//@ sourceURL=cs-mailvelope.min.js' >> common/ui/inline/build/cs-mailvelope.min.js | ||
|
||
build-cs: pack minify | ||
|
||
copy-common: | ||
@echo Update common folder... | ||
@cp -ur common/* chrome/common | ||
@cp -ur common/* firefox/data/common | ||
|
||
copy-dep: | ||
@echo Update openpgp.js files... | ||
@cp -u dep/chrome/openpgpjs/resources/openpgp.js chrome/dep | ||
@cp -u dep/chrome/openpgpjs/resources/openpgp.min.js chrome/dep | ||
|
||
test-build: pack copy-common copy-dep | ||
|
||
build: build-cs copy-common | ||
|
||
dist-ff: | ||
@echo package add-on as an XPI file in dist folder | ||
@cfx xpi --pkgdir=firefox | ||
@mv mailvelope.xpi dist | ||
|
||
minify: pack compile | ||
start-ff: | ||
@echo Start Firefox... | ||
@cfx run --pkgdir=firefox --profiledir=$(PROFILEDIR) | ||
|
||
test-ff: test-build start-ff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script data-main="background" src="require.js"></script> | ||
</head> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,214 @@ | ||
/** | ||
* Mailvelope - secure email with OpenPGP encryption for Webmail | ||
* Copyright (C) 2012 Thomas Oberndörfer | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License version 3 | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
requirejs.config({ | ||
paths: { | ||
jquery: 'common/dep/jquery.min', | ||
openpgp: 'dep/openpgp' | ||
}, | ||
shim: { | ||
'openpgp': { | ||
deps: ['jquery'], | ||
exports: 'openpgp' | ||
} | ||
} | ||
}); | ||
|
||
define(["common/lib/controller", "lib/pgpViewModel", "openpgp", "jquery"], function(controller, model, openpgp, $) { | ||
|
||
// inject content script only once per time slot | ||
var injectTimeSlot = 600; | ||
// injection time slot currently open | ||
var injectOpen = true; | ||
// optimized cs injection variant, bootstrap code injected that loads cs | ||
var injectOptimized = true; | ||
// keep reloaded iframes | ||
var frameHosts = []; | ||
// content script coding as string | ||
var csCode = ''; | ||
|
||
function init() { | ||
controller.extend({initScriptInjection: initScriptInjection}); | ||
openpgp.init(); | ||
initDefaults(function() { | ||
migrate(); | ||
initConnectionManager(); | ||
initContextMenu(); | ||
initScriptInjection(); | ||
initMessageListener(); | ||
}); | ||
} | ||
|
||
function initDefaults(done) { | ||
// apply defaults if don't exist | ||
if (model.getWatchList() === null) { | ||
$.get(chrome.extension.getURL('common/res/defaults.json'), function(data) { | ||
model.setWatchList(data.watch_list); | ||
done(); | ||
}, 'json'); | ||
} else { | ||
done(); | ||
} | ||
} | ||
|
||
function initConnectionManager() { | ||
// store incoming connections by name and id | ||
chrome.extension.onConnect.addListener(function(port) { | ||
//console.log('ConnectionManager: onConnect:', port); | ||
controller.addPort(port); | ||
port.onMessage.addListener(controller.handlePortMessage); | ||
// update active ports on disconnect | ||
port.onDisconnect.addListener(controller.removePort); | ||
}); | ||
} | ||
|
||
function initMessageListener() { | ||
chrome.extension.onMessage.addListener( | ||
function(request, sender, sendResponse) { | ||
switch (request.event) { | ||
// for content scripts requesting code | ||
case 'get-cs': | ||
sendResponse({code: csCode}); | ||
break; | ||
case 'get-tabid': | ||
sendResponse({tabid: sender.tab.id}); | ||
break; | ||
default: | ||
controller.handleMessageEvent(request, sender, sendResponse); | ||
} | ||
} | ||
); | ||
} | ||
|
||
function initContextMenu() { | ||
chrome.contextMenus.create({ | ||
"title": "Encrypt", | ||
"contexts": ["page", "frame", "selection", "link", "editable"], | ||
"onclick": onContextMenuEncrypt | ||
}); | ||
} | ||
|
||
function onContextMenuEncrypt(info) { | ||
//console.log(info); | ||
chrome.tabs.getSelected(null, function(tab) { | ||
chrome.tabs.sendMessage(tab.id, {event: "context-encrypt"}); | ||
}); | ||
} | ||
|
||
function initScriptInjection() { | ||
|
||
if (injectOptimized && csCode === '') { | ||
// load content script | ||
$.get(chrome.extension.getURL('common/ui/inline/build/cs-mailvelope.js'), function(data) { | ||
csCode = data; | ||
}); | ||
} | ||
|
||
var filterURL = controller.getWatchListFilterURLs(); | ||
|
||
filterURL = filterURL.map(function(host) { | ||
return '*://' + host + '/*'; | ||
}); | ||
|
||
var filterType = ["main_frame", "sub_frame"]; | ||
|
||
var requestFilter = { | ||
urls: filterURL, | ||
types: filterType | ||
} | ||
chrome.webRequest.onCompleted.removeListener(watchListRequestHandler); | ||
if (filterURL.length !== 0) { | ||
chrome.webRequest.onCompleted.addListener(watchListRequestHandler, requestFilter); | ||
} | ||
} | ||
|
||
function watchListRequestHandler(details) { | ||
// store frame URL | ||
frameHosts.push(model.getHost(details.url)); | ||
if (injectOpen || details.type === "main_frame") { | ||
setTimeout(function() { | ||
if (frameHosts.length === 0) { | ||
// no requests since last inject | ||
return; | ||
} | ||
//console.log('cs injected'); | ||
var scriptDetails; | ||
if (injectOptimized) { | ||
scriptDetails = {code: csBootstrap(), allFrames: true} | ||
} else { | ||
scriptDetails = {file: "common/ui/inline/build/cs-mailvelope.js", allFrames: true} | ||
} | ||
chrome.tabs.executeScript(details.tabId, scriptDetails, function() { | ||
chrome.tabs.insertCSS(details.tabId, {file: "common/ui/inline/framestyles.css", allFrames: true}); | ||
// open injection time slot | ||
injectOpen = true; | ||
}); | ||
// reset buffer after injection | ||
frameHosts.length = 0; | ||
}, injectTimeSlot); | ||
// close injection time slot | ||
injectOpen = false; | ||
} | ||
} | ||
|
||
function csBootstrap() { | ||
return " \ | ||
if (!document.mailvelopeControl) { \ | ||
var hosts = " + JSON.stringify(frameHosts) + "; \ | ||
var match = hosts.some(function(host) { \ | ||
return host === document.location.host; \ | ||
}); \ | ||
if (match) { \ | ||
chrome.extension.sendMessage({event: 'get-cs'}, function(response) { \ | ||
eval(response.code); \ | ||
}); \ | ||
} \ | ||
} \ | ||
"; | ||
} | ||
|
||
function migrate() { | ||
// migration | ||
migrateTo0420(); | ||
} | ||
|
||
function migrateTo0420() { | ||
for (var i = 0; i < openpgp.keyring.privateKeys.length; i++) { | ||
// check if corresponding public key | ||
var found = openpgp.keyring.getPublicKeysForKeyId(openpgp.keyring.privateKeys[i].obj.getKeyId()); | ||
if (found.length === 0) { | ||
// create public key from private key | ||
var pubArmored = openpgp.keyring.privateKeys[i].obj.extractPublicKey(); | ||
if (pubArmored === null) { | ||
// remove private key | ||
openpgp.keyring.removePrivateKey(i); | ||
i--; | ||
} else { | ||
// import public key | ||
var pubKey = openpgp.read_publicKey(pubArmored); | ||
for (var j = 0; j < pubKey.length; j++) { | ||
openpgp.keyring.publicKeys.push({armored: pubArmored, obj: pubKey[j], keyId: pubKey[j].getKeyId()}); | ||
} | ||
openpgp.keyring.store(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
init(); | ||
|
||
}); |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.