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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java

Issue 1969303002: Upstream WebAPK notification related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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/notifications/NotificationPlatformBridge.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java
index ea0de6251f943f980700d173fd1c2b984344843e..6866f65de26a3d69a8d8dbb005ef8ab5553334ee 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationPlatformBridge.java
@@ -37,6 +37,7 @@ import org.chromium.chrome.browser.preferences.website.SingleWebsitePreferences;
import org.chromium.chrome.browser.preferences.website.SiteSettingsCategory;
import org.chromium.chrome.browser.util.UrlUtilities;
import org.chromium.chrome.browser.widget.RoundedIconGenerator;
+import org.chromium.webapk.lib.client.WebApkValidator;
import java.net.URI;
import java.net.URISyntaxException;
@@ -157,6 +158,19 @@ public class NotificationPlatformBridge {
}
/**
+ * Returns the package for the WebAPK which should handle the URL.
+ * @param url The url to check.
+ * @return Package name of the WebAPK which should handle the URL. Returns empty string if the
Peter Beverloo 2016/05/19 15:59:00 nit: other code in this file indents wrapped descr
+ * URL should not be handled by a WebAPK.
+ */
+ @CalledByNative
+ private String queryWebApkPackage(String url) {
+ String webApkPackage =
+ WebApkValidator.queryWebApkPackage(mAppContext, url);
+ return webApkPackage == null ? "" : webApkPackage;
+ }
+
+ /**
* Invoked by the NotificationService when a Notification intent has been received. There may
* not be an active instance of the NotificationPlatformBridge at this time, so inform the
* native side through a static method, initializing both ends if needed.
@@ -185,10 +199,20 @@ public class NotificationPlatformBridge {
Log.i(TAG, "Dispatching notification event to native: " + persistentNotificationId);
if (NotificationConstants.ACTION_CLICK_NOTIFICATION.equals(intent.getAction())) {
+ String webApkPackage = "";
+ if (CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_WEBAPK)) {
+ webApkPackage = intent.getStringExtra(
+ NotificationConstants.EXTRA_NOTIFICATION_INFO_WEBAPK_PACKAGE);
+ if (webApkPackage == null
+ || !sInstance.queryWebApkPackage(origin).equals(webApkPackage)) {
+ webApkPackage = "";
+ }
Peter Beverloo 2016/05/19 15:59:00 Have you considered getting rid of the empty strin
pkotwicz 2016/05/20 00:45:18 My understanding is that ConvertJavaStringToUTF8()
Peter Beverloo 2016/05/20 14:12:15 Yeah, but something like the following is easy eno
+ }
int actionIndex = intent.getIntExtra(
NotificationConstants.EXTRA_NOTIFICATION_INFO_ACTION_INDEX, -1);
sInstance.onNotificationClicked(
- persistentNotificationId, origin, profileId, incognito, tag, actionIndex);
+ persistentNotificationId, origin, profileId, incognito, tag, webApkPackage,
+ actionIndex);
return true;
} else if (NotificationConstants.ACTION_CLOSE_NOTIFICATION.equals(intent.getAction())) {
// Notification deleteIntent is executed only "when the notification is explicitly
@@ -289,12 +313,16 @@ public class NotificationPlatformBridge {
* @param action The action this pending intent will represent.
* @param persistentNotificationId The persistent id of the notification.
* @param origin The origin to whom the notification belongs.
+ * @param profileId
+ * @param incognito
Peter Beverloo 2016/05/19 15:59:00 Oops, sorry! :) Mind changing this to: @param pro
* @param tag The tag of the notification. May be NULL.
+ * @param webApkPackage The package of the WebAPK associated with the notification. Empty if
+ * the notification is not associated with a WebAPK.
Peter Beverloo 2016/05/19 15:59:00 nit: as before, alignment
* @param actionIndex The zero-based index of the action button, or -1 if not applicable.
*/
private PendingIntent makePendingIntent(String action, long persistentNotificationId,
String origin, String profileId, boolean incognito, @Nullable String tag,
- int actionIndex) {
+ @Nullable String webApkPackage, int actionIndex) {
Uri intentData = makeIntentData(persistentNotificationId, origin, actionIndex);
Intent intent = new Intent(action, intentData);
intent.setClass(mAppContext, NotificationService.Receiver.class);
@@ -305,6 +333,8 @@ public class NotificationPlatformBridge {
intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_PROFILE_ID, profileId);
intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_PROFILE_INCOGNITO, incognito);
intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_TAG, tag);
+ intent.putExtra(
+ NotificationConstants.EXTRA_NOTIFICATION_INFO_WEBAPK_PACKAGE, webApkPackage);
intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_ACTION_INDEX, actionIndex);
return PendingIntent.getBroadcast(mAppContext, PENDING_INTENT_REQUEST_CODE, intent,
@@ -451,9 +481,9 @@ public class NotificationPlatformBridge {
*/
@CalledByNative
private void displayNotification(long persistentNotificationId, String origin, String profileId,
- boolean incognito, String tag, String title, String body, Bitmap icon, Bitmap badge,
- int[] vibrationPattern, long timestamp, boolean renotify, boolean silent,
- String[] actionTitles, Bitmap[] actionIcons) {
+ boolean incognito, String tag, String webApkPackage, String title, String body,
Peter Beverloo 2016/05/19 15:59:00 You mark |webApkPackage| as @Nullable in makePendi
pkotwicz 2016/05/20 00:45:18 I removed the @Nullable annotation from makePendin
+ Bitmap icon, Bitmap badge, int[] vibrationPattern, long timestamp, boolean renotify,
+ boolean silent, String[] actionTitles, Bitmap[] actionIcons) {
if (actionTitles.length != actionIcons.length) {
throw new IllegalArgumentException("The number of action titles and icons must match.");
}
@@ -479,10 +509,10 @@ public class NotificationPlatformBridge {
PendingIntent clickIntent = makePendingIntent(
NotificationConstants.ACTION_CLICK_NOTIFICATION, persistentNotificationId, origin,
- profileId, incognito, tag, -1 /* actionIndex */);
+ profileId, incognito, tag, webApkPackage, -1 /* actionIndex */);
PendingIntent closeIntent = makePendingIntent(
NotificationConstants.ACTION_CLOSE_NOTIFICATION, persistentNotificationId, origin,
- profileId, incognito, tag, -1 /* actionIndex */);
+ profileId, incognito, tag, webApkPackage, -1 /* actionIndex */);
NotificationBuilderBase notificationBuilder =
createNotificationBuilder()
@@ -503,7 +533,7 @@ public class NotificationPlatformBridge {
notificationBuilder.addAction(actionIcons[actionIndex], actionTitles[actionIndex],
makePendingIntent(NotificationConstants.ACTION_CLICK_NOTIFICATION,
persistentNotificationId, origin, profileId,
- incognito, tag, actionIndex));
+ incognito, tag, webApkPackage, actionIndex));
}
// If action buttons are displayed, there isn't room for the full Site Settings button
@@ -525,7 +555,12 @@ public class NotificationPlatformBridge {
}
String platformTag = makePlatformTag(persistentNotificationId, origin, tag);
- mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilder.build());
+ if (webApkPackage.isEmpty()) {
+ mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilder.build());
+ } else {
+ WebApkNotificationClient.displayNotification(
+ webApkPackage, notificationBuilder, platformTag, PLATFORM_ID);
+ }
}
private NotificationBuilderBase createNotificationBuilder() {
@@ -631,13 +666,20 @@ public class NotificationPlatformBridge {
* @param persistentNotificationId The persistent id of the notification.
* @param origin The origin to which the notification belongs.
* @param tag The tag of the notification. May be NULL.
+ * @param webApkPackage The package of the WebAPK associated with the notification.
+ * Empty if the notification is not associated with a WebAPK.
Peter Beverloo 2016/05/19 15:59:00 nit: alignment
*/
@CalledByNative
- private void closeNotification(
- String profileId, long persistentNotificationId, String origin, String tag) {
+ private void closeNotification(String profileId, long persistentNotificationId, String origin,
+ String tag, String webApkPackage) {
// TODO(miguelg) make profile_id part of the tag.
String platformTag = makePlatformTag(persistentNotificationId, origin, tag);
- mNotificationManager.cancel(platformTag, PLATFORM_ID);
+
+ if (webApkPackage.isEmpty()) {
+ mNotificationManager.cancel(platformTag, PLATFORM_ID);
+ } else {
+ WebApkNotificationClient.closeNotification(webApkPackage, platformTag, PLATFORM_ID);
+ }
}
/**
@@ -649,12 +691,16 @@ public class NotificationPlatformBridge {
* @param profileId Id of the profile that showed the notification.
* @param incognito if the profile session was an off the record one.
* @param tag The tag of the notification. May be NULL.
+ * @param webApkPackage The package of the WebAPK associated with the notification.
+ * Empty if the notification is not associated with a WebAPK.
Peter Beverloo 2016/05/19 15:59:00 nit: alignment
+ * @param actionIndex
Peter Beverloo 2016/05/19 15:59:00 Oops, sorry! :) Mind changing this to: * @param a
*/
private void onNotificationClicked(long persistentNotificationId, String origin,
- String profileId, boolean incognito, String tag, int actionIndex) {
+ String profileId, boolean incognito, String tag, String webApkPackage,
+ int actionIndex) {
mLastNotificationClickMs = System.currentTimeMillis();
nativeOnNotificationClicked(mNativeNotificationPlatformBridge, persistentNotificationId,
- origin, profileId, incognito, tag, actionIndex);
+ origin, profileId, incognito, tag, webApkPackage, actionIndex);
}
/**
@@ -678,7 +724,7 @@ public class NotificationPlatformBridge {
private native void nativeOnNotificationClicked(long nativeNotificationPlatformBridgeAndroid,
long persistentNotificationId, String origin, String profileId, boolean incognito,
- String tag, int actionIndex);
+ String tag, String webApkPackage, int actionIndex);
private native void nativeOnNotificationClosed(long nativeNotificationPlatformBridgeAndroid,
long persistentNotificationId, String origin, String profileId, boolean incognito,
String tag, boolean byUser);

Powered by Google App Engine
This is Rietveld 408576698