Search in sources :

Example 1 with ChromeTabbedActivity

use of org.chromium.chrome.browser.ChromeTabbedActivity in project AndroidChromium by JackyAndroid.

the class ChromeLauncherActivity method launchFirstRunExperience.

/**
     * Tries to launch the First Run Experience.  If ChromeLauncherActivity is running with the
     * wrong Intent flags, we instead relaunch ChromeLauncherActivity to make sure it runs in its
     * own task, which then triggers First Run.
     * @return Whether or not the First Run Experience needed to be shown.
     * @param forTabbedMode Whether the First Run Experience is launched for tabbed mode.
     */
private boolean launchFirstRunExperience(boolean forTabbedMode) {
    // Tries to launch the Generic First Run Experience for intent from GSA.
    boolean showLightweightFre = IntentHandler.determineExternalIntentSource(this.getPackageName(), getIntent()) != ExternalAppId.GSA;
    Intent freIntent = FirstRunFlowSequencer.checkIfFirstRunIsNecessary(this, getIntent(), showLightweightFre);
    if (freIntent == null)
        return false;
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
        if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_LIGHTWEIGHT_FIRST_RUN_EXPERIENCE)) {
            boolean isTabbedModeActive = false;
            boolean isLightweightFreActive = false;
            boolean isGenericFreActive = false;
            List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
            for (WeakReference<Activity> weakActivity : activities) {
                Activity activity = weakActivity.get();
                if (activity == null) {
                    continue;
                }
                if (activity instanceof ChromeTabbedActivity) {
                    isTabbedModeActive = true;
                    continue;
                }
                if (activity instanceof LightweightFirstRunActivity) {
                    isLightweightFreActive = true;
                    // A Generic or a new Lightweight First Run Experience will be launched
                    // below, so finish the old Lightweight First Run Experience.
                    activity.setResult(Activity.RESULT_CANCELED);
                    activity.finish();
                    continue;
                }
                if (activity instanceof FirstRunActivity) {
                    isGenericFreActive = true;
                    continue;
                }
            }
            if (forTabbedMode) {
                if (isTabbedModeActive || isLightweightFreActive || !showLightweightFre) {
                    // Lets ChromeTabbedActivity checks and launches the Generic First Run
                    // Experience.
                    launchTabbedMode(false);
                    finish();
                    return true;
                }
            } else if (isGenericFreActive) {
                // Launch the Generic First Run Experience if it is active previously.
                freIntent = FirstRunFlowSequencer.createGenericFirstRunIntent(this, TextUtils.equals(getIntent().getAction(), Intent.ACTION_MAIN));
            }
        }
        // Add a PendingIntent so that the intent used to launch Chrome will be resent when
        // first run is completed or canceled.
        FirstRunFlowSequencer.addPendingIntent(this, freIntent, getIntent());
        startActivity(freIntent);
    } else {
        Intent newIntent = new Intent(getIntent());
        newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(newIntent);
    }
    finish();
    return true;
}
Also used : LightweightFirstRunActivity(org.chromium.chrome.browser.firstrun.LightweightFirstRunActivity) ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) LightweightFirstRunActivity(org.chromium.chrome.browser.firstrun.LightweightFirstRunActivity) FirstRunActivity(org.chromium.chrome.browser.firstrun.FirstRunActivity) WeakReference(java.lang.ref.WeakReference) WebappLauncherActivity(org.chromium.chrome.browser.webapps.WebappLauncherActivity) LightweightFirstRunActivity(org.chromium.chrome.browser.firstrun.LightweightFirstRunActivity) ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) CustomTabActivity(org.chromium.chrome.browser.customtabs.CustomTabActivity) SeparateTaskCustomTabActivity(org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity) UpgradeActivity(org.chromium.chrome.browser.upgrade.UpgradeActivity) FirstRunActivity(org.chromium.chrome.browser.firstrun.FirstRunActivity) Activity(android.app.Activity) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent)

Example 2 with ChromeTabbedActivity

use of org.chromium.chrome.browser.ChromeTabbedActivity in project AndroidChromium by JackyAndroid.

the class IncognitoNotificationService method focusChromeIfNecessary.

private void focusChromeIfNecessary() {
    Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();
    int tabbedTaskId = -1;
    List<WeakReference<Activity>> runningActivities = ApplicationStatus.getRunningActivities();
    for (int i = 0; i < runningActivities.size(); i++) {
        Activity activity = runningActivities.get(i).get();
        if (activity == null)
            continue;
        if (activity instanceof ChromeTabbedActivity) {
            tabbedTaskId = activity.getTaskId();
            break;
        }
    }
    // snapshot that would need to be regenerated.
    if (visibleTaskIds.contains(tabbedTaskId))
        return;
    Context context = ContextUtils.getApplicationContext();
    Intent startIntent = new Intent(Intent.ACTION_MAIN);
    startIntent.setPackage(context.getPackageName());
    startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(startIntent);
}
Also used : Context(android.content.Context) ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) WeakReference(java.lang.ref.WeakReference) ChromeLauncherActivity(org.chromium.chrome.browser.document.ChromeLauncherActivity) ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) Activity(android.app.Activity) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 3 with ChromeTabbedActivity

