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

Side by Side Diff: chrome/common/extensions/docs/examples/api/nativeMessaging/host/native-messaging-example-host

Issue 138133015: Update comments in the Native Messaging example (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | « no previous file | 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 messaging host. Shows a Tkinter dialog with incoming messages 6 # A simple native messaging host. Shows a Tkinter dialog with incoming messages
7 # that also allows to send message back to the webapp. 7 # that also allows to send message back to the webapp.
8 8
9 import struct 9 import struct
10 import sys 10 import sys
(...skipping 11 matching lines...) Expand all
22 # Write message size. 22 # Write message size.
23 sys.stdout.write(struct.pack('I', len(message))) 23 sys.stdout.write(struct.pack('I', len(message)))
24 # Write the message itself. 24 # Write the message itself.
25 sys.stdout.write(message) 25 sys.stdout.write(message)
26 sys.stdout.flush() 26 sys.stdout.flush()
27 27
28 # Thread that reads messages from the webapp. 28 # Thread that reads messages from the webapp.
29 def read_thread_func(queue): 29 def read_thread_func(queue):
30 message_number = 0 30 message_number = 0
31 while 1: 31 while 1:
32 # Read the message type (first 4 bytes). 32 # Read the message length (first 4 bytes).
33 text_length_bytes = sys.stdin.read(4) 33 text_length_bytes = sys.stdin.read(4)
34 34
35 if len(text_length_bytes) == 0: 35 if len(text_length_bytes) == 0:
36 if queue: 36 if queue:
37 queue.put(None) 37 queue.put(None)
38 sys.exit(0) 38 sys.exit(0)
39 39
40 # Read the message length (4 bytes). 40 # Unpack message length as 4 byte integer.
41 text_length = struct.unpack('i', text_length_bytes)[0] 41 text_length = struct.unpack('i', text_length_bytes)[0]
42 42
43 # Read the text (JSON object) of the message. 43 # Read the text (JSON object) of the message.
44 text = sys.stdin.read(text_length).decode('utf-8') 44 text = sys.stdin.read(text_length).decode('utf-8')
45 45
46 if queue: 46 if queue:
47 queue.put(text) 47 queue.put(text)
48 else: 48 else:
49 # In headless mode just send an echo message back. 49 # In headless mode just send an echo message back.
50 send_message('{"echo": %s}' % text) 50 send_message('{"echo": %s}' % text)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 thread.daemon = True 112 thread.daemon = True
113 thread.start() 113 thread.start()
114 114
115 main_window.mainloop() 115 main_window.mainloop()
116 116
117 sys.exit(0) 117 sys.exit(0)
118 118
119 119
120 if __name__ == '__main__': 120 if __name__ == '__main__':
121 Main() 121 Main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698