Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / android / java / src / org / chromium / chrome / browser / tabmodel / TabModel.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.chrome.browser.Tab;
8 import org.chromium.chrome.browser.profiles.Profile;
9
10 /**
11  * TabModel organizes all the open tabs and allows you to create new ones. There are two TabModels
12  * in the app at this time: normal and incognito. More could be added to allow for windows or
13  * something.
14  */
15 public interface TabModel extends TabList {
16     /**
17      * A list of the various ways tabs can be launched.
18      */
19     public enum TabLaunchType {
20         FROM_LINK,             // Opened from a link.
21         FROM_EXTERNAL_APP,     // Opened by and external app.
22         FROM_MENU_OR_OVERVIEW, // Opened from the options menu or the tab stack overview.
23         FROM_RESTORE,          // Opened after restoring state from storage.
24         // Opened from the long press menu. Like FROM_MENU but also sets up a parent/child
25         // relationship like FROM_LINK. FOREGROUND and BACKGROUND indicates whether the current tab
26         // should be automatically switched to the new tab or not.
27         FROM_LONGPRESS_FOREGROUND,
28         FROM_LONGPRESS_BACKGROUND,
29         FROM_INSTANT,          // Tab was created by instant.
30         FROM_KEYBOARD          // Opened from a physical keyboard via shortcut.
31     }
32
33     /**
34      * A list of the various ways tabs can eb selected.
35      */
36     public enum TabSelectionType {
37         FROM_CLOSE, // Selection of adjacent tab when the active tab is closed in foreground.
38         FROM_EXIT,  // Selection of adjacent tab when the active tab is closed upon app exit.
39         FROM_NEW,   // Selection of newly created tab (e.g. for a url intent or NTP).
40         FROM_USER   // User-originated switch to existing tab or selection of main tab on app
41                     // startup.
42     }
43
44     /**
45      * @return The profile associated with the current model.
46      */
47     public Profile getProfile();
48
49     /**
50      * Unregisters and destroys the specified tab, and then switches to the previous tab.
51      * @param tab The non-null tab to close
52      * @return true if the tab was found
53      */
54     public boolean closeTab(Tab tab);
55
56     /**
57      * Unregisters and destroys the specified tab, and then switches to the previous tab.
58      *
59      * @param tab The non-null tab to close
60      * @param animate true iff the closing animation should be displayed
61      * @param uponExit true iff the tab is being closed upon application exit (after user presses
62      *                 the system back button)
63      * @param canUndo Whether or not this action can be undone. If this is {@code true} and
64      *                {@link #supportsPendingClosures()} is {@code true}, this {@link Tab}
65      *                will not actually be closed until {@link #commitTabClosure(int)} or
66      *                {@link #commitAllTabClosures()} is called, but it will be effectively removed
67      *                from this list. To get a comprehensive list of all tabs, including ones that
68      *                have been partially closed, use the {@link TabList} from
69      *                {@link #getComprehensiveModel()}.
70      * @return true if the tab was found
71      */
72     public boolean closeTab(Tab tab, boolean animate, boolean uponExit, boolean canUndo);
73
74     /**
75      * Returns which tab would be selected if the specified tab {@code id} were closed.
76      * @param id The ID of tab which would be closed.
77      * @return The id of the next tab that would be visible.
78      */
79     public Tab getNextTabIfClosed(int id);
80
81     /**
82      * Close all the tabs on this model.
83      */
84     public void closeAllTabs();
85
86     /**
87      * Close all tabs on this model. If allowDelegation is true, the model has the option
88      * of not closing all tabs and delegating the closure to another class.
89      * @param allowDelegation true iff the model may delegate the close all request.
90      *                        false iff the model must close all tabs.
91      * @param uponExit true iff the tabs are being closed upon application exit (after user presses
92      *                 the system back button)
93      */
94     public void closeAllTabs(boolean allowDelegation, boolean uponExit);
95
96     /**
97      * @return Whether or not this model supports pending closures.
98      */
99     public boolean supportsPendingClosures();
100
101     /**
102      * Commits all pending closures, closing all tabs that had a chance to be undone.
103      */
104     public void commitAllTabClosures();
105
106     /**
107      * Commits a pending closure specified by {@code tabId}.
108      * @param tabId The id of the {@link Tab} to commit the pending closure.
109      */
110     public void commitTabClosure(int tabId);
111
112     /**
113      * Cancels a pending {@link Tab} closure, bringing the tab back into this model.  Note that this
114      * will select the rewound {@link Tab}.
115      * @param tabId The id of the {@link Tab} to undo.
116      */
117     public void cancelTabClosure(int tabId);
118
119     /**
120      * @return The complete {@link TabList} this {@link TabModel} represents.  Note that this may
121      *         be different than this actual {@link TabModel} if it supports pending closures
122      *         {@link #supportsPendingClosures()}, as this will include all pending closure tabs.
123      */
124     public TabList getComprehensiveModel();
125
126     /**
127      * Selects a tab by its index.
128      * @param i    The index of the tab to select.
129      * @param type The type of selection.
130      */
131     public void setIndex(int i, final TabSelectionType type);
132
133     /**
134      * Moves a tab to a new index.
135      * @param id       The id of the tab to move.
136      * @param newIndex The new place to put the tab.
137      */
138     public void moveTab(int id, int newIndex);
139
140     /**
141      * To be called when this model should be destroyed.  The model should no longer be used after
142      * this.
143      */
144     public void destroy();
145
146     /**
147      * Adds a newly created tab to this model.
148      * @param tab   The tab to be added.
149      * @param index The index where the tab should be inserted. The model may override the index.
150      * @param type  How the tab was opened.
151      */
152     void addTab(Tab tab, int index, TabLaunchType type);
153
154     /**
155      * Subscribes a {@link TabModelObserver} to be notified about changes to this model.
156      * @param observer The observer to be subscribed.
157      */
158     void addObserver(TabModelObserver observer);
159
160     /**
161      * Unsubscribes a previously subscribed {@link TabModelObserver}.
162      * @param observer The observer to be unsubscribed.
163      */
164     void removeObserver(TabModelObserver observer);
165 }