2017-09-09 17:55:30 +02:00
|
|
|
var bg_isBackground = true,
|
2017-09-09 17:42:12 +02:00
|
|
|
bg_utilsService,
|
|
|
|
bg_i18nService,
|
|
|
|
bg_constantsService,
|
|
|
|
bg_cryptoService,
|
|
|
|
bg_tokenService,
|
|
|
|
bg_appIdService,
|
|
|
|
bg_apiService,
|
|
|
|
bg_environmentService,
|
|
|
|
bg_userService,
|
|
|
|
bg_settingsService,
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_cipherService,
|
2017-09-09 17:42:12 +02:00
|
|
|
bg_folderService,
|
|
|
|
bg_lockService,
|
|
|
|
bg_syncService,
|
|
|
|
bg_passwordGenerationService,
|
|
|
|
bg_totpService,
|
|
|
|
bg_autofillService;
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
var loginToAutoFill = null,
|
|
|
|
pageDetailsToAutoFill = [],
|
|
|
|
autofillTimeout = null,
|
|
|
|
menuOptionsLoaded = [],
|
|
|
|
pendingAuthRequests = [],
|
|
|
|
syncTimeout = null,
|
2017-09-28 20:03:01 +02:00
|
|
|
bg_loginsToAdd = [],
|
|
|
|
bg_sidebarAction = (typeof opr !== 'undefined') && opr.sidebarAction ? opr.sidebarAction : chrome.sidebarAction;
|
2017-09-09 17:42:12 +02:00
|
|
|
|
|
|
|
// init services
|
|
|
|
bg_utilsService = new UtilsService();
|
|
|
|
bg_i18nService = new i18nService(bg_utilsService);
|
|
|
|
bg_constantsService = new ConstantsService(bg_i18nService);
|
2017-10-17 18:22:50 +02:00
|
|
|
bg_cryptoService = new CryptoService(bg_constantsService, bg_utilsService);
|
2017-10-13 23:07:20 +02:00
|
|
|
bg_tokenService = new TokenService(bg_utilsService);
|
2017-10-17 15:25:22 +02:00
|
|
|
bg_appIdService = new AppIdService(bg_utilsService);
|
2017-09-09 17:42:12 +02:00
|
|
|
bg_apiService = new ApiService(bg_tokenService, bg_appIdService, bg_utilsService, bg_constantsService, logout);
|
|
|
|
bg_environmentService = new EnvironmentService(bg_constantsService, bg_apiService);
|
2017-10-13 23:07:20 +02:00
|
|
|
bg_userService = new UserService(bg_tokenService, bg_apiService, bg_cryptoService, bg_utilsService);
|
|
|
|
bg_settingsService = new SettingsService(bg_userService, bg_utilsService);
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_cipherService = new CipherService(bg_cryptoService, bg_userService, bg_apiService, bg_settingsService, bg_utilsService,
|
2017-10-14 20:27:14 +02:00
|
|
|
bg_constantsService);
|
2017-10-13 23:07:20 +02:00
|
|
|
bg_folderService = new FolderService(bg_cryptoService, bg_userService, bg_apiService, bg_i18nService, bg_utilsService);
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_lockService = new LockService(bg_constantsService, bg_cryptoService, bg_folderService, bg_cipherService, bg_utilsService,
|
2017-09-28 16:39:31 +02:00
|
|
|
setIcon, refreshBadgeAndMenu);
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_syncService = new SyncService(bg_cipherService, bg_folderService, bg_userService, bg_apiService, bg_settingsService,
|
2017-09-09 17:42:12 +02:00
|
|
|
bg_cryptoService, logout);
|
2017-10-17 22:42:05 +02:00
|
|
|
bg_passwordGenerationService = new PasswordGenerationService(bg_constantsService, bg_utilsService, bg_cryptoService);
|
2017-09-09 17:42:12 +02:00
|
|
|
bg_totpService = new TotpService(bg_constantsService);
|
2017-10-18 03:10:44 +02:00
|
|
|
bg_autofillService = new AutofillService(bg_utilsService, bg_totpService, bg_tokenService, bg_cipherService,
|
|
|
|
bg_constantsService);
|
2017-09-09 17:42:12 +02:00
|
|
|
|
|
|
|
if (chrome.commands) {
|
|
|
|
chrome.commands.onCommand.addListener(function (command) {
|
|
|
|
if (command === 'generate_password') {
|
|
|
|
ga('send', {
|
|
|
|
hitType: 'event',
|
|
|
|
eventAction: 'Generated Password From Command'
|
|
|
|
});
|
|
|
|
bg_passwordGenerationService.getOptions().then(function (options) {
|
|
|
|
var password = bg_passwordGenerationService.generatePassword(options);
|
|
|
|
bg_utilsService.copyToClipboard(password);
|
2017-10-17 22:42:05 +02:00
|
|
|
bg_passwordGenerationService.addHistory(password);
|
2017-09-09 17:42:12 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else if (command === 'autofill_login') {
|
|
|
|
chrome.tabs.query({ active: true }, function (tabs) {
|
|
|
|
if (tabs.length) {
|
|
|
|
ga('send', {
|
|
|
|
hitType: 'event',
|
|
|
|
eventAction: 'Autofilled From Command'
|
|
|
|
});
|
2017-10-02 16:29:46 +02:00
|
|
|
collectPageDetailsForContentScript(tabs[0], 'autofill_cmd');
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
|
|
|
if (msg.command === 'loggedIn' || msg.command === 'unlocked' || msg.command === 'locked') {
|
|
|
|
setIcon();
|
|
|
|
refreshBadgeAndMenu();
|
2017-06-05 20:27:24 +02:00
|
|
|
}
|
2017-09-09 17:42:12 +02:00
|
|
|
else if (msg.command === 'logout') {
|
|
|
|
logout(msg.expired, function () { });
|
2017-08-31 18:42:09 +02:00
|
|
|
}
|
2017-09-09 17:42:12 +02:00
|
|
|
else if (msg.command === 'syncCompleted' && msg.successfully) {
|
|
|
|
setTimeout(refreshBadgeAndMenu, 2000);
|
2017-08-28 19:00:46 +02:00
|
|
|
}
|
2017-09-09 17:42:12 +02:00
|
|
|
else if (msg.command === 'bgOpenOverlayPopup') {
|
|
|
|
messageCurrentTab('openOverlayPopup', msg.data);
|
2016-12-30 08:09:54 +01:00
|
|
|
}
|
2017-09-09 17:42:12 +02:00
|
|
|
else if (msg.command === 'bgCloseOverlayPopup') {
|
|
|
|
messageCurrentTab('closeOverlayPopup');
|
2016-12-30 08:09:54 +01:00
|
|
|
}
|
2017-09-09 17:42:12 +02:00
|
|
|
else if (msg.command === 'bgOpenNotificationBar') {
|
|
|
|
messageTab(sender.tab.id, 'openNotificationBar', msg.data);
|
|
|
|
}
|
|
|
|
else if (msg.command === 'bgCloseNotificationBar') {
|
|
|
|
messageTab(sender.tab.id, 'closeNotificationBar');
|
|
|
|
}
|
|
|
|
else if (msg.command === 'bgAdjustNotificationBar') {
|
|
|
|
messageTab(sender.tab.id, 'adjustNotificationBar', msg.data);
|
|
|
|
}
|
|
|
|
else if (msg.command === 'bgCollectPageDetails') {
|
2017-10-02 16:29:46 +02:00
|
|
|
collectPageDetailsForContentScript(sender.tab, msg.sender);
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
|
|
|
else if (msg.command === 'bgAddLogin') {
|
|
|
|
addLogin(msg.login, sender.tab);
|
|
|
|
}
|
|
|
|
else if (msg.command === 'bgAddClose') {
|
|
|
|
removeAddLogin(sender.tab);
|
|
|
|
}
|
|
|
|
else if (msg.command === 'bgAddSave') {
|
|
|
|
saveAddLogin(sender.tab);
|
|
|
|
}
|
|
|
|
else if (msg.command === 'bgNeverSave') {
|
|
|
|
saveNever(sender.tab);
|
|
|
|
}
|
|
|
|
else if (msg.command === 'collectPageDetailsResponse') {
|
|
|
|
if (msg.sender === 'notificationBar') {
|
|
|
|
var forms = bg_autofillService.getFormsWithPasswordFields(msg.details);
|
2017-10-06 04:30:46 +02:00
|
|
|
messageTab(msg.tab.id, 'notificationBarPageDetails', { details: msg.details, forms: forms });
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
|
|
|
else if (msg.sender === 'autofiller' || msg.sender === 'autofill_cmd') {
|
|
|
|
bg_autofillService.doAutoFillForLastUsedLogin([{
|
|
|
|
frameId: sender.frameId, tab: msg.tab, details: msg.details
|
2017-10-07 19:17:43 +02:00
|
|
|
}], msg.sender === 'autofill_cmd');
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
2017-10-18 04:52:56 +02:00
|
|
|
else if (msg.sender === 'contextMenu') {
|
2017-09-09 17:42:12 +02:00
|
|
|
clearTimeout(autofillTimeout);
|
|
|
|
pageDetailsToAutoFill.push({ frameId: sender.frameId, tab: msg.tab, details: msg.details });
|
|
|
|
autofillTimeout = setTimeout(autofillPage, 300);
|
|
|
|
}
|
|
|
|
} else if (msg.command === 'bgUpdateContextMenu') {
|
|
|
|
refreshBadgeAndMenu();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (chrome.runtime.onInstalled) {
|
|
|
|
chrome.runtime.onInstalled.addListener(function (details) {
|
|
|
|
ga('send', {
|
|
|
|
hitType: 'event',
|
|
|
|
eventAction: 'onInstalled ' + details.reason
|
|
|
|
});
|
2016-09-28 05:36:55 +02:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
if (details.reason === 'install') {
|
|
|
|
chrome.tabs.create({ url: 'https://bitwarden.com/browser-start/' }, function (tab) { });
|
|
|
|
}
|
2016-09-29 01:12:14 +02:00
|
|
|
});
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
chrome.tabs.onActivated.addListener(function (activeInfo) {
|
|
|
|
refreshBadgeAndMenu();
|
|
|
|
});
|
2016-11-17 06:42:20 +01:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
var onReplacedRan = false;
|
|
|
|
chrome.tabs.onReplaced.addListener(function (addedTabId, removedTabId) {
|
|
|
|
if (onReplacedRan) {
|
|
|
|
return;
|
2016-11-17 06:42:20 +01:00
|
|
|
}
|
2017-09-09 17:42:12 +02:00
|
|
|
onReplacedRan = true;
|
|
|
|
checkbg_loginsToAdd();
|
|
|
|
refreshBadgeAndMenu();
|
2016-09-29 01:12:14 +02:00
|
|
|
});
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
var onUpdatedRan = false;
|
|
|
|
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
|
|
|
if (onUpdatedRan) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
onUpdatedRan = true;
|
|
|
|
checkbg_loginsToAdd();
|
|
|
|
refreshBadgeAndMenu();
|
|
|
|
});
|
2017-09-04 18:09:11 +02:00
|
|
|
|
2017-09-26 02:35:54 +02:00
|
|
|
if (chrome.windows) {
|
|
|
|
chrome.windows.onFocusChanged.addListener(function (windowId) {
|
|
|
|
if (windowId === null || windowId < 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-04 18:09:11 +02:00
|
|
|
|
2017-09-26 02:35:54 +02:00
|
|
|
refreshBadgeAndMenu();
|
|
|
|
});
|
|
|
|
}
|
2017-09-04 18:09:11 +02:00
|
|
|
|
2017-09-26 02:35:54 +02:00
|
|
|
if (chrome.contextMenus) {
|
|
|
|
chrome.contextMenus.onClicked.addListener(function (info, tab) {
|
|
|
|
if (info.menuItemId === 'generate-password') {
|
|
|
|
ga('send', {
|
|
|
|
hitType: 'event',
|
|
|
|
eventAction: 'Generated Password From Context Menu'
|
|
|
|
});
|
|
|
|
bg_passwordGenerationService.getOptions().then(function (options) {
|
|
|
|
var password = bg_passwordGenerationService.generatePassword(options);
|
|
|
|
bg_utilsService.copyToClipboard(password);
|
2017-10-17 22:42:05 +02:00
|
|
|
bg_passwordGenerationService.addHistory(password);
|
2017-09-26 02:35:54 +02:00
|
|
|
});
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
2017-09-26 02:35:54 +02:00
|
|
|
else if (info.parentMenuItemId === 'autofill' || info.parentMenuItemId === 'copy-username' ||
|
|
|
|
info.parentMenuItemId === 'copy-password') {
|
|
|
|
var id = info.menuItemId.split('_')[1];
|
|
|
|
if (id === 'noop') {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-04 18:09:11 +02:00
|
|
|
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_cipherService.getAllDecrypted().then(function (logins) {
|
2017-09-26 02:35:54 +02:00
|
|
|
for (var i = 0; i < logins.length; i++) {
|
|
|
|
if (logins[i].id === id) {
|
|
|
|
if (info.parentMenuItemId === 'autofill') {
|
|
|
|
ga('send', {
|
|
|
|
hitType: 'event',
|
|
|
|
eventAction: 'Autofilled From Context Menu'
|
|
|
|
});
|
|
|
|
startAutofillPage(logins[i]);
|
|
|
|
}
|
|
|
|
else if (info.parentMenuItemId === 'copy-username') {
|
|
|
|
ga('send', {
|
|
|
|
hitType: 'event',
|
|
|
|
eventAction: 'Copied Username From Context Menu'
|
|
|
|
});
|
|
|
|
bg_utilsService.copyToClipboard(logins[i].username);
|
|
|
|
}
|
|
|
|
else if (info.parentMenuItemId === 'copy-password') {
|
|
|
|
ga('send', {
|
|
|
|
hitType: 'event',
|
|
|
|
eventAction: 'Copied Password From Context Menu'
|
|
|
|
});
|
|
|
|
bg_utilsService.copyToClipboard(logins[i].password);
|
|
|
|
}
|
|
|
|
return;
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
2017-09-04 18:09:11 +02:00
|
|
|
}
|
2017-09-26 02:35:54 +02:00
|
|
|
}, function () {
|
2017-09-04 18:09:11 +02:00
|
|
|
|
2017-09-26 02:35:54 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-09-04 18:09:11 +02:00
|
|
|
|
2017-09-15 15:47:47 +02:00
|
|
|
if (chrome.webRequest && chrome.webRequest.onAuthRequired) {
|
|
|
|
chrome.webRequest.onAuthRequired.addListener(function (details, callback) {
|
|
|
|
if (!details.url || pendingAuthRequests.indexOf(details.requestId) != -1) {
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
return;
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
2017-09-08 05:26:56 +02:00
|
|
|
|
2017-09-15 15:47:47 +02:00
|
|
|
var domain = bg_utilsService.getDomain(details.url);
|
|
|
|
if (!domain) {
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
return;
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
2017-09-08 05:26:56 +02:00
|
|
|
|
2017-09-15 15:47:47 +02:00
|
|
|
pendingAuthRequests.push(details.requestId);
|
|
|
|
|
|
|
|
if (bg_utilsService.isFirefox()) {
|
|
|
|
return new Promise(function (resolve, reject) {
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_cipherService.getAllDecryptedForDomain(domain).then(function (logins) {
|
2017-09-15 15:47:47 +02:00
|
|
|
if (!logins || logins.length !== 1) {
|
|
|
|
reject();
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 05:26:56 +02:00
|
|
|
|
2017-09-15 15:47:47 +02:00
|
|
|
resolve({
|
|
|
|
authCredentials: {
|
|
|
|
username: logins[0].username,
|
|
|
|
password: logins[0].password
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, function () {
|
|
|
|
reject();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_cipherService.getAllDecryptedForDomain(domain).then(function (logins) {
|
2017-09-09 17:42:12 +02:00
|
|
|
if (!logins || logins.length !== 1) {
|
2017-09-15 15:47:47 +02:00
|
|
|
callback();
|
2017-09-09 17:42:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-15 15:47:47 +02:00
|
|
|
callback({
|
2017-09-09 17:42:12 +02:00
|
|
|
authCredentials: {
|
|
|
|
username: logins[0].username,
|
|
|
|
password: logins[0].password
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, function () {
|
|
|
|
callback();
|
2017-09-08 05:26:56 +02:00
|
|
|
});
|
2017-09-15 15:47:47 +02:00
|
|
|
}
|
|
|
|
}, { urls: ['http://*/*', 'https://*/*'] }, [bg_utilsService.isFirefox() ? 'blocking' : 'asyncBlocking']);
|
2017-09-08 05:26:56 +02:00
|
|
|
|
2017-09-15 15:47:47 +02:00
|
|
|
chrome.webRequest.onCompleted.addListener(completeAuthRequest, { urls: ['http://*/*'] });
|
|
|
|
chrome.webRequest.onErrorOccurred.addListener(completeAuthRequest, { urls: ['http://*/*'] });
|
2017-09-22 04:45:24 +02:00
|
|
|
}
|
2017-09-08 05:26:56 +02:00
|
|
|
|
2017-09-22 04:45:24 +02:00
|
|
|
function completeAuthRequest(details) {
|
|
|
|
var i = pendingAuthRequests.indexOf(details.requestId);
|
|
|
|
if (i > -1) {
|
|
|
|
pendingAuthRequests.splice(i, 1);
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
2017-09-08 05:26:56 +02:00
|
|
|
}
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
var buildingContextMenu = false;
|
|
|
|
function buildContextMenu(callback) {
|
2017-09-26 02:35:54 +02:00
|
|
|
if (!chrome.contextMenus || buildingContextMenu) {
|
2017-09-09 17:42:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
buildingContextMenu = true;
|
|
|
|
|
|
|
|
chrome.contextMenus.removeAll(function () {
|
2016-10-26 05:03:21 +02:00
|
|
|
chrome.contextMenus.create({
|
|
|
|
type: 'normal',
|
2017-09-09 17:42:12 +02:00
|
|
|
id: 'root',
|
2016-10-26 05:03:21 +02:00
|
|
|
contexts: ['all'],
|
2017-09-09 17:42:12 +02:00
|
|
|
title: 'bitwarden'
|
2016-10-26 05:03:21 +02:00
|
|
|
}, function () {
|
|
|
|
chrome.contextMenus.create({
|
|
|
|
type: 'normal',
|
2017-09-09 17:42:12 +02:00
|
|
|
id: 'autofill',
|
2016-11-25 05:54:22 +01:00
|
|
|
parentId: 'root',
|
2016-10-26 05:03:21 +02:00
|
|
|
contexts: ['all'],
|
2017-09-09 17:42:12 +02:00
|
|
|
title: bg_i18nService.autoFill
|
2016-10-26 05:03:21 +02:00
|
|
|
}, function () {
|
2017-09-09 17:42:12 +02:00
|
|
|
if (bg_utilsService.isFirefox() || bg_utilsService.isEdge()) {
|
|
|
|
// Firefox & Edge do not support writing to the clipboard from background
|
|
|
|
buildingContextMenu = false;
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-10-26 05:03:21 +02:00
|
|
|
chrome.contextMenus.create({
|
|
|
|
type: 'normal',
|
2017-09-09 17:42:12 +02:00
|
|
|
id: 'copy-username',
|
2016-11-25 05:54:22 +01:00
|
|
|
parentId: 'root',
|
2016-10-26 05:03:21 +02:00
|
|
|
contexts: ['all'],
|
2017-09-09 17:42:12 +02:00
|
|
|
title: bg_i18nService.copyUsername
|
2016-10-26 05:03:21 +02:00
|
|
|
}, function () {
|
2016-11-25 05:54:22 +01:00
|
|
|
chrome.contextMenus.create({
|
|
|
|
type: 'normal',
|
2017-09-09 17:42:12 +02:00
|
|
|
id: 'copy-password',
|
2016-11-25 05:54:22 +01:00
|
|
|
parentId: 'root',
|
|
|
|
contexts: ['all'],
|
2017-09-09 17:42:12 +02:00
|
|
|
title: bg_i18nService.copyPassword
|
2016-11-25 05:54:22 +01:00
|
|
|
}, function () {
|
2017-09-09 17:42:12 +02:00
|
|
|
chrome.contextMenus.create({
|
|
|
|
type: 'separator',
|
|
|
|
parentId: 'root'
|
|
|
|
});
|
|
|
|
|
|
|
|
chrome.contextMenus.create({
|
|
|
|
type: 'normal',
|
|
|
|
id: 'generate-password',
|
|
|
|
parentId: 'root',
|
|
|
|
contexts: ['all'],
|
|
|
|
title: bg_i18nService.generatePasswordCopied
|
|
|
|
}, function () {
|
|
|
|
buildingContextMenu = false;
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
2016-11-25 05:54:22 +01:00
|
|
|
});
|
2016-10-26 05:03:21 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function setIcon() {
|
2017-09-28 20:03:01 +02:00
|
|
|
if (!chrome.browserAction && !bg_sidebarAction) {
|
2017-09-26 02:35:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
bg_userService.isAuthenticated(function (isAuthenticated) {
|
|
|
|
bg_cryptoService.getKey().then(function (key) {
|
|
|
|
var suffix = '';
|
|
|
|
if (!isAuthenticated) {
|
|
|
|
suffix = '_gray';
|
|
|
|
}
|
|
|
|
else if (!key) {
|
|
|
|
suffix = '_locked';
|
|
|
|
}
|
|
|
|
|
2017-09-28 16:39:31 +02:00
|
|
|
actionSetIcon(chrome.browserAction, suffix);
|
2017-09-28 20:03:01 +02:00
|
|
|
actionSetIcon(bg_sidebarAction, suffix);
|
2017-09-28 16:39:31 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function actionSetIcon(theAction, suffix) {
|
|
|
|
if (theAction && theAction.setIcon) {
|
|
|
|
theAction.setIcon({
|
2017-09-09 17:42:12 +02:00
|
|
|
path: {
|
|
|
|
'19': 'images/icon19' + suffix + '.png',
|
|
|
|
'38': 'images/icon38' + suffix + '.png',
|
|
|
|
}
|
|
|
|
});
|
2017-09-28 16:39:31 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
2016-09-17 02:20:02 +02:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function refreshBadgeAndMenu() {
|
2017-09-26 02:35:54 +02:00
|
|
|
if (!chrome.windows || !chrome.contextMenus) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
chrome.tabs.query({ active: true, windowId: chrome.windows.WINDOW_ID_CURRENT }, function (tabs) {
|
|
|
|
var tab = null;
|
|
|
|
if (tabs.length > 0) {
|
|
|
|
tab = tabs[0];
|
2017-09-04 18:09:11 +02:00
|
|
|
}
|
2017-09-09 17:42:12 +02:00
|
|
|
|
|
|
|
if (!tab) {
|
|
|
|
return;
|
2017-09-04 18:09:11 +02:00
|
|
|
}
|
2017-01-21 04:32:21 +01:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
chrome.storage.local.get(bg_constantsService.disableContextMenuItemKey, function (obj) {
|
|
|
|
if (!obj[bg_constantsService.disableContextMenuItemKey]) {
|
|
|
|
buildContextMenu(function () {
|
|
|
|
contextMenuReady(tab, true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
chrome.contextMenus.removeAll();
|
|
|
|
contextMenuReady(tab, false);
|
2017-09-04 18:09:11 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
2017-01-21 04:32:21 +01:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function contextMenuReady(tab, contextMenuEnabled) {
|
|
|
|
loadMenuAndUpdateBadge(tab.url, tab.id, contextMenuEnabled);
|
|
|
|
onUpdatedRan = onReplacedRan = false;
|
|
|
|
}
|
2016-09-23 04:04:50 +02:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function loadMenuAndUpdateBadge(url, tabId, contextMenuEnabled) {
|
2017-09-28 20:03:01 +02:00
|
|
|
if (!chrome.browserAction && !bg_sidebarAction) {
|
2016-09-23 04:04:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-28 20:03:01 +02:00
|
|
|
if (!url) {
|
2017-09-09 17:42:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-09-16 05:24:45 +02:00
|
|
|
|
2017-09-28 20:03:01 +02:00
|
|
|
var tabDomain = bg_utilsService.getDomain(url);
|
|
|
|
if (!tabDomain) {
|
2017-09-26 02:35:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-09-28 20:03:01 +02:00
|
|
|
setActionBadgeColor(chrome.browserAction);
|
|
|
|
setActionBadgeColor(bg_sidebarAction);
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
menuOptionsLoaded = [];
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_cipherService.getAllDecryptedForDomain(tabDomain).then(function (logins) {
|
2017-10-17 05:21:12 +02:00
|
|
|
logins.sort(bg_cipherService.sortCiphersByLastUsedThenName);
|
2017-01-21 05:20:09 +01:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
if (contextMenuEnabled) {
|
|
|
|
for (var i = 0; i < logins.length; i++) {
|
|
|
|
loadLoginContextMenuOptions(logins[i]);
|
|
|
|
}
|
2016-09-16 05:24:45 +02:00
|
|
|
}
|
|
|
|
|
2017-09-28 20:03:01 +02:00
|
|
|
var theText = '';
|
2017-09-09 17:42:12 +02:00
|
|
|
if (logins.length > 0 && logins.length < 9) {
|
2017-09-28 20:03:01 +02:00
|
|
|
theText = logins.length.toString();
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
|
|
|
else if (logins.length > 0) {
|
2017-09-28 20:03:01 +02:00
|
|
|
theText = '9+';
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (contextMenuEnabled) {
|
|
|
|
loadNoLoginsContextMenuOptions(bg_i18nService.noMatchingLogins);
|
|
|
|
}
|
|
|
|
}
|
2017-09-28 20:03:01 +02:00
|
|
|
|
|
|
|
setBrowserActionText(theText, tabId);
|
|
|
|
setSidebarActionText(theText, tabId);
|
2017-09-09 17:42:12 +02:00
|
|
|
}, function () {
|
2017-03-15 04:17:22 +01:00
|
|
|
if (contextMenuEnabled) {
|
2017-09-09 17:42:12 +02:00
|
|
|
loadNoLoginsContextMenuOptions(bg_i18nService.vaultLocked);
|
2017-03-15 04:17:22 +01:00
|
|
|
}
|
2017-09-28 20:03:01 +02:00
|
|
|
setBrowserActionText('', tabId);
|
|
|
|
setSidebarActionText('', tabId);
|
2016-10-25 06:23:21 +02:00
|
|
|
});
|
2017-09-28 20:03:01 +02:00
|
|
|
|
|
|
|
function setActionBadgeColor(theAction) {
|
|
|
|
if (theAction && theAction.setBadgeBackgroundColor) {
|
|
|
|
theAction.setBadgeBackgroundColor({ color: '#294e5f' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setBrowserActionText(text, tabId) {
|
|
|
|
if (chrome.browserAction && chrome.browserAction.setBadgeText) {
|
|
|
|
chrome.browserAction.setBadgeText({
|
|
|
|
text: text,
|
|
|
|
tabId: tabId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function setSidebarActionText(text, tabId) {
|
|
|
|
if (!bg_sidebarAction) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bg_sidebarAction.setBadgeText) {
|
|
|
|
bg_sidebarAction.setBadgeText({
|
|
|
|
text: text,
|
|
|
|
tabId: tabId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if (bg_sidebarAction.setTitle) {
|
|
|
|
var title = 'bitwarden';
|
|
|
|
if (text && text !== '') {
|
|
|
|
title += (' [' + text + ']');
|
|
|
|
}
|
|
|
|
bg_sidebarAction.setTitle({
|
|
|
|
title: title,
|
|
|
|
tabId: tabId
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2016-12-30 08:09:54 +01:00
|
|
|
}
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function messageCurrentTab(command, data) {
|
|
|
|
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
|
|
|
var tabId = null;
|
|
|
|
if (tabs.length > 0) {
|
|
|
|
tabId = tabs[0].id;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
2016-12-30 08:09:54 +01:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
messageTab(tabId, command, data);
|
|
|
|
});
|
2016-12-30 08:09:54 +01:00
|
|
|
}
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function messageTab(tabId, command, data, callback) {
|
|
|
|
if (!tabId) {
|
|
|
|
return;
|
2017-01-27 05:12:09 +01:00
|
|
|
}
|
2016-12-30 08:09:54 +01:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
var obj = {
|
|
|
|
command: command
|
|
|
|
};
|
2017-08-30 14:28:48 +02:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
if (data) {
|
|
|
|
obj.data = data;
|
2017-08-31 21:30:01 +02:00
|
|
|
}
|
2016-12-30 08:09:54 +01:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
chrome.tabs.sendMessage(tabId, obj, function () {
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
});
|
2016-12-30 08:09:54 +01:00
|
|
|
}
|
|
|
|
|
2017-10-02 16:29:46 +02:00
|
|
|
function collectPageDetailsForContentScript(tab, sender) {
|
2017-09-09 17:42:12 +02:00
|
|
|
if (!tab || !tab.id) {
|
|
|
|
return;
|
2016-12-30 20:25:57 +01:00
|
|
|
}
|
|
|
|
|
2017-10-18 04:52:56 +02:00
|
|
|
chrome.tabs.sendMessage(tab.id, {
|
|
|
|
command: 'collectPageDetails',
|
|
|
|
tab: tab,
|
|
|
|
sender: sender
|
|
|
|
}, function () {
|
2017-09-09 17:42:12 +02:00
|
|
|
if (chrome.runtime.lastError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-12-30 20:25:57 +01:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function addLogin(login, tab) {
|
|
|
|
var loginDomain = bg_utilsService.getDomain(login.url);
|
|
|
|
if (!loginDomain) {
|
|
|
|
return;
|
2016-12-30 20:25:57 +01:00
|
|
|
}
|
2017-08-28 14:56:05 +02:00
|
|
|
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_cipherService.getAllDecryptedForDomain(loginDomain).then(function (logins) {
|
2017-09-09 17:42:12 +02:00
|
|
|
var match = false;
|
|
|
|
for (var i = 0; i < logins.length; i++) {
|
|
|
|
if (logins[i].username === login.username) {
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-12-30 20:25:57 +01:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
if (!match) {
|
|
|
|
// remove any old logins for this tab
|
|
|
|
removeAddLogin(tab);
|
|
|
|
|
|
|
|
bg_loginsToAdd.push({
|
|
|
|
username: login.username,
|
|
|
|
password: login.password,
|
|
|
|
name: loginDomain,
|
|
|
|
domain: loginDomain,
|
|
|
|
uri: login.url,
|
|
|
|
tabId: tab.id,
|
|
|
|
expires: new Date((new Date()).getTime() + 30 * 60000) // 30 minutes
|
|
|
|
});
|
|
|
|
checkbg_loginsToAdd(tab);
|
|
|
|
}
|
|
|
|
});
|
2016-12-30 20:25:57 +01:00
|
|
|
}
|
2017-01-27 05:12:09 +01:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function cleanupbg_loginsToAdd() {
|
|
|
|
for (var i = bg_loginsToAdd.length - 1; i >= 0; i--) {
|
|
|
|
if (bg_loginsToAdd[i].expires < new Date()) {
|
2017-06-27 05:55:51 +02:00
|
|
|
bg_loginsToAdd.splice(i, 1);
|
2017-01-27 05:12:09 +01:00
|
|
|
}
|
2016-12-30 20:25:57 +01:00
|
|
|
}
|
2016-12-30 08:09:54 +01:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
setTimeout(cleanupbg_loginsToAdd, 2 * 60 * 1000); // check every 2 minutes
|
|
|
|
}
|
2017-06-13 19:59:16 +02:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function removeAddLogin(tab) {
|
|
|
|
for (var i = bg_loginsToAdd.length - 1; i >= 0; i--) {
|
|
|
|
if (bg_loginsToAdd[i].tabId === tab.id) {
|
2017-06-27 05:55:51 +02:00
|
|
|
bg_loginsToAdd.splice(i, 1);
|
2017-06-13 19:59:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function saveAddLogin(tab) {
|
|
|
|
for (var i = bg_loginsToAdd.length - 1; i >= 0; i--) {
|
|
|
|
if (bg_loginsToAdd[i].tabId === tab.id) {
|
|
|
|
var loginToAdd = bg_loginsToAdd[i];
|
|
|
|
|
|
|
|
var tabDomain = bg_utilsService.getDomain(tab.url);
|
|
|
|
if (tabDomain && tabDomain === loginToAdd.domain) {
|
|
|
|
bg_loginsToAdd.splice(i, 1);
|
2017-10-06 16:36:45 +02:00
|
|
|
|
|
|
|
/* jshint ignore:start */
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_cipherService.encrypt({
|
2017-09-09 17:42:12 +02:00
|
|
|
id: null,
|
|
|
|
folderId: null,
|
|
|
|
favorite: false,
|
|
|
|
name: loginToAdd.name,
|
|
|
|
uri: loginToAdd.uri,
|
|
|
|
username: loginToAdd.username,
|
|
|
|
password: loginToAdd.password,
|
|
|
|
notes: null
|
|
|
|
}).then(function (loginModel) {
|
|
|
|
var login = new Login(loginModel, true);
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_cipherService.saveWithServer(login).then(function (login) {
|
2017-09-09 17:42:12 +02:00
|
|
|
ga('send', {
|
|
|
|
hitType: 'event',
|
|
|
|
eventAction: 'Added Login from Notification Bar'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-10-06 16:36:45 +02:00
|
|
|
/* jshint ignore:end */
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
messageTab(tab.id, 'closeNotificationBar');
|
|
|
|
}
|
|
|
|
}
|
2017-01-27 05:12:09 +01:00
|
|
|
}
|
2016-12-30 08:09:54 +01:00
|
|
|
}
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function saveNever(tab) {
|
|
|
|
for (var i = bg_loginsToAdd.length - 1; i >= 0; i--) {
|
|
|
|
if (bg_loginsToAdd[i].tabId === tab.id) {
|
|
|
|
var loginToAdd = bg_loginsToAdd[i];
|
2016-12-30 20:50:16 +01:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
var tabDomain = bg_utilsService.getDomain(tab.url);
|
|
|
|
if (tabDomain && tabDomain === loginToAdd.domain) {
|
|
|
|
bg_loginsToAdd.splice(i, 1);
|
|
|
|
var hostname = bg_utilsService.getHostname(tab.url);
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_cipherService.saveNeverDomain(hostname);
|
2017-09-09 17:42:12 +02:00
|
|
|
messageTab(tab.id, 'closeNotificationBar');
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 05:41:53 +02:00
|
|
|
}
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
2016-09-22 05:41:53 +02:00
|
|
|
|
2017-10-06 16:36:45 +02:00
|
|
|
function checkbg_loginsToAdd(tab) {
|
2017-09-09 17:42:12 +02:00
|
|
|
if (!bg_loginsToAdd.length) {
|
2016-12-30 08:09:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-09-22 05:41:53 +02:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
if (tab) {
|
|
|
|
check();
|
2016-12-30 08:09:54 +01:00
|
|
|
return;
|
2016-09-22 05:41:53 +02:00
|
|
|
}
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
|
|
|
if (tabs.length > 0) {
|
|
|
|
tab = tabs[0];
|
|
|
|
check();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function check() {
|
|
|
|
if (!tab) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var tabDomain = bg_utilsService.getDomain(tab.url);
|
|
|
|
if (!tabDomain) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < bg_loginsToAdd.length; i++) {
|
|
|
|
if (bg_loginsToAdd[i].tabId === tab.id && bg_loginsToAdd[i].domain === tabDomain) {
|
|
|
|
messageTab(tab.id, 'openNotificationBar', {
|
|
|
|
type: 'add'
|
2017-10-06 16:36:45 +02:00
|
|
|
}, function () { });
|
2017-09-09 17:42:12 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-12-30 08:09:54 +01:00
|
|
|
}
|
|
|
|
}
|
2016-12-30 20:50:16 +01:00
|
|
|
}
|
2016-09-22 05:41:53 +02:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function startAutofillPage(login) {
|
|
|
|
loginToAutoFill = login;
|
|
|
|
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
|
|
|
var tab = null;
|
|
|
|
if (tabs.length > 0) {
|
|
|
|
tab = tabs[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-17 06:13:12 +02:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
if (!tab) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-17 06:13:12 +02:00
|
|
|
|
2017-10-18 04:52:56 +02:00
|
|
|
chrome.tabs.sendMessage(tab.id, {
|
|
|
|
command: 'collectPageDetails',
|
|
|
|
tab: tab,
|
|
|
|
sender: 'contextMenu'
|
|
|
|
}, function () {
|
2017-09-09 17:42:12 +02:00
|
|
|
});
|
2017-01-27 05:12:09 +01:00
|
|
|
});
|
2017-01-21 04:32:21 +01:00
|
|
|
}
|
2017-09-09 17:42:12 +02:00
|
|
|
|
|
|
|
function autofillPage() {
|
2017-10-07 19:10:04 +02:00
|
|
|
bg_autofillService.doAutoFill({
|
2017-10-17 21:22:16 +02:00
|
|
|
cipher: loginToAutoFill,
|
2017-10-07 19:10:04 +02:00
|
|
|
pageDetails: pageDetailsToAutoFill,
|
|
|
|
fromBackground: true
|
|
|
|
});
|
2017-09-09 17:42:12 +02:00
|
|
|
// reset
|
|
|
|
loginToAutoFill = null;
|
|
|
|
pageDetailsToAutoFill = [];
|
2016-10-14 05:42:08 +02:00
|
|
|
}
|
2016-09-17 02:20:02 +02:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function loadLoginContextMenuOptions(login) {
|
|
|
|
var title = login.name + (login.username && login.username !== '' ? ' (' + login.username + ')' : '');
|
|
|
|
loadContextMenuOptions(title, login.id, login);
|
2017-01-21 05:20:09 +01:00
|
|
|
}
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function loadNoLoginsContextMenuOptions(noLoginsMessage) {
|
|
|
|
loadContextMenuOptions(noLoginsMessage, 'noop', null);
|
2016-10-14 05:42:08 +02:00
|
|
|
}
|
2016-09-17 02:20:02 +02:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
function loadContextMenuOptions(title, idSuffix, login) {
|
2017-09-26 02:35:54 +02:00
|
|
|
if (!chrome.contextMenus || menuOptionsLoaded.indexOf(idSuffix) > -1) {
|
2017-09-09 17:42:12 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
menuOptionsLoaded.push(idSuffix);
|
|
|
|
|
|
|
|
if (!login || (login.password && login.password !== '')) {
|
|
|
|
chrome.contextMenus.create({
|
|
|
|
type: 'normal',
|
|
|
|
id: 'autofill_' + idSuffix,
|
|
|
|
parentId: 'autofill',
|
|
|
|
contexts: ['all'],
|
|
|
|
title: title
|
|
|
|
}, function () {
|
|
|
|
if (chrome.runtime.lastError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bg_utilsService.isFirefox()) {
|
|
|
|
// Firefox does not support writing to the clipboard from background
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!login || (login.username && login.username !== '')) {
|
|
|
|
chrome.contextMenus.create({
|
|
|
|
type: 'normal',
|
|
|
|
id: 'copy-username_' + idSuffix,
|
|
|
|
parentId: 'copy-username',
|
|
|
|
contexts: ['all'],
|
|
|
|
title: title
|
|
|
|
}, function () {
|
|
|
|
if (chrome.runtime.lastError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!login || (login.password && login.password !== '')) {
|
|
|
|
chrome.contextMenus.create({
|
|
|
|
type: 'normal',
|
|
|
|
id: 'copy-password_' + idSuffix,
|
|
|
|
parentId: 'copy-password',
|
|
|
|
contexts: ['all'],
|
|
|
|
title: title
|
|
|
|
}, function () {
|
|
|
|
if (chrome.runtime.lastError) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-10-14 05:42:08 +02:00
|
|
|
}
|
2017-09-09 17:42:12 +02:00
|
|
|
|
|
|
|
function logout(expired, callback) {
|
2017-10-13 23:07:20 +02:00
|
|
|
bg_syncService.setLastSync(new Date(0), function () {
|
|
|
|
bg_userService.getUserIdPromise().then(function (userId) {
|
|
|
|
return Q.all([
|
|
|
|
bg_tokenService.clearToken(),
|
|
|
|
bg_cryptoService.clearKeys(),
|
|
|
|
bg_userService.clear(),
|
|
|
|
bg_settingsService.clear(userId),
|
2017-10-17 05:11:32 +02:00
|
|
|
bg_cipherService.clear(userId),
|
2017-10-17 22:42:05 +02:00
|
|
|
bg_folderService.clear(userId),
|
|
|
|
bg_passwordGenerationService.clear()
|
2017-10-13 23:07:20 +02:00
|
|
|
]).then(function () {
|
|
|
|
chrome.runtime.sendMessage({
|
|
|
|
command: 'doneLoggingOut', expired: expired
|
2017-01-19 06:21:20 +01:00
|
|
|
});
|
2017-10-13 23:07:20 +02:00
|
|
|
setIcon();
|
|
|
|
refreshBadgeAndMenu();
|
|
|
|
callback();
|
2017-01-19 06:21:20 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function fullSync(override) {
|
|
|
|
override = override || false;
|
|
|
|
bg_syncService.getLastSync(function (lastSync) {
|
|
|
|
var syncInternal = 6 * 60 * 60 * 1000; // 6 hours
|
|
|
|
var lastSyncAgo = new Date() - lastSync;
|
|
|
|
if (override || !lastSync || lastSyncAgo >= syncInternal) {
|
|
|
|
bg_syncService.fullSync(override || false, function () {
|
|
|
|
scheduleNextSync();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
2017-09-09 14:40:15 +02:00
|
|
|
scheduleNextSync();
|
2017-09-09 17:42:12 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function scheduleNextSync() {
|
|
|
|
if (syncTimeout) {
|
|
|
|
clearTimeout(syncTimeout);
|
2016-09-22 02:13:52 +02:00
|
|
|
}
|
2017-09-09 14:40:15 +02:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
syncTimeout = setTimeout(fullSync, 5 * 60 * 1000); // check every 5 minutes
|
2017-09-09 14:40:15 +02:00
|
|
|
}
|
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
// Bootstrap
|
2017-09-04 18:09:11 +02:00
|
|
|
|
2017-09-09 17:42:12 +02:00
|
|
|
bg_environmentService.setUrlsFromStorage(function () {
|
|
|
|
setIcon();
|
|
|
|
cleanupbg_loginsToAdd();
|
|
|
|
fullSync(true);
|
|
|
|
});
|
|
|
|
})();
|