diff --git a/src/background.js b/src/background.js
index 573ed40054..2941b84bff 100644
--- a/src/background.js
+++ b/src/background.js
@@ -1,4 +1,5 @@
var isBackground = true;
+var loginsToAdd = [];
var i18nService = new i18nService();
var constantsService = new ConstantsService();
var utilsService = new UtilsService();
@@ -56,15 +57,28 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
messageCurrentTab('closeOverlayPopup');
}
else if (msg.command === 'bgOpenNotificationBar') {
- messageCurrentTab('openNotificationBar');
+ messageCurrentTab('openNotificationBar', msg.data);
}
else if (msg.command === 'bgCloseNotificationBar') {
messageCurrentTab('closeNotificationBar');
}
+ else if (msg.command === 'bgCollectPageDetails') {
+ collectPageDetailsForContentScript(sender.tab);
+ }
+ else if (msg.command === 'bgAddLogin') {
+ addLogin(msg.login, sender.tab);
+ }
else if (msg.command === 'collectPageDetailsResponse') {
- clearTimeout(autofillTimeout);
- pageDetailsToAutoFill.push({ frameId: sender.frameId, tabId: msg.tabId, details: msg.details });
- autofillTimeout = setTimeout(autofillPage, 300);
+ // messageCurrentTab('openNotificationBar', { type: 'add', typeData: null });
+ if (msg.contentScript) {
+ var forms = autofillService.getFormsWithPasswordFields(msg.details);
+ messageTab(msg.tabId, 'pageDetails', { details: msg.details, forms: forms });
+ }
+ else {
+ clearTimeout(autofillTimeout);
+ pageDetailsToAutoFill.push({ frameId: sender.frameId, tabId: msg.tabId, details: msg.details });
+ autofillTimeout = setTimeout(autofillPage, 300);
+ }
}
});
@@ -156,6 +170,7 @@ function buildContextMenu(callback) {
}
chrome.tabs.onActivated.addListener(function (activeInfo) {
+ checkLoginsToAdd();
refreshBadgeAndMenu();
});
@@ -165,6 +180,7 @@ chrome.tabs.onReplaced.addListener(function (addedTabId, removedTabId) {
return;
}
onReplacedRan = true;
+ checkLoginsToAdd();
refreshBadgeAndMenu();
});
@@ -174,6 +190,7 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
return;
}
onUpdatedRan = true;
+ checkLoginsToAdd();
refreshBadgeAndMenu();
});
@@ -300,6 +317,60 @@ chrome.contextMenus.onClicked.addListener(function (info, tab) {
});
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;
+ }
+
+ messageTab(tabId, command, data);
+ });
+}
+
+function messageTab(tabId, command, data) {
+ if (!tabId) {
+ return;
+ }
+
+ var obj = {
+ command: command
+ };
+
+ if (data) {
+ obj['data'] = data;
+ }
+
+ chrome.tabs.sendMessage(tabId, obj);
+}
+
+function collectPageDetailsForContentScript(tab) {
+ chrome.tabs.sendMessage(tab.id, { command: 'collectPageDetails', tabId: tab.id, contentScript: true }, function () { });
+}
+
+function addLogin(login, tab) {
+ var loginDomain = tldjs.getDomain(login.url);
+ if (!loginDomain) {
+ return;
+ }
+
+ loginsToAdd.push({
+ username: login.username,
+ password: login.password,
+ name: loginDomain,
+ uri: login.url,
+ tabId: tab.id
+ });
+ checkLoginsToAdd();
+}
+
+function checkLoginsToAdd() {
+ if (!loginsToAdd.length) {
+ return;
+ }
+
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
var tabId = null;
if (tabs.length > 0) {
@@ -313,15 +384,17 @@ function messageCurrentTab(command, data) {
return;
}
- var obj = {
- command: command
- };
-
- if (data) {
- obj['data'] = data;
+ var tabDomain = tldjs.getDomain(tabs[0].url);
+ if (!tabDomain) {
+ return;
}
- chrome.tabs.sendMessage(tabId, obj);
+ for (var i = 0; i < loginsToAdd.length; i++) {
+ if (loginsToAdd[i].tabId === tabId && loginsToAdd[i].name === tabDomain) {
+ messageTab(tabId, 'openNotificationBar', { type: 'add' });
+ break;
+ }
+ }
});
}
diff --git a/src/content/autofill.js b/src/content/autofill.js
index 4c0157f0c3..d3361f13ef 100644
--- a/src/content/autofill.js
+++ b/src/content/autofill.js
@@ -90,7 +90,8 @@
chrome.runtime.sendMessage({
command: 'collectPageDetailsResponse',
tabId: msg.tabId,
- details: pageDetailsObj
+ details: pageDetailsObj,
+ contentScript: msg.contentScript ? true : false
});
sendResponse();
return true;
diff --git a/src/content/notificationBar.js b/src/content/notificationBar.js
index f518893c6e..4ca3fbdd49 100644
--- a/src/content/notificationBar.js
+++ b/src/content/notificationBar.js
@@ -1,8 +1,14 @@
!(function () {
+ var pageDetails = [],
+ formData = [];
+ chrome.runtime.sendMessage({
+ command: 'bgCollectPageDetails'
+ });
+
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.command === 'openNotificationBar') {
closeBar();
- openBar();
+ openBar(msg.data.type, msg.data.typeData);
sendResponse();
return true;
}
@@ -11,11 +17,103 @@
sendResponse();
return true;
}
+ else if (msg.command === 'pageDetails') {
+ console.log(msg.data);
+ pageDetails.push(msg.data.details);
+ watchForms(msg.data.forms);
+ sendResponse();
+ return true;
+ }
});
- function openBar() {
+ function watchForms(forms) {
+ if (!forms || !forms.length) {
+ return;
+ }
+
+ for (var i = 0; i < forms.length; i++) {
+ var form = null,
+ formId = forms[i].form ? forms[i].form.htmlID : null;
+
+ if (formId && formId !== '') {
+ form = document.getElementById(formId);
+ }
+
+ if (!form) {
+ var index = parseInt(forms[i].form.opid.split('__')[2]);
+ form = document.getElementsByTagName('form')[index];
+ }
+
+ if (form) {
+ forms[i].formElement = form;
+ formData.push(forms[i]);
+ form.addEventListener('submit', formSubmitted, false);
+ }
+ }
+ }
+
+ function formSubmitted(e) {
+ for (var i = 0; i < formData.length; i++) {
+ if (formData[i].formElement === e.target) {
+ var password = null,
+ username = null,
+ passwordId = formData[i].password ? formData[i].password.htmlID : null,
+ usernameId = formData[i].username ? formData[i].username.htmlID : null;
+
+ if (passwordId && passwordId !== '') {
+ password = document.getElementById(passwordId);
+ }
+ else if (formData[i].password) {
+ password = document.getElementsByTagName('input')[formData[i].password.elementNumber];
+ }
+
+ if (usernameId && usernameId !== '') {
+ username = document.getElementById(usernameId);
+ }
+ else if (formData[i].username) {
+ username = document.getElementsByTagName('input')[formData[i].username.elementNumber];
+ }
+
+ var login = {
+ username: username.value,
+ password: password.value,
+ url: document.URL
+ };
+
+ if (login.password && login.password !== '') {
+ chrome.runtime.sendMessage({
+ command: 'bgAddLogin',
+ login: login
+ });
+ break;
+ }
+ }
+ }
+ }
+
+ function openBar(type, typeData) {
+ var barPage = 'notification/bar.html';
+ switch (type) {
+ case 'info':
+ barPage = barPage + '?info=' + typeData.text;
+ break;
+ case 'warning':
+ barPage = barPage + '?warning=' + typeData.text;
+ break;
+ case 'error':
+ barPage = barPage + '?error=' + typeData.text;
+ break;
+ case 'success':
+ barPage = barPage + '?success=' + typeData.text;
+ break;
+ case 'add':
+ barPage = barPage + '?add=1';
+ default:
+ break;
+ }
+
var iframe = document.createElement('iframe');
- iframe.src = chrome.extension.getURL('notification/bar.html');
+ iframe.src = chrome.extension.getURL(barPage);
iframe.style.cssText = 'height: 41px; width: 100%; border: 0;';
var frameDiv = document.createElement('div');
diff --git a/src/notification/bar.css b/src/notification/bar.css
new file mode 100644
index 0000000000..cc882e533a
--- /dev/null
+++ b/src/notification/bar.css
@@ -0,0 +1,54 @@
+body {
+ background-color: #ffffff;
+ padding: 0;
+ margin: 0;
+ height: 100%;
+ font-size: 14px;
+ line-height: 16px;
+ color: #333333;
+ font-family: Arial, Helvetica, sans-serif;
+}
+
+table {
+ width: 100%;
+}
+
+.outter-table > tbody > tr > td {
+ padding: 0 0 0 10px;
+ border-bottom: 1px solid #333333;
+ height: 40px;
+}
+
+ .outter-table > tbody > tr > td:last-child {
+ padding-right: 10px;
+ }
+
+.inner-table td {
+ padding: 0 10px 0 0;
+}
+
+ .inner-table td:last-child {
+ padding: 0;
+ }
+
+ .inner-table td button {
+ margin-left: 5px;
+ }
+
+img {
+ border: 0;
+ margin: 0;
+ padding: 0;
+}
+
+#logo {
+ width: 24px;
+ height: 24px;
+ display: block;
+}
+
+#close {
+ width: 18px;
+ height: 18px;
+ display: block;
+}
diff --git a/src/notification/bar.html b/src/notification/bar.html
index feefa448bd..6d8a273ed0 100644
--- a/src/notification/bar.html
+++ b/src/notification/bar.html
@@ -3,74 +3,41 @@
-
-
+
-
-
-
-
- |
-
- This is the notification bar
- |
-
-
-
-
- |
-
+
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+
+
+
+
+
+ Should bitwarden remember this password for you? |
+
+
+
+ |
+
+
+
+
+ This is an alert.
+
+
+
+