Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / android / java / src / org / chromium / chrome / browser / tabmodel / TabModelSelector.java
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.
4
5 package org.chromium.chrome.browser.tabmodel;
6
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;
11
12 import java.util.List;
13
14 /**
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
17  * be using.
18  */
19 public interface TabModelSelector {
20     /**
21      * Interface of listener that get notified on changes in the {@link TabModel}s.
22      */
23     public interface ChangeListener {
24         /**
25          * Called whenever the {@link TabModel} has changed.
26          */
27         void onChange();
28
29         /**
30          * Called when a new tab is created.
31          */
32         void onNewTabCreated(Tab tab);
33     }
34
35     /**
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.
38      */
39     void selectModel(boolean incognito);
40
41     /**
42      * Get a specific tab model
43      * @return Never returns null.  Returns a stub when real model is uninitialized.
44      */
45     TabModel getModel(boolean incognito);
46
47     /**
48      * @return a list for the underlying models
49      */
50     List<TabModel> getModels();
51
52     /**
53      * @return the model at {@code index} or null if no model exist for that index.
54      */
55     @VisibleForTesting
56     TabModel getModelAt(int index);
57
58     /**
59      * Get the current tab model.
60      * @return Never returns null.  Returns a stub when real model is uninitialized.
61      */
62     TabModel getCurrentModel();
63
64     /**
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.
67      */
68     Tab getCurrentTab();
69
70     /**
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.
74      */
75     int getCurrentTabId();
76
77     /**
78      * Convenience function to get the {@link TabModel} for a {@link Tab} specified by
79      * {@code id}.
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}.
82      */
83     TabModel getModelForTabId(int id);
84
85     /**
86      * @return The index of the current {@link TabModel}.
87      */
88     int getCurrentModelIndex();
89
90     /**
91      * @return If the incognito {@link TabModel} is current.
92      */
93     boolean isIncognitoSelected();
94
95     /**
96      * Opens a new tab.
97      *
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.
103      */
104     Tab openNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent, boolean incognito);
105
106     /**
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
110      */
111     boolean closeTab(Tab tab);
112
113     /**
114      * Close all tabs across all tab models
115      */
116     void closeAllTabs();
117
118     /**
119      * Get total tab count across all tab models
120      */
121     int getTotalTabCount();
122
123     /**
124      * Search all TabModels for a tab with the specified id.
125      * @return specified tab or null if tab is not found
126      */
127     Tab getTabById(int id);
128
129     /**
130      * Registers a listener that get notified when the {@link TabModel} changes. Multiple listeners
131      * can be registered at the same time.
132      * @param changeListener The {@link TabModelSelector.ChangeListener} to notify.
133      */
134     void registerChangeListener(ChangeListener changeListener);
135
136     /**
137      * Unregisters the listener.
138      * @param changeListener The {@link TabModelSelector.ChangeListener} to remove.
139      */
140     void unregisterChangeListener(ChangeListener changeListener);
141
142     /**
143      * Calls {@link TabModel#commitAllTabClosures()} on all {@link TabModel}s owned by this
144      * selector.
145      */
146     void commitAllTabClosures();
147 }