This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
/
pageaction_interface.js
57 lines (52 loc) · 1.78 KB
/
pageaction_interface.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function getActiveTab(callback) {
// Taken from: http://code.google.com/p/pgn4web/issues/detail?id=110
chrome.windows.getCurrent(function(win) {
chrome.tabs.query({
'windowId': win.id,
'active': true
},
function(tabArray) {
callback(tabArray[0]);
} );
});
}
// This is called when the user has PIN authenticated in the browser action
// popup. Fills in the forms on the current page.
function formFillCurrentTab() {
getActiveTab(function(tab) {
var tabID = tab.id;
getPageDataForPopup(function (logins) {
// TODO: Find out how to present a user with a choice if they have
// more than one login saved for the current domain.
chrome.tabs.sendMessage(tabID,{
type: 'fill_form',
login: logins[0]
});
});
});
}
function getPageDataForPopup(callback) {
getActiveTab(function(tab) {
var newURL = new Uri(tab.url);
getLoginsForSite(newURL.host(),function(logins) {
// if (logins.length == 0) return;
callback(logins);
});
});
}
chrome.tabs.onUpdated.addListener(function(tabId,changeInfo) {
console.log('tab onupdated!');
if (changeInfo.url) {
var newURL = new Uri(changeInfo.url);
getLoginsForSite(newURL.host(), function(logins) {
console.log('Found ', logins.length, " logins for ", newURL.host());
// console.log(newURL.host(),' is the newest domain on tab ',tabId);
if (logins.length > 0) {
console.log('calling show for tab ', tabId, ' on url ', changeInfo.url);
chrome.pageAction.show(tabId);
}
});
}
});
function getCurrentTabInfo() {
}