| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java
|
| index 337a3a997a905b558711614896dae30c57f4c9ae..04fbe40ccc390e255e69a9e7c255b9f731878ec7 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java
|
| @@ -20,6 +20,7 @@ import android.support.v4.app.NotificationCompat;
|
|
|
| import org.chromium.base.ContextUtils;
|
| import org.chromium.base.annotations.CalledByNative;
|
| +import org.chromium.base.annotations.JNINamespace;
|
| import org.chromium.chrome.R;
|
| import org.chromium.chrome.browser.IntentHandler;
|
| import org.chromium.chrome.browser.ShortcutHelper;
|
| @@ -30,6 +31,7 @@ import org.chromium.chrome.browser.document.ChromeLauncherActivity;
|
| *
|
| * Exposes helper functions to native C++ code.
|
| */
|
| +@JNINamespace("ntp_snippets")
|
| public class ContentSuggestionsNotificationHelper {
|
| private static final String NOTIFICATION_TAG = "ContentSuggestionsNotification";
|
| private static final String NOTIFICATION_ID_EXTRA = "notification_id";
|
| @@ -37,6 +39,25 @@ public class ContentSuggestionsNotificationHelper {
|
| private ContentSuggestionsNotificationHelper() {} // Prevent instantiation
|
|
|
| /**
|
| + * Opens the content suggestion when notification is tapped.
|
| + */
|
| + public static final class OpenUrlReceiver extends BroadcastReceiver {
|
| + public void onReceive(Context context, Intent intent) {
|
| + openUrl(intent.getData());
|
| + nativeNotificationTapped();
|
| + }
|
| + }
|
| +
|
| + /**
|
| + * Records dismissal when notification is swiped away.
|
| + */
|
| + public static final class DeleteReceiver extends BroadcastReceiver {
|
| + public void onReceive(Context context, Intent intent) {
|
| + nativeNotificationDismissed();
|
| + }
|
| + }
|
| +
|
| + /**
|
| * Removes the notification after a timeout period.
|
| */
|
| public static final class TimeoutReceiver extends BroadcastReceiver {
|
| @@ -44,19 +65,19 @@ public class ContentSuggestionsNotificationHelper {
|
| int id = intent.getIntExtra(NOTIFICATION_ID_EXTRA, -1);
|
| if (id < 0) return;
|
| hideNotification(id);
|
| + nativeNotificationExpired();
|
| }
|
| }
|
|
|
| - @CalledByNative
|
| - private static void openUrl(String url) {
|
| + private static void openUrl(Uri uri) {
|
| Context context = ContextUtils.getApplicationContext();
|
| - Intent intent = new Intent();
|
| - intent.setAction(Intent.ACTION_VIEW);
|
| - intent.setData(Uri.parse(url));
|
| - intent.setClass(context, ChromeLauncherActivity.class);
|
| - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
| - intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
|
| - intent.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true);
|
| + 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);
|
| }
|
| @@ -81,16 +102,13 @@ public class ContentSuggestionsNotificationHelper {
|
| }
|
| }
|
|
|
| - Intent intent = new Intent()
|
| - .setAction(Intent.ACTION_VIEW)
|
| - .setData(Uri.parse(url))
|
| - .setClass(context, ChromeLauncherActivity.class)
|
| - .putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true)
|
| - .putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
|
| + Intent contentIntent = new Intent(context, OpenUrlReceiver.class).setData(Uri.parse(url));
|
| + Intent deleteIntent = new Intent(context, DeleteReceiver.class).setData(Uri.parse(url));
|
| NotificationCompat.Builder builder =
|
| new NotificationCompat.Builder(context)
|
| .setAutoCancel(true)
|
| - .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0))
|
| + .setContentIntent(PendingIntent.getBroadcast(context, 0, contentIntent, 0))
|
| + .setDeleteIntent(PendingIntent.getBroadcast(context, 0, deleteIntent, 0))
|
| .setContentTitle(title)
|
| .setContentText(text)
|
| .setGroup(NOTIFICATION_TAG)
|
| @@ -134,4 +152,8 @@ public class ContentSuggestionsNotificationHelper {
|
| manager.cancel(NOTIFICATION_TAG, 0);
|
| }
|
| }
|
| +
|
| + private static native void nativeNotificationTapped();
|
| + private static native void nativeNotificationDismissed();
|
| + private static native void nativeNotificationExpired();
|
| }
|
|
|