[Sugar-devel] [PATCH 2/2] Remove mozilla xpcom and hulahop, add WebKit

Manuel Quiñones manuq at laptop.org
Tue Nov 29 06:30:40 EST 2011


This commit breaks a lot of Browse functionality.  This is marked in
the code with a FIXME keyword.

Original work was done by Daniel Drake.

Signed-off-by: Manuel Quiñones <manuq at laptop.org>
---
 browser.py     |  100 +++++++++++++++++++++++++-------------------------------
 edittoolbar.py |    6 +---
 palettes.py    |    3 --
 viewtoolbar.py |    1 +
 webactivity.py |   35 +++++--------------
 webtoolbar.py  |   10 +++---
 6 files changed, 61 insertions(+), 94 deletions(-)

diff --git a/browser.py b/browser.py
index ce30067..573a9ab 100644
--- a/browser.py
+++ b/browser.py
@@ -23,22 +23,18 @@ from gettext import gettext as _
 from gi.repository import GObject
 from gi.repository import Gtk
 from gi.repository import Pango
-import hulahop
-import xpcom
-from xpcom.nsError import *
-from xpcom import components
-from xpcom.components import interfaces
-from hulahop.webview import WebView
+from gi.repository import WebKit
 
 from sugar3 import env
 from sugar3.activity import activity
 from sugar3.graphics import style
 from sugar3.graphics.icon import Icon
 
-import sessionstore
-from palettes import ContentInvoker
-from sessionhistory import HistoryListener
-from progresslistener import ProgressListener
+# FIXME
+# import sessionstore
+# from palettes import ContentInvoker
+# from sessionhistory import HistoryListener
+# from progresslistener import ProgressListener
 from widgets import BrowserNotebook
 
 _ZOOM_AMOUNT = 0.1
@@ -46,8 +42,6 @@ _LIBRARY_PATH = '/usr/share/library-common/index.html'
 
 
 class SaveListener(object):
-    _com_interfaces_ = interfaces.nsIWebProgressListener
-
     def __init__(self, user_data, callback):
         self._user_data = user_data
         self._callback = callback
@@ -79,9 +73,6 @@ class SaveListener(object):
 
 
 class CommandListener(object):
-
-    _com_interfaces_ = interfaces.nsIDOMEventListener
-
     def __init__(self, window):
         self._window = window
 
@@ -107,8 +98,6 @@ class TabbedView(BrowserNotebook):
                             ([])),
     }
 
