Permalink
Browse files

add initial working xpcom nsiObserver code

  • Loading branch information...
0 parents commit 91d37cfd5cf3d454723c6b72160239ca2bd1caa3 Luke Closs committed Feb 20, 2008
Showing with 104 additions and 0 deletions.
  1. +51 −0 index.html
  2. +42 −0 test-web-view.py
  3. +11 −0 todo
@@ -0,0 +1,51 @@
+<html>
+ <head>
+ <title>Foo</title>
+ </head>
+ <script type="text/javascript">
+ document.set_msg = function (msg) {
+ document.getElementById('baz').innerHTML = msg;
+ }
+
+ document.observer = {
+ observe: function(subject,topic,data){
+ document.set_msg("Topic sent: " + topic + " - " + data);
+ }
+ };
+
+
+ function foo_button(self) {
+ try {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+ var observerService = Components.classes["@mozilla.org/observer-service;1"]
+ .getService(Components.interfaces.nsIObserverService);
+ observerService.addObserver(document.observer,"my-topic",false);
+ observerService.notifyObservers(self,"my-topic","foo");
+ }
+ catch(err) {
+ document.set_msg(err)
+ }
+ }
+ function bar_button(self) {
+ try {
+ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
+ var observerService = Components.classes["@mozilla.org/observer-service;1"]
+ .getService(Components.interfaces.nsIObserverService);
+ observerService.addObserver(document.observer,"my-topic",false);
+ observerService.notifyObservers(self,"my-topic","bar");
+ }
+ catch(err) {
+ document.set_msg(err)
+ }
+ }
+
+ </script>
+ <body>
+ <form>
+ <input type="button" name="foo" value="Foo" onClick="foo_button()">
+ <input type="button" name="bar" value="Bar" onClick="bar_button()">
+ </form>
+ <div id="baz">Empty</div>
+ </body>
+</html>
+
@@ -0,0 +1,42 @@
+import os
+import gtk
+import hulahop
+hulahop.startup(os.path.expanduser('~/.test-hulahop'))
+from hulahop.webview import WebView
+from xpcom import components
+
+class TestObserver:
+ _com_interfaces_ = components.interfaces.nsIObserver
+
+ def observe(self, subject, topic, data):
+ print "observed! - %s - %s" % (topic, data)
+
+def quit(window):
+ hulahop.shutdown()
+ gtk.main_quit()
+
+window = gtk.Window()
+window.set_default_size(600, 400)
+window.connect("destroy", quit)
+
+pref_class = components.classes["@mozilla.org/preferences-service;1"]
+prefs = pref_class.getService(components.interfaces.nsIPrefService)
+prefs.getBranch('signed.applets.').setBoolPref('codebase_principal_support', True);
+prefs.getBranch('capability.principal.').setCharPref(
+ 'socialcalc.granted', 'UniversalXPConnect')
+prefs.getBranch('capability.principal.').setCharPref(
+ 'socialcalc.id', 'file:///home/olpc/src/testapp/index.html')
+
+web_view = WebView()
+web_view.load_uri('file:///home/olpc/src/testapp/index.html')
+web_view.show()
+
+observerService = components.classes["@mozilla.org/observer-service;1"]
+ob_serv = observerService.getService(components.interfaces.nsIObserverService);
+ob_serv.addObserver(TestObserver(),"my-topic",False);
+
+
+window.add(web_view)
+window.show()
+
+gtk.main()
11 todo
@@ -0,0 +1,11 @@
+save:
+* python fires event to say "start saving"
+* js fires event to say "ready to save"
+* python reads textContent from event target
+* python saves to disk
+
+load:
+* python reads from disk
+* python writes content into dom
+* python fires event to say "ready to load"
+

0 comments on commit 91d37cf

Please sign in to comment.