Revert "Only store leading 13 bits of password hash."
[chromium-blink-merge.git] / chrome / browser / ui / views / elevation_icon_setter.cc
blobccffcbe689cba7373154f52e96654470267f9b5a
1 // Copyright 2014 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.
5 #include "chrome/browser/ui/views/elevation_icon_setter.h"
7 #include "base/task_runner_util.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "ui/views/controls/button/label_button.h"
11 #if defined(OS_WIN)
12 #include <windows.h>
13 #include <shellapi.h>
14 #include "base/win/win_util.h"
15 #include "base/win/windows_version.h"
16 #include "ui/gfx/icon_util.h"
17 #include "ui/gfx/win/dpi.h"
18 #endif
21 // Helpers --------------------------------------------------------------------
23 namespace {
25 scoped_ptr<SkBitmap> GetElevationIcon() {
26 scoped_ptr<SkBitmap> icon;
27 #if defined(OS_WIN)
28 if ((base::win::GetVersion() < base::win::VERSION_VISTA) ||
29 !base::win::UserAccountControlIsEnabled())
30 return icon.Pass();
32 SHSTOCKICONINFO icon_info = { sizeof(SHSTOCKICONINFO) };
33 typedef HRESULT (STDAPICALLTYPE *GetStockIconInfo)(SHSTOCKICONID,
34 UINT,
35 SHSTOCKICONINFO*);
36 // Even with the runtime guard above, we have to use GetProcAddress()
37 // here, because otherwise the loader will try to resolve the function
38 // address on startup, which will break on XP.
39 GetStockIconInfo func = reinterpret_cast<GetStockIconInfo>(
40 GetProcAddress(GetModuleHandle(L"shell32.dll"), "SHGetStockIconInfo"));
41 // TODO(pkasting): Run on a background thread since this call spins a nested
42 // message loop.
43 if (FAILED((*func)(SIID_SHIELD, SHGSI_ICON | SHGSI_SMALLICON, &icon_info)))
44 return icon.Pass();
46 icon.reset(IconUtil::CreateSkBitmapFromHICON(
47 icon_info.hIcon,
48 gfx::Size(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON))));
49 DestroyIcon(icon_info.hIcon);
50 #endif
51 return icon.Pass();
54 } // namespace
57 // ElevationIconSetter --------------------------------------------------------
59 ElevationIconSetter::ElevationIconSetter(views::LabelButton* button)
60 : button_(button),
61 weak_factory_(this) {
62 base::PostTaskAndReplyWithResult(
63 content::BrowserThread::GetBlockingPool(),
64 FROM_HERE,
65 base::Bind(&GetElevationIcon),
66 base::Bind(&ElevationIconSetter::SetButtonIcon,
67 weak_factory_.GetWeakPtr()));
70 ElevationIconSetter::~ElevationIconSetter() {
73 void ElevationIconSetter::SetButtonIcon(scoped_ptr<SkBitmap> icon) {
74 if (icon) {
75 float device_scale_factor = 1.0f;
76 #if defined(OS_WIN)
77 // Windows gives us back a correctly-scaled image for the current DPI, so
78 // mark this image as having been scaled for the current DPI already.
79 device_scale_factor = gfx::GetDPIScale();
80 #endif
81 button_->SetImage(
82 views::Button::STATE_NORMAL,
83 gfx::ImageSkia(gfx::ImageSkiaRep(*icon, device_scale_factor)));
84 button_->SizeToPreferredSize();
85 if (button_->parent())
86 button_->parent()->Layout();