Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_android.cc

Issue 1969303002: Upstream WebAPK notification related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/android/jni_string.h" 11 #include "base/android/jni_string.h"
12 #include "base/command_line.h"
12 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/notifications/notification.h" 17 #include "chrome/browser/notifications/notification.h"
17 #include "chrome/browser/notifications/persistent_notification_delegate.h" 18 #include "chrome/browser/notifications/persistent_notification_delegate.h"
18 #include "chrome/browser/notifications/platform_notification_service_impl.h" 19 #include "chrome/browser/notifications/platform_notification_service_impl.h"
19 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/common/chrome_switches.h"
20 #include "content/public/common/persistent_notification_status.h" 22 #include "content/public/common/persistent_notification_status.h"
21 #include "content/public/common/platform_notification_data.h" 23 #include "content/public/common/platform_notification_data.h"
22 #include "jni/NotificationPlatformBridge_jni.h" 24 #include "jni/NotificationPlatformBridge_jni.h"
23 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
24 #include "ui/gfx/android/java_bitmap.h" 26 #include "ui/gfx/android/java_bitmap.h"
25 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
26 28
27 using base::android::AttachCurrentThread; 29 using base::android::AttachCurrentThread;
28 using base::android::ConvertJavaStringToUTF8; 30 using base::android::ConvertJavaStringToUTF8;
29 using base::android::ConvertUTF16ToJavaString; 31 using base::android::ConvertUTF16ToJavaString;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 83 }
82 84
83 void NotificationPlatformBridgeAndroid::OnNotificationClicked( 85 void NotificationPlatformBridgeAndroid::OnNotificationClicked(
84 JNIEnv* env, 86 JNIEnv* env,
85 const JavaParamRef<jobject>& java_object, 87 const JavaParamRef<jobject>& java_object,
86 jlong persistent_notification_id, 88 jlong persistent_notification_id,
87 const JavaParamRef<jstring>& java_origin, 89 const JavaParamRef<jstring>& java_origin,
88 const JavaParamRef<jstring>& java_profile_id, 90 const JavaParamRef<jstring>& java_profile_id,
89 jboolean incognito, 91 jboolean incognito,
90 const JavaParamRef<jstring>& java_tag, 92 const JavaParamRef<jstring>& java_tag,
93 const JavaParamRef<jstring>& java_webapk_package,
91 jint action_index) { 94 jint action_index) {
92 GURL origin(ConvertJavaStringToUTF8(env, java_origin)); 95 GURL origin(ConvertJavaStringToUTF8(env, java_origin));
93 std::string tag = ConvertJavaStringToUTF8(env, java_tag); 96 std::string tag = ConvertJavaStringToUTF8(env, java_tag);
94 std::string profile_id = ConvertJavaStringToUTF8(env, java_profile_id); 97 std::string profile_id = ConvertJavaStringToUTF8(env, java_profile_id);
98 std::string webapk_package =
99 ConvertJavaStringToUTF8(env, java_webapk_package);
95 100
96 regenerated_notification_infos_[persistent_notification_id] = 101 regenerated_notification_infos_[persistent_notification_id] =
97 std::make_pair(origin.spec(), tag); 102 RegeneratedNotificationInfo(origin.spec(), tag, webapk_package);
98 103
99 PlatformNotificationServiceImpl::GetInstance() 104 PlatformNotificationServiceImpl::GetInstance()
100 ->ProcessPersistentNotificationOperation( 105 ->ProcessPersistentNotificationOperation(
101 PlatformNotificationServiceImpl::NOTIFICATION_CLICK, profile_id, 106 PlatformNotificationServiceImpl::NOTIFICATION_CLICK, profile_id,
102 incognito, origin, persistent_notification_id, action_index); 107 incognito, origin, persistent_notification_id, action_index);
103 } 108 }
104 109
105 void NotificationPlatformBridgeAndroid::OnNotificationClosed( 110 void NotificationPlatformBridgeAndroid::OnNotificationClosed(
106 JNIEnv* env, 111 JNIEnv* env,
107 const JavaParamRef<jobject>& java_object, 112 const JavaParamRef<jobject>& java_object,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // property on that object instead, making this cast unnecessary. 144 // property on that object instead, making this cast unnecessary.
140 PersistentNotificationDelegate* delegate = 145 PersistentNotificationDelegate* delegate =
141 static_cast<PersistentNotificationDelegate*>(notification.delegate()); 146 static_cast<PersistentNotificationDelegate*>(notification.delegate());
142 DCHECK(delegate); 147 DCHECK(delegate);
143 148
144 int64_t persistent_notification_id = delegate->persistent_notification_id(); 149 int64_t persistent_notification_id = delegate->persistent_notification_id();
145 GURL origin_url(notification.origin_url().GetOrigin()); 150 GURL origin_url(notification.origin_url().GetOrigin());
146 151
147 ScopedJavaLocalRef<jstring> origin = 152 ScopedJavaLocalRef<jstring> origin =
148 ConvertUTF8ToJavaString(env, origin_url.spec()); 153 ConvertUTF8ToJavaString(env, origin_url.spec());
154
155 ScopedJavaLocalRef<jstring> webapk_package;
156 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
157 switches::kEnableWebApk)) {
158 webapk_package = Java_NotificationPlatformBridge_queryWebApkPackage(
159 env, java_object_.obj(), origin.obj());
160 } else {
161 webapk_package = ConvertUTF8ToJavaString(env, "");
162 }
163
149 ScopedJavaLocalRef<jstring> tag = 164 ScopedJavaLocalRef<jstring> tag =
150 ConvertUTF8ToJavaString(env, notification.tag()); 165 ConvertUTF8ToJavaString(env, notification.tag());
151 ScopedJavaLocalRef<jstring> title = 166 ScopedJavaLocalRef<jstring> title =
152 ConvertUTF16ToJavaString(env, notification.title()); 167 ConvertUTF16ToJavaString(env, notification.title());
153 ScopedJavaLocalRef<jstring> body = 168 ScopedJavaLocalRef<jstring> body =
154 ConvertUTF16ToJavaString(env, notification.message()); 169 ConvertUTF16ToJavaString(env, notification.message());
155 170
156 ScopedJavaLocalRef<jobject> notification_icon; 171 ScopedJavaLocalRef<jobject> notification_icon;
157 SkBitmap notification_icon_bitmap = notification.icon().AsBitmap(); 172 SkBitmap notification_icon_bitmap = notification.icon().AsBitmap();
158 if (!notification_icon_bitmap.drawsNothing()) 173 if (!notification_icon_bitmap.drawsNothing())
(...skipping 14 matching lines...) Expand all
173 ConvertToJavaBitmaps(notification.buttons()); 188 ConvertToJavaBitmaps(notification.buttons());
174 189
175 ScopedJavaLocalRef<jintArray> vibration_pattern = 190 ScopedJavaLocalRef<jintArray> vibration_pattern =
176 base::android::ToJavaIntArray(env, notification.vibration_pattern()); 191 base::android::ToJavaIntArray(env, notification.vibration_pattern());
177 192
178 ScopedJavaLocalRef<jstring> j_profile_id = 193 ScopedJavaLocalRef<jstring> j_profile_id =
179 ConvertUTF8ToJavaString(env, profile_id); 194 ConvertUTF8ToJavaString(env, profile_id);
180 195
181 Java_NotificationPlatformBridge_displayNotification( 196 Java_NotificationPlatformBridge_displayNotification(
182 env, java_object_.obj(), persistent_notification_id, origin.obj(), 197 env, java_object_.obj(), persistent_notification_id, origin.obj(),
183 j_profile_id.obj(), incognito, tag.obj(), title.obj(), body.obj(), 198 j_profile_id.obj(), incognito, tag.obj(), webapk_package.obj(),
184 notification_icon.obj(), badge.obj(), vibration_pattern.obj(), 199 title.obj(), body.obj(), notification_icon.obj(), badge.obj(),
185 notification.timestamp().ToJavaTime(), notification.renotify(), 200 vibration_pattern.obj(), notification.timestamp().ToJavaTime(),
186 notification.silent(), action_titles.obj(), action_icons.obj()); 201 notification.renotify(), notification.silent(), action_titles.obj(),
202 action_icons.obj());
187 203
188 regenerated_notification_infos_[persistent_notification_id] = 204 regenerated_notification_infos_[persistent_notification_id] =
189 std::make_pair(origin_url.spec(), notification.tag()); 205 RegeneratedNotificationInfo(
206 origin_url.spec(), notification.tag(),
207 ConvertJavaStringToUTF8(env, webapk_package));
190 } 208 }
191 209
192 void NotificationPlatformBridgeAndroid::Close( 210 void NotificationPlatformBridgeAndroid::Close(
193 const std::string& profile_id, 211 const std::string& profile_id,
194 const std::string& notification_id) { 212 const std::string& notification_id) {
195 int64_t persistent_notification_id = 0; 213 int64_t persistent_notification_id = 0;
196 214
197 // TODO(peter): Use the |delegate_id| directly when notification ids are being 215 // TODO(peter): Use the |delegate_id| directly when notification ids are being
198 // generated by content/ instead of us. 216 // generated by content/ instead of us.
199 if (!base::StringToInt64(notification_id, &persistent_notification_id)) { 217 if (!base::StringToInt64(notification_id, &persistent_notification_id)) {
200 LOG(WARNING) << "Unable to decode notification_id " << notification_id; 218 LOG(WARNING) << "Unable to decode notification_id " << notification_id;
201 return; 219 return;
202 } 220 }
203 221
204 const auto iterator = 222 const auto iterator =
205 regenerated_notification_infos_.find(persistent_notification_id); 223 regenerated_notification_infos_.find(persistent_notification_id);
206 if (iterator == regenerated_notification_infos_.end()) 224 if (iterator == regenerated_notification_infos_.end())
207 return; 225 return;
208 226
209 const RegeneratedNotificationInfo& notification_info = iterator->second; 227 const RegeneratedNotificationInfo& notification_info = iterator->second;
210 228
211 JNIEnv* env = AttachCurrentThread(); 229 JNIEnv* env = AttachCurrentThread();
212 230
213 ScopedJavaLocalRef<jstring> origin = 231 ScopedJavaLocalRef<jstring> origin =
214 ConvertUTF8ToJavaString(env, notification_info.first); 232 ConvertUTF8ToJavaString(env, notification_info.origin);
215 ScopedJavaLocalRef<jstring> tag = 233 ScopedJavaLocalRef<jstring> tag =
216 ConvertUTF8ToJavaString(env, notification_info.second); 234 ConvertUTF8ToJavaString(env, notification_info.tag);
235 ScopedJavaLocalRef<jstring> webapk_package =
236 ConvertUTF8ToJavaString(env, notification_info.webapk_package);
237
217 ScopedJavaLocalRef<jstring> j_profile_id = 238 ScopedJavaLocalRef<jstring> j_profile_id =
218 ConvertUTF8ToJavaString(env, profile_id); 239 ConvertUTF8ToJavaString(env, profile_id);
219 240
220 regenerated_notification_infos_.erase(iterator); 241 regenerated_notification_infos_.erase(iterator);
221 242
222 Java_NotificationPlatformBridge_closeNotification( 243 Java_NotificationPlatformBridge_closeNotification(
223 env, java_object_.obj(), j_profile_id.obj(), persistent_notification_id, 244 env, java_object_.obj(), j_profile_id.obj(), persistent_notification_id,
224 origin.obj(), tag.obj()); 245 origin.obj(), tag.obj(), webapk_package.obj());
225 } 246 }
226 247
227 bool NotificationPlatformBridgeAndroid::GetDisplayed( 248 bool NotificationPlatformBridgeAndroid::GetDisplayed(
228 const std::string& profile_id, 249 const std::string& profile_id,
229 bool incognito, 250 bool incognito,
230 std::set<std::string>* notifications) const { 251 std::set<std::string>* notifications) const {
231 // TODO(miguelg): This can actually be implemented for M+ 252 // TODO(miguelg): This can actually be implemented for M+
232 return false; 253 return false;
233 } 254 }
234 255
235 bool NotificationPlatformBridgeAndroid::SupportsNotificationCenter() const { 256 bool NotificationPlatformBridgeAndroid::SupportsNotificationCenter() const {
236 return true; 257 return true;
237 } 258 }
238 259
239 bool NotificationPlatformBridgeAndroid::RegisterNotificationPlatformBridge( 260 bool NotificationPlatformBridgeAndroid::RegisterNotificationPlatformBridge(
240 JNIEnv* env) { 261 JNIEnv* env) {
241 return RegisterNativesImpl(env); 262 return RegisterNativesImpl(env);
242 } 263 }
264
265 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo::
266 RegeneratedNotificationInfo() {}
267
268 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo::
269 RegeneratedNotificationInfo(const std::string& origin,
270 const std::string& tag,
271 const std::string& webapk_package)
272 : origin(origin), tag(tag), webapk_package(webapk_package) {}
273
274 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo::
275 ~RegeneratedNotificationInfo() {}
OLDNEW
« no previous file with comments | « chrome/browser/notifications/notification_platform_bridge_android.h ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698