OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """Launches Chrome. | 5 """Launches Chrome. |
6 | 6 |
7 This script launches Chrome and waits until its window shows up. | 7 This script launches Chrome and waits until its window shows up. |
8 """ | 8 """ |
9 | 9 |
10 import optparse | 10 import optparse |
11 import subprocess | |
12 import sys | 11 import sys |
13 import time | 12 import time |
| 13 import win32process |
14 | 14 |
15 import chrome_helper | 15 import chrome_helper |
16 | 16 |
17 | 17 |
18 def WaitForWindow(process_id, class_pattern): | 18 def WaitForWindow(process_id, class_pattern): |
19 """Waits until a window specified by |process_id| and class name shows up. | 19 """Waits until a window specified by |process_id| and class name shows up. |
20 | 20 |
21 Args: | 21 Args: |
22 process_id: The ID of the process that owns the window. | 22 process_id: The ID of the process that owns the window. |
23 class_pattern: The regular expression pattern of the window class name. | 23 class_pattern: The regular expression pattern of the window class name. |
(...skipping 11 matching lines...) Expand all Loading... |
35 | 35 |
36 | 36 |
37 def main(): | 37 def main(): |
38 usage = 'usage: %prog chrome_path' | 38 usage = 'usage: %prog chrome_path' |
39 parser = optparse.OptionParser(usage, description='Launch Chrome.') | 39 parser = optparse.OptionParser(usage, description='Launch Chrome.') |
40 _, args = parser.parse_args() | 40 _, args = parser.parse_args() |
41 if len(args) != 1: | 41 if len(args) != 1: |
42 parser.error('Incorrect number of arguments.') | 42 parser.error('Incorrect number of arguments.') |
43 chrome_path = args[0] | 43 chrome_path = args[0] |
44 | 44 |
45 process = subprocess.Popen(chrome_path) | 45 _, _, process_id, _ = win32process.CreateProcess(None, chrome_path, None, |
46 if not WaitForWindow(process.pid, 'Chrome_WidgetWin_'): | 46 None, 0, 0, None, None, |
| 47 win32process.STARTUPINFO()) |
| 48 if not WaitForWindow(process_id, 'Chrome_WidgetWin_'): |
47 raise Exception('Could not launch Chrome.') | 49 raise Exception('Could not launch Chrome.') |
48 return 0 | 50 return 0 |
49 | 51 |
50 | 52 |
51 if __name__ == '__main__': | 53 if __name__ == '__main__': |
52 sys.exit(main()) | 54 sys.exit(main()) |
OLD | NEW |