Commit a37624bc authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[Self Share] Add confirmation notification when user successfully send tab to other devices

Add a transient notification to tell the user that the tab is successfully shared.

Bug: 941177
Change-Id: I8ede1448c9bd3a4eabea2ae234f08640abc0c1d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1518899
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Reviewed-by: default avatarJeffrey Cohen <jeffreycohen@chromium.org>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#641691}
parent 20c67bc7
......@@ -45,7 +45,7 @@ void DesktopNotificationHandler::DisplayNewEntry(
message_center::NOTIFICATION_TYPE_SIMPLE, entry->GetGUID(),
base::UTF8ToUTF16(entry->GetTitle()), device_info, gfx::Image(),
base::UTF8ToUTF16(url.host()), url, message_center::NotifierId(url),
optional_fields, nullptr);
optional_fields, /*delegate=*/nullptr);
NotificationDisplayServiceFactory::GetForProfile(profile_)->Display(
NotificationHandler::Type::SEND_TAB_TO_SELF, notification);
}
......@@ -84,12 +84,31 @@ void DesktopNotificationHandler::OnClick(
Navigate(&params);
NotificationDisplayServiceFactory::GetForProfile(profile)->Close(
NotificationHandler::Type::SEND_TAB_TO_SELF, notification_id);
// Delete the entry in SendTabToSelfModel
SendTabToSelfSyncServiceFactory::GetForProfile(profile)
->GetSendTabToSelfModel()
->DeleteEntry(notification_id);
std::move(completed_closure).Run();
}
void DesktopNotificationHandler::DisplaySendingConfirmation(
const SendTabToSelfEntry* entry) {
const GURL& url = entry->GetURL();
// Declare a notification
message_center::Notification notification(
message_center::NOTIFICATION_TYPE_SIMPLE, entry->GetGUID(),
l10n_util::GetStringUTF16(
IDS_MESSAGE_NOTIFICATION_SEND_TAB_TO_SELF_CONFIRMATION_SUCCESS),
base::UTF8ToUTF16(entry->GetTitle()), gfx::Image(),
base::UTF8ToUTF16(url.host()), url, message_center::NotifierId(url),
message_center::RichNotificationData(), /*delegate=*/nullptr);
NotificationDisplayServiceFactory::GetForProfile(profile_)->Display(
NotificationHandler::Type::SEND_TAB_TO_SELF, notification);
}
void DesktopNotificationHandler::DisplayFailureMessage() {
// TODO(crbug/942206): implement after the design has been finalized
NOTIMPLEMENTED();
}
} // namespace send_tab_to_self
......@@ -43,6 +43,13 @@ class DesktopNotificationHandler : public NotificationHandler,
const base::Optional<base::string16>& reply,
base::OnceClosure completed_closure) override;
// When the user share a tab, a confirmation notification will be shown.
// Displays a notification telling the user that the tab was successfully
// sent.
void DisplaySendingConfirmation(const SendTabToSelfEntry* entry);
// Displays a notification telling the user that the tab could not be sent.
void DisplayFailureMessage();
protected:
Profile* const profile_;
DISALLOW_COPY_AND_ASSIGN(DesktopNotificationHandler);
......
......@@ -8,6 +8,7 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/send_tab_to_self/desktop_notification_handler.h"
#include "chrome/browser/sync/device_info_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/send_tab_to_self_sync_service_factory.h"
......@@ -72,9 +73,15 @@ bool ShouldOfferFeature(Browser* browser) {
void CreateNewEntry(content::WebContents* tab, Profile* profile) {
GURL url = tab->GetURL();
std::string title = base::UTF16ToUTF8(tab->GetTitle());
SendTabToSelfSyncServiceFactory::GetForProfile(profile)
->GetSendTabToSelfModel()
->AddEntry(url, title);
const send_tab_to_self::SendTabToSelfEntry* entry =
SendTabToSelfSyncServiceFactory::GetForProfile(profile)
->GetSendTabToSelfModel()
->AddEntry(url, title);
if (entry) {
DesktopNotificationHandler(profile).DisplaySendingConfirmation(entry);
} else {
DesktopNotificationHandler(profile).DisplayFailureMessage();
}
}
} // namespace send_tab_to_self
......@@ -767,6 +767,9 @@ need to be translated for each locale.-->
<message name="IDS_MESSAGE_NOTIFICATION_SEND_TAB_TO_SELF_DEVICE_INFO" desc="The message text for the notification when the user receive a shared tab from another device. It shows the name of the device which shared the tab.">
Shared from <ph name="DEVICE_NAME">$1<ex>Ted's Pixel 2</ex></ph>
</message>
<message name="IDS_MESSAGE_NOTIFICATION_SEND_TAB_TO_SELF_CONFIRMATION_SUCCESS" desc="The title text for the comformation notification when the user successfully share a tab to other devices.">
Sending tab...
</message>
<if expr="chromeos">
<message name="IDS_MESSAGE_CENTER_NOTIFIER_SCREENSHOT_NAME" desc="The name of screenshot notifier that is a system component">
Screenshot
......
81ac47988e7b25274c7281f2ccb43b3e12f7ecfb
\ No newline at end of file
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