Search in sources :

Example 51 with Tab

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

the class TabModelImpl method cancelTabClosure.

@Override
public void cancelTabClosure(int tabId) {
    Tab tab = mRewoundList.getPendingRewindTab(tabId);
    if (tab == null)
        return;
    tab.setClosing(false);
    // Find a valid previous tab entry so we know what tab to insert after.  With the following
    // example, calling cancelTabClosure(4) would need to know to insert after 2.  So we have to
    // track across mRewoundTabs and mTabs and see what the last valid mTabs entry was (2) when
    // we hit the 4 in the rewound list.  An insertIndex of -1 represents the beginning of the
    // list, as this is the index of tab to insert after.
    // mTabs:       0   2     5
    // mRewoundTabs 0 1 2 3 4 5
    int prevIndex = -1;
    final int stopIndex = mRewoundList.indexOf(tab);
    for (int rewoundIndex = 0; rewoundIndex < stopIndex; rewoundIndex++) {
        Tab rewoundTab = mRewoundList.getTabAt(rewoundIndex);
        if (prevIndex == mTabs.size() - 1)
            break;
        if (rewoundTab == mTabs.get(prevIndex + 1))
            prevIndex++;
    }
    // Figure out where to insert the tab.  Just add one to prevIndex, as -1 represents the
    // beginning of the list, so we'll insert at 0.
    int insertIndex = prevIndex + 1;
    if (mIndex >= insertIndex)
        mIndex++;
    mTabs.add(insertIndex, tab);
    WebContents webContents = tab.getWebContents();
    if (webContents != null)
        webContents.setAudioMuted(false);
    boolean activeModel = mModelDelegate.getCurrentModel() == this;
    if (mIndex == INVALID_TAB_INDEX) {
        // set mIndex but don't kick off everything that happens when calling setIndex().
        if (activeModel) {
            TabModelUtils.setIndex(this, insertIndex);
        } else {
            mIndex = insertIndex;
        }
    }
    // Re-save the tab list now that it is being kept.
    mTabSaver.saveTabListAsynchronously();
    for (TabModelObserver obs : mObservers) obs.tabClosureUndone(tab);
}
Also used : WebContents(org.chromium.content_public.browser.WebContents) Tab(org.chromium.chrome.browser.tab.Tab)

Example 52 with Tab

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

the class TabModelImpl method moveTab.

