Commit 4c1aee64 authored by Pavel Yatsuk's avatar Pavel Yatsuk Committed by Commit Bot

[Messages] Add getter methods for message properties in MessageWrapper

Getter methods are needed for feature code unittests.

BUG=1123947
R=twellington@chromium.org

Change-Id: I853a337a92f04c99e27e7c5d3205b13a3ed46c4e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2540942
Commit-Queue: Pavel Yatsuk <pavely@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828560}
parent 0715e810
......@@ -45,21 +45,42 @@ public final class MessageWrapper {
return mMessageProperties;
}
@CalledByNative
String getTitle() {
return mMessageProperties.get(MessageBannerProperties.TITLE);
}
@CalledByNative
void setTitle(String title) {
mMessageProperties.set(MessageBannerProperties.TITLE, title);
}
@CalledByNative
String getDescription() {
return mMessageProperties.get(MessageBannerProperties.DESCRIPTION);
}
@CalledByNative
void setDescription(String description) {
mMessageProperties.set(MessageBannerProperties.DESCRIPTION, description);
}
@CalledByNative
String getPrimaryButtonText() {
return mMessageProperties.get(MessageBannerProperties.PRIMARY_BUTTON_TEXT);
}
@CalledByNative
void setPrimaryButtonText(String primaryButtonText) {
mMessageProperties.set(MessageBannerProperties.PRIMARY_BUTTON_TEXT, primaryButtonText);
}
@CalledByNative
@DrawableRes
int getIconResourceId() {
return mMessageProperties.get(MessageBannerProperties.ICON_RESOURCE_ID);
}
@CalledByNative
void setIconResourceId(@DrawableRes int resourceId) {
mMessageProperties.set(MessageBannerProperties.ICON_RESOURCE_ID, resourceId);
......
......@@ -27,6 +27,14 @@ MessageWrapper::~MessageWrapper() {
CHECK(message_dismissed_);
}
base::string16 MessageWrapper::GetTitle() {
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jstring> jtitle =
Java_MessageWrapper_getTitle(env, java_message_wrapper_);
return jtitle.is_null() ? base::string16()
: base::android::ConvertJavaStringToUTF16(jtitle);
}
void MessageWrapper::SetTitle(const base::string16& title) {
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jstring> jtitle =
......@@ -34,6 +42,15 @@ void MessageWrapper::SetTitle(const base::string16& title) {
Java_MessageWrapper_setTitle(env, java_message_wrapper_, jtitle);
}
base::string16 MessageWrapper::GetDescription() {
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jstring> jdescription =
Java_MessageWrapper_getDescription(env, java_message_wrapper_);
return jdescription.is_null()
? base::string16()
: base::android::ConvertJavaStringToUTF16(jdescription);
}
void MessageWrapper::SetDescription(const base::string16& description) {
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jstring> jdescription =
......@@ -41,6 +58,15 @@ void MessageWrapper::SetDescription(const base::string16& description) {
Java_MessageWrapper_setDescription(env, java_message_wrapper_, jdescription);
}
base::string16 MessageWrapper::GetPrimaryButtonText() {
JNIEnv* env = base::android::AttachCurrentThread();
base::android::ScopedJavaLocalRef<jstring> jprimary_button_text =
Java_MessageWrapper_getPrimaryButtonText(env, java_message_wrapper_);
return jprimary_button_text.is_null()
? base::string16()
: base::android::ConvertJavaStringToUTF16(jprimary_button_text);
}
void MessageWrapper::SetPrimaryButtonText(
const base::string16& primary_button_text) {
JNIEnv* env = base::android::AttachCurrentThread();
......@@ -50,6 +76,11 @@ void MessageWrapper::SetPrimaryButtonText(
jprimary_button_text);
}
int MessageWrapper::GetIconResourceId() {
JNIEnv* env = base::android::AttachCurrentThread();
return Java_MessageWrapper_getIconResourceId(env, java_message_wrapper_);
}
void MessageWrapper::SetIconResourceId(int resource_id) {
JNIEnv* env = base::android::AttachCurrentThread();
Java_MessageWrapper_setIconResourceId(env, java_message_wrapper_,
......
......@@ -28,11 +28,19 @@ class MessageWrapper {
MessageWrapper(const MessageWrapper&) = delete;
MessageWrapper& operator=(const MessageWrapper&) = delete;
// Methods to set message properties. On Android the values are propagated to
// Java and stored in |PropertyModel|.
// Methods to manipulate message properties. On Android the values are
// propagated to Java and stored in |PropertyModel|.
// TODO(pavely): Reevaluate if propagating values to Java immediately is
// really necessary. Alternatively we could collect all the values in native
// and pass them to Java when enqueueing the message.
base::string16 GetTitle();
void SetTitle(const base::string16& title);
base::string16 GetDescription();
void SetDescription(const base::string16& description);
base::string16 GetPrimaryButtonText();
void SetPrimaryButtonText(const base::string16& primary_button_text);
int GetIconResourceId();
// When setting a message icon use ResourceMapper::MapToJavaDrawableId to
// translate from chromium resource_id to Android drawable resource_id.
void SetIconResourceId(int resource_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment