| 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/context_utils.h" | 10 #include "base/android/context_utils.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 java_object_.obj()); | 82 java_object_.obj()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void NotificationPlatformBridgeAndroid::OnNotificationClicked( | 85 void NotificationPlatformBridgeAndroid::OnNotificationClicked( |
| 86 JNIEnv* env, | 86 JNIEnv* env, |
| 87 const JavaParamRef<jobject>& java_object, | 87 const JavaParamRef<jobject>& java_object, |
| 88 jlong persistent_notification_id, | 88 jlong persistent_notification_id, |
| 89 const JavaParamRef<jstring>& java_origin, | 89 const JavaParamRef<jstring>& java_origin, |
| 90 const JavaParamRef<jstring>& java_profile_id, | 90 const JavaParamRef<jstring>& java_profile_id, |
| 91 jboolean incognito, | 91 jboolean incognito, |
| 92 const JavaParamRef<jstring>& java_web_apk_package, | 92 const JavaParamRef<jstring>& java_webapk_package, |
| 93 const JavaParamRef<jstring>& java_tag, | 93 const JavaParamRef<jstring>& java_tag, |
| 94 jint action_index) { | 94 jint action_index) { |
| 95 GURL origin(ConvertJavaStringToUTF8(env, java_origin)); | 95 GURL origin(ConvertJavaStringToUTF8(env, java_origin)); |
| 96 std::string tag = ConvertJavaStringToUTF8(env, java_tag); | 96 std::string tag = ConvertJavaStringToUTF8(env, java_tag); |
| 97 std::string profile_id = ConvertJavaStringToUTF8(env, java_profile_id); | 97 std::string profile_id = ConvertJavaStringToUTF8(env, java_profile_id); |
| 98 std::string web_apk_package = | 98 std::string webapk_package = |
| 99 ConvertJavaStringToUTF8(env, java_web_apk_package); | 99 ConvertJavaStringToUTF8(env, java_webapk_package); |
| 100 | 100 |
| 101 regenerated_notification_infos_[persistent_notification_id] = | 101 regenerated_notification_infos_[persistent_notification_id] = |
| 102 RegeneratedNotificationInfo(origin.spec(), tag, web_apk_package); | 102 RegeneratedNotificationInfo(origin.spec(), tag, webapk_package); |
| 103 | 103 |
| 104 PlatformNotificationServiceImpl::GetInstance() | 104 PlatformNotificationServiceImpl::GetInstance() |
| 105 ->ProcessPersistentNotificationOperation( | 105 ->ProcessPersistentNotificationOperation( |
| 106 PlatformNotificationServiceImpl::NOTIFICATION_CLICK, profile_id, | 106 PlatformNotificationServiceImpl::NOTIFICATION_CLICK, profile_id, |
| 107 incognito, origin, persistent_notification_id, action_index); | 107 incognito, origin, persistent_notification_id, action_index); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void NotificationPlatformBridgeAndroid::OnNotificationClosed( | 110 void NotificationPlatformBridgeAndroid::OnNotificationClosed( |
| 111 JNIEnv* env, | 111 JNIEnv* env, |
| 112 const JavaParamRef<jobject>& java_object, | 112 const JavaParamRef<jobject>& java_object, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // property on that object instead, making this cast unnecessary. | 144 // property on that object instead, making this cast unnecessary. |
| 145 PersistentNotificationDelegate* delegate = | 145 PersistentNotificationDelegate* delegate = |
| 146 static_cast<PersistentNotificationDelegate*>(notification.delegate()); | 146 static_cast<PersistentNotificationDelegate*>(notification.delegate()); |
| 147 DCHECK(delegate); | 147 DCHECK(delegate); |
| 148 | 148 |
| 149 int64_t persistent_notification_id = delegate->persistent_notification_id(); | 149 int64_t persistent_notification_id = delegate->persistent_notification_id(); |
| 150 GURL origin_url(notification.origin_url().GetOrigin()); | 150 GURL origin_url(notification.origin_url().GetOrigin()); |
| 151 | 151 |
| 152 ScopedJavaLocalRef<jstring> origin = | 152 ScopedJavaLocalRef<jstring> origin = |
| 153 ConvertUTF8ToJavaString(env, origin_url.spec()); | 153 ConvertUTF8ToJavaString(env, origin_url.spec()); |
| 154 ScopedJavaLocalRef<jstring> web_apk_package = | 154 ScopedJavaLocalRef<jstring> webapk_package = |
| 155 Java_NotificationPlatformBridge_queryWebApkPackage(env, java_object_.obj()
, | 155 Java_NotificationPlatformBridge_queryWebApkPackage(env, java_object_.obj()
, |
| 156 origin.obj()); | 156 origin.obj()); |
| 157 ScopedJavaLocalRef<jstring> tag = | 157 ScopedJavaLocalRef<jstring> tag = |
| 158 ConvertUTF8ToJavaString(env, notification.tag()); | 158 ConvertUTF8ToJavaString(env, notification.tag()); |
| 159 ScopedJavaLocalRef<jstring> title = | 159 ScopedJavaLocalRef<jstring> title = |
| 160 ConvertUTF16ToJavaString(env, notification.title()); | 160 ConvertUTF16ToJavaString(env, notification.title()); |
| 161 ScopedJavaLocalRef<jstring> body = | 161 ScopedJavaLocalRef<jstring> body = |
| 162 ConvertUTF16ToJavaString(env, notification.message()); | 162 ConvertUTF16ToJavaString(env, notification.message()); |
| 163 | 163 |
| 164 ScopedJavaLocalRef<jobject> notification_icon; | 164 ScopedJavaLocalRef<jobject> notification_icon; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 181 ConvertToJavaBitmaps(notification.buttons()); | 181 ConvertToJavaBitmaps(notification.buttons()); |
| 182 | 182 |
| 183 ScopedJavaLocalRef<jintArray> vibration_pattern = | 183 ScopedJavaLocalRef<jintArray> vibration_pattern = |
| 184 base::android::ToJavaIntArray(env, notification.vibration_pattern()); | 184 base::android::ToJavaIntArray(env, notification.vibration_pattern()); |
| 185 | 185 |
| 186 ScopedJavaLocalRef<jstring> j_profile_id = | 186 ScopedJavaLocalRef<jstring> j_profile_id = |
| 187 ConvertUTF8ToJavaString(env, profile_id); | 187 ConvertUTF8ToJavaString(env, profile_id); |
| 188 | 188 |
| 189 Java_NotificationPlatformBridge_displayNotification( | 189 Java_NotificationPlatformBridge_displayNotification( |
| 190 env, java_object_.obj(), persistent_notification_id, origin.obj(), | 190 env, java_object_.obj(), persistent_notification_id, origin.obj(), |
| 191 j_profile_id.obj(), incognito, tag.obj(), web_apk_package.obj(), | 191 j_profile_id.obj(), incognito, tag.obj(), webapk_package.obj(), |
| 192 title.obj(), body.obj(), notification_icon.obj(), badge.obj(), | 192 title.obj(), body.obj(), notification_icon.obj(), badge.obj(), |
| 193 vibration_pattern.obj(), notification.timestamp().ToJavaTime(), | 193 vibration_pattern.obj(), notification.timestamp().ToJavaTime(), |
| 194 notification.renotify(), notification.silent(), action_titles.obj(), | 194 notification.renotify(), notification.silent(), action_titles.obj(), |
| 195 action_icons.obj()); | 195 action_icons.obj()); |
| 196 | 196 |
| 197 regenerated_notification_infos_[persistent_notification_id] = | 197 regenerated_notification_infos_[persistent_notification_id] = |
| 198 RegeneratedNotificationInfo( | 198 RegeneratedNotificationInfo( |
| 199 origin_url.spec(), notification.tag(), | 199 origin_url.spec(), notification.tag(), |
| 200 ConvertJavaStringToUTF8(env, web_apk_package)); | 200 ConvertJavaStringToUTF8(env, webapk_package)); |
| 201 | 201 |
| 202 notification.delegate()->Display(); | 202 notification.delegate()->Display(); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void NotificationPlatformBridgeAndroid::Close( | 205 void NotificationPlatformBridgeAndroid::Close( |
| 206 const std::string& profile_id, | 206 const std::string& profile_id, |
| 207 const std::string& notification_id) { | 207 const std::string& notification_id) { |
| 208 int64_t persistent_notification_id = 0; | 208 int64_t persistent_notification_id = 0; |
| 209 | 209 |
| 210 // TODO(peter): Use the |delegate_id| directly when notification ids are being | 210 // TODO(peter): Use the |delegate_id| directly when notification ids are being |
| 211 // generated by content/ instead of us. | 211 // generated by content/ instead of us. |
| 212 if (!base::StringToInt64(notification_id, &persistent_notification_id)) { | 212 if (!base::StringToInt64(notification_id, &persistent_notification_id)) { |
| 213 LOG(WARNING) << "Unable to decode notification_id " << notification_id; | 213 LOG(WARNING) << "Unable to decode notification_id " << notification_id; |
| 214 return; | 214 return; |
| 215 } | 215 } |
| 216 | 216 |
| 217 const auto iterator = | 217 const auto iterator = |
| 218 regenerated_notification_infos_.find(persistent_notification_id); | 218 regenerated_notification_infos_.find(persistent_notification_id); |
| 219 if (iterator == regenerated_notification_infos_.end()) | 219 if (iterator == regenerated_notification_infos_.end()) |
| 220 return; | 220 return; |
| 221 | 221 |
| 222 const RegeneratedNotificationInfo& notification_info = iterator->second; | 222 const RegeneratedNotificationInfo& notification_info = iterator->second; |
| 223 | 223 |
| 224 JNIEnv* env = AttachCurrentThread(); | 224 JNIEnv* env = AttachCurrentThread(); |
| 225 | 225 |
| 226 ScopedJavaLocalRef<jstring> origin = | 226 ScopedJavaLocalRef<jstring> origin = |
| 227 ConvertUTF8ToJavaString(env, notification_info.origin); | 227 ConvertUTF8ToJavaString(env, notification_info.origin); |
| 228 ScopedJavaLocalRef<jstring> web_apk_package = | 228 ScopedJavaLocalRef<jstring> webapk_package = |
| 229 ConvertUTF8ToJavaString(env, notification_info.web_apk_package); | 229 ConvertUTF8ToJavaString(env, notification_info.webapk_package); |
| 230 ScopedJavaLocalRef<jstring> tag = | 230 ScopedJavaLocalRef<jstring> tag = |
| 231 ConvertUTF8ToJavaString(env, notification_info.tag); | 231 ConvertUTF8ToJavaString(env, notification_info.tag); |
| 232 ScopedJavaLocalRef<jstring> j_profile_id = | 232 ScopedJavaLocalRef<jstring> j_profile_id = |
| 233 ConvertUTF8ToJavaString(env, profile_id); | 233 ConvertUTF8ToJavaString(env, profile_id); |
| 234 | 234 |
| 235 regenerated_notification_infos_.erase(iterator); | 235 regenerated_notification_infos_.erase(iterator); |
| 236 | 236 |
| 237 Java_NotificationPlatformBridge_closeNotification( | 237 Java_NotificationPlatformBridge_closeNotification( |
| 238 env, java_object_.obj(), j_profile_id.obj(), persistent_notification_id, | 238 env, java_object_.obj(), j_profile_id.obj(), persistent_notification_id, |
| 239 origin.obj(), tag.obj(), web_apk_package.obj()); | 239 origin.obj(), tag.obj(), webapk_package.obj()); |
| 240 } | 240 } |
| 241 | 241 |
| 242 bool NotificationPlatformBridgeAndroid::GetDisplayed( | 242 bool NotificationPlatformBridgeAndroid::GetDisplayed( |
| 243 const std::string& profile_id, | 243 const std::string& profile_id, |
| 244 bool incognito, | 244 bool incognito, |
| 245 std::set<std::string>* notifications) const { | 245 std::set<std::string>* notifications) const { |
| 246 // TODO(miguelg): This can actually be implemented for M+ | 246 // TODO(miguelg): This can actually be implemented for M+ |
| 247 return false; | 247 return false; |
| 248 } | 248 } |
| 249 | 249 |
| 250 bool NotificationPlatformBridgeAndroid::SupportsNotificationCenter() const { | 250 bool NotificationPlatformBridgeAndroid::SupportsNotificationCenter() const { |
| 251 return true; | 251 return true; |
| 252 } | 252 } |
| 253 | 253 |
| 254 bool NotificationPlatformBridgeAndroid::RegisterNotificationPlatformBridge( | 254 bool NotificationPlatformBridgeAndroid::RegisterNotificationPlatformBridge( |
| 255 JNIEnv* env) { | 255 JNIEnv* env) { |
| 256 return RegisterNativesImpl(env); | 256 return RegisterNativesImpl(env); |
| 257 } | 257 } |
| 258 | 258 |
| 259 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: | 259 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: |
| 260 RegeneratedNotificationInfo() {} | 260 RegeneratedNotificationInfo() {} |
| 261 | 261 |
| 262 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: | 262 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: |
| 263 RegeneratedNotificationInfo(const std::string& origin, | 263 RegeneratedNotificationInfo(const std::string& origin, |
| 264 const std::string& tag, | 264 const std::string& tag, |
| 265 const std::string& web_apk_package) | 265 const std::string& webapk_package) |
| 266 : origin(origin), tag(tag), web_apk_package(web_apk_package) {} | 266 : origin(origin), tag(tag), webapk_package(webapk_package) {} |
| 267 | 267 |
| 268 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: | 268 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: |
| 269 ~RegeneratedNotificationInfo() {} | 269 ~RegeneratedNotificationInfo() {} |
| OLD | NEW |