Java Code Examples for org.chromium.chrome.browser.ShortcutHelper#getScopeFromUrl()

The following examples show how to use org.chromium.chrome.browser.ShortcutHelper#getScopeFromUrl() . 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: WebappInfo.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
protected WebappInfo(String id, String url, String scope, String encodedIcon, String name,
        String shortName, int displayMode, int orientation, int source, long themeColor,
        long backgroundColor, boolean isIconGenerated) {
    Uri uri = Uri.parse(url);
    if (TextUtils.isEmpty(scope)) {
        scope = ShortcutHelper.getScopeFromUrl(url);
    }
    Uri scopeUri = Uri.parse(scope);

    mEncodedIcon = encodedIcon;
    mId = id;
    mName = name;
    mShortName = shortName;
    mUri = uri;
    mScopeUri = scopeUri;
    mDisplayMode = displayMode;
    mOrientation = orientation;
    mSource = source;
    mThemeColor = themeColor;
    mBackgroundColor = backgroundColor;
    mIsIconGenerated = isIconGenerated;
    mIsInitialized = mUri != null;
}
 
Example 2
Source File: WebappInfo.java    From 365browser with Apache License 2.0 6 votes vote down vote up
protected WebappInfo(String id, String url, String scope, Icon icon, String name,
        String shortName, int displayMode, int orientation, int source, long themeColor,
        long backgroundColor, boolean isIconGenerated) {
    Uri uri = Uri.parse(url);
    if (TextUtils.isEmpty(scope)) {
        scope = ShortcutHelper.getScopeFromUrl(url);
    }
    Uri scopeUri = Uri.parse(scope);

    mIcon = icon;
    mId = id;
    mName = name;
    mShortName = shortName;
    mUri = uri;
    mScopeUri = scopeUri;
    mDisplayMode = displayMode;
    mOrientation = orientation;
    mSource = source;
    mThemeColor = themeColor;
    mBackgroundColor = backgroundColor;
    mIsIconGenerated = isIconGenerated;
    mIsInitialized = mUri != null;
}
 
Example 3
Source File: ManifestUpgradeDetector.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Called when the updated Web Manifest has been fetched.
 */
@Override
public void onGotManifestData(String startUrl, String scopeUrl, String name, String shortName,
        String iconUrl, String iconMurmur2Hash, Bitmap iconBitmap, int displayMode,
        int orientation, long themeColor, long backgroundColor) {
    mFetcher.destroy();
    mFetcher = null;

    if (TextUtils.isEmpty(scopeUrl)) {
        scopeUrl = ShortcutHelper.getScopeFromUrl(startUrl);
    }

    FetchedManifestData fetchedData = new FetchedManifestData();
    fetchedData.startUrl = startUrl;
    fetchedData.scopeUrl = scopeUrl;
    fetchedData.name = name;
    fetchedData.shortName = shortName;
    fetchedData.iconUrl = iconUrl;
    fetchedData.iconMurmur2Hash = iconMurmur2Hash;
    fetchedData.icon = iconBitmap;
    fetchedData.displayMode = displayMode;
    fetchedData.orientation = orientation;
    fetchedData.themeColor = themeColor;
    fetchedData.backgroundColor = backgroundColor;

    // TODO(hanxi): crbug.com/627824. Validate whether the new fetched data is
    // WebAPK-compatible.
    boolean upgrade = needsUpgrade(fetchedData);
    mCallback.onGotManifestData(upgrade, fetchedData);
}
 
Example 4
Source File: WebappDataStorage.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the data stored in this object to match that in the supplied intent.
 * @param shortcutIntent The intent to pull web app data from.
 */
