Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebExtension (Firefox) compatibility for chromeIPass #595

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c9d88b9
chromeipass: Initial WebExtension support for Firefox
projectgus Feb 15, 2017
91eabf1
chromeipass: Add browser-polyfill for Chrome compatibility (part tested)
projectgus Feb 16, 2017
b316d6e
chromeipass: Fix usage of webextension getBackgroundPage (returns pro…
projectgus Feb 19, 2017
863e846
chromeipass: Display "Generate Password" key icons on Firefox
projectgus Feb 19, 2017
955a063
chromeipass: Move clipboard copy operation to foreground tab (FF compat)
projectgus Feb 19, 2017
8a897b3
chromeipass: Re-enable onAuthRequested (HTTP Auth) for Chrome, hide o…
projectgus Feb 19, 2017
37ea426
chromeipass: Hide Chrome Web Store link on settings page, if not Chro…
projectgus Feb 19, 2017
3b17eaf
move cip.init() so it's run after everything is defined. seems to fix…
smorks Aug 15, 2017
6d89476
async httpauth working for firefox (supported in firefox v54 and up)
smorks Aug 15, 2017
8da91c2
update version to 2.8.1
smorks Aug 15, 2017
b2222a9
remove unused pendingCallbacks, and reject the promise so it still pr…
smorks Aug 15, 2017
4ee91f8
update version to 2.8.2
smorks Aug 15, 2017
86ed1c3
hack to show alerts in firefox
smorks Aug 25, 2017
88a8187
update version to 2.8.3
smorks Aug 25, 2017
269a0fb
merge in latest from pfn, includes command api support (better hotkey…
smorks Aug 29, 2017
49f84b6
update version to 2.8.4, remove "Chrome" from description
smorks Aug 29, 2017
3ae33bf
first attempt at using storage api to store settings
smorks Aug 31, 2017
bc09e10
update project page to my own, add credits for firefox compatibility,…
smorks Aug 31, 2017
66940f7
update version to 2.8.5
smorks Aug 31, 2017
75c8838
whoops, properly remove old settings
smorks Aug 31, 2017
7b24957
add addon id
smorks Aug 31, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 47 additions & 46 deletions chromeipass/background/browserAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ browserAction.show = function(callback, tab) {
data = page.tabs[tab.id].stack[page.tabs[tab.id].stack.length - 1];
}

chrome.browserAction.setIcon({
browser.browserAction.setIcon({
tabId: tab.id,
path: "/icons/19x19/" + browserAction.generateIconName(data.iconType, data.icon)
});

if(data.popup) {
chrome.browserAction.setPopup({
browser.browserAction.setPopup({
tabId: tab.id,
popup: "popups/" + data.popup
});
Expand All @@ -34,12 +34,12 @@ browserAction.update = function(interval) {

var data = page.tabs[page.currentTabId].stack[page.tabs[page.currentTabId].stack.length - 1];

if(typeof data.visibleForMilliSeconds != "undefined") {
if(typeof data.visibleForMilliSeconds != "undefined") {
if(data.visibleForMilliSeconds <= 0) {
browserAction.stackPop(page.currentTabId);
browserAction.show(null, {"id": page.currentTabId});
page.clearCredentials(page.currentTabId);
return;
return;
}
data.visibleForMilliSeconds -= interval;
}
Expand All @@ -57,7 +57,7 @@ browserAction.update = function(interval) {
data.intervalIcon.index = 0;
}

chrome.browserAction.setIcon({
browser.browserAction.setIcon({
tabId: page.currentTabId,
path: "/icons/19x19/" + browserAction.generateIconName(null, data.intervalIcon.icons[data.intervalIcon.index])
});
Expand All @@ -74,10 +74,10 @@ browserAction.showDefault = function(callback, tab) {
stackData.iconType = "cross";
}

if(page.tabs[tab.id].loginList.length > 0) {
stackData.iconType = "questionmark";
stackData.popup = "popup_login.html";
}
if(page.tabs[tab.id].loginList.length > 0) {
stackData.iconType = "questionmark";
stackData.popup = "popup_login.html";
}

browserAction.stackUnshift(stackData, tab.id);

Expand Down Expand Up @@ -183,12 +183,12 @@ browserAction.removeRememberPopup = function(callback, tab, removeImmediately) {
}

if(page.tabs[tab.id].stack.length == 0) {
page.clearCredentials(tab.id);
page.clearCredentials(tab.id);
return;
}
var data = page.tabs[tab.id].stack[page.tabs[tab.id].stack.length - 1];

if(removeImmediately || !isNaN(data.visibleForPageUpdates)) {
if(removeImmediately || !isNaN(data.visibleForPageUpdates)) {
var currentMS = Date.now();
if( removeImmediately || (data.visibleForPageUpdates <= 0 && data.redirectOffset > 0)) {
browserAction.stackPop(tab.id);
Expand All @@ -199,47 +199,48 @@ browserAction.removeRememberPopup = function(callback, tab, removeImmediately) {
else if (!isNaN(data.visibleForPageUpdates) && data.redirectOffset > 0 && currentMS >= data.redirectOffset) {
data.visibleForPageUpdates = data.visibleForPageUpdates - 1;
}
}
}
};

browserAction.setRememberPopup = function(tabId, username, password, url, usernameExists, credentialsList) {
var settings = typeof(localStorage.settings)=='undefined' ? {} : JSON.parse(localStorage.settings);

var id = tabId || page.currentTabId;

var timeoutMinMillis = parseInt(getValueOrDefault(settings, "blinkMinTimeout", BLINK_TIMEOUT_REDIRECT_THRESHOLD_TIME_DEFAULT, 0)) ;
if (timeoutMinMillis > 0) {
timeoutMinMillis += Date.now();
}
var blinkTimeout = getValueOrDefault(settings, "blinkTimeout", BLINK_TIMEOUT_DEFAULT, 0);
var pageUpdateAllowance = getValueOrDefault(settings, "allowedRedirect", BLINK_TIMEOUT_REDIRECT_COUNT_DEFAULT, 0);
browser.storage.local.get({'settings': {}}).then(function(item) {
var settings = item.settings;
var id = tabId || page.currentTabId;

var stackData = {
visibleForMilliSeconds: blinkTimeout,
visibleForPageUpdates: pageUpdateAllowance,
redirectOffset: timeoutMinMillis,
level: 10,
intervalIcon: {
index: 0,
counter: 0,
max: 2,
icons: ["icon_remember_red_background_19x19.png", "icon_remember_red_lock_19x19.png"]
},
icon: "icon_remember_red_background_19x19.png",
popup: "popup_remember.html"
}
var timeoutMinMillis = parseInt(getValueOrDefault(settings, "blinkMinTimeout", BLINK_TIMEOUT_REDIRECT_THRESHOLD_TIME_DEFAULT, 0)) ;
if (timeoutMinMillis > 0) {
timeoutMinMillis += Date.now();
}
var blinkTimeout = getValueOrDefault(settings, "blinkTimeout", BLINK_TIMEOUT_DEFAULT, 0);
var pageUpdateAllowance = getValueOrDefault(settings, "allowedRedirect", BLINK_TIMEOUT_REDIRECT_COUNT_DEFAULT, 0);

var stackData = {
visibleForMilliSeconds: blinkTimeout,
visibleForPageUpdates: pageUpdateAllowance,
redirectOffset: timeoutMinMillis,
level: 10,
intervalIcon: {
index: 0,
counter: 0,
max: 2,
icons: ["icon_remember_red_background_19x19.png", "icon_remember_red_lock_19x19.png"]
},
icon: "icon_remember_red_background_19x19.png",
popup: "popup_remember.html"
}

browserAction.stackPush(stackData, id);
browserAction.stackPush(stackData, id);

page.tabs[id].credentials = {
"username": username,
"password": password,
"url": url,
"usernameExists": usernameExists,
"list": credentialsList
};
page.tabs[id].credentials = {
"username": username,
"password": password,
"url": url,
"usernameExists": usernameExists,
"list": credentialsList
};

browserAction.show(null, {"id": id});
browserAction.show(null, {"id": id});
});
}

function getValueOrDefault(settings, key, defaultVal, min) {
Expand All @@ -264,4 +265,4 @@ browserAction.generateIconName = function(iconType, icon) {
name += "_19x19.png";

return name;
}
}
49 changes: 23 additions & 26 deletions chromeipass/background/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ event.invoke = function(handler, callback, senderTabId, args, secondTime) {
// remove information from no longer existing tabs
page.removePageInformationFromNotExistingTabs();

chrome.tabs.get(senderTabId, function(tab) {
//chrome.tabs.query({"active": true, "windowId": chrome.windows.WINDOW_ID_CURRENT}, function(tabs) {
//if (tabs.length === 0)
// return; // For example: only the background devtools or a popup are opened
//var tab = tabs[0];

browser.tabs.get(senderTabId).then(function(tab) {
if(!tab) {
return;
}
Expand Down Expand Up @@ -82,34 +77,38 @@ event.invoke = function(handler, callback, senderTabId, args, secondTime) {
});
}


event.onShowAlert = function(callback, tab, message) {
if( page.settings.supressAlerts ){ console.log(message); }
else { alert(message); }
else { browser.tabs.executeScript({code: 'alert(\''+message+'\')'}); }
}

event.onLoadSettings = function(callback, tab) {
page.settings = (typeof(localStorage.settings) == 'undefined') ? {} : JSON.parse(localStorage.settings);
browser.storage.local.get({'settings': {}}).then((item) => {
callback(item.settings);
}, (err) => {
console.log('error loading settings: ' + err);
});
}

event.onLoadKeyRing = function(callback, tab) {
keepass.keyRing = (typeof(localStorage.keyRing) == 'undefined') ? {} : JSON.parse(localStorage.keyRing);
if(keepass.isAssociated() && !keepass.keyRing[keepass.associated.hash]) {
keepass.associated = {
"value": false,
"hash": null
};
}
}

event.onGetSettings = function(callback, tab) {
event.onLoadSettings();
callback({ data: page.settings });
browser.storage.local.get({'keyRing': {}}).then(function(item) {
keepass.keyRing = item.keyRing;
if(keepass.isAssociated() && !keepass.keyRing[keepass.associated.hash]) {
keepass.associated = {
"value": false,
"hash": null
};
}
callback(item.keyRing);
}, (err) => {
console.log('error loading keyRing: ' + err);
});
}

event.onSaveSettings = function(callback, tab, settings) {
localStorage.settings = JSON.stringify(settings);
event.onLoadSettings();
browser.storage.local.set({'settings': settings}).then(function() {
event.onLoadSettings();
});
}

event.onGetStatus = function(callback, tab) {
Expand Down Expand Up @@ -224,7 +223,6 @@ event.messageHandlers = {
'check_update_keepasshttp': event.onCheckUpdateKeePassHttp,
'get_connected_database': event.onGetConnectedDatabase,
'get_keepasshttp_versions': event.onGetKeePassHttpVersions,
'get_settings': event.onGetSettings,
'get_status': event.onGetStatus,
'get_tab_information': event.onGetTabInformation,
'load_keyring': event.onLoadKeyRing,
Expand All @@ -241,5 +239,4 @@ event.messageHandlers = {
'stack_add': browserAction.stackAdd,
'update_available_keepasshttp': event.onUpdateAvailableKeePassHttp,
'generate_password': keepass.generatePassword,
'copy_password': keepass.copyPassword
};
};
32 changes: 17 additions & 15 deletions chromeipass/background/httpauth.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
var httpAuth = httpAuth || {};

httpAuth.pendingCallbacks = [];
httpAuth.requestId = "";
httpAuth.callback = null;
httpAuth.tabId = 0;
httpAuth.url = null;
httpAuth.isProxy = false;
httpAuth.proxyUrl = null;
httpAuth.resolve = null;
httpAuth.reject = null;


httpAuth.handleRequest = function (details, callback) {
if(httpAuth.requestId == details.requestId || !page.tabs[details.tabId]) {
callback({});
}
else {
httpAuth.requestId = details.requestId;
httpAuth.pendingCallbacks.push(callback);
httpAuth.processPendingCallbacks(details);
}
httpAuth.handleRequest = function (details) {
return new Promise((resolve, reject) => {
if(httpAuth.requestId == details.requestId || !page.tabs[details.tabId]) {
reject({});
}
else {
httpAuth.requestId = details.requestId;
httpAuth.resolve = resolve;
httpAuth.reject = reject;
httpAuth.processPendingCallbacks(details);
}
});
}

httpAuth.processPendingCallbacks = function(details) {
httpAuth.callback = httpAuth.pendingCallbacks.pop();
httpAuth.tabId = details.tabId;
httpAuth.url = details.url;
httpAuth.isProxy = details.isProxy;
Expand All @@ -47,19 +49,19 @@ httpAuth.loginOrShowCredentials = function(logins) {
//generate popup-list for HTTP Auth usernames + descriptions

if(page.settings.autoFillAndSend) {
httpAuth.callback({
httpAuth.resolve({
authCredentials: {
username: logins[0].Login,
password: logins[0].Password
}
});
}
else {
httpAuth.callback({});
httpAuth.reject({});
}
}
// no logins found
else {
httpAuth.callback({});
httpAuth.reject({});
}
}
Loading