Commit 66cc022e authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

Windows Native Notifications: Inline reply.

Bug: 734095
Change-Id: I87213656fd5e692650d75e8ca7929931bcb54f2d
Reviewed-on: https://chromium-review.googlesource.com/955482
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarTommy Martino <tmartino@chromium.org>
Reviewed-by: default avatarXi Cheng <chengx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542100}
parent 6c23b352
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <utility> #include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/hash.h" #include "base/hash.h"
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
#include "chrome/browser/notifications/notification_template_builder.h" #include "chrome/browser/notifications/notification_template_builder.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/install_static/install_util.h" #include "chrome/install_static/install_util.h"
#include "chrome/installer/util/install_util.h" #include "chrome/installer/util/install_util.h"
#include "chrome/installer/util/shell_util.h" #include "chrome/installer/util/shell_util.h"
...@@ -87,6 +89,7 @@ void ForwardNotificationOperationOnUiThread( ...@@ -87,6 +89,7 @@ void ForwardNotificationOperationOnUiThread(
const std::string& profile_id, const std::string& profile_id,
bool incognito, bool incognito,
const base::Optional<int>& action_index, const base::Optional<int>& action_index,
const base::Optional<base::string16>& reply,
const base::Optional<bool>& by_user) { const base::Optional<bool>& by_user) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!g_browser_process) if (!g_browser_process)
...@@ -96,7 +99,7 @@ void ForwardNotificationOperationOnUiThread( ...@@ -96,7 +99,7 @@ void ForwardNotificationOperationOnUiThread(
profile_id, incognito, profile_id, incognito,
base::Bind(&NotificationDisplayServiceImpl::ProfileLoadedCallback, base::Bind(&NotificationDisplayServiceImpl::ProfileLoadedCallback,
operation, notification_type, origin, notification_id, operation, notification_type, origin, notification_id,
action_index, /*reply=*/base::nullopt, by_user)); action_index, reply, by_user));
} }
} // namespace } // namespace
...@@ -497,7 +500,8 @@ class NotificationPlatformBridgeWinImpl ...@@ -497,7 +500,8 @@ class NotificationPlatformBridgeWinImpl
base::BindOnce(&ForwardNotificationOperationOnUiThread, operation, base::BindOnce(&ForwardNotificationOperationOnUiThread, operation,
launch_id.notification_type(), launch_id.origin_url(), launch_id.notification_type(), launch_id.origin_url(),
launch_id.notification_id(), launch_id.profile_id(), launch_id.notification_id(), launch_id.profile_id(),
launch_id.incognito(), action_index, by_user)); launch_id.incognito(), action_index,
/*reply=*/base::nullopt, by_user));
} }
base::Optional<int> ParseActionIndex( base::Optional<int> ParseActionIndex(
...@@ -732,14 +736,22 @@ void NotificationPlatformBridgeWin::SetReadyCallback( ...@@ -732,14 +736,22 @@ void NotificationPlatformBridgeWin::SetReadyCallback(
} }
// static // static
bool NotificationPlatformBridgeWin::HandleActivation( bool NotificationPlatformBridgeWin::HandleActivation() {
const std::string& launch_id_str) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
std::string launch_id_str =
command_line->GetSwitchValueASCII(switches::kNotificationLaunchId);
NotificationLaunchId launch_id(launch_id_str); NotificationLaunchId launch_id(launch_id_str);
if (!launch_id.is_valid()) if (!launch_id.is_valid())
return false; return false;
base::Optional<base::string16> reply;
base::string16 inline_reply =
command_line->GetSwitchValueNative(switches::kNotificationInlineReply);
if (!inline_reply.empty())
reply = inline_reply;
NotificationCommon::Operation operation = launch_id.is_for_context_menu() NotificationCommon::Operation operation = launch_id.is_for_context_menu()
? NotificationCommon::SETTINGS ? NotificationCommon::SETTINGS
: NotificationCommon::CLICK; : NotificationCommon::CLICK;
...@@ -747,7 +759,7 @@ bool NotificationPlatformBridgeWin::HandleActivation( ...@@ -747,7 +759,7 @@ bool NotificationPlatformBridgeWin::HandleActivation(
ForwardNotificationOperationOnUiThread( ForwardNotificationOperationOnUiThread(
operation, launch_id.notification_type(), launch_id.origin_url(), operation, launch_id.notification_type(), launch_id.origin_url(),
launch_id.notification_id(), launch_id.profile_id(), launch_id.notification_id(), launch_id.profile_id(),
launch_id.incognito(), launch_id.button_index(), /*by_user=*/true); launch_id.incognito(), launch_id.button_index(), reply, /*by_user=*/true);
return true; return true;
} }
......
...@@ -38,9 +38,9 @@ class NotificationPlatformBridgeWin : public NotificationPlatformBridge { ...@@ -38,9 +38,9 @@ class NotificationPlatformBridgeWin : public NotificationPlatformBridge {
const GetDisplayedNotificationsCallback& callback) const override; const GetDisplayedNotificationsCallback& callback) const override;
void SetReadyCallback(NotificationBridgeReadyCallback callback) override; void SetReadyCallback(NotificationBridgeReadyCallback callback) override;
// Handles notification activation given |launch_id_str| via the // Handles notification activation from the notification_helper process.
// notification_helper process. Returns false if |launch_id_str| is invalid. // Returns false if the launch id, passed via the command line, is invalid.
static bool HandleActivation(const std::string& launch_id_str); static bool HandleActivation();
// Extracts the profile ID from |launch_id_str|. // Extracts the profile ID from |launch_id_str|.
static std::string GetProfileIdFromLaunchId(const std::string& launch_id_str); static std::string GetProfileIdFromLaunchId(const std::string& launch_id_str);
......
...@@ -335,9 +335,7 @@ bool StartupBrowserCreatorImpl::Launch(Profile* profile, ...@@ -335,9 +335,7 @@ bool StartupBrowserCreatorImpl::Launch(Profile* profile,
// Launch() call is from notification_helper.exe to process toast activation. // Launch() call is from notification_helper.exe to process toast activation.
// Delegate to the notification system; do not open a browser window here. // Delegate to the notification system; do not open a browser window here.
if (command_line_.HasSwitch(switches::kNotificationLaunchId)) { if (command_line_.HasSwitch(switches::kNotificationLaunchId)) {
if (NotificationPlatformBridgeWin::HandleActivation( if (NotificationPlatformBridgeWin::HandleActivation()) {
command_line_.GetSwitchValueASCII(
switches::kNotificationLaunchId))) {
RecordLaunchModeHistogram(LM_WIN_PLATFORM_NOTIFICATION); RecordLaunchModeHistogram(LM_WIN_PLATFORM_NOTIFICATION);
return true; return true;
} }
......
...@@ -921,6 +921,10 @@ const char kHideIcons[] = "hide-icons"; ...@@ -921,6 +921,10 @@ const char kHideIcons[] = "hide-icons";
// This flag is only relevant for Windows currently. // This flag is only relevant for Windows currently.
const char kNoNetworkProfileWarning[] = "no-network-profile-warning"; const char kNoNetworkProfileWarning[] = "no-network-profile-warning";
// Used in combination with kNotificationLaunchId to specify the inline reply
// entered in the toast in the Windows Action Center.
const char kNotificationInlineReply[] = "notification-inline-reply";
// Used for launching Chrome when a toast displayed in the Windows Action Center // Used for launching Chrome when a toast displayed in the Windows Action Center
// has been activated. Should contain the launch ID encoded by Chrome. // has been activated. Should contain the launch ID encoded by Chrome.
const char kNotificationLaunchId[] = "notification-launch-id"; const char kNotificationLaunchId[] = "notification-launch-id";
......
...@@ -286,6 +286,7 @@ extern const char kEnableCloudPrintXps[]; ...@@ -286,6 +286,7 @@ extern const char kEnableCloudPrintXps[];
extern const char kEnableProfileShortcutManager[]; extern const char kEnableProfileShortcutManager[];
extern const char kHideIcons[]; extern const char kHideIcons[];
extern const char kNoNetworkProfileWarning[]; extern const char kNoNetworkProfileWarning[];
extern const char kNotificationInlineReply[];
extern const char kNotificationLaunchId[]; extern const char kNotificationLaunchId[];
extern const char kPrefetchArgumentBrowserBackground[]; extern const char kPrefetchArgumentBrowserBackground[];
extern const char kPrefetchArgumentWatcher[]; extern const char kPrefetchArgumentWatcher[];
......
...@@ -13,6 +13,13 @@ ...@@ -13,6 +13,13 @@
#include "notification_helper/notification_helper_util.h" #include "notification_helper/notification_helper_util.h"
#include "notification_helper/trace_util.h" #include "notification_helper/trace_util.h"
namespace {
// The response entered by the user while interacting with the toast.
const wchar_t kUserResponse[] = L"userResponse";
} // namespace
namespace notification_helper { namespace notification_helper {
NotificationActivator::~NotificationActivator() = default; NotificationActivator::~NotificationActivator() = default;
...@@ -55,6 +62,16 @@ HRESULT NotificationActivator::Activate( ...@@ -55,6 +62,16 @@ HRESULT NotificationActivator::Activate(
base::CommandLine command_line(base::CommandLine::NO_PROGRAM); base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
command_line.AppendSwitchNative(switches::kNotificationLaunchId, command_line.AppendSwitchNative(switches::kNotificationLaunchId,
invoked_args); invoked_args);
// Check to see if a user response (inline reply) is also supplied.
for (ULONG i = 0; i < count; ++i) {
if (lstrcmpW(kUserResponse, data[i].Key) == 0) {
command_line.AppendSwitchNative(switches::kNotificationInlineReply,
data[i].Value);
break;
}
}
base::string16 params(command_line.GetCommandLineString()); base::string16 params(command_line.GetCommandLineString());
SHELLEXECUTEINFO info; SHELLEXECUTEINFO info;
......
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