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

The following examples show how to use org.chromium.chrome.browser.tab.Tab#getId() . 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: LayoutManagerChrome.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType launchType) {
    int tabId = tab.getId();
    if (launchType != TabLaunchType.FROM_RESTORE) {
        boolean incognito = tab.isIncognito();
        boolean willBeSelected = launchType != TabLaunchType.FROM_LONGPRESS_BACKGROUND
                || (!getTabModelSelector().isIncognitoSelected() && incognito);
        float lastTapX = LocalizationUtils.isLayoutRtl() ? mLastContentWidthDp : 0.f;
        float lastTapY = 0.f;
        if (launchType != TabLaunchType.FROM_CHROME_UI) {
            float heightDelta =
                    mLastFullscreenViewportDp.height() - mLastVisibleViewportDp.height();
            lastTapX = mPxToDp * mLastTapX;
            lastTapY = mPxToDp * mLastTapY - heightDelta;
        }

        tabCreated(tabId, getTabModelSelector().getCurrentTabId(), launchType, incognito,
                willBeSelected, lastTapX, lastTapY);
    }
}
 
Example 2
Source File: TabPersistentStore.java    From 365browser with Apache License 2.0 6 votes vote down vote up
public void removeTabFromQueues(Tab tab) {
    mTabsToSave.remove(tab);
    mTabsToRestore.remove(getTabToRestoreById(tab.getId()));

    if (mLoadTabTask != null && mLoadTabTask.mTabToRestore.id == tab.getId()) {
        mLoadTabTask.cancel(false);
        mLoadTabTask = null;
        loadNextTab();
    }

    if (mSaveTabTask != null && mSaveTabTask.mId == tab.getId()) {
        mSaveTabTask.cancel(false);
        mSaveTabTask = null;
        saveNextTab();
    }

    cleanupPersistentData(tab.getId(), tab.isIncognito());
}
 
Example 3
Source File: LayoutManagerChrome.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
public void didAddTab(Tab tab, TabLaunchType launchType) {
    int tabId = tab.getId();
    if (launchType == TabLaunchType.FROM_RESTORE) {
        getActiveLayout().onTabRestored(time(), tabId);
    } else {
        boolean incognito = tab.isIncognito();
        boolean willBeSelected = launchType != TabLaunchType.FROM_LONGPRESS_BACKGROUND
                || (!getTabModelSelector().isIncognitoSelected() && incognito);
        float lastTapX = LocalizationUtils.isLayoutRtl() ? mLastContentWidthDp : 0.f;
        float lastTapY = 0.f;
        if (launchType != TabLaunchType.FROM_CHROME_UI) {
            float heightDelta =
                    mLastFullscreenViewportDp.height() - mLastVisibleViewportDp.height();
            lastTapX = mPxToDp * mLastTapX;
            lastTapY = mPxToDp * mLastTapY - heightDelta;
        }

        tabCreated(tabId, getTabModelSelector().getCurrentTabId(), launchType, incognito,
                willBeSelected, lastTapX, lastTapY);
    }
}
 
Example 4
Source File: StripLayoutHelper.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void computeAndUpdateTabOrders(boolean delayResize) {
    final int count = mModel.getCount();
    StripLayoutTab[] tabs = new StripLayoutTab[count];

    for (int i = 0; i < count; i++) {
        final Tab tab = mModel.getTabAt(i);
        final int id = tab.getId();
        final StripLayoutTab oldTab = findTabById(id);
        tabs[i] = oldTab != null ? oldTab : createStripTab(id);
        setAccessibilityDescription(tabs[i], tab);
    }

    int oldStripLength = mStripTabs.length;
    mStripTabs = tabs;

    if (mStripTabs.length != oldStripLength) resizeTabStrip(delayResize);

    updateVisualTabOrdering();
}
 
