WebKitRenderer.st
changeset 3 32456ba40192
parent 2 7e604e6f195e
child 4 385102f5bf00
--- a/WebKitRenderer.st	Fri Jun 03 08:54:52 2011 +0000
+++ b/WebKitRenderer.st	Mon Jun 06 17:41:38 2011 +0000
@@ -1,7 +1,7 @@
 "{ Package: 'stx:libwebkit' }"
 
 Object subclass:#WebKitRenderer
-	instanceVariableNames:'view in out'
+	instanceVariableNames:'view pid connection'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Views-WebKit'
@@ -12,12 +12,48 @@
 
 for: aWebKitView
 
-    self new initializeForView: aWebKitView
+    ^self new initializeForView: aWebKitView
 
     "Created: / 02-06-2011 / 23:38:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-06-2011 / 10:38:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!WebKitRenderer methodsFor:'initialization'!
+!WebKitRenderer methodsFor:'event loop'!
+
+dispatchEvent
+
+    | event |
+    connection atEnd ifTrue:[^self].
+    event := connection nextLine.
+    event ifNil:[^self].
+    Transcript showCR: event.
+
+    "Created: / 06-06-2011 / 18:13:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+eventLoop
+
+    [ connection atEnd ] whileFalse: [
+        self dispatchEvent 
+    ]
+
+    "Created: / 06-06-2011 / 18:00:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!WebKitRenderer methodsFor:'initialization & release'!
+
+close
+    self shouldImplement
+
+    "Created: / 06-06-2011 / 18:38:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+init
+
+    connection nextPutAll:'set uri = http://www.webkit.org'; cr.
+
+    "Created: / 06-06-2011 / 18:00:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
 
 initializeForView: aWebKitView
 
@@ -26,30 +62,60 @@
     "Created: / 02-06-2011 / 23:38:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!WebKitRenderer methodsFor:'spawn/terminate renderer'!
+!WebKitRenderer methodsFor:'private'!
 
-spawnRenderer
+startEventLoop
+    
+    [ 
+        self waitFor; init; eventLoop; close
+    ] fork
+
+    "Created: / 06-06-2011 / 17:57:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
 
-    | inPipe outPipe |
-    inPipe := NonPositionableExternalStream makePipe.
-    outPipe := NonPositionableExternalStream makePipe.
+waitFor
+
+    | client |
+
+    connection listenFor: 1.
+    client := connection accept.
+    connection port asFilename remove.
+    connection close.
+    connection := client.
+
+    "Created: / 06-06-2011 / 18:00:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
 
-    self halt:'Unfinished'.
+!WebKitRenderer methodsFor:'spawn / terminate'!
+
+spawn
+    |path uzbl args|
 
-    OperatingSystem
-        exec: '/home/jv/work/uzbl/uzbl-core'
-        withArguments: #('/home/jv/work/uzbl/uzbl-core' '-c' '-' '-p' '-s')
-        environment: nil
-        fileDescriptors: #(1 2 3)
-        fork: true
-        newPgrp: false
-        inDirectory: Filename defaultDirectory pathName
+    path := Filename newTemporary.
+    connection := Socket newUNIXserverAt:path pathName.
+    uzbl := '/home/jv/work/uzbl/uzbl-core'.
+    args := (Array 
+                with:'/home/jv/work/uzbl/uzbl-core'
+                with:'-s'
+                with:view rendererView embeddingWindowId
+                with:'--connect-socket=' , path pathName).
+     "pid := OperatingSystem
+     exec: uzbl
+     withArguments: args
+     environment: nil
+     fileDescriptors: #(1 2 3)
+     fork: true
+     newPgrp: false
+     inDirectory: path directory pathName
+    "
+    self halt.
+    self startEventLoop.
 
     "Created: / 02-06-2011 / 23:40:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-06-2011 / 18:04:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-terminateRenderer
-
+terminate
     "Created: / 02-06-2011 / 23:40:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !