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

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

Issue 211543008: Show a modified outdated upgrade Bubble for non-enterprise users without auto-update (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Shot in the dark to try and prevent Mac crashes... Created 6 years, 8 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" 5 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h"
6 6
7 #if defined(OS_WIN)
8 #include <shellapi.h>
9 #endif
10
7 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/path_service.h"
13 #include "base/prefs/pref_service.h"
14 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/upgrade_detector.h" 15 #include "chrome/browser/upgrade_detector.h"
16 #include "chrome/common/pref_names.h"
9 #include "content/public/browser/page_navigator.h" 17 #include "content/public/browser/page_navigator.h"
10 #include "content/public/browser/user_metrics.h" 18 #include "content/public/browser/user_metrics.h"
11 #include "grit/chromium_strings.h" 19 #include "grit/chromium_strings.h"
12 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
13 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/views/controls/button/label_button.h" 24 #include "ui/views/controls/button/label_button.h"
17 #include "ui/views/controls/image_view.h" 25 #include "ui/views/controls/image_view.h"
18 #include "ui/views/controls/label.h" 26 #include "ui/views/controls/label.h"
19 #include "ui/views/layout/grid_layout.h" 27 #include "ui/views/layout/grid_layout.h"
20 #include "ui/views/layout/layout_constants.h" 28 #include "ui/views/layout/layout_constants.h"
21 #include "ui/views/widget/widget.h" 29 #include "ui/views/widget/widget.h"
22 #include "url/gurl.h" 30 #include "url/gurl.h"
23 31
32 #if defined(OS_WIN)
33 #include "base/win/win_util.h"
34 #include "base/win/windows_version.h"
35 #include "chrome/installer/util/install_util.h"
36 #include "ui/gfx/icon_util.h"
37 #endif
38
24 using views::GridLayout; 39 using views::GridLayout;
25 40
26 namespace { 41 namespace {
27 42
28 // Fixed width of the column holding the description label of the bubble. 43 // Fixed width of the column holding the description label of the bubble.
29 // TODO(mad): Make sure there is enough room for all languages. 44 // TODO(mad): Make sure there is enough room for all languages.
30 const int kWidthOfDescriptionText = 330; 45 const int kWidthOfDescriptionText = 330;
31 46
32 // We subtract 2 to account for the natural button padding, and 47 // We subtract 2 to account for the natural button padding, and
33 // to bring the separation visually in line with the row separation 48 // to bring the separation visually in line with the row separation
34 // height. 49 // height.
35 const int kButtonPadding = views::kRelatedButtonHSpacing - 2; 50 const int kButtonPadding = views::kRelatedButtonHSpacing - 2;
36 51
37 // The URL to be used to re-install Chrome when auto-update failed for too long. 52 // 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" 53 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"; 54 "&utm_campaign=en&utm_source=en-et-na-us-chrome-bubble&utm_medium=et";
40 55
41 // The maximum number of ignored bubble we track in the NumLaterPerReinstall 56 // The maximum number of ignored bubble we track in the NumLaterPerReinstall
42 // histogram. 57 // histogram.
43 const int kMaxIgnored = 50; 58 const int kMaxIgnored = 50;
44 // The number of buckets we want the NumLaterPerReinstall histogram to use. 59 // The number of buckets we want the NumLaterPerReinstall histogram to use.
45 const int kNumIgnoredBuckets = 5; 60 const int kNumIgnoredBuckets = 5;
46 61
62 // Adds an elevation icon to |button| when running a system level install.
63 void AddElevationIconIfNeeded(views::LabelButton* button) {
64 #if defined(OS_WIN)
65 if ((base::win::GetVersion() >= base::win::VERSION_VISTA) &&
66 base::win::UserAccountControlIsEnabled()) {
67 base::FilePath exe_path;
68 PathService::Get(base::FILE_EXE, &exe_path);
69 if (InstallUtil::IsPerUserInstall(exe_path.value().c_str()))
70 return;
71
72 // This code was lifted from chrome/browser/ui/views/infobars/infobar_view.
73 // TODO(mad): Investigate the possibility of moving it to a common place.
74 SHSTOCKICONINFO icon_info = { sizeof(SHSTOCKICONINFO) };
75 // Even with the runtime guard above, we have to use GetProcAddress() here,
76 // because otherwise the loader will try to resolve the function address on
77 // startup, which will break on XP.
78 typedef HRESULT (STDAPICALLTYPE *GetStockIconInfo)(SHSTOCKICONID, UINT,
79 SHSTOCKICONINFO*);
80 GetStockIconInfo func = reinterpret_cast<GetStockIconInfo>(
81 GetProcAddress(GetModuleHandle(L"shell32.dll"), "SHGetStockIconInfo"));
82 if (SUCCEEDED((*func)(SIID_SHIELD, SHGSI_ICON | SHGSI_SMALLICON,
83 &icon_info))) {
84 scoped_ptr<SkBitmap> icon(IconUtil::CreateSkBitmapFromHICON(
85 icon_info.hIcon, gfx::Size(GetSystemMetrics(SM_CXSMICON),
86 GetSystemMetrics(SM_CYSMICON))));
87 if (icon.get()) {
88 button->SetImage(views::Button::STATE_NORMAL,
89 gfx::ImageSkia::CreateFrom1xBitmap(*icon));
90 }
91 DestroyIcon(icon_info.hIcon);
92 }
93 }
94 #endif
95 }
96
47 } // namespace 97 } // namespace
48 98
49 // OutdatedUpgradeBubbleView --------------------------------------------------- 99 // OutdatedUpgradeBubbleView ---------------------------------------------------
50 100
51 OutdatedUpgradeBubbleView* OutdatedUpgradeBubbleView::upgrade_bubble_ = NULL; 101 OutdatedUpgradeBubbleView* OutdatedUpgradeBubbleView::upgrade_bubble_ = NULL;
52 int OutdatedUpgradeBubbleView::num_ignored_bubbles_ = 0; 102 int OutdatedUpgradeBubbleView::num_ignored_bubbles_ = 0;
53 103
54 // static 104 // static
55 void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view, 105 void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view,
56 content::PageNavigator* navigator) { 106 content::PageNavigator* navigator,
107 bool auto_update_enabled) {
57 if (IsShowing()) 108 if (IsShowing())
58 return; 109 return;
59 upgrade_bubble_ = new OutdatedUpgradeBubbleView(anchor_view, navigator); 110 upgrade_bubble_ = new OutdatedUpgradeBubbleView(
111 anchor_view, navigator, auto_update_enabled);
60 views::BubbleDelegateView::CreateBubble(upgrade_bubble_)->Show(); 112 views::BubbleDelegateView::CreateBubble(upgrade_bubble_)->Show();
61 content::RecordAction( 113 content::RecordAction(base::UserMetricsAction(
62 base::UserMetricsAction("OutdatedUpgradeBubble.Show")); 114 auto_update_enabled ? "OutdatedUpgradeBubble.Show"
115 : "OutdatedUpgradeBubble.ShowNoAU"));
63 } 116 }
64 117
65 bool OutdatedUpgradeBubbleView::IsAvailable() { 118 bool OutdatedUpgradeBubbleView::IsAvailable() {
66 // This should only work on non-Chrome OS desktop platforms. 119 // This should only work on non-Chrome OS desktop platforms.
67 #if defined(OS_WIN) || defined(OS_MACOSX) || \ 120 #if defined(OS_WIN) || defined(OS_MACOSX) || \
68 (defined(OS_LINUX) && !defined(OS_CHROMEOS)) 121 (defined(OS_LINUX) && !defined(OS_CHROMEOS))
69 return true; 122 return true;
70 #else 123 #else
71 return false; 124 return false;
72 #endif 125 #endif
73 } 126 }
74 127
75 OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() { 128 OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() {
76 if (!chose_to_reinstall_ && num_ignored_bubbles_ < kMaxIgnored) 129 if (!accepted_ && num_ignored_bubbles_ < kMaxIgnored)
77 ++num_ignored_bubbles_; 130 ++num_ignored_bubbles_;
78 } 131 }
79 132
80 views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() { 133 views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() {
81 return reinstall_button_; 134 return accept_button_;
82 } 135 }
83 136
84 void OutdatedUpgradeBubbleView::WindowClosing() { 137 void OutdatedUpgradeBubbleView::WindowClosing() {
85 // Reset |upgrade_bubble_| here, not in destructor, because destruction is 138 // Reset |upgrade_bubble_| here, not in destructor, because destruction is
86 // asynchronous and ShowBubble may be called before full destruction and 139 // asynchronous and ShowBubble may be called before full destruction and
87 // would attempt to show a bubble that is closing. 140 // would attempt to show a bubble that is closing.
88 DCHECK_EQ(upgrade_bubble_, this); 141 DCHECK_EQ(upgrade_bubble_, this);
89 upgrade_bubble_ = NULL; 142 upgrade_bubble_ = NULL;
90 } 143 }
91 144
92 void OutdatedUpgradeBubbleView::Init() { 145 void OutdatedUpgradeBubbleView::Init() {
93 base::string16 product_name(
94 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
95 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 146 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
96 reinstall_button_ = new views::LabelButton( 147 accept_button_ = new views::LabelButton(
97 this, l10n_util::GetStringFUTF16(IDS_REINSTALL_APP, product_name)); 148 this, l10n_util::GetStringUTF16(
98 reinstall_button_->SetStyle(views::Button::STYLE_BUTTON); 149 auto_update_enabled_ ? IDS_REINSTALL_APP : IDS_REENABLE_UPDATES));
99 reinstall_button_->SetIsDefault(true); 150 accept_button_->SetStyle(views::Button::STYLE_BUTTON);
100 reinstall_button_->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont)); 151 accept_button_->SetIsDefault(true);
152 accept_button_->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont));
153 AddElevationIconIfNeeded(accept_button_);
101 154
102 later_button_ = new views::LabelButton( 155 later_button_ = new views::LabelButton(
103 this, l10n_util::GetStringUTF16(IDS_LATER)); 156 this, l10n_util::GetStringUTF16(IDS_LATER));
104 later_button_->SetStyle(views::Button::STYLE_BUTTON); 157 later_button_->SetStyle(views::Button::STYLE_BUTTON);
105 158
106 views::Label* title_label = new views::Label( 159 views::Label* title_label = new views::Label(
107 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TITLE, product_name)); 160 l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_TITLE));
108 title_label->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); 161 title_label->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont));
109 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 162 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
110 163
111 views::Label* text_label = new views::Label( 164 views::Label* text_label = new views::Label(l10n_util::GetStringUTF16(
112 l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TEXT, product_name)); 165 auto_update_enabled_ ? IDS_UPGRADE_BUBBLE_TEXT
166 : IDS_UPGRADE_BUBBLE_REENABLE_TEXT));
113 text_label->SetMultiLine(true); 167 text_label->SetMultiLine(true);
114 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 168 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
115 169
116 views::ImageView* image_view = new views::ImageView(); 170 views::ImageView* image_view = new views::ImageView();
117 image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU_SEVERITY_HIGH)); 171 image_view->SetImage(rb.GetImageSkiaNamed(IDR_UPDATE_MENU_SEVERITY_HIGH));
118 172
119 GridLayout* layout = new GridLayout(this); 173 GridLayout* layout = new GridLayout(this);
120 SetLayoutManager(layout); 174 SetLayoutManager(layout);
121 175
122 const int kIconTitleColumnSetId = 0; 176 const int kIconTitleColumnSetId = 0;
(...skipping 27 matching lines...) Expand all
150 layout->AddView(image_view); 204 layout->AddView(image_view);
151 layout->AddView(title_label); 205 layout->AddView(title_label);
152 206
153 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); 207 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
154 layout->StartRow(0, kTextColumnSetId); 208 layout->StartRow(0, kTextColumnSetId);
155 layout->AddView(text_label); 209 layout->AddView(text_label);
156 210
157 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); 211 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing);
158 212
159 layout->StartRow(0, kButtonsColumnSetId); 213 layout->StartRow(0, kButtonsColumnSetId);
160 layout->AddView(reinstall_button_); 214 layout->AddView(accept_button_);
161 layout->AddView(later_button_); 215 layout->AddView(later_button_);
162 216
163 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); 217 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE));
164 } 218 }
165 219
166 OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView( 220 OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView(
167 views::View* anchor_view, content::PageNavigator* navigator) 221 views::View* anchor_view,
222 content::PageNavigator* navigator,
223 bool auto_update_enabled)
168 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 224 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
169 chose_to_reinstall_(false), 225 auto_update_enabled_(auto_update_enabled),
170 reinstall_button_(NULL), 226 accepted_(false),
227 accept_button_(NULL),
171 later_button_(NULL), 228 later_button_(NULL),
172 navigator_(navigator) { 229 navigator_(navigator) {
173 // Compensate for built-in vertical padding in the anchor view's image. 230 // Compensate for built-in vertical padding in the anchor view's image.
174 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); 231 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
175 } 232 }
176 233
177 void OutdatedUpgradeBubbleView::ButtonPressed( 234 void OutdatedUpgradeBubbleView::ButtonPressed(
178 views::Button* sender, const ui::Event& event) { 235 views::Button* sender, const ui::Event& event) {
179 if (event.IsMouseEvent() && 236 if (event.IsMouseEvent() &&
180 !(static_cast<const ui::MouseEvent*>(&event))->IsOnlyLeftMouseButton()) { 237 !(static_cast<const ui::MouseEvent*>(&event))->IsOnlyLeftMouseButton()) {
181 return; 238 return;
182 } 239 }
183 HandleButtonPressed(sender); 240 HandleButtonPressed(sender);
184 } 241 }
185 242
186 void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) { 243 void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) {
187 if (sender == reinstall_button_) { 244 if (sender == accept_button_) {
188 DCHECK(UpgradeDetector::GetInstance()->is_outdated_install()); 245 accepted_ = true;
189 chose_to_reinstall_ = true; 246 if (auto_update_enabled_) {
190 UMA_HISTOGRAM_CUSTOM_COUNTS( 247 DCHECK(UpgradeDetector::GetInstance()->is_outdated_install());
191 "OutdatedUpgradeBubble.NumLaterPerReinstall", num_ignored_bubbles_, 248 UMA_HISTOGRAM_CUSTOM_COUNTS(
192 0, kMaxIgnored, kNumIgnoredBuckets); 249 "OutdatedUpgradeBubble.NumLaterPerReinstall", num_ignored_bubbles_,
193 content::RecordAction( 250 0, kMaxIgnored, kNumIgnoredBuckets);
194 base::UserMetricsAction("OutdatedUpgradeBubble.Reinstall")); 251 content::RecordAction(
195 navigator_->OpenURL(content::OpenURLParams(GURL(kDownloadChromeUrl), 252 base::UserMetricsAction("OutdatedUpgradeBubble.Reinstall"));
196 content::Referrer(), 253 navigator_->OpenURL(content::OpenURLParams(GURL(kDownloadChromeUrl),
197 NEW_FOREGROUND_TAB, 254 content::Referrer(),
198 content::PAGE_TRANSITION_LINK, 255 NEW_FOREGROUND_TAB,
199 false)); 256 content::PAGE_TRANSITION_LINK,
257 false));
258 } else {
259 DCHECK(UpgradeDetector::GetInstance()->is_outdated_install_no_au());
260 UMA_HISTOGRAM_CUSTOM_COUNTS(
261 "OutdatedUpgradeBubble.NumLaterPerEnableAU", num_ignored_bubbles_,
262 0, kMaxIgnored, kNumIgnoredBuckets);
263 content::RecordAction(
264 base::UserMetricsAction("OutdatedUpgradeBubble.EnableAU"));
265 // TODO(robertshield): Make a call to GoogleUpdateSettings to enable
266 // auto-update.
267 if (g_browser_process->local_state()) {
268 g_browser_process->local_state()->SetBoolean(
269 prefs::kAttemptedToEnableAutoupdate, true);
270 }
271 }
200 } else { 272 } else {
201 DCHECK_EQ(later_button_, sender); 273 DCHECK_EQ(later_button_, sender);
202 content::RecordAction( 274 content::RecordAction(
203 base::UserMetricsAction("OutdatedUpgradeBubble.Later")); 275 base::UserMetricsAction("OutdatedUpgradeBubble.Later"));
204 } 276 }
205 GetWidget()->Close(); 277 GetWidget()->Close();
206 } 278 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/outdated_upgrade_bubble_view.h ('k') | chrome/browser/ui/views/toolbar/toolbar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698