diff --git a/content/bookmarks.js b/content/bookmarks.js index 41a88f90..fdcffa93 100644 --- a/content/bookmarks.js +++ b/content/bookmarks.js @@ -503,7 +503,7 @@ function Bookmarks() //{{{ return searchEngines; }, - getSuggestions: function getSuggestions(engine, query) + getSuggestions: function getSuggestions(engine, query, callback) { let ss = Components.classes["@mozilla.org/browser/search-service;1"] .getService(Components.interfaces.nsIBrowserSearchService); @@ -515,16 +515,25 @@ function Bookmarks() //{{{ if (!queryURI) return []; - let resp = util.httpGet(queryURI); - let json = Components.classes["@mozilla.org/dom/json;1"] - .createInstance(Components.interfaces.nsIJSON); - try + function process(resp) { - let results = json.decode(resp.responseText)[1]; - return [[item, ""] for ([k, item] in Iterator(results)) if (typeof item == "string")]; + let json = Components.classes["@mozilla.org/dom/json;1"] + .createInstance(Components.interfaces.nsIJSON); + let results = []; + try + { + results = json.decode(resp.responseText)[1]; + results = [[item, ""] for ([k, item] in Iterator(results)) if (typeof item == "string")]; + } + catch (e) {} + if (!callback) + return results; + callback(results); } - catch (e) {} - return []; + + let resp = util.httpGet(queryURI, callback && process); + if (!callback) + return process(resp); }, // TODO: add filtering diff --git a/content/completion.js b/content/completion.js index e4c3f0fc..23aed55b 100644 --- a/content/completion.js +++ b/content/completion.js @@ -1514,10 +1514,13 @@ function Completion() //{{{ let ctxt = context.fork(name, 0); ctxt.title = [engine.description + " Suggestions"]; - ctxt.background = true; ctxt.compare = null; - ctxt.regenerate = true; - ctxt.generate = function () bookmarks.getSuggestions(name, this.filter); + ctxt.incomplete = true; + bookmarks.getSuggestions(name, ctxt.filter, function (compl) { + ctxt.incomplete = false; + ctxt.completions = compl; + liberator.dump(compl); + }); }); }, diff --git a/content/util.js b/content/util.js index 4ca214d2..26eaa998 100644 --- a/content/util.js +++ b/content/util.js @@ -285,18 +285,25 @@ const util = { //{{{ return ret; }, - httpGet: function httpGet(url) + httpGet: function httpGet(url, callback) { try { - var xmlhttp = new XMLHttpRequest(); - xmlhttp.open("GET", url, false); + let xmlhttp = new XMLHttpRequest(); + if (callback) + { + xmlhttp.onreadystatechange = function () { + if (xmlhttp.readyState == 4) + callback(xmlhttp) + } + } + xmlhttp.open("GET", url, !!callback); xmlhttp.send(null); return xmlhttp; } catch (e) { - liberator.log("Error opening " + url, 1); + liberator.log("Error opening " + url + ": " + e, 1); } },