Bug 1222107 - Display error message when installing a duplicate search engine; r=Gijs
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -1431,17 +1431,32 @@
if (target.classList.contains("addengine-item")) {
// On success, hide and reshow the panel to show the new engine.
let installCallback = {
onSuccess: function(engine) {
event.target.hidePopup();
BrowserSearch.searchBar.openSuggestionsPanel();
},
onError: function(errorCode) {
- Components.utils.reportError("Error adding search engine: " + errorCode);
+ if (errorCode != Ci.nsISearchInstallCallback.ERROR_DUPLICATE_ENGINE) {
+ // Download error is shown by the search service
+ return;
+ }
+ const kSearchBundleURI = "chrome://global/locale/search/search.properties";
+ let searchBundle = Services.strings.createBundle(kSearchBundleURI);
+ let brandBundle = document.getElementById("bundle_brand");
+ let brandName = brandBundle.getString("brandShortName");
+ let title = searchBundle.GetStringFromName("error_invalid_engine_title");
+ let text = searchBundle.formatStringFromName("error_duplicate_engine_msg",
+ [brandName, target.getAttribute("uri")], 2);
+ Services.prompt.QueryInterface(Ci.nsIPromptFactory);
+ let prompt = Services.prompt.getPrompt(gBrowser.contentWindow, Ci.nsIPrompt);
+ prompt.QueryInterface(Ci.nsIWritablePropertyBag2);
+ prompt.setPropertyAsBool("allowTabModal", true);
+ prompt.alert(title, text);
}
}
Services.search.addEngine(target.getAttribute("uri"), null,
target.getAttribute("image"), false,
installCallback);
}
let anonid = target.getAttribute("anonid");
if (anonid == "search-one-offs-context-open-in-new-tab") {