src/Builder4/FakeServer.vala
[app.Builder.js] / src / Builder4 / FakeServer.vala
1 /**
2  * Idea is to serve the files from the file system, so no need to setup apache etc...
3  * This should work for the static content like css / javascript etc.. but 
4  * will cause issues with 'dynamic' xhr files (eg. the php stuff)
5  *
6  * the idea is nicked from geary.
7  * 
8  */
9
10 public class FakeServer : Object
11 {
12         Webkit.WebView view
13         
14         public FakeServer(Webkit.WebView wkview)
15         {
16                 this.view = wkview;
17                 // 
18                 
19                   
20         // Hook up signals.
21         this.wkview.load_finished.connect(on_load_finished);
22         this.wkview.resource_request_starting.connect(on_resource_request_starting);
23         this.wkview.navigation_policy_decision_requested.connect(on_navigation_policy_decision_requested);
24         this.wkview.new_window_policy_decision_requested.connect(on_navigation_policy_decision_requested);
25           
26         // Load the HTML into WebKit.
27         // Note: load_finished signal MUST be hooked up before this call.
28         string html_text = GearyApplication.instance.read_theme_file("message-viewer.html") ?? "";
29         load_string(html_text, "text/html", "UTF8", "");
30         }
31         
32         private bool on_navigation_policy_decision_requested(
33                 WebKit.WebFrame frame,
34         WebKit.NetworkRequest request,
35         WebKit.WebNavigationAction navigation_action,
36         WebKit.WebPolicyDecision policy_decision
37         ) {
38         policy_decision.ignore();
39         
40         // not sure if we should allow navigations...
41         return true;
42     }
43                 
44 }