1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.chrome.browser.tabmodel;
7 import org.chromium.base.VisibleForTesting;
8 import org.chromium.chrome.browser.Tab;
9 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
10 import org.chromium.content_public.browser.LoadUrlParams;
12 import java.util.List;
15 * TabModelSelector is a wrapper class containing both a normal and an incognito TabModel.
16 * This class helps the app know which mode it is currently in, and which TabModel it should
19 public interface TabModelSelector {
21 * Interface of listener that get notified on changes in the {@link TabModel}s.
23 public interface ChangeListener {
25 * Called whenever the {@link TabModel} has changed.
30 * Called when a new tab is created.
32 void onNewTabCreated(Tab tab);
36 * Set the current model. This won't cause an animation, but will still change the stack that is
37 * currently visible if the tab switcher is open.
39 void selectModel(boolean incognito);
42 * Get a specific tab model
43 * @return Never returns null. Returns a stub when real model is uninitialized.
45 TabModel getModel(boolean incognito);
48 * @return a list for the underlying models
50 List<TabModel> getModels();
53 * @return the model at {@code index} or null if no model exist for that index.
56 TabModel getModelAt(int index);
59 * Get the current tab model.
60 * @return Never returns null. Returns a stub when real model is uninitialized.
62 TabModel getCurrentModel();
65 * Convenience function to get the current tab on the current model
66 * @return Current tab or null if none exists or if the model is not initialized.
71 * Convenience function to get the current tab id on the current model.
72 * @return Id of the current tab or {@link Tab#INVALID_TAB_ID} if no tab is selected or the
73 * model is not initialized.
75 int getCurrentTabId();
78 * Convenience function to get the {@link TabModel} for a {@link Tab} specified by
80 * @param id The id of the {@link Tab} to find the {@link TabModel} for.
81 * @return The {@link TabModel} that owns the {@link Tab} specified by {@code id}.
83 TabModel getModelForTabId(int id);
86 * @return The index of the current {@link TabModel}.
88 int getCurrentModelIndex();
91 * @return If the incognito {@link TabModel} is current.
93 boolean isIncognitoSelected();
98 * @param loadUrlParams parameters of the url load
99 * @param type Describes how the new tab is being opened.
100 * @param parent The parent tab for this new tab (or null if one does not exist).
101 * @param incognito Whether to open the new tab in incognito mode.
102 * @return The newly opened tab.
104 Tab openNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent, boolean incognito);
107 * Searches through all children models for the specified Tab and closes the tab if it exists.
108 * @param tab the non-null tab to close
109 * @return true if the tab was found
111 boolean closeTab(Tab tab);
114 * Close all tabs across all tab models
119 * Close all tabs across all tab models
120 * @param uponExit true iff the tabs are being closed upon application exit (after user presses
121 * the system back button)
123 void closeAllTabs(boolean uponExit);
126 * Get total tab count across all tab models
128 int getTotalTabCount();
131 * Search all TabModels for a tab with the specified id.
132 * @return specified tab or null if tab is not found
134 Tab getTabById(int id);
137 * Registers a listener that get notified when the {@link TabModel} changes. Multiple listeners
138 * can be registered at the same time.
139 * @param changeListener The {@link TabModelSelector.ChangeListener} to notify.
141 void registerChangeListener(ChangeListener changeListener);
144 * Unregisters the listener.
145 * @param changeListener The {@link TabModelSelector.ChangeListener} to remove.
147 void unregisterChangeListener(ChangeListener changeListener);
150 * Calls {@link TabModel#commitAllTabClosures()} on all {@link TabModel}s owned by this
153 void commitAllTabClosures();