Bug 1222107 - Display error message when installing a duplicate search engine; r=Gijs
authorMichael Kaply <mozilla@kaply.com>
Wed, 06 Apr 2016 16:19:11 -0500
changeset 348996 603e3444222259d97127198c5e3371fc087f7888
parent 348995 d7976fa32978a786a43ba4fa720f061bb096abcf
child 348997 81df156cb345cc8a11b46c4f11783c03047c4694
push id14989
push userdtownsend@mozilla.com
push dateFri, 08 Apr 2016 20:09:09 +0000
reviewersGijs
bugs1222107
milestone48.0a1
Bug 1222107 - Display error message when installing a duplicate search engine; r=Gijs
browser/components/search/content/search.xml
--- 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") {