Index: chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java |
index 39a0b3549dff443f46c225c0c16fc7f08f1e0640..d9e905caf765baca4114fdaf5d461407ff2631de 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/document/TabDelegate.java |
@@ -19,6 +19,7 @@ import org.chromium.chrome.browser.UrlConstants; |
import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
import org.chromium.chrome.browser.document.DocumentMetricIds; |
import org.chromium.chrome.browser.tab.ChromeTab; |
+import org.chromium.chrome.browser.tab.TabIdManager; |
import org.chromium.chrome.browser.tabmodel.TabCreatorManager.TabCreator; |
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
import org.chromium.chrome.browser.util.FeatureUtilities; |
@@ -29,8 +30,6 @@ import org.chromium.ui.base.PageTransition; |
import java.lang.ref.WeakReference; |
-import javax.annotation.Nullable; |
- |
/** |
* Asynchronously creates Tabs by creating/starting up Activities. |
*/ |
@@ -78,42 +77,16 @@ public class TabDelegate extends TabCreator { |
*/ |
public boolean createTabWithWebContents( |
WebContents webContents, int parentId, TabLaunchType type, String url, int startedBy) { |
- // Tabs can't be launched in affiliated mode when a webcontents exists. |
- assert type != TabLaunchType.FROM_LONGPRESS_BACKGROUND; |
- |
if (url == null) url = ""; |
- Context context = ApplicationStatus.getApplicationContext(); |
+ // TODO(dfalcantara): Does this transition make sense? (crbug.com/509886) |
int pageTransition = startedBy == DocumentMetricIds.STARTED_BY_CHROME_HOME_RECENT_TABS |
? PageTransition.RELOAD : PageTransition.AUTO_TOPLEVEL; |
- Activity parentActivity = getActivityForTabId(parentId); |
- |
- if (FeatureUtilities.isDocumentMode(context)) { |
- AsyncTabCreationParams asyncParams = |
- new AsyncTabCreationParams(new LoadUrlParams(url, pageTransition), webContents); |
- asyncParams.setDocumentStartedBy(startedBy); |
- ChromeLauncherActivity.launchDocumentInstance( |
- parentActivity, mIsIncognito, asyncParams); |
- } else { |
- // TODO(dfalcantara): Unify the document-mode path with this path so that both go |
- // through the ChromeLauncherActivity via an Intent. |
- Intent tabbedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
- tabbedIntent.setClass(context, ChromeLauncherActivity.class); |
- tabbedIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, mIsIncognito); |
- tabbedIntent.putExtra(IntentHandler.EXTRA_WEB_CONTENTS, webContents); |
- tabbedIntent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, pageTransition); |
- tabbedIntent.putExtra(IntentHandler.EXTRA_PARENT_TAB_ID, parentId); |
- |
- if (parentActivity != null && parentActivity.getIntent() != null) { |
- tabbedIntent.putExtra( |
- IntentHandler.EXTRA_PARENT_INTENT, parentActivity.getIntent()); |
- } |
- |
- tabbedIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
- IntentHandler.startActivityForTrustedIntent(tabbedIntent, context); |
- } |
- |
+ AsyncTabCreationParams asyncParams = |
+ new AsyncTabCreationParams(new LoadUrlParams(url, pageTransition), webContents); |
+ asyncParams.setDocumentStartedBy(startedBy); |
+ createNewTab(asyncParams, type, parentId); |
return true; |
} |
@@ -151,7 +124,7 @@ public class TabDelegate extends TabCreator { |
} |
// Tab is created aysnchronously. Can't return anything, yet. |
- createNewTab(asyncParams, type, parent); |
+ createNewTab(asyncParams, type, parent == null ? Tab.INVALID_TAB_ID : parent.getId()); |
return null; |
} |
@@ -159,30 +132,36 @@ public class TabDelegate extends TabCreator { |
* Creates a Tab to host the given WebContents asynchronously. |
* @param asyncParams Parameters to create the Tab with, including the URL. |
* @param type Information about how the tab was launched. |
- * @param parent The parent tab, if it exists. |
+ * @param parentId ID of the parent tab, if it exists. |
*/ |
public void createNewTab( |
- AsyncTabCreationParams asyncParams, TabLaunchType type, @Nullable Tab parent) { |
+ AsyncTabCreationParams asyncParams, TabLaunchType type, int parentId) { |
assert asyncParams != null; |
- if (FeatureUtilities.isDocumentMode(ApplicationStatus.getApplicationContext())) { |
+ // Tabs should't be launched in affiliated mode when a webcontents exists. |
+ assert !(type == TabLaunchType.FROM_LONGPRESS_BACKGROUND |
+ && asyncParams.getWebContents() != null); |
+ |
+ Context context = ApplicationStatus.getApplicationContext(); |
+ Activity parentActivity = getActivityForTabId(parentId); |
+ |
+ if (FeatureUtilities.isDocumentMode(context)) { |
ChromeLauncherActivity.launchDocumentInstance( |
- getActivityFromTab(parent), mIsIncognito, asyncParams); |
+ parentActivity, mIsIncognito, asyncParams); |
} else { |
- // TODO(dfalcantara): Start parceling all of the LoadUrlParams when ChromeTabbedActivity |
- // can use them. Use the same non-duplication mechanism as the |
- // WebContents so that they don't get reused across process restarts. |
- Context context = ApplicationStatus.getApplicationContext(); |
+ // TODO(dfalcantara): Is it possible to get rid of this conditional? |
+ int assignedTabId = TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID); |
+ AsyncTabCreationParamsManager.add(assignedTabId, asyncParams); |
Intent intent = new Intent( |
Intent.ACTION_VIEW, Uri.parse(asyncParams.getLoadUrlParams().getUrl())); |
intent.setClass(context, ChromeLauncherActivity.class); |
+ intent.putExtra(IntentHandler.EXTRA_TAB_ID, assignedTabId); |
intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, mIsIncognito); |
- intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, |
- asyncParams.getLoadUrlParams().getTransitionType()); |
+ intent.putExtra(IntentHandler.EXTRA_PARENT_TAB_ID, parentId); |
- if (parent != null) { |
- intent.putExtra(IntentHandler.EXTRA_PARENT_TAB_ID, parent.getId()); |
+ if (parentActivity != null && parentActivity.getIntent() != null) { |
+ intent.putExtra(IntentHandler.EXTRA_PARENT_INTENT, parentActivity.getIntent()); |
} |
if (asyncParams.getRequestId() != null) { |
@@ -195,11 +174,6 @@ public class TabDelegate extends TabCreator { |
} |
} |
- private Activity getActivityFromTab(Tab tab) { |
- return tab == null || tab.getWindowAndroid() == null |
- ? null : tab.getWindowAndroid().getActivity().get(); |
- } |
- |
/** @return Running Activity that owns the given Tab, null if the Activity couldn't be found. */ |
private Activity getActivityForTabId(int id) { |
if (id == Tab.INVALID_TAB_ID) return null; |