org.chromium.chrome.browser.omnibox.geo.GeolocationHeader Java Examples

The following examples show how to use org.chromium.chrome.browser.omnibox.geo.GeolocationHeader. 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: ChromeActionModeCallback.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void search() {
    RecordUserAction.record("MobileActionMode.WebSearch");
    if (mTab.getTabModelSelector() == null) return;

    String query = mHelper.sanitizeQuery(mHelper.getSelectedText(),
            ActionModeCallbackHelper.MAX_SEARCH_QUERY_LENGTH);
    if (TextUtils.isEmpty(query)) return;

    String url = TemplateUrlService.getInstance().getUrlForSearchQuery(query);
    String headers = GeolocationHeader.getGeoHeader(mContext.getApplicationContext(),
            url, mTab.isIncognito());

    LoadUrlParams loadUrlParams = new LoadUrlParams(url);
    loadUrlParams.setVerbatimHeaders(headers);
    loadUrlParams.setTransitionType(PageTransition.GENERATED);
    mTab.getTabModelSelector().openNewTab(loadUrlParams,
            TabLaunchType.FROM_LONGPRESS_FOREGROUND, mTab, mTab.isIncognito());
}
 
Example #2
Source File: ChromeActionModeCallback.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void search() {
    RecordUserAction.record("MobileActionMode.WebSearch");
    if (mTab.getTabModelSelector() == null) return;

    String query = ActionModeCallbackHelper.sanitizeQuery(mHelper.getSelectedText(),
            ActionModeCallbackHelper.MAX_SEARCH_QUERY_LENGTH);
    if (TextUtils.isEmpty(query)) return;

    String url = TemplateUrlService.getInstance().getUrlForSearchQuery(query);
    String headers = GeolocationHeader.getGeoHeader(url, mTab);

    LoadUrlParams loadUrlParams = new LoadUrlParams(url);
    loadUrlParams.setVerbatimHeaders(headers);
    loadUrlParams.setTransitionType(PageTransition.GENERATED);
    mTab.getTabModelSelector().openNewTab(loadUrlParams,
            TabLaunchType.FROM_LONGPRESS_FOREGROUND, mTab, mTab.isIncognito());
}
 
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: 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 #5
Source File: Tab.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void performWebSearch(String searchQuery) {
    if (TextUtils.isEmpty(searchQuery)) return;
    if (getTabModelSelector() == null) return;
    String url = TemplateUrlService.getInstance().getUrlForSearchQuery(searchQuery);
    String headers = GeolocationHeader.getGeoHeader(getApplicationContext(), url,
            isIncognito());

    LoadUrlParams loadUrlParams = new LoadUrlParams(url);
    loadUrlParams.setVerbatimHeaders(headers);
    loadUrlParams.setTransitionType(PageTransition.GENERATED);
    getTabModelSelector().openNewTab(loadUrlParams,
            TabLaunchType.FROM_LONGPRESS_FOREGROUND, Tab.this, isIncognito());
}
 
Example #6
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 #7
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 #8
Source File: SingleWebsitePreferences.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the current host matches the default search engine host and location for the
 * default search engine is being granted via x-geo.
 * @param context The current context.
 */
private boolean hasXGeoLocationPermission(Context context) {
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.CONSISTENT_OMNIBOX_GEOLOCATION)) {
        return false;
    }

    String searchUrl = TemplateUrlService.getInstance().getUrlForSearchQuery("foo");
    return mSite.getAddress().matches(searchUrl)
            && GeolocationHeader.isGeoHeaderEnabledForUrl(searchUrl, false);
}
 
Example #9
Source File: SingleWebsitePreferences.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if the current host matches the default search engine host and location for the
 * default search engine is being granted via x-geo.
 * @param context The current context.
 */
private boolean hasXGeoLocationPermission(Context context) {
    String searchUrl = TemplateUrlService.getInstance().getUrlForSearchQuery("foo");
    return mSite.getAddress().matches(searchUrl)
            && GeolocationHeader.isGeoHeaderEnabledForUrl(context, searchUrl, false);
}
 
Example #10
Source File: SingleWebsitePreferences.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if the current host matches the default search engine host and location for the
 * default search engine is being granted via x-geo.
 * @param context The current context.
 */
private boolean hasXGeoLocationPermission(Context context) {
    String searchUrl = TemplateUrlService.getInstance().getUrlForSearchQuery("foo");
    return mSite.getAddress().matches(searchUrl)
            && GeolocationHeader.isGeoHeaderEnabledForUrl(context, searchUrl, false);
}