Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: chrome/test/data/native_messaging/native_hosts/echo.py

Issue 1809383004: Set current directory when launching Native Messaging processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/common/extensions/docs/templates/articles/nativeMessaging.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 # Verify that the process was started in the correct directory.
42 cwd = os.getcwd()
43 script_path = os.path.dirname(os.path.abspath(sys.argv[0]))
44 if cwd.lower() != script_path.lower():
45 sys.stderr.write('Native messaging host started in a wrong directory.')
46 return 1
47
48 # Verify that --parent-window parameter is correct.
41 if platform.system() == 'Windows' and parent_window: 49 if platform.system() == 'Windows' and parent_window:
42 import win32gui 50 import win32gui
43 if not win32gui.IsWindow(parent_window): 51 if not win32gui.IsWindow(parent_window):
44 sys.stderr.write('Invalid --parent-window.\n') 52 sys.stderr.write('Invalid --parent-window.\n')
45 return 1 53 return 1
46 54
47 while 1: 55 while 1:
48 # Read the message type (first 4 bytes). 56 # Read the message type (first 4 bytes).
49 text_length_bytes = sys.stdin.read(4) 57 text_length_bytes = sys.stdin.read(4)
50 58
(...skipping 26 matching lines...) Expand all
77 85
78 message_number += 1 86 message_number += 1
79 87
80 message = '{{"id": {0}, "echo": {1}, "caller_url": "{2}"}}'.format( 88 message = '{{"id": {0}, "echo": {1}, "caller_url": "{2}"}}'.format(
81 message_number, text, caller_url).encode('utf-8') 89 message_number, text, caller_url).encode('utf-8')
82 if not WriteMessage(message): 90 if not WriteMessage(message):
83 break 91 break
84 92
85 if __name__ == '__main__': 93 if __name__ == '__main__':
86 sys.exit(Main()) 94 sys.exit(Main())
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/templates/articles/nativeMessaging.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698