Java Code Examples for org.chromium.chrome.browser.util.IntentUtils#safeHasExtra()

The following examples show how to use org.chromium.chrome.browser.util.IntentUtils#safeHasExtra() . 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: ShareActivity.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        Intent intent = getIntent();
        if (intent == null) return;
        if (!Intent.ACTION_SEND.equals(intent.getAction())) return;
        if (!IntentUtils.safeHasExtra(intent, ShareHelper.EXTRA_TASK_ID)) return;

        ChromeActivity triggeringActivity = getTriggeringActivity();
        if (triggeringActivity == null) return;

        handleShareAction(triggeringActivity);
    } finally {
        finish();
    }
}
 
Example 2
Source File: PrintShareActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try {
        Intent intent = getIntent();
        if (intent == null) return;
        if (!Intent.ACTION_SEND.equals(intent.getAction())) return;
        if (!IntentUtils.safeHasExtra(getIntent(), ShareHelper.EXTRA_TASK_ID)) return;
        handlePrintAction();
    } finally {
        finish();
    }
}
 
Example 3
Source File: ChromeLauncherActivity.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether or not an Herb prototype may hijack an Intent.
 */
public static boolean canBeHijackedByHerb(Intent intent) {
    String url = IntentHandler.getUrlFromIntent(intent);

    // Only VIEW Intents with URLs are rerouted to Custom Tabs.
    if (intent == null || !TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())
            || TextUtils.isEmpty(url)) {
        return false;
    }

    // Don't open explicitly opted out intents in custom tabs.
    if (CustomTabsIntent.shouldAlwaysUseBrowserUI(intent)) {
        return false;
    }

    // Don't reroute Chrome Intents.
    Context context = ContextUtils.getApplicationContext();
    if (TextUtils.equals(context.getPackageName(),
            IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION_ID))
            || IntentHandler.wasIntentSenderChrome(intent, context)) {
        return false;
    }

    // Don't reroute internal chrome URLs.
    try {
        URI uri = URI.create(url);
        if (UrlUtilities.isInternalScheme(uri)) return false;
    } catch (IllegalArgumentException e) {
        return false;
    }

    // Don't reroute Home screen shortcuts.
    if (IntentUtils.safeHasExtra(intent, ShortcutHelper.EXTRA_SOURCE)) {
        return false;
    }

    return true;
}
 
Example 4
Source File: ChromeLauncherActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether or not an Herb prototype may hijack an Intent.
 */
public static boolean canBeHijackedByHerb(Intent intent) {
    String url = IntentHandler.getUrlFromIntent(intent);

    // Only VIEW Intents with URLs are rerouted to Custom Tabs.
    if (intent == null || !TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())
            || TextUtils.isEmpty(url)) {
        return false;
    }

    // Don't open explicitly opted out intents in custom tabs.
    if (CustomTabsIntent.shouldAlwaysUseBrowserUI(intent)) {
        return false;
    }

    // Don't reroute Chrome Intents.
    Context context = ContextUtils.getApplicationContext();
    if (TextUtils.equals(context.getPackageName(),
            IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION_ID))
            || IntentHandler.wasIntentSenderChrome(intent)) {
        return false;
    }

    // Don't reroute internal chrome URLs.
    try {
        URI uri = URI.create(url);
        if (UrlUtilities.isInternalScheme(uri)) return false;
    } catch (IllegalArgumentException e) {
        return false;
    }

    // Don't reroute Home screen shortcuts.
    if (IntentUtils.safeHasExtra(intent, ShortcutHelper.EXTRA_SOURCE)) {
        return false;
    }

    return true;
}
 
