Bug 330887: see if async loading of search engines helps Ts, will back this out after a couple of cycles, a=mconnor
git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@193606 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -2829,6 +2829,7 @@ const BrowserSearch = {
|
||||
} else {
|
||||
var ss = Cc["@mozilla.org/browser/search-service;1"].
|
||||
getService(Ci.nsIBrowserSearchService);
|
||||
ss.init();
|
||||
var searchForm = ss.defaultEngine.searchForm;
|
||||
loadURI(searchForm, null, null);
|
||||
}
|
||||
@@ -2848,6 +2849,7 @@ const BrowserSearch = {
|
||||
loadSearch: function BrowserSearch_search(searchText, useNewTab) {
|
||||
var ss = Cc["@mozilla.org/browser/search-service;1"].
|
||||
getService(Ci.nsIBrowserSearchService);
|
||||
ss.init();
|
||||
var engine;
|
||||
|
||||
// If the search bar is visible, use the current engine, otherwise, fall back
|
||||
@@ -4873,11 +4875,14 @@ nsContextMenu.prototype = {
|
||||
if (selectedText.length > 15)
|
||||
selectedText = selectedText.substr(0,15) + "...";
|
||||
|
||||
var ss = Cc["@mozilla.org/browser/search-service;1"].
|
||||
getService(Ci.nsIBrowserSearchService);
|
||||
ss.init();
|
||||
|
||||
// Use the current engine if the search bar is visible, the default
|
||||
// engine otherwise.
|
||||
var engineName = "";
|
||||
var ss = Cc["@mozilla.org/browser/search-service;1"].
|
||||
getService(Ci.nsIBrowserSearchService);
|
||||
|
||||
if (BrowserSearch.getSearchBar())
|
||||
engineName = ss.currentEngine.name;
|
||||
else
|
||||
|
||||
@@ -81,19 +81,24 @@
|
||||
<implementation implements="nsIObserver">
|
||||
|
||||
<constructor><![CDATA[
|
||||
setTimeout(function (a) { a.init(); }, 0, this);
|
||||
var os =
|
||||
Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
os.addObserver(this, "browser-search-engine-modified", false);
|
||||
os.addObserver(this, "browser-search-service", false);
|
||||
|
||||
// Use the async init since we're loading on startup. We'll get
|
||||
// notified via the "browser-search-service" observer above when the
|
||||
// loading is done
|
||||
this.searchService.asyncInit();
|
||||
]]></constructor>
|
||||
|
||||
<method name="init">
|
||||
<method name="_init">
|
||||
<body><![CDATA[
|
||||
// Refresh the display (updating icon, etc)
|
||||
this.updateDisplay();
|
||||
this.populatePopup();
|
||||
|
||||
var os =
|
||||
Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
os.addObserver(this, "browser-search-engine-modified", false);
|
||||
this._initialized = true;
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
@@ -101,6 +106,7 @@
|
||||
var os = Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
os.removeObserver(this, "browser-search-engine-modified");
|
||||
os.removeObserver(this, "browser-search-service");
|
||||
]]></destructor>
|
||||
|
||||
<field name="_stringBundle">document.getAnonymousNodes(this)[0];</field>
|
||||
@@ -111,6 +117,7 @@
|
||||
"searchbar-popup");
|
||||
</field>
|
||||
<field name="_ss">null</field>
|
||||
<field name="_initialized">false</field>
|
||||
|
||||
<property name="currentEngine" onset="this.searchService.currentEngine = val;"
|
||||
onget="return this.searchService.currentEngine;"/>
|
||||
@@ -148,17 +155,24 @@
|
||||
<parameter name="aTopic"/>
|
||||
<parameter name="aVerb"/>
|
||||
<body><![CDATA[
|
||||
switch (aVerb) {
|
||||
case "engine-removed":
|
||||
case "engine-added":
|
||||
case "engine-changed":
|
||||
// An engine was removed (or hidden), added, or an icon was
|
||||
// changed
|
||||
this.populatePopup();
|
||||
// Fall through
|
||||
case "engine-current":
|
||||
// The current engine was changed
|
||||
this.updateDisplay();
|
||||
if (aTopic == "browser-search-engine-modified" && this._initialized) {
|
||||
switch (aVerb) {
|
||||
case "engine-removed":
|
||||
case "engine-added":
|
||||
case "engine-changed":
|
||||
// An engine was removed (or hidden), added, or an icon was
|
||||
// changed, so rebuild the popup menu
|
||||
this.populatePopup();
|
||||
// Fall through
|
||||
case "engine-current":
|
||||
// The current engine was changed, so just update the displayed
|
||||
// icon
|
||||
this.updateDisplay();
|
||||
break;
|
||||
}
|
||||
} else if (aTopic == "browser-search-service" &&
|
||||
aVerb == "ready") {
|
||||
this._init();
|
||||
}
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
@@ -134,7 +134,7 @@ interface nsISearchEngine : nsISupports
|
||||
|
||||
};
|
||||
|
||||
[scriptable, uuid(eaa8c60f-a0d7-4afe-b629-ab5ac9434298)]
|
||||
[scriptable, uuid(047b4ab0-3e9b-4cea-8bd8-c4ffc0a8462e)]
|
||||
interface nsIBrowserSearchService : nsISupports
|
||||
{
|
||||
/**
|
||||
@@ -187,6 +187,21 @@ interface nsIBrowserSearchService : nsISupports
|
||||
in AString method,
|
||||
in AString url);
|
||||
|
||||
/**
|
||||
* Initializes the search service asynchronously. Loads all saved engines
|
||||
* from disk and notifies observers of SEARCH_SERVICE_TOPIC with the
|
||||
* verb SEARCH_SERVICE_READY when done.
|
||||
* The notification is sent even if the search service is already
|
||||
* initialized.
|
||||
*/
|
||||
void asyncInit();
|
||||
|
||||
/**
|
||||
* Initializes the search service synchronously. Loads all saved engines from
|
||||
* disk. Must be called before using the search service.
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Returns an engine with the specified alias.
|
||||
*
|
||||
@@ -271,6 +286,30 @@ interface nsIBrowserSearchService : nsISupports
|
||||
*/
|
||||
#define SEARCH_ENGINE_ADDED "engine-added"
|
||||
|
||||
/**
|
||||
* Sent when the "current" engine is changed.
|
||||
*/
|
||||
#define SEARCH_ENGINE_CURRENT "engine-current";
|
||||
|
||||
/**
|
||||
* The observer topic to listen to for events related to the search service
|
||||
* itself.
|
||||
*/
|
||||
#define SEARCH_SERVICE_TOPIC "browser-search-service"
|
||||
|
||||
/**
|
||||
* Sent when the search service has finished loading all engines.
|
||||
*/
|
||||
#define SEARCH_SERVICE_READY "ready";
|
||||
|
||||
/**
|
||||
* Sent when a search engine being loaded from a file is completely loaded.
|
||||
* This is used internally by the search service as an indication of when the
|
||||
* engine can be added to the internal store, and therefore should not be used
|
||||
* to detect engine availability.
|
||||
*/
|
||||
#define SEARCH_SERVICE_ENGINE_LOADED "engine-loaded"
|
||||
|
||||
/**
|
||||
* Sent when a search engine being installed from a remote plugin description
|
||||
* file is completely loaded. This is used internally by the search service as
|
||||
@@ -278,11 +317,11 @@ interface nsIBrowserSearchService : nsISupports
|
||||
* therefore should not be used to detect engine availability. It is always
|
||||
* followed by an "added" notification.
|
||||
*/
|
||||
#define SEARCH_ENGINE_LOADED "engine-loaded"
|
||||
#define SEARCH_SERVICE_ENGINE_LOADED_REMOTE "engine-loaded-uri"
|
||||
|
||||
/**
|
||||
* Sent when the "current" engine is changed.
|
||||
* Sent to notify the search service that a search engine failed to load.
|
||||
*/
|
||||
#define SEARCH_ENGINE_CURRENT "engine-current";
|
||||
#define SEARCH_SERVICE_ENGINE_LOAD_FAILED "engine-load-failed";
|
||||
|
||||
%}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user