bug 337178 - hook up remote search suggestions, r=gavin, a=bonecho drivers

This commit is contained in:
mconnor%steelgryphon.com 2006-05-08 21:41:54 +00:00
Родитель 957ea17717
Коммит 87a363948c
6 изменённых файлов: 49 добавлений и 4 удалений

Просмотреть файл

@ -48,6 +48,7 @@ XPIDL_MODULE = browsersearch
XPIDLSRCS = nsIBrowserSearchService.idl
EXTRA_PP_COMPONENTS = nsSearchService.js
EXTRA_PP_COMPONENTS = nsSearchService.js \
nsSearchSuggestions.js
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -108,6 +108,9 @@
Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.addObserver(this, "browser-search-engine-modified", false);
// make sure we're using the right autocomplete
this._updateAutocompleteSearch();
]]></body>
</method>
@ -355,11 +358,31 @@
if (newIndex >= 0 && newIndex < this._engines.length)
this.currentEngine = this._engines[newIndex];
this._updateAutocompleteSearch()
aEvent.preventDefault();
aEvent.stopPropagation();
]]></body>
</method>
<method name="_updateAutocompleteSearch">
<body><![CDATA[
var autocompleteSearch = this.currentEngine.suggestionURI ?
"remote-url-suggestions" :
"form-history";
this._textbox.setAttribute("autocompletesearch", autocompleteSearch);
this._textbox.mSearchNames = null;
// Resetting the input property causes the field to notify
// the autocomplete controller that the search service(s) it must
// use have changed. We have no means of notifying it about this
// change directly.
this._textbox.mController.input = null;
this._textbox.mController.input = this._textbox;
]]></body>
</method>
<method name="handleSearchCommand">
<parameter name="aEvent"/>
<body><![CDATA[

Просмотреть файл

@ -41,7 +41,7 @@
interface nsIURI;
interface nsIInputStream;
[scriptable, uuid(ebe9f0f6-ca5a-415a-b578-82e2db61fb2a)]
[scriptable, uuid(58e4f602-a7c8-4cd1-9dca-716705e826ef)]
interface nsISearchSubmission : nsISupports
{
/**
@ -112,6 +112,11 @@ interface nsISearchEngine : nsISupports
*/
attribute boolean hidden;
/**
* A URI object for retrieving suggested searches
*/
readonly attribute nsIURI suggestionURI;
/**
* A nsIURI corresponding to the engine's icon, stored locally. May be null.
*/

Просмотреть файл

@ -383,11 +383,11 @@ function closeSafeOutputStream(aFOS) {
* The URL string from which to create an nsIURI.
* @returns an nsIURI object, or null if the creation of the URI failed.
*/
function makeURI(aURLSpec) {
function makeURI(aURLSpec, aCharset) {
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
try {
return ios.newURI(aURLSpec, null, null);
return ios.newURI(aURLSpec, aCharset, null);
} catch (ex) { }
return null;
@ -1143,6 +1143,9 @@ Engine.prototype = {
case "InputEncoding":
this._queryCharset = child.textContent.toUpperCase();
break;
case "SuggestionURL":
this._createSuggestionURI(child.textContent);
break;
}
}
ENSURE(this.name && (this._urls.length > 0),
@ -1509,6 +1512,13 @@ Engine.prototype = {
closeSafeOutputStream(fos);
},
_createSuggestionURI: function SRCH_ENG_createSuggestionURI (aURLString) {
var suggestionURI = makeURI(aURLString, this._queryCharset);
if (suggestionURI &&
(suggestionURI.schemeIs("http") || suggestionURI.schemeIs("https")))
this._suggestionURI = suggestionURI;
},
/**
* Remove the engine's file from disk. The search service calls this once it
* removes the engine from its internal store. This function will throw if
@ -1557,6 +1567,10 @@ Engine.prototype = {
}
},
get suggestionURI() {
return this._suggestionURI;
},
get iconURI() {
return this._iconURI;
},

Просмотреть файл

@ -3,6 +3,7 @@
<os:Description>Google Search</os:Description>
<os:InputEncoding>UTF-8</os:InputEncoding>
<os:Image width="16" height="16">data:image/x-icon;base64,R0lGODlhEAAQAPfLAAATVikwdA8SnxUfgAsWpAAilholjxw4jBc7kwAlvQQ2sRMsoBUqqhMzuhY/vxw4tSgmiyM1mSUztiQ6sTE3sQ4qyxMxxRoyxiAuxR1CtBxJsBxasSJuuTFguBte0Rlf2xVc9h9W9xVjzxVr0gdj6BRh4R1o5yBcyiZbyydT1i9b2Ddb1iFY6CJg2Vpor1dzvEJu20Z0yi23QDy1REi2OUy0O1WzOVC4PU+tVUe5Sk2xQU2zRUO4UE21Ula2SmKEqWWF2HyPx2+a6X6e6Xqk1m+s78sUDs4UGdEQB9YfDdwaANEfHd0YEscjAM4mAM0qANIoD9IkGdslGswuItYgL4aP0ImP2YGZ36Opzaq2wq/S+rzX/7/e8MrS1MLO/sTb48rT8snX/83c89PZ+crq+cH1/9Dl/9Ln/93r/9fy/+Hf7P/42eDm/O7u/+T29uX2/eT2/+f4/+f5/+j/9u//8+3/9u7/9ur5/+j//+n//+v//u3//+7//e7//+////b66/T/6vX/6/f/7f/07fj/4fv/4Pj/5v/45v7/4/r+7/3/6fDw+Pfx//D/9/X/8fT/8/f/8ff/8/D///H///L8/fL///P///X7//b6/ff/+/T///b9//f///v19//w9v/09P/29v/x+f/y///z///1+v/1///2///3//j79P/58/z/8/z99/z/9v7/9P7/9vn7//v6//j9//n9//j///n///v//vv////4+v/5+//6+P/4///6/P/6/v/6///7///9+P/8+v/9+v7/+Pz////8/f/9/f79///8///9//7//////////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAMsALAAAAAAQABAAAAj/AEn4oIFjBw8bOnrMuJGjhowZM1T8UdYJUZ5ZcNRYWjSrVK5QU0DMmtUnzRAXEy4o6FCEy6NDTkQIq1MmRgM0eZTlCXMgQJtRSE4gmgUkwh1EiZTNUiamy6NUUExcuoJgDCdDjQg9KgVL2SNFT1hwEvKglLBWuixZ+jSrlSBdRlL04bBBkTBdpZTpIqWsFaBcTEr0QaEhl6dWlswKW6poDRUPlmAUQKWMkTJLc76QMQNGUZMWgIgkCFJnlq5WXigwkFClVZQQyuRgELAlk7JBymCZGYAF0ZEPrQixgUDAihxVdPpoAZAFUZIRfThxgvPCwAILDipk+OFG2ZIVoxApERtPfvwlvZ+kQFzPvv0MJQEBADs=</os:Image>
<SuggestionURL>http://www.google.com/complete/search?csv=t&amp;qu=</SuggestionURL>
<os:Url type="text/html" method="GET" template="http://www.google.com/search">
<os:Param name="q" value="{searchTerms}"/>
<os:Param name="start" value="0"/>

Просмотреть файл

@ -2,6 +2,7 @@
<os:ShortName>Yahoo</os:ShortName>
<os:Description>Yahoo Search</os:Description>
<os:InputEncoding>UTF-8</os:InputEncoding>
<SuggestionURL>http://ff.search.yahoo.com/gossip?output=fxjson&amp;command=</SuggestionURL>
<os:Image width="16" height="16">data:image/x-icon;base64,R0lGODlhEAAQAJECAP8AAAAAAP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0NogQuyBDEnEd2kHkfFWUamEzmpZSfmaIHPHrRguUm/fT+UwAAOw==</os:Image>
<os:Url type="text/html" method="GET" template="http://search.yahoo.com/search">
<os:Param name="p" value="{searchTerms}"/>