Search in sources :

Example 1 with TabReparentingParams

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

the class Tab method detachAndStartReparenting.

/**
     * Begins the tab reparenting process. Detaches the tab from its current activity and fires
     * an Intent to reparent the tab into its new host activity.
     *
     * @param intent An optional intent with the desired component, flags, or extras to use when
     *               launching the new host activity. This intent's URI and action will be
     *               overriden. This may be null if no intent customization is needed.
     * @param startActivityOptions Options to pass to {@link Activity#startActivity(Intent, Bundle)}
     * @param finalizeCallback A callback that will be called after the tab is attached to the new
     *                         host activity in {@link #attachAndFinishReparenting}.
     * @return Whether reparenting succeeded. If false, the tab was not removed and the intent was
     *         not fired.
     */
public boolean detachAndStartReparenting(Intent intent, Bundle startActivityOptions, Runnable finalizeCallback) {
    ChromeActivity activity = getActivity();
    if (activity == null)
        return false;
    if (intent == null)
        intent = new Intent();
    if (intent.getComponent() == null) {
        intent.setClass(mThemedApplicationContext, ChromeLauncherActivity.class);
    }
    intent.setAction(Intent.ACTION_VIEW);
    if (TextUtils.isEmpty(intent.getDataString()))
        intent.setData(Uri.parse(getUrl()));
    if (isIncognito()) {
        intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
    }
    IntentHandler.addTrustedIntentExtras(intent, activity);
    if (ChromeFeatureList.isEnabled(ChromeFeatureList.TAB_REPARENTING)) {
        TabModelSelector tabModelSelector = getTabModelSelector();
        if (tabModelSelector == null)
            return false;
        mIsDetachedForReparenting = true;
        // Add the tab to AsyncTabParamsManager before removing it from the current model to
        // ensure the global count of tabs is correct. See crbug.com/611806.
        intent.putExtra(IntentHandler.EXTRA_TAB_ID, mId);
        AsyncTabParamsManager.add(mId, new TabReparentingParams(this, intent, finalizeCallback));
        tabModelSelector.getModel(mIncognito).removeTab(this);
        // TODO(mthiesse): File a bug when crbug isn't down.
        if (mContentViewCore != null)
            mContentViewCore.updateWindowAndroid(null);
        attachTabContentManager(null);
    }
    activity.startActivity(intent, startActivityOptions);
    return true;
}
Also used : SingleTabModelSelector(org.chromium.chrome.browser.tabmodel.SingleTabModelSelector) TabModelSelector(org.chromium.chrome.browser.tabmodel.TabModelSelector) TabReparentingParams(org.chromium.chrome.browser.tabmodel.TabReparentingParams) Intent(android.content.Intent) ChromeActivity(org.chromium.chrome.browser.ChromeActivity)

Aggregations

Intent (android.content.Intent)1 ChromeActivity (org.chromium.chrome.browser.ChromeActivity)1 SingleTabModelSelector (org.chromium.chrome.browser.tabmodel.SingleTabModelSelector)1 TabModelSelector (org.chromium.chrome.browser.tabmodel.TabModelSelector)1 TabReparentingParams (org.chromium.chrome.browser.tabmodel.TabReparentingParams)1