OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # A simple native client in python. | 6 # A simple native client in python. |
7 # All this client does is echo the text it receives back at the extension. | 7 # All this client does is echo the text it receives back at the extension. |
8 | 8 |
9 import os | 9 import os |
10 import platform | 10 import platform |
(...skipping 20 matching lines...) Expand all Loading... |
31 return 1 | 31 return 1 |
32 # TODO(sergeyu): Use argparse module to parse the arguments (not available in | 32 # TODO(sergeyu): Use argparse module to parse the arguments (not available in |
33 # Python 2.6). | 33 # Python 2.6). |
34 for arg in sys.argv[1:]: | 34 for arg in sys.argv[1:]: |
35 if arg.startswith('--'): | 35 if arg.startswith('--'): |
36 if arg.startswith('--parent-window='): | 36 if arg.startswith('--parent-window='): |
37 parent_window = long(arg[len('--parent-window='):]) | 37 parent_window = long(arg[len('--parent-window='):]) |
38 elif caller_url == None: | 38 elif caller_url == None: |
39 caller_url = arg | 39 caller_url = arg |
40 | 40 |
41 if platform.system() == 'Windows': | 41 if platform.system() == 'Windows' and parent_window: |
42 import win32gui | 42 import win32gui |
43 if parent_window and not win32gui.IsWindow(parent_window): | 43 if not win32gui.IsWindow(parent_window): |
44 sys.stderr.write('Invalid --parent-window.\n') | 44 sys.stderr.write('Invalid --parent-window.\n') |
45 return 1 | 45 return 1 |
46 | 46 |
47 while 1: | 47 while 1: |
48 # Read the message type (first 4 bytes). | 48 # Read the message type (first 4 bytes). |
49 text_length_bytes = sys.stdin.read(4) | 49 text_length_bytes = sys.stdin.read(4) |
50 | 50 |
51 if len(text_length_bytes) == 0: | 51 if len(text_length_bytes) == 0: |
52 break | 52 break |
53 | 53 |
(...skipping 23 matching lines...) Expand all Loading... |
77 | 77 |
78 message_number += 1 | 78 message_number += 1 |
79 | 79 |
80 message = '{{"id": {0}, "echo": {1}, "caller_url": "{2}"}}'.format( | 80 message = '{{"id": {0}, "echo": {1}, "caller_url": "{2}"}}'.format( |
81 message_number, text, caller_url).encode('utf-8') | 81 message_number, text, caller_url).encode('utf-8') |
82 if not WriteMessage(message): | 82 if not WriteMessage(message): |
83 break | 83 break |
84 | 84 |
85 if __name__ == '__main__': | 85 if __name__ == '__main__': |
86 sys.exit(Main()) | 86 sys.exit(Main()) |
OLD | NEW |