/usr/share/pyshared/freevo/util/webbrowser.py is in python-freevo 1.9.2b2-4.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | # -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# Module for controlling a simple undecorated web browser.
# -----------------------------------------------------------------------
# $Id: youtube.py 11862 2011-08-07 11:56:13Z adam $
#
# -----------------------------------------------------------------------
#
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------
'''
Module for controlling a simple undecorated web browser.
'''
import logging
logger = logging.getLogger("freevo.util.webbrowser")
import config
import json
import threading
import os.path
from kaa.process import Process
import event
from util.httpserver import get_local_server, LongPollHandler
JSON_MIMETYPE= 'application/json'
JS_MIMETYPE = 'application/javascript'
HTML_DIR = os.path.join(config.SHARE_DIR, 'html')
_initial_url = None
def start_web_browser(initial_url, exit_handler=None):
"""
Create a new instance of a web browser.
@param initial_url: Optional initial URL to be displayed.
"""
global _initial_url
_initial_url = initial_url
local_server = get_local_server()
proxy = 'localhost:%d' % local_server.server_port
start_url = 'http://freevo/wbinitial.html'
browser_process = Process([config.CHROME_PATH, '--app='+start_url, '--proxy-server=' + proxy])
if exit_handler:
browser_process.signals['exited'].connect(exit_handler)
browser_process.start()
return browser_process
class WebIPC(object):
def __init__(self, server):
self.return_pending = False
self.return_event = threading.Event()
self.lphandler = LongPollHandler(JSON_MIMETYPE)
self.server = server
server.register_handler('^.*/freevo/ipc$', self.__ipc_handler)
server.register_handler('^.*/freevo/ipc.js$', self.__js_handler)
def __ipc_handler(self, request):
if request.command == 'POST':
self.__send_handler(request)
if request.command == 'GET':
self.lphandler(request)
else:
request.send_error(405)
def __js_handler(self, request):
request.send_response(200)
request.send_header('content-type', JS_MIMETYPE)
request.end_headers()
f = open(os.path.join(HTML_DIR, 'ipc.js'))
request.wfile.write(f.read())
f.close()
def __send_handler(self, request):
l = int(request.headers.getheader('Content-Length'))
s = request.rfile.read(l)
try:
result = None
args = json.loads(s)
if args['cmd'] == 'return':
if self.return_pending:
self.return_pending = False
self.return_result = args.get('data')
self.return_event.set()
else:
_debug_('Unexpected return!')
elif args['cmd'] == 'event':
event.Event('WEB_IPC', args['data']).post()
else:
_debug_('Unexpected ')
if result is None:
result = {}
request.send_response(200)
request.send_header('content-type', JSON_MIMETYPE)
request.end_headers()
json.dump(result, request.wfile)
except:
request.send_error(500)
def __calljs(self, js):
self.return_pending = True
self.lphandler.append(json.dumps({'cmd':js}))
self.return_event.wait(10.0)
self.return_event.clear()
return self.return_result
def __getattr__(self, item):
return JSObject(self.__calljs, None, item)
class JSObject(object):
def __init__(self, ipc, parent, name):
self.ipc = ipc
self.parent = parent
self.name = name
def __getattr__(self, item):
return JSObject(self.ipc, self, item)
def __call__(self, *args, **kwargs):
n = self.name
p = self.parent
while p is not None:
n = p.name + '.' + n
p = p.parent
return self.ipc('%s(%s)' % (n, json.dumps(args)[1:-1]))
def _get_initial_HTML(request):
f = open(os.path.join(HTML_DIR, 'wbinitial.html'))
initial_html = f.read()
f.close()
html = initial_html % (config.CONF.width, config.CONF.height, config.CONF.x, config.CONF.y, _initial_url)
request.send_response(200)
request.send_header('content-type', 'text/html')
request.send_header('content-length', str(len(html)))
request.end_headers()
request.wfile.write(html)
get_local_server().register_handler('^http://freevo/wbinitial.html$', _get_initial_HTML)
ipc = WebIPC(get_local_server())
|