Commit 1b2247e8 authored by tedchoc's avatar tedchoc Committed by Commit bot

Remove code that implies external apps can open incognito tabs.

On Android, we restrict who can open incognito tabs to only
Chrome.  The logic to enforce this was spread across
IntentHandler#shouldIgnoreIntent and
ChromeTabbedActivity#processUrlViewIntent.  It was unclear and
confusing to read, so this removes the invalid paths and makes
it more explicit about what is allowed.

BUG=

Review-Url: https://codereview.chromium.org/2601183002
Cr-Commit-Position: refs/heads/master@{#440918}
parent d34d9547
...@@ -839,34 +839,28 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode ...@@ -839,34 +839,28 @@ public class ChromeTabbedActivity extends ChromeActivity implements OverviewMode
openNewTab(url, referer, headers, externalAppId, intent, true); openNewTab(url, referer, headers, externalAppId, intent, true);
break; break;
case OPEN_NEW_INCOGNITO_TAB: case OPEN_NEW_INCOGNITO_TAB:
if (!TextUtils.equals(externalAppId, getPackageName())) {
assert false : "Only Chrome is allowed to open incognito tabs";
Log.e(TAG, "Only Chrome is allowed to open incognito tabs");
return;
}
if (url == null || url.equals(UrlConstants.NTP_URL)) { if (url == null || url.equals(UrlConstants.NTP_URL)) {
TabLaunchType launchType;
if (fromLauncherShortcut) { if (fromLauncherShortcut) {
getTabCreator(true).launchUrl( getTabCreator(true).launchUrl(
UrlConstants.NTP_URL, TabLaunchType.FROM_EXTERNAL_APP); UrlConstants.NTP_URL, TabLaunchType.FROM_EXTERNAL_APP);
recordLauncherShortcutAction(true); recordLauncherShortcutAction(true);
reportNewTabShortcutUsed(true); reportNewTabShortcutUsed(true);
} else if (TextUtils.equals(externalAppId, getPackageName())) { } else {
// Used by the Account management screen to open a new incognito tab. // Used by the Account management screen to open a new incognito tab.
// Account management screen collects its metrics separately. // Account management screen collects its metrics separately.
getTabCreator(true).launchUrl( getTabCreator(true).launchUrl(
UrlConstants.NTP_URL, TabLaunchType.FROM_CHROME_UI, UrlConstants.NTP_URL, TabLaunchType.FROM_CHROME_UI,
intent, mIntentHandlingTimeMs); intent, mIntentHandlingTimeMs);
} else {
getTabCreator(true).launchUrl(
UrlConstants.NTP_URL, TabLaunchType.FROM_EXTERNAL_APP,
intent, mIntentHandlingTimeMs);
RecordUserAction.record("MobileReceivedExternalIntent");
} }
} else { } else {
if (TextUtils.equals(externalAppId, getPackageName())) {
getTabCreator(true).launchUrl( getTabCreator(true).launchUrl(
url, TabLaunchType.FROM_LINK, intent, mIntentHandlingTimeMs); url, TabLaunchType.FROM_LINK, intent, mIntentHandlingTimeMs);
} else {
getTabCreator(true).launchUrlFromExternalApp(url, referer, headers,
externalAppId, true, intent, mIntentHandlingTimeMs);
RecordUserAction.record("MobileReceivedExternalIntent");
}
} }
break; break;
default: default:
......
...@@ -662,9 +662,16 @@ public class IntentHandler { ...@@ -662,9 +662,16 @@ public class IntentHandler {
// Determine if this intent came from a trustworthy source (either Chrome or Google // Determine if this intent came from a trustworthy source (either Chrome or Google
// first party applications). // first party applications).
boolean isInternal = isIntentChromeOrFirstParty(intent, context); boolean isInternal = isIntentChromeOrFirstParty(intent, context);
boolean isFromChrome = wasIntentSenderChrome(intent, context);
// "Open new incognito tab" is currently limited to Chrome or first parties.
if (!isInternal // "Open new incognito tab" is currently limited to Chrome.
//
// The pending incognito URL check is to handle the case where the user is shown an
// Android intent picker while in incognito and they select the current Chrome instance
// from the list. In this case, we do not apply our Chrome token as the user has the
// option to select apps outside of our control, so we rely on this in memory check
// instead.
if (!isFromChrome
&& IntentUtils.safeGetBooleanExtra( && IntentUtils.safeGetBooleanExtra(
intent, EXTRA_OPEN_NEW_INCOGNITO_TAB, false) intent, EXTRA_OPEN_NEW_INCOGNITO_TAB, false)
&& (getPendingIncognitoUrl() == null && (getPendingIncognitoUrl() == 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