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