org.chromium.chrome.browser.ShortcutSource Java Examples

The following examples show how to use org.chromium.chrome.browser.ShortcutSource. 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 delion with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a WebappInfo.
 * @param intent Intent containing info about the app.
 */
public static WebappInfo create(Intent intent) {
    String id = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_ID);
    String icon = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_ICON);
    String url = IntentUtils.safeGetStringExtra(intent, ShortcutHelper.EXTRA_URL);
    int displayMode = displayModeFromIntent(intent);
    int orientation = orientationFromIntent(intent);
    int source = IntentUtils.safeGetIntExtra(intent,
            ShortcutHelper.EXTRA_SOURCE, ShortcutSource.UNKNOWN);
    long themeColor = IntentUtils.safeGetLongExtra(intent,
            ShortcutHelper.EXTRA_THEME_COLOR,
            ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING);
    long backgroundColor = IntentUtils.safeGetLongExtra(intent,
            ShortcutHelper.EXTRA_BACKGROUND_COLOR,
            ShortcutHelper.MANIFEST_COLOR_INVALID_OR_MISSING);
    boolean isIconGenerated = IntentUtils.safeGetBooleanExtra(intent,
            ShortcutHelper.EXTRA_IS_ICON_GENERATED, false);

    String name = nameFromIntent(intent);
    String shortName = shortNameFromIntent(intent);
    String webApkPackageName = IntentUtils.safeGetStringExtra(intent,
            ShortcutHelper.EXTRA_WEBAPK_PACKAGE_NAME);

    return create(id, url, icon, name, shortName, displayMode, orientation, source,
            themeColor, backgroundColor, isIconGenerated, webApkPackageName);
}
 
Example #2
Source File: WebappLauncherActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private int getWebApkSource(WebappInfo webappInfo) {
    WebappDataStorage storage = null;

    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        WebappRegistry.warmUpSharedPrefsForId(webappInfo.id());
        storage = WebappRegistry.getInstance().getWebappDataStorage(webappInfo.id());
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }

    if (storage != null) {
        int source = storage.getSource();
        if (source != ShortcutSource.UNKNOWN) {
            return source;
        }
    }
    return ShortcutSource.WEBAPK_UNKNOWN;
}
 
Example #3
Source File: BookmarkWidgetProxy.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (BookmarkWidgetService.getChangeFolderAction(context)
            .equals(intent.getAction())) {
        BookmarkWidgetService.changeFolder(context, intent);
    } else {
        Intent view = new Intent(intent);
        view.setClass(context, ChromeLauncherActivity.class);
        view.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.BOOKMARK_NAVIGATOR_WIDGET);
        view.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
        startActivity(context, view);
    }
}
 
Example #4
Source File: BookmarkWidgetProxy.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (BookmarkWidgetService.getChangeFolderAction(context)
            .equals(intent.getAction())) {
        BookmarkWidgetService.changeFolder(context, intent);
    } else {
        Intent view = new Intent(intent);
        view.setClass(context, ChromeLauncherActivity.class);
        view.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.BOOKMARK_NAVIGATOR_WIDGET);
        view.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
        startActivity(context, view);
    }
}
 
Example #5
Source File: BookmarkWidgetProxy.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (BookmarkWidgetService.getChangeFolderAction(context)
            .equals(intent.getAction())) {
        BookmarkWidgetService.changeFolder(context, intent);
    } else {
        Intent view = new Intent(intent);
        view.setClass(context, ChromeLauncherActivity.class);
        view.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.BOOKMARK_NAVIGATOR_WIDGET);
        view.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
        startActivity(context, view);
    }
}
 
Example #6
Source File: WebappInfo.java    From 365browser with Apache License 2.0 5 votes vote down vote up
protected static int sourceFromIntent(Intent intent) {
    int source = IntentUtils.safeGetIntExtra(
            intent, ShortcutHelper.EXTRA_SOURCE, ShortcutSource.UNKNOWN);
    if (source >= ShortcutSource.COUNT) {
        source = ShortcutSource.UNKNOWN;
    }
    return source;
}
 
Example #7
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 #8
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 #9
Source File: WebappLauncherActivity.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an Intent to launch the web app.
 * @param info     Information about the web app.
 * @param isWebApk If true, launch the app as a WebApkActivity.  If false, launch the app as
 *                 a WebappActivity.
 */
