~ubuntu-branches/ubuntu/natty/miro/natty

« back to all changes in this revision

Viewing changes to linux/plat/frontends/widgets/webkitbrowser.py

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2011-01-22 02:46:33 UTC
  • mfrom: (1.4.10 upstream) (1.7.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20110122024633-kjme8u93y2il5nmf
Tags: 3.5.1-1ubuntu1
* Merge from debian.  Remaining ubuntu changes:
  - Use python 2.7 instead of python 2.6
  - Relax dependency on python-dbus to >= 0.83.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Miro - an RSS based video player application
 
2
# Copyright (C) 2010 Participatory Culture Foundation
 
3
#
 
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.
 
8
#
 
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.
 
13
#
 
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
 
17
#
 
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
 
20
# library.
 
21
#
 
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.
 
28
 
 
29
"""
 
30
Code for a WebKit based browser.
 
31
 
 
32
Documentation for WebKitGTK+:
 
33
http://webkitgtk.org/reference/index.html
 
34
 
 
35
Documentation for PyWebKitGTK: 
 
36
http://code.google.com/p/pywebkitgtk/
 
37
"""
 
38
 
 
39
from miro import config, prefs
 
40
 
 
41
import gtk
 
42
import webkit
 
43
 
 
44
def fix_user_agent(agent):
 
45
    """Default user agent for WebKitGTK+ is something like:
 
46
 
 
47
    Mozilla/5.0 (X11; U; Linux x86_64; c) AppleWebKit/531.2+ (KHTML, like Gecko) Safari/531.2+
 
48
 
 
49
    This function takes that string, drops the last bit, and adds Miro
 
50
    bits.
 
51
    """
 
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)
 
57
 
 
58
class WebKitEmbed(webkit.WebView):
 
59
    def __init__(self):
 
60
        webkit.WebView.__init__(self)
 
61
        settings = self.get_settings()
 
62
 
 
63
        # this disables all plugins -- Miro has problems with the
 
64
        # adobe flash plugin and hangs when the plugin loads and starts
 
65
        # doing things.
 
66
        settings.set_property('enable-plugins', False)
 
67
 
 
68
        # sets zoom to affect text and images
 
69
        self.set_full_content_zoom(True)
 
70
 
 
71
        # webkit will keep track of history
 
72
        self.set_maintains_back_forward_list(True)
 
73
 
 
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)
 
78
 
 
79
        self.connect_after("populate-popup", self.handle_populate_popup)
 
80
 
 
81
    def get_frame(self):
 
82
        # our browser isn't tabbed, so we always get the main
 
83
        # frame and operate on that.
 
84
        return self.get_main_frame()
 
85
 
 
86
    def handle_zoom_in(self, menu_item, view):
 
87
        view.zoom_in()
 
88
 
 
89
    def handle_zoom_out(self, menu_item, view):
 
90
        view.zoom_out()
 
91
 
 
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)
 
95
 
 
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)
 
99
        menu.append(zoom_in)
 
100
 
 
101
        zoom_out = gtk.ImageMenuItem(gtk.STOCK_ZOOM_OUT)
 
102
        zoom_out.connect('activate', self.handle_zoom_out, view)
 
103
        menu.append(zoom_out)
 
104
 
 
105
        zoom_full = gtk.ImageMenuItem(gtk.STOCK_ZOOM_100)
 
106
        zoom_full.connect('activate', self.handle_zoom_full, view)
 
107
        menu.append(zoom_full)
 
108
 
 
109
        menu.show_all()
 
110
        return False