Java Code Examples for org.chromium.chrome.browser.tab.Tab

The following examples show how to use org.chromium.chrome.browser.tab.Tab. These examples are extracted from open source projects. 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 Project: AndroidChromium   Source File: LayoutManagerChromePhone.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void tabClosed(int id, int nextId, boolean incognito, boolean tabRemoved) {
    boolean showOverview = nextId == Tab.INVALID_TAB_ID;
    Layout overviewLayout = useAccessibilityLayout() ? mOverviewListLayout : mOverviewLayout;
    if (getActiveLayout() != overviewLayout && showOverview) {
        // Since there will be no 'next' tab to display, switch to
        // overview mode when the animation is finished.
        setNextLayout(overviewLayout);
    }
    getActiveLayout().onTabClosed(time(), id, nextId, incognito);
    Tab nextTab = getTabById(nextId);
    if (nextTab != null) nextTab.requestFocus();
    boolean animate = !tabRemoved && animationsEnabled();
    if (getActiveLayout() != overviewLayout && showOverview && !animate) {
        startShowing(overviewLayout, false);
    }
}
 
Example 2
Source Project: AndroidChromium   Source File: TabModelImpl.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 3
Source Project: 365browser   Source File: ChromeTabCreator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean createTabWithWebContents(Tab parent, WebContents webContents, int parentId,
        TabLaunchType type, String url) {
    // The parent tab was already closed.  Do not open child tabs.
    if (mTabModel.isClosurePending(parentId)) return false;

    // If parent is in the same tab model, place the new tab next to it.
    int position = TabModel.INVALID_TAB_INDEX;
    int index = TabModelUtils.getTabIndexById(mTabModel, parentId);
    if (index != TabModel.INVALID_TAB_INDEX) position = index + 1;

    boolean openInForeground = mOrderController.willOpenInForeground(type, mIncognito);
    TabDelegateFactory delegateFactory = parent == null ? createDefaultTabDelegateFactory()
            : parent.getDelegateFactory();
    Tab tab = Tab.createLiveTab(Tab.INVALID_TAB_ID, mActivity, mIncognito,
            mNativeWindow, type, parentId, !openInForeground);
    tab.initialize(webContents, mTabContentManager, delegateFactory, !openInForeground, false);
    mTabModel.addTab(tab, position, type);
    return true;
}
 
Example 4
Source Project: delion   Source File: ExternalNavigationParams.java    License: Apache License 2.0 6 votes vote down vote up
private ExternalNavigationParams(String url, boolean isIncognito, String referrerUrl,
        int pageTransition, boolean isRedirect, boolean appMustBeInForeground,
        TabRedirectHandler redirectHandler, Tab tab, boolean openInNewTab,
        boolean isBackgroundTabNavigation, boolean isMainFrame, String webApkPackageName,
        boolean hasUserGesture,
        boolean shouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent) {
    mUrl = url;
    mIsIncognito = isIncognito;
    mPageTransition = pageTransition;
    mReferrerUrl = referrerUrl;
    mIsRedirect = isRedirect;
    mApplicationMustBeInForeground = appMustBeInForeground;
    mRedirectHandler = redirectHandler;
    mTab = tab;
    mOpenInNewTab = openInNewTab;
    mIsBackgroundTabNavigation = isBackgroundTabNavigation;
    mIsMainFrame = isMainFrame;
    mWebApkPackageName = webApkPackageName;
    mHasUserGesture = hasUserGesture;
    mShouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent =
            shouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent;
}
 
Example 5
Source Project: 365browser   Source File: ChromeFullscreenManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setPositionsForTabToNonFullscreen() {
    Tab tab = getTab();
    if (tab == null || tab.isShowingBrowserControlsEnabled()) {
        setPositionsForTab(0, 0, getTopControlsHeight());
    } else {
        setPositionsForTab(-getTopControlsHeight(), getBottomControlsHeight(), 0);
    }
}
 
Example 6
Source Project: delion   Source File: ToolbarModelImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the tab that contains the information to be displayed in the toolbar.
 * @param tab The tab associated currently with the toolbar.
 * @param isIncognito Whether the incognito model is currently selected, which must match the
 *                    passed in tab if non-null.
 */
public void setTab(Tab tab, boolean isIncognito) {
    mTab = tab;
    if (mTab != null) {
        assert mTab.isIncognito() == isIncognito;
    }
    mIsIncognito = isIncognito;
}
 
Example 7
Source Project: 365browser   Source File: TabModelUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param model   The {@link TabModel} to act on.
 * @param tabId   The id of the {@link Tab} to close.
 * @param canUndo Whether or not this closure can be undone.
 * @return        {@code true} if the {@link Tab} was found.
 */
