Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.preferences; | 5 package org.chromium.chrome.browser.preferences; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.content.SharedPreferences; | 9 import android.content.SharedPreferences; |
| 10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
| 11 import android.os.Build; | 11 import android.os.Build; |
| 12 import android.os.Bundle; | 12 import android.os.Bundle; |
| 13 import android.text.SpannableString; | 13 import android.text.SpannableString; |
| 14 import android.text.style.ForegroundColorSpan; | 14 import android.text.style.ForegroundColorSpan; |
| 15 import android.view.LayoutInflater; | 15 import android.view.LayoutInflater; |
| 16 import android.view.View; | 16 import android.view.View; |
| 17 import android.view.View.AccessibilityDelegate; | 17 import android.view.View.AccessibilityDelegate; |
| 18 import android.view.View.OnClickListener; | 18 import android.view.View.OnClickListener; |
| 19 import android.view.ViewGroup; | 19 import android.view.ViewGroup; |
| 20 import android.view.accessibility.AccessibilityEvent; | 20 import android.view.accessibility.AccessibilityEvent; |
| 21 import android.view.accessibility.AccessibilityNodeInfo; | 21 import android.view.accessibility.AccessibilityNodeInfo; |
| 22 import android.widget.BaseAdapter; | 22 import android.widget.BaseAdapter; |
| 23 import android.widget.RadioButton; | 23 import android.widget.RadioButton; |
| 24 import android.widget.TextView; | 24 import android.widget.TextView; |
| 25 | 25 |
| 26 import org.chromium.base.ApiCompatibilityUtils; | 26 import org.chromium.base.ApiCompatibilityUtils; |
| 27 import org.chromium.base.ContextUtils; | 27 import org.chromium.base.ContextUtils; |
| 28 import org.chromium.base.metrics.RecordUserAction; | |
| 28 import org.chromium.chrome.R; | 29 import org.chromium.chrome.R; |
| 30 import org.chromium.chrome.browser.locale.LocaleManager; | |
| 29 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; | 31 import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader; |
| 30 import org.chromium.chrome.browser.preferences.website.ContentSetting; | 32 import org.chromium.chrome.browser.preferences.website.ContentSetting; |
| 31 import org.chromium.chrome.browser.preferences.website.GeolocationInfo; | 33 import org.chromium.chrome.browser.preferences.website.GeolocationInfo; |
| 32 import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; | 34 import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences; |
| 33 import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge; | 35 import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge; |
| 34 import org.chromium.chrome.browser.search_engines.TemplateUrlService; | 36 import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
| 35 import org.chromium.chrome.browser.search_engines.TemplateUrlService.LoadListene r; | 37 import org.chromium.chrome.browser.search_engines.TemplateUrlService.LoadListene r; |
| 36 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl ; | 38 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl ; |
| 37 import org.chromium.components.location.LocationUtils; | 39 import org.chromium.components.location.LocationUtils; |
| 38 import org.chromium.ui.text.SpanApplier; | 40 import org.chromium.ui.text.SpanApplier; |
| 39 import org.chromium.ui.text.SpanApplier.SpanInfo; | 41 import org.chromium.ui.text.SpanApplier.SpanInfo; |
| 40 | 42 |
| 43 import java.util.ArrayList; | |
| 41 import java.util.List; | 44 import java.util.List; |
| 42 | 45 |
| 43 /** | 46 /** |
| 44 * A custom adapter for listing search engines. | 47 * A custom adapter for listing search engines. |
| 45 */ | 48 */ |
| 46 public class SearchEngineAdapter extends BaseAdapter implements LoadListener, On ClickListener { | 49 public class SearchEngineAdapter extends BaseAdapter implements LoadListener, On ClickListener { |
| 47 /** | 50 /** |
| 48 * A callback for reporting progress to the owner. | 51 * A callback for reporting progress to the owner. |
| 49 */ | 52 */ |
| 50 public interface SelectSearchEngineCallback { | 53 public interface SelectSearchEngineCallback { |
| 51 /** | 54 /** |
| 52 * Called when the search engine data has loaded and we've determined th e currently active | 55 * Called when the search engine data has loaded and we've determined th e currently active |
| 53 * one. | 56 * one. |
| 54 * @param name Provides the name of it (with a simplified URL in parenth esis). | 57 * @param name Provides the name of it (with a simplified URL in parenth esis). |
|
Ian Wen
2016/10/19 00:03:31
You should update the javadoc for this function.
ltian
2016/10/19 18:56:31
Interface will be removed and this class will dire
| |
| 55 */ | 58 */ |
| 56 void currentSearchEngineDetermined(int selectedIndex); | 59 void currentSearchEngineDetermined(String keyword); |
| 57 } | 60 } |
| 58 | 61 |
| 59 // The current context. | 62 // The current context. |
| 60 private Context mContext; | 63 private Context mContext; |
| 61 | 64 |
| 62 // The layout inflater to use for the custom views. | 65 // The layout inflater to use for the custom views. |
| 63 private LayoutInflater mLayoutInflater; | 66 private LayoutInflater mLayoutInflater; |
| 64 | 67 |
| 65 // The callback to use for notifying caller of progress. | 68 // The callback to use for notifying caller of progress. |
| 66 private SelectSearchEngineCallback mCallback; | 69 private SelectSearchEngineCallback mCallback; |
| 67 | 70 |
| 68 // The list of available search engines. | 71 // The list of prepopluated and default search engines. |
| 69 private List<TemplateUrl> mSearchEngines; | 72 private List<TemplateUrl> mPrepopulatedSearchEngines = new ArrayList<Templat eUrl>(); |
| 70 // The position (index into mSearchEngines) of the currently selected search engine. Can be -1 | 73 // The list of recently visited search engines. |
| 74 private List<TemplateUrl> mRecentVisitedSearchEngines = new ArrayList<Templa teUrl>(); | |
|
Ian Wen
2016/10/19 00:03:30
How about renaming it to mRecentSearchEngines?
ltian
2016/10/19 18:56:31
Done.
| |
| 75 // The position (index into mPrepopulatedSearchEngines) of the currently sel ected search engine. | |
| 76 // Can be -1 | |
| 71 // if current search engine is managed and set to something other than the p re-populated values. | 77 // if current search engine is managed and set to something other than the p re-populated values. |
|
Ian Wen
2016/10/19 00:03:31
Please reformat the comments.
ltian
2016/10/19 18:56:31
Done.
| |
| 72 private int mSelectedSearchEnginePosition = -1; | 78 private int mSelectedSearchEnginePosition = -1; |
| 73 | 79 |
| 74 // The position of the default search engine before user's action. | 80 // The position of the default search engine before user's action. |
| 75 private int mInitialEnginePosition = -1; | 81 private int mInitialEnginePosition = -1; |
| 76 | 82 |
| 83 private static final int VIEW_TYPE_ITEM = 0; | |
| 84 private static final int VIEW_TYPE_DIVIDER = 1; | |
|
Ian Wen
2016/10/19 00:03:31
Like what I said in last patchset, public members
ltian
2016/10/19 18:56:31
Done.
| |
| 85 | |
| 77 /** | 86 /** |
| 78 * Construct a SearchEngineAdapter. | 87 * Construct a SearchEngineAdapter. |
| 79 * @param context The current context. | 88 * @param context The current context. |
| 80 * @param callback The callback to use to communicate back. | 89 * @param callback The callback to use to communicate back. |
| 81 */ | 90 */ |
| 82 public SearchEngineAdapter(Context context, SelectSearchEngineCallback callb ack) { | 91 public SearchEngineAdapter(Context context, SelectSearchEngineCallback callb ack) { |
| 83 mContext = context; | 92 mContext = context; |
| 84 mLayoutInflater = (LayoutInflater) mContext.getSystemService( | 93 mLayoutInflater = (LayoutInflater) mContext.getSystemService( |
| 85 Context.LAYOUT_INFLATER_SERVICE); | 94 Context.LAYOUT_INFLATER_SERVICE); |
| 86 mCallback = callback; | 95 mCallback = callback; |
| 87 | 96 |
| 88 initEntries(); | 97 initEntries(); |
| 89 } | 98 } |
| 90 | 99 |
| 91 /** | |
| 92 * @return The index of the selected engine before user's action. | |
| 93 */ | |
| 94 public int getInitialSearchEnginePosition() { | |
| 95 return mInitialEnginePosition; | |
| 96 } | |
| 97 | |
| 98 // Used for testing. | 100 // Used for testing. |
| 99 | 101 |
| 100 String getValueForTesting() { | 102 String getValueForTesting() { |
| 101 return Integer.toString(mSelectedSearchEnginePosition); | 103 return Integer.toString(mSelectedSearchEnginePosition); |
| 102 } | 104 } |
| 103 | 105 |
| 104 void setValueForTesting(String value) { | 106 String setValueForTesting(String value) { |
| 105 searchEngineSelected(Integer.parseInt(value)); | 107 return searchEngineSelected(Integer.parseInt(value)); |
| 108 } | |
| 109 | |
| 110 String getKeywordForTesting(int index) { | |
| 111 return toKeyword(index); | |
| 106 } | 112 } |
| 107 | 113 |
| 108 /** | 114 /** |
| 109 * Initialize the search engine list. | 115 * Initialize the search engine list. |
| 110 */ | 116 */ |
| 111 private void initEntries() { | 117 private void initEntries() { |
| 112 TemplateUrlService templateUrlService = TemplateUrlService.getInstance() ; | 118 TemplateUrlService templateUrlService = TemplateUrlService.getInstance() ; |
| 113 if (!templateUrlService.isLoaded()) { | 119 if (!templateUrlService.isLoaded()) { |
| 114 templateUrlService.registerLoadListener(this); | 120 templateUrlService.registerLoadListener(this); |
| 115 templateUrlService.load(); | 121 templateUrlService.load(); |
| 116 return; // Flow continues in onTemplateUrlServiceLoaded below. | 122 return; // Flow continues in onTemplateUrlServiceLoaded below. |
| 117 } | 123 } |
| 118 | 124 |
| 119 // Fetch all the search engine info and the currently active one. | 125 int defaultSearchEngineIndex = templateUrlService.getDefaultSearchEngine Index(); |
| 120 mSearchEngines = templateUrlService.getLocalizedSearchEngines(); | 126 // Fetch all the search engine info and the currently active one, based on their types, |
| 121 int searchEngineIndex = templateUrlService.getDefaultSearchEngineIndex() ; | 127 // add into different lists. |
|
Ian Wen
2016/10/19 00:03:31
I would simply remove the comments between 126 and
ltian
2016/10/19 18:56:31
Done.
| |
| 122 // Convert the TemplateUrl index into an index into mSearchEngines. | 128 for (TemplateUrl templateUrl : templateUrlService.getLocalizedSearchEngi nes()) { |
|
Ian Wen
2016/10/19 00:03:31
I would rename getLocalizedSearchEngines() to getS
ltian
2016/10/19 18:56:31
Done.
| |
| 129 if (templateUrl.getType() == TemplateUrlService.TYPE_PREPOPULATED | |
| 130 || templateUrl.getType() == TemplateUrlService.TYPE_DEFAULT) { | |
| 131 mPrepopulatedSearchEngines.add(templateUrl); | |
| 132 } else { | |
| 133 mRecentVisitedSearchEngines.add(templateUrl); | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 // Convert the TemplateUrl index into an index of mSearchEngines. | |
| 123 mSelectedSearchEnginePosition = -1; | 138 mSelectedSearchEnginePosition = -1; |
| 124 for (int i = 0; i < mSearchEngines.size(); ++i) { | 139 for (int i = 0; i < mPrepopulatedSearchEngines.size(); ++i) { |
| 125 if (mSearchEngines.get(i).getIndex() == searchEngineIndex) { | 140 if (mPrepopulatedSearchEngines.get(i).getIndex() == defaultSearchEng ineIndex) { |
| 126 mSelectedSearchEnginePosition = i; | 141 mSelectedSearchEnginePosition = i; |
| 127 } | 142 } |
| 128 } | 143 } |
| 144 | |
| 145 for (int i = 0; i < mRecentVisitedSearchEngines.size(); ++i) { | |
| 146 if (mRecentVisitedSearchEngines.get(i).getIndex() == defaultSearchEn gineIndex) { | |
| 147 mSelectedSearchEnginePosition = i + mPrepopulatedSearchEngines.s ize() + 1; | |
|
Ian Wen
2016/10/19 00:03:31
Please explain why you need to add one here.
"//
ltian
2016/10/19 18:56:31
Done.
| |
| 148 } | |
| 149 } | |
| 150 | |
| 129 mInitialEnginePosition = mSelectedSearchEnginePosition; | 151 mInitialEnginePosition = mSelectedSearchEnginePosition; |
| 130 | 152 |
| 131 // Report back what is selected. | 153 // Report back what is selected. |
| 132 mCallback.currentSearchEngineDetermined(toIndex(mSelectedSearchEnginePos ition)); | 154 mCallback.currentSearchEngineDetermined(toKeyword(mSelectedSearchEngineP osition)); |
| 133 } | 155 } |
| 134 | 156 |
| 135 private int toIndex(int position) { | 157 private String toKeyword(int position) { |
| 136 return mSearchEngines.get(position).getIndex(); | 158 if (position < mPrepopulatedSearchEngines.size()) { |
| 159 return mPrepopulatedSearchEngines.get(position).getKeyword(); | |
| 160 } else { | |
| 161 position -= mPrepopulatedSearchEngines.size() + 1; | |
| 162 return mRecentVisitedSearchEngines.get(position).getKeyword(); | |
| 163 } | |
| 137 } | 164 } |
| 138 | 165 |
| 139 // BaseAdapter: | 166 // BaseAdapter: |
| 140 | 167 |
| 141 @Override | 168 @Override |
| 142 public int getCount() { | 169 public int getCount() { |
| 143 return mSearchEngines == null ? 0 : mSearchEngines.size(); | 170 return mPrepopulatedSearchEngines == null |
| 171 ? 0 | |
| 172 : mPrepopulatedSearchEngines.size() + mRecentVisitedSearchEngine s.size() + 1; | |
| 144 } | 173 } |
| 145 | 174 |
| 146 @Override | 175 @Override |
| 147 public Object getItem(int pos) { | 176 public Object getItem(int pos) { |
| 148 TemplateUrl templateUrl = mSearchEngines.get(pos); | 177 if (pos < mPrepopulatedSearchEngines.size()) { |
| 149 return templateUrl.getShortName(); | 178 return mPrepopulatedSearchEngines.get(pos); |
| 179 } else if (pos > mPrepopulatedSearchEngines.size()) { | |
| 180 pos -= mPrepopulatedSearchEngines.size() + 1; | |
| 181 return mRecentVisitedSearchEngines.get(pos); | |
| 182 } | |
| 183 return null; | |
| 150 } | 184 } |
| 151 | 185 |
| 152 @Override | 186 @Override |
| 153 public long getItemId(int position) { | 187 public long getItemId(int position) { |
| 154 return position; | 188 return position; |
| 155 } | 189 } |
| 156 | 190 |
| 157 @Override | 191 @Override |
| 192 public int getItemViewType(int position) { | |
| 193 if (position == mPrepopulatedSearchEngines.size()) { | |
| 194 return VIEW_TYPE_DIVIDER; | |
| 195 } else { | |
| 196 return VIEW_TYPE_ITEM; | |
| 197 } | |
| 198 } | |
| 199 | |
| 200 @Override | |
| 158 public View getView(int position, View convertView, ViewGroup parent) { | 201 public View getView(int position, View convertView, ViewGroup parent) { |
| 159 View view = convertView; | 202 View view = convertView; |
| 160 if (convertView == null) { | 203 TemplateUrl templateUrl = (TemplateUrl) getItem(position); |
| 204 int itemViewType = getItemViewType(position); | |
| 205 if (itemViewType == VIEW_TYPE_DIVIDER) { | |
|
Ian Wen
2016/10/19 00:03:31
Oops this is a mistake.
The reason why you need t
ltian
2016/10/19 18:56:31
Done.
| |
| 206 view = mLayoutInflater.inflate(R.layout.search_engine_recent_title, null); | |
| 207 } else { | |
| 161 view = mLayoutInflater.inflate(R.layout.search_engine, null); | 208 view = mLayoutInflater.inflate(R.layout.search_engine, null); |
| 162 } | 209 } |
| 210 if (itemViewType == VIEW_TYPE_DIVIDER) { | |
| 211 view.setOnClickListener(null); | |
| 212 view.setEnabled(false); | |
| 213 return view; | |
| 214 } | |
| 163 | 215 |
| 164 view.setOnClickListener(this); | 216 view.setOnClickListener(this); |
| 165 view.setTag(position); | 217 view.setTag(position); |
| 166 | 218 |
| 167 // TODO(finnur): There's a tinting bug in the AppCompat lib (see http:// crbug.com/474695), | 219 // TODO(finnur): There's a tinting bug in the AppCompat lib (see http:// crbug.com/474695), |
| 168 // which causes the first radiobox to always appear selected, even if it is not. It is being | 220 // which causes the first radiobox to always appear selected, even if it is not. It is being |
| 169 // addressed, but in the meantime we should use the native RadioButton i nstead. | 221 // addressed, but in the meantime we should use the native RadioButton i nstead. |
| 170 RadioButton radioButton = (RadioButton) view.findViewById(R.id.radiobutt on); | 222 RadioButton radioButton = (RadioButton) view.findViewById(R.id.radiobutt on); |
| 171 // On Lollipop this removes the redundant animation ring on selection bu t on older versions | 223 // On Lollipop this removes the redundant animation ring on selection bu t on older versions |
| 172 // it would cause the radio button to disappear. | 224 // it would cause the radio button to disappear. |
| 173 // TODO(finnur): Remove the encompassing if statement once we go back to using the AppCompat | 225 // TODO(finnur): Remove the encompassing if statement once we go back to using the AppCompat |
| 174 // control. | 226 // control. |
| 175 final boolean selected = position == mSelectedSearchEnginePosition; | 227 final boolean selected = position == mSelectedSearchEnginePosition; |
| 176 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | 228 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| 177 radioButton.setBackgroundResource(0); | 229 radioButton.setBackgroundResource(0); |
| 178 } | 230 } |
| 179 radioButton.setChecked(selected); | 231 radioButton.setChecked(selected); |
| 180 | 232 |
| 181 TextView description = (TextView) view.findViewById(R.id.description); | 233 TextView description = (TextView) view.findViewById(R.id.description); |
| 182 TemplateUrl templateUrl = mSearchEngines.get(position); | |
| 183 Resources resources = mContext.getResources(); | 234 Resources resources = mContext.getResources(); |
| 184 description.setText(templateUrl.getShortName()); | 235 description.setText(templateUrl.getShortName()); |
| 185 | 236 |
| 237 TextView url = (TextView) view.findViewById(R.id.url); | |
| 238 url.setText(templateUrl.getUrl()); | |
| 239 if (templateUrl.getType() == TemplateUrlService.TYPE_PREPOPULATED | |
| 240 || templateUrl.getType() == TemplateUrlService.TYPE_DEFAULT | |
| 241 || templateUrl.getUrl().length() == 0) { | |
| 242 url.setVisibility(View.GONE); | |
| 243 } | |
| 244 | |
| 186 // To improve the explore-by-touch experience, the radio button is hidde n from accessibility | 245 // To improve the explore-by-touch experience, the radio button is hidde n from accessibility |
| 187 // and instead, "checked" or "not checked" is read along with the search engine's name, e.g. | 246 // and instead, "checked" or "not checked" is read along with the search engine's name, e.g. |
| 188 // "google.com checked" or "google.com not checked". | 247 // "google.com checked" or "google.com not checked". |
| 189 radioButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILIT Y_NO); | 248 radioButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILIT Y_NO); |
| 190 description.setAccessibilityDelegate(new AccessibilityDelegate() { | 249 description.setAccessibilityDelegate(new AccessibilityDelegate() { |
| 191 @Override | 250 @Override |
| 192 public void onInitializeAccessibilityEvent(View host, AccessibilityE vent event) { | 251 public void onInitializeAccessibilityEvent(View host, AccessibilityE vent event) { |
| 193 super.onInitializeAccessibilityEvent(host, event); | 252 super.onInitializeAccessibilityEvent(host, event); |
| 194 event.setChecked(selected); | 253 event.setChecked(selected); |
| 195 } | 254 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 | 299 |
| 241 @Override | 300 @Override |
| 242 public void onClick(View view) { | 301 public void onClick(View view) { |
| 243 if (view.getTag() == null) { | 302 if (view.getTag() == null) { |
| 244 onLocationLinkClicked(); | 303 onLocationLinkClicked(); |
| 245 } else { | 304 } else { |
| 246 searchEngineSelected((int) view.getTag()); | 305 searchEngineSelected((int) view.getTag()); |
| 247 } | 306 } |
| 248 } | 307 } |
| 249 | 308 |
| 250 private void searchEngineSelected(int position) { | 309 private String searchEngineSelected(int position) { |
| 251 // First clean up any automatically added permissions (if any) for the p reviously selected | 310 // First clean up any automatically added permissions (if any) for the p reviously selected |
| 252 // search engine. | 311 // search engine. |
| 253 SharedPreferences sharedPreferences = | 312 SharedPreferences sharedPreferences = |
| 254 ContextUtils.getAppSharedPreferences(); | 313 ContextUtils.getAppSharedPreferences(); |
| 255 if (sharedPreferences.getBoolean(PrefServiceBridge.LOCATION_AUTO_ALLOWED , false)) { | 314 if (sharedPreferences.getBoolean(PrefServiceBridge.LOCATION_AUTO_ALLOWED , false)) { |
| 256 if (locationEnabled(mSelectedSearchEnginePosition, false)) { | 315 if (locationEnabled(mSelectedSearchEnginePosition, false)) { |
| 257 String url = TemplateUrlService.getInstance().getSearchEngineUrl FromTemplateUrl( | 316 String url = TemplateUrlService.getInstance().getSearchEngineUrl FromTemplateUrl( |
| 258 toIndex(mSelectedSearchEnginePosition)); | 317 toKeyword(mSelectedSearchEnginePosition)); |
| 259 WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin( | 318 WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin( |
| 260 url, url, ContentSetting.DEFAULT.toInt(), false); | 319 url, url, ContentSetting.DEFAULT.toInt(), false); |
| 261 } | 320 } |
| 262 sharedPreferences.edit().remove(PrefServiceBridge.LOCATION_AUTO_ALLO WED).apply(); | 321 sharedPreferences.edit().remove(PrefServiceBridge.LOCATION_AUTO_ALLO WED).apply(); |
| 263 } | 322 } |
| 264 | 323 |
| 265 // Record the change in search engine. | 324 // Record the change in search engine. |
| 266 mSelectedSearchEnginePosition = position; | 325 mSelectedSearchEnginePosition = position; |
| 267 | 326 |
| 327 String keyword = toKeyword(mSelectedSearchEnginePosition); | |
| 268 // Report the change back. | 328 // Report the change back. |
| 269 mCallback.currentSearchEngineDetermined(toIndex(mSelectedSearchEnginePos ition)); | 329 mCallback.currentSearchEngineDetermined(keyword); |
| 270 | 330 |
| 331 // If the user has manually set the default search engine, disable auto switching. | |
| 332 boolean manualSwitch = mSelectedSearchEnginePosition != mInitialEnginePo sition; | |
| 333 if (manualSwitch) { | |
| 334 RecordUserAction.record("SearchEngine_ManualChange"); | |
| 335 LocaleManager.getInstance().setSearchEngineAutoSwitch(false); | |
| 336 } | |
| 271 notifyDataSetChanged(); | 337 notifyDataSetChanged(); |
| 338 return keyword; | |
| 272 } | 339 } |
| 273 | 340 |
| 274 private void onLocationLinkClicked() { | 341 private void onLocationLinkClicked() { |
| 275 if (!LocationUtils.getInstance().isSystemLocationSettingEnabled()) { | 342 if (!LocationUtils.getInstance().isSystemLocationSettingEnabled()) { |
| 276 mContext.startActivity(LocationUtils.getInstance().getSystemLocation SettingsIntent()); | 343 mContext.startActivity(LocationUtils.getInstance().getSystemLocation SettingsIntent()); |
| 277 } else { | 344 } else { |
| 278 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsP age( | 345 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsP age( |
| 279 mContext, SingleWebsitePreferences.class.getName()); | 346 mContext, SingleWebsitePreferences.class.getName()); |
| 280 String url = TemplateUrlService.getInstance().getSearchEngineUrlFrom TemplateUrl( | 347 String url = TemplateUrlService.getInstance().getSearchEngineUrlFrom TemplateUrl( |
| 281 toIndex(mSelectedSearchEnginePosition)); | 348 toKeyword(mSelectedSearchEnginePosition)); |
| 282 Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsFor Site(url); | 349 Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsFor Site(url); |
| 283 fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION, | 350 fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION, |
| 284 locationEnabled(mSelectedSearchEnginePosition, true)); | 351 locationEnabled(mSelectedSearchEnginePosition, true)); |
| 285 settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, f ragmentArgs); | 352 settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, f ragmentArgs); |
| 286 mContext.startActivity(settingsIntent); | 353 mContext.startActivity(settingsIntent); |
| 287 } | 354 } |
| 288 } | 355 } |
| 289 | 356 |
| 290 private boolean locationEnabled(int position, boolean checkGeoHeader) { | 357 private boolean locationEnabled(int position, boolean checkGeoHeader) { |
| 291 if (position == -1) return false; | 358 if (position == -1) return false; |
| 292 | 359 |
| 293 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl( | 360 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl( |
| 294 toIndex(position)); | 361 toKeyword(position)); |
| 295 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ; | 362 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ; |
| 296 ContentSetting locationPermission = locationSettings.getContentSetting() ; | 363 ContentSetting locationPermission = locationSettings.getContentSetting() ; |
| 297 // Handle the case where the geoHeader being sent when no permission has been specified. | 364 // Handle the case where the geoHeader being sent when no permission has been specified. |
| 298 if (locationPermission == ContentSetting.ASK && checkGeoHeader) { | 365 if (locationPermission == ContentSetting.ASK && checkGeoHeader) { |
| 299 return GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, fal se); | 366 return GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, fal se); |
| 300 } | 367 } |
| 301 return locationPermission == ContentSetting.ALLOW; | 368 return locationPermission == ContentSetting.ALLOW; |
| 302 } | 369 } |
| 303 } | 370 } |
| OLD | NEW |