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

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

Issue 22532011: Pass handle of the native view window to the native messaging host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/api/messaging/native_process_launcher.cc ('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 sys 10 import sys
11 import struct 11 import struct
12 12
13 def WriteMessage(message): 13 def WriteMessage(message):
14 try: 14 try:
15 sys.stdout.write(struct.pack("I", len(message))) 15 sys.stdout.write(struct.pack("I", len(message)))
16 sys.stdout.write(message) 16 sys.stdout.write(message)
17 sys.stdout.flush() 17 sys.stdout.flush()
18 return True 18 return True
19 except IOError: 19 except IOError:
20 return False 20 return False
21 21
22 def Main(): 22 def Main():
23 message_number = 0 23 message_number = 0
24 24
25 if len(sys.argv) < 2: 25 if len(sys.argv) < 2:
26 sys.stderr.write("URL of the calling application is not specified.\n") 26 sys.stderr.write("URL of the calling application is not specified.\n")
27 return; 27 return;
28 caller_url = sys.argv[1] 28 for arg in sys.argv[1:]:
29 if not arg.startswith('--'):
30 caller_url = arg
31 break
29 32
30 while 1: 33 while 1:
31 # Read the message type (first 4 bytes). 34 # Read the message type (first 4 bytes).
32 text_length_bytes = sys.stdin.read(4) 35 text_length_bytes = sys.stdin.read(4)
33 36
34 if len(text_length_bytes) == 0: 37 if len(text_length_bytes) == 0:
35 break 38 break
36 39
37 # Read the message length (4 bytes). 40 # Read the message length (4 bytes).
38 text_length = struct.unpack('i', text_length_bytes)[0] 41 text_length = struct.unpack('i', text_length_bytes)[0]
(...skipping 21 matching lines...) Expand all
60 63
61 message_number += 1 64 message_number += 1
62 65
63 if not WriteMessage( 66 if not WriteMessage(
64 '{{"id": {0}, "echo": {1}, "caller_url": "{2}"}}'.format( 67 '{{"id": {0}, "echo": {1}, "caller_url": "{2}"}}'.format(
65 message_number, text, caller_url).encode('utf-8')): 68 message_number, text, caller_url).encode('utf-8')):
66 break 69 break
67 70
68 if __name__ == '__main__': 71 if __name__ == '__main__':
69 Main() 72 Main()
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/messaging/native_process_launcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698