Example 5
Source File: InstantAppsHandler.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private boolean handleIncomingIntentInternal(
        Context context, Intent intent, boolean isCustomTabsIntent, long startTime) {
    boolean isEnabled = isEnabled(context);
    if (!isEnabled || (isCustomTabsIntent && !IntentUtils.safeGetBooleanExtra(
            intent, CUSTOM_APPS_INSTANT_APP_EXTRA, false))) {
        Log.i(TAG, "Not handling with Instant Apps. Enabled? " + isEnabled);
        return false;
    }

    if (IntentUtils.safeGetBooleanExtra(intent, DO_NOT_LAUNCH_EXTRA, false)) {
        maybeRecordFallbackStats(intent);
        Log.i(TAG, "Not handling with Instant Apps (DO_NOT_LAUNCH_EXTRA)");
        return false;
    }

    if (IntentUtils.safeGetBooleanExtra(
            intent, IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false)
            || IntentUtils.safeHasExtra(intent, ShortcutHelper.EXTRA_SOURCE)
            || isIntentFromChrome(context, intent)
            || (IntentHandler.getUrlFromIntent(intent) == null)) {
        Log.i(TAG, "Not handling with Instant Apps (other)");
        return false;
    }

    // Used to search for the intent handlers. Needs null component to return correct results.
    Intent intentCopy = new Intent(intent);
    intentCopy.setComponent(null);
    Intent selector = intentCopy.getSelector();
    if (selector != null) selector.setComponent(null);

    if (!(isCustomTabsIntent || isChromeDefaultHandler(context))
            || ExternalNavigationDelegateImpl.isPackageSpecializedHandler(
                    context, null, intentCopy)) {
        // Chrome is not the default browser or a specialized handler exists.
        Log.i(TAG, "Not handling with Instant Apps because Chrome is not default or "
                + "there's a specialized handler");
        return false;
    }

    Intent callbackIntent = new Intent(intent);
    callbackIntent.putExtra(DO_NOT_LAUNCH_EXTRA, true);
    callbackIntent.putExtra(INSTANT_APP_START_TIME_EXTRA, startTime);

    return tryLaunchingInstantApp(context, intent, isCustomTabsIntent, callbackIntent);
}
 
Example 6
Source File: MultiWindowUtils.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Determines the correct ChromeTabbedActivity class to use for an incoming intent.
 * @param intent The incoming intent that is starting ChromeTabbedActivity.
 * @param context The current Context, used to retrieve the ActivityManager system service.
 * @return The ChromeTabbedActivity to use for the incoming intent.
 */
public Class<? extends ChromeTabbedActivity> getTabbedActivityForIntent(
        @Nullable Intent intent, Context context) {
    // 1. Exit early if the build version doesn't support Android N+ multi-window mode or
    // ChromeTabbedActivity2 isn't running.
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M
            || (mTabbedActivity2TaskRunning != null && !mTabbedActivity2TaskRunning)) {
        return ChromeTabbedActivity.class;
    }

    // 2. If the intent has a window id set, use that.
    if (intent != null && IntentUtils.safeHasExtra(intent, IntentHandler.EXTRA_WINDOW_ID)) {
        int windowId = IntentUtils.safeGetIntExtra(intent, IntentHandler.EXTRA_WINDOW_ID, 0);
        if (windowId == 1) return ChromeTabbedActivity.class;
        if (windowId == 2) return ChromeTabbedActivity2.class;
    }

    // 3. If only one ChromeTabbedActivity is currently in Android recents, use it.
    boolean tabbed2TaskRunning = isActivityTaskInRecents(
            ChromeTabbedActivity2.class.getName(), context);

    // Exit early if ChromeTabbedActivity2 isn't running.
    if (!tabbed2TaskRunning) {
        mTabbedActivity2TaskRunning = false;
        return ChromeTabbedActivity.class;
    }

    boolean tabbedTaskRunning = isActivityTaskInRecents(
            ChromeTabbedActivity.class.getName(), context);
    if (!tabbedTaskRunning) {
        return ChromeTabbedActivity2.class;
    }

    // 4. If only one of the ChromeTabbedActivity's is currently visible use it.
    // e.g. ChromeTabbedActivity is docked to the top of the screen and another app is docked
    // to the bottom.

    // Find the activities.
    Activity tabbedActivity = null;
    Activity tabbedActivity2 = null;
    for (WeakReference<Activity> reference : ApplicationStatus.getRunningActivities()) {
        Activity activity = reference.get();
        if (activity == null) continue;
        if (activity.getClass().equals(ChromeTabbedActivity.class)) {
            tabbedActivity = activity;
        } else if (activity.getClass().equals(ChromeTabbedActivity2.class)) {
            tabbedActivity2 = activity;
        }
    }

    // Determine if only one is visible.
    boolean tabbedActivityVisible = isActivityVisible(tabbedActivity);
    boolean tabbedActivity2Visible = isActivityVisible(tabbedActivity2);
    if (tabbedActivityVisible ^ tabbedActivity2Visible) {
        if (tabbedActivityVisible) return ChromeTabbedActivity.class;
        return ChromeTabbedActivity2.class;
    }

    // 5. Use the ChromeTabbedActivity that was resumed most recently if it's still running.
    if (mLastResumedTabbedActivity != null) {
        ChromeTabbedActivity lastResumedActivity = mLastResumedTabbedActivity.get();
        if (lastResumedActivity != null) {
            Class<?> lastResumedClassName = lastResumedActivity.getClass();
            if (tabbedTaskRunning
                    && lastResumedClassName.equals(ChromeTabbedActivity.class)) {
                return ChromeTabbedActivity.class;
            }
            if (tabbed2TaskRunning
                    && lastResumedClassName.equals(ChromeTabbedActivity2.class)) {
                return ChromeTabbedActivity2.class;
            }
        }
    }

    // 6. Default to regular ChromeTabbedActivity.
    return ChromeTabbedActivity.class;
}
 