public void updateFromShortcutIntent(Intent shortcutIntent) {
    if (shortcutIntent == null) return;

    SharedPreferences.Editor editor = mPreferences.edit();
    boolean updated = false;

    // The URL and scope may have been deleted by the user clearing their history. Check whether
    // they are present, and update if necessary.
    String url = mPreferences.getString(KEY_URL, URL_INVALID);
    if (url.equals(URL_INVALID)) {
        url = IntentUtils.safeGetStringExtra(shortcutIntent, ShortcutHelper.EXTRA_URL);
        editor.putString(KEY_URL, url);
        updated = true;
    }

    if (mPreferences.getString(KEY_SCOPE, URL_INVALID).equals(URL_INVALID)) {
        String scope = IntentUtils.safeGetStringExtra(
                shortcutIntent, ShortcutHelper.EXTRA_SCOPE);
        if (scope == null) {
            scope = ShortcutHelper.getScopeFromUrl(url);
        }
        editor.putString(KEY_SCOPE, scope);
        updated = true;
    }

    // For all other fields, assume that if the version key is present and equal to
    // ShortcutHelper.WEBAPP_SHORTCUT_VERSION, then all fields are present and do not need to be
    // updated. All fields except for the last used time, scope, and URL are either set or
    // cleared together.
    if (mPreferences.getInt(KEY_VERSION, VERSION_INVALID)
            != ShortcutHelper.WEBAPP_SHORTCUT_VERSION) {
        editor.putString(KEY_NAME, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_NAME));
        editor.putString(KEY_SHORT_NAME, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_SHORT_NAME));
        editor.putString(KEY_ICON, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_ICON));
        editor.putInt(KEY_VERSION, ShortcutHelper.WEBAPP_SHORTCUT_VERSION);

        // "Standalone" was the original assumed default for all web apps.
        editor.putInt(KEY_DISPLAY_MODE, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_DISPLAY_MODE,
                    WebDisplayMode.Standalone));
        editor.putInt(KEY_ORIENTATION, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_ORIENTATION,
                    ScreenOrientationValues.DEFAULT));
        editor.putLong(KEY_THEME_COLOR, IntentUtils.safeGetLongExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_THEME_COLOR,
                    ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING));
        editor.putLong(KEY_BACKGROUND_COLOR, IntentUtils.safeGetLongExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_BACKGROUND_COLOR,
                    ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING));
        editor.putBoolean(KEY_IS_ICON_GENERATED, IntentUtils.safeGetBooleanExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_IS_ICON_GENERATED, false));
        editor.putString(KEY_ACTION, shortcutIntent.getAction());
        editor.putInt(KEY_SOURCE, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_SOURCE,
                    ShortcutSource.UNKNOWN));
        updated = true;
    }
    if (updated) editor.apply();
}
 
Example 5
Source File: WebappDataStorage.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the data stored in this object to match that in the supplied intent.
 * @param shortcutIntent The intent to pull web app data from.
 */
