Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkDisclosureNotificationManager.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkDisclosureNotificationManager.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkDisclosureNotificationManager.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5fc75a0b5a8f28acbb22143420c31d841f338759 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkDisclosureNotificationManager.java |
| @@ -0,0 +1,64 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.webapps; |
| + |
| +import android.app.Notification; |
| +import android.content.Context; |
| +import android.graphics.BitmapFactory; |
| + |
| +import org.chromium.base.ContextUtils; |
| +import org.chromium.chrome.R; |
| +import org.chromium.chrome.browser.notifications.NotificationUmaTracker; |
| +import org.chromium.chrome.browser.notifications.StandardNotificationBuilder; |
| +import org.chromium.chrome.browser.notifications.WebApkNotificationClient; |
| +import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions; |
| + |
| +import java.util.Random; |
| + |
| +/** |
| + * Manages the notification indicating that a WebApk is backed by chrome code and may share data. |
| + */ |
| +public class WebApkDisclosureNotificationManager { |
| + private static final String WEBAPK_OPEN_TAG = "webapk_notification"; |
| + |
| + /** |
| + * Shows the privacy disclosure informing the user that Chrome is being used. |
| + * @param webappInfo Web App this is currently displayed fullscreen. |
| + * @param storage |
| + * @return identifier used to display the notification |
|
awdf
2017/05/24 14:47:42
nit: indentation is weird
|
| + */ |
| + public static int showDisclosure(WebappInfo webappInfo, WebappDataStorage storage) { |
|
dominickn
2017/05/24 01:24:36
The WebappDataStorage isn't currently used in here
Yaron
2017/05/24 14:59:25
omitted - can't pass it as part of the intent so p
|
| + Context context = ContextUtils.getApplicationContext(); |
| + String title = webappInfo.shortName(); |
| + |
| + StandardNotificationBuilder builder = new StandardNotificationBuilder(context); |
| + builder.setTitle(title) |
| + .setVisibility(Notification.VISIBILITY_SECRET) |
| + .setLargeIcon(BitmapFactory.decodeResource( |
| + context.getResources(), R.drawable.ic_launcher)) |
| + .setDeleteIntent(WebApkDisclosureNotificationService.getDeleteIntent( |
| + context, webappInfo.id())) |
| + .setBody(context.getResources().getString( |
| + R.string.webapk_running_in_chrome_disclosure, title)); |
| + |
| + int id = (new Random()).nextInt(); |
| + WebApkNotificationClient.notifyNotification(webappInfo.webApkPackageName(), |
| + builder, WEBAPK_OPEN_TAG, id); |
| + // Even though the Notification is shown via the WebApk, we still want to record UMA. |
| + NotificationUmaTracker.getInstance().onNotificationShown( |
| + NotificationUmaTracker.WEBAPK, ChannelDefinitions.CHANNEL_ID_BROWSER); |
|
awdf
2017/05/24 14:47:42
Here you're recording that the notification is ass
|
| + return id; |
| + } |
| + |
| + /** |
| + * Dismisses the notification. |
| + * @param webappInfo Web App this is currently displayed fullscreen. |
| + * @param id The identifier for the tag to dismiss. |
| + */ |
| + public static void dismissNotification(WebappInfo webappInfo, int id) { |
| + WebApkNotificationClient.cancelNotification( |
| + webappInfo.webApkPackageName(), WEBAPK_OPEN_TAG, id); |
| + } |
| +} |