Example 5
Source File: TabModelUtils.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Find the index of the {@link Tab} with the specified id.
 * @param model The {@link TabModel} to act on.
 * @param tabId The id of the {@link Tab} to find.
 * @return      Specified {@link Tab} index or {@link TabList#INVALID_TAB_INDEX} if the
 *              {@link Tab} is not found
 */
public static int getTabIndexById(TabList model, int tabId) {
    int count = model.getCount();

    for (int i = 0; i < count; i++) {
        Tab tab = model.getTabAt(i);
        if (tab.getId() == tabId) return i;
    }

    return TabModel.INVALID_TAB_INDEX;
}
 
Example 6
Source File: TabModelImpl.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * A utility method for easily finding a {@link Tab} that can be closed.
 * @return The next tab that is in the middle of being closed.
 */
public Tab getNextRewindableTab() {
    if (!hasPendingClosures()) return null;

    for (int i = 0; i < mRewoundTabs.size(); i++) {
        Tab tab = i < TabModelImpl.this.getCount() ? TabModelImpl.this.getTabAt(i) : null;
        Tab rewoundTab = mRewoundTabs.get(i);

        if (tab == null || rewoundTab.getId() != tab.getId()) return rewoundTab;
    }

    return null;
}
 
Example 7
Source File: TabModelImpl.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Removes the given tab from the tab model and selects a new tab.
 */
private void removeTabAndSelectNext(Tab tab, TabSelectionType selectionType, boolean pauseMedia,
        boolean updateRewoundList) {
    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();
}
 
Example 8
Source File: LayerTitleCache.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void updateFaviconFromHistory(Tab tab, Bitmap faviconBitmap) {
    if (!tab.isInitialized()) return;

    int tabId = tab.getId();
    Title title = mTitles.get(tabId);
    if (title == null) return;
    if (!title.updateFaviconFromHistory(faviconBitmap)) return;

    if (mNativeLayerTitleCache != 0) {
        nativeUpdateFavicon(mNativeLayerTitleCache, tabId, title.getFaviconResId());
    }
}
 
Example 9
Source File: ReaderModeManager.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onContentChanged(Tab tab) {
    // Only listen to events on the currently active tab.
    if (tab.getId() != mTabId) return;
    closeReaderPanel(StateChangeReason.UNKNOWN, false);

    if (mTabStatusMap.containsKey(mTabId)) {
        // If the panel was closed using the "x" icon, don't show it again for this tab.
        if (mTabStatusMap.get(mTabId).isDismissed()) return;
        removeTabState(mTabId);
    }

    ReaderModeTabInfo tabInfo = new ReaderModeTabInfo();
    tabInfo.setStatus(NOT_POSSIBLE);
    tabInfo.setUrl(tab.getUrl());
    mTabStatusMap.put(tab.getId(), tabInfo);

    if (tab.getWebContents() != null) {
        tabInfo.setWebContentsObserver(createWebContentsObserver(tab.getWebContents()));
        if (DomDistillerUrlUtils.isDistilledPage(tab.getUrl())) {
            tabInfo.setStatus(STARTED);
            mReaderModePageUrl = tab.getUrl();
            closeReaderPanel(StateChangeReason.CONTENT_CHANGED, true);
        }
        // Make sure there is a distillability delegate set on the WebContents.
        setDistillabilityCallback(tab.getId());
    }

    if (tab.getInfoBarContainer() != null) tab.getInfoBarContainer().addObserver(this);
}
 
Example 10
Source File: LayerTitleCache.java    From delion with Apache License 2.0 5 votes vote down vote up
private String getUpdatedTitleInternal(Tab tab, String titleString,
        boolean fetchFaviconFromHistory) {
    final int tabId = tab.getId();
    Bitmap originalFavicon = tab.getFavicon();

    boolean isDarkTheme = tab.isIncognito();
    // If theme colors are enabled in the tab switcher, the theme might require lighter text.
    if (FeatureUtilities.areTabSwitcherThemeColorsEnabled()
            && !DeviceFormFactor.isTablet(mContext)) {
        isDarkTheme |= ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor());
    }

    ColorUtils.shouldUseLightForegroundOnBackground(tab.getThemeColor());
    boolean isRtl = tab.isTitleDirectionRtl();
    TitleBitmapFactory titleBitmapFactory = isDarkTheme
            ? mDarkTitleBitmapFactory : mStandardTitleBitmapFactory;

    Title title = mTitles.get(tabId);
    if (title == null) {
        title = new Title();
        mTitles.put(tabId, title);
        title.register();
    }

    title.set(titleBitmapFactory.getTitleBitmap(mContext, titleString),
            titleBitmapFactory.getFaviconBitmap(mContext, originalFavicon),
            fetchFaviconFromHistory);

    if (mNativeLayerTitleCache != 0) {
        nativeUpdateLayer(mNativeLayerTitleCache, tabId, title.getTitleResId(),
                title.getFaviconResId(), isDarkTheme, isRtl);
    }
    return titleString;
}
 
