Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(752)

Side by Side Diff: chrome/browser/ui/views/outdated_upgrade_bubble_view.cc

Issue 11440020: Add an outdated upgrade bubble view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed OWNERS comments... Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h"
6
7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/upgrade_detector.h"
9 #include "content/public/browser/page_navigator.h"
10 #include "content/public/browser/user_metrics.h"
11 #include "googleurl/src/gurl.h"
12 #include "grit/chromium_strings.h"
13 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/views/controls/button/text_button.h"
18 #include "ui/views/controls/image_view.h"
19 #include "ui/views/controls/label.h"
20 #include "ui/views/layout/grid_layout.h"
21 #include "ui/views/layout/layout_constants.h"
22 #include "ui/views/widget/widget.h"
23
24 using views::GridLayout;
25
26 namespace {
27
28 // Fixed width of the column holding the description label of the bubble.
29 // TODO(mad): Make sure there is enough room for all languages.
30 const int kWidthOfDescriptionText = 330;
31
32 // We subtract 2 to account for the natural button padding, and
33 // to bring the separation visually in line with the row separation
34 // height.
35 const int kButtonPadding = views::kRelatedButtonHSpacing - 2;
36
37 // The URL to be used to re-install Chrome when auto-update failed for too long.
38 const char kDownloadChromeUrl[] = "https://www.google.com/chrome/?&brand=CHWL"
39 "&utm_campaign=en&utm_source=en-et-na-us-chrome-bubble&utm_medium=et";
40
41 // The maximum number of ignored bubble we track in the NumLaterPerReinstall
42 // histogram.
43 const int kMaxIgnored = 50;
44 // The number of buckets we want the NumLaterPerReinstall histogram to use.
45 const int kNumIgnoredBuckets = 5;
46
47 } // namespace
48
49 // OutdatedUpgradeBubbleView ---------------------------------------------------
50
51 OutdatedUpgradeBubbleView* OutdatedUpgradeBubbleView::upgrade_bubble_ = NULL;
52 int OutdatedUpgradeBubbleView::num_ignored_bubbles_ = 0;
53
54 // static
55 void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view,
56 content::PageNavigator* navigator) {
57 if (IsShowing())
58 return;
59 upgrade_bubble_ = new OutdatedUpgradeBubbleView(anchor_view, navigator);
60 views::BubbleDelegateView::CreateBubble(upgrade_bubble_);
61 upgrade_bubble_->StartFade(true);
62 }
63
64 bool OutdatedUpgradeBubbleView::IsAvailable() {
65 // This should only work on non-Chrome OS desktop platforms.
66 #if defined(OS_WIN) || defined(OS_MACOSX) || \
67 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
68 return true;
69 #else
70 return false;
71 #endif
72 }
73
74 OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() {
75 if (!chose_to_reinstall_ && num_ignored_bubbles_ < kMaxIgnored)
76 ++num_ignored_bubbles_;
77 }
78
79 views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() {
80 return reinstall_button_;
81 }
82
83 void OutdatedUpgradeBubbleView::WindowClosing() {
84 // Reset |upgrade_bubble_| here, not in destructor, because destruction is
85 // asynchronous and ShowBubble may be called before full destruction and
86 // would attempt to show a bubble that is closing.
87 DCHECK_EQ(upgrade_bubble_, this);
88 upgrade_bubble_ = NULL;
89 }
90
91 void OutdatedUpgradeBubbleView::Init() {
92 string16 product_name(l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
93 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
94 reinstall_button_ = new views::NativeTextButton(
95 this, l10n_util::GetStringFUTF16(IDS_REINSTALL_APP, product_name));
96 reinstall_button_->SetIsDefault(true);
97 reinstall_button_->SetFont(rb.GetFont(ui::ResourceBundle::BoldFont));
98
99 later_button_ = new views::NativeTextButton(
100 this, l10n_util::GetStringUTF16(IDS_LATER));
101
102 views::Label* title_label = new views::Label(
103 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TITLE, product_name));
104 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
105 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
106
107 views::Label* text_label = new views::Label(
108 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TEXT, product_name));
109 text_label->SetMultiLine(true);
110 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
111
112 views::ImageView* image_view = new views::ImageView();
113 image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU3));
114
115 GridLayout* layout = new GridLayout(this);
116 SetLayoutManager(layout);
117
118 const int kIconTitleColumnSetId = 0;
119 views::ColumnSet* cs = layout->AddColumnSet(kIconTitleColumnSetId);
120
121 // Top (icon-title) row.
122 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
123 GridLayout::USE_PREF, 0, 0);
124 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
125 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
126 GridLayout::USE_PREF, 0, 0);
127 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
128
129 // Middle (text) row.
130 const int kTextColumnSetId = 1;
131 cs = layout->AddColumnSet(kTextColumnSetId);
132 cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
133 GridLayout::FIXED, kWidthOfDescriptionText, 0);
134
135 // Bottom (buttons) row.
136 const int kButtonsColumnSetId = 2;
137 cs = layout->AddColumnSet(kButtonsColumnSetId);
138 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
139 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
140 GridLayout::USE_PREF, 0, 0);
141 cs->AddPaddingColumn(0, kButtonPadding);
142 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
143 GridLayout::USE_PREF, 0, 0);
144
145 layout->StartRow(0, kIconTitleColumnSetId);
146 layout->AddView(image_view);
147 layout->AddView(title_label);
148
149 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
150 layout->StartRow(0, kTextColumnSetId);
151 layout->AddView(text_label);
152
153 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
154
155 layout->StartRow(0, kButtonsColumnSetId);
156 layout->AddView(reinstall_button_);
157 layout->AddView(later_button_);
158
159 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
160 }
161
162 OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView(
163 views::View* anchor_view, content::PageNavigator* navigator)
164 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
165 chose_to_reinstall_(false),
166 reinstall_button_(NULL),
167 later_button_(NULL),
168 navigator_(navigator) {
169 // Compensate for built-in vertical padding in the anchor view's image.
170 set_anchor_insets(gfx::Insets(5, 0, 5, 0));
171 }
172
173 void OutdatedUpgradeBubbleView::ButtonPressed(
174 views::Button* sender, const ui::Event& event) {
175 if (event.IsMouseEvent() &&
176 !(static_cast<const ui::MouseEvent*>(&event))->IsOnlyLeftMouseButton()) {
177 return;
178 }
179 HandleButtonPressed(sender);
180 }
181
182 void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) {
183 if (sender == reinstall_button_) {
184 DCHECK(UpgradeDetector::GetInstance()->is_outdated_install());
185 chose_to_reinstall_ = true;
186 UMA_HISTOGRAM_CUSTOM_COUNTS(
187 "OutdatedUpgradeBubble.NumLaterPerReinstall", num_ignored_bubbles_,
188 0, kMaxIgnored, kNumIgnoredBuckets);
189 content::RecordAction(
190 content::UserMetricsAction("OutdatedUpgradeBubble.Reinstall"));
191 navigator_->OpenURL(content::OpenURLParams(GURL(kDownloadChromeUrl),
192 content::Referrer(),
193 NEW_FOREGROUND_TAB,
194 content::PAGE_TRANSITION_LINK,
195 false));
196 } else {
197 DCHECK_EQ(later_button_, sender);
198 content::RecordAction(
199 content::UserMetricsAction("OutdatedUpgradeBubble.Later"));
200 }
201 StartFade(false);
202 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/outdated_upgrade_bubble_view.h ('k') | chrome/browser/ui/views/toolbar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698