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

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

Issue 2506193003: Hide location permission if a search engine is non-Google or its location permission is unset. (Closed)
Patch Set: Update behavior that even Google's location is unset, location permission info is hidden. Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
(...skipping 22 matching lines...) Expand all
33 import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge; 33 import org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge;
34 import org.chromium.chrome.browser.search_engines.TemplateUrlService; 34 import org.chromium.chrome.browser.search_engines.TemplateUrlService;
35 import org.chromium.chrome.browser.search_engines.TemplateUrlService.LoadListene r; 35 import org.chromium.chrome.browser.search_engines.TemplateUrlService.LoadListene r;
36 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl ; 36 import org.chromium.chrome.browser.search_engines.TemplateUrlService.TemplateUrl ;
37 import org.chromium.components.location.LocationUtils; 37 import org.chromium.components.location.LocationUtils;
38 import org.chromium.ui.text.SpanApplier; 38 import org.chromium.ui.text.SpanApplier;
39 import org.chromium.ui.text.SpanApplier.SpanInfo; 39 import org.chromium.ui.text.SpanApplier.SpanInfo;
40 40
41 import java.util.List; 41 import java.util.List;
42 42
43
43 /** 44 /**
44 * A custom adapter for listing search engines. 45 * A custom adapter for listing search engines.
45 */ 46 */
46 public class SearchEngineAdapter extends BaseAdapter implements LoadListener, On ClickListener { 47 public class SearchEngineAdapter extends BaseAdapter implements LoadListener, On ClickListener {
47 /** 48 /**
48 * A callback for reporting progress to the owner. 49 * A callback for reporting progress to the owner.
49 */ 50 */
50 public interface SelectSearchEngineCallback { 51 public interface SelectSearchEngineCallback {
51 /** 52 /**
52 * Called when the search engine data has loaded and we've determined th e currently active 53 * Called when the search engine data has loaded and we've determined th e currently active
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 public void onInitializeAccessibilityNodeInfo(View host, Accessibili tyNodeInfo info) { 199 public void onInitializeAccessibilityNodeInfo(View host, Accessibili tyNodeInfo info) {
199 super.onInitializeAccessibilityNodeInfo(host, info); 200 super.onInitializeAccessibilityNodeInfo(host, info);
200 info.setCheckable(true); 201 info.setCheckable(true);
201 info.setChecked(selected); 202 info.setChecked(selected);
202 } 203 }
203 }); 204 });
204 205
205 TextView link = (TextView) view.findViewById(R.id.link); 206 TextView link = (TextView) view.findViewById(R.id.link);
206 link.setVisibility(selected ? View.VISIBLE : View.GONE); 207 link.setVisibility(selected ? View.VISIBLE : View.GONE);
207 if (selected) { 208 if (selected) {
208 ForegroundColorSpan linkSpan = new ForegroundColorSpan( 209 if (!shouldShowLocationInfo(position)) {
209 ApiCompatibilityUtils.getColor(resources, R.color.pref_accen t_color)); 210 link.setVisibility(View.GONE);
210 if (LocationUtils.getInstance().isSystemLocationSettingEnabled()) {
211 String message = mContext.getString(
212 locationEnabled(position, true)
213 ? R.string.search_engine_location_allowed
214 : R.string.search_engine_location_blocked);
215 SpannableString messageWithLink = new SpannableString(message);
216 messageWithLink.setSpan(linkSpan, 0, messageWithLink.length(), 0 );
217 link.setText(messageWithLink);
218 } else { 211 } else {
219 link.setText(SpanApplier.applySpans( 212 ForegroundColorSpan linkSpan = new ForegroundColorSpan(
220 mContext.getString(R.string.android_location_off), 213 ApiCompatibilityUtils.getColor(resources, R.color.pref_a ccent_color));
221 new SpanInfo("<link>", "</link>", linkSpan))); 214 if (LocationUtils.getInstance().isSystemLocationSettingEnabled() ) {
Peter Kasting 2016/11/17 23:12:05 Is this condition, in this nested case, still what
ltian 2016/11/18 00:17:36 That part is necessary. Here the "system location"
Peter Kasting 2016/11/18 00:24:47 Right, that was the UI I figured was here. I gues
215 String message = mContext.getString(
216 locationEnabled(position, true)
217 ? R.string.search_engine_location_allowed
218 : R.string.search_engine_location_blocked);
219 SpannableString messageWithLink = new SpannableString(messag e);
220 messageWithLink.setSpan(linkSpan, 0, messageWithLink.length( ), 0);
221 link.setText(messageWithLink);
222 } else {
223 link.setText(SpanApplier.applySpans(
224 mContext.getString(R.string.android_location_off),
225 new SpanInfo("<link>", "</link>", linkSpan)));
226 }
227
228 link.setOnClickListener(this);
222 } 229 }
223
224 link.setOnClickListener(this);
225 } 230 }
226 231
227 return view; 232 return view;
228 } 233 }
229 234
230 // TemplateUrlService.LoadListener 235 // TemplateUrlService.LoadListener
231 236
232 @Override 237 @Override
233 public void onTemplateUrlServiceLoaded() { 238 public void onTemplateUrlServiceLoaded() {
234 TemplateUrlService.getInstance().unregisterLoadListener(this); 239 TemplateUrlService.getInstance().unregisterLoadListener(this);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl( 298 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl(
294 toIndex(position)); 299 toIndex(position));
295 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ; 300 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ;
296 ContentSetting locationPermission = locationSettings.getContentSetting() ; 301 ContentSetting locationPermission = locationSettings.getContentSetting() ;
297 // Handle the case where the geoHeader being sent when no permission has been specified. 302 // Handle the case where the geoHeader being sent when no permission has been specified.
298 if (locationPermission == ContentSetting.ASK && checkGeoHeader) { 303 if (locationPermission == ContentSetting.ASK && checkGeoHeader) {
299 return GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, fal se); 304 return GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, fal se);
300 } 305 }
301 return locationPermission == ContentSetting.ALLOW; 306 return locationPermission == ContentSetting.ALLOW;
302 } 307 }
308
309 private boolean shouldShowLocationInfo(int position) {
310 String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemp lateUrl(
311 toIndex(position));
312 GeolocationInfo locationSettings = new GeolocationInfo(url, null, false) ;
313 ContentSetting locationPermission = locationSettings.getContentSetting() ;
Peter Kasting 2016/11/17 23:12:05 This code seems like it partially duplicates locat
ltian 2016/11/18 00:17:36 I thought about it before but the two functions lo
Peter Kasting 2016/11/18 00:24:47 I think we want something like the following (over
314 // For Google search engine, if location permission is granted for the w hole app,
315 // even its own location permission is unset, its location permission is still granted.
316 return locationPermission != ContentSetting.ASK
317 || GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, fals e);
318 }
303 } 319 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698