Java Code Examples for org.chromium.chrome.browser.util.UrlUtilities#nativeIsGoogleSearchUrl()

The following examples show how to use org.chromium.chrome.browser.util.UrlUtilities#nativeIsGoogleSearchUrl() . 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: HelpAndFeedback.java    From delion with Apache License 2.0 6 votes vote down vote up
/**
 * Get help context ID from URL.
 *
 * @param url The URL to be checked.
 * @param isIncognito Whether we are in incognito mode or not.
 * @return Help context ID that matches the URL and incognito mode.
 */
public static String getHelpContextIdFromUrl(Context context, String url, boolean isIncognito) {
    if (TextUtils.isEmpty(url)) {
        return context.getString(R.string.help_context_general);
    } else if (url.startsWith(UrlConstants.BOOKMARKS_URL)) {
        return context.getString(R.string.help_context_bookmarks);
    } else if (url.equals(UrlConstants.HISTORY_URL)) {
        return context.getString(R.string.help_context_history);
    // Note: For www.google.com the following function returns false.
    } else if (UrlUtilities.nativeIsGoogleSearchUrl(url)) {
        return context.getString(R.string.help_context_search_results);
    // For incognito NTP, we want to show incognito help.
    } else if (isIncognito) {
        return context.getString(R.string.help_context_incognito);
    } else if (url.equals(UrlConstants.NTP_URL)) {
        return context.getString(R.string.help_context_new_tab);
    }
    return context.getString(R.string.help_context_webpage);
}
 
Example 2
Source File: GeolocationHeader.java    From delion with Apache License 2.0 6 votes vote down vote up
private static boolean isGeoHeaderEnabledForUrl(Context context, String url,
        boolean isIncognito, boolean recordUma) {
    // Only send X-Geo in normal mode.
    if (isIncognito) return false;

    // Only send X-Geo header to Google domains.
    if (!UrlUtilities.nativeIsGoogleSearchUrl(url)) return false;

    Uri uri = Uri.parse(url);
    if (!HTTPS_SCHEME.equals(uri.getScheme())) return false;

    if (!hasGeolocationPermission(context)) {
        if (recordUma) recordHistogram(UMA_LOCATION_DISABLED_FOR_CHROME_APP);
        return false;
    }

    // Only send X-Geo header if the user hasn't disabled geolocation for url.
    if (isLocationDisabledForUrl(uri, isIncognito)) {
        if (recordUma) recordHistogram(UMA_LOCATION_DISABLED_FOR_GOOGLE_DOMAIN);
        return false;
    }

    return true;
}
 
Example 3
Source File: HelpAndFeedback.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
/**
 * Get help context ID from URL.
 *
 * @param url The URL to be checked.
 * @param isIncognito Whether we are in incognito mode or not.
 * @return Help context ID that matches the URL and incognito mode.
 */
public static String getHelpContextIdFromUrl(Context context, String url, boolean isIncognito) {
    if (TextUtils.isEmpty(url)) {
        return context.getString(R.string.help_context_general);
    } else if (url.startsWith(UrlConstants.BOOKMARKS_URL)) {
        return context.getString(R.string.help_context_bookmarks);
    } else if (url.equals(UrlConstants.HISTORY_URL)) {
        return context.getString(R.string.help_context_history);
    // Note: For www.google.com the following function returns false.
    } else if (UrlUtilities.nativeIsGoogleSearchUrl(url)) {
        return context.getString(R.string.help_context_search_results);
    // For incognito NTP, we want to show incognito help.
    } else if (isIncognito) {
        return context.getString(R.string.help_context_incognito);
    } else if (url.equals(UrlConstants.NTP_URL)) {
        return context.getString(R.string.help_context_new_tab);
    }
    return context.getString(R.string.help_context_webpage);
}
 
