1 import os.path
2 import gtkmozembed
3
4 import logging
5 log = logging.getLogger("WebBrowser")
6
7 import conduit.platform
8 import conduit.utils.Singleton as Singleton
9
11 """
12 A Singleton whose only responsibilty is to configure gtkmozembed to
13 use the correct profile path. Gtkmozembed only allows its profile
14 path to be set once
15 """
16
17 DEFAULT_PROFILE = 'default'
18
27
29 """
30 Some webbrowsers need a profile dir. Make it if
31 it doesnt exist
32 """
33 subdir = os.path.join(conduit.USER_DIR, 'mozilla')
34 profdir = os.path.join(subdir, self._profile)
35 if not os.access(profdir, os.F_OK):
36 os.makedirs(profdir)
37 return subdir
38
40 """
41 Create the file prefs.js in the mozilla profile directory. This
42 file does things like turn off the warning when navigating to https pages.
43 """
44 prefsContent = """\
45 # Mozilla User Preferences
46 user_pref("security.warn_entering_secure", false);
47 user_pref("security.warn_entering_weak", false);
48 user_pref("security.warn_viewing_mixed", false);
49 user_pref("security.warn_leaving_secure", false);
50 user_pref("security.warn_submit_insecure", false);
51 user_pref("security.warn_entering_secure.show_once", false);
52 user_pref("security.warn_entering_weak.show_once", false);
53 user_pref("security.warn_viewing_mixed.show_once", false);
54 user_pref("security.warn_leaving_secure.show_once", false);
55 user_pref("security.warn_submit_insecure.show_once", false);
56 user_pref("security.enable_java", false);
57 user_pref("browser.xul.error_pages.enabled", false);
58 user_pref("general.useragent.vendor", "%s");
59 user_pref("general.useragent.vendorSub", "%s");
60 user_pref("general.useragent.vendorComment", "%s");
61 """ % ("Conduit",conduit.VERSION,"http://www.conduit-project.org")
62
63 if conduit.GLOBALS.settings.proxy_enabled():
64 log.info("Setting mozilla proxy details")
65 host,port,user,password = conduit.GLOBALS.settings.get_proxy()
66 prefsContent += """\
67 user_pref("network.proxy.type", 1);
68 user_pref("network.proxy.http", "%s");
69 user_pref("network.proxy.http_port", %d);
70 user_pref("network.proxy.ssl", "%s");
71 user_pref("network.proxy.ssl_port", %s);
72 user_pref("network.proxy.share_proxy_settings", true);
73 """ % (host,port,host,port)
74
75 prefsPath = os.path.join(self._profileDir,self._profile,'prefs.js')
76 f = open(prefsPath, "wt")
77 f.write(prefsContent)
78 f.close()
79
81 """
82 Wraps the GTK embeddable Mozilla in the WebBrowser interface
83 """
100
103
105 self.url_load_request = True
106 self.moz.load_url(str)
107 self.url_load_request = False
108
111
113 self.emit("status_changed", self.moz.get_link_message())
114
116 if self.url_load_request:
117 return False
118 else:
119 return self.emit("open_uri", uri)
120
123
125 self.location = location
126 self.emit("location_changed",self.location)
127
129 if maxim < 1:
130 self.emit("loading_progress", -1.0)
131 else:
132 self.emit("loading_progress", (cur/maxim))
133
135 self.emit("loading_started")
136
138 self.emit("loading_finished")
139