下面列出了android.app.ActivityManager.RecentTaskInfo#org.chromium.chrome.browser.document.ChromeLauncherActivity 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static void openUrl(Activity activity, String url, ComponentName componentName) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.putExtra(Browser.EXTRA_APPLICATION_ID,
activity.getApplicationContext().getPackageName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (componentName != null) {
intent.setComponent(componentName);
} else {
// If the bookmark manager is shown in a tab on a phone (rather than in a separate
// activity) the component name may be null. Send the intent through
// ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
intent.setClass(activity, ChromeLauncherActivity.class);
}
IntentHandler.startActivityForTrustedIntent(intent, activity);
}
private Intent createNewTabIntent(AsyncTabCreationParams asyncParams, int parentId) {
int assignedTabId = TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID);
AsyncTabParamsManager.add(assignedTabId, asyncParams);
Intent intent = new Intent(
Intent.ACTION_VIEW, Uri.parse(asyncParams.getLoadUrlParams().getUrl()));
intent.setClass(ContextUtils.getApplicationContext(), ChromeLauncherActivity.class);
intent.putExtra(IntentHandler.EXTRA_TAB_ID, assignedTabId);
intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, mIsIncognito);
intent.putExtra(IntentHandler.EXTRA_PARENT_TAB_ID, parentId);
Activity parentActivity = ActivityDelegate.getActivityForTabId(parentId);
if (parentActivity != null && parentActivity.getIntent() != null) {
intent.putExtra(IntentHandler.EXTRA_PARENT_INTENT, parentActivity.getIntent());
}
if (asyncParams.getRequestId() != null) {
intent.putExtra(ServiceTabLauncher.LAUNCH_REQUEST_ID_EXTRA,
asyncParams.getRequestId().intValue());
}
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void removeNonVisibleChromeTabbedRecentEntries() {
Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();
Context context = ContextUtils.getApplicationContext();
ActivityManager manager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
PackageManager pm = getPackageManager();
for (AppTask task : manager.getAppTasks()) {
RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
if (info == null) continue;
String className = DocumentUtils.getTaskClassName(task, pm);
// It is not easily possible to distinguish between tasks sitting on top of
// ChromeLauncherActivity, so we treat them all as likely ChromeTabbedActivities and
// close them to be on the cautious side of things.
if ((TextUtils.equals(className, ChromeTabbedActivity.class.getName())
|| TextUtils.equals(className, ChromeLauncherActivity.class.getName()))
&& !visibleTaskIds.contains(info.id)) {
task.finishAndRemoveTask();
}
}
}
/**
* Updates |mIntentHistory| and |mLastIntentUpdatedTime|. If |intent| comes from chrome and
* currently |mIsOnEffectiveIntentRedirectChain| is true, that means |intent| was sent from
* this tab because only the front tab or a new tab can receive an intent from chrome. In that
* case, |intent| is added to |mIntentHistory|.
* Otherwise, |mIntentHistory| and |mPreviousResolvers| are cleared, and then |intent| is put
* into |mIntentHistory|.
*/
public void updateIntent(Intent intent) {
clear();
if (mContext == null || intent == null || !Intent.ACTION_VIEW.equals(intent.getAction())) {
return;
}
String chromePackageName = mContext.getPackageName();
// If an intent is heading explicitly to Chrome, we should stay in Chrome.
if (TextUtils.equals(chromePackageName, intent.getPackage())
|| TextUtils.equals(chromePackageName, IntentUtils.safeGetStringExtra(intent,
Browser.EXTRA_APPLICATION_ID))) {
mIsInitialIntentHeadingToChrome = true;
}
mIsCustomTabIntent = ChromeLauncherActivity.isCustomTabIntent(intent);
// Copies minimum information to retrieve resolvers.
mInitialIntent = new Intent(Intent.ACTION_VIEW);
mInitialIntent.setData(intent.getData());
if (intent.getCategories() != null) {
for (String category : intent.getCategories()) {
mInitialIntent.addCategory(category);
}
}
}
private static void openUrl(Activity activity, String url, ComponentName componentName) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.putExtra(Browser.EXTRA_APPLICATION_ID,
activity.getApplicationContext().getPackageName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK);
if (componentName != null) {
intent.setComponent(componentName);
} else {
// If the bookmark manager is shown in a tab on a phone (rather than in a separate
// activity) the component name may be null. Send the intent through
// ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
intent.setClass(activity, ChromeLauncherActivity.class);
}
IntentHandler.startActivityForTrustedIntent(intent, activity);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void removeNonVisibleChromeTabbedRecentEntries() {
Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();
Context context = ContextUtils.getApplicationContext();
ActivityManager manager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
PackageManager pm = getPackageManager();
for (AppTask task : manager.getAppTasks()) {
RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
if (info == null) continue;
String className = DocumentUtils.getTaskClassName(task, pm);
// It is not easily possible to distinguish between tasks sitting on top of
// ChromeLauncherActivity, so we treat them all as likely ChromeTabbedActivities and
// close them to be on the cautious side of things.
if ((TextUtils.equals(className, ChromeTabbedActivity.class.getName())
|| TextUtils.equals(className, ChromeLauncherActivity.class.getName()))
&& !visibleTaskIds.contains(info.id)) {
task.finishAndRemoveTask();
}
}
}
@Override
public boolean maybeLaunchInstantApp(Tab tab, String url, String referrerUrl,
boolean isIncomingRedirect) {
if (tab == null || tab.getWebContents() == null) return false;
InstantAppsHandler handler = InstantAppsHandler.getInstance();
Intent intent = tab.getTabRedirectHandler() != null
? tab.getTabRedirectHandler().getInitialIntent() : null;
// TODO(mariakhomenko): consider also handling NDEF_DISCOVER action redirects.
if (isIncomingRedirect && intent != null && intent.getAction() == Intent.ACTION_VIEW) {
// Set the URL the redirect was resolved to for checking the existence of the
// instant app inside handleIncomingIntent().
Intent resolvedIntent = new Intent(intent);
resolvedIntent.setData(Uri.parse(url));
return handler.handleIncomingIntent(getAvailableContext(), resolvedIntent,
ChromeLauncherActivity.isCustomTabIntent(resolvedIntent));
} else if (!isIncomingRedirect) {
// Check if the navigation is coming from SERP and skip instant app handling.
if (isSerpReferrer(referrerUrl, tab)) return false;
return handler.handleNavigation(
getAvailableContext(), url,
TextUtils.isEmpty(referrerUrl) ? null : Uri.parse(referrerUrl),
tab.getWebContents());
}
return false;
}
@Override
public void loadUrl(String url) {
// Wait until native has loaded.
if (!mIsActivityUsable) {
mQueuedUrl = url;
return;
}
// Don't do anything if the input was empty. This is done after the native check to prevent
// resending a queued query after the user deleted it.
if (TextUtils.isEmpty(url)) return;
// Fix up the URL and send it to the full browser.
String fixedUrl = UrlFormatter.fixupUrl(url);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(fixedUrl));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
intent.setClass(this, ChromeLauncherActivity.class);
IntentHandler.addTrustedIntentExtras(intent);
IntentUtils.safeStartActivity(this, intent,
ActivityOptionsCompat
.makeCustomAnimation(this, android.R.anim.fade_in, android.R.anim.fade_out)
.toBundle());
RecordUserAction.record("SearchWidget.SearchMade");
finish();
}
private static void openUrl(Activity activity, String url, ComponentName componentName) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.putExtra(Browser.EXTRA_APPLICATION_ID,
activity.getApplicationContext().getPackageName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(IntentHandler.EXTRA_PAGE_TRANSITION_TYPE, PageTransition.AUTO_BOOKMARK);
if (componentName != null) {
intent.setComponent(componentName);
} else {
// If the bookmark manager is shown in a tab on a phone (rather than in a separate
// activity) the component name may be null. Send the intent through
// ChromeLauncherActivity instead to avoid crashing. See crbug.com/615012.
intent.setClass(activity, ChromeLauncherActivity.class);
}
IntentHandler.startActivityForTrustedIntent(intent);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void removeNonVisibleChromeTabbedRecentEntries() {
Set<Integer> visibleTaskIds = getTaskIdsForVisibleActivities();
Context context = ContextUtils.getApplicationContext();
ActivityManager manager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
PackageManager pm = getPackageManager();
for (AppTask task : manager.getAppTasks()) {
RecentTaskInfo info = DocumentUtils.getTaskInfoFromTask(task);
if (info == null) continue;
String className = DocumentUtils.getTaskClassName(task, pm);
// It is not easily possible to distinguish between tasks sitting on top of
// ChromeLauncherActivity, so we treat them all as likely ChromeTabbedActivities and
// close them to be on the cautious side of things.
if ((ChromeTabbedActivity.isTabbedModeClassName(className)
|| TextUtils.equals(className, ChromeLauncherActivity.class.getName()))
&& !visibleTaskIds.contains(info.id)) {
task.finishAndRemoveTask();
}
}
}
@Override
public boolean maybeLaunchInstantApp(Tab tab, String url, String referrerUrl,
boolean isIncomingRedirect) {
if (tab == null || tab.getWebContents() == null) return false;
InstantAppsHandler handler = InstantAppsHandler.getInstance();
Intent intent = tab.getTabRedirectHandler() != null
? tab.getTabRedirectHandler().getInitialIntent() : null;
// TODO(mariakhomenko): consider also handling NDEF_DISCOVER action redirects.
if (isIncomingRedirect && intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) {
// Set the URL the redirect was resolved to for checking the existence of the
// instant app inside handleIncomingIntent().
Intent resolvedIntent = new Intent(intent);
resolvedIntent.setData(Uri.parse(url));
return handler.handleIncomingIntent(getAvailableContext(), resolvedIntent,
ChromeLauncherActivity.isCustomTabIntent(resolvedIntent), true);
} else if (!isIncomingRedirect) {
// Check if the navigation is coming from SERP and skip instant app handling.
if (isSerpReferrer(tab)) return false;
return handler.handleNavigation(getAvailableContext(), url,
TextUtils.isEmpty(referrerUrl) ? null : Uri.parse(referrerUrl), tab);
}
return false;
}
/**
* Opens a new Tab with the possibility of showing it in a Custom Tab, instead.
*
* See IntentHandler#processUrlViewIntent() for an explanation most of the parameters.
* @param forceNewTab If not handled by a Custom Tab, forces the new tab to be created.
*/
private void openNewTab(String url, String referer, String headers,
String externalAppId, Intent intent, boolean forceNewTab) {
boolean isAllowedToReturnToExternalApp = IntentUtils.safeGetBooleanExtra(intent,
ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, true);
String herbFlavor = FeatureUtilities.getHerbFlavor();
if (isAllowedToReturnToExternalApp
&& ChromeLauncherActivity.canBeHijackedByHerb(intent)
&& TextUtils.equals(ChromeSwitches.HERB_FLAVOR_DILL, herbFlavor)) {
Log.d(TAG, "Sending to CustomTabActivity");
mActivityStopMetrics.setStopReason(
ActivityStopMetrics.STOP_REASON_CUSTOM_TAB_STARTED);
Intent newIntent = ChromeLauncherActivity.createCustomTabActivityIntent(
ChromeTabbedActivity.this, intent, false);
newIntent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
newIntent.putExtra(
CustomTabIntentDataProvider.EXTRA_IS_OPENED_BY_CHROME, true);
ChromeLauncherActivity.updateHerbIntent(ChromeTabbedActivity.this,
newIntent, Uri.parse(IntentHandler.getUrlFromIntent(newIntent)));
// Launch the Activity on top of this task.
int updatedFlags = newIntent.getFlags();
updatedFlags &= ~Intent.FLAG_ACTIVITY_NEW_TASK;
updatedFlags &= ~Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
newIntent.setFlags(updatedFlags);
startActivityForResult(newIntent, CCT_RESULT);
} else {
// Create a new tab.
Tab newTab =
launchIntent(url, referer, headers, externalAppId, forceNewTab, intent);
newTab.setIsAllowedToReturnToExternalApp(isAllowedToReturnToExternalApp);
RecordUserAction.record("MobileReceivedExternalIntent");
}
}
@Override
public void onReceive(Context context, Intent intent) {
if (BookmarkWidgetService.getChangeFolderAction(context)
.equals(intent.getAction())) {
BookmarkWidgetService.changeFolder(context, intent);
} else {
Intent view = new Intent(intent);
view.setClass(context, ChromeLauncherActivity.class);
view.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.BOOKMARK_NAVIGATOR_WIDGET);
view.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
startActivity(context, view);
}
}
/**
* @param activity The {@link Activity} to check.
* @return Whether or not {@code activity} should run in pre-N Samsung multi-instance mode.
*/
public boolean shouldRunInLegacyMultiInstanceMode(ChromeLauncherActivity activity) {
return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
&& TextUtils.equals(activity.getIntent().getAction(), Intent.ACTION_MAIN)
&& isLegacyMultiWindow(activity)
&& activity.isChromeBrowserActivityRunning();
}
/**
* Makes |intent| able to support multi-instance in pre-N Samsung multi-window mode.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void makeLegacyMultiInstanceIntent(ChromeLauncherActivity activity, Intent intent) {
if (isLegacyMultiWindow(activity)) {
if (TextUtils.equals(ChromeTabbedActivity.class.getName(),
intent.getComponent().getClassName())) {
intent.setClassName(activity, MultiInstanceChromeTabbedActivity.class.getName());
}
intent.setFlags(intent.getFlags()
& ~(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT));
}
}
/**
* Opens a new Tab with the possibility of showing it in a Custom Tab, instead.
*
* See IntentHandler#processUrlViewIntent() for an explanation most of the parameters.
* @param forceNewTab If not handled by a Custom Tab, forces the new tab to be created.
*/
private void openNewTab(String url, String referer, String headers,
String externalAppId, Intent intent, boolean forceNewTab) {
boolean isAllowedToReturnToExternalApp = IntentUtils.safeGetBooleanExtra(intent,
ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, true);
// Create a new tab.
Tab newTab =
launchIntent(url, referer, headers, externalAppId, forceNewTab, intent);
newTab.setIsAllowedToReturnToExternalApp(isAllowedToReturnToExternalApp);
logMobileReceivedExternalIntent(externalAppId, intent);
}
@Override
public void onReceive(Context context, Intent intent) {
if (BookmarkWidgetService.getChangeFolderAction(context)
.equals(intent.getAction())) {
BookmarkWidgetService.changeFolder(context, intent);
} else {
Intent view = new Intent(intent);
view.setClass(context, ChromeLauncherActivity.class);
view.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.BOOKMARK_NAVIGATOR_WIDGET);
view.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
startActivity(context, view);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String intentAction = getIntent().getAction();
// Exit early if the original intent action isn't for opening a new tab.
if (!intentAction.equals(ACTION_OPEN_NEW_TAB)
&& !intentAction.equals(ACTION_OPEN_NEW_INCOGNITO_TAB)) {
finish();
return;
}
Intent newIntent = new Intent();
newIntent.setAction(Intent.ACTION_VIEW);
newIntent.setData(Uri.parse(UrlConstants.NTP_URL));
newIntent.setClass(this, ChromeLauncherActivity.class);
newIntent.putExtra(IntentHandler.EXTRA_INVOKED_FROM_SHORTCUT, true);
newIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
newIntent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
IntentHandler.addTrustedIntentExtras(newIntent, this);
if (intentAction.equals(ACTION_OPEN_NEW_INCOGNITO_TAB)) {
newIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
}
// This system call is often modified by OEMs and not actionable. http://crbug.com/619646.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
StrictMode.allowThreadDiskWrites();
try {
startActivity(newIntent);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
finish();
}
/**
* @param activity The {@link Activity} to check.
* @return Whether or not {@code activity} should run in pre-N Samsung multi-instance mode.
*/
public boolean shouldRunInLegacyMultiInstanceMode(ChromeLauncherActivity activity) {
return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
&& TextUtils.equals(activity.getIntent().getAction(), Intent.ACTION_MAIN)
&& isLegacyMultiWindow(activity)
&& activity.isChromeBrowserActivityRunning();
}
/**
* Makes |intent| able to support multi-instance in pre-N Samsung multi-window mode.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void makeLegacyMultiInstanceIntent(ChromeLauncherActivity activity, Intent intent) {
if (isLegacyMultiWindow(activity)) {
if (TextUtils.equals(ChromeTabbedActivity.class.getName(),
intent.getComponent().getClassName())) {
intent.setClassName(activity, MultiInstanceChromeTabbedActivity.class.getName());
}
intent.setFlags(intent.getFlags()
& ~(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT));
}
}
/**
* Updates |mIntentHistory| and |mLastIntentUpdatedTime|. If |intent| comes from chrome and
* currently |mIsOnEffectiveIntentRedirectChain| is true, that means |intent| was sent from
* this tab because only the front tab or a new tab can receive an intent from chrome. In that
* case, |intent| is added to |mIntentHistory|.
* Otherwise, |mIntentHistory| and |mPreviousResolvers| are cleared, and then |intent| is put
* into |mIntentHistory|.
*/
public void updateIntent(Intent intent) {
clear();
if (mContext == null || intent == null || !Intent.ACTION_VIEW.equals(intent.getAction())) {
return;
}
mIsCustomTabIntent = ChromeLauncherActivity.isCustomTabIntent(intent);
boolean checkIsToChrome = true;
// All custom tabs VIEW intents are by design explicit intents, so the presence of package
// name doesn't imply they have to be handled by Chrome explicitly. Check if external apps
// should be checked for handling the initial redirect chain.
if (mIsCustomTabIntent) {
boolean sendToExternalApps = IntentUtils.safeGetBooleanExtra(intent,
CustomTabIntentDataProvider.EXTRA_SEND_TO_EXTERNAL_DEFAULT_HANDLER, false);
checkIsToChrome = !(sendToExternalApps
&& ChromeFeatureList.isEnabled(ChromeFeatureList.CCT_EXTERNAL_LINK_HANDLING));
}
if (checkIsToChrome) mIsInitialIntentHeadingToChrome = isIntentToChrome(mContext, intent);
// A copy of the intent with component cleared to find resolvers.
mInitialIntent = new Intent(intent).setComponent(null);
Intent selector = mInitialIntent.getSelector();
if (selector != null) selector.setComponent(null);
}
@Override
public void onReceive(Context context, Intent intent) {
if (BookmarkWidgetService.getChangeFolderAction(context)
.equals(intent.getAction())) {
BookmarkWidgetService.changeFolder(context, intent);
} else {
Intent view = new Intent(intent);
view.setClass(context, ChromeLauncherActivity.class);
view.putExtra(ShortcutHelper.EXTRA_SOURCE, ShortcutSource.BOOKMARK_NAVIGATOR_WIDGET);
view.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
startActivity(context, view);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String intentAction = getIntent().getAction();
// Exit early if the original intent action isn't for opening a new tab.
if (!intentAction.equals(ACTION_OPEN_NEW_TAB)
&& !intentAction.equals(ACTION_OPEN_NEW_INCOGNITO_TAB)) {
finish();
return;
}
Intent newIntent = new Intent();
newIntent.setAction(Intent.ACTION_VIEW);
newIntent.setData(Uri.parse(UrlConstants.NTP_URL));
newIntent.setClass(this, ChromeLauncherActivity.class);
newIntent.putExtra(IntentHandler.EXTRA_INVOKED_FROM_SHORTCUT, true);
newIntent.putExtra(Browser.EXTRA_CREATE_NEW_TAB, true);
newIntent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
IntentHandler.addTrustedIntentExtras(newIntent);
if (intentAction.equals(ACTION_OPEN_NEW_INCOGNITO_TAB)) {
newIntent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
}
// This system call is often modified by OEMs and not actionable. http://crbug.com/619646.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
startActivity(newIntent);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
finish();
}
/**
* @param activity The {@link Activity} to check.
* @return Whether or not {@code activity} should run in pre-N Samsung multi-instance mode.
*/
public boolean shouldRunInLegacyMultiInstanceMode(ChromeLauncherActivity activity) {
return Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP
&& TextUtils.equals(activity.getIntent().getAction(), Intent.ACTION_MAIN)
&& isLegacyMultiWindow(activity)
&& activity.isChromeBrowserActivityRunning();
}
/**
* Makes |intent| able to support multi-instance in pre-N Samsung multi-window mode.
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void makeLegacyMultiInstanceIntent(ChromeLauncherActivity activity, Intent intent) {
if (isLegacyMultiWindow(activity)) {
if (TextUtils.equals(ChromeTabbedActivity.class.getName(),
intent.getComponent().getClassName())) {
intent.setClassName(activity, MultiInstanceChromeTabbedActivity.class.getName());
}
intent.setFlags(intent.getFlags()
& ~(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NEW_DOCUMENT));
}
}
private static void openUrl(Uri uri) {
Context context = ContextUtils.getApplicationContext();
Intent intent = new Intent()
.setAction(Intent.ACTION_VIEW)
.setData(uri)
.setClass(context, ChromeLauncherActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName())
.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
IntentHandler.addTrustedIntentExtras(intent);
context.startActivity(intent);
}
@Override
public void onOpenInNewChromeTabFromCCT(String linkUrl, boolean isIncognito) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(mTab.getApplicationContext(), ChromeLauncherActivity.class);
intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false);
if (isIncognito) {
intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
intent.putExtra(
Browser.EXTRA_APPLICATION_ID, mTab.getApplicationContext().getPackageName());
IntentHandler.addTrustedIntentExtras(intent);
IntentHandler.setTabLaunchType(intent, TabLaunchType.FROM_EXTERNAL_APP);
}
IntentUtils.safeStartActivity(mTab.getActivity(), intent);
}
/**
* Updates |mIntentHistory| and |mLastIntentUpdatedTime|. If |intent| comes from chrome and
* currently |mIsOnEffectiveIntentRedirectChain| is true, that means |intent| was sent from
* this tab because only the front tab or a new tab can receive an intent from chrome. In that
* case, |intent| is added to |mIntentHistory|.
* Otherwise, |mIntentHistory| and |mPreviousResolvers| are cleared, and then |intent| is put
* into |mIntentHistory|.
*/
public void updateIntent(Intent intent) {
clear();
if (mContext == null || intent == null || !Intent.ACTION_VIEW.equals(intent.getAction())) {
return;
}
mIsCustomTabIntent = ChromeLauncherActivity.isCustomTabIntent(intent);
boolean checkIsToChrome = true;
// All custom tabs VIEW intents are by design explicit intents, so the presence of package
// name doesn't imply they have to be handled by Chrome explicitly. Check if external apps
// should be checked for handling the initial redirect chain.
if (mIsCustomTabIntent) {
boolean sendToExternalApps = IntentUtils.safeGetBooleanExtra(intent,
CustomTabIntentDataProvider.EXTRA_SEND_TO_EXTERNAL_DEFAULT_HANDLER, false);
checkIsToChrome = !(sendToExternalApps
&& ChromeFeatureList.isEnabled(ChromeFeatureList.CCT_EXTERNAL_LINK_HANDLING));
}
if (checkIsToChrome) mIsInitialIntentHeadingToChrome = isIntentToChrome(mContext, intent);
// A copy of the intent with component cleared to find resolvers.
mInitialIntent = new Intent(intent).setComponent(null);
Intent selector = mInitialIntent.getSelector();
if (selector != null) selector.setComponent(null);
}
private void launchInTab(String webappUrl, int webappSource) {
if (TextUtils.isEmpty(webappUrl)) return;
Intent launchIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(webappUrl));
launchIntent.setClassName(getPackageName(), ChromeLauncherActivity.class.getName());
launchIntent.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
launchIntent.putExtra(ShortcutHelper.EXTRA_SOURCE, webappSource);
launchIntent.setFlags(
Intent.FLAG_ACTIVITY_NEW_TASK | ApiCompatibilityUtils.getActivityNewDocumentFlag());
startActivity(launchIntent);
}
/**
* Called when the {@code linkUrl} should be opened in Chrome incognito tab.
* @param linkUrl The url to open.
*/
public void onOpenInIncognitoTab(String linkUrl) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage(mContext.getPackageName());
intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false);
intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, mContext.getPackageName());
IntentHandler.addTrustedIntentExtras(intent);
IntentHandler.setTabLaunchType(intent, TabLaunchType.FROM_EXTERNAL_APP);
IntentUtils.safeStartActivity(mContext, intent);
}