@@ 40,7 40,13 @@ serveSession sessions = WD.withSession fail (\uuid session -> msum [
dir "url" $ getURL session,
dir "refresh" $ reloadPage session,
dir "back" $ sessionAction WD.back session,
- dir "forward" $ sessionAction WD.next session
+ dir "forward" $ sessionAction WD.next session,
+ dir "window" $ msum [ -- Noops
+ getWindowHandle uuid,
+ delSession sessions uuid, -- Closing the only window closes the session.
+ switchWindowHandle uuid,
+ dir "handles" $ getWindowHandles uuid
+ ]
]) sessions
where
fail uuid'| Just _ <- ID.fromString uuid' = errJSON 404 "invalid session ID" $ (
@@ 118,3 124,28 @@ sessionAction cb session = do
nullDir
liftIO $ cb session
ok $ toResponse ()
+
+---- Windowing noops
+getWindowHandle uuid = do
+ method GET
+ nullDir
+ ok $ toResponse ("window-" ++ ID.toString uuid)
+
+data WindowHandle = WindowHandle { handle :: String } deriving Generic
+instance FromJSON WindowHandle
+switchWindowHandle uuid = do
+ method POST
+ nullDir
+ handle <- getJSON
+ case handle of
+ Nothing -> errJSON 400 "invalid argument" "Failed to parse JSON input"
+ Just (WindowHandle handle') | handle' /= "window-" ++ ID.toString uuid ->
+ errJSON 404 "no such window" "Rhapsode isn't a multi-window or multi-tab browser"
+ _ -> ok $ toResponse ()
+
+getWindowHandles uuid = do
+ method GET
+ nullDir
+ okJSON ["window-" ++ ID.toString uuid]
+
+