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

The following examples show how to use org.chromium.chrome.browser.util.UrlUtilities#getDomainAndRegistry() . These examples are extracted from open source projects. 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 Project: delion   File: RoundedIconGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the text which should be used for generating a rounded icon based on |url|.
 *
 * @param url URL to consider when getting the icon's text.
 * @param includePrivateRegistries Should private registries be considered as TLDs?
 * @return The text to use on the rounded icon, or NULL if |url| is empty or the domain cannot
 *         be resolved.
 */
@Nullable
@VisibleForTesting
public static String getIconTextForUrl(String url, boolean includePrivateRegistries) {
    String domain = UrlUtilities.getDomainAndRegistry(url, includePrivateRegistries);
    if (!TextUtils.isEmpty(domain)) return domain;

    // Special-case chrome:// and chrome-native:// URLs.
    if (url.startsWith(UrlConstants.CHROME_SCHEME)
            || url.startsWith(UrlConstants.CHROME_NATIVE_SCHEME)) {
        return "chrome";
    }

    // Use the host component of |url| when it can be parsed as a URI.
    try {
        URI uri = new URI(url);
        if (!TextUtils.isEmpty(uri.getHost())) {
            return uri.getHost();
        }
    } catch (Exception e) {
        Log.w(TAG, "Unable to parse the URL for generating an icon: " + url);
    }

    return url;
}
 
Example 2
/**
 * Returns the text which should be used for generating a rounded icon based on |url|.
 *
 * @param url URL to consider when getting the icon's text.
 * @param includePrivateRegistries Should private registries be considered as TLDs?
 * @return The text to use on the rounded icon, or NULL if |url| is empty or the domain cannot
 *         be resolved.
 */
@Nullable
@VisibleForTesting
public static String getIconTextForUrl(String url, boolean includePrivateRegistries) {
    String domain = UrlUtilities.getDomainAndRegistry(url, includePrivateRegistries);
    if (!TextUtils.isEmpty(domain)) return domain;

    // Special-case chrome:// and chrome-native:// URLs.
    if (url.startsWith(UrlConstants.CHROME_SCHEME)
            || url.startsWith(UrlConstants.CHROME_NATIVE_SCHEME)) {
        return "chrome";
    }

    // Use the host component of |url| when it can be parsed as a URI.
    try {
        URI uri = new URI(url);
        if (!TextUtils.isEmpty(uri.getHost())) {
            return uri.getHost();
        }
    } catch (Exception e) {
        Log.w(TAG, "Unable to parse the URL for generating an icon: " + url);
    }

    return url;
}
 
Example 3
Source Project: 365browser   File: RoundedIconGenerator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns the text which should be used for generating a rounded icon based on |url|.
 *
 * @param url URL to consider when getting the icon's text.
 * @param includePrivateRegistries Should private registries be considered as TLDs?
 * @return The text to use on the rounded icon, or NULL if |url| is empty or the domain cannot
 *         be resolved.
 */
@Nullable
@VisibleForTesting
public static String getIconTextForUrl(String url, boolean includePrivateRegistries) {
    String domain = UrlUtilities.getDomainAndRegistry(url, includePrivateRegistries);
    if (!TextUtils.isEmpty(domain)) return domain;

    // Special-case chrome:// and chrome-native:// URLs.
    if (url.startsWith(UrlConstants.CHROME_URL_PREFIX)
            || url.startsWith(UrlConstants.CHROME_NATIVE_URL_PREFIX)) {
        return UrlConstants.CHROME_SCHEME;
    }

    // Use the host component of |url| when it can be parsed as a URI.
    try {
        URI uri = new URI(url);
        if (!TextUtils.isEmpty(uri.getHost())) {
            return uri.getHost();
        }
    } catch (Exception e) {
        Log.w(TAG, "Unable to parse the URL for generating an icon: " + url);
    }

    return url;
}
 
