Bug 769145 - Part 3: Add mSuggestionsEnabled boolean. r=mfinkle
authorBrian Nicholson <bnicholson@mozilla.com>
Tue, 02 Oct 2012 10:51:48 -0700
changeset 108915 ecaff73e5a633b344e6960a7d6b21f672fb174de
parent 108914 cc505740ad56f5365f66461a276ded7dfa20002b
child 108916 580f710a84e8f99229aca9f4e11e1c8f2df47253
push id23601
push userryanvm@gmail.com
push dateWed, 03 Oct 2012 01:23:59 +0000
treeherdermozilla-central@635fcc11d2b1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs769145
milestone18.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 769145 - Part 3: Add mSuggestionsEnabled boolean. r=mfinkle
mobile/android/base/awesomebar/AllPagesTab.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/awesomebar/AllPagesTab.java
+++ b/mobile/android/base/awesomebar/AllPagesTab.java
@@ -49,16 +49,17 @@ public class AllPagesTab extends Awesome
     private static final String TAG = "allPages";
 
     private static final int SUGGESTION_TIMEOUT = 3000;
     private static final int SUGGESTION_MAX = 3;
 
     private String mSearchTerm;
     private ArrayList<SearchEngine> mSearchEngines;
     private SuggestClient mSuggestClient;
+    private boolean mSuggestionsEnabled;
     private AsyncTask<String, Void, ArrayList<String>> mSuggestTask;
     private AwesomeBarCursorAdapter mCursorAdapter = null;
     private boolean mTelemetrySent = false;
 
     private class SearchEntryViewHolder {
         public FlowLayout suggestionView;
         public ImageView iconView;
         public LinearLayout userEnteredView;
@@ -131,25 +132,25 @@ public class AllPagesTab extends Awesome
     }
 
     private void filterSuggestions(String searchTerm) {
         // cancel previous query
         if (mSuggestTask != null) {
             mSuggestTask.cancel(true);
         }
 
-        if (mSuggestClient != null) {
+        if (mSuggestClient != null && mSuggestionsEnabled) {
             mSuggestTask = new AsyncTask<String, Void, ArrayList<String>>() {
-                 protected ArrayList<String> doInBackground(String... query) {
-                     return mSuggestClient.query(query[0]);
-                 }
+                protected ArrayList<String> doInBackground(String... query) {
+                    return mSuggestClient.query(query[0]);
+                }
 
-                 protected void onPostExecute(ArrayList<String> suggestions) {
-                     setSuggestions(suggestions);
-                 }
+                protected void onPostExecute(ArrayList<String> suggestions) {
+                    setSuggestions(suggestions);
+                }
             };
             mSuggestTask.execute(searchTerm);
         }
     }
 
     protected AwesomeBarCursorAdapter getCursorAdapter() {
         if (mCursorAdapter == null) {
             // Load the list using a custom adapter so we can create the bitmaps
@@ -245,17 +246,17 @@ public class AllPagesTab extends Awesome
         }
 
         public void filter(String searchTerm) {
             mSearchTerm = searchTerm;
             getFilter().filter(searchTerm);
         }
 
         private int getSuggestEngineCount() {
-            return (mSearchTerm.length() == 0 || mSuggestClient == null) ? 0 : 1;
+            return (mSearchTerm.length() == 0 || mSuggestClient == null || !mSuggestionsEnabled) ? 0 : 1;
         }
 
         // Add the search engines to the number of reported results.
         @Override
         public int getCount() {
             final int resultCount = super.getCount();
 
             // don't show search engines or suggestions if search field is empty
@@ -464,16 +465,17 @@ public class AllPagesTab extends Awesome
     /**
      * Sets search engines to be shown for user-entered queries.
      */
     public void setSearchEngines(JSONObject data) {
         try {
             String suggestEngine = data.isNull("suggestEngine") ? null : data.getString("suggestEngine");
             String suggestTemplate = data.isNull("suggestTemplate") ? null : data.getString("suggestTemplate");
             JSONArray engines = data.getJSONArray("searchEngines");
+            mSuggestionsEnabled = data.getBoolean("suggestEnabled");
 
             mSearchEngines = new ArrayList<SearchEngine>();
             for (int i = 0; i < engines.length(); i++) {
                 JSONObject engineJSON = engines.getJSONObject(i);
                 String name = engineJSON.getString("name");
                 String iconURI = engineJSON.getString("iconURI");
                 Drawable icon = getDrawableFromDataURI(iconURI);
                 if (name.equals(suggestEngine) && suggestTemplate != null) {
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -6130,30 +6130,29 @@ var SearchEngines = {
       return {
         name: engine.name,
         iconURI: (engine.iconURI ? engine.iconURI.spec : null)
       };
     });
 
     let suggestTemplate = null;
     let suggestEngine = null;
-    if (Services.prefs.getBoolPref("browser.search.suggest.enabled")) {
-      let engine = this.getSuggestionEngine();
-      if (engine != null) {
-        suggestEngine = engine.name;
-        suggestTemplate = engine.getSubmission("__searchTerms__", "application/x-suggestions+json").uri.spec;
-      }
+    let engine = this.getSuggestionEngine();
+    if (engine != null) {
+      suggestEngine = engine.name;
+      suggestTemplate = engine.getSubmission("__searchTerms__", "application/x-suggestions+json").uri.spec;
     }
 
     sendMessageToJava({
       gecko: {
         type: "SearchEngines:Data",
         searchEngines: searchEngines,
         suggestEngine: suggestEngine,
-        suggestTemplate: suggestTemplate
+        suggestTemplate: suggestTemplate,
+        suggestEnabled: Services.prefs.getBoolPref("browser.search.suggest.enabled")
       }
     });
   },
 
   observe: function observe(aSubject, aTopic, aData) {
     if (aTopic == "SearchEngines:Get") {
       Services.search.init(this._handleSearchEnginesGet.bind(this));
     }