| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/notifications/notification_platform_bridge_android.h" | 5 #include "chrome/browser/notifications/notification_platform_bridge_android.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 NotificationPlatformBridge* NotificationPlatformBridge::Create() { | 102 NotificationPlatformBridge* NotificationPlatformBridge::Create() { |
| 103 return new NotificationPlatformBridgeAndroid(); | 103 return new NotificationPlatformBridgeAndroid(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 NotificationPlatformBridgeAndroid::NotificationPlatformBridgeAndroid() { | 106 NotificationPlatformBridgeAndroid::NotificationPlatformBridgeAndroid() { |
| 107 java_object_.Reset(Java_NotificationPlatformBridge_create( | 107 java_object_.Reset(Java_NotificationPlatformBridge_create( |
| 108 AttachCurrentThread(), reinterpret_cast<intptr_t>(this))); | 108 AttachCurrentThread(), reinterpret_cast<intptr_t>(this))); |
| 109 } | 109 } |
| 110 | 110 |
| 111 NotificationPlatformBridgeAndroid::~NotificationPlatformBridgeAndroid() { | 111 NotificationPlatformBridgeAndroid::~NotificationPlatformBridgeAndroid() { |
| 112 Java_NotificationPlatformBridge_destroy(AttachCurrentThread(), | 112 Java_NotificationPlatformBridge_destroy(AttachCurrentThread(), java_object_); |
| 113 java_object_.obj()); | |
| 114 } | 113 } |
| 115 | 114 |
| 116 void NotificationPlatformBridgeAndroid::OnNotificationClicked( | 115 void NotificationPlatformBridgeAndroid::OnNotificationClicked( |
| 117 JNIEnv* env, | 116 JNIEnv* env, |
| 118 const JavaParamRef<jobject>& java_object, | 117 const JavaParamRef<jobject>& java_object, |
| 119 const JavaParamRef<jstring>& java_notification_id, | 118 const JavaParamRef<jstring>& java_notification_id, |
| 120 const JavaParamRef<jstring>& java_origin, | 119 const JavaParamRef<jstring>& java_origin, |
| 121 const JavaParamRef<jstring>& java_profile_id, | 120 const JavaParamRef<jstring>& java_profile_id, |
| 122 jboolean incognito, | 121 jboolean incognito, |
| 123 const JavaParamRef<jstring>& java_tag, | 122 const JavaParamRef<jstring>& java_tag, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 GURL origin_url(notification.origin_url().GetOrigin()); | 185 GURL origin_url(notification.origin_url().GetOrigin()); |
| 187 ScopedJavaLocalRef<jstring> webapk_package; | 186 ScopedJavaLocalRef<jstring> webapk_package; |
| 188 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 187 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 189 switches::kEnableWebApk)) { | 188 switches::kEnableWebApk)) { |
| 190 GURL scope_url(notification.service_worker_scope()); | 189 GURL scope_url(notification.service_worker_scope()); |
| 191 if (!scope_url.is_valid()) | 190 if (!scope_url.is_valid()) |
| 192 scope_url = origin_url; | 191 scope_url = origin_url; |
| 193 ScopedJavaLocalRef<jstring> j_scope_url = | 192 ScopedJavaLocalRef<jstring> j_scope_url = |
| 194 ConvertUTF8ToJavaString(env, scope_url.spec()); | 193 ConvertUTF8ToJavaString(env, scope_url.spec()); |
| 195 webapk_package = Java_NotificationPlatformBridge_queryWebApkPackage( | 194 webapk_package = Java_NotificationPlatformBridge_queryWebApkPackage( |
| 196 env, java_object_.obj(), j_scope_url.obj()); | 195 env, java_object_, j_scope_url); |
| 197 } else { | 196 } else { |
| 198 webapk_package = ConvertUTF8ToJavaString(env, ""); | 197 webapk_package = ConvertUTF8ToJavaString(env, ""); |
| 199 } | 198 } |
| 200 | 199 |
| 201 ScopedJavaLocalRef<jstring> j_notification_id = | 200 ScopedJavaLocalRef<jstring> j_notification_id = |
| 202 ConvertUTF8ToJavaString(env, notification_id); | 201 ConvertUTF8ToJavaString(env, notification_id); |
| 203 ScopedJavaLocalRef<jstring> j_origin = | 202 ScopedJavaLocalRef<jstring> j_origin = |
| 204 ConvertUTF8ToJavaString(env, origin_url.spec()); | 203 ConvertUTF8ToJavaString(env, origin_url.spec()); |
| 205 ScopedJavaLocalRef<jstring> tag = | 204 ScopedJavaLocalRef<jstring> tag = |
| 206 ConvertUTF8ToJavaString(env, notification.tag()); | 205 ConvertUTF8ToJavaString(env, notification.tag()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 228 ScopedJavaLocalRef<jobjectArray> action_icons = | 227 ScopedJavaLocalRef<jobjectArray> action_icons = |
| 229 ConvertToJavaBitmaps(notification.buttons()); | 228 ConvertToJavaBitmaps(notification.buttons()); |
| 230 | 229 |
| 231 ScopedJavaLocalRef<jintArray> vibration_pattern = | 230 ScopedJavaLocalRef<jintArray> vibration_pattern = |
| 232 base::android::ToJavaIntArray(env, notification.vibration_pattern()); | 231 base::android::ToJavaIntArray(env, notification.vibration_pattern()); |
| 233 | 232 |
| 234 ScopedJavaLocalRef<jstring> j_profile_id = | 233 ScopedJavaLocalRef<jstring> j_profile_id = |
| 235 ConvertUTF8ToJavaString(env, profile_id); | 234 ConvertUTF8ToJavaString(env, profile_id); |
| 236 | 235 |
| 237 Java_NotificationPlatformBridge_displayNotification( | 236 Java_NotificationPlatformBridge_displayNotification( |
| 238 env, java_object_.obj(), j_notification_id.obj(), j_origin.obj(), | 237 env, java_object_, j_notification_id, j_origin, j_profile_id, incognito, |
| 239 j_profile_id.obj(), incognito, tag.obj(), webapk_package.obj(), | 238 tag, webapk_package, title, body, notification_icon, badge, |
| 240 title.obj(), body.obj(), notification_icon.obj(), badge.obj(), | 239 vibration_pattern, notification.timestamp().ToJavaTime(), |
| 241 vibration_pattern.obj(), notification.timestamp().ToJavaTime(), | 240 notification.renotify(), notification.silent(), action_titles, |
| 242 notification.renotify(), notification.silent(), action_titles.obj(), | 241 action_icons); |
| 243 action_icons.obj()); | |
| 244 | 242 |
| 245 regenerated_notification_infos_[notification_id] = | 243 regenerated_notification_infos_[notification_id] = |
| 246 RegeneratedNotificationInfo(origin_url.spec(), notification.tag(), | 244 RegeneratedNotificationInfo(origin_url.spec(), notification.tag(), |
| 247 ConvertJavaStringToUTF8(env, webapk_package)); | 245 ConvertJavaStringToUTF8(env, webapk_package)); |
| 248 } | 246 } |
| 249 | 247 |
| 250 void NotificationPlatformBridgeAndroid::Close( | 248 void NotificationPlatformBridgeAndroid::Close( |
| 251 const std::string& profile_id, | 249 const std::string& profile_id, |
| 252 const std::string& notification_id) { | 250 const std::string& notification_id) { |
| 253 const auto iterator = regenerated_notification_infos_.find(notification_id); | 251 const auto iterator = regenerated_notification_infos_.find(notification_id); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 266 ConvertUTF8ToJavaString(env, notification_info.tag); | 264 ConvertUTF8ToJavaString(env, notification_info.tag); |
| 267 ScopedJavaLocalRef<jstring> webapk_package = | 265 ScopedJavaLocalRef<jstring> webapk_package = |
| 268 ConvertUTF8ToJavaString(env, notification_info.webapk_package); | 266 ConvertUTF8ToJavaString(env, notification_info.webapk_package); |
| 269 | 267 |
| 270 ScopedJavaLocalRef<jstring> j_profile_id = | 268 ScopedJavaLocalRef<jstring> j_profile_id = |
| 271 ConvertUTF8ToJavaString(env, profile_id); | 269 ConvertUTF8ToJavaString(env, profile_id); |
| 272 | 270 |
| 273 regenerated_notification_infos_.erase(iterator); | 271 regenerated_notification_infos_.erase(iterator); |
| 274 | 272 |
| 275 Java_NotificationPlatformBridge_closeNotification( | 273 Java_NotificationPlatformBridge_closeNotification( |
| 276 env, java_object_.obj(), j_profile_id.obj(), j_notification_id.obj(), | 274 env, java_object_, j_profile_id, j_notification_id, origin, tag, |
| 277 origin.obj(), tag.obj(), webapk_package.obj()); | 275 webapk_package); |
| 278 } | 276 } |
| 279 | 277 |
| 280 bool NotificationPlatformBridgeAndroid::GetDisplayed( | 278 bool NotificationPlatformBridgeAndroid::GetDisplayed( |
| 281 const std::string& profile_id, | 279 const std::string& profile_id, |
| 282 bool incognito, | 280 bool incognito, |
| 283 std::set<std::string>* notifications) const { | 281 std::set<std::string>* notifications) const { |
| 284 // TODO(miguelg): This can actually be implemented for M+ | 282 // TODO(miguelg): This can actually be implemented for M+ |
| 285 return false; | 283 return false; |
| 286 } | 284 } |
| 287 | 285 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 305 RegeneratedNotificationInfo() {} | 303 RegeneratedNotificationInfo() {} |
| 306 | 304 |
| 307 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: | 305 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: |
| 308 RegeneratedNotificationInfo(const std::string& origin, | 306 RegeneratedNotificationInfo(const std::string& origin, |
| 309 const std::string& tag, | 307 const std::string& tag, |
| 310 const std::string& webapk_package) | 308 const std::string& webapk_package) |
| 311 : origin(origin), tag(tag), webapk_package(webapk_package) {} | 309 : origin(origin), tag(tag), webapk_package(webapk_package) {} |
| 312 | 310 |
| 313 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: | 311 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: |
| 314 ~RegeneratedNotificationInfo() {} | 312 ~RegeneratedNotificationInfo() {} |
| OLD | NEW |