| Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java
|
| index 6d2d8c50cb10f63235fb2aed25ce8dad250532be..cc43f68a3fb5f617ff4d0cd362c9dc57dd0a4ea5 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/PrefServiceBridge.java
|
| @@ -6,6 +6,7 @@ package org.chromium.chrome.browser.preferences;
|
|
|
| import android.content.Context;
|
| import android.content.SharedPreferences;
|
| +import android.net.Uri;
|
| import android.preference.PreferenceManager;
|
| import android.text.TextUtils;
|
| import android.util.Log;
|
| @@ -13,6 +14,7 @@ import android.util.Log;
|
| import org.chromium.base.CalledByNative;
|
| import org.chromium.base.ThreadUtils;
|
| import org.chromium.chrome.browser.ContentSettingsType;
|
| +import org.chromium.chrome.browser.UrlUtilities;
|
| import org.chromium.chrome.browser.preferences.website.ContentSetting;
|
| import org.chromium.chrome.browser.preferences.website.ContentSettingException;
|
| import org.chromium.chrome.browser.preferences.website.GeolocationInfo;
|
| @@ -21,6 +23,7 @@ import org.chromium.chrome.browser.search_engines.TemplateUrlService;
|
|
|
| import java.util.ArrayList;
|
| import java.util.List;
|
| +import java.util.Locale;
|
|
|
| /**
|
| * PrefServiceBridge is a singleton which provides access to some native preferences. Ideally
|
| @@ -44,6 +47,8 @@ public final class PrefServiceBridge {
|
|
|
| private static String sProfilePath;
|
|
|
| + private static final String HTTPS_SCHEME = "https";
|
| +
|
| // Object to notify when "clear browsing data" completes.
|
| private OnClearBrowsingDataListener mClearBrowsingDataListener;
|
| private static final String LOG_TAG = "PrefServiceBridge";
|
| @@ -178,6 +183,55 @@ public final class PrefServiceBridge {
|
| }
|
|
|
| /**
|
| + * Whether the geo header is allowed to be sent for the current URL.
|
| + * @param context The Context used to get the device location.
|
| + * @param url The URL of the request with which this header will be sent.
|
| + * @param isIncognito Whether the request will happen in an incognito tab.
|
| + */
|
| + public static boolean isGeoHeaderEnabledForUrl(
|
| + Context context, String url, boolean isIncognito) {
|
| + // TODO(finnur): delete this method once GeolocationHeader has been upstreamed.
|
| + // Only send the Geo header in normal mode.
|
| + if (isIncognito) return false;
|
| +
|
| + // Only send the Geo header to Google domains.
|
| + if (!UrlUtilities.nativeIsGoogleSearchUrl(url)) return false;
|
| +
|
| + Uri uri = Uri.parse(url);
|
| + if (!HTTPS_SCHEME.equals(uri.getScheme())) return false;
|
| +
|
| + // Only send Geo header if the user hasn't disabled geolocation for url.
|
| + if (isLocationDisabledForUrl(uri)) return false;
|
| +
|
| + return true;
|
| + }
|
| +
|
| + /**
|
| + * Returns true if the user has disabled sharing their location with url (e.g. via the
|
| + * geolocation infobar). If the user has not chosen a preference for url and url uses the https
|
| + * scheme, this considers the user's preference for url with the http scheme instead.
|
| + */
|
| + public static boolean isLocationDisabledForUrl(Uri uri) {
|
| + // TODO(finnur): Delete this method once GeolocationHeader has been upstreamed.
|
| + GeolocationInfo locationSettings = new GeolocationInfo(uri.toString(), null);
|
| + ContentSetting locationPermission = locationSettings.getContentSetting();
|
| +
|
| + // If no preference has been chosen and the scheme is https, fall back to the preference for
|
| + // this same host over http with no explicit port number.
|
| + if (locationPermission == null || locationPermission == ContentSetting.ASK) {
|
| + String scheme = uri.getScheme();
|
| + if (scheme != null && scheme.toLowerCase(Locale.US).equals("https")
|
| + && uri.getAuthority() != null && uri.getUserInfo() == null) {
|
| + String urlWithHttp = "http://" + uri.getHost();
|
| + locationSettings = new GeolocationInfo(urlWithHttp, null);
|
| + locationPermission = locationSettings.getContentSetting();
|
| + }
|
| + }
|
| +
|
| + return locationPermission == ContentSetting.BLOCK;
|
| + }
|
| +
|
| + /**
|
| * Returns the path to the user's profile directory via a callback. The callback may be
|
| * called synchronously or asynchronously.
|
| */
|
|
|