2 * Copyright (c) 2010, 2011 Marco Peereboom <marco@peereboom.us>
3 * Copyright (c) 2011 Stevan Andjelkovic <stevan@student.chalmers.se>
4 * Copyright (c) 2010, 2011 Edd Barrett <vext01@gmail.com>
5 * Copyright (c) 2011 Todd T. Fries <todd@fries.net>
6 * Copyright (c) 2011 Raphael Graf <r@undefined.ch>
7 * Copyright (c) 2011 Michal Mazurek <akfaew@jasminek.net>
9 * Permission to use, copy, modify, and distribute this software for any
10 * purpose with or without fee is hereby granted, provided that the above
11 * copyright notice and this permission notice appear in all copies.
13 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 char *version
= XXXTERM_VERSION
;
26 /* hooked functions */
27 void (*_soup_cookie_jar_add_cookie
)(SoupCookieJar
*, SoupCookie
*);
28 void (*_soup_cookie_jar_delete_cookie
)(SoupCookieJar
*,
32 u_int32_t swm_debug
= 0
53 GCRY_THREAD_OPTION_PTHREAD_IMPL
;
65 TAILQ_ENTRY(session
) entry
;
68 TAILQ_HEAD(session_list
, session
);
71 RB_ENTRY(domain
) entry
;
73 int handy
; /* app use */
75 RB_HEAD(domain_list
, domain
);
78 TAILQ_ENTRY(undo
) entry
;
81 int back
; /* Keeps track of how many back
82 * history items there are. */
84 TAILQ_HEAD(undo_tailq
, undo
);
88 TAILQ_ENTRY(sp
) entry
;
90 TAILQ_HEAD(sp_list
, sp
);
92 struct command_entry
{
94 TAILQ_ENTRY(command_entry
) entry
;
96 TAILQ_HEAD(command_list
, command_entry
);
99 #define XT_DIR (".xxxterm")
100 #define XT_CACHE_DIR ("cache")
101 #define XT_CERT_DIR ("certs/")
102 #define XT_SESSIONS_DIR ("sessions/")
103 #define XT_CONF_FILE ("xxxterm.conf")
104 #define XT_QMARKS_FILE ("quickmarks")
105 #define XT_SAVED_TABS_FILE ("main_session")
106 #define XT_RESTART_TABS_FILE ("restart_tabs")
107 #define XT_SOCKET_FILE ("socket")
108 #define XT_HISTORY_FILE ("history")
109 #define XT_REJECT_FILE ("rejected.txt")
110 #define XT_COOKIE_FILE ("cookies.txt")
111 #define XT_SAVE_SESSION_ID ("SESSION_NAME=")
112 #define XT_SEARCH_FILE ("search_history")
113 #define XT_COMMAND_FILE ("command_history")
114 #define XT_DLMAN_REFRESH "10"
115 #define XT_MAX_URL_LENGTH (4096) /* 1 page is atomic, don't make bigger */
116 #define XT_MAX_UNDO_CLOSE_TAB (32)
117 #define XT_RESERVED_CHARS "$&+,/:;=?@ \"<>#%%{}|^~[]`"
118 #define XT_PRINT_EXTRA_MARGIN 10
119 #define XT_URL_REGEX ("^[[:blank:]]*[^[:blank:]]*([[:alnum:]-]+\\.)+[[:alnum:]-][^[:blank:]]*[[:blank:]]*$")
120 #define XT_INVALID_MARK (-1) /* XXX this is a double, maybe use something else, like a nan */
123 #define XT_COLOR_RED "#cc0000"
124 #define XT_COLOR_YELLOW "#ffff66"
125 #define XT_COLOR_BLUE "lightblue"
126 #define XT_COLOR_GREEN "#99ff66"
127 #define XT_COLOR_WHITE "white"
128 #define XT_COLOR_BLACK "black"
130 #define XT_COLOR_CT_BACKGROUND "#000000"
131 #define XT_COLOR_CT_INACTIVE "#dddddd"
132 #define XT_COLOR_CT_ACTIVE "#bbbb00"
133 #define XT_COLOR_CT_SEPARATOR "#555555"
135 #define XT_COLOR_SB_SEPARATOR "#555555"
137 #define XT_PROTO_DELIM "://"
140 #define XT_MOVE_INVALID (0)
141 #define XT_MOVE_DOWN (1)
142 #define XT_MOVE_UP (2)
143 #define XT_MOVE_BOTTOM (3)
144 #define XT_MOVE_TOP (4)
145 #define XT_MOVE_PAGEDOWN (5)
146 #define XT_MOVE_PAGEUP (6)
147 #define XT_MOVE_HALFDOWN (7)
148 #define XT_MOVE_HALFUP (8)
149 #define XT_MOVE_LEFT (9)
150 #define XT_MOVE_FARLEFT (10)
151 #define XT_MOVE_RIGHT (11)
152 #define XT_MOVE_FARRIGHT (12)
153 #define XT_MOVE_PERCENT (13)
155 #define XT_QMARK_SET (0)
156 #define XT_QMARK_OPEN (1)
157 #define XT_QMARK_TAB (2)
159 #define XT_MARK_SET (0)
160 #define XT_MARK_GOTO (1)
162 #define XT_TAB_LAST (-4)
163 #define XT_TAB_FIRST (-3)
164 #define XT_TAB_PREV (-2)
165 #define XT_TAB_NEXT (-1)
166 #define XT_TAB_INVALID (0)
167 #define XT_TAB_NEW (1)
168 #define XT_TAB_DELETE (2)
169 #define XT_TAB_DELQUIT (3)
170 #define XT_TAB_OPEN (4)
171 #define XT_TAB_UNDO_CLOSE (5)
172 #define XT_TAB_SHOW (6)
173 #define XT_TAB_HIDE (7)
174 #define XT_TAB_NEXTSTYLE (8)
176 #define XT_NAV_INVALID (0)
177 #define XT_NAV_BACK (1)
178 #define XT_NAV_FORWARD (2)
179 #define XT_NAV_RELOAD (3)
181 #define XT_FOCUS_INVALID (0)
182 #define XT_FOCUS_URI (1)
183 #define XT_FOCUS_SEARCH (2)
185 #define XT_SEARCH_INVALID (0)
186 #define XT_SEARCH_NEXT (1)
187 #define XT_SEARCH_PREV (2)
189 #define XT_PASTE_CURRENT_TAB (0)
190 #define XT_PASTE_NEW_TAB (1)
192 #define XT_ZOOM_IN (-1)
193 #define XT_ZOOM_OUT (-2)
194 #define XT_ZOOM_NORMAL (100)
196 #define XT_URL_SHOW (1)
197 #define XT_URL_HIDE (2)
199 #define XT_WL_TOGGLE (1<<0)
200 #define XT_WL_ENABLE (1<<1)
201 #define XT_WL_DISABLE (1<<2)
202 #define XT_WL_FQDN (1<<3) /* default */
203 #define XT_WL_TOPLEVEL (1<<4)
204 #define XT_WL_PERSISTENT (1<<5)
205 #define XT_WL_SESSION (1<<6)
206 #define XT_WL_RELOAD (1<<7)
208 #define XT_SHOW (1<<7)
209 #define XT_DELETE (1<<8)
210 #define XT_SAVE (1<<9)
211 #define XT_OPEN (1<<10)
213 #define XT_CMD_OPEN (0)
214 #define XT_CMD_OPEN_CURRENT (1)
215 #define XT_CMD_TABNEW (2)
216 #define XT_CMD_TABNEW_CURRENT (3)
218 #define XT_STATUS_NOTHING (0)
219 #define XT_STATUS_LINK (1)
220 #define XT_STATUS_URI (2)
221 #define XT_STATUS_LOADING (3)
223 #define XT_SES_DONOTHING (0)
224 #define XT_SES_CLOSETABS (1)
226 #define XT_BM_NORMAL (0)
227 #define XT_BM_WHITELIST (1)
228 #define XT_BM_KIOSK (2)
230 #define XT_PREFIX (1<<0)
231 #define XT_USERARG (1<<1)
232 #define XT_URLARG (1<<2)
233 #define XT_INTARG (1<<3)
234 #define XT_SESSARG (1<<4)
235 #define XT_SETARG (1<<5)
237 #define XT_HINT_NEWTAB (1<<0)
239 #define XT_MODE_INSERT (0)
240 #define XT_MODE_COMMAND (1)
242 #define XT_TABS_NORMAL 0
243 #define XT_TABS_COMPACT 1
245 #define XT_BUFCMD_SZ (8)
247 #define XT_EJS_SHOW (1<<0)
255 TAILQ_ENTRY(mime_type
) entry
;
257 TAILQ_HEAD(mime_type_list
, mime_type
);
263 TAILQ_ENTRY(alias
) entry
;
265 TAILQ_HEAD(alias_list
, alias
);
267 /* settings that require restart */
268 int tabless
= 0; /* allow only 1 tab */
269 int enable_socket
= 0;
270 int single_instance
= 0; /* only allow one xxxterm to run */
271 int fancy_bar
= 1; /* fancy toolbar */
272 int browser_mode
= XT_BM_NORMAL
;
273 int enable_localstorage
= 1;
274 char *statusbar_elems
= NULL
;
276 /* runtime settings */
277 int show_tabs
= 1; /* show tabs on notebook */
278 int tab_style
= XT_TABS_NORMAL
; /* tab bar style */
279 int show_url
= 1; /* show url toolbar on notebook */
280 int show_statusbar
= 0; /* vimperator style status bar */
281 int ctrl_click_focus
= 0; /* ctrl click gets focus */
282 int cookies_enabled
= 1; /* enable cookies */
283 int read_only_cookies
= 0; /* enable to not write cookies */
284 int enable_scripts
= 1;
285 int enable_plugins
= 1;
286 gfloat default_zoom_level
= 1.0;
287 char default_script
[PATH_MAX
];
288 int window_height
= 768;
289 int window_width
= 1024;
290 int icon_size
= 2; /* 1 = smallest, 2+ = bigger */
291 int refresh_interval
= 10; /* download refresh interval */
292 int enable_plugin_whitelist
= 0;
293 int enable_cookie_whitelist
= 0;
294 int enable_js_whitelist
= 0;
295 int session_timeout
= 3600; /* cookie session timeout */
296 int cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_ALWAYS
;
297 char *ssl_ca_file
= NULL
;
298 char *resource_dir
= NULL
;
299 gboolean ssl_strict_certs
= FALSE
;
300 int append_next
= 1; /* append tab after current tab */
302 char *search_string
= NULL
;
303 char *http_proxy
= NULL
;
304 char download_dir
[PATH_MAX
];
305 char runtime_settings
[PATH_MAX
]; /* override of settings */
306 int allow_volatile_cookies
= 0;
307 int save_global_history
= 0; /* save global history to disk */
308 char *user_agent
= NULL
;
309 int save_rejected_cookies
= 0;
310 int session_autosave
= 0;
311 int guess_search
= 0;
312 int dns_prefetch
= FALSE
;
313 gint max_connections
= 25;
314 gint max_host_connections
= 5;
315 gint enable_spell_checking
= 0;
316 char *spell_check_languages
= NULL
;
317 int xterm_workaround
= 0;
318 char *url_regex
= NULL
;
319 int history_autosave
= 0;
320 char search_file
[PATH_MAX
];
321 char command_file
[PATH_MAX
];
322 char *encoding
= NULL
;
323 int autofocus_onload
= 0;
325 char *cmd_font_name
= NULL
;
326 char *oops_font_name
= NULL
;
327 char *statusbar_font_name
= NULL
;
328 char *tabbar_font_name
= NULL
;
329 PangoFontDescription
*cmd_font
;
330 PangoFontDescription
*oops_font
;
331 PangoFontDescription
*statusbar_font
;
332 PangoFontDescription
*tabbar_font
;
333 char *qmarks
[XT_NOMARKS
];
335 int btn_down
; /* M1 down in any wv */
336 regex_t url_re
; /* guess_search regex */
340 int set_browser_mode(struct settings
*, char *);
341 int set_cookie_policy(struct settings
*, char *);
342 int set_download_dir(struct settings
*, char *);
343 int set_default_script(struct settings
*, char *);
344 int set_runtime_dir(struct settings
*, char *);
345 int set_tab_style(struct settings
*, char *);
346 int set_work_dir(struct settings
*, char *);
347 int add_alias(struct settings
*, char *);
348 int add_mime_type(struct settings
*, char *);
349 int add_cookie_wl(struct settings
*, char *);
350 int add_js_wl(struct settings
*, char *);
351 int add_pl_wl(struct settings
*, char *);
352 int add_kb(struct settings
*, char *);
353 void button_set_stockid(GtkWidget
*, char *);
354 GtkWidget
* create_button(char *, char *, int);
356 char *get_browser_mode(struct settings
*);
357 char *get_cookie_policy(struct settings
*);
358 char *get_download_dir(struct settings
*);
359 char *get_default_script(struct settings
*);
360 char *get_runtime_dir(struct settings
*);
361 char *get_tab_style(struct settings
*);
362 char *get_work_dir(struct settings
*);
363 void startpage_add(const char *, ...);
365 void walk_alias(struct settings
*, void (*)(struct settings
*,
366 char *, void *), void *);
367 void walk_cookie_wl(struct settings
*, void (*)(struct settings
*,
368 char *, void *), void *);
369 void walk_js_wl(struct settings
*, void (*)(struct settings
*,
370 char *, void *), void *);
371 void walk_pl_wl(struct settings
*, void (*)(struct settings
*,
372 char *, void *), void *);
373 void walk_kb(struct settings
*, void (*)(struct settings
*, char *,
375 void walk_mime_type(struct settings
*, void (*)(struct settings
*,
376 char *, void *), void *);
378 void recalc_tabs(void);
379 void recolor_compact_tabs(void);
380 void set_current_tab(int page_num
);
381 gboolean
update_statusbar_position(GtkAdjustment
*, gpointer
);
382 void marks_clear(struct tab
*t
);
384 int set_http_proxy(char *);
387 int (*set
)(struct settings
*, char *);
388 char *(*get
)(struct settings
*);
389 void (*walk
)(struct settings
*,
390 void (*cb
)(struct settings
*, char *, void *),
394 struct special s_browser_mode
= {
400 struct special s_cookie
= {
406 struct special s_alias
= {
412 struct special s_mime
= {
418 struct special s_js
= {
424 struct special s_pl
= {
430 struct special s_kb
= {
436 struct special s_cookie_wl
= {
442 struct special s_default_script
= {
448 struct special s_download_dir
= {
454 struct special s_work_dir
= {
460 struct special s_tab_style
= {
469 #define XT_S_INVALID (0)
472 #define XT_S_FLOAT (3)
474 #define XT_SF_RESTART (1<<0)
475 #define XT_SF_RUNTIME (1<<1)
480 int (*activate
)(char *);
482 { "allow_volatile_cookies", XT_S_INT
, 0, &allow_volatile_cookies
, NULL
, NULL
},
483 { "append_next", XT_S_INT
, 0, &append_next
, NULL
, NULL
},
484 { "autofocus_onload", XT_S_INT
, 0, &autofocus_onload
, NULL
, NULL
},
485 { "browser_mode", XT_S_INT
, 0, NULL
, NULL
,&s_browser_mode
},
486 { "cookie_policy", XT_S_INT
, 0, NULL
, NULL
,&s_cookie
},
487 { "cookies_enabled", XT_S_INT
, 0, &cookies_enabled
, NULL
, NULL
},
488 { "ctrl_click_focus", XT_S_INT
, 0, &ctrl_click_focus
, NULL
, NULL
},
489 { "default_zoom_level", XT_S_FLOAT
, 0, NULL
, NULL
, NULL
, &default_zoom_level
},
490 { "default_script", XT_S_STR
, 0, NULL
, NULL
,&s_default_script
},
491 { "download_dir", XT_S_STR
, 0, NULL
, NULL
,&s_download_dir
},
492 { "enable_cookie_whitelist", XT_S_INT
, 0, &enable_cookie_whitelist
, NULL
, NULL
},
493 { "enable_js_whitelist", XT_S_INT
, 0, &enable_js_whitelist
, NULL
, NULL
},
494 { "enable_plugin_whitelist", XT_S_INT
, 0, &enable_plugin_whitelist
, NULL
, NULL
},
495 { "enable_localstorage", XT_S_INT
, 0, &enable_localstorage
, NULL
, NULL
},
496 { "enable_plugins", XT_S_INT
, 0, &enable_plugins
, NULL
, NULL
},
497 { "enable_scripts", XT_S_INT
, 0, &enable_scripts
, NULL
, NULL
},
498 { "enable_socket", XT_S_INT
, XT_SF_RESTART
,&enable_socket
, NULL
, NULL
},
499 { "enable_spell_checking", XT_S_INT
, 0, &enable_spell_checking
, NULL
, NULL
},
500 { "encoding", XT_S_STR
, 0, NULL
, &encoding
, NULL
},
501 { "fancy_bar", XT_S_INT
, XT_SF_RESTART
,&fancy_bar
, NULL
, NULL
},
502 { "guess_search", XT_S_INT
, 0, &guess_search
, NULL
, NULL
},
503 { "history_autosave", XT_S_INT
, 0, &history_autosave
, NULL
, NULL
},
504 { "home", XT_S_STR
, 0, NULL
, &home
, NULL
},
505 { "http_proxy", XT_S_STR
, 0, NULL
, &http_proxy
, NULL
, NULL
, set_http_proxy
},
506 { "icon_size", XT_S_INT
, 0, &icon_size
, NULL
, NULL
},
507 { "max_connections", XT_S_INT
, XT_SF_RESTART
,&max_connections
, NULL
, NULL
},
508 { "max_host_connections", XT_S_INT
, XT_SF_RESTART
,&max_host_connections
, NULL
, NULL
},
509 { "read_only_cookies", XT_S_INT
, 0, &read_only_cookies
, NULL
, NULL
},
510 { "refresh_interval", XT_S_INT
, 0, &refresh_interval
, NULL
, NULL
},
511 { "resource_dir", XT_S_STR
, 0, NULL
, &resource_dir
, NULL
},
512 { "search_string", XT_S_STR
, 0, NULL
, &search_string
, NULL
},
513 { "save_global_history", XT_S_INT
, XT_SF_RESTART
,&save_global_history
, NULL
, NULL
},
514 { "save_rejected_cookies", XT_S_INT
, XT_SF_RESTART
,&save_rejected_cookies
, NULL
, NULL
},
515 { "session_timeout", XT_S_INT
, 0, &session_timeout
, NULL
, NULL
},
516 { "session_autosave", XT_S_INT
, 0, &session_autosave
, NULL
, NULL
},
517 { "single_instance", XT_S_INT
, XT_SF_RESTART
,&single_instance
, NULL
, NULL
},
518 { "show_tabs", XT_S_INT
, 0, &show_tabs
, NULL
, NULL
},
519 { "show_url", XT_S_INT
, 0, &show_url
, NULL
, NULL
},
520 { "show_statusbar", XT_S_INT
, 0, &show_statusbar
, NULL
, NULL
},
521 { "spell_check_languages", XT_S_STR
, 0, NULL
, &spell_check_languages
, NULL
},
522 { "ssl_ca_file", XT_S_STR
, 0, NULL
, &ssl_ca_file
, NULL
},
523 { "ssl_strict_certs", XT_S_INT
, 0, &ssl_strict_certs
, NULL
, NULL
},
524 { "statusbar_elems", XT_S_STR
, 0, NULL
, &statusbar_elems
, NULL
},
525 { "tab_style", XT_S_STR
, 0, NULL
, NULL
,&s_tab_style
},
526 { "url_regex", XT_S_STR
, 0, NULL
, &url_regex
, NULL
},
527 { "user_agent", XT_S_STR
, 0, NULL
, &user_agent
, NULL
},
528 { "window_height", XT_S_INT
, 0, &window_height
, NULL
, NULL
},
529 { "window_width", XT_S_INT
, 0, &window_width
, NULL
, NULL
},
530 { "work_dir", XT_S_STR
, 0, NULL
, NULL
,&s_work_dir
},
531 { "xterm_workaround", XT_S_INT
, 0, &xterm_workaround
, NULL
, NULL
},
534 { "cmd_font", XT_S_STR
, 0, NULL
, &cmd_font_name
, NULL
},
535 { "oops_font", XT_S_STR
, 0, NULL
, &oops_font_name
, NULL
},
536 { "statusbar_font", XT_S_STR
, 0, NULL
, &statusbar_font_name
, NULL
},
537 { "tabbar_font", XT_S_STR
, 0, NULL
, &tabbar_font_name
, NULL
},
539 /* runtime settings */
540 { "alias", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_alias
},
541 { "cookie_wl", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_cookie_wl
},
542 { "js_wl", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_js
},
543 { "keybinding", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_kb
},
544 { "mime_type", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_mime
},
545 { "pl_wl", XT_S_STR
, XT_SF_RUNTIME
, NULL
, NULL
, &s_pl
},
548 const gchar
*get_uri(struct tab
*);
549 const gchar
*get_title(struct tab
*, bool);
552 extern char *__progname
;
555 GtkWidget
*main_window
;
556 GtkNotebook
*notebook
;
558 GtkWidget
*arrow
, *abtn
;
559 struct tab_list tabs
;
560 struct history_list hl
;
561 struct session_list sessions
;
562 struct domain_list c_wl
;
563 struct domain_list js_wl
;
564 struct domain_list pl_wl
;
565 struct undo_tailq undos
;
566 struct keybinding_list kbl
;
568 struct command_list chl
;
569 struct command_list shl
;
570 struct command_entry
*history_at
;
571 struct command_entry
*search_at
;
573 int cmd_history_count
= 0;
574 int search_history_count
= 0;
576 long long unsigned int blocked_cookies
= 0;
577 char named_session
[PATH_MAX
];
578 GtkListStore
*completion_model
;
579 GtkListStore
*buffers_store
;
581 /* starts from 1 to catch atoi() failures when calling xtp_handle_dl() */
582 int next_download_id
= 1;
584 void xxx_dir(char *);
585 int icon_size_map(int);
586 void completion_add(struct tab
*);
587 void completion_add_uri(const gchar
*);
590 history_delete(struct command_list
*l
, int *counter
)
592 struct command_entry
*c
;
594 if (l
== NULL
|| counter
== NULL
)
597 c
= TAILQ_LAST(l
, command_list
);
601 TAILQ_REMOVE(l
, c
, entry
);
608 history_add(struct command_list
*list
, char *file
, char *l
, int *counter
)
610 struct command_entry
*c
;
613 if (list
== NULL
|| l
== NULL
|| counter
== NULL
)
616 /* don't add the same line */
617 c
= TAILQ_FIRST(list
);
619 if (!strcmp(c
->line
+ 1 /* skip space */, l
))
622 c
= g_malloc0(sizeof *c
);
623 c
->line
= g_strdup_printf(" %s", l
);
626 TAILQ_INSERT_HEAD(list
, c
, entry
);
629 history_delete(list
, counter
);
631 if (history_autosave
&& file
) {
632 f
= fopen(file
, "w");
634 show_oops(NULL
, "couldn't write history %s", file
);
638 TAILQ_FOREACH_REVERSE(c
, list
, command_list
, entry
) {
640 fprintf(f
, "%s\n", c
->line
);
648 history_read(struct command_list
*list
, char *file
, int *counter
)
651 char *s
, line
[65536];
653 if (list
== NULL
|| file
== NULL
)
656 f
= fopen(file
, "r");
658 startpage_add("couldn't open history file %s", file
);
663 s
= fgets(line
, sizeof line
, f
);
664 if (s
== NULL
|| feof(f
) || ferror(f
))
666 if ((s
= strchr(line
, '\n')) == NULL
) {
667 startpage_add("invalid history file %s", file
);
673 history_add(list
, NULL
, line
+ 1, counter
);
681 /* marks and quickmarks array storage.
682 * first a-z, then A-Z, then 0-9 */
689 if (i
>= 0 && i
<= 'z' - 'a')
693 if (i
>= 0 && i
<= 'Z' - 'A')
708 if (m
>= 'a' && m
<= 'z')
709 return ret
+ m
- 'a';
711 ret
+= 'z' - 'a' + 1;
712 if (m
>= 'A' && m
<= 'Z')
713 return ret
+ m
- 'A';
715 ret
+= 'Z' - 'A' + 1;
716 if (m
>= '0' && m
<= '9')
717 return ret
+ m
- '0';
726 int saved_errno
, status
;
731 while ((pid
= waitpid(WAIT_ANY
, &status
, WNOHANG
)) != 0) {
735 if (errno
!= ECHILD
) {
737 clog_warn("sigchild: waitpid:");
743 if (WIFEXITED(status
)) {
744 if (WEXITSTATUS(status
) != 0) {
746 clog_warnx("sigchild: child exit status: %d",
747 WEXITSTATUS(status));
752 clog_warnx("sigchild: child is terminated abnormally");
761 is_g_object_setting(GObject
*o
, char *str
)
763 guint n_props
= 0, i
;
764 GParamSpec
**proplist
;
766 if (! G_IS_OBJECT(o
))
769 proplist
= g_object_class_list_properties(G_OBJECT_GET_CLASS(o
),
772 for (i
=0; i
< n_props
; i
++) {
773 if (! strcmp(proplist
[i
]->name
, str
))
780 get_current_tab(void)
784 TAILQ_FOREACH(t
, &tabs
, entry
) {
785 if (t
->tab_id
== gtk_notebook_get_current_page(notebook
))
789 warnx("%s: no current tab", __func__
);
795 set_status(struct tab
*t
, gchar
*s
, int status
)
803 case XT_STATUS_LOADING
:
804 type
= g_strdup_printf("Loading: %s", s
);
808 type
= g_strdup_printf("Link: %s", s
);
810 t
->status
= g_strdup(gtk_entry_get_text(
811 GTK_ENTRY(t
->sbe
.statusbar
)));
815 type
= g_strdup_printf("%s", s
);
817 t
->status
= g_strdup(type
);
821 t
->status
= g_strdup(s
);
823 case XT_STATUS_NOTHING
:
828 gtk_entry_set_text(GTK_ENTRY(t
->sbe
.statusbar
), s
);
834 hide_cmd(struct tab
*t
)
836 history_at
= NULL
; /* just in case */
837 search_at
= NULL
; /* just in case */
838 gtk_widget_hide(t
->cmd
);
842 show_cmd(struct tab
*t
)
846 gtk_widget_hide(t
->oops
);
847 gtk_widget_show(t
->cmd
);
851 hide_buffers(struct tab
*t
)
853 gtk_widget_hide(t
->buffers
);
854 gtk_list_store_clear(buffers_store
);
864 sort_tabs_by_page_num(struct tab
***stabs
)
869 num_tabs
= gtk_notebook_get_n_pages(notebook
);
871 *stabs
= g_malloc0(num_tabs
* sizeof(struct tab
*));
873 TAILQ_FOREACH(t
, &tabs
, entry
)
874 (*stabs
)[gtk_notebook_page_num(notebook
, t
->vbox
)] = t
;
880 buffers_make_list(void)
883 const gchar
*title
= NULL
;
885 struct tab
**stabs
= NULL
;
887 num_tabs
= sort_tabs_by_page_num(&stabs
);
889 for (i
= 0; i
< num_tabs
; i
++)
891 gtk_list_store_append(buffers_store
, &iter
);
892 title
= get_title(stabs
[i
], FALSE
);
893 gtk_list_store_set(buffers_store
, &iter
,
894 COL_ID
, i
+ 1, /* Enumerate the tabs starting from 1
904 show_buffers(struct tab
*t
)
907 gtk_widget_show(t
->buffers
);
908 gtk_widget_grab_focus(GTK_WIDGET(t
->buffers
));
912 toggle_buffers(struct tab
*t
)
914 if (gtk_widget_get_visible(t
->buffers
))
921 buffers(struct tab
*t
, struct karg
*args
)
929 hide_oops(struct tab
*t
)
931 gtk_widget_hide(t
->oops
);
935 show_oops(struct tab
*at
, const char *fmt
, ...)
939 struct tab
*t
= NULL
;
945 if ((t
= get_current_tab()) == NULL
)
951 if (vasprintf(&msg
, fmt
, ap
) == -1)
952 errx(1, "show_oops failed");
955 gtk_entry_set_text(GTK_ENTRY(t
->oops
), msg
);
956 gtk_widget_hide(t
->cmd
);
957 gtk_widget_show(t
->oops
);
964 get_as_string(struct settings
*s
)
975 warnx("get_as_string skip %s\n", s
->name
);
976 } else if (s
->type
== XT_S_INT
)
977 r
= g_strdup_printf("%d", *s
->ival
);
978 else if (s
->type
== XT_S_STR
)
979 r
= g_strdup(*s
->sval
);
980 else if (s
->type
== XT_S_FLOAT
)
981 r
= g_strdup_printf("%f", *s
->fval
);
983 r
= g_strdup_printf("INVALID TYPE");
989 settings_walk(void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
994 for (i
= 0; i
< LENGTH(rs
); i
++) {
995 if (rs
[i
].s
&& rs
[i
].s
->walk
)
996 rs
[i
].s
->walk(&rs
[i
], cb
, cb_args
);
998 s
= get_as_string(&rs
[i
]);
999 cb(&rs
[i
], s
, cb_args
);
1006 set_browser_mode(struct settings
*s
, char *val
)
1008 if (!strcmp(val
, "whitelist")) {
1009 browser_mode
= XT_BM_WHITELIST
;
1010 allow_volatile_cookies
= 0;
1011 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY
;
1012 cookies_enabled
= 1;
1013 enable_cookie_whitelist
= 1;
1014 enable_plugin_whitelist
= 1;
1016 read_only_cookies
= 0;
1017 save_rejected_cookies
= 0;
1018 session_timeout
= 3600;
1020 enable_js_whitelist
= 1;
1021 enable_localstorage
= 0;
1022 } else if (!strcmp(val
, "normal")) {
1023 browser_mode
= XT_BM_NORMAL
;
1024 allow_volatile_cookies
= 0;
1025 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_ALWAYS
;
1026 cookies_enabled
= 1;
1027 enable_cookie_whitelist
= 0;
1028 enable_plugin_whitelist
= 0;
1030 read_only_cookies
= 0;
1031 save_rejected_cookies
= 0;
1032 session_timeout
= 3600;
1034 enable_js_whitelist
= 0;
1035 enable_localstorage
= 1;
1036 } else if (!strcmp(val
, "kiosk")) {
1037 browser_mode
= XT_BM_KIOSK
;
1038 allow_volatile_cookies
= 0;
1039 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_ALWAYS
;
1040 cookies_enabled
= 1;
1041 enable_cookie_whitelist
= 0;
1042 enable_plugin_whitelist
= 0;
1044 read_only_cookies
= 0;
1045 save_rejected_cookies
= 0;
1046 session_timeout
= 3600;
1048 enable_js_whitelist
= 0;
1049 enable_localstorage
= 1;
1059 get_browser_mode(struct settings
*s
)
1063 if (browser_mode
== XT_BM_WHITELIST
)
1064 r
= g_strdup("whitelist");
1065 else if (browser_mode
== XT_BM_NORMAL
)
1066 r
= g_strdup("normal");
1067 else if (browser_mode
== XT_BM_KIOSK
)
1068 r
= g_strdup("kiosk");
1076 set_cookie_policy(struct settings
*s
, char *val
)
1078 if (!strcmp(val
, "no3rdparty"))
1079 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY
;
1080 else if (!strcmp(val
, "accept"))
1081 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_ALWAYS
;
1082 else if (!strcmp(val
, "reject"))
1083 cookie_policy
= SOUP_COOKIE_JAR_ACCEPT_NEVER
;
1091 get_cookie_policy(struct settings
*s
)
1095 if (cookie_policy
== SOUP_COOKIE_JAR_ACCEPT_NO_THIRD_PARTY
)
1096 r
= g_strdup("no3rdparty");
1097 else if (cookie_policy
== SOUP_COOKIE_JAR_ACCEPT_ALWAYS
)
1098 r
= g_strdup("accept");
1099 else if (cookie_policy
== SOUP_COOKIE_JAR_ACCEPT_NEVER
)
1100 r
= g_strdup("reject");
1108 get_default_script(struct settings
*s
)
1110 if (default_script
[0] == '\0')
1112 return (g_strdup(default_script
));
1116 set_default_script(struct settings
*s
, char *val
)
1119 snprintf(default_script
, sizeof default_script
, "%s/%s",
1120 pwd
->pw_dir
, &val
[1]);
1122 strlcpy(default_script
, val
, sizeof default_script
);
1128 get_download_dir(struct settings
*s
)
1130 if (download_dir
[0] == '\0')
1132 return (g_strdup(download_dir
));
1136 set_download_dir(struct settings
*s
, char *val
)
1139 snprintf(download_dir
, sizeof download_dir
, "%s/%s",
1140 pwd
->pw_dir
, &val
[1]);
1142 strlcpy(download_dir
, val
, sizeof download_dir
);
1147 char work_dir
[PATH_MAX
];
1148 char certs_dir
[PATH_MAX
];
1149 char cache_dir
[PATH_MAX
];
1150 char sessions_dir
[PATH_MAX
];
1151 char cookie_file
[PATH_MAX
];
1152 SoupURI
*proxy_uri
= NULL
;
1153 SoupSession
*session
;
1154 SoupCookieJar
*s_cookiejar
;
1155 SoupCookieJar
*p_cookiejar
;
1156 char rc_fname
[PATH_MAX
];
1158 struct mime_type_list mtl
;
1159 struct alias_list aliases
;
1162 struct tab
*create_new_tab(char *, struct undo
*, int, int);
1163 void delete_tab(struct tab
*);
1164 void setzoom_webkit(struct tab
*, int);
1165 int run_script(struct tab
*, char *);
1166 int download_rb_cmp(struct download
*, struct download
*);
1167 gboolean
cmd_execute(struct tab
*t
, char *str
);
1170 history_rb_cmp(struct history
*h1
, struct history
*h2
)
1172 return (strcmp(h1
->uri
, h2
->uri
));
1174 RB_GENERATE(history_list
, history
, entry
, history_rb_cmp
);
1177 domain_rb_cmp(struct domain
*d1
, struct domain
*d2
)
1179 return (strcmp(d1
->d
, d2
->d
));
1181 RB_GENERATE(domain_list
, domain
, entry
, domain_rb_cmp
);
1184 get_work_dir(struct settings
*s
)
1186 if (work_dir
[0] == '\0')
1188 return (g_strdup(work_dir
));
1192 set_work_dir(struct settings
*s
, char *val
)
1195 snprintf(work_dir
, sizeof work_dir
, "%s/%s",
1196 pwd
->pw_dir
, &val
[1]);
1198 strlcpy(work_dir
, val
, sizeof work_dir
);
1204 get_tab_style(struct settings
*s
)
1206 if (tab_style
== XT_TABS_NORMAL
)
1207 return (g_strdup("normal"));
1209 return (g_strdup("compact"));
1213 set_tab_style(struct settings
*s
, char *val
)
1215 if (!strcmp(val
, "normal"))
1216 tab_style
= XT_TABS_NORMAL
;
1217 else if (!strcmp(val
, "compact"))
1218 tab_style
= XT_TABS_COMPACT
;
1226 download_rb_cmp(struct download
*e1
, struct download
*e2
)
1228 return (e1
->id
< e2
->id
? -1 : e1
->id
> e2
->id
);
1230 RB_GENERATE(download_list
, download
, entry
, download_rb_cmp
);
1232 struct valid_url_types
{
1243 valid_url_type(char *url
)
1247 for (i
= 0; i
< LENGTH(vut
); i
++)
1248 if (!strncasecmp(vut
[i
].type
, url
, strlen(vut
[i
].type
)))
1255 print_cookie(char *msg
, SoupCookie
*c
)
1261 DNPRINTF(XT_D_COOKIE
, "%s\n", msg
);
1262 DNPRINTF(XT_D_COOKIE
, "name : %s\n", c
->name
);
1263 DNPRINTF(XT_D_COOKIE
, "value : %s\n", c
->value
);
1264 DNPRINTF(XT_D_COOKIE
, "domain : %s\n", c
->domain
);
1265 DNPRINTF(XT_D_COOKIE
, "path : %s\n", c
->path
);
1266 DNPRINTF(XT_D_COOKIE
, "expires : %s\n",
1267 c
->expires
? soup_date_to_string(c
->expires
, SOUP_DATE_HTTP
) : "");
1268 DNPRINTF(XT_D_COOKIE
, "secure : %d\n", c
->secure
);
1269 DNPRINTF(XT_D_COOKIE
, "http_only: %d\n", c
->http_only
);
1270 DNPRINTF(XT_D_COOKIE
, "====================================\n");
1274 walk_alias(struct settings
*s
,
1275 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1280 if (s
== NULL
|| cb
== NULL
) {
1281 show_oops(NULL
, "walk_alias invalid parameters");
1285 TAILQ_FOREACH(a
, &aliases
, entry
) {
1286 str
= g_strdup_printf("%s --> %s", a
->a_name
, a
->a_uri
);
1287 cb(s
, str
, cb_args
);
1293 match_alias(char *url_in
)
1297 char *url_out
= NULL
, *search
, *enc_arg
;
1299 search
= g_strdup(url_in
);
1301 if (strsep(&arg
, " \t") == NULL
) {
1302 show_oops(NULL
, "match_alias: NULL URL");
1306 TAILQ_FOREACH(a
, &aliases
, entry
) {
1307 if (!strcmp(search
, a
->a_name
))
1312 DNPRINTF(XT_D_URL
, "match_alias: matched alias %s\n",
1315 enc_arg
= soup_uri_encode(arg
, XT_RESERVED_CHARS
);
1316 url_out
= g_strdup_printf(a
->a_uri
, enc_arg
);
1319 url_out
= g_strdup_printf(a
->a_uri
, "");
1327 guess_url_type(char *url_in
)
1330 char *url_out
= NULL
, *enc_search
= NULL
;
1333 /* substitute aliases */
1334 url_out
= match_alias(url_in
);
1335 if (url_out
!= NULL
)
1338 /* see if we are an about page */
1339 if (!strncmp(url_in
, XT_URI_ABOUT
, XT_URI_ABOUT_LEN
))
1340 for (i
= 0; i
< about_list_size(); i
++)
1341 if (!strcmp(&url_in
[XT_URI_ABOUT_LEN
],
1342 about_list
[i
].name
)) {
1343 url_out
= g_strdup(url_in
);
1347 if (guess_search
&& url_regex
&&
1348 !(g_str_has_prefix(url_in
, "http://") ||
1349 g_str_has_prefix(url_in
, "https://"))) {
1350 if (regexec(&url_re
, url_in
, 0, NULL
, 0)) {
1351 /* invalid URI so search instead */
1352 enc_search
= soup_uri_encode(url_in
, XT_RESERVED_CHARS
);
1353 url_out
= g_strdup_printf(search_string
, enc_search
);
1359 /* XXX not sure about this heuristic */
1360 if (stat(url_in
, &sb
) == 0)
1361 url_out
= g_strdup_printf("file://%s", url_in
);
1363 url_out
= g_strdup_printf("http://%s", url_in
); /* guess http */
1365 DNPRINTF(XT_D_URL
, "guess_url_type: guessed %s\n", url_out
);
1371 load_uri(struct tab
*t
, gchar
*uri
)
1374 gchar
*newuri
= NULL
;
1380 /* Strip leading spaces. */
1381 while (*uri
&& isspace(*uri
))
1384 if (strlen(uri
) == 0) {
1389 t
->xtp_meaning
= XT_XTP_TAB_MEANING_NORMAL
;
1391 if (valid_url_type(uri
)) {
1392 newuri
= guess_url_type(uri
);
1396 if (!strncmp(uri
, XT_URI_ABOUT
, XT_URI_ABOUT_LEN
)) {
1397 for (i
= 0; i
< about_list_size(); i
++)
1398 if (!strcmp(&uri
[XT_URI_ABOUT_LEN
], about_list
[i
].name
)) {
1399 bzero(&args
, sizeof args
);
1400 about_list
[i
].func(t
, &args
);
1401 gtk_widget_set_sensitive(GTK_WIDGET(t
->stop
),
1405 show_oops(t
, "invalid about page");
1409 set_status(t
, (char *)uri
, XT_STATUS_LOADING
);
1411 webkit_web_view_load_uri(t
->wv
, uri
);
1418 get_uri(struct tab
*t
)
1420 const gchar
*uri
= NULL
;
1422 if (webkit_web_view_get_load_status(t
->wv
) == WEBKIT_LOAD_FAILED
)
1424 if (t
->xtp_meaning
== XT_XTP_TAB_MEANING_NORMAL
) {
1425 uri
= webkit_web_view_get_uri(t
->wv
);
1427 /* use tmp_uri to make sure it is g_freed */
1430 t
->tmp_uri
=g_strdup_printf("%s%s", XT_URI_ABOUT
,
1431 about_list
[t
->xtp_meaning
].name
);
1438 get_title(struct tab
*t
, bool window
)
1440 const gchar
*set
= NULL
, *title
= NULL
;
1441 WebKitLoadStatus status
= webkit_web_view_get_load_status(t
->wv
);
1443 if (status
== WEBKIT_LOAD_PROVISIONAL
|| status
== WEBKIT_LOAD_FAILED
||
1444 t
->xtp_meaning
== XT_XTP_TAB_MEANING_BL
)
1447 title
= webkit_web_view_get_title(t
->wv
);
1448 if ((set
= title
? title
: get_uri(t
)))
1452 set
= window
? XT_NAME
: "(untitled)";
1458 add_alias(struct settings
*s
, char *line
)
1461 struct alias
*a
= NULL
;
1463 if (s
== NULL
|| line
== NULL
) {
1464 show_oops(NULL
, "add_alias invalid parameters");
1469 a
= g_malloc(sizeof(*a
));
1471 if ((alias
= strsep(&l
, " \t,")) == NULL
|| l
== NULL
) {
1472 show_oops(NULL
, "add_alias: incomplete alias definition");
1475 if (strlen(alias
) == 0 || strlen(l
) == 0) {
1476 show_oops(NULL
, "add_alias: invalid alias definition");
1480 a
->a_name
= g_strdup(alias
);
1481 a
->a_uri
= g_strdup(l
);
1483 DNPRINTF(XT_D_CONFIG
, "add_alias: %s for %s\n", a
->a_name
, a
->a_uri
);
1485 TAILQ_INSERT_TAIL(&aliases
, a
, entry
);
1495 add_mime_type(struct settings
*s
, char *line
)
1499 struct mime_type
*m
= NULL
;
1500 int downloadfirst
= 0;
1502 /* XXX this could be smarter */
1504 if (line
== NULL
|| strlen(line
) == 0) {
1505 show_oops(NULL
, "add_mime_type invalid parameters");
1514 m
= g_malloc(sizeof(*m
));
1516 if ((mime_type
= strsep(&l
, " \t,")) == NULL
|| l
== NULL
) {
1517 show_oops(NULL
, "add_mime_type: invalid mime_type");
1520 if (mime_type
[strlen(mime_type
) - 1] == '*') {
1521 mime_type
[strlen(mime_type
) - 1] = '\0';
1526 if (strlen(mime_type
) == 0 || strlen(l
) == 0) {
1527 show_oops(NULL
, "add_mime_type: invalid mime_type");
1531 m
->mt_type
= g_strdup(mime_type
);
1532 m
->mt_action
= g_strdup(l
);
1533 m
->mt_download
= downloadfirst
;
1535 DNPRINTF(XT_D_CONFIG
, "add_mime_type: type %s action %s default %d\n",
1536 m
->mt_type
, m
->mt_action
, m
->mt_default
);
1538 TAILQ_INSERT_TAIL(&mtl
, m
, entry
);
1548 find_mime_type(char *mime_type
)
1550 struct mime_type
*m
, *def
= NULL
, *rv
= NULL
;
1552 TAILQ_FOREACH(m
, &mtl
, entry
) {
1553 if (m
->mt_default
&&
1554 !strncmp(mime_type
, m
->mt_type
, strlen(m
->mt_type
)))
1557 if (m
->mt_default
== 0 && !strcmp(mime_type
, m
->mt_type
)) {
1570 walk_mime_type(struct settings
*s
,
1571 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1573 struct mime_type
*m
;
1576 if (s
== NULL
|| cb
== NULL
) {
1577 show_oops(NULL
, "walk_mime_type invalid parameters");
1581 TAILQ_FOREACH(m
, &mtl
, entry
) {
1582 str
= g_strdup_printf("%s%s --> %s",
1584 m
->mt_default
? "*" : "",
1586 cb(s
, str
, cb_args
);
1592 wl_add(char *str
, struct domain_list
*wl
, int handy
)
1598 if (str
== NULL
|| wl
== NULL
|| strlen(str
) < 2)
1601 DNPRINTF(XT_D_COOKIE
, "wl_add in: %s\n", str
);
1603 /* treat *.moo.com the same as .moo.com */
1604 if (str
[0] == '*' && str
[1] == '.')
1606 else if (str
[0] == '.')
1611 /* slice off port number */
1612 p
= g_strrstr(str
, ":");
1616 d
= g_malloc(sizeof *d
);
1618 d
->d
= g_strdup_printf(".%s", str
);
1620 d
->d
= g_strdup(str
);
1623 if (RB_INSERT(domain_list
, wl
, d
))
1626 DNPRINTF(XT_D_COOKIE
, "wl_add: %s\n", d
->d
);
1637 add_cookie_wl(struct settings
*s
, char *entry
)
1639 wl_add(entry
, &c_wl
, 1);
1644 walk_cookie_wl(struct settings
*s
,
1645 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1649 if (s
== NULL
|| cb
== NULL
) {
1650 show_oops(NULL
, "walk_cookie_wl invalid parameters");
1654 RB_FOREACH_REVERSE(d
, domain_list
, &c_wl
)
1655 cb(s
, d
->d
, cb_args
);
1659 walk_js_wl(struct settings
*s
,
1660 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1664 if (s
== NULL
|| cb
== NULL
) {
1665 show_oops(NULL
, "walk_js_wl invalid parameters");
1669 RB_FOREACH_REVERSE(d
, domain_list
, &js_wl
)
1670 cb(s
, d
->d
, cb_args
);
1674 add_js_wl(struct settings
*s
, char *entry
)
1676 wl_add(entry
, &js_wl
, 1 /* persistent */);
1681 walk_pl_wl(struct settings
*s
,
1682 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
1686 if (s
== NULL
|| cb
== NULL
) {
1687 show_oops(NULL
, "walk_pl_wl invalid parameters");
1691 RB_FOREACH_REVERSE(d
, domain_list
, &pl_wl
)
1692 cb(s
, d
->d
, cb_args
);
1696 add_pl_wl(struct settings
*s
, char *entry
)
1698 wl_add(entry
, &pl_wl
, 1 /* persistent */);
1703 wl_find(const gchar
*search
, struct domain_list
*wl
)
1706 struct domain
*d
= NULL
, dfind
;
1709 if (search
== NULL
|| wl
== NULL
)
1711 if (strlen(search
) < 2)
1714 if (search
[0] != '.')
1715 s
= g_strdup_printf(".%s", search
);
1717 s
= g_strdup(search
);
1719 for (i
= strlen(s
) - 1; i
>= 0; i
--) {
1722 d
= RB_FIND(domain_list
, wl
, &dfind
);
1736 wl_find_uri(const gchar
*s
, struct domain_list
*wl
)
1742 if (s
== NULL
|| wl
== NULL
)
1745 if (!strncmp(s
, "http://", strlen("http://")))
1746 s
= &s
[strlen("http://")];
1747 else if (!strncmp(s
, "https://", strlen("https://")))
1748 s
= &s
[strlen("https://")];
1753 for (i
= 0; i
< strlen(s
) + 1 /* yes er need this */; i
++)
1754 /* chop string at first slash */
1755 if (s
[i
] == '/' || s
[i
] == ':' || s
[i
] == '\0') {
1758 r
= wl_find(ss
, wl
);
1767 settings_add(char *var
, char *val
)
1774 for (i
= 0, rv
= 0; i
< LENGTH(rs
); i
++) {
1775 if (strcmp(var
, rs
[i
].name
))
1779 if (rs
[i
].s
->set(&rs
[i
], val
))
1780 errx(1, "invalid value for %s: %s", var
, val
);
1784 switch (rs
[i
].type
) {
1793 errx(1, "invalid sval for %s",
1807 errx(1, "invalid type for %s", var
);
1816 config_parse(char *filename
, int runtime
)
1819 char *line
, *cp
, *var
, *val
;
1820 size_t len
, lineno
= 0;
1822 char file
[PATH_MAX
];
1825 DNPRINTF(XT_D_CONFIG
, "config_parse: filename %s\n", filename
);
1827 if (filename
== NULL
)
1830 if (runtime
&& runtime_settings
[0] != '\0') {
1831 snprintf(file
, sizeof file
, "%s/%s",
1832 work_dir
, runtime_settings
);
1833 if (stat(file
, &sb
)) {
1834 warnx("runtime file doesn't exist, creating it");
1835 if ((f
= fopen(file
, "w")) == NULL
)
1837 fprintf(f
, "# AUTO GENERATED, DO NOT EDIT\n");
1841 strlcpy(file
, filename
, sizeof file
);
1843 if ((config
= fopen(file
, "r")) == NULL
) {
1844 warn("config_parse: cannot open %s", filename
);
1849 if ((line
= fparseln(config
, &len
, &lineno
, NULL
, 0)) == NULL
)
1850 if (feof(config
) || ferror(config
))
1854 cp
+= (long)strspn(cp
, WS
);
1855 if (cp
[0] == '\0') {
1861 if ((var
= strsep(&cp
, WS
)) == NULL
|| cp
== NULL
)
1862 startpage_add("invalid configuration file entry: %s",
1865 cp
+= (long)strspn(cp
, WS
);
1867 if ((val
= strsep(&cp
, "\0")) == NULL
)
1870 DNPRINTF(XT_D_CONFIG
, "config_parse: %s=%s\n",
1872 handled
= settings_add(var
, val
);
1875 startpage_add("invalid configuration file entry"
1876 ": %s=%s", var
, val
);
1886 js_ref_to_string(JSContextRef context
, JSValueRef ref
)
1892 jsref
= JSValueToStringCopy(context
, ref
, NULL
);
1896 l
= JSStringGetMaximumUTF8CStringSize(jsref
);
1899 JSStringGetUTF8CString(jsref
, s
, l
);
1900 JSStringRelease(jsref
);
1906 disable_hints(struct tab
*t
)
1908 DNPRINTF(XT_D_JS
, "%s\n", __func__
);
1910 run_script(t
, "hints.clearHints();");
1916 enable_hints(struct tab
*t
)
1918 DNPRINTF(XT_D_JS
, "%s\n", __func__
);
1920 run_script(t
, JS_HINTING
);
1923 run_script(t
, "hints.createHints('', 'F');");
1925 run_script(t
, "hints.createHints('', 'f');");
1929 #define XT_JS_DONE ("done;")
1930 #define XT_JS_DONE_LEN (strlen(XT_JS_DONE))
1931 #define XT_JS_INSERT ("insert;")
1932 #define XT_JS_INSERT_LEN (strlen(XT_JS_INSERT))
1935 run_script(struct tab
*t
, char *s
)
1937 JSGlobalContextRef ctx
;
1938 WebKitWebFrame
*frame
;
1940 JSValueRef val
, exception
;
1943 DNPRINTF(XT_D_JS
, "run_script: tab %d %s\n",
1944 t
->tab_id
, s
== (char *)JS_HINTING
? "JS_HINTING" : s
);
1946 /* a bit silly but it prevents some heartburn */
1947 if (t
->script_init
== 0) {
1949 run_script(t
, JS_HINTING
);
1952 frame
= webkit_web_view_get_main_frame(t
->wv
);
1953 ctx
= webkit_web_frame_get_global_context(frame
);
1955 str
= JSStringCreateWithUTF8CString(s
);
1956 val
= JSEvaluateScript(ctx
, str
, JSContextGetGlobalObject(ctx
),
1957 NULL
, 0, &exception
);
1958 JSStringRelease(str
);
1960 DNPRINTF(XT_D_JS
, "run_script: val %p\n", val
);
1962 es
= js_ref_to_string(ctx
, exception
);
1964 /* show_oops(t, "script exception: %s", es); */
1965 DNPRINTF(XT_D_JS
, "run_script: exception %s\n", es
);
1970 es
= js_ref_to_string(ctx
, val
);
1973 if (!strncmp(es
, XT_JS_DONE
, XT_JS_DONE_LEN
))
1975 if (!strncmp(es
, XT_JS_INSERT
, XT_JS_INSERT_LEN
))
1979 DNPRINTF(XT_D_JS
, "run_script: val %s\n", es
);
1988 hint(struct tab
*t
, struct karg
*args
)
1991 DNPRINTF(XT_D_JS
, "hint: tab %d args %d\n", t
->tab_id
, args
->i
);
1993 if (t
->hints_on
== 0) {
1994 if (args
->i
== XT_HINT_NEWTAB
)
2004 apply_style(struct tab
*t
)
2006 g_object_set(G_OBJECT(t
->settings
),
2007 "user-stylesheet-uri", t
->stylesheet
, (char *)NULL
);
2011 userstyle(struct tab
*t
, struct karg
*args
)
2013 DNPRINTF(XT_D_JS
, "userstyle: tab %d\n", t
->tab_id
);
2017 g_object_set(G_OBJECT(t
->settings
),
2018 "user-stylesheet-uri", NULL
, (char *)NULL
);
2027 * Doesn't work fully, due to the following bug:
2028 * https://bugs.webkit.org/show_bug.cgi?id=51747
2031 restore_global_history(void)
2033 char file
[PATH_MAX
];
2038 const char delim
[3] = {'\\', '\\', '\0'};
2040 snprintf(file
, sizeof file
, "%s/%s", work_dir
, XT_HISTORY_FILE
);
2042 if ((f
= fopen(file
, "r")) == NULL
) {
2043 warnx("%s: fopen", __func__
);
2048 if ((uri
= fparseln(f
, NULL
, NULL
, delim
, 0)) == NULL
)
2049 if (feof(f
) || ferror(f
))
2052 if ((title
= fparseln(f
, NULL
, NULL
, delim
, 0)) == NULL
)
2053 if (feof(f
) || ferror(f
)) {
2055 warnx("%s: broken history file\n", __func__
);
2059 if (uri
&& strlen(uri
) && title
&& strlen(title
)) {
2060 webkit_web_history_item_new_with_data(uri
, title
);
2061 h
= g_malloc(sizeof(struct history
));
2062 h
->uri
= g_strdup(uri
);
2063 h
->title
= g_strdup(title
);
2064 RB_INSERT(history_list
, &hl
, h
);
2065 completion_add_uri(h
->uri
);
2067 warnx("%s: failed to restore history\n", __func__
);
2083 save_global_history_to_disk(struct tab
*t
)
2085 char file
[PATH_MAX
];
2089 snprintf(file
, sizeof file
, "%s/%s", work_dir
, XT_HISTORY_FILE
);
2091 if ((f
= fopen(file
, "w")) == NULL
) {
2092 show_oops(t
, "%s: global history file: %s",
2093 __func__
, strerror(errno
));
2097 RB_FOREACH_REVERSE(h
, history_list
, &hl
) {
2098 if (h
->uri
&& h
->title
)
2099 fprintf(f
, "%s\n%s\n", h
->uri
, h
->title
);
2108 quit(struct tab
*t
, struct karg
*args
)
2110 if (save_global_history
)
2111 save_global_history_to_disk(t
);
2119 restore_sessions_list(void)
2122 struct dirent
*dp
= NULL
;
2125 sdir
= opendir(sessions_dir
);
2127 while ((dp
= readdir(sdir
)) != NULL
)
2128 if (dp
->d_type
== DT_REG
) {
2129 s
= g_malloc(sizeof(struct session
));
2130 s
->name
= g_strdup(dp
->d_name
);
2131 TAILQ_INSERT_TAIL(&sessions
, s
, entry
);
2138 open_tabs(struct tab
*t
, struct karg
*a
)
2140 char file
[PATH_MAX
];
2144 struct tab
*ti
, *tt
;
2149 ti
= TAILQ_LAST(&tabs
, tab_list
);
2151 snprintf(file
, sizeof file
, "%s/%s", sessions_dir
, a
->s
);
2152 if ((f
= fopen(file
, "r")) == NULL
)
2156 if ((uri
= fparseln(f
, NULL
, NULL
, "\0\0\0", 0)) == NULL
)
2157 if (feof(f
) || ferror(f
))
2160 /* retrieve session name */
2161 if (uri
&& g_str_has_prefix(uri
, XT_SAVE_SESSION_ID
)) {
2162 strlcpy(named_session
,
2163 &uri
[strlen(XT_SAVE_SESSION_ID
)],
2164 sizeof named_session
);
2168 if (uri
&& strlen(uri
))
2169 create_new_tab(uri
, NULL
, 1, -1);
2175 /* close open tabs */
2176 if (a
->i
== XT_SES_CLOSETABS
&& ti
!= NULL
) {
2178 tt
= TAILQ_FIRST(&tabs
);
2199 restore_saved_tabs(void)
2201 char file
[PATH_MAX
];
2202 int unlink_file
= 0;
2207 snprintf(file
, sizeof file
, "%s/%s",
2208 sessions_dir
, XT_RESTART_TABS_FILE
);
2209 if (stat(file
, &sb
) == -1)
2210 a
.s
= XT_SAVED_TABS_FILE
;
2213 a
.s
= XT_RESTART_TABS_FILE
;
2216 a
.i
= XT_SES_DONOTHING
;
2217 rv
= open_tabs(NULL
, &a
);
2226 save_tabs(struct tab
*t
, struct karg
*a
)
2228 char file
[PATH_MAX
];
2230 int num_tabs
= 0, i
;
2231 struct tab
**stabs
= NULL
;
2233 /* tab may be null here */
2238 snprintf(file
, sizeof file
, "%s/%s",
2239 sessions_dir
, named_session
);
2241 snprintf(file
, sizeof file
, "%s/%s", sessions_dir
, a
->s
);
2243 if ((f
= fopen(file
, "w")) == NULL
) {
2244 show_oops(t
, "Can't open save_tabs file: %s", strerror(errno
));
2248 /* save session name */
2249 fprintf(f
, "%s%s\n", XT_SAVE_SESSION_ID
, named_session
);
2251 /* Save tabs, in the order they are arranged in the notebook. */
2252 num_tabs
= sort_tabs_by_page_num(&stabs
);
2254 for (i
= 0; i
< num_tabs
; i
++)
2256 if (get_uri(stabs
[i
]) != NULL
)
2257 fprintf(f
, "%s\n", get_uri(stabs
[i
]));
2258 else if (gtk_entry_get_text(GTK_ENTRY(
2259 stabs
[i
]->uri_entry
)))
2260 fprintf(f
, "%s\n", gtk_entry_get_text(GTK_ENTRY(
2261 stabs
[i
]->uri_entry
)));
2266 /* try and make sure this gets to disk NOW. XXX Backup first? */
2267 if (fflush(f
) != 0 || fsync(fileno(f
)) != 0) {
2268 show_oops(t
, "May not have managed to save session: %s",
2278 save_tabs_and_quit(struct tab
*t
, struct karg
*args
)
2290 run_page_script(struct tab
*t
, struct karg
*args
)
2293 char *tmp
, script
[PATH_MAX
];
2295 tmp
= args
->s
!= NULL
&& strlen(args
->s
) > 0 ? args
->s
: default_script
;
2296 if (tmp
[0] == '\0') {
2297 show_oops(t
, "no script specified");
2301 if ((uri
= get_uri(t
)) == NULL
) {
2302 show_oops(t
, "tab is empty, not running script");
2307 snprintf(script
, sizeof script
, "%s/%s",
2308 pwd
->pw_dir
, &tmp
[1]);
2310 strlcpy(script
, tmp
, sizeof script
);
2314 show_oops(t
, "can't fork to run script");
2324 execlp(script
, script
, uri
, (void *)NULL
);
2334 yank_uri(struct tab
*t
, struct karg
*args
)
2337 GtkClipboard
*clipboard
;
2339 if ((uri
= get_uri(t
)) == NULL
)
2342 clipboard
= gtk_clipboard_get(GDK_SELECTION_PRIMARY
);
2343 gtk_clipboard_set_text(clipboard
, uri
, -1);
2349 paste_uri(struct tab
*t
, struct karg
*args
)
2351 GtkClipboard
*clipboard
;
2352 GdkAtom atom
= gdk_atom_intern("CUT_BUFFER0", FALSE
);
2354 gchar
*p
= NULL
, *uri
;
2356 /* try primary clipboard first */
2357 clipboard
= gtk_clipboard_get(GDK_SELECTION_PRIMARY
);
2358 p
= gtk_clipboard_wait_for_text(clipboard
);
2360 /* if it failed get whatever text is in cut_buffer0 */
2361 if (p
== NULL
&& xterm_workaround
)
2362 if (gdk_property_get(gdk_get_default_root_window(),
2364 gdk_atom_intern("STRING", FALSE
),
2366 1024 * 1024 /* picked out of my butt */,
2372 /* yes sir, we need to NUL the string */
2378 while (*uri
&& isspace(*uri
))
2380 if (strlen(uri
) == 0) {
2381 show_oops(t
, "empty paste buffer");
2384 if (guess_search
== 0 && valid_url_type(uri
)) {
2385 /* we can be clever and paste this in search box */
2386 show_oops(t
, "not a valid URL");
2390 if (args
->i
== XT_PASTE_CURRENT_TAB
)
2392 else if (args
->i
== XT_PASTE_NEW_TAB
)
2393 create_new_tab(uri
, NULL
, 1, -1);
2404 find_domain(const gchar
*s
, int toplevel
)
2412 uri
= soup_uri_new(s
);
2414 if (uri
== NULL
|| !SOUP_URI_VALID_FOR_HTTP(uri
)) {
2418 if (toplevel
&& !isdigit(uri
->host
[strlen(uri
->host
) - 1])) {
2419 if ((p
= strrchr(uri
->host
, '.')) != NULL
) {
2420 while(--p
>= uri
->host
&& *p
!= '.');
2427 ret
= g_strdup_printf(".%s", p
);
2435 toggle_cwl(struct tab
*t
, struct karg
*args
)
2446 dom
= find_domain(uri
, args
->i
& XT_WL_TOPLEVEL
);
2448 if (uri
== NULL
|| dom
== NULL
||
2449 webkit_web_view_get_load_status(t
->wv
) == WEBKIT_LOAD_FAILED
) {
2450 show_oops(t
, "Can't toggle domain in cookie white list");
2453 d
= wl_find(dom
, &c_wl
);
2460 if (args
->i
& XT_WL_TOGGLE
)
2462 else if ((args
->i
& XT_WL_ENABLE
) && es
!= 1)
2464 else if ((args
->i
& XT_WL_DISABLE
) && es
!= 0)
2468 /* enable cookies for domain */
2469 wl_add(dom
, &c_wl
, 0);
2471 /* disable cookies for domain */
2473 RB_REMOVE(domain_list
, &c_wl
, d
);
2476 if (args
->i
& XT_WL_RELOAD
)
2477 webkit_web_view_reload(t
->wv
);
2485 toggle_js(struct tab
*t
, struct karg
*args
)
2495 g_object_get(G_OBJECT(t
->settings
),
2496 "enable-scripts", &es
, (char *)NULL
);
2497 if (args
->i
& XT_WL_TOGGLE
)
2499 else if ((args
->i
& XT_WL_ENABLE
) && es
!= 1)
2501 else if ((args
->i
& XT_WL_DISABLE
) && es
!= 0)
2507 dom
= find_domain(uri
, args
->i
& XT_WL_TOPLEVEL
);
2509 if (uri
== NULL
|| dom
== NULL
||
2510 webkit_web_view_get_load_status(t
->wv
) == WEBKIT_LOAD_FAILED
) {
2511 show_oops(t
, "Can't toggle domain in JavaScript white list");
2516 button_set_stockid(t
->js_toggle
, GTK_STOCK_MEDIA_PLAY
);
2517 wl_add(dom
, &js_wl
, 0 /* session */);
2519 d
= wl_find(dom
, &js_wl
);
2521 RB_REMOVE(domain_list
, &js_wl
, d
);
2522 button_set_stockid(t
->js_toggle
, GTK_STOCK_MEDIA_PAUSE
);
2524 g_object_set(G_OBJECT(t
->settings
),
2525 "enable-scripts", es
, (char *)NULL
);
2526 g_object_set(G_OBJECT(t
->settings
),
2527 "javascript-can-open-windows-automatically", es
, (char *)NULL
);
2528 webkit_web_view_set_settings(t
->wv
, t
->settings
);
2530 if (args
->i
& XT_WL_RELOAD
)
2531 webkit_web_view_reload(t
->wv
);
2539 toggle_pl(struct tab
*t
, struct karg
*args
)
2549 g_object_get(G_OBJECT(t
->settings
),
2550 "enable-plugins", &es
, (char *)NULL
);
2551 if (args
->i
& XT_WL_TOGGLE
)
2553 else if ((args
->i
& XT_WL_ENABLE
) && es
!= 1)
2555 else if ((args
->i
& XT_WL_DISABLE
) && es
!= 0)
2561 dom
= find_domain(uri
, args
->i
& XT_WL_TOPLEVEL
);
2563 if (uri
== NULL
|| dom
== NULL
||
2564 webkit_web_view_get_load_status(t
->wv
) == WEBKIT_LOAD_FAILED
) {
2565 show_oops(t
, "Can't toggle domain in plugins white list");
2570 wl_add(dom
, &pl_wl
, 0 /* session */);
2572 d
= wl_find(dom
, &pl_wl
);
2574 RB_REMOVE(domain_list
, &pl_wl
, d
);
2576 g_object_set(G_OBJECT(t
->settings
),
2577 "enable-plugins", es
, (char *)NULL
);
2578 webkit_web_view_set_settings(t
->wv
, t
->settings
);
2580 if (args
->i
& XT_WL_RELOAD
)
2581 webkit_web_view_reload(t
->wv
);
2589 js_toggle_cb(GtkWidget
*w
, struct tab
*t
)
2594 g_object_get(G_OBJECT(t
->settings
),
2595 "enable-scripts", &es
, (char *)NULL
);
2600 set
= XT_WL_DISABLE
;
2602 a
.i
= set
| XT_WL_TOPLEVEL
;
2605 a
.i
= set
| XT_WL_TOPLEVEL
;
2608 a
.i
= XT_WL_TOGGLE
| XT_WL_TOPLEVEL
| XT_WL_RELOAD
;
2613 toggle_src(struct tab
*t
, struct karg
*args
)
2620 mode
= webkit_web_view_get_view_source_mode(t
->wv
);
2621 webkit_web_view_set_view_source_mode(t
->wv
, !mode
);
2622 webkit_web_view_reload(t
->wv
);
2628 focus_webview(struct tab
*t
)
2633 /* only grab focus if we are visible */
2634 if (gtk_notebook_get_current_page(notebook
) == t
->tab_id
)
2635 gtk_widget_grab_focus(GTK_WIDGET(t
->wv
));
2639 focus(struct tab
*t
, struct karg
*args
)
2641 if (t
== NULL
|| args
== NULL
)
2647 if (args
->i
== XT_FOCUS_URI
)
2648 gtk_widget_grab_focus(GTK_WIDGET(t
->uri_entry
));
2649 else if (args
->i
== XT_FOCUS_SEARCH
)
2650 gtk_widget_grab_focus(GTK_WIDGET(t
->search_entry
));
2656 startpage(struct tab
*t
, struct karg
*args
)
2658 char *page
, *body
, *b
;
2662 show_oops(NULL
, "startpage invalid parameters");
2664 body
= g_strdup_printf("<b>Startup Exception(s):</b><p>");
2666 TAILQ_FOREACH(s
, &spl
, entry
) {
2668 body
= g_strdup_printf("%s%s<br>", body
, s
->line
);
2672 page
= get_html_page("Startup Exception", body
, "", 0);
2675 load_webkit_string(t
, page
, XT_URI_ABOUT_STARTPAGE
);
2682 startpage_add(const char *fmt
, ...)
2692 if (vasprintf(&msg
, fmt
, ap
) == -1)
2693 errx(1, "startpage_add failed");
2696 s
= g_malloc0(sizeof *s
);
2699 TAILQ_INSERT_TAIL(&spl
, s
, entry
);
2703 show_certs(struct tab
*t
, gnutls_x509_crt_t
*certs
,
2704 size_t cert_count
, char *title
)
2706 gnutls_datum_t cinfo
;
2710 body
= g_strdup("");
2712 for (i
= 0; i
< cert_count
; i
++) {
2713 if (gnutls_x509_crt_print(certs
[i
], GNUTLS_CRT_PRINT_FULL
,
2718 body
= g_strdup_printf("%s<h2>Cert #%d</h2><pre>%s</pre>",
2719 body
, i
, cinfo
.data
);
2720 gnutls_free(cinfo
.data
);
2724 tmp
= get_html_page(title
, body
, "", 0);
2727 load_webkit_string(t
, tmp
, XT_URI_ABOUT_CERTS
);
2732 ca_cmd(struct tab
*t
, struct karg
*args
)
2735 int rv
= 1, certs
= 0, certs_read
;
2738 gnutls_x509_crt_t
*c
= NULL
;
2739 char *certs_buf
= NULL
, *s
;
2741 if ((f
= fopen(ssl_ca_file
, "r")) == NULL
) {
2742 show_oops(t
, "Can't open CA file: %s", ssl_ca_file
);
2746 if (fstat(fileno(f
), &sb
) == -1) {
2747 show_oops(t
, "Can't stat CA file: %s", ssl_ca_file
);
2751 certs_buf
= g_malloc(sb
.st_size
+ 1);
2752 if (fread(certs_buf
, 1, sb
.st_size
, f
) != sb
.st_size
) {
2753 show_oops(t
, "Can't read CA file: %s", strerror(errno
));
2756 certs_buf
[sb
.st_size
] = '\0';
2759 while ((s
= strstr(s
, "BEGIN CERTIFICATE"))) {
2761 s
+= strlen("BEGIN CERTIFICATE");
2764 bzero(&dt
, sizeof dt
);
2765 dt
.data
= (unsigned char *)certs_buf
;
2766 dt
.size
= sb
.st_size
;
2767 c
= g_malloc(sizeof(gnutls_x509_crt_t
) * certs
);
2768 certs_read
= gnutls_x509_crt_list_import(c
, (unsigned int *)&certs
, &dt
,
2769 GNUTLS_X509_FMT_PEM
, 0);
2770 if (certs_read
<= 0) {
2771 show_oops(t
, "No cert(s) available");
2774 show_certs(t
, c
, certs_read
, "Certificate Authority Certificates");
2787 connect_socket_from_uri(const gchar
*uri
, const gchar
**error_str
, char *domain
,
2791 struct addrinfo hints
, *res
= NULL
, *ai
;
2792 int rv
= -1, s
= -1, on
, error
;
2794 static gchar myerror
[256]; /* this is not thread safe */
2797 *error_str
= myerror
;
2798 if (uri
&& !g_str_has_prefix(uri
, "https://")) {
2799 *error_str
= "invalid URI";
2803 su
= soup_uri_new(uri
);
2805 *error_str
= "invalid soup URI";
2808 if (!SOUP_URI_VALID_FOR_HTTP(su
)) {
2809 *error_str
= "invalid HTTPS URI";
2813 snprintf(port
, sizeof port
, "%d", su
->port
);
2814 bzero(&hints
, sizeof(struct addrinfo
));
2815 hints
.ai_flags
= AI_CANONNAME
;
2816 hints
.ai_family
= AF_UNSPEC
;
2817 hints
.ai_socktype
= SOCK_STREAM
;
2819 if ((error
= getaddrinfo(su
->host
, port
, &hints
, &res
))) {
2820 snprintf(myerror
, sizeof myerror
, "getaddrinfo failed: %s",
2821 gai_strerror(errno
));
2825 for (ai
= res
; ai
; ai
= ai
->ai_next
) {
2831 if (ai
->ai_family
!= AF_INET
&& ai
->ai_family
!= AF_INET6
)
2833 s
= socket(ai
->ai_family
, ai
->ai_socktype
, ai
->ai_protocol
);
2836 if (setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, &on
,
2839 if (connect(s
, ai
->ai_addr
, ai
->ai_addrlen
) == 0)
2843 snprintf(myerror
, sizeof myerror
,
2844 "could not obtain certificates from: %s",
2850 strlcpy(domain
, su
->host
, domain_sz
);
2857 if (rv
== -1 && s
!= -1)
2864 stop_tls(gnutls_session_t gsession
, gnutls_certificate_credentials_t xcred
)
2867 gnutls_deinit(gsession
);
2869 gnutls_certificate_free_credentials(xcred
);
2875 start_tls(const gchar
**error_str
, int s
, gnutls_session_t
*gs
,
2876 gnutls_certificate_credentials_t
*xc
)
2878 gnutls_certificate_credentials_t xcred
;
2879 gnutls_session_t gsession
;
2881 static gchar myerror
[1024]; /* this is not thread safe */
2883 if (gs
== NULL
|| xc
== NULL
)
2890 gnutls_certificate_allocate_credentials(&xcred
);
2891 gnutls_certificate_set_x509_trust_file(xcred
, ssl_ca_file
,
2892 GNUTLS_X509_FMT_PEM
);
2894 gnutls_init(&gsession
, GNUTLS_CLIENT
);
2895 gnutls_priority_set_direct(gsession
, "PERFORMANCE", NULL
);
2896 gnutls_credentials_set(gsession
, GNUTLS_CRD_CERTIFICATE
, xcred
);
2897 gnutls_transport_set_ptr(gsession
, (gnutls_transport_ptr_t
)(long)s
);
2898 if ((rv
= gnutls_handshake(gsession
)) < 0) {
2899 snprintf(myerror
, sizeof myerror
,
2900 "gnutls_handshake failed %d fatal %d %s",
2902 gnutls_error_is_fatal(rv
),
2903 gnutls_strerror_name(rv
));
2904 stop_tls(gsession
, xcred
);
2908 gnutls_credentials_type_t cred
;
2909 cred
= gnutls_auth_get_type(gsession
);
2910 if (cred
!= GNUTLS_CRD_CERTIFICATE
) {
2911 snprintf(myerror
, sizeof myerror
,
2912 "gnutls_auth_get_type failed %d",
2914 stop_tls(gsession
, xcred
);
2922 *error_str
= myerror
;
2927 get_connection_certs(gnutls_session_t gsession
, gnutls_x509_crt_t
**certs
,
2931 const gnutls_datum_t
*cl
;
2932 gnutls_x509_crt_t
*all_certs
;
2935 if (certs
== NULL
|| cert_count
== NULL
)
2937 if (gnutls_certificate_type_get(gsession
) != GNUTLS_CRT_X509
)
2939 cl
= gnutls_certificate_get_peers(gsession
, &len
);
2943 all_certs
= g_malloc(sizeof(gnutls_x509_crt_t
) * len
);
2944 for (i
= 0; i
< len
; i
++) {
2945 gnutls_x509_crt_init(&all_certs
[i
]);
2946 if (gnutls_x509_crt_import(all_certs
[i
], &cl
[i
],
2947 GNUTLS_X509_FMT_PEM
< 0)) {
2961 free_connection_certs(gnutls_x509_crt_t
*certs
, size_t cert_count
)
2965 for (i
= 0; i
< cert_count
; i
++)
2966 gnutls_x509_crt_deinit(certs
[i
]);
2971 statusbar_modify_attr(struct tab
*t
, const char *text
, const char *base
)
2973 GdkColor c_text
, c_base
;
2975 gdk_color_parse(text
, &c_text
);
2976 gdk_color_parse(base
, &c_base
);
2978 gtk_widget_modify_text(t
->sbe
.statusbar
, GTK_STATE_NORMAL
, &c_text
);
2979 gtk_widget_modify_text(t
->sbe
.buffercmd
, GTK_STATE_NORMAL
, &c_text
);
2980 gtk_widget_modify_text(t
->sbe
.zoom
, GTK_STATE_NORMAL
, &c_text
);
2981 gtk_widget_modify_text(t
->sbe
.position
, GTK_STATE_NORMAL
, &c_text
);
2983 gtk_widget_modify_base(t
->sbe
.statusbar
, GTK_STATE_NORMAL
, &c_base
);
2984 gtk_widget_modify_base(t
->sbe
.buffercmd
, GTK_STATE_NORMAL
, &c_base
);
2985 gtk_widget_modify_base(t
->sbe
.zoom
, GTK_STATE_NORMAL
, &c_base
);
2986 gtk_widget_modify_base(t
->sbe
.position
, GTK_STATE_NORMAL
, &c_base
);
2990 save_certs(struct tab
*t
, gnutls_x509_crt_t
*certs
,
2991 size_t cert_count
, char *domain
)
2994 char cert_buf
[64 * 1024], file
[PATH_MAX
];
2999 if (t
== NULL
|| certs
== NULL
|| cert_count
<= 0 || domain
== NULL
)
3002 snprintf(file
, sizeof file
, "%s/%s", certs_dir
, domain
);
3003 if ((f
= fopen(file
, "w")) == NULL
) {
3004 show_oops(t
, "Can't create cert file %s %s",
3005 file
, strerror(errno
));
3009 for (i
= 0; i
< cert_count
; i
++) {
3010 cert_buf_sz
= sizeof cert_buf
;
3011 if (gnutls_x509_crt_export(certs
[i
], GNUTLS_X509_FMT_PEM
,
3012 cert_buf
, &cert_buf_sz
)) {
3013 show_oops(t
, "gnutls_x509_crt_export failed");
3016 if (fwrite(cert_buf
, cert_buf_sz
, 1, f
) != 1) {
3017 show_oops(t
, "Can't write certs: %s", strerror(errno
));
3022 /* not the best spot but oh well */
3023 gdk_color_parse("lightblue", &color
);
3024 gtk_widget_modify_base(t
->uri_entry
, GTK_STATE_NORMAL
, &color
);
3025 statusbar_modify_attr(t
, XT_COLOR_BLACK
, "lightblue");
3038 load_compare_cert(const gchar
*uri
, const gchar
**error_str
)
3040 char domain
[8182], file
[PATH_MAX
];
3041 char cert_buf
[64 * 1024], r_cert_buf
[64 * 1024];
3043 unsigned int error
= 0;
3045 size_t cert_buf_sz
, cert_count
;
3046 enum cert_trust rv
= CERT_UNTRUSTED
;
3047 static gchar serr
[80]; /* this isn't thread safe */
3048 gnutls_session_t gsession
;
3049 gnutls_x509_crt_t
*certs
;
3050 gnutls_certificate_credentials_t xcred
;
3052 DNPRINTF(XT_D_URL
, "%s: %s\n", __func__
, uri
);
3056 if ((s
= connect_socket_from_uri(uri
, error_str
, domain
,
3057 sizeof domain
)) == -1)
3060 DNPRINTF(XT_D_URL
, "%s: fd %d\n", __func__
, s
);
3063 if (start_tls(error_str
, s
, &gsession
, &xcred
))
3065 DNPRINTF(XT_D_URL
, "%s: got tls\n", __func__
);
3067 /* verify certs in case cert file doesn't exist */
3068 if (gnutls_certificate_verify_peers2(gsession
, &error
) !=
3070 *error_str
= "Invalid certificates";
3075 if (get_connection_certs(gsession
, &certs
, &cert_count
)) {
3076 *error_str
= "Can't get connection certificates";
3080 snprintf(file
, sizeof file
, "%s/%s", certs_dir
, domain
);
3081 if ((f
= fopen(file
, "r")) == NULL
) {
3087 for (i
= 0; i
< cert_count
; i
++) {
3088 cert_buf_sz
= sizeof cert_buf
;
3089 if (gnutls_x509_crt_export(certs
[i
], GNUTLS_X509_FMT_PEM
,
3090 cert_buf
, &cert_buf_sz
)) {
3093 if (fread(r_cert_buf
, cert_buf_sz
, 1, f
) != 1) {
3094 rv
= CERT_BAD
; /* critical */
3097 if (bcmp(r_cert_buf
, cert_buf
, sizeof cert_buf_sz
)) {
3098 rv
= CERT_BAD
; /* critical */
3107 free_connection_certs(certs
, cert_count
);
3109 /* we close the socket first for speed */
3113 /* only complain if we didn't save it locally */
3114 if (error
&& rv
!= CERT_LOCAL
) {
3115 strlcpy(serr
, "Certificate exception(s): ", sizeof serr
);
3116 if (error
& GNUTLS_CERT_INVALID
)
3117 strlcat(serr
, "invalid, ", sizeof serr
);
3118 if (error
& GNUTLS_CERT_REVOKED
)
3119 strlcat(serr
, "revoked, ", sizeof serr
);
3120 if (error
& GNUTLS_CERT_SIGNER_NOT_FOUND
)
3121 strlcat(serr
, "signer not found, ", sizeof serr
);
3122 if (error
& GNUTLS_CERT_SIGNER_NOT_CA
)
3123 strlcat(serr
, "not signed by CA, ", sizeof serr
);
3124 if (error
& GNUTLS_CERT_INSECURE_ALGORITHM
)
3125 strlcat(serr
, "insecure algorithm, ", sizeof serr
);
3126 if (error
& GNUTLS_CERT_NOT_ACTIVATED
)
3127 strlcat(serr
, "not activated, ", sizeof serr
);
3128 if (error
& GNUTLS_CERT_EXPIRED
)
3129 strlcat(serr
, "expired, ", sizeof serr
);
3130 for (i
= strlen(serr
) - 1; i
> 0; i
--)
3131 if (serr
[i
] == ',') {
3138 stop_tls(gsession
, xcred
);
3144 cert_cmd(struct tab
*t
, struct karg
*args
)
3146 const gchar
*uri
, *error_str
= NULL
;
3150 gnutls_session_t gsession
;
3151 gnutls_x509_crt_t
*certs
;
3152 gnutls_certificate_credentials_t xcred
;
3157 if (ssl_ca_file
== NULL
) {
3158 show_oops(t
, "Can't open CA file: %s", ssl_ca_file
);
3162 if ((uri
= get_uri(t
)) == NULL
) {
3163 show_oops(t
, "Invalid URI");
3167 if ((s
= connect_socket_from_uri(uri
, &error_str
, domain
,
3168 sizeof domain
)) == -1) {
3169 show_oops(t
, "%s", error_str
);
3174 if (start_tls(&error_str
, s
, &gsession
, &xcred
))
3178 if (get_connection_certs(gsession
, &certs
, &cert_count
)) {
3179 show_oops(t
, "get_connection_certs failed");
3183 if (args
->i
& XT_SHOW
)
3184 show_certs(t
, certs
, cert_count
, "Certificate Chain");
3185 else if (args
->i
& XT_SAVE
)
3186 save_certs(t
, certs
, cert_count
, domain
);
3188 free_connection_certs(certs
, cert_count
);
3190 /* we close the socket first for speed */
3193 stop_tls(gsession
, xcred
);
3194 if (error_str
&& strlen(error_str
))
3195 show_oops(t
, "%s", error_str
);
3200 remove_cookie(int index
)
3206 DNPRINTF(XT_D_COOKIE
, "remove_cookie: %d\n", index
);
3208 cf
= soup_cookie_jar_all_cookies(s_cookiejar
);
3210 for (i
= 1; cf
; cf
= cf
->next
, i
++) {
3214 print_cookie("remove cookie", c
);
3215 soup_cookie_jar_delete_cookie(s_cookiejar
, c
);
3220 soup_cookies_free(cf
);
3226 wl_show(struct tab
*t
, struct karg
*args
, char *title
, struct domain_list
*wl
)
3231 body
= g_strdup("");
3234 if (args
->i
& XT_WL_PERSISTENT
) {
3236 body
= g_strdup_printf("%s<h2>Persistent</h2>", body
);
3238 RB_FOREACH(d
, domain_list
, wl
) {
3242 body
= g_strdup_printf("%s%s<br/>", body
, d
->d
);
3248 if (args
->i
& XT_WL_SESSION
) {
3250 body
= g_strdup_printf("%s<h2>Session</h2>", body
);
3252 RB_FOREACH(d
, domain_list
, wl
) {
3256 body
= g_strdup_printf("%s%s<br/>", body
, d
->d
);
3261 tmp
= get_html_page(title
, body
, "", 0);
3264 load_webkit_string(t
, tmp
, XT_URI_ABOUT_JSWL
);
3265 else if (wl
== &c_wl
)
3266 load_webkit_string(t
, tmp
, XT_URI_ABOUT_COOKIEWL
);
3268 load_webkit_string(t
, tmp
, XT_URI_ABOUT_PLUGINWL
);
3273 #define XT_WL_INVALID (0)
3274 #define XT_WL_JAVASCRIPT (1)
3275 #define XT_WL_COOKIE (2)
3276 #define XT_WL_PLUGIN (3)
3278 wl_save(struct tab
*t
, struct karg
*args
, int list
)
3280 char file
[PATH_MAX
], *lst_str
= NULL
;
3282 char *line
= NULL
, *lt
= NULL
, *dom
= NULL
;
3290 if (t
== NULL
|| args
== NULL
)
3293 if (runtime_settings
[0] == '\0')
3296 snprintf(file
, sizeof file
, "%s/%s", work_dir
, runtime_settings
);
3297 if ((f
= fopen(file
, "r+")) == NULL
)
3301 case XT_WL_JAVASCRIPT
:
3302 lst_str
= "JavaScript";
3303 lt
= g_strdup_printf("js_wl=%s", dom
);
3307 lt
= g_strdup_printf("cookie_wl=%s", dom
);
3311 lt
= g_strdup_printf("pl_wl=%s", dom
);
3314 show_oops(t
, "Invalid list id: %d", list
);
3319 dom
= find_domain(uri
, args
->i
& XT_WL_TOPLEVEL
);
3320 if (uri
== NULL
|| dom
== NULL
||
3321 webkit_web_view_get_load_status(t
->wv
) == WEBKIT_LOAD_FAILED
) {
3322 show_oops(t
, "Can't add domain to %s white list", lst_str
);
3327 line
= fparseln(f
, &linelen
, NULL
, NULL
, 0);
3330 if (!strcmp(line
, lt
))
3336 fprintf(f
, "%s\n", lt
);
3341 case XT_WL_JAVASCRIPT
:
3342 d
= wl_find(dom
, &js_wl
);
3344 settings_add("js_wl", dom
);
3345 d
= wl_find(dom
, &js_wl
);
3351 d
= wl_find(dom
, &c_wl
);
3353 settings_add("cookie_wl", dom
);
3354 d
= wl_find(dom
, &c_wl
);
3358 /* find and add to persistent jar */
3359 cf
= soup_cookie_jar_all_cookies(s_cookiejar
);
3360 for (;cf
; cf
= cf
->next
) {
3362 if (!strcmp(dom
, ci
->domain
) ||
3363 !strcmp(&dom
[1], ci
->domain
)) /* deal with leading . */ {
3364 c
= soup_cookie_copy(ci
);
3365 _soup_cookie_jar_add_cookie(p_cookiejar
, c
);
3368 soup_cookies_free(cf
);
3372 d
= wl_find(dom
, &pl_wl
);
3374 settings_add("pl_wl", dom
);
3375 d
= wl_find(dom
, &pl_wl
);
3380 abort(); /* can't happen */
3398 js_show_wl(struct tab
*t
, struct karg
*args
)
3400 args
->i
= XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
;
3401 wl_show(t
, args
, "JavaScript White List", &js_wl
);
3407 cookie_show_wl(struct tab
*t
, struct karg
*args
)
3409 args
->i
= XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
;
3410 wl_show(t
, args
, "Cookie White List", &c_wl
);
3416 cookie_cmd(struct tab
*t
, struct karg
*args
)
3418 if (args
->i
& XT_SHOW
)
3419 wl_show(t
, args
, "Cookie White List", &c_wl
);
3420 else if (args
->i
& XT_WL_TOGGLE
) {
3421 args
->i
|= XT_WL_RELOAD
;
3422 toggle_cwl(t
, args
);
3423 } else if (args
->i
& XT_SAVE
) {
3424 args
->i
|= XT_WL_RELOAD
;
3425 wl_save(t
, args
, XT_WL_COOKIE
);
3426 } else if (args
->i
& XT_DELETE
)
3427 show_oops(t
, "'cookie delete' currently unimplemented");
3433 js_cmd(struct tab
*t
, struct karg
*args
)
3435 if (args
->i
& XT_SHOW
)
3436 wl_show(t
, args
, "JavaScript White List", &js_wl
);
3437 else if (args
->i
& XT_SAVE
) {
3438 args
->i
|= XT_WL_RELOAD
;
3439 wl_save(t
, args
, XT_WL_JAVASCRIPT
);
3440 } else if (args
->i
& XT_WL_TOGGLE
) {
3441 args
->i
|= XT_WL_RELOAD
;
3443 } else if (args
->i
& XT_DELETE
)
3444 show_oops(t
, "'js delete' currently unimplemented");
3450 pl_show_wl(struct tab
*t
, struct karg
*args
)
3452 args
->i
= XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
;
3453 wl_show(t
, args
, "Plugin White List", &pl_wl
);
3459 pl_cmd(struct tab
*t
, struct karg
*args
)
3461 if (args
->i
& XT_SHOW
)
3462 wl_show(t
, args
, "Plugin White List", &pl_wl
);
3463 else if (args
->i
& XT_SAVE
) {
3464 args
->i
|= XT_WL_RELOAD
;
3465 wl_save(t
, args
, XT_WL_PLUGIN
);
3466 } else if (args
->i
& XT_WL_TOGGLE
) {
3467 args
->i
|= XT_WL_RELOAD
;
3469 } else if (args
->i
& XT_DELETE
)
3470 show_oops(t
, "'plugin delete' currently unimplemented");
3476 toplevel_cmd(struct tab
*t
, struct karg
*args
)
3478 js_toggle_cb(t
->js_toggle
, t
);
3484 add_favorite(struct tab
*t
, struct karg
*args
)
3486 char file
[PATH_MAX
];
3489 size_t urilen
, linelen
;
3490 const gchar
*uri
, *title
;
3495 /* don't allow adding of xtp pages to favorites */
3496 if (t
->xtp_meaning
!= XT_XTP_TAB_MEANING_NORMAL
) {
3497 show_oops(t
, "%s: can't add xtp pages to favorites", __func__
);
3501 snprintf(file
, sizeof file
, "%s/%s", work_dir
, XT_FAVS_FILE
);
3502 if ((f
= fopen(file
, "r+")) == NULL
) {
3503 show_oops(t
, "Can't open favorites file: %s", strerror(errno
));
3507 title
= get_title(t
, FALSE
);
3510 if (title
== NULL
|| uri
== NULL
) {
3511 show_oops(t
, "can't add page to favorites");
3515 urilen
= strlen(uri
);
3518 if ((line
= fparseln(f
, &linelen
, NULL
, NULL
, 0)) == NULL
)
3519 if (feof(f
) || ferror(f
))
3522 if (linelen
== urilen
&& !strcmp(line
, uri
))
3529 fprintf(f
, "\n%s\n%s", title
, uri
);
3535 update_favorite_tabs(NULL
);
3541 can_go_back_for_real(struct tab
*t
)
3544 WebKitWebHistoryItem
*item
;
3550 /* rely on webkit to make sure we can go backward when on an about page */
3552 if (uri
== NULL
|| g_str_has_prefix(uri
, "about:"))
3553 return (webkit_web_view_can_go_back(t
->wv
));
3555 /* the back/forwars list is stupid so help determine if we can go back */
3556 for (i
= 0, item
= webkit_web_back_forward_list_get_current_item(t
->bfl
);
3558 i
--, item
= webkit_web_back_forward_list_get_nth_item(t
->bfl
, i
)) {
3559 if (strcmp(webkit_web_history_item_get_uri(item
), uri
))
3567 can_go_forward_for_real(struct tab
*t
)
3570 WebKitWebHistoryItem
*item
;
3576 /* rely on webkit to make sure we can go forward when on an about page */
3578 if (uri
== NULL
|| g_str_has_prefix(uri
, "about:"))
3579 return (webkit_web_view_can_go_forward(t
->wv
));
3581 /* the back/forwars list is stupid so help selecting a different item */
3582 for (i
= 0, item
= webkit_web_back_forward_list_get_current_item(t
->bfl
);
3584 i
++, item
= webkit_web_back_forward_list_get_nth_item(t
->bfl
, i
)) {
3585 if (strcmp(webkit_web_history_item_get_uri(item
), uri
))
3593 go_back_for_real(struct tab
*t
)
3596 WebKitWebHistoryItem
*item
;
3604 webkit_web_view_go_back(t
->wv
);
3607 /* the back/forwars list is stupid so help selecting a different item */
3608 for (i
= 0, item
= webkit_web_back_forward_list_get_current_item(t
->bfl
);
3610 i
--, item
= webkit_web_back_forward_list_get_nth_item(t
->bfl
, i
)) {
3611 if (strcmp(webkit_web_history_item_get_uri(item
), uri
)) {
3612 webkit_web_view_go_to_back_forward_item(t
->wv
, item
);
3619 go_forward_for_real(struct tab
*t
)
3622 WebKitWebHistoryItem
*item
;
3630 webkit_web_view_go_forward(t
->wv
);
3633 /* the back/forwars list is stupid so help selecting a different item */
3634 for (i
= 0, item
= webkit_web_back_forward_list_get_current_item(t
->bfl
);
3636 i
++, item
= webkit_web_back_forward_list_get_nth_item(t
->bfl
, i
)) {
3637 if (strcmp(webkit_web_history_item_get_uri(item
), uri
)) {
3638 webkit_web_view_go_to_back_forward_item(t
->wv
, item
);
3645 navaction(struct tab
*t
, struct karg
*args
)
3647 WebKitWebHistoryItem
*item
;
3648 WebKitWebFrame
*frame
;
3650 DNPRINTF(XT_D_NAV
, "navaction: tab %d opcode %d\n",
3651 t
->tab_id
, args
->i
);
3653 t
->xtp_meaning
= XT_XTP_TAB_MEANING_NORMAL
;
3655 if (args
->i
== XT_NAV_BACK
)
3656 item
= webkit_web_back_forward_list_get_current_item(t
->bfl
);
3658 item
= webkit_web_back_forward_list_get_forward_item(t
->bfl
);
3660 return (XT_CB_PASSTHROUGH
);
3661 webkit_web_view_go_to_back_forward_item(t
->wv
, item
);
3663 return (XT_CB_PASSTHROUGH
);
3669 go_back_for_real(t
);
3671 case XT_NAV_FORWARD
:
3673 go_forward_for_real(t
);
3676 frame
= webkit_web_view_get_main_frame(t
->wv
);
3677 webkit_web_frame_reload(frame
);
3680 return (XT_CB_PASSTHROUGH
);
3684 move(struct tab
*t
, struct karg
*args
)
3686 GtkAdjustment
*adjust
;
3687 double pi
, si
, pos
, ps
, upper
, lower
, max
;
3693 case XT_MOVE_BOTTOM
:
3695 case XT_MOVE_PAGEDOWN
:
3696 case XT_MOVE_PAGEUP
:
3697 case XT_MOVE_HALFDOWN
:
3698 case XT_MOVE_HALFUP
:
3699 case XT_MOVE_PERCENT
:
3700 adjust
= t
->adjust_v
;
3703 adjust
= t
->adjust_h
;
3707 pos
= gtk_adjustment_get_value(adjust
);
3708 ps
= gtk_adjustment_get_page_size(adjust
);
3709 upper
= gtk_adjustment_get_upper(adjust
);
3710 lower
= gtk_adjustment_get_lower(adjust
);
3711 si
= gtk_adjustment_get_step_increment(adjust
);
3712 pi
= gtk_adjustment_get_page_increment(adjust
);
3715 DNPRINTF(XT_D_MOVE
, "move: opcode %d %s pos %f ps %f upper %f lower %f "
3716 "max %f si %f pi %f\n",
3717 args
->i
, adjust
== t
->adjust_h
? "horizontal" : "vertical",
3718 pos
, ps
, upper
, lower
, max
, si
, pi
);
3724 gtk_adjustment_set_value(adjust
, MIN(pos
, max
));
3729 gtk_adjustment_set_value(adjust
, MAX(pos
, lower
));
3731 case XT_MOVE_BOTTOM
:
3732 case XT_MOVE_FARRIGHT
:
3733 gtk_adjustment_set_value(adjust
, max
);
3736 case XT_MOVE_FARLEFT
:
3737 gtk_adjustment_set_value(adjust
, lower
);
3739 case XT_MOVE_PAGEDOWN
:
3741 gtk_adjustment_set_value(adjust
, MIN(pos
, max
));
3743 case XT_MOVE_PAGEUP
:
3745 gtk_adjustment_set_value(adjust
, MAX(pos
, lower
));
3747 case XT_MOVE_HALFDOWN
:
3749 gtk_adjustment_set_value(adjust
, MIN(pos
, max
));
3751 case XT_MOVE_HALFUP
:
3753 gtk_adjustment_set_value(adjust
, MAX(pos
, lower
));
3755 case XT_MOVE_PERCENT
:
3756 percent
= atoi(args
->s
) / 100.0;
3757 pos
= max
* percent
;
3758 if (pos
< 0.0 || pos
> max
)
3760 gtk_adjustment_set_value(adjust
, pos
);
3763 return (XT_CB_PASSTHROUGH
);
3766 DNPRINTF(XT_D_MOVE
, "move: new pos %f %f\n", pos
, MIN(pos
, max
));
3768 return (XT_CB_HANDLED
);
3772 url_set_visibility(void)
3776 TAILQ_FOREACH(t
, &tabs
, entry
)
3777 if (show_url
== 0) {
3778 gtk_widget_hide(t
->toolbar
);
3781 gtk_widget_show(t
->toolbar
);
3785 notebook_tab_set_visibility(void)
3787 if (show_tabs
== 0) {
3788 gtk_widget_hide(tab_bar
);
3789 gtk_notebook_set_show_tabs(notebook
, FALSE
);
3791 if (tab_style
== XT_TABS_NORMAL
) {
3792 gtk_widget_hide(tab_bar
);
3793 gtk_notebook_set_show_tabs(notebook
, TRUE
);
3794 } else if (tab_style
== XT_TABS_COMPACT
) {
3795 gtk_widget_show(tab_bar
);
3796 gtk_notebook_set_show_tabs(notebook
, FALSE
);
3802 statusbar_set_visibility(void)
3806 TAILQ_FOREACH(t
, &tabs
, entry
)
3807 if (show_statusbar
== 0) {
3808 gtk_widget_hide(t
->statusbar_box
);
3811 gtk_widget_show(t
->statusbar_box
);
3815 url_set(struct tab
*t
, int enable_url_entry
)
3820 show_url
= enable_url_entry
;
3822 if (enable_url_entry
) {
3823 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(t
->sbe
.statusbar
),
3824 GTK_ENTRY_ICON_PRIMARY
, NULL
);
3825 gtk_entry_set_progress_fraction(GTK_ENTRY(t
->sbe
.statusbar
), 0);
3827 pixbuf
= gtk_entry_get_icon_pixbuf(GTK_ENTRY(t
->uri_entry
),
3828 GTK_ENTRY_ICON_PRIMARY
);
3830 gtk_entry_get_progress_fraction(GTK_ENTRY(t
->uri_entry
));
3831 gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(t
->sbe
.statusbar
),
3832 GTK_ENTRY_ICON_PRIMARY
, pixbuf
);
3833 gtk_entry_set_progress_fraction(GTK_ENTRY(t
->sbe
.statusbar
),
3839 fullscreen(struct tab
*t
, struct karg
*args
)
3841 DNPRINTF(XT_D_TAB
, "%s: %p %d\n", __func__
, t
, args
->i
);
3844 return (XT_CB_PASSTHROUGH
);
3846 if (show_url
== 0) {
3854 url_set_visibility();
3855 notebook_tab_set_visibility();
3857 return (XT_CB_HANDLED
);
3861 statustoggle(struct tab
*t
, struct karg
*args
)
3863 DNPRINTF(XT_D_TAB
, "%s: %p %d\n", __func__
, t
, args
->i
);
3865 if (show_statusbar
== 1) {
3867 statusbar_set_visibility();
3868 } else if (show_statusbar
== 0) {
3870 statusbar_set_visibility();
3872 return (XT_CB_HANDLED
);
3876 urlaction(struct tab
*t
, struct karg
*args
)
3878 int rv
= XT_CB_HANDLED
;
3880 DNPRINTF(XT_D_TAB
, "%s: %p %d\n", __func__
, t
, args
->i
);
3883 return (XT_CB_PASSTHROUGH
);
3887 if (show_url
== 0) {
3889 url_set_visibility();
3893 if (show_url
== 1) {
3895 url_set_visibility();
3903 tabaction(struct tab
*t
, struct karg
*args
)
3905 int rv
= XT_CB_HANDLED
;
3906 char *url
= args
->s
;
3910 DNPRINTF(XT_D_TAB
, "tabaction: %p %d\n", t
, args
->i
);
3913 return (XT_CB_PASSTHROUGH
);
3917 if (strlen(url
) > 0)
3918 create_new_tab(url
, NULL
, 1, args
->precount
);
3920 create_new_tab(NULL
, NULL
, 1, args
->precount
);
3923 if (args
->precount
< 0)
3926 TAILQ_FOREACH(tt
, &tabs
, entry
)
3927 if (tt
->tab_id
== args
->precount
- 1) {
3932 case XT_TAB_DELQUIT
:
3933 if (gtk_notebook_get_n_pages(notebook
) > 1)
3939 if (strlen(url
) > 0)
3942 rv
= XT_CB_PASSTHROUGH
;
3948 if (show_tabs
== 0) {
3950 notebook_tab_set_visibility();
3954 if (show_tabs
== 1) {
3956 notebook_tab_set_visibility();
3959 case XT_TAB_NEXTSTYLE
:
3960 if (tab_style
== XT_TABS_NORMAL
) {
3961 tab_style
= XT_TABS_COMPACT
;
3962 recolor_compact_tabs();
3965 tab_style
= XT_TABS_NORMAL
;
3966 notebook_tab_set_visibility();
3968 case XT_TAB_UNDO_CLOSE
:
3969 if (undo_count
== 0) {
3970 DNPRINTF(XT_D_TAB
, "%s: no tabs to undo close",
3975 u
= TAILQ_FIRST(&undos
);
3976 create_new_tab(u
->uri
, u
, 1, -1);
3978 TAILQ_REMOVE(&undos
, u
, entry
);
3980 /* u->history is freed in create_new_tab() */
3985 rv
= XT_CB_PASSTHROUGH
;
3999 resizetab(struct tab
*t
, struct karg
*args
)
4001 if (t
== NULL
|| args
== NULL
) {
4002 show_oops(NULL
, "resizetab invalid parameters");
4003 return (XT_CB_PASSTHROUGH
);
4006 DNPRINTF(XT_D_TAB
, "resizetab: tab %d %d\n",
4007 t
->tab_id
, args
->i
);
4009 setzoom_webkit(t
, args
->i
);
4011 return (XT_CB_HANDLED
);
4015 movetab(struct tab
*t
, struct karg
*args
)
4019 if (t
== NULL
|| args
== NULL
) {
4020 show_oops(NULL
, "movetab invalid parameters");
4021 return (XT_CB_PASSTHROUGH
);
4024 DNPRINTF(XT_D_TAB
, "movetab: tab %d opcode %d\n",
4025 t
->tab_id
, args
->i
);
4027 if (args
->i
>= XT_TAB_INVALID
)
4028 return (XT_CB_PASSTHROUGH
);
4030 if (TAILQ_EMPTY(&tabs
))
4031 return (XT_CB_PASSTHROUGH
);
4033 n
= gtk_notebook_get_n_pages(notebook
);
4034 dest
= gtk_notebook_get_current_page(notebook
);
4038 if (args
->precount
< 0)
4039 dest
= dest
== n
- 1 ? 0 : dest
+ 1;
4041 dest
= args
->precount
- 1;
4045 if (args
->precount
< 0)
4048 dest
-= args
->precount
% n
;
4061 return (XT_CB_PASSTHROUGH
);
4064 if (dest
< 0 || dest
>= n
)
4065 return (XT_CB_PASSTHROUGH
);
4066 if (t
->tab_id
== dest
) {
4067 DNPRINTF(XT_D_TAB
, "movetab: do nothing\n");
4068 return (XT_CB_HANDLED
);
4071 set_current_tab(dest
);
4073 return (XT_CB_HANDLED
);
4079 command_mode(struct tab
*t
, struct karg
*args
)
4081 if (args
->i
== XT_MODE_COMMAND
)
4082 run_script(t
, "hints.clearFocus();");
4084 run_script(t
, "hints.focusInput();");
4085 return (XT_CB_HANDLED
);
4089 command(struct tab
*t
, struct karg
*args
)
4091 char *s
= NULL
, *ss
= NULL
;
4096 if (t
== NULL
|| args
== NULL
) {
4097 show_oops(NULL
, "command invalid parameters");
4098 return (XT_CB_PASSTHROUGH
);
4109 if (cmd_prefix
== 0)
4112 ss
= g_strdup_printf(":%d", cmd_prefix
);
4118 bzero(&a
, sizeof a
);
4124 bzero(&a
, sizeof a
);
4125 a
.i
= XT_HINT_NEWTAB
;
4135 case XT_CMD_OPEN_CURRENT
:
4138 case XT_CMD_TABNEW_CURRENT
:
4139 if (!s
) /* FALL THROUGH? */
4141 if ((uri
= get_uri(t
)) != NULL
) {
4142 ss
= g_strdup_printf("%s%s", s
, uri
);
4147 show_oops(t
, "command: invalid opcode %d", args
->i
);
4148 return (XT_CB_PASSTHROUGH
);
4151 DNPRINTF(XT_D_CMD
, "command: type %s\n", s
);
4153 gtk_entry_set_text(GTK_ENTRY(t
->cmd
), s
);
4154 gdk_color_parse(XT_COLOR_WHITE
, &color
);
4155 gtk_widget_modify_base(t
->cmd
, GTK_STATE_NORMAL
, &color
);
4157 gtk_widget_grab_focus(GTK_WIDGET(t
->cmd
));
4158 gtk_editable_set_position(GTK_EDITABLE(t
->cmd
), -1);
4163 return (XT_CB_HANDLED
);
4167 search(struct tab
*t
, struct karg
*args
)
4171 if (t
== NULL
|| args
== NULL
) {
4172 show_oops(NULL
, "search invalid parameters");
4177 case XT_SEARCH_NEXT
:
4178 d
= t
->search_forward
;
4180 case XT_SEARCH_PREV
:
4181 d
= !t
->search_forward
;
4184 return (XT_CB_PASSTHROUGH
);
4187 if (t
->search_text
== NULL
) {
4188 if (global_search
== NULL
)
4189 return (XT_CB_PASSTHROUGH
);
4191 d
= t
->search_forward
= TRUE
;
4192 t
->search_text
= g_strdup(global_search
);
4193 webkit_web_view_mark_text_matches(t
->wv
, global_search
, FALSE
, 0);
4194 webkit_web_view_set_highlight_text_matches(t
->wv
, TRUE
);
4198 DNPRINTF(XT_D_CMD
, "search: tab %d opc %d forw %d text %s\n",
4199 t
->tab_id
, args
->i
, t
->search_forward
, t
->search_text
);
4201 webkit_web_view_search_text(t
->wv
, t
->search_text
, FALSE
, d
, TRUE
);
4203 return (XT_CB_HANDLED
);
4206 struct settings_args
{
4212 print_setting(struct settings
*s
, char *val
, void *cb_args
)
4215 struct settings_args
*sa
= cb_args
;
4220 if (s
->flags
& XT_SF_RUNTIME
)
4226 *sa
->body
= g_strdup_printf(
4228 "<td style='background-color: %s; width: 10%%;word-break:break-all'>%s</td>"
4229 "<td style='background-color: %s; width: 20%%;word-break:break-all'>%s</td>",
4241 set_show(struct tab
*t
, struct karg
*args
)
4243 char *body
, *page
, *tmp
;
4245 struct settings_args sa
;
4247 bzero(&sa
, sizeof sa
);
4251 body
= g_strdup_printf("<div align='center'><table><tr>"
4252 "<th align='left'>Setting</th>"
4253 "<th align='left'>Value</th></tr>\n");
4255 settings_walk(print_setting
, &sa
);
4258 /* small message if there are none */
4261 body
= g_strdup_printf("%s\n<tr><td style='text-align:center'"
4262 "colspan='2'>No settings</td></tr>\n", body
);
4267 body
= g_strdup_printf("%s</table></div>", body
);
4270 page
= get_html_page("Settings", body
, "", 0);
4274 load_webkit_string(t
, page
, XT_URI_ABOUT_SET
);
4278 return (XT_CB_PASSTHROUGH
);
4282 set(struct tab
*t
, struct karg
*args
)
4287 if (args
== NULL
|| args
->s
== NULL
)
4288 return (set_show(t
, args
));
4291 p
= g_strstrip(args
->s
);
4294 return (set_show(t
, args
));
4296 /* we got some sort of string */
4297 val
= g_strrstr(p
, "=");
4300 val
= g_strchomp(val
);
4303 for (i
= 0; i
< LENGTH(rs
); i
++) {
4304 if (strcmp(rs
[i
].name
, p
))
4307 if (rs
[i
].activate
) {
4308 if (rs
[i
].activate(val
))
4309 show_oops(t
, "%s invalid value %s",
4312 show_oops(t
, ":set %s = %s", p
, val
);
4315 show_oops(t
, "not a runtime option: %s", p
);
4319 show_oops(t
, "unknown option: %s", p
);
4323 for (i
= 0; i
< LENGTH(rs
); i
++) {
4324 if (strcmp(rs
[i
].name
, p
))
4327 /* XXX this could use some cleanup */
4328 switch (rs
[i
].type
) {
4331 show_oops(t
, "%s = %d",
4332 rs
[i
].name
, *rs
[i
].ival
);
4333 else if (rs
[i
].s
&& rs
[i
].s
->get
)
4334 show_oops(t
, "%s = %s",
4336 rs
[i
].s
->get(&rs
[i
]));
4337 else if (rs
[i
].s
&& rs
[i
].s
->get
== NULL
)
4338 show_oops(t
, "%s = ...", rs
[i
].name
);
4340 show_oops(t
, "%s = ", rs
[i
].name
);
4344 show_oops(t
, "%s = %f",
4345 rs
[i
].name
, *rs
[i
].fval
);
4346 else if (rs
[i
].s
&& rs
[i
].s
->get
)
4347 show_oops(t
, "%s = %s",
4349 rs
[i
].s
->get(&rs
[i
]));
4350 else if (rs
[i
].s
&& rs
[i
].s
->get
== NULL
)
4351 show_oops(t
, "%s = ...", rs
[i
].name
);
4353 show_oops(t
, "%s = ", rs
[i
].name
);
4356 if (rs
[i
].sval
&& *rs
[i
].sval
)
4357 show_oops(t
, "%s = %s",
4358 rs
[i
].name
, *rs
[i
].sval
);
4359 else if (rs
[i
].s
&& rs
[i
].s
->get
)
4360 show_oops(t
, "%s = %s",
4362 rs
[i
].s
->get(&rs
[i
]));
4363 else if (rs
[i
].s
&& rs
[i
].s
->get
== NULL
)
4364 show_oops(t
, "%s = ...", rs
[i
].name
);
4366 show_oops(t
, "%s = ", rs
[i
].name
);
4369 show_oops(t
, "unknown type for %s", rs
[i
].name
);
4375 show_oops(t
, "unknown option: %s", p
);
4378 return (XT_CB_PASSTHROUGH
);
4382 session_save(struct tab
*t
, char *filename
)
4388 if (strlen(filename
) == 0)
4391 if (filename
[0] == '.' || filename
[0] == '/')
4395 if (save_tabs(t
, &a
))
4397 strlcpy(named_session
, filename
, sizeof named_session
);
4399 /* add the new session to the list of sessions */
4400 s
= g_malloc(sizeof(struct session
));
4401 s
->name
= g_strdup(filename
);
4402 TAILQ_INSERT_TAIL(&sessions
, s
, entry
);
4410 session_open(struct tab
*t
, char *filename
)
4415 if (strlen(filename
) == 0)
4418 if (filename
[0] == '.' || filename
[0] == '/')
4422 a
.i
= XT_SES_CLOSETABS
;
4423 if (open_tabs(t
, &a
))
4426 strlcpy(named_session
, filename
, sizeof named_session
);
4434 session_delete(struct tab
*t
, char *filename
)
4436 char file
[PATH_MAX
];
4440 if (strlen(filename
) == 0)
4443 if (filename
[0] == '.' || filename
[0] == '/')
4446 snprintf(file
, sizeof file
, "%s/%s", sessions_dir
, filename
);
4450 if (!strcmp(filename
, named_session
))
4451 strlcpy(named_session
, XT_SAVED_TABS_FILE
,
4452 sizeof named_session
);
4454 /* remove session from sessions list */
4455 TAILQ_FOREACH(s
, &sessions
, entry
) {
4456 if (!strcmp(s
->name
, filename
))
4461 TAILQ_REMOVE(&sessions
, s
, entry
);
4462 g_free((gpointer
) s
->name
);
4471 session_cmd(struct tab
*t
, struct karg
*args
)
4473 char *filename
= args
->s
;
4478 if (args
->i
& XT_SHOW
)
4479 show_oops(t
, "Current session: %s", named_session
[0] == '\0' ?
4480 XT_SAVED_TABS_FILE
: named_session
);
4481 else if (args
->i
& XT_SAVE
) {
4482 if (session_save(t
, filename
)) {
4483 show_oops(t
, "Can't save session: %s",
4484 filename
? filename
: "INVALID");
4487 } else if (args
->i
& XT_OPEN
) {
4488 if (session_open(t
, filename
)) {
4489 show_oops(t
, "Can't open session: %s",
4490 filename
? filename
: "INVALID");
4493 } else if (args
->i
& XT_DELETE
) {
4494 if (session_delete(t
, filename
)) {
4495 show_oops(t
, "Can't delete session: %s",
4496 filename
? filename
: "INVALID");
4501 return (XT_CB_PASSTHROUGH
);
4505 script_cmd(struct tab
*t
, struct karg
*args
)
4507 JSGlobalContextRef ctx
;
4508 WebKitWebFrame
*frame
;
4510 JSValueRef val
, exception
;
4519 if ((f
= fopen(args
->s
, "r")) == NULL
) {
4520 show_oops(t
, "Can't open script file: %s", args
->s
);
4524 if (fstat(fileno(f
), &sb
) == -1) {
4525 show_oops(t
, "Can't stat script file: %s", args
->s
);
4529 buf
= g_malloc0(sb
.st_size
+ 1);
4530 if (fread(buf
, 1, sb
.st_size
, f
) != sb
.st_size
) {
4531 show_oops(t
, "Can't read script file: %s", args
->s
);
4535 /* this code needs to be redone */
4536 frame
= webkit_web_view_get_main_frame(t
->wv
);
4537 ctx
= webkit_web_frame_get_global_context(frame
);
4539 str
= JSStringCreateWithUTF8CString(buf
);
4540 val
= JSEvaluateScript(ctx
, str
, JSContextGetGlobalObject(ctx
),
4541 NULL
, 0, &exception
);
4542 JSStringRelease(str
);
4544 DNPRINTF(XT_D_JS
, "run_script: val %p\n", val
);
4546 es
= js_ref_to_string(ctx
, exception
);
4548 show_oops(t
, "script exception: %s", es
);
4553 es
= js_ref_to_string(ctx
, val
);
4556 if (!strncmp(es
, XT_JS_DONE
, XT_JS_DONE_LEN
))
4558 if (!strncmp(es
, XT_JS_INSERT
, XT_JS_INSERT_LEN
))
4562 show_oops(t
, "script complete return value: '%s'", es
);
4565 show_oops(t
, "script complete: without a return value");
4574 return (XT_CB_PASSTHROUGH
);
4578 * Make a hardcopy of the page
4581 print_page(struct tab
*t
, struct karg
*args
)
4583 WebKitWebFrame
*frame
;
4585 GtkPrintOperation
*op
;
4586 GtkPrintOperationAction action
;
4587 GtkPrintOperationResult print_res
;
4588 GError
*g_err
= NULL
;
4589 int marg_l
, marg_r
, marg_t
, marg_b
;
4591 DNPRINTF(XT_D_PRINTING
, "%s:", __func__
);
4593 ps
= gtk_page_setup_new();
4594 op
= gtk_print_operation_new();
4595 action
= GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
;
4596 frame
= webkit_web_view_get_main_frame(t
->wv
);
4598 /* the default margins are too small, so we will bump them */
4599 marg_l
= gtk_page_setup_get_left_margin(ps
, GTK_UNIT_MM
) +
4600 XT_PRINT_EXTRA_MARGIN
;
4601 marg_r
= gtk_page_setup_get_right_margin(ps
, GTK_UNIT_MM
) +
4602 XT_PRINT_EXTRA_MARGIN
;
4603 marg_t
= gtk_page_setup_get_top_margin(ps
, GTK_UNIT_MM
) +
4604 XT_PRINT_EXTRA_MARGIN
;
4605 marg_b
= gtk_page_setup_get_bottom_margin(ps
, GTK_UNIT_MM
) +
4606 XT_PRINT_EXTRA_MARGIN
;
4609 gtk_page_setup_set_left_margin(ps
, marg_l
, GTK_UNIT_MM
);
4610 gtk_page_setup_set_right_margin(ps
, marg_r
, GTK_UNIT_MM
);
4611 gtk_page_setup_set_top_margin(ps
, marg_t
, GTK_UNIT_MM
);
4612 gtk_page_setup_set_bottom_margin(ps
, marg_b
, GTK_UNIT_MM
);
4614 gtk_print_operation_set_default_page_setup(op
, ps
);
4616 /* this appears to free 'op' and 'ps' */
4617 print_res
= webkit_web_frame_print_full(frame
, op
, action
, &g_err
);
4619 /* check it worked */
4620 if (print_res
== GTK_PRINT_OPERATION_RESULT_ERROR
) {
4621 show_oops(NULL
, "can't print: %s", g_err
->message
);
4622 g_error_free (g_err
);
4630 go_home(struct tab
*t
, struct karg
*args
)
4637 set_encoding(struct tab
*t
, struct karg
*args
)
4641 if (args
->s
&& strlen(g_strstrip(args
->s
)) == 0) {
4642 e
= webkit_web_view_get_custom_encoding(t
->wv
);
4644 e
= webkit_web_view_get_encoding(t
->wv
);
4645 show_oops(t
, "encoding: %s", e
? e
: "N/A");
4647 webkit_web_view_set_custom_encoding(t
->wv
, args
->s
);
4653 restart(struct tab
*t
, struct karg
*args
)
4657 a
.s
= XT_RESTART_TABS_FILE
;
4659 execvp(start_argv
[0], start_argv
);
4665 #define CTRL GDK_CONTROL_MASK
4666 #define MOD1 GDK_MOD1_MASK
4667 #define SHFT GDK_SHIFT_MASK
4669 /* inherent to GTK not all keys will be caught at all times */
4670 /* XXX sort key bindings */
4671 struct key_binding
{
4676 TAILQ_ENTRY(key_binding
) entry
; /* in bss so no need to init */
4678 { "command_mode", 0, 0, GDK_Escape
},
4679 { "insert_mode", 0, 0, GDK_i
},
4680 { "cookiejar", MOD1
, 0, GDK_j
},
4681 { "downloadmgr", MOD1
, 0, GDK_d
},
4682 { "history", MOD1
, 0, GDK_h
},
4683 { "print", CTRL
, 0, GDK_p
},
4684 { "search", 0, 0, GDK_slash
},
4685 { "searchb", 0, 0, GDK_question
},
4686 { "statustoggle", CTRL
, 0, GDK_n
},
4687 { "command", 0, 0, GDK_colon
},
4688 { "qa", CTRL
, 0, GDK_q
},
4689 { "restart", MOD1
, 0, GDK_q
},
4690 { "js toggle", CTRL
, 0, GDK_j
},
4691 { "cookie toggle", MOD1
, 0, GDK_c
},
4692 { "togglesrc", CTRL
, 0, GDK_s
},
4693 { "yankuri", 0, 0, GDK_y
},
4694 { "pasteuricur", 0, 0, GDK_p
},
4695 { "pasteurinew", 0, 0, GDK_P
},
4696 { "toplevel toggle", 0, 0, GDK_F4
},
4697 { "help", 0, 0, GDK_F1
},
4698 { "run_script", MOD1
, 0, GDK_r
},
4701 { "searchnext", 0, 0, GDK_n
},
4702 { "searchprevious", 0, 0, GDK_N
},
4705 { "focusaddress", 0, 0, GDK_F6
},
4706 { "focussearch", 0, 0, GDK_F7
},
4709 { "hinting", 0, 0, GDK_f
},
4710 { "hinting", 0, 0, GDK_period
},
4711 { "hinting_newtab", SHFT
, 0, GDK_F
},
4712 { "hinting_newtab", 0, 0, GDK_comma
},
4714 /* custom stylesheet */
4715 { "userstyle", 0, 0, GDK_s
},
4718 { "goback", 0, 0, GDK_BackSpace
},
4719 { "goback", MOD1
, 0, GDK_Left
},
4720 { "goforward", SHFT
, 0, GDK_BackSpace
},
4721 { "goforward", MOD1
, 0, GDK_Right
},
4722 { "reload", 0, 0, GDK_F5
},
4723 { "reload", CTRL
, 0, GDK_r
},
4724 { "reload", CTRL
, 0, GDK_l
},
4725 { "favorites", MOD1
, 1, GDK_f
},
4727 /* vertical movement */
4728 { "scrolldown", 0, 0, GDK_j
},
4729 { "scrolldown", 0, 0, GDK_Down
},
4730 { "scrollup", 0, 0, GDK_Up
},
4731 { "scrollup", 0, 0, GDK_k
},
4732 { "scrollbottom", 0, 0, GDK_G
},
4733 { "scrollbottom", 0, 0, GDK_End
},
4734 { "scrolltop", 0, 0, GDK_Home
},
4735 { "scrollpagedown", 0, 0, GDK_space
},
4736 { "scrollpagedown", CTRL
, 0, GDK_f
},
4737 { "scrollhalfdown", CTRL
, 0, GDK_d
},
4738 { "scrollpagedown", 0, 0, GDK_Page_Down
},
4739 { "scrollpageup", 0, 0, GDK_Page_Up
},
4740 { "scrollpageup", CTRL
, 0, GDK_b
},
4741 { "scrollhalfup", CTRL
, 0, GDK_u
},
4742 /* horizontal movement */
4743 { "scrollright", 0, 0, GDK_l
},
4744 { "scrollright", 0, 0, GDK_Right
},
4745 { "scrollleft", 0, 0, GDK_Left
},
4746 { "scrollleft", 0, 0, GDK_h
},
4747 { "scrollfarright", 0, 0, GDK_dollar
},
4748 { "scrollfarleft", 0, 0, GDK_0
},
4751 { "tabnew", CTRL
, 0, GDK_t
},
4752 { "999tabnew", CTRL
, 0, GDK_T
},
4753 { "tabclose", CTRL
, 1, GDK_w
},
4754 { "tabundoclose", 0, 0, GDK_U
},
4755 { "tabnext 1", CTRL
, 0, GDK_1
},
4756 { "tabnext 2", CTRL
, 0, GDK_2
},
4757 { "tabnext 3", CTRL
, 0, GDK_3
},
4758 { "tabnext 4", CTRL
, 0, GDK_4
},
4759 { "tabnext 5", CTRL
, 0, GDK_5
},
4760 { "tabnext 6", CTRL
, 0, GDK_6
},
4761 { "tabnext 7", CTRL
, 0, GDK_7
},
4762 { "tabnext 8", CTRL
, 0, GDK_8
},
4763 { "tabnext 9", CTRL
, 0, GDK_9
},
4764 { "tabfirst", CTRL
, 0, GDK_less
},
4765 { "tablast", CTRL
, 0, GDK_greater
},
4766 { "tabprevious", CTRL
, 0, GDK_Left
},
4767 { "tabnext", CTRL
, 0, GDK_Right
},
4768 { "focusout", CTRL
, 0, GDK_minus
},
4769 { "focusin", CTRL
, 0, GDK_plus
},
4770 { "focusin", CTRL
, 0, GDK_equal
},
4771 { "focusreset", CTRL
, 0, GDK_0
},
4773 /* command aliases (handy when -S flag is used) */
4774 { "promptopen", 0, 0, GDK_F9
},
4775 { "promptopencurrent", 0, 0, GDK_F10
},
4776 { "prompttabnew", 0, 0, GDK_F11
},
4777 { "prompttabnewcurrent",0, 0, GDK_F12
},
4779 TAILQ_HEAD(keybinding_list
, key_binding
);
4782 walk_kb(struct settings
*s
,
4783 void (*cb
)(struct settings
*, char *, void *), void *cb_args
)
4785 struct key_binding
*k
;
4788 if (s
== NULL
|| cb
== NULL
) {
4789 show_oops(NULL
, "walk_kb invalid parameters");
4793 TAILQ_FOREACH(k
, &kbl
, entry
) {
4799 if (gdk_keyval_name(k
->key
) == NULL
)
4802 strlcat(str
, k
->cmd
, sizeof str
);
4803 strlcat(str
, ",", sizeof str
);
4805 if (k
->mask
& GDK_SHIFT_MASK
)
4806 strlcat(str
, "S-", sizeof str
);
4807 if (k
->mask
& GDK_CONTROL_MASK
)
4808 strlcat(str
, "C-", sizeof str
);
4809 if (k
->mask
& GDK_MOD1_MASK
)
4810 strlcat(str
, "M1-", sizeof str
);
4811 if (k
->mask
& GDK_MOD2_MASK
)
4812 strlcat(str
, "M2-", sizeof str
);
4813 if (k
->mask
& GDK_MOD3_MASK
)
4814 strlcat(str
, "M3-", sizeof str
);
4815 if (k
->mask
& GDK_MOD4_MASK
)
4816 strlcat(str
, "M4-", sizeof str
);
4817 if (k
->mask
& GDK_MOD5_MASK
)
4818 strlcat(str
, "M5-", sizeof str
);
4820 strlcat(str
, gdk_keyval_name(k
->key
), sizeof str
);
4821 cb(s
, str
, cb_args
);
4826 init_keybindings(void)
4829 struct key_binding
*k
;
4831 for (i
= 0; i
< LENGTH(keys
); i
++) {
4832 k
= g_malloc0(sizeof *k
);
4833 k
->cmd
= keys
[i
].cmd
;
4834 k
->mask
= keys
[i
].mask
;
4835 k
->use_in_entry
= keys
[i
].use_in_entry
;
4836 k
->key
= keys
[i
].key
;
4837 TAILQ_INSERT_HEAD(&kbl
, k
, entry
);
4839 DNPRINTF(XT_D_KEYBINDING
, "init_keybindings: added: %s\n",
4840 k
->cmd
? k
->cmd
: "unnamed key");
4845 keybinding_clearall(void)
4847 struct key_binding
*k
, *next
;
4849 for (k
= TAILQ_FIRST(&kbl
); k
; k
= next
) {
4850 next
= TAILQ_NEXT(k
, entry
);
4854 DNPRINTF(XT_D_KEYBINDING
, "keybinding_clearall: %s\n",
4855 k
->cmd
? k
->cmd
: "unnamed key");
4856 TAILQ_REMOVE(&kbl
, k
, entry
);
4862 keybinding_add(char *cmd
, char *key
, int use_in_entry
)
4864 struct key_binding
*k
;
4865 guint keyval
, mask
= 0;
4868 DNPRINTF(XT_D_KEYBINDING
, "keybinding_add: %s %s\n", cmd
, key
);
4870 /* Keys which are to be used in entry have been prefixed with an
4871 * exclamation mark. */
4875 /* find modifier keys */
4876 if (strstr(key
, "S-"))
4877 mask
|= GDK_SHIFT_MASK
;
4878 if (strstr(key
, "C-"))
4879 mask
|= GDK_CONTROL_MASK
;
4880 if (strstr(key
, "M1-"))
4881 mask
|= GDK_MOD1_MASK
;
4882 if (strstr(key
, "M2-"))
4883 mask
|= GDK_MOD2_MASK
;
4884 if (strstr(key
, "M3-"))
4885 mask
|= GDK_MOD3_MASK
;
4886 if (strstr(key
, "M4-"))
4887 mask
|= GDK_MOD4_MASK
;
4888 if (strstr(key
, "M5-"))
4889 mask
|= GDK_MOD5_MASK
;
4892 for (i
= strlen(key
) - 1; i
> 0; i
--)
4896 /* validate keyname */
4897 keyval
= gdk_keyval_from_name(key
);
4898 if (keyval
== GDK_VoidSymbol
) {
4899 warnx("invalid keybinding name %s", key
);
4902 /* must run this test too, gtk+ doesn't handle 10 for example */
4903 if (gdk_keyval_name(keyval
) == NULL
) {
4904 warnx("invalid keybinding name %s", key
);
4908 /* Remove eventual dupes. */
4909 TAILQ_FOREACH(k
, &kbl
, entry
)
4910 if (k
->key
== keyval
&& k
->mask
== mask
) {
4911 TAILQ_REMOVE(&kbl
, k
, entry
);
4917 k
= g_malloc0(sizeof *k
);
4918 k
->cmd
= g_strdup(cmd
);
4920 k
->use_in_entry
= use_in_entry
;
4923 DNPRINTF(XT_D_KEYBINDING
, "keybinding_add: %s 0x%x %d 0x%x\n",
4928 DNPRINTF(XT_D_KEYBINDING
, "keybinding_add: adding: %s %s\n",
4929 k
->cmd
, gdk_keyval_name(keyval
));
4931 TAILQ_INSERT_HEAD(&kbl
, k
, entry
);
4937 add_kb(struct settings
*s
, char *entry
)
4941 DNPRINTF(XT_D_KEYBINDING
, "add_kb: %s\n", entry
);
4943 /* clearall is special */
4944 if (!strcmp(entry
, "clearall")) {
4945 keybinding_clearall();
4949 kb
= strstr(entry
, ",");
4955 return (keybinding_add(entry
, key
, key
[0] == '!'));
4961 int (*func
)(struct tab
*, struct karg
*);
4965 { "command_mode", 0, command_mode
, XT_MODE_COMMAND
, 0 },
4966 { "insert_mode", 0, command_mode
, XT_MODE_INSERT
, 0 },
4967 { "command", 0, command
, ':', 0 },
4968 { "search", 0, command
, '/', 0 },
4969 { "searchb", 0, command
, '?', 0 },
4970 { "hinting", 0, command
, '.', 0 },
4971 { "hinting_newtab", 0, command
, ',', 0 },
4972 { "togglesrc", 0, toggle_src
, 0, 0 },
4974 /* yanking and pasting */
4975 { "yankuri", 0, yank_uri
, 0, 0 },
4976 /* XXX: pasteuri{cur,new} do not work from the cmd_entry? */
4977 { "pasteuricur", 0, paste_uri
, XT_PASTE_CURRENT_TAB
, 0 },
4978 { "pasteurinew", 0, paste_uri
, XT_PASTE_NEW_TAB
, 0 },
4981 { "searchnext", 0, search
, XT_SEARCH_NEXT
, 0 },
4982 { "searchprevious", 0, search
, XT_SEARCH_PREV
, 0 },
4985 { "focusaddress", 0, focus
, XT_FOCUS_URI
, 0 },
4986 { "focussearch", 0, focus
, XT_FOCUS_SEARCH
, 0 },
4989 { "hinting", 0, hint
, 0, 0 },
4990 { "hinting_newtab", 0, hint
, XT_HINT_NEWTAB
, 0 },
4992 /* custom stylesheet */
4993 { "userstyle", 0, userstyle
, 0, 0 },
4996 { "goback", 0, navaction
, XT_NAV_BACK
, 0 },
4997 { "goforward", 0, navaction
, XT_NAV_FORWARD
, 0 },
4998 { "reload", 0, navaction
, XT_NAV_RELOAD
, 0 },
5000 /* vertical movement */
5001 { "scrolldown", 0, move
, XT_MOVE_DOWN
, 0 },
5002 { "scrollup", 0, move
, XT_MOVE_UP
, 0 },
5003 { "scrollbottom", 0, move
, XT_MOVE_BOTTOM
, 0 },
5004 { "scrolltop", 0, move
, XT_MOVE_TOP
, 0 },
5005 { "1", 0, move
, XT_MOVE_TOP
, 0 },
5006 { "scrollhalfdown", 0, move
, XT_MOVE_HALFDOWN
, 0 },
5007 { "scrollhalfup", 0, move
, XT_MOVE_HALFUP
, 0 },
5008 { "scrollpagedown", 0, move
, XT_MOVE_PAGEDOWN
, 0 },
5009 { "scrollpageup", 0, move
, XT_MOVE_PAGEUP
, 0 },
5010 /* horizontal movement */
5011 { "scrollright", 0, move
, XT_MOVE_RIGHT
, 0 },
5012 { "scrollleft", 0, move
, XT_MOVE_LEFT
, 0 },
5013 { "scrollfarright", 0, move
, XT_MOVE_FARRIGHT
, 0 },
5014 { "scrollfarleft", 0, move
, XT_MOVE_FARLEFT
, 0 },
5016 { "favorites", 0, xtp_page_fl
, 0, 0 },
5017 { "fav", 0, xtp_page_fl
, 0, 0 },
5018 { "favadd", 0, add_favorite
, 0, 0 },
5020 { "qall", 0, quit
, 0, 0 },
5021 { "quitall", 0, quit
, 0, 0 },
5022 { "w", 0, save_tabs
, 0, 0 },
5023 { "wq", 0, save_tabs_and_quit
, 0, 0 },
5024 { "help", 0, help
, 0, 0 },
5025 { "about", 0, about
, 0, 0 },
5026 { "stats", 0, stats
, 0, 0 },
5027 { "version", 0, about
, 0, 0 },
5030 { "js", 0, js_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
5031 { "save", 1, js_cmd
, XT_SAVE
| XT_WL_FQDN
, 0 },
5032 { "domain", 2, js_cmd
, XT_SAVE
| XT_WL_TOPLEVEL
, 0 },
5033 { "fqdn", 2, js_cmd
, XT_SAVE
| XT_WL_FQDN
, 0 },
5034 { "show", 1, js_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
5035 { "all", 2, js_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
5036 { "persistent", 2, js_cmd
, XT_SHOW
| XT_WL_PERSISTENT
, 0 },
5037 { "session", 2, js_cmd
, XT_SHOW
| XT_WL_SESSION
, 0 },
5038 { "toggle", 1, js_cmd
, XT_WL_TOGGLE
| XT_WL_FQDN
, 0 },
5039 { "domain", 2, js_cmd
, XT_WL_TOGGLE
| XT_WL_TOPLEVEL
, 0 },
5040 { "fqdn", 2, js_cmd
, XT_WL_TOGGLE
| XT_WL_FQDN
, 0 },
5042 /* cookie command */
5043 { "cookie", 0, cookie_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
5044 { "save", 1, cookie_cmd
, XT_SAVE
| XT_WL_FQDN
, 0 },
5045 { "domain", 2, cookie_cmd
, XT_SAVE
| XT_WL_TOPLEVEL
, 0 },
5046 { "fqdn", 2, cookie_cmd
, XT_SAVE
| XT_WL_FQDN
, 0 },
5047 { "show", 1, cookie_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
5048 { "all", 2, cookie_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
5049 { "persistent", 2, cookie_cmd
, XT_SHOW
| XT_WL_PERSISTENT
, 0 },
5050 { "session", 2, cookie_cmd
, XT_SHOW
| XT_WL_SESSION
, 0 },
5051 { "toggle", 1, cookie_cmd
, XT_WL_TOGGLE
| XT_WL_FQDN
, 0 },
5052 { "domain", 2, cookie_cmd
, XT_WL_TOGGLE
| XT_WL_TOPLEVEL
, 0 },
5053 { "fqdn", 2, cookie_cmd
, XT_WL_TOGGLE
| XT_WL_FQDN
, 0 },
5055 /* plugin command */
5056 { "plugin", 0, pl_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
5057 { "save", 1, pl_cmd
, XT_SAVE
| XT_WL_FQDN
, 0 },
5058 { "domain", 2, pl_cmd
, XT_SAVE
| XT_WL_TOPLEVEL
, 0 },
5059 { "fqdn", 2, pl_cmd
, XT_SAVE
| XT_WL_FQDN
, 0 },
5060 { "show", 1, pl_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
5061 { "all", 2, pl_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
5062 { "persistent", 2, pl_cmd
, XT_SHOW
| XT_WL_PERSISTENT
, 0 },
5063 { "session", 2, pl_cmd
, XT_SHOW
| XT_WL_SESSION
, 0 },
5064 { "toggle", 1, pl_cmd
, XT_WL_TOGGLE
| XT_WL_FQDN
, 0 },
5065 { "domain", 2, pl_cmd
, XT_WL_TOGGLE
| XT_WL_TOPLEVEL
, 0 },
5066 { "fqdn", 2, pl_cmd
, XT_WL_TOGGLE
| XT_WL_FQDN
, 0 },
5068 /* toplevel (domain) command */
5069 { "toplevel", 0, toplevel_cmd
, XT_WL_TOGGLE
| XT_WL_TOPLEVEL
| XT_WL_RELOAD
, 0 },
5070 { "toggle", 1, toplevel_cmd
, XT_WL_TOGGLE
| XT_WL_TOPLEVEL
| XT_WL_RELOAD
, 0 },
5073 { "cookiejar", 0, xtp_page_cl
, 0, 0 },
5076 { "cert", 0, cert_cmd
, XT_SHOW
, 0 },
5077 { "save", 1, cert_cmd
, XT_SAVE
, 0 },
5078 { "show", 1, cert_cmd
, XT_SHOW
, 0 },
5080 { "ca", 0, ca_cmd
, 0, 0 },
5081 { "downloadmgr", 0, xtp_page_dl
, 0, 0 },
5082 { "dl", 0, xtp_page_dl
, 0, 0 },
5083 { "h", 0, xtp_page_hl
, 0, 0 },
5084 { "history", 0, xtp_page_hl
, 0, 0 },
5085 { "home", 0, go_home
, 0, 0 },
5086 { "restart", 0, restart
, 0, 0 },
5087 { "urlhide", 0, urlaction
, XT_URL_HIDE
, 0 },
5088 { "urlshow", 0, urlaction
, XT_URL_SHOW
, 0 },
5089 { "statustoggle", 0, statustoggle
, 0, 0 },
5090 { "run_script", 0, run_page_script
, 0, XT_USERARG
},
5092 { "print", 0, print_page
, 0, 0 },
5095 { "focusin", 0, resizetab
, XT_ZOOM_IN
, 0 },
5096 { "focusout", 0, resizetab
, XT_ZOOM_OUT
, 0 },
5097 { "focusreset", 0, resizetab
, XT_ZOOM_NORMAL
, 0 },
5098 { "q", 0, tabaction
, XT_TAB_DELQUIT
, 0 },
5099 { "quit", 0, tabaction
, XT_TAB_DELQUIT
, 0 },
5100 { "open", 0, tabaction
, XT_TAB_OPEN
, XT_URLARG
},
5101 { "tabclose", 0, tabaction
, XT_TAB_DELETE
, XT_PREFIX
| XT_INTARG
},
5102 { "tabedit", 0, tabaction
, XT_TAB_NEW
, XT_PREFIX
| XT_URLARG
},
5103 { "tabfirst", 0, movetab
, XT_TAB_FIRST
, 0 },
5104 { "tabhide", 0, tabaction
, XT_TAB_HIDE
, 0 },
5105 { "tablast", 0, movetab
, XT_TAB_LAST
, 0 },
5106 { "tabnew", 0, tabaction
, XT_TAB_NEW
, XT_PREFIX
| XT_URLARG
},
5107 { "tabnext", 0, movetab
, XT_TAB_NEXT
, XT_PREFIX
| XT_INTARG
},
5108 { "tabnextstyle", 0, tabaction
, XT_TAB_NEXTSTYLE
, 0 },
5109 { "tabprevious", 0, movetab
, XT_TAB_PREV
, XT_PREFIX
| XT_INTARG
},
5110 { "tabrewind", 0, movetab
, XT_TAB_FIRST
, 0 },
5111 { "tabshow", 0, tabaction
, XT_TAB_SHOW
, 0 },
5112 { "tabs", 0, buffers
, 0, 0 },
5113 { "tabundoclose", 0, tabaction
, XT_TAB_UNDO_CLOSE
, 0 },
5114 { "buffers", 0, buffers
, 0, 0 },
5115 { "ls", 0, buffers
, 0, 0 },
5116 { "encoding", 0, set_encoding
, 0, XT_USERARG
},
5118 /* command aliases (handy when -S flag is used) */
5119 { "promptopen", 0, command
, XT_CMD_OPEN
, 0 },
5120 { "promptopencurrent", 0, command
, XT_CMD_OPEN_CURRENT
, 0 },
5121 { "prompttabnew", 0, command
, XT_CMD_TABNEW
, 0 },
5122 { "prompttabnewcurrent",0, command
, XT_CMD_TABNEW_CURRENT
, 0 },
5125 { "set", 0, set
, 0, XT_SETARG
},
5127 { "fullscreen", 0, fullscreen
, 0, 0 },
5128 { "f", 0, fullscreen
, 0, 0 },
5131 { "session", 0, session_cmd
, XT_SHOW
, 0 },
5132 { "delete", 1, session_cmd
, XT_DELETE
, XT_SESSARG
},
5133 { "open", 1, session_cmd
, XT_OPEN
, XT_SESSARG
},
5134 { "save", 1, session_cmd
, XT_SAVE
, XT_USERARG
},
5135 { "show", 1, session_cmd
, XT_SHOW
, 0 },
5137 /* external javascript */
5138 { "script", 0, script_cmd
, XT_EJS_SHOW
, XT_USERARG
},
5141 { "inspector", 0, inspector_cmd
, XT_INS_SHOW
, 0 },
5142 { "show", 1, inspector_cmd
, XT_INS_SHOW
, 0 },
5143 { "hide", 1, inspector_cmd
, XT_INS_HIDE
, 0 },
5150 } cmd_status
= {-1, 0};
5153 wv_release_button_cb(GtkWidget
*btn
, GdkEventButton
*e
, struct tab
*t
)
5156 if (e
->type
== GDK_BUTTON_RELEASE
&& e
->button
== 1)
5163 wv_button_cb(GtkWidget
*btn
, GdkEventButton
*e
, struct tab
*t
)
5170 if (e
->type
== GDK_BUTTON_PRESS
&& e
->button
== 1)
5172 else if (e
->type
== GDK_BUTTON_PRESS
&& e
->button
== 8 /* btn 4 */) {
5178 } else if (e
->type
== GDK_BUTTON_PRESS
&& e
->button
== 9 /* btn 5 */) {
5180 a
.i
= XT_NAV_FORWARD
;
5190 tab_close_cb(GtkWidget
*btn
, GdkEventButton
*e
, struct tab
*t
)
5192 DNPRINTF(XT_D_TAB
, "tab_close_cb: tab %d\n", t
->tab_id
);
5194 if (e
->type
== GDK_BUTTON_PRESS
&& e
->button
== 1)
5203 activate_uri_entry_cb(GtkWidget
* entry
, struct tab
*t
)
5205 const gchar
*uri
= gtk_entry_get_text(GTK_ENTRY(entry
));
5207 DNPRINTF(XT_D_URL
, "activate_uri_entry_cb: %s\n", uri
);
5210 show_oops(NULL
, "activate_uri_entry_cb invalid parameters");
5215 show_oops(t
, "activate_uri_entry_cb no uri");
5219 uri
+= strspn(uri
, "\t ");
5221 /* if xxxt:// treat specially */
5222 if (parse_xtp_url(t
, uri
))
5225 /* otherwise continue to load page normally */
5226 load_uri(t
, (gchar
*)uri
);
5231 activate_search_entry_cb(GtkWidget
* entry
, struct tab
*t
)
5233 const gchar
*search
= gtk_entry_get_text(GTK_ENTRY(entry
));
5234 char *newuri
= NULL
;
5237 DNPRINTF(XT_D_URL
, "activate_search_entry_cb: %s\n", search
);
5240 show_oops(NULL
, "activate_search_entry_cb invalid parameters");
5244 if (search_string
== NULL
) {
5245 show_oops(t
, "no search_string");
5249 t
->xtp_meaning
= XT_XTP_TAB_MEANING_NORMAL
;
5251 enc_search
= soup_uri_encode(search
, XT_RESERVED_CHARS
);
5252 newuri
= g_strdup_printf(search_string
, enc_search
);
5256 webkit_web_view_load_uri(t
->wv
, newuri
);
5264 check_and_set_cookie(const gchar
*uri
, struct tab
*t
)
5266 struct domain
*d
= NULL
;
5269 if (uri
== NULL
|| t
== NULL
)
5272 if ((d
= wl_find_uri(uri
, &c_wl
)) == NULL
)
5277 DNPRINTF(XT_D_COOKIE
, "check_and_set_cookie: %s %s\n",
5278 es
? "enable" : "disable", uri
);
5280 g_object_set(G_OBJECT(t
->settings
),
5281 "enable-html5-local-storage", es
, (char *)NULL
);
5282 webkit_web_view_set_settings(t
->wv
, t
->settings
);
5286 check_and_set_js(const gchar
*uri
, struct tab
*t
)
5288 struct domain
*d
= NULL
;
5291 if (uri
== NULL
|| t
== NULL
)
5294 if ((d
= wl_find_uri(uri
, &js_wl
)) == NULL
)
5299 DNPRINTF(XT_D_JS
, "check_and_set_js: %s %s\n",
5300 es
? "enable" : "disable", uri
);
5302 g_object_set(G_OBJECT(t
->settings
),
5303 "enable-scripts", es
, (char *)NULL
);
5304 g_object_set(G_OBJECT(t
->settings
),
5305 "javascript-can-open-windows-automatically", es
, (char *)NULL
);
5306 webkit_web_view_set_settings(t
->wv
, t
->settings
);
5308 button_set_stockid(t
->js_toggle
,
5309 es
? GTK_STOCK_MEDIA_PLAY
: GTK_STOCK_MEDIA_PAUSE
);
5313 check_and_set_pl(const gchar
*uri
, struct tab
*t
)
5315 struct domain
*d
= NULL
;
5318 if (uri
== NULL
|| t
== NULL
)
5321 if ((d
= wl_find_uri(uri
, &pl_wl
)) == NULL
)
5326 DNPRINTF(XT_D_JS
, "check_and_set_pl: %s %s\n",
5327 es
? "enable" : "disable", uri
);
5329 g_object_set(G_OBJECT(t
->settings
),
5330 "enable-plugins", es
, (char *)NULL
);
5331 webkit_web_view_set_settings(t
->wv
, t
->settings
);
5335 color_address_bar(gpointer p
)
5338 struct tab
*tt
, *t
= p
;
5339 gchar
*col_str
= XT_COLOR_WHITE
;
5340 const gchar
*uri
, *u
= NULL
, *error_str
= NULL
;
5343 gdk_threads_enter();
5345 DNPRINTF(XT_D_URL
, "%s:\n", __func__
);
5347 /* make sure t still exists */
5350 TAILQ_FOREACH(tt
, &tabs
, entry
)
5356 if ((uri
= get_uri(t
)) == NULL
)
5361 gdk_threads_leave();
5364 col_str
= XT_COLOR_YELLOW
;
5365 switch (load_compare_cert(u
, &error_str
)) {
5367 col_str
= XT_COLOR_BLUE
;
5370 col_str
= XT_COLOR_GREEN
;
5372 case CERT_UNTRUSTED
:
5373 col_str
= XT_COLOR_YELLOW
;
5376 col_str
= XT_COLOR_RED
;
5381 gdk_threads_enter();
5383 /* make sure t isn't deleted */
5384 TAILQ_FOREACH(tt
, &tabs
, entry
)
5391 /* test to see if the user navigated away and canceled the thread */
5392 if (t
->thread
!= g_thread_self())
5394 if ((uri
= get_uri(t
)) == NULL
) {
5398 if (strcmp(uri
, u
)) {
5399 /* make sure we are still the same url */
5405 gdk_color_parse(col_str
, &color
);
5406 gtk_widget_modify_base(t
->uri_entry
, GTK_STATE_NORMAL
, &color
);
5408 if (!strcmp(col_str
, XT_COLOR_WHITE
))
5409 statusbar_modify_attr(t
, col_str
, XT_COLOR_BLACK
);
5411 statusbar_modify_attr(t
, XT_COLOR_BLACK
, col_str
);
5413 if (error_str
&& error_str
[0] != '\0')
5414 show_oops(t
, "%s", error_str
);
5419 /* t is invalid at this point */
5421 g_free((gpointer
)u
);
5423 gdk_threads_leave();
5428 show_ca_status(struct tab
*t
, const char *uri
)
5431 gchar
*col_str
= XT_COLOR_WHITE
;
5433 DNPRINTF(XT_D_URL
, "show_ca_status: %d %s %s\n",
5434 ssl_strict_certs
, ssl_ca_file
, uri
);
5441 if (ssl_ca_file
== NULL
) {
5442 if (g_str_has_prefix(uri
, "http://"))
5444 if (g_str_has_prefix(uri
, "https://")) {
5445 col_str
= XT_COLOR_RED
;
5450 if (g_str_has_prefix(uri
, "http://") ||
5451 !g_str_has_prefix(uri
, "https://"))
5455 * It is not necessary to see if the thread is already running.
5456 * If the thread is in progress setting it to something else aborts it
5460 /* thread the coloring of the address bar */
5461 t
->thread
= g_thread_create((GThreadFunc
)color_address_bar
, t
, TRUE
, NULL
);
5463 color_address_bar(t
);
5469 gdk_color_parse(col_str
, &color
);
5470 gtk_widget_modify_base(t
->uri_entry
, GTK_STATE_NORMAL
, &color
);
5472 if (!strcmp(col_str
, XT_COLOR_WHITE
))
5473 statusbar_modify_attr(t
, col_str
, XT_COLOR_BLACK
);
5475 statusbar_modify_attr(t
, XT_COLOR_BLACK
, col_str
);
5480 free_favicon(struct tab
*t
)
5482 DNPRINTF(XT_D_DOWNLOAD
, "%s: down %p req %p\n",
5483 __func__
, t
->icon_download
, t
->icon_request
);
5485 if (t
->icon_request
)
5486 g_object_unref(t
->icon_request
);
5487 if (t
->icon_dest_uri
)
5488 g_free(t
->icon_dest_uri
);
5490 t
->icon_request
= NULL
;
5491 t
->icon_dest_uri
= NULL
;
5495 xt_icon_from_name(struct tab
*t
, gchar
*name
)
5497 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(t
->uri_entry
),
5498 GTK_ENTRY_ICON_PRIMARY
, "text-html");
5500 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(t
->sbe
.statusbar
),
5501 GTK_ENTRY_ICON_PRIMARY
, "text-html");
5503 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(t
->sbe
.statusbar
),
5504 GTK_ENTRY_ICON_PRIMARY
, NULL
);
5508 xt_icon_from_pixbuf(struct tab
*t
, GdkPixbuf
*pb
)
5510 GdkPixbuf
*pb_scaled
;
5512 if (gdk_pixbuf_get_width(pb
) > 16 || gdk_pixbuf_get_height(pb
) > 16)
5513 pb_scaled
= gdk_pixbuf_scale_simple(pb
, 16, 16,
5514 GDK_INTERP_BILINEAR
);
5518 gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(t
->uri_entry
),
5519 GTK_ENTRY_ICON_PRIMARY
, pb_scaled
);
5521 gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(t
->sbe
.statusbar
),
5522 GTK_ENTRY_ICON_PRIMARY
, pb_scaled
);
5524 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(t
->sbe
.statusbar
),
5525 GTK_ENTRY_ICON_PRIMARY
, NULL
);
5527 if (pb_scaled
!= pb
)
5528 g_object_unref(pb_scaled
);
5532 xt_icon_from_file(struct tab
*t
, char *file
)
5536 if (g_str_has_prefix(file
, "file://"))
5537 file
+= strlen("file://");
5539 pb
= gdk_pixbuf_new_from_file(file
, NULL
);
5541 xt_icon_from_pixbuf(t
, pb
);
5544 xt_icon_from_name(t
, "text-html");
5548 is_valid_icon(char *file
)
5551 const char *mime_type
;
5555 gf
= g_file_new_for_path(file
);
5556 fi
= g_file_query_info(gf
, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
, 0,
5558 mime_type
= g_file_info_get_content_type(fi
);
5559 valid
= g_strcmp0(mime_type
, "image/x-ico") == 0 ||
5560 g_strcmp0(mime_type
, "image/vnd.microsoft.icon") == 0 ||
5561 g_strcmp0(mime_type
, "image/png") == 0 ||
5562 g_strcmp0(mime_type
, "image/gif") == 0 ||
5563 g_strcmp0(mime_type
, "application/octet-stream") == 0;
5571 set_favicon_from_file(struct tab
*t
, char *file
)
5575 if (t
== NULL
|| file
== NULL
)
5578 if (g_str_has_prefix(file
, "file://"))
5579 file
+= strlen("file://");
5580 DNPRINTF(XT_D_DOWNLOAD
, "%s: loading %s\n", __func__
, file
);
5582 if (!stat(file
, &sb
)) {
5583 if (sb
.st_size
== 0 || !is_valid_icon(file
)) {
5584 /* corrupt icon so trash it */
5585 DNPRINTF(XT_D_DOWNLOAD
, "%s: corrupt icon %s\n",
5588 /* no need to set icon to default here */
5592 xt_icon_from_file(t
, file
);
5596 favicon_download_status_changed_cb(WebKitDownload
*download
, GParamSpec
*spec
,
5599 WebKitDownloadStatus status
= webkit_download_get_status(download
);
5600 struct tab
*tt
= NULL
, *t
= NULL
;
5603 * find the webview instead of passing in the tab as it could have been
5604 * deleted from underneath us.
5606 TAILQ_FOREACH(tt
, &tabs
, entry
) {
5615 DNPRINTF(XT_D_DOWNLOAD
, "%s: tab %d status %d\n",
5616 __func__
, t
->tab_id
, status
);
5619 case WEBKIT_DOWNLOAD_STATUS_ERROR
:
5621 t
->icon_download
= NULL
;
5624 case WEBKIT_DOWNLOAD_STATUS_CREATED
:
5627 case WEBKIT_DOWNLOAD_STATUS_STARTED
:
5630 case WEBKIT_DOWNLOAD_STATUS_CANCELLED
:
5632 DNPRINTF(XT_D_DOWNLOAD
, "%s: freeing favicon %d\n",
5633 __func__
, t
->tab_id
);
5634 t
->icon_download
= NULL
;
5637 case WEBKIT_DOWNLOAD_STATUS_FINISHED
:
5640 DNPRINTF(XT_D_DOWNLOAD
, "%s: setting icon to %s\n",
5641 __func__
, t
->icon_dest_uri
);
5642 set_favicon_from_file(t
, t
->icon_dest_uri
);
5643 /* these will be freed post callback */
5644 t
->icon_request
= NULL
;
5645 t
->icon_download
= NULL
;
5653 abort_favicon_download(struct tab
*t
)
5655 DNPRINTF(XT_D_DOWNLOAD
, "%s: down %p\n", __func__
, t
->icon_download
);
5657 #if !WEBKIT_CHECK_VERSION(1, 4, 0)
5658 if (t
->icon_download
) {
5659 g_signal_handlers_disconnect_by_func(G_OBJECT(t
->icon_download
),
5660 G_CALLBACK(favicon_download_status_changed_cb
), t
->wv
);
5661 webkit_download_cancel(t
->icon_download
);
5662 t
->icon_download
= NULL
;
5667 xt_icon_from_name(t
, "text-html");
5671 notify_icon_loaded_cb(WebKitWebView
*wv
, gchar
*uri
, struct tab
*t
)
5673 DNPRINTF(XT_D_DOWNLOAD
, "%s %s\n", __func__
, uri
);
5675 if (uri
== NULL
|| t
== NULL
)
5678 #if WEBKIT_CHECK_VERSION(1, 4, 0)
5679 /* take icon from WebKitIconDatabase */
5682 pb
= webkit_web_view_get_icon_pixbuf(wv
);
5684 xt_icon_from_pixbuf(t
, pb
);
5687 xt_icon_from_name(t
, "text-html");
5688 #elif WEBKIT_CHECK_VERSION(1, 1, 18)
5689 /* download icon to cache dir */
5690 gchar
*name_hash
, file
[PATH_MAX
];
5693 if (t
->icon_request
) {
5694 DNPRINTF(XT_D_DOWNLOAD
, "%s: download in progress\n", __func__
);
5698 /* check to see if we got the icon in cache */
5699 name_hash
= g_compute_checksum_for_string(G_CHECKSUM_SHA256
, uri
, -1);
5700 snprintf(file
, sizeof file
, "%s/%s.ico", cache_dir
, name_hash
);
5703 if (!stat(file
, &sb
)) {
5704 if (sb
.st_size
> 0) {
5705 DNPRINTF(XT_D_DOWNLOAD
, "%s: loading from cache %s\n",
5707 set_favicon_from_file(t
, file
);
5711 /* corrupt icon so trash it */
5712 DNPRINTF(XT_D_DOWNLOAD
, "%s: corrupt icon %s\n",
5717 /* create download for icon */
5718 t
->icon_request
= webkit_network_request_new(uri
);
5719 if (t
->icon_request
== NULL
) {
5720 DNPRINTF(XT_D_DOWNLOAD
, "%s: invalid uri %s\n",
5725 t
->icon_download
= webkit_download_new(t
->icon_request
);
5726 if (t
->icon_download
== NULL
)
5729 /* we have to free icon_dest_uri later */
5730 t
->icon_dest_uri
= g_strdup_printf("file://%s", file
);
5731 webkit_download_set_destination_uri(t
->icon_download
,
5734 if (webkit_download_get_status(t
->icon_download
) ==
5735 WEBKIT_DOWNLOAD_STATUS_ERROR
) {
5736 g_object_unref(t
->icon_request
);
5737 g_free(t
->icon_dest_uri
);
5738 t
->icon_request
= NULL
;
5739 t
->icon_dest_uri
= NULL
;
5743 g_signal_connect(G_OBJECT(t
->icon_download
), "notify::status",
5744 G_CALLBACK(favicon_download_status_changed_cb
), t
->wv
);
5746 webkit_download_start(t
->icon_download
);
5751 notify_load_status_cb(WebKitWebView
* wview
, GParamSpec
* pspec
, struct tab
*t
)
5753 const gchar
*uri
= NULL
, *title
= NULL
;
5754 struct history
*h
, find
;
5758 DNPRINTF(XT_D_URL
, "notify_load_status_cb: %d %s\n",
5759 webkit_web_view_get_load_status(wview
),
5760 get_uri(t
) ? get_uri(t
) : "NOTHING");
5763 show_oops(NULL
, "notify_load_status_cb invalid parameters");
5767 switch (webkit_web_view_get_load_status(wview
)) {
5768 case WEBKIT_LOAD_PROVISIONAL
:
5770 abort_favicon_download(t
);
5771 #if GTK_CHECK_VERSION(2, 20, 0)
5772 gtk_widget_show(t
->spinner
);
5773 gtk_spinner_start(GTK_SPINNER(t
->spinner
));
5775 gtk_label_set_text(GTK_LABEL(t
->label
), "Loading");
5777 gtk_widget_set_sensitive(GTK_WIDGET(t
->stop
), TRUE
);
5779 /* assume we are a new address */
5780 gdk_color_parse("white", &color
);
5781 gtk_widget_modify_base(t
->uri_entry
, GTK_STATE_NORMAL
, &color
);
5782 statusbar_modify_attr(t
, "white", XT_COLOR_BLACK
);
5784 /* take focus if we are visible */
5790 /* kill color thread */
5795 case WEBKIT_LOAD_COMMITTED
:
5800 gtk_entry_set_text(GTK_ENTRY(t
->uri_entry
), uri
);
5806 set_status(t
, (char *)uri
, XT_STATUS_LOADING
);
5808 /* check if js white listing is enabled */
5809 if (enable_plugin_whitelist
)
5810 check_and_set_pl(uri
, t
);
5811 if (enable_cookie_whitelist
)
5812 check_and_set_cookie(uri
, t
);
5813 if (enable_js_whitelist
)
5814 check_and_set_js(uri
, t
);
5820 /* we know enough to autosave the session */
5821 if (session_autosave
) {
5826 show_ca_status(t
, uri
);
5829 case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT
:
5833 case WEBKIT_LOAD_FINISHED
:
5839 if (!strncmp(uri
, "http://", strlen("http://")) ||
5840 !strncmp(uri
, "https://", strlen("https://")) ||
5841 !strncmp(uri
, "file://", strlen("file://"))) {
5843 h
= RB_FIND(history_list
, &hl
, &find
);
5845 title
= get_title(t
, FALSE
);
5846 h
= g_malloc(sizeof *h
);
5847 h
->uri
= g_strdup(uri
);
5848 h
->title
= g_strdup(title
);
5849 RB_INSERT(history_list
, &hl
, h
);
5850 completion_add_uri(h
->uri
);
5851 update_history_tabs(NULL
);
5855 set_status(t
, (char *)uri
, XT_STATUS_URI
);
5856 #if WEBKIT_CHECK_VERSION(1, 1, 18)
5857 case WEBKIT_LOAD_FAILED
:
5860 #if GTK_CHECK_VERSION(2, 20, 0)
5861 gtk_spinner_stop(GTK_SPINNER(t
->spinner
));
5862 gtk_widget_hide(t
->spinner
);
5865 gtk_widget_set_sensitive(GTK_WIDGET(t
->stop
), FALSE
);
5870 gtk_widget_set_sensitive(GTK_WIDGET(t
->backward
), TRUE
);
5872 gtk_widget_set_sensitive(GTK_WIDGET(t
->backward
),
5873 can_go_back_for_real(t
));
5875 gtk_widget_set_sensitive(GTK_WIDGET(t
->forward
),
5876 can_go_forward_for_real(t
));
5880 notify_title_cb(WebKitWebView
* wview
, GParamSpec
* pspec
, struct tab
*t
)
5882 const gchar
*title
= NULL
, *win_title
= NULL
;
5884 title
= get_title(t
, FALSE
);
5885 win_title
= get_title(t
, TRUE
);
5886 gtk_label_set_text(GTK_LABEL(t
->label
), title
);
5887 gtk_label_set_text(GTK_LABEL(t
->tab_elems
.label
), title
);
5888 if (t
->tab_id
== gtk_notebook_get_current_page(notebook
))
5889 gtk_window_set_title(GTK_WINDOW(main_window
), win_title
);
5893 webview_load_finished_cb(WebKitWebView
*wv
, WebKitWebFrame
*wf
, struct tab
*t
)
5895 run_script(t
, JS_HINTING
);
5896 if (autofocus_onload
&&
5897 t
->tab_id
== gtk_notebook_get_current_page(notebook
))
5898 run_script(t
, "hints.focusInput();");
5900 run_script(t
, "hints.clearFocus();");
5904 webview_progress_changed_cb(WebKitWebView
*wv
, int progress
, struct tab
*t
)
5906 gtk_entry_set_progress_fraction(GTK_ENTRY(t
->uri_entry
),
5907 progress
== 100 ? 0 : (double)progress
/ 100);
5908 if (show_url
== 0) {
5909 gtk_entry_set_progress_fraction(GTK_ENTRY(t
->sbe
.statusbar
),
5910 progress
== 100 ? 0 : (double)progress
/ 100);
5913 update_statusbar_position(NULL
, NULL
);
5917 webview_npd_cb(WebKitWebView
*wv
, WebKitWebFrame
*wf
,
5918 WebKitNetworkRequest
*request
, WebKitWebNavigationAction
*na
,
5919 WebKitWebPolicyDecision
*pd
, struct tab
*t
)
5922 WebKitWebNavigationReason reason
;
5923 struct domain
*d
= NULL
;
5926 show_oops(NULL
, "webview_npd_cb invalid parameters");
5930 DNPRINTF(XT_D_NAV
, "webview_npd_cb: ctrl_click %d %s\n",
5932 webkit_network_request_get_uri(request
));
5934 uri
= (char *)webkit_network_request_get_uri(request
);
5936 /* if this is an xtp url, we don't load anything else */
5937 if (parse_xtp_url(t
, uri
))
5940 if ((t
->hints_on
&& t
->new_tab
) || t
->ctrl_click
) {
5942 create_new_tab(uri
, NULL
, ctrl_click_focus
, -1);
5943 webkit_web_policy_decision_ignore(pd
);
5944 return (TRUE
); /* we made the decission */
5948 * This is a little hairy but it comes down to this:
5949 * when we run in whitelist mode we have to assist the browser in
5950 * opening the URL that it would have opened in a new tab.
5952 reason
= webkit_web_navigation_action_get_reason(na
);
5953 if (reason
== WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED
) {
5954 t
->xtp_meaning
= XT_XTP_TAB_MEANING_NORMAL
;
5955 if (enable_scripts
== 0 && enable_cookie_whitelist
== 1)
5956 if (uri
&& (d
= wl_find_uri(uri
, &js_wl
)) == NULL
)
5958 webkit_web_policy_decision_use(pd
);
5959 return (TRUE
); /* we made the decision */
5966 webview_cwv_cb(WebKitWebView
*wv
, WebKitWebFrame
*wf
, struct tab
*t
)
5969 struct domain
*d
= NULL
;
5971 WebKitWebView
*webview
= NULL
;
5973 DNPRINTF(XT_D_NAV
, "webview_cwv_cb: %s\n",
5974 webkit_web_view_get_uri(wv
));
5977 /* open in current tab */
5979 } else if (enable_scripts
== 0 && enable_cookie_whitelist
== 1) {
5980 uri
= webkit_web_view_get_uri(wv
);
5981 if (uri
&& (d
= wl_find_uri(uri
, &js_wl
)) == NULL
)
5984 tt
= create_new_tab(NULL
, NULL
, 1, -1);
5986 } else if (enable_scripts
== 1) {
5987 tt
= create_new_tab(NULL
, NULL
, 1, -1);
5995 webview_closewv_cb(WebKitWebView
*wv
, struct tab
*t
)
5998 struct domain
*d
= NULL
;
6000 DNPRINTF(XT_D_NAV
, "webview_close_cb: %d\n", t
->tab_id
);
6002 if (enable_scripts
== 0 && enable_cookie_whitelist
== 1) {
6003 uri
= webkit_web_view_get_uri(wv
);
6004 if (uri
&& (d
= wl_find_uri(uri
, &js_wl
)) == NULL
)
6008 } else if (enable_scripts
== 1)
6015 webview_event_cb(GtkWidget
*w
, GdkEventButton
*e
, struct tab
*t
)
6017 /* we can not eat the event without throwing gtk off so defer it */
6019 /* catch middle click */
6020 if (e
->type
== GDK_BUTTON_RELEASE
&& e
->button
== 2) {
6025 /* catch ctrl click */
6026 if (e
->type
== GDK_BUTTON_RELEASE
&&
6027 CLEAN(e
->state
) == GDK_CONTROL_MASK
)
6032 return (XT_CB_PASSTHROUGH
);
6036 run_mimehandler(struct tab
*t
, char *mime_type
, WebKitNetworkRequest
*request
)
6038 struct mime_type
*m
;
6040 m
= find_mime_type(mime_type
);
6048 show_oops(t
, "can't fork mime handler");
6058 execlp(m
->mt_action
, m
->mt_action
,
6059 webkit_network_request_get_uri(request
), (void *)NULL
);
6068 get_mime_type(const char *file
)
6071 char *mime_type
= NULL
;
6075 if (g_str_has_prefix(file
, "file://"))
6076 file
+= strlen("file://");
6078 gf
= g_file_new_for_path(file
);
6079 fi
= g_file_query_info(gf
, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
, 0,
6081 if ((m
= g_file_info_get_content_type(fi
)) != NULL
)
6082 mime_type
= g_strdup(m
);
6090 run_download_mimehandler(char *mime_type
, char *file
)
6092 struct mime_type
*m
;
6094 m
= find_mime_type(mime_type
);
6100 show_oops(NULL
, "can't fork download mime handler");
6110 if (g_str_has_prefix(file
, "file://"))
6111 file
+= strlen("file://");
6112 execlp(m
->mt_action
, m
->mt_action
, file
, (void *)NULL
);
6121 download_status_changed_cb(WebKitDownload
*download
, GParamSpec
*spec
,
6124 WebKitDownloadStatus status
;
6125 const char *file
= NULL
;
6128 if (download
== NULL
)
6130 status
= webkit_download_get_status(download
);
6131 if (status
!= WEBKIT_DOWNLOAD_STATUS_FINISHED
)
6134 file
= webkit_download_get_destination_uri(download
);
6137 mime
= get_mime_type(file
);
6141 run_download_mimehandler((char *)mime
, (char *)file
);
6146 webview_mimetype_cb(WebKitWebView
*wv
, WebKitWebFrame
*frame
,
6147 WebKitNetworkRequest
*request
, char *mime_type
,
6148 WebKitWebPolicyDecision
*decision
, struct tab
*t
)
6151 show_oops(NULL
, "webview_mimetype_cb invalid parameters");
6155 DNPRINTF(XT_D_DOWNLOAD
, "webview_mimetype_cb: tab %d mime %s\n",
6156 t
->tab_id
, mime_type
);
6158 if (run_mimehandler(t
, mime_type
, request
) == 0) {
6159 webkit_web_policy_decision_ignore(decision
);
6164 if (webkit_web_view_can_show_mime_type(wv
, mime_type
) == FALSE
) {
6165 webkit_web_policy_decision_download(decision
);
6173 webview_download_cb(WebKitWebView
*wv
, WebKitDownload
*wk_download
,
6177 const gchar
*suggested_name
;
6178 gchar
*filename
= NULL
;
6180 struct download
*download_entry
;
6183 if (wk_download
== NULL
|| t
== NULL
) {
6184 show_oops(NULL
, "%s invalid parameters", __func__
);
6188 suggested_name
= webkit_download_get_suggested_filename(wk_download
);
6189 if (suggested_name
== NULL
)
6190 return (FALSE
); /* abort download */
6201 filename
= g_strdup_printf("%d%s", i
, suggested_name
);
6203 uri
= g_strdup_printf("file://%s/%s", download_dir
, i
?
6204 filename
: suggested_name
);
6206 } while (!stat(uri
+ strlen("file://"), &sb
));
6208 DNPRINTF(XT_D_DOWNLOAD
, "%s: tab %d filename %s "
6209 "local %s\n", __func__
, t
->tab_id
, filename
, uri
);
6211 webkit_download_set_destination_uri(wk_download
, uri
);
6213 if (webkit_download_get_status(wk_download
) ==
6214 WEBKIT_DOWNLOAD_STATUS_ERROR
) {
6215 show_oops(t
, "%s: download failed to start", __func__
);
6217 gtk_label_set_text(GTK_LABEL(t
->label
), "Download Failed");
6219 /* connect "download first" mime handler */
6220 g_signal_connect(G_OBJECT(wk_download
), "notify::status",
6221 G_CALLBACK(download_status_changed_cb
), NULL
);
6223 download_entry
= g_malloc(sizeof(struct download
));
6224 download_entry
->download
= wk_download
;
6225 download_entry
->tab
= t
;
6226 download_entry
->id
= next_download_id
++;
6227 RB_INSERT(download_list
, &downloads
, download_entry
);
6228 /* get from history */
6229 g_object_ref(wk_download
);
6230 gtk_label_set_text(GTK_LABEL(t
->label
), "Downloading");
6231 show_oops(t
, "Download of '%s' started...",
6232 basename((char *)webkit_download_get_destination_uri(wk_download
)));
6241 /* sync other download manager tabs */
6242 update_download_tabs(NULL
);
6245 * NOTE: never redirect/render the current tab before this
6246 * function returns. This will cause the download to never start.
6248 return (ret
); /* start download */
6252 webview_hover_cb(WebKitWebView
*wv
, gchar
*title
, gchar
*uri
, struct tab
*t
)
6254 DNPRINTF(XT_D_KEY
, "webview_hover_cb: %s %s\n", title
, uri
);
6257 show_oops(NULL
, "webview_hover_cb");
6262 set_status(t
, uri
, XT_STATUS_LINK
);
6265 set_status(t
, t
->status
, XT_STATUS_NOTHING
);
6270 mark(struct tab
*t
, struct karg
*arg
)
6276 if ((index
= marktoindex(mark
)) == -1)
6279 if (arg
->i
== XT_MARK_SET
)
6280 t
->mark
[index
] = gtk_adjustment_get_value(t
->adjust_v
);
6281 else if (arg
->i
== XT_MARK_GOTO
) {
6282 if (t
->mark
[index
] == XT_INVALID_MARK
) {
6283 show_oops(t
, "mark '%c' does not exist", mark
);
6286 /* XXX t->mark[index] can be bigger than the maximum if ajax or
6287 something changes the document size */
6288 gtk_adjustment_set_value(t
->adjust_v
, t
->mark
[index
]);
6295 marks_clear(struct tab
*t
)
6299 for (i
= 0; i
< LENGTH(t
->mark
); i
++)
6300 t
->mark
[i
] = XT_INVALID_MARK
;
6306 char file
[PATH_MAX
];
6307 char *line
= NULL
, *p
;
6312 snprintf(file
, sizeof file
, "%s/%s", work_dir
, XT_QMARKS_FILE
);
6313 if ((f
= fopen(file
, "r+")) == NULL
) {
6314 show_oops(NULL
, "Can't open quickmarks file: %s", strerror(errno
));
6318 for (i
= 1; ; i
++) {
6319 if ((line
= fparseln(f
, &linelen
, NULL
, NULL
, 0)) == NULL
)
6321 if (strlen(line
) == 0 || line
[0] == '#') {
6327 p
= strtok(line
, " \t");
6329 if (p
== NULL
|| strlen(p
) != 1 ||
6330 (index
= marktoindex(*p
)) == -1) {
6331 warnx("corrupt quickmarks file, line %d", i
);
6335 p
= strtok(NULL
, " \t");
6336 if (qmarks
[index
] != NULL
)
6337 g_free(qmarks
[index
]);
6338 qmarks
[index
] = g_strdup(p
);
6349 char file
[PATH_MAX
];
6353 snprintf(file
, sizeof file
, "%s/%s", work_dir
, XT_QMARKS_FILE
);
6354 if ((f
= fopen(file
, "r+")) == NULL
) {
6355 show_oops(NULL
, "Can't open quickmarks file: %s", strerror(errno
));
6359 for (i
= 0; i
< XT_NOMARKS
; i
++)
6360 if (qmarks
[i
] != NULL
)
6361 fprintf(f
, "%c %s\n", indextomark(i
), qmarks
[i
]);
6369 qmark(struct tab
*t
, struct karg
*arg
)
6374 mark
= arg
->s
[strlen(arg
->s
)-1];
6375 index
= marktoindex(mark
);
6381 if (qmarks
[index
] != NULL
)
6382 g_free(qmarks
[index
]);
6384 qmarks_load(); /* sync if multiple instances */
6385 qmarks
[index
] = g_strdup(get_uri(t
));
6389 if (qmarks
[index
] != NULL
)
6390 load_uri(t
, qmarks
[index
]);
6392 show_oops(t
, "quickmark \"%c\" does not exist",
6398 if (qmarks
[index
] != NULL
)
6399 create_new_tab(qmarks
[index
], NULL
, 1, -1);
6401 show_oops(t
, "quickmark \"%c\" does not exist",
6412 go_up(struct tab
*t
, struct karg
*args
)
6418 levels
= atoi(args
->s
);
6422 uri
= g_strdup(webkit_web_view_get_uri(t
->wv
));
6423 if ((tmp
= strstr(uri
, XT_PROTO_DELIM
)) == NULL
)
6425 tmp
+= strlen(XT_PROTO_DELIM
);
6427 /* if an uri starts with a slash, leave it alone (for file:///) */
6434 p
= strrchr(tmp
, '/');
6448 gototab(struct tab
*t
, struct karg
*args
)
6451 struct karg arg
= {0, NULL
, -1};
6453 tab
= atoi(args
->s
);
6455 arg
.i
= XT_TAB_NEXT
;
6464 zoom_amount(struct tab
*t
, struct karg
*arg
)
6466 struct karg narg
= {0, NULL
, -1};
6468 narg
.i
= atoi(arg
->s
);
6469 resizetab(t
, &narg
);
6475 flip_colon(struct tab
*t
, struct karg
*arg
)
6477 struct karg narg
= {0, NULL
, -1};
6480 if (t
== NULL
|| arg
== NULL
)
6483 p
= strstr(arg
->s
, ":");
6495 /* buffer commands receive the regex that triggered them in arg.s */
6496 char bcmd
[XT_BUFCMD_SZ
];
6500 #define XT_PRE_NO (0)
6501 #define XT_PRE_YES (1)
6502 #define XT_PRE_MAYBE (2)
6504 int (*func
)(struct tab
*, struct karg
*);
6508 { "^[0-9]*gu$", XT_PRE_MAYBE
, "gu", go_up
, 0 },
6509 { "^gg$", XT_PRE_NO
, "gg", move
, XT_MOVE_TOP
},
6510 { "^gG$", XT_PRE_NO
, "gG", move
, XT_MOVE_BOTTOM
},
6511 { "^[0-9]+%$", XT_PRE_YES
, "%", move
, XT_MOVE_PERCENT
},
6512 { "^gh$", XT_PRE_NO
, "gh", go_home
, 0 },
6513 { "^m[a-zA-Z0-9]$", XT_PRE_NO
, "m", mark
, XT_MARK_SET
},
6514 { "^['][a-zA-Z0-9]$", XT_PRE_NO
, "'", mark
, XT_MARK_GOTO
},
6515 { "^[0-9]+t$", XT_PRE_YES
, "t", gototab
, 0 },
6516 { "^M[a-zA-Z0-9]$", XT_PRE_NO
, "M", qmark
, XT_QMARK_SET
},
6517 { "^go[a-zA-Z0-9]$", XT_PRE_NO
, "go", qmark
, XT_QMARK_OPEN
},
6518 { "^gn[a-zA-Z0-9]$", XT_PRE_NO
, "gn", qmark
, XT_QMARK_TAB
},
6519 { "^ZR$", XT_PRE_NO
, "ZR", restart
, 0 },
6520 { "^ZZ$", XT_PRE_NO
, "ZZ", quit
, 0 },
6521 { "^zi$", XT_PRE_NO
, "zi", resizetab
, XT_ZOOM_IN
},
6522 { "^zo$", XT_PRE_NO
, "zo", resizetab
, XT_ZOOM_OUT
},
6523 { "^z0$", XT_PRE_NO
, "z0", resizetab
, XT_ZOOM_NORMAL
},
6524 { "^[0-9]+Z$", XT_PRE_YES
, "Z", zoom_amount
, 0 },
6525 { "^[0-9]+:$", XT_PRE_YES
, ":", flip_colon
, 0 },
6529 buffercmd_init(void)
6533 for (i
= 0; i
< LENGTH(buffercmds
); i
++)
6534 if (regcomp(&buffercmds
[i
].cregex
, buffercmds
[i
].regex
,
6535 REG_EXTENDED
| REG_NOSUB
))
6536 startpage_add("invalid buffercmd regex %s",
6537 buffercmds
[i
].regex
);
6541 buffercmd_abort(struct tab
*t
)
6545 DNPRINTF(XT_D_BUFFERCMD
, "buffercmd_abort: clearing buffer\n");
6546 for (i
= 0; i
< LENGTH(bcmd
); i
++)
6549 cmd_prefix
= 0; /* clear prefix for non-buffer commands */
6550 gtk_entry_set_text(GTK_ENTRY(t
->sbe
.buffercmd
), bcmd
);
6554 buffercmd_execute(struct tab
*t
, struct buffercmd
*cmd
)
6556 struct karg arg
= {0, NULL
, -1};
6559 arg
.s
= g_strdup(bcmd
);
6561 DNPRINTF(XT_D_BUFFERCMD
, "buffercmd_execute: buffer \"%s\" "
6562 "matches regex \"%s\", executing\n", bcmd
, cmd
->regex
);
6572 buffercmd_addkey(struct tab
*t
, guint keyval
)
6575 char s
[XT_BUFCMD_SZ
];
6577 if (keyval
== GDK_Escape
) {
6579 return (XT_CB_HANDLED
);
6582 /* key with modifier or non-ascii character */
6583 if (!isascii(keyval
))
6584 return (XT_CB_PASSTHROUGH
);
6586 DNPRINTF(XT_D_BUFFERCMD
, "buffercmd_addkey: adding key \"%c\" "
6587 "to buffer \"%s\"\n", keyval
, bcmd
);
6589 for (i
= 0; i
< LENGTH(bcmd
); i
++)
6590 if (bcmd
[i
] == '\0') {
6595 /* buffer full, ignore input */
6596 if (i
>= LENGTH(bcmd
) -1) {
6597 DNPRINTF(XT_D_BUFFERCMD
, "buffercmd_addkey: buffer full\n");
6599 return (XT_CB_HANDLED
);
6602 gtk_entry_set_text(GTK_ENTRY(t
->sbe
.buffercmd
), bcmd
);
6604 /* find exact match */
6605 for (i
= 0; i
< LENGTH(buffercmds
); i
++)
6606 if (regexec(&buffercmds
[i
].cregex
, bcmd
,
6607 (size_t) 0, NULL
, 0) == 0) {
6608 buffercmd_execute(t
, &buffercmds
[i
]);
6612 /* find non exact matches to see if we need to abort ot not */
6613 for (i
= 0, match
= 0; i
< LENGTH(buffercmds
); i
++) {
6614 DNPRINTF(XT_D_BUFFERCMD
, "trying: %s\n", bcmd
);
6617 if (buffercmds
[i
].precount
== XT_PRE_MAYBE
) {
6618 if (isdigit(bcmd
[0])) {
6619 if (sscanf(bcmd
, "%d%s", &c
, s
) == 0)
6623 if (sscanf(bcmd
, "%s", s
) == 0)
6626 } else if (buffercmds
[i
].precount
== XT_PRE_YES
) {
6627 if (sscanf(bcmd
, "%d%s", &c
, s
) == 0)
6630 if (sscanf(bcmd
, "%s", s
) == 0)
6633 if (c
== -1 && buffercmds
[i
].precount
)
6635 if (!strncmp(s
, buffercmds
[i
].cmd
, strlen(s
)))
6638 DNPRINTF(XT_D_BUFFERCMD
, "got[%d] %d <%s>: %d %s\n",
6639 i
, match
, buffercmds
[i
].cmd
, c
, s
);
6642 DNPRINTF(XT_D_BUFFERCMD
, "aborting: %s\n", bcmd
);
6647 return (XT_CB_HANDLED
);
6651 handle_keypress(struct tab
*t
, GdkEventKey
*e
, int entry
)
6653 struct key_binding
*k
;
6655 /* handle keybindings if buffercmd is empty.
6656 if not empty, allow commands like C-n */
6657 if (bcmd
[0] == '\0' || ((e
->state
& (CTRL
| MOD1
)) != 0))
6658 TAILQ_FOREACH(k
, &kbl
, entry
)
6659 if (e
->keyval
== k
->key
6660 && (entry
? k
->use_in_entry
: 1)) {
6662 if ((e
->state
& (CTRL
| MOD1
)) == 0)
6663 return (cmd_execute(t
, k
->cmd
));
6664 } else if ((e
->state
& k
->mask
) == k
->mask
) {
6665 return (cmd_execute(t
, k
->cmd
));
6669 if (!entry
&& ((e
->state
& (CTRL
| MOD1
)) == 0))
6670 return buffercmd_addkey(t
, e
->keyval
);
6672 return (XT_CB_PASSTHROUGH
);
6676 wv_keypress_after_cb(GtkWidget
*w
, GdkEventKey
*e
, struct tab
*t
)
6680 /* don't use w directly; use t->whatever instead */
6683 show_oops(NULL
, "wv_keypress_after_cb");
6684 return (XT_CB_PASSTHROUGH
);
6687 DNPRINTF(XT_D_KEY
, "wv_keypress_after_cb: keyval 0x%x mask 0x%x t %p\n",
6688 e
->keyval
, e
->state
, t
);
6691 /* XXX make sure cmd entry is enabled */
6692 return (XT_CB_HANDLED
);
6695 snprintf(s
, sizeof s
, "%c", e
->keyval
);
6696 if (CLEAN(e
->state
) == 0 && isdigit(s
[0]))
6697 cmd_prefix
= 10 * cmd_prefix
+ atoi(s
);
6700 return (handle_keypress(t
, e
, 0));
6704 wv_keypress_cb(GtkEntry
*w
, GdkEventKey
*e
, struct tab
*t
)
6708 /* Hide buffers, if they are visible, with escape. */
6709 if (gtk_widget_get_visible(GTK_WIDGET(t
->buffers
)) &&
6710 CLEAN(e
->state
) == 0 && e
->keyval
== GDK_Escape
) {
6711 gtk_widget_grab_focus(GTK_WIDGET(t
->wv
));
6713 return (XT_CB_HANDLED
);
6716 return (XT_CB_PASSTHROUGH
);
6720 hint_continue(struct tab
*t
)
6722 const gchar
*c
= gtk_entry_get_text(GTK_ENTRY(t
->cmd
));
6724 const gchar
*errstr
= NULL
;
6728 if (!(c
[0] == '.' || c
[0] == ','))
6730 if (strlen(c
) == 1) {
6731 /* XXX should not happen */
6736 if (isdigit(c
[1])) {
6738 i
= strtonum(&c
[1], 1, 4096, &errstr
);
6740 show_oops(t
, "invalid numerical hint %s", &c
[1]);
6743 s
= g_strdup_printf("hints.updateHints(%lld);", i
);
6747 /* alphanumeric input */
6748 s
= g_strdup_printf("hints.createHints('%s', '%c');",
6749 &c
[1], c
[0] == '.' ? 'f' : 'F');
6760 search_continue(struct tab
*t
)
6762 const gchar
*c
= gtk_entry_get_text(GTK_ENTRY(t
->cmd
));
6763 gboolean rv
= FALSE
;
6765 if (c
[0] == ':' || c
[0] == '.' || c
[0] == ',')
6767 if (strlen(c
) == 1) {
6768 webkit_web_view_unmark_text_matches(t
->wv
);
6773 t
->search_forward
= TRUE
;
6774 else if (c
[0] == '?')
6775 t
->search_forward
= FALSE
;
6785 search_cb(struct tab
*t
)
6787 const gchar
*c
= gtk_entry_get_text(GTK_ENTRY(t
->cmd
));
6790 if (search_continue(t
) == FALSE
)
6794 if (webkit_web_view_search_text(t
->wv
, &c
[1], FALSE
, t
->search_forward
,
6796 /* not found, mark red */
6797 gdk_color_parse(XT_COLOR_RED
, &color
);
6798 gtk_widget_modify_base(t
->cmd
, GTK_STATE_NORMAL
, &color
);
6799 /* unmark and remove selection */
6800 webkit_web_view_unmark_text_matches(t
->wv
);
6801 /* my kingdom for a way to unselect text in webview */
6803 /* found, highlight all */
6804 webkit_web_view_unmark_text_matches(t
->wv
);
6805 webkit_web_view_mark_text_matches(t
->wv
, &c
[1], FALSE
, 0);
6806 webkit_web_view_set_highlight_text_matches(t
->wv
, TRUE
);
6807 gdk_color_parse(XT_COLOR_WHITE
, &color
);
6808 gtk_widget_modify_base(t
->cmd
, GTK_STATE_NORMAL
, &color
);
6816 cmd_keyrelease_cb(GtkEntry
*w
, GdkEventKey
*e
, struct tab
*t
)
6818 const gchar
*c
= gtk_entry_get_text(w
);
6821 show_oops(NULL
, "cmd_keyrelease_cb invalid parameters");
6822 return (XT_CB_PASSTHROUGH
);
6825 DNPRINTF(XT_D_CMD
, "cmd_keyrelease_cb: keyval 0x%x mask 0x%x t %p\n",
6826 e
->keyval
, e
->state
, t
);
6829 if (!(e
->keyval
== GDK_Tab
|| e
->keyval
== GDK_ISO_Left_Tab
)) {
6830 if (hint_continue(t
) == FALSE
)
6835 if (search_continue(t
) == FALSE
)
6838 /* if search length is > 4 then no longer play timeout games */
6839 if (strlen(c
) > 4) {
6841 g_source_remove(t
->search_id
);
6848 /* reestablish a new timer if the user types fast */
6850 g_source_remove(t
->search_id
);
6851 t
->search_id
= g_timeout_add(250, (GSourceFunc
)search_cb
, (gpointer
)t
);
6854 return (XT_CB_PASSTHROUGH
);
6858 match_uri(const gchar
*uri
, const gchar
*key
) {
6861 gboolean match
= FALSE
;
6865 if (!strncmp(key
, uri
, len
))
6868 voffset
= strstr(uri
, "/") + 2;
6869 if (!strncmp(key
, voffset
, len
))
6871 else if (g_str_has_prefix(voffset
, "www.")) {
6872 voffset
= voffset
+ strlen("www.");
6873 if (!strncmp(key
, voffset
, len
))
6882 match_session(const gchar
*name
, const gchar
*key
) {
6885 sub
= strcasestr(name
, key
);
6891 cmd_getlist(int id
, char *key
)
6898 if (cmds
[id
].type
& XT_URLARG
) {
6899 RB_FOREACH_REVERSE(h
, history_list
, &hl
)
6900 if (match_uri(h
->uri
, key
)) {
6901 cmd_status
.list
[c
] = (char *)h
->uri
;
6907 } else if (cmds
[id
].type
& XT_SESSARG
) {
6908 TAILQ_FOREACH(s
, &sessions
, entry
)
6909 if (match_session(s
->name
, key
)) {
6910 cmd_status
.list
[c
] = (char *)s
->name
;
6916 } else if (cmds
[id
].type
& XT_SETARG
) {
6917 for (i
= 0; i
< LENGTH(rs
); i
++)
6918 if(!strncmp(key
, rs
[i
].name
, strlen(key
)))
6919 cmd_status
.list
[c
++] = rs
[i
].name
;
6925 dep
= (id
== -1) ? 0 : cmds
[id
].level
+ 1;
6927 for (i
= id
+ 1; i
< LENGTH(cmds
); i
++) {
6928 if (cmds
[i
].level
< dep
)
6930 if (cmds
[i
].level
== dep
&& !strncmp(key
, cmds
[i
].cmd
,
6931 strlen(key
)) && !isdigit(cmds
[i
].cmd
[0]))
6932 cmd_status
.list
[c
++] = cmds
[i
].cmd
;
6940 cmd_getnext(int dir
)
6942 cmd_status
.index
+= dir
;
6944 if (cmd_status
.index
< 0)
6945 cmd_status
.index
= cmd_status
.len
- 1;
6946 else if (cmd_status
.index
>= cmd_status
.len
)
6947 cmd_status
.index
= 0;
6949 return cmd_status
.list
[cmd_status
.index
];
6953 cmd_tokenize(char *s
, char *tokens
[])
6956 char *tok
, *last
= NULL
;
6957 size_t len
= strlen(s
);
6960 blank
= len
== 0 || (len
> 0 && s
[len
- 1] == ' ');
6961 for (tok
= strtok_r(s
, " ", &last
); tok
&& i
< 3;
6962 tok
= strtok_r(NULL
, " ", &last
), i
++)
6972 cmd_complete(struct tab
*t
, char *str
, int dir
)
6974 GtkEntry
*w
= GTK_ENTRY(t
->cmd
);
6975 int i
, j
, levels
, c
= 0, dep
= 0, parent
= -1;
6977 char *tok
, *match
, *s
= g_strdup(str
);
6979 char res
[XT_MAX_URL_LENGTH
+ 32] = ":";
6982 DNPRINTF(XT_D_CMD
, "%s: complete %s\n", __func__
, str
);
6985 for (i
= 0; isdigit(s
[i
]); i
++)
6988 for (; isspace(s
[i
]); i
++)
6993 levels
= cmd_tokenize(s
, tokens
);
6995 for (i
= 0; i
< levels
- 1; i
++) {
6998 for (j
= c
; j
< LENGTH(cmds
); j
++) {
6999 if (cmds
[j
].level
< dep
)
7001 if (cmds
[j
].level
== dep
&& !strncmp(tok
, cmds
[j
].cmd
,
7005 if (strlen(tok
) == strlen(cmds
[j
].cmd
)) {
7012 if (matchcount
== 1) {
7013 strlcat(res
, tok
, sizeof res
);
7014 strlcat(res
, " ", sizeof res
);
7024 if (cmd_status
.index
== -1)
7025 cmd_getlist(parent
, tokens
[i
]);
7027 if (cmd_status
.len
> 0) {
7028 match
= cmd_getnext(dir
);
7029 strlcat(res
, match
, sizeof res
);
7030 gtk_entry_set_text(w
, res
);
7031 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
7038 cmd_execute(struct tab
*t
, char *str
)
7040 struct cmd
*cmd
= NULL
;
7041 char *tok
, *last
= NULL
, *s
= g_strdup(str
), *sc
;
7043 int j
, len
, c
= 0, dep
= 0, matchcount
= 0;
7044 int prefix
= -1, rv
= XT_CB_PASSTHROUGH
;
7045 struct karg arg
= {0, NULL
, -1};
7050 for (j
= 0; j
<3 && isdigit(s
[j
]); j
++)
7056 while (isspace(s
[0]))
7059 if (strlen(s
) > 0 && strlen(prefixstr
) > 0)
7060 prefix
= atoi(prefixstr
);
7064 for (tok
= strtok_r(s
, " ", &last
); tok
;
7065 tok
= strtok_r(NULL
, " ", &last
)) {
7067 for (j
= c
; j
< LENGTH(cmds
); j
++) {
7068 if (cmds
[j
].level
< dep
)
7070 len
= (tok
[strlen(tok
) - 1] == '!') ? strlen(tok
) - 1 :
7072 if (cmds
[j
].level
== dep
&&
7073 !strncmp(tok
, cmds
[j
].cmd
, len
)) {
7077 if (len
== strlen(cmds
[j
].cmd
)) {
7083 if (matchcount
== 1) {
7088 show_oops(t
, "Invalid command: %s", str
);
7094 show_oops(t
, "Empty command");
7100 arg
.precount
= prefix
;
7101 else if (cmd_prefix
> 0)
7102 arg
.precount
= cmd_prefix
;
7104 if (j
> 0 && !(cmd
->type
& XT_PREFIX
) && arg
.precount
> -1) {
7105 show_oops(t
, "No prefix allowed: %s", str
);
7109 arg
.s
= last
? g_strdup(last
) : g_strdup("");
7110 if (cmd
->type
& XT_INTARG
&& last
&& strlen(last
) > 0) {
7111 if (arg
.s
== NULL
) {
7112 show_oops(t
, "Invalid command");
7115 arg
.precount
= atoi(arg
.s
);
7116 if (arg
.precount
<= 0) {
7117 if (arg
.s
[0] == '0')
7118 show_oops(t
, "Zero count");
7120 show_oops(t
, "Trailing characters");
7125 DNPRINTF(XT_D_CMD
, "%s: prefix %d arg %s\n",
7126 __func__
, arg
.precount
, arg
.s
);
7142 entry_key_cb(GtkEntry
*w
, GdkEventKey
*e
, struct tab
*t
)
7145 show_oops(NULL
, "entry_key_cb invalid parameters");
7146 return (XT_CB_PASSTHROUGH
);
7149 DNPRINTF(XT_D_CMD
, "entry_key_cb: keyval 0x%x mask 0x%x t %p\n",
7150 e
->keyval
, e
->state
, t
);
7154 if (e
->keyval
== GDK_Escape
) {
7155 /* don't use focus_webview(t) because we want to type :cmds */
7156 gtk_widget_grab_focus(GTK_WIDGET(t
->wv
));
7159 return (handle_keypress(t
, e
, 1));
7162 struct command_entry
*
7163 history_prev(struct command_list
*l
, struct command_entry
*at
)
7166 at
= TAILQ_LAST(l
, command_list
);
7168 at
= TAILQ_PREV(at
, command_list
, entry
);
7170 at
= TAILQ_LAST(l
, command_list
);
7176 struct command_entry
*
7177 history_next(struct command_list
*l
, struct command_entry
*at
)
7180 at
= TAILQ_FIRST(l
);
7182 at
= TAILQ_NEXT(at
, entry
);
7184 at
= TAILQ_FIRST(l
);
7191 cmd_keypress_cb(GtkEntry
*w
, GdkEventKey
*e
, struct tab
*t
)
7193 int rv
= XT_CB_HANDLED
;
7194 const gchar
*c
= gtk_entry_get_text(w
);
7198 show_oops(NULL
, "cmd_keypress_cb parameters");
7199 return (XT_CB_PASSTHROUGH
);
7202 DNPRINTF(XT_D_CMD
, "cmd_keypress_cb: keyval 0x%x mask 0x%x t %p\n",
7203 e
->keyval
, e
->state
, t
);
7207 e
->keyval
= GDK_Escape
;
7208 else if (!(c
[0] == ':' || c
[0] == '/' || c
[0] == '?' ||
7209 c
[0] == '.' || c
[0] == ','))
7210 e
->keyval
= GDK_Escape
;
7212 if (e
->keyval
!= GDK_Tab
&& e
->keyval
!= GDK_Shift_L
&&
7213 e
->keyval
!= GDK_ISO_Left_Tab
)
7214 cmd_status
.index
= -1;
7216 switch (e
->keyval
) {
7219 cmd_complete(t
, (char *)&c
[1], 1);
7220 else if (c
[0] == '.' || c
[0] == ',')
7221 run_script(t
, "hints.focusNextHint();");
7223 case GDK_ISO_Left_Tab
:
7225 cmd_complete(t
, (char *)&c
[1], -1);
7226 else if (c
[0] == '.' || c
[0] == ',')
7227 run_script(t
, "hints.focusPreviousHint();");
7231 if ((search_at
= history_next(&shl
, search_at
))) {
7232 search_at
->line
[0] = c
[0];
7233 gtk_entry_set_text(w
, search_at
->line
);
7234 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
7236 } else if (c
[0] == '/') {
7237 if ((search_at
= history_prev(&chl
, search_at
))) {
7238 search_at
->line
[0] = c
[0];
7239 gtk_entry_set_text(w
, search_at
->line
);
7240 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
7242 } if (c
[0] == ':') {
7243 if ((history_at
= history_prev(&chl
, history_at
))) {
7244 history_at
->line
[0] = c
[0];
7245 gtk_entry_set_text(w
, history_at
->line
);
7246 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
7252 if ((search_at
= history_next(&shl
, search_at
))) {
7253 search_at
->line
[0] = c
[0];
7254 gtk_entry_set_text(w
, search_at
->line
);
7255 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
7257 } else if (c
[0] == '?') {
7258 if ((search_at
= history_prev(&chl
, search_at
))) {
7259 search_at
->line
[0] = c
[0];
7260 gtk_entry_set_text(w
, search_at
->line
);
7261 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
7263 } if (c
[0] == ':') {
7264 if ((history_at
= history_next(&chl
, history_at
))) {
7265 history_at
->line
[0] = c
[0];
7266 gtk_entry_set_text(w
, history_at
->line
);
7267 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
7272 if (!(!strcmp(c
, ":") || !strcmp(c
, "/") || !strcmp(c
, "?") ||
7273 !strcmp(c
, ".") || !strcmp(c
, ","))) {
7274 /* see if we are doing hinting and reset it */
7275 if (c
[0] == '.' || c
[0] == ',') {
7276 /* recreate hints */
7277 s
= g_strdup_printf("hints.createHints('', "
7278 "'%c');", c
[0] == '.' ? 'f' : 'F');
7291 if (c
!= NULL
&& (c
[0] == '/' || c
[0] == '?'))
7292 webkit_web_view_unmark_text_matches(t
->wv
);
7294 /* no need to cancel hints */
7298 rv
= XT_CB_PASSTHROUGH
;
7304 wv_popup_cb(GtkEntry
*entry
, GtkMenu
*menu
, struct tab
*t
)
7306 DNPRINTF(XT_D_CMD
, "wv_popup_cb: tab %d\n", t
->tab_id
);
7310 cmd_popup_cb(GtkEntry
*entry
, GtkMenu
*menu
, struct tab
*t
)
7312 /* popup menu enabled */
7317 cmd_focusout_cb(GtkWidget
*w
, GdkEventFocus
*e
, struct tab
*t
)
7320 show_oops(NULL
, "cmd_focusout_cb invalid parameters");
7321 return (XT_CB_PASSTHROUGH
);
7324 DNPRINTF(XT_D_CMD
, "cmd_focusout_cb: tab %d popup %d\n",
7325 t
->tab_id
, t
->popup
);
7327 /* if popup is enabled don't lose focus */
7330 return (XT_CB_PASSTHROUGH
);
7337 if (show_url
== 0 || t
->focus_wv
)
7340 gtk_widget_grab_focus(GTK_WIDGET(t
->uri_entry
));
7342 return (XT_CB_PASSTHROUGH
);
7346 cmd_activate_cb(GtkEntry
*entry
, struct tab
*t
)
7349 const gchar
*c
= gtk_entry_get_text(entry
);
7352 show_oops(NULL
, "cmd_activate_cb invalid parameters");
7356 DNPRINTF(XT_D_CMD
, "cmd_activate_cb: tab %d %s\n", t
->tab_id
, c
);
7362 else if (!(c
[0] == ':' || c
[0] == '/' || c
[0] == '?' ||
7363 c
[0] == '.' || c
[0] == ','))
7369 if (c
[0] == '/' || c
[0] == '?') {
7370 /* see if there is a timer pending */
7372 g_source_remove(t
->search_id
);
7377 if (t
->search_text
) {
7378 g_free(t
->search_text
);
7379 t
->search_text
= NULL
;
7382 t
->search_text
= g_strdup(s
);
7384 g_free(global_search
);
7385 global_search
= g_strdup(s
);
7386 t
->search_forward
= c
[0] == '/';
7388 history_add(&shl
, search_file
, s
, &search_history_count
);
7390 } else if (c
[0] == '.' || c
[0] == ',') {
7391 run_script(t
, "hints.fire();");
7392 /* XXX history for link following? */
7396 history_add(&chl
, command_file
, s
, &cmd_history_count
);
7403 backward_cb(GtkWidget
*w
, struct tab
*t
)
7408 show_oops(NULL
, "backward_cb invalid parameters");
7412 DNPRINTF(XT_D_NAV
, "backward_cb: tab %d\n", t
->tab_id
);
7419 forward_cb(GtkWidget
*w
, struct tab
*t
)
7424 show_oops(NULL
, "forward_cb invalid parameters");
7428 DNPRINTF(XT_D_NAV
, "forward_cb: tab %d\n", t
->tab_id
);
7430 a
.i
= XT_NAV_FORWARD
;
7435 home_cb(GtkWidget
*w
, struct tab
*t
)
7438 show_oops(NULL
, "home_cb invalid parameters");
7442 DNPRINTF(XT_D_NAV
, "home_cb: tab %d\n", t
->tab_id
);
7448 stop_cb(GtkWidget
*w
, struct tab
*t
)
7450 WebKitWebFrame
*frame
;
7453 show_oops(NULL
, "stop_cb invalid parameters");
7457 DNPRINTF(XT_D_NAV
, "stop_cb: tab %d\n", t
->tab_id
);
7459 frame
= webkit_web_view_get_main_frame(t
->wv
);
7460 if (frame
== NULL
) {
7461 show_oops(t
, "stop_cb: no frame");
7465 webkit_web_frame_stop_loading(frame
);
7466 abort_favicon_download(t
);
7470 setup_webkit(struct tab
*t
)
7472 if (is_g_object_setting(G_OBJECT(t
->settings
), "enable-dns-prefetching"))
7473 g_object_set(G_OBJECT(t
->settings
), "enable-dns-prefetching",
7474 FALSE
, (char *)NULL
);
7476 warnx("webkit does not have \"enable-dns-prefetching\" property");
7477 g_object_set(G_OBJECT(t
->settings
),
7478 "user-agent", t
->user_agent
, (char *)NULL
);
7479 g_object_set(G_OBJECT(t
->settings
),
7480 "enable-scripts", enable_scripts
, (char *)NULL
);
7481 g_object_set(G_OBJECT(t
->settings
),
7482 "enable-plugins", enable_plugins
, (char *)NULL
);
7483 g_object_set(G_OBJECT(t
->settings
),
7484 "javascript-can-open-windows-automatically", enable_scripts
,
7486 g_object_set(G_OBJECT(t
->settings
),
7487 "enable-html5-database", FALSE
, (char *)NULL
);
7488 g_object_set(G_OBJECT(t
->settings
),
7489 "enable-html5-local-storage", enable_localstorage
, (char *)NULL
);
7490 g_object_set(G_OBJECT(t
->settings
),
7491 "enable_spell_checking", enable_spell_checking
, (char *)NULL
);
7492 g_object_set(G_OBJECT(t
->settings
),
7493 "spell_checking_languages", spell_check_languages
, (char *)NULL
);
7494 g_object_set(G_OBJECT(t
->settings
),
7495 "enable-developer-extras", TRUE
, (char *)NULL
);
7496 g_object_set(G_OBJECT(t
->wv
),
7497 "full-content-zoom", TRUE
, (char *)NULL
);
7499 webkit_web_view_set_settings(t
->wv
, t
->settings
);
7503 update_statusbar_position(GtkAdjustment
* adjustment
, gpointer data
)
7505 struct tab
*ti
, *t
= NULL
;
7506 gdouble view_size
, value
, max
;
7509 TAILQ_FOREACH(ti
, &tabs
, entry
)
7510 if (ti
->tab_id
== gtk_notebook_get_current_page(notebook
)) {
7518 if (adjustment
== NULL
)
7519 adjustment
= gtk_scrolled_window_get_vadjustment(
7520 GTK_SCROLLED_WINDOW(t
->browser_win
));
7522 view_size
= gtk_adjustment_get_page_size(adjustment
);
7523 value
= gtk_adjustment_get_value(adjustment
);
7524 max
= gtk_adjustment_get_upper(adjustment
) - view_size
;
7527 position
= g_strdup("All");
7528 else if (value
== max
)
7529 position
= g_strdup("Bot");
7530 else if (value
== 0)
7531 position
= g_strdup("Top");
7533 position
= g_strdup_printf("%d%%", (int) ((value
/ max
) * 100));
7535 gtk_entry_set_text(GTK_ENTRY(t
->sbe
.position
), position
);
7542 create_window(const gchar
*name
)
7546 w
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
7547 gtk_window_set_default_size(GTK_WINDOW(w
), window_width
, window_height
);
7548 gtk_widget_set_name(w
, name
);
7549 gtk_window_set_wmclass(GTK_WINDOW(w
), name
, "XXXTerm");
7555 create_browser(struct tab
*t
)
7559 GtkAdjustment
*adjustment
;
7562 show_oops(NULL
, "create_browser invalid parameters");
7566 t
->sb_h
= GTK_SCROLLBAR(gtk_hscrollbar_new(NULL
));
7567 t
->sb_v
= GTK_SCROLLBAR(gtk_vscrollbar_new(NULL
));
7568 t
->adjust_h
= gtk_range_get_adjustment(GTK_RANGE(t
->sb_h
));
7569 t
->adjust_v
= gtk_range_get_adjustment(GTK_RANGE(t
->sb_v
));
7571 w
= gtk_scrolled_window_new(t
->adjust_h
, t
->adjust_v
);
7572 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w
),
7573 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
7575 t
->wv
= WEBKIT_WEB_VIEW(webkit_web_view_new());
7576 gtk_container_add(GTK_CONTAINER(w
), GTK_WIDGET(t
->wv
));
7579 t
->settings
= webkit_web_settings_new();
7581 g_object_set(t
->settings
, "default-encoding", encoding
, (char *)NULL
);
7583 if (user_agent
== NULL
) {
7584 g_object_get(G_OBJECT(t
->settings
), "user-agent", &strval
,
7586 t
->user_agent
= g_strdup_printf("%s %s+", strval
, version
);
7589 t
->user_agent
= g_strdup(user_agent
);
7591 t
->stylesheet
= g_strdup_printf("file://%s/style.css", resource_dir
);
7594 gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(w
));
7595 g_signal_connect(G_OBJECT(adjustment
), "value-changed",
7596 G_CALLBACK(update_statusbar_position
), NULL
);
7605 create_kiosk_toolbar(struct tab
*t
)
7607 GtkWidget
*toolbar
= NULL
, *b
;
7609 b
= gtk_hbox_new(FALSE
, 0);
7611 gtk_container_set_border_width(GTK_CONTAINER(toolbar
), 0);
7613 /* backward button */
7614 t
->backward
= create_button("Back", GTK_STOCK_GO_BACK
, 0);
7615 gtk_widget_set_sensitive(t
->backward
, FALSE
);
7616 g_signal_connect(G_OBJECT(t
->backward
), "clicked",
7617 G_CALLBACK(backward_cb
), t
);
7618 gtk_box_pack_start(GTK_BOX(b
), t
->backward
, TRUE
, TRUE
, 0);
7620 /* forward button */
7621 t
->forward
= create_button("Forward", GTK_STOCK_GO_FORWARD
, 0);
7622 gtk_widget_set_sensitive(t
->forward
, FALSE
);
7623 g_signal_connect(G_OBJECT(t
->forward
), "clicked",
7624 G_CALLBACK(forward_cb
), t
);
7625 gtk_box_pack_start(GTK_BOX(b
), t
->forward
, TRUE
, TRUE
, 0);
7628 t
->gohome
= create_button("Home", GTK_STOCK_HOME
, 0);
7629 gtk_widget_set_sensitive(t
->gohome
, true);
7630 g_signal_connect(G_OBJECT(t
->gohome
), "clicked",
7631 G_CALLBACK(home_cb
), t
);
7632 gtk_box_pack_start(GTK_BOX(b
), t
->gohome
, TRUE
, TRUE
, 0);
7634 /* create widgets but don't use them */
7635 t
->uri_entry
= gtk_entry_new();
7636 t
->stop
= create_button("Stop", GTK_STOCK_STOP
, 0);
7637 t
->js_toggle
= create_button("JS-Toggle", enable_scripts
?
7638 GTK_STOCK_MEDIA_PLAY
: GTK_STOCK_MEDIA_PAUSE
, 0);
7644 create_toolbar(struct tab
*t
)
7646 GtkWidget
*toolbar
= NULL
, *b
, *eb1
;
7648 b
= gtk_hbox_new(FALSE
, 0);
7650 gtk_container_set_border_width(GTK_CONTAINER(toolbar
), 0);
7652 /* backward button */
7653 t
->backward
= create_button("Back", GTK_STOCK_GO_BACK
, 0);
7654 gtk_widget_set_sensitive(t
->backward
, FALSE
);
7655 g_signal_connect(G_OBJECT(t
->backward
), "clicked",
7656 G_CALLBACK(backward_cb
), t
);
7657 gtk_box_pack_start(GTK_BOX(b
), t
->backward
, FALSE
, FALSE
, 0);
7659 /* forward button */
7660 t
->forward
= create_button("Forward",GTK_STOCK_GO_FORWARD
, 0);
7661 gtk_widget_set_sensitive(t
->forward
, FALSE
);
7662 g_signal_connect(G_OBJECT(t
->forward
), "clicked",
7663 G_CALLBACK(forward_cb
), t
);
7664 gtk_box_pack_start(GTK_BOX(b
), t
->forward
, FALSE
,
7668 t
->stop
= create_button("Stop", GTK_STOCK_STOP
, 0);
7669 gtk_widget_set_sensitive(t
->stop
, FALSE
);
7670 g_signal_connect(G_OBJECT(t
->stop
), "clicked",
7671 G_CALLBACK(stop_cb
), t
);
7672 gtk_box_pack_start(GTK_BOX(b
), t
->stop
, FALSE
,
7676 t
->js_toggle
= create_button("JS-Toggle", enable_scripts
?
7677 GTK_STOCK_MEDIA_PLAY
: GTK_STOCK_MEDIA_PAUSE
, 0);
7678 gtk_widget_set_sensitive(t
->js_toggle
, TRUE
);
7679 g_signal_connect(G_OBJECT(t
->js_toggle
), "clicked",
7680 G_CALLBACK(js_toggle_cb
), t
);
7681 gtk_box_pack_start(GTK_BOX(b
), t
->js_toggle
, FALSE
, FALSE
, 0);
7683 t
->uri_entry
= gtk_entry_new();
7684 g_signal_connect(G_OBJECT(t
->uri_entry
), "activate",
7685 G_CALLBACK(activate_uri_entry_cb
), t
);
7686 g_signal_connect(G_OBJECT(t
->uri_entry
), "key-press-event",
7687 G_CALLBACK(entry_key_cb
), t
);
7689 eb1
= gtk_hbox_new(FALSE
, 0);
7690 gtk_container_set_border_width(GTK_CONTAINER(eb1
), 1);
7691 gtk_box_pack_start(GTK_BOX(eb1
), t
->uri_entry
, TRUE
, TRUE
, 0);
7692 gtk_box_pack_start(GTK_BOX(b
), eb1
, TRUE
, TRUE
, 0);
7695 if (search_string
) {
7697 t
->search_entry
= gtk_entry_new();
7698 gtk_entry_set_width_chars(GTK_ENTRY(t
->search_entry
), 30);
7699 g_signal_connect(G_OBJECT(t
->search_entry
), "activate",
7700 G_CALLBACK(activate_search_entry_cb
), t
);
7701 g_signal_connect(G_OBJECT(t
->search_entry
), "key-press-event",
7702 G_CALLBACK(entry_key_cb
), t
);
7703 gtk_widget_set_size_request(t
->search_entry
, -1, -1);
7704 eb2
= gtk_hbox_new(FALSE
, 0);
7705 gtk_container_set_border_width(GTK_CONTAINER(eb2
), 1);
7706 gtk_box_pack_start(GTK_BOX(eb2
), t
->search_entry
, TRUE
, TRUE
,
7708 gtk_box_pack_start(GTK_BOX(b
), eb2
, FALSE
, FALSE
, 0);
7715 create_buffers(struct tab
*t
)
7717 GtkCellRenderer
*renderer
;
7720 view
= gtk_tree_view_new();
7722 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view
), FALSE
);
7724 renderer
= gtk_cell_renderer_text_new();
7725 gtk_tree_view_insert_column_with_attributes
7726 (GTK_TREE_VIEW(view
), -1, "Id", renderer
, "text", COL_ID
, (char *)NULL
);
7728 renderer
= gtk_cell_renderer_text_new();
7729 gtk_tree_view_insert_column_with_attributes
7730 (GTK_TREE_VIEW(view
), -1, "Title", renderer
, "text", COL_TITLE
,
7733 gtk_tree_view_set_model
7734 (GTK_TREE_VIEW(view
), GTK_TREE_MODEL(buffers_store
));
7740 row_activated_cb(GtkTreeView
*view
, GtkTreePath
*path
,
7741 GtkTreeViewColumn
*col
, struct tab
*t
)
7746 gtk_widget_grab_focus(GTK_WIDGET(t
->wv
));
7748 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(buffers_store
), &iter
,
7751 (GTK_TREE_MODEL(buffers_store
), &iter
, COL_ID
, &id
, -1);
7752 set_current_tab(id
- 1);
7758 /* after tab reordering/creation/removal */
7765 TAILQ_FOREACH(t
, &tabs
, entry
) {
7766 t
->tab_id
= gtk_notebook_page_num(notebook
, t
->vbox
);
7767 if (t
->tab_id
> maxid
)
7770 gtk_widget_show(t
->tab_elems
.sep
);
7773 TAILQ_FOREACH(t
, &tabs
, entry
) {
7774 if (t
->tab_id
== maxid
) {
7775 gtk_widget_hide(t
->tab_elems
.sep
);
7781 /* after active tab change */
7783 recolor_compact_tabs(void)
7789 gdk_color_parse(XT_COLOR_CT_INACTIVE
, &color
);
7790 TAILQ_FOREACH(t
, &tabs
, entry
)
7791 gtk_widget_modify_fg(t
->tab_elems
.label
, GTK_STATE_NORMAL
,
7794 curid
= gtk_notebook_get_current_page(notebook
);
7795 TAILQ_FOREACH(t
, &tabs
, entry
)
7796 if (t
->tab_id
== curid
) {
7797 gdk_color_parse(XT_COLOR_CT_ACTIVE
, &color
);
7798 gtk_widget_modify_fg(t
->tab_elems
.label
,
7799 GTK_STATE_NORMAL
, &color
);
7805 set_current_tab(int page_num
)
7807 buffercmd_abort(get_current_tab());
7808 gtk_notebook_set_current_page(notebook
, page_num
);
7809 recolor_compact_tabs();
7813 undo_close_tab_save(struct tab
*t
)
7817 struct undo
*u1
, *u2
;
7819 WebKitWebHistoryItem
*item
;
7821 if ((uri
= get_uri(t
)) == NULL
)
7824 u1
= g_malloc0(sizeof(struct undo
));
7825 u1
->uri
= g_strdup(uri
);
7827 t
->bfl
= webkit_web_view_get_back_forward_list(t
->wv
);
7829 m
= webkit_web_back_forward_list_get_forward_length(t
->bfl
);
7830 n
= webkit_web_back_forward_list_get_back_length(t
->bfl
);
7833 /* forward history */
7834 items
= webkit_web_back_forward_list_get_forward_list_with_limit(t
->bfl
, m
);
7838 u1
->history
= g_list_prepend(u1
->history
,
7839 webkit_web_history_item_copy(item
));
7840 items
= g_list_next(items
);
7845 item
= webkit_web_back_forward_list_get_current_item(t
->bfl
);
7846 u1
->history
= g_list_prepend(u1
->history
,
7847 webkit_web_history_item_copy(item
));
7851 items
= webkit_web_back_forward_list_get_back_list_with_limit(t
->bfl
, n
);
7855 u1
->history
= g_list_prepend(u1
->history
,
7856 webkit_web_history_item_copy(item
));
7857 items
= g_list_next(items
);
7860 TAILQ_INSERT_HEAD(&undos
, u1
, entry
);
7862 if (undo_count
> XT_MAX_UNDO_CLOSE_TAB
) {
7863 u2
= TAILQ_LAST(&undos
, undo_tailq
);
7864 TAILQ_REMOVE(&undos
, u2
, entry
);
7866 g_list_free(u2
->history
);
7875 delete_tab(struct tab
*t
)
7879 DNPRINTF(XT_D_TAB
, "delete_tab: %p\n", t
);
7885 * no need to join thread here because it won't access t on completion
7888 TAILQ_REMOVE(&tabs
, t
, entry
);
7891 /* Halt all webkit activity. */
7892 abort_favicon_download(t
);
7893 webkit_web_view_stop_loading(t
->wv
);
7895 /* Save the tab, so we can undo the close. */
7896 undo_close_tab_save(t
);
7900 g_source_remove(t
->search_id
);
7903 bzero(&a
, sizeof a
);
7905 inspector_cmd(t
, &a
);
7907 if (browser_mode
== XT_BM_KIOSK
) {
7908 gtk_widget_destroy(t
->uri_entry
);
7909 gtk_widget_destroy(t
->stop
);
7910 gtk_widget_destroy(t
->js_toggle
);
7913 gtk_widget_destroy(t
->tab_elems
.eventbox
);
7914 gtk_widget_destroy(t
->vbox
);
7916 g_free(t
->user_agent
);
7917 g_free(t
->stylesheet
);
7922 if (TAILQ_EMPTY(&tabs
)) {
7923 if (browser_mode
== XT_BM_KIOSK
)
7924 create_new_tab(home
, NULL
, 1, -1);
7926 create_new_tab(NULL
, NULL
, 1, -1);
7929 /* recreate session */
7930 if (session_autosave
) {
7931 bzero(&a
, sizeof a
);
7933 save_tabs(NULL
, &a
);
7937 recolor_compact_tabs();
7941 update_statusbar_zoom(struct tab
*t
)
7944 char s
[16] = { '\0' };
7946 g_object_get(G_OBJECT(t
->wv
), "zoom-level", &zoom
, (char *)NULL
);
7947 if ((zoom
<= 0.99 || zoom
>= 1.01))
7948 snprintf(s
, sizeof s
, "%d%%", (int)(zoom
* 100));
7949 gtk_entry_set_text(GTK_ENTRY(t
->sbe
.zoom
), s
);
7953 setzoom_webkit(struct tab
*t
, int adjust
)
7955 #define XT_ZOOMPERCENT 0.04
7960 show_oops(NULL
, "setzoom_webkit invalid parameters");
7964 g_object_get(G_OBJECT(t
->wv
), "zoom-level", &zoom
, (char *)NULL
);
7965 if (adjust
== XT_ZOOM_IN
)
7966 zoom
+= XT_ZOOMPERCENT
;
7967 else if (adjust
== XT_ZOOM_OUT
)
7968 zoom
-= XT_ZOOMPERCENT
;
7969 else if (adjust
> 0)
7970 zoom
= default_zoom_level
+ adjust
/ 100.0 - 1.0;
7972 show_oops(t
, "setzoom_webkit invalid zoom value");
7976 if (zoom
< XT_ZOOMPERCENT
)
7977 zoom
= XT_ZOOMPERCENT
;
7978 g_object_set(G_OBJECT(t
->wv
), "zoom-level", zoom
, (char *)NULL
);
7979 update_statusbar_zoom(t
);
7983 tab_clicked_cb(GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
7985 struct tab
*t
= (struct tab
*) data
;
7987 DNPRINTF(XT_D_TAB
, "tab_clicked_cb: tab: %d\n", t
->tab_id
);
7989 switch (event
->button
) {
7991 set_current_tab(t
->tab_id
);
8002 append_tab(struct tab
*t
)
8007 TAILQ_INSERT_TAIL(&tabs
, t
, entry
);
8008 t
->tab_id
= gtk_notebook_append_page(notebook
, t
->vbox
, t
->tab_content
);
8012 create_sbe(int width
)
8016 sbe
= gtk_entry_new();
8017 gtk_entry_set_inner_border(GTK_ENTRY(sbe
), NULL
);
8018 gtk_entry_set_has_frame(GTK_ENTRY(sbe
), FALSE
);
8019 gtk_widget_set_can_focus(GTK_WIDGET(sbe
), FALSE
);
8020 gtk_widget_modify_font(GTK_WIDGET(sbe
), statusbar_font
);
8021 gtk_entry_set_alignment(GTK_ENTRY(sbe
), 1.0);
8022 gtk_widget_set_size_request(sbe
, width
, -1);
8028 create_new_tab(char *title
, struct undo
*u
, int focus
, int position
)
8033 WebKitWebHistoryItem
*item
;
8037 int sbe_p
= 0, sbe_b
= 0,
8040 DNPRINTF(XT_D_TAB
, "create_new_tab: title %s focus %d\n", title
, focus
);
8042 if (tabless
&& !TAILQ_EMPTY(&tabs
)) {
8043 DNPRINTF(XT_D_TAB
, "create_new_tab: new tab rejected\n");
8047 t
= g_malloc0(sizeof *t
);
8049 if (title
== NULL
) {
8050 title
= "(untitled)";
8054 t
->vbox
= gtk_vbox_new(FALSE
, 0);
8056 /* label + button for tab */
8057 b
= gtk_hbox_new(FALSE
, 0);
8060 #if GTK_CHECK_VERSION(2, 20, 0)
8061 t
->spinner
= gtk_spinner_new();
8063 t
->label
= gtk_label_new(title
);
8064 bb
= create_button("Close", GTK_STOCK_CLOSE
, 1);
8065 gtk_widget_set_size_request(t
->label
, 100, 0);
8066 gtk_label_set_max_width_chars(GTK_LABEL(t
->label
), 20);
8067 gtk_label_set_ellipsize(GTK_LABEL(t
->label
), PANGO_ELLIPSIZE_END
);
8068 gtk_widget_set_size_request(b
, 130, 0);
8070 gtk_box_pack_start(GTK_BOX(b
), bb
, FALSE
, FALSE
, 0);
8071 gtk_box_pack_start(GTK_BOX(b
), t
->label
, FALSE
, FALSE
, 0);
8072 #if GTK_CHECK_VERSION(2, 20, 0)
8073 gtk_box_pack_start(GTK_BOX(b
), t
->spinner
, FALSE
, FALSE
, 0);
8077 if (browser_mode
== XT_BM_KIOSK
) {
8078 t
->toolbar
= create_kiosk_toolbar(t
);
8079 gtk_box_pack_start(GTK_BOX(t
->vbox
), t
->toolbar
, FALSE
, FALSE
,
8082 t
->toolbar
= create_toolbar(t
);
8084 gtk_box_pack_start(GTK_BOX(t
->vbox
), t
->toolbar
, FALSE
,
8092 t
->browser_win
= create_browser(t
);
8093 gtk_box_pack_start(GTK_BOX(t
->vbox
), t
->browser_win
, TRUE
, TRUE
, 0);
8095 /* oops message for user feedback */
8096 t
->oops
= gtk_entry_new();
8097 gtk_entry_set_inner_border(GTK_ENTRY(t
->oops
), NULL
);
8098 gtk_entry_set_has_frame(GTK_ENTRY(t
->oops
), FALSE
);
8099 gtk_widget_set_can_focus(GTK_WIDGET(t
->oops
), FALSE
);
8100 gdk_color_parse(XT_COLOR_RED
, &color
);
8101 gtk_widget_modify_base(t
->oops
, GTK_STATE_NORMAL
, &color
);
8102 gtk_box_pack_end(GTK_BOX(t
->vbox
), t
->oops
, FALSE
, FALSE
, 0);
8103 gtk_widget_modify_font(GTK_WIDGET(t
->oops
), oops_font
);
8106 t
->cmd
= gtk_entry_new();
8107 gtk_entry_set_inner_border(GTK_ENTRY(t
->cmd
), NULL
);
8108 gtk_entry_set_has_frame(GTK_ENTRY(t
->cmd
), FALSE
);
8109 gtk_box_pack_end(GTK_BOX(t
->vbox
), t
->cmd
, FALSE
, FALSE
, 0);
8110 gtk_widget_modify_font(GTK_WIDGET(t
->cmd
), cmd_font
);
8113 t
->statusbar_box
= gtk_hbox_new(FALSE
, 0);
8115 t
->sbe
.statusbar
= gtk_entry_new();
8116 gtk_entry_set_inner_border(GTK_ENTRY(t
->sbe
.statusbar
), NULL
);
8117 gtk_entry_set_has_frame(GTK_ENTRY(t
->sbe
.statusbar
), FALSE
);
8118 gtk_widget_set_can_focus(GTK_WIDGET(t
->sbe
.statusbar
), FALSE
);
8119 gtk_widget_modify_font(GTK_WIDGET(t
->sbe
.statusbar
), statusbar_font
);
8121 /* create these widgets only if specified in statusbar_elems */
8123 t
->sbe
.position
= create_sbe(40);
8124 t
->sbe
.zoom
= create_sbe(40);
8125 t
->sbe
.buffercmd
= create_sbe(60);
8127 statusbar_modify_attr(t
, XT_COLOR_WHITE
, XT_COLOR_BLACK
);
8129 gtk_box_pack_start(GTK_BOX(t
->statusbar_box
), t
->sbe
.statusbar
, TRUE
,
8132 /* gtk widgets cannot be added to a box twice. sbe_* variables
8133 make sure of this */
8134 for (p
= statusbar_elems
; *p
!= '\0'; p
++) {
8138 GtkWidget
*sep
= gtk_vseparator_new();
8140 gdk_color_parse(XT_COLOR_SB_SEPARATOR
, &color
);
8141 gtk_widget_modify_bg(sep
, GTK_STATE_NORMAL
, &color
);
8142 gtk_box_pack_start(GTK_BOX(t
->statusbar_box
), sep
,
8143 FALSE
, FALSE
, FALSE
);
8148 warnx("flag \"%c\" specified more than "
8149 "once in statusbar_elems\n", *p
);
8153 gtk_box_pack_start(GTK_BOX(t
->statusbar_box
),
8154 t
->sbe
.position
, FALSE
, FALSE
, FALSE
);
8158 warnx("flag \"%c\" specified more than "
8159 "once in statusbar_elems\n", *p
);
8163 gtk_box_pack_start(GTK_BOX(t
->statusbar_box
),
8164 t
->sbe
.buffercmd
, FALSE
, FALSE
, FALSE
);
8168 warnx("flag \"%c\" specified more than "
8169 "once in statusbar_elems\n", *p
);
8173 gtk_box_pack_start(GTK_BOX(t
->statusbar_box
),
8174 t
->sbe
.zoom
, FALSE
, FALSE
, FALSE
);
8177 warnx("illegal flag \"%c\" in statusbar_elems\n", *p
);
8182 gtk_box_pack_end(GTK_BOX(t
->vbox
), t
->statusbar_box
, FALSE
, FALSE
, 0);
8185 t
->buffers
= create_buffers(t
);
8186 gtk_box_pack_end(GTK_BOX(t
->vbox
), t
->buffers
, FALSE
, FALSE
, 0);
8188 /* xtp meaning is normal by default */
8189 t
->xtp_meaning
= XT_XTP_TAB_MEANING_NORMAL
;
8191 /* set empty favicon */
8192 xt_icon_from_name(t
, "text-html");
8194 /* and show it all */
8195 gtk_widget_show_all(b
);
8196 gtk_widget_show_all(t
->vbox
);
8198 /* compact tab bar */
8199 t
->tab_elems
.label
= gtk_label_new(title
);
8200 gtk_label_set_width_chars(GTK_LABEL(t
->tab_elems
.label
), 1.0);
8201 gtk_misc_set_alignment(GTK_MISC(t
->tab_elems
.label
), 0.0, 0.0);
8202 gtk_misc_set_padding(GTK_MISC(t
->tab_elems
.label
), 4.0, 4.0);
8203 gtk_widget_modify_font(GTK_WIDGET(t
->tab_elems
.label
), tabbar_font
);
8205 t
->tab_elems
.eventbox
= gtk_event_box_new();
8206 t
->tab_elems
.box
= gtk_hbox_new(FALSE
, 0);
8207 t
->tab_elems
.sep
= gtk_vseparator_new();
8209 gdk_color_parse(XT_COLOR_CT_BACKGROUND
, &color
);
8210 gtk_widget_modify_bg(t
->tab_elems
.eventbox
, GTK_STATE_NORMAL
, &color
);
8211 gdk_color_parse(XT_COLOR_CT_INACTIVE
, &color
);
8212 gtk_widget_modify_fg(t
->tab_elems
.label
, GTK_STATE_NORMAL
, &color
);
8213 gdk_color_parse(XT_COLOR_CT_SEPARATOR
, &color
);
8214 gtk_widget_modify_bg(t
->tab_elems
.sep
, GTK_STATE_NORMAL
, &color
);
8216 gtk_box_pack_start(GTK_BOX(t
->tab_elems
.box
), t
->tab_elems
.label
, TRUE
,
8218 gtk_box_pack_start(GTK_BOX(t
->tab_elems
.box
), t
->tab_elems
.sep
, FALSE
,
8220 gtk_container_add(GTK_CONTAINER(t
->tab_elems
.eventbox
),
8223 gtk_box_pack_start(GTK_BOX(tab_bar
), t
->tab_elems
.eventbox
, TRUE
,
8225 gtk_widget_show_all(t
->tab_elems
.eventbox
);
8227 if (append_next
== 0 || gtk_notebook_get_n_pages(notebook
) == 0)
8230 id
= position
>= 0 ? position
:
8231 gtk_notebook_get_current_page(notebook
) + 1;
8232 if (id
> gtk_notebook_get_n_pages(notebook
))
8235 TAILQ_INSERT_TAIL(&tabs
, t
, entry
);
8236 gtk_notebook_insert_page(notebook
, t
->vbox
, b
, id
);
8237 gtk_box_reorder_child(GTK_BOX(tab_bar
),
8238 t
->tab_elems
.eventbox
, id
);
8243 #if GTK_CHECK_VERSION(2, 20, 0)
8244 /* turn spinner off if we are a new tab without uri */
8246 gtk_spinner_stop(GTK_SPINNER(t
->spinner
));
8247 gtk_widget_hide(t
->spinner
);
8250 /* make notebook tabs reorderable */
8251 gtk_notebook_set_tab_reorderable(notebook
, t
->vbox
, TRUE
);
8253 /* compact tabs clickable */
8254 g_signal_connect(G_OBJECT(t
->tab_elems
.eventbox
),
8255 "button_press_event", G_CALLBACK(tab_clicked_cb
), t
);
8257 g_object_connect(G_OBJECT(t
->cmd
),
8258 "signal::key-press-event", G_CALLBACK(cmd_keypress_cb
), t
,
8259 "signal::key-release-event", G_CALLBACK(cmd_keyrelease_cb
), t
,
8260 "signal::focus-out-event", G_CALLBACK(cmd_focusout_cb
), t
,
8261 "signal::activate", G_CALLBACK(cmd_activate_cb
), t
,
8262 "signal::populate-popup", G_CALLBACK(cmd_popup_cb
), t
,
8265 /* reuse wv_button_cb to hide oops */
8266 g_object_connect(G_OBJECT(t
->oops
),
8267 "signal::button_press_event", G_CALLBACK(wv_button_cb
), t
,
8270 g_signal_connect(t
->buffers
,
8271 "row-activated", G_CALLBACK(row_activated_cb
), t
);
8272 g_object_connect(G_OBJECT(t
->buffers
),
8273 "signal::key-press-event", G_CALLBACK(wv_keypress_cb
), t
, (char *)NULL
);
8275 g_object_connect(G_OBJECT(t
->wv
),
8276 "signal::key-press-event", G_CALLBACK(wv_keypress_cb
), t
,
8277 "signal-after::key-press-event", G_CALLBACK(wv_keypress_after_cb
), t
,
8278 "signal::hovering-over-link", G_CALLBACK(webview_hover_cb
), t
,
8279 "signal::download-requested", G_CALLBACK(webview_download_cb
), t
,
8280 "signal::mime-type-policy-decision-requested", G_CALLBACK(webview_mimetype_cb
), t
,
8281 "signal::navigation-policy-decision-requested", G_CALLBACK(webview_npd_cb
), t
,
8282 "signal::new-window-policy-decision-requested", G_CALLBACK(webview_npd_cb
), t
,
8283 "signal::create-web-view", G_CALLBACK(webview_cwv_cb
), t
,
8284 "signal::close-web-view", G_CALLBACK(webview_closewv_cb
), t
,
8285 "signal::event", G_CALLBACK(webview_event_cb
), t
,
8286 "signal::load-finished", G_CALLBACK(webview_load_finished_cb
), t
,
8287 "signal::load-progress-changed", G_CALLBACK(webview_progress_changed_cb
), t
,
8288 "signal::icon-loaded", G_CALLBACK(notify_icon_loaded_cb
), t
,
8289 "signal::button_press_event", G_CALLBACK(wv_button_cb
), t
,
8290 "signal::button_release_event", G_CALLBACK(wv_release_button_cb
), t
,
8291 "signal::populate-popup", G_CALLBACK(wv_popup_cb
), t
,
8293 g_signal_connect(t
->wv
,
8294 "notify::load-status", G_CALLBACK(notify_load_status_cb
), t
);
8295 g_signal_connect(t
->wv
,
8296 "notify::title", G_CALLBACK(notify_title_cb
), t
);
8298 /* hijack the unused keys as if we were the browser */
8299 g_object_connect(G_OBJECT(t
->toolbar
),
8300 "signal-after::key-press-event", G_CALLBACK(wv_keypress_after_cb
), t
,
8303 g_signal_connect(G_OBJECT(bb
), "button_press_event",
8304 G_CALLBACK(tab_close_cb
), t
);
8307 t
->bfl
= webkit_web_view_get_back_forward_list(t
->wv
);
8308 /* restore the tab's history */
8309 if (u
&& u
->history
) {
8313 webkit_web_back_forward_list_add_item(t
->bfl
, item
);
8314 items
= g_list_next(items
);
8317 item
= g_list_nth_data(u
->history
, u
->back
);
8319 webkit_web_view_go_to_back_forward_item(t
->wv
, item
);
8322 g_list_free(u
->history
);
8324 webkit_web_back_forward_list_clear(t
->bfl
);
8330 url_set_visibility();
8331 statusbar_set_visibility();
8334 set_current_tab(t
->tab_id
);
8335 DNPRINTF(XT_D_TAB
, "create_new_tab: going to tab: %d\n",
8339 gtk_entry_set_text(GTK_ENTRY(t
->uri_entry
), title
);
8343 gtk_widget_grab_focus(GTK_WIDGET(t
->uri_entry
));
8350 recolor_compact_tabs();
8351 setzoom_webkit(t
, XT_ZOOM_NORMAL
);
8356 notebook_switchpage_cb(GtkNotebook
*nb
, GtkWidget
*nbp
, guint pn
,
8362 DNPRINTF(XT_D_TAB
, "notebook_switchpage_cb: tab: %d\n", pn
);
8364 if (gtk_notebook_get_current_page(notebook
) == -1)
8367 TAILQ_FOREACH(t
, &tabs
, entry
) {
8368 if (t
->tab_id
== pn
) {
8369 DNPRINTF(XT_D_TAB
, "notebook_switchpage_cb: going to "
8372 uri
= get_title(t
, TRUE
);
8373 gtk_window_set_title(GTK_WINDOW(main_window
), uri
);
8379 /* can't use focus_webview here */
8380 gtk_widget_grab_focus(GTK_WIDGET(t
->wv
));
8387 notebook_pagereordered_cb(GtkNotebook
*nb
, GtkWidget
*nbp
, guint pn
,
8390 struct tab
*t
= NULL
, *tt
;
8394 TAILQ_FOREACH(tt
, &tabs
, entry
)
8395 if (tt
->tab_id
== pn
) {
8401 DNPRINTF(XT_D_TAB
, "page_reordered_cb: tab: %d\n", t
->tab_id
);
8403 gtk_box_reorder_child(GTK_BOX(tab_bar
), t
->tab_elems
.eventbox
,
8408 menuitem_response(struct tab
*t
)
8410 gtk_notebook_set_current_page(notebook
, t
->tab_id
);
8414 arrow_cb(GtkWidget
*w
, GdkEventButton
*event
, gpointer user_data
)
8416 GtkWidget
*menu
, *menu_items
;
8417 GdkEventButton
*bevent
;
8421 if (event
->type
== GDK_BUTTON_PRESS
) {
8422 bevent
= (GdkEventButton
*) event
;
8423 menu
= gtk_menu_new();
8425 TAILQ_FOREACH(ti
, &tabs
, entry
) {
8426 if ((uri
= get_uri(ti
)) == NULL
)
8427 /* XXX make sure there is something to print */
8428 /* XXX add gui pages in here to look purdy */
8430 menu_items
= gtk_menu_item_new_with_label(uri
);
8431 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menu_items
);
8432 gtk_widget_show(menu_items
);
8434 g_signal_connect_swapped((menu_items
),
8435 "activate", G_CALLBACK(menuitem_response
),
8439 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
, NULL
, NULL
,
8440 bevent
->button
, bevent
->time
);
8442 /* unref object so it'll free itself when popped down */
8443 #if !GTK_CHECK_VERSION(3, 0, 0)
8444 /* XXX does not need unref with gtk+3? */
8445 g_object_ref_sink(menu
);
8446 g_object_unref(menu
);
8449 return (TRUE
/* eat event */);
8452 return (FALSE
/* propagate */);
8456 icon_size_map(int icon_size
)
8458 if (icon_size
<= GTK_ICON_SIZE_INVALID
||
8459 icon_size
> GTK_ICON_SIZE_DIALOG
)
8460 return (GTK_ICON_SIZE_SMALL_TOOLBAR
);
8466 create_button(char *name
, char *stockid
, int size
)
8468 GtkWidget
*button
, *image
;
8472 rcstring
= g_strdup_printf(
8473 "style \"%s-style\"\n"
8475 " GtkWidget::focus-padding = 0\n"
8476 " GtkWidget::focus-line-width = 0\n"
8480 "widget \"*.%s\" style \"%s-style\"", name
, name
, name
);
8481 gtk_rc_parse_string(rcstring
);
8483 button
= gtk_button_new();
8484 gtk_button_set_focus_on_click(GTK_BUTTON(button
), FALSE
);
8485 gtk_icon_size
= icon_size_map(size
? size
: icon_size
);
8487 image
= gtk_image_new_from_stock(stockid
, gtk_icon_size
);
8488 gtk_widget_set_size_request(GTK_WIDGET(image
), -1, -1);
8489 gtk_container_set_border_width(GTK_CONTAINER(button
), 1);
8490 gtk_container_add(GTK_CONTAINER(button
), GTK_WIDGET(image
));
8491 gtk_widget_set_name(button
, name
);
8492 gtk_button_set_relief(GTK_BUTTON(button
), GTK_RELIEF_NONE
);
8498 button_set_stockid(GtkWidget
*button
, char *stockid
)
8502 image
= gtk_image_new_from_stock(stockid
, icon_size_map(icon_size
));
8503 gtk_widget_set_size_request(GTK_WIDGET(image
), -1, -1);
8504 gtk_button_set_image(GTK_BUTTON(button
), image
);
8508 clipb_primary_cb(GtkClipboard
*primary
, GdkEvent
*event
, gpointer notused
)
8511 GdkAtom atom
= gdk_atom_intern("CUT_BUFFER0", FALSE
);
8514 if (xterm_workaround
== 0)
8518 * xterm doesn't play nice with clipboards because it clears the
8519 * primary when clicked. We rely on primary being set to properly
8520 * handle middle mouse button clicks (paste). So when someone clears
8521 * primary copy whatever is in CUT_BUFFER0 into primary to simualte
8522 * other application behavior (as in DON'T clear primary).
8525 p
= gtk_clipboard_wait_for_text(primary
);
8527 if (gdk_property_get(gdk_get_default_root_window(),
8529 gdk_atom_intern("STRING", FALSE
),
8531 1024 * 1024 /* picked out of my butt */,
8537 /* yes sir, we need to NUL the string */
8539 gtk_clipboard_set_text(primary
, p
, -1);
8553 char file
[PATH_MAX
];
8556 vbox
= gtk_vbox_new(FALSE
, 0);
8557 gtk_box_set_spacing(GTK_BOX(vbox
), 0);
8558 notebook
= GTK_NOTEBOOK(gtk_notebook_new());
8559 #if !GTK_CHECK_VERSION(3, 0, 0)
8560 /* XXX seems to be needed with gtk+2 */
8561 gtk_notebook_set_tab_hborder(notebook
, 0);
8562 gtk_notebook_set_tab_vborder(notebook
, 0);
8564 gtk_notebook_set_scrollable(notebook
, TRUE
);
8565 gtk_notebook_set_show_border(notebook
, FALSE
);
8566 gtk_widget_set_can_focus(GTK_WIDGET(notebook
), FALSE
);
8568 abtn
= gtk_button_new();
8569 arrow
= gtk_arrow_new(GTK_ARROW_DOWN
, GTK_SHADOW_NONE
);
8570 gtk_widget_set_size_request(arrow
, -1, -1);
8571 gtk_container_add(GTK_CONTAINER(abtn
), arrow
);
8572 gtk_widget_set_size_request(abtn
, -1, 20);
8574 #if GTK_CHECK_VERSION(2, 20, 0)
8575 gtk_notebook_set_action_widget(notebook
, abtn
, GTK_PACK_END
);
8577 gtk_widget_set_size_request(GTK_WIDGET(notebook
), -1, -1);
8579 /* compact tab bar */
8580 tab_bar
= gtk_hbox_new(TRUE
, 0);
8582 gtk_box_pack_start(GTK_BOX(vbox
), tab_bar
, FALSE
, FALSE
, 0);
8583 gtk_box_pack_start(GTK_BOX(vbox
), GTK_WIDGET(notebook
), TRUE
, TRUE
, 0);
8584 gtk_widget_set_size_request(vbox
, -1, -1);
8586 g_object_connect(G_OBJECT(notebook
),
8587 "signal::switch-page", G_CALLBACK(notebook_switchpage_cb
), NULL
,
8589 g_object_connect(G_OBJECT(notebook
),
8590 "signal::page-reordered", G_CALLBACK(notebook_pagereordered_cb
),
8591 NULL
, (char *)NULL
);
8592 g_signal_connect(G_OBJECT(abtn
), "button_press_event",
8593 G_CALLBACK(arrow_cb
), NULL
);
8595 main_window
= create_window("xxxterm");
8596 gtk_container_add(GTK_CONTAINER(main_window
), vbox
);
8597 g_signal_connect(G_OBJECT(main_window
), "delete_event",
8598 G_CALLBACK(gtk_main_quit
), NULL
);
8601 for (i
= 0; i
< LENGTH(icons
); i
++) {
8602 snprintf(file
, sizeof file
, "%s/%s", resource_dir
, icons
[i
]);
8603 pb
= gdk_pixbuf_new_from_file(file
, NULL
);
8604 l
= g_list_append(l
, pb
);
8606 gtk_window_set_default_icon_list(l
);
8608 /* clipboard work around */
8609 if (xterm_workaround
)
8611 G_OBJECT(gtk_clipboard_get(GDK_SELECTION_PRIMARY
)),
8612 "owner-change", G_CALLBACK(clipb_primary_cb
), NULL
);
8614 gtk_widget_show_all(abtn
);
8615 gtk_widget_show_all(main_window
);
8616 notebook_tab_set_visibility();
8620 set_hook(void **hook
, char *name
)
8623 errx(1, "set_hook");
8625 if (*hook
== NULL
) {
8626 *hook
= dlsym(RTLD_NEXT
, name
);
8628 errx(1, "can't hook %s", name
);
8632 /* override libsoup soup_cookie_equal because it doesn't look at domain */
8634 soup_cookie_equal(SoupCookie
*cookie1
, SoupCookie
*cookie2
)
8636 g_return_val_if_fail(cookie1
, FALSE
);
8637 g_return_val_if_fail(cookie2
, FALSE
);
8639 return (!strcmp (cookie1
->name
, cookie2
->name
) &&
8640 !strcmp (cookie1
->value
, cookie2
->value
) &&
8641 !strcmp (cookie1
->path
, cookie2
->path
) &&
8642 !strcmp (cookie1
->domain
, cookie2
->domain
));
8646 transfer_cookies(void)
8649 SoupCookie
*sc
, *pc
;
8651 cf
= soup_cookie_jar_all_cookies(p_cookiejar
);
8653 for (;cf
; cf
= cf
->next
) {
8655 sc
= soup_cookie_copy(pc
);
8656 _soup_cookie_jar_add_cookie(s_cookiejar
, sc
);
8659 soup_cookies_free(cf
);
8663 soup_cookie_jar_delete_cookie(SoupCookieJar
*jar
, SoupCookie
*c
)
8668 print_cookie("soup_cookie_jar_delete_cookie", c
);
8670 if (cookies_enabled
== 0)
8673 if (jar
== NULL
|| c
== NULL
)
8676 /* find and remove from persistent jar */
8677 cf
= soup_cookie_jar_all_cookies(p_cookiejar
);
8679 for (;cf
; cf
= cf
->next
) {
8681 if (soup_cookie_equal(ci
, c
)) {
8682 _soup_cookie_jar_delete_cookie(p_cookiejar
, ci
);
8687 soup_cookies_free(cf
);
8689 /* delete from session jar */
8690 _soup_cookie_jar_delete_cookie(s_cookiejar
, c
);
8694 soup_cookie_jar_add_cookie(SoupCookieJar
*jar
, SoupCookie
*cookie
)
8696 struct domain
*d
= NULL
;
8700 DNPRINTF(XT_D_COOKIE
, "soup_cookie_jar_add_cookie: %p %p %p\n",
8701 jar
, p_cookiejar
, s_cookiejar
);
8703 if (cookies_enabled
== 0)
8706 /* see if we are up and running */
8707 if (p_cookiejar
== NULL
) {
8708 _soup_cookie_jar_add_cookie(jar
, cookie
);
8711 /* disallow p_cookiejar adds, shouldn't happen */
8712 if (jar
== p_cookiejar
)
8716 if (jar
== NULL
|| cookie
== NULL
)
8719 if (enable_cookie_whitelist
&&
8720 (d
= wl_find(cookie
->domain
, &c_wl
)) == NULL
) {
8722 DNPRINTF(XT_D_COOKIE
,
8723 "soup_cookie_jar_add_cookie: reject %s\n",
8725 if (save_rejected_cookies
) {
8726 if ((r_cookie_f
= fopen(rc_fname
, "a+")) == NULL
) {
8727 show_oops(NULL
, "can't open reject cookie file");
8730 fseek(r_cookie_f
, 0, SEEK_END
);
8731 fprintf(r_cookie_f
, "%s%s\t%s\t%s\t%s\t%lu\t%s\t%s\n",
8732 cookie
->http_only
? "#HttpOnly_" : "",
8734 *cookie
->domain
== '.' ? "TRUE" : "FALSE",
8736 cookie
->secure
? "TRUE" : "FALSE",
8738 (gulong
)soup_date_to_time_t(cookie
->expires
) :
8745 if (!allow_volatile_cookies
)
8749 if (cookie
->expires
== NULL
&& session_timeout
) {
8750 soup_cookie_set_expires(cookie
,
8751 soup_date_new_from_now(session_timeout
));
8752 print_cookie("modified add cookie", cookie
);
8755 /* see if we are white listed for persistence */
8756 if ((d
&& d
->handy
) || (enable_cookie_whitelist
== 0)) {
8757 /* add to persistent jar */
8758 c
= soup_cookie_copy(cookie
);
8759 print_cookie("soup_cookie_jar_add_cookie p_cookiejar", c
);
8760 _soup_cookie_jar_add_cookie(p_cookiejar
, c
);
8763 /* add to session jar */
8764 print_cookie("soup_cookie_jar_add_cookie s_cookiejar", cookie
);
8765 _soup_cookie_jar_add_cookie(s_cookiejar
, cookie
);
8771 char file
[PATH_MAX
];
8773 set_hook((void *)&_soup_cookie_jar_add_cookie
,
8774 "soup_cookie_jar_add_cookie");
8775 set_hook((void *)&_soup_cookie_jar_delete_cookie
,
8776 "soup_cookie_jar_delete_cookie");
8778 if (cookies_enabled
== 0)
8782 * the following code is intricate due to overriding several libsoup
8784 * do not alter order of these operations.
8787 /* rejected cookies */
8788 if (save_rejected_cookies
)
8789 snprintf(rc_fname
, sizeof file
, "%s/%s", work_dir
,
8792 /* persistent cookies */
8793 snprintf(file
, sizeof file
, "%s/%s", work_dir
, XT_COOKIE_FILE
);
8794 p_cookiejar
= soup_cookie_jar_text_new(file
, read_only_cookies
);
8796 /* session cookies */
8797 s_cookiejar
= soup_cookie_jar_new();
8798 g_object_set(G_OBJECT(s_cookiejar
), SOUP_COOKIE_JAR_ACCEPT_POLICY
,
8799 cookie_policy
, (void *)NULL
);
8802 soup_session_add_feature(session
, (SoupSessionFeature
*)s_cookiejar
);
8806 setup_proxy(char *uri
)
8809 g_object_set(session
, "proxy_uri", NULL
, (char *)NULL
);
8810 soup_uri_free(proxy_uri
);
8814 if (http_proxy
!= uri
) {
8821 http_proxy
= g_strdup(uri
);
8822 DNPRINTF(XT_D_CONFIG
, "setup_proxy: %s\n", uri
);
8823 proxy_uri
= soup_uri_new(http_proxy
);
8824 if (!(proxy_uri
== NULL
|| !SOUP_URI_VALID_FOR_HTTP(proxy_uri
)))
8825 g_object_set(session
, "proxy-uri", proxy_uri
,
8831 set_http_proxy(char *proxy
)
8838 /* see if we need to clear it instead */
8839 if (strlen(proxy
) == 0) {
8844 uri
= soup_uri_new(proxy
);
8845 if (uri
== NULL
|| !SOUP_URI_VALID_FOR_HTTP(uri
))
8856 send_cmd_to_socket(char *cmd
)
8859 struct sockaddr_un sa
;
8861 if ((s
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
8862 warnx("%s: socket", __func__
);
8866 sa
.sun_family
= AF_UNIX
;
8867 snprintf(sa
.sun_path
, sizeof(sa
.sun_path
), "%s/%s",
8868 work_dir
, XT_SOCKET_FILE
);
8871 if (connect(s
, (struct sockaddr
*)&sa
, len
) == -1) {
8872 warnx("%s: connect", __func__
);
8876 if (send(s
, cmd
, strlen(cmd
) + 1, 0) == -1) {
8877 warnx("%s: send", __func__
);
8888 socket_watcher(GIOChannel
*source
, GIOCondition condition
, gpointer data
)
8891 char str
[XT_MAX_URL_LENGTH
];
8892 socklen_t t
= sizeof(struct sockaddr_un
);
8893 struct sockaddr_un sa
;
8898 gint fd
= g_io_channel_unix_get_fd(source
);
8900 if ((s
= accept(fd
, (struct sockaddr
*)&sa
, &t
)) == -1) {
8905 if (getpeereid(s
, &uid
, &gid
) == -1) {
8909 if (uid
!= getuid() || gid
!= getgid()) {
8910 warnx("unauthorized user");
8916 warnx("not a valid user");
8920 n
= recv(s
, str
, sizeof(str
), 0);
8924 tt
= TAILQ_LAST(&tabs
, tab_list
);
8925 cmd_execute(tt
, str
);
8933 struct sockaddr_un sa
;
8935 if ((s
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
8936 warn("is_running: socket");
8940 sa
.sun_family
= AF_UNIX
;
8941 snprintf(sa
.sun_path
, sizeof(sa
.sun_path
), "%s/%s",
8942 work_dir
, XT_SOCKET_FILE
);
8945 /* connect to see if there is a listener */
8946 if (connect(s
, (struct sockaddr
*)&sa
, len
) == -1)
8947 rv
= 0; /* not running */
8949 rv
= 1; /* already running */
8960 struct sockaddr_un sa
;
8962 if ((s
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
8963 warn("build_socket: socket");
8967 sa
.sun_family
= AF_UNIX
;
8968 snprintf(sa
.sun_path
, sizeof(sa
.sun_path
), "%s/%s",
8969 work_dir
, XT_SOCKET_FILE
);
8972 /* connect to see if there is a listener */
8973 if (connect(s
, (struct sockaddr
*)&sa
, len
) == -1) {
8974 /* no listener so we will */
8975 unlink(sa
.sun_path
);
8977 if (bind(s
, (struct sockaddr
*)&sa
, len
) == -1) {
8978 warn("build_socket: bind");
8982 if (listen(s
, 1) == -1) {
8983 warn("build_socket: listen");
8996 completion_select_cb(GtkEntryCompletion
*widget
, GtkTreeModel
*model
,
8997 GtkTreeIter
*iter
, struct tab
*t
)
9001 gtk_tree_model_get(model
, iter
, 0, &value
, -1);
9009 completion_hover_cb(GtkEntryCompletion
*widget
, GtkTreeModel
*model
,
9010 GtkTreeIter
*iter
, struct tab
*t
)
9014 gtk_tree_model_get(model
, iter
, 0, &value
, -1);
9015 gtk_entry_set_text(GTK_ENTRY(t
->uri_entry
), value
);
9016 gtk_editable_set_position(GTK_EDITABLE(t
->uri_entry
), -1);
9023 completion_add_uri(const gchar
*uri
)
9027 /* add uri to list_store */
9028 gtk_list_store_append(completion_model
, &iter
);
9029 gtk_list_store_set(completion_model
, &iter
, 0, uri
, -1);
9033 completion_match(GtkEntryCompletion
*completion
, const gchar
*key
,
9034 GtkTreeIter
*iter
, gpointer user_data
)
9037 gboolean match
= FALSE
;
9039 gtk_tree_model_get(GTK_TREE_MODEL(completion_model
), iter
, 0, &value
,
9045 match
= match_uri(value
, key
);
9052 completion_add(struct tab
*t
)
9054 /* enable completion for tab */
9055 t
->completion
= gtk_entry_completion_new();
9056 gtk_entry_completion_set_text_column(t
->completion
, 0);
9057 gtk_entry_set_completion(GTK_ENTRY(t
->uri_entry
), t
->completion
);
9058 gtk_entry_completion_set_model(t
->completion
,
9059 GTK_TREE_MODEL(completion_model
));
9060 gtk_entry_completion_set_match_func(t
->completion
, completion_match
,
9062 gtk_entry_completion_set_minimum_key_length(t
->completion
, 1);
9063 gtk_entry_completion_set_inline_selection(t
->completion
, TRUE
);
9064 g_signal_connect(G_OBJECT (t
->completion
), "match-selected",
9065 G_CALLBACK(completion_select_cb
), t
);
9066 g_signal_connect(G_OBJECT (t
->completion
), "cursor-on-match",
9067 G_CALLBACK(completion_hover_cb
), t
);
9075 if (stat(dir
, &sb
)) {
9076 if (mkdir(dir
, S_IRWXU
) == -1)
9077 err(1, "mkdir %s", dir
);
9079 err(1, "stat %s", dir
);
9081 if (S_ISDIR(sb
.st_mode
) == 0)
9082 errx(1, "%s not a dir", dir
);
9083 if (((sb
.st_mode
& (S_IRWXU
| S_IRWXG
| S_IRWXO
))) != S_IRWXU
) {
9084 warnx("fixing invalid permissions on %s", dir
);
9085 if (chmod(dir
, S_IRWXU
) == -1)
9086 err(1, "chmod %s", dir
);
9094 "%s [-nSTVt][-f file][-s session] url ...\n", __progname
);
9098 GStaticRecMutex my_gdk_mtx
= G_STATIC_REC_MUTEX_INIT
;
9099 volatile int mtx_depth
;
9103 * The linux flash plugin violates the gdk locking mechanism.
9104 * Work around the issue by using a recursive mutex with some match applied
9105 * to see if we hit a buggy condition.
9107 * The following code is painful so just don't read it. It really doesn't
9108 * make much sense but seems to work.
9113 g_static_rec_mutex_lock(&my_gdk_mtx
);
9116 if (mtx_depth
<= 0) {
9117 /* should not happen */
9118 show_oops(NULL
, "negative mutex locking bug, trying to "
9120 fprintf(stderr
, "negative mutex locking bug, trying to "
9122 g_static_rec_mutex_unlock_full(&my_gdk_mtx
);
9123 g_static_rec_mutex_lock(&my_gdk_mtx
);
9128 if (mtx_depth
!= 1) {
9129 /* decrease mutext depth to 1 */
9131 g_static_rec_mutex_unlock(&my_gdk_mtx
);
9133 } while (mtx_depth
> 1);
9142 /* if mutex depth isn't 1 then something went bad */
9143 if (mtx_depth
!= 1) {
9144 x
= g_static_rec_mutex_unlock_full(&my_gdk_mtx
);
9146 /* should not happen */
9147 show_oops(NULL
, "mutex unlocking bug, trying to "
9149 fprintf(stderr
, "mutex unlocking bug, trying to "
9153 if (mtx_complain
== 0) {
9154 show_oops(NULL
, "buggy mutex implementation detected, "
9155 "work around implemented");
9156 fprintf(stderr
, "buggy mutex implementation detected, "
9157 "work around implemented");
9164 g_static_rec_mutex_unlock(&my_gdk_mtx
);
9168 main(int argc
, char *argv
[])
9171 int c
, s
, optn
= 0, opte
= 0, focus
= 1;
9172 char conf
[PATH_MAX
] = { '\0' };
9173 char file
[PATH_MAX
];
9174 char *env_proxy
= NULL
;
9178 struct sigaction sact
;
9179 GIOChannel
*channel
;
9186 g_thread_init(NULL
);
9187 gdk_threads_set_lock_functions(mtx_lock
, mtx_unlock
);
9189 gdk_threads_enter();
9191 gcry_control (GCRYCTL_SET_THREAD_CBS
, &gcry_threads_pthread
);
9193 gtk_init(&argc
, &argv
);
9195 gnutls_global_init();
9197 strlcpy(named_session
, XT_SAVED_TABS_FILE
, sizeof named_session
);
9202 RB_INIT(&downloads
);
9204 TAILQ_INIT(&sessions
);
9207 TAILQ_INIT(&aliases
);
9214 /* fiddle with ulimits */
9215 if (getrlimit(RLIMIT_NOFILE
, &rlp
) == -1)
9218 /* just use them all */
9219 rlp
.rlim_cur
= rlp
.rlim_max
;
9220 if (setrlimit(RLIMIT_NOFILE
, &rlp
) == -1)
9222 if (getrlimit(RLIMIT_NOFILE
, &rlp
) == -1)
9224 else if (rlp
.rlim_cur
<= 256)
9225 startpage_add("%s requires at least 256 file "
9226 "descriptors, currently it has up to %d available",
9227 __progname
, rlp
.rlim_cur
);
9230 while ((c
= getopt(argc
, argv
, "STVf:s:tne")) != -1) {
9239 errx(0 , "Version: %s", version
);
9242 strlcpy(conf
, optarg
, sizeof(conf
));
9245 strlcpy(named_session
, optarg
, sizeof(named_session
));
9266 xtp_generate_keys();
9269 bzero(&sact
, sizeof(sact
));
9270 sigemptyset(&sact
.sa_mask
);
9271 sact
.sa_handler
= sigchild
;
9272 sact
.sa_flags
= SA_NOCLDSTOP
;
9273 sigaction(SIGCHLD
, &sact
, NULL
);
9275 /* set download dir */
9276 pwd
= getpwuid(getuid());
9278 errx(1, "invalid user %d", getuid());
9279 strlcpy(download_dir
, pwd
->pw_dir
, sizeof download_dir
);
9281 /* compile buffer command regexes */
9284 /* set default string settings */
9285 home
= g_strdup("https://www.cyphertite.com");
9286 search_string
= g_strdup("https://ssl.scroogle.org/cgi-bin/nbbwssl.cgi?Gw=%s");
9287 resource_dir
= g_strdup("/usr/local/share/xxxterm/");
9288 strlcpy(runtime_settings
, "runtime", sizeof runtime_settings
);
9289 cmd_font_name
= g_strdup("monospace normal 9");
9290 oops_font_name
= g_strdup("monospace normal 9");
9291 statusbar_font_name
= g_strdup("monospace normal 9");
9292 tabbar_font_name
= g_strdup("monospace normal 9");
9293 statusbar_elems
= g_strdup("BP");
9294 encoding
= g_strdup("ISO-8859-1");
9296 /* read config file */
9297 if (strlen(conf
) == 0)
9298 snprintf(conf
, sizeof conf
, "%s/.%s",
9299 pwd
->pw_dir
, XT_CONF_FILE
);
9300 config_parse(conf
, 0);
9303 cmd_font
= pango_font_description_from_string(cmd_font_name
);
9304 oops_font
= pango_font_description_from_string(oops_font_name
);
9305 statusbar_font
= pango_font_description_from_string(statusbar_font_name
);
9306 tabbar_font
= pango_font_description_from_string(tabbar_font_name
);
9308 /* working directory */
9309 if (strlen(work_dir
) == 0)
9310 snprintf(work_dir
, sizeof work_dir
, "%s/%s",
9311 pwd
->pw_dir
, XT_DIR
);
9314 /* icon cache dir */
9315 snprintf(cache_dir
, sizeof cache_dir
, "%s/%s", work_dir
, XT_CACHE_DIR
);
9319 snprintf(certs_dir
, sizeof certs_dir
, "%s/%s", work_dir
, XT_CERT_DIR
);
9323 snprintf(sessions_dir
, sizeof sessions_dir
, "%s/%s",
9324 work_dir
, XT_SESSIONS_DIR
);
9325 xxx_dir(sessions_dir
);
9327 /* runtime settings that can override config file */
9328 if (runtime_settings
[0] != '\0')
9329 config_parse(runtime_settings
, 1);
9332 if (!strcmp(download_dir
, pwd
->pw_dir
))
9333 strlcat(download_dir
, "/downloads", sizeof download_dir
);
9334 xxx_dir(download_dir
);
9336 /* favorites file */
9337 snprintf(file
, sizeof file
, "%s/%s", work_dir
, XT_FAVS_FILE
);
9338 if (stat(file
, &sb
)) {
9339 warnx("favorites file doesn't exist, creating it");
9340 if ((f
= fopen(file
, "w")) == NULL
)
9341 err(1, "favorites");
9345 /* quickmarks file */
9346 snprintf(file
, sizeof file
, "%s/%s", work_dir
, XT_QMARKS_FILE
);
9347 if (stat(file
, &sb
)) {
9348 warnx("quickmarks file doesn't exist, creating it");
9349 if ((f
= fopen(file
, "w")) == NULL
)
9350 err(1, "quickmarks");
9354 /* search history */
9355 if (history_autosave
) {
9356 snprintf(search_file
, sizeof search_file
, "%s/%s",
9357 work_dir
, XT_SEARCH_FILE
);
9358 if (stat(search_file
, &sb
)) {
9359 warnx("search history file doesn't exist, creating it");
9360 if ((f
= fopen(search_file
, "w")) == NULL
)
9361 err(1, "search_history");
9364 history_read(&shl
, search_file
, &search_history_count
);
9367 /* command history */
9368 if (history_autosave
) {
9369 snprintf(command_file
, sizeof command_file
, "%s/%s",
9370 work_dir
, XT_COMMAND_FILE
);
9371 if (stat(command_file
, &sb
)) {
9372 warnx("command history file doesn't exist, creating it");
9373 if ((f
= fopen(command_file
, "w")) == NULL
)
9374 err(1, "command_history");
9377 history_read(&chl
, command_file
, &cmd_history_count
);
9381 session
= webkit_get_default_session();
9386 if (stat(ssl_ca_file
, &sb
)) {
9387 warnx("no CA file: %s", ssl_ca_file
);
9388 g_free(ssl_ca_file
);
9391 g_object_set(session
,
9392 SOUP_SESSION_SSL_CA_FILE
, ssl_ca_file
,
9393 SOUP_SESSION_SSL_STRICT
, ssl_strict_certs
,
9397 /* guess_search regex */
9398 if (url_regex
== NULL
)
9399 url_regex
= g_strdup(XT_URL_REGEX
);
9401 if (regcomp(&url_re
, url_regex
, REG_EXTENDED
| REG_NOSUB
))
9402 startpage_add("invalid url regex %s", url_regex
);
9405 env_proxy
= getenv("http_proxy");
9407 setup_proxy(env_proxy
);
9409 setup_proxy(http_proxy
);
9412 send_cmd_to_socket(argv
[0]);
9416 /* set some connection parameters */
9417 g_object_set(session
, "max-conns", max_connections
, (char *)NULL
);
9418 g_object_set(session
, "max-conns-per-host", max_host_connections
,
9421 /* see if there is already an xxxterm running */
9422 if (single_instance
&& is_running()) {
9424 warnx("already running");
9429 cmd
= g_strdup_printf("%s %s", "tabnew", argv
[0]);
9430 send_cmd_to_socket(cmd
);
9440 /* uri completion */
9441 completion_model
= gtk_list_store_new(1, G_TYPE_STRING
);
9444 buffers_store
= gtk_list_store_new
9445 (NUM_COLS
, G_TYPE_UINT
, G_TYPE_STRING
);
9451 notebook_tab_set_visibility();
9453 if (save_global_history
)
9454 restore_global_history();
9456 /* restore session list */
9457 restore_sessions_list();
9459 if (!strcmp(named_session
, XT_SAVED_TABS_FILE
))
9460 restore_saved_tabs();
9462 a
.s
= named_session
;
9463 a
.i
= XT_SES_DONOTHING
;
9464 open_tabs(NULL
, &a
);
9467 /* see if we have an exception */
9468 if (!TAILQ_EMPTY(&spl
)) {
9469 create_new_tab("about:startpage", NULL
, focus
, -1);
9474 create_new_tab(argv
[0], NULL
, focus
, -1);
9481 if (TAILQ_EMPTY(&tabs
))
9482 create_new_tab(home
, NULL
, 1, -1);
9485 if ((s
= build_socket()) != -1) {
9486 channel
= g_io_channel_unix_new(s
);
9487 g_io_add_watch(channel
, G_IO_IN
, socket_watcher
, NULL
);
9493 gdk_threads_leave();
9494 g_static_rec_mutex_unlock_full(&my_gdk_mtx
); /* just in case */
9497 gnutls_global_deinit();