| 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 0c0f775c285db2fa0ddb146bcab885e8b5406614..6e49a3fa71db775d7c06a0391299e73c120d9dba 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
|
| @@ -4,7 +4,9 @@
|
|
|
| package org.chromium.chrome.browser.browseractions;
|
|
|
| +import android.annotation.TargetApi;
|
| import android.app.Activity;
|
| +import android.app.NotificationManager;
|
| import android.app.PendingIntent;
|
| import android.app.PendingIntent.CanceledException;
|
| import android.content.ClipData;
|
| @@ -12,13 +14,21 @@ import android.content.ClipboardManager;
|
| import android.content.Context;
|
| import android.content.Intent;
|
| import android.net.Uri;
|
| +import android.os.Build;
|
| import android.provider.Browser;
|
| +import android.service.notification.StatusBarNotification;
|
|
|
| import org.chromium.base.ContextUtils;
|
| import org.chromium.base.Log;
|
| 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.ChannelDefinitions;
|
| +import org.chromium.chrome.browser.notifications.ChromeNotificationBuilder;
|
| +import org.chromium.chrome.browser.notifications.NotificationBuilderFactory;
|
| +import org.chromium.chrome.browser.notifications.NotificationConstants;
|
| +import org.chromium.chrome.browser.notifications.NotificationUmaTracker;
|
| import org.chromium.chrome.browser.util.IntentUtils;
|
| import org.chromium.ui.widget.Toast;
|
|
|
| @@ -27,9 +37,62 @@ import org.chromium.ui.widget.Toast;
|
| */
|
| public class BrowserActionsContextMenuItemDelegate {
|
| private static final String TAG = "BrowserActionsItem";
|
| + /**
|
| + * Action to request open ChromeTabbedActivity in tab switcher mode.
|
| + */
|
| + public static final String ACTION_BROWSER_ACTIONS_OPEN_IN_BACKGROUND =
|
| + "org.chromium.chrome.browser.browseractions.browser_action_open_in_background";
|
| +
|
| + /**
|
| + * Extra that indicates whether to show a Tab for single url or the tab swictcher for
|
| + * multiple urls.
|
| + */
|
| + public static final String EXTRA_IS_SINGLE_URL =
|
| + "org.chromium.chrome.browser.browseractions.is_single_url";
|
|
|
| private final Context mContext;
|
| private final Activity mActivity;
|
| + private final NotificationManager mNotificationManager;
|
| +
|
| + private void sendBrowserActionsNotification(String linkUrl) {
|
| + Intent intent = new Intent(mContext, ChromeTabbedActivity.class);
|
| + intent.setAction(ACTION_BROWSER_ACTIONS_OPEN_IN_BACKGROUND);
|
| + intent.putExtra(EXTRA_IS_SINGLE_URL, true);
|
| + ChromeNotificationBuilder builder =
|
| + NotificationBuilderFactory
|
| + .createChromeNotificationBuilder(
|
| + true /* preferCompat */, ChannelDefinitions.CHANNEL_ID_BROWSER)
|
| + .setSmallIcon(R.drawable.infobar_chrome)
|
| + .setLocalOnly(true)
|
| + .setAutoCancel(true)
|
| + .setContentText(
|
| + mContext.getString(R.string.browser_actions_notification_text))
|
| + .setContentTitle(mContext.getString(
|
| + R.string.browser_actions_single_link_open_notification_title));
|
| + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && hasBrowserActionsNotification()) {
|
| + builder.setContentTitle(mContext.getString(
|
| + R.string.browser_actions_multi_links_open_notification_title));
|
| + intent.putExtra(EXTRA_IS_SINGLE_URL, false);
|
| + }
|
| + PendingIntent notifyPendingIntent =
|
| + PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
| + builder.setContentIntent(notifyPendingIntent);
|
| + mNotificationManager.notify(
|
| + NotificationConstants.NOTIFICATION_ID_BROWSER_ACTIONS, builder.build());
|
| + NotificationUmaTracker.getInstance().onNotificationShown(
|
| + NotificationUmaTracker.BROWSER_ACTIONS, ChannelDefinitions.CHANNEL_ID_BROWSER);
|
| + }
|
| +
|
| + @TargetApi(Build.VERSION_CODES.M)
|
| + private boolean hasBrowserActionsNotification() {
|
| + StatusBarNotification[] notifications = mNotificationManager.getActiveNotifications();
|
| + for (StatusBarNotification notification : notifications) {
|
| + if (notification.getId() == NotificationConstants.NOTIFICATION_ID_BROWSER_ACTIONS) {
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| + }
|
|
|
| /**
|
| * Builds a {@link BrowserActionsContextMenuItemDelegate} instance.
|
| @@ -37,6 +100,8 @@ public class BrowserActionsContextMenuItemDelegate {
|
| public BrowserActionsContextMenuItemDelegate(Activity activity) {
|
| mContext = ContextUtils.getApplicationContext();
|
| mActivity = activity;
|
| + mNotificationManager =
|
| + (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
|
| }
|
|
|
| /**
|
| @@ -71,7 +136,12 @@ public class BrowserActionsContextMenuItemDelegate {
|
| * Called when the {@code linkUrl} should be opened in Chrome in the background.
|
| * @param linkUrl The url to open.
|
| */
|
| - public void onOpenInBackground(String linkUrl) {}
|
| + public void onOpenInBackground(String linkUrl) {
|
| + sendBrowserActionsNotification(linkUrl);
|
| + Toast.makeText(mContext, R.string.browser_actions_open_in_background_toast_message,
|
| + Toast.LENGTH_SHORT)
|
| + .show();
|
| + }
|
|
|
| /**
|
| * Called when a custom item of Browser action menu is selected.
|
|
|