Bug 1073775 - Pass default engine from JS to Java, instead of making assumptions based on engine list order. r=liuche a=sylvestre
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 23 Feb 2015 13:13:24 -0800
changeset 250073 21ec3b2d3da5
parent 250068 192f6746dc45
child 250074 82ef773ccb71
push id4495
push usermfinkle@mozilla.com
push date2015-02-25 00:10 +0000
treeherdermozilla-beta@21ec3b2d3da5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche, sylvestre
bugs1073775
milestone37.0
Bug 1073775 - Pass default engine from JS to Java, instead of making assumptions based on engine list order. r=liuche a=sylvestre
mobile/android/base/home/BrowserSearch.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/home/BrowserSearch.java
+++ b/mobile/android/base/home/BrowserSearch.java
@@ -556,16 +556,18 @@ public class BrowserSearch extends HomeF
 
             ArrayList<SearchEngine> searchEngines = new ArrayList<SearchEngine>();
             for (int i = 0; i < engines.length(); i++) {
                 final JSONObject engineJSON = engines.getJSONObject(i);
                 final SearchEngine engine = new SearchEngine(engineJSON);
 
                 if (engine.name.equals(suggestEngine) && suggestTemplate != null) {
                     // Suggest engine should be at the front of the list.
+                    // We're baking in an assumption here that the suggest engine
+                    // is also the default engine.
                     searchEngines.add(0, engine);
 
                     // The only time Tabs.getInstance().getSelectedTab() should
                     // be null is when we're restoring after a crash. We should
                     // never restore private tabs when that happens, so it
                     // should be safe to assume that null means non-private.
                     Tab tab = Tabs.getInstance().getSelectedTab();
                     final boolean isPrivate = (tab != null && tab.isPrivate());
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -7023,16 +7023,24 @@ var SearchEngines = {
   // Fetch list of search engines. all ? All engines : Visible engines only.
   _handleSearchEnginesGetVisible: function _handleSearchEnginesGetVisible(rv, all) {
     if (!Components.isSuccessCode(rv)) {
       Cu.reportError("Could not initialize search service, bailing out.");
       return;
     }
 
     let engineData = Services.search.getVisibleEngines({});
+
+    // Our Java UI assumes that the default engine is the first item in the array,
+    // so we need to make sure that's the case.
+    if (engineData[0] !== Services.search.defaultEngine) {
+      engineData = engineData.filter(engine => engine !== Services.search.defaultEngine);
+      engineData.unshift(Services.search.defaultEngine);
+    }
+
     let searchEngines = engineData.map(function (engine) {
       return {
         name: engine.name,
         identifier: engine.identifier,
         iconURI: (engine.iconURI ? engine.iconURI.spec : null),
         hidden: engine.hidden
       };
     });