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> |
(...skipping 11 matching lines...) Expand all Loading... |
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" |
39 #include "base/strings/string_util.h" | 37 #include "base/strings/string_util.h" |
40 #include "base/strings/stringprintf.h" | 38 #include "base/strings/stringprintf.h" |
41 #include "base/strings/utf_string_conversions.h" | 39 #include "base/strings/utf_string_conversions.h" |
42 #include "base/threading/thread_restrictions.h" | 40 #include "base/threading/thread_restrictions.h" |
43 #include "base/win/registry.h" | 41 #include "base/win/registry.h" |
44 #include "base/win/scoped_co_mem.h" | |
45 #include "base/win/scoped_comptr.h" | 42 #include "base/win/scoped_comptr.h" |
46 #include "base/win/scoped_handle.h" | 43 #include "base/win/scoped_handle.h" |
47 #include "base/win/scoped_propvariant.h" | 44 #include "base/win/scoped_propvariant.h" |
48 #include "base/win/windows_version.h" | 45 #include "base/win/windows_version.h" |
49 | 46 |
50 namespace base { | 47 namespace base { |
51 namespace win { | 48 namespace win { |
52 | 49 |
53 namespace { | 50 namespace { |
54 | 51 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 97 } |
101 | 98 |
102 return false; | 99 return false; |
103 } | 100 } |
104 | 101 |
105 const bool value_; | 102 const bool value_; |
106 | 103 |
107 DISALLOW_COPY_AND_ASSIGN(LazyIsUser32AndGdi32Available); | 104 DISALLOW_COPY_AND_ASSIGN(LazyIsUser32AndGdi32Available); |
108 }; | 105 }; |
109 | 106 |
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 | 107 // Returns the current platform role. We use the PowerDeterminePlatformRoleEx |
115 // API for that. | 108 // API for that. |
116 POWER_PLATFORM_ROLE GetPlatformRole() { | 109 POWER_PLATFORM_ROLE GetPlatformRole() { |
117 return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2); | 110 return PowerDeterminePlatformRoleEx(POWER_PLATFORM_ROLE_V2); |
118 } | 111 } |
119 | 112 |
120 } // namespace | 113 } // namespace |
121 | 114 |
122 // Uses the Windows 10 WRL API's to query the current system state. The API's | 115 // 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. | 116 // 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"; | 511 "PlatformRoleSlate\n"; |
519 } | 512 } |
520 } | 513 } |
521 } else { | 514 } else { |
522 if (reason) | 515 if (reason) |
523 *reason += "Device role is not mobile or slate.\n"; | 516 *reason += "Device role is not mobile or slate.\n"; |
524 } | 517 } |
525 return is_tablet; | 518 return is_tablet; |
526 } | 519 } |
527 | 520 |
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}; | 521 enum DomainEnrollementState {UNKNOWN = -1, NOT_ENROLLED, ENROLLED}; |
625 static volatile long int g_domain_state = UNKNOWN; | 522 static volatile long int g_domain_state = UNKNOWN; |
626 | 523 |
627 bool IsEnrolledToDomain() { | 524 bool IsEnrolledToDomain() { |
628 // Doesn't make any sense to retry inside a user session because joining a | 525 // Doesn't make any sense to retry inside a user session because joining a |
629 // domain will only kick in on a restart. | 526 // domain will only kick in on a restart. |
630 if (g_domain_state == UNKNOWN) { | 527 if (g_domain_state == UNKNOWN) { |
631 LPWSTR domain; | 528 LPWSTR domain; |
632 NETSETUP_JOIN_STATUS join_status; | 529 NETSETUP_JOIN_STATUS join_status; |
633 if(::NetGetJoinInformation(NULL, &domain, &join_status) != NERR_Success) | 530 if(::NetGetJoinInformation(NULL, &domain, &join_status) != NERR_Success) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 } | 597 } |
701 | 598 |
702 void DisableFlicks(HWND hwnd) { | 599 void DisableFlicks(HWND hwnd) { |
703 ::SetProp(hwnd, MICROSOFT_TABLETPENSERVICE_PROPERTY, | 600 ::SetProp(hwnd, MICROSOFT_TABLETPENSERVICE_PROPERTY, |
704 reinterpret_cast<HANDLE>(TABLET_DISABLE_FLICKS | | 601 reinterpret_cast<HANDLE>(TABLET_DISABLE_FLICKS | |
705 TABLET_DISABLE_FLICKFALLBACKKEYS)); | 602 TABLET_DISABLE_FLICKFALLBACKKEYS)); |
706 } | 603 } |
707 | 604 |
708 } // namespace win | 605 } // namespace win |
709 } // namespace base | 606 } // namespace base |
OLD | NEW |