Index: chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuItemDelegate.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuItemDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuItemDelegate.java |
index 5c1d5b56e0b164930efff40b4c68479f4fa65d9e..7d3f8bad7587e2e710ba81af656d94a708fd1f40 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuItemDelegate.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuItemDelegate.java |
@@ -16,12 +16,9 @@ |
import android.net.Uri; |
import android.provider.Browser; |
-import org.chromium.base.ApplicationStatus; |
import org.chromium.base.ContextUtils; |
import org.chromium.base.Log; |
-import org.chromium.base.VisibleForTesting; |
import org.chromium.chrome.R; |
-import org.chromium.chrome.browser.ChromeTabbedActivity; |
import org.chromium.chrome.browser.IntentHandler; |
import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
import org.chromium.chrome.browser.notifications.ChromeNotificationBuilder; |
@@ -31,14 +28,9 @@ |
import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions; |
import org.chromium.chrome.browser.share.ShareHelper; |
import org.chromium.chrome.browser.share.ShareParams; |
-import org.chromium.chrome.browser.tab.Tab; |
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
import org.chromium.chrome.browser.util.IntentUtils; |
-import org.chromium.content_public.browser.LoadUrlParams; |
-import org.chromium.content_public.common.Referrer; |
import org.chromium.ui.widget.Toast; |
- |
-import java.lang.ref.WeakReference; |
/** |
* A delegate responsible for taking actions based on browser action context menu selections. |
@@ -65,8 +57,6 @@ |
private final NotificationManager mNotificationManager; |
private final SharedPreferences mSharedPreferences; |
private final String mSourcePackageName; |
- |
- private Intent mNotificationIntent; |
/** |
* Builds a {@link BrowserActionsContextMenuItemDelegate} instance. |
@@ -81,13 +71,8 @@ |
mSourcePackageName = sourcePackageName; |
} |
- @VisibleForTesting |
- Intent getNotificationIntent() { |
- return mNotificationIntent; |
- } |
- |
- private void sendBrowserActionsNotification(int tabId) { |
- ChromeNotificationBuilder builder = createNotificationBuilder(tabId); |
+ private void sendBrowserActionsNotification() { |
+ ChromeNotificationBuilder builder = createNotificationBuilder(); |
mNotificationManager.notify( |
NotificationConstants.NOTIFICATION_ID_BROWSER_ACTIONS, builder.build()); |
mSharedPreferences.edit().putBoolean(PREF_HAS_BROWSER_ACTIONS_NOTIFICATION, true).apply(); |
@@ -95,7 +80,7 @@ |
NotificationUmaTracker.BROWSER_ACTIONS, ChannelDefinitions.CHANNEL_ID_BROWSER); |
} |
- private ChromeNotificationBuilder createNotificationBuilder(int tabId) { |
+ private ChromeNotificationBuilder createNotificationBuilder() { |
ChromeNotificationBuilder builder = |
NotificationBuilderFactory |
.createChromeNotificationBuilder( |
@@ -109,46 +94,22 @@ |
? R.string.browser_actions_multi_links_open_notification_title |
: R.string.browser_actions_single_link_open_notification_title; |
builder.setContentTitle(mActivity.getString(titleResId)); |
- mNotificationIntent = buildNotificationIntent(tabId); |
- PendingIntent notifyPendingIntent = PendingIntent.getActivity( |
- mActivity, 0, mNotificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
+ Intent intent = buildNotificationIntent(); |
+ PendingIntent notifyPendingIntent = |
+ PendingIntent.getActivity(mActivity, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); |
builder.setContentIntent(notifyPendingIntent); |
return builder; |
} |
- private Intent buildNotificationIntent(int tabId) { |
- boolean multipleUrls = hasBrowserActionsNotification(); |
- if (!multipleUrls && tabId != Tab.INVALID_TAB_ID) { |
- return Tab.createBringTabToFrontIntent(tabId); |
- } |
+ private Intent buildNotificationIntent() { |
Intent intent = new Intent(mActivity, ChromeLauncherActivity.class); |
intent.setAction(ACTION_BROWSER_ACTIONS_OPEN_IN_BACKGROUND); |
- intent.putExtra(EXTRA_IS_SINGLE_URL, !multipleUrls); |
+ intent.putExtra(EXTRA_IS_SINGLE_URL, !hasBrowserActionsNotification()); |
return intent; |
} |
- boolean hasBrowserActionsNotification() { |
+ private boolean hasBrowserActionsNotification() { |
return mSharedPreferences.getBoolean(PREF_HAS_BROWSER_ACTIONS_NOTIFICATION, false); |
- } |
- |
- private int openTabInBackground(String linkUrl) { |
- int tabId = Tab.INVALID_TAB_ID; |
- Referrer referrer = IntentHandler.constructValidReferrerForAuthority(mSourcePackageName); |
- LoadUrlParams loadUrlParams = new LoadUrlParams(linkUrl); |
- loadUrlParams.setReferrer(referrer); |
- for (WeakReference<Activity> ref : ApplicationStatus.getRunningActivities()) { |
- if (!(ref.get() instanceof ChromeTabbedActivity)) continue; |
- |
- ChromeTabbedActivity activity = (ChromeTabbedActivity) ref.get(); |
- if (activity == null) continue; |
- if (activity.getTabModelSelector() != null) { |
- Tab tab = activity.getTabModelSelector().openNewTab( |
- loadUrlParams, TabLaunchType.FROM_BROWSER_ACTIONS, null, false); |
- assert tab != null; |
- tabId = tab.getId(); |
- } |
- } |
- return tabId; |
} |
/** |
@@ -183,19 +144,10 @@ |
* @param linkUrl The url to open. |
*/ |
public void onOpenInBackground(String linkUrl) { |
- int tabId = openTabInBackground(linkUrl); |
- if (tabId != Tab.INVALID_TAB_ID) { |
- sendBrowserActionsNotification(tabId); |
- Toast.makeText(mActivity, R.string.browser_actions_open_in_background_toast_message, |
- Toast.LENGTH_SHORT) |
- .show(); |
- } else { |
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl)); |
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
- intent.setClass(mActivity, ChromeLauncherActivity.class); |
- intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false); |
- IntentUtils.safeStartActivity(mActivity, intent); |
- } |
+ sendBrowserActionsNotification(); |
+ Toast.makeText(mActivity, R.string.browser_actions_open_in_background_toast_message, |
+ Toast.LENGTH_SHORT) |
+ .show(); |
} |
/** |