Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/browseractions/BrowserActionsContextMenuItemDelegate.java

Issue 2876863002: [Android] Show notification for opening new tab in background of Browser Actions (Closed)
Patch Set: Update based on David's comment and rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 eb8103067cf9ba6098c427cc1cab7c2bc887cbe0..abbf43b5028966a94cdf84a13a7b0f6d243adf81 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,22 +14,85 @@ 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;
/**
* A delegate responsible for taking actions based on browser action context menu selections.
*/
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);
David Trainor- moved to gerrit 2017/05/17 16:48:02 ChromeLauncherActivity?
ltian 2017/05/19 21:02:47 Done.
+ intent.setAction(ACTION_BROWSER_ACTIONS_OPEN_IN_BACKGROUND);
+ intent.putExtra(EXTRA_IS_SINGLE_URL, true);
David Trainor- moved to gerrit 2017/05/17 16:48:02 Can we just pull isSingleUrl() out to a helper tha
ltian 2017/05/19 21:02:47 Talk with Sam and he is ok to display notification
+ 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.
@@ -35,6 +100,8 @@ public class BrowserActionsContextMenuItemDelegate {
public BrowserActionsContextMenuItemDelegate(Activity activity) {
mContext = ContextUtils.getApplicationContext();
mActivity = activity;
+ mNotificationManager =
+ (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
}
/**
@@ -68,7 +135,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.

Powered by Google App Engine
This is Rietveld 408576698