use of org.chromium.chrome.browser.ChromeTabbedActivity in project AndroidChromium by JackyAndroid.

the class DownloadUtils method showDownloadManager.

/**
     * Displays the download manager UI. Note the UI is different on tablets and on phones.
     * @return Whether the UI was shown.
     */
public static boolean showDownloadManager(@Nullable Activity activity, @Nullable Tab tab) {
    if (!isDownloadHomeEnabled())
        return false;
    // Figure out what tab was last being viewed by the user.
    if (activity == null)
        activity = ApplicationStatus.getLastTrackedFocusedActivity();
    if (tab == null && activity instanceof ChromeTabbedActivity) {
        tab = ((ChromeTabbedActivity) activity).getActivityTab();
    }
    Context appContext = ContextUtils.getApplicationContext();
    if (DeviceFormFactor.isTablet(appContext)) {
        // Download Home shows up as a tab on tablets.
        LoadUrlParams params = new LoadUrlParams(UrlConstants.DOWNLOADS_URL);
        if (tab == null || !tab.isInitialized()) {
            // Open a new tab, which pops Chrome into the foreground.
            TabDelegate delegate = new TabDelegate(false);
            delegate.createNewTab(params, TabLaunchType.FROM_CHROME_UI, null);
        } else {
            // Download Home shows up inside an existing tab, but only if the last Activity was
            // the ChromeTabbedActivity.
            tab.loadUrl(params);
            // Bring Chrome to the foreground, if possible.
            Intent intent = Tab.createBringTabToFrontIntent(tab.getId());
            if (intent != null) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                IntentUtils.safeStartActivity(appContext, intent);
            }
        }
    } else {
        // Download Home shows up as a new Activity on phones.
        Intent intent = new Intent();
        intent.setClass(appContext, DownloadActivity.class);
        if (tab != null)
            intent.putExtra(EXTRA_IS_OFF_THE_RECORD, tab.isIncognito());
        if (activity == null) {
            // Stands alone in its own task.
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            appContext.startActivity(intent);
        } else {
            // Sits on top of another Activity.
            intent.putExtra(IntentHandler.EXTRA_PARENT_COMPONENT, activity.getComponentName());
            activity.startActivity(intent);
        }
    }
    return true;
}
Also used : Context(android.content.Context) ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) LoadUrlParams(org.chromium.content_public.browser.LoadUrlParams) TabDelegate(org.chromium.chrome.browser.tabmodel.document.TabDelegate)

Example 4 with ChromeTabbedActivity

use of org.chromium.chrome.browser.ChromeTabbedActivity in project AndroidChromium by JackyAndroid.

the class MultiWindowUtils method getTabbedActivityForIntent.

/**
     * 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(Intent intent, Context context) {
    // 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.hasExtra(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;
}
Also used : ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) ChromeTabbedActivity2(org.chromium.chrome.browser.ChromeTabbedActivity2) ChromeLauncherActivity(org.chromium.chrome.browser.document.ChromeLauncherActivity) ChromeTabbedActivity(org.chromium.chrome.browser.ChromeTabbedActivity) Activity(android.app.Activity)

Aggregations

ChromeTabbedActivity (org.chromium.chrome.browser.ChromeTabbedActivity)4 Activity (android.app.Activity)3 Intent (android.content.Intent)3 PendingIntent (android.app.PendingIntent)2 Context (android.content.Context)2 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)2 WeakReference (java.lang.ref.WeakReference)2 ChromeLauncherActivity (org.chromium.chrome.browser.document.ChromeLauncherActivity)2 ChromeTabbedActivity2 (org.chromium.chrome.browser.ChromeTabbedActivity2)1 CustomTabActivity (org.chromium.chrome.browser.customtabs.CustomTabActivity)1 SeparateTaskCustomTabActivity (org.chromium.chrome.browser.customtabs.SeparateTaskCustomTabActivity)1 FirstRunActivity (org.chromium.chrome.browser.firstrun.FirstRunActivity)1 LightweightFirstRunActivity (org.chromium.chrome.browser.firstrun.LightweightFirstRunActivity)1 TabDelegate (org.chromium.chrome.browser.tabmodel.document.TabDelegate)1 UpgradeActivity (org.chromium.chrome.browser.upgrade.UpgradeActivity)1 WebappLauncherActivity (org.chromium.chrome.browser.webapps.WebappLauncherActivity)1 LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)1