Commit 267017bd authored by qinmin's avatar qinmin Committed by Commit bot

If tab is created from chrome UI, don't mark the tab as external app

All tabs created by TabDelegate.createNewTab() are treated as from external
apps.
However, if the tab was created from Chrome's own UI, we shouldn't do
this.
Otherwise, clicking the back button will dismiss the Chrome app.
This change also passes the header String when creating a new tab.
This allows Chrome UI to create tabs with correct header Strings.

BUG=637239

Review-Url: https://codereview.chromium.org/2319143004
Cr-Commit-Position: refs/heads/master@{#417204}
parent 7dbeb9e5
...@@ -1215,7 +1215,6 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode ...@@ -1215,7 +1215,6 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
// - we decided to close the tab, but it was opened by an external app, so we will go // - we decided to close the tab, but it was opened by an external app, so we will go
// exit Chrome on top of closing the tab // exit Chrome on top of closing the tab
final boolean minimizeApp = !shouldCloseTab || currentTab.isCreatedForExternalApp(); final boolean minimizeApp = !shouldCloseTab || currentTab.isCreatedForExternalApp();
if (minimizeApp) { if (minimizeApp) {
if (shouldCloseTab) { if (shouldCloseTab) {
recordBackPressedUma("Minimized and closed tab", BACK_PRESSED_MINIMIZED_TAB_CLOSED); recordBackPressedUma("Minimized and closed tab", BACK_PRESSED_MINIMIZED_TAB_CLOSED);
...@@ -1293,12 +1292,15 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode ...@@ -1293,12 +1292,15 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false); IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false);
boolean fromLauncherShortcut = IntentUtils.safeGetBooleanExtra( boolean fromLauncherShortcut = IntentUtils.safeGetBooleanExtra(
intent, IntentHandler.EXTRA_INVOKED_FROM_SHORTCUT, false); intent, IntentHandler.EXTRA_INVOKED_FROM_SHORTCUT, false);
return getTabCreator(isIncognito).launchUrl( LoadUrlParams loadUrlParams = new LoadUrlParams(url);
url, loadUrlParams.setIntentReceivedTimestamp(mIntentHandlingTimeMs);
loadUrlParams.setVerbatimHeaders(headers);
return getTabCreator(isIncognito).createNewTab(
loadUrlParams,
fromLauncherShortcut ? TabLaunchType.FROM_EXTERNAL_APP fromLauncherShortcut ? TabLaunchType.FROM_EXTERNAL_APP
: TabLaunchType.FROM_LINK, : TabLaunchType.FROM_LINK,
intent, null,
mIntentHandlingTimeMs); intent);
} else { } else {
return getTabCreator(false).launchUrlFromExternalApp(url, referer, headers, return getTabCreator(false).launchUrlFromExternalApp(url, referer, headers,
externalAppId, forceNewTab, intent, mIntentHandlingTimeMs); externalAppId, forceNewTab, intent, mIntentHandlingTimeMs);
......
...@@ -181,7 +181,7 @@ public class OfflinePageDownloadBridge implements DownloadServiceDelegate, Offli ...@@ -181,7 +181,7 @@ public class OfflinePageDownloadBridge implements DownloadServiceDelegate, Offli
? new AsyncTabCreationParams(params) ? new AsyncTabCreationParams(params)
: new AsyncTabCreationParams(params, componentName); : new AsyncTabCreationParams(params, componentName);
final TabDelegate tabDelegate = new TabDelegate(false); final TabDelegate tabDelegate = new TabDelegate(false);
tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_LINK, Tab.INVALID_TAB_ID); tabDelegate.createNewTab(asyncParams, TabLaunchType.FROM_CHROME_UI, Tab.INVALID_TAB_ID);
} }
/** /**
......
...@@ -80,7 +80,7 @@ public class ChromeTabCreator extends TabCreatorManager.TabCreator { ...@@ -80,7 +80,7 @@ public class ChromeTabCreator extends TabCreatorManager.TabCreator {
* @param intent the source of the url if it isn't null. * @param intent the source of the url if it isn't null.
* @return The new tab. * @return The new tab.
*/ */
private Tab createNewTab(LoadUrlParams loadUrlParams, TabModel.TabLaunchType type, public Tab createNewTab(LoadUrlParams loadUrlParams, TabModel.TabLaunchType type,
Tab parent, Intent intent) { Tab parent, Intent intent) {
// If parent is in the same tab model, place the new tab next to it. // If parent is in the same tab model, place the new tab next to it.
int position = TabModel.INVALID_TAB_INDEX; int position = TabModel.INVALID_TAB_INDEX;
......
...@@ -81,7 +81,8 @@ public class TabDelegate extends TabCreator { ...@@ -81,7 +81,8 @@ public class TabDelegate extends TabCreator {
*/ */
public void createTabInOtherWindow(LoadUrlParams loadUrlParams, Activity activity, public void createTabInOtherWindow(LoadUrlParams loadUrlParams, Activity activity,
int parentId) { int parentId) {
Intent intent = createNewTabIntent(new AsyncTabCreationParams(loadUrlParams), parentId); Intent intent = createNewTabIntent(
new AsyncTabCreationParams(loadUrlParams), parentId, false);
Class<? extends Activity> targetActivity = Class<? extends Activity> targetActivity =
MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(activity); MultiWindowUtils.getInstance().getOpenInOtherWindowActivity(activity);
...@@ -117,11 +118,13 @@ public class TabDelegate extends TabCreator { ...@@ -117,11 +118,13 @@ public class TabDelegate extends TabCreator {
assert !(type == TabLaunchType.FROM_LONGPRESS_BACKGROUND assert !(type == TabLaunchType.FROM_LONGPRESS_BACKGROUND
&& asyncParams.getWebContents() != null); && asyncParams.getWebContents() != null);
Intent intent = createNewTabIntent(asyncParams, parentId); Intent intent = createNewTabIntent(
asyncParams, parentId, type == TabLaunchType.FROM_CHROME_UI);
IntentHandler.startActivityForTrustedIntent(intent, ContextUtils.getApplicationContext()); IntentHandler.startActivityForTrustedIntent(intent, ContextUtils.getApplicationContext());
} }
private Intent createNewTabIntent(AsyncTabCreationParams asyncParams, int parentId) { private Intent createNewTabIntent(
AsyncTabCreationParams asyncParams, int parentId, boolean isChromeUI) {
int assignedTabId = TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID); int assignedTabId = TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID);
AsyncTabParamsManager.add(assignedTabId, asyncParams); AsyncTabParamsManager.add(assignedTabId, asyncParams);
...@@ -148,6 +151,12 @@ public class TabDelegate extends TabCreator { ...@@ -148,6 +151,12 @@ public class TabDelegate extends TabCreator {
intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, mIsIncognito); intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, mIsIncognito);
intent.putExtra(IntentHandler.EXTRA_PARENT_TAB_ID, parentId); intent.putExtra(IntentHandler.EXTRA_PARENT_TAB_ID, parentId);
if (isChromeUI) {
intent.putExtra(Browser.EXTRA_APPLICATION_ID,
ContextUtils.getApplicationContext().getPackageName());
intent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
}
Activity parentActivity = ActivityDelegate.getActivityForTabId(parentId); Activity parentActivity = ActivityDelegate.getActivityForTabId(parentId);
if (parentActivity != null && parentActivity.getIntent() != null) { if (parentActivity != null && parentActivity.getIntent() != null) {
intent.putExtra(IntentHandler.EXTRA_PARENT_INTENT, parentActivity.getIntent()); intent.putExtra(IntentHandler.EXTRA_PARENT_INTENT, parentActivity.getIntent());
......
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