# Copyright (C) 2006, Red Hat, Inc. # Copyright (C) 2007, One Laptop Per Child # Copyright (C) 2009, Luke Kenneth Casson Leighton # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import os import hulahop #from sugar import env #hulahop.startup(os.path.join(env.get_profile_path(), 'gecko')) # this is equivalent to ~/.firefox profiles subdirectory hulahop.startup('/home/bryan/public_html/irc/hulahop/whatisthis') from hulahop.webview import WebView import gtk import gobject import xpcom from xpcom.nsError import * from xpcom import components from xpcom.components import interfaces from progresslistener import ProgressListener class ContentInvoker: _com_interfaces_ = interfaces.nsIDOMEventListener def __init__(self, browser): self._browser = browser def handleEvent(self, event): print event.type, event.button target = event.target print "target:", target.tagName.lower() class Browser(WebView): def __init__(self): WebView.__init__(self) self.progress = ProgressListener() 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 self.progress.connect('loading-stop', self._loaded) self.progress.connect('loading-progress', self._loading) def do_setup(self): WebView.do_setup(self) self.progress.setup(self) listener = xpcom.server.WrapObject(ContentInvoker(self), interfaces.nsIDOMEventListener) self.window_root.addEventListener('click', listener, False) def _loaded(self, progress_listener): """ once document is loaded, we can now "do" stuff. until the document is "loaded", it's unsafe to go messing with the DOM, because stuff either isn't initialised properly or, more importantly, the loaded document will overwrite anything that's been done up to that point! """ doc = self.get_dom_window().document page_title = doc.title page_url = doc.location.href #sending javascript over self.evaluate_script("x = 5;") import pdb; pdb.set_trace() def _loading(self, progress_listener, progress): print "loading", progress win = gtk.Window(gtk.WINDOW_TOPLEVEL) win.set_size_request(800,600) win.connect('destroy', gtk.main_quit) wv = Browser() wv.show() win.add(wv) win.show() # load the blank document. wv.load_uri('http://www.sciencedirect.com/science/journal/03044211/36/1') # start gtk gtk.main()