Example 11
Source File: Stack.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the {@link StackTab}s needed for display and populates {@link #mStackTabs}.
 * It is called from show() at the beginning of every new draw phase. It tries to reuse old
 * {@link StackTab} instead of creating new ones every time.
 * @param restoreState Whether or not to restore the {@link LayoutTab} state when we rebuild the
 *                     {@link StackTab}s.  There are some properties like maximum content size
 *                     or whether or not to show the toolbar that might have to be restored if
 *                     we're calling this while the switcher is already visible.
 */
private void createStackTabs(boolean restoreState) {
    final int count = mTabModel.getCount();
    if (count == 0) {
        cleanupTabs();
    } else {
        StackTab[] oldTabs = mStackTabs;
        mStackTabs = new StackTab[count];

        final boolean isIncognito = mTabModel.isIncognito();
        final boolean needTitle = !mLayout.isHiding();
        for (int i = 0; i < count; ++i) {
            Tab tab = mTabModel.getTabAt(i);
            int tabId = tab != null ? tab.getId() : Tab.INVALID_TAB_ID;
            mStackTabs[i] = findTabById(oldTabs, tabId);

            float maxContentWidth = -1.f;
            float maxContentHeight = -1.f;

            if (mStackTabs[i] != null && mStackTabs[i].getLayoutTab() != null && restoreState) {
                maxContentWidth = mStackTabs[i].getLayoutTab().getMaxContentWidth();
                maxContentHeight = mStackTabs[i].getLayoutTab().getMaxContentHeight();
            }

            LayoutTab layoutTab = mLayout.createLayoutTab(tabId, isIncognito,
                    Layout.SHOW_CLOSE_BUTTON, needTitle, maxContentWidth, maxContentHeight);
            layoutTab.setInsetBorderVertical(true);
            layoutTab.setShowToolbar(!FeatureUtilities.isChromeHomeEnabled());
            layoutTab.setToolbarAlpha(0.f);
            layoutTab.setAnonymizeToolbar(!mIsStackForCurrentTabModel
                    || mTabModel.index() != i);

            if (mStackTabs[i] == null) {
                mStackTabs[i] = new StackTab(layoutTab);
            } else {
                mStackTabs[i].setLayoutTab(layoutTab);
            }

            mStackTabs[i].setNewIndex(i);
            // The initial enterStack animation will take care of
            // positioning, scaling, etc.
        }
    }
}
 
Example 12
Source File: PaymentRequestImpl.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void didSelectTab(Tab tab, TabSelectionType type, int lastId) {
    if (tab == null || tab.getId() != lastId) onDismiss();
}
 
Example 13
Source File: PaymentRequestImpl.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void didSelectTab(Tab tab, TabSelectionType type, int lastId) {
    if (tab == null || tab.getId() != lastId) onDismiss();
}
 
Example 14
Source File: TabPersistentStore.java    From delion with Apache License 2.0 4 votes vote down vote up
SaveTabTask(Tab tab) {
    mTab = tab;
    mId = tab.getId();
    mEncrypted = tab.isIncognito();
}
 
Example 15
Source File: LayoutManagerChrome.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public void didSelectTab(Tab tab, TabSelectionType type, int lastId) {
    if (tab.getId() != lastId) tabSelected(tab.getId(), lastId, tab.isIncognito());
}
 
Example 16
Source File: SingleTabModel.java    From delion with Apache License 2.0 4 votes vote down vote up
@Override
public int indexOf(Tab tab) {
    return mTab != null && mTab.getId() == tab.getId() ? 0 : INVALID_TAB_INDEX;
}
 
Example 17
Source File: ReaderModeManager.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void onShown(Tab shownTab) {
    if (mTabModelSelector == null) return;

    int shownTabId = shownTab.getId();
    Tab previousTab = mTabModelSelector.getTabById(mTabId);
    mTabId = shownTabId;

    // If the reader panel was dismissed, stop here.
    if (mTabStatusMap.containsKey(shownTabId)
            && mTabStatusMap.get(shownTabId).isDismissed()) {
        return;
    }

    // Set this manager as the active one for the UI utils.
    DomDistillerUIUtils.setReaderModeManagerDelegate(this);

    // Update infobar state based on current tab.
    if (shownTab.getInfoBarContainer() != null) {
        mIsInfoBarContainerShown = shownTab.getInfoBarContainer().hasInfoBars();
    }

    // Remove the infobar observer from the previous tab and attach it to the current one.
    if (previousTab != null && previousTab.getInfoBarContainer() != null) {
        previousTab.getInfoBarContainer().removeObserver(this);
    }

    if (shownTab.getInfoBarContainer() != null) {
        shownTab.getInfoBarContainer().addObserver(this);
    }

    // If there is no state info for this tab, create it.
    ReaderModeTabInfo tabInfo = mTabStatusMap.get(shownTabId);
    if (tabInfo == null) {
        tabInfo = new ReaderModeTabInfo();
        tabInfo.setStatus(NOT_POSSIBLE);
        tabInfo.setUrl(shownTab.getUrl());
        mTabStatusMap.put(shownTabId, tabInfo);
    }

    // Make sure there is a WebContentsObserver on this tab's WebContents.
    if (tabInfo.getWebContentsObserver() == null) {
        tabInfo.setWebContentsObserver(createWebContentsObserver(shownTab.getWebContents()));
    }

    // Make sure there is a distillability delegate set on the WebContents.
    setDistillabilityCallback(shownTabId);

    requestReaderPanelShow(StateChangeReason.UNKNOWN);
}
 
Example 18
Source File: TabPersistentStore.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void restoreTab(
        TabRestoreDetails tabToRestore, TabState tabState, boolean setAsActive) {
    // If we don't have enough information about the Tab, bail out.
    boolean isIncognito = isIncognitoTabBeingRestored(tabToRestore, tabState);
    if (tabState == null) {
        if (tabToRestore.isIncognito == null) {
            Log.w(TAG, "Failed to restore tab: not enough info about its type was available.");
            return;
        } else if (isIncognito) {
            Log.i(TAG, "Failed to restore Incognito tab: its TabState could not be restored.");
            return;
        }
    }

    TabModel model = mTabModelSelector.getModel(isIncognito);
    SparseIntArray restoredTabs = isIncognito ? mIncognitoTabsRestored : mNormalTabsRestored;
    int restoredIndex = 0;
    if (tabToRestore.fromMerge) {
        // Put any tabs being merged into this list at the end.
        restoredIndex = mTabModelSelector.getModel(isIncognito).getCount();
    } else if (restoredTabs.size() > 0
            && tabToRestore.originalIndex > restoredTabs.keyAt(restoredTabs.size() - 1)) {
        // If the tab's index is too large, restore it at the end of the list.
        restoredIndex = restoredTabs.size();
    } else {
         // Otherwise try to find the tab we should restore before, if any.
        for (int i = 0; i < restoredTabs.size(); i++) {
            if (restoredTabs.keyAt(i) > tabToRestore.originalIndex) {
                Tab nextTabByIndex = TabModelUtils.getTabById(model, restoredTabs.valueAt(i));
                restoredIndex = nextTabByIndex != null ? model.indexOf(nextTabByIndex) : -1;
                break;
            }
        }
    }

    int tabId = tabToRestore.id;
    if (tabState != null) {
        mTabCreatorManager.getTabCreator(isIncognito).createFrozenTab(
                tabState, tabToRestore.id, restoredIndex);
    } else {
        Log.w(TAG, "Failed to restore TabState; creating Tab with last known URL.");
        Tab fallbackTab = mTabCreatorManager.getTabCreator(isIncognito).createNewTab(
                new LoadUrlParams(tabToRestore.url), TabModel.TabLaunchType.FROM_RESTORE, null);
        tabId = fallbackTab.getId();
        model.moveTab(tabId, restoredIndex);
    }

    // If the tab is being restored from a merge and its index is 0, then the model being
    // merged into doesn't contain any tabs. Select the first tab to avoid having no tab
    // selected. TODO(twellington): The first tab will always be selected. Instead, the tab that
    // was selected in the other model before the merge should be selected after the merge.
    if (setAsActive || (tabToRestore.fromMerge && restoredIndex == 0)) {
        boolean wasIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();
        int selectedModelTabCount = mTabModelSelector.getCurrentModel().getCount();

        TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, tabId));
        boolean isIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();

        // Setting the index will cause the tab's model to be selected. Set it back to the model
        // that was selected before setting the index if the index is being set during a merge
        // unless the previously selected model is empty (e.g. showing the empty background
        // view on tablets).
        if (tabToRestore.fromMerge
                && wasIncognitoTabModelSelected != isIncognitoTabModelSelected
                && selectedModelTabCount != 0) {
            mTabModelSelector.selectModel(wasIncognitoTabModelSelected);
        }
    }
    restoredTabs.put(tabToRestore.originalIndex, tabId);
}
 
Example 19
Source File: SingleTabModel.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public int indexOf(Tab tab) {
    return mTab != null && mTab.getId() == tab.getId() ? 0 : INVALID_TAB_INDEX;
}
 
Example 20
Source File: LayoutManagerChrome.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void tabClosed(int tabId, boolean incognito, boolean tabRemoved) {
    Tab currentTab =
            getTabModelSelector() != null ? getTabModelSelector().getCurrentTab() : null;
    int nextTabId = currentTab != null ? currentTab.getId() : Tab.INVALID_TAB_ID;
    tabClosed(tabId, nextTabId, incognito, tabRemoved);
}