Chromium Code Reviews| 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..62aaf1fe9c1380844f84ab9323b2fa73d70904d4 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 |
| @@ -37,6 +37,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(); |
|
Bernhard Bauer
2017/01/11 15:21:49
Do you actually know that the native library has b
sfiera
2017/01/11 15:41:51
Ah, no, I don't (checked; it may not be). I really
Bernhard Bauer
2017/01/11 15:58:24
That's the thing. Loading the native library is qu
sfiera
2017/01/12 11:26:23
In the OpenUrlReceiver, we're going to be spinning
Bernhard Bauer
2017/01/12 12:13:52
What do you mean by not block?
sfiera
2017/01/12 12:50:24
Here, it's not safe yet to call the native method,
|
| + } |
| + } |
| + |
| + /** |
| + * 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 +63,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 +100,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 +150,8 @@ public class ContentSuggestionsNotificationHelper { |
| manager.cancel(NOTIFICATION_TAG, 0); |
| } |
| } |
| + |
| + private static native void nativeNotificationTapped(); |
| + private static native void nativeNotificationDismissed(); |
| + private static native void nativeNotificationExpired(); |
| } |