private Intent createWebappLaunchIntent(WebappInfo info, int source, boolean isWebApk) {
    String activityName = isWebApk ? WebApkActivity.class.getName()
            : WebappActivity.class.getName();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        // Specifically assign the app to a particular WebappActivity instance.
        int namespace = isWebApk
                ? ActivityAssigner.WEBAPK_NAMESPACE : ActivityAssigner.WEBAPP_NAMESPACE;
        int activityIndex = ActivityAssigner.instance(namespace).assign(info.id());
        activityName += String.valueOf(activityIndex);
    }

    // Create an intent to launch the Webapp in an unmapped WebappActivity.
    Intent launchIntent = new Intent();
    launchIntent.setClassName(this, activityName);
    info.setWebappIntentExtras(launchIntent);

    // On L+, firing intents with the exact same data should relaunch a particular
    // Activity.
    launchIntent.setAction(Intent.ACTION_VIEW);
    launchIntent.setData(Uri.parse(WebappActivity.WEBAPP_SCHEME + "://" + info.id()));

    if (!isWebApk) {
        // For WebAPK, we don't start a new task for WebApkActivity, it is just on top
        // of the WebAPK's main activity and in the same task.
        launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | ApiCompatibilityUtils.getActivityNewDocumentFlag());

        // If this is launching from a notification, we want to ensure that the URL being
        // launched is the URL in the intent. If a paused WebappActivity exists for this id,
        // then by default it will be focused and we have no way of sending the desired URL to
        // it (the intent is swallowed). As a workaround, set the CLEAR_TOP flag to ensure that
        // the existing Activity is cleared and relaunched with this intent.
        // TODO(dominickn): ideally, we want be able to route an intent to
        // WebappActivity.onNewIntent instead of restarting the Activity.
        if (source == ShortcutSource.NOTIFICATION) {
            launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }
    }
    return launchIntent;
}
 
Example #10
Source File: WebappInfo.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
protected static int sourceFromIntent(Intent intent) {
    return IntentUtils.safeGetIntExtra(
            intent, ShortcutHelper.EXTRA_SOURCE, ShortcutSource.UNKNOWN);
}
 
Example #11
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 #12
Source File: WebappDataStorage.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/** Returns the source stored in this object, or ShortcutSource.UNKNOWN if it is not stored. */
public int getSource() {
    return mPreferences.getInt(KEY_SOURCE, ShortcutSource.UNKNOWN);
}
 
Example #13
Source File: WebappLauncherActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Creates an Intent to launch the web app.
 * @param info     Information about the web app.
 * @param isWebApk If true, launch the app as a WebApkActivity.  If false, launch the app as
 *                 a WebappActivity.
 */
private Intent createWebappLaunchIntent(WebappInfo info, int source, boolean isWebApk) {
    String activityName = isWebApk ? WebApkActivity.class.getName()
            : WebappActivity.class.getName();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        // Specifically assign the app to a particular WebappActivity instance.
        int namespace = isWebApk
                ? ActivityAssigner.WEBAPK_NAMESPACE : ActivityAssigner.WEBAPP_NAMESPACE;
        int activityIndex = ActivityAssigner.instance(namespace).assign(info.id());
        activityName += String.valueOf(activityIndex);

        // Finishes the old activity if it has been assigned to a different WebappActivity. See
        // crbug.com/702998.
        for (WeakReference<Activity> activityRef : ApplicationStatus.getRunningActivities()) {
            Activity activity = activityRef.get();
            if (!(activity instanceof WebappActivity)
                    || !activity.getClass().getName().equals(activityName)) {
                continue;
            }
            WebappActivity webappActivity = (WebappActivity) activity;
            if (!TextUtils.equals(webappActivity.mWebappInfo.id(), info.id())) {
                activity.finish();
            }
            break;
        }
    }

    // Create an intent to launch the Webapp in an unmapped WebappActivity.
    Intent launchIntent = new Intent();
    launchIntent.setClassName(this, activityName);
    info.setWebappIntentExtras(launchIntent);

    // On L+, firing intents with the exact same data should relaunch a particular
    // Activity.
    launchIntent.setAction(Intent.ACTION_VIEW);
    launchIntent.setData(Uri.parse(WebappActivity.WEBAPP_SCHEME + "://" + info.id()));
    launchIntent.setFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK | ApiCompatibilityUtils.getActivityNewDocumentFlag());

    if (!isWebApk) {
        // If this is launching from a notification, we want to ensure that the URL being
        // launched is the URL in the intent. If a paused WebappActivity exists for this id,
        // then by default it will be focused and we have no way of sending the desired URL to
        // it (the intent is swallowed). As a workaround, set the CLEAR_TOP flag to ensure that
        // the existing Activity is cleared and relaunched with this intent.
        // TODO(dominickn): ideally, we want be able to route an intent to
        // WebappActivity.onNewIntent instead of restarting the Activity.
        if (source == ShortcutSource.NOTIFICATION) {
            launchIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }
    }
    return launchIntent;
}
 
Example #14
Source File: WebappInfo.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if the WebappInfo was created for an Intent fired from a launcher shortcut (as
 * opposed to an intent from a push notification or other internal source).
 */
public boolean isLaunchedFromHomescreen() {
    int source = source();
    return source != ShortcutSource.NOTIFICATION && source != ShortcutSource.EXTERNAL_INTENT;
}
 
Example #15
Source File: WebappInfo.java    From delion with Apache License 2.0 2 votes vote down vote up
/**
 * Returns true if the WebappInfo was created for an Intent fired from a launcher shortcut (as
 * opposed to an intent from a push notification or other internal source).
 */
public boolean isLaunchedFromHomescreen() {
    return source() != ShortcutSource.NOTIFICATION;
}
 
Example #16
Source File: WebappInfo.java    From AndroidChromium with Apache License 2.0 2 votes vote down vote up
/**
 * Returns true if the WebappInfo was created for an Intent fired from a launcher shortcut (as
 * opposed to an intent from a push notification or other internal source).
 */
public boolean isLaunchedFromHomescreen() {
    return source() != ShortcutSource.NOTIFICATION;
}