org.chromium.chrome.browser.preferences.website.ContentSetting Java Examples

The following examples show how to use org.chromium.chrome.browser.preferences.website.ContentSetting. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchEngineAdapter.java    From 365browser with Apache License 2.0 6 votes vote down vote up
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)) {
                return WebsitePreferenceBridge.getDSEGeolocationSetting();
            }
        } else if (GeolocationHeader.isGeoHeaderEnabledForUrl(url, false)) {
            return true;
        }
    }

    return locationPermission == ContentSetting.ALLOW;
}
 
Example #2
Source File: SearchEngineAdapter.java    From delion with Apache License 2.0 6 votes vote down vote up
private void searchEngineSelected(int position) {
    // First clean up any automatically added permissions (if any) for the previously selected
    // search engine.
    SharedPreferences sharedPreferences =
            ContextUtils.getAppSharedPreferences();
    if (sharedPreferences.getBoolean(PrefServiceBridge.LOCATION_AUTO_ALLOWED, false)) {
        if (locationEnabled(mSelectedSearchEnginePosition, false)) {
            String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemplateUrl(
                    toIndex(mSelectedSearchEnginePosition));
            WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin(
                    url, url, ContentSetting.DEFAULT.toInt(), false);
        }
        sharedPreferences.edit().remove(PrefServiceBridge.LOCATION_AUTO_ALLOWED).apply();
    }

    // Record the change in search engine.
    mSelectedSearchEnginePosition = position;
    TemplateUrlService.getInstance().setSearchEngine(toIndex(mSelectedSearchEnginePosition));

    // Report the change back.
    TemplateUrl templateUrl = mSearchEngines.get(mSelectedSearchEnginePosition);
    mCallback.currentSearchEngineDetermined(templateUrl.getShortName());

    notifyDataSetChanged();
}
 
Example #3
Source File: SearchEngineAdapter.java    From 365browser with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: PrefServiceBridge.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #5
Source File: SearchEngineAdapter.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void searchEngineSelected(int position) {
    // First clean up any automatically added permissions (if any) for the previously selected
    // search engine.
    SharedPreferences sharedPreferences =
            ContextUtils.getAppSharedPreferences();
    if (sharedPreferences.getBoolean(PrefServiceBridge.LOCATION_AUTO_ALLOWED, false)) {
        if (locationEnabled(mSelectedSearchEnginePosition, false)) {
            String url = TemplateUrlService.getInstance().getSearchEngineUrlFromTemplateUrl(
                    toIndex(mSelectedSearchEnginePosition));
            WebsitePreferenceBridge.nativeSetGeolocationSettingForOrigin(
                    url, url, ContentSetting.DEFAULT.toInt(), false);
        }
        sharedPreferences.edit().remove(PrefServiceBridge.LOCATION_AUTO_ALLOWED).apply();
    }

    // Record the change in search engine.
    mSelectedSearchEnginePosition = position;

    // Report the change back.
    mCallback.currentSearchEngineDetermined(toIndex(mSelectedSearchEnginePosition));

    notifyDataSetChanged();
}
 
Example #6
Source File: PrefServiceBridge.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #7
Source File: PrefServiceBridge.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static void addContentSettingExceptionToList(
        ArrayList<ContentSettingException> list,
        int contentSettingsType,
        String pattern,
        int contentSetting,
        String source) {
    ContentSettingException exception = new ContentSettingException(
            contentSettingsType, pattern, ContentSetting.fromInt(contentSetting), source);
    list.add(exception);
}
 
Example #8
Source File: GeolocationHeader.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the domain permission as either granted, blocked or prompt.
 * This is based upon the location permission for sharing their location with url (e.g. via the
 * geolocation infobar).
 */
@Permission
private static int getDomainPermission(String url, boolean isIncognito) {
    ContentSetting domainPermission = locationContentSettingForUrl(Uri.parse(url), isIncognito);
    switch (domainPermission) {
        case ALLOW:
            return PERMISSION_GRANTED;
        case ASK:
            return PERMISSION_PROMPT;
        default:
            return PERMISSION_BLOCKED;
    }
}
 
Example #9
Source File: GeolocationHeader.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the user has disabled sharing their location with url (e.g. via the
 * geolocation infobar).
 */
static boolean isLocationDisabledForUrl(Uri uri, boolean isIncognito) {
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) {
        boolean enabled = WebsitePreferenceBridge.shouldUseDSEGeolocationSetting(
                                  uri.toString(), isIncognito)
                && WebsitePreferenceBridge.getDSEGeolocationSetting();
        return !enabled;
    } else {
        return locationContentSettingForUrl(uri, isIncognito) == ContentSetting.BLOCK;
    }
}
 
