Java Code Examples for org.chromium.chrome.browser.tabmodel.TabModel#isIncognito()

The following examples show how to use org.chromium.chrome.browser.tabmodel.TabModel#isIncognito() . 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: StackLayout.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a UI element is attempting to close a tab.  This will perform the required close
 * animations.  When the UI is ready to actually close the tab
 * {@link #uiDoneClosingTab(long, int, boolean, boolean)} should be called to actually propagate
 * the event to the model.
 * @param time The current time of the app in ms.
 * @param id   The id of the tab to close.
 */
public void uiRequestingCloseTab(long time, int id) {
    // Start the tab closing effect if necessary.
    getTabStack(id).tabClosingEffect(time, id);

    int incognitoCount = mTabModelSelector.getModel(true).getCount();
    TabModel model = mTabModelSelector.getModelForTabId(id);
    if (model != null && model.isIncognito()) incognitoCount--;
    boolean incognitoVisible = incognitoCount > 0;

    // Make sure we show/hide both stacks depending on which tab we're closing.
    startMarginAnimation(true, incognitoVisible);
    if (!incognitoVisible) uiPreemptivelySelectTabModel(false);
}
 
Example 2
Source File: StackLayout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a UI element is attempting to close a tab.  This will perform the required close
 * animations.  When the UI is ready to actually close the tab
 * {@link #uiDoneClosingTab(long, int, boolean, boolean)} should be called to actually propagate
 * the event to the model.
 * @param time The current time of the app in ms.
 * @param id   The id of the tab to close.
 */
public void uiRequestingCloseTab(long time, int id) {
    // Start the tab closing effect if necessary.
    getTabStack(id).tabClosingEffect(time, id);

    int incognitoCount = mTabModelSelector.getModel(true).getCount();
    TabModel model = mTabModelSelector.getModelForTabId(id);
    if (model != null && model.isIncognito()) incognitoCount--;
    boolean incognitoVisible = incognitoCount > 0;

    // Make sure we show/hide both stacks depending on which tab we're closing.
    startMarginAnimation(true, incognitoVisible);
    if (!incognitoVisible) uiPreemptivelySelectTabModel(false);
}
 
Example 3
Source File: StackLayout.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a UI element is attempting to close a tab.  This will perform the required close
 * animations.  When the UI is ready to actually close the tab
 * {@link #uiDoneClosingTab(long, int, boolean, boolean)} should be called to actually propagate
 * the event to the model.
 * @param time The current time of the app in ms.
 * @param id   The id of the tab to close.
 */
public void uiRequestingCloseTab(long time, int id) {
    // Start the tab closing effect if necessary.
    getTabStack(id).tabClosingEffect(time, id);

    int incognitoCount = mTabModelSelector.getModel(true).getCount();
    TabModel model = mTabModelSelector.getModelForTabId(id);
    if (model != null && model.isIncognito()) incognitoCount--;
    boolean incognitoVisible = incognitoCount > 0;

    // Make sure we show/hide both stacks depending on which tab we're closing.
    startMarginAnimation(true, incognitoVisible);
    if (!incognitoVisible) uiPreemptivelySelectTabModel(false);
}
 
Example 4
Source File: ChromeTabbedActivity.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onMenuOrKeyboardAction(final int id, boolean fromMenu) {
    final Tab currentTab = getActivityTab();
    if (id == R.id.move_to_other_window_menu_id) {
        if (currentTab != null) moveTabToOtherWindow(currentTab);
    } else if (id == R.id.new_tab_menu_id) {
        getTabModelSelector().getModel(false).commitAllTabClosures();
        RecordUserAction.record("MobileMenuNewTab");
        RecordUserAction.record("MobileNewTabOpened");
        reportNewTabShortcutUsed(false);
        getTabCreator(false).launchUrl(UrlConstants.NTP_URL, TabLaunchType.FROM_CHROME_UI);
        mLocaleManager.showSearchEnginePromoIfNeeded(this);
    } else if (id == R.id.new_incognito_tab_menu_id) {
        if (PrefServiceBridge.getInstance().isIncognitoModeEnabled()) {
            getTabModelSelector().getModel(false).commitAllTabClosures();
            // This action must be recorded before opening the incognito tab since UMA actions
            // are dropped when an incognito tab is open.
            RecordUserAction.record("MobileMenuNewIncognitoTab");
            RecordUserAction.record("MobileNewTabOpened");
            reportNewTabShortcutUsed(true);
            getTabCreator(true).launchUrl(UrlConstants.NTP_URL, TabLaunchType.FROM_CHROME_UI);
        }
    } else if (id == R.id.all_bookmarks_menu_id) {
        if (currentTab != null) {
            getCompositorViewHolder().hideKeyboard(new Runnable() {
                @Override
                public void run() {
                    StartupMetrics.getInstance().recordOpenedBookmarks();
                    BookmarkUtils.showBookmarkManager(ChromeTabbedActivity.this);
                }
            });
            RecordUserAction.record("MobileMenuAllBookmarks");
        }
    } else if (id == R.id.recent_tabs_menu_id) {
        if (currentTab != null) {
            currentTab.loadUrl(new LoadUrlParams(
                    UrlConstants.RECENT_TABS_URL,
                    PageTransition.AUTO_BOOKMARK));
            RecordUserAction.record("MobileMenuOpenTabs");
        }
    } else if (id == R.id.close_all_tabs_menu_id) {
        // Close both incognito and normal tabs
        getTabModelSelector().closeAllTabs();
        RecordUserAction.record("MobileMenuCloseAllTabs");
    } else if (id == R.id.close_all_incognito_tabs_menu_id) {
        // Close only incognito tabs
        getTabModelSelector().getModel(true).closeAllTabs();
        // TODO(nileshagrawal) Record unique action for this. See bug http://b/5542946.
        RecordUserAction.record("MobileMenuCloseAllTabs");
    } else if (id == R.id.find_in_page_id) {
        mFindToolbarManager.showToolbar();
        if (getContextualSearchManager() != null) {
            getContextualSearchManager().hideContextualSearch(StateChangeReason.UNKNOWN);
        }
        if (fromMenu) {
            RecordUserAction.record("MobileMenuFindInPage");
        } else {
            RecordUserAction.record("MobileShortcutFindInPage");
        }
    } else if (id == R.id.focus_url_bar) {
        boolean isUrlBarVisible = !mLayoutManager.overviewVisible()
                && (!isTablet() || getCurrentTabModel().getCount() != 0);
        if (isUrlBarVisible) {
            getToolbarManager().setUrlBarFocus(true);
        }
    } else if (id == R.id.downloads_menu_id) {
        DownloadUtils.showDownloadManager(this, currentTab);
        RecordUserAction.record("MobileMenuDownloadManager");
    } else if (id == R.id.open_recently_closed_tab) {
        TabModel currentModel = mTabModelSelectorImpl.getCurrentModel();
        if (!currentModel.isIncognito()) currentModel.openMostRecentlyClosedTab();
        RecordUserAction.record("MobileTabClosedUndoShortCut");
    } else if (id == R.id.enter_vr_id) {
        mVrShellDelegate.enterVRIfNecessary();
    } else {
        return super.onMenuOrKeyboardAction(id, fromMenu);
    }
    return true;
}
 
Example 5
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onMenuOrKeyboardAction(final int id, boolean fromMenu) {
    final Tab currentTab = getActivityTab();
    boolean currentTabIsNtp = currentTab != null && NewTabPage.isNTPUrl(currentTab.getUrl());
    if (id == R.id.move_to_other_window_menu_id) {
        if (currentTab != null) moveTabToOtherWindow(currentTab);
    } else if (id == R.id.new_tab_menu_id) {
        getTabModelSelector().getModel(false).commitAllTabClosures();
        RecordUserAction.record("MobileMenuNewTab");
        RecordUserAction.record("MobileNewTabOpened");
        reportNewTabShortcutUsed(false);
        getTabCreator(false).launchNTP();

        mLocaleManager.showSearchEnginePromoIfNeeded(this, null);
    } else if (id == R.id.new_incognito_tab_menu_id) {
        if (PrefServiceBridge.getInstance().isIncognitoModeEnabled()) {
            getTabModelSelector().getModel(false).commitAllTabClosures();
            // This action must be recorded before opening the incognito tab since UMA actions
            // are dropped when an incognito tab is open.
            RecordUserAction.record("MobileMenuNewIncognitoTab");
            RecordUserAction.record("MobileNewTabOpened");
            reportNewTabShortcutUsed(true);
            getTabCreator(true).launchNTP();
        }
    } else if (id == R.id.all_bookmarks_menu_id) {
        if (currentTab != null) {
            getCompositorViewHolder().hideKeyboard(new Runnable() {
                @Override
                public void run() {
                    StartupMetrics.getInstance().recordOpenedBookmarks();
                    BookmarkUtils.showBookmarkManager(ChromeTabbedActivity.this);
                }
            });
            if (currentTabIsNtp) {
                NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_BOOKMARKS_MANAGER);
            }
            RecordUserAction.record("MobileMenuAllBookmarks");
        }
    } else if (id == R.id.recent_tabs_menu_id) {
        if (currentTab != null) {
            currentTab.loadUrl(new LoadUrlParams(
                    UrlConstants.RECENT_TABS_URL,
                    PageTransition.AUTO_BOOKMARK));
            if (currentTabIsNtp) {
                NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_RECENT_TABS_MANAGER);
            }
            RecordUserAction.record("MobileMenuRecentTabs");
        }
    } else if (id == R.id.close_all_tabs_menu_id) {
        // Close both incognito and normal tabs
        getTabModelSelector().closeAllTabs();
        RecordUserAction.record("MobileMenuCloseAllTabs");
    } else if (id == R.id.close_all_incognito_tabs_menu_id) {
        // Close only incognito tabs
        getTabModelSelector().getModel(true).closeAllTabs();
        // TODO(nileshagrawal) Record unique action for this. See bug http://b/5542946.
        RecordUserAction.record("MobileMenuCloseAllTabs");
    } else if (id == R.id.find_in_page_id) {
        mFindToolbarManager.showToolbar();
        if (getContextualSearchManager() != null) {
            getContextualSearchManager().hideContextualSearch(StateChangeReason.UNKNOWN);
        }
        if (fromMenu) {
            RecordUserAction.record("MobileMenuFindInPage");
        } else {
            RecordUserAction.record("MobileShortcutFindInPage");
        }
    } else if (id == R.id.focus_url_bar) {
        boolean isUrlBarVisible = !mLayoutManager.overviewVisible()
                && (!isTablet() || getCurrentTabModel().getCount() != 0);
        if (isUrlBarVisible) {
            getToolbarManager().setUrlBarFocus(true);
        }
    } else if (id == R.id.downloads_menu_id) {
        DownloadUtils.showDownloadManager(this, currentTab);
        if (currentTabIsNtp) {
            NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_DOWNLOADS_MANAGER);
        }
        RecordUserAction.record("MobileMenuDownloadManager");
    } else if (id == R.id.open_recently_closed_tab) {
        TabModel currentModel = mTabModelSelectorImpl.getCurrentModel();
        if (!currentModel.isIncognito()) currentModel.openMostRecentlyClosedTab();
        RecordUserAction.record("MobileTabClosedUndoShortCut");
    } else if (id == R.id.enter_vr_id) {
        VrShellDelegate.enterVrIfNecessary();
    } else {
        return super.onMenuOrKeyboardAction(id, fromMenu);
    }
    return true;
}