| 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..ea3f556638fabe622aa957072841d22150b38227
|
| --- /dev/null
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkDisclosureNotificationManager.java
|
| @@ -0,0 +1,67 @@
|
| +// 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;
|
| +
|
| +/**
|
| + * Manages the notification indicating that a WebApk is backed by chrome code and may share data.
|
| + * It's shown while an Unbound WebApk is displayed in the foreground until the user dismisses it.
|
| + */
|
| +public class WebApkDisclosureNotificationManager {
|
| + // We always use the same integer id when showing and closing notifications. The notification
|
| + // tag is always set, which is a safe and sufficient way of identifying a notification, so the
|
| + // integer id is not needed anymore except it must not vary in an uncontrolled way.
|
| + private static final int PLATFORM_ID = 100;
|
| +
|
| + // Prefix used for generating a unique notification tag.
|
| + private static final String DISMISSAL_NOTIFICATION_TAG_PREFIX =
|
| + "dismissal_notification_tag_prefix.";
|
| + /**
|
| + * Shows the privacy disclosure informing the user that Chrome is being used.
|
| + * @param webappInfo Web App this is currently displayed fullscreen.
|
| + */
|
| + public static void showDisclosure(WebappInfo webappInfo) {
|
| + Context context = ContextUtils.getApplicationContext();
|
| + String title = webappInfo.shortName();
|
| +
|
| + StandardNotificationBuilder builder =
|
| + new StandardNotificationBuilder(context, ChannelDefinitions.CHANNEL_ID_BROWSER);
|
| + builder.setTitle(title)
|
| + .setPriority(Notification.PRIORITY_MIN)
|
| + .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));
|
| +
|
| + WebApkNotificationClient.notifyNotification(webappInfo.webApkPackageName(), builder,
|
| + DISMISSAL_NOTIFICATION_TAG_PREFIX + webappInfo.webApkPackageName(), PLATFORM_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);
|
| + }
|
| +
|
| + /**
|
| + * Dismisses the notification.
|
| + * @param webappInfo Web App this is currently displayed fullscreen.
|
| + */
|
| + public static void dismissNotification(WebappInfo webappInfo) {
|
| + WebApkNotificationClient.cancelNotification(
|
| + webappInfo.webApkPackageName(),
|
| + DISMISSAL_NOTIFICATION_TAG_PREFIX + webappInfo.webApkPackageName(),
|
| + PLATFORM_ID);
|
| + }
|
| +}
|
|
|