OLD | NEW |
1 // Copyright (c) 2010 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 "chrome_frame/test/chrome_frame_test_utils.h" | 5 #include "chrome_frame/test/chrome_frame_test_utils.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlwin.h> | 8 #include <atlwin.h> |
9 #include <iepmapi.h> | 9 #include <iepmapi.h> |
10 #include <sddl.h> | 10 #include <sddl.h> |
11 | 11 |
12 #include "app/clipboard/clipboard.h" | 12 #include "app/clipboard/clipboard.h" |
13 #include "app/clipboard/scoped_clipboard_writer.h" | 13 #include "app/clipboard/scoped_clipboard_writer.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
16 #include "base/file_version_info.h" | 16 #include "base/file_version_info.h" |
17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
18 #include "base/process_util.h" | 18 #include "base/process_util.h" |
19 #include "base/scoped_handle.h" | |
20 #include "base/scoped_ptr.h" | 19 #include "base/scoped_ptr.h" |
21 #include "base/string_util.h" | 20 #include "base/string_util.h" |
22 #include "base/stringprintf.h" | 21 #include "base/stringprintf.h" |
23 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
24 #include "base/win/registry.h" | 23 #include "base/win/registry.h" |
| 24 #include "base/win/scoped_handle.h" |
25 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" |
26 #include "ceee/ie/common/ceee_util.h" | 26 #include "ceee/ie/common/ceee_util.h" |
27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
28 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
29 #include "chrome/common/chrome_paths_internal.h" | 29 #include "chrome/common/chrome_paths_internal.h" |
30 #include "chrome_frame/utils.h" | 30 #include "chrome_frame/utils.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
33 namespace chrome_frame_test { | 33 namespace chrome_frame_test { |
34 | 34 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // windows on all threads of the process. | 88 // windows on all threads of the process. |
89 // The return value is the number of visible windows a close request was | 89 // The return value is the number of visible windows a close request was |
90 // sent to. | 90 // sent to. |
91 int CloseVisibleWindowsOnAllThreads(HANDLE process) { | 91 int CloseVisibleWindowsOnAllThreads(HANDLE process) { |
92 DWORD process_id = ::GetProcessId(process); | 92 DWORD process_id = ::GetProcessId(process); |
93 if (process_id == 0) { | 93 if (process_id == 0) { |
94 NOTREACHED(); | 94 NOTREACHED(); |
95 return 0; | 95 return 0; |
96 } | 96 } |
97 | 97 |
98 ScopedHandle snapshot(CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0)); | 98 base::win::ScopedHandle snapshot( |
| 99 CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0)); |
99 if (!snapshot.IsValid()) { | 100 if (!snapshot.IsValid()) { |
100 NOTREACHED(); | 101 NOTREACHED(); |
101 return 0; | 102 return 0; |
102 } | 103 } |
103 | 104 |
104 int window_close_attempts = 0; | 105 int window_close_attempts = 0; |
105 THREADENTRY32 te = { sizeof(THREADENTRY32) }; | 106 THREADENTRY32 te = { sizeof(THREADENTRY32) }; |
106 if (Thread32First(snapshot, &te)) { | 107 if (Thread32First(snapshot, &te)) { |
107 do { | 108 do { |
108 if (RTL_CONTAINS_FIELD(&te, te.dwSize, th32OwnerProcessID) && | 109 if (RTL_CONTAINS_FIELD(&te, te.dwSize, th32OwnerProcessID) && |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 DCHECK(!impersonated_); | 303 DCHECK(!impersonated_); |
303 DCHECK(!IsImpersonated()); | 304 DCHECK(!IsImpersonated()); |
304 HANDLE process_token_handle = NULL; | 305 HANDLE process_token_handle = NULL; |
305 BOOL ok = ::OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE, | 306 BOOL ok = ::OpenProcessToken(GetCurrentProcess(), TOKEN_DUPLICATE, |
306 &process_token_handle); | 307 &process_token_handle); |
307 if (!ok) { | 308 if (!ok) { |
308 DLOG(ERROR) << "::OpenProcessToken failed: " << GetLastError(); | 309 DLOG(ERROR) << "::OpenProcessToken failed: " << GetLastError(); |
309 return ok; | 310 return ok; |
310 } | 311 } |
311 | 312 |
312 ScopedHandle process_token(process_token_handle); | 313 base::win::ScopedHandle process_token(process_token_handle); |
313 // Create impersonation low integrity token. | 314 // Create impersonation low integrity token. |
314 HANDLE impersonation_token_handle = NULL; | 315 HANDLE impersonation_token_handle = NULL; |
315 ok = ::DuplicateTokenEx(process_token, | 316 ok = ::DuplicateTokenEx(process_token, |
316 TOKEN_QUERY | TOKEN_IMPERSONATE | TOKEN_ADJUST_DEFAULT, NULL, | 317 TOKEN_QUERY | TOKEN_IMPERSONATE | TOKEN_ADJUST_DEFAULT, NULL, |
317 SecurityImpersonation, TokenImpersonation, &impersonation_token_handle); | 318 SecurityImpersonation, TokenImpersonation, &impersonation_token_handle); |
318 if (!ok) { | 319 if (!ok) { |
319 DLOG(ERROR) << "::DuplicateTokenEx failed: " << GetLastError(); | 320 DLOG(ERROR) << "::DuplicateTokenEx failed: " << GetLastError(); |
320 return ok; | 321 return ok; |
321 } | 322 } |
322 | 323 |
323 // TODO(stoyan): sandbox/src/restricted_token_utils.cc has | 324 // TODO(stoyan): sandbox/src/restricted_token_utils.cc has |
324 // SetTokenIntegrityLevel function already. | 325 // SetTokenIntegrityLevel function already. |
325 ScopedHandle impersonation_token(impersonation_token_handle); | 326 base::win::ScopedHandle impersonation_token(impersonation_token_handle); |
326 PSID integrity_sid = NULL; | 327 PSID integrity_sid = NULL; |
327 TOKEN_MANDATORY_LABEL tml = {0}; | 328 TOKEN_MANDATORY_LABEL tml = {0}; |
328 ok = ::ConvertStringSidToSid(SDDL_ML_LOW, &integrity_sid); | 329 ok = ::ConvertStringSidToSid(SDDL_ML_LOW, &integrity_sid); |
329 if (!ok) { | 330 if (!ok) { |
330 DLOG(ERROR) << "::ConvertStringSidToSid failed: " << GetLastError(); | 331 DLOG(ERROR) << "::ConvertStringSidToSid failed: " << GetLastError(); |
331 return ok; | 332 return ok; |
332 } | 333 } |
333 | 334 |
334 tml.Label.Attributes = SE_GROUP_INTEGRITY | SE_GROUP_INTEGRITY_ENABLED; | 335 tml.Label.Attributes = SE_GROUP_INTEGRITY | SE_GROUP_INTEGRITY_ENABLED; |
335 tml.Label.Sid = integrity_sid; | 336 tml.Label.Sid = integrity_sid; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 DLOG_IF(ERROR, closed != 0) << "Closed " << closed << " windows forcefully"; | 534 DLOG_IF(ERROR, closed != 0) << "Closed " << closed << " windows forcefully"; |
534 } | 535 } |
535 | 536 |
536 // Attempt to connect to a running crash_service instance. Success occurs if we | 537 // Attempt to connect to a running crash_service instance. Success occurs if we |
537 // can actually connect to the service's pipe or we receive ERROR_PIPE_BUSY. | 538 // can actually connect to the service's pipe or we receive ERROR_PIPE_BUSY. |
538 // Waits up to |timeout_ms| for success. |timeout_ms| may be 0, meaning only try | 539 // Waits up to |timeout_ms| for success. |timeout_ms| may be 0, meaning only try |
539 // once, or negative, meaning wait forever. | 540 // once, or negative, meaning wait forever. |
540 bool DetectRunningCrashService(int timeout_ms) { | 541 bool DetectRunningCrashService(int timeout_ms) { |
541 // Wait for the crash_service.exe to be ready for clients. | 542 // Wait for the crash_service.exe to be ready for clients. |
542 base::Time start = base::Time::Now(); | 543 base::Time start = base::Time::Now(); |
543 ScopedHandle new_pipe; | 544 base::win::ScopedHandle new_pipe; |
544 | 545 |
545 while (true) { | 546 while (true) { |
546 new_pipe.Set(::CreateFile(kCrashServicePipeName, | 547 new_pipe.Set(::CreateFile(kCrashServicePipeName, |
547 kCrashServicePipeDesiredAccess, | 548 kCrashServicePipeDesiredAccess, |
548 0, // dwShareMode | 549 0, // dwShareMode |
549 NULL, // lpSecurityAttributes | 550 NULL, // lpSecurityAttributes |
550 OPEN_EXISTING, | 551 OPEN_EXISTING, |
551 kCrashServicePipeFlagsAndAttributes, | 552 kCrashServicePipeFlagsAndAttributes, |
552 NULL)); // hTemplateFile | 553 NULL)); // hTemplateFile |
553 | 554 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 bool wait) { | 668 bool wait) { |
668 bool result = true; | 669 bool result = true; |
669 base::NamedProcessIterator iter(executable_name, NULL); | 670 base::NamedProcessIterator iter(executable_name, NULL); |
670 while (const base::ProcessEntry* entry = iter.NextProcessEntry()) { | 671 while (const base::ProcessEntry* entry = iter.NextProcessEntry()) { |
671 result &= base::KillProcessById(entry->pid(), exit_code, wait); | 672 result &= base::KillProcessById(entry->pid(), exit_code, wait); |
672 } | 673 } |
673 return result; | 674 return result; |
674 } | 675 } |
675 | 676 |
676 } // namespace chrome_frame_test | 677 } // namespace chrome_frame_test |
OLD | NEW |