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

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

Issue 768373004: Improve native messaging documentation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments #4 + fix Python script for Windows Created 6 years 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
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
11 import threading 11 import threading
12 import Queue 12 import Queue
13 13
14 try: 14 try:
15 import Tkinter 15 import Tkinter
16 import tkMessageBox 16 import tkMessageBox
17 except ImportError: 17 except ImportError:
18 Tkinter = None 18 Tkinter = None
19 19
20 # On Windows, the default I/O mode is O_TEXT. Set this to O_BINARY
21 # to avoid unwanted modifications of the input/output streams.
22 if sys.platform == "win32":
23 import os, msvcrt
24 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
25 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
26
20 # Helper function that sends a message to the webapp. 27 # Helper function that sends a message to the webapp.
21 def send_message(message): 28 def send_message(message):
22 # Write message size. 29 # Write message size.
23 sys.stdout.write(struct.pack('I', len(message))) 30 sys.stdout.write(struct.pack('I', len(message)))
24 # Write the message itself. 31 # Write the message itself.
25 sys.stdout.write(message) 32 sys.stdout.write(message)
26 sys.stdout.flush() 33 sys.stdout.flush()
27 34
28 # Thread that reads messages from the webapp. 35 # Thread that reads messages from the webapp.
29 def read_thread_func(queue): 36 def read_thread_func(queue):
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 thread.daemon = True 119 thread.daemon = True
113 thread.start() 120 thread.start()
114 121
115 main_window.mainloop() 122 main_window.mainloop()
116 123
117 sys.exit(0) 124 sys.exit(0)
118 125
119 126
120 if __name__ == '__main__': 127 if __name__ == '__main__':
121 Main() 128 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698