Search in sources :

Example 1 with GeolocationInfo

use of org.chromium.chrome.browser.preferences.website.GeolocationInfo in project AndroidChromium by JackyAndroid.

the class GeolocationHeader method isLocationDisabledForUrl.

/**
     * 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.
     */
static boolean isLocationDisabledForUrl(Uri uri, boolean isIncognito) {
    GeolocationInfo locationSettings = new GeolocationInfo(uri.toString(), null, isIncognito);
    ContentSetting locationPermission = locationSettings.getContentSetting();
    // 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, isIncognito);
            locationPermission = locationSettings.getContentSetting();
        }
    }
    return locationPermission == ContentSetting.BLOCK;
}
Also used : ContentSetting(org.chromium.chrome.browser.preferences.website.ContentSetting) GeolocationInfo(org.chromium.chrome.browser.preferences.website.GeolocationInfo)

Example 2 with GeolocationInfo

use of org.chromium.chrome.browser.preferences.website.GeolocationInfo in project AndroidChromium by JackyAndroid.

the class SearchEngineAdapter method locationEnabled.

private boolean locationEnabled(int position, boolean checkGeoHeader) {
    if (position == -1)
        return false;
    String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemplateUrl(toIndex(position));
    GeolocationInfo locationSettings = new GeolocationInfo(url, null, false);
    ContentSetting locationPermission = locationSettings.getContentSetting();
    // Handle the case where the geoHeader being sent when no permission has been specified.
    if (locationPermission == ContentSetting.ASK && checkGeoHeader) {
        return GeolocationHeader.isGeoHeaderEnabledForUrl(mContext, url, false);
    }
    return locationPermission == ContentSetting.ALLOW;
}
Also used : ContentSetting(org.chromium.chrome.browser.preferences.website.ContentSetting) GeolocationInfo(org.chromium.chrome.browser.preferences.website.GeolocationInfo) SpannableString(android.text.SpannableString)

Example 3 with GeolocationInfo

use of org.chromium.chrome.browser.preferences.website.GeolocationInfo in project AndroidChromium by JackyAndroid.

the class PrefServiceBridge method maybeCreatePermissionForDefaultSearchEngine.

/**
     * Add a permission entry for Location for the default search engine.
     * @param allowed Whether to create an Allowed permission or a Denied permission.
     * @param context The current context to use.
     */
public static void maybeCreatePermissionForDefaultSearchEngine(boolean allowed, Context context) {
    TemplateUrlService templateUrlService = TemplateUrlService.getInstance();
    String url = templateUrlService.getSearchEngineUrlFromTemplateUrl(templateUrlService.getDefaultSearchEngineIndex());
    if (allowed && !url.startsWith("https:"))
        return;
    GeolocationInfo locationSettings = new GeolocationInfo(url, null, false);
    ContentSetting locationPermission = locationSettings.getContentSetting();
    if (locationPermission == null || locationPermission == ContentSetting.ASK) {
        WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin(url, url, allowed ? ContentSetting.ALLOW.toInt() : ContentSetting.BLOCK.toInt(), false);
        SharedPreferences sharedPreferences = ContextUtils.getAppSharedPreferences();
        sharedPreferences.edit().putBoolean(LOCATION_AUTO_ALLOWED, true).apply();
    }
}
Also used : TemplateUrlService(org.chromium.chrome.browser.search_engines.TemplateUrlService) ContentSetting(org.chromium.chrome.browser.preferences.website.ContentSetting) SharedPreferences(android.content.SharedPreferences) GeolocationInfo(org.chromium.chrome.browser.preferences.website.GeolocationInfo)

Aggregations

ContentSetting (org.chromium.chrome.browser.preferences.website.ContentSetting)3 GeolocationInfo (org.chromium.chrome.browser.preferences.website.GeolocationInfo)3 SharedPreferences (android.content.SharedPreferences)1 SpannableString (android.text.SpannableString)1 TemplateUrlService (org.chromium.chrome.browser.search_engines.TemplateUrlService)1