1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.tabmodel;
import org.chromium.base.TraceEvent;
import org.chromium.chrome.browser.TabState;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.WebContents;
/**
* An interface to return a {@link TabCreator} either for regular or incognito tabs.
*/
public interface TabCreatorManager {
/**
* Creates Tabs. If the TabCreator creates Tabs asynchronously, null pointers will be returned
* everywhere instead of a Tab.
*
* TODO(dfalcantara): Hunt down more places where we don't actually need to return a Tab.
*/
public abstract class TabCreator {
/**
* @return Whether the TabCreator creates Tabs asynchronously.
*/
public abstract boolean createsTabsAsynchronously();
/**
* Creates a new tab and posts to UI.
* @param loadUrlParams parameters of the url load.
* @param type Information about how the tab was launched.
* @param parent the parent tab, if present.
* @return The new tab.
*/
public abstract Tab createNewTab(
LoadUrlParams loadUrlParams, TabModel.TabLaunchType type, Tab parent);
/**
* On restore, allows us to create a frozen version of a tab using saved tab state we read
* from disk.
* @param state The tab state that the tab can be restored from.
* @param id The id to give the new tab.
* @param index The index for where to place the tab.
*/
public abstract Tab createFrozenTab(TabState state, int id, int index);
/**
* Creates a new tab and loads the specified URL in it. This is a convenience method for
* {@link #createNewTab} with the default {@link LoadUrlParams} and no parent tab.
*
* @param url the URL to open.
* @param type the type of action that triggered that launch. Determines how the tab is
* opened (for example, in the foreground or background).
* @return the created tab.
*/
public abstract Tab launchUrl(String url, TabModel.TabLaunchType type);
/**
* Creates a Tab to host the given WebContents.
* @param parent The parent tab, if present.
* @param webContents The web contents to create a tab around.
* @param parentId The id of the parent tab.
* @param type The TabLaunchType describing how this tab was created.
* @param url URL to show in the Tab. (Needed only for asynchronous tab creation.)
* @return Whether a Tab was created successfully.
*/
public abstract boolean createTabWithWebContents(Tab parent, WebContents webContents,
int parentId, TabLaunchType type, String url);
/**
* Creates a tab around the native web contents pointer.
* @param parent The parent tab, if present.
* @param webContents The web contents to create a tab around.
* @param parentId The id of the parent tab.
* @param type The TabLaunchType describing how this tab was created.
* @return Whether a Tab was created successfully.
*/
public final boolean createTabWithWebContents(Tab parent,
WebContents webContents, int parentId, TabLaunchType type) {
return createTabWithWebContents(parent, webContents, parentId, type,
webContents.getUrl());
}
/**
* Creates a new tab and loads the NTP.
*/
public final void launchNTP() {
try {
TraceEvent.begin("TabCreator.launchNTP");
launchUrl(UrlConstants.NTP_URL, TabModel.TabLaunchType.FROM_CHROME_UI);
} finally {
TraceEvent.end("TabCreator.launchNTP");
}
}
}
/**
* @return A {@link TabCreator} that will create either regular or incognito tabs.
* @param incognito True if the method should return the TabCreator for incognito tabs, false
* for regular tabs.
*/
TabCreator getTabCreator(boolean incognito);
}
|