OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.tabmodel; | 5 package org.chromium.chrome.browser.tabmodel; |
6 | 6 |
7 import android.content.Intent; | 7 import android.content.Intent; |
8 import android.text.TextUtils; | 8 import android.text.TextUtils; |
9 | 9 |
10 import org.chromium.base.SysUtils; | 10 import org.chromium.base.SysUtils; |
11 import org.chromium.base.TraceEvent; | 11 import org.chromium.base.TraceEvent; |
12 import org.chromium.chrome.browser.ChromeActivity; | 12 import org.chromium.chrome.browser.ChromeActivity; |
13 import org.chromium.chrome.browser.IntentHandler; | 13 import org.chromium.chrome.browser.IntentHandler; |
14 import org.chromium.chrome.browser.Tab; | 14 import org.chromium.chrome.browser.Tab; |
15 import org.chromium.chrome.browser.TabState; | 15 import org.chromium.chrome.browser.TabState; |
16 import org.chromium.chrome.browser.UrlUtilities; | 16 import org.chromium.chrome.browser.UrlUtilities; |
17 import org.chromium.chrome.browser.WarmupManager; | 17 import org.chromium.chrome.browser.WarmupManager; |
18 import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; | 18 import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; |
19 import org.chromium.chrome.browser.tab.ChromeTab; | 19 import org.chromium.chrome.browser.tab.ChromeTab; |
20 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 20 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 21 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams; |
| 22 import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParamsManag
er; |
21 import org.chromium.chrome.browser.util.IntentUtils; | 23 import org.chromium.chrome.browser.util.IntentUtils; |
22 import org.chromium.components.service_tab_launcher.ServiceTabLauncher; | 24 import org.chromium.components.service_tab_launcher.ServiceTabLauncher; |
23 import org.chromium.content_public.browser.LoadUrlParams; | 25 import org.chromium.content_public.browser.LoadUrlParams; |
24 import org.chromium.content_public.browser.WebContents; | 26 import org.chromium.content_public.browser.WebContents; |
25 import org.chromium.content_public.common.Referrer; | 27 import org.chromium.content_public.common.Referrer; |
26 import org.chromium.ui.base.PageTransition; | 28 import org.chromium.ui.base.PageTransition; |
27 import org.chromium.ui.base.WindowAndroid; | 29 import org.chromium.ui.base.WindowAndroid; |
28 | 30 |
29 /** | 31 /** |
30 * This class creates various kinds of new tabs and adds them to the right {@lin
k TabModel}. | 32 * This class creates various kinds of new tabs and adds them to the right {@lin
k TabModel}. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 private ChromeTab createNewTab(LoadUrlParams loadUrlParams, TabModel.TabLaun
chType type, | 100 private ChromeTab createNewTab(LoadUrlParams loadUrlParams, TabModel.TabLaun
chType type, |
99 Tab parent, int position, Intent intent) { | 101 Tab parent, int position, Intent intent) { |
100 try { | 102 try { |
101 TraceEvent.begin("ChromeTabCreator.createNewTab"); | 103 TraceEvent.begin("ChromeTabCreator.createNewTab"); |
102 int parentId = parent != null ? parent.getId() : Tab.INVALID_TAB_ID; | 104 int parentId = parent != null ? parent.getId() : Tab.INVALID_TAB_ID; |
103 | 105 |
104 // Sanitize the url. | 106 // Sanitize the url. |
105 loadUrlParams.setUrl(UrlUtilities.fixupUrl(loadUrlParams.getUrl())); | 107 loadUrlParams.setUrl(UrlUtilities.fixupUrl(loadUrlParams.getUrl())); |
106 loadUrlParams.setTransitionType(getTransitionType(type)); | 108 loadUrlParams.setTransitionType(getTransitionType(type)); |
107 | 109 |
108 WebContents webContents = IntentHandler.getWebContentsFromIntent(int
ent); | 110 // Check if the tab is being created asynchronously. |
| 111 int assignedTabId = IntentUtils.safeGetIntExtra( |
| 112 intent, IntentHandler.EXTRA_TAB_ID, Tab.INVALID_TAB_ID); |
| 113 AsyncTabCreationParams asyncParams = |
| 114 AsyncTabCreationParamsManager.remove(assignedTabId); |
| 115 WebContents webContents = asyncParams == null ? null : asyncParams.g
etWebContents(); |
| 116 |
109 boolean openInForeground = mOrderController.willOpenInForeground(typ
e, mIncognito) | 117 boolean openInForeground = mOrderController.willOpenInForeground(typ
e, mIncognito) |
110 || webContents != null; | 118 || webContents != null; |
111 | |
112 ChromeTab tab; | 119 ChromeTab tab; |
113 if (webContents != null) { | 120 if (webContents != null) { |
114 // A WebContents was passed through the Intent. Create a new Ta
b to hold it. | 121 // A WebContents was passed through the Intent. Create a new Ta
b to hold it. |
115 Intent parentIntent = IntentUtils.safeGetParcelableExtra( | 122 Intent parentIntent = IntentUtils.safeGetParcelableExtra( |
116 intent, IntentHandler.EXTRA_PARENT_INTENT); | 123 intent, IntentHandler.EXTRA_PARENT_INTENT); |
117 parentId = IntentUtils.safeGetIntExtra( | 124 parentId = IntentUtils.safeGetIntExtra( |
118 intent, IntentHandler.EXTRA_PARENT_TAB_ID, parentId); | 125 intent, IntentHandler.EXTRA_PARENT_TAB_ID, parentId); |
119 | 126 |
120 tab = ChromeTab.createLiveTab(Tab.INVALID_TAB_ID, mActivity, mIn
cognito, | 127 assert TabModelUtils.getTabIndexById(mTabModel, assignedTabId) |
| 128 == TabModel.INVALID_TAB_INDEX; |
| 129 tab = ChromeTab.createLiveTab(assignedTabId, mActivity, mIncogni
to, |
121 mNativeWindow, type, parentId, !openInForeground); | 130 mNativeWindow, type, parentId, !openInForeground); |
122 tab.initialize(webContents, mTabContentManager, !openInForegroun
d); | 131 tab.initialize(webContents, mTabContentManager, !openInForegroun
d); |
123 tab.setParentIntent(parentIntent); | 132 tab.setParentIntent(parentIntent); |
124 webContents.resumeLoadingCreatedWebContents(); | 133 webContents.resumeLoadingCreatedWebContents(); |
125 } else if (!openInForeground && SysUtils.isLowEndDevice()) { | 134 } else if (!openInForeground && SysUtils.isLowEndDevice()) { |
126 // On low memory devices the tabs opened in background are not l
oaded automatically | 135 // On low memory devices the tabs opened in background are not l
oaded automatically |
127 // to preserve resources (cpu, memory, strong renderer binding)
for the foreground | 136 // to preserve resources (cpu, memory, strong renderer binding)
for the foreground |
128 // tab. | 137 // tab. |
129 tab = ChromeTab.createTabForLazyLoad(mActivity, mIncognito, mNat
iveWindow, type, | 138 tab = ChromeTab.createTabForLazyLoad(mActivity, mIncognito, mNat
iveWindow, type, |
130 parentId, loadUrlParams); | 139 parentId, loadUrlParams); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 * Sets the tab model and tab content manager to use. | 301 * Sets the tab model and tab content manager to use. |
293 * @param model The new {@link TabModel} to use. | 302 * @param model The new {@link TabModel} to use. |
294 * @param manager The new {@link TabContentManager} to use. | 303 * @param manager The new {@link TabContentManager} to use. |
295 */ | 304 */ |
296 public void setTabModel(TabModel model, TabContentManager manager) { | 305 public void setTabModel(TabModel model, TabContentManager manager) { |
297 mTabModel = model; | 306 mTabModel = model; |
298 mTabContentManager = manager; | 307 mTabContentManager = manager; |
299 } | 308 } |
300 | 309 |
301 } | 310 } |
OLD | NEW |