Java Code Examples for org.chromium.chrome.browser.tab.Tab#setClosing()

The following examples show how to use org.chromium.chrome.browser.tab.Tab#setClosing() . 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: TabModelImpl.java    From delion with Apache License 2.0 4 votes vote down vote up
@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) {
        // If we're the active model call setIndex to actually select this tab, otherwise just
        // 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);
}
 
Example 2
Source File: TabModelImpl.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@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) {
        // If we're the active model call setIndex to actually select this tab, otherwise just
        // 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);
}
 
Example 3
Source File: TabModelImpl.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@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 = isCurrentModel();

    if (mIndex == INVALID_TAB_INDEX) {
        // If we're the active model call setIndex to actually select this tab, otherwise just
        // 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);
}
 
Example 4
Source File: TabModelImpl.java    From delion with Apache License 2.0 3 votes vote down vote up
/**
 * Performs the necessary actions to remove this {@link Tab} from this {@link TabModel}.
 * This does not actually destroy the {@link Tab} (see
 * {@link #finalizeTabClosure(Tab)}.
 *
 * @param tab The {@link Tab} to remove from this {@link TabModel}.
 * @param animate Whether or not to animate the closing.
 * @param uponExit Whether or not this is closing while the Activity is exiting.
 * @param canUndo Whether or not this operation can be undone. Note that if this is {@code true}
 *                and {@link #supportsPendingClosures()} is {@code true},
 *                {@link #commitTabClosure(int)} or {@link #commitAllTabClosures()} needs to be
 *                called to actually delete and clean up {@code tab}.
 */
private void startTabClosure(Tab tab, boolean animate, boolean uponExit, boolean canUndo) {
    tab.setClosing(true);

    for (TabModelObserver obs : mObservers) obs.willCloseTab(tab, animate);

    TabSelectionType selectionType =
            uponExit ? TabSelectionType.FROM_EXIT : TabSelectionType.FROM_CLOSE;
    boolean pauseMedia = canUndo;
    boolean updateRewoundList = !canUndo;
    removeTabAndSelectNext(tab, selectionType, pauseMedia, updateRewoundList);
}
 
Example 5
Source File: TabModelImpl.java    From AndroidChromium with Apache License 2.0 3 votes vote down vote up
/**
 * Performs the necessary actions to remove this {@link Tab} from this {@link TabModel}.
 * This does not actually destroy the {@link Tab} (see
 * {@link #finalizeTabClosure(Tab)}.
 *
 * @param tab The {@link Tab} to remove from this {@link TabModel}.
 * @param animate Whether or not to animate the closing.
 * @param uponExit Whether or not this is closing while the Activity is exiting.
 * @param canUndo Whether or not this operation can be undone. Note that if this is {@code true}
 *                and {@link #supportsPendingClosures()} is {@code true},
 *                {@link #commitTabClosure(int)} or {@link #commitAllTabClosures()} needs to be
 *                called to actually delete and clean up {@code tab}.
 */
private void startTabClosure(Tab tab, boolean animate, boolean uponExit, boolean canUndo) {
    tab.setClosing(true);

    for (TabModelObserver obs : mObservers) obs.willCloseTab(tab, animate);

    TabSelectionType selectionType =
            uponExit ? TabSelectionType.FROM_EXIT : TabSelectionType.FROM_CLOSE;
    boolean pauseMedia = canUndo;
    boolean updateRewoundList = !canUndo;
    removeTabAndSelectNext(tab, selectionType, pauseMedia, updateRewoundList);
}
 
Example 6
Source File: TabModelImpl.java    From 365browser with Apache License 2.0 3 votes vote down vote up
/**
 * Performs the necessary actions to remove this {@link Tab} from this {@link TabModel}.
 * This does not actually destroy the {@link Tab} (see
 * {@link #finalizeTabClosure(Tab)}.
 *
 * @param tab The {@link Tab} to remove from this {@link TabModel}.
 * @param animate Whether or not to animate the closing.
 * @param uponExit Whether or not this is closing while the Activity is exiting.
 * @param canUndo Whether or not this operation can be undone. Note that if this is {@code true}
 *                and {@link #supportsPendingClosures()} is {@code true},
 *                {@link #commitTabClosure(int)} or {@link #commitAllTabClosures()} needs to be
 *                called to actually delete and clean up {@code tab}.
 */
private void startTabClosure(Tab tab, boolean animate, boolean uponExit, boolean canUndo) {
    tab.setClosing(true);

    for (TabModelObserver obs : mObservers) obs.willCloseTab(tab, animate);

    TabSelectionType selectionType =
            uponExit ? TabSelectionType.FROM_EXIT : TabSelectionType.FROM_CLOSE;
    boolean pauseMedia = canUndo;
    boolean updateRewoundList = !canUndo;
    removeTabAndSelectNext(tab, selectionType, pauseMedia, updateRewoundList);
}