diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-05-09 14:22:11 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2016-05-09 15:11:45 +0000 |
commit | 2ddb2d3e14eef3de7dbd0cef553d669b9ac2361c (patch) | |
tree | e75f511546c5fd1a173e87c1f9fb11d7ac8d1af3 /chromium/base/win/win_util.cc | |
parent | a4f3d46271c57e8155ba912df46a05559d14726e (diff) |
BASELINE: Update Chromium to 51.0.2704.41
Also adds in all smaller components by reversing logic for exclusion.
Change-Id: Ibf90b506e7da088ea2f65dcf23f2b0992c504422
Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'chromium/base/win/win_util.cc')
-rw-r--r-- | chromium/base/win/win_util.cc | 89 |
1 files changed, 63 insertions, 26 deletions
diff --git a/chromium/base/win/win_util.cc b/chromium/base/win/win_util.cc index 85612a247dd..4e18d40601e 100644 --- a/chromium/base/win/win_util.cc +++ b/chromium/base/win/win_util.cc @@ -22,17 +22,20 @@ #include <signal.h> #include <stddef.h> #include <stdlib.h> +#include <tchar.h> // Must be before tpcshrd.h or for any use of _T macro +#include <tpcshrd.h> #include <uiviewsettingsinterop.h> #include <windows.ui.viewmanagement.h> #include <winstring.h> #include <wrl/wrappers/corewrappers.h> +#include <memory> + #include "base/base_switches.h" #include "base/command_line.h" #include "base/lazy_instance.h" #include "base/logging.h" #include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" @@ -114,12 +117,14 @@ POWER_PLATFORM_ROLE GetPlatformRole() { return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2); } +} // namespace + // Uses the Windows 10 WRL API's to query the current system state. The API's // we are using in the function below are supported in Win32 apps as per msdn. // It looks like the API implementation is buggy at least on Surface 4 causing // it to always return UserInteractionMode_Touch which as per documentation // indicates tablet mode. -bool IsWindows10TabletDevice() { +bool IsWindows10TabletMode(HWND hwnd) { if (GetVersion() < VERSION_WIN10) return false; @@ -178,7 +183,7 @@ bool IsWindows10TabletDevice() { // Avoid using GetForegroundWindow here and pass in the HWND of the window // intiating the request to display the keyboard. hr = view_settings_interop->GetForWindow( - ::GetForegroundWindow(), + hwnd, __uuidof(ABI::Windows::UI::ViewManagement::IUIViewSettings), view_settings.ReceiveVoid()); if (FAILED(hr)) @@ -190,8 +195,6 @@ bool IsWindows10TabletDevice() { return mode == ABI::Windows::UI::ViewManagement::UserInteractionMode_Touch; } -} // namespace - // Returns true if a physical keyboard is detected on Windows 8 and up. // Uses the Setup APIs to enumerate the attached keyboards and returns true // if the keyboard count is 1 or more.. While this will work in most cases @@ -347,7 +350,7 @@ bool GetUserSidString(std::wstring* user_sid) { ScopedHandle token_scoped(token); DWORD size = sizeof(TOKEN_USER) + SECURITY_MAX_SID_SIZE; - scoped_ptr<BYTE[]> user_bytes(new BYTE[size]); + std::unique_ptr<BYTE[]> user_bytes(new BYTE[size]); TOKEN_USER* user = reinterpret_cast<TOKEN_USER*>(user_bytes.get()); if (!::GetTokenInformation(token, TokenUser, user, size, &size)) @@ -475,7 +478,7 @@ bool IsTabletDevice(std::string* reason) { return false; } - if (IsWindows10TabletDevice()) + if (IsWindows10TabletMode(::GetForegroundWindow())) return true; if (GetSystemMetrics(SM_MAXIMUMTOUCHES) == 0) { @@ -573,7 +576,7 @@ bool DisplayVirtualKeyboard() { // We then replace the %CommonProgramFiles% value with the actual common // files path found in the process. string16 common_program_files_path; - scoped_ptr<wchar_t[]> common_program_files_wow6432; + std::unique_ptr<wchar_t[]> common_program_files_wow6432; DWORD buffer_size = GetEnvironmentVariable(L"CommonProgramW6432", NULL, 0); if (buffer_size) { @@ -645,29 +648,63 @@ void SetDomainStateForTesting(bool state) { g_domain_state = state ? ENROLLED : NOT_ENROLLED; } -bool MaybeHasSHA256Support() { - const OSInfo* os_info = OSInfo::GetInstance(); - - if (os_info->version() == VERSION_PRE_XP) - return false; // Too old to have it and this OS is not supported anyway. +bool IsUser32AndGdi32Available() { + static base::LazyInstance<LazyIsUser32AndGdi32Available>::Leaky available = + LAZY_INSTANCE_INITIALIZER; + return available.Get().value(); +} - if (os_info->version() == VERSION_XP) - return os_info->service_pack().major >= 3; // Windows XP SP3 has it. +bool GetLoadedModulesSnapshot(HANDLE process, std::vector<HMODULE>* snapshot) { + DCHECK(snapshot); + DCHECK_EQ(0u, snapshot->size()); + snapshot->resize(128); + + // We will retry at least once after first determining |bytes_required|. If + // the list of modules changes after we receive |bytes_required| we may retry + // more than once. + int retries_remaining = 5; + do { + DWORD bytes_required = 0; + // EnumProcessModules returns 'success' even if the buffer size is too + // small. + DCHECK_GE(std::numeric_limits<DWORD>::max(), + snapshot->size() * sizeof(HMODULE)); + if (!::EnumProcessModules( + process, &(*snapshot)[0], + static_cast<DWORD>(snapshot->size() * sizeof(HMODULE)), + &bytes_required)) { + DPLOG(ERROR) << "::EnumProcessModules failed."; + return false; + } + DCHECK_EQ(0u, bytes_required % sizeof(HMODULE)); + size_t num_modules = bytes_required / sizeof(HMODULE); + if (num_modules <= snapshot->size()) { + // Buffer size was too big, presumably because a module was unloaded. + snapshot->erase(snapshot->begin() + num_modules, snapshot->end()); + return true; + } else if (num_modules == 0) { + DLOG(ERROR) << "Can't determine the module list size."; + return false; + } else { + // Buffer size was too small. Try again with a larger buffer. A little + // more room is given to avoid multiple expensive calls to + // ::EnumProcessModules() just because one module has been added. + snapshot->resize(num_modules + 8, NULL); + } + } while (--retries_remaining); - // Assume it is missing in this case, although it may not be. This category - // includes Windows XP x64, and Windows Server, where a hotfix could be - // deployed. - if (os_info->version() == VERSION_SERVER_2003) - return false; + DLOG(ERROR) << "Failed to enumerate modules."; + return false; +} - DCHECK(os_info->version() >= VERSION_VISTA); - return true; // New enough to have SHA-256 support. +void EnableFlicks(HWND hwnd) { + ::RemoveProp(hwnd, MICROSOFT_TABLETPENSERVICE_PROPERTY); } -bool IsUser32AndGdi32Available() { - static base::LazyInstance<LazyIsUser32AndGdi32Available>::Leaky available = - LAZY_INSTANCE_INITIALIZER; - return available.Get().value(); +void DisableFlicks(HWND hwnd) { + ::SetProp(hwnd, MICROSOFT_TABLETPENSERVICE_PROPERTY, + reinterpret_cast<HANDLE>(TABLET_DISABLE_FLICKS | + TABLET_DISABLE_FLICKFALLBACKKEYS)); } } // namespace win |