From 4e2f528939c61b1759f76fdab7910b68c55dd7be Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Mon, 27 Dec 2010 18:32:47 -0800 Subject: [PATCH] fix form autocomplete to support multiple service sources the web progress listener still does not setup the message event listener at the correct time --- .../src/chrome/content/overlay.js | 56 +++++++++++-------- .../src/components/nsFormFillOverride.js | 20 ++++--- .../src/modules/ffshareAutoCompleteData.js | 20 +++++-- 3 files changed, 58 insertions(+), 38 deletions(-) diff --git a/extensions/firefox-share/src/chrome/content/overlay.js b/extensions/firefox-share/src/chrome/content/overlay.js index 36a4368..3b135d9 100755 --- a/extensions/firefox-share/src/chrome/content/overlay.js +++ b/extensions/firefox-share/src/chrome/content/overlay.js @@ -132,26 +132,11 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org"; onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus) { var flags = Components.interfaces.nsIWebProgressListener; - if (aStateFlags & flags.STATE_IS_WINDOW && - aStateFlags & flags.STATE_STOP) { - var status; - - try { - status = aRequest.nsIHttpChannel.responseStatus; - } catch (e) { - //Could be just an invalid URL or not an http thing. Need to be sure to not endlessly - //load error page if it is already loaded. - if (this.tabFrame.shareFrame.contentWindow.location.href !== ffshare.errorPage) { - status = 1000; - } else { - status = 200; - } - } - - if (status < 200 || status > 399) { - this.tabFrame.shareFrame.contentWindow.location = ffshare.errorPage; - } else { + if (aStateFlags & flags.STATE_IS_DOCUMENT && + (aStateFlags & flags.STATE_START)) { + dump("YES! adding message listener now!\n"); this.tabFrame.shareFrame.contentWindow.wrappedJSObject.addEventListener("message", fn.bind(this, function (evt) { + dump("message received\n"); //Make sure we only act on messages from the page we expect. if (ffshare.prefs.share_url.indexOf(evt.origin) === 0) { //Mesages have the following properties: @@ -176,6 +161,26 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org"; } } }), false); + } else + if (aStateFlags & flags.STATE_IS_DOCUMENT && + aStateFlags & flags.STATE_STOP) { + var status; + + try { + status = aRequest.nsIHttpChannel.responseStatus; + } catch (e) { + //Could be just an invalid URL or not an http thing. Need to be sure to not endlessly + //load error page if it is already loaded. + if (this.tabFrame.shareFrame.contentWindow.location.href !== ffshare.errorPage) { + status = 1000; + } else { + status = 200; + } + } + + if (status < 200 || status > 399) { + this.tabFrame.shareFrame.contentWindow.location = ffshare.errorPage; + } else { } } }, @@ -184,7 +189,7 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org"; onProgressChange: function (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {}, onSecurityChange: function (aWebProgress, aRequest, aState) {}, onStatusChange: function (aWebProgress, aRequest, aStatus, aMessage) { - //log("onStatus Change: " + aRequest.nsIHttpChannel.responseStatus + ": " + aRequest.loadFlags + ", " + aRequest + ", " + aMessage); + //dump("onStatus Change: " + aRequest.nsIHttpChannel.responseStatus + ": " + aRequest.loadFlags + ", " + aRequest + ", " + aMessage+"\n"); } }; @@ -265,7 +270,7 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org"; var shareFrameProgress = this.shareFrame.webProgress; this.stateProgressListener = new StateProgressListener(this); - shareFrameProgress.addProgressListener(this.stateProgressListener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_WINDOW); + this.shareFrame.addProgressListener(this.stateProgressListener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT); this.navProgressListener = new NavProgressListener(this); gBrowser.getBrowserForTab(this.tab).webProgress.addProgressListener(this.navProgressListener, Components.interfaces.nsIWebProgress.NOTIFY_LOCATION); @@ -304,7 +309,7 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org"; if (iframeNode === null) { //Create the iframe. - iframeNode = document.createElement("browser"); + this.shareFrame = iframeNode = document.createElement("browser"); //Allow the rich autocomplete, something built into gecko. iframeNode.setAttribute('autocompletepopup', 'PopupAutoCompleteRichResult'); @@ -342,8 +347,9 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org"; '#options=' + encodeURIComponent(JSON.stringify(options)); iframeNode.setAttribute("type", "content"); - iframeNode.setAttribute("src", url); notificationBox.insertBefore(iframeNode, notificationBox.firstChild); + this.registerListener(); + iframeNode.setAttribute("src", url); } return (this.shareFrame = iframeNode); }, @@ -382,7 +388,7 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org"; this.visible = true; - this.registerListener(); + //this.registerListener(); }, /** @@ -631,6 +637,8 @@ var FFSHARE_EXT_ID = "ffshare@mozilla.org"; }, autoCompleteData: function (data) { + dump("ffshare got data\n"); + dump(" autoCompleteData for "+data.domain+"\n"); ffshareAutoCompleteData.set(data); } }; diff --git a/extensions/firefox-share/src/components/nsFormFillOverride.js b/extensions/firefox-share/src/components/nsFormFillOverride.js index 0938243..23119cf 100644 --- a/extensions/firefox-share/src/components/nsFormFillOverride.js +++ b/extensions/firefox-share/src/components/nsFormFillOverride.js @@ -27,7 +27,7 @@ const Cu = Components.utils; Cu.import("resource://gre/modules/XPCOMUtils.jsm"); function _() { - return; // comment out for verbose debugging + //return; // comment out for verbose debugging let msg = Array.join(arguments, " "); dump(msg + "\n"); Cu.reportError(msg); @@ -35,7 +35,6 @@ function _() { _("?loaded"); __defineGetter__("acDataStorage", function() { - delete this.ffshareAutoCompleteData; Cu.import("resource://ffshare/modules/ffshareAutoCompleteData.js"); return ffshareAutoCompleteData; }); @@ -64,13 +63,16 @@ FFShareAutoComplete.prototype = { return false; }, - findEmails: function findEmails(query) { + findEmails: function findEmails(query, field) { _("findEmails", Array.slice(arguments)); - let result = Cc["@mozilla.org/autocomplete/simple-result;1"]. createInstance(Ci.nsIAutoCompleteSimpleResult); result.setSearchString(query); + let datadomain = field.getAttribute('autocompletestore'); + if (!datadomain) + return result; + //convert the query to only be for things after the comma. var parts = query.split(','), previousMatch = ''; @@ -83,13 +85,13 @@ FFShareAutoComplete.prototype = { _("query is now: [" + query + "]"); _("previousMatch is now: " + previousMatch); - - let data = acDataStorage.get(); - +_("data domain is: "+datadomain); + let data = acDataStorage.get(datadomain); +_("matching against "+data.length+" entries"); data.forEach(function (item) { var displayNameLower = item.displayName.toLowerCase(), emailLower = item.email.toLowerCase(); - +_("match? "+displayNameLower+" "+emailLower); if (displayNameLower.indexOf(query) !== -1 || emailLower.indexOf(query) !== -1) { result.appendMatch(previousMatch + item.email + ', ', (displayNameLower === emailLower ? item.email : item.displayName + '<' + item.email + '>'), null, 'ffshare'); @@ -106,7 +108,7 @@ _("previousMatch is now: " + previousMatch); _("FFShareAutoComplete search", Array.slice(arguments)); if (this.isShareType(name, field)) - return this.findEmails(query); + return this.findEmails(query, field); return null; } }; diff --git a/extensions/firefox-share/src/modules/ffshareAutoCompleteData.js b/extensions/firefox-share/src/modules/ffshareAutoCompleteData.js index 0faa1a2..9b16097 100644 --- a/extensions/firefox-share/src/modules/ffshareAutoCompleteData.js +++ b/extensions/firefox-share/src/modules/ffshareAutoCompleteData.js @@ -20,16 +20,26 @@ * * Contributor(s): * */ +const Cu = Components.utils; let EXPORTED_SYMBOLS = ["ffshareAutoCompleteData"]; -let data = []; +let data = {}; + +function _() { + //return; // comment out for verbose debugging + let msg = Array.join(arguments, " "); + dump(msg + "\n"); + Cu.reportError(msg); +} let ffshareAutoCompleteData = { - get: function () { - return data; + get: function (domain) { + _("XXX getting data for "+domain); + return data[domain]; }, - set: function (newData) { - data = (newData || []); + set: function (acdata) { + _("XXX setting "+acdata.contacts.length+" contacts for "+acdata.domain); + data[acdata.domain] = (acdata.contacts || []); } };