Java Code Examples for org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge#nativeSetGeolocationSettingForOrigin()

The following examples show how to use org.chromium.chrome.browser.preferences.website.WebsitePreferenceBridge#nativeSetGeolocationSettingForOrigin() . 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 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 2
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 3
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 4
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();
    }
}