public void updateFromShortcutIntent(Intent shortcutIntent) {
    if (shortcutIntent == null) return;

    SharedPreferences.Editor editor = mPreferences.edit();
    boolean updated = false;

    // The URL and scope may have been deleted by the user clearing their history. Check whether
    // they are present, and update if necessary.
    String url = mPreferences.getString(KEY_URL, URL_INVALID);
    if (url.equals(URL_INVALID)) {
        url = IntentUtils.safeGetStringExtra(shortcutIntent, ShortcutHelper.EXTRA_URL);
        editor.putString(KEY_URL, url);
        updated = true;
    }

    if (mPreferences.getString(KEY_SCOPE, URL_INVALID).equals(URL_INVALID)) {
        String scope = IntentUtils.safeGetStringExtra(
                shortcutIntent, ShortcutHelper.EXTRA_SCOPE);
        if (scope == null) {
            scope = ShortcutHelper.getScopeFromUrl(url);
        }
        editor.putString(KEY_SCOPE, scope);
        updated = true;
    }

    // For all other fields, assume that if the version key is present and equal to
    // ShortcutHelper.WEBAPP_SHORTCUT_VERSION, then all fields are present and do not need to be
    // updated. All fields except for the last used time, scope, and URL are either set or
    // cleared together.
    if (mPreferences.getInt(KEY_VERSION, VERSION_INVALID)
            != ShortcutHelper.WEBAPP_SHORTCUT_VERSION) {
        editor.putString(KEY_NAME, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_NAME));
        editor.putString(KEY_SHORT_NAME, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_SHORT_NAME));
        editor.putString(KEY_ICON, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_ICON));
        editor.putInt(KEY_VERSION, ShortcutHelper.WEBAPP_SHORTCUT_VERSION);

        // "Standalone" was the original assumed default for all web apps.
        editor.putInt(KEY_DISPLAY_MODE, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_DISPLAY_MODE,
                    WebDisplayMode.Standalone));
        editor.putInt(KEY_ORIENTATION, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_ORIENTATION,
                    ScreenOrientationValues.DEFAULT));
        editor.putLong(KEY_THEME_COLOR, IntentUtils.safeGetLongExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_THEME_COLOR,
                    ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING));
        editor.putLong(KEY_BACKGROUND_COLOR, IntentUtils.safeGetLongExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_BACKGROUND_COLOR,
                    ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING));
        editor.putBoolean(KEY_IS_ICON_GENERATED, IntentUtils.safeGetBooleanExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_IS_ICON_GENERATED, false));
        editor.putString(KEY_ACTION, shortcutIntent.getAction());
        editor.putInt(KEY_SOURCE, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_SOURCE,
                    ShortcutSource.UNKNOWN));
        editor.putString(KEY_WEBAPK_PACKAGE_NAME, IntentUtils.safeGetStringExtra(
                shortcutIntent, ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME));
        updated = true;
    }
    if (updated) editor.apply();
}
 
Example 6
Source File: WebappDataStorage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the data stored in this object to match that in the supplied intent.
 * @param shortcutIntent The intent to pull web app data from.
 */
public void updateFromShortcutIntent(Intent shortcutIntent) {
    if (shortcutIntent == null) return;

    SharedPreferences.Editor editor = mPreferences.edit();
    boolean updated = false;

    // The URL and scope may have been deleted by the user clearing their history. Check whether
    // they are present, and update if necessary.
    String url = mPreferences.getString(KEY_URL, URL_INVALID);
    if (url.equals(URL_INVALID)) {
        url = IntentUtils.safeGetStringExtra(shortcutIntent, ShortcutHelper.EXTRA_URL);
        editor.putString(KEY_URL, url);
        updated = true;
    }

    if (mPreferences.getString(KEY_SCOPE, URL_INVALID).equals(URL_INVALID)) {
        String scope = IntentUtils.safeGetStringExtra(
                shortcutIntent, ShortcutHelper.EXTRA_SCOPE);
        if (scope == null) {
            scope = ShortcutHelper.getScopeFromUrl(url);
        }
        editor.putString(KEY_SCOPE, scope);
        updated = true;
    }

    // For all other fields, assume that if the version key is present and equal to
    // ShortcutHelper.WEBAPP_SHORTCUT_VERSION, then all fields are present and do not need to be
    // updated. All fields except for the last used time, scope, and URL are either set or
    // cleared together.
    if (mPreferences.getInt(KEY_VERSION, VERSION_INVALID)
            != ShortcutHelper.WEBAPP_SHORTCUT_VERSION) {
        editor.putString(KEY_NAME, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_NAME));
        editor.putString(KEY_SHORT_NAME, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_SHORT_NAME));
        editor.putString(KEY_ICON, IntentUtils.safeGetStringExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_ICON));
        editor.putInt(KEY_VERSION, ShortcutHelper.WEBAPP_SHORTCUT_VERSION);

        // "Standalone" was the original assumed default for all web apps.
        editor.putInt(KEY_DISPLAY_MODE,
                IntentUtils.safeGetIntExtra(shortcutIntent, ShortcutHelper.EXTRA_DISPLAY_MODE,
                        WebDisplayMode.STANDALONE));
        editor.putInt(KEY_ORIENTATION, IntentUtils.safeGetIntExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_ORIENTATION,
                    ScreenOrientationValues.DEFAULT));
        editor.putLong(KEY_THEME_COLOR, IntentUtils.safeGetLongExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_THEME_COLOR,
                    ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING));
        editor.putLong(KEY_BACKGROUND_COLOR, IntentUtils.safeGetLongExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_BACKGROUND_COLOR,
                    ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING));
        editor.putBoolean(KEY_IS_ICON_GENERATED, IntentUtils.safeGetBooleanExtra(
                    shortcutIntent, ShortcutHelper.EXTRA_IS_ICON_GENERATED, false));
        editor.putString(KEY_ACTION, shortcutIntent.getAction());

        String webApkPackageName = IntentUtils.safeGetStringExtra(
                shortcutIntent, WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME);
        editor.putString(KEY_WEBAPK_PACKAGE_NAME, webApkPackageName);

        if (TextUtils.isEmpty(webApkPackageName)) {
            editor.putInt(KEY_SOURCE,
                    IntentUtils.safeGetIntExtra(shortcutIntent, ShortcutHelper.EXTRA_SOURCE,
                            ShortcutSource.UNKNOWN));
        }
        updated = true;
    }
    if (updated) editor.apply();
}
 