Example #10
Source File: PageInfoPopup.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Update the permission string for the Default Search Engine.
 */
private String statusTextForDSEPermission(PageInfoPermissionEntry permission) {
    if (permission.setting == ContentSetting.ALLOW) {
        return mContext.getString(R.string.page_info_dse_permission_allowed);
    }

    return mContext.getString(R.string.page_info_dse_permission_blocked);
}
 
Example #11
Source File: PageInfoPopup.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new row for the given permission.
 *
 * @param name The title of the permission to display to the user.
 * @param type The ContentSettingsType of the permission.
 * @param currentSettingValue The ContentSetting value of the currently selected setting.
 */
@CalledByNative
private void addPermissionSection(String name, int type, int currentSettingValue) {
    // We have at least one permission, so show the lower permissions area.
    setVisibilityOfPermissionsList(true);
    mDisplayedPermissions.add(new PageInfoPermissionEntry(name, type, ContentSetting
            .fromInt(currentSettingValue)));
}
 
Example #12
Source File: PrefServiceBridge.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static void addContentSettingExceptionToList(
        ArrayList<ContentSettingException> list,
        int contentSettingsType,
        String pattern,
        int contentSetting,
        String source) {
    ContentSettingException exception = new ContentSettingException(
            contentSettingsType, pattern, ContentSetting.fromInt(contentSetting), source);
    list.add(exception);
}
 
Example #13
Source File: SearchEngineAdapter.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #14
Source File: WebsiteSettingsPopup.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new row for the given permission.
 *
 * @param name The title of the permission to display to the user.
 * @param type The ContentSettingsType of the permission.
 * @param currentSettingValue The ContentSetting value of the currently selected setting.
 */
@CalledByNative
private void addPermissionSection(String name, int type, int currentSettingValue) {
    // We have at least one permission, so show the lower permissions area.
    setVisibilityOfPermissionsList(true);
    mDisplayedPermissions.add(new PageInfoPermissionEntry(name, type, ContentSetting
            .fromInt(currentSettingValue)));
}
 
Example #15
Source File: PrefServiceBridge.java    From delion with Apache License 2.0 5 votes vote down vote up
@CalledByNative
private static void addContentSettingExceptionToList(
        ArrayList<ContentSettingException> list,
        int contentSettingsType,
        String pattern,
        int contentSetting,
        String source) {
    ContentSettingException exception = new ContentSettingException(
            contentSettingsType, pattern, ContentSetting.fromInt(contentSetting), source);
    list.add(exception);
}
 
Example #16
Source File: SearchEngineAdapter.java    From delion with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #17
Source File: WebsiteSettingsPopup.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new row for the given permission.
 *
 * @param name The title of the permission to display to the user.
 * @param type The ContentSettingsType of the permission.
 * @param currentSettingValue The ContentSetting value of the currently selected setting.
 */
@CalledByNative
private void addPermissionSection(String name, int type, int currentSettingValue) {
    // We have at least one permission, so show the lower permissions area.
    setVisibilityOfPermissionsList(true);
    mDisplayedPermissions.add(new PageInfoPermissionEntry(name, type, ContentSetting
            .fromInt(currentSettingValue)));
}
 
Example #18
Source File: PageInfoPopup.java    From 365browser with Apache License 2.0 4 votes vote down vote up
PageInfoPermissionEntry(String name, int type, ContentSetting setting) {
    this.name = name;
    this.type = type;
    this.setting = setting;
}
 
Example #19
Source File: WebsiteSettingsPopup.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
PageInfoPermissionEntry(String name, int type, ContentSetting setting) {
    this.name = name;
    this.type = type;
    this.setting = setting;
}
 
Example #20
Source File: GeolocationHeader.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the location permission for sharing their location with url (e.g. via the
 * geolocation infobar).
 */
static ContentSetting locationContentSettingForUrl(Uri uri, boolean isIncognito) {
    GeolocationInfo locationSettings = new GeolocationInfo(uri.toString(), null, isIncognito);
    ContentSetting locationPermission = locationSettings.getContentSetting();
    return locationPermission;
}
 
Example #21
Source File: WebsiteSettingsPopup.java    From delion with Apache License 2.0 4 votes vote down vote up
PageInfoPermissionEntry(String name, int type, ContentSetting setting) {
    this.name = name;
    this.type = type;
    this.setting = setting;
}