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

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

Issue 12285015: Require manifests for native messaging hosts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 # A simple native client in python.
7 # All this client does is echo the text it receives back at the extension.
8
9 import sys
10 import struct
11
12 def Main():
13 message_number = 0
14
15 while 1:
16 # Read the message type (first 4 bytes).
17 text_length_bytes = sys.stdin.read(4)
18
19 if len(text_length_bytes) == 0:
20 break
21
22 # Read the message length (4 bytes).
23 text_length = struct.unpack('i', text_length_bytes)[0]
24
25 # Read the text (JSON object) of the message.
26 text = sys.stdin.read(text_length).decode('utf-8')
27
28 message_number += 1
29
30 response = '{{"id": {0}, "echo": {1}}}'.format(message_number,
31 text).encode('utf-8')
32
33 try:
34 sys.stdout.write(struct.pack("I", len(response)))
35 sys.stdout.write(response)
36 sys.stdout.flush()
37 except IOError:
38 break
39
40 if __name__ == '__main__':
41 Main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698