Commit 756282c5 authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Add UserAction when tooltip is shown

Log a UserAction when the tooltip in CookieControlsBubbleView is shown.
In order to listen for this event, an observer was added to TooltipIcon.

Bug: 1047118
Change-Id: I2e61ce1e689cf17d917da9c4101e3e65f8d7a45d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2030170Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738118}
parent 689362cb
......@@ -20,7 +20,6 @@
#include "ui/gfx/text_utils.h"
#include "ui/views/background.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/bubble/tooltip_icon.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/link.h"
#include "ui/views/layout/box_layout.h"
......@@ -105,7 +104,7 @@ CookieControlsBubbleView::CookieControlsBubbleView(
CookieControlsController* controller)
: LocationBarBubbleDelegateView(anchor_view, web_contents),
controller_(controller) {
observer_.Add(controller);
controller_observer_.Add(controller);
DialogDelegate::set_buttons(ui::DIALOG_BUTTON_NONE);
}
......@@ -126,7 +125,9 @@ void CookieControlsBubbleView::UpdateUi() {
text_->SetVisible(true);
text_->SetText(
l10n_util::GetStringUTF16(IDS_COOKIE_CONTROLS_NOT_WORKING_DESCRIPTION));
extra_view_ = SetExtraView(CreateInfoIcon());
auto tooltip_icon = CreateInfoIcon();
tooltip_observer_.Add(tooltip_icon.get());
extra_view_ = SetExtraView(std::move(tooltip_icon));
show_cookies_link_->SetVisible(true);
} else if (status_ == CookieControlsController::Status::kEnabled) {
header_view_->SetVisible(true);
......@@ -295,3 +296,12 @@ void CookieControlsBubbleView::NotWorkingLinkClicked() {
intermediate_step_ = IntermediateStep::kTurnOffButton;
UpdateUi();
}
void CookieControlsBubbleView::OnTooltipBubbleShown(views::TooltipIcon* icon) {
base::RecordAction(UserMetricsAction("CookieControls.Bubble.TooltipShown"));
}
void CookieControlsBubbleView::OnTooltipIconDestroying(
views::TooltipIcon* icon) {
tooltip_observer_.Remove(icon);
}
......@@ -11,6 +11,7 @@
#include "chrome/browser/ui/cookie_controls/cookie_controls_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_bubble_delegate_view.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "ui/views/bubble/tooltip_icon.h"
#include "ui/views/controls/button/button.h"
namespace content {
......@@ -24,6 +25,7 @@ class Label;
// View used to display the cookie controls ui.
class CookieControlsBubbleView : public LocationBarBubbleDelegateView,
public views::TooltipIcon::Observer,
public CookieControlsView {
public:
static void ShowBubble(views::View* anchor_view,
......@@ -67,6 +69,10 @@ class CookieControlsBubbleView : public LocationBarBubbleDelegateView,
void NotWorkingLinkClicked();
void OnDialogAccepted();
// views::TooltipIcon::Observer:
void OnTooltipBubbleShown(views::TooltipIcon* icon) override;
void OnTooltipIconDestroying(views::TooltipIcon* icon) override;
CookieControlsController* controller_ = nullptr;
CookieControlsController::Status status_ =
......@@ -81,7 +87,10 @@ class CookieControlsBubbleView : public LocationBarBubbleDelegateView,
views::View* extra_view_ = nullptr;
views::View* show_cookies_link_ = nullptr;
ScopedObserver<CookieControlsController, CookieControlsView> observer_{this};
ScopedObserver<CookieControlsController, CookieControlsView>
controller_observer_{this};
ScopedObserver<views::TooltipIcon, views::TooltipIcon::Observer>
tooltip_observer_{this};
DISALLOW_COPY_AND_ASSIGN(CookieControlsBubbleView);
};
......
......@@ -4983,6 +4983,14 @@ should be able to be added at any place in this file.
<description>The cookie controls UI was opened.</description>
</action>
<action name="CookieControls.Bubble.TooltipShown">
<owner>dullweber@chromium.org</owner>
<owner>huanzhong@chromium.org</owner>
<description>
The user looked at the tooltip inside the cookie controls bubble.
</description>
</action>
<action name="CookieControls.Bubble.TurnOff">
<owner>dullweber@chromium.org</owner>
<owner>huanzhong@chromium.org</owner>
......
......@@ -25,6 +25,8 @@ TooltipIcon::TooltipIcon(const base::string16& tooltip, int tooltip_icon_size)
}
TooltipIcon::~TooltipIcon() {
for (auto& observer : observers_)
observer.OnTooltipIconDestroying(this);
HideBubble();
}
......@@ -65,6 +67,14 @@ void TooltipIcon::MouseMovedOutOfHost() {
HideBubble();
}
void TooltipIcon::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void TooltipIcon::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
void TooltipIcon::SetDrawAsHovered(bool hovered) {
SetImage(gfx::CreateVectorIcon(
vector_icons::kInfoOutlineIcon, tooltip_icon_size_,
......@@ -95,6 +105,9 @@ void TooltipIcon::ShowBubble() {
std::make_unique<MouseWatcherViewHost>(frame, gfx::Insets()), this);
mouse_watcher_->Start(GetWidget()->GetNativeWindow());
}
for (auto& observer : observers_)
observer.OnTooltipBubbleShown(this);
}
void TooltipIcon::HideBubble() {
......
......@@ -26,6 +26,15 @@ class VIEWS_EXPORT TooltipIcon : public ImageView,
public MouseWatcherListener,
public WidgetObserver {
public:
class Observer : public base::CheckedObserver {
public:
// Called when tooltip bubble of the TooltipIcon is shown.
virtual void OnTooltipBubbleShown(TooltipIcon* icon) = 0;
// Called when the TooltipIcon is being destroyed.
virtual void OnTooltipIconDestroying(TooltipIcon* icon) = 0;
};
METADATA_HEADER(TooltipIcon);
explicit TooltipIcon(const base::string16& tooltip,
......@@ -53,6 +62,9 @@ class VIEWS_EXPORT TooltipIcon : public ImageView,
anchor_point_arrow_ = arrow;
}
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
private:
// Changes the color to reflect the hover node_data.
void SetDrawAsHovered(bool hovered);
......@@ -92,6 +104,8 @@ class VIEWS_EXPORT TooltipIcon : public ImageView,
ScopedObserver<Widget, WidgetObserver> observer_{this};
base::ObserverList<Observer, /*check_empty=*/true> observers_;
DISALLOW_COPY_AND_ASSIGN(TooltipIcon);
};
......
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