Bug 336452: Improve search-engine confirmation dialog. r=mconnor, ui-r=beltzner
This commit is contained in:
@@ -359,7 +359,7 @@
|
||||
// We only detect OpenSearch files
|
||||
var type = Components.interfaces.nsISearchEngine.DATA_XML;
|
||||
searchService.addEngine(aTarget.getAttribute("uri"), type,
|
||||
aTarget.getAttribute("src"));
|
||||
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.
|
||||
|
||||
@@ -15,13 +15,14 @@
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Google Inc.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005-2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Ben Goodger <beng@google.com> (Original author)
|
||||
* Gavin Sharp <gavin@gavinsharp.com>
|
||||
* Joe Hughes <joe@retrovirus.com>
|
||||
* Pamela Greene <pamg.bugs@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -161,11 +162,12 @@ interface nsISearchEngine : nsISupports
|
||||
|
||||
};
|
||||
|
||||
[scriptable, uuid(5bcbc35a-8514-4583-9ef1-5bf5d10327f4)]
|
||||
[scriptable, uuid(89a503ac-ea67-4bad-89f9-aa2b06140702)]
|
||||
interface nsIBrowserSearchService : nsISupports
|
||||
{
|
||||
/**
|
||||
* Adds a new search engine from the file at the supplied URI.
|
||||
* Adds a new search engine from the file at the supplied URI and optionally
|
||||
* selects it as the current engine.
|
||||
*
|
||||
* @param engineURL
|
||||
* The URL to the search engine's description file.
|
||||
@@ -179,10 +181,15 @@ interface nsIBrowserSearchService : nsISupports
|
||||
* icon. This value may be overridden by an icon specified in the
|
||||
* engine description file.
|
||||
*
|
||||
* @param select
|
||||
* A boolean value indicating whether the newly added engine should
|
||||
* be selected as the current engine after it finishes loading.
|
||||
*
|
||||
* @throws NS_ERROR_FAILURE if the type is invalid, or if the description
|
||||
* file cannot be successfully loaded.
|
||||
*/
|
||||
void addEngine(in AString engineURL, in long type, in AString iconURL);
|
||||
void addEngine(in AString engineURL, in long type, in AString iconURL,
|
||||
in boolean select);
|
||||
|
||||
/**
|
||||
* Adds a new search engine.
|
||||
|
||||
@@ -15,13 +15,14 @@
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Google Inc.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2005
|
||||
# Portions created by the Initial Developer are Copyright (C) 2005-2006
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Ben Goodger <beng@google.com> (Original author)
|
||||
# Gavin Sharp <gavin@gavinsharp.com>
|
||||
# Joe Hughes <joe@retrovirus.com
|
||||
# Pamela Greene <pamg.bugs@gmail.com>
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -886,8 +887,8 @@ Engine.prototype = {
|
||||
// A URL string pointing to the engine's search form.
|
||||
_searchForm: null,
|
||||
// The URI object from which the engine was retrieved.
|
||||
// This is null for local plugins, and is only used for error messages and
|
||||
// logging.
|
||||
// This is null for local plugins, and is used for error messages, logging,
|
||||
// and determining whether to start using a newly added engine right away.
|
||||
_uri: null,
|
||||
|
||||
/**
|
||||
@@ -1752,6 +1753,12 @@ Engine.prototype = {
|
||||
return this._type;
|
||||
},
|
||||
|
||||
// This getter is used in SearchService.observer. It is not intended to be
|
||||
// used (or needed) by callers outside this file.
|
||||
get uri() {
|
||||
return this._uri;
|
||||
},
|
||||
|
||||
get searchForm() {
|
||||
if (!this._searchForm) {
|
||||
// No searchForm specified in the engine definition file, use the prePath
|
||||
@@ -1864,6 +1871,14 @@ SearchService.prototype = {
|
||||
_engines: { },
|
||||
_sortedEngines: [],
|
||||
|
||||
// If this is set to the URI of the description of a search engine being added
|
||||
// to the list (typically by calling addEngine()), that engine will be
|
||||
// selected as the current engine when it finishes loading. If another
|
||||
// engine is added with "start using this one now" before the first selected
|
||||
// engine finishes loading, the second choice will override the first one.
|
||||
// If the selected engine fails to load, this marker will be cleared.
|
||||
_selectNewEngineURI: null,
|
||||
|
||||
_init: function() {
|
||||
engineMetadataService.init();
|
||||
this._addObservers();
|
||||
@@ -2220,11 +2235,17 @@ SearchService.prototype = {
|
||||
this._addEngineToStore(engine);
|
||||
},
|
||||
|
||||
addEngine: function SRCH_SVC_addEngine(aEngineURL, aType, aIconURL) {
|
||||
// If aSelect is true, the newly added engine will be selected as the current
|
||||
// engine when it finishes loading.
|
||||
addEngine: function SRCH_SVC_addEngine(aEngineURL, aType, aIconURL, aSelect) {
|
||||
LOG("addEngine: Adding \"" + aEngineURL + "\".");
|
||||
try {
|
||||
var engine = new Engine(makeURI(aEngineURL), aType, false);
|
||||
var uri = makeURI(aEngineURL);
|
||||
var engine = new Engine(uri, aType, false);
|
||||
engine._initFromURI();
|
||||
|
||||
if (aSelect)
|
||||
this._selectNewEngineURI = uri;
|
||||
} catch (ex) {
|
||||
LOG("addEngine: Error adding engine:\n" + ex);
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
@@ -2323,6 +2344,12 @@ SearchService.prototype = {
|
||||
LOG("nsISearchEngine::observe: Done installation of " + engine.name
|
||||
+ ".");
|
||||
this._addEngineToStore(engine.wrappedJSObject);
|
||||
// Optionally start using this engine now.
|
||||
if (this._selectNewEngineURI &&
|
||||
this._selectNewEngineURI == engine.wrappedJSObject.uri) {
|
||||
this.currentEngine = aEngine;
|
||||
this._selectNewEngineURI = null;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case XPCOM_SHUTDOWN_TOPIC:
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
* David Hyatt <hyatt@mozilla.org>
|
||||
* Christopher A. Aillon <christopher@aillon.com>
|
||||
* Myk Melez <myk@mozilla.org>
|
||||
* Pamela Greene <pamg.bugs@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@@ -70,6 +71,11 @@ function nsSidebar()
|
||||
const nsIPromptService = Components.interfaces.nsIPromptService;
|
||||
this.promptService =
|
||||
Components.classes[PROMPTSERVICE_CONTRACTID].getService(nsIPromptService);
|
||||
|
||||
const SEARCHSERVICE_CONTRACTID = "@mozilla.org/browser/search-service;1";
|
||||
const nsIBrowserSearchService = Components.interfaces.nsIBrowserSearchService;
|
||||
this.searchService =
|
||||
Components.classes[SEARCHSERVICE_CONTRACTID].getService(nsIBrowserSearchService);
|
||||
}
|
||||
|
||||
nsSidebar.prototype.nc = "http://home.netscape.com/NC-rdf#";
|
||||
@@ -126,16 +132,55 @@ function (aTitle, aContentURL, aCustomizeURL, aPersist)
|
||||
features, dialogArgs);
|
||||
}
|
||||
|
||||
/* decorate prototype to provide ``class'' methods and property accessors */
|
||||
nsSidebar.prototype.confirmSearchEngine =
|
||||
function (engineURL, suggestedTitle)
|
||||
{
|
||||
var stringBundle = srGetStrBundle("chrome://browser/locale/sidebar/sidebar.properties");
|
||||
var titleMessage = stringBundle.GetStringFromName("addEngineConfirmTitle");
|
||||
|
||||
// With tentative title: Add "Somebody's Search" to the list...
|
||||
// With no title: Add a new search engine to the list...
|
||||
var engineName;
|
||||
if (suggestedTitle)
|
||||
engineName = stringBundle.formatStringFromName("addEngineQuotedEngineName",
|
||||
[suggestedTitle], 1);
|
||||
else
|
||||
engineName = stringBundle.GetStringFromName("addEngineDefaultEngineName");
|
||||
|
||||
// Display only the hostname portion of the URL.
|
||||
try {
|
||||
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var uri = ios.newURI(engineURL, null, null);
|
||||
engineURL = uri.host;
|
||||
}
|
||||
catch (e) {
|
||||
// If newURI fails, fall back to the full URL.
|
||||
}
|
||||
|
||||
var dialogMessage = stringBundle.formatStringFromName("addEngineConfirmText",
|
||||
[suggestedTitle, engineURL], 2);
|
||||
|
||||
return this.promptService.confirm(null, titleMessage, dialogMessage);
|
||||
[engineName, engineURL], 2);
|
||||
var checkboxMessage = stringBundle.GetStringFromName("addEngineUseNowText");
|
||||
var addButtonLabel = stringBundle.GetStringFromName("addEngineAddButtonLabel");
|
||||
|
||||
const ps = this.promptService;
|
||||
var buttonFlags = (ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_0) +
|
||||
(ps.BUTTON_TITLE_CANCEL * ps.BUTTON_POS_1) +
|
||||
ps.BUTTON_POS_0_DEFAULT;
|
||||
|
||||
var checked = {value: false};
|
||||
// confirmEx returns the index of the button that was pressed. Since "Add" is
|
||||
// button 0, we want to return the negation of that value.
|
||||
var confirm = !this.promptService.confirmEx(null,
|
||||
titleMessage,
|
||||
dialogMessage,
|
||||
buttonFlags,
|
||||
addButtonLabel,
|
||||
"", "", // button 1 & 2 names not used
|
||||
checkboxMessage,
|
||||
checked);
|
||||
|
||||
return {confirmed: confirm, useNow: checked.value};
|
||||
}
|
||||
|
||||
// The expected suffix for the engine URL should be bare, i.e. without the
|
||||
@@ -176,15 +221,14 @@ function (engineURL, iconURL, suggestedTitle, suggestedCategory)
|
||||
|
||||
if (!this.validateSearchEngine(engineURL, "src", iconURL))
|
||||
return;
|
||||
|
||||
if (!this.confirmSearchEngine(engineURL, suggestedTitle))
|
||||
|
||||
var confirmation = this.confirmSearchEngine(engineURL, suggestedTitle);
|
||||
if (!confirmation.confirmed)
|
||||
return;
|
||||
|
||||
var searchService = Components.classes["@mozilla.org/browser/search-service;1"]
|
||||
.getService(Components.interfaces.nsIBrowserSearchService);
|
||||
|
||||
const typeText = Components.interfaces.nsISearchEngine.DATA_TEXT;
|
||||
if (searchService)
|
||||
searchService.addEngine(engineURL, typeText, iconURL);
|
||||
this.searchService.addEngine(engineURL, typeText, iconURL,
|
||||
confirmation.useNow);
|
||||
}
|
||||
|
||||
// This function exists largely to implement window.external.AddSearchProvider(),
|
||||
@@ -207,14 +251,14 @@ function (aDescriptionURL)
|
||||
|
||||
if (!this.validateSearchEngine(aDescriptionURL, "xml", iconURL))
|
||||
return;
|
||||
|
||||
if (!this.confirmSearchEngine(aDescriptionURL, ""))
|
||||
|
||||
var confirmation = this.confirmSearchEngine(aDescriptionURL, "");
|
||||
if (!confirmation.confirmed)
|
||||
return;
|
||||
|
||||
var searchService = Components.classes["@mozilla.org/browser/search-service;1"]
|
||||
.getService(Components.interfaces.nsIBrowserSearchService);
|
||||
|
||||
const typeXML = Components.interfaces.nsISearchEngine.DATA_XML;
|
||||
searchService.addEngine(aDescriptionURL, typeXML, iconURL);
|
||||
this.searchService.addEngine(aDescriptionURL, typeXML, iconURL,
|
||||
confirmation.useNow);
|
||||
}
|
||||
|
||||
nsSidebar.prototype.addMicrosummaryGenerator =
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
addEngineConfirmTitle=Add Search Engine
|
||||
addEngineConfirmText=Add the following search engine to the Search Bar?\n\nName: %S\nSource: %S
|
||||
addEngineConfirmText= Add %S to the list of engines available in the search bar?\n\nFrom: %S
|
||||
addEngineQuotedEngineName="%S"
|
||||
addEngineDefaultEngineName=a new search engine
|
||||
addEngineUseNowText=Start &using it right away
|
||||
addEngineAddButtonLabel=Add
|
||||
|
||||
addMicsumGenConfirmTitle=Add Microsummary Generator
|
||||
addMicsumGenConfirmText=Add the following microsummary generator?\n\nSource: %S
|
||||
|
||||
Reference in New Issue
Block a user