Chromium Code Reviews| Index: chrome/test/data/native_messaging/native_hosts/echo.py |
| diff --git a/chrome/test/data/native_messaging/native_hosts/echo.py b/chrome/test/data/native_messaging/native_hosts/echo.py |
| index e9550f6cf678f7831b2617c03b3e39f23a6f7dfe..b7176b141ac617931cc6c7b3d9cac44ff87fcaad 100755 |
| --- a/chrome/test/data/native_messaging/native_hosts/echo.py |
| +++ b/chrome/test/data/native_messaging/native_hosts/echo.py |
| @@ -7,6 +7,7 @@ |
| # All this client does is echo the text it receives back at the extension. |
| import os |
| +import platform |
| import sys |
| import struct |
| @@ -22,13 +23,24 @@ def WriteMessage(message): |
| def Main(): |
| message_number = 0 |
| + caller_url = None; |
|
miket_OOO
2014/01/07 17:15:11
Begone, semicolon!
Sergey Ulanov
2014/01/07 20:56:10
Done.
|
| + parent_window = None |
| + |
| if len(sys.argv) < 2: |
| sys.stderr.write("URL of the calling application is not specified.\n") |
| - return; |
| + return 1 |
| for arg in sys.argv[1:]: |
| - if not arg.startswith('--'): |
| + if arg.startswith('--'): |
| + if arg.startswith('--parent-window='): |
|
miket_OOO
2014/01/07 17:15:11
Not a big deal, but it makes me sad when I see man
Sergey Ulanov
2014/01/07 20:56:10
Added TODO. FWIW argparse is available only starti
|
| + parent_window = long(arg[len('--parent-window='):]) |
| + elif caller_url == None: |
| caller_url = arg |
| - break |
| + |
| + if platform.system() == 'Windows': |
| + import win32gui |
| + if not win32gui.IsWindow(parent_window): |
| + sys.stderr.write('Invalid --parent-window.\n') |
| + return 1 |
| while 1: |
| # Read the message type (first 4 bytes). |
| @@ -63,10 +75,10 @@ def Main(): |
| message_number += 1 |
| - if not WriteMessage( |
| - '{{"id": {0}, "echo": {1}, "caller_url": "{2}"}}'.format( |
| - message_number, text, caller_url).encode('utf-8')): |
| + message = '{{"id": {0}, "echo": {1}, "caller_url": "{2}"}}'.format( |
| + message_number, text, caller_url).encode('utf-8') |
| + if not WriteMessage(message): |
| break |
| if __name__ == '__main__': |
| - Main() |
| + sys.exit(Main()) |