Only navigate to URI if scheme_handler doesn't print "USED".
[uzbl-mobile] / uzbl.h
1 /* -*- c-basic-offset: 4; -*-
2
3  * See LICENSE for license details
4  *
5  * Changelog:
6  * ---------
7  *
8  * (c) 2009 by Robert Manea
9  *     - introduced struct concept
10  *     - statusbar template
11  *
12  */
13
14 enum {
15   /* statusbar symbols */
16   SYM_TITLE, SYM_URI, SYM_NAME,
17   SYM_LOADPRGS, SYM_LOADPRGSBAR,
18   SYM_KEYCMD, SYM_MODE, SYM_MSG,
19   SYM_SELECTED_URI,
20 };
21
22 const struct {
23     gchar *symbol_name;
24     guint symbol_token;
25 } symbols[] = {
26     {"KEYCMD",               SYM_KEYCMD},
27
28     {NULL,                   0}
29 }, *symp = symbols;
30
31 /* status bar elements */
32 typedef struct {
33     gint           load_progress;
34     gchar          *msg;
35     gchar          *progress_s, *progress_u;
36     int            progress_w;
37     gchar          *progress_bar;
38     gchar          *mode_indicator;
39 } StatusBar;
40
41
42 /* gui elements */
43 typedef struct {
44     GtkWidget*     main_window;
45     gchar*         geometry;
46     GtkPlug*       plug;
47     GtkWidget*     scrolled_win;
48     GtkWidget*     vbox;
49     GtkWidget*     mainbar;
50     GtkWidget*     mainbar_label;
51     GtkScrollbar*  scbar_v;   // Horizontal and Vertical Scrollbar
52     GtkScrollbar*  scbar_h;   // (These are still hidden)
53     GtkAdjustment* bar_v; // Information about document length
54     GtkAdjustment* bar_h; // and scrolling position
55     WebKitWebView* web_view;
56     gchar*         main_title;
57     gchar*         icon;
58
59     /* WebInspector */
60     GtkWidget *inspector_window;
61     WebKitWebInspector *inspector;
62
63     StatusBar sbar;
64 } GUI;
65
66
67 /* external communication*/
68 enum { FIFO, SOCKET};
69 typedef struct {
70     gchar          *fifo_path;
71     gchar          *socket_path;
72     /* stores (key)"variable name" -> (value)"pointer to this var*/
73     GHashTable     *proto_var;
74
75     gchar          *sync_stdout;
76 } Communication;
77
78
79 /* internal state */
80 typedef struct {
81     gchar    *uri;
82     gchar    *config_file;
83     int      socket_id;
84     char     *instance_name;
85     gchar    *selected_url;
86     gchar    *executable_path;
87     gchar*   keycmd;
88     gchar*   searchtx;
89     gboolean verbose;
90 } State;
91
92
93 /* networking */
94 typedef struct {
95     SoupSession *soup_session;
96     SoupLogger *soup_logger;
97     char *proxy_url;
98     char *useragent;
99     gint max_conns;
100     gint max_conns_host;
101 } Network;
102
103
104 /* behaviour */
105 typedef struct {
106     gchar*   load_finish_handler;
107     gchar*   load_start_handler;
108     gchar*   load_commit_handler;
109     gchar*   status_format;
110     gchar*   title_format_short;
111     gchar*   title_format_long;
112     gchar*   status_background;
113     gchar*   history_handler;
114     gchar*   fifo_dir;
115     gchar*   socket_dir;
116     gchar*   download_handler;
117     gchar*   cookie_handler;
118     gchar*   new_window;
119     gchar*   scheme_handler;
120     gboolean always_insert_mode;
121     gboolean show_status;
122     gboolean insert_mode;
123     gboolean status_top;
124     gboolean reset_command_mode;
125     gchar*   modkey;
126     guint    modmask;
127     guint    http_debug;
128     gchar*   shell_cmd;
129     /* WebKitWebSettings exports */
130     guint    font_size;
131     guint    monospace_size;
132     guint    minimum_font_size;
133     gfloat   zoom_level;
134     guint    disable_plugins;
135     guint    disable_scripts;
136     guint    autoload_img;
137     guint    autoshrink_img;
138     guint    enable_spellcheck;
139     guint    enable_private;
140     guint    print_bg;
141     gchar*   style_uri;
142     guint    resizable_txt;
143     gchar*   default_encoding;
144     guint    enforce_96dpi;
145     gchar    *inject_html;
146     guint    caret_browsing;
147     guint    mode;
148     gchar*   base_url;
149     gchar*   html_endmarker;
150     gchar*   insert_indicator;
151     gchar*   cmd_indicator;
152     GString* html_buffer;
153     guint    html_timeout;
154     gboolean print_version;
155
156     /* command list: name -> Command  */
157     GHashTable* commands;
158 } Behaviour;
159
160 /* javascript */
161 typedef struct {
162     gboolean            initialized;
163     JSClassDefinition   classdef;
164     JSClassRef          classref;
165 } Javascript;
166
167 /* static information */
168 typedef struct {
169     int   webkit_major;
170     int   webkit_minor;
171     int   webkit_micro;
172     gchar *arch;
173     gchar *commit;
174 } Info;
175
176 /* main uzbl data structure */
177 typedef struct {
178     GUI           gui;
179     State         state;
180     Network       net;
181     Behaviour     behave;
182     Communication comm;
183     Javascript    js;
184     Info          info;
185
186     Window        xwin;
187
188     /* group bindings: key -> action */
189     GHashTable* bindings;
190 } Uzbl;
191
192
193 typedef struct {
194     char* name;
195     char* param;
196 } Action;
197
198 typedef void sigfunc(int);
199
200 /* XDG Stuff */
201
202 typedef struct {
203     gchar* environmental;
204     gchar* default_value;
205 } XDG_Var;
206
207 XDG_Var XDG[] =
208 {
209     { "XDG_CONFIG_HOME", "~/.config" },
210     { "XDG_DATA_HOME",   "~/.local/share" },
211     { "XDG_CACHE_HOME",  "~/.cache" },
212     { "XDG_CONFIG_DIRS", "/etc/xdg" },
213     { "XDG_DATA_DIRS",   "/usr/local/share/:/usr/share/" },
214 };
215
216 /* Functions */
217 char *
218 itos(int val);
219
220 char *
221 str_replace (const char* search, const char* replace, const char* string);
222
223 GArray*
224 read_file_by_line (gchar *path);
225
226 gchar*
227 parseenv (char* string);
228
229 void
230 clean_up(void);
231
232 void
233 catch_sigterm(int s);
234
235 sigfunc *
236 setup_signal(int signe, sigfunc *shandler);
237
238 gboolean
239 set_var_value(gchar *name, gchar *val);
240
241 void
242 print(WebKitWebView *page, GArray *argv, GString *result);
243
244 gboolean
245 navigation_decision_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data);
246
247 gboolean
248 new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data);
249
250 gboolean
251 mime_policy_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, gchar *mime_type,  WebKitWebPolicyDecision *policy_decision, gpointer user_data);
252
253 WebKitWebView*
254 create_web_view_cb (WebKitWebView  *web_view, WebKitWebFrame *frame, gpointer user_data);
255
256 gboolean
257 download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data);
258
259 void
260 toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result);
261
262 void
263 toggle_status_cb (WebKitWebView* page, GArray *argv, GString *result);
264
265 void
266 link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data);
267
268 void
269 title_change_cb (WebKitWebView* web_view, GParamSpec param_spec);
270
271 void
272 progress_change_cb (WebKitWebView* page, gint progress, gpointer data);
273
274 void
275 load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
276
277 void
278 load_start_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
279
280 void
281 load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data);
282
283 void
284 destroy_cb (GtkWidget* widget, gpointer data);
285
286 void
287 log_history_cb ();
288
289 void
290 commands_hash(void);
291
292 void
293 free_action(gpointer act);
294
295 Action*
296 new_action(const gchar *name, const gchar *param);
297
298 bool
299 file_exists (const char * filename);
300
301 void
302 set_keycmd();
303
304 void
305 set_mode_indicator();
306
307 void
308 update_indicator();
309
310 void
311 set_insert_mode(gboolean mode);
312
313 void
314 toggle_insert_mode(WebKitWebView *page, GArray *argv, GString *result);
315
316 void
317 load_uri (WebKitWebView * web_view, GArray *argv, GString *result);
318
319 void
320 new_window_load_uri (const gchar * uri);
321
322 void
323 chain (WebKitWebView *page, GArray *argv, GString *result);
324
325 void
326 keycmd (WebKitWebView *page, GArray *argv, GString *result);
327
328 void
329 keycmd_nl (WebKitWebView *page, GArray *argv, GString *result);
330
331 void
332 keycmd_bs (WebKitWebView *page, GArray *argv, GString *result);
333
334 void
335 close_uzbl (WebKitWebView *page, GArray *argv, GString *result);
336
337 gboolean
338 run_command(const gchar *command, const guint npre,
339             const gchar **args, const gboolean sync, char **output_stdout);
340
341 char*
342 build_progressbar_ascii(int percent);
343
344 void
345 spawn(WebKitWebView *web_view, GArray *argv, GString *result);
346
347 void
348 spawn_sh(WebKitWebView *web_view, GArray *argv, GString *result);
349
350 void
351 spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result);
352
353 void
354 spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result);
355
356 void
357 parse_command(const char *cmd, const char *param, GString *result);
358
359 void
360 parse_cmd_line(const char *ctl_line, GString *result);
361
362 gchar*
363 build_stream_name(int type, const gchar *dir);
364
365 gboolean
366 control_fifo(GIOChannel *gio, GIOCondition condition);
367
368 gchar*
369 init_fifo(gchar *dir);
370
371 gboolean
372 control_stdin(GIOChannel *gio, GIOCondition condition);
373
374 void
375 create_stdin();
376
377 gchar*
378 init_socket(gchar *dir);
379
380 gboolean
381 control_socket(GIOChannel *chan);
382
383 gboolean
384 control_client_socket(GIOChannel *chan);
385
386 void
387 update_title (void);
388
389 gboolean
390 key_press_cb (GtkWidget* window, GdkEventKey* event);
391
392 void
393 run_keycmd(const gboolean key_ret);
394
395 void
396 exec_paramcmd(const Action* act, const guint i);
397
398 void
399 initialize ();
400
401 void
402 create_browser ();
403
404 GtkWidget*
405 create_mainbar ();
406
407 GtkWidget*
408 create_window ();
409
410 GtkPlug*
411 create_plug ();
412
413 void
414 run_handler (const gchar *act, const gchar *args);
415
416 void
417 add_binding (const gchar *key, const gchar *act);
418
419 gchar*
420 get_xdg_var (XDG_Var xdg);
421
422 gchar*
423 find_xdg_file (int xdg_type, char* filename);
424
425 void
426 settings_init ();
427
428 void
429 search_text (WebKitWebView *page, GArray *argv, const gboolean forward);
430
431 void
432 search_forward_text (WebKitWebView *page, GArray *argv, GString *result);
433
434 void
435 search_reverse_text (WebKitWebView *page, GArray *argv, GString *result);
436
437 void
438 dehilight (WebKitWebView *page, GArray *argv, GString *result);
439
440 void
441 run_js (WebKitWebView * web_view, GArray *argv, GString *result);
442
443 void
444 run_external_js (WebKitWebView * web_view, GArray *argv, GString *result);
445
446 void
447 eval_js(WebKitWebView * web_view, gchar *script, GString *result);
448
449 void handle_cookies (SoupSession *session,
450                             SoupMessage *msg,
451                             gpointer     user_data);
452 void
453 save_cookies (SoupMessage *msg,
454                 gpointer     user_data);
455
456 void
457 set_var(WebKitWebView *page, GArray *argv, GString *result);
458
459 void
460 act_bind(WebKitWebView *page, GArray *argv, GString *result);
461
462 void
463 act_dump_config();
464
465 void
466 render_html();
467
468 void
469 set_timeout(int seconds);
470
471 void
472 dump_var_hash(gpointer k, gpointer v, gpointer ud);
473
474 void
475 dump_key_hash(gpointer k, gpointer v, gpointer ud);
476
477 void
478 dump_config();
479
480 void
481 retreive_geometry();
482
483 gboolean
484 configure_event_cb(GtkWidget* window, GdkEventConfigure* event);
485
486 typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result);
487 typedef struct {
488     Command function;
489     gboolean no_split;
490 } CommandInfo;
491
492 /* Command callbacks */
493 void
494 cmd_load_uri();
495
496 void
497 cmd_set_status();
498
499 void
500 set_proxy_url();
501
502 void
503 set_icon();
504
505 void
506 cmd_cookie_handler();
507
508 void
509 cmd_scheme_handler();
510
511 void
512 move_statusbar();
513
514 void
515 cmd_always_insert_mode();
516
517 void
518 cmd_http_debug();
519
520 void
521 cmd_max_conns();
522
523 void
524 cmd_max_conns_host();
525
526 /* exported WebKitWebSettings properties */
527
528 void
529 cmd_font_size();
530
531 void
532 cmd_zoom_level();
533
534 void
535 cmd_disable_plugins();
536
537 void
538 cmd_disable_scripts();
539
540 void
541 cmd_minimum_font_size();
542
543 void
544 cmd_fifo_dir();
545
546 void
547 cmd_socket_dir();
548
549 void
550 cmd_modkey();
551
552 void
553 cmd_useragent() ;
554
555 void
556 cmd_autoload_img();
557
558 void
559 cmd_autoshrink_img();
560
561 void
562 cmd_enable_spellcheck();
563
564 void
565 cmd_enable_private();
566
567 void
568 cmd_print_bg();
569
570 void
571 cmd_style_uri();
572
573 void
574 cmd_resizable_txt();
575
576 void
577 cmd_default_encoding();
578
579 void
580 cmd_enforce_96dpi();
581
582 void
583 cmd_inject_html();
584
585 void
586 cmd_caret_browsing();
587
588 void
589 cmd_set_geometry();
590
591 /* vi: set et ts=4: */