diff --git a/Info.plist b/Info.plist index 4e6a08a..b2ce805 100644 --- a/Info.plist +++ b/Info.plist @@ -13,26 +13,13 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleShortVersionString - 1.0.alpha1 + 1.0.alpha2 CFBundleVersion - 0.8.1 + 0.8.2 Chrome Global Page global.html - Popovers - - - Filename - popovers/credentials.html - Height - - Identifier - passafari_credentials - Width - - - Toolbar Items @@ -46,6 +33,8 @@ Label passafari + Menu + Popover @@ -59,10 +48,6 @@ end.js - Start - - start.js - Description @@ -81,6 +66,8 @@ All + Update Manifest URL + https://raw.githubusercontent.com/mmichaa/passafari.safariextension/master/Update.plist Website https://github.com/mmichaa/passafari.safariextension/ diff --git a/Update.plist b/Update.plist index 447432d..dd9815d 100644 --- a/Update.plist +++ b/Update.plist @@ -10,11 +10,11 @@ Developer Identifier 897X8SYVFR CFBundleVersion - 1.0.alpha1 + 1.0.alpha2 CFBundleShortVersionString - 0.8.1 + 0.8.2 URL - https://github.com/mmichaa/passafari.safariextension/releases/download/v1.0.alpha1/passafari-v1.0.alpha1.safariextz + https://github.com/mmichaa/passafari.safariextension/releases/download/v1.0.alpha2/passafari-v1.0.alpha2.safariextz diff --git a/end.js b/end.js index 928f842..62aa712 100644 --- a/end.js +++ b/end.js @@ -1,19 +1,17 @@ console.log('passafari: end.js'); -var passafari_injected_end; - function passafari_injected_message_handler(event) { var name = event.name; var data = event.message; console.log("passafari_injected_message_handler: " + name); - if(name === "credentials") { + if(name === "passafari_credentials") { passafari_injected_credentials_handler(name, data); } return undefined; -}; +} function passafari_injected_credentials_handler(event_name, event_data) { if(event_data.length === 1) { @@ -37,10 +35,9 @@ function passafari_injected_credentials_handler(event_name, event_data) { return undefined; } -if(!passafari_injected_end && window.parent === window) { - console.log('passafari: passafari_injected_end'); +if(window.parent === window) { + console.log('passafari: window.top'); safari.self.addEventListener("message", passafari_injected_message_handler, false); - passafari_injected_end = true; } function passafari_input_candidates() { @@ -78,5 +75,15 @@ function passafari_input_candidates() { } } + for(var candidate_idx=0; candidate_idx < candidates.length; candidate_idx++) { + var inputs = candidates[candidate_idx]; + + if (inputs.username === document.activeElement || inputs.password === document.activeElement) { + console.log("passafari_input_candidates: using focused fields.") + candidates = [ inputs ]; + break; + } + } + return candidates; } \ No newline at end of file diff --git a/global.js b/global.js index cbaf0ec..52d6b6b 100644 --- a/global.js +++ b/global.js @@ -1,9 +1,11 @@ function passafari_command_handler(event) { console.log("passafari_command_handler: " + event.command); - if (event.command == "passafari_open") { + if (event.command === "passafari_open") { passafari_open(event); - } else if (event.command == "passafari-associate") { - passafari_associate(event); + } else if (event.command === "passafari_select_credentials") { + passafari_select_credentials(event); + } else { + console.log(event); } return undefined; }; @@ -12,26 +14,14 @@ function passafari_message_handler(event) { console.log("passafari_message_handler: " + event.name); if (event.name == "passafari_associate") { passafari_associate(event); + } else { + console.log(event); } return undefined; }; -function passafari_popover_handler(event) { - console.log("passafari_popover_handler: " + event.target.identifier); - - return undefined; -} - -function passafari_validate_handler(event) { - console.log("passafari_validate_handler: " + event.command); - return undefined; -} - safari.application.addEventListener("command", passafari_command_handler, false); safari.application.addEventListener("message", passafari_message_handler, false); -safari.application.addEventListener("popover", passafari_popover_handler, true); -safari.application.addEventListener("validate", passafari_validate_handler, true); - function passafari_open(event) { passafari_associate(); @@ -41,7 +31,7 @@ function passafari_open(event) { } else if (credentials.length === 1) { passafari_notify_injected(credentials); } else { - //passafari_display_credentials(credentials); + passafari_display_credentials(credentials); } }); @@ -69,7 +59,7 @@ function passafari_retrieve_credentials(callback) { var tab = undefined; var url = safari.application.activeBrowserWindow.activeTab.url; var submiturl = undefined; - var forceCallback = function() {}; + var forceCallback = false; var triggerUnlock = true; if(callback && url) { @@ -80,34 +70,38 @@ function passafari_retrieve_credentials(callback) { } function passafari_display_credentials(credentials) { - var toolbar_item = safari.extension.toolbarItems[0]; + var toolbarItem = safari.extension.toolbarItems[0]; - if(!toolbar_item.popover) { - var width = 300; - var height = 400; + safari.extension.removeMenu("passafari_credentials"); + var menu = safari.extension.createMenu("passafari_credentials"); - var popover = safari.extension.createPopover("credentials", safari.extension.baseURI + "popovers/credentials.html", width, height); + for(var idx = 0; idx < credentials.length; idx++) { + var credential = credentials[idx]; - toolbar_item.popover = popover; + menu.appendMenuItem("passafari_credentials_" + idx, credential.Login + " | " + credential.Name, "passafari_select_credentials"); } - var popover_document = toolbar_item.popover.contentWindow.document; - var ul = popover_document.getElementById("credentials-list"); - ul.innerHTML = ""; + toolbarItem.menu = menu; + toolbarItem.showMenu(); - for(var idx = 0; idx < credentials.length; idx++) { - var credential = credentials[idx]; - var li = popover_document.createElement("li"); - var li_text = popover_document.createTextNode(credential.Login + ' | ' + credential.Name); - li.appendChild(li_text); - ul.appendChild(li); - } + return undefined; +} + +function passafari_select_credentials(event) { + var idx = parseInt( event.target.identifier.split("_").pop() ); - toolbar_item.showPopover(); + passafari_retrieve_credentials(function(credentials) { + if (credentials.length === 0) { + } else if (credentials.length === 1) { + passafari_notify_injected(credentials); + } else { + passafari_notify_injected([ credentials[idx] ]); + } + }); return undefined; } function passafari_notify_injected(credentials) { - safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("credentials", credentials); + safari.application.activeBrowserWindow.activeTab.page.dispatchMessage("passafari_credentials", credentials); } \ No newline at end of file diff --git a/javascripts/keepass.js b/javascripts/keepass.js index 5a14680..061309b 100644 --- a/javascripts/keepass.js +++ b/javascripts/keepass.js @@ -49,7 +49,7 @@ keepass.updateCredentials = function(callback, tab, entryId, username, password, // is browser associated to keepass? if(!keepass.testAssociation(tab)) { - browserAction.showDefault(null, tab); + //browserAction.showDefault(null, tab); callback("error"); return; } @@ -102,7 +102,7 @@ keepass.retrieveCredentials = function (callback, tab, url, submiturl, forceCall // is browser associated to keepass? if(!keepass.testAssociation(tab, triggerUnlock)) { - browserAction.showDefault(null, tab); + //browserAction.showDefault(null, tab); if(forceCallback) { callback([]); } @@ -146,15 +146,16 @@ keepass.retrieveCredentials = function (callback, tab, url, submiturl, forceCall keepass.updateLastUsed(keepass.databaseHash); if(entries.length == 0) { //questionmark-icon is not triggered, so we have to trigger for the normal symbol - browserAction.showDefault(null, tab); + //browserAction.showDefault(null, tab); + console.log("No credentials found for " + url + "."); } } else { - console.log("RetrieveCredentials for " + url + " rejected"); + console.log("Retrieve credentials for " + url + " rejected."); } } else { - browserAction.showDefault(null, tab); + //browserAction.showDefault(null, tab); } //page.debug("keepass.retrieveCredentials() => entries.length = {1}", entries.length); @@ -166,7 +167,7 @@ keepass.retrieveCredentials = function (callback, tab, url, submiturl, forceCall keepass.generatePassword = function (callback, tab, forceCallback) { // is browser associated to keepass? if(!keepass.testAssociation(tab)) { - browserAction.showDefault(null, tab); + //browserAction.showDefault(null, tab); if(forceCallback) { callback([]); } @@ -217,7 +218,7 @@ keepass.generatePassword = function (callback, tab, forceCallback) { } } else { - browserAction.showDefault(null, tab); + //browserAction.showDefault(null, tab); } callback(passwords); diff --git a/popovers/credentials.html b/popovers/credentials.html deleted file mode 100644 index 4cd08ac..0000000 --- a/popovers/credentials.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - -

Credentials

- - - \ No newline at end of file diff --git a/start.js b/start.js index 9b1db9e..a5faac3 100644 --- a/start.js +++ b/start.js @@ -1,10 +1,5 @@ -/* console.log('passafari: start.js'); -var passafari_injected_start; - -if(!passafari_injected_start && window.parent === window) { - console.log('passafari: passafari_injected_start'); - passafari_injected_start = true; -} -*/ \ No newline at end of file +if(window.parent === window) { + console.log('passafari: window.top'); +} \ No newline at end of file