@Override
public void moveTab(int id, int newIndex) {
    newIndex = MathUtils.clamp(newIndex, 0, mTabs.size());
    int curIndex = TabModelUtils.getTabIndexById(this, id);
    if (curIndex == INVALID_TAB_INDEX || curIndex == newIndex || curIndex + 1 == newIndex) {
        return;
    }
    // TODO(dtrainor): Update the list of undoable tabs instead of committing it.
    commitAllTabClosures();
    Tab tab = mTabs.remove(curIndex);
    if (curIndex < newIndex)
        --newIndex;
    mTabs.add(newIndex, tab);
    if (curIndex == mIndex) {
        mIndex = newIndex;
    } else if (curIndex < mIndex && newIndex >= mIndex) {
        --mIndex;
    } else if (curIndex > mIndex && newIndex <= mIndex) {
        ++mIndex;
    }
    mRewoundList.resetRewoundState();
    for (TabModelObserver obs : mObservers) obs.didMoveTab(tab, newIndex, curIndex);
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Example 53 with Tab

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

the class TabModelOrderController method determineInsertionIndex.

/**
     * Determine the insertion index of the next tab.
     *
     * @param type The launch type of the new tab.
     * @return Where to insert the tab.
     */
public int determineInsertionIndex(TabLaunchType type, Tab newTab) {
    TabModel currentModel = mTabModelSelector.getCurrentModel();
    Tab currentTab = TabModelUtils.getCurrentTab(currentModel);
    if (currentTab == null) {
        assert (currentModel.getCount() == 0);
        return 0;
    }
    int currentId = currentTab.getId();
    int currentIndex = TabModelUtils.getTabIndexById(currentModel, currentId);
    if (sameModelType(currentModel, newTab)) {
        if (willOpenInForeground(type, newTab.isIncognito())) {
            // the tab that opened that link.
            return currentIndex + 1;
        } else {
            // If the tab was opened in the background, position at the end of
            // it's 'group'.
            int index = getIndexOfLastTabOpenedBy(currentId, currentIndex);
            if (index != NO_TAB) {
                return index + 1;
            } else {
                return currentIndex + 1;
            }
        }
    } else {
        // If the tab is opening in the other model type, just put it at the end.
        return mTabModelSelector.getModel(newTab.isIncognito()).getCount();
    }
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Example 54 with Tab

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

the class TabModelOrderController method getIndexOfLastTabOpenedBy.

/**
     * Returns the index of the last tab in the model opened by the specified
     * opener, starting at startIndex. To clarify, the tabs are traversed in the
     * descending order of their position in the model. This means that the tab
     * furthest in the stack with the given opener id will be returned.
     *
     * @param openerId The opener of interest.
     * @param startIndex The start point of the search.
     * @return The last tab if found, NO_TAB otherwise.
     */
private int getIndexOfLastTabOpenedBy(int openerId, int startIndex) {
    TabModel currentModel = mTabModelSelector.getCurrentModel();
    int count = currentModel.getCount();
    for (int i = count - 1; i >= startIndex; i--) {
        Tab tab = currentModel.getTabAt(i);
        if (tab.getParentId() == openerId && tab.isGroupedWithParent()) {
            return i;
        }
    }
    return NO_TAB;
}
Also used : Tab(org.chromium.chrome.browser.tab.Tab)

Example 55 with Tab

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

the class TabPersistentStore method saveState.

public void saveState() {
    // Temporarily allowing disk access. TODO: Fix. See http://b/5518024
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
    try {
        long saveStateStartTime = SystemClock.uptimeMillis();
        // it looked when the SaveListTask was first created.
        if (mSaveListTask != null)
            mSaveListTask.cancel(true);
        try {
            saveListToFile(serializeTabMetadata());
        } catch (IOException e) {
            Log.w(TAG, "Error while saving tabs state; will attempt to continue...", e);
        }
        logExecutionTime("SaveListTime", saveStateStartTime);
        // Add current tabs to save because they did not get a save signal yet.
        Tab currentStandardTab = TabModelUtils.getCurrentTab(mTabModelSelector.getModel(false));
        if (currentStandardTab != null && !mTabsToSave.contains(currentStandardTab) && currentStandardTab.isTabStateDirty() && // persistent.
        !isTabUrlContentScheme(currentStandardTab)) {
            mTabsToSave.addLast(currentStandardTab);
        }
        Tab currentIncognitoTab = TabModelUtils.getCurrentTab(mTabModelSelector.getModel(true));
        if (currentIncognitoTab != null && !mTabsToSave.contains(currentIncognitoTab) && currentIncognitoTab.isTabStateDirty() && !isTabUrlContentScheme(currentIncognitoTab)) {
            mTabsToSave.addLast(currentIncognitoTab);
        }
        // Wait for the current tab to save.
        if (mSaveTabTask != null) {
            // wrote the state to disk.  That's why we have to check mStateSaved here.
            if (mSaveTabTask.cancel(false) && !mSaveTabTask.mStateSaved) {
                // The task was successfully cancelled.  We should try to save this state again.
                Tab cancelledTab = mSaveTabTask.mTab;
                if (!mTabsToSave.contains(cancelledTab) && cancelledTab.isTabStateDirty() && !isTabUrlContentScheme(cancelledTab)) {
                    mTabsToSave.addLast(cancelledTab);
                }
            }
            mSaveTabTask = null;
        }
        long saveTabsStartTime = SystemClock.uptimeMillis();
        // Synchronously save any remaining unsaved tabs (hopefully very few).
        for (Tab tab : mTabsToSave) {
            int id = tab.getId();
            boolean incognito = tab.isIncognito();
            try {
                TabState state = tab.getState();
                if (state != null) {
                    TabState.saveState(getTabStateFile(id, incognito), state, incognito);
                }
            } catch (OutOfMemoryError e) {
                Log.w(TAG, "Out of memory error while attempting to save tab state.  Erasing.");
                deleteTabState(id, incognito);
            }
        }
        mTabsToSave.clear();
        logExecutionTime("SaveTabsTime", saveTabsStartTime);
        logExecutionTime("SaveStateTime", saveStateStartTime);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
Also used : StrictMode(android.os.StrictMode) Tab(org.chromium.chrome.browser.tab.Tab) IOException(java.io.IOException) TabState(org.chromium.chrome.browser.TabState)

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