Search in sources :

Example 46 with Tab

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

the class ChromeTabCreator method createNewTab.

/**
     * Creates a new tab and posts to UI.
     * @param loadUrlParams parameters of the url load.
     * @param type Information about how the tab was launched.
     * @param parent the parent tab, if present.
     * @param position the requested position (index in the tab model)
     * @param intent the source of the url if it isn't null.
     * @return The new tab.
     */
private Tab createNewTab(LoadUrlParams loadUrlParams, TabModel.TabLaunchType type, Tab parent, int position, Intent intent) {
    try {
        TraceEvent.begin("ChromeTabCreator.createNewTab");
        int parentId = parent != null ? parent.getId() : Tab.INVALID_TAB_ID;
        // Sanitize the url.
        loadUrlParams.setUrl(UrlFormatter.fixupUrl(loadUrlParams.getUrl()));
        loadUrlParams.setTransitionType(getTransitionType(type, intent));
        // Check if the tab is being created asynchronously.
        int assignedTabId = intent == null ? Tab.INVALID_TAB_ID : IntentUtils.safeGetIntExtra(intent, IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID);
        AsyncTabParams asyncParams = AsyncTabParamsManager.remove(assignedTabId);
        boolean openInForeground = mOrderController.willOpenInForeground(type, mIncognito);
        TabDelegateFactory delegateFactory = parent == null ? createDefaultTabDelegateFactory() : parent.getDelegateFactory();
        Tab tab;
        if (asyncParams != null && asyncParams.getTabToReparent() != null) {
            type = TabLaunchType.FROM_REPARENTING;
            openInForeground = true;
            TabReparentingParams params = (TabReparentingParams) asyncParams;
            tab = params.getTabToReparent();
            tab.attachAndFinishReparenting(mActivity, createDefaultTabDelegateFactory(), params);
        } else if (asyncParams != null && asyncParams.getWebContents() != null) {
            openInForeground = true;
            WebContents webContents = asyncParams.getWebContents();
            // A WebContents was passed through the Intent.  Create a new Tab to hold it.
            Intent parentIntent = IntentUtils.safeGetParcelableExtra(intent, IntentHandler.EXTRA_PARENT_INTENT);
            parentId = IntentUtils.safeGetIntExtra(intent, IntentHandler.EXTRA_PARENT_TAB_ID, parentId);
            assert TabModelUtils.getTabIndexById(mTabModel, assignedTabId) == TabModel.INVALID_TAB_INDEX;
            tab = Tab.createLiveTab(assignedTabId, mActivity, mIncognito, mNativeWindow, type, parentId, !openInForeground);
            tab.initialize(webContents, mTabContentManager, delegateFactory, !openInForeground, false);
            tab.setParentIntent(parentIntent);
            webContents.resumeLoadingCreatedWebContents();
        } else if (!openInForeground && SysUtils.isLowEndDevice()) {
            // On low memory devices the tabs opened in background are not loaded automatically
            // to preserve resources (cpu, memory, strong renderer binding) for the foreground
            // tab.
            tab = Tab.createTabForLazyLoad(mActivity, mIncognito, mNativeWindow, type, parentId, loadUrlParams);
            tab.initialize(null, mTabContentManager, delegateFactory, !openInForeground, false);
        } else {
            tab = Tab.createLiveTab(Tab.INVALID_TAB_ID, mActivity, mIncognito, mNativeWindow, type, parentId, !openInForeground);
            tab.initialize(null, mTabContentManager, delegateFactory, !openInForeground, false);
            tab.loadUrl(loadUrlParams);
        }
        tab.getTabRedirectHandler().updateIntent(intent);
        if (intent != null && intent.hasExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA)) {
            ServiceTabLauncher.onWebContentsForRequestAvailable(intent.getIntExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA, 0), tab.getWebContents());
        }
        mTabModel.addTab(tab, position, type);
        return tab;
    } finally {
        TraceEvent.end("ChromeTabCreator.createNewTab");
    }
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) Tab(org.chromium.chrome.browser.tab.Tab) Intent(android.content.Intent) TabDelegateFactory(org.chromium.chrome.browser.tab.TabDelegateFactory)

Example 47 with Tab

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

the class TabModelImpl method getNextTabIfClosed.

