Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/SearchEngineAdapter.java

Issue 2367373003: [Android] Allow setting recently visited search engines as default search engine (Closed)
Patch Set: Reorganize template_url_serivce_android code. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 private static final int VIEW_TYPE_ITEM = 0;
48 * A callback for reporting progress to the owner. 51 private static final int VIEW_TYPE_DIVIDER = 1;
49 */ 52
gone 2016/11/28 21:37:02 Remove newline above
ltian 2016/11/29 02:44:02 Done.
50 public interface SelectSearchEngineCallback { 53 private static final int VIEW_TYPE_COUNT = 2;
51 /**
52 * Called when the search engine data has loaded and we've determined th e currently active
53 * one.
54 * @param name Provides the name of it (with a simplified URL in parenth esis).
55 */
56 void currentSearchEngineDetermined(int selectedIndex);
57 }
58 54
59 // The current context. 55 // The current context.
gone 2016/11/28 21:37:02 Switch these to /** javadoc style */ comments so t
ltian 2016/11/29 02:44:02 Done.
60 private Context mContext; 56 private Context mContext;
61 57
62 // The layout inflater to use for the custom views. 58 // The layout inflater to use for the custom views.
63 private LayoutInflater mLayoutInflater; 59 private LayoutInflater mLayoutInflater;
64 60
65 // The callback to use for notifying caller of progress. 61 // The list of prepopluated and default search engines.
66 private SelectSearchEngineCallback mCallback; 62 private List<TemplateUrl> mPrepopulatedSearchEngines = new ArrayList<Templat eUrl>();
gone 2016/11/28 21:37:02 = new ArrayList<>();
ltian 2016/11/29 02:44:02 Done.
67 63
68 // The list of available search engines. 64 // The list of recently visited search engines.
69 private List<TemplateUrl> mSearchEngines; 65 private List<TemplateUrl> mRecentSearchEngines = new ArrayList<TemplateUrl>( );
70 // The position (index into mSearchEngines) of the currently selected search engine. Can be -1 66
71 // if current search engine is managed and set to something other than the p re-populated values. 67 // The position (index into mPrepopulatedSearchEngines) of the currently sel ected search engine.
68 // Can be -1 if current search engine is managed and set to something other than the
69 // pre-populated values.
72 private int mSelectedSearchEnginePosition = -1; 70 private int mSelectedSearchEnginePosition = -1;
73 71
74 // The position of the default search engine before user's action. 72 // The position of the default search engine before user's action.
75 private int mInitialEnginePosition = -1; 73 private int mInitialEnginePosition = -1;
76 74
77 /** 75 /**
78 * Construct a SearchEngineAdapter. 76 * Construct a SearchEngineAdapter.
79 * @param context The current context. 77 * @param context The current context.
80 * @param callback The callback to use to communicate back.
81 */ 78 */
82 public SearchEngineAdapter(Context context, SelectSearchEngineCallback callb ack) { 79 public SearchEngineAdapter(Context context) {
83 mContext = context; 80 mContext = context;
84 mLayoutInflater = (LayoutInflater) mContext.getSystemService( 81 mLayoutInflater = (LayoutInflater) mContext.getSystemService(
85 Context.LAYOUT_INFLATER_SERVICE); 82 Context.LAYOUT_INFLATER_SERVICE);
86 mCallback = callback;
87 83
88 initEntries(); 84 initEntries();
89 } 85 }
90 86
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. 87 // Used for testing.
99 88
100 String getValueForTesting() { 89 String getValueForTesting() {
gone 2016/11/28 21:37:02 Adding @VisibleForTesting or naming the function S
ltian 2016/11/29 02:44:02 Done.
101 return Integer.toString(mSelectedSearchEnginePosition); 90 return Integer.toString(mSelectedSearchEnginePosition);
102 } 91 }
103 92
104 void setValueForTesting(String value) { 93 String setValueForTesting(String value) {
105 searchEngineSelected(Integer.parseInt(value)); 94 return searchEngineSelected(Integer.parseInt(value));
95 }
96
97 String getKeywordForTesting(int index) {
98 return toKeyword(index);
106 } 99 }
107 100
108 /** 101 /**
109 * Initialize the search engine list. 102 * Initialize the search engine list.
110 */ 103 */
111 private void initEntries() { 104 private void initEntries() {
112 TemplateUrlService templateUrlService = TemplateUrlService.getInstance() ; 105 TemplateUrlService templateUrlService = TemplateUrlService.getInstance() ;
113 if (!templateUrlService.isLoaded()) { 106 if (!templateUrlService.isLoaded()) {
114 templateUrlService.registerLoadListener(this); 107 templateUrlService.registerLoadListener(this);
115 templateUrlService.load(); 108 templateUrlService.load();
116 return; // Flow continues in onTemplateUrlServiceLoaded below. 109 return; // Flow continues in onTemplateUrlServiceLoaded below.
117 } 110 }
118 111
119 // Fetch all the search engine info and the currently active one. 112 int defaultSearchEngineIndex = templateUrlService.getDefaultSearchEngine Index();
120 mSearchEngines = templateUrlService.getLocalizedSearchEngines(); 113 for (TemplateUrl templateUrl : templateUrlService.getSearchEngines()) {
121 int searchEngineIndex = templateUrlService.getDefaultSearchEngineIndex() ; 114 if (templateUrl.getType() == TemplateUrlService.TYPE_PREPOPULATED
122 // Convert the TemplateUrl index into an index into mSearchEngines. 115 || templateUrl.getType() == TemplateUrlService.TYPE_DEFAULT) {
116 mPrepopulatedSearchEngines.add(templateUrl);
117 } else {
118 mRecentSearchEngines.add(templateUrl);
119 }
120 }
121
122 // Convert the TemplateUrl index into an index of mSearchEngines.
123 mSelectedSearchEnginePosition = -1; 123 mSelectedSearchEnginePosition = -1;
124 for (int i = 0; i < mSearchEngines.size(); ++i) { 124 for (int i = 0; i < mPrepopulatedSearchEngines.size(); ++i) {
125 if (mSearchEngines.get(i).getIndex() == searchEngineIndex) { 125 if (mPrepopulatedSearchEngines.get(i).getIndex() == defaultSearchEng ineIndex) {
126 mSelectedSearchEnginePosition = i; 126 mSelectedSearchEnginePosition = i;
127 } 127 }
128 } 128 }
129
130 for (int i = 0; i < mRecentSearchEngines.size(); ++i) {
131 if (mRecentSearchEngines.get(i).getIndex() == defaultSearchEngineInd ex) {
132 // Add one to offset the title for recent search engine list
gone 2016/11/28 21:37:02 1) Add period to end of the comment 2) the title f
ltian 2016/11/29 02:44:02 Done.
133 mSelectedSearchEnginePosition = i + mPrepopulatedSearchEngines.s ize() + 1;
134 }
135 }
136
129 mInitialEnginePosition = mSelectedSearchEnginePosition; 137 mInitialEnginePosition = mSelectedSearchEnginePosition;
130 138
131 // Report back what is selected. 139 TemplateUrlService.getInstance().setSearchEngine(toKeyword(mSelectedSear chEnginePosition));
132 mCallback.currentSearchEngineDetermined(toIndex(mSelectedSearchEnginePos ition));
133 } 140 }
134 141
135 private int toIndex(int position) { 142 private String toKeyword(int position) {
136 return mSearchEngines.get(position).getIndex(); 143 if (position < mPrepopulatedSearchEngines.size()) {
144 return mPrepopulatedSearchEngines.get(position).getKeyword();
145 } else {
146 position -= mPrepopulatedSearchEngines.size() + 1;
gone 2016/11/28 21:37:02 You use "mPrepopulatedSearchEngines.size() + 1" in
ltian 2016/11/29 02:44:02 Done.
147 return mRecentSearchEngines.get(position).getKeyword();
148 }
137 } 149 }
138 150
139 // BaseAdapter: 151 // BaseAdapter:
140 152
141 @Override 153 @Override
142 public int getCount() { 154 public int getCount() {
143 return mSearchEngines == null ? 0 : mSearchEngines.size(); 155 return mPrepopulatedSearchEngines == null
156 ? 0
157 : mPrepopulatedSearchEngines.size() + mRecentSearchEngines.size( ) + 1;
158 }
159
160 @Override
161 public int getViewTypeCount() {
162 return VIEW_TYPE_COUNT;
144 } 163 }
145 164
146 @Override 165 @Override
147 public Object getItem(int pos) { 166 public Object getItem(int pos) {
148 TemplateUrl templateUrl = mSearchEngines.get(pos); 167 if (pos < mPrepopulatedSearchEngines.size()) {
149 return templateUrl.getShortName(); 168 return mPrepopulatedSearchEngines.get(pos);
169 } else if (pos > mPrepopulatedSearchEngines.size()) {
170 pos -= mPrepopulatedSearchEngines.size() + 1;
171 return mRecentSearchEngines.get(pos);
172 }
173 return null;
150 } 174 }
151 175
152 @Override 176 @Override
153 public long getItemId(int position) { 177 public long getItemId(int position) {
154 return position; 178 return position;
155 } 179 }
156 180
157 @Override 181 @Override
182 public int getItemViewType(int position) {
183 if (position == mPrepopulatedSearchEngines.size()) {
184 return VIEW_TYPE_DIVIDER;
185 } else {
186 return VIEW_TYPE_ITEM;
187 }
188 }
189
190 @Override
158 public View getView(int position, View convertView, ViewGroup parent) { 191 public View getView(int position, View convertView, ViewGroup parent) {
159 View view = convertView; 192 View view = convertView;
193 TemplateUrl templateUrl = (TemplateUrl) getItem(position);
194 int itemViewType = getItemViewType(position);
160 if (convertView == null) { 195 if (convertView == null) {
161 view = mLayoutInflater.inflate(R.layout.search_engine, null); 196 if (itemViewType == VIEW_TYPE_DIVIDER) {
197 view = mLayoutInflater.inflate(R.layout.search_engine_recent_tit le, null);
198 } else {
199 view = mLayoutInflater.inflate(R.layout.search_engine, null);
200 }
gone 2016/11/28 21:37:02 view = mLayoutInflater.inflate(itemViewType == VIE
ltian 2016/11/29 02:44:02 Done.
201 }
202 if (itemViewType == VIEW_TYPE_DIVIDER) {
203 return view;
162 } 204 }
163 205
164 view.setOnClickListener(this); 206 view.setOnClickListener(this);
165 view.setTag(position); 207 view.setTag(position);
166 208
167 // TODO(finnur): There's a tinting bug in the AppCompat lib (see http:// crbug.com/474695), 209 // 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 210 // 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. 211 // addressed, but in the meantime we should use the native RadioButton i nstead.
170 RadioButton radioButton = (RadioButton) view.findViewById(R.id.radiobutt on); 212 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 213 // On Lollipop this removes the redundant animation ring on selection bu t on older versions
172 // it would cause the radio button to disappear. 214 // it would cause the radio button to disappear.
173 // TODO(finnur): Remove the encompassing if statement once we go back to using the AppCompat 215 // TODO(finnur): Remove the encompassing if statement once we go back to using the AppCompat
174 // control. 216 // control.
175 final boolean selected = position == mSelectedSearchEnginePosition; 217 final boolean selected = position == mSelectedSearchEnginePosition;
176 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 218 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
177 radioButton.setBackgroundResource(0); 219 radioButton.setBackgroundResource(0);
178 } 220 }
179 radioButton.setChecked(selected); 221 radioButton.setChecked(selected);
180 222
181 TextView description = (TextView) view.findViewById(R.id.description); 223 TextView description = (TextView) view.findViewById(R.id.name);
182 TemplateUrl templateUrl = mSearchEngines.get(position);
183 Resources resources = mContext.getResources(); 224 Resources resources = mContext.getResources();
184 description.setText(templateUrl.getShortName()); 225 description.setText(templateUrl.getShortName());
185 226
227 TextView url = (TextView) view.findViewById(R.id.url);
228 url.setText(templateUrl.getUrl());
229 if (templateUrl.getType() == TemplateUrlService.TYPE_PREPOPULATED
230 || templateUrl.getType() == TemplateUrlService.TYPE_DEFAULT
231 || templateUrl.getUrl().length() == 0) {
232 url.setVisibility(View.GONE);
233 }
234
186 // To improve the explore-by-touch experience, the radio button is hidde n from accessibility 235 // 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. 236 // 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". 237 // "google.com checked" or "google.com not checked".
189 radioButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILIT Y_NO); 238 radioButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILIT Y_NO);
190 description.setAccessibilityDelegate(new AccessibilityDelegate() { 239 description.setAccessibilityDelegate(new AccessibilityDelegate() {
191 @Override 240 @Override
192 public void onInitializeAccessibilityEvent(View host, AccessibilityE vent event) { 241 public void onInitializeAccessibilityEvent(View host, AccessibilityE vent event) {
193 super.onInitializeAccessibilityEvent(host, event); 242 super.onInitializeAccessibilityEvent(host, event);
194 event.setChecked(selected); 243 event.setChecked(selected);
195 } 244 }
196 245
197 @Override 246 @Override
198 public void onInitializeAccessibilityNodeInfo(View host, Accessibili tyNodeInfo info) { 247 public void onInitializeAccessibilityNodeInfo(View host, Accessibili tyNodeInfo info) {
199 super.onInitializeAccessibilityNodeInfo(host, info); 248 super.onInitializeAccessibilityNodeInfo(host, info);
200 info.setCheckable(true); 249 info.setCheckable(true);
201 info.setChecked(selected); 250 info.setChecked(selected);
202 } 251 }
203 }); 252 });
204 253
205 TextView link = (TextView) view.findViewById(R.id.link); 254 TextView link = (TextView) view.findViewById(R.id.location_permission);
206 link.setVisibility(selected ? View.VISIBLE : View.GONE); 255 link.setVisibility(selected ? View.VISIBLE : View.GONE);
207 if (selected) { 256 if (selected) {
208 if (getLocationPermissionType(position, true) == ContentSetting.ASK) { 257 if (getLocationPermissionType(position, true) == ContentSetting.ASK) {
209 link.setVisibility(View.GONE); 258 link.setVisibility(View.GONE);
210 } else { 259 } else {
211 ForegroundColorSpan linkSpan = new ForegroundColorSpan( 260 ForegroundColorSpan linkSpan = new ForegroundColorSpan(
212 ApiCompatibilityUtils.getColor(resources, R.color.pref_a ccent_color)); 261 ApiCompatibilityUtils.getColor(resources, R.color.pref_a ccent_color));
213 if (LocationUtils.getInstance().isSystemLocationSettingEnabled() ) { 262 if (LocationUtils.getInstance().isSystemLocationSettingEnabled() ) {
214 String message = mContext.getString( 263 String message = mContext.getString(
215 locationEnabled(position, true) 264 locationEnabled(position, true)
(...skipping 28 matching lines...) Expand all
244 293
245 @Override 294 @Override
246 public void onClick(View view) { 295 public void onClick(View view) {
247 if (view.getTag() == null) { 296 if (view.getTag() == null) {
248 onLocationLinkClicked(); 297 onLocationLinkClicked();
249 } else { 298 } else {
250 searchEngineSelected((int) view.getTag()); 299 searchEngineSelected((int) view.getTag());
251 } 300 }
252 } 301 }
253 302
254 private void searchEngineSelected(int position) { 303 private String searchEngineSelected(int position) {
255 // First clean up any automatically added permissions (if any) for the p reviously selected 304 // First clean up any automatically added permissions (if any) for the p reviously selected
256 // search engine. 305 // search engine.
257 SharedPreferences sharedPreferences = 306 SharedPreferences sharedPreferences =
258 ContextUtils.getAppSharedPreferences(); 307 ContextUtils.getAppSharedPreferences();
259 if (sharedPreferences.getBoolean(PrefServiceBridge.LOCATION_AUTO_ALLOWED , false)) { 308 if (sharedPreferences.getBoolean(PrefServiceBridge.LOCATION_AUTO_ALLOWED , false)) {
260 if (locationEnabled(mSelectedSearchEnginePosition, false)) { 309 if (locationEnabled(mSelectedSearchEnginePosition, false)) {
261 String url = TemplateUrlService.getInstance().getSearchEngineUrl FromTemplateUrl( 310 String url = TemplateUrlService.getInstance().getSearchEngineUrl FromTemplateUrl(
262 toIndex(mSelectedSearchEnginePosition)); 311 toKeyword(mSelectedSearchEnginePosition));
263 WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin( 312 WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin(
264 url, url, ContentSetting.DEFAULT.toInt(), false); 313 url, url, ContentSetting.DEFAULT.toInt(), false);
265 } 314 }
266 sharedPreferences.edit().remove(PrefServiceBridge.LOCATION_AUTO_ALLO WED).apply(); 315 sharedPreferences.edit().remove(PrefServiceBridge.LOCATION_AUTO_ALLO WED).apply();
267 } 316 }
268 317
269 // Record the change in search engine. 318 // Record the change in search engine.
270 mSelectedSearchEnginePosition = position; 319 mSelectedSearchEnginePosition = position;
271 320
272 // Report the change back. 321 String keyword = toKeyword(mSelectedSearchEnginePosition);
273 mCallback.currentSearchEngineDetermined(toIndex(mSelectedSearchEnginePos ition)); 322 TemplateUrlService.getInstance().setSearchEngine(keyword);
274 323
324 // If the user has manually set the default search engine, disable auto switching.
325 boolean manualSwitch = mSelectedSearchEnginePosition != mInitialEnginePo sition;
326 if (manualSwitch) {
327 RecordUserAction.record("SearchEngine_ManualChange");
328 LocaleManager.getInstance().setSearchEngineAutoSwitch(false);
329 }
275 notifyDataSetChanged(); 330 notifyDataSetChanged();
331 return keyword;
276 } 332 }
277 333
278 private void onLocationLinkClicked() { 334 private void onLocationLinkClicked() {
279 if (!LocationUtils.getInstance().isSystemLocationSettingEnabled()) { 335 if (!LocationUtils.getInstance().isSystemLocationSettingEnabled()) {
280 mContext.startActivity(LocationUtils.getInstance().getSystemLocation SettingsIntent()); 336 mContext.startActivity(LocationUtils.getInstance().getSystemLocation SettingsIntent());
281 } else { 337 } else {
282 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsP age( 338 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsP age(
283 mContext, SingleWebsitePreferences.class.getName()); 339 mContext, SingleWebsitePreferences.class.getName());
284 String url = TemplateUrlService.getInstance().getSearchEngineUrlFrom TemplateUrl( 340 String url = TemplateUrlService.getInstance().getSearchEngineUrlFrom TemplateUrl(
285 toIndex(mSelectedSearchEnginePosition)); 341 toKeyword(mSelectedSearchEnginePosition));
286 Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsFor Site(url); 342 Bundle fragmentArgs = SingleWebsitePreferences.createFragmentArgsFor Site(url);
287 fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION, 343 fragmentArgs.putBoolean(SingleWebsitePreferences.EXTRA_LOCATION,
288 locationEnabled(mSelectedSearchEnginePosition, true)); 344 locationEnabled(mSelectedSearchEnginePosition, true));
289 settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, f ragmentArgs); 345 settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, f ragmentArgs);
290 mContext.startActivity(settingsIntent); 346 mContext.startActivity(settingsIntent);
291 } 347 }
292 } 348 }
293 349
294 private ContentSetting getLocationPermissionType(int position, boolean check GeoHeader) { 350 private ContentSetting getLocationPermissionType(int position, boolean check GeoHeader) {
295 if (position == -1) { 351 if (position == -1) {
296 return ContentSetting.BLOCK; 352 return ContentSetting.BLOCK;
297 } 353 }
298 354
299 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl( 355 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl(
300 toIndex(position)); 356 toKeyword(position));
301 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ; 357 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ;
302 ContentSetting locationPermission = locationSettings.getContentSetting() ; 358 ContentSetting locationPermission = locationSettings.getContentSetting() ;
303 if (locationPermission == ContentSetting.ASK) { 359 if (locationPermission == ContentSetting.ASK) {
304 // Handle the case where the geoHeader being sent when no permission has been specified. 360 // Handle the case where the geoHeader being sent when no permission has been specified.
305 if (checkGeoHeader && GeolocationHeader.isGeoHeaderEnabledForUrl( 361 if (checkGeoHeader && GeolocationHeader.isGeoHeaderEnabledForUrl(
306 mContext, url, false)) { 362 mContext, url, false)) {
307 locationPermission = ContentSetting.ALLOW; 363 locationPermission = ContentSetting.ALLOW;
308 } 364 }
309 } 365 }
310 return locationPermission; 366 return locationPermission;
311 } 367 }
312 368
313 private boolean locationEnabled(int position, boolean checkGeoHeader) { 369 private boolean locationEnabled(int position, boolean checkGeoHeader) {
314 return getLocationPermissionType(position, checkGeoHeader) == ContentSet ting.ALLOW; 370 return getLocationPermissionType(position, checkGeoHeader) == ContentSet ting.ALLOW;
315 } 371 }
316 372
317 } 373 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698