From 79b51226ff0a6bb2d9d5a815948b5537119ef9bb Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Tue, 11 Nov 2008 19:15:19 +0000 Subject: Merge commit 'v0.4.7' into upstream Conflicts (add test, avoid debian/* ): tests/test-web-view.py --- (limited to 'python') diff --git a/python/__init__.py b/python/__init__.py index 6065ebe..a1fde26 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -16,6 +16,7 @@ # Boston, MA 02111-1307, USA. import os +import logging import sys import ConfigParser @@ -26,6 +27,7 @@ from hulahop import config sys.path.insert(0, os.path.join(config.libxul_dir, 'python')) from hulahop._hulahop import shutdown +from hulahop._hulahop import get_view_for_window from hulahop import _hulahop _XO_DPI = 200 @@ -60,33 +62,36 @@ def startup(profile_path, components_dirs=[]): def _check_compreg(profile_path): comp_path = os.path.join(profile_path, 'compatibility.ini') - existant = True - valid = True try: cp = ConfigParser.ConfigParser(defaults={'app_version' : ''}) if not cp.read(comp_path): - existant = False + valid = False else: valid = cp.get('main', 'app_version') == _app_version and \ cp.get('main', 'libxul_dir') == config.libxul_dir except ConfigParser.Error: valid = False - - if not valid and existant: - compreg = os.path.join(profile_path, 'compreg.dat') - - os.unlink(comp_path) - os.unlink(compreg) - - cp = ConfigParser.ConfigParser() - cp.add_section('main') - cp.set('main', 'app_version', _app_version) - cp.set('main', 'libxul_dir', config.libxul_dir) - - f = open(comp_path, 'w') - cp.write(f) - f.close() + + if not valid: + compreg = os.path.join(profile_path, 'compreg.dat') + if os.path.exists(compreg): + try: + os.unlink(compreg) + except OSError, e: + logging.error('Unlink error: %s' % e) + + cp = ConfigParser.ConfigParser() + cp.add_section('main') + cp.set('main', 'app_version', _app_version) + cp.set('main', 'libxul_dir', config.libxul_dir) + + f = open(comp_path, 'w') + try: + cp.write(f) + except ConfigParser.Error, e: + logging.error('Can not write %s error: %s' % (comp_path, e)) + f.close() def _get_layout_dpi(): gtk_xft_dpi = gtk.settings_get_default().get_property('gtk-xft-dpi') diff --git a/python/hulahop.defs b/python/hulahop.defs index 55c1733..d07bf16 100644 --- a/python/hulahop.defs +++ b/python/hulahop.defs @@ -5,9 +5,9 @@ (gtype-id "HULAHOP_TYPE_WEB_VIEW") ) -(define-method create_window +(define-virtual setup (of-object "HulahopWebView") - (c-name "hulahop_web_view_create_window") + (c-name "hulahop_web_view_setup") (return-type "none") ) @@ -76,3 +76,11 @@ (return-type "none") ) +(define-function get_view_for_window + (c-name "hulahop_get_view_for_window") + (return-type "HulahopWebView*") + (parameters + '("PyObject*" "dom_window") + ) +) + diff --git a/python/webview.py b/python/webview.py index b4dc51f..3cccde6 100644 --- a/python/webview.py +++ b/python/webview.py @@ -25,8 +25,6 @@ from xpcom import components from xpcom.components import interfaces from xpcom.nsError import * -_views = [] - class _Chrome: _com_interfaces_ = interfaces.nsIWebBrowserChrome, \ interfaces.nsIWebBrowserChrome2, \ @@ -147,6 +145,9 @@ class _Chrome: #logging.debug("nsIEmbeddingSiteWindow.get_visibility: %r" % self.web_view.get_toplevel().props.visible) return self.web_view.get_toplevel().props.visible + def get_webBrowser(self): + return self.web_view.browser + def get_chromeFlags(self): return self._chrome_flags @@ -206,6 +207,7 @@ class WebView(_hulahop.WebView): 'status' : (str, None, None, None, gobject.PARAM_READABLE) } + def __init__(self): _hulahop.WebView.__init__(self) @@ -225,15 +227,13 @@ class WebView(_hulahop.WebView): interfaces.nsIWebProgressListener) self._status = '' + self._first_uri = None - self.create_window() + def do_setup(self): + _hulahop.WebView.do_setup(self) - self.connect('destroy', self.__destroy_cb) - - _views.append(self) - - def __destroy_cb(self): - _views.remove(self) + if self._first_uri: + self.load_uri(self._first_uri) def _notify_title_changed(self): self.notify('title') @@ -268,9 +268,12 @@ class WebView(_hulahop.WebView): return self.browser.contentDOMWindow def load_uri(self, uri): - self.web_navigation.loadURI( - uri, interfaces.nsIWebNavigation.LOAD_FLAGS_NONE, - None, None, None) + try: + self.web_navigation.loadURI( + uri, interfaces.nsIWebNavigation.LOAD_FLAGS_NONE, + None, None, None) + except xpcom.Exception: + self._first_uri = uri dom_window = property(get_dom_window) browser = property(get_browser) @@ -278,9 +281,3 @@ class WebView(_hulahop.WebView): doc_shell = property(get_doc_shell) web_progress = property(get_web_progress) web_navigation = property(get_web_navigation) - -def lookup_view(chrome): - for view in _views: - if view._chrome == chrome: - return view - return None -- cgit v0.9.1