| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/desktop_capture/win/desktop.h" | 11 #include "webrtc/modules/desktop_capture/win/desktop.h" |
| 12 | 12 |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "webrtc/system_wrappers/include/logging.h" | 15 #include "webrtc/system_wrappers/include/logging.h" |
| 16 | 16 |
| 17 namespace webrtc { | 17 namespace webrtc { |
| 18 | 18 |
| 19 Desktop::Desktop(HDESK desktop, bool own) : desktop_(desktop), own_(own) { | 19 Desktop::Desktop(HDESK desktop, bool own) : desktop_(desktop), own_(own) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 Desktop::~Desktop() { | 22 Desktop::~Desktop() { |
| 23 if (own_ && desktop_ != NULL) { | 23 if (own_ && desktop_ != nullptr) { |
| 24 if (!::CloseDesktop(desktop_)) { | 24 if (!::CloseDesktop(desktop_)) { |
| 25 LOG(LS_ERROR) << "Failed to close the owned desktop handle: " | 25 LOG(LS_ERROR) << "Failed to close the owned desktop handle: " |
| 26 << GetLastError(); | 26 << GetLastError(); |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 | 30 |
| 31 bool Desktop::GetName(std::wstring* desktop_name_out) const { | 31 bool Desktop::GetName(std::wstring* desktop_name_out) const { |
| 32 if (desktop_ == NULL) | 32 if (desktop_ == nullptr) |
| 33 return false; | 33 return false; |
| 34 | 34 |
| 35 DWORD length = 0; | 35 DWORD length = 0; |
| 36 int rv = GetUserObjectInformationW(desktop_, UOI_NAME, NULL, 0, &length); | 36 int rv = GetUserObjectInformationW(desktop_, UOI_NAME, nullptr, 0, &length); |
| 37 if (rv || GetLastError() != ERROR_INSUFFICIENT_BUFFER) | 37 if (rv || GetLastError() != ERROR_INSUFFICIENT_BUFFER) |
| 38 abort(); | 38 abort(); |
| 39 | 39 |
| 40 length /= sizeof(WCHAR); | 40 length /= sizeof(WCHAR); |
| 41 std::vector<WCHAR> buffer(length); | 41 std::vector<WCHAR> buffer(length); |
| 42 if (!GetUserObjectInformationW(desktop_, UOI_NAME, &buffer[0], | 42 if (!GetUserObjectInformationW(desktop_, UOI_NAME, &buffer[0], |
| 43 length * sizeof(WCHAR), &length)) { | 43 length * sizeof(WCHAR), &length)) { |
| 44 LOG(LS_ERROR) << "Failed to query the desktop name: " << GetLastError(); | 44 LOG(LS_ERROR) << "Failed to query the desktop name: " << GetLastError(); |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 70 | 70 |
| 71 return true; | 71 return true; |
| 72 } | 72 } |
| 73 | 73 |
| 74 Desktop* Desktop::GetDesktop(const WCHAR* desktop_name) { | 74 Desktop* Desktop::GetDesktop(const WCHAR* desktop_name) { |
| 75 ACCESS_MASK desired_access = | 75 ACCESS_MASK desired_access = |
| 76 DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW | DESKTOP_ENUMERATE | | 76 DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW | DESKTOP_ENUMERATE | |
| 77 DESKTOP_HOOKCONTROL | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS | | 77 DESKTOP_HOOKCONTROL | DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS | |
| 78 DESKTOP_SWITCHDESKTOP | GENERIC_WRITE; | 78 DESKTOP_SWITCHDESKTOP | GENERIC_WRITE; |
| 79 HDESK desktop = OpenDesktop(desktop_name, 0, FALSE, desired_access); | 79 HDESK desktop = OpenDesktop(desktop_name, 0, FALSE, desired_access); |
| 80 if (desktop == NULL) { | 80 if (desktop == nullptr) { |
| 81 LOG(LS_ERROR) << "Failed to open the desktop '" << desktop_name << "': " | 81 LOG(LS_ERROR) << "Failed to open the desktop '" << desktop_name << "': " |
| 82 << GetLastError(); | 82 << GetLastError(); |
| 83 return NULL; | 83 return nullptr; |
| 84 } | 84 } |
| 85 | 85 |
| 86 return new Desktop(desktop, true); | 86 return new Desktop(desktop, true); |
| 87 } | 87 } |
| 88 | 88 |
| 89 Desktop* Desktop::GetInputDesktop() { | 89 Desktop* Desktop::GetInputDesktop() { |
| 90 HDESK desktop = OpenInputDesktop( | 90 HDESK desktop = OpenInputDesktop( |
| 91 0, FALSE, GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE); | 91 0, FALSE, GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE); |
| 92 if (desktop == NULL) | 92 if (desktop == nullptr) |
| 93 return NULL; | 93 return nullptr; |
| 94 | 94 |
| 95 return new Desktop(desktop, true); | 95 return new Desktop(desktop, true); |
| 96 } | 96 } |
| 97 | 97 |
| 98 Desktop* Desktop::GetThreadDesktop() { | 98 Desktop* Desktop::GetThreadDesktop() { |
| 99 HDESK desktop = ::GetThreadDesktop(GetCurrentThreadId()); | 99 HDESK desktop = ::GetThreadDesktop(GetCurrentThreadId()); |
| 100 if (desktop == NULL) { | 100 if (desktop == nullptr) { |
| 101 LOG(LS_ERROR) << "Failed to retrieve the handle of the desktop assigned to " | 101 LOG(LS_ERROR) << "Failed to retrieve the handle of the desktop assigned to " |
| 102 "the current thread: " | 102 "the current thread: " |
| 103 << GetLastError(); | 103 << GetLastError(); |
| 104 return NULL; | 104 return nullptr; |
| 105 } | 105 } |
| 106 | 106 |
| 107 return new Desktop(desktop, false); | 107 return new Desktop(desktop, false); |
| 108 } | 108 } |
| 109 | 109 |
| 110 } // namespace webrtc | 110 } // namespace webrtc |
| OLD | NEW |