mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 340868: Offer to re-add an autodiscovered search engine if user removes it. r=beng
This commit is contained in:
parent
661c6cdea5
commit
d6847d9cdd
@ -2962,16 +2962,6 @@ const BrowserSearch = {
|
||||
if (!etype)
|
||||
return;
|
||||
|
||||
if (target.title) {
|
||||
// If this engine (identified by title) is already in the list, ignore it.
|
||||
// XXX This will need to be changed when engines are identified by URL;
|
||||
// see bug 335102.
|
||||
var searchService = Components.classes["@mozilla.org/browser/search-service;1"]
|
||||
.getService(Components.interfaces.nsIBrowserSearchService);
|
||||
if (searchService.getEngineByName(target.title))
|
||||
return;
|
||||
}
|
||||
|
||||
if (etype == "application/opensearchdescription+xml" &&
|
||||
searchRelRegex.test(erel) && searchHrefRegex.test(ehref))
|
||||
{
|
||||
@ -2982,21 +2972,45 @@ const BrowserSearch = {
|
||||
if (searchButton) {
|
||||
var browser = gBrowser.getBrowserForDocument(targetDoc);
|
||||
// Append the URI and an appropriate title to the browser data.
|
||||
var engines = [];
|
||||
if (browser.engines)
|
||||
engines = browser.engines;
|
||||
|
||||
var iconURL = null;
|
||||
if (gBrowser.shouldLoadFavIcon(browser.currentURI))
|
||||
iconURL = browser.currentURI.prePath + "/favicon.ico";
|
||||
var usableTitle = target.title || browser.contentTitle || target.href;
|
||||
var hidden = false;
|
||||
if (target.title) {
|
||||
// If this engine (identified by title) is already in the list, add it
|
||||
// to the list of hidden engines rather than to the main list.
|
||||
// XXX This will need to be changed when engines are identified by URL;
|
||||
// see bug 335102.
|
||||
var searchService =
|
||||
Components.classes["@mozilla.org/browser/search-service;1"]
|
||||
.getService(Components.interfaces.nsIBrowserSearchService);
|
||||
if (searchService.getEngineByName(target.title))
|
||||
hidden = true;
|
||||
}
|
||||
|
||||
var engines = [];
|
||||
if (hidden) {
|
||||
if (browser.hiddenEngines)
|
||||
engines = browser.hiddenEngines;
|
||||
}
|
||||
else {
|
||||
if (browser.engines)
|
||||
engines = browser.engines;
|
||||
}
|
||||
|
||||
engines.push({ uri: target.href,
|
||||
title: usableTitle,
|
||||
icon: iconURL });
|
||||
browser.engines = engines;
|
||||
|
||||
if (browser == gBrowser || browser == gBrowser.mCurrentBrowser)
|
||||
this.updateSearchButton();
|
||||
if (hidden) {
|
||||
browser.hiddenEngines = engines;
|
||||
}
|
||||
else {
|
||||
browser.engines = engines;
|
||||
if (browser == gBrowser || browser == gBrowser.mCurrentBrowser)
|
||||
this.updateSearchButton();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -192,19 +192,93 @@
|
||||
<body><![CDATA[
|
||||
if (aTopic == "browser-search-engine-modified") {
|
||||
switch (aVerb) {
|
||||
case "engine-removed":
|
||||
this.offerNewEngine(aEngine);
|
||||
break;
|
||||
case "engine-added":
|
||||
this.hideNewEngine(aEngine);
|
||||
break;
|
||||
case "engine-current":
|
||||
// The current engine was changed. Rebuilding the menu appears to
|
||||
// confuse its idea of whether it should be open when it's just
|
||||
// been clicked, so we force it to close now.
|
||||
this._popup.hidePopup();
|
||||
// Fall through.
|
||||
case "engine-removed":
|
||||
case "engine-added":
|
||||
break;
|
||||
case "engine-changed":
|
||||
// An engine was removed (or hidden) or added, or an icon was
|
||||
// changed.
|
||||
this.rebuildPopup();
|
||||
this.updateDisplay();
|
||||
// changed. Do nothing special.
|
||||
}
|
||||
|
||||
// Rebuild the popup and update the display after any modification.
|
||||
this.rebuildPopup();
|
||||
this.updateDisplay();
|
||||
}
|
||||
}
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<!-- There are two seaprate lists of search engines, whose uses intersect
|
||||
in this file. The search service (nsIBrowserSearchService and
|
||||
nsSearchService.js) maintains a list of Engine objects which is used to
|
||||
populate the searchbox list of available engines and to perform queries.
|
||||
That list is accessed here via this.SearchService, and it's that sort of
|
||||
Engine that is passed to this binding's observer as aEngine.
|
||||
|
||||
In addition, browser.js fills two lists of autodetected search engines
|
||||
(browser.engines and browser.hiddenEngines) as properties of
|
||||
mCurrentBrowser. Those lists contain unnamed JS objects of the form
|
||||
{ uri:, title:, icon: }, and that's what the searchbar uses to determine
|
||||
whether to show any "Add <EngineName>" menu items in the drop-down.
|
||||
|
||||
The two types of engines are currently related by their identifying
|
||||
titles (the Engine object's 'name'), although that may change; see bug
|
||||
335102. -->
|
||||
|
||||
<!-- If the engine that was just removed from the searchbox list was
|
||||
autodetected on this page, move it to the browser's active list so it will
|
||||
be offered to be added again. -->
|
||||
<method name="offerNewEngine">
|
||||
<parameter name="aEngine"/>
|
||||
<body><![CDATA[
|
||||
var browser = getBrowser().mCurrentBrowser;
|
||||
if (browser.hiddenEngines) {
|
||||
// XXX This will need to be changed when engines are identified by
|
||||
// URL rather than title; see bug 335102.
|
||||
var removeTitle = aEngine.wrappedJSObject.name;
|
||||
for (var i = 0; i < browser.hiddenEngines.length; i++) {
|
||||
if (browser.hiddenEngines[i].title == removeTitle) {
|
||||
if (!browser.engines)
|
||||
browser.engines = [];
|
||||
browser.engines.push(browser.hiddenEngines[i]);
|
||||
browser.hiddenEngines.splice(i, 1);
|
||||
BrowserSearch.updateSearchButton();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<!-- If the engine that was just added to the searchbox list was
|
||||
autodetected on this page, move it to the browser's hidden list so it is
|
||||
no longer offered to be added. -->
|
||||
<method name="hideNewEngine">
|
||||
<parameter name="aEngine"/>
|
||||
<body><![CDATA[
|
||||
var browser = getBrowser().mCurrentBrowser;
|
||||
if (browser.engines) {
|
||||
// XXX This will need to be changed when engines are identified by
|
||||
// URL rather than title; see bug 335102.
|
||||
var removeTitle = aEngine.wrappedJSObject.name;
|
||||
for (var i = 0; i < browser.engines.length; i++) {
|
||||
if (browser.engines[i].title == removeTitle) {
|
||||
if (!browser.hiddenEngines)
|
||||
browser.hiddenEngines = [];
|
||||
browser.hiddenEngines.push(browser.engines[i]);
|
||||
browser.engines.splice(i, 1);
|
||||
BrowserSearch.updateSearchButton();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></body>
|
||||
@ -360,21 +434,6 @@
|
||||
var type = Components.interfaces.nsISearchEngine.DATA_XML;
|
||||
searchService.addEngine(aTarget.getAttribute("uri"), type,
|
||||
aTarget.getAttribute("src"), false);
|
||||
// Remove this engine from the list and refresh the search button.
|
||||
// XXX This will need to be changed when engines are identified
|
||||
// by URL; see bug 335102.
|
||||
var browser = getBrowser().mCurrentBrowser;
|
||||
var removeTitle = aTarget.getAttribute("title");
|
||||
// No need to null-check browser.engines, since it should contain at
|
||||
// least the item the user just chose.
|
||||
for (var i = 0; i < browser.engines.length; i++) {
|
||||
if (browser.engines[i].title == removeTitle) {
|
||||
browser.engines.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (browser.engines.length == 0)
|
||||
this._button.removeAttribute("addengines");
|
||||
}
|
||||
else if (aTarget.engine) {
|
||||
this.currentEngine = aTarget.engine;
|
||||
|
@ -26,6 +26,10 @@
|
||||
list-style-image: url("chrome://browser/skin/bookmarks/bookmark-item.png");
|
||||
}
|
||||
|
||||
.searchbar-popup {
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
.autocomplete-textbox-container {
|
||||
border: none;
|
||||
padding-right: 0px;
|
||||
|
@ -8,6 +8,10 @@
|
||||
-moz-image-region: rect(0px, 16px, 16px, 0px);
|
||||
}
|
||||
|
||||
.searchbar-popup {
|
||||
min-width: 100px;
|
||||
}
|
||||
|
||||
.search-go-button-container {
|
||||
border-left: 1px solid ThreeDShadow;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user