Commit ac88fe8c authored by Yuwei Huang's avatar Yuwei Huang Committed by Commit Bot

[remoting][mobile] Remove TOAST notification appearance

Dialog notifications now support "Don't show again" checkbox, and it is
deemed nontrivial to implement toast with action button on Android, so
the usefulness and maintenance difficulty of having the TOAST appearance
is questionable. This CL removes the TOAST appearance and the appearance
enum altogether.

Bug: 1001291
Change-Id: I2fe082a80fd9f84dbda96faa453ef99d732e9dda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1848412Reviewed-by: default avatarYuwei Huang <yuweih@chromium.org>
Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703960}
parent 37d11630
...@@ -98,10 +98,7 @@ template("remoting_android_client_java_tmpl") { ...@@ -98,10 +98,7 @@ template("remoting_android_client_java_tmpl") {
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ] annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
srcjar_deps = [ srcjar_deps = [ "//remoting/client/jni:jni_enums" ]
"//remoting/client/jni:jni_enums",
"//remoting/client/notification:notification_enums",
]
if (defined(invoker.play_services_package)) { if (defined(invoker.play_services_package)) {
deps += [ deps += [
......
...@@ -15,7 +15,6 @@ import androidx.annotation.IntDef; ...@@ -15,7 +15,6 @@ import androidx.annotation.IntDef;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods; import org.chromium.base.annotations.NativeMethods;
import org.chromium.chromoting.NotificationAppearance;
import org.chromium.chromoting.Preconditions; import org.chromium.chromoting.Preconditions;
import org.chromium.chromoting.R; import org.chromium.chromoting.R;
...@@ -66,8 +65,7 @@ public final class NotificationPresenter { ...@@ -66,8 +65,7 @@ public final class NotificationPresenter {
} }
@CalledByNative @CalledByNative
void onNotificationFetched(@NotificationAppearance int appearance, String messageText, void onNotificationFetched(String messageText, String linkText, String linkUrl) {
String linkText, String linkUrl) {
Preconditions.isTrue(mState == State.FETCHING); Preconditions.isTrue(mState == State.FETCHING);
mState = State.FETCHED; mState = State.FETCHED;
......
...@@ -57,14 +57,12 @@ void JniNotificationPresenter::OnNotificationFetched( ...@@ -57,14 +57,12 @@ void JniNotificationPresenter::OnNotificationFetched(
Java_NotificationPresenter_onNoNotification(env, java_presenter); Java_NotificationPresenter_onNoNotification(env, java_presenter);
return; return;
} }
jint j_appearance = static_cast<jint>(notification->appearance);
auto j_message_text = auto j_message_text =
ConvertUTF8ToJavaString(env, notification->message_text); ConvertUTF8ToJavaString(env, notification->message_text);
auto j_link_text = ConvertUTF8ToJavaString(env, notification->link_text); auto j_link_text = ConvertUTF8ToJavaString(env, notification->link_text);
auto j_link_url = ConvertUTF8ToJavaString(env, notification->link_url); auto j_link_url = ConvertUTF8ToJavaString(env, notification->link_url);
Java_NotificationPresenter_onNotificationFetched(env, java_presenter, Java_NotificationPresenter_onNotificationFetched(
j_appearance, j_message_text, env, java_presenter, j_message_text, j_link_text, j_link_url);
j_link_text, j_link_url);
} }
static jlong JNI_NotificationPresenter_Init( static jlong JNI_NotificationPresenter_Init(
......
...@@ -2,11 +2,6 @@ ...@@ -2,11 +2,6 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
if (is_android) {
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
}
source_set("notification") { source_set("notification") {
sources = [ sources = [
"gstatic_json_fetcher.cc", "gstatic_json_fetcher.cc",
...@@ -30,14 +25,6 @@ source_set("notification") { ...@@ -30,14 +25,6 @@ source_set("notification") {
] ]
} }
if (is_android) {
java_cpp_enum("notification_enums") {
sources = [
"notification_message.h",
]
}
}
source_set("unit_tests") { source_set("unit_tests") {
testonly = true testonly = true
......
...@@ -254,7 +254,6 @@ base::Optional<NotificationMessage> NotificationClient::ParseAndMatchRule( ...@@ -254,7 +254,6 @@ base::Optional<NotificationMessage> NotificationClient::ParseAndMatchRule(
const std::string& user_email, const std::string& user_email,
std::string* out_message_text_filename, std::string* out_message_text_filename,
std::string* out_link_text_filename) { std::string* out_link_text_filename) {
std::string appearance_string;
std::string target_platform; std::string target_platform;
std::string version_spec_string; std::string version_spec_string;
std::string message_id; std::string message_id;
...@@ -262,8 +261,7 @@ base::Optional<NotificationMessage> NotificationClient::ParseAndMatchRule( ...@@ -262,8 +261,7 @@ base::Optional<NotificationMessage> NotificationClient::ParseAndMatchRule(
std::string link_text_filename; std::string link_text_filename;
std::string link_url; std::string link_url;
int percent; int percent;
if (!FindKeyAndGet(rule, "appearance", &appearance_string) || if (!FindKeyAndGet(rule, "target_platform", &target_platform) ||
!FindKeyAndGet(rule, "target_platform", &target_platform) ||
!FindKeyAndGet(rule, "version", &version_spec_string) || !FindKeyAndGet(rule, "version", &version_spec_string) ||
!FindKeyAndGet(rule, "message_id", &message_id) || !FindKeyAndGet(rule, "message_id", &message_id) ||
!FindKeyAndGet(rule, "message_text", &message_text_filename) || !FindKeyAndGet(rule, "message_text", &message_text_filename) ||
...@@ -304,14 +302,6 @@ base::Optional<NotificationMessage> NotificationClient::ParseAndMatchRule( ...@@ -304,14 +302,6 @@ base::Optional<NotificationMessage> NotificationClient::ParseAndMatchRule(
} }
auto message = base::make_optional<NotificationMessage>(); auto message = base::make_optional<NotificationMessage>();
if (appearance_string == "TOAST") {
message->appearance = NotificationMessage::Appearance::TOAST;
} else if (appearance_string == "DIALOG") {
message->appearance = NotificationMessage::Appearance::DIALOG;
} else {
LOG(ERROR) << "Unknown appearance: " << appearance_string;
return base::nullopt;
}
message->message_id = message_id; message->message_id = message_id;
message->link_url = link_url; message->link_url = link_url;
message->allow_dont_show_again = false; message->allow_dont_show_again = false;
......
...@@ -45,8 +45,7 @@ MATCHER(NoMessage, "") { ...@@ -45,8 +45,7 @@ MATCHER(NoMessage, "") {
} }
MATCHER_P(MessageMatches, expected, "") { MATCHER_P(MessageMatches, expected, "") {
return arg->appearance == expected.appearance && return arg->message_id == expected.message_id &&
arg->message_id == expected.message_id &&
arg->message_text == expected.message_text && arg->message_text == expected.message_text &&
arg->link_text == expected.link_text && arg->link_text == expected.link_text &&
arg->link_url == expected.link_url; arg->link_url == expected.link_url;
...@@ -59,7 +58,6 @@ decltype(auto) ReturnByMove(T t) { ...@@ -59,7 +58,6 @@ decltype(auto) ReturnByMove(T t) {
base::Value CreateDefaultRule() { base::Value CreateDefaultRule() {
base::Value rule(base::Value::Type::DICTIONARY); base::Value rule(base::Value::Type::DICTIONARY);
rule.SetStringKey("appearance", "TOAST");
rule.SetStringKey("target_platform", "IOS"); rule.SetStringKey("target_platform", "IOS");
rule.SetStringKey("version", "[75-)"); rule.SetStringKey("version", "[75-)");
rule.SetStringKey("message_id", "test_message"); rule.SetStringKey("message_id", "test_message");
...@@ -80,7 +78,6 @@ base::Value CreateDefaultTranslations(const std::string& text) { ...@@ -80,7 +78,6 @@ base::Value CreateDefaultTranslations(const std::string& text) {
NotificationMessage CreateDefaultNotification() { NotificationMessage CreateDefaultNotification() {
NotificationMessage message; NotificationMessage message;
message.appearance = NotificationMessage::Appearance::TOAST;
message.message_id = "test_message"; message.message_id = "test_message";
message.message_text = "zh-CN:message"; message.message_text = "zh-CN:message";
message.link_text = "zh-CN:link"; message.link_text = "zh-CN:link";
......
...@@ -10,13 +10,6 @@ ...@@ -10,13 +10,6 @@
namespace remoting { namespace remoting {
struct NotificationMessage final { struct NotificationMessage final {
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chromoting
// GENERATED_JAVA_CLASS_NAME_OVERRIDE: NotificationAppearance
enum class Appearance {
TOAST,
DIALOG,
};
NotificationMessage(); NotificationMessage();
NotificationMessage(const NotificationMessage&); NotificationMessage(const NotificationMessage&);
NotificationMessage(NotificationMessage&&); NotificationMessage(NotificationMessage&&);
...@@ -25,7 +18,6 @@ struct NotificationMessage final { ...@@ -25,7 +18,6 @@ struct NotificationMessage final {
NotificationMessage& operator=(const NotificationMessage&); NotificationMessage& operator=(const NotificationMessage&);
NotificationMessage& operator=(NotificationMessage&&); NotificationMessage& operator=(NotificationMessage&&);
Appearance appearance;
std::string message_id; std::string message_id;
std::string message_text; std::string message_text;
std::string link_text; std::string link_text;
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "remoting/ios/app/notification_presenter.h" #include "remoting/ios/app/notification_presenter.h"
#import "ios/third_party/material_components_ios/src/components/Dialogs/src/MaterialDialogs.h" #import "ios/third_party/material_components_ios/src/components/Dialogs/src/MaterialDialogs.h"
#import "ios/third_party/material_components_ios/src/components/Snackbar/src/MaterialSnackbar.h"
#import "remoting/ios/app/notification_dialog_view_controller.h" #import "remoting/ios/app/notification_dialog_view_controller.h"
#import "remoting/ios/facade/remoting_authentication.h" #import "remoting/ios/facade/remoting_authentication.h"
#import "remoting/ios/facade/remoting_service.h" #import "remoting/ios/facade/remoting_service.h"
...@@ -141,53 +140,19 @@ void NotificationPresenter::OnNotificationFetched( ...@@ -141,53 +140,19 @@ void NotificationPresenter::OnNotificationFetched(
[RemotingPreferences.instance synchronizeFlags]; [RemotingPreferences.instance synchronizeFlags];
} }
NSURL* url = BOOL shouldShowDontShowAgain =
[NSURL URLWithString:base::SysUTF8ToNSString(notification->link_url)]; notification->allow_dont_show_again && ui_state == SHOWN_AT_LEAST_ONCE;
NotificationDialogViewController* dialogVc =
NSString* message_text_nsstring = [[NotificationDialogViewController alloc]
base::SysUTF8ToNSString(notification->message_text); initWithNotificationMessage:*notification
NSString* link_text_nsstring = shouldShowDontShowAgainToggle:shouldShowDontShowAgain];
base::SysUTF8ToNSString(notification->link_text); [dialogVc presentOnTopVCWithCompletion:^(BOOL isDontShowAgainOn) {
NotificationUiState new_ui_state =
switch (notification->appearance) { isDontShowAgainOn ? USER_CHOSE_DONT_SHOW_AGAIN : SHOWN_AT_LEAST_ONCE;
case NotificationMessage::Appearance::TOAST: { [RemotingPreferences.instance setObject:UiStateToNSNumber(new_ui_state)
MDCSnackbarMessage* message = [MDCSnackbarMessage new]; forFlag:RemotingFlagNotificationUiState];
message.text = message_text_nsstring; [RemotingPreferences.instance synchronizeFlags];
MDCSnackbarMessageAction* action = [MDCSnackbarMessageAction new]; }];
action.handler = ^{
[[UIApplication sharedApplication] openURL:url
options:@{}
completionHandler:nil];
};
action.title = link_text_nsstring;
message.action = action;
message.duration = MDCSnackbarMessageDurationMax;
[MDCSnackbarManager showMessage:message];
break;
}
case NotificationMessage::Appearance::DIALOG: {
BOOL shouldShowDontShowAgain = notification->allow_dont_show_again &&
ui_state == SHOWN_AT_LEAST_ONCE;
NotificationDialogViewController* dialogVc =
[[NotificationDialogViewController alloc]
initWithNotificationMessage:*notification
shouldShowDontShowAgainToggle:shouldShowDontShowAgain];
[dialogVc presentOnTopVCWithCompletion:^(BOOL isDontShowAgainOn) {
NotificationUiState new_ui_state = isDontShowAgainOn
? USER_CHOSE_DONT_SHOW_AGAIN
: SHOWN_AT_LEAST_ONCE;
[RemotingPreferences.instance
setObject:UiStateToNSNumber(new_ui_state)
forFlag:RemotingFlagNotificationUiState];
[RemotingPreferences.instance synchronizeFlags];
}];
break;
}
default:
LOG(DFATAL) << "Unknown appearance: "
<< static_cast<int>(notification->appearance);
break;
}
} }
} // namespace remoting } // namespace remoting
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