mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-06 20:14:11 +01:00
Perform search-suggest query asynchronously via async http request rather than background thread.
This commit is contained in:
@@ -503,7 +503,7 @@ function Bookmarks() //{{{
|
|||||||
return searchEngines;
|
return searchEngines;
|
||||||
},
|
},
|
||||||
|
|
||||||
getSuggestions: function getSuggestions(engine, query)
|
getSuggestions: function getSuggestions(engine, query, callback)
|
||||||
{
|
{
|
||||||
let ss = Components.classes["@mozilla.org/browser/search-service;1"]
|
let ss = Components.classes["@mozilla.org/browser/search-service;1"]
|
||||||
.getService(Components.interfaces.nsIBrowserSearchService);
|
.getService(Components.interfaces.nsIBrowserSearchService);
|
||||||
@@ -515,16 +515,25 @@ function Bookmarks() //{{{
|
|||||||
if (!queryURI)
|
if (!queryURI)
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
let resp = util.httpGet(queryURI);
|
function process(resp)
|
||||||
let json = Components.classes["@mozilla.org/dom/json;1"]
|
|
||||||
.createInstance(Components.interfaces.nsIJSON);
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
let results = json.decode(resp.responseText)[1];
|
let json = Components.classes["@mozilla.org/dom/json;1"]
|
||||||
return [[item, ""] for ([k, item] in Iterator(results)) if (typeof item == "string")];
|
.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
|
// TODO: add filtering
|
||||||
|
|||||||
@@ -1514,10 +1514,13 @@ function Completion() //{{{
|
|||||||
let ctxt = context.fork(name, 0);
|
let ctxt = context.fork(name, 0);
|
||||||
|
|
||||||
ctxt.title = [engine.description + " Suggestions"];
|
ctxt.title = [engine.description + " Suggestions"];
|
||||||
ctxt.background = true;
|
|
||||||
ctxt.compare = null;
|
ctxt.compare = null;
|
||||||
ctxt.regenerate = true;
|
ctxt.incomplete = true;
|
||||||
ctxt.generate = function () bookmarks.getSuggestions(name, this.filter);
|
bookmarks.getSuggestions(name, ctxt.filter, function (compl) {
|
||||||
|
ctxt.incomplete = false;
|
||||||
|
ctxt.completions = compl;
|
||||||
|
liberator.dump(compl);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -285,18 +285,25 @@ const util = { //{{{
|
|||||||
return ret;
|
return ret;
|
||||||
},
|
},
|
||||||
|
|
||||||
httpGet: function httpGet(url)
|
httpGet: function httpGet(url, callback)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var xmlhttp = new XMLHttpRequest();
|
let xmlhttp = new XMLHttpRequest();
|
||||||
xmlhttp.open("GET", url, false);
|
if (callback)
|
||||||
|
{
|
||||||
|
xmlhttp.onreadystatechange = function () {
|
||||||
|
if (xmlhttp.readyState == 4)
|
||||||
|
callback(xmlhttp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xmlhttp.open("GET", url, !!callback);
|
||||||
xmlhttp.send(null);
|
xmlhttp.send(null);
|
||||||
return xmlhttp;
|
return xmlhttp;
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
{
|
{
|
||||||
liberator.log("Error opening " + url, 1);
|
liberator.log("Error opening " + url + ": " + e, 1);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user