From 9f030df327e7f62045f73d97814c458b33eab95b Mon Sep 17 00:00:00 2001 From: varjolintu Date: Sat, 29 Jul 2017 10:26:16 +0300 Subject: [PATCH] Some minor changes, mostly related to Firefox --- CHANGELOG | 4 +++ README.md | 7 +++++ ...rjolintu.keepassxc-browser-chrome-win.json | 3 +- com.varjolintu.keepassxc-browser-chrome.json | 3 +- keepassxc-browser/background/event.js | 6 ---- keepassxc-browser/background/init.js | 12 ++++--- keepassxc-browser/background/keepass.js | 26 +--------------- keepassxc-browser/keepassxc-browser.js | 31 +++++++++++++------ keepassxc-browser/manifest.json | 4 +-- keepassxc-browser/options/options.js | 2 +- keepassxc-browser/popups/popup_httpauth.js | 3 +- keepassxc-browser/popups/popup_login.js | 2 +- 12 files changed, 51 insertions(+), 52 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 726d92c..f8707dd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +0.2.7 (2017-??-??) +========================= +- Some Firefox related changes (credits to projectgus) + 0.2.6 (2017-07-23) ========================= - Fixed error message variables diff --git a/README.md b/README.md index 05dd478..bf98488 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,17 @@ Chrome extension for [KeePassXC](https://keepassxc.org/) with Native Messaging. This is a heavily forked version of [pfn](https://github.com/pfn)'s [chromeIPass](https://github.com/pfn/passifox). +Some changes merged also from [projectgus'](https://github.com/projectgus/passifox) fork. For testing purposes, please use following unofficial KeePassXC [release's](https://github.com/varjolintu/keepassxc/releases). Get the extension for [Firefox](https://addons.mozilla.org/en-US/firefox/addon/keepassxc-browser/) or [Chrome/Chromium](https://chrome.google.com/webstore/detail/keepassxc-browser/iopaggbpplllidnfmcghoonnokmjoicf). +If you want to use the extension manually with the latest stable build of Firefox, you can do the following: +- Install [Firefox Nightly](https://www.mozilla.org/en-US/firefox/channel/desktop/#nightly) +- Download the .crx file from [releases](https://github.com/varjolintu/keepassxc-browser/releases) +- Drag the .crx to the Firefox's Add-ons page (about:addons) +- Close Firefox Nightly and start the stable Firefox. The add-on should be now installed + ## How it works There are two methods which you can use keepassxc-browser to connect to KeePassXC: diff --git a/com.varjolintu.keepassxc-browser-chrome-win.json b/com.varjolintu.keepassxc-browser-chrome-win.json index 608265f..acf8450 100644 --- a/com.varjolintu.keepassxc-browser-chrome-win.json +++ b/com.varjolintu.keepassxc-browser-chrome-win.json @@ -5,6 +5,7 @@ "type": "stdio", "allowed_origins": [ "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/", - "chrome-extension://fhakpkpdnjecjfceboihdjpfmgajebii/" + "chrome-extension://fhakpkpdnjecjfceboihdjpfmgajebii/", + "chrome-extension://jaikbblhommnkeialomogohhdlndpfbi/" ] } \ No newline at end of file diff --git a/com.varjolintu.keepassxc-browser-chrome.json b/com.varjolintu.keepassxc-browser-chrome.json index 9266fe9..0fb2adb 100644 --- a/com.varjolintu.keepassxc-browser-chrome.json +++ b/com.varjolintu.keepassxc-browser-chrome.json @@ -5,6 +5,7 @@ "type": "stdio", "allowed_origins": [ "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/", - "chrome-extension://fhakpkpdnjecjfceboihdjpfmgajebii/" + "chrome-extension://fhakpkpdnjecjfceboihdjpfmgajebii/", + "chrome-extension://jaikbblhommnkeialomogohhdlndpfbi/" ] } \ No newline at end of file diff --git a/keepassxc-browser/background/event.js b/keepassxc-browser/background/event.js index 4e4d208..e10a89a 100644 --- a/keepassxc-browser/background/event.js +++ b/keepassxc-browser/background/event.js @@ -44,11 +44,6 @@ event.invoke = function(handler, callback, senderTabId, args, secondTime) { page.removePageInformationFromNotExistingTabs(); browser.tabs.get(senderTabId, (tab) => { - //browser.tabs.query({'active': true, 'windowId': browser.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]; - if (!tab) { return; } @@ -260,6 +255,5 @@ event.messageHandlers = { 'stack_add': browserAction.stackAdd, 'update_available_keepassxc': event.onUpdateAvailableKeePassXC, 'generate_password': keepass.generatePassword, - 'copy_password': keepass.copyPassword, 'reconnect': event.onReconnect }; \ No newline at end of file diff --git a/keepassxc-browser/background/init.js b/keepassxc-browser/background/init.js index 934777b..d9f3cfc 100644 --- a/keepassxc-browser/background/init.js +++ b/keepassxc-browser/background/init.js @@ -10,7 +10,9 @@ keepass.changePublicKeys(null, (pkRes) => { window.browser = (function () { return window.msBrowser || window.browser || window.chrome; })(); // Set initial tab-ID -browser.tabs.query({'active': true, 'windowId': browser.windows.WINDOW_ID_CURRENT}, (tabs) => { +//browser.tabs.query({'active': true, 'windowId': browser.windows.WINDOW_ID_CURRENT}, (tabs) => { +browser.tabs.query({"active": true, "currentWindow": true}, (tabs) => { +//browser.tabs.query({"active": true, "currentWindow": true}).then((tabs) => { if (tabs.length === 0) return; // For example: only the background devtools or a popup are opened page.currentTabId = tabs[0].id; @@ -80,9 +82,11 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { }); // Retrieve Credentials and try auto-login for HTTPAuth requests -browser.webRequest.onAuthRequired.addListener(httpAuth.handleRequest, - { urls: [''] }, ['asyncBlocking'] -); +if (browser.webRequest.onAuthRequired) { + browser.webRequest.onAuthRequired.addListener(httpAuth.handleRequest, + { urls: [''] }, ['asyncBlocking'] + ); +} browser.runtime.onMessage.addListener(event.onMessage); diff --git a/keepassxc-browser/background/keepass.js b/keepassxc-browser/background/keepass.js index 6eda72b..d87438c 100644 --- a/keepassxc-browser/background/keepass.js +++ b/keepassxc-browser/background/keepass.js @@ -273,30 +273,6 @@ keepass.generatePassword = function (callback, tab, forceCallback) { }, tab); } -keepass.copyPassword = function(callback, tab, password) { - browser.runtime.getBackgroundPage((bg) => { - let c2c = bg.document.getElementById('copy2clipboard'); - if (!c2c) { - let input = document.createElement('input'); - input.type = 'text'; - input.id = 'copy2clipboard'; - bg.document.getElementsByTagName('body')[0].appendChild(input); - c2c = bg.document.getElementById('copy2clipboard'); - } - - c2c.value = password; - c2c.select(); - try { - document.execCommand('copy'); - c2c.value = ''; - callback(true); - } - catch (err) { - console.log('Could not copy password to clipboard: ' + err); - } - }); -} - keepass.associate = function(callback, tab) { if (keepass.isAssociated()) { return; @@ -654,7 +630,7 @@ keepass.checkForNewKeePassXCVersion = function() { }; xhr.onerror = function(e) { - console.log('checkForNewKeePassXCVersion error: ${e}'); + console.log('checkForNewKeePassXCVersion error:' + e); } xhr.send(); diff --git a/keepassxc-browser/keepassxc-browser.js b/keepassxc-browser/keepassxc-browser.js index eb00503..a2ff9d4 100644 --- a/keepassxc-browser/keepassxc-browser.js +++ b/keepassxc-browser/keepassxc-browser.js @@ -271,10 +271,7 @@ cipPassword.createDialog = function() { id: 'cip-genpw-btn-clipboard', click: (e) => { e.preventDefault(); - browser.runtime.sendMessage({ - action: 'copy_password', - args: [jQuery('input#cip-genpw-textfield-password').val()] - }, cipPassword.callbackPasswordCopied); + cipPassword.copyPasswordToClipboard(); } }, 'Fill & copy': @@ -309,11 +306,7 @@ cipPassword.createDialog = function() { } } - // Copy password to clipboard - browser.runtime.sendMessage({ - action: 'copy_password', - args: [$password] - }, cipPassword.callbackPasswordCopied); + cipPassword.copyPasswordToClipboard(); } } } @@ -381,6 +374,26 @@ cipPassword.setIconPosition = function($icon, $field) { .css('left', $field.offset().left + $field.outerWidth() - $icon.data('size') - $icon.data('offset')) } +cipPassword.copyPasswordToClipboard = function(e) { + if (e) { + e.preventDefault(); + } + + const input = jQuery("input#cip-genpw-textfield-password"); + input.select() + try { + const success = document.execCommand('copy'); + if (success) { + jQuery("#cip-genpw-btn-clipboard").addClass("b2c-btn-success"); + } + jQuery("#cip-genpw-dialog").select(); + input.value = ''; + } + catch (err) { + console.log('Could not copy password to clipboard: ' + err); + } +} + cipPassword.callbackPasswordCopied = function(bool) { if (bool) { jQuery('#cip-genpw-btn-clipboard').addClass('btn-success'); diff --git a/keepassxc-browser/manifest.json b/keepassxc-browser/manifest.json index 46815eb..97404e4 100644 --- a/keepassxc-browser/manifest.json +++ b/keepassxc-browser/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "keepassxc-browser", - "version": "0.2.6", + "version": "0.2.7", "description": "KeePassXC integration for modern web browsers", "author": "Sami Vänttinen", "icons": { @@ -74,7 +74,7 @@ "applications": { "gecko": { "id": "keepassxc-browser@sami.vanttinen", - "strict_min_version": "56.0a1" + "strict_min_version": "54.0" } } } diff --git a/keepassxc-browser/options/options.js b/keepassxc-browser/options/options.js index 7b44586..25286df 100644 --- a/keepassxc-browser/options/options.js +++ b/keepassxc-browser/options/options.js @@ -36,7 +36,7 @@ options.saveSetting = function(name) { localStorage.settings = JSON.stringify(options.settings); - chrome.extension.sendMessage({ + browser.runtime.sendMessage({ action: 'load_settings' }); } diff --git a/keepassxc-browser/popups/popup_httpauth.js b/keepassxc-browser/popups/popup_httpauth.js index 445c4bd..aa839bf 100644 --- a/keepassxc-browser/popups/popup_httpauth.js +++ b/keepassxc-browser/popups/popup_httpauth.js @@ -2,8 +2,7 @@ window.browser = (function () { return window.msBrowser || window.browser || win $(function() { browser.runtime.getBackgroundPage(function(global) { - browser.tabs.query(null, (tab) => { - //const data = global.tab_httpauth_list['tab' + tab.id]; + browser.tabs.query({"active": true, "currentWindow": true}, (tab) => { const data = global.page.tabs[tab.id].loginList; let ul = document.getElementById('login-list'); for (let i = 0; i < data.logins.length; i++) { diff --git a/keepassxc-browser/popups/popup_login.js b/keepassxc-browser/popups/popup_login.js index 11b152a..19b6d2d 100644 --- a/keepassxc-browser/popups/popup_login.js +++ b/keepassxc-browser/popups/popup_login.js @@ -2,7 +2,7 @@ window.browser = (function () { return window.msBrowser || window.browser || win $(function() { browser.runtime.getBackgroundPage(function(global) { - browser.tabs.query({'active': true, 'windowId': browser.windows.WINDOW_ID_CURRENT}, function(tabs) { + browser.tabs.query({"active": true, "currentWindow": true}, (tabs) => { if (tabs.length === 0) return; // For example: only the background devtools or a popup are opened const tab = tabs[0];