Commit d65ce76c authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Move IntentUtils#createBringTabToFrontIntent() to DocumentUtils.

This is the only function in IntentUtils that depends on
chrome/browser. IntentUtils can then be moved to a separate util
build target.

Bug: 995916
Change-Id: I25307932e08b605f292947f7af2d4fe2be98b70f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1774301Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695395}
parent d55b9286
......@@ -1693,6 +1693,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/ui/system/StatusBarColorController.java",
"java/src/org/chromium/chrome/browser/util/AccessibilityUtil.java",
"java/src/org/chromium/chrome/browser/util/ChromeContextUtil.java",
"java/src/org/chromium/chrome/browser/util/ChromeIntentUtil.java",
"java/src/org/chromium/chrome/browser/util/ColorUtils.java",
"java/src/org/chromium/chrome/browser/util/FeatureUtilities.java",
"java/src/org/chromium/chrome/browser/util/IntentUtils.java",
......
......@@ -7,7 +7,7 @@ package org.chromium.chrome.browser.media.router.caf;
import android.content.Intent;
import org.chromium.chrome.browser.metrics.MediaNotificationUma;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.browser.util.ChromeIntentUtil;
import org.chromium.chrome.media.router.R;
/** NotificationController implementation for presentation. */
......@@ -19,7 +19,7 @@ public class CafNotificationController extends BaseNotificationController {
@Override
public Intent createContentIntent() {
Intent contentIntent = IntentUtils.createBringTabToFrontIntent(
Intent contentIntent = ChromeIntentUtil.createBringTabToFrontIntent(
mSessionController.getRouteCreationInfo().tabId);
if (contentIntent != null) {
contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME,
......
......@@ -56,6 +56,7 @@ import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.document.TabDelegate;
import org.chromium.chrome.browser.util.ChromeIntentUtil;
import org.chromium.chrome.browser.util.ConversionUtils;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.chrome.browser.util.IntentUtils;
......@@ -197,7 +198,7 @@ public class DownloadUtils {
tab.loadUrl(params);
// Bring Chrome to the foreground, if possible.
Intent intent = IntentUtils.createBringTabToFrontIntent(tab.getId());
Intent intent = ChromeIntentUtil.createBringTabToFrontIntent(tab.getId());
if (intent != null) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
IntentUtils.safeStartActivity(appContext, intent);
......
......@@ -30,7 +30,7 @@ import org.chromium.chrome.browser.notifications.PendingIntentProvider;
import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabWindowManager;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.browser.util.ChromeIntentUtil;
import org.chromium.content_public.browser.WebContents;
import java.net.MalformedURLException;
......@@ -201,7 +201,7 @@ public class MediaCaptureNotificationService extends Service {
.setSmallIcon(getNotificationIconId(mediaType))
.setLocalOnly(true);
Intent tabIntent = IntentUtils.createBringTabToFrontIntent(notificationId);
Intent tabIntent = ChromeIntentUtil.createBringTabToFrontIntent(notificationId);
if (tabIntent != null) {
PendingIntentProvider contentIntent = PendingIntentProvider.getActivity(
ContextUtils.getApplicationContext(), notificationId, tabIntent, 0);
......
......@@ -24,7 +24,7 @@ import org.chromium.chrome.browser.tab.EmptyTabObserver;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabObserver;
import org.chromium.chrome.browser.tabmodel.TabSelectionType;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.browser.util.ChromeIntentUtil;
import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.content_public.browser.MediaSession;
import org.chromium.content_public.browser.MediaSessionObserver;
......@@ -208,7 +208,7 @@ public class MediaSessionTabHelper implements MediaImageCallback {
return;
}
Intent contentIntent = IntentUtils.createBringTabToFrontIntent(mTab.getId());
Intent contentIntent = ChromeIntentUtil.createBringTabToFrontIntent(mTab.getId());
if (contentIntent != null) {
contentIntent.putExtra(MediaNotificationUma.INTENT_EXTRA_NAME,
MediaNotificationUma.Source.MEDIA);
......@@ -318,8 +318,9 @@ public class MediaSessionTabHelper implements MediaImageCallback {
assert tab == mTab;
if (!navigation.hasCommitted() || !navigation.isInMainFrame()
|| navigation.isSameDocument())
|| navigation.isSameDocument()) {
return;
}
String origin = mTab.getUrl();
try {
......
......@@ -38,7 +38,7 @@ import org.chromium.chrome.browser.tabmodel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelUtils;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.browser.util.ChromeIntentUtil;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager;
......@@ -215,7 +215,7 @@ public class ActivityTabWebContentsDelegateAndroid extends TabWebContentsDelegat
// Note that calling only the intent in order to activate the tab is slightly slower
// because it will change the tab when the intent is handled, which happens after
// Chrome gets back to the foreground.
Intent newIntent = IntentUtils.createBringTabToFrontIntent(mTab.getId());
Intent newIntent = ChromeIntentUtil.createBringTabToFrontIntent(mTab.getId());
if (newIntent != null) {
newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mTab.getApplicationContext().startActivity(newIntent);
......
// Copyright 2019 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.util;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.provider.Browser;
import android.support.annotation.Nullable;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
/**
* Utilities to construct intents to Chrome.
*/
public class ChromeIntentUtil {
public static final String TAG = "ChromeIntentUtil";
/**
* Creates an Intent that tells Chrome to bring an Activity for a particular Tab back to the
* foreground.
* @param tabId The id of the Tab to bring to the foreground.
* @return Created Intent or null if this operation isn't possible.
*/
@Nullable
public static Intent createBringTabToFrontIntent(int tabId) {
// Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a
// {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded.
for (Activity activity : ApplicationStatus.getRunningActivities()) {
if (activity instanceof CustomTabActivity
&& ((CustomTabActivity) activity).getActivityTab() != null
&& tabId == ((CustomTabActivity) activity).getActivityTab().getId()) {
return null;
}
}
Context context = ContextUtils.getApplicationContext();
Intent intent = new Intent(context, ChromeLauncherActivity.class);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
intent.putExtra(IntentHandler.TabOpenType.BRING_TAB_TO_FRONT_STRING, tabId);
return intent;
}
}
......@@ -4,7 +4,6 @@
package org.chromium.chrome.browser.util;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
......@@ -15,18 +14,12 @@ import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.TransactionTooLargeException;
import android.provider.Browser;
import android.support.annotation.Nullable;
import android.support.v4.app.BundleCompat;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.IntentHandler.TabOpenType;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import java.io.Serializable;
import java.util.ArrayList;
......@@ -448,31 +441,6 @@ public class IntentUtils {
}
}
/**
* Creates an Intent that tells Chrome to bring an Activity for a particular Tab back to the
* foreground.
* @param tabId The id of the Tab to bring to the foreground.
* @return Created Intent or null if this operation isn't possible.
*/
@Nullable
public static Intent createBringTabToFrontIntent(int tabId) {
// Iterate through all {@link CustomTab}s and check whether the given tabId belongs to a
// {@link CustomTab}. If so, return null as the client app's task cannot be foregrounded.
for (Activity activity : ApplicationStatus.getRunningActivities()) {
if (activity instanceof CustomTabActivity
&& ((CustomTabActivity) activity).getActivityTab() != null
&& tabId == ((CustomTabActivity) activity).getActivityTab().getId()) {
return null;
}
}
Context context = ContextUtils.getApplicationContext();
Intent intent = new Intent(context, ChromeLauncherActivity.class);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
intent.putExtra(TabOpenType.BRING_TAB_TO_FRONT_STRING, tabId);
return intent;
}
private static Intent logInvalidIntent(Intent intent, Exception e) {
Log.e(TAG, "Invalid incoming intent.", e);
return intent.replaceExtras((Bundle) null);
......
......@@ -31,7 +31,7 @@ import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.DeferredStartupHandler;
import org.chromium.chrome.browser.ShortcutHelper;
import org.chromium.chrome.browser.tab.TabIdManager;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.browser.util.ChromeIntentUtil;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.MultiActivityTestRule;
import org.chromium.chrome.test.util.ApplicationTestUtils;
......@@ -198,7 +198,7 @@ public class WebappModeTest {
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
// Bring the WebappActivity back via an Intent.
Intent intent = IntentUtils.createBringTabToFrontIntent(webappTabId);
Intent intent = ChromeIntentUtil.createBringTabToFrontIntent(webappTabId);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
......
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