| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "sandbox/win/src/window.h" | 5 #include "sandbox/win/src/window.h" |
| 6 | 6 |
| 7 #include <aclapi.h> | 7 #include <aclapi.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 *winsta = ::CreateWindowStationW(NULL, 0, WINSTA_ALL_ACCESS, &attributes); | 46 *winsta = ::CreateWindowStationW(NULL, 0, WINSTA_ALL_ACCESS, &attributes); |
| 47 LocalFree(attributes.lpSecurityDescriptor); | 47 LocalFree(attributes.lpSecurityDescriptor); |
| 48 | 48 |
| 49 if (*winsta) | 49 if (*winsta) |
| 50 return SBOX_ALL_OK; | 50 return SBOX_ALL_OK; |
| 51 | 51 |
| 52 return SBOX_ERROR_CANNOT_CREATE_WINSTATION; | 52 return SBOX_ERROR_CANNOT_CREATE_WINSTATION; |
| 53 } | 53 } |
| 54 | 54 |
| 55 ResultCode CreateAltDesktop(HWINSTA winsta, HDESK* desktop) { | 55 ResultCode CreateAltDesktop(HWINSTA winsta, HDESK* desktop) { |
| 56 std::wstring desktop_name = L"sbox_alternate_desktop_"; | 56 base::string16 desktop_name = L"sbox_alternate_desktop_"; |
| 57 | 57 |
| 58 // Append the current PID to the desktop name. | 58 // Append the current PID to the desktop name. |
| 59 wchar_t buffer[16]; | 59 wchar_t buffer[16]; |
| 60 _snwprintf_s(buffer, sizeof(buffer) / sizeof(wchar_t), L"0x%X", | 60 _snwprintf_s(buffer, sizeof(buffer) / sizeof(wchar_t), L"0x%X", |
| 61 ::GetCurrentProcessId()); | 61 ::GetCurrentProcessId()); |
| 62 desktop_name += buffer; | 62 desktop_name += buffer; |
| 63 | 63 |
| 64 // Get the security attributes from the current desktop, we will use this as | 64 // Get the security attributes from the current desktop, we will use this as |
| 65 // the base security attributes for the new desktop. | 65 // the base security attributes for the new desktop. |
| 66 SECURITY_ATTRIBUTES attributes = {0}; | 66 SECURITY_ATTRIBUTES attributes = {0}; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 93 return SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION; | 93 return SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 if (*desktop) | 97 if (*desktop) |
| 98 return SBOX_ALL_OK; | 98 return SBOX_ALL_OK; |
| 99 | 99 |
| 100 return SBOX_ERROR_CANNOT_CREATE_DESKTOP; | 100 return SBOX_ERROR_CANNOT_CREATE_DESKTOP; |
| 101 } | 101 } |
| 102 | 102 |
| 103 std::wstring GetWindowObjectName(HANDLE handle) { | 103 base::string16 GetWindowObjectName(HANDLE handle) { |
| 104 // Get the size of the name. | 104 // Get the size of the name. |
| 105 DWORD size = 0; | 105 DWORD size = 0; |
| 106 ::GetUserObjectInformation(handle, UOI_NAME, NULL, 0, &size); | 106 ::GetUserObjectInformation(handle, UOI_NAME, NULL, 0, &size); |
| 107 | 107 |
| 108 if (!size) { | 108 if (!size) { |
| 109 NOTREACHED(); | 109 NOTREACHED(); |
| 110 return std::wstring(); | 110 return base::string16(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 // Create the buffer that will hold the name. | 113 // Create the buffer that will hold the name. |
| 114 scoped_ptr<wchar_t[]> name_buffer(new wchar_t[size]); | 114 scoped_ptr<wchar_t[]> name_buffer(new wchar_t[size]); |
| 115 | 115 |
| 116 // Query the name of the object. | 116 // Query the name of the object. |
| 117 if (!::GetUserObjectInformation(handle, UOI_NAME, name_buffer.get(), size, | 117 if (!::GetUserObjectInformation(handle, UOI_NAME, name_buffer.get(), size, |
| 118 &size)) { | 118 &size)) { |
| 119 NOTREACHED(); | 119 NOTREACHED(); |
| 120 return std::wstring(); | 120 return base::string16(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 return std::wstring(name_buffer.get()); | 123 return base::string16(name_buffer.get()); |
| 124 } | 124 } |
| 125 | 125 |
| 126 std::wstring GetFullDesktopName(HWINSTA winsta, HDESK desktop) { | 126 base::string16 GetFullDesktopName(HWINSTA winsta, HDESK desktop) { |
| 127 if (!desktop) { | 127 if (!desktop) { |
| 128 NOTREACHED(); | 128 NOTREACHED(); |
| 129 return std::wstring(); | 129 return base::string16(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 std::wstring name; | 132 base::string16 name; |
| 133 if (winsta) { | 133 if (winsta) { |
| 134 name = GetWindowObjectName(winsta); | 134 name = GetWindowObjectName(winsta); |
| 135 name += L'\\'; | 135 name += L'\\'; |
| 136 } | 136 } |
| 137 | 137 |
| 138 name += GetWindowObjectName(desktop); | 138 name += GetWindowObjectName(desktop); |
| 139 return name; | 139 return name; |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // namespace sandbox | 142 } // namespace sandbox |
| OLD | NEW |