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

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

Issue 1969873003: Remove WebApkServiceImpl#getBroadcastPendingIntent() because it is unneeded (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
« no previous file with comments | « no previous file | chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/NotificationClient.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7a26a4a93ce65ca16224f6fa0bd7c87126b38ab1..c611f2ae215719bd5c56b3ccf3e96923bc51cad8 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
@@ -305,21 +305,21 @@ public class NotificationPlatformBridge {
}
/**
- * Returns the Intent to create a PendingIntent for completing |action| on the notification
- * identified by the data in the other parameters.
+ * Returns the PendingIntent for completing |action| on the notification identified by the data
+ * in the other parameters.
*
* @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
- * @param webApkPackage The package of the WebAPK associated with the notification.
- * Empty if the notification is not associated with a WebAPK.
+ * @param webApkPackage The package of the WebAPK associated with the notification. Empty if
+ * the notification is not associated with a WebAPK.
* @param tag The tag of the notification. May be NULL.
* @param actionIndex The zero-based index of the action button, or -1 if not applicable.
*/
- private Intent makeIntent(String action, long persistentNotificationId, String origin,
- String profileId, boolean incognito, @Nullable String webApkPackage,
+ private PendingIntent makePendingIntent(String action, long persistentNotificationId,
+ String origin, String profileId, boolean incognito, @Nullable String webApkPackage,
@Nullable String tag, int actionIndex) {
Uri intentData = makeIntentData(persistentNotificationId, origin, actionIndex);
Intent intent = new Intent(action, intentData);
@@ -335,24 +335,6 @@ public class NotificationPlatformBridge {
NotificationConstants.EXTRA_NOTIFICATION_INFO_WEB_APK_PACKAGE, webApkPackage);
intent.putExtra(NotificationConstants.EXTRA_NOTIFICATION_INFO_ACTION_INDEX, actionIndex);
- return intent;
- }
- /**
- * Returns the PendingIntent for completing |action| on the notification identified by the data
- * in the other parameters.
- *
- * @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 tag The tag of the notification. May be NULL.
- * @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) {
- Intent intent = makeIntent(action, persistentNotificationId, origin, profileId, incognito,
- null, tag, actionIndex);
-
return PendingIntent.getBroadcast(mAppContext, PENDING_INTENT_REQUEST_CODE, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
@@ -504,8 +486,7 @@ public class NotificationPlatformBridge {
throw new IllegalArgumentException("The number of action titles and icons must match.");
}
- final NotificationBuilderBase notificationBuilder = createNotificationBuilder();
- final String platformTag = makePlatformTag(persistentNotificationId, origin, tag);
+ Resources res = mAppContext.getResources();
// Record whether it's known whether notifications can be shown to the user at all.
RecordHistogram.recordEnumeratedHistogram(
@@ -513,127 +494,71 @@ public class NotificationPlatformBridge {
NotificationSystemStatusUtil.determineAppNotificationStatus(mAppContext),
NotificationSystemStatusUtil.APP_NOTIFICATIONS_STATUS_BOUNDARY);
- buildNotification(notificationBuilder,
- true /* hasSettings */, actionTitles != null ? actionTitles.length : 0,
- persistentNotificationId, origin, profileId, incognito, tag,
- title, body, icon, badge, vibrationPattern, timestamp, renotify, silent);
+ // Set up a pending intent for going to the settings screen for |origin|.
+ Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(
+ mAppContext, SingleWebsitePreferences.class.getName());
+ settingsIntent.setData(
+ makeIntentData(persistentNotificationId, origin, -1 /* actionIndex */));
+ settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS,
+ SingleWebsitePreferences.createFragmentArgsForSite(origin));
- if (!webApkPackage.isEmpty()) {
- displayNotificationInWebAPK(notificationBuilder, persistentNotificationId, origin,
- profileId, incognito, tag, webApkPackage, actionTitles, actionIcons,
- platformTag);
- return;
- } else {
- PendingIntent clickIntent = makePendingIntent(
- NotificationConstants.ACTION_CLICK_NOTIFICATION, persistentNotificationId,
- origin, profileId, incognito, tag, -1 /* actionIndex */);
- PendingIntent closeIntent = makePendingIntent(
- NotificationConstants.ACTION_CLOSE_NOTIFICATION, persistentNotificationId,
- origin, profileId, incognito, tag, -1 /* actionIndex */);
- notificationBuilder.setContentIntent(clickIntent)
- .setDeleteIntent(closeIntent);
-
- PendingIntent[] actionIntents = null;
- if (actionTitles.length > 0) {
- actionIntents = new PendingIntent[actionTitles.length];
- for (int actionIndex = 0; actionIndex < actionTitles.length;
- actionIndex++) {
- notificationBuilder.addAction(actionIcons[actionIndex],
- actionTitles[actionIndex],
- makePendingIntent(NotificationConstants.ACTION_CLICK_NOTIFICATION,
- persistentNotificationId, origin, profileId,
- incognito, tag, actionIndex));
- }
- }
- mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilder.build());
- }
- }
-
- /**
- * Build and format a notification to display. Every fields (except PendingIntents) are set
- * to the notification builder within this function.
- */
- private void buildNotification(NotificationBuilderBase notificationBuilder,
- boolean hasSettings, int actionLength,
- 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) {
- Resources res = mAppContext.getResources();
- PendingIntent pendingSettingsIntent = null;
- if (hasSettings) {
- // Set up a pending intent for going to the settings screen for |origin|.
- Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage(
- mAppContext, SingleWebsitePreferences.class.getName());
- settingsIntent.setData(
- makeIntentData(persistentNotificationId, origin, -1 /* actionIndex */));
- settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS,
- SingleWebsitePreferences.createFragmentArgsForSite(origin));
-
- pendingSettingsIntent = PendingIntent.getActivity(mAppContext,
- PENDING_INTENT_REQUEST_CODE, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent pendingSettingsIntent = PendingIntent.getActivity(mAppContext,
+ PENDING_INTENT_REQUEST_CODE, settingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent clickIntent = makePendingIntent(
+ NotificationConstants.ACTION_CLICK_NOTIFICATION, persistentNotificationId, origin,
+ profileId, incognito, webApkPackage, tag, -1 /* actionIndex */);
+ PendingIntent closeIntent = makePendingIntent(
+ NotificationConstants.ACTION_CLOSE_NOTIFICATION, persistentNotificationId,
+ origin, profileId, incognito, webApkPackage, tag, -1 /* actionIndex */);
+
+ NotificationBuilderBase notificationBuilder =
+ createNotificationBuilder()
+ .setTitle(title)
+ .setBody(body)
+ .setLargeIcon(ensureNormalizedIcon(icon, origin))
+ .setSmallIcon(R.drawable.ic_chrome)
+ .setSmallIcon(badge)
+ .setContentIntent(clickIntent)
+ .setDeleteIntent(closeIntent)
+ .setTicker(createTickerText(title, body))
+ .setTimestamp(timestamp)
+ .setRenotify(renotify)
+ .setOrigin(UrlUtilities.formatUrlForSecurityDisplay(
+ origin, false /* showScheme */));
+
+ for (int actionIndex = 0; actionIndex < actionTitles.length; actionIndex++) {
+ notificationBuilder.addAction(actionIcons[actionIndex], actionTitles[actionIndex],
+ makePendingIntent(NotificationConstants.ACTION_CLICK_NOTIFICATION,
+ persistentNotificationId, origin, profileId,
+ incognito, webApkPackage, tag, actionIndex));
}
- notificationBuilder.setTitle(title)
- .setBody(body)
- .setLargeIcon(ensureNormalizedIcon(icon, origin))
- .setSmallIcon(R.drawable.ic_chrome)
- .setSmallIcon(badge)
- .setTicker(createTickerText(title, body))
- .setTimestamp(timestamp)
- .setRenotify(renotify)
- .setOrigin(UrlUtilities.formatUrlForSecurityDisplay(
- origin, false /* showScheme */));
- if (hasSettings) {
- // If action buttons are displayed, there isn't room for the full Site Settings button
- // label and icon, so abbreviate it. This has the unfortunate side-effect of
- // unnecessarily abbreviating it on Android Wear also (crbug.com/576656).
- // If custom layouts are enabled, the label and icon provided here only affect
- // Android Wear, so don't abbreviate them.
- boolean abbreviateSiteSettings = actionLength > 0 && !useCustomLayouts();
- int settingsIconId = abbreviateSiteSettings ? 0 : R.drawable.settings_cog;
- CharSequence settingsTitle = abbreviateSiteSettings
- ? res.getString(R.string.notification_site_settings_button)
- : res.getString(R.string.page_info_site_settings_button);
- // If the settings button is displayed together with the other buttons it has to
- // be the last one, so add it after the other actions.
- notificationBuilder.addSettingsAction(settingsIconId, settingsTitle,
- pendingSettingsIntent);
- }
+ // If action buttons are displayed, there isn't room for the full Site Settings button
+ // label and icon, so abbreviate it. This has the unfortunate side-effect of unnecessarily
+ // abbreviating it on Android Wear also (crbug.com/576656). If custom layouts are enabled,
+ // the label and icon provided here only affect Android Wear, so don't abbreviate them.
+ boolean abbreviateSiteSettings = actionTitles.length > 0 && !useCustomLayouts();
+ int settingsIconId = abbreviateSiteSettings ? 0 : R.drawable.settings_cog;
+ CharSequence settingsTitle = abbreviateSiteSettings
+ ? res.getString(R.string.notification_site_settings_button)
+ : res.getString(R.string.page_info_site_settings_button);
+ // If the settings button is displayed together with the other buttons it has to be the last
+ // one, so add it after the other actions.
+ notificationBuilder.addSettingsAction(settingsIconId, settingsTitle, pendingSettingsIntent);
notificationBuilder.setDefaults(makeDefaults(vibrationPattern.length, silent));
if (vibrationPattern.length > 0) {
notificationBuilder.setVibrate(makeVibrationPattern(vibrationPattern));
}
- }
- /**
- * Bind to the Service of required WebAPK, create an notification and display.
- */
- private void displayNotificationInWebAPK(NotificationBuilderBase notificationBuilder,
- long persistentNotificationId, String origin, String profileId,
- boolean incognito, String tag, String webApkPackage, String[] actionTitles,
- Bitmap[] actionIcons, String platformTag) {
- Intent clickIntent = makeIntent(NotificationConstants.ACTION_CLICK_NOTIFICATION,
- persistentNotificationId, origin,
- profileId, incognito, webApkPackage, tag, -1 /* actionIndex */);
- Intent closeIntent = makeIntent(NotificationConstants.ACTION_CLOSE_NOTIFICATION,
- persistentNotificationId, origin, profileId, incognito, webApkPackage,
- tag, -1 /* actionIndex */);
- Intent[] actionIntents = null;
- if (actionTitles.length > 0) {
- actionIntents = new Intent[actionTitles.length];
- for (int actionIndex = 0; actionIndex < actionTitles.length;
- actionIndex++) {
- actionIntents[actionIndex] = makeIntent(
- NotificationConstants.ACTION_CLICK_NOTIFICATION, persistentNotificationId,
- origin, profileId, incognito, webApkPackage, tag, actionIndex);
- }
+ String platformTag = makePlatformTag(persistentNotificationId, origin, tag);
+ if (webApkPackage.isEmpty()) {
+ mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilder.build());
+ } else {
+ new NotificationClient().displayNotification(
+ notificationBuilder, platformTag, PLATFORM_ID, webApkPackage);
}
- NotificationClient client = new NotificationClient();
- client.displayNotification(PENDING_INTENT_REQUEST_CODE, notificationBuilder, clickIntent,
- closeIntent, actionIntents, actionTitles, actionIcons,
- PendingIntent.FLAG_UPDATE_CURRENT, platformTag, PLATFORM_ID, webApkPackage);
}
private NotificationBuilderBase createNotificationBuilder() {
« no previous file with comments | « no previous file | chrome/android/webapk/libs/client/src/org/chromium/webapk/lib/client/NotificationClient.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698