@Override
public Tab getNextTabIfClosed(int id) {
    Tab tabToClose = TabModelUtils.getTabById(this, id);
    Tab currentTab = TabModelUtils.getCurrentTab(this);
    if (tabToClose == null)
        return currentTab;
    int closingTabIndex = indexOf(tabToClose);
    Tab adjacentTab = getTabAt((closingTabIndex == 0) ? 1 : closingTabIndex - 1);
    Tab parentTab = findTabInAllTabModels(tabToClose.getParentId());
    // Determine which tab to select next according to these rules:
    //   * If closing a background tab, keep the current tab selected.
    //   * Otherwise, if not in overview mode, select the parent tab if it exists.
    //   * Otherwise, select an adjacent tab if one exists.
    //   * Otherwise, if closing the last incognito tab, select the current normal tab.
    //   * Otherwise, select nothing.
    Tab nextTab = null;
    if (tabToClose != currentTab && currentTab != null && !currentTab.isClosing()) {
        nextTab = currentTab;
    } else if (parentTab != null && !parentTab.isClosing() && !mModelDelegate.isInOverviewMode()) {
        nextTab = parentTab;
    } else if (adjacentTab != null && !adjacentTab.isClosing()) {
        nextTab = adjacentTab;
    } else if (isIncognito()) {
        nextTab = TabModelUtils.getCurrentTab(mModelDelegate.getModel(false));
        if (nextTab != null && nextTab.isClosing())
            nextTab = null;
    }
    return nextTab;
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Example 48 with Tab

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

the class TabModelImpl method openMostRecentlyClosedTab.

@Override
public void openMostRecentlyClosedTab() {
    // First try to recover tab from rewound list, same as {@link UndoBarController}.
    if (mRewoundList.hasPendingClosures()) {
        Tab tab = mRewoundList.getNextRewindableTab();
        if (tab == null)
            return;
        cancelTabClosure(tab.getId());
        return;
    }
    // If there are no pending closures in the rewound list,
    // then try to restore the tab from the native tab restore service.
    mRecentlyClosedBridge.openRecentlyClosedTab();
    // If there is only one tab, select it.
    if (getCount() == 1)
        setIndex(0, TabSelectionType.FROM_NEW);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Example 49 with Tab

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

the class TabModelImpl method removeTabAndSelectNext.

/**
     * Removes the given tab from the tab model and selects a new tab.
     */
private void removeTabAndSelectNext(Tab tab, TabSelectionType selectionType, boolean pauseMedia, boolean updateRewoundList) {
    assert selectionType == TabSelectionType.FROM_CLOSE || selectionType == TabSelectionType.FROM_EXIT;
    final int closingTabId = tab.getId();
    final int closingTabIndex = indexOf(tab);
    Tab currentTab = TabModelUtils.getCurrentTab(this);
    Tab adjacentTab = getTabAt(closingTabIndex == 0 ? 1 : closingTabIndex - 1);
    Tab nextTab = getNextTabIfClosed(closingTabId);
    // TODO(dtrainor): Update the list of undoable tabs instead of committing it.
    if (updateRewoundList)
        commitAllTabClosures();
    // Cancel or mute any media currently playing.
    if (pauseMedia) {
        WebContents webContents = tab.getWebContents();
        if (webContents != null) {
            webContents.suspendAllMediaPlayers();
            webContents.setAudioMuted(true);
        }
    }
    mTabs.remove(tab);
    boolean nextIsIncognito = nextTab == null ? false : nextTab.isIncognito();
    int nextTabId = nextTab == null ? Tab.INVALID_TAB_ID : nextTab.getId();
    int nextTabIndex = nextTab == null ? INVALID_TAB_INDEX : TabModelUtils.getTabIndexById(mModelDelegate.getModel(nextIsIncognito), nextTabId);
    if (nextTab != currentTab) {
        if (nextIsIncognito != isIncognito())
            mIndex = indexOf(adjacentTab);
        TabModel nextModel = mModelDelegate.getModel(nextIsIncognito);
        nextModel.setIndex(nextTabIndex, selectionType);
    } else {
        mIndex = nextTabIndex;
    }
    if (updateRewoundList)
        mRewoundList.resetRewoundState();
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) Tab(org.chromium.chrome.browser.tab.Tab)

Example 50 with Tab

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

the class TabModelImpl method destroy.

@Override
public void destroy() {
    for (Tab tab : mTabs) {
        if (tab.isInitialized())
            tab.destroy();
    }
    mRewoundList.destroy();
    mTabs.clear();
    mObservers.clear();
    mRecentlyClosedBridge.destroy();
    super.destroy();
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Aggregations

Tab (org.chromium.chrome.browser.tab.Tab)116 LayoutTab (org.chromium.chrome.browser.compositor.layouts.components.LayoutTab)13 TabModel (org.chromium.chrome.browser.tabmodel.TabModel)10 LoadUrlParams (org.chromium.content_public.browser.LoadUrlParams)9 SuppressLint (android.annotation.SuppressLint)8 TabModelSelectorTabObserver (org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver)8 Intent (android.content.Intent)5 FrameLayout (android.widget.FrameLayout)4 ContentViewCore (org.chromium.content.browser.ContentViewCore)4 WebContents (org.chromium.content_public.browser.WebContents)4 Activity (android.app.Activity)3 Bitmap (android.graphics.Bitmap)3 TabLaunchType (org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType)3 PendingIntent (android.app.PendingIntent)2 Context (android.content.Context)2 Bundle (android.os.Bundle)2 StrictMode (android.os.StrictMode)2 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2