Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / tools / remote_test_helper / rth_server.py
blob064c16b448b6fbb1396bc64c8b33e326a9156241
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import jsonrpclib
5 import SimpleJSONRPCServer as _server
8 class RequestHandler(_server.SimpleJSONRPCRequestHandler):
9 """Custom JSON-RPC request handler."""
11 FILES = {
12 'client.html': {'content-type': 'text/html'},
13 'host.html': {'content-type': 'text/html'},
14 'client.js': {'content-type': 'application/javascript'},
15 'host.js': {'content-type': 'application/javascript'},
16 'jsonrpc.js': {'content-type': 'application/javascript'}
19 def do_GET(self):
20 """Custom GET handler to return default pages."""
21 filename = self.path.lstrip('/')
22 if filename not in self.FILES:
23 self.report_404()
24 return
25 with open(filename) as f:
26 data = f.read()
27 self.send_response(200)
28 for key, value in self.FILES[filename].iteritems():
29 self.send_header(key, value)
30 self.end_headers()
31 self.wfile.write(data)
34 class RPCHandler(object):
35 """Class to define and handle RPC calls."""
37 CLEARED_EVENT = {'action': 0, 'event': 0, 'modifiers': 0}
39 def __init__(self):
40 self.last_event = self.CLEARED_EVENT
42 def ClearLastEvent(self):
43 """Clear the last event."""
44 self.last_event = self.CLEARED_EVENT
45 return True
47 def SetLastEvent(self, action, value, modifier):
48 """Set the last action, value, and modifiers."""
49 self.last_event = {
50 'action': action,
51 'value': value,
52 'modifiers': modifier
54 return True
56 def GetLastEvent(self):
57 return self.last_event
60 def main():
61 server = _server.SimpleJSONRPCServer(
62 ('', 3474), requestHandler=RequestHandler,
63 logRequests=True, allow_none=True)
64 server.register_instance(RPCHandler())
65 server.serve_forever()
68 if __name__ == '__main__':
69 main()