Bug 910189: Part 2 - Enable removing of default engines. r=margaret
☠☠ backed out by e04fb3e318fc ☠ ☠
authorChenxia Liu <liuche@mozilla.com>
Wed, 18 Dec 2013 15:21:14 -0800
changeset 161199 30258cd308b53567e9aa6b3c1050bfd06d61716b
parent 161198 c572890f16a29e29443e3e5605ccd7ec2d8f7e2a
child 161200 72a80fc289f2fd128132fdd799c3c36f85eeea1a
push id25871
push usercbook@mozilla.com
push dateThu, 19 Dec 2013 09:34:02 +0000
treeherdermozilla-central@5c7fa2bfea8b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs910189
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 910189: Part 2 - Enable removing of default engines. r=margaret
mobile/android/base/preferences/SearchEnginePreference.java
mobile/android/base/preferences/SearchPreferenceCategory.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/preferences/SearchEnginePreference.java
+++ b/mobile/android/base/preferences/SearchEnginePreference.java
@@ -35,18 +35,16 @@ public class SearchEnginePreference exte
     public static final int INDEX_SET_DEFAULT_BUTTON = 0;
     public static final int INDEX_REMOVE_BUTTON = 1;
 
     // Cache label to avoid repeated use of the resource system.
     public final String LABEL_IS_DEFAULT;
 
     // Specifies if this engine is configured as the default search engine.
     private boolean mIsDefaultEngine;
-    // Specifies if this engine is one of the ones bundled with the app, which cannot be deleted.
-    private boolean mIsImmutableEngine;
 
     // Dialog element labels.
     private String[] mDialogItems;
 
     // The popup displayed when this element is tapped.
     private AlertDialog mDialog;
 
     private final SearchPreferenceCategory mParentCategory;
@@ -116,22 +114,17 @@ public class SearchEnginePreference exte
     /**
      * Configure this Preference object from the Gecko search engine JSON object.
      * @param geckoEngineJSON The Gecko-formatted JSON object representing the search engine.
      * @throws JSONException If the JSONObject is invalid.
      */
     public void setSearchEngineFromJSON(JSONObject geckoEngineJSON) throws JSONException {
         final String engineName = geckoEngineJSON.getString("name");
         final SpannableString titleSpannable = new SpannableString(engineName);
-        mIsImmutableEngine = geckoEngineJSON.getBoolean("immutable");
 
-        if (mIsImmutableEngine) {
-            // Delete the "Remove" option from the menu.
-            mDialogItems = new String[] { getContext().getResources().getString(R.string.pref_search_set_default) };
-        }
         setTitle(titleSpannable);
 
         final String iconURI = geckoEngineJSON.getString("iconURI");
         // Keep a reference to the bitmap - we'll need it later in onBindView.
         try {
             mIconBitmap = BitmapUtils.getBitmapFromDataURI(iconURI);
         } catch (IllegalArgumentException e) {
             Log.e(LOGTAG, "IllegalArgumentException creating Bitmap. Most likely a zero-length bitmap.", e);
@@ -171,21 +164,16 @@ public class SearchEnginePreference exte
                 @Override
                 public void run() {
                     Toast.makeText(getContext(), R.string.pref_search_last_toast, Toast.LENGTH_SHORT).show();
                 }
             });
             return;
         }
 