Example 7
Source File: WebApkInfo.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Construct a {@link WebApkInfo} instance.
 *
 * @param id                      ID for the WebAPK.
 * @param url                     URL that the WebAPK should navigate to when launched.
 * @param forceNavigation         Whether the WebAPK should navigate to {@link url} if the
 *                                WebAPK is already open.
 * @param scope                   Scope for the WebAPK.
 * @param icon                    Icon to show for the WebAPK.
 * @param name                    Name of the WebAPK.
 * @param shortName               The short name of the WebAPK.
 * @param displayMode             Display mode of the WebAPK.
 * @param orientation             Orientation of the WebAPK.
 * @param source                  Source that the WebAPK was launched from.
 * @param themeColor              The theme color of the WebAPK.
 * @param backgroundColor         The background color of the WebAPK.
 * @param webApkPackageName       The package of the WebAPK.
 * @param shellApkVersion         Version of the code in //chrome/android/webapk/shell_apk.
 * @param manifestUrl             URL of the Web Manifest.
 * @param manifestStartUrl        URL that the WebAPK should navigate to when launched from the
 *                                homescreen. Different from the {@link url} parameter if the
 *                                WebAPK is launched from a deep link.
 * @param iconUrlToMurmur2HashMap Map of the WebAPK's icon URLs to Murmur2 hashes of the
 *                                icon untransformed bytes.
 */
public static WebApkInfo create(String id, String url, boolean forceNavigation, String scope,
        Icon icon, String name, String shortName, int displayMode, int orientation, int source,
        long themeColor, long backgroundColor, String webApkPackageName, int shellApkVersion,
        String manifestUrl, String manifestStartUrl,
        Map<String, String> iconUrlToMurmur2HashMap) {
    if (id == null || url == null || manifestStartUrl == null || webApkPackageName == null) {
        Log.e(TAG,
                "Incomplete data provided: " + id + ", " + url + ", " + manifestStartUrl + ", "
                        + webApkPackageName);
        return null;
    }

    // The default scope should be computed from the Web Manifest start URL. If the WebAPK was
    // launched from a deep link {@link startUrl} may be different from the Web Manifest start
    // URL.
    if (TextUtils.isEmpty(scope)) {
        scope = ShortcutHelper.getScopeFromUrl(manifestStartUrl);
    }

    return new WebApkInfo(id, url, forceNavigation, scope, icon, name, shortName, displayMode,
            orientation, source, themeColor, backgroundColor, webApkPackageName,
            shellApkVersion, manifestUrl, manifestStartUrl, iconUrlToMurmur2HashMap);
}