public static boolean closeTabById(TabModel model, int tabId, boolean canUndo) {
    Tab tab = TabModelUtils.getTabById(model, tabId);
    if (tab == null) return false;

    return model.closeTab(tab, true, false, canUndo);
}
 
Example 8
Source Project: 365browser   Source File: ReaderModeManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroyed(Tab tab) {
    if (tab == null) return;
    if (tab.getInfoBarContainer() != null) {
        tab.getInfoBarContainer().removeObserver(this);
    }
    // If the panel was not shown for the previous navigation, record it now.
    ReaderModeTabInfo info = mTabStatusMap.get(tab.getId());
    if (info != null && !info.isPanelShowRecorded()) {
        recordPanelVisibilityForNavigation(false);
    }
    removeTabState(tab.getId());
}
 
Example 9
Source Project: delion   Source File: ChromeActivity.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Remove a view that previously obscured the content of all tabs.
 *
 * @param view The view that no longer obscures the contents of all tabs.
 */
public void removeViewObscuringAllTabs(View view) {
    mViewsObscuringAllTabs.remove(view);

    Tab tab = getActivityTab();
    if (tab != null) tab.updateAccessibilityVisibility();
}
 
Example 10
Source Project: AndroidChromium   Source File: ToolbarManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Updates the current button states and calls appropriate abstract visibility methods, giving
 * inheriting classes the chance to update the button visuals as well.
 */
private void updateButtonStatus() {
    Tab currentTab = mToolbarModel.getTab();
    boolean tabCrashed = currentTab != null && currentTab.isShowingSadTab();

    mToolbar.updateButtonVisibility();
    mToolbar.updateBackButtonVisibility(currentTab != null && currentTab.canGoBack());
    mToolbar.updateForwardButtonVisibility(currentTab != null && currentTab.canGoForward());
    updateReloadState(tabCrashed);
    updateBookmarkButtonStatus();

    mToolbar.getMenuButtonWrapper().setVisibility(View.VISIBLE);
}
 
Example 11
Source Project: AndroidChromium   Source File: TabModelImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Actually closes and cleans up {@code tab}.
 * @param tab The {@link Tab} to close.
 */
private void finalizeTabClosure(Tab tab) {
    if (mTabContentManager != null) mTabContentManager.removeTabThumbnail(tab.getId());
    mTabSaver.removeTabFromQueues(tab);

    if (!isIncognito()) tab.createHistoricalTab();

    tab.destroy();

    for (TabModelObserver obs : mObservers) obs.didCloseTab(tab.getId(), tab.isIncognito());
}
 
Example 12
Source Project: 365browser   Source File: ToolbarModelImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Tab getTab() {
    // TODO(dtrainor, tedchoc): Remove the isInitialized() check when we no longer wait for
    // TAB_CLOSED events to remove this tab.  Otherwise there is a chance we use this tab after
    // {@link ChromeTab#destroy()} is called.
    if (mBottomSheet != null && mBottomSheet.isShowingNewTab()) {
        return null;
    }
    return (mTab == null || !mTab.isInitialized()) ? null : mTab;
}
 
Example 13
Source Project: delion   Source File: LayoutManagerChrome.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void willAddTab(Tab tab, TabLaunchType type) {
    // Open the new tab
    if (type == TabLaunchType.FROM_RESTORE) return;
    if (type == TabLaunchType.FROM_REPARENTING) return;

    tabCreating(getTabModelSelector().getCurrentTabId(), tab.getUrl(), tab.isIncognito());
}
 
Example 14
Source Project: 365browser   Source File: ToolbarManager.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean forward() {
    Tab tab = mToolbarModel.getTab();
    if (tab != null && tab.canGoForward()) {
        tab.goForward();
        updateButtonStatus();
        return true;
    }
    return false;
}
 
Example 15
Source Project: AndroidChromium   Source File: StackLayout.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the tab stack state for the specified tab id.
 *
 * @param tabId The id of the tab to lookup.
 * @return The tab stack index for the given tab id.
 * @VisibleForTesting
 */
protected int getTabStackIndex(int tabId) {
    if (tabId == Tab.INVALID_TAB_ID) {
        boolean incognito = mTemporarySelectedStack != null
                ? mTemporarySelectedStack
                : mTabModelSelector.isIncognitoSelected();
        return incognito ? 1 : 0;
    } else {
        return TabModelUtils.getTabById(mTabModelSelector.getModel(true), tabId) != null ? 1
                                                                                         : 0;
    }
}
 
Example 16
Source Project: 365browser   Source File: PreferencesLauncher.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Opens the UI to clear browsing data.
 * @param tab The tab that triggered the request.
 */
