Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
fix context menu not showing in firefox. fixes #16
Browse files Browse the repository at this point in the history
also remove shortcut keys from context menu items, since it wasn't working in firefox anyways.
  • Loading branch information
smorks committed Oct 5, 2017
1 parent 537fd4e commit 39e8ed7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
5 changes: 5 additions & 0 deletions src/background/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ cipevent.pageClearLogins = function(callback, tab) {
callback();
}

cipevent.isFirefox = function(callback) {
callback(utils.isFirefox);
}

// all methods named in this object have to be declared BEFORE this!
cipevent.messageHandlers = {
'add_credentials': keepass.addCredentials,
Expand All @@ -245,4 +249,5 @@ cipevent.messageHandlers = {
'stack_add': browserAction.stackAdd,
'update_available_keepasshttp': cipevent.onUpdateAvailableKeePassHttp,
'generate_password': keepass.generatePassword,
'is_firefox': cipevent.isFirefox
};
23 changes: 14 additions & 9 deletions src/background/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ if (browser.webRequest.onAuthRequired) {
var reqType = 'blocking';
var opts = { urls: ['<all_urls>'] };

if (/Chrome/.test(navigator.userAgent) && /Google/.test(navigator.vendor)) {
if (utils.isFirefox) {
handleReq = httpAuth.handleRequestCallback;
reqType = 'asyncBlocking';
}
Expand All @@ -98,13 +98,18 @@ if (browser.webRequest.onAuthRequired) {
*/
browser.runtime.onMessage.addListener(cipevent.onMessage);

var menuContexts = ['editable'];

if (utils.isFirefox) {
menuContexts.push('password');
}

/**
* Add context menu entry for filling in username + password
*/
browser.contextMenus.create({
"title": "Fill &User + Pass",
"contexts": [ "editable" ],
"title": "Fill User + Pass",
"contexts": menuContexts,
"onclick": function(info, tab) {
browser.tabs.sendMessage(tab.id, {
action: "fill_user_pass"
Expand All @@ -116,8 +121,8 @@ browser.contextMenus.create({
* Add context menu entry for filling in only password which matches for given username
*/
browser.contextMenus.create({
"title": "Fill &Pass Only",
"contexts": [ "editable" ],
"title": "Fill Pass Only",
"contexts": menuContexts,
"onclick": function(info, tab) {
browser.tabs.sendMessage(tab.id, {
action: "fill_pass_only"
Expand All @@ -129,8 +134,8 @@ browser.contextMenus.create({
* Add context menu entry for creating icon for generate-password dialog
*/
browser.contextMenus.create({
"title": "Show Password &Generator Icons",
"contexts": [ "editable" ],
"title": "Show Password Generator Icons",
"contexts": menuContexts,
"onclick": function(info, tab) {
browser.tabs.sendMessage(tab.id, {
action: "activate_password_generator"
Expand All @@ -142,8 +147,8 @@ browser.contextMenus.create({
* Add context menu entry for creating icon for generate-password dialog
*/
browser.contextMenus.create({
"title": "&Save credentials",
"contexts": [ "editable" ],
"title": "Save credentials",
"contexts": menuContexts,
"onclick": function(info, tab) {
browser.tabs.sendMessage(tab.id, {
action: "remember_credentials"
Expand Down
8 changes: 8 additions & 0 deletions src/background/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

var utils = {};

utils.isFirefox = false;

if (!(/Chrome/.test(navigator.userAgent) && /Google/.test(navigator.vendor))) {
utils.isFirefox = true;
}
1 change: 1 addition & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"background/aes.js",
"background/cryptoHelpers.js",
"background/utf8.js",
"background/utils.js",
"background/keepass.js",
"background/httpauth.js",
"background/browserAction.js",
Expand Down
9 changes: 5 additions & 4 deletions src/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@ options.initSpecifiedCredentialFields = function() {
options.initAbout = function() {
var manifest = browser.runtime.getManifest();
$("#tab-about em.versionCIP").text(manifest.version);
if (!(/Chrome/.test(navigator.userAgent) && /Google/.test(navigator.vendor))) {
/* Not Chrome or Chromium */
$("#chrome-web-store-link").remove();
}
browser.runtime.sendMessage({ action: 'is_firefox' }).then((isFirefox) => {
if (isFirefox) {
$("#chrome-web-store-link").remove();
}
});
}

0 comments on commit 39e8ed7

Please sign in to comment.