Bug 1017903 - Remove synchronous search service initialization. r=liuche

This commit is contained in:
Margaret Leibovic 2014-09-05 15:39:55 -07:00
parent b24ede1d47
commit 9a7620fe77

View File

@ -3936,50 +3936,52 @@ Tab.prototype = {
// Check that type matches opensearch. // Check that type matches opensearch.
let isOpenSearch = (type == "application/opensearchdescription+xml"); let isOpenSearch = (type == "application/opensearchdescription+xml");
if (isOpenSearch && target.title && /^(?:https?|ftp):/i.test(target.href)) { if (isOpenSearch && target.title && /^(?:https?|ftp):/i.test(target.href)) {
let visibleEngines = Services.search.getVisibleEngines(); Services.search.init(() => {
// NOTE: Engines are currently identified by name, but this can be changed let visibleEngines = Services.search.getVisibleEngines();
// when Engines are identified by URL (see bug 335102). // NOTE: Engines are currently identified by name, but this can be changed
if (visibleEngines.some(function(e) { // when Engines are identified by URL (see bug 335102).
return e.name == target.title; if (visibleEngines.some(function(e) {
})) { return e.name == target.title;
// This engine is already present, do nothing.
return;
}
if (this.browser.engines) {
// This engine has already been handled, do nothing.
if (this.browser.engines.some(function(e) {
return e.url == target.href;
})) { })) {
return; // This engine is already present, do nothing.
return;
} }
} else {
this.browser.engines = [];
}
// Get favicon. if (this.browser.engines) {
let iconURL = target.ownerDocument.documentURIObject.prePath + "/favicon.ico"; // This engine has already been handled, do nothing.
if (this.browser.engines.some(function(e) {
return e.url == target.href;
})) {
return;
}
} else {
this.browser.engines = [];
}
let newEngine = { // Get favicon.
title: target.title, let iconURL = target.ownerDocument.documentURIObject.prePath + "/favicon.ico";
url: target.href,
iconURL: iconURL
};
this.browser.engines.push(newEngine); let newEngine = {
title: target.title,
url: target.href,
iconURL: iconURL
};
// Don't send a message to display engines if we've already handled an engine. this.browser.engines.push(newEngine);
if (this.browser.engines.length > 1)
return;
// Broadcast message that this tab contains search engines that should be visible. // Don't send a message to display engines if we've already handled an engine.
let newEngineMessage = { if (this.browser.engines.length > 1)
type: "Link:OpenSearch", return;
tabID: this.id,
visible: true
};
Messaging.sendRequest(newEngineMessage); // Broadcast message that this tab contains search engines that should be visible.
let newEngineMessage = {
type: "Link:OpenSearch",
tabID: this.id,
visible: true
};
Messaging.sendRequest(newEngineMessage);
});
} }
} }
break; break;