conduit r1470 - in trunk: . conduit
- From: jstowers svn gnome org
- To: svn-commits-list gnome org
- Subject: conduit r1470 - in trunk: . conduit
- Date: Sat, 24 May 2008 03:31:11 +0000 (UTC)
Author: jstowers
Date: Sat May 24 03:31:11 2008
New Revision: 1470
URL: http://svn.gnome.org/viewvc/conduit?rev=1470&view=rev
Log:
2008-05-24 John Stowers <john stowers gmail com>
* conduit/Settings.py:
* conduit/Web.py: Add proxy support (both env var and gconf) to the built
in browser.
Modified:
trunk/ChangeLog
trunk/conduit/Settings.py
trunk/conduit/Web.py
Modified: trunk/conduit/Settings.py
==============================================================================
--- trunk/conduit/Settings.py (original)
+++ trunk/conduit/Settings.py Sat May 24 03:31:11 2008
@@ -6,6 +6,8 @@
Copyright: John Stowers, 2006
License: GPLv2
"""
+import re
+import os
import gobject
try:
@@ -62,14 +64,10 @@
class Settings(gobject.GObject):
"""
- Class for storing conduit.GLOBALS.settings.
+ Class for storing conduit.GLOBALS.settings. Keys of type str, bool, int,
+ and list of strings supported at this stage.
- Settings come in two categories.
- 1) Preferences which are application specific and get stored in gconf
- 2) Per conduit.GLOBALS.settings.which describe the way dataproviders are connected
- and the specific per dataprovider sync settings.
-
- Keys of type str, bool, int, and list of strings supported at this stage
+ Also stores the special proxy settings.
"""
__gsignals__ = {
'changed' : (gobject.SIGNAL_RUN_LAST | gobject.SIGNAL_DETAILED, gobject.TYPE_NONE, ()),
@@ -196,6 +194,55 @@
log.warn("Unknown gconf type (k:%s v:%s t:%s)" % (key,value,vtype))
return False
- return True
+ return True
+
+ def proxy_enabled(self):
+ """
+ @returns: True if the user has specified a http proxy via
+ the http_proxy environment variable, or in gconf
+ """
+ return os.environ.has_key("http_proxy") or \
+ self.client.get_bool("/system/http_proxy/use_http_proxy")
+
+ def get_proxy(self):
+ """
+ Returns the details of the configured http proxy.
+ The http_proxy environment variable overrides the GNOME setting
+ @returns: host,port,user,password
+ """
+ if self.proxy_enabled():
+ #env vars have preference
+ if os.environ.has_key("http_proxy"):
+ #re taken from python boto
+ pattern = re.compile(
+ '(?:http://)?' \
+ '(?:(?P<user>\w+):(?P<pass>.*)@)?' \
+ '(?P<host>[\w\-\.]+)' \
+ '(?::(?P<port>\d+))?'
+ )
+ match = pattern.match(os.environ['http_proxy'])
+ if match:
+ return (match.group('host'),
+ int(match.group('port')),
+ match.group('user'),
+ match.group('pass'))
+ #now try gconf
+ if self.client.get_bool("/system/http_proxy/use_authentication"):
+ return (self.client.get_string("/system/http_proxy/host"),
+ self.client.get_int("/system/http_proxy/port"),
+ self.client.get_string("/system/http_proxy/authentication_user"),
+ self.client.get_string("/system/http_proxy/authentication_password"))
+ else:
+ return (self.client.get_string("/system/http_proxy/host"),
+ self.client.get_int("/system/http_proxy/port"),
+ "",
+ "")
+
+ return ("",0,"","")
+
+
+
+
+
Modified: trunk/conduit/Web.py
==============================================================================
--- trunk/conduit/Web.py (original)
+++ trunk/conduit/Web.py Sat May 24 03:31:11 2008
@@ -18,16 +18,6 @@
webbrowser.open(url,new=1,autoraise=True)
log.debug("Opened %s" % url)
-def get_profile_subdir(subdir):
- """
- Some webbrowsers need a profile dir. Make it if
- it doesnt exist
- """
- profdir = os.path.join(conduit.USER_DIR, subdir)
- if not os.access(profdir, os.F_OK):
- os.makedirs(profdir)
- return profdir
-
class _WebBrowser(gobject.GObject):
"""
Basic webbrowser abstraction to provide an upgrade path
@@ -54,7 +44,7 @@
def __init__(self, emitOnIdle=False):
gobject.GObject.__init__(self)
self.emitOnIdle = emitOnIdle
-
+
def emit(self, *args):
"""
Override the gobject signal emission so that signals
@@ -75,16 +65,23 @@
"""
Wraps the GTK embeddable Mozilla in the WebBrowser interface
"""
+
+ PROFILE = 'default'
+
def __init__(self):
_WebBrowser.__init__(self)
#lazy import and other hoops necessary because
#set_profile path must be the first call to gtkmozembed
- #after it is imported
+ #after it is imported, otherwise it crashes..
if 'gtkmozembed' not in sys.modules:
import gtkmozembed
global gtkmozembed
- gtkmozembed.set_profile_path(get_profile_subdir('mozilla'), 'default')
+
+ #setup the mozilla environment
+ profdir = self._get_profile_subdir()
+ self._create_prefs_js()
+ gtkmozembed.set_profile_path(profdir, self.PROFILE)
self.url_load_request = False # flag to break load_url recursion
self.location = ""
@@ -96,6 +93,58 @@
self.moz.connect("progress", self._signal_progress)
self.moz.connect("net-start", self._signal_net_start)
self.moz.connect("net-stop", self._signal_net_stop)
+
+ def _get_profile_subdir(self):
+ """
+ Some webbrowsers need a profile dir. Make it if
+ it doesnt exist
+ """
+ subdir = os.path.join(conduit.USER_DIR, 'mozilla')
+ profdir = os.path.join(subdir, self.PROFILE)
+ if not os.access(profdir, os.F_OK):
+ os.makedirs(profdir)
+ return subdir
+
+ def _create_prefs_js(self):
+ """
+ Create the file prefs.js in the mozilla profile directory. This
+ file does things like turn off the warning when navigating to https pages.
+ """
+ prefsContent = """\
+# Mozilla User Preferences
+user_pref("security.warn_entering_secure", false);
+user_pref("security.warn_entering_weak", false);
+user_pref("security.warn_viewing_mixed", false);
+user_pref("security.warn_leaving_secure", false);
+user_pref("security.warn_submit_insecure", false);
+user_pref("security.warn_entering_secure.show_once", false);
+user_pref("security.warn_entering_weak.show_once", false);
+user_pref("security.warn_viewing_mixed.show_once", false);
+user_pref("security.warn_leaving_secure.show_once", false);
+user_pref("security.warn_submit_insecure.show_once", false);
+user_pref("security.enable_java", false);
+user_pref("browser.xul.error_pages.enabled", false);
+user_pref("general.useragent.vendor", "%s");
+user_pref("general.useragent.vendorSub", "%s");
+user_pref("general.useragent.vendorComment", "%s");
+""" % ("Conduit",conduit.VERSION,"http://www.conduit-project.org")
+
+ if conduit.GLOBALS.settings.proxy_enabled():
+ log.info("Setting mozilla proxy details")
+ host,port,user,password = conduit.GLOBALS.settings.get_proxy()
+ prefsContent += """\
+user_pref("network.proxy.type", 1);
+user_pref("network.proxy.http", "%s");
+user_pref("network.proxy.http_port", %d);
+user_pref("network.proxy.ssl", "%s");
+user_pref("network.proxy.ssl_port", %s);
+user_pref("network.proxy.share_proxy_settings", true);
+""" % (host,port,host,port)
+
+ prefsPath = os.path.join(self._get_profile_subdir(),self.PROFILE,'prefs.js')
+ f = open(prefsPath, "wt")
+ f.write(prefsContent)
+ f.close()
def widget(self):
return self.moz
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]