@CalledByNative
private static void openClearBrowsingData(Tab tab) {
    Activity activity = tab.getWindowAndroid().getActivity().get();
    if (activity == null) {
        Log.e(TAG, "Attempting to open clear browsing data for a tab without a valid activity");
        return;
    }

    Intent intent = createIntentForClearBrowsingDataPage(activity);
    activity.startActivity(intent);
}
 
Example 17
Source Project: delion   Source File: TabModelImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Close all tabs on this model without notifying observers about pending tab closures.
 *
 * @param animate true iff the closing animation should be displayed
 * @param uponExit true iff the tabs are being closed upon application exit (after user presses
 *                 the system back button)
 * @param canUndo Whether or not this action can be undone. If this is {@code true} and
 *                {@link #supportsPendingClosures()} is {@code true}, these {@link Tab}s
 *                will not actually be closed until {@link #commitTabClosure(int)} or
 *                {@link #commitAllTabClosures()} is called, but they will be effectively
 *                removed from this list.
 */
public void closeAllTabs(boolean animate, boolean uponExit, boolean canUndo) {
    for (int i = 0; i < getCount(); i++) getTabAt(i).setClosing(true);

    ArrayList<Integer> closedTabs = new ArrayList<Integer>();
    while (getCount() > 0) {
        Tab tab = getTabAt(0);
        closedTabs.add(tab.getId());
        closeTab(tab, animate, uponExit, canUndo, false);
    }

    if (!uponExit && canUndo && supportsPendingClosures()) {
        for (TabModelObserver obs : mObservers) obs.allTabsPendingClosure(closedTabs);
    }
}
 
Example 18
Source Project: delion   Source File: LayoutManagerChromePhone.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void tabCreated(int id, int sourceId, TabLaunchType launchType, boolean isIncognito,
        boolean willBeSelected, float originX, float originY) {
    super.tabCreated(id, sourceId, launchType, isIncognito, willBeSelected, originX, originY);

    if (willBeSelected) {
        Tab newTab = TabModelUtils.getTabById(getTabModelSelector().getModel(isIncognito), id);
        if (newTab != null) newTab.requestFocus();
    }
}
 
Example 19
Source Project: AndroidChromium   Source File: TabModelImpl.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 20
Source Project: AndroidChromium   Source File: TabModelUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param model The {@link TabModel} to act on.
 * @param index The index of the {@link Tab} to close.
 * @return      {@code true} if the {@link Tab} was found.
 */
public static boolean closeTabByIndex(TabModel model, int index) {
    Tab tab = model.getTabAt(index);
    if (tab == null) return false;

    return model.closeTab(tab);
}
 
Example 21
Source Project: AndroidChromium   Source File: CompositorViewHolder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onContentChanged() {
    if (mTabModelSelector == null) {
        // Not yet initialized, onContentChanged() will eventually get called by
        // setTabModelSelector.
        return;
    }
    Tab tab = mTabModelSelector.getCurrentTab();
    setTab(tab);
}
 
Example 22
Source Project: delion   Source File: SimpleAnimationLayout.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void show(long time, boolean animate) {
    super.show(time, animate);

    if (mTabModelSelector != null && mTabContentManager != null) {
        Tab tab = mTabModelSelector.getCurrentTab();
        if (tab != null && tab.isNativePage()) mTabContentManager.cacheTabThumbnail(tab);
    }

    reset();
}
 
Example 23
Source Project: 365browser   Source File: ReaderModeManager.java    License: Apache License 2.0 5 votes vote down vote up
public ReaderModeManager(TabModelSelector selector, ChromeActivity activity) {
    super(selector);
    mTabId = Tab.INVALID_TAB_ID;
    mTabModelSelector = selector;
    mChromeActivity = activity;
    mTabStatusMap = new HashMap<>();
    mIsReaderHeuristicAlwaysTrue = isDistillerHeuristicAlwaysTrue();
}
 
Example 24
Source Project: AndroidChromium   Source File: LayerTitleCache.java    License: 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 25
Source Project: delion   Source File: ActivityDelegate.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return Running Activity that owns the given Tab, null if the Activity couldn't be found.
 */
public static Activity getActivityForTabId(int id) {
    if (id == Tab.INVALID_TAB_ID) return null;

    for (WeakReference<Activity> ref : ApplicationStatus.getRunningActivities()) {
        if (!(ref.get() instanceof ChromeActivity)) continue;

        ChromeActivity activity = (ChromeActivity) ref.get();
        if (activity == null) continue;

        if (activity.getTabModelSelector().getTabById(id) != null) return activity;
    }
    return null;
}
 
Example 26
Source Project: delion   Source File: CustomTabActivity.java    License: Apache License 2.0 5 votes vote down vote up
private Tab createMainTab() {
    CustomTabsConnection customTabsConnection =
            CustomTabsConnection.getInstance(getApplication());
    String url = getUrlToLoad();
    // Get any referrer that has been explicitly set by the app.
    String referrerUrl = IntentHandler.getReferrerUrlIncludingExtraHeaders(getIntent(), this);
    if (referrerUrl == null) {
        Referrer referrer = customTabsConnection.getReferrerForSession(mSession);
        if (referrer != null) referrerUrl = referrer.getUrl();
    }
    Tab tab = new Tab(TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID),
            Tab.INVALID_TAB_ID, false, this, getWindowAndroid(),
            TabLaunchType.FROM_EXTERNAL_APP, null, null);
    tab.setAppAssociatedWith(customTabsConnection.getClientPackageNameForSession(mSession));

    mPrerenderedUrl = customTabsConnection.getPrerenderedUrl(mSession);
    WebContents webContents =
            customTabsConnection.takePrerenderedUrl(mSession, url, referrerUrl);
    mHasPrerendered = webContents != null;
    if (webContents == null) webContents = customTabsConnection.takeSpareWebContents();
    if (webContents == null) webContents = WebContentsFactory.createWebContents(false, false);
    tab.initialize(webContents, getTabContentManager(),
            new CustomTabDelegateFactory(mIntentDataProvider.shouldEnableUrlBarHiding()), false,
            false);
    tab.getTabRedirectHandler().updateIntent(getIntent());
    tab.getView().requestFocus();
    mTabObserver = new CustomTabObserver(getApplication(), mSession);
    tab.addObserver(mTabObserver);
    return tab;
}
 
Example 27
Source Project: 365browser   Source File: OfflinePageTabObserver.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create and attach a tab observer if we don't already have one, otherwise update it.
 * @param tab The tab we are adding an observer for.
 */
public static void addObserverForTab(Tab tab) {
    OfflinePageTabObserver observer = getObserverForActivity(tab.getActivity());
    assert observer != null;
    observer.startObservingTab(tab);
    observer.maybeShowReloadSnackbar(tab, false);
}
 
Example 28
Source Project: 365browser   Source File: TabPersistentStore.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Serializes {@code selector} to a byte array, copying out the data pertaining to tab ordering
 * and selected indices.
 * @param selector          The {@link TabModelSelector} to serialize.
 * @param tabsBeingRestored Tabs that are in the process of being restored.
 * @return                  {@code byte[]} containing the serialized state of {@code selector}.
 */
@VisibleForTesting
public static byte[] serializeTabModelSelector(TabModelSelector selector,
        List<TabRestoreDetails> tabsBeingRestored) throws IOException {
    ThreadUtils.assertOnUiThread();

    TabModel incognitoModel = selector.getModel(true);
    TabModelMetadata incognitoInfo = new TabModelMetadata(incognitoModel.index());
    for (int i = 0; i < incognitoModel.getCount(); i++) {
        incognitoInfo.ids.add(incognitoModel.getTabAt(i).getId());
        incognitoInfo.urls.add(incognitoModel.getTabAt(i).getUrl());
    }

    TabModel normalModel = selector.getModel(false);
    TabModelMetadata normalInfo = new TabModelMetadata(normalModel.index());
    for (int i = 0; i < normalModel.getCount(); i++) {
        normalInfo.ids.add(normalModel.getTabAt(i).getId());
        normalInfo.urls.add(normalModel.getTabAt(i).getUrl());
    }

    // Cache the active tab id to be pre-loaded next launch.
    int activeTabId = Tab.INVALID_TAB_ID;
    int activeIndex = normalModel.index();
    if (activeIndex != TabList.INVALID_TAB_INDEX) {
        activeTabId = normalModel.getTabAt(activeIndex).getId();
    }
    // Always override the existing value in case there is no active tab.
    ContextUtils.getAppSharedPreferences().edit().putInt(
            PREF_ACTIVE_TAB_ID, activeTabId).apply();

    return serializeMetadata(normalInfo, incognitoInfo, tabsBeingRestored);
}
 
Example 29
Source Project: AndroidChromium   Source File: FindToolbar.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Checks to see if a ContentViewCore is available to hook into.
 */
protected boolean isViewAvailable() {
    Tab currentTab = mTabModelSelector.getCurrentTab();
    return currentTab != null && currentTab.getContentViewCore() != null;
}
 
Example 30
Source Project: AndroidChromium   Source File: RecentlyClosedBridge.java    License: Apache License 2.0 4 votes vote down vote up
private native boolean nativeOpenRecentlyClosedTab(long nativeRecentlyClosedTabsBridge,
Tab tab, int recentTabId, int windowOpenDisposition);