Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/win/win_util.h" | 5 #include "base/win/win_util.h" |
| 6 | 6 |
| 7 #include <aclapi.h> | 7 #include <aclapi.h> |
| 8 #include <cfgmgr32.h> | 8 #include <cfgmgr32.h> |
| 9 #include <lm.h> | 9 #include <lm.h> |
| 10 #include <powrprof.h> | 10 #include <powrprof.h> |
| 11 #include <shellapi.h> | |
| 12 #include <shlobj.h> | |
| 13 #include <shobjidl.h> // Must be before propkey. | 11 #include <shobjidl.h> // Must be before propkey. |
| 14 #include <initguid.h> | 12 #include <initguid.h> |
| 15 #include <inspectable.h> | 13 #include <inspectable.h> |
| 16 #include <propkey.h> | 14 #include <propkey.h> |
| 17 #include <propvarutil.h> | 15 #include <propvarutil.h> |
| 18 #include <psapi.h> | 16 #include <psapi.h> |
| 19 #include <roapi.h> | 17 #include <roapi.h> |
| 20 #include <sddl.h> | 18 #include <sddl.h> |
| 21 #include <setupapi.h> | 19 #include <setupapi.h> |
| 22 #include <signal.h> | 20 #include <signal.h> |
| 23 #include <stddef.h> | 21 #include <stddef.h> |
| 24 #include <stdlib.h> | 22 #include <stdlib.h> |
| 25 #include <tchar.h> // Must be before tpcshrd.h or for any use of _T macro | 23 #include <tchar.h> // Must be before tpcshrd.h or for any use of _T macro |
| 26 #include <tpcshrd.h> | 24 #include <tpcshrd.h> |
| 27 #include <uiviewsettingsinterop.h> | 25 #include <uiviewsettingsinterop.h> |
| 28 #include <windows.ui.viewmanagement.h> | 26 #include <windows.ui.viewmanagement.h> |
| 29 #include <winstring.h> | 27 #include <winstring.h> |
| 30 #include <wrl/wrappers/corewrappers.h> | 28 #include <wrl/wrappers/corewrappers.h> |
| 31 | 29 |
| 32 #include <memory> | 30 #include <memory> |
| 33 | 31 |
| 34 #include "base/base_switches.h" | 32 #include "base/base_switches.h" |
| 35 #include "base/command_line.h" | 33 #include "base/command_line.h" |
| 36 #include "base/lazy_instance.h" | 34 #include "base/lazy_instance.h" |
| 37 #include "base/logging.h" | 35 #include "base/logging.h" |
| 38 #include "base/macros.h" | 36 #include "base/macros.h" |
| 37 #include "base/memory/singleton.h" | |
|
grt (UTC plus 2)
2016/05/24 18:22:34
unused
ananta
2016/05/24 20:42:39
Done.
| |
| 39 #include "base/strings/string_util.h" | 38 #include "base/strings/string_util.h" |
| 40 #include "base/strings/stringprintf.h" | 39 #include "base/strings/stringprintf.h" |
| 41 #include "base/strings/utf_string_conversions.h" | 40 #include "base/strings/utf_string_conversions.h" |
| 42 #include "base/threading/thread_restrictions.h" | 41 #include "base/threading/thread_restrictions.h" |
| 43 #include "base/win/registry.h" | 42 #include "base/win/registry.h" |
| 44 #include "base/win/scoped_co_mem.h" | |
| 45 #include "base/win/scoped_comptr.h" | 43 #include "base/win/scoped_comptr.h" |
| 46 #include "base/win/scoped_handle.h" | 44 #include "base/win/scoped_handle.h" |
| 47 #include "base/win/scoped_propvariant.h" | 45 #include "base/win/scoped_propvariant.h" |
| 48 #include "base/win/windows_version.h" | 46 #include "base/win/windows_version.h" |
| 49 | 47 |
| 50 namespace base { | 48 namespace base { |
| 51 namespace win { | 49 namespace win { |
| 52 | 50 |
| 53 namespace { | 51 namespace { |
| 54 | 52 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 } | 98 } |
| 101 | 99 |
| 102 return false; | 100 return false; |
| 103 } | 101 } |
| 104 | 102 |
| 105 const bool value_; | 103 const bool value_; |
| 106 | 104 |
| 107 DISALLOW_COPY_AND_ASSIGN(LazyIsUser32AndGdi32Available); | 105 DISALLOW_COPY_AND_ASSIGN(LazyIsUser32AndGdi32Available); |
| 108 }; | 106 }; |
| 109 | 107 |
| 110 const wchar_t kWindows8OSKRegPath[] = | |
| 111 L"Software\\Classes\\CLSID\\{054AAE20-4BEA-4347-8A35-64A533254A9D}" | |
| 112 L"\\LocalServer32"; | |
| 113 | |
| 114 // Returns the current platform role. We use the PowerDeterminePlatformRoleEx | 108 // Returns the current platform role. We use the PowerDeterminePlatformRoleEx |
| 115 // API for that. | 109 // API for that. |
| 116 POWER_PLATFORM_ROLE GetPlatformRole() { | 110 POWER_PLATFORM_ROLE GetPlatformRole() { |
| 117 return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2); | 111 return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2); |
| 118 } | 112 } |
| 119 | 113 |
| 120 } // namespace | 114 } // namespace |
| 121 | 115 |
| 122 // Uses the Windows 10 WRL API's to query the current system state. The API's | 116 // Uses the Windows 10 WRL API's to query the current system state. The API's |
| 123 // we are using in the function below are supported in Win32 apps as per msdn. | 117 // we are using in the function below are supported in Win32 apps as per msdn. |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 518 "PlatformRoleSlate\n"; | 512 "PlatformRoleSlate\n"; |
| 519 } | 513 } |
| 520 } | 514 } |
| 521 } else { | 515 } else { |
| 522 if (reason) | 516 if (reason) |
| 523 *reason += "Device role is not mobile or slate.\n"; | 517 *reason += "Device role is not mobile or slate.\n"; |
| 524 } | 518 } |
| 525 return is_tablet; | 519 return is_tablet; |
| 526 } | 520 } |
| 527 | 521 |
| 528 bool DisplayVirtualKeyboard() { | |
| 529 if (GetVersion() < VERSION_WIN8) | |
| 530 return false; | |
| 531 | |
| 532 if (IsKeyboardPresentOnSlate(nullptr)) | |
| 533 return false; | |
| 534 | |
| 535 static LazyInstance<string16>::Leaky osk_path = LAZY_INSTANCE_INITIALIZER; | |
| 536 | |
| 537 if (osk_path.Get().empty()) { | |
| 538 // We need to launch TabTip.exe from the location specified under the | |
| 539 // LocalServer32 key for the {{054AAE20-4BEA-4347-8A35-64A533254A9D}} | |
| 540 // CLSID. | |
| 541 // TabTip.exe is typically found at | |
| 542 // c:\program files\common files\microsoft shared\ink on English Windows. | |
| 543 // We don't want to launch TabTip.exe from | |
| 544 // c:\program files (x86)\common files\microsoft shared\ink. This path is | |
| 545 // normally found on 64 bit Windows. | |
| 546 RegKey key(HKEY_LOCAL_MACHINE, kWindows8OSKRegPath, | |
| 547 KEY_READ | KEY_WOW64_64KEY); | |
| 548 DWORD osk_path_length = 1024; | |
| 549 if (key.ReadValue(NULL, | |
| 550 WriteInto(&osk_path.Get(), osk_path_length), | |
| 551 &osk_path_length, | |
| 552 NULL) != ERROR_SUCCESS) { | |
| 553 DLOG(WARNING) << "Failed to read on screen keyboard path from registry"; | |
| 554 return false; | |
| 555 } | |
| 556 size_t common_program_files_offset = | |
| 557 osk_path.Get().find(L"%CommonProgramFiles%"); | |
| 558 // Typically the path to TabTip.exe read from the registry will start with | |
| 559 // %CommonProgramFiles% which needs to be replaced with the corrsponding | |
| 560 // expanded string. | |
| 561 // If the path does not begin with %CommonProgramFiles% we use it as is. | |
| 562 if (common_program_files_offset != string16::npos) { | |
| 563 // Preserve the beginning quote in the path. | |
| 564 osk_path.Get().erase(common_program_files_offset, | |
| 565 wcslen(L"%CommonProgramFiles%")); | |
| 566 // The path read from the registry contains the %CommonProgramFiles% | |
| 567 // environment variable prefix. On 64 bit Windows the SHGetKnownFolderPath | |
| 568 // function returns the common program files path with the X86 suffix for | |
| 569 // the FOLDERID_ProgramFilesCommon value. | |
| 570 // To get the correct path to TabTip.exe we first read the environment | |
| 571 // variable CommonProgramW6432 which points to the desired common | |
| 572 // files path. Failing that we fallback to the SHGetKnownFolderPath API. | |
| 573 | |
| 574 // We then replace the %CommonProgramFiles% value with the actual common | |
| 575 // files path found in the process. | |
| 576 string16 common_program_files_path; | |
| 577 std::unique_ptr<wchar_t[]> common_program_files_wow6432; | |
| 578 DWORD buffer_size = | |
| 579 GetEnvironmentVariable(L"CommonProgramW6432", NULL, 0); | |
| 580 if (buffer_size) { | |
| 581 common_program_files_wow6432.reset(new wchar_t[buffer_size]); | |
| 582 GetEnvironmentVariable(L"CommonProgramW6432", | |
| 583 common_program_files_wow6432.get(), | |
| 584 buffer_size); | |
| 585 common_program_files_path = common_program_files_wow6432.get(); | |
| 586 DCHECK(!common_program_files_path.empty()); | |
| 587 } else { | |
| 588 ScopedCoMem<wchar_t> common_program_files; | |
| 589 if (FAILED(SHGetKnownFolderPath(FOLDERID_ProgramFilesCommon, 0, NULL, | |
| 590 &common_program_files))) { | |
| 591 return false; | |
| 592 } | |
| 593 common_program_files_path = common_program_files; | |
| 594 } | |
| 595 | |
| 596 osk_path.Get().insert(1, common_program_files_path); | |
| 597 } | |
| 598 } | |
| 599 | |
| 600 HINSTANCE ret = ::ShellExecuteW(NULL, | |
| 601 L"", | |
| 602 osk_path.Get().c_str(), | |
| 603 NULL, | |
| 604 NULL, | |
| 605 SW_SHOW); | |
| 606 return reinterpret_cast<intptr_t>(ret) > 32; | |
| 607 } | |
| 608 | |
| 609 bool DismissVirtualKeyboard() { | |
| 610 if (GetVersion() < VERSION_WIN8) | |
| 611 return false; | |
| 612 | |
| 613 // We dismiss the virtual keyboard by generating the ESC keystroke | |
| 614 // programmatically. | |
| 615 const wchar_t kOSKClassName[] = L"IPTip_Main_Window"; | |
| 616 HWND osk = ::FindWindow(kOSKClassName, NULL); | |
| 617 if (::IsWindow(osk) && ::IsWindowEnabled(osk)) { | |
| 618 PostMessage(osk, WM_SYSCOMMAND, SC_CLOSE, 0); | |
| 619 return true; | |
| 620 } | |
| 621 return false; | |
| 622 } | |
| 623 | |
| 624 enum DomainEnrollementState {UNKNOWN = -1, NOT_ENROLLED, ENROLLED}; | 522 enum DomainEnrollementState {UNKNOWN = -1, NOT_ENROLLED, ENROLLED}; |
| 625 static volatile long int g_domain_state = UNKNOWN; | 523 static volatile long int g_domain_state = UNKNOWN; |
| 626 | 524 |
| 627 bool IsEnrolledToDomain() { | 525 bool IsEnrolledToDomain() { |
| 628 // Doesn't make any sense to retry inside a user session because joining a | 526 // Doesn't make any sense to retry inside a user session because joining a |
| 629 // domain will only kick in on a restart. | 527 // domain will only kick in on a restart. |
| 630 if (g_domain_state == UNKNOWN) { | 528 if (g_domain_state == UNKNOWN) { |
| 631 LPWSTR domain; | 529 LPWSTR domain; |
| 632 NETSETUP_JOIN_STATUS join_status; | 530 NETSETUP_JOIN_STATUS join_status; |
| 633 if(::NetGetJoinInformation(NULL, &domain, &join_status) != NERR_Success) | 531 if(::NetGetJoinInformation(NULL, &domain, &join_status) != NERR_Success) |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 700 } | 598 } |
| 701 | 599 |
| 702 void DisableFlicks(HWND hwnd) { | 600 void DisableFlicks(HWND hwnd) { |
| 703 ::SetProp(hwnd, MICROSOFT_TABLETPENSERVICE_PROPERTY, | 601 ::SetProp(hwnd, MICROSOFT_TABLETPENSERVICE_PROPERTY, |
| 704 reinterpret_cast<HANDLE>(TABLET_DISABLE_FLICKS | | 602 reinterpret_cast<HANDLE>(TABLET_DISABLE_FLICKS | |
| 705 TABLET_DISABLE_FLICKFALLBACKKEYS)); | 603 TABLET_DISABLE_FLICKFALLBACKKEYS)); |
| 706 } | 604 } |
| 707 | 605 |
| 708 } // namespace win | 606 } // namespace win |
| 709 } // namespace base | 607 } // namespace base |
| OLD | NEW |