Skip to content

Commit

Permalink
[send-tab-to-self/desktop] Add desktop promos UI
Browse files Browse the repository at this point in the history
This CL adds new UI which is behind a feature flag disabled by default.
We'll still iterate on the UI, e.g. if the user
is signed in but has no valid target devices, no account indication
is shown yet.

The existing SendTabToSelfBubbleViewImpl is renamed since it's no
longer the only implementation of SendTabToSelfBubbleView.

Mocks: crbug.com/1219433#c0
Implementation: crbug.com/1219433#c9

Bug: 1219433
Change-Id: Id1316ebe77a04726394e9a64d4ccf5aa47e8dde9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3610315
Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: David Roger <droger@chromium.org>
Commit-Queue: Victor Vianna <victorvianna@google.com>
Cr-Commit-Position: refs/heads/main@{#1001440}
  • Loading branch information
Victor Hugo Vianna Silva authored and Chromium LUCI CQ committed May 10, 2022
1 parent a71e316 commit 4ca5c34
Show file tree
Hide file tree
Showing 27 changed files with 380 additions and 76 deletions.
3 changes: 3 additions & 0 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -8748,6 +8748,9 @@ Check your passwords anytime in <ph name="GOOGLE_PASSWORD_MANAGER">$1<ex>Google
<message name="IDS_SEND_TAB_TO_SELF_MANAGE_DEVICES_LINK" desc="Text with a link to a page where the user can manage the devices they can share a tab to.">
<ph name="BEGIN_LINK">$1</ph>Your devices<ph name="END_LINK">$2</ph> · <ph name="EMAIL">$3<ex>foo@gmail.com</ex></ph>
</message>
<message name="IDS_SEND_TAB_TO_SELF_PROMO_LABEL" desc = "Text in UI promoting send tab to self. Signed out users see this text and a sign-in button. Signed in users with no valid target device see just the text.">
You can send tabs between devices that are signed in with the same Google Account
</message>

<!-- Share via QR Code strings -->
<if expr="not use_titlecase">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
62a0a2a062b1584703c24b8bcea8c13422e4dd46
6 changes: 4 additions & 2 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4709,10 +4709,12 @@ static_library("ui") {
"views/safe_browsing/tailored_security_unconsented_modal.h",
"views/send_tab_to_self/send_tab_to_self_bubble_device_button.cc",
"views/send_tab_to_self/send_tab_to_self_bubble_device_button.h",
"views/send_tab_to_self/send_tab_to_self_bubble_view_impl.cc",
"views/send_tab_to_self/send_tab_to_self_bubble_view_impl.h",
"views/send_tab_to_self/send_tab_to_self_device_picker_bubble_view.cc",
"views/send_tab_to_self/send_tab_to_self_device_picker_bubble_view.h",
"views/send_tab_to_self/send_tab_to_self_icon_view.cc",
"views/send_tab_to_self/send_tab_to_self_icon_view.h",
"views/send_tab_to_self/send_tab_to_self_promo_bubble_view.cc",
"views/send_tab_to_self/send_tab_to_self_promo_bubble_view.h",
"views/send_tab_to_self/send_tab_to_self_toolbar_bubble_view.cc",
"views/send_tab_to_self/send_tab_to_self_toolbar_bubble_view.h",
"views/send_tab_to_self/send_tab_to_self_toolbar_icon_view.cc",
Expand Down
14 changes: 10 additions & 4 deletions chrome/browser/ui/browser_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,16 @@ class BrowserWindow : public ui::BaseWindow {
const GURL& url,
bool show_back_button) = 0;

// Shows the "send tab to self" bubble. This must only be called as a direct
// result of user action.
virtual send_tab_to_self::SendTabToSelfBubbleView* ShowSendTabToSelfBubble(
content::WebContents* contents) = 0;
// Shows the "send tab to self" device picker bubble. This must only be called
// as a direct result of user action.
virtual send_tab_to_self::SendTabToSelfBubbleView*
ShowSendTabToSelfDevicePickerBubble(content::WebContents* contents) = 0;

// Shows the "send tab to self" promo bubble. This must only be called as a
// direct result of user action.
virtual send_tab_to_self::SendTabToSelfBubbleView*
ShowSendTabToSelfPromoBubble(content::WebContents* contents,
bool show_signin_button) = 0;

#if BUILDFLAG(IS_CHROMEOS)
// Returns the PageActionIconView for the Sharing Hub.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/send_tab_to_self/send_tab_to_self_util.h"
#include "chrome/browser/sharing_hub/sharing_hub_features.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/send_tab_to_self_sync_service_factory.h"
Expand Down Expand Up @@ -64,8 +65,26 @@ void SendTabToSelfBubbleController::ShowBubble(bool show_back_button) {
show_back_button_ = show_back_button;
bubble_shown_ = true;
Browser* browser = chrome::FindBrowserWithWebContents(&GetWebContents());
send_tab_to_self_bubble_view_ =
browser->window()->ShowSendTabToSelfBubble(&GetWebContents());
absl::optional<send_tab_to_self::EntryPointDisplayReason> reason =
send_tab_to_self::GetEntryPointDisplayReason(&GetWebContents());
DCHECK(reason);
switch (*reason) {
case send_tab_to_self::EntryPointDisplayReason::kOfferFeature:
send_tab_to_self_bubble_view_ =
browser->window()->ShowSendTabToSelfDevicePickerBubble(
&GetWebContents());
break;
case send_tab_to_self::EntryPointDisplayReason::kOfferSignIn:
send_tab_to_self_bubble_view_ =
browser->window()->ShowSendTabToSelfPromoBubble(
&GetWebContents(), /*show_signin_button=*/true);
break;
case send_tab_to_self::EntryPointDisplayReason::kInformNoTargetDevice:
send_tab_to_self_bubble_view_ =
browser->window()->ShowSendTabToSelfPromoBubble(
&GetWebContents(), /*show_signin_button=*/false);
break;
}

if (sharing_hub::SharingHubOmniboxEnabled(
GetWebContents().GetBrowserContext())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ class SendTabToSelfBubbleController

private:
friend class content::WebContentsUserData<SendTabToSelfBubbleController>;
friend class SendTabToSelfBubbleViewImplTest;
FRIEND_TEST_ALL_PREFIXES(SendTabToSelfBubbleViewImplTest, PopulateScrollView);
FRIEND_TEST_ALL_PREFIXES(SendTabToSelfBubbleViewImplTest, DevicePressed);
friend class SendTabToSelfDevicePickerBubbleViewTest;
FRIEND_TEST_ALL_PREFIXES(SendTabToSelfDevicePickerBubbleViewTest,
PopulateScrollView);
FRIEND_TEST_ALL_PREFIXES(SendTabToSelfDevicePickerBubbleViewTest,
DevicePressed);

void UpdateIcon();

Expand Down
31 changes: 28 additions & 3 deletions chrome/browser/ui/views/frame/browser_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@
#include "chrome/browser/ui/views/profiles/profile_indicator_icon.h"
#include "chrome/browser/ui/views/profiles/profile_menu_view_base.h"
#include "chrome/browser/ui/views/qrcode_generator/qrcode_generator_bubble.h"
#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_bubble_view_impl.h"
#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_device_picker_bubble_view.h"
#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_icon_view.h"
#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_promo_bubble_view.h"
#include "chrome/browser/ui/views/sharing/sharing_dialog_view.h"
#include "chrome/browser/ui/views/sharing_hub/screenshot/screenshot_captured_bubble.h"
#include "chrome/browser/ui/views/sharing_hub/sharing_hub_bubble_view_impl.h"
Expand Down Expand Up @@ -2362,20 +2363,44 @@ SharingDialog* BrowserView::ShowSharingDialog(
return dialog_view;
}

send_tab_to_self::SendTabToSelfBubbleView* BrowserView::ShowSendTabToSelfBubble(
send_tab_to_self::SendTabToSelfBubbleView*
BrowserView::ShowSendTabToSelfDevicePickerBubble(
content::WebContents* web_contents) {
PageActionIconType icon_type =
sharing_hub::SharingHubOmniboxEnabled(browser_->profile())
? PageActionIconType::kSharingHub
: PageActionIconType::kSendTabToSelf;

auto* bubble = new send_tab_to_self::SendTabToSelfBubbleViewImpl(
auto* bubble = new send_tab_to_self::SendTabToSelfDevicePickerBubbleView(
toolbar_button_provider()->GetAnchorView(icon_type), web_contents);
PageActionIconView* icon_view =
toolbar_button_provider()->GetPageActionIconView(icon_type);
if (icon_view)
bubble->SetHighlightedButton(icon_view);

views::BubbleDialogDelegateView::CreateBubble(bubble);
// This is always triggered due to a user gesture, c.f. this method's
// documentation in the interface.
bubble->ShowForReason(LocationBarBubbleDelegateView::USER_GESTURE);
return bubble;
}

send_tab_to_self::SendTabToSelfBubbleView*
BrowserView::ShowSendTabToSelfPromoBubble(content::WebContents* web_contents,
bool show_signin_button) {
PageActionIconType icon_type =
sharing_hub::SharingHubOmniboxEnabled(web_contents->GetBrowserContext())
? PageActionIconType::kSharingHub
: PageActionIconType::kSendTabToSelf;

auto* bubble = new send_tab_to_self::SendTabToSelfPromoBubbleView(
toolbar_button_provider()->GetAnchorView(icon_type), web_contents,
show_signin_button);
PageActionIconView* icon_view =
toolbar_button_provider()->GetPageActionIconView(icon_type);
if (icon_view)
bubble->SetHighlightedButton(icon_view);

views::BubbleDialogDelegateView::CreateBubble(bubble);
// This is always triggered due to a user gesture, c.f. method documentation.
bubble->ShowForReason(LocationBarBubbleDelegateView::USER_GESTURE);
Expand Down
7 changes: 5 additions & 2 deletions chrome/browser/ui/views/frame/browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,11 @@ class BrowserView : public BrowserWindow,
content::WebContents* contents,
const GURL& url,
bool show_back_button) override;
send_tab_to_self::SendTabToSelfBubbleView* ShowSendTabToSelfBubble(
content::WebContents* contents) override;
send_tab_to_self::SendTabToSelfBubbleView*
ShowSendTabToSelfDevicePickerBubble(content::WebContents* contents) override;
send_tab_to_self::SendTabToSelfBubbleView* ShowSendTabToSelfPromoBubble(
content::WebContents* contents,
bool show_signin_button) override;
#if BUILDFLAG(IS_CHROMEOS)
views::Button* GetSharingHubIconButton() override;
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,34 @@ class SendTabToSelfBubbleTest : public DialogBrowserTest {
web_contents->SetUserData(
TestSendTabToSelfBubbleController::UserDataKey(),
std::make_unique<TestSendTabToSelfBubbleController>(web_contents));
BrowserView::GetBrowserViewForBrowser(browser())->ShowSendTabToSelfBubble(
web_contents);

if (name == "ShowDeviceList") {
BrowserView::GetBrowserViewForBrowser(browser())
->ShowSendTabToSelfDevicePickerBubble(web_contents);
} else if (name == "ShowSigninPromo") {
BrowserView::GetBrowserViewForBrowser(browser())
->ShowSendTabToSelfPromoBubble(web_contents,
/*show_signin_button=*/true);
} else if (name == "ShowNoTargetDevicePromo") {
BrowserView::GetBrowserViewForBrowser(browser())
->ShowSendTabToSelfPromoBubble(web_contents,
/*show_signin_button=*/false);
} else {
NOTREACHED();
}
}
};

IN_PROC_BROWSER_TEST_F(SendTabToSelfBubbleTest, InvokeUi_default) {
IN_PROC_BROWSER_TEST_F(SendTabToSelfBubbleTest, InvokeUi_ShowDeviceList) {
ShowAndVerifyUi();
}

IN_PROC_BROWSER_TEST_F(SendTabToSelfBubbleTest, InvokeUi_ShowSigninPromo) {
ShowAndVerifyUi();
}

IN_PROC_BROWSER_TEST_F(SendTabToSelfBubbleTest,
InvokeUi_ShowNoTargetDevicePromo) {
ShowAndVerifyUi();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "base/time/time.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/views/hover_button.h"
#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_bubble_view_impl.h"
#include "chrome/browser/ui/views/send_tab_to_self/send_tab_to_self_device_picker_bubble_view.h"
#include "chrome/grit/generated_resources.h"
#include "components/send_tab_to_self/target_device_info.h"
#include "ui/base/l10n/l10n_util.h"
Expand Down Expand Up @@ -56,15 +56,15 @@ std::u16string GetLastUpdatedTime(const TargetDeviceInfo& device_info) {
} // namespace

SendTabToSelfBubbleDeviceButton::SendTabToSelfBubbleDeviceButton(
SendTabToSelfBubbleViewImpl* bubble,
SendTabToSelfDevicePickerBubbleView* bubble,
const TargetDeviceInfo& device_info)
: HoverButton(
base::BindRepeating(&SendTabToSelfBubbleViewImpl::DeviceButtonPressed,
base::Unretained(bubble),
base::Unretained(this)),
CreateIcon(device_info.device_type),
base::UTF8ToUTF16(device_info.device_name),
GetLastUpdatedTime(device_info)) {
: HoverButton(base::BindRepeating(
&SendTabToSelfDevicePickerBubbleView::DeviceButtonPressed,
base::Unretained(bubble),
base::Unretained(this)),
CreateIcon(device_info.device_type),
base::UTF8ToUTF16(device_info.device_name),
GetLastUpdatedTime(device_info)) {
device_name_ = device_info.device_name;
device_guid_ = device_info.cache_guid;
device_type_ = device_info.device_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

namespace send_tab_to_self {

class SendTabToSelfBubbleViewImpl;
class SendTabToSelfDevicePickerBubbleView;
struct TargetDeviceInfo;

// A button representing a device in share bubble. It is highlighted when
// hovered.
class SendTabToSelfBubbleDeviceButton : public HoverButton {
public:
METADATA_HEADER(SendTabToSelfBubbleDeviceButton);
SendTabToSelfBubbleDeviceButton(SendTabToSelfBubbleViewImpl* bubble,
SendTabToSelfBubbleDeviceButton(SendTabToSelfDevicePickerBubbleView* bubble,
const TargetDeviceInfo& device_info);
SendTabToSelfBubbleDeviceButton(const SendTabToSelfBubbleDeviceButton&) =
delete;
Expand Down

0 comments on commit 4ca5c34

Please sign in to comment.