-        // If we are both default and immutable, we have no enabled items to show on the menu - abort.
-        if (mIsDefaultEngine && mIsImmutableEngine) {
-            return;
-        }
-
         final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
         builder.setTitle(getTitle().toString());
         builder.setItems(mDialogItems, new DialogInterface.OnClickListener() {
             // Forward the various events that we care about to the container class for handling.
             @Override
             public void onClick(DialogInterface dialog, int indexClicked) {
                 hideDialog();
                 switch (indexClicked) {
--- a/mobile/android/base/preferences/SearchPreferenceCategory.java
+++ b/mobile/android/base/preferences/SearchPreferenceCategory.java
@@ -40,17 +40,17 @@ public class SearchPreferenceCategory ex
     protected void onAttachedToActivity() {
         super.onAttachedToActivity();
 
         // Ensures default engine remains at top of list.
         setOrderingAsAdded(true);
 
         // Request list of search engines from Gecko.
         GeckoAppShell.registerEventListener("SearchEngines:Data", this);
-        GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:Get", null));
+        GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SearchEngines:GetVisible", null));
     }
 
     @Override
     public void handleMessage(String event, final JSONObject data) {
         if (event.equals("SearchEngines:Data")) {
             // We are no longer interested in this event from Gecko, as we do not request it again with
             // this instance.
             GeckoAppShell.unregisterEventListener("SearchEngines:Data", this);
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -6603,17 +6603,16 @@ OverscrollController.prototype = {
 
 var SearchEngines = {
   _contextMenuId: null,
   PREF_SUGGEST_ENABLED: "browser.search.suggest.enabled",
   PREF_SUGGEST_PROMPTED: "browser.search.suggest.prompted",
 
   init: function init() {
     Services.obs.addObserver(this, "SearchEngines:Add", false);
-    Services.obs.addObserver(this, "SearchEngines:Get", false);
     Services.obs.addObserver(this, "SearchEngines:GetVisible", false);
     Services.obs.addObserver(this, "SearchEngines:SetDefault", false);
     Services.obs.addObserver(this, "SearchEngines:Remove", false);
 
     let filter = {
       matches: function (aElement) {
         // Copied from body of isTargetAKeywordField function in nsContextMenu.js
         if(!(aElement instanceof HTMLInputElement))
@@ -6646,47 +6645,37 @@ var SearchEngines = {
       action: function(aElement) {
         SearchEngines.addEngine(aElement);
       }
     }
   },
 
   uninit: function uninit() {
     Services.obs.removeObserver(this, "SearchEngines:Add");
-    Services.obs.removeObserver(this, "SearchEngines:Get");
     Services.obs.removeObserver(this, "SearchEngines:GetVisible");
     Services.obs.removeObserver(this, "SearchEngines:SetDefault");
     Services.obs.removeObserver(this, "SearchEngines:Remove");
     if (this._contextMenuId != null)
       NativeWindow.contextmenus.remove(this._contextMenuId);
   },
 
   // Fetch list of search engines. all ? All engines : Visible engines only.
-  _handleSearchEnginesGet: function _handleSearchEnginesGet(rv, all) {
+  _handleSearchEnginesGetVisible: function _handleSearchEnginesGetVisible(rv) {
     if (!Components.isSuccessCode(rv)) {
       Cu.reportError("Could not initialize search service, bailing out.");
       return;
     }
-    let engineData;
-    if (all) {
-      engineData = Services.search.getEngines({});
-    } else {
-      engineData = Services.search.getVisibleEngines({});
-    }
-
-    // These engines are the bundled ones - they may not be uninstalled.
-    let immutableEngines = Services.search.getDefaultEngines();
-
+
+    let engineData = Services.search.getVisibleEngines({});
     let searchEngines = engineData.map(function (engine) {
       return {
         name: engine.name,
         identifier: engine.identifier,
         iconURI: (engine.iconURI ? engine.iconURI.spec : null),
-        hidden: engine.hidden,
-        immutable: immutableEngines.indexOf(engine) != -1
+        hidden: engine.hidden
       };
     });
 
     let suggestTemplate = null;
     let suggestEngine = null;
 
     // Check to see if the default engine supports search suggestions. We only need to check
     // the default engine because we only show suggestions for the default engine in the UI.
@@ -6713,42 +6702,31 @@ var SearchEngines = {
     let searchURI = Services.search.defaultEngine.getSubmission("dummy").uri;
     let callbacks = window.QueryInterface(Ci.nsIInterfaceRequestor)
                           .getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsILoadContext);
     try {
       connector.speculativeConnect(searchURI, callbacks);
     } catch (e) {}
   },
 
-  _handleSearchEnginesGetAll: function _handleSearchEnginesGetAll(rv) {
-    this._handleSearchEnginesGet(rv, true);
-  },
-  _handleSearchEnginesGetVisible: function _handleSearchEnginesGetVisible(rv) {
-    this._handleSearchEnginesGet(rv, false)
-  },
-
   // Helper method to extract the engine name from a JSON. Simplifies the observe function.
   _extractEngineFromJSON: function _extractEngineFromJSON(aData) {
     let data = JSON.parse(aData);
     return Services.search.getEngineByName(data.engine);
   },
 
   observe: function observe(aSubject, aTopic, aData) {
     let engine;
     switch(aTopic) {
       case "SearchEngines:Add":
         this.displaySearchEnginesList(aData);
         break;
       case "SearchEngines:GetVisible":
         Services.search.init(this._handleSearchEnginesGetVisible.bind(this));
         break;
-      case "SearchEngines:Get":
-        // Return a list of all engines, including "Hidden" ones.
-        Services.search.init(this._handleSearchEnginesGetAll.bind(this));
-        break;
       case "SearchEngines:SetDefault":
         engine = this._extractEngineFromJSON(aData);
         // Move the new default search engine to the top of the search engine list.
         Services.search.moveEngine(engine, 0);
         Services.search.defaultEngine = engine;
         break;
       case "SearchEngines:Remove":
         // Make sure the engine isn't hidden before removing it, to make sure it's