Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/notifications/WebApkNotificationClient.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/WebApkNotificationClient.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/WebApkNotificationClient.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6fd974299daa7a49173d488cf8da0ad7727315e1 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/WebApkNotificationClient.java |
| @@ -0,0 +1,73 @@ |
| +// Copyright 2016 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.notifications; |
| + |
| +import android.os.RemoteException; |
| + |
| +import org.chromium.base.Callback; |
| +import org.chromium.base.Log; |
| +import org.chromium.webapk.lib.client.WebApkServiceConnectionManager; |
| +import org.chromium.webapk.lib.runtime_library.IWebApkApi; |
| + |
| +/** |
| + * WebApkNotificationClient provides API to open/close notifications from WebAPK. |
|
Peter Beverloo
2016/05/19 15:59:00
Comment suggestion:
* This class provides an API
pkotwicz
2016/05/20 00:45:19
Yes, we can modify this class as we please
|
| + */ |
| +public class WebApkNotificationClient { |
| + private static final String TAG = "cr_WebApk"; |
| + |
| + // Callback which catches RemoteExceptions thrown due to IWebApkApi failure. |
|
Peter Beverloo
2016/05/19 15:59:00
This seems like a very generic concept, is this th
pkotwicz
2016/05/20 00:45:19
I think of ApiUseCallback as a convenience class.
|
| + private abstract static class ApiUseCallback implements Callback<IWebApkApi> { |
| + public abstract void useApi(IWebApkApi api) throws RemoteException; |
| + |
| + @Override |
| + public void onResult(IWebApkApi api) { |
| + try { |
| + useApi(api); |
| + } catch (RemoteException e) { |
| + Log.w(TAG, "WebApkAPI use failed.", e); |
| + } |
| + } |
| + } |
| + |
| + /** |
| + * Connect to a WebAPK's bound service, build a notification and hand it over to the WebAPK to |
| + * display. Handing over the notification makes the notification look like it originated from |
| + * the WebAPK - not Chrome - in the Android UI. |
| + * @param webApkPackage Package of the WebAPK to bind to. |
| + * @param notificationBuilder |
| + * @param platformTag |
| + * @param platformID |
|
Peter Beverloo
2016/05/19 15:59:00
nit: I think our style guide says that parameters
pkotwicz
2016/05/20 00:45:19
Removed the @params
|
| + */ |
| + public static void displayNotification(String webApkPackage, |
| + final NotificationBuilderBase notificationBuilder, final String platformTag, |
| + final int platformID) { |
| + final ApiUseCallback connectionCallback = new ApiUseCallback() { |
| + @Override |
| + public void useApi(IWebApkApi api) throws RemoteException { |
| + notificationBuilder.setSmallIcon(api.getSmallIconId()); |
|
Peter Beverloo
2016/05/19 15:59:00
Is a WebAPK guaranteed to have a small icon Id spe
pkotwicz
2016/05/20 00:45:19
I am unsure what we will do in the long term. Righ
Peter Beverloo
2016/05/20 14:12:15
These badges are Bitmaps, which indeed require M+.
|
| + api.displayNotification(platformTag, platformID, notificationBuilder.build()); |
| + } |
| + }; |
| + |
| + WebApkServiceConnectionManager.getInstance().connect(webApkPackage, connectionCallback); |
| + } |
| + |
| + /** |
| + * Closes notification previously shown by WebAPK. |
| + * @param webApkPackage Package of the WebAPK which displayed the notification. |
| + * @param platformTag |
| + * @param platformID |
| + */ |
| + public static void closeNotification( |
| + String webApkPackage, final String platformTag, final int platformID) { |
| + final ApiUseCallback connectionCallback = new ApiUseCallback() { |
| + @Override |
| + public void useApi(IWebApkApi api) throws RemoteException { |
| + api.closeNotification(platformTag, platformID); |
| + } |
| + }; |
| + WebApkServiceConnectionManager.getInstance().connect(webApkPackage, connectionCallback); |
| + } |
| +} |