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

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

Issue 2418153002: Hooking up Android N inline notification replies end-to-end (Closed)
Patch Set: Hooking up Android N inline notification replies end-to-end Created 4 years, 2 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/command_line.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/strings/nullable_string16.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/notifications/native_notification_display_service.h" 18 #include "chrome/browser/notifications/native_notification_display_service.h"
18 #include "chrome/browser/notifications/notification.h" 19 #include "chrome/browser/notifications/notification.h"
19 #include "chrome/browser/notifications/notification_common.h" 20 #include "chrome/browser/notifications/notification_common.h"
20 #include "chrome/browser/notifications/notification_display_service_factory.h" 21 #include "chrome/browser/notifications/notification_display_service_factory.h"
21 #include "chrome/browser/notifications/persistent_notification_delegate.h" 22 #include "chrome/browser/notifications/persistent_notification_delegate.h"
22 #include "chrome/browser/notifications/platform_notification_service_impl.h" 23 #include "chrome/browser/notifications/platform_notification_service_impl.h"
23 #include "chrome/browser/profiles/profile_manager.h" 24 #include "chrome/browser/profiles/profile_manager.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
26 #include "components/pref_registry/pref_registry_syncable.h" 27 #include "components/pref_registry/pref_registry_syncable.h"
27 #include "content/public/common/persistent_notification_status.h" 28 #include "content/public/common/persistent_notification_status.h"
28 #include "content/public/common/platform_notification_data.h" 29 #include "content/public/common/platform_notification_data.h"
29 #include "jni/NotificationPlatformBridge_jni.h" 30 #include "jni/NotificationPlatformBridge_jni.h"
30 #include "third_party/skia/include/core/SkBitmap.h" 31 #include "third_party/skia/include/core/SkBitmap.h"
31 #include "ui/gfx/android/java_bitmap.h" 32 #include "ui/gfx/android/java_bitmap.h"
32 #include "ui/gfx/image/image.h" 33 #include "ui/gfx/image/image.h"
33 34
34 using base::android::AttachCurrentThread; 35 using base::android::AttachCurrentThread;
35 using base::android::ConvertJavaStringToUTF8; 36 using base::android::ConvertJavaStringToUTF8;
37 using base::android::ConvertJavaStringToUTF16;
36 using base::android::ConvertUTF16ToJavaString; 38 using base::android::ConvertUTF16ToJavaString;
37 using base::android::ConvertUTF8ToJavaString; 39 using base::android::ConvertUTF8ToJavaString;
38 using base::android::JavaParamRef; 40 using base::android::JavaParamRef;
39 using base::android::ScopedJavaLocalRef; 41 using base::android::ScopedJavaLocalRef;
40 42
41 namespace { 43 namespace {
42 44
43 ScopedJavaLocalRef<jobjectArray> ConvertToJavaBitmaps( 45 ScopedJavaLocalRef<jobjectArray> ConvertToJavaBitmaps(
44 const std::vector<message_center::ButtonInfo>& buttons) { 46 const std::vector<message_center::ButtonInfo>& buttons) {
45 std::vector<SkBitmap> skbitmaps; 47 std::vector<SkBitmap> skbitmaps;
(...skipping 18 matching lines...) Expand all
64 } 66 }
65 67
66 // Callback to run once the profile has been loaded in order to perform a 68 // Callback to run once the profile has been loaded in order to perform a
67 // given |operation| in a notification. 69 // given |operation| in a notification.
68 // TODO(miguelg) move it to notification_common? 70 // TODO(miguelg) move it to notification_common?
69 void ProfileLoadedCallback(NotificationCommon::Operation operation, 71 void ProfileLoadedCallback(NotificationCommon::Operation operation,
70 NotificationCommon::Type notification_type, 72 NotificationCommon::Type notification_type,
71 const std::string& origin, 73 const std::string& origin,
72 const std::string& notification_id, 74 const std::string& notification_id,
73 int action_index, 75 int action_index,
76 const base::NullableString16& reply,
74 Profile* profile) { 77 Profile* profile) {
75 if (!profile) { 78 if (!profile) {
76 // TODO(miguelg): Add UMA for this condition. 79 // TODO(miguelg): Add UMA for this condition.
77 // Perhaps propagate this through PersistentNotificationStatus. 80 // Perhaps propagate this through PersistentNotificationStatus.
78 LOG(WARNING) << "Profile not loaded correctly"; 81 LOG(WARNING) << "Profile not loaded correctly";
79 return; 82 return;
80 } 83 }
81 84
82 NotificationDisplayService* display_service = 85 NotificationDisplayService* display_service =
83 NotificationDisplayServiceFactory::GetForProfile(profile); 86 NotificationDisplayServiceFactory::GetForProfile(profile);
84 87
85 static_cast<NativeNotificationDisplayService*>(display_service) 88 static_cast<NativeNotificationDisplayService*>(display_service)
86 ->ProcessNotificationOperation(operation, notification_type, origin, 89 ->ProcessNotificationOperation(operation, notification_type, origin,
87 notification_id, action_index); 90 notification_id, action_index, reply);
88 } 91 }
89 92
90 } // namespace 93 } // namespace
91 94
92 // Called by the Java side when a notification event has been received, but the 95 // Called by the Java side when a notification event has been received, but the
93 // NotificationBridge has not been initialized yet. Enforce initialization of 96 // NotificationBridge has not been initialized yet. Enforce initialization of
94 // the class. 97 // the class.
95 static void InitializeNotificationPlatformBridge( 98 static void InitializeNotificationPlatformBridge(
96 JNIEnv* env, 99 JNIEnv* env,
97 const JavaParamRef<jclass>& clazz) { 100 const JavaParamRef<jclass>& clazz) {
(...skipping 16 matching lines...) Expand all
114 117
115 void NotificationPlatformBridgeAndroid::OnNotificationClicked( 118 void NotificationPlatformBridgeAndroid::OnNotificationClicked(
116 JNIEnv* env, 119 JNIEnv* env,
117 const JavaParamRef<jobject>& java_object, 120 const JavaParamRef<jobject>& java_object,
118 const JavaParamRef<jstring>& java_notification_id, 121 const JavaParamRef<jstring>& java_notification_id,
119 const JavaParamRef<jstring>& java_origin, 122 const JavaParamRef<jstring>& java_origin,
120 const JavaParamRef<jstring>& java_profile_id, 123 const JavaParamRef<jstring>& java_profile_id,
121 jboolean incognito, 124 jboolean incognito,
122 const JavaParamRef<jstring>& java_tag, 125 const JavaParamRef<jstring>& java_tag,
123 const JavaParamRef<jstring>& java_webapk_package, 126 const JavaParamRef<jstring>& java_webapk_package,
124 jint action_index) { 127 jint action_index,
128 const base::android::JavaParamRef<_jstring*>& java_reply) {
Peter Beverloo 2016/10/17 14:11:39 Are you sure that we can't just have const Ja
awdf 2016/10/17 14:51:24 :O wow, I have no idea where that came from.. perh
125 std::string notification_id = 129 std::string notification_id =
126 ConvertJavaStringToUTF8(env, java_notification_id); 130 ConvertJavaStringToUTF8(env, java_notification_id);
127 std::string tag = ConvertJavaStringToUTF8(env, java_tag); 131 std::string tag = ConvertJavaStringToUTF8(env, java_tag);
128 std::string profile_id = ConvertJavaStringToUTF8(env, java_profile_id); 132 std::string profile_id = ConvertJavaStringToUTF8(env, java_profile_id);
129 std::string webapk_package = 133 std::string webapk_package =
130 ConvertJavaStringToUTF8(env, java_webapk_package); 134 ConvertJavaStringToUTF8(env, java_webapk_package);
135 base::NullableString16 reply =
136 java_reply
137 ? base::NullableString16(ConvertJavaStringToUTF16(env, java_reply),
138 false /* is_null */)
139 : base::NullableString16();
131 140
132 GURL origin(ConvertJavaStringToUTF8(env, java_origin)); 141 GURL origin(ConvertJavaStringToUTF8(env, java_origin));
133 regenerated_notification_infos_[notification_id] = 142 regenerated_notification_infos_[notification_id] =
134 RegeneratedNotificationInfo(origin.spec(), tag, webapk_package); 143 RegeneratedNotificationInfo(origin.spec(), tag, webapk_package);
135 144
136 ProfileManager* profile_manager = g_browser_process->profile_manager(); 145 ProfileManager* profile_manager = g_browser_process->profile_manager();
137 DCHECK(profile_manager); 146 DCHECK(profile_manager);
138 147
139 profile_manager->LoadProfile( 148 profile_manager->LoadProfile(
140 profile_id, incognito, 149 profile_id, incognito,
141 base::Bind(&ProfileLoadedCallback, NotificationCommon::CLICK, 150 base::Bind(&ProfileLoadedCallback, NotificationCommon::CLICK,
142 NotificationCommon::PERSISTENT, origin.spec(), notification_id, 151 NotificationCommon::PERSISTENT, origin.spec(), notification_id,
143 action_index)); 152 action_index, reply));
144 } 153 }
145 154
146 void NotificationPlatformBridgeAndroid::OnNotificationClosed( 155 void NotificationPlatformBridgeAndroid::OnNotificationClosed(
147 JNIEnv* env, 156 JNIEnv* env,
148 const JavaParamRef<jobject>& java_object, 157 const JavaParamRef<jobject>& java_object,
149 const JavaParamRef<jstring>& java_notification_id, 158 const JavaParamRef<jstring>& java_notification_id,
150 const JavaParamRef<jstring>& java_origin, 159 const JavaParamRef<jstring>& java_origin,
151 const JavaParamRef<jstring>& java_profile_id, 160 const JavaParamRef<jstring>& java_profile_id,
152 jboolean incognito, 161 jboolean incognito,
153 const JavaParamRef<jstring>& java_tag, 162 const JavaParamRef<jstring>& java_tag,
154 jboolean by_user) { 163 jboolean by_user) {
155 std::string profile_id = ConvertJavaStringToUTF8(env, java_profile_id); 164 std::string profile_id = ConvertJavaStringToUTF8(env, java_profile_id);
156 std::string notification_id = 165 std::string notification_id =
157 ConvertJavaStringToUTF8(env, java_notification_id); 166 ConvertJavaStringToUTF8(env, java_notification_id);
158 167
159 // The notification was closed by the platform, so clear all local state. 168 // The notification was closed by the platform, so clear all local state.
160 regenerated_notification_infos_.erase(notification_id); 169 regenerated_notification_infos_.erase(notification_id);
161 170
162 ProfileManager* profile_manager = g_browser_process->profile_manager(); 171 ProfileManager* profile_manager = g_browser_process->profile_manager();
163 DCHECK(profile_manager); 172 DCHECK(profile_manager);
164 173
165 profile_manager->LoadProfile( 174 profile_manager->LoadProfile(
166 profile_id, incognito, 175 profile_id, incognito,
167 base::Bind(&ProfileLoadedCallback, NotificationCommon::CLOSE, 176 base::Bind(&ProfileLoadedCallback, NotificationCommon::CLOSE,
168 NotificationCommon::PERSISTENT, 177 NotificationCommon::PERSISTENT,
169 ConvertJavaStringToUTF8(env, java_origin), notification_id, 178 ConvertJavaStringToUTF8(env, java_origin), notification_id,
170 -1 /* action index */)); 179 -1 /* action index */, base::NullableString16() /* reply */));
171 } 180 }
172 181
173 void NotificationPlatformBridgeAndroid::Display( 182 void NotificationPlatformBridgeAndroid::Display(
174 NotificationCommon::Type notification_type, 183 NotificationCommon::Type notification_type,
175 const std::string& notification_id, 184 const std::string& notification_id,
176 const std::string& profile_id, 185 const std::string& profile_id,
177 bool incognito, 186 bool incognito,
178 const Notification& notification) { 187 const Notification& notification) {
179 JNIEnv* env = AttachCurrentThread(); 188 JNIEnv* env = AttachCurrentThread();
180 // TODO(miguelg): Store the notification type in java instead of assuming it's 189 // TODO(miguelg): Store the notification type in java instead of assuming it's
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 RegeneratedNotificationInfo() {} 331 RegeneratedNotificationInfo() {}
323 332
324 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: 333 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo::
325 RegeneratedNotificationInfo(const std::string& origin, 334 RegeneratedNotificationInfo(const std::string& origin,
326 const std::string& tag, 335 const std::string& tag,
327 const std::string& webapk_package) 336 const std::string& webapk_package)
328 : origin(origin), tag(tag), webapk_package(webapk_package) {} 337 : origin(origin), tag(tag), webapk_package(webapk_package) {}
329 338
330 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo:: 339 NotificationPlatformBridgeAndroid::RegeneratedNotificationInfo::
331 ~RegeneratedNotificationInfo() {} 340 ~RegeneratedNotificationInfo() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698