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

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

Issue 2815643006: Fix location aspects of search engine settings UI Android UI (Closed)
Patch Set: Remove confusing comment Created 3 years, 8 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/SearchEngineAdapter.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/SearchEngineAdapter.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/SearchEngineAdapter.java
index 785c6fa53153e4ea672f277b4d37a1a38b8ddce3..d57c055734e24157ff53653c8c521c785a9a3fad 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/SearchEngineAdapter.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/SearchEngineAdapter.java
@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.preferences;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
+import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.SpannableString;
@@ -29,6 +30,7 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
+import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.locale.LocaleManager;
import org.chromium.chrome.browser.omnibox.geo.GeolocationHeader;
import org.chromium.chrome.browser.preferences.website.ContentSetting;
@@ -344,22 +346,25 @@ public class SearchEngineAdapter extends BaseAdapter
assert false;
link.setVisibility(View.GONE);
} else if (selected) {
- if (getLocationPermissionType(templateUrl) == ContentSetting.ASK) {
+ if (!locationShouldBeShown(templateUrl)) {
link.setVisibility(View.GONE);
} else {
ForegroundColorSpan linkSpan = new ForegroundColorSpan(
ApiCompatibilityUtils.getColor(resources, R.color.google_blue_700));
- if (LocationUtils.getInstance().isSystemLocationSettingEnabled()) {
+ // If location is allowed but system location is off, show a message explaining how
+ // to turn location on.
+ if (locationEnabled(templateUrl)
+ && !LocationUtils.getInstance().isSystemLocationSettingEnabled()) {
+ link.setText(SpanApplier.applySpans(
+ mContext.getString(R.string.android_location_off),
+ new SpanInfo("<link>", "</link>", linkSpan)));
+ } else {
String message = mContext.getString(locationEnabled(templateUrl)
? R.string.search_engine_location_allowed
: R.string.search_engine_location_blocked);
SpannableString messageWithLink = new SpannableString(message);
messageWithLink.setSpan(linkSpan, 0, messageWithLink.length(), 0);
link.setText(messageWithLink);
- } else {
- link.setText(SpanApplier.applySpans(
- mContext.getString(R.string.android_location_off),
- new SpanInfo("<link>", "</link>", linkSpan)));
}
link.setOnClickListener(this);
@@ -428,11 +433,11 @@ public class SearchEngineAdapter extends BaseAdapter
}
}
- private ContentSetting getLocationPermissionType(TemplateUrl templateUrl) {
+ private String getSearchEngineUrl(TemplateUrl templateUrl) {
if (templateUrl == null) {
Log.e(TAG, "Invalid null template URL found");
assert false;
- return ContentSetting.BLOCK;
+ return "";
}
String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemplateUrl(
@@ -440,27 +445,50 @@ public class SearchEngineAdapter extends BaseAdapter
if (url == null) {
Log.e(TAG, "Invalid template URL found: %s", templateUrl);
assert false;
- return ContentSetting.BLOCK;
+ return "";
}
+
+ return url;
+ }
+
+ private boolean locationShouldBeShown(TemplateUrl templateUrl) {
+ String url = getSearchEngineUrl(templateUrl);
+ if (url.isEmpty()) return false;
+
+ // Do not show location if the scheme isn't HTTPS.
+ Uri uri = Uri.parse(url);
+ if (!UrlConstants.HTTPS_SCHEME.equals(uri.getScheme())) return false;
+
+ // Only show the location setting if it is explicitly enabled or disabled.
+ GeolocationInfo locationSettings = new GeolocationInfo(url, null, false);
+ ContentSetting locationPermission = locationSettings.getContentSetting();
+ if (locationPermission != ContentSetting.ASK) return true;
+
+ if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) {
+ return WebsitePreferenceBridge.shouldUseDSEGeolocationSetting(url, false);
+ }
+
+ return GeolocationHeader.isGeoHeaderEnabledForUrl(url, false);
+ }
+
+ private boolean locationEnabled(TemplateUrl templateUrl) {
+ String url = getSearchEngineUrl(templateUrl);
+ if (url.isEmpty()) return false;
+
GeolocationInfo locationSettings = new GeolocationInfo(url, null, false);
ContentSetting locationPermission = locationSettings.getContentSetting();
if (locationPermission == ContentSetting.ASK) {
// Handle the case where the geoHeader being sent when no permission has been specified.
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) {
if (WebsitePreferenceBridge.shouldUseDSEGeolocationSetting(url, false)) {
- locationPermission = WebsitePreferenceBridge.getDSEGeolocationSetting()
- ? ContentSetting.ALLOW
- : ContentSetting.BLOCK;
+ return WebsitePreferenceBridge.getDSEGeolocationSetting();
}
} else if (GeolocationHeader.isGeoHeaderEnabledForUrl(url, false)) {
- locationPermission = ContentSetting.ALLOW;
+ return true;
}
}
- return locationPermission;
- }
- private boolean locationEnabled(TemplateUrl templateUrl) {
- return getLocationPermissionType(templateUrl) == ContentSetting.ALLOW;
+ return locationPermission == ContentSetting.ALLOW;
}
private int computeStartIndexForRecentSearchEngines() {
« 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