-    _com_interfaces_ = interfaces.nsIWindowCreator
-
     AGENT_SHEET = os.path.join(activity.get_bundle_path(),
                                'agent-stylesheet.css')
     USER_SHEET = os.path.join(env.get_profile_path(), 'gecko',
@@ -120,36 +109,37 @@ class TabbedView(BrowserNotebook):
         self.props.show_border = False
         self.props.scrollable = True
 
-        io_service_class = components.classes[ \
-                "@mozilla.org/network/io-service;1"]
-        io_service = io_service_class.getService(interfaces.nsIIOService)
-
-        # Use xpcom to turn off "offline mode" detection, which disables
-        # access to localhost for no good reason.  (Trac #6250.)
-        io_service2 = io_service_class.getService(interfaces.nsIIOService2)
-        io_service2.manageOfflineStatus = False
-
-        cls = components.classes['@mozilla.org/content/style-sheet-service;1']
-        style_sheet_service = cls.getService(interfaces.nsIStyleSheetService)
-
-        if os.path.exists(TabbedView.AGENT_SHEET):
-            agent_sheet_uri = io_service.newURI('file:///' +
-                                                TabbedView.AGENT_SHEET,
-                                                None, None)
-            style_sheet_service.loadAndRegisterSheet(agent_sheet_uri,
-                    interfaces.nsIStyleSheetService.AGENT_SHEET)
-
-        if os.path.exists(TabbedView.USER_SHEET):
-            url = 'file:///' + TabbedView.USER_SHEET
-            user_sheet_uri = io_service.newURI(url, None, None)
-            style_sheet_service.loadAndRegisterSheet(user_sheet_uri,
-                    interfaces.nsIStyleSheetService.USER_SHEET)
-
-        cls = components.classes['@mozilla.org/embedcomp/window-watcher;1']
-        window_watcher = cls.getService(interfaces.nsIWindowWatcher)
-        window_creator = xpcom.server.WrapObject(self,
-                                                 interfaces.nsIWindowCreator)
-        window_watcher.setWindowCreator(window_creator)
+        # FIXME
+        # io_service_class = components.classes[ \
+        #         "@mozilla.org/network/io-service;1"]
+        # io_service = io_service_class.getService(interfaces.nsIIOService)
+
+        # # Use xpcom to turn off "offline mode" detection, which disables
+        # # access to localhost for no good reason.  (Trac #6250.)
+        # io_service2 = io_service_class.getService(interfaces.nsIIOService2)
+        # io_service2.manageOfflineStatus = False
+
+        # cls = components.classes['@mozilla.org/content/style-sheet-service;1']
+        # style_sheet_service = cls.getService(interfaces.nsIStyleSheetService)
+
+        # if os.path.exists(TabbedView.AGENT_SHEET):
+        #     agent_sheet_uri = io_service.newURI('file:///' +
+        #                                         TabbedView.AGENT_SHEET,
+        #                                         None, None)
+        #     style_sheet_service.loadAndRegisterSheet(agent_sheet_uri,
+        #             interfaces.nsIStyleSheetService.AGENT_SHEET)
+
+        # if os.path.exists(TabbedView.USER_SHEET):
+        #     url = 'file:///' + TabbedView.USER_SHEET
+        #     user_sheet_uri = io_service.newURI(url, None, None)
+        #     style_sheet_service.loadAndRegisterSheet(user_sheet_uri,
+        #             interfaces.nsIStyleSheetService.USER_SHEET)
+
+        # cls = components.classes['@mozilla.org/embedcomp/window-watcher;1']
+        # window_watcher = cls.getService(interfaces.nsIWindowWatcher)
+        # window_creator = xpcom.server.WrapObject(self,
+        #                                          interfaces.nsIWindowCreator)
+        # window_watcher.setWindowCreator(window_creator)
 
         self.connect('size-allocate', self.__size_allocate_cb)
         self.connect('page-added', self.__page_added_cb)
@@ -242,7 +232,9 @@ class TabbedView(BrowserNotebook):
 
         n_pages = self.get_n_pages()
         canvas_size = self.get_allocation()
-        overlap_size = self.style_get_property('tab-overlap') * n_pages - 1
+        # FIXME
+        # overlap_size = self.style_get_property('tab-overlap') * n_pages - 1
+        overlap_size = 0
         allowed_size = canvas_size.width - overlap_size
 
         tab_new_size = int(allowed_size * 1.0 / (n_pages + 1))
@@ -385,7 +377,7 @@ class TabLabel(Gtk.HBox):
             self._label.set_text(browser.props.title)
 
 
-class Browser(WebView):
+class Browser(WebKit.WebView):
     __gtype_name__ = 'Browser'
 
     __gsignals__ = {
@@ -398,13 +390,11 @@ class Browser(WebView):
     }
 
     def __init__(self):
-        WebView.__init__(self)
-
-        self.history = HistoryListener()
-        self.progress = ProgressListener()
+        WebKit.WebView.__init__(self)
 
-        cls = components.classes["@mozilla.org/typeaheadfind;1"]
-        self.typeahead = cls.createInstance(interfaces.nsITypeAheadFind)
+        # FIXME
+        # self.history = HistoryListener()
+        # self.progress = ProgressListener()
 
     def do_setup(self):
         WebView.do_setup(self)
diff --git a/edittoolbar.py b/edittoolbar.py
index 7273382..ac54245 100644
--- a/edittoolbar.py
+++ b/edittoolbar.py
@@ -16,10 +16,9 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 from gi.repository import Gtk
+from gi.repository import Gdk
 from gettext import gettext as _
 
-from xpcom.components import interfaces
-
 from sugar3.activity import activity
 from sugar3.graphics import iconentry
 from sugar3.graphics.toolbutton import ToolButton
@@ -27,9 +26,6 @@ from sugar3.graphics import style
 
 
 class EditToolbar(activity.EditToolbar):
-
-    _com_interfaces_ = interfaces.nsIObserver
-
     def __init__(self, act):
         activity.EditToolbar.__init__(self)
 
diff --git a/palettes.py b/palettes.py
index 38f6823..01c34d4 100644
--- a/palettes.py
+++ b/palettes.py
@@ -22,9 +22,6 @@ from gettext import gettext as _
 
 from gi.repository import Gtk
 from gi.repository import GObject
-import xpcom
-from xpcom import components
-from xpcom.components import interfaces
 
 from sugar3.graphics.palette import Palette, Invoker
 from sugar3.graphics.menuitem import MenuItem
diff --git a/viewtoolbar.py b/viewtoolbar.py
index 0e77137..7daadc9 100644
--- a/viewtoolbar.py
+++ b/viewtoolbar.py
@@ -18,6 +18,7 @@
 from gettext import gettext as _
 
 from gi.repository import Gtk
+from gi.repository import GObject
 
 from sugar3.graphics.toolbutton import ToolButton
 
diff --git a/webactivity.py b/webactivity.py
index e25088f..2efa70e 100644
--- a/webactivity.py
+++ b/webactivity.py
@@ -25,6 +25,7 @@ from gi.repository import GObject
 GObject.threads_init()
 
 from gi.repository import Gtk
+from gi.repository import Gdk
 import base64
 import time
 import shutil
@@ -35,10 +36,6 @@ import locale
 import cairo
 from hashlib import sha1
 
-# HACK: Needed by http://dev.sugarlabs.org/ticket/456
-import gnome
-gnome.init('Hulahop', '1.0')
-
 from sugar3.activity import activity
 from sugar3.graphics import style
 import telepathy
@@ -132,13 +129,6 @@ def _seed_xs_cookie():
         _logger.debug('seed_xs_cookie: Updated cookie successfully')
 
 
-import hulahop
-hulahop.set_app_version(os.environ['SUGAR_BUNDLE_VERSION'])
-hulahop.startup(_profile_path)
-
-from xpcom import components
-
-
 def _set_char_preference(name, value):
     cls = components.classes["@mozilla.org/preferences-service;1"]
     prefService = cls.getService(components.interfaces.nsIPrefService)
@@ -164,11 +154,12 @@ from browser import TabbedView
 from webtoolbar import PrimaryToolbar
 from edittoolbar import EditToolbar
 from viewtoolbar import ViewToolbar
-import downloadmanager
+# FIXME
+# import downloadmanager
 
 # TODO: make the registration clearer SL #3087
-import globalhistory  # pylint: disable=W0611
-import filepicker  # pylint: disable=W0611
+# import globalhistory  # pylint: disable=W0611
+# import filepicker  # pylint: disable=W0611
 
 from model import Model
 from sugar3.presence.tubeconn import TubeConnection
@@ -188,25 +179,17 @@ class WebActivity(activity.Activity):
 
         _logger.debug('Starting the web activity')
 
-        downloadmanager.remove_old_parts()
+        # FIXME
+        # downloadmanager.remove_old_parts()
 
         self._force_close = False
         self._tabbed_view = TabbedView()
         self._tabbed_view.connect('focus-url-entry', self._on_focus_url_entry)
 
-        _set_accept_languages()
+        # FIXME
+        # _set_accept_languages()
         _seed_xs_cookie()
 
-        # don't pick up the sugar theme - use the native mozilla one instead
-        cls = components.classes['@mozilla.org/preferences-service;1']
-        pref_service = cls.getService(components.interfaces.nsIPrefService)
-        branch = pref_service.getBranch("mozilla.widget.")
-        branch.setBoolPref("disable-native-theme", True)
-
-        # Start password manager
-        cls = components.classes["@mozilla.org/login-manager;1"]
-        login_manager = cls.getService(components.interfaces.nsILoginManager)
-
         # HACK
         # Currently, the multiple tabs feature crashes the Browse activity
         # on cairo versions 1.8.10 or later. The exact cause for this
diff --git a/webtoolbar.py b/webtoolbar.py
index 00a7e87..af89fb5 100644
--- a/webtoolbar.py
+++ b/webtoolbar.py
@@ -21,7 +21,6 @@ from gettext import gettext as _
 from gi.repository import GObject
 from gi.repository import Gtk
 from gi.repository import Pango
-from xpcom.components import interfaces
 
 from sugar3.graphics.toolbutton import ToolButton
 from sugar3.graphics.menuitem import MenuItem
@@ -30,7 +29,8 @@ from sugar3.graphics.toolbarbox import ToolbarBox as ToolbarBase
 from sugar3.activity.widgets import ActivityToolbarButton
 from sugar3.activity.widgets import StopButton
 
-import filepicker
+# FIXME
+# import filepicker
 import places
 
 
@@ -48,7 +48,7 @@ class WebEntry(iconentry.IconEntry):
         self._title = None
         self._search_view = self._search_create_view()
 
-        self._search_window = Gtk.Window(Gtk.WindowType.POPUP)
+        self._search_window = Gtk.Window(type=Gtk.WindowType.POPUP)
         self._search_window.add(self._search_view)
         self._search_view.show()
 
@@ -102,7 +102,7 @@ class WebEntry(iconentry.IconEntry):
         cell.props.font = 'Bold'
         column.pack_start(cell, True)
 
-        column.set_attributes(cell, text=self._COL_TITLE)
+        column.add_attribute(cell, 'text', self._COL_TITLE)
 
         cell = Gtk.CellRendererText()
         cell.props.ellipsize = Pango.EllipsizeMode.END
@@ -110,7 +110,7 @@ class WebEntry(iconentry.IconEntry):
         cell.props.alignment = Pango.Alignment.LEFT
         column.pack_start(cell, True)
 
-        column.set_attributes(cell, text=self._COL_ADDRESS)
+        column.add_attribute(cell, 'text', self._COL_ADDRESS)
 
         return view
 
-- 
1.7.7.3



More information about the Sugar-devel mailing list