Chromium Code Reviews| Index: chrome/browser/ui/views/outdated_upgrade_bubble_view.cc |
| diff --git a/chrome/browser/ui/views/outdated_upgrade_bubble_view.cc b/chrome/browser/ui/views/outdated_upgrade_bubble_view.cc |
| index 5c741b9040d4f3f6eea2abf3f81a77bb92cd88d5..0f90c34aa7971f46f7db8320fea20cfae8fa93b1 100644 |
| --- a/chrome/browser/ui/views/outdated_upgrade_bubble_view.cc |
| +++ b/chrome/browser/ui/views/outdated_upgrade_bubble_view.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/metrics/histogram.h" |
| #include "chrome/browser/upgrade_detector.h" |
| +#include "chrome/installer/util/install_util.h" |
| #include "content/public/browser/page_navigator.h" |
| #include "content/public/browser/user_metrics.h" |
| #include "grit/chromium_strings.h" |
| @@ -21,6 +22,12 @@ |
| #include "ui/views/widget/widget.h" |
| #include "url/gurl.h" |
| +#if defined(OS_WIN) |
| +#include "base/win/win_util.h" |
| +#include "base/win/windows_version.h" |
| +#include "ui/gfx/icon_util.h" |
| +#endif |
| + |
| using views::GridLayout; |
| namespace { |
| @@ -44,6 +51,41 @@ const int kMaxIgnored = 50; |
| // The number of buckets we want the NumLaterPerReinstall histogram to use. |
| const int kNumIgnoredBuckets = 5; |
| +// Adds an elevation icon to |button| when running a system level install. |
| +void AddElevationIconIfNeeded(views::LabelButton* button) { |
| +#if defined(OS_WIN) |
| + if ((base::win::GetVersion() >= base::win::VERSION_VISTA) && |
| + base::win::UserAccountControlIsEnabled()) { |
| + wchar_t exe_path[MAX_PATH * 2] = {}; |
| + 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.
|
| + if (InstallUtil::IsPerUserInstall(exe_path)) |
| + return; |
| + |
| + // This code was lifted from chrome/browser/ui/views/infobars/infobar_view. |
| + // TODO(mad): Investigate the possibility of moving it to a common place. |
| + SHSTOCKICONINFO icon_info = { sizeof(SHSTOCKICONINFO) }; |
| + // Even with the runtime guard above, we have to use GetProcAddress() here, |
| + // because otherwise the loader will try to resolve the function address on |
| + // startup, which will break on XP. |
| + typedef HRESULT (STDAPICALLTYPE *GetStockIconInfo)(SHSTOCKICONID, UINT, |
| + SHSTOCKICONINFO*); |
| + GetStockIconInfo func = reinterpret_cast<GetStockIconInfo>( |
| + GetProcAddress(GetModuleHandle(L"shell32.dll"), "SHGetStockIconInfo")); |
| + if (SUCCEEDED((*func)(SIID_SHIELD, SHGSI_ICON | SHGSI_SMALLICON, |
| + &icon_info))) { |
| + scoped_ptr<SkBitmap> icon(IconUtil::CreateSkBitmapFromHICON( |
| + icon_info.hIcon, gfx::Size(GetSystemMetrics(SM_CXSMICON), |
| + GetSystemMetrics(SM_CYSMICON)))); |
| + if (icon.get()) { |
| + button->SetImage(views::Button::STATE_NORMAL, |
| + gfx::ImageSkia::CreateFrom1xBitmap(*icon)); |
| + } |
| + DestroyIcon(icon_info.hIcon); |
| + } |
| + } |
| +#endif |
| +} |
| + |
| } // namespace |
| // OutdatedUpgradeBubbleView --------------------------------------------------- |
| @@ -53,13 +95,16 @@ int OutdatedUpgradeBubbleView::num_ignored_bubbles_ = 0; |
| // static |
| void OutdatedUpgradeBubbleView::ShowBubble(views::View* anchor_view, |
| - content::PageNavigator* navigator) { |
| + content::PageNavigator* navigator, |
| + bool auto_update_on) { |
| if (IsShowing()) |
| return; |
| - upgrade_bubble_ = new OutdatedUpgradeBubbleView(anchor_view, navigator); |
| + upgrade_bubble_ = new OutdatedUpgradeBubbleView( |
| + anchor_view, navigator, auto_update_on); |
| views::BubbleDelegateView::CreateBubble(upgrade_bubble_)->Show(); |
| - content::RecordAction( |
| - base::UserMetricsAction("OutdatedUpgradeBubble.Show")); |
| + content::RecordAction(base::UserMetricsAction( |
| + auto_update_on ? "OutdatedUpgradeBubble.Show" |
| + : "OutdatedUpgradeBubble.ShowNoAU")); |
| } |
| bool OutdatedUpgradeBubbleView::IsAvailable() { |
| @@ -73,12 +118,12 @@ bool OutdatedUpgradeBubbleView::IsAvailable() { |
| } |
| OutdatedUpgradeBubbleView::~OutdatedUpgradeBubbleView() { |
| - if (!chose_to_reinstall_ && num_ignored_bubbles_ < kMaxIgnored) |
| + if (!accepted_ && num_ignored_bubbles_ < kMaxIgnored) |
| ++num_ignored_bubbles_; |
| } |
| views::View* OutdatedUpgradeBubbleView::GetInitiallyFocusedView() { |
| - return reinstall_button_; |
| + return accept_button_; |
| } |
| void OutdatedUpgradeBubbleView::WindowClosing() { |
| @@ -90,26 +135,27 @@ void OutdatedUpgradeBubbleView::WindowClosing() { |
| } |
| void OutdatedUpgradeBubbleView::Init() { |
| - base::string16 product_name( |
| - l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); |
| ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| - reinstall_button_ = new views::LabelButton( |
| - this, l10n_util::GetStringFUTF16(IDS_REINSTALL_APP, product_name)); |
| - reinstall_button_->SetStyle(views::Button::STYLE_BUTTON); |
| - reinstall_button_->SetIsDefault(true); |
| - reinstall_button_->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont)); |
| + accept_button_ = new views::LabelButton( |
| + this, l10n_util::GetStringUTF16( |
| + auto_update_on_ ? IDS_REINSTALL_APP : IDS_REENABLE_UPDATES)); |
| + accept_button_->SetStyle(views::Button::STYLE_BUTTON); |
| + accept_button_->SetIsDefault(true); |
| + accept_button_->SetFontList(rb.GetFontList(ui::ResourceBundle::BoldFont)); |
| + AddElevationIconIfNeeded(accept_button_); |
| later_button_ = new views::LabelButton( |
| this, l10n_util::GetStringUTF16(IDS_LATER)); |
| later_button_->SetStyle(views::Button::STYLE_BUTTON); |
| views::Label* title_label = new views::Label( |
| - l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TITLE, product_name)); |
| + l10n_util::GetStringUTF16(IDS_UPGRADE_BUBBLE_TITLE)); |
| title_label->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); |
| title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| - views::Label* text_label = new views::Label( |
| - l10n_util::GetStringFUTF16(IDS_UPGRADE_BUBBLE_TEXT, product_name)); |
| + views::Label* text_label = new views::Label(l10n_util::GetStringUTF16( |
| + auto_update_on_ ? IDS_UPGRADE_BUBBLE_TEXT : |
| + IDS_UPGRADE_BUBBLE_REENABLE_TEXT)); |
| text_label->SetMultiLine(true); |
| text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| @@ -157,17 +203,20 @@ void OutdatedUpgradeBubbleView::Init() { |
| layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| layout->StartRow(0, kButtonsColumnSetId); |
| - layout->AddView(reinstall_button_); |
| + layout->AddView(accept_button_); |
| layout->AddView(later_button_); |
| AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
| } |
| OutdatedUpgradeBubbleView::OutdatedUpgradeBubbleView( |
| - views::View* anchor_view, content::PageNavigator* navigator) |
| + views::View* anchor_view, |
| + content::PageNavigator* navigator, |
| + bool auto_update_on) |
| : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| - chose_to_reinstall_(false), |
| - reinstall_button_(NULL), |
| + auto_update_on_(auto_update_on), |
| + accepted_(false), |
| + accept_button_(NULL), |
| later_button_(NULL), |
| navigator_(navigator) { |
| // Compensate for built-in vertical padding in the anchor view's image. |
| @@ -184,19 +233,30 @@ void OutdatedUpgradeBubbleView::ButtonPressed( |
| } |
| void OutdatedUpgradeBubbleView::HandleButtonPressed(views::Button* sender) { |
| - if (sender == reinstall_button_) { |
| - DCHECK(UpgradeDetector::GetInstance()->is_outdated_install()); |
| - chose_to_reinstall_ = true; |
| - UMA_HISTOGRAM_CUSTOM_COUNTS( |
| - "OutdatedUpgradeBubble.NumLaterPerReinstall", num_ignored_bubbles_, |
| - 0, kMaxIgnored, kNumIgnoredBuckets); |
| - content::RecordAction( |
| - base::UserMetricsAction("OutdatedUpgradeBubble.Reinstall")); |
| - navigator_->OpenURL(content::OpenURLParams(GURL(kDownloadChromeUrl), |
| - content::Referrer(), |
| - NEW_FOREGROUND_TAB, |
| - content::PAGE_TRANSITION_LINK, |
| - false)); |
| + if (sender == accept_button_) { |
| + accepted_ = true; |
| + if (auto_update_on_) { |
| + DCHECK(UpgradeDetector::GetInstance()->is_outdated_install()); |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
| + "OutdatedUpgradeBubble.NumLaterPerReinstall", num_ignored_bubbles_, |
| + 0, kMaxIgnored, kNumIgnoredBuckets); |
| + content::RecordAction( |
| + base::UserMetricsAction("OutdatedUpgradeBubble.Reinstall")); |
| + navigator_->OpenURL(content::OpenURLParams(GURL(kDownloadChromeUrl), |
| + content::Referrer(), |
| + NEW_FOREGROUND_TAB, |
| + content::PAGE_TRANSITION_LINK, |
| + false)); |
| + } else { |
| + DCHECK(UpgradeDetector::GetInstance()->is_outdated_install_no_au()); |
| + UMA_HISTOGRAM_CUSTOM_COUNTS( |
| + "OutdatedUpgradeBubble.NumLaterPerEnableAU", num_ignored_bubbles_, |
| + 0, kMaxIgnored, kNumIgnoredBuckets); |
| + content::RecordAction( |
| + base::UserMetricsAction("OutdatedUpgradeBubble.EnableAU")); |
| + // TODO(robertshield): Make a call to GoogleUpdateSettings to enable |
| + // 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.
|
| + } |
| } else { |
| DCHECK_EQ(later_button_, sender); |
| content::RecordAction( |