1
# Miro - an RSS based video player application
2
# Copyright (C) 2010 Participatory Culture Foundation
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# In addition, as a special exception, the copyright holders give
19
# permission to link the code of portions of this program with the OpenSSL
22
# You must obey the GNU General Public License in all respects for all of
23
# the code used other than OpenSSL. If you modify file(s) with this
24
# exception, you may extend this exception to your version of the file(s),
25
# but you are not obligated to do so. If you do not wish to do so, delete
26
# this exception statement from your version. If you delete this exception
27
# statement from all source files in the program, then also delete it here.
30
Code for a WebKit based browser.
32
Documentation for WebKitGTK+:
33
http://webkitgtk.org/reference/index.html
35
Documentation for PyWebKitGTK:
36
http://code.google.com/p/pywebkitgtk/
39
from miro import config, prefs
44
def fix_user_agent(agent):
45
"""Default user agent for WebKitGTK+ is something like:
47
Mozilla/5.0 (X11; U; Linux x86_64; c) AppleWebKit/531.2+ (KHTML, like Gecko) Safari/531.2+
49
This function takes that string, drops the last bit, and adds Miro
52
agent = agent.split(" ")[:-1]
53
agent.append("%s/%s (%s)" % (config.get(prefs.SHORT_APP_NAME),
54
config.get(prefs.APP_VERSION),
55
config.get(prefs.PROJECT_URL)))
56
return " ".join(agent)
58
class WebKitEmbed(webkit.WebView):
60
webkit.WebView.__init__(self)
61
settings = self.get_settings()
63
# this disables all plugins -- Miro has problems with the
64
# adobe flash plugin and hangs when the plugin loads and starts
66
settings.set_property('enable-plugins', False)
68
# sets zoom to affect text and images
69
self.set_full_content_zoom(True)
71
# webkit will keep track of history
72
self.set_maintains_back_forward_list(True)
74
# fixes the user agent to include Miro bits
75
agent = settings.get_property('user-agent')
76
agent = fix_user_agent(agent)
77
settings.set_property('user-agent', agent)
79
self.connect_after("populate-popup", self.handle_populate_popup)
82
# our browser isn't tabbed, so we always get the main
83
# frame and operate on that.
84
return self.get_main_frame()
86
def handle_zoom_in(self, menu_item, view):
89
def handle_zoom_out(self, menu_item, view):
92
def handle_zoom_full(self, menu_item, view):
93
if not (view.get_zoom_level() == 1.0):
94
view.set_zoom_level(1.0)
96
def handle_populate_popup(self, view, menu):
97
zoom_in = gtk.ImageMenuItem(gtk.STOCK_ZOOM_IN)
98
zoom_in.connect('activate', self.handle_zoom_in, view)
101
zoom_out = gtk.ImageMenuItem(gtk.STOCK_ZOOM_OUT)
102
zoom_out.connect('activate', self.handle_zoom_out, view)
103
menu.append(zoom_out)
105
zoom_full = gtk.ImageMenuItem(gtk.STOCK_ZOOM_100)
106
zoom_full.connect('activate', self.handle_zoom_full, view)
107
menu.append(zoom_full)