ipc/chromium/src/base/win_util.cc

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
michael@0 2 // Use of this source code is governed by a BSD-style license that can be
michael@0 3 // found in the LICENSE file.
michael@0 4
michael@0 5 #include "base/win_util.h"
michael@0 6
michael@0 7 #include <map>
michael@0 8 #include <sddl.h>
michael@0 9
michael@0 10 #include "base/logging.h"
michael@0 11 #include "base/registry.h"
michael@0 12 #include "base/scoped_handle.h"
michael@0 13 #include "base/scoped_ptr.h"
michael@0 14 #include "base/singleton.h"
michael@0 15 #include "base/string_util.h"
michael@0 16 #include "base/tracked.h"
michael@0 17
michael@0 18 namespace win_util {
michael@0 19
michael@0 20 WinVersion GetWinVersion() {
michael@0 21 static bool checked_version = false;
michael@0 22 static WinVersion win_version = WINVERSION_PRE_2000;
michael@0 23 if (!checked_version) {
michael@0 24 OSVERSIONINFOEX version_info;
michael@0 25 version_info.dwOSVersionInfoSize = sizeof version_info;
michael@0 26 GetVersionEx(reinterpret_cast<OSVERSIONINFO*>(&version_info));
michael@0 27 if (version_info.dwMajorVersion == 5) {
michael@0 28 switch (version_info.dwMinorVersion) {
michael@0 29 case 0:
michael@0 30 win_version = WINVERSION_2000;
michael@0 31 break;
michael@0 32 case 1:
michael@0 33 win_version = WINVERSION_XP;
michael@0 34 break;
michael@0 35 case 2:
michael@0 36 default:
michael@0 37 win_version = WINVERSION_SERVER_2003;
michael@0 38 break;
michael@0 39 }
michael@0 40 } else if (version_info.dwMajorVersion == 6) {
michael@0 41 if (version_info.wProductType != VER_NT_WORKSTATION) {
michael@0 42 // 2008 is 6.0, and 2008 R2 is 6.1.
michael@0 43 win_version = WINVERSION_2008;
michael@0 44 } else {
michael@0 45 if (version_info.dwMinorVersion == 0) {
michael@0 46 win_version = WINVERSION_VISTA;
michael@0 47 } else {
michael@0 48 win_version = WINVERSION_WIN7;
michael@0 49 }
michael@0 50 }
michael@0 51 } else if (version_info.dwMajorVersion > 6) {
michael@0 52 win_version = WINVERSION_WIN7;
michael@0 53 }
michael@0 54 checked_version = true;
michael@0 55 }
michael@0 56 return win_version;
michael@0 57 }
michael@0 58
michael@0 59 bool IsShiftPressed() {
michael@0 60 return (::GetKeyState(VK_SHIFT) & 0x80) == 0x80;
michael@0 61 }
michael@0 62
michael@0 63 bool IsCtrlPressed() {
michael@0 64 return (::GetKeyState(VK_CONTROL) & 0x80) == 0x80;
michael@0 65 }
michael@0 66
michael@0 67 bool IsAltPressed() {
michael@0 68 return (::GetKeyState(VK_MENU) & 0x80) == 0x80;
michael@0 69 }
michael@0 70
michael@0 71 std::wstring FormatMessage(unsigned messageid) {
michael@0 72 wchar_t* string_buffer = NULL;
michael@0 73 unsigned string_length = ::FormatMessage(
michael@0 74 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
michael@0 75 FORMAT_MESSAGE_IGNORE_INSERTS, NULL, messageid, 0,
michael@0 76 reinterpret_cast<wchar_t *>(&string_buffer), 0, NULL);
michael@0 77
michael@0 78 std::wstring formatted_string;
michael@0 79 if (string_buffer) {
michael@0 80 formatted_string = string_buffer;
michael@0 81 LocalFree(reinterpret_cast<HLOCAL>(string_buffer));
michael@0 82 } else {
michael@0 83 // The formating failed. simply convert the message value into a string.
michael@0 84 SStringPrintf(&formatted_string, L"message number %d", messageid);
michael@0 85 }
michael@0 86 return formatted_string;
michael@0 87 }
michael@0 88
michael@0 89 std::wstring FormatLastWin32Error() {
michael@0 90 return FormatMessage(GetLastError());
michael@0 91 }
michael@0 92
michael@0 93 } // namespace win_util
michael@0 94
michael@0 95 #ifdef _MSC_VER
michael@0 96 //
michael@0 97 // If the ASSERT below fails, please install Visual Studio 2005 Service Pack 1.
michael@0 98 //
michael@0 99 extern char VisualStudio2005ServicePack1Detection[10];
michael@0 100 COMPILE_ASSERT(sizeof(&VisualStudio2005ServicePack1Detection) == sizeof(void*),
michael@0 101 VS2005SP1Detect);
michael@0 102 //
michael@0 103 // Chrome requires at least Service Pack 1 for Visual Studio 2005.
michael@0 104 //
michael@0 105 #endif // _MSC_VER
michael@0 106
michael@0 107 #if 0
michael@0 108 #error You must install the Windows 2008 or Vista Software Development Kit and \
michael@0 109 set it as your default include path to build this library. You can grab it by \
michael@0 110 searching for "download windows sdk 2008" in your favorite web search engine. \
michael@0 111 Also make sure you register the SDK with Visual Studio, by selecting \
michael@0 112 "Integrate Windows SDK with Visual Studio 2005" from the Windows SDK \
michael@0 113 menu (see Start - All Programs - Microsoft Windows SDK - \
michael@0 114 Visual Studio Registration).
michael@0 115 #endif

mercurial