Example 7
Source File: InstantAppsHandler.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private boolean handleIncomingIntentInternal(
        Context context, Intent intent, boolean isCustomTabsIntent, long startTime,
        boolean isRedirect) {
    if (!isRedirect && !isCustomTabsIntent && BuildInfo.isAtLeastO()) {
        Log.i(TAG, "Disabled for Android O+");
        return false;
    }

    if (isCustomTabsIntent && !IntentUtils.safeGetBooleanExtra(
            intent, CUSTOM_APPS_INSTANT_APP_EXTRA, false)) {
        Log.i(TAG, "Not handling with Instant Apps (missing CUSTOM_APPS_INSTANT_APP_EXTRA)");
        return false;
    }

    if (IntentUtils.safeGetBooleanExtra(intent, DO_NOT_LAUNCH_EXTRA, false)
            || (BuildInfo.isAtLeastO() && (intent.getFlags() & FLAG_DO_NOT_LAUNCH) != 0)) {
        maybeRecordFallbackStats(intent);
        Log.i(TAG, "Not handling with Instant Apps (DO_NOT_LAUNCH_EXTRA)");
        return false;
    }

    if (IntentUtils.safeGetBooleanExtra(
            intent, IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false)
            || IntentUtils.safeHasExtra(intent, ShortcutHelper.EXTRA_SOURCE)
            || isIntentFromChrome(context, intent)
            || (IntentHandler.getUrlFromIntent(intent) == null)) {
        Log.i(TAG, "Not handling with Instant Apps (other)");
        return false;
    }

    // Used to search for the intent handlers. Needs null component to return correct results.
    Intent intentCopy = new Intent(intent);
    intentCopy.setComponent(null);
    Intent selector = intentCopy.getSelector();
    if (selector != null) selector.setComponent(null);

    if (!(isCustomTabsIntent || isChromeDefaultHandler(context))
            || ExternalNavigationDelegateImpl.isPackageSpecializedHandler(null, intentCopy)) {
        // Chrome is not the default browser or a specialized handler exists.
        Log.i(TAG, "Not handling with Instant Apps because Chrome is not default or "
                + "there's a specialized handler");
        return false;
    }

    Intent callbackIntent = new Intent(intent);
    callbackIntent.putExtra(DO_NOT_LAUNCH_EXTRA, true);
    callbackIntent.putExtra(INSTANT_APP_START_TIME_EXTRA, startTime);

    return tryLaunchingInstantApp(context, intent, isCustomTabsIntent, callbackIntent);
}