From dcb5f998b24f359d7c3e1980da3c58b6f6e2331a Mon Sep 17 00:00:00 2001 From: Manuel QuiƱones Date: Wed, 28 Nov 2012 14:53:59 +0000 Subject: Display security as a lock icon for secured pages - SL #4245 For pages using the https protocol, display a) a lock icon if there were no errors in the certification, or b) a broken lock icon if the certification failed. Use the same logic as Epiphany: http://git.gnome.org/browse/epiphany/tree/embed/ephy-web-view.c#n2321 Signed-off-by: Manuel QuiƱones Acked-by: Manuel Kaufmann --- diff --git a/browser.py b/browser.py index 8b986ad..7419d2d 100644 --- a/browser.py +++ b/browser.py @@ -513,10 +513,16 @@ class Browser(WebKit.WebView): 'open-pdf': (GObject.SignalFlags.RUN_FIRST, None, ([str])), + 'security-status-changed': (GObject.SignalFlags.RUN_FIRST, + None, + ([])), } CURRENT_SUGAR_VERSION = '0.98' + SECURITY_STATUS_SECURE = 1 + SECURITY_STATUS_INSECURE = 2 + def __init__(self): WebKit.WebView.__init__(self) @@ -545,6 +551,8 @@ class Browser(WebKit.WebView): # presses Enter on the URL Entry self.loading_uri = None + self.security_status = None + # Reference to the global history and callbacks to handle it: self._global_history = globalhistory.get_global_history() self.connect('notify::load-status', self.__load_status_changed_cb) @@ -648,12 +656,28 @@ class Browser(WebKit.WebView): return True def __load_status_changed_cb(self, widget, param): - """Add the url to the global history or update it.""" status = widget.get_load_status() if status <= WebKit.LoadStatus.COMMITTED: + # Add the url to the global history or update it. uri = self.get_uri() self._global_history.add_page(uri) + if status == WebKit.LoadStatus.COMMITTED: + # Update the security status. + response = widget.get_main_frame().get_network_response() + message = response.get_message() + if message: + use_https, certificate, tls_errors = message.get_https_status() + + if use_https: + if tls_errors == 0: + self.security_status = self.SECURITY_STATUS_SECURE + else: + self.security_status = self.SECURITY_STATUS_INSECURE + else: + self.security_status = None + self.emit('security-status-changed') + def __title_changed_cb(self, widget, param): """Update title in global history.""" uri = self.get_uri() diff --git a/icons/channel-insecure-symbolic.svg b/icons/channel-insecure-symbolic.svg new file mode 100644 index 0000000..4c6ee0b --- /dev/null +++ b/icons/channel-insecure-symbolic.svg @@ -0,0 +1,59 @@ + + + +]> + + + Gnome Symbolic Icon Theme + + + + + + + + + + + + + + + diff --git a/icons/channel-secure-symbolic.svg b/icons/channel-secure-symbolic.svg new file mode 100644 index 0000000..8405550 --- /dev/null +++ b/icons/channel-secure-symbolic.svg @@ -0,0 +1,60 @@ + + + +]> + + + Gnome Symbolic Icon Theme + + + + + + + + + + + + + + + diff --git a/pdfviewer.py b/pdfviewer.py index 6ce4fcf..6cfbaed 100644 --- a/pdfviewer.py +++ b/pdfviewer.py @@ -177,6 +177,7 @@ class DummyBrowser(GObject.GObject): 'new-tab': (GObject.SignalFlags.RUN_FIRST, None, ([str])), 'tab-close': (GObject.SignalFlags.RUN_FIRST, None, ([object])), 'selection-changed': (GObject.SignalFlags.RUN_FIRST, None, ([])), + 'security-status-changed': (GObject.SignalFlags.RUN_FIRST, None, ([])), } __gproperties__ = { @@ -194,6 +195,7 @@ class DummyBrowser(GObject.GObject): self._uri = "" self._progress = 0.0 self._load_status = WebKit.LoadStatus.PROVISIONAL + self.security_status = None def do_get_property(self, prop): if prop.name == 'title': diff --git a/webactivity.py b/webactivity.py index 0e3b61b..3c0d337 100644 --- a/webactivity.py +++ b/webactivity.py @@ -156,6 +156,8 @@ class WebActivity(activity.Activity): session = WebKit.get_default_session() session.set_property('accept-language-auto', True) + session.set_property('ssl-use-system-ca-file', True) + session.set_property('ssl-strict', False) # By default, cookies are not stored persistently, we have to # add a cookie jar so that they get saved to disk. We use one diff --git a/webtoolbar.py b/webtoolbar.py index 642b310..dc0b3de 100644 --- a/webtoolbar.py +++ b/webtoolbar.py @@ -337,6 +337,7 @@ class PrimaryToolbar(ToolbarBase): self._progress_changed_hid = None self._session_history_changed_hid = None self._uri_changed_hid = None + self._security_status_changed_hid = None if tabbed_view.get_n_pages(): self._connect_to_browser(tabbed_view.props.current_browser) @@ -355,6 +356,7 @@ class PrimaryToolbar(ToolbarBase): self._browser.disconnect(self._uri_changed_hid) self._browser.disconnect(self._progress_changed_hid) self._browser.disconnect(self._loading_changed_hid) + self._browser.disconnect(self._security_status_changed_hid) self._browser = browser if not isinstance(self._browser, DummyBrowser): @@ -364,6 +366,7 @@ class PrimaryToolbar(ToolbarBase): self._set_address(address) self._set_progress(self._browser.props.progress) self._set_status(self._browser.props.load_status) + self._set_security_status(self._browser.security_status) is_webkit_browser = isinstance(self._browser, Browser) self.entry.props.editable = is_webkit_browser @@ -374,18 +377,36 @@ class PrimaryToolbar(ToolbarBase): 'notify::progress', self.__progress_changed_cb) self._loading_changed_hid = self._browser.connect( 'notify::load-status', self.__loading_changed_cb) + self._security_status_changed_hid = self._browser.connect( + 'security-status-changed', self.__security_status_changed_cb) self._update_navigation_buttons() def __loading_changed_cb(self, widget, param): self._set_status(widget.get_load_status()) + def __security_status_changed_cb(self, widget): + self._set_security_status(widget.security_status) + def __progress_changed_cb(self, widget, param): self._set_progress(widget.get_progress()) def _set_status(self, status): self._set_loading(status < WebKit.LoadStatus.FINISHED) + def _set_security_status(self, security_status): + # Display security status as a lock icon in the left side of + # the URL entry. + if security_status is None: + self.entry.set_icon_from_pixbuf( + iconentry.ICON_ENTRY_PRIMARY, None) + elif security_status == Browser.SECURITY_STATUS_SECURE: + self.entry.set_icon_from_name( + iconentry.ICON_ENTRY_PRIMARY, 'channel-secure-symbolic') + elif security_status == Browser.SECURITY_STATUS_INSECURE: + self.entry.set_icon_from_name( + iconentry.ICON_ENTRY_PRIMARY, 'channel-insecure-symbolic') + def _set_progress(self, progress): if progress == 1.0: self.entry.set_progress_fraction(0.0) -- cgit v0.9.1