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() . 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: RoundedIconGenerator.java    From delion with 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
Source File: RoundedIconGenerator.java    From AndroidChromium with 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 3
Source File: RoundedIconGenerator.java    From 365browser with 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
Source File: ActivityTabTaskDescriptionHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
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
Source File: ActivityTabTaskDescriptionHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
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
Source File: ActivityTabTaskDescriptionHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
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 File: WebsiteAddress.java    From delion with 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 File: WebsiteAddress.java    From AndroidChromium with 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 File: WebsiteAddress.java    From 365browser with 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);
}