Index: chrome/browser/notifications/notification_platform_bridge_android.cc |
diff --git a/chrome/browser/notifications/notification_platform_bridge_android.cc b/chrome/browser/notifications/notification_platform_bridge_android.cc |
index 7e928f279298e93015e0d898ff4596204b01869a..12aa848594ae025338eb6e805285323e624b9ca4 100644 |
--- a/chrome/browser/notifications/notification_platform_bridge_android.cc |
+++ b/chrome/browser/notifications/notification_platform_bridge_android.cc |
@@ -9,6 +9,7 @@ |
#include "base/android/jni_array.h" |
#include "base/android/jni_string.h" |
+#include "base/bind.h" |
#include "base/command_line.h" |
#include "base/files/file_path.h" |
#include "base/logging.h" |
@@ -43,6 +44,10 @@ using base::android::ScopedJavaLocalRef; |
namespace { |
+// Callback to call after querying WebAPK package name is done. |
+// The parameter is the package name of the WebAPK that matches the query. |
+using QueryWebApkPackageCallback = base::Callback<void(const std::string&)>; |
+ |
// A Java counterpart will be generated for this enum. |
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.notifications |
enum NotificationActionType { |
@@ -139,7 +144,8 @@ NotificationPlatformBridge* NotificationPlatformBridge::Create() { |
return new NotificationPlatformBridgeAndroid(); |
} |
-NotificationPlatformBridgeAndroid::NotificationPlatformBridgeAndroid() { |
+NotificationPlatformBridgeAndroid::NotificationPlatformBridgeAndroid() |
+ : weak_ptr_factory_(this) { |
java_object_.Reset(Java_NotificationPlatformBridge_create( |
AttachCurrentThread(), reinterpret_cast<intptr_t>(this))); |
} |
@@ -231,12 +237,26 @@ void NotificationPlatformBridgeAndroid::Display( |
scope_url = origin_url; |
pkotwicz
2017/07/10 19:06:06
Nit: Can you remove |origin_url| and initialize |s
Xi Han
2017/07/12 13:49:14
Done.
|
ScopedJavaLocalRef<jstring> j_scope_url = |
ConvertUTF8ToJavaString(env, scope_url.spec()); |
- ScopedJavaLocalRef<jstring> webapk_package = |
- Java_NotificationPlatformBridge_queryWebApkPackage( |
- env, java_object_, j_scope_url); |
+ uintptr_t callback_pointer = |
+ reinterpret_cast<uintptr_t>(new QueryWebApkPackageCallback(base::Bind( |
+ &NotificationPlatformBridgeAndroid::OnQueryWebApkPackageInternal, |
+ weak_ptr_factory_.GetWeakPtr(), notification_id, profile_id, |
+ incognito, notification))); |
+ Java_NotificationPlatformBridge_queryWebApkPackage( |
+ env, java_object_, j_scope_url, callback_pointer); |
+} |
+void NotificationPlatformBridgeAndroid::OnQueryWebApkPackageInternal( |
+ const std::string& notification_id, |
+ const std::string& profile_id, |
+ bool incognito, |
+ const Notification& notification, |
+ const std::string& webapk_package) { |
+ JNIEnv* env = AttachCurrentThread(); |
ScopedJavaLocalRef<jstring> j_notification_id = |
ConvertUTF8ToJavaString(env, notification_id); |
+ |
+ GURL origin_url(notification.origin_url().GetOrigin()); |
ScopedJavaLocalRef<jstring> j_origin = |
ConvertUTF8ToJavaString(env, origin_url.spec()); |
ScopedJavaLocalRef<jstring> tag = |
@@ -269,16 +289,32 @@ void NotificationPlatformBridgeAndroid::Display( |
ScopedJavaLocalRef<jstring> j_profile_id = |
ConvertUTF8ToJavaString(env, profile_id); |
+ ScopedJavaLocalRef<jstring> j_webapk_package = |
+ ConvertUTF8ToJavaString(env, webapk_package); |
Java_NotificationPlatformBridge_displayNotification( |
env, java_object_, j_notification_id, j_origin, j_profile_id, incognito, |
- tag, webapk_package, title, body, image, notification_icon, badge, |
+ tag, j_webapk_package, title, body, image, notification_icon, badge, |
vibration_pattern, notification.timestamp().ToJavaTime(), |
notification.renotify(), notification.silent(), actions); |
regenerated_notification_infos_[notification_id] = |
RegeneratedNotificationInfo(origin_url.spec(), notification.tag(), |
- ConvertJavaStringToUTF8(env, webapk_package)); |
+ webapk_package); |
+} |
+ |
+void NotificationPlatformBridgeAndroid::OnQueryWebApkPackage( |
+ JNIEnv* env, |
+ const JavaParamRef<jobject>& java_object, |
+ const JavaParamRef<jstring>& java_webapk_package, |
+ const jlong jcallback_pointer) { |
+ DCHECK(jcallback_pointer); |
+ std::string webapk_package = |
+ ConvertJavaStringToUTF8(env, java_webapk_package); |
+ QueryWebApkPackageCallback* callback = |
+ reinterpret_cast<QueryWebApkPackageCallback*>(jcallback_pointer); |
+ callback->Run(webapk_package); |
+ delete callback; |
} |
void NotificationPlatformBridgeAndroid::Close( |