From 84821fd67d7fe52fb36bb9fb232804c3d608ad20 Mon Sep 17 00:00:00 2001 From: byron jones Date: Sat, 4 Mar 2017 11:33:17 +0800 Subject: [PATCH] Add option to disable content menu integation (#99) * Add option to disable content menu integation Fixes issue #98 * pass tab to contextMenuReady --- src/_locales/en/messages.json | 8 ++++ src/background.js | 18 +++++++-- .../settings/settingsFeaturesController.js | 37 +++++++++++++++++++ .../app/settings/views/settingsFeatures.html | 12 ++++++ src/services/constantsService.js | 1 + 5 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index c526eb18..2ff254b1 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -646,5 +646,13 @@ "notificationAddSave": { "message": "Yes, Save Now", "description": "Yes, Save Now" + }, + "disableContextMenuItem": { + "message": "Disable Context Menu Integration", + "description": "Disable Context Menu Integration" + }, + "disableContextMenuItemDesc": { + "message": "bitwarden's context menu item provides quick access to logins for the current tab.", + "desription": "bitwarden's context menu item provides quick access to logins for the current tab." } } diff --git a/src/background.js b/src/background.js index 56748c45..7885f3e4 100644 --- a/src/background.js +++ b/src/background.js @@ -78,6 +78,8 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { pageDetailsToAutoFill.push({ frameId: sender.frameId, tabId: msg.tabId, details: msg.details }); autofillTimeout = setTimeout(autofillPage, 300); } + } else if (msg.command === 'bgUpdateContextMenu') { + refreshBadgeAndMenu(); } }); @@ -227,13 +229,23 @@ function refreshBadgeAndMenu() { return; } - buildContextMenu(function () { - loadMenuAndUpdateBadge(tab.url, tab.id, true); - onUpdatedRan = onReplacedRan = false; + chrome.storage.local.get(constantsService.disableContextMenuItemKey, function (obj) { + if (! obj[constantsService.disableContextMenuItemKey]) { + buildContextMenu(function() { contextMenuReady(tab) }); + } + else { + chrome.contextMenus.removeAll(); + contextMenuReady(tab); + } }); }); } +function contextMenuReady(tab) { + loadMenuAndUpdateBadge(tab.url, tab.id, true); + onUpdatedRan = onReplacedRan = false; +} + function loadMenuAndUpdateBadge(url, tabId, loadContextMenuOptions) { if (!url) { return; diff --git a/src/popup/app/settings/settingsFeaturesController.js b/src/popup/app/settings/settingsFeaturesController.js index 50083bb1..19db1785 100644 --- a/src/popup/app/settings/settingsFeaturesController.js +++ b/src/popup/app/settings/settingsFeaturesController.js @@ -5,6 +5,7 @@ $scope.i18n = i18nService; $scope.disableGa = false; $scope.disableAddLoginNotification = false; + $scope.disableContextMenuItem = false; chrome.storage.local.get(constantsService.disableGaKey, function (obj) { // Default for Firefox is disabled. @@ -30,6 +31,17 @@ $scope.$apply(); }); + chrome.storage.local.get(constantsService.disableContextMenuItemKey, function (obj) { + if (obj && obj[constantsService.disableContextMenuItemKey]) { + $scope.disableContextMenuItem = true; + } + else { + $scope.disableContextMenuItem = false; + } + + $scope.$apply(); + }); + $scope.updateGa = function () { chrome.storage.local.get(constantsService.disableGaKey, function (obj) { // Default for Firefox is disabled. @@ -75,4 +87,29 @@ }); }); }; + + $scope.updateDisableContextMenuItem = function () { + chrome.storage.local.get(constantsService.disableContextMenuItemKey, function (obj) { + if (obj[constantsService.disableContextMenuItemKey]) { + // enable + obj[constantsService.disableContextMenuItemKey] = false; + } + else { + // disable + $analytics.eventTrack('Disabled Context Menu Item'); + obj[constantsService.disableContextMenuItemKey] = true; + } + + chrome.storage.local.set(obj, function () { + $scope.disableContextMenuItem = obj[constantsService.disableContextMenuItemKey]; + $scope.$apply(); + if (!obj[constantsService.disableContextMenuItemKey]) { + $analytics.eventTrack('Enabled Context Menu Item'); + } + chrome.runtime.sendMessage({ + command: 'bgUpdateContextMenu' + }); + }); + }); + }; }); diff --git a/src/popup/app/settings/views/settingsFeatures.html b/src/popup/app/settings/views/settingsFeatures.html index 5be7840a..6749bc6d 100644 --- a/src/popup/app/settings/views/settingsFeatures.html +++ b/src/popup/app/settings/views/settingsFeatures.html @@ -29,5 +29,17 @@ {{i18n.addLoginNotificationDesc}} +
+
+
+ + +
+
+ +
diff --git a/src/services/constantsService.js b/src/services/constantsService.js index 92748435..94f7431f 100644 --- a/src/services/constantsService.js +++ b/src/services/constantsService.js @@ -2,6 +2,7 @@ function ConstantsService() { return { disableGaKey: 'disableGa', disableAddLoginNotificationKey: 'disableAddLoginNotification', + disableContextMenuItemKey: 'disableContextMenuItem', lockOptionKey: 'lockOption', lastActiveKey: 'lastActive' };