From 1c6026c4b9329b4d0aa94238ef3e76c04b9118d4 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 10 Mar 2014 19:33:36 -0700 Subject: [PATCH] Fix search suggestion issues. --HG-- extra : rebase_source : 4aeeb43dc214f7ae2e8275fb6190556eade78890 --- common/content/bookmarks.js | 41 +++++++++++++++++++++++++++++++++---- common/content/hints.js | 2 ++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/common/content/bookmarks.js b/common/content/bookmarks.js index 3e3c254e..65905d9e 100644 --- a/common/content/bookmarks.js +++ b/common/content/bookmarks.js @@ -232,6 +232,31 @@ var Bookmarks = Module("bookmarks", { }).toObject(); }, + /** + * Returns true if the given search engine provides suggestions. + * engine based on the given *query*. The results are always in the + * form of an array of strings. If *callback* is provided, the + * request is executed asynchronously and *callback* is called on + * completion. Otherwise, the request is executed synchronously and + * the results are returned. + * + * @param {string} engineName The name of the search engine from + * which to request suggestions. + * @returns {boolean} + */ + hasSuggestions: function hasSuggestions(engineName, query, callback) { + const responseType = "application/x-suggestions+json"; + + if (hasOwnProperty(this.suggestionProviders, engineName)) + return true; + + let engine = hasOwnProperty(this.searchEngines, engineName) && this.searchEngines[engineName]; + if (engine && engine.supportsResponseType(responseType)) + return true; + + return false; + }, + /** * Retrieves a list of search suggestions from the named search * engine based on the given *query*. The results are always in the @@ -697,16 +722,19 @@ var Bookmarks = Module("bookmarks", { let engineList = (engineAliases || options["suggestengines"].join(",") || "google").split(","); engineList.forEach(function (name) { + if (!bookmarks.hasSuggestions(name)) + return; + var desc = name; let engine = bookmarks.searchEngines[name]; if (engine) - var desc = engine.description; - else if (!hasOwnProperty(bookmarks.suggestionProviders, name)) - return; + desc = engine.description; + let [, word] = /^\s*(\S+)/.exec(context.filter) || []; if (!kludge && word == name) // FIXME: Check for matching keywords return; + let ctxt = context.fork(name, 0); ctxt.title = [/*L*/desc + " Suggestions"]; @@ -727,7 +755,12 @@ var Bookmarks = Module("bookmarks", { ctxt.incomplete = false; ctxt.completions = array.uniq(ctxt.completions.filter(c => compl.contains(c)) .concat(compl), true); - }, Cu.reportError); + }, function (e) { + ctxt.incomplete = false; + ctxt.completions = []; + if (e) + Cu.reportError(e); + }); }); }; diff --git a/common/content/hints.js b/common/content/hints.js index d22bfcff..6995311e 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -305,6 +305,8 @@ var HintSession = Class("HintSession", CommandMode, { return false; let computedStyle = doc.defaultView.getComputedStyle(elem, null); + if (!computedStyle) + return false; if (computedStyle.visibility != "visible" || computedStyle.display == "none") return false; return true;