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