Example 4
private void updateTaskDescription() {
    if (mCurrentTab == null) {
        updateTaskDescription(null, null);
        return;
    }

    if (NewTabPage.isNTPUrl(mCurrentTab.getUrl()) && !mCurrentTab.isIncognito()) {
        // NTP needs a new color in recents, but uses the default application title and icon
        updateTaskDescription(null, null);
        return;
    }

    String label = mCurrentTab.getTitle();
    String domain = UrlUtilities.getDomainAndRegistry(mCurrentTab.getUrl(), false);
    if (TextUtils.isEmpty(label)) {
        label = domain;
    }
    if (mLargestFavicon == null && TextUtils.isEmpty(label)) {
        updateTaskDescription(null, null);
        return;
    }

    Bitmap bitmap = null;
    if (!mCurrentTab.isIncognito()) {
        bitmap = mIconGenerator.getBitmap(mCurrentTab.getUrl(), mLargestFavicon);
    }

    updateTaskDescription(label, bitmap);
}
 
Example 5
private void updateTaskDescription() {
    if (mCurrentTab == null) {
        updateTaskDescription(null, null);
        return;
    }

    if (NewTabPage.isNTPUrl(mCurrentTab.getUrl()) && !mCurrentTab.isIncognito()) {
        // NTP needs a new color in recents, but uses the default application title and icon
        updateTaskDescription(null, null);
        return;
    }

    String label = mCurrentTab.getTitle();
    String domain = UrlUtilities.getDomainAndRegistry(mCurrentTab.getUrl(), false);
    if (TextUtils.isEmpty(label)) {
        label = domain;
    }
    if (mLargestFavicon == null && TextUtils.isEmpty(label)) {
        updateTaskDescription(null, null);
        return;
    }

    Bitmap bitmap = null;
    if (!mCurrentTab.isIncognito()) {
        bitmap = mIconGenerator.getBitmap(mCurrentTab.getUrl(), mLargestFavicon);
    }

    updateTaskDescription(label, bitmap);
}
 
Example 6
private void updateTaskDescription() {
    if (mCurrentTab == null) {
        updateTaskDescription(null, null);
        return;
    }

    if (NewTabPage.isNTPUrl(mCurrentTab.getUrl()) && !mCurrentTab.isIncognito()) {
        // NTP needs a new color in recents, but uses the default application title and icon
        updateTaskDescription(null, null);
        return;
    }

    String label = mCurrentTab.getTitle();
    String domain = UrlUtilities.getDomainAndRegistry(mCurrentTab.getUrl(), false);
    if (TextUtils.isEmpty(label)) {
        label = domain;
    }
    if (mLargestFavicon == null && TextUtils.isEmpty(label)) {
        updateTaskDescription(null, null);
        return;
    }

    Bitmap bitmap = null;
    if (!mCurrentTab.isIncognito()) {
        bitmap = mIconGenerator.getBitmap(mCurrentTab.getUrl(), mLargestFavicon);
    }

    updateTaskDescription(label, bitmap);
}
 
Example 7
Source Project: delion   File: WebsiteAddress.java    License: Apache License 2.0 4 votes vote down vote up
private String getDomainAndRegistry() {
    if (mOrigin != null) return UrlUtilities.getDomainAndRegistry(mOrigin, false);
    // getDomainAndRegistry works better having a protocol prefix.
    return UrlUtilities.getDomainAndRegistry(HTTP_SCHEME + SCHEME_SUFFIX + mHost, false);
}
 
Example 8
Source Project: AndroidChromium   File: WebsiteAddress.java    License: Apache License 2.0 4 votes vote down vote up
private String getDomainAndRegistry() {
    if (mOrigin != null) return UrlUtilities.getDomainAndRegistry(mOrigin, false);
    // getDomainAndRegistry works better having a protocol prefix.
    return UrlUtilities.getDomainAndRegistry(HTTP_SCHEME + SCHEME_SUFFIX + mHost, false);
}
 
Example 9
Source Project: 365browser   File: WebsiteAddress.java    License: Apache License 2.0 4 votes vote down vote up
private String getDomainAndRegistry() {
    if (mOrigin != null) return UrlUtilities.getDomainAndRegistry(mOrigin, false);
    // getDomainAndRegistry works better having a protocol prefix.
    return UrlUtilities.getDomainAndRegistry(HTTP_SCHEME + SCHEME_SUFFIX + mHost, false);
}