Example 4
Source File: GeolocationHeader.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private static boolean isGeoHeaderEnabledForUrl(Context context, String url,
        boolean isIncognito, boolean recordUma) {
    // Only send X-Geo in normal mode.
    if (isIncognito) return false;

    // Only send X-Geo header to Google domains.
    if (!UrlUtilities.nativeIsGoogleSearchUrl(url)) return false;

    Uri uri = Uri.parse(url);
    if (!HTTPS_SCHEME.equals(uri.getScheme())) return false;

    if (!hasGeolocationPermission(context)) {
        if (recordUma) recordHistogram(UMA_LOCATION_DISABLED_FOR_CHROME_APP);
        return false;
    }

    // Only send X-Geo header if the user hasn't disabled geolocation for url.
    if (isLocationDisabledForUrl(uri, isIncognito)) {
        if (recordUma) recordHistogram(UMA_LOCATION_DISABLED_FOR_GOOGLE_DOMAIN);
        return false;
    }

    return true;
}
 
Example 5
Source File: HelpAndFeedback.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Get help context ID from URL.
 *
 * @param url The URL to be checked.
 * @param isIncognito Whether we are in incognito mode or not.
 * @return Help context ID that matches the URL and incognito mode.
 */
public static String getHelpContextIdFromUrl(Context context, String url, boolean isIncognito) {
    if (TextUtils.isEmpty(url)) {
        return context.getString(R.string.help_context_general);
    } else if (url.startsWith(UrlConstants.BOOKMARKS_URL)) {
        return context.getString(R.string.help_context_bookmarks);
    } else if (url.equals(UrlConstants.HISTORY_URL)) {
        return context.getString(R.string.help_context_history);
    // Note: For www.google.com the following function returns false.
    } else if (UrlUtilities.nativeIsGoogleSearchUrl(url)) {
        return context.getString(R.string.help_context_search_results);
    // For incognito NTP, we want to show incognito help.
    } else if (isIncognito) {
        return context.getString(R.string.help_context_incognito);
    } else if (url.equals(UrlConstants.NTP_URL)) {
        return context.getString(R.string.help_context_new_tab);
    }
    return context.getString(R.string.help_context_webpage);
}
 
Example 6
Source File: GeolocationHeader.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@HeaderState
private static int geoHeaderStateForUrl(String url, boolean isIncognito, boolean recordUma) {
    // Only send X-Geo in normal mode.
    if (isIncognito) return INCOGNITO;

    // Only send X-Geo header to Google domains.
    if (!UrlUtilities.nativeIsGoogleSearchUrl(url)) return UNSUITABLE_URL;

    Uri uri = Uri.parse(url);
    if (!UrlConstants.HTTPS_SCHEME.equals(uri.getScheme())) return NOT_HTTPS;

    if (!hasGeolocationPermission()) {
        if (recordUma) recordHistogram(UMA_LOCATION_DISABLED_FOR_CHROME_APP);
        return LOCATION_PERMISSION_BLOCKED;
    }

    // Only send X-Geo header if the user hasn't disabled geolocation for url.
    if (isLocationDisabledForUrl(uri, isIncognito)) {
        if (recordUma) recordHistogram(UMA_LOCATION_DISABLED_FOR_GOOGLE_DOMAIN);
        return LOCATION_PERMISSION_BLOCKED;
    }

    return HEADER_ENABLED;
}
 
Example 7
Source File: ExternalNavigationDelegateImpl.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSerpReferrer(String referrerUrl, Tab tab) {
    if (tab == null || tab.getWebContents() == null) {
        return false;
    }

    NavigationController nController = tab.getWebContents().getNavigationController();
    int index = nController.getLastCommittedEntryIndex();
    if (index == -1) return false;

    NavigationEntry entry = nController.getEntryAtIndex(index);
    if (entry == null) return false;

    return UrlUtilities.nativeIsGoogleSearchUrl(entry.getUrl());
}
 
Example 8
Source File: ExternalNavigationDelegateImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isSerpReferrer(Tab tab) {
    // TODO (thildebr): Investigate whether or not we can use getLastCommittedUrl() instead of
    // the NavigationController.
    if (tab == null || tab.getWebContents() == null) return false;

    NavigationController nController = tab.getWebContents().getNavigationController();
    int index = nController.getLastCommittedEntryIndex();
    if (index == -1) return false;

    NavigationEntry entry = nController.getEntryAtIndex(index);
    if (entry == null) return false;

    return UrlUtilities.nativeIsGoogleSearchUrl(entry.getUrl());
}