Commit a918d71e authored by wnwen's avatar wnwen Committed by Commit bot

Minor cleanup of launching document tabs.

BUG=612245,509886

Review-Url: https://codereview.chromium.org/2021913002
Cr-Commit-Position: refs/heads/master@{#396912}
parent c192fbb4
......@@ -8,7 +8,6 @@ import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import org.chromium.chrome.browser.document.DocumentMetricIds;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams;
......@@ -51,11 +50,6 @@ public class ChromeServiceTabLauncher extends ServiceTabLauncher {
// If we do not find a WebappDataStorage corresponding to this URL, or if it hasn't
// been opened recently enough, open the URL in a tab.
if (storage == null || !storage.wasLaunchedRecently()) {
// TODO(peter): Determine the intent source based on the |disposition| with
// which the tab is being launched. Right now this is gated by a check in the
// native implementation.
int intentSource = DocumentMetricIds.STARTED_BY_WINDOW_OPEN;
LoadUrlParams loadUrlParams = new LoadUrlParams(url, PageTransition.LINK);
loadUrlParams.setPostData(postData);
loadUrlParams.setVerbatimHeaders(extraHeaders);
......@@ -63,8 +57,6 @@ public class ChromeServiceTabLauncher extends ServiceTabLauncher {
AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(loadUrlParams,
requestId);
asyncParams.setDocumentStartedBy(intentSource);
tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHROME_UI,
Tab.INVALID_TAB_ID);
} else {
......
......@@ -79,15 +79,6 @@ public class ChromeLauncherActivity extends Activity
private static final String TAG = "document_CLActivity";
/** New instance should be launched in the foreground. */
public static final int LAUNCH_MODE_FOREGROUND = 0;
/** New instance should be launched as an affiliated task. */
public static final int LAUNCH_MODE_AFFILIATED = 1;
/** Existing instance should be retargetted, if possible. */
public static final int LAUNCH_MODE_RETARGET = 2;
private static final int FIRST_RUN_EXPERIENCE_REQUEST_CODE = 101;
/**
......
......@@ -15,8 +15,8 @@ import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.document.ActivityDelegate;
/**
* Deprected class for running Chrome in document mode. Kept around to force users into the correct
* {@link Activity}.
* Deprecated class for running Chrome in document mode. Kept around to force users into the
* correct {@link Activity}.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class DocumentActivity extends ChromeActivity {
......
// 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.document;
/**
* IDs for metrics tracking Document-mode actions.
*/
public class DocumentMetricIds {
// DocumentActivity.StartedBy (sparse)
public static final int STARTED_BY_UNKNOWN = 0;
public static final int STARTED_BY_LAUNCHER = 1;
public static final int STARTED_BY_ACTIVITY_RESTARTED = 2;
public static final int STARTED_BY_ACTIVITY_BROUGHT_TO_FOREGROUND = 3;
public static final int STARTED_BY_CHROME_HOME_MOST_VISITED = 100;
public static final int STARTED_BY_CHROME_HOME_BOOKMARK = 101;
public static final int STARTED_BY_CHROME_HOME_RECENT_TABS = 102;
public static final int STARTED_BY_WINDOW_OPEN = 200;
public static final int STARTED_BY_CONTEXT_MENU = 201;
public static final int STARTED_BY_OPTIONS_MENU = 202;
public static final int STARTED_BY_SEARCH_RESULT_PAGE = 300;
public static final int STARTED_BY_SEARCH_SUGGESTION_EXTERNAL = 301;
public static final int STARTED_BY_SEARCH_SUGGESTION_CHROME = 302;
// Please reserve 4xx for STARTED_BY_EXTERNAL_APP_
public static final int STARTED_BY_EXTERNAL_APP_GMAIL = 400;
public static final int STARTED_BY_EXTERNAL_APP_FACEBOOK = 401;
public static final int STARTED_BY_EXTERNAL_APP_PLUS = 402;
public static final int STARTED_BY_EXTERNAL_APP_TWITTER = 403;
public static final int STARTED_BY_EXTERNAL_APP_CHROME = 404;
public static final int STARTED_BY_EXTERNAL_APP_OTHER = 405;
public static final int STARTED_BY_EXTERNAL_APP_HANGOUTS = 406;
public static final int STARTED_BY_EXTERNAL_APP_MESSENGER = 407;
public static final int STARTED_BY_EXTERNAL_APP_NEWS = 408;
public static final int STARTED_BY_EXTERNAL_APP_LINE = 409;
public static final int STARTED_BY_EXTERNAL_APP_WHATSAPP = 410;
public static final int STARTED_BY_EXTERNAL_APP_GSA = 411;
public static final int STARTED_BY_CONTEXTUAL_SEARCH = 500;
}
......@@ -20,7 +20,6 @@ import android.util.Log;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.document.ActivityDelegate;
import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelImpl;
import java.util.ArrayList;
......@@ -33,38 +32,6 @@ import java.util.List;
public class DocumentUtils {
public static final String TAG = "DocumentUtilities";
/**
* Finishes tasks other than the one with the given task ID that were started with the given
* tabId, leaving a unique task to own a Tab with that particular ID.
* @param tabId ID of the tab to remove duplicates for.
* @param canonicalTaskId ID of the task will be the only one left with the ID.
* @return Intent of one of the tasks that were finished.
*/
public static Intent finishOtherTasksWithTabID(int tabId, int canonicalTaskId) {
if (tabId == Tab.INVALID_TAB_ID || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return null;
}
Context context = ContextUtils.getApplicationContext();
ActivityManager manager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.AppTask> tasksToFinish = new ArrayList<ActivityManager.AppTask>();
for (ActivityManager.AppTask task : manager.getAppTasks()) {
RecentTaskInfo taskInfo = getTaskInfoFromTask(task);
if (taskInfo == null) continue;
int taskId = taskInfo.id;
Intent baseIntent = taskInfo.baseIntent;
int otherTabId = ActivityDelegate.getTabIdFromIntent(baseIntent);
if (otherTabId == tabId && (taskId == -1 || taskId != canonicalTaskId)) {
tasksToFinish.add(task);
}
}
return finishAndRemoveTasks(tasksToFinish);
}
/**
* Finishes tasks other than the one with the given ID that were started with the given data
* in the Intent, removing those tasks from Recents and leaving a unique task with the data.
......
......@@ -6,8 +6,8 @@ package org.chromium.chrome.browser.tabmodel.document;
import android.content.Intent;
import org.chromium.chrome.browser.ChromeServiceTabLauncher;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.document.DocumentMetricIds;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.AsyncTabParams;
import org.chromium.content_public.browser.LoadUrlParams;
......@@ -30,15 +30,6 @@ public class AsyncTabCreationParams implements AsyncTabParams {
/** The tab launch request ID from the {@link ChromeServiceTabLauncher}. **/
private final Integer mRequestId;
/** How to start a {@link DocumentTab}. */
private int mDocumentLaunchMode = ChromeLauncherActivity.LAUNCH_MODE_FOREGROUND;
/** What caused a {@link DocumentTab} to be created. */
private int mDocumentStartedBy = DocumentMetricIds.STARTED_BY_UNKNOWN;
/** Whether or not the {@link WebContents} should be initially hidden. */
private boolean mIsAffiliated;
/** Create parameters for creating a Tab asynchronously. */
public AsyncTabCreationParams(LoadUrlParams loadUrlParams) {
this(loadUrlParams, null, null, null);
......@@ -62,22 +53,6 @@ public class AsyncTabCreationParams implements AsyncTabParams {
assert requestId != null;
}
public void setDocumentLaunchMode(int launchMode) {
mDocumentLaunchMode = launchMode;
}
public void setDocumentStartedBy(int startedBy) {
mDocumentStartedBy = startedBy;
}
public int getDocumentLaunchMode() {
return mDocumentLaunchMode;
}
public int getDocumentStartedBy() {
return mDocumentStartedBy;
}
@Override
public LoadUrlParams getLoadUrlParams() {
return mLoadUrlParams;
......@@ -98,14 +73,6 @@ public class AsyncTabCreationParams implements AsyncTabParams {
return mWebContents;
}
public void setIsAffiliated(boolean isAffiliated) {
mIsAffiliated = isAffiliated;
}
public boolean isAffiliated() {
return mIsAffiliated;
}
private AsyncTabCreationParams(LoadUrlParams loadUrlParams, Intent originalIntent,
WebContents webContents, Integer requestId) {
assert loadUrlParams != null;
......
......@@ -7,15 +7,12 @@ package org.chromium.chrome.browser.tabmodel.document;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.TabState;
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.multiwindow.MultiWindowUtils;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabIdManager;
......@@ -60,29 +57,11 @@ public class TabDelegate extends TabCreator {
@Override
public boolean createTabWithWebContents(Tab parent, WebContents webContents, int parentId,
TabLaunchType type, String url) {
return createTabWithWebContents(
webContents, parentId, type, url, DocumentMetricIds.STARTED_BY_WINDOW_OPEN);
}
/**
* Creates a Tab to host the given WebContents asynchronously.
* @param webContents WebContents that has been pre-created.
* @param parentId ID of the parent Tab.
* @param type Launch type for the Tab.
* @param url URL that the WebContents was opened for.
* @param startedBy See {@link DocumentMetricIds}.
*/
public boolean createTabWithWebContents(
WebContents webContents, int parentId, TabLaunchType type, String url, int startedBy) {
if (url == null) url = "";
// 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;
AsyncTabCreationParams asyncParams =
new AsyncTabCreationParams(new LoadUrlParams(url, pageTransition), webContents);
asyncParams.setDocumentStartedBy(startedBy);
new AsyncTabCreationParams(
new LoadUrlParams(url, PageTransition.AUTO_TOPLEVEL), webContents);
createNewTab(asyncParams, type, parentId);
return true;
}
......@@ -117,32 +96,6 @@ public class TabDelegate extends TabCreator {
@Override
public Tab createNewTab(LoadUrlParams loadUrlParams, TabLaunchType type, Tab parent) {
AsyncTabCreationParams asyncParams = new AsyncTabCreationParams(loadUrlParams);
// Figure out how the page will be launched.
if (TextUtils.equals(UrlConstants.NTP_URL, loadUrlParams.getUrl())) {
asyncParams.setDocumentLaunchMode(ChromeLauncherActivity.LAUNCH_MODE_RETARGET);
} else if (type == TabLaunchType.FROM_LONGPRESS_BACKGROUND) {
if (!parent.isIncognito() && mIsIncognito) {
// Incognito tabs opened from regular tabs open in the foreground for privacy
// concerns.
asyncParams.setDocumentLaunchMode(ChromeLauncherActivity.LAUNCH_MODE_FOREGROUND);
} else {
asyncParams.setDocumentLaunchMode(ChromeLauncherActivity.LAUNCH_MODE_AFFILIATED);
}
}
// Classify the startup type.
if (parent != null && TextUtils.equals(UrlConstants.NTP_URL, parent.getUrl())) {
asyncParams.setDocumentStartedBy(
DocumentMetricIds.STARTED_BY_CHROME_HOME_MOST_VISITED);
} else if (type == TabLaunchType.FROM_LONGPRESS_BACKGROUND
|| type == TabLaunchType.FROM_LONGPRESS_FOREGROUND) {
asyncParams.setDocumentStartedBy(DocumentMetricIds.STARTED_BY_CONTEXT_MENU);
} else if (type == TabLaunchType.FROM_CHROME_UI) {
asyncParams.setDocumentStartedBy(DocumentMetricIds.STARTED_BY_OPTIONS_MENU);
}
// Tab is created aysnchronously. Can't return anything, yet.
createNewTab(asyncParams, type, parent == null ? Tab.INVALID_TAB_ID : parent.getId());
return null;
}
......@@ -162,8 +115,7 @@ public class TabDelegate extends TabCreator {
&& asyncParams.getWebContents() != null);
Intent intent = createNewTabIntent(asyncParams, parentId);
IntentHandler.startActivityForTrustedIntent(
intent, ContextUtils.getApplicationContext());
IntentHandler.startActivityForTrustedIntent(intent, ContextUtils.getApplicationContext());
}
private Intent createNewTabIntent(AsyncTabCreationParams asyncParams, int parentId) {
......
......@@ -268,7 +268,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/document/ChromeLauncherActivity.java",
"java/src/org/chromium/chrome/browser/document/CipherKeyActivity.java",
"java/src/org/chromium/chrome/browser/document/DocumentActivity.java",
"java/src/org/chromium/chrome/browser/document/DocumentMetricIds.java",
"java/src/org/chromium/chrome/browser/document/DocumentUtils.java",
"java/src/org/chromium/chrome/browser/document/DocumentWebContentsDelegate.java",
"java/src/org/chromium/chrome/browser/document/IncognitoDocumentActivity.java",
......
......@@ -10,7 +10,6 @@ import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams;
import org.chromium.chrome.browser.tabmodel.document.TabDelegate;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.WebContents;
/**
* Mocks out calls to get Tabs for the DocumentTabModel.
......@@ -30,12 +29,6 @@ public class MockTabDelegate extends TabDelegate {
return null;
}
@Override
public boolean createTabWithWebContents(
WebContents webContents, int parentId, TabLaunchType type, String url, int startedBy) {
return false;
}
@Override
public Tab launchUrl(String url, TabLaunchType type) {
return null;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment