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