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
3 # found in the LICENSE file.
7 This script sends a WM_CLOSE message to each window of Chrome and waits until
8 the process terminates.
22 def CloseWindows(process_path
):
23 """Closes all windows owned by processes whose path is |process_path|.
26 process_path: The path to the process.
29 A boolean indicating whether the processes successfully terminate within
32 start_time
= time
.time()
33 while time
.time() - start_time
< 30:
34 process_ids
= chrome_helper
.GetProcessIDs(process_path
)
38 for hwnd
in chrome_helper
.GetWindowHandles(process_ids
):
40 win32gui
.PostMessage(hwnd
, win32con
.WM_CLOSE
, 0, 0)
41 except pywintypes
.error
as error
:
42 # It's normal that some window handles have become invalid.
43 if error
.args
[0] != winerror
.ERROR_INVALID_WINDOW_HANDLE
:
50 usage
= 'usage: %prog chrome_path'
51 parser
= optparse
.OptionParser(usage
, description
='Quit Chrome.')
52 _
, args
= parser
.parse_args()
54 parser
.error('Incorrect number of arguments.')
57 if not CloseWindows(chrome_path
):
58 raise Exception('Could not quit Chrome.')
62 if __name__
== '__main__':