1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-23 11:56:00 +01:00

Add option to disable content menu integation (#99)

* Add option to disable content menu integation

Fixes issue #98

* pass tab to contextMenuReady
This commit is contained in:
byron jones 2017-03-04 11:33:17 +08:00 committed by Kyle Spearrin
parent 0298c19e13
commit 84821fd67d
5 changed files with 73 additions and 3 deletions

View File

@ -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."
}
}

View File

@ -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;

View File

@ -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'
});
});
});
};
});

View File

@ -29,5 +29,17 @@
{{i18n.addLoginNotificationDesc}}
</div>
</div>
<div class="list-section">
<div class="list-section-items">
<div class="list-section-item list-section-item-checkbox">
<label for="context-menu">{{i18n.disableContextMenuItem}}</label>
<input id="context-menu" type="checkbox" ng-model="disableContextMenuItem"
ng-change="updateDisableContextMenuItem()">
</div>
</div>
<div class="list-section-footer">
{{i18n.disableContextMenuItemDesc}}
</div>
</div>
</div>
</div>

View File

@ -2,6 +2,7 @@ function ConstantsService() {
return {
disableGaKey: 'disableGa',
disableAddLoginNotificationKey: 'disableAddLoginNotification',
disableContextMenuItemKey: 'disableContextMenuItem',
lockOptionKey: 'lockOption',
lastActiveKey: 'lastActive'
};