Created
November 9, 2010 15:49
-
-
Save autonome/669262 to your computer and use it in GitHub Desktop.
Jetpack module for querying the datasource that powers the Firefox awesomebar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Ci, Cc, Cu } = require("chrome"); | |
Cu.import("resource://gre/modules/Services.jsm", this); | |
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this); | |
function AutoCompleteInput(aSearches) { | |
this.searches = aSearches; | |
} | |
AutoCompleteInput.prototype = { | |
timeout: 10, | |
textValue: "", | |
searches: null, | |
searchParam: "", | |
popupOpen: false, | |
minResultsForPopup: 0, | |
invalidate: function() {}, | |
disableAutoComplete: false, | |
completeDefaultIndex: false, | |
get popup() { return this; }, | |
onSearchBegin: function() {}, | |
onSearchComplete: function() {}, | |
setSelectedIndex: function() {}, | |
get searchCount() { return this.searches.length; }, | |
getSearchAt: function(aIndex) this.searches[aIndex], | |
QueryInterface: XPCOMUtils.generateQI([ | |
Ci.nsIAutoCompleteInput, | |
Ci.nsIAutoCompletePopup, | |
]) | |
}; | |
exports.search = function search(options) { | |
let controller = Cc["@mozilla.org/autocomplete/controller;1"]. | |
getService(Ci.nsIAutoCompleteController); | |
// Make an AutoCompleteInput that uses our searches | |
// and confirms results on search complete | |
let input = new AutoCompleteInput(["history"]); | |
controller.input = input; | |
input.searchParam = options.search; | |
input.onSearchBegin = function() {}; | |
input.onSearchComplete = function onSearchComplete() { | |
let results = []; | |
for (let i = 0; i < controller.matchCount; i++) { | |
let result = { | |
url: controller.getValueAt(i), | |
title: controller.getCommentAt(i), | |
//label: controller.getLabelAt(i), | |
style: controller.getStyleAt(i), | |
image: controller.getImageAt(i) | |
}; | |
if (options.onResult) | |
options.onResult(result); | |
results.push(result); | |
} | |
if (options.onComplete) | |
options.onComplete(results); | |
}; | |
controller.startSearch(options.search); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please explain what is this and how I can use it?