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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/notifications/NotificationBuilderBase.java

Issue 2841193002: Implement privacy disclosure for an unbound webapk. (Closed)
Patch Set: nit Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.notifications; 5 package org.chromium.chrome.browser.notifications;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.annotation.TargetApi; 8 import android.annotation.TargetApi;
9 import android.app.Notification; 9 import android.app.Notification;
10 import android.app.PendingIntent; 10 import android.app.PendingIntent;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 /** 101 /**
102 * The maximum number of author provided action buttons. The settings button is not part of this 102 * The maximum number of author provided action buttons. The settings button is not part of this
103 * count. 103 * count.
104 */ 104 */
105 private static final int MAX_AUTHOR_PROVIDED_ACTION_BUTTONS = 2; 105 private static final int MAX_AUTHOR_PROVIDED_ACTION_BUTTONS = 2;
106 106
107 private final int mLargeIconWidthPx; 107 private final int mLargeIconWidthPx;
108 private final int mLargeIconHeightPx; 108 private final int mLargeIconHeightPx;
109 private final RoundedIconGenerator mIconGenerator; 109 private final RoundedIconGenerator mIconGenerator;
110 protected final String mChannelId;
110 111
111 protected CharSequence mTitle; 112 protected CharSequence mTitle;
112 protected CharSequence mBody; 113 protected CharSequence mBody;
113 protected CharSequence mOrigin; 114 protected CharSequence mOrigin;
114 protected CharSequence mTickerText; 115 protected CharSequence mTickerText;
115 protected Bitmap mImage; 116 protected Bitmap mImage;
116 protected int mSmallIconId; 117 protected int mSmallIconId;
117 protected Bitmap mSmallIconBitmap; 118 protected Bitmap mSmallIconBitmap;
118 protected PendingIntent mContentIntent; 119 protected PendingIntent mContentIntent;
119 protected PendingIntent mDeleteIntent; 120 protected PendingIntent mDeleteIntent;
120 protected List<Action> mActions = new ArrayList<>(MAX_AUTHOR_PROVIDED_ACTION _BUTTONS); 121 protected List<Action> mActions = new ArrayList<>(MAX_AUTHOR_PROVIDED_ACTION _BUTTONS);
121 protected Action mSettingsAction; 122 protected Action mSettingsAction;
122 protected int mDefaults = Notification.DEFAULT_ALL; 123 protected int mDefaults = Notification.DEFAULT_ALL;
123 protected long[] mVibratePattern; 124 protected long[] mVibratePattern;
124 protected long mTimestamp; 125 protected long mTimestamp;
125 protected boolean mRenotify; 126 protected boolean mRenotify;
126 127 protected int mPriority;
127 private Bitmap mLargeIcon; 128 private Bitmap mLargeIcon;
128 129
129 public NotificationBuilderBase(Resources resources) { 130 public NotificationBuilderBase(
131 Resources resources, @ChannelDefinitions.ChannelId String channelId) {
130 mLargeIconWidthPx = 132 mLargeIconWidthPx =
131 resources.getDimensionPixelSize(android.R.dimen.notification_lar ge_icon_width); 133 resources.getDimensionPixelSize(android.R.dimen.notification_lar ge_icon_width);
132 mLargeIconHeightPx = 134 mLargeIconHeightPx =
133 resources.getDimensionPixelSize(android.R.dimen.notification_lar ge_icon_height); 135 resources.getDimensionPixelSize(android.R.dimen.notification_lar ge_icon_height);
134 mIconGenerator = createIconGenerator(resources); 136 mIconGenerator = createIconGenerator(resources);
137 mChannelId = channelId;
135 } 138 }
136 139
137 /** 140 /**
138 * Combines all of the options that have been set and returns a new Notifica tion object. 141 * Combines all of the options that have been set and returns a new Notifica tion object.
139 */ 142 */
140 public abstract Notification build(); 143 public abstract Notification build();
141 144
142 /** 145 /**
143 * Sets the title text of the notification. 146 * Sets the title text of the notification.
144 */ 147 */
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 296
294 /** 297 /**
295 * Sets the vibration pattern to use. 298 * Sets the vibration pattern to use.
296 */ 299 */
297 public NotificationBuilderBase setVibrate(long[] pattern) { 300 public NotificationBuilderBase setVibrate(long[] pattern) {
298 mVibratePattern = Arrays.copyOf(pattern, pattern.length); 301 mVibratePattern = Arrays.copyOf(pattern, pattern.length);
299 return this; 302 return this;
300 } 303 }
301 304
302 /** 305 /**
306 * Sets the priority of the notification (if set to private, overrides |setD efaults| and
307 * |setVibrate|)
308 */
309 public NotificationBuilderBase setPriority(int priority) {
310 mPriority = priority;
311 return this;
312 }
313
314 /**
303 * Sets the timestamp at which the event of the notification took place. 315 * Sets the timestamp at which the event of the notification took place.
304 */ 316 */
305 public NotificationBuilderBase setTimestamp(long timestamp) { 317 public NotificationBuilderBase setTimestamp(long timestamp) {
306 mTimestamp = timestamp; 318 mTimestamp = timestamp;
307 return this; 319 return this;
308 } 320 }
309 321
310 /** 322 /**
311 * Sets the behavior for when the notification is replaced. 323 * Sets the behavior for when the notification is replaced.
312 */ 324 */
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 367
356 /** 368 /**
357 * Creates a public version of the notification to be displayed in sensitive contexts, such as 369 * Creates a public version of the notification to be displayed in sensitive contexts, such as
358 * on the lockscreen, displaying just the site origin and badge or generated icon. 370 * on the lockscreen, displaying just the site origin and badge or generated icon.
359 */ 371 */
360 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 372 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
361 protected Notification createPublicNotification(Context context) { 373 protected Notification createPublicNotification(Context context) {
362 // Use a non-compat builder because we want the default small icon behav iour. 374 // Use a non-compat builder because we want the default small icon behav iour.
363 ChromeNotificationBuilder builder = 375 ChromeNotificationBuilder builder =
364 NotificationBuilderFactory 376 NotificationBuilderFactory
365 .createChromeNotificationBuilder( 377 .createChromeNotificationBuilder(false /* preferCompat * /, mChannelId)
366 false /* preferCompat */, ChannelDefinitions.CHA NNEL_ID_SITES)
367 .setContentText(context.getString( 378 .setContentText(context.getString(
368 org.chromium.chrome.R.string.notification_hidden _text)) 379 org.chromium.chrome.R.string.notification_hidden _text))
369 .setSmallIcon(org.chromium.chrome.R.drawable.ic_chrome); 380 .setSmallIcon(org.chromium.chrome.R.drawable.ic_chrome);
370 381
371 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { 382 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
372 // On N, 'subtext' displays at the top of the notification and this looks better. 383 // On N, 'subtext' displays at the top of the notification and this looks better.
373 builder.setSubText(mOrigin); 384 builder.setSubText(mOrigin);
374 } else { 385 } else {
375 // Set origin as title on L & M, because they look odd without one. 386 // Set origin as title on L & M, because they look odd without one.
376 builder.setContentTitle(mOrigin); 387 builder.setContentTitle(mOrigin);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 int largeIconWidthPx = 496 int largeIconWidthPx =
486 resources.getDimensionPixelSize(android.R.dimen.notification_lar ge_icon_width); 497 resources.getDimensionPixelSize(android.R.dimen.notification_lar ge_icon_width);
487 int largeIconHeightPx = 498 int largeIconHeightPx =
488 resources.getDimensionPixelSize(android.R.dimen.notification_lar ge_icon_height); 499 resources.getDimensionPixelSize(android.R.dimen.notification_lar ge_icon_height);
489 float density = resources.getDisplayMetrics().density; 500 float density = resources.getDisplayMetrics().density;
490 int cornerRadiusPx = Math.min(largeIconWidthPx, largeIconHeightPx) / 2; 501 int cornerRadiusPx = Math.min(largeIconWidthPx, largeIconHeightPx) / 2;
491 return new RoundedIconGenerator(largeIconWidthPx, largeIconHeightPx, cor nerRadiusPx, 502 return new RoundedIconGenerator(largeIconWidthPx, largeIconHeightPx, cor nerRadiusPx,
492 NOTIFICATION_ICON_BG_COLOR, NOTIFICATION_ICON_TEXT_SIZE_DP * den sity); 503 NOTIFICATION_ICON_BG_COLOR, NOTIFICATION_ICON_TEXT_SIZE_DP * den sity);
493 } 504 }
494 } 505 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698