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, 2012 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.
25 char *version
= XXXTERM_VERSION
;
28 uint32_t swm_debug
= 0
51 GCRY_THREAD_OPTION_PTHREAD_IMPL
;
63 TAILQ_ENTRY(session
) entry
;
66 TAILQ_HEAD(session_list
, session
);
69 TAILQ_ENTRY(undo
) entry
;
72 int back
; /* Keeps track of how many back
73 * history items there are. */
75 TAILQ_HEAD(undo_tailq
, undo
);
77 struct command_entry
{
79 TAILQ_ENTRY(command_entry
) entry
;
81 TAILQ_HEAD(command_list
, command_entry
);
84 #define XT_DIR (".xxxterm")
85 #define XT_CACHE_DIR ("cache")
86 #define XT_CERT_DIR ("certs")
87 #define XT_JS_DIR ("js")
88 #define XT_SESSIONS_DIR ("sessions")
89 #define XT_TEMP_DIR ("tmp")
90 #define XT_CONF_FILE ("xxxterm.conf")
91 #define XT_QMARKS_FILE ("quickmarks")
92 #define XT_SAVED_TABS_FILE ("main_session")
93 #define XT_RESTART_TABS_FILE ("restart_tabs")
94 #define XT_SOCKET_FILE ("socket")
95 #define XT_SAVE_SESSION_ID ("SESSION_NAME=")
96 #define XT_SEARCH_FILE ("search_history")
97 #define XT_COMMAND_FILE ("command_history")
98 #define XT_DLMAN_REFRESH "10"
99 #define XT_MAX_URL_LENGTH (4096) /* 1 page is atomic, don't make bigger */
100 #define XT_MAX_UNDO_CLOSE_TAB (32)
101 #define XT_RESERVED_CHARS "$&+,/:;=?@ \"<>#%%{}|^~[]`"
102 #define XT_PRINT_EXTRA_MARGIN 10
103 #define XT_URL_REGEX ("^[[:blank:]]*[^[:blank:]]*([[:alnum:]-]+\\.)+[[:alnum:]-][^[:blank:]]*[[:blank:]]*$")
104 #define XT_INVALID_MARK (-1) /* XXX this is a double, maybe use something else, like a nan */
107 #define XT_COLOR_RED "#cc0000"
108 #define XT_COLOR_YELLOW "#ffff66"
109 #define XT_COLOR_BLUE "lightblue"
110 #define XT_COLOR_GREEN "#99ff66"
111 #define XT_COLOR_WHITE "white"
112 #define XT_COLOR_BLACK "black"
114 #define XT_COLOR_CT_BACKGROUND "#000000"
115 #define XT_COLOR_CT_INACTIVE "#dddddd"
116 #define XT_COLOR_CT_ACTIVE "#bbbb00"
117 #define XT_COLOR_CT_SEPARATOR "#555555"
119 #define XT_COLOR_SB_SEPARATOR "#555555"
121 #define XT_PROTO_DELIM "://"
124 #define XT_MOVE_INVALID (0)
125 #define XT_MOVE_DOWN (1)
126 #define XT_MOVE_UP (2)
127 #define XT_MOVE_BOTTOM (3)
128 #define XT_MOVE_TOP (4)
129 #define XT_MOVE_PAGEDOWN (5)
130 #define XT_MOVE_PAGEUP (6)
131 #define XT_MOVE_HALFDOWN (7)
132 #define XT_MOVE_HALFUP (8)
133 #define XT_MOVE_LEFT (9)
134 #define XT_MOVE_FARLEFT (10)
135 #define XT_MOVE_RIGHT (11)
136 #define XT_MOVE_FARRIGHT (12)
137 #define XT_MOVE_PERCENT (13)
138 #define XT_MOVE_CENTER (14)
140 #define XT_QMARK_SET (0)
141 #define XT_QMARK_OPEN (1)
142 #define XT_QMARK_TAB (2)
144 #define XT_MARK_SET (0)
145 #define XT_MARK_GOTO (1)
147 #define XT_GO_UP_ROOT (999)
149 #define XT_TAB_LAST (-4)
150 #define XT_TAB_FIRST (-3)
151 #define XT_TAB_PREV (-2)
152 #define XT_TAB_NEXT (-1)
153 #define XT_TAB_INVALID (0)
154 #define XT_TAB_NEW (1)
155 #define XT_TAB_DELETE (2)
156 #define XT_TAB_DELQUIT (3)
157 #define XT_TAB_OPEN (4)
158 #define XT_TAB_UNDO_CLOSE (5)
159 #define XT_TAB_SHOW (6)
160 #define XT_TAB_HIDE (7)
161 #define XT_TAB_NEXTSTYLE (8)
162 #define XT_TAB_LOAD_IMAGES (9)
164 #define XT_NAV_INVALID (0)
165 #define XT_NAV_BACK (1)
166 #define XT_NAV_FORWARD (2)
167 #define XT_NAV_RELOAD (3)
168 #define XT_NAV_STOP (4)
170 #define XT_FOCUS_INVALID (0)
171 #define XT_FOCUS_URI (1)
172 #define XT_FOCUS_SEARCH (2)
174 #define XT_SEARCH_INVALID (0)
175 #define XT_SEARCH_NEXT (1)
176 #define XT_SEARCH_PREV (2)
178 #define XT_STYLE_CURRENT_TAB (0)
179 #define XT_STYLE_GLOBAL (1)
181 #define XT_PASTE_CURRENT_TAB (0)
182 #define XT_PASTE_NEW_TAB (1)
184 #define XT_ZOOM_IN (-1)
185 #define XT_ZOOM_OUT (-2)
186 #define XT_ZOOM_NORMAL (100)
188 #define XT_URL_SHOW (1)
189 #define XT_URL_HIDE (2)
191 #define XT_CMD_OPEN (0)
192 #define XT_CMD_OPEN_CURRENT (1)
193 #define XT_CMD_TABNEW (2)
194 #define XT_CMD_TABNEW_CURRENT (3)
196 #define XT_STATUS_NOTHING (0)
197 #define XT_STATUS_LINK (1)
198 #define XT_STATUS_URI (2)
199 #define XT_STATUS_LOADING (3)
201 #define XT_SES_DONOTHING (0)
202 #define XT_SES_CLOSETABS (1)
204 #define XT_PREFIX (1<<0)
205 #define XT_USERARG (1<<1)
206 #define XT_URLARG (1<<2)
207 #define XT_INTARG (1<<3)
208 #define XT_SESSARG (1<<4)
209 #define XT_SETARG (1<<5)
211 #define XT_HINT_NEWTAB (1<<0)
213 #define XT_BUFCMD_SZ (8)
215 #define XT_EJS_SHOW (1<<0)
217 GtkWidget
* create_button(char *, char *, int);
219 void recalc_tabs(void);
220 void recolor_compact_tabs(void);
221 void set_current_tab(int page_num
);
222 gboolean
update_statusbar_position(GtkAdjustment
*, gpointer
);
223 void marks_clear(struct tab
*t
);
226 extern char *__progname
;
227 char * const *start_argv
;
229 GtkWidget
*main_window
;
230 GtkNotebook
*notebook
;
232 GtkWidget
*arrow
, *abtn
;
233 struct tab_list tabs
;
234 struct history_list hl
;
235 int hl_purge_count
= 0;
236 struct session_list sessions
;
237 struct domain_list c_wl
;
238 struct domain_list js_wl
;
239 struct domain_list pl_wl
;
240 struct undo_tailq undos
;
241 struct keybinding_list kbl
;
243 struct user_agent_list ua_list
;
244 int user_agent_count
= 0;
245 struct command_list chl
;
246 struct command_list shl
;
247 struct command_entry
*history_at
;
248 struct command_entry
*search_at
;
250 int cmd_history_count
= 0;
251 int search_history_count
= 0;
253 long long unsigned int blocked_cookies
= 0;
254 char named_session
[PATH_MAX
];
255 GtkListStore
*completion_model
;
256 GtkListStore
*buffers_store
;
258 char *qmarks
[XT_NOMARKS
];
259 int btn_down
; /* M1 down in any wv */
260 regex_t url_re
; /* guess_search regex */
262 /* starts from 1 to catch atoi() failures when calling xtp_handle_dl() */
263 int next_download_id
= 1;
265 void xxx_dir(char *);
266 int icon_size_map(int);
269 history_delete(struct command_list
*l
, int *counter
)
271 struct command_entry
*c
;
273 if (l
== NULL
|| counter
== NULL
)
276 c
= TAILQ_LAST(l
, command_list
);
280 TAILQ_REMOVE(l
, c
, entry
);
287 history_add(struct command_list
*list
, char *file
, char *l
, int *counter
)
289 struct command_entry
*c
;
292 if (list
== NULL
|| l
== NULL
|| counter
== NULL
)
295 /* don't add the same line */
296 c
= TAILQ_FIRST(list
);
298 if (!strcmp(c
->line
+ 1 /* skip space */, l
))
301 c
= g_malloc0(sizeof *c
);
302 c
->line
= g_strdup_printf(" %s", l
);
305 TAILQ_INSERT_HEAD(list
, c
, entry
);
308 history_delete(list
, counter
);
310 if (history_autosave
&& file
) {
311 f
= fopen(file
, "w");
313 show_oops(NULL
, "couldn't write history %s", file
);
317 TAILQ_FOREACH_REVERSE(c
, list
, command_list
, entry
) {
319 fprintf(f
, "%s\n", c
->line
);
327 history_read(struct command_list
*list
, char *file
, int *counter
)
330 char *s
, line
[65536];
332 if (list
== NULL
|| file
== NULL
)
335 f
= fopen(file
, "r");
337 startpage_add("couldn't open history file %s", file
);
342 s
= fgets(line
, sizeof line
, f
);
343 if (s
== NULL
|| feof(f
) || ferror(f
))
345 if ((s
= strchr(line
, '\n')) == NULL
) {
346 startpage_add("invalid history file %s", file
);
352 history_add(list
, NULL
, line
+ 1, counter
);
360 /* marks and quickmarks array storage.
361 * first a-z, then A-Z, then 0-9 */
368 if (i
>= 0 && i
<= 'z' - 'a')
372 if (i
>= 0 && i
<= 'Z' - 'A')
387 if (m
>= 'a' && m
<= 'z')
388 return ret
+ m
- 'a';
390 ret
+= 'z' - 'a' + 1;
391 if (m
>= 'A' && m
<= 'Z')
392 return ret
+ m
- 'A';
394 ret
+= 'Z' - 'A' + 1;
395 if (m
>= '0' && m
<= '9')
396 return ret
+ m
- '0';
401 #ifndef XT_SIGNALS_DISABLE
405 int saved_errno
, status
;
410 while ((pid
= waitpid(WAIT_ANY
, &status
, WNOHANG
)) != 0) {
414 if (errno
!= ECHILD
) {
416 clog_warn("sigchild: waitpid:");
422 if (WIFEXITED(status
)) {
423 if (WEXITSTATUS(status
) != 0) {
425 clog_warnx("sigchild: child exit status: %d",
426 WEXITSTATUS(status));
431 clog_warnx("sigchild: child is terminated abnormally");
441 is_g_object_setting(GObject
*o
, char *str
)
443 guint n_props
= 0, i
;
444 GParamSpec
**proplist
;
446 if (! G_IS_OBJECT(o
))
449 proplist
= g_object_class_list_properties(G_OBJECT_GET_CLASS(o
),
452 for (i
=0; i
< n_props
; i
++) {
453 if (! strcmp(proplist
[i
]->name
, str
))
460 get_current_tab(void)
464 TAILQ_FOREACH(t
, &tabs
, entry
) {
465 if (t
->tab_id
== gtk_notebook_get_current_page(notebook
))
469 warnx("%s: no current tab", __func__
);
475 set_status(struct tab
*t
, gchar
*s
, int status
)
483 case XT_STATUS_LOADING
:
484 type
= g_strdup_printf("Loading: %s", s
);
488 type
= g_strdup_printf("Link: %s", s
);
490 t
->status
= g_strdup(gtk_entry_get_text(
491 GTK_ENTRY(t
->sbe
.statusbar
)));
495 type
= g_strdup_printf("%s", s
);
497 t
->status
= g_strdup(type
);
501 t
->status
= g_strdup(s
);
503 case XT_STATUS_NOTHING
:
508 gtk_entry_set_text(GTK_ENTRY(t
->sbe
.statusbar
), s
);
514 hide_cmd(struct tab
*t
)
516 DNPRINTF(XT_D_CMD
, "%s: tab %d\n", __func__
, t
->tab_id
);
518 history_at
= NULL
; /* just in case */
519 search_at
= NULL
; /* just in case */
520 gtk_widget_hide(t
->cmd
);
524 show_cmd(struct tab
*t
)
526 DNPRINTF(XT_D_CMD
, "%s: tab %d\n", __func__
, t
->tab_id
);
530 gtk_widget_hide(t
->oops
);
531 gtk_widget_show(t
->cmd
);
535 hide_buffers(struct tab
*t
)
537 gtk_widget_hide(t
->buffers
);
538 gtk_list_store_clear(buffers_store
);
549 sort_tabs_by_page_num(struct tab
***stabs
)
554 num_tabs
= gtk_notebook_get_n_pages(notebook
);
556 *stabs
= g_malloc0(num_tabs
* sizeof(struct tab
*));
558 TAILQ_FOREACH(t
, &tabs
, entry
)
559 (*stabs
)[gtk_notebook_page_num(notebook
, t
->vbox
)] = t
;
565 buffers_make_list(void)
568 const gchar
*title
= NULL
;
570 struct tab
**stabs
= NULL
;
572 num_tabs
= sort_tabs_by_page_num(&stabs
);
574 for (i
= 0; i
< num_tabs
; i
++)
576 gtk_list_store_append(buffers_store
, &iter
);
577 title
= get_title(stabs
[i
], FALSE
);
578 gtk_list_store_set(buffers_store
, &iter
,
579 COL_ID
, i
+ 1, /* Enumerate the tabs starting from 1
581 COL_FAVICON
, gtk_image_get_pixbuf
582 (GTK_IMAGE(stabs
[i
]->tab_elems
.favicon
)),
591 show_buffers(struct tab
*t
)
593 if (gtk_widget_get_visible(GTK_WIDGET(t
->buffers
)))
597 gtk_widget_show(t
->buffers
);
598 gtk_widget_grab_focus(GTK_WIDGET(t
->buffers
));
602 toggle_buffers(struct tab
*t
)
604 if (gtk_widget_get_visible(t
->buffers
))
611 buffers(struct tab
*t
, struct karg
*args
)
619 hide_oops(struct tab
*t
)
621 gtk_widget_hide(t
->oops
);
625 show_oops(struct tab
*at
, const char *fmt
, ...)
629 struct tab
*t
= NULL
;
635 if ((t
= get_current_tab()) == NULL
)
641 if (vasprintf(&msg
, fmt
, ap
) == -1)
642 errx(1, "show_oops failed");
645 gtk_entry_set_text(GTK_ENTRY(t
->oops
), msg
);
646 gtk_widget_hide(t
->cmd
);
647 gtk_widget_show(t
->oops
);
653 char work_dir
[PATH_MAX
];
654 char certs_dir
[PATH_MAX
];
655 char js_dir
[PATH_MAX
];
656 char cache_dir
[PATH_MAX
];
657 char sessions_dir
[PATH_MAX
];
658 char temp_dir
[PATH_MAX
];
659 char cookie_file
[PATH_MAX
];
660 SoupSession
*session
;
661 SoupCookieJar
*s_cookiejar
;
662 SoupCookieJar
*p_cookiejar
;
663 char rc_fname
[PATH_MAX
];
665 struct mime_type_list mtl
;
666 struct alias_list aliases
;
669 struct tab
*create_new_tab(char *, struct undo
*, int, int);
670 void delete_tab(struct tab
*);
671 void setzoom_webkit(struct tab
*, int);
672 int download_rb_cmp(struct download
*, struct download
*);
673 gboolean
cmd_execute(struct tab
*t
, char *str
);
676 history_rb_cmp(struct history
*h1
, struct history
*h2
)
678 return (strcmp(h1
->uri
, h2
->uri
));
680 RB_GENERATE(history_list
, history
, entry
, history_rb_cmp
);
683 domain_rb_cmp(struct domain
*d1
, struct domain
*d2
)
685 return (strcmp(d1
->d
, d2
->d
));
687 RB_GENERATE(domain_list
, domain
, entry
, domain_rb_cmp
);
690 download_rb_cmp(struct download
*e1
, struct download
*e2
)
692 return (e1
->id
< e2
->id
? -1 : e1
->id
> e2
->id
);
694 RB_GENERATE(download_list
, download
, entry
, download_rb_cmp
);
696 struct valid_url_types
{
707 valid_url_type(char *url
)
711 for (i
= 0; i
< LENGTH(vut
); i
++)
712 if (!strncasecmp(vut
[i
].type
, url
, strlen(vut
[i
].type
)))
719 match_alias(char *url_in
)
723 char *url_out
= NULL
, *search
, *enc_arg
;
725 search
= g_strdup(url_in
);
727 if (strsep(&arg
, " \t") == NULL
) {
728 show_oops(NULL
, "match_alias: NULL URL");
732 TAILQ_FOREACH(a
, &aliases
, entry
) {
733 if (!strcmp(search
, a
->a_name
))
738 DNPRINTF(XT_D_URL
, "match_alias: matched alias %s\n",
741 enc_arg
= soup_uri_encode(arg
, XT_RESERVED_CHARS
);
742 url_out
= g_strdup_printf(a
->a_uri
, enc_arg
);
745 url_out
= g_strdup_printf(a
->a_uri
, "");
753 guess_url_type(char *url_in
)
756 char *url_out
= NULL
, *enc_search
= NULL
;
761 /* substitute aliases */
762 url_out
= match_alias(url_in
);
766 /* see if we are an about page */
767 if (!strncmp(url_in
, XT_URI_ABOUT
, XT_URI_ABOUT_LEN
))
768 for (i
= 0; i
< about_list_size(); i
++)
769 if (!strcmp(&url_in
[XT_URI_ABOUT_LEN
],
770 about_list
[i
].name
)) {
771 url_out
= g_strdup(url_in
);
775 if (guess_search
&& url_regex
&&
776 !(g_str_has_prefix(url_in
, "http://") ||
777 g_str_has_prefix(url_in
, "https://"))) {
778 if (regexec(&url_re
, url_in
, 0, NULL
, 0)) {
779 /* invalid URI so search instead */
780 enc_search
= soup_uri_encode(url_in
, XT_RESERVED_CHARS
);
781 url_out
= g_strdup_printf(search_string
, enc_search
);
787 /* XXX not sure about this heuristic */
788 if (stat(url_in
, &sb
) == 0) {
789 if (url_in
[0] == '/')
790 url_out
= g_strdup_printf("file://%s", url_in
);
792 cwd
= malloc(PATH_MAX
);
793 if (getcwd(cwd
, PATH_MAX
) != NULL
) {
794 url_out
= g_strdup_printf("file://%s/%s",cwd
, url_in
);
799 url_out
= g_strdup_printf("http://%s", url_in
); /* guess http */
801 DNPRINTF(XT_D_URL
, "guess_url_type: guessed %s\n", url_out
);
807 load_uri(struct tab
*t
, gchar
*uri
)
810 gchar
*newuri
= NULL
;
816 /* Strip leading spaces. */
817 while (*uri
&& isspace(*uri
))
820 if (strlen(uri
) == 0) {
825 t
->xtp_meaning
= XT_XTP_TAB_MEANING_NORMAL
;
827 if (valid_url_type(uri
)) {
828 newuri
= guess_url_type(uri
);
832 if (!strncmp(uri
, XT_URI_ABOUT
, XT_URI_ABOUT_LEN
)) {
833 for (i
= 0; i
< about_list_size(); i
++)
834 if (!strcmp(&uri
[XT_URI_ABOUT_LEN
], about_list
[i
].name
)) {
835 bzero(&args
, sizeof args
);
836 about_list
[i
].func(t
, &args
);
837 gtk_widget_set_sensitive(GTK_WIDGET(t
->stop
),
841 show_oops(t
, "invalid about page");
845 set_status(t
, (char *)uri
, XT_STATUS_LOADING
);
847 webkit_web_view_load_uri(t
->wv
, uri
);
854 get_uri(struct tab
*t
)
856 const gchar
*uri
= NULL
;
858 if (webkit_web_view_get_load_status(t
->wv
) == WEBKIT_LOAD_FAILED
)
860 if (t
->xtp_meaning
== XT_XTP_TAB_MEANING_NORMAL
) {
861 uri
= webkit_web_view_get_uri(t
->wv
);
863 /* use tmp_uri to make sure it is g_freed */
866 t
->tmp_uri
=g_strdup_printf("%s%s", XT_URI_ABOUT
,
867 about_list
[t
->xtp_meaning
].name
);
874 get_title(struct tab
*t
, bool window
)
876 const gchar
*set
= NULL
, *title
= NULL
;
877 WebKitLoadStatus status
= webkit_web_view_get_load_status(t
->wv
);
879 if (status
== WEBKIT_LOAD_PROVISIONAL
|| status
== WEBKIT_LOAD_FAILED
||
880 t
->xtp_meaning
== XT_XTP_TAB_MEANING_BL
)
883 title
= webkit_web_view_get_title(t
->wv
);
884 if ((set
= title
? title
: get_uri(t
)))
888 set
= window
? XT_NAME
: "(untitled)";
894 find_mime_type(char *mime_type
)
896 struct mime_type
*m
, *def
= NULL
, *rv
= NULL
;
898 TAILQ_FOREACH(m
, &mtl
, entry
) {
900 !strncmp(mime_type
, m
->mt_type
, strlen(m
->mt_type
)))
903 if (m
->mt_default
== 0 && !strcmp(mime_type
, m
->mt_type
)) {
916 wl_find_uri(const gchar
*s
, struct domain_list
*wl
)
922 if (s
== NULL
|| wl
== NULL
)
925 if (!strncmp(s
, "http://", strlen("http://")))
926 s
= &s
[strlen("http://")];
927 else if (!strncmp(s
, "https://", strlen("https://")))
928 s
= &s
[strlen("https://")];
933 for (i
= 0; i
< strlen(s
) + 1 /* yes er need this */; i
++)
934 /* chop string at first slash */
935 if (s
[i
] == '/' || s
[i
] == ':' || s
[i
] == '\0') {
947 js_ref_to_string(JSContextRef context
, JSValueRef ref
)
953 jsref
= JSValueToStringCopy(context
, ref
, NULL
);
957 l
= JSStringGetMaximumUTF8CStringSize(jsref
);
960 JSStringGetUTF8CString(jsref
, s
, l
);
961 JSStringRelease(jsref
);
966 #define XT_JS_DONE ("done;")
967 #define XT_JS_DONE_LEN (strlen(XT_JS_DONE))
968 #define XT_JS_INSERT ("insert;")
969 #define XT_JS_INSERT_LEN (strlen(XT_JS_INSERT))
972 run_script(struct tab
*t
, char *s
)
974 JSGlobalContextRef ctx
;
975 WebKitWebFrame
*frame
;
977 JSValueRef val
, exception
;
980 DNPRINTF(XT_D_JS
, "%s: tab %d %s\n", __func__
,
981 t
->tab_id
, s
== (char *)JS_HINTING
? "JS_HINTING" : s
);
983 frame
= webkit_web_view_get_main_frame(t
->wv
);
984 ctx
= webkit_web_frame_get_global_context(frame
);
986 str
= JSStringCreateWithUTF8CString(s
);
987 val
= JSEvaluateScript(ctx
, str
, JSContextGetGlobalObject(ctx
),
988 NULL
, 0, &exception
);
989 JSStringRelease(str
);
991 DNPRINTF(XT_D_JS
, "%s: val %p\n", __func__
, val
);
993 es
= js_ref_to_string(ctx
, exception
);
995 DNPRINTF(XT_D_JS
, "%s: exception %s\n", __func__
, es
);
1000 es
= js_ref_to_string(ctx
, val
);
1003 if (!strncmp(es
, XT_JS_DONE
, XT_JS_DONE_LEN
))
1005 if (!strncmp(es
, XT_JS_INSERT
, XT_JS_INSERT_LEN
))
1009 DNPRINTF(XT_D_JS
, "%s: val %s\n", __func__
, es
);
1018 enable_hints(struct tab
*t
)
1020 DNPRINTF(XT_D_JS
, "%s: tab %d\n", __func__
, t
->tab_id
);
1023 run_script(t
, "hints.createHints('', 'F');");
1025 run_script(t
, "hints.createHints('', 'f');");
1026 t
->mode
= XT_MODE_HINT
;
1030 disable_hints(struct tab
*t
)
1032 DNPRINTF(XT_D_JS
, "%s: tab %d\n", __func__
, t
->tab_id
);
1034 run_script(t
, "hints.clearHints();");
1035 t
->mode
= XT_MODE_COMMAND
;
1040 passthrough(struct tab
*t
, struct karg
*args
)
1042 t
->mode
= XT_MODE_PASSTHROUGH
;
1047 hint(struct tab
*t
, struct karg
*args
)
1050 DNPRINTF(XT_D_JS
, "hint: tab %d args %d\n", t
->tab_id
, args
->i
);
1052 if (t
->mode
== XT_MODE_HINT
) {
1053 if (args
->i
== XT_HINT_NEWTAB
)
1063 apply_style(struct tab
*t
)
1066 g_object_set(G_OBJECT(t
->settings
),
1067 "user-stylesheet-uri", t
->stylesheet
, (char *)NULL
);
1071 remove_style(struct tab
*t
)
1074 g_object_set(G_OBJECT(t
->settings
),
1075 "user-stylesheet-uri", NULL
, (char *)NULL
);
1079 userstyle(struct tab
*t
, struct karg
*args
)
1083 DNPRINTF(XT_D_JS
, "userstyle: tab %d\n", t
->tab_id
);
1086 case XT_STYLE_CURRENT_TAB
:
1092 case XT_STYLE_GLOBAL
:
1093 if (userstyle_global
) {
1094 userstyle_global
= 0;
1095 TAILQ_FOREACH(tt
, &tabs
, entry
)
1098 userstyle_global
= 1;
1099 TAILQ_FOREACH(tt
, &tabs
, entry
)
1109 quit(struct tab
*t
, struct karg
*args
)
1111 if (save_global_history
)
1112 save_global_history_to_disk(t
);
1120 restore_sessions_list(void)
1123 struct dirent
*dp
= NULL
;
1127 sdir
= opendir(sessions_dir
);
1129 while ((dp
= readdir(sdir
)) != NULL
)
1130 #if defined __MINGW32__
1131 reg
= 1; /* windows only has regular files */
1133 reg
= dp
->d_type
== DT_REG
;
1136 s
= g_malloc(sizeof(struct session
));
1137 s
->name
= g_strdup(dp
->d_name
);
1138 TAILQ_INSERT_TAIL(&sessions
, s
, entry
);
1145 open_tabs(struct tab
*t
, struct karg
*a
)
1147 char file
[PATH_MAX
];
1151 struct tab
*ti
, *tt
;
1156 ti
= TAILQ_LAST(&tabs
, tab_list
);
1158 snprintf(file
, sizeof file
, "%s" PS
"%s", sessions_dir
, a
->s
);
1159 if ((f
= fopen(file
, "r")) == NULL
)
1163 if ((uri
= fparseln(f
, NULL
, NULL
, "\0\0\0", 0)) == NULL
)
1164 if (feof(f
) || ferror(f
))
1167 /* retrieve session name */
1168 if (uri
&& g_str_has_prefix(uri
, XT_SAVE_SESSION_ID
)) {
1169 strlcpy(named_session
,
1170 &uri
[strlen(XT_SAVE_SESSION_ID
)],
1171 sizeof named_session
);
1175 if (uri
&& strlen(uri
))
1176 create_new_tab(uri
, NULL
, 1, -1);
1182 /* close open tabs */
1183 if (a
->i
== XT_SES_CLOSETABS
&& ti
!= NULL
) {
1185 tt
= TAILQ_FIRST(&tabs
);
1206 restore_saved_tabs(void)
1208 char file
[PATH_MAX
];
1209 int unlink_file
= 0;
1214 snprintf(file
, sizeof file
, "%s" PS
"%s",
1215 sessions_dir
, XT_RESTART_TABS_FILE
);
1216 if (stat(file
, &sb
) == -1)
1217 a
.s
= XT_SAVED_TABS_FILE
;
1220 a
.s
= XT_RESTART_TABS_FILE
;
1223 a
.i
= XT_SES_DONOTHING
;
1224 rv
= open_tabs(NULL
, &a
);
1233 save_tabs(struct tab
*t
, struct karg
*a
)
1235 char file
[PATH_MAX
];
1237 int num_tabs
= 0, i
;
1238 struct tab
**stabs
= NULL
;
1240 /* tab may be null here */
1245 snprintf(file
, sizeof file
, "%s" PS
"%s",
1246 sessions_dir
, named_session
);
1248 snprintf(file
, sizeof file
, "%s" PS
"%s", sessions_dir
, a
->s
);
1250 if ((f
= fopen(file
, "w")) == NULL
) {
1251 show_oops(t
, "Can't open save_tabs file: %s", strerror(errno
));
1255 /* save session name */
1256 fprintf(f
, "%s%s\n", XT_SAVE_SESSION_ID
, named_session
);
1258 /* Save tabs, in the order they are arranged in the notebook. */
1259 num_tabs
= sort_tabs_by_page_num(&stabs
);
1261 for (i
= 0; i
< num_tabs
; i
++)
1263 if (get_uri(stabs
[i
]) != NULL
)
1264 fprintf(f
, "%s\n", get_uri(stabs
[i
]));
1265 else if (gtk_entry_get_text(GTK_ENTRY(
1266 stabs
[i
]->uri_entry
)))
1267 fprintf(f
, "%s\n", gtk_entry_get_text(GTK_ENTRY(
1268 stabs
[i
]->uri_entry
)));
1273 /* try and make sure this gets to disk NOW. XXX Backup first? */
1274 if (fflush(f
) != 0 || fsync(fileno(f
)) != 0) {
1275 show_oops(t
, "May not have managed to save session: %s",
1285 save_tabs_and_quit(struct tab
*t
, struct karg
*args
)
1297 run_page_script(struct tab
*t
, struct karg
*args
)
1300 char *tmp
, script
[PATH_MAX
];
1302 tmp
= args
->s
!= NULL
&& strlen(args
->s
) > 0 ? args
->s
: default_script
;
1303 if (tmp
[0] == '\0') {
1304 show_oops(t
, "no script specified");
1308 if ((uri
= get_uri(t
)) == NULL
) {
1309 show_oops(t
, "tab is empty, not running script");
1314 snprintf(script
, sizeof script
, "%s" PS
"%s",
1315 pwd
->pw_dir
, &tmp
[1]);
1317 strlcpy(script
, tmp
, sizeof script
);
1319 return (fork_exec(t
, script
, uri
, "can't launch external script"));
1323 yank_uri(struct tab
*t
, struct karg
*args
)
1326 GtkClipboard
*clipboard
;
1328 if ((uri
= get_uri(t
)) == NULL
)
1331 clipboard
= gtk_clipboard_get(GDK_SELECTION_PRIMARY
);
1332 gtk_clipboard_set_text(clipboard
, uri
, -1);
1338 paste_uri(struct tab
*t
, struct karg
*args
)
1340 GtkClipboard
*clipboard
;
1341 GdkAtom atom
= gdk_atom_intern("CUT_BUFFER0", FALSE
);
1343 gchar
*p
= NULL
, *uri
;
1345 /* try primary clipboard first */
1346 clipboard
= gtk_clipboard_get(GDK_SELECTION_PRIMARY
);
1347 p
= gtk_clipboard_wait_for_text(clipboard
);
1349 /* if it failed get whatever text is in cut_buffer0 */
1350 if (p
== NULL
&& xterm_workaround
)
1351 if (gdk_property_get(gdk_get_default_root_window(),
1353 gdk_atom_intern("STRING", FALSE
),
1355 1024 * 1024 /* picked out of my butt */,
1363 /* yes sir, we need to NUL the string */
1369 while (*uri
&& isspace(*uri
))
1371 if (strlen(uri
) == 0) {
1372 show_oops(t
, "empty paste buffer");
1375 if (guess_search
== 0 && valid_url_type(uri
)) {
1376 /* we can be clever and paste this in search box */
1377 show_oops(t
, "not a valid URL");
1381 if (args
->i
== XT_PASTE_CURRENT_TAB
)
1383 else if (args
->i
== XT_PASTE_NEW_TAB
)
1384 create_new_tab(uri
, NULL
, 1, -1);
1395 js_toggle_cb(GtkWidget
*w
, struct tab
*t
)
1400 g_object_get(G_OBJECT(t
->settings
),
1401 "enable-scripts", &es
, (char *)NULL
);
1406 set
= XT_WL_DISABLE
;
1408 a
.i
= set
| XT_WL_TOPLEVEL
;
1411 a
.i
= set
| XT_WL_TOPLEVEL
;
1414 a
.i
= XT_WL_TOGGLE
| XT_WL_TOPLEVEL
| XT_WL_RELOAD
;
1419 toggle_src(struct tab
*t
, struct karg
*args
)
1426 mode
= webkit_web_view_get_view_source_mode(t
->wv
);
1427 webkit_web_view_set_view_source_mode(t
->wv
, !mode
);
1428 webkit_web_view_reload(t
->wv
);
1434 focus_webview(struct tab
*t
)
1439 /* only grab focus if we are visible */
1440 if (gtk_notebook_get_current_page(notebook
) == t
->tab_id
)
1441 gtk_widget_grab_focus(GTK_WIDGET(t
->wv
));
1445 focus(struct tab
*t
, struct karg
*args
)
1447 if (t
== NULL
|| args
== NULL
)
1453 if (args
->i
== XT_FOCUS_URI
)
1454 gtk_widget_grab_focus(GTK_WIDGET(t
->uri_entry
));
1455 else if (args
->i
== XT_FOCUS_SEARCH
)
1456 gtk_widget_grab_focus(GTK_WIDGET(t
->search_entry
));
1462 connect_socket_from_uri(const gchar
*uri
, const gchar
**error_str
, char *domain
,
1466 struct addrinfo hints
, *res
= NULL
, *ai
;
1467 int rv
= -1, s
= -1, on
, error
;
1469 static gchar myerror
[256]; /* this is not thread safe */
1472 *error_str
= myerror
;
1473 if (uri
&& !g_str_has_prefix(uri
, "https://")) {
1474 *error_str
= "invalid URI";
1478 su
= soup_uri_new(uri
);
1480 *error_str
= "invalid soup URI";
1483 if (!SOUP_URI_VALID_FOR_HTTP(su
)) {
1484 *error_str
= "invalid HTTPS URI";
1488 snprintf(port
, sizeof port
, "%d", su
->port
);
1489 bzero(&hints
, sizeof(struct addrinfo
));
1490 hints
.ai_flags
= AI_CANONNAME
;
1491 hints
.ai_family
= AF_UNSPEC
;
1492 hints
.ai_socktype
= SOCK_STREAM
;
1494 if ((error
= getaddrinfo(su
->host
, port
, &hints
, &res
))) {
1495 snprintf(myerror
, sizeof myerror
, "getaddrinfo failed: %s",
1496 gai_strerror(errno
));
1500 for (ai
= res
; ai
; ai
= ai
->ai_next
) {
1506 if (ai
->ai_family
!= AF_INET
&& ai
->ai_family
!= AF_INET6
)
1508 s
= socket(ai
->ai_family
, ai
->ai_socktype
, ai
->ai_protocol
);
1511 if (setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, &on
,
1514 if (connect(s
, ai
->ai_addr
, ai
->ai_addrlen
) == 0)
1518 snprintf(myerror
, sizeof myerror
,
1519 "could not obtain certificates from: %s",
1525 strlcpy(domain
, su
->host
, domain_sz
);
1532 if (rv
== -1 && s
!= -1)
1540 custom_gnutls_push(void *s
, const void *buf
, size_t len
)
1542 return send((size_t)s
, buf
, len
, 0);
1546 custom_gnutls_pull(void *s
, void *buf
, size_t len
)
1548 return recv((size_t)s
, buf
, len
, 0);
1553 stop_tls(gnutls_session_t gsession
, gnutls_certificate_credentials_t xcred
)
1556 gnutls_deinit(gsession
);
1558 gnutls_certificate_free_credentials(xcred
);
1564 start_tls(const gchar
**error_str
, int s
, gnutls_session_t
*gs
,
1565 gnutls_certificate_credentials_t
*xc
)
1567 gnutls_certificate_credentials_t xcred
;
1568 gnutls_session_t gsession
;
1570 static gchar myerror
[1024]; /* this is not thread safe */
1572 if (gs
== NULL
|| xc
== NULL
)
1579 gnutls_certificate_allocate_credentials(&xcred
);
1580 gnutls_certificate_set_x509_trust_file(xcred
, ssl_ca_file
,
1581 GNUTLS_X509_FMT_PEM
);
1583 gnutls_init(&gsession
, GNUTLS_CLIENT
);
1584 gnutls_priority_set_direct(gsession
, "PERFORMANCE", NULL
);
1585 gnutls_credentials_set(gsession
, GNUTLS_CRD_CERTIFICATE
, xcred
);
1586 gnutls_transport_set_ptr(gsession
, (gnutls_transport_ptr_t
)(long)s
);
1588 /* sockets on windows don't use file descriptors */
1589 gnutls_transport_set_push_function(gsession
, custom_gnutls_push
);
1590 gnutls_transport_set_pull_function(gsession
, custom_gnutls_pull
);
1592 if ((rv
= gnutls_handshake(gsession
)) < 0) {
1593 snprintf(myerror
, sizeof myerror
,
1594 "gnutls_handshake failed %d fatal %d %s",
1596 gnutls_error_is_fatal(rv
),
1597 #if LIBGNUTLS_VERSION_MAJOR >= 2 && LIBGNUTLS_VERSION_MINOR >= 6
1598 gnutls_strerror_name(rv
));
1600 "GNUTLS version is too old to provide human readable error");
1602 stop_tls(gsession
, xcred
);
1606 gnutls_credentials_type_t cred
;
1607 cred
= gnutls_auth_get_type(gsession
);
1608 if (cred
!= GNUTLS_CRD_CERTIFICATE
) {
1609 snprintf(myerror
, sizeof myerror
,
1610 "gnutls_auth_get_type failed %d",
1612 stop_tls(gsession
, xcred
);
1620 *error_str
= myerror
;
1625 get_connection_certs(gnutls_session_t gsession
, gnutls_x509_crt_t
**certs
,
1629 const gnutls_datum_t
*cl
;
1630 gnutls_x509_crt_t
*all_certs
;
1633 if (certs
== NULL
|| cert_count
== NULL
)
1635 if (gnutls_certificate_type_get(gsession
) != GNUTLS_CRT_X509
)
1637 cl
= gnutls_certificate_get_peers(gsession
, &len
);
1641 all_certs
= g_malloc(sizeof(gnutls_x509_crt_t
) * len
);
1642 for (i
= 0; i
< len
; i
++) {
1643 gnutls_x509_crt_init(&all_certs
[i
]);
1644 if (gnutls_x509_crt_import(all_certs
[i
], &cl
[i
],
1645 GNUTLS_X509_FMT_PEM
< 0)) {
1659 free_connection_certs(gnutls_x509_crt_t
*certs
, size_t cert_count
)
1663 for (i
= 0; i
< cert_count
; i
++)
1664 gnutls_x509_crt_deinit(certs
[i
]);
1669 statusbar_modify_attr(struct tab
*t
, const char *text
, const char *base
)
1671 GdkColor c_text
, c_base
;
1673 gdk_color_parse(text
, &c_text
);
1674 gdk_color_parse(base
, &c_base
);
1676 gtk_widget_modify_text(t
->sbe
.statusbar
, GTK_STATE_NORMAL
, &c_text
);
1677 gtk_widget_modify_text(t
->sbe
.buffercmd
, GTK_STATE_NORMAL
, &c_text
);
1678 gtk_widget_modify_text(t
->sbe
.zoom
, GTK_STATE_NORMAL
, &c_text
);
1679 gtk_widget_modify_text(t
->sbe
.position
, GTK_STATE_NORMAL
, &c_text
);
1681 gtk_widget_modify_base(t
->sbe
.statusbar
, GTK_STATE_NORMAL
, &c_base
);
1682 gtk_widget_modify_base(t
->sbe
.buffercmd
, GTK_STATE_NORMAL
, &c_base
);
1683 gtk_widget_modify_base(t
->sbe
.zoom
, GTK_STATE_NORMAL
, &c_base
);
1684 gtk_widget_modify_base(t
->sbe
.position
, GTK_STATE_NORMAL
, &c_base
);
1688 save_certs(struct tab
*t
, gnutls_x509_crt_t
*certs
,
1689 size_t cert_count
, char *domain
)
1692 char cert_buf
[64 * 1024], file
[PATH_MAX
];
1697 if (t
== NULL
|| certs
== NULL
|| cert_count
<= 0 || domain
== NULL
)
1700 snprintf(file
, sizeof file
, "%s" PS
"%s", certs_dir
, domain
);
1701 if ((f
= fopen(file
, "w")) == NULL
) {
1702 show_oops(t
, "Can't create cert file %s %s",
1703 file
, strerror(errno
));
1707 for (i
= 0; i
< cert_count
; i
++) {
1708 cert_buf_sz
= sizeof cert_buf
;
1709 if (gnutls_x509_crt_export(certs
[i
], GNUTLS_X509_FMT_PEM
,
1710 cert_buf
, &cert_buf_sz
)) {
1711 show_oops(t
, "gnutls_x509_crt_export failed");
1714 if (fwrite(cert_buf
, cert_buf_sz
, 1, f
) != 1) {
1715 show_oops(t
, "Can't write certs: %s", strerror(errno
));
1720 /* not the best spot but oh well */
1721 gdk_color_parse("lightblue", &color
);
1722 gtk_widget_modify_base(t
->uri_entry
, GTK_STATE_NORMAL
, &color
);
1723 statusbar_modify_attr(t
, XT_COLOR_BLACK
, "lightblue");
1736 load_compare_cert(const gchar
*uri
, const gchar
**error_str
)
1738 char domain
[8182], file
[PATH_MAX
];
1739 char cert_buf
[64 * 1024], r_cert_buf
[64 * 1024];
1741 unsigned int error
= 0;
1743 size_t cert_buf_sz
, cert_count
;
1744 enum cert_trust rv
= CERT_UNTRUSTED
;
1745 static gchar serr
[80]; /* this isn't thread safe */
1746 gnutls_session_t gsession
;
1747 gnutls_x509_crt_t
*certs
;
1748 gnutls_certificate_credentials_t xcred
;
1750 DNPRINTF(XT_D_URL
, "%s: %s\n", __func__
, uri
);
1754 if ((s
= connect_socket_from_uri(uri
, error_str
, domain
,
1755 sizeof domain
)) == -1)
1758 DNPRINTF(XT_D_URL
, "%s: fd %d\n", __func__
, s
);
1761 if (start_tls(error_str
, s
, &gsession
, &xcred
))
1763 DNPRINTF(XT_D_URL
, "%s: got tls\n", __func__
);
1765 /* verify certs in case cert file doesn't exist */
1766 if (gnutls_certificate_verify_peers2(gsession
, &error
) !=
1768 *error_str
= "Invalid certificates";
1773 if (get_connection_certs(gsession
, &certs
, &cert_count
)) {
1774 *error_str
= "Can't get connection certificates";
1778 snprintf(file
, sizeof file
, "%s" PS
"%s", certs_dir
, domain
);
1779 if ((f
= fopen(file
, "r")) == NULL
) {
1785 for (i
= 0; i
< cert_count
; i
++) {
1786 cert_buf_sz
= sizeof cert_buf
;
1787 if (gnutls_x509_crt_export(certs
[i
], GNUTLS_X509_FMT_PEM
,
1788 cert_buf
, &cert_buf_sz
)) {
1791 if (fread(r_cert_buf
, cert_buf_sz
, 1, f
) != 1) {
1792 rv
= CERT_BAD
; /* critical */
1795 if (bcmp(r_cert_buf
, cert_buf
, sizeof cert_buf_sz
)) {
1796 rv
= CERT_BAD
; /* critical */
1805 free_connection_certs(certs
, cert_count
);
1807 /* we close the socket first for speed */
1811 /* only complain if we didn't save it locally */
1812 if (error
&& rv
!= CERT_LOCAL
) {
1813 strlcpy(serr
, "Certificate exception(s): ", sizeof serr
);
1814 if (error
& GNUTLS_CERT_INVALID
)
1815 strlcat(serr
, "invalid, ", sizeof serr
);
1816 if (error
& GNUTLS_CERT_REVOKED
)
1817 strlcat(serr
, "revoked, ", sizeof serr
);
1818 if (error
& GNUTLS_CERT_SIGNER_NOT_FOUND
)
1819 strlcat(serr
, "signer not found, ", sizeof serr
);
1820 if (error
& GNUTLS_CERT_SIGNER_NOT_CA
)
1821 strlcat(serr
, "not signed by CA, ", sizeof serr
);
1822 if (error
& GNUTLS_CERT_INSECURE_ALGORITHM
)
1823 strlcat(serr
, "insecure algorithm, ", sizeof serr
);
1824 #if LIBGNUTLS_VERSION_MAJOR >= 2 && LIBGNUTLS_VERSION_MINOR >= 6
1825 if (error
& GNUTLS_CERT_NOT_ACTIVATED
)
1826 strlcat(serr
, "not activated, ", sizeof serr
);
1827 if (error
& GNUTLS_CERT_EXPIRED
)
1828 strlcat(serr
, "expired, ", sizeof serr
);
1830 for (i
= strlen(serr
) - 1; i
> 0; i
--)
1831 if (serr
[i
] == ',') {
1838 stop_tls(gsession
, xcred
);
1844 cert_cmd(struct tab
*t
, struct karg
*args
)
1846 const gchar
*uri
, *error_str
= NULL
;
1850 gnutls_session_t gsession
;
1851 gnutls_x509_crt_t
*certs
;
1852 gnutls_certificate_credentials_t xcred
;
1857 if (ssl_ca_file
== NULL
) {
1858 show_oops(t
, "Can't open CA file: %s", ssl_ca_file
);
1862 if ((uri
= get_uri(t
)) == NULL
) {
1863 show_oops(t
, "Invalid URI");
1867 if ((s
= connect_socket_from_uri(uri
, &error_str
, domain
,
1868 sizeof domain
)) == -1) {
1869 show_oops(t
, "%s", error_str
);
1874 if (start_tls(&error_str
, s
, &gsession
, &xcred
))
1878 if (get_connection_certs(gsession
, &certs
, &cert_count
)) {
1879 show_oops(t
, "get_connection_certs failed");
1883 if (args
->i
& XT_SHOW
)
1884 show_certs(t
, certs
, cert_count
, "Certificate Chain");
1885 else if (args
->i
& XT_SAVE
)
1886 save_certs(t
, certs
, cert_count
, domain
);
1888 free_connection_certs(certs
, cert_count
);
1890 /* we close the socket first for speed */
1893 stop_tls(gsession
, xcred
);
1894 if (error_str
&& strlen(error_str
))
1895 show_oops(t
, "%s", error_str
);
1900 remove_cookie(int index
)
1906 DNPRINTF(XT_D_COOKIE
, "remove_cookie: %d\n", index
);
1908 cf
= soup_cookie_jar_all_cookies(s_cookiejar
);
1910 for (i
= 1; cf
; cf
= cf
->next
, i
++) {
1914 print_cookie("remove cookie", c
);
1915 soup_cookie_jar_delete_cookie(s_cookiejar
, c
);
1920 soup_cookies_free(cf
);
1926 remove_cookie_domain(int domain_id
)
1928 int domain_count
, rv
= 1;
1933 DNPRINTF(XT_D_COOKIE
, "remove_cookie_domain: %d\n", domain_id
);
1936 cf
= soup_cookie_jar_all_cookies(s_cookiejar
);
1938 for (domain_count
= 0; cf
; cf
= cf
->next
) {
1941 if (strcmp(last_domain
, c
->domain
) != 0) {
1943 last_domain
= c
->domain
;
1946 if (domain_count
< domain_id
)
1948 else if (domain_count
> domain_id
)
1951 print_cookie("remove cookie", c
);
1952 soup_cookie_jar_delete_cookie(s_cookiejar
, c
);
1956 soup_cookies_free(cf
);
1968 DNPRINTF(XT_D_COOKIE
, "remove_cookie_all\n");
1970 cf
= soup_cookie_jar_all_cookies(s_cookiejar
);
1972 for (; cf
; cf
= cf
->next
) {
1975 print_cookie("remove cookie", c
);
1976 soup_cookie_jar_delete_cookie(s_cookiejar
, c
);
1980 soup_cookies_free(cf
);
1986 toplevel_cmd(struct tab
*t
, struct karg
*args
)
1988 js_toggle_cb(t
->js_toggle
, t
);
1994 can_go_back_for_real(struct tab
*t
)
1997 WebKitWebHistoryItem
*item
;
2003 /* rely on webkit to make sure we can go backward when on an about page */
2005 if (uri
== NULL
|| g_str_has_prefix(uri
, "about:"))
2006 return (webkit_web_view_can_go_back(t
->wv
));
2008 /* the back/forwars list is stupid so help determine if we can go back */
2009 for (i
= 0, item
= webkit_web_back_forward_list_get_current_item(t
->bfl
);
2011 i
--, item
= webkit_web_back_forward_list_get_nth_item(t
->bfl
, i
)) {
2012 if (strcmp(webkit_web_history_item_get_uri(item
), uri
))
2020 can_go_forward_for_real(struct tab
*t
)
2023 WebKitWebHistoryItem
*item
;
2029 /* rely on webkit to make sure we can go forward when on an about page */
2031 if (uri
== NULL
|| g_str_has_prefix(uri
, "about:"))
2032 return (webkit_web_view_can_go_forward(t
->wv
));
2034 /* the back/forwars list is stupid so help selecting a different item */
2035 for (i
= 0, item
= webkit_web_back_forward_list_get_current_item(t
->bfl
);
2037 i
++, item
= webkit_web_back_forward_list_get_nth_item(t
->bfl
, i
)) {
2038 if (strcmp(webkit_web_history_item_get_uri(item
), uri
))
2046 go_back_for_real(struct tab
*t
)
2049 WebKitWebHistoryItem
*item
;
2057 webkit_web_view_go_back(t
->wv
);
2060 /* the back/forwars list is stupid so help selecting a different item */
2061 for (i
= 0, item
= webkit_web_back_forward_list_get_current_item(t
->bfl
);
2063 i
--, item
= webkit_web_back_forward_list_get_nth_item(t
->bfl
, i
)) {
2064 if (strcmp(webkit_web_history_item_get_uri(item
), uri
)) {
2065 webkit_web_view_go_to_back_forward_item(t
->wv
, item
);
2072 go_forward_for_real(struct tab
*t
)
2075 WebKitWebHistoryItem
*item
;
2083 webkit_web_view_go_forward(t
->wv
);
2086 /* the back/forwars list is stupid so help selecting a different item */
2087 for (i
= 0, item
= webkit_web_back_forward_list_get_current_item(t
->bfl
);
2089 i
++, item
= webkit_web_back_forward_list_get_nth_item(t
->bfl
, i
)) {
2090 if (strcmp(webkit_web_history_item_get_uri(item
), uri
)) {
2091 webkit_web_view_go_to_back_forward_item(t
->wv
, item
);
2098 navaction(struct tab
*t
, struct karg
*args
)
2100 WebKitWebHistoryItem
*item
;
2101 WebKitWebFrame
*frame
;
2103 DNPRINTF(XT_D_NAV
, "navaction: tab %d opcode %d\n",
2104 t
->tab_id
, args
->i
);
2106 t
->xtp_meaning
= XT_XTP_TAB_MEANING_NORMAL
;
2108 if (args
->i
== XT_NAV_BACK
)
2109 item
= webkit_web_back_forward_list_get_current_item(t
->bfl
);
2111 item
= webkit_web_back_forward_list_get_forward_item(t
->bfl
);
2113 return (XT_CB_PASSTHROUGH
);
2114 webkit_web_view_go_to_back_forward_item(t
->wv
, item
);
2116 return (XT_CB_PASSTHROUGH
);
2122 go_back_for_real(t
);
2124 case XT_NAV_FORWARD
:
2126 go_forward_for_real(t
);
2129 frame
= webkit_web_view_get_main_frame(t
->wv
);
2130 webkit_web_frame_reload(frame
);
2133 frame
= webkit_web_view_get_main_frame(t
->wv
);
2134 webkit_web_frame_stop_loading(frame
);
2137 return (XT_CB_PASSTHROUGH
);
2141 move(struct tab
*t
, struct karg
*args
)
2143 GtkAdjustment
*adjust
;
2144 double pi
, si
, pos
, ps
, upper
, lower
, max
;
2150 case XT_MOVE_BOTTOM
:
2152 case XT_MOVE_PAGEDOWN
:
2153 case XT_MOVE_PAGEUP
:
2154 case XT_MOVE_HALFDOWN
:
2155 case XT_MOVE_HALFUP
:
2156 case XT_MOVE_PERCENT
:
2157 case XT_MOVE_CENTER
:
2158 adjust
= t
->adjust_v
;
2161 adjust
= t
->adjust_h
;
2165 pos
= gtk_adjustment_get_value(adjust
);
2166 ps
= gtk_adjustment_get_page_size(adjust
);
2167 upper
= gtk_adjustment_get_upper(adjust
);
2168 lower
= gtk_adjustment_get_lower(adjust
);
2169 si
= gtk_adjustment_get_step_increment(adjust
);
2170 pi
= gtk_adjustment_get_page_increment(adjust
);
2173 DNPRINTF(XT_D_MOVE
, "move: opcode %d %s pos %f ps %f upper %f lower %f "
2174 "max %f si %f pi %f\n",
2175 args
->i
, adjust
== t
->adjust_h
? "horizontal" : "vertical",
2176 pos
, ps
, upper
, lower
, max
, si
, pi
);
2182 gtk_adjustment_set_value(adjust
, MIN(pos
, max
));
2187 gtk_adjustment_set_value(adjust
, MAX(pos
, lower
));
2189 case XT_MOVE_BOTTOM
:
2190 case XT_MOVE_FARRIGHT
:
2191 gtk_adjustment_set_value(adjust
, max
);
2194 case XT_MOVE_FARLEFT
:
2195 gtk_adjustment_set_value(adjust
, lower
);
2197 case XT_MOVE_PAGEDOWN
:
2199 gtk_adjustment_set_value(adjust
, MIN(pos
, max
));
2201 case XT_MOVE_PAGEUP
:
2203 gtk_adjustment_set_value(adjust
, MAX(pos
, lower
));
2205 case XT_MOVE_HALFDOWN
:
2207 gtk_adjustment_set_value(adjust
, MIN(pos
, max
));
2209 case XT_MOVE_HALFUP
:
2211 gtk_adjustment_set_value(adjust
, MAX(pos
, lower
));
2213 case XT_MOVE_CENTER
:
2214 args
->s
= g_strdup("50.0");
2216 case XT_MOVE_PERCENT
:
2217 percent
= atoi(args
->s
) / 100.0;
2218 pos
= max
* percent
;
2219 if (pos
< 0.0 || pos
> max
)
2221 gtk_adjustment_set_value(adjust
, pos
);
2224 return (XT_CB_PASSTHROUGH
);
2227 DNPRINTF(XT_D_MOVE
, "move: new pos %f %f\n", pos
, MIN(pos
, max
));
2229 return (XT_CB_HANDLED
);
2233 url_set_visibility(void)
2237 TAILQ_FOREACH(t
, &tabs
, entry
)
2238 if (show_url
== 0) {
2239 gtk_widget_hide(t
->toolbar
);
2242 gtk_widget_show(t
->toolbar
);
2246 notebook_tab_set_visibility(void)
2248 if (show_tabs
== 0) {
2249 gtk_widget_hide(tab_bar
);
2250 gtk_notebook_set_show_tabs(notebook
, FALSE
);
2252 if (tab_style
== XT_TABS_NORMAL
) {
2253 gtk_widget_hide(tab_bar
);
2254 gtk_notebook_set_show_tabs(notebook
, TRUE
);
2255 } else if (tab_style
== XT_TABS_COMPACT
) {
2256 gtk_widget_show(tab_bar
);
2257 gtk_notebook_set_show_tabs(notebook
, FALSE
);
2263 statusbar_set_visibility(void)
2267 TAILQ_FOREACH(t
, &tabs
, entry
){
2268 if (show_statusbar
== 0)
2269 gtk_widget_hide(t
->statusbar_box
);
2271 gtk_widget_show(t
->statusbar_box
);
2278 url_set(struct tab
*t
, int enable_url_entry
)
2283 show_url
= enable_url_entry
;
2285 if (enable_url_entry
) {
2286 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(t
->sbe
.statusbar
),
2287 GTK_ENTRY_ICON_PRIMARY
, NULL
);
2288 gtk_entry_set_progress_fraction(GTK_ENTRY(t
->sbe
.statusbar
), 0);
2290 pixbuf
= gtk_entry_get_icon_pixbuf(GTK_ENTRY(t
->uri_entry
),
2291 GTK_ENTRY_ICON_PRIMARY
);
2293 gtk_entry_get_progress_fraction(GTK_ENTRY(t
->uri_entry
));
2294 gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(t
->sbe
.statusbar
),
2295 GTK_ENTRY_ICON_PRIMARY
, pixbuf
);
2296 gtk_entry_set_progress_fraction(GTK_ENTRY(t
->sbe
.statusbar
),
2302 fullscreen(struct tab
*t
, struct karg
*args
)
2304 DNPRINTF(XT_D_TAB
, "%s: %p %d\n", __func__
, t
, args
->i
);
2307 return (XT_CB_PASSTHROUGH
);
2309 if (show_url
== 0) {
2317 url_set_visibility();
2318 notebook_tab_set_visibility();
2320 return (XT_CB_HANDLED
);
2324 statustoggle(struct tab
*t
, struct karg
*args
)
2326 DNPRINTF(XT_D_TAB
, "%s: %p %d\n", __func__
, t
, args
->i
);
2328 if (show_statusbar
== 1) {
2330 statusbar_set_visibility();
2331 } else if (show_statusbar
== 0) {
2333 statusbar_set_visibility();
2335 return (XT_CB_HANDLED
);
2339 urlaction(struct tab
*t
, struct karg
*args
)
2341 int rv
= XT_CB_HANDLED
;
2343 DNPRINTF(XT_D_TAB
, "%s: %p %d\n", __func__
, t
, args
->i
);
2346 return (XT_CB_PASSTHROUGH
);
2350 if (show_url
== 0) {
2352 url_set_visibility();
2356 if (show_url
== 1) {
2358 url_set_visibility();
2366 tabaction(struct tab
*t
, struct karg
*args
)
2368 int rv
= XT_CB_HANDLED
;
2369 char *url
= args
->s
;
2373 DNPRINTF(XT_D_TAB
, "tabaction: %p %d\n", t
, args
->i
);
2376 return (XT_CB_PASSTHROUGH
);
2380 if (strlen(url
) > 0)
2381 create_new_tab(url
, NULL
, 1, args
->precount
);
2383 create_new_tab(NULL
, NULL
, 1, args
->precount
);
2386 if (args
->precount
< 0)
2389 TAILQ_FOREACH(tt
, &tabs
, entry
)
2390 if (tt
->tab_id
== args
->precount
- 1) {
2395 case XT_TAB_DELQUIT
:
2396 if (gtk_notebook_get_n_pages(notebook
) > 1)
2402 if (strlen(url
) > 0)
2405 rv
= XT_CB_PASSTHROUGH
;
2411 if (show_tabs
== 0) {
2413 notebook_tab_set_visibility();
2417 if (show_tabs
== 1) {
2419 notebook_tab_set_visibility();
2422 case XT_TAB_NEXTSTYLE
:
2423 if (tab_style
== XT_TABS_NORMAL
) {
2424 tab_style
= XT_TABS_COMPACT
;
2425 recolor_compact_tabs();
2428 tab_style
= XT_TABS_NORMAL
;
2429 notebook_tab_set_visibility();
2431 case XT_TAB_UNDO_CLOSE
:
2432 if (undo_count
== 0) {
2433 DNPRINTF(XT_D_TAB
, "%s: no tabs to undo close",
2438 u
= TAILQ_FIRST(&undos
);
2439 create_new_tab(u
->uri
, u
, 1, -1);
2441 TAILQ_REMOVE(&undos
, u
, entry
);
2443 /* u->history is freed in create_new_tab() */
2447 case XT_TAB_LOAD_IMAGES
:
2449 if (!auto_load_images
) {
2451 /* Enable auto-load images (this will load all
2452 * previously unloaded images). */
2453 g_object_set(G_OBJECT(t
->settings
),
2454 "auto-load-images", TRUE
, (char *)NULL
);
2455 webkit_web_view_set_settings(t
->wv
, t
->settings
);
2457 webkit_web_view_reload(t
->wv
);
2459 /* Webkit triggers an event when we change the setting,
2460 * so we can't disable the auto-loading at once.
2462 * Unfortunately, webkit does not tell us when it's done.
2463 * Instead, we wait until the next request, and then
2464 * disable autoloading again.
2466 t
->load_images
= TRUE
;
2470 rv
= XT_CB_PASSTHROUGH
;
2484 resizetab(struct tab
*t
, struct karg
*args
)
2486 if (t
== NULL
|| args
== NULL
) {
2487 show_oops(NULL
, "resizetab invalid parameters");
2488 return (XT_CB_PASSTHROUGH
);
2491 DNPRINTF(XT_D_TAB
, "resizetab: tab %d %d\n",
2492 t
->tab_id
, args
->i
);
2494 setzoom_webkit(t
, args
->i
);
2496 return (XT_CB_HANDLED
);
2500 movetab(struct tab
*t
, struct karg
*args
)
2504 if (t
== NULL
|| args
== NULL
) {
2505 show_oops(NULL
, "movetab invalid parameters");
2506 return (XT_CB_PASSTHROUGH
);
2509 DNPRINTF(XT_D_TAB
, "movetab: tab %d opcode %d\n",
2510 t
->tab_id
, args
->i
);
2512 if (args
->i
>= XT_TAB_INVALID
)
2513 return (XT_CB_PASSTHROUGH
);
2515 if (TAILQ_EMPTY(&tabs
))
2516 return (XT_CB_PASSTHROUGH
);
2518 n
= gtk_notebook_get_n_pages(notebook
);
2519 dest
= gtk_notebook_get_current_page(notebook
);
2523 if (args
->precount
< 0)
2524 dest
= dest
== n
- 1 ? 0 : dest
+ 1;
2526 dest
= args
->precount
- 1;
2530 if (args
->precount
< 0)
2533 dest
-= args
->precount
% n
;
2546 return (XT_CB_PASSTHROUGH
);
2549 if (dest
< 0 || dest
>= n
)
2550 return (XT_CB_PASSTHROUGH
);
2551 if (t
->tab_id
== dest
) {
2552 DNPRINTF(XT_D_TAB
, "movetab: do nothing\n");
2553 return (XT_CB_HANDLED
);
2556 set_current_tab(dest
);
2558 return (XT_CB_HANDLED
);
2565 command(struct tab
*t
, struct karg
*args
)
2567 char *s
= NULL
, *ss
= NULL
;
2572 if (t
== NULL
|| args
== NULL
) {
2573 show_oops(NULL
, "command invalid parameters");
2574 return (XT_CB_PASSTHROUGH
);
2585 if (cmd_prefix
== 0)
2588 ss
= g_strdup_printf(":%d", cmd_prefix
);
2594 t
->mode
= XT_MODE_HINT
;
2595 bzero(&a
, sizeof a
);
2601 t
->mode
= XT_MODE_HINT
;
2602 bzero(&a
, sizeof a
);
2603 a
.i
= XT_HINT_NEWTAB
;
2613 case XT_CMD_OPEN_CURRENT
:
2616 case XT_CMD_TABNEW_CURRENT
:
2617 if (!s
) /* FALL THROUGH? */
2619 if ((uri
= get_uri(t
)) != NULL
) {
2620 ss
= g_strdup_printf("%s%s", s
, uri
);
2625 show_oops(t
, "command: invalid opcode %d", args
->i
);
2626 return (XT_CB_PASSTHROUGH
);
2629 DNPRINTF(XT_D_CMD
, "%s: tab %d type %s\n", __func__
, t
->tab_id
, s
);
2631 gtk_entry_set_text(GTK_ENTRY(t
->cmd
), s
);
2632 gdk_color_parse(XT_COLOR_WHITE
, &color
);
2633 gtk_widget_modify_base(t
->cmd
, GTK_STATE_NORMAL
, &color
);
2635 gtk_widget_grab_focus(GTK_WIDGET(t
->cmd
));
2636 gtk_editable_set_position(GTK_EDITABLE(t
->cmd
), -1);
2641 return (XT_CB_HANDLED
);
2645 search(struct tab
*t
, struct karg
*args
)
2649 if (t
== NULL
|| args
== NULL
) {
2650 show_oops(NULL
, "search invalid parameters");
2655 case XT_SEARCH_NEXT
:
2656 d
= t
->search_forward
;
2658 case XT_SEARCH_PREV
:
2659 d
= !t
->search_forward
;
2662 return (XT_CB_PASSTHROUGH
);
2665 if (t
->search_text
== NULL
) {
2666 if (global_search
== NULL
)
2667 return (XT_CB_PASSTHROUGH
);
2669 d
= t
->search_forward
= TRUE
;
2670 t
->search_text
= g_strdup(global_search
);
2671 webkit_web_view_mark_text_matches(t
->wv
, global_search
, FALSE
, 0);
2672 webkit_web_view_set_highlight_text_matches(t
->wv
, TRUE
);
2676 DNPRINTF(XT_D_CMD
, "search: tab %d opc %d forw %d text %s\n",
2677 t
->tab_id
, args
->i
, t
->search_forward
, t
->search_text
);
2679 webkit_web_view_search_text(t
->wv
, t
->search_text
, FALSE
, d
, TRUE
);
2681 return (XT_CB_HANDLED
);
2685 session_save(struct tab
*t
, char *filename
)
2691 if (strlen(filename
) == 0)
2694 if (filename
[0] == '.' || filename
[0] == '/')
2698 if (save_tabs(t
, &a
))
2700 strlcpy(named_session
, filename
, sizeof named_session
);
2702 /* add the new session to the list of sessions */
2703 s
= g_malloc(sizeof(struct session
));
2704 s
->name
= g_strdup(filename
);
2705 TAILQ_INSERT_TAIL(&sessions
, s
, entry
);
2713 session_open(struct tab
*t
, char *filename
)
2718 if (strlen(filename
) == 0)
2721 if (filename
[0] == '.' || filename
[0] == '/')
2725 a
.i
= XT_SES_CLOSETABS
;
2726 if (open_tabs(t
, &a
))
2729 strlcpy(named_session
, filename
, sizeof named_session
);
2737 session_delete(struct tab
*t
, char *filename
)
2739 char file
[PATH_MAX
];
2743 if (strlen(filename
) == 0)
2746 if (filename
[0] == '.' || filename
[0] == '/')
2749 snprintf(file
, sizeof file
, "%s" PS
"%s", sessions_dir
, filename
);
2753 if (!strcmp(filename
, named_session
))
2754 strlcpy(named_session
, XT_SAVED_TABS_FILE
,
2755 sizeof named_session
);
2757 /* remove session from sessions list */
2758 TAILQ_FOREACH(s
, &sessions
, entry
) {
2759 if (!strcmp(s
->name
, filename
))
2764 TAILQ_REMOVE(&sessions
, s
, entry
);
2765 g_free((gpointer
) s
->name
);
2774 session_cmd(struct tab
*t
, struct karg
*args
)
2776 char *filename
= args
->s
;
2781 if (args
->i
& XT_SHOW
)
2782 show_oops(t
, "Current session: %s", named_session
[0] == '\0' ?
2783 XT_SAVED_TABS_FILE
: named_session
);
2784 else if (args
->i
& XT_SAVE
) {
2785 if (session_save(t
, filename
)) {
2786 show_oops(t
, "Can't save session: %s",
2787 filename
? filename
: "INVALID");
2790 } else if (args
->i
& XT_OPEN
) {
2791 if (session_open(t
, filename
)) {
2792 show_oops(t
, "Can't open session: %s",
2793 filename
? filename
: "INVALID");
2796 } else if (args
->i
& XT_DELETE
) {
2797 if (session_delete(t
, filename
)) {
2798 show_oops(t
, "Can't delete session: %s",
2799 filename
? filename
: "INVALID");
2804 return (XT_CB_PASSTHROUGH
);
2808 script_cmd(struct tab
*t
, struct karg
*args
)
2817 if ((f
= fopen(args
->s
, "r")) == NULL
) {
2818 show_oops(t
, "Can't open script file: %s", args
->s
);
2822 if (fstat(fileno(f
), &sb
) == -1) {
2823 show_oops(t
, "Can't stat script file: %s", args
->s
);
2827 buf
= g_malloc0(sb
.st_size
+ 1);
2828 if (fread(buf
, 1, sb
.st_size
, f
) != sb
.st_size
) {
2829 show_oops(t
, "Can't read script file: %s", args
->s
);
2833 DNPRINTF(XT_D_JS
, "%s: about to run script\n", __func__
);
2842 return (XT_CB_PASSTHROUGH
);
2846 * Make a hardcopy of the page
2849 print_page(struct tab
*t
, struct karg
*args
)
2851 WebKitWebFrame
*frame
;
2853 GtkPrintOperation
*op
;
2854 GtkPrintOperationAction action
;
2855 GtkPrintOperationResult print_res
;
2856 GError
*g_err
= NULL
;
2857 int marg_l
, marg_r
, marg_t
, marg_b
;
2859 DNPRINTF(XT_D_PRINTING
, "%s:", __func__
);
2861 ps
= gtk_page_setup_new();
2862 op
= gtk_print_operation_new();
2863 action
= GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
;
2864 frame
= webkit_web_view_get_main_frame(t
->wv
);
2866 /* the default margins are too small, so we will bump them */
2867 marg_l
= gtk_page_setup_get_left_margin(ps
, GTK_UNIT_MM
) +
2868 XT_PRINT_EXTRA_MARGIN
;
2869 marg_r
= gtk_page_setup_get_right_margin(ps
, GTK_UNIT_MM
) +
2870 XT_PRINT_EXTRA_MARGIN
;
2871 marg_t
= gtk_page_setup_get_top_margin(ps
, GTK_UNIT_MM
) +
2872 XT_PRINT_EXTRA_MARGIN
;
2873 marg_b
= gtk_page_setup_get_bottom_margin(ps
, GTK_UNIT_MM
) +
2874 XT_PRINT_EXTRA_MARGIN
;
2877 gtk_page_setup_set_left_margin(ps
, marg_l
, GTK_UNIT_MM
);
2878 gtk_page_setup_set_right_margin(ps
, marg_r
, GTK_UNIT_MM
);
2879 gtk_page_setup_set_top_margin(ps
, marg_t
, GTK_UNIT_MM
);
2880 gtk_page_setup_set_bottom_margin(ps
, marg_b
, GTK_UNIT_MM
);
2882 gtk_print_operation_set_default_page_setup(op
, ps
);
2884 /* this appears to free 'op' and 'ps' */
2885 print_res
= webkit_web_frame_print_full(frame
, op
, action
, &g_err
);
2887 /* check it worked */
2888 if (print_res
== GTK_PRINT_OPERATION_RESULT_ERROR
) {
2889 show_oops(NULL
, "can't print: %s", g_err
->message
);
2890 g_error_free (g_err
);
2898 go_home(struct tab
*t
, struct karg
*args
)
2905 set_encoding(struct tab
*t
, struct karg
*args
)
2909 if (args
->s
&& strlen(g_strstrip(args
->s
)) == 0) {
2910 e
= webkit_web_view_get_custom_encoding(t
->wv
);
2912 e
= webkit_web_view_get_encoding(t
->wv
);
2913 show_oops(t
, "encoding: %s", e
? e
: "N/A");
2915 webkit_web_view_set_custom_encoding(t
->wv
, args
->s
);
2921 restart(struct tab
*t
, struct karg
*args
)
2925 a
.s
= XT_RESTART_TABS_FILE
;
2927 execvp(start_argv
[0], start_argv
);
2933 char *http_proxy_save
; /* not a setting, used to toggle */
2936 proxy_cmd(struct tab
*t
, struct karg
*args
)
2938 DNPRINTF(XT_D_CMD
, "%s: tab %d\n", __func__
, t
->tab_id
);
2945 if (http_proxy_save
)
2946 g_free(http_proxy_save
);
2947 http_proxy_save
= g_strdup(http_proxy
);
2950 if (args
->i
& XT_PRXY_SHOW
) {
2952 show_oops(t
, "http_proxy = %s", http_proxy
);
2954 show_oops(t
, "proxy is currently disabled");
2955 } else if (args
->i
& XT_PRXY_TOGGLE
) {
2956 if (http_proxy_save
== NULL
&& http_proxy
== NULL
) {
2957 show_oops(t
, "can't toggle proxy");
2963 setup_proxy(http_proxy_save
);
2966 return (XT_CB_PASSTHROUGH
);
2971 int (*func
)(struct tab
*, struct karg
*);
2975 { "command_mode", 0, command_mode
, XT_MODE_COMMAND
, 0 },
2976 { "insert_mode", 0, command_mode
, XT_MODE_INSERT
, 0 },
2977 { "command", 0, command
, ':', 0 },
2978 { "search", 0, command
, '/', 0 },
2979 { "searchb", 0, command
, '?', 0 },
2980 { "hinting", 0, command
, '.', 0 },
2981 { "hinting_newtab", 0, command
, ',', 0 },
2982 { "togglesrc", 0, toggle_src
, 0, 0 },
2983 { "editsrc", 0, edit_src
, 0, 0 },
2984 { "editelement", 0, edit_element
, 0, 0 },
2985 { "passthrough", 0, passthrough
, 0, 0 },
2987 /* yanking and pasting */
2988 { "yankuri", 0, yank_uri
, 0, 0 },
2989 /* XXX: pasteuri{cur,new} do not work from the cmd_entry? */
2990 { "pasteuricur", 0, paste_uri
, XT_PASTE_CURRENT_TAB
, 0 },
2991 { "pasteurinew", 0, paste_uri
, XT_PASTE_NEW_TAB
, 0 },
2994 { "searchnext", 0, search
, XT_SEARCH_NEXT
, 0 },
2995 { "searchprevious", 0, search
, XT_SEARCH_PREV
, 0 },
2998 { "focusaddress", 0, focus
, XT_FOCUS_URI
, 0 },
2999 { "focussearch", 0, focus
, XT_FOCUS_SEARCH
, 0 },
3002 { "hinting", 0, hint
, 0, 0 },
3003 { "hinting_newtab", 0, hint
, XT_HINT_NEWTAB
, 0 },
3005 /* custom stylesheet */
3006 { "userstyle", 0, userstyle
, XT_STYLE_CURRENT_TAB
, 0 },
3007 { "userstyle_global", 0, userstyle
, XT_STYLE_GLOBAL
, 0 },
3010 { "goback", 0, navaction
, XT_NAV_BACK
, 0 },
3011 { "goforward", 0, navaction
, XT_NAV_FORWARD
, 0 },
3012 { "reload", 0, navaction
, XT_NAV_RELOAD
, 0 },
3013 { "stop", 0, navaction
, XT_NAV_STOP
, 0 },
3015 /* vertical movement */
3016 { "scrolldown", 0, move
, XT_MOVE_DOWN
, 0 },
3017 { "scrollup", 0, move
, XT_MOVE_UP
, 0 },
3018 { "scrollbottom", 0, move
, XT_MOVE_BOTTOM
, 0 },
3019 { "scrolltop", 0, move
, XT_MOVE_TOP
, 0 },
3020 { "1", 0, move
, XT_MOVE_TOP
, 0 },
3021 { "scrollhalfdown", 0, move
, XT_MOVE_HALFDOWN
, 0 },
3022 { "scrollhalfup", 0, move
, XT_MOVE_HALFUP
, 0 },
3023 { "scrollpagedown", 0, move
, XT_MOVE_PAGEDOWN
, 0 },
3024 { "scrollpageup", 0, move
, XT_MOVE_PAGEUP
, 0 },
3025 /* horizontal movement */
3026 { "scrollright", 0, move
, XT_MOVE_RIGHT
, 0 },
3027 { "scrollleft", 0, move
, XT_MOVE_LEFT
, 0 },
3028 { "scrollfarright", 0, move
, XT_MOVE_FARRIGHT
, 0 },
3029 { "scrollfarleft", 0, move
, XT_MOVE_FARLEFT
, 0 },
3031 { "favorites", 0, xtp_page_fl
, 0, 0 },
3032 { "fav", 0, xtp_page_fl
, 0, 0 },
3033 { "favadd", 0, add_favorite
, 0, 0 },
3035 { "qall", 0, quit
, 0, 0 },
3036 { "quitall", 0, quit
, 0, 0 },
3037 { "w", 0, save_tabs
, 0, 0 },
3038 { "wq", 0, save_tabs_and_quit
, 0, 0 },
3039 { "help", 0, help
, 0, 0 },
3040 { "about", 0, about
, 0, 0 },
3041 { "stats", 0, stats
, 0, 0 },
3042 { "version", 0, about
, 0, 0 },
3045 { "js", 0, js_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
3046 { "save", 1, js_cmd
, XT_SAVE
| XT_WL_FQDN
, 0 },
3047 { "domain", 2, js_cmd
, XT_SAVE
| XT_WL_TOPLEVEL
, 0 },
3048 { "fqdn", 2, js_cmd
, XT_SAVE
| XT_WL_FQDN
, 0 },
3049 { "show", 1, js_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
3050 { "all", 2, js_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
3051 { "persistent", 2, js_cmd
, XT_SHOW
| XT_WL_PERSISTENT
, 0 },
3052 { "session", 2, js_cmd
, XT_SHOW
| XT_WL_SESSION
, 0 },
3053 { "toggle", 1, js_cmd
, XT_WL_TOGGLE
| XT_WL_FQDN
, 0 },
3054 { "domain", 2, js_cmd
, XT_WL_TOGGLE
| XT_WL_TOPLEVEL
, 0 },
3055 { "fqdn", 2, js_cmd
, XT_WL_TOGGLE
| XT_WL_FQDN
, 0 },
3057 /* cookie command */
3058 { "cookie", 0, cookie_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
3059 { "save", 1, cookie_cmd
, XT_SAVE
| XT_WL_FQDN
, 0 },
3060 { "domain", 2, cookie_cmd
, XT_SAVE
| XT_WL_TOPLEVEL
, 0 },
3061 { "fqdn", 2, cookie_cmd
, XT_SAVE
| XT_WL_FQDN
, 0 },
3062 { "show", 1, cookie_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
3063 { "all", 2, cookie_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
3064 { "persistent", 2, cookie_cmd
, XT_SHOW
| XT_WL_PERSISTENT
, 0 },
3065 { "session", 2, cookie_cmd
, XT_SHOW
| XT_WL_SESSION
, 0 },
3066 { "toggle", 1, cookie_cmd
, XT_WL_TOGGLE
| XT_WL_FQDN
, 0 },
3067 { "domain", 2, cookie_cmd
, XT_WL_TOGGLE
| XT_WL_TOPLEVEL
, 0 },
3068 { "fqdn", 2, cookie_cmd
, XT_WL_TOGGLE
| XT_WL_FQDN
, 0 },
3069 { "purge", 1, cookie_cmd
, XT_DELETE
, 0 },
3071 /* plugin command */
3072 { "plugin", 0, pl_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
3073 { "save", 1, pl_cmd
, XT_SAVE
| XT_WL_FQDN
, 0 },
3074 { "domain", 2, pl_cmd
, XT_SAVE
| XT_WL_TOPLEVEL
, 0 },
3075 { "fqdn", 2, pl_cmd
, XT_SAVE
| XT_WL_FQDN
, 0 },
3076 { "show", 1, pl_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
3077 { "all", 2, pl_cmd
, XT_SHOW
| XT_WL_PERSISTENT
| XT_WL_SESSION
, 0 },
3078 { "persistent", 2, pl_cmd
, XT_SHOW
| XT_WL_PERSISTENT
, 0 },
3079 { "session", 2, pl_cmd
, XT_SHOW
| XT_WL_SESSION
, 0 },
3080 { "toggle", 1, pl_cmd
, XT_WL_TOGGLE
| XT_WL_FQDN
, 0 },
3081 { "domain", 2, pl_cmd
, XT_WL_TOGGLE
| XT_WL_TOPLEVEL
, 0 },
3082 { "fqdn", 2, pl_cmd
, XT_WL_TOGGLE
| XT_WL_FQDN
, 0 },
3084 /* toplevel (domain) command */
3085 { "toplevel", 0, toplevel_cmd
, XT_WL_TOGGLE
| XT_WL_TOPLEVEL
| XT_WL_RELOAD
, 0 },
3086 { "toggle", 1, toplevel_cmd
, XT_WL_TOGGLE
| XT_WL_TOPLEVEL
| XT_WL_RELOAD
, 0 },
3089 { "cookiejar", 0, xtp_page_cl
, 0, 0 },
3092 { "cert", 0, cert_cmd
, XT_SHOW
, 0 },
3093 { "save", 1, cert_cmd
, XT_SAVE
, 0 },
3094 { "show", 1, cert_cmd
, XT_SHOW
, 0 },
3096 { "ca", 0, ca_cmd
, 0, 0 },
3097 { "downloadmgr", 0, xtp_page_dl
, 0, 0 },
3098 { "dl", 0, xtp_page_dl
, 0, 0 },
3099 { "h", 0, xtp_page_hl
, 0, 0 },
3100 { "history", 0, xtp_page_hl
, 0, 0 },
3101 { "home", 0, go_home
, 0, 0 },
3102 { "restart", 0, restart
, 0, 0 },
3103 { "urlhide", 0, urlaction
, XT_URL_HIDE
, 0 },
3104 { "urlshow", 0, urlaction
, XT_URL_SHOW
, 0 },
3105 { "statustoggle", 0, statustoggle
, 0, 0 },
3106 { "run_script", 0, run_page_script
, 0, XT_USERARG
},
3108 { "print", 0, print_page
, 0, 0 },
3111 { "focusin", 0, resizetab
, XT_ZOOM_IN
, 0 },
3112 { "focusout", 0, resizetab
, XT_ZOOM_OUT
, 0 },
3113 { "focusreset", 0, resizetab
, XT_ZOOM_NORMAL
, 0 },
3114 { "q", 0, tabaction
, XT_TAB_DELQUIT
, 0 },
3115 { "quit", 0, tabaction
, XT_TAB_DELQUIT
, 0 },
3116 { "open", 0, tabaction
, XT_TAB_OPEN
, XT_URLARG
},
3117 { "tabclose", 0, tabaction
, XT_TAB_DELETE
, XT_PREFIX
| XT_INTARG
},
3118 { "tabedit", 0, tabaction
, XT_TAB_NEW
, XT_PREFIX
| XT_URLARG
},
3119 { "tabfirst", 0, movetab
, XT_TAB_FIRST
, 0 },
3120 { "tabhide", 0, tabaction
, XT_TAB_HIDE
, 0 },
3121 { "tablast", 0, movetab
, XT_TAB_LAST
, 0 },
3122 { "tabnew", 0, tabaction
, XT_TAB_NEW
, XT_PREFIX
| XT_URLARG
},
3123 { "tabnext", 0, movetab
, XT_TAB_NEXT
, XT_PREFIX
| XT_INTARG
},
3124 { "tabnextstyle", 0, tabaction
, XT_TAB_NEXTSTYLE
, 0 },
3125 { "tabprevious", 0, movetab
, XT_TAB_PREV
, XT_PREFIX
| XT_INTARG
},
3126 { "tabrewind", 0, movetab
, XT_TAB_FIRST
, 0 },
3127 { "tabshow", 0, tabaction
, XT_TAB_SHOW
, 0 },
3128 { "tabs", 0, buffers
, 0, 0 },
3129 { "tabundoclose", 0, tabaction
, XT_TAB_UNDO_CLOSE
, 0 },
3130 { "buffers", 0, buffers
, 0, 0 },
3131 { "ls", 0, buffers
, 0, 0 },
3132 { "encoding", 0, set_encoding
, 0, XT_USERARG
},
3133 { "loadimages", 0, tabaction
, XT_TAB_LOAD_IMAGES
, 0 },
3135 /* command aliases (handy when -S flag is used) */
3136 { "promptopen", 0, command
, XT_CMD_OPEN
, 0 },
3137 { "promptopencurrent", 0, command
, XT_CMD_OPEN_CURRENT
, 0 },
3138 { "prompttabnew", 0, command
, XT_CMD_TABNEW
, 0 },
3139 { "prompttabnewcurrent",0, command
, XT_CMD_TABNEW_CURRENT
, 0 },
3142 { "set", 0, set
, 0, XT_SETARG
},
3144 { "fullscreen", 0, fullscreen
, 0, 0 },
3145 { "f", 0, fullscreen
, 0, 0 },
3148 { "session", 0, session_cmd
, XT_SHOW
, 0 },
3149 { "delete", 1, session_cmd
, XT_DELETE
, XT_SESSARG
},
3150 { "open", 1, session_cmd
, XT_OPEN
, XT_SESSARG
},
3151 { "save", 1, session_cmd
, XT_SAVE
, XT_USERARG
},
3152 { "show", 1, session_cmd
, XT_SHOW
, 0 },
3154 /* external javascript */
3155 { "script", 0, script_cmd
, XT_EJS_SHOW
, XT_USERARG
},
3158 { "inspector", 0, inspector_cmd
, XT_INS_SHOW
, 0 },
3159 { "show", 1, inspector_cmd
, XT_INS_SHOW
, 0 },
3160 { "hide", 1, inspector_cmd
, XT_INS_HIDE
, 0 },
3163 { "proxy", 0, proxy_cmd
, XT_PRXY_SHOW
, 0 },
3164 { "show", 1, proxy_cmd
, XT_PRXY_SHOW
, 0 },
3165 { "toggle", 1, proxy_cmd
, XT_PRXY_TOGGLE
, 0 },
3172 } cmd_status
= {-1, 0};
3175 wv_release_button_cb(GtkWidget
*btn
, GdkEventButton
*e
, struct tab
*t
)
3178 if (e
->type
== GDK_BUTTON_RELEASE
&& e
->button
== 1)
3185 wv_button_cb(GtkWidget
*btn
, GdkEventButton
*e
, struct tab
*t
)
3188 WebKitHitTestResult
*hit_test_result
;
3191 hit_test_result
= webkit_web_view_get_hit_test_result(t
->wv
, e
);
3192 g_object_get(hit_test_result
, "context", &context
, NULL
);
3197 if (context
& WEBKIT_HIT_TEST_RESULT_CONTEXT_EDITABLE
)
3198 t
->mode
= XT_MODE_INSERT
;
3200 t
->mode
= XT_MODE_COMMAND
;
3202 if (e
->type
== GDK_BUTTON_PRESS
&& e
->button
== 1)
3204 else if (e
->type
== GDK_BUTTON_PRESS
&& e
->button
== 8 /* btn 4 */) {
3210 } else if (e
->type
== GDK_BUTTON_PRESS
&& e
->button
== 9 /* btn 5 */) {
3212 a
.i
= XT_NAV_FORWARD
;
3222 tab_close_cb(GtkWidget
*btn
, GdkEventButton
*e
, struct tab
*t
)
3224 DNPRINTF(XT_D_TAB
, "tab_close_cb: tab %d\n", t
->tab_id
);
3226 if (e
->type
== GDK_BUTTON_PRESS
&& e
->button
== 1)
3235 activate_uri_entry_cb(GtkWidget
* entry
, struct tab
*t
)
3237 const gchar
*uri
= gtk_entry_get_text(GTK_ENTRY(entry
));
3239 DNPRINTF(XT_D_URL
, "activate_uri_entry_cb: %s\n", uri
);
3242 show_oops(NULL
, "activate_uri_entry_cb invalid parameters");
3247 show_oops(t
, "activate_uri_entry_cb no uri");
3251 uri
+= strspn(uri
, "\t ");
3253 /* if xxxt:// treat specially */
3254 if (parse_xtp_url(t
, uri
))
3257 /* otherwise continue to load page normally */
3258 load_uri(t
, (gchar
*)uri
);
3263 activate_search_entry_cb(GtkWidget
* entry
, struct tab
*t
)
3265 const gchar
*search
= gtk_entry_get_text(GTK_ENTRY(entry
));
3266 char *newuri
= NULL
;
3269 DNPRINTF(XT_D_URL
, "activate_search_entry_cb: %s\n", search
);
3272 show_oops(NULL
, "activate_search_entry_cb invalid parameters");
3276 if (search_string
== NULL
) {
3277 show_oops(t
, "no search_string");
3281 t
->xtp_meaning
= XT_XTP_TAB_MEANING_NORMAL
;
3283 enc_search
= soup_uri_encode(search
, XT_RESERVED_CHARS
);
3284 newuri
= g_strdup_printf(search_string
, enc_search
);
3288 webkit_web_view_load_uri(t
->wv
, newuri
);
3296 check_and_set_cookie(const gchar
*uri
, struct tab
*t
)
3298 struct domain
*d
= NULL
;
3301 if (uri
== NULL
|| t
== NULL
)
3304 if ((d
= wl_find_uri(uri
, &c_wl
)) == NULL
)
3309 DNPRINTF(XT_D_COOKIE
, "check_and_set_cookie: %s %s\n",
3310 es
? "enable" : "disable", uri
);
3312 g_object_set(G_OBJECT(t
->settings
),
3313 "enable-html5-local-storage", es
, (char *)NULL
);
3314 webkit_web_view_set_settings(t
->wv
, t
->settings
);
3318 check_and_set_js(const gchar
*uri
, struct tab
*t
)
3320 struct domain
*d
= NULL
;
3323 if (uri
== NULL
|| t
== NULL
)
3326 if ((d
= wl_find_uri(uri
, &js_wl
)) == NULL
)
3331 DNPRINTF(XT_D_JS
, "check_and_set_js: %s %s\n",
3332 es
? "enable" : "disable", uri
);
3334 g_object_set(G_OBJECT(t
->settings
),
3335 "enable-scripts", es
, (char *)NULL
);
3336 g_object_set(G_OBJECT(t
->settings
),
3337 "javascript-can-open-windows-automatically", es
, (char *)NULL
);
3338 webkit_web_view_set_settings(t
->wv
, t
->settings
);
3340 button_set_stockid(t
->js_toggle
,
3341 es
? GTK_STOCK_MEDIA_PLAY
: GTK_STOCK_MEDIA_PAUSE
);
3345 check_and_set_pl(const gchar
*uri
, struct tab
*t
)
3347 struct domain
*d
= NULL
;
3350 if (uri
== NULL
|| t
== NULL
)
3353 if ((d
= wl_find_uri(uri
, &pl_wl
)) == NULL
)
3358 DNPRINTF(XT_D_JS
, "check_and_set_pl: %s %s\n",
3359 es
? "enable" : "disable", uri
);
3361 g_object_set(G_OBJECT(t
->settings
),
3362 "enable-plugins", es
, (char *)NULL
);
3363 webkit_web_view_set_settings(t
->wv
, t
->settings
);
3367 color_address_bar(gpointer p
)
3370 struct tab
*tt
, *t
= p
;
3371 gchar
*col_str
= XT_COLOR_WHITE
;
3372 const gchar
*uri
, *u
= NULL
, *error_str
= NULL
;
3375 gdk_threads_enter();
3377 DNPRINTF(XT_D_URL
, "%s:\n", __func__
);
3379 /* make sure t still exists */
3382 TAILQ_FOREACH(tt
, &tabs
, entry
)
3388 if ((uri
= get_uri(t
)) == NULL
)
3393 gdk_threads_leave();
3396 col_str
= XT_COLOR_YELLOW
;
3397 switch (load_compare_cert(u
, &error_str
)) {
3399 col_str
= XT_COLOR_BLUE
;
3402 col_str
= XT_COLOR_GREEN
;
3404 case CERT_UNTRUSTED
:
3405 col_str
= XT_COLOR_YELLOW
;
3408 col_str
= XT_COLOR_RED
;
3413 gdk_threads_enter();
3415 /* make sure t isn't deleted */
3416 TAILQ_FOREACH(tt
, &tabs
, entry
)
3423 /* test to see if the user navigated away and canceled the thread */
3424 if (t
->thread
!= g_thread_self())
3426 if ((uri
= get_uri(t
)) == NULL
) {
3430 if (strcmp(uri
, u
)) {
3431 /* make sure we are still the same url */
3437 gdk_color_parse(col_str
, &color
);
3438 gtk_widget_modify_base(t
->uri_entry
, GTK_STATE_NORMAL
, &color
);
3440 if (!strcmp(col_str
, XT_COLOR_WHITE
))
3441 statusbar_modify_attr(t
, col_str
, XT_COLOR_BLACK
);
3443 statusbar_modify_attr(t
, XT_COLOR_BLACK
, col_str
);
3445 if (error_str
&& error_str
[0] != '\0')
3446 show_oops(t
, "%s", error_str
);
3451 /* t is invalid at this point */
3453 g_free((gpointer
)u
);
3455 gdk_threads_leave();
3460 show_ca_status(struct tab
*t
, const char *uri
)
3463 gchar
*col_str
= XT_COLOR_WHITE
;
3465 DNPRINTF(XT_D_URL
, "show_ca_status: %d %s %s\n",
3466 ssl_strict_certs
, ssl_ca_file
, uri
);
3473 if (ssl_ca_file
== NULL
) {
3474 if (g_str_has_prefix(uri
, "http://"))
3476 if (g_str_has_prefix(uri
, "https://")) {
3477 col_str
= XT_COLOR_RED
;
3482 if (g_str_has_prefix(uri
, "http://") ||
3483 !g_str_has_prefix(uri
, "https://"))
3487 * It is not necessary to see if the thread is already running.
3488 * If the thread is in progress setting it to something else aborts it
3492 /* thread the coloring of the address bar */
3493 t
->thread
= g_thread_create((GThreadFunc
)color_address_bar
, t
, TRUE
, NULL
);
3495 color_address_bar(t
);
3501 gdk_color_parse(col_str
, &color
);
3502 gtk_widget_modify_base(t
->uri_entry
, GTK_STATE_NORMAL
, &color
);
3504 if (!strcmp(col_str
, XT_COLOR_WHITE
))
3505 statusbar_modify_attr(t
, col_str
, XT_COLOR_BLACK
);
3507 statusbar_modify_attr(t
, XT_COLOR_BLACK
, col_str
);
3512 free_favicon(struct tab
*t
)
3514 DNPRINTF(XT_D_DOWNLOAD
, "%s: down %p req %p\n",
3515 __func__
, t
->icon_download
, t
->icon_request
);
3517 if (t
->icon_request
)
3518 g_object_unref(t
->icon_request
);
3519 if (t
->icon_dest_uri
)
3520 g_free(t
->icon_dest_uri
);
3522 t
->icon_request
= NULL
;
3523 t
->icon_dest_uri
= NULL
;
3527 xt_icon_from_name(struct tab
*t
, gchar
*name
)
3529 if (!enable_favicon_entry
)
3532 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(t
->uri_entry
),
3533 GTK_ENTRY_ICON_PRIMARY
, "text-html");
3535 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(t
->sbe
.statusbar
),
3536 GTK_ENTRY_ICON_PRIMARY
, "text-html");
3538 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(t
->sbe
.statusbar
),
3539 GTK_ENTRY_ICON_PRIMARY
, NULL
);
3543 xt_icon_from_pixbuf(struct tab
*t
, GdkPixbuf
*pb
)
3545 GdkPixbuf
*pb_scaled
;
3547 if (gdk_pixbuf_get_width(pb
) > 16 || gdk_pixbuf_get_height(pb
) > 16)
3548 pb_scaled
= gdk_pixbuf_scale_simple(pb
, 16, 16,
3549 GDK_INTERP_BILINEAR
);
3553 if (enable_favicon_entry
) {
3556 gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(t
->uri_entry
),
3557 GTK_ENTRY_ICON_PRIMARY
, pb_scaled
);
3560 if (show_url
== 0) {
3561 gtk_entry_set_icon_from_pixbuf(GTK_ENTRY(t
->sbe
.statusbar
),
3562 GTK_ENTRY_ICON_PRIMARY
, pb_scaled
);
3564 gtk_entry_set_icon_from_icon_name(GTK_ENTRY(t
->sbe
.statusbar
),
3565 GTK_ENTRY_ICON_PRIMARY
, NULL
);
3568 /* XXX: Only supports the minimal tabs atm. */
3569 if (enable_favicon_tabs
)
3570 gtk_image_set_from_pixbuf(GTK_IMAGE(t
->tab_elems
.favicon
),
3573 if (pb_scaled
!= pb
)
3574 g_object_unref(pb_scaled
);
3578 xt_icon_from_file(struct tab
*t
, char *file
)
3582 if (g_str_has_prefix(file
, "file://"))
3583 file
+= strlen("file://");
3585 pb
= gdk_pixbuf_new_from_file(file
, NULL
);
3587 xt_icon_from_pixbuf(t
, pb
);
3590 xt_icon_from_name(t
, "text-html");
3594 is_valid_icon(char *file
)
3597 const char *mime_type
;
3601 gf
= g_file_new_for_path(file
);
3602 fi
= g_file_query_info(gf
, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
, 0,
3604 mime_type
= g_file_info_get_content_type(fi
);
3605 valid
= g_strcmp0(mime_type
, "image/x-ico") == 0 ||
3606 g_strcmp0(mime_type
, "image/vnd.microsoft.icon") == 0 ||
3607 g_strcmp0(mime_type
, "image/png") == 0 ||
3608 g_strcmp0(mime_type
, "image/gif") == 0 ||
3609 g_strcmp0(mime_type
, "application/octet-stream") == 0;
3617 set_favicon_from_file(struct tab
*t
, char *file
)
3621 if (t
== NULL
|| file
== NULL
)
3624 if (g_str_has_prefix(file
, "file://"))
3625 file
+= strlen("file://");
3626 DNPRINTF(XT_D_DOWNLOAD
, "%s: loading %s\n", __func__
, file
);
3628 if (!stat(file
, &sb
)) {
3629 if (sb
.st_size
== 0 || !is_valid_icon(file
)) {
3630 /* corrupt icon so trash it */
3631 DNPRINTF(XT_D_DOWNLOAD
, "%s: corrupt icon %s\n",
3634 /* no need to set icon to default here */
3638 xt_icon_from_file(t
, file
);
3642 favicon_download_status_changed_cb(WebKitDownload
*download
, GParamSpec
*spec
,
3645 WebKitDownloadStatus status
= webkit_download_get_status(download
);
3646 struct tab
*tt
= NULL
, *t
= NULL
;
3649 * find the webview instead of passing in the tab as it could have been
3650 * deleted from underneath us.
3652 TAILQ_FOREACH(tt
, &tabs
, entry
) {
3661 DNPRINTF(XT_D_DOWNLOAD
, "%s: tab %d status %d\n",
3662 __func__
, t
->tab_id
, status
);
3665 case WEBKIT_DOWNLOAD_STATUS_ERROR
:
3667 t
->icon_download
= NULL
;
3670 case WEBKIT_DOWNLOAD_STATUS_CREATED
:
3673 case WEBKIT_DOWNLOAD_STATUS_STARTED
:
3676 case WEBKIT_DOWNLOAD_STATUS_CANCELLED
:
3678 DNPRINTF(XT_D_DOWNLOAD
, "%s: freeing favicon %d\n",
3679 __func__
, t
->tab_id
);
3680 t
->icon_download
= NULL
;
3683 case WEBKIT_DOWNLOAD_STATUS_FINISHED
:
3686 DNPRINTF(XT_D_DOWNLOAD
, "%s: setting icon to %s\n",
3687 __func__
, t
->icon_dest_uri
);
3688 set_favicon_from_file(t
, t
->icon_dest_uri
);
3689 /* these will be freed post callback */
3690 t
->icon_request
= NULL
;
3691 t
->icon_download
= NULL
;
3699 abort_favicon_download(struct tab
*t
)
3701 DNPRINTF(XT_D_DOWNLOAD
, "%s: down %p\n", __func__
, t
->icon_download
);
3703 #if !WEBKIT_CHECK_VERSION(1, 4, 0)
3704 if (t
->icon_download
) {
3705 g_signal_handlers_disconnect_by_func(G_OBJECT(t
->icon_download
),
3706 G_CALLBACK(favicon_download_status_changed_cb
), t
->wv
);
3707 webkit_download_cancel(t
->icon_download
);
3708 t
->icon_download
= NULL
;
3713 xt_icon_from_name(t
, "text-html");
3717 notify_icon_loaded_cb(WebKitWebView
*wv
, gchar
*uri
, struct tab
*t
)
3719 DNPRINTF(XT_D_DOWNLOAD
, "%s %s\n", __func__
, uri
);
3721 if (uri
== NULL
|| t
== NULL
)
3724 #if WEBKIT_CHECK_VERSION(1, 4, 0)
3725 /* take icon from WebKitIconDatabase */
3728 pb
= webkit_web_view_get_icon_pixbuf(wv
);
3730 xt_icon_from_pixbuf(t
, pb
);
3733 xt_icon_from_name(t
, "text-html");
3734 #elif WEBKIT_CHECK_VERSION(1, 1, 18)
3735 /* download icon to cache dir */
3736 gchar
*name_hash
, file
[PATH_MAX
];
3739 if (t
->icon_request
) {
3740 DNPRINTF(XT_D_DOWNLOAD
, "%s: download in progress\n", __func__
);
3744 /* check to see if we got the icon in cache */
3745 name_hash
= g_compute_checksum_for_string(G_CHECKSUM_SHA256
, uri
, -1);
3746 snprintf(file
, sizeof file
, "%s" PS
"%s.ico", cache_dir
, name_hash
);
3749 if (!stat(file
, &sb
)) {
3750 if (sb
.st_size
> 0) {
3751 DNPRINTF(XT_D_DOWNLOAD
, "%s: loading from cache %s\n",
3753 set_favicon_from_file(t
, file
);
3757 /* corrupt icon so trash it */
3758 DNPRINTF(XT_D_DOWNLOAD
, "%s: corrupt icon %s\n",
3763 /* create download for icon */
3764 t
->icon_request
= webkit_network_request_new(uri
);
3765 if (t
->icon_request
== NULL
) {
3766 DNPRINTF(XT_D_DOWNLOAD
, "%s: invalid uri %s\n",
3771 t
->icon_download
= webkit_download_new(t
->icon_request
);
3772 if (t
->icon_download
== NULL
)
3775 /* we have to free icon_dest_uri later */
3776 t
->icon_dest_uri
= g_strdup_printf("file://%s", file
);
3777 webkit_download_set_destination_uri(t
->icon_download
,
3780 if (webkit_download_get_status(t
->icon_download
) ==
3781 WEBKIT_DOWNLOAD_STATUS_ERROR
) {
3782 g_object_unref(t
->icon_request
);
3783 g_free(t
->icon_dest_uri
);
3784 t
->icon_request
= NULL
;
3785 t
->icon_dest_uri
= NULL
;
3789 g_signal_connect(G_OBJECT(t
->icon_download
), "notify::status",
3790 G_CALLBACK(favicon_download_status_changed_cb
), t
->wv
);
3792 webkit_download_start(t
->icon_download
);
3797 notify_load_status_cb(WebKitWebView
* wview
, GParamSpec
* pspec
, struct tab
*t
)
3799 const gchar
*uri
= NULL
;
3800 struct history
*h
, find
;
3804 DNPRINTF(XT_D_URL
, "notify_load_status_cb: %d %s\n",
3805 webkit_web_view_get_load_status(wview
),
3806 get_uri(t
) ? get_uri(t
) : "NOTHING");
3809 show_oops(NULL
, "notify_load_status_cb invalid parameters");
3813 switch (webkit_web_view_get_load_status(wview
)) {
3814 case WEBKIT_LOAD_PROVISIONAL
:
3816 abort_favicon_download(t
);
3817 #if GTK_CHECK_VERSION(2, 20, 0)
3818 gtk_widget_show(t
->spinner
);
3819 gtk_spinner_start(GTK_SPINNER(t
->spinner
));
3821 gtk_label_set_text(GTK_LABEL(t
->label
), "Loading");
3823 gtk_widget_set_sensitive(GTK_WIDGET(t
->stop
), TRUE
);
3825 /* assume we are a new address */
3826 gdk_color_parse("white", &color
);
3827 gtk_widget_modify_base(t
->uri_entry
, GTK_STATE_NORMAL
, &color
);
3828 statusbar_modify_attr(t
, "white", XT_COLOR_BLACK
);
3830 /* take focus if we are visible */
3836 /* kill color thread */
3841 case WEBKIT_LOAD_COMMITTED
:
3846 gtk_entry_set_text(GTK_ENTRY(t
->uri_entry
), uri
);
3852 set_status(t
, (char *)uri
, XT_STATUS_LOADING
);
3854 /* check if js white listing is enabled */
3855 if (enable_plugin_whitelist
)
3856 check_and_set_pl(uri
, t
);
3857 if (enable_cookie_whitelist
)
3858 check_and_set_cookie(uri
, t
);
3859 if (enable_js_whitelist
)
3860 check_and_set_js(uri
, t
);
3866 /* we know enough to autosave the session */
3867 if (session_autosave
) {
3872 show_ca_status(t
, uri
);
3873 run_script(t
, JS_HINTING
);
3874 if (enable_autoscroll
)
3875 run_script(t
, JS_AUTOSCROLL
);
3878 case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT
:
3880 if (color_visited_uris
) {
3881 color_visited(t
, color_visited_helper());
3883 /* This colors the links you middle-click (open in new
3884 * tab) in the current tab. */
3885 if (t
->tab_id
!= gtk_notebook_get_current_page(notebook
) &&
3886 (uri
= get_uri(t
)) != NULL
)
3887 color_visited(get_current_tab(),
3888 g_strdup_printf("{'%s' : 'dummy'}", uri
));
3892 case WEBKIT_LOAD_FINISHED
:
3894 if ((uri
= get_uri(t
)) == NULL
)
3897 if (!strncmp(uri
, "http://", strlen("http://")) ||
3898 !strncmp(uri
, "https://", strlen("https://")) ||
3899 !strncmp(uri
, "file://", strlen("file://"))) {
3900 find
.uri
= (gchar
*)uri
;
3901 h
= RB_FIND(history_list
, &hl
, &find
);
3903 insert_history_item(uri
,
3904 get_title(t
, FALSE
), time(NULL
));
3906 h
->time
= time(NULL
);
3909 set_status(t
, (char *)uri
, XT_STATUS_URI
);
3910 #if WEBKIT_CHECK_VERSION(1, 1, 18)
3911 case WEBKIT_LOAD_FAILED
:
3914 #if GTK_CHECK_VERSION(2, 20, 0)
3915 gtk_spinner_stop(GTK_SPINNER(t
->spinner
));
3916 gtk_widget_hide(t
->spinner
);
3919 gtk_widget_set_sensitive(GTK_WIDGET(t
->stop
), FALSE
);
3924 gtk_widget_set_sensitive(GTK_WIDGET(t
->backward
), TRUE
);
3926 gtk_widget_set_sensitive(GTK_WIDGET(t
->backward
),
3927 can_go_back_for_real(t
));
3929 gtk_widget_set_sensitive(GTK_WIDGET(t
->forward
),
3930 can_go_forward_for_real(t
));
3934 notify_title_cb(WebKitWebView
* wview
, GParamSpec
* pspec
, struct tab
*t
)
3936 const gchar
*title
= NULL
, *win_title
= NULL
;
3938 title
= get_title(t
, FALSE
);
3939 win_title
= get_title(t
, TRUE
);
3941 gtk_label_set_text(GTK_LABEL(t
->label
), title
);
3942 gtk_label_set_text(GTK_LABEL(t
->tab_elems
.label
), title
);
3945 if (win_title
&& t
->tab_id
== gtk_notebook_get_current_page(notebook
))
3946 gtk_window_set_title(GTK_WINDOW(main_window
), win_title
);
3950 get_domain(const gchar
*host
)
3955 /* handle silly domains like .co.uk */
3957 if ((x
= strlen(host
)) <= 6)
3958 return (g_strdup(host
));
3960 if (host
[x
- 3] == '.' && host
[x
- 6] == '.') {
3966 return (g_strdup(&host
[x
+ 1]));
3970 p
= g_strrstr(host
, ".");
3972 return (g_strdup(""));
3978 return (g_strdup(p
+ 1));
3980 return (g_strdup(host
));
3984 js_autorun(struct tab
*t
)
3988 size_t got_default
= 0, got_host
= 0;
3990 char deff
[PATH_MAX
], hostf
[PATH_MAX
];
3991 char *js
= NULL
, *jsat
, *domain
= NULL
;
3992 FILE *deffile
= NULL
, *hostfile
= NULL
;
3994 if (js_autorun_enabled
== 0)
3999 !(g_str_has_prefix(uri
, "http://") ||
4000 g_str_has_prefix(uri
, "https://")))
4003 su
= soup_uri_new(uri
);
4006 if (!SOUP_URI_VALID_FOR_HTTP(su
))
4009 DNPRINTF(XT_D_JS
, "%s: host: %s domain: %s\n", __func__
,
4011 domain
= get_domain(su
->host
);
4013 snprintf(deff
, sizeof deff
, "%s" PS
"default.js", js_dir
);
4014 if ((deffile
= fopen(deff
, "r")) != NULL
) {
4015 if (fstat(fileno(deffile
), &sb
) == -1) {
4016 show_oops(t
, "can't stat default JS file");
4019 got_default
= sb
.st_size
;
4022 /* try host first followed by domain */
4023 snprintf(hostf
, sizeof hostf
, "%s" PS
"%s.js", js_dir
, su
->host
);
4024 DNPRINTF(XT_D_JS
, "trying file: %s\n", hostf
);
4025 if ((hostfile
= fopen(hostf
, "r")) == NULL
) {
4026 snprintf(hostf
, sizeof hostf
, "%s" PS
"%s.js", js_dir
, domain
);
4027 DNPRINTF(XT_D_JS
, "trying file: %s\n", hostf
);
4028 if ((hostfile
= fopen(hostf
, "r")) == NULL
)
4031 DNPRINTF(XT_D_JS
, "file: %s\n", hostf
);
4032 if (fstat(fileno(hostfile
), &sb
) == -1) {
4033 show_oops(t
, "can't stat %s JS file", hostf
);
4036 got_host
= sb
.st_size
;
4039 if (got_default
+ got_host
== 0)
4042 js
= g_malloc0(got_default
+ got_host
+ 1);
4046 if (fread(js
, got_default
, 1, deffile
) != 1) {
4047 show_oops(t
, "default file read error");
4050 jsat
= js
+ got_default
;
4054 if (fread(jsat
, got_host
, 1, hostfile
) != 1) {
4055 show_oops(t
, "host file read error");
4060 DNPRINTF(XT_D_JS
, "%s: about to run script\n", __func__
);
4077 webview_load_finished_cb(WebKitWebView
*wv
, WebKitWebFrame
*wf
, struct tab
*t
)
4079 /* autorun some js if enabled */
4087 webview_progress_changed_cb(WebKitWebView
*wv
, int progress
, struct tab
*t
)
4089 gtk_entry_set_progress_fraction(GTK_ENTRY(t
->uri_entry
),
4090 progress
== 100 ? 0 : (double)progress
/ 100);
4091 if (show_url
== 0) {
4092 gtk_entry_set_progress_fraction(GTK_ENTRY(t
->sbe
.statusbar
),
4093 progress
== 100 ? 0 : (double)progress
/ 100);
4096 update_statusbar_position(NULL
, NULL
);
4100 session_rq_cb(SoupSession
*s
, SoupMessage
*msg
, SoupSocket
*socket
, gpointer data
)
4105 if (s
== NULL
|| msg
== NULL
)
4108 if (referer_mode
== XT_REFERER_ALWAYS
)
4111 /* Check if referer is set - and what the user requested for referers */
4112 ref
= soup_message_headers_get_one(msg
->request_headers
, "Referer");
4114 DNPRINTF(XT_D_NAV
, "session_rq_cb: Referer: %s\n", ref
);
4115 switch (referer_mode
) {
4116 case XT_REFERER_NEVER
:
4117 DNPRINTF(XT_D_NAV
, "session_rq_cb: removing referer\n");
4118 soup_message_headers_remove(msg
->request_headers
,
4121 case XT_REFERER_SAME_DOMAIN
:
4122 dest
= soup_message_get_uri(msg
);
4124 if (dest
&& !strstr(ref
, dest
->host
)) {
4125 soup_message_headers_remove(msg
->request_headers
, "Referer");
4126 DNPRINTF(XT_D_NAV
, "session_rq_cb: removing referer (not same domain)\n");
4129 case XT_REFERER_CUSTOM
:
4130 DNPRINTF(XT_D_NAV
, "session_rq_cb: setting referer to %s\n", referer_custom
);
4131 soup_message_headers_replace(msg
->request_headers
,
4132 "Referer", referer_custom
);
4139 webview_npd_cb(WebKitWebView
*wv
, WebKitWebFrame
*wf
,
4140 WebKitNetworkRequest
*request
, WebKitWebNavigationAction
*na
,
4141 WebKitWebPolicyDecision
*pd
, struct tab
*t
)
4144 WebKitWebNavigationReason reason
;
4145 struct domain
*d
= NULL
;
4148 show_oops(NULL
, "webview_npd_cb invalid parameters");
4152 DNPRINTF(XT_D_NAV
, "webview_npd_cb: ctrl_click %d %s\n",
4154 webkit_network_request_get_uri(request
));
4156 uri
= (char *)webkit_network_request_get_uri(request
);
4158 if (!auto_load_images
&& t
->load_images
) {
4160 /* Disable autoloading of images, now that we're done loading
4162 g_object_set(G_OBJECT(t
->settings
),
4163 "auto-load-images", FALSE
, (char *)NULL
);
4164 webkit_web_view_set_settings(t
->wv
, t
->settings
);
4166 t
->load_images
= FALSE
;
4169 /* If this is an xtp url, we don't load anything else. */
4170 if (parse_xtp_url(t
, uri
))
4173 if ((t
->mode
== XT_MODE_HINT
&& t
->new_tab
) || t
->ctrl_click
) {
4175 create_new_tab(uri
, NULL
, ctrl_click_focus
, -1);
4176 webkit_web_policy_decision_ignore(pd
);
4177 return (TRUE
); /* we made the decission */
4180 /* Change user agent if more than one has been given. */
4181 if (user_agent_count
> 1) {
4182 struct user_agent
*ua
;
4184 if ((ua
= TAILQ_NEXT(user_agent
, entry
)) == NULL
)
4185 user_agent
= TAILQ_FIRST(&ua_list
);
4189 free(t
->user_agent
);
4190 t
->user_agent
= g_strdup(user_agent
->value
);
4192 DNPRINTF(XT_D_NAV
, "user-agent: %s\n", t
->user_agent
);
4194 g_object_set(G_OBJECT(t
->settings
),
4195 "user-agent", t
->user_agent
, (char *)NULL
);
4197 webkit_web_view_set_settings(wv
, t
->settings
);
4201 * This is a little hairy but it comes down to this:
4202 * when we run in whitelist mode we have to assist the browser in
4203 * opening the URL that it would have opened in a new tab.
4205 reason
= webkit_web_navigation_action_get_reason(na
);
4206 if (reason
== WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED
) {
4207 t
->xtp_meaning
= XT_XTP_TAB_MEANING_NORMAL
;
4208 if (enable_scripts
== 0 && enable_cookie_whitelist
== 1)
4209 if (uri
&& (d
= wl_find_uri(uri
, &js_wl
)) == NULL
)
4211 webkit_web_policy_decision_use(pd
);
4212 return (TRUE
); /* we made the decision */
4219 webview_cwv_cb(WebKitWebView
*wv
, WebKitWebFrame
*wf
, struct tab
*t
)
4222 struct domain
*d
= NULL
;
4224 WebKitWebView
*webview
= NULL
;
4227 DNPRINTF(XT_D_NAV
, "webview_cwv_cb: %s\n",
4228 webkit_web_view_get_uri(wv
));
4231 /* open in current tab */
4233 } else if (enable_scripts
== 0 && enable_js_whitelist
== 1) {
4234 uri
= webkit_web_view_get_uri(wv
);
4235 if (uri
&& (d
= wl_find_uri(uri
, &js_wl
)) == NULL
)
4238 if (t
->ctrl_click
) {
4239 x
= ctrl_click_focus
;
4242 tt
= create_new_tab(NULL
, NULL
, x
, -1);
4244 } else if (enable_scripts
== 1) {
4245 if (t
->ctrl_click
) {
4246 x
= ctrl_click_focus
;
4249 tt
= create_new_tab(NULL
, NULL
, x
, -1);
4257 webview_closewv_cb(WebKitWebView
*wv
, struct tab
*t
)
4260 struct domain
*d
= NULL
;
4262 DNPRINTF(XT_D_NAV
, "webview_close_cb: %d\n", t
->tab_id
);
4264 if (enable_scripts
== 0 && enable_cookie_whitelist
== 1) {
4265 uri
= webkit_web_view_get_uri(wv
);
4266 if (uri
&& (d
= wl_find_uri(uri
, &js_wl
)) == NULL
)
4270 } else if (enable_scripts
== 1)
4277 webview_event_cb(GtkWidget
*w
, GdkEventButton
*e
, struct tab
*t
)
4279 /* we can not eat the event without throwing gtk off so defer it */
4281 /* catch middle click */
4282 if (e
->type
== GDK_BUTTON_RELEASE
&& e
->button
== 2) {
4287 /* catch ctrl click */
4288 if (e
->type
== GDK_BUTTON_RELEASE
&&
4289 CLEAN(e
->state
) == GDK_CONTROL_MASK
)
4294 return (XT_CB_PASSTHROUGH
);
4298 run_mimehandler(struct tab
*t
, char *mime_type
, WebKitNetworkRequest
*request
)
4300 struct mime_type
*m
;
4302 m
= find_mime_type(mime_type
);
4308 return (fork_exec(t
, m
->mt_action
,
4309 webkit_network_request_get_uri(request
),
4310 "can't launch MIME handler"));
4314 get_mime_type(const char *file
)
4317 char *mime_type
= NULL
;
4321 if (g_str_has_prefix(file
, "file://"))
4322 file
+= strlen("file://");
4324 gf
= g_file_new_for_path(file
);
4325 fi
= g_file_query_info(gf
, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE
, 0,
4327 if ((m
= g_file_info_get_content_type(fi
)) != NULL
)
4328 mime_type
= g_strdup(m
);
4336 run_download_mimehandler(char *mime_type
, char *file
)
4338 struct mime_type
*m
;
4340 m
= find_mime_type(mime_type
);
4344 return (fork_exec(NULL
, m
->mt_action
, file
,
4345 "can't launch download MIME handler"));
4349 download_status_changed_cb(WebKitDownload
*download
, GParamSpec
*spec
,
4352 WebKitDownloadStatus status
;
4353 const char *file
= NULL
;
4356 if (download
== NULL
)
4358 status
= webkit_download_get_status(download
);
4359 if (status
!= WEBKIT_DOWNLOAD_STATUS_FINISHED
)
4362 file
= webkit_download_get_destination_uri(download
);
4365 mime
= get_mime_type(file
);
4369 run_download_mimehandler((char *)mime
, (char *)file
);
4374 webview_mimetype_cb(WebKitWebView
*wv
, WebKitWebFrame
*frame
,
4375 WebKitNetworkRequest
*request
, char *mime_type
,
4376 WebKitWebPolicyDecision
*decision
, struct tab
*t
)
4379 show_oops(NULL
, "webview_mimetype_cb invalid parameters");
4383 DNPRINTF(XT_D_DOWNLOAD
, "webview_mimetype_cb: tab %d mime %s\n",
4384 t
->tab_id
, mime_type
);
4386 if (run_mimehandler(t
, mime_type
, request
) == 0) {
4387 webkit_web_policy_decision_ignore(decision
);
4392 if (webkit_web_view_can_show_mime_type(wv
, mime_type
) == FALSE
) {
4393 webkit_web_policy_decision_download(decision
);
4401 download_start(struct tab
*t
, struct download
*d
, int flag
)
4403 WebKitNetworkRequest
*req
;
4405 const gchar
*suggested_name
;
4406 gchar
*filename
= NULL
;
4411 if (d
== NULL
|| t
== NULL
) {
4412 show_oops(NULL
, "%s invalid parameters", __func__
);
4416 suggested_name
= webkit_download_get_suggested_filename(d
->download
);
4417 if (suggested_name
== NULL
)
4418 return (FALSE
); /* abort download */
4429 filename
= g_strdup_printf("%d%s", i
, suggested_name
);
4432 uri
= g_strdup_printf("%s\\%s", download_dir
, i
?
4433 filename
: suggested_name
);
4435 uri
= g_strdup_printf("file://%s/%s", download_dir
, i
?
4436 filename
: suggested_name
);
4440 } while (!stat(uri
, &sb
));
4442 } while (!stat(uri
+ strlen("file://"), &sb
)); /* XXX is the + strlen right? */
4445 DNPRINTF(XT_D_DOWNLOAD
, "%s: tab %d filename %s "
4446 "local %s\n", __func__
, t
->tab_id
, filename
, uri
);
4448 /* if we're restarting the download, or starting
4449 * it after doing something else, we need to recreate
4450 * the download request.
4452 if (flag
== XT_DL_RESTART
) {
4453 req
= webkit_network_request_new(webkit_download_get_uri(d
->download
));
4454 webkit_download_cancel(d
->download
);
4455 g_object_unref(d
->download
);
4456 d
->download
= webkit_download_new(req
);
4459 webkit_download_set_destination_uri(d
->download
, uri
);
4461 if (webkit_download_get_status(d
->download
) ==
4462 WEBKIT_DOWNLOAD_STATUS_ERROR
) {
4463 show_oops(t
, "%s: download failed to start", __func__
);
4465 gtk_label_set_text(GTK_LABEL(t
->label
), "Download Failed");
4467 /* connect "download first" mime handler */
4468 g_signal_connect(G_OBJECT(d
->download
), "notify::status",
4469 G_CALLBACK(download_status_changed_cb
), NULL
);
4471 /* get from history */
4472 g_object_ref(d
->download
);
4473 gtk_label_set_text(GTK_LABEL(t
->label
), "Downloading");
4474 show_oops(t
, "Download of '%s' started...",
4475 basename((char *)webkit_download_get_destination_uri(d
->download
)));
4478 if (flag
!= XT_DL_START
)
4479 webkit_download_start(d
->download
);
4481 DNPRINTF(XT_D_DOWNLOAD
, "download status : %d",
4482 webkit_download_get_status(d
->download
));
4484 /* sync other download manager tabs */
4485 update_download_tabs(NULL
);
4497 download_ask_cb(struct tab
*t
, GdkEventKey
*e
, gpointer data
)
4499 struct download
*d
= data
;
4503 t
->mode_cb_data
= NULL
;
4506 e
->keyval
= GDK_Escape
;
4507 return (XT_CB_PASSTHROUGH
);
4510 DPRINTF("download_ask_cb: User pressed %c\n", e
->keyval
);
4511 if (e
->keyval
== 'y' || e
->keyval
== 'Y' || e
->keyval
== GDK_Return
)
4512 /* We need to do a RESTART, because we're not calling from
4513 * webview_download_cb
4515 download_start(t
, d
, XT_DL_RESTART
);
4517 /* for all other keyvals, we just let the download be */
4518 e
->keyval
= GDK_Escape
;
4519 return (XT_CB_HANDLED
);
4523 download_ask(struct tab
*t
, struct download
*d
)
4525 const gchar
*suggested_name
;
4527 suggested_name
= webkit_download_get_suggested_filename(d
->download
);
4528 if (suggested_name
== NULL
)
4529 return (FALSE
); /* abort download */
4531 show_oops(t
, "download file %s [y/n] ?", suggested_name
);
4532 t
->mode_cb
= download_ask_cb
;
4533 t
->mode_cb_data
= d
;
4539 webview_download_cb(WebKitWebView
*wv
, WebKitDownload
*wk_download
,
4542 const gchar
*suggested_name
;
4543 struct download
*download_entry
;
4546 if (wk_download
== NULL
|| t
== NULL
) {
4547 show_oops(NULL
, "%s invalid parameters", __func__
);
4551 suggested_name
= webkit_download_get_suggested_filename(wk_download
);
4552 if (suggested_name
== NULL
)
4553 return (FALSE
); /* abort download */
4555 download_entry
= g_malloc(sizeof(struct download
));
4556 download_entry
->download
= wk_download
;
4557 download_entry
->tab
= t
;
4558 download_entry
->id
= next_download_id
++;
4559 RB_INSERT(download_list
, &downloads
, download_entry
);
4561 if (download_mode
== XT_DM_START
)
4562 ret
= download_start(t
, download_entry
, XT_DL_START
);
4563 else if (download_mode
== XT_DM_ASK
)
4564 ret
= download_ask(t
, download_entry
);
4565 else if (download_mode
== XT_DM_ADD
)
4566 show_oops(t
, "added %s to download manager",
4569 /* sync other download manager tabs */
4570 update_download_tabs(NULL
);
4573 * NOTE: never redirect/render the current tab before this
4574 * function returns. This will cause the download to never start.
4576 return (ret
); /* start download */
4580 webview_hover_cb(WebKitWebView
*wv
, gchar
*title
, gchar
*uri
, struct tab
*t
)
4582 DNPRINTF(XT_D_KEY
, "webview_hover_cb: %s %s\n", title
, uri
);
4585 show_oops(NULL
, "webview_hover_cb");
4590 set_status(t
, uri
, XT_STATUS_LINK
);
4593 set_status(t
, t
->status
, XT_STATUS_NOTHING
);
4598 mark(struct tab
*t
, struct karg
*arg
)
4604 if ((index
= marktoindex(mark
)) == -1)
4607 if (arg
->i
== XT_MARK_SET
)
4608 t
->mark
[index
] = gtk_adjustment_get_value(t
->adjust_v
);
4609 else if (arg
->i
== XT_MARK_GOTO
) {
4610 if (t
->mark
[index
] == XT_INVALID_MARK
) {
4611 show_oops(t
, "mark '%c' does not exist", mark
);
4614 /* XXX t->mark[index] can be bigger than the maximum if ajax or
4615 something changes the document size */
4616 gtk_adjustment_set_value(t
->adjust_v
, t
->mark
[index
]);
4623 marks_clear(struct tab
*t
)
4627 for (i
= 0; i
< LENGTH(t
->mark
); i
++)
4628 t
->mark
[i
] = XT_INVALID_MARK
;
4634 char file
[PATH_MAX
];
4635 char *line
= NULL
, *p
;
4640 snprintf(file
, sizeof file
, "%s" PS
"%s", work_dir
, XT_QMARKS_FILE
);
4641 if ((f
= fopen(file
, "r+")) == NULL
) {
4642 show_oops(NULL
, "Can't open quickmarks file: %s", strerror(errno
));
4646 for (i
= 1; ; i
++) {
4647 if ((line
= fparseln(f
, &linelen
, NULL
, NULL
, 0)) == NULL
)
4649 if (strlen(line
) == 0 || line
[0] == '#') {
4655 p
= strtok(line
, " \t");
4657 if (p
== NULL
|| strlen(p
) != 1 ||
4658 (index
= marktoindex(*p
)) == -1) {
4659 warnx("corrupt quickmarks file, line %d", i
);
4663 p
= strtok(NULL
, " \t");
4664 if (qmarks
[index
] != NULL
)
4665 g_free(qmarks
[index
]);
4666 qmarks
[index
] = g_strdup(p
);
4677 char file
[PATH_MAX
];
4681 snprintf(file
, sizeof file
, "%s" PS
"%s", work_dir
, XT_QMARKS_FILE
);
4682 if ((f
= fopen(file
, "r+")) == NULL
) {
4683 show_oops(NULL
, "Can't open quickmarks file: %s", strerror(errno
));
4687 for (i
= 0; i
< XT_NOMARKS
; i
++)
4688 if (qmarks
[i
] != NULL
)
4689 fprintf(f
, "%c %s\n", indextomark(i
), qmarks
[i
]);
4697 qmark(struct tab
*t
, struct karg
*arg
)
4702 mark
= arg
->s
[strlen(arg
->s
)-1];
4703 index
= marktoindex(mark
);
4709 if (qmarks
[index
] != NULL
) {
4710 g_free(qmarks
[index
]);
4711 qmarks
[index
] = NULL
;
4714 qmarks_load(); /* sync if multiple instances */
4715 qmarks
[index
] = g_strdup(get_uri(t
));
4719 if (qmarks
[index
] != NULL
)
4720 load_uri(t
, qmarks
[index
]);
4722 show_oops(t
, "quickmark \"%c\" does not exist",
4728 if (qmarks
[index
] != NULL
)
4729 create_new_tab(qmarks
[index
], NULL
, 1, -1);
4731 show_oops(t
, "quickmark \"%c\" does not exist",
4742 go_up(struct tab
*t
, struct karg
*args
)
4749 if (args
->i
== XT_GO_UP_ROOT
)
4750 levels
= XT_GO_UP_ROOT
;
4751 else if ((levels
= atoi(args
->s
)) == 0)
4754 uri
= g_strdup(get_uri(t
));
4756 if ((tmp
= strstr(uri
, XT_PROTO_DELIM
)) == NULL
)
4759 tmp
+= strlen(XT_PROTO_DELIM
);
4761 /* if an uri starts with a slash, leave it alone (for file:///) */
4766 p
= strrchr(tmp
, '/');
4780 gototab(struct tab
*t
, struct karg
*args
)
4783 struct karg arg
= {0, NULL
, -1};
4785 tab
= atoi(args
->s
);
4788 arg
.i
= XT_TAB_NEXT
;
4800 gotonexttab(struct tab
*t
, struct karg
*args
)
4802 int count
, n_tabs
, dest
;
4803 struct karg arg
= {0, NULL
, -1};
4805 count
= atoi(args
->s
);
4809 arg
.i
= XT_TAB_NEXT
;
4811 n_tabs
= gtk_notebook_get_n_pages(notebook
);
4812 dest
= gtk_notebook_get_current_page(notebook
);
4814 dest
+= (count
+ 1) % n_tabs
;
4817 arg
.precount
= dest
;
4819 DNPRINTF(XT_D_BUFFERCMD
, "gotonexttab: count: %d - dest : %d \n", count
, dest
);
4827 gotoprevtab(struct tab
*t
, struct karg
*args
)
4830 struct karg arg
= {0, NULL
, -1};
4832 count
= atoi(args
->s
);
4836 arg
.i
= XT_TAB_PREV
;
4837 arg
.precount
= count
;
4839 DNPRINTF(XT_D_BUFFERCMD
, "gotoprevtab: count: %d\n", count
);
4846 zoom_amount(struct tab
*t
, struct karg
*arg
)
4848 struct karg narg
= {0, NULL
, -1};
4850 narg
.i
= atoi(arg
->s
);
4851 resizetab(t
, &narg
);
4857 flip_colon(struct tab
*t
, struct karg
*arg
)
4859 struct karg narg
= {0, NULL
, -1};
4862 if (t
== NULL
|| arg
== NULL
)
4865 p
= strstr(arg
->s
, ":");
4877 /* buffer commands receive the regex that triggered them in arg.s */
4878 char bcmd
[XT_BUFCMD_SZ
];
4882 #define XT_PRE_NO (0)
4883 #define XT_PRE_YES (1)
4884 #define XT_PRE_MAYBE (2)
4886 int (*func
)(struct tab
*, struct karg
*);
4890 { "^[0-9]*gu$", XT_PRE_MAYBE
, "gu", go_up
, 0 },
4891 { "^gU$", XT_PRE_NO
, "gU", go_up
, XT_GO_UP_ROOT
},
4892 { "^gg$", XT_PRE_NO
, "gg", move
, XT_MOVE_TOP
},
4893 { "^gG$", XT_PRE_NO
, "gG", move
, XT_MOVE_BOTTOM
},
4894 { "^[0-9]+%$", XT_PRE_YES
, "%", move
, XT_MOVE_PERCENT
},
4895 { "^zz$", XT_PRE_NO
, "zz", move
, XT_MOVE_CENTER
},
4896 { "^gh$", XT_PRE_NO
, "gh", go_home
, 0 },
4897 { "^m[a-zA-Z0-9]$", XT_PRE_NO
, "m", mark
, XT_MARK_SET
},
4898 { "^['][a-zA-Z0-9]$", XT_PRE_NO
, "'", mark
, XT_MARK_GOTO
},
4899 { "^[0-9]+t$", XT_PRE_YES
, "t", gototab
, 0 },
4900 { "^g0$", XT_PRE_YES
, "g0", gototab
, XT_TAB_FIRST
},
4901 { "^g[$]$", XT_PRE_YES
, "g$", gototab
, XT_TAB_LAST
},
4902 { "^[0-9]*gt$", XT_PRE_YES
, "t", gotonexttab
, 0 },
4903 { "^[0-9]*gT$", XT_PRE_YES
, "T", gotoprevtab
, 0 },
4904 { "^M[a-zA-Z0-9]$", XT_PRE_NO
, "M", qmark
, XT_QMARK_SET
},
4905 { "^go[a-zA-Z0-9]$", XT_PRE_NO
, "go", qmark
, XT_QMARK_OPEN
},
4906 { "^gn[a-zA-Z0-9]$", XT_PRE_NO
, "gn", qmark
, XT_QMARK_TAB
},
4907 { "^ZR$", XT_PRE_NO
, "ZR", restart
, 0 },
4908 { "^ZZ$", XT_PRE_NO
, "ZZ", quit
, 0 },
4909 { "^zi$", XT_PRE_NO
, "zi", resizetab
, XT_ZOOM_IN
},
4910 { "^zo$", XT_PRE_NO
, "zo", resizetab
, XT_ZOOM_OUT
},
4911 { "^z0$", XT_PRE_NO
, "z0", resizetab
, XT_ZOOM_NORMAL
},
4912 { "^[0-9]+Z$", XT_PRE_YES
, "Z", zoom_amount
, 0 },
4913 { "^[0-9]+:$", XT_PRE_YES
, ":", flip_colon
, 0 },
4917 buffercmd_init(void)
4921 for (i
= 0; i
< LENGTH(buffercmds
); i
++)
4922 if (regcomp(&buffercmds
[i
].cregex
, buffercmds
[i
].regex
,
4923 REG_EXTENDED
| REG_NOSUB
))
4924 startpage_add("invalid buffercmd regex %s",
4925 buffercmds
[i
].regex
);
4929 buffercmd_abort(struct tab
*t
)
4936 DNPRINTF(XT_D_BUFFERCMD
, "%s: clearing buffer\n", __func__
);
4938 for (i
= 0; i
< LENGTH(bcmd
); i
++)
4941 cmd_prefix
= 0; /* clear prefix for non-buffer commands */
4942 gtk_entry_set_text(GTK_ENTRY(t
->sbe
.buffercmd
), bcmd
);
4946 buffercmd_execute(struct tab
*t
, struct buffercmd
*cmd
)
4948 struct karg arg
= {0, NULL
, -1};
4951 arg
.s
= g_strdup(bcmd
);
4953 DNPRINTF(XT_D_BUFFERCMD
, "buffercmd_execute: buffer \"%s\" "
4954 "matches regex \"%s\", executing\n", bcmd
, cmd
->regex
);
4964 buffercmd_addkey(struct tab
*t
, guint keyval
)
4967 char s
[XT_BUFCMD_SZ
];
4969 if (gtk_widget_get_visible(GTK_WIDGET(t
->buffers
))) {
4971 return (XT_CB_PASSTHROUGH
);
4974 if (keyval
== GDK_Escape
) {
4976 return (XT_CB_HANDLED
);
4979 /* key with modifier or non-ascii character */
4980 if (!isascii(keyval
)) {
4982 * XXX this looks wrong but fixes some sites like
4983 * http://www.seslisozluk.com/
4984 * that eat a shift or ctrl and end putting default focus in js
4985 * instead of ignoring the keystroke
4986 * so instead of return (XT_CB_PASSTHROUGH); eat the key
4988 return (XT_CB_HANDLED
);
4991 DNPRINTF(XT_D_BUFFERCMD
, "buffercmd_addkey: adding key \"%c\" "
4992 "to buffer \"%s\"\n", keyval
, bcmd
);
4994 for (i
= 0; i
< LENGTH(bcmd
); i
++)
4995 if (bcmd
[i
] == '\0') {
5000 /* buffer full, ignore input */
5001 if (i
>= LENGTH(bcmd
) -1) {
5002 DNPRINTF(XT_D_BUFFERCMD
, "buffercmd_addkey: buffer full\n");
5004 return (XT_CB_HANDLED
);
5007 gtk_entry_set_text(GTK_ENTRY(t
->sbe
.buffercmd
), bcmd
);
5009 /* find exact match */
5010 for (i
= 0; i
< LENGTH(buffercmds
); i
++)
5011 if (regexec(&buffercmds
[i
].cregex
, bcmd
,
5012 (size_t) 0, NULL
, 0) == 0) {
5013 buffercmd_execute(t
, &buffercmds
[i
]);
5017 /* find non exact matches to see if we need to abort ot not */
5018 for (i
= 0, match
= 0; i
< LENGTH(buffercmds
); i
++) {
5019 DNPRINTF(XT_D_BUFFERCMD
, "trying: %s\n", bcmd
);
5022 if (buffercmds
[i
].precount
== XT_PRE_MAYBE
) {
5023 if (isdigit(bcmd
[0])) {
5024 if (sscanf(bcmd
, "%d%s", &c
, s
) == 0)
5028 if (sscanf(bcmd
, "%s", s
) == 0)
5031 } else if (buffercmds
[i
].precount
== XT_PRE_YES
) {
5032 if (sscanf(bcmd
, "%d%s", &c
, s
) == 0)
5035 if (sscanf(bcmd
, "%s", s
) == 0)
5038 if (c
== -1 && buffercmds
[i
].precount
)
5040 if (!strncmp(s
, buffercmds
[i
].cmd
, strlen(s
)))
5043 DNPRINTF(XT_D_BUFFERCMD
, "got[%d] %d <%s>: %d %s\n",
5044 i
, match
, buffercmds
[i
].cmd
, c
, s
);
5047 DNPRINTF(XT_D_BUFFERCMD
, "aborting: %s\n", bcmd
);
5052 return (XT_CB_HANDLED
);
5056 handle_keypress(struct tab
*t
, GdkEventKey
*e
, int entry
)
5058 struct key_binding
*k
;
5060 /* handle keybindings if buffercmd is empty.
5061 if not empty, allow commands like C-n */
5062 if (bcmd
[0] == '\0' || ((e
->state
& (CTRL
| MOD1
)) != 0))
5063 TAILQ_FOREACH(k
, &kbl
, entry
)
5064 if (e
->keyval
== k
->key
5065 && (entry
? k
->use_in_entry
: 1)) {
5066 /* when we are edditing eat ctrl/mod keys */
5067 if (edit_mode
== XT_EM_VI
&&
5068 t
->mode
== XT_MODE_INSERT
&&
5069 (e
->state
& CTRL
|| e
->state
& MOD1
))
5070 return (XT_CB_PASSTHROUGH
);
5073 if ((e
->state
& (CTRL
| MOD1
)) == 0)
5074 return (cmd_execute(t
, k
->cmd
));
5075 } else if ((e
->state
& k
->mask
) == k
->mask
) {
5076 return (cmd_execute(t
, k
->cmd
));
5080 if (!entry
&& ((e
->state
& (CTRL
| MOD1
)) == 0))
5081 return buffercmd_addkey(t
, e
->keyval
);
5083 return (XT_CB_PASSTHROUGH
);
5087 wv_keypress_cb(GtkEntry
*w
, GdkEventKey
*e
, struct tab
*t
)
5091 /* don't use w directly; use t->whatever instead */
5094 show_oops(NULL
, "wv_keypress_cb");
5095 return (XT_CB_PASSTHROUGH
);
5101 return t
->mode_cb(t
, e
, t
->mode_cb_data
);
5103 DNPRINTF(XT_D_KEY
, "wv_keypress_cb: mode %d keyval 0x%x mask "
5104 "0x%x tab %d\n", t
->mode
, e
->keyval
, e
->state
, t
->tab_id
);
5106 /* Hide buffers, if they are visible, with escape. */
5107 if (gtk_widget_get_visible(GTK_WIDGET(t
->buffers
)) &&
5108 CLEAN(e
->state
) == 0 && e
->keyval
== GDK_Escape
) {
5109 gtk_widget_grab_focus(GTK_WIDGET(t
->wv
));
5111 return (XT_CB_HANDLED
);
5114 if (t
->mode
== XT_MODE_HINT
)
5115 return (XT_CB_HANDLED
);
5117 if ((CLEAN(e
->state
) == 0 && e
->keyval
== GDK_Tab
) ||
5118 (CLEAN(e
->state
) == SHFT
&& e
->keyval
== GDK_Tab
))
5119 /* something focussy is about to happen */
5120 return (XT_CB_PASSTHROUGH
);
5122 /* check if we are some sort of text input thing in the dom */
5123 input_check_mode(t
);
5125 if (t
->mode
== XT_MODE_HINT
) {
5126 /* XXX make sure cmd entry is enabled */
5127 return (XT_CB_HANDLED
);
5128 } else if (t
->mode
== XT_MODE_PASSTHROUGH
) {
5129 if (CLEAN(e
->state
) == 0 && e
->keyval
== GDK_Escape
)
5130 t
->mode
= XT_MODE_COMMAND
;
5131 return (XT_CB_PASSTHROUGH
);
5132 } else if (t
->mode
== XT_MODE_COMMAND
) {
5134 snprintf(s
, sizeof s
, "%c", e
->keyval
);
5135 if (CLEAN(e
->state
) == 0 && isdigit(s
[0]))
5136 cmd_prefix
= 10 * cmd_prefix
+ atoi(s
);
5137 return (handle_keypress(t
, e
, 0));
5140 return (handle_keypress(t
, e
, 1));
5144 return (XT_CB_PASSTHROUGH
);
5148 hint_continue(struct tab
*t
)
5150 const gchar
*c
= gtk_entry_get_text(GTK_ENTRY(t
->cmd
));
5152 const gchar
*errstr
= NULL
;
5156 if (!(c
[0] == '.' || c
[0] == ','))
5158 if (strlen(c
) == 1) {
5159 /* XXX should not happen */
5164 if (isdigit(c
[1])) {
5166 i
= strtonum(&c
[1], 1, 4096, &errstr
);
5168 show_oops(t
, "invalid numerical hint %s", &c
[1]);
5171 s
= g_strdup_printf("hints.updateHints(%d);", i
);
5175 /* alphanumeric input */
5176 s
= g_strdup_printf("hints.createHints('%s', '%c');",
5177 &c
[1], c
[0] == '.' ? 'f' : 'F');
5188 search_continue(struct tab
*t
)
5190 const gchar
*c
= gtk_entry_get_text(GTK_ENTRY(t
->cmd
));
5191 gboolean rv
= FALSE
;
5193 if (c
[0] == ':' || c
[0] == '.' || c
[0] == ',')
5195 if (strlen(c
) == 1) {
5196 webkit_web_view_unmark_text_matches(t
->wv
);
5201 t
->search_forward
= TRUE
;
5202 else if (c
[0] == '?')
5203 t
->search_forward
= FALSE
;
5213 search_cb(struct tab
*t
)
5215 const gchar
*c
= gtk_entry_get_text(GTK_ENTRY(t
->cmd
));
5218 if (search_continue(t
) == FALSE
)
5222 if (webkit_web_view_search_text(t
->wv
, &c
[1], FALSE
, t
->search_forward
,
5224 /* not found, mark red */
5225 gdk_color_parse(XT_COLOR_RED
, &color
);
5226 gtk_widget_modify_base(t
->cmd
, GTK_STATE_NORMAL
, &color
);
5227 /* unmark and remove selection */
5228 webkit_web_view_unmark_text_matches(t
->wv
);
5229 /* my kingdom for a way to unselect text in webview */
5231 /* found, highlight all */
5232 webkit_web_view_unmark_text_matches(t
->wv
);
5233 webkit_web_view_mark_text_matches(t
->wv
, &c
[1], FALSE
, 0);
5234 webkit_web_view_set_highlight_text_matches(t
->wv
, TRUE
);
5235 gdk_color_parse(XT_COLOR_WHITE
, &color
);
5236 gtk_widget_modify_base(t
->cmd
, GTK_STATE_NORMAL
, &color
);
5244 cmd_keyrelease_cb(GtkEntry
*w
, GdkEventKey
*e
, struct tab
*t
)
5246 const gchar
*c
= gtk_entry_get_text(w
);
5249 show_oops(NULL
, "cmd_keyrelease_cb invalid parameters");
5250 return (XT_CB_PASSTHROUGH
);
5253 DNPRINTF(XT_D_CMD
, "cmd_keyrelease_cb: keyval 0x%x mask 0x%x tab %d\n",
5254 e
->keyval
, e
->state
, t
->tab_id
);
5257 if (!(e
->keyval
== GDK_Tab
|| e
->keyval
== GDK_ISO_Left_Tab
)) {
5258 if (hint_continue(t
) == FALSE
)
5263 if (search_continue(t
) == FALSE
)
5266 /* if search length is > 4 then no longer play timeout games */
5267 if (strlen(c
) > 4) {
5269 g_source_remove(t
->search_id
);
5276 /* reestablish a new timer if the user types fast */
5278 g_source_remove(t
->search_id
);
5279 t
->search_id
= g_timeout_add(250, (GSourceFunc
)search_cb
, (gpointer
)t
);
5282 return (XT_CB_PASSTHROUGH
);
5286 match_uri(const gchar
*uri
, const gchar
*key
) {
5289 gboolean match
= FALSE
;
5293 if (!strncmp(key
, uri
, len
))
5296 voffset
= strstr(uri
, "/") + 2;
5297 if (!strncmp(key
, voffset
, len
))
5299 else if (g_str_has_prefix(voffset
, "www.")) {
5300 voffset
= voffset
+ strlen("www.");
5301 if (!strncmp(key
, voffset
, len
))
5310 match_session(const gchar
*name
, const gchar
*key
) {
5313 sub
= strcasestr(name
, key
);
5319 cmd_getlist(int id
, char *key
)
5326 if (cmds
[id
].type
& XT_URLARG
) {
5327 RB_FOREACH_REVERSE(h
, history_list
, &hl
)
5328 if (match_uri(h
->uri
, key
)) {
5329 cmd_status
.list
[c
] = (char *)h
->uri
;
5335 } else if (cmds
[id
].type
& XT_SESSARG
) {
5336 TAILQ_FOREACH(s
, &sessions
, entry
)
5337 if (match_session(s
->name
, key
)) {
5338 cmd_status
.list
[c
] = (char *)s
->name
;
5344 } else if (cmds
[id
].type
& XT_SETARG
) {
5345 for (i
= 0; i
< get_settings_size(); i
++)
5346 if (!strncmp(key
, get_setting_name(i
),
5348 cmd_status
.list
[c
++] =
5349 get_setting_name(i
);
5355 dep
= (id
== -1) ? 0 : cmds
[id
].level
+ 1;
5357 for (i
= id
+ 1; i
< LENGTH(cmds
); i
++) {
5358 if (cmds
[i
].level
< dep
)
5360 if (cmds
[i
].level
== dep
&& !strncmp(key
, cmds
[i
].cmd
,
5361 strlen(key
)) && !isdigit(cmds
[i
].cmd
[0]))
5362 cmd_status
.list
[c
++] = cmds
[i
].cmd
;
5370 cmd_getnext(int dir
)
5372 cmd_status
.index
+= dir
;
5374 if (cmd_status
.index
< 0)
5375 cmd_status
.index
= cmd_status
.len
- 1;
5376 else if (cmd_status
.index
>= cmd_status
.len
)
5377 cmd_status
.index
= 0;
5379 return cmd_status
.list
[cmd_status
.index
];
5383 cmd_tokenize(char *s
, char *tokens
[])
5386 char *tok
, *last
= NULL
;
5387 size_t len
= strlen(s
);
5390 blank
= len
== 0 || (len
> 0 && s
[len
- 1] == ' ');
5391 for (tok
= strtok_r(s
, " ", &last
); tok
&& i
< 3;
5392 tok
= strtok_r(NULL
, " ", &last
), i
++)
5402 cmd_complete(struct tab
*t
, char *str
, int dir
)
5404 GtkEntry
*w
= GTK_ENTRY(t
->cmd
);
5405 int i
, j
, levels
, c
= 0, dep
= 0, parent
= -1;
5407 char *tok
, *match
, *s
= g_strdup(str
);
5409 char res
[XT_MAX_URL_LENGTH
+ 32] = ":";
5412 DNPRINTF(XT_D_CMD
, "%s: complete %s\n", __func__
, str
);
5415 for (i
= 0; isdigit(s
[i
]); i
++)
5418 for (; isspace(s
[i
]); i
++)
5423 levels
= cmd_tokenize(s
, tokens
);
5425 for (i
= 0; i
< levels
- 1; i
++) {
5428 for (j
= c
; j
< LENGTH(cmds
); j
++) {
5429 if (cmds
[j
].level
< dep
)
5431 if (cmds
[j
].level
== dep
&& !strncmp(tok
, cmds
[j
].cmd
,
5435 if (strlen(tok
) == strlen(cmds
[j
].cmd
)) {
5442 if (matchcount
== 1) {
5443 strlcat(res
, tok
, sizeof res
);
5444 strlcat(res
, " ", sizeof res
);
5454 if (cmd_status
.index
== -1)
5455 cmd_getlist(parent
, tokens
[i
]);
5457 if (cmd_status
.len
> 0) {
5458 match
= cmd_getnext(dir
);
5459 strlcat(res
, match
, sizeof res
);
5460 gtk_entry_set_text(w
, res
);
5461 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
5468 cmd_execute(struct tab
*t
, char *str
)
5470 struct cmd
*cmd
= NULL
;
5471 char *tok
, *last
= NULL
, *s
= g_strdup(str
), *sc
;
5473 int j
, len
, c
= 0, dep
= 0, matchcount
= 0;
5474 int prefix
= -1, rv
= XT_CB_PASSTHROUGH
;
5475 struct karg arg
= {0, NULL
, -1};
5480 for (j
= 0; j
<3 && isdigit(s
[j
]); j
++)
5486 while (isspace(s
[0]))
5489 if (strlen(s
) > 0 && strlen(prefixstr
) > 0)
5490 prefix
= atoi(prefixstr
);
5494 for (tok
= strtok_r(s
, " ", &last
); tok
;
5495 tok
= strtok_r(NULL
, " ", &last
)) {
5497 for (j
= c
; j
< LENGTH(cmds
); j
++) {
5498 if (cmds
[j
].level
< dep
)
5500 len
= (tok
[strlen(tok
) - 1] == '!') ? strlen(tok
) - 1 :
5502 if (cmds
[j
].level
== dep
&&
5503 !strncmp(tok
, cmds
[j
].cmd
, len
)) {
5507 if (len
== strlen(cmds
[j
].cmd
)) {
5513 if (matchcount
== 1) {
5518 show_oops(t
, "Invalid command: %s", str
);
5524 show_oops(t
, "Empty command");
5530 arg
.precount
= prefix
;
5531 else if (cmd_prefix
> 0)
5532 arg
.precount
= cmd_prefix
;
5534 if (j
> 0 && !(cmd
->type
& XT_PREFIX
) && arg
.precount
> -1) {
5535 show_oops(t
, "No prefix allowed: %s", str
);
5539 arg
.s
= last
? g_strdup(last
) : g_strdup("");
5540 if (cmd
->type
& XT_INTARG
&& last
&& strlen(last
) > 0) {
5541 if (arg
.s
== NULL
) {
5542 show_oops(t
, "Invalid command");
5545 arg
.precount
= atoi(arg
.s
);
5546 if (arg
.precount
<= 0) {
5547 if (arg
.s
[0] == '0')
5548 show_oops(t
, "Zero count");
5550 show_oops(t
, "Trailing characters");
5555 DNPRINTF(XT_D_CMD
, "%s: prefix %d arg %s\n",
5556 __func__
, arg
.precount
, arg
.s
);
5572 entry_key_cb(GtkEntry
*w
, GdkEventKey
*e
, struct tab
*t
)
5575 show_oops(NULL
, "entry_key_cb invalid parameters");
5576 return (XT_CB_PASSTHROUGH
);
5579 DNPRINTF(XT_D_CMD
, "entry_key_cb: keyval 0x%x mask 0x%x tab %d\n",
5580 e
->keyval
, e
->state
, t
->tab_id
);
5584 if (e
->keyval
== GDK_Escape
) {
5585 /* don't use focus_webview(t) because we want to type :cmds */
5586 gtk_widget_grab_focus(GTK_WIDGET(t
->wv
));
5589 return (handle_keypress(t
, e
, 1));
5592 struct command_entry
*
5593 history_prev(struct command_list
*l
, struct command_entry
*at
)
5596 at
= TAILQ_LAST(l
, command_list
);
5598 at
= TAILQ_PREV(at
, command_list
, entry
);
5600 at
= TAILQ_LAST(l
, command_list
);
5606 struct command_entry
*
5607 history_next(struct command_list
*l
, struct command_entry
*at
)
5610 at
= TAILQ_FIRST(l
);
5612 at
= TAILQ_NEXT(at
, entry
);
5614 at
= TAILQ_FIRST(l
);
5621 cmd_keypress_cb(GtkEntry
*w
, GdkEventKey
*e
, struct tab
*t
)
5623 int rv
= XT_CB_HANDLED
;
5624 const gchar
*c
= gtk_entry_get_text(w
);
5628 show_oops(NULL
, "cmd_keypress_cb parameters");
5629 return (XT_CB_PASSTHROUGH
);
5632 DNPRINTF(XT_D_CMD
, "cmd_keypress_cb: keyval 0x%x mask 0x%x tab %d\n",
5633 e
->keyval
, e
->state
, t
->tab_id
);
5637 e
->keyval
= GDK_Escape
;
5638 else if (!(c
[0] == ':' || c
[0] == '/' || c
[0] == '?' ||
5639 c
[0] == '.' || c
[0] == ','))
5640 e
->keyval
= GDK_Escape
;
5642 if (e
->keyval
!= GDK_Tab
&& e
->keyval
!= GDK_Shift_L
&&
5643 e
->keyval
!= GDK_ISO_Left_Tab
)
5644 cmd_status
.index
= -1;
5646 switch (e
->keyval
) {
5649 cmd_complete(t
, (char *)&c
[1], 1);
5650 else if (c
[0] == '.' || c
[0] == ',')
5651 run_script(t
, "hints.focusNextHint();");
5653 case GDK_ISO_Left_Tab
:
5655 cmd_complete(t
, (char *)&c
[1], -1);
5656 else if (c
[0] == '.' || c
[0] == ',')
5657 run_script(t
, "hints.focusPreviousHint();");
5661 if ((search_at
= history_next(&shl
, search_at
))) {
5662 search_at
->line
[0] = c
[0];
5663 gtk_entry_set_text(w
, search_at
->line
);
5664 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
5666 } else if (c
[0] == '/') {
5667 if ((search_at
= history_prev(&chl
, search_at
))) {
5668 search_at
->line
[0] = c
[0];
5669 gtk_entry_set_text(w
, search_at
->line
);
5670 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
5672 } if (c
[0] == ':') {
5673 if ((history_at
= history_prev(&chl
, history_at
))) {
5674 history_at
->line
[0] = c
[0];
5675 gtk_entry_set_text(w
, history_at
->line
);
5676 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
5682 if ((search_at
= history_next(&shl
, search_at
))) {
5683 search_at
->line
[0] = c
[0];
5684 gtk_entry_set_text(w
, search_at
->line
);
5685 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
5687 } else if (c
[0] == '?') {
5688 if ((search_at
= history_prev(&chl
, search_at
))) {
5689 search_at
->line
[0] = c
[0];
5690 gtk_entry_set_text(w
, search_at
->line
);
5691 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
5693 } if (c
[0] == ':') {
5694 if ((history_at
= history_next(&chl
, history_at
))) {
5695 history_at
->line
[0] = c
[0];
5696 gtk_entry_set_text(w
, history_at
->line
);
5697 gtk_editable_set_position(GTK_EDITABLE(w
), -1);
5702 if (!(!strcmp(c
, ":") || !strcmp(c
, "/") || !strcmp(c
, "?") ||
5703 !strcmp(c
, ".") || !strcmp(c
, ","))) {
5704 /* see if we are doing hinting and reset it */
5705 if (c
[0] == '.' || c
[0] == ',') {
5706 /* recreate hints */
5707 s
= g_strdup_printf("hints.createHints('', "
5708 "'%c');", c
[0] == '.' ? 'f' : 'F');
5721 if (c
!= NULL
&& (c
[0] == '/' || c
[0] == '?'))
5722 webkit_web_view_unmark_text_matches(t
->wv
);
5724 /* no need to cancel hints */
5728 rv
= XT_CB_PASSTHROUGH
;
5734 wv_popup_cb(GtkEntry
*entry
, GtkMenu
*menu
, struct tab
*t
)
5736 DNPRINTF(XT_D_CMD
, "wv_popup_cb: tab %d\n", t
->tab_id
);
5740 cmd_popup_cb(GtkEntry
*entry
, GtkMenu
*menu
, struct tab
*t
)
5742 /* popup menu enabled */
5747 cmd_focusout_cb(GtkWidget
*w
, GdkEventFocus
*e
, struct tab
*t
)
5750 show_oops(NULL
, "cmd_focusout_cb invalid parameters");
5751 return (XT_CB_PASSTHROUGH
);
5754 DNPRINTF(XT_D_CMD
, "cmd_focusout_cb: tab %d popup %d\n",
5755 t
->tab_id
, t
->popup
);
5757 /* if popup is enabled don't lose focus */
5760 return (XT_CB_PASSTHROUGH
);
5767 if (show_url
== 0 || t
->focus_wv
)
5770 gtk_widget_grab_focus(GTK_WIDGET(t
->uri_entry
));
5772 return (XT_CB_PASSTHROUGH
);
5776 cmd_activate_cb(GtkEntry
*entry
, struct tab
*t
)
5779 const gchar
*c
= gtk_entry_get_text(entry
);
5782 show_oops(NULL
, "cmd_activate_cb invalid parameters");
5786 DNPRINTF(XT_D_CMD
, "cmd_activate_cb: tab %d %s\n", t
->tab_id
, c
);
5791 else if (!(c
[0] == ':' || c
[0] == '/' || c
[0] == '?' ||
5792 c
[0] == '.' || c
[0] == ','))
5798 if (c
[0] == '/' || c
[0] == '?') {
5799 /* see if there is a timer pending */
5801 g_source_remove(t
->search_id
);
5806 if (t
->search_text
) {
5807 g_free(t
->search_text
);
5808 t
->search_text
= NULL
;
5811 t
->search_text
= g_strdup(s
);
5813 g_free(global_search
);
5814 global_search
= g_strdup(s
);
5815 t
->search_forward
= c
[0] == '/';
5817 history_add(&shl
, search_file
, s
, &search_history_count
);
5818 } else if (c
[0] == '.' || c
[0] == ',') {
5819 run_script(t
, "hints.fire();");
5820 /* XXX history for link following? */
5821 } else if (c
[0] == ':') {
5822 history_add(&chl
, command_file
, s
, &cmd_history_count
);
5823 /* can't call hide_cmd after cmd_execute */
5834 backward_cb(GtkWidget
*w
, struct tab
*t
)
5839 show_oops(NULL
, "backward_cb invalid parameters");
5843 DNPRINTF(XT_D_NAV
, "backward_cb: tab %d\n", t
->tab_id
);
5850 forward_cb(GtkWidget
*w
, struct tab
*t
)
5855 show_oops(NULL
, "forward_cb invalid parameters");
5859 DNPRINTF(XT_D_NAV
, "forward_cb: tab %d\n", t
->tab_id
);
5861 a
.i
= XT_NAV_FORWARD
;
5866 home_cb(GtkWidget
*w
, struct tab
*t
)
5869 show_oops(NULL
, "home_cb invalid parameters");
5873 DNPRINTF(XT_D_NAV
, "home_cb: tab %d\n", t
->tab_id
);
5879 stop_cb(GtkWidget
*w
, struct tab
*t
)
5881 WebKitWebFrame
*frame
;
5884 show_oops(NULL
, "stop_cb invalid parameters");
5888 DNPRINTF(XT_D_NAV
, "stop_cb: tab %d\n", t
->tab_id
);
5890 frame
= webkit_web_view_get_main_frame(t
->wv
);
5891 if (frame
== NULL
) {
5892 show_oops(t
, "stop_cb: no frame");
5896 webkit_web_frame_stop_loading(frame
);
5897 abort_favicon_download(t
);
5901 setup_webkit(struct tab
*t
)
5903 if (is_g_object_setting(G_OBJECT(t
->settings
), "enable-dns-prefetching"))
5904 g_object_set(G_OBJECT(t
->settings
), "enable-dns-prefetching",
5905 FALSE
, (char *)NULL
);
5907 warnx("webkit does not have \"enable-dns-prefetching\" property");
5908 g_object_set(G_OBJECT(t
->settings
),
5909 "user-agent", t
->user_agent
, (char *)NULL
);
5910 g_object_set(G_OBJECT(t
->settings
),
5911 "enable-scripts", enable_scripts
, (char *)NULL
);
5912 g_object_set(G_OBJECT(t
->settings
),
5913 "enable-plugins", enable_plugins
, (char *)NULL
);
5914 g_object_set(G_OBJECT(t
->settings
),
5915 "javascript-can-open-windows-automatically", enable_scripts
,
5917 g_object_set(G_OBJECT(t
->settings
),
5918 "enable-html5-database", FALSE
, (char *)NULL
);
5919 g_object_set(G_OBJECT(t
->settings
),
5920 "enable-html5-local-storage", enable_localstorage
, (char *)NULL
);
5921 g_object_set(G_OBJECT(t
->settings
),
5922 "enable_spell_checking", enable_spell_checking
, (char *)NULL
);
5923 g_object_set(G_OBJECT(t
->settings
),
5924 "spell_checking_languages", spell_check_languages
, (char *)NULL
);
5925 g_object_set(G_OBJECT(t
->settings
),
5926 "enable-developer-extras", TRUE
, (char *)NULL
);
5927 g_object_set(G_OBJECT(t
->wv
),
5928 "full-content-zoom", TRUE
, (char *)NULL
);
5929 g_object_set(G_OBJECT(t
->settings
),
5930 "auto-load-images", auto_load_images
, (char *)NULL
);
5932 webkit_web_view_set_settings(t
->wv
, t
->settings
);
5936 update_statusbar_position(GtkAdjustment
* adjustment
, gpointer data
)
5938 struct tab
*ti
, *t
= NULL
;
5939 gdouble view_size
, value
, max
;
5942 TAILQ_FOREACH(ti
, &tabs
, entry
)
5943 if (ti
->tab_id
== gtk_notebook_get_current_page(notebook
)) {
5951 if (adjustment
== NULL
)
5952 adjustment
= gtk_scrolled_window_get_vadjustment(
5953 GTK_SCROLLED_WINDOW(t
->browser_win
));
5955 view_size
= gtk_adjustment_get_page_size(adjustment
);
5956 value
= gtk_adjustment_get_value(adjustment
);
5957 max
= gtk_adjustment_get_upper(adjustment
) - view_size
;
5960 position
= g_strdup("All");
5961 else if (value
== max
)
5962 position
= g_strdup("Bot");
5963 else if (value
== 0)
5964 position
= g_strdup("Top");
5966 position
= g_strdup_printf("%d%%", (int) ((value
/ max
) * 100));
5968 gtk_entry_set_text(GTK_ENTRY(t
->sbe
.position
), position
);
5975 create_window(const gchar
*name
)
5979 w
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
5980 if (window_maximize
)
5981 gtk_window_maximize(GTK_WINDOW(w
));
5983 gtk_window_set_default_size(GTK_WINDOW(w
), window_width
, window_height
);
5984 gtk_widget_set_name(w
, name
);
5985 gtk_window_set_wmclass(GTK_WINDOW(w
), name
, "XXXTerm");
5991 create_browser(struct tab
*t
)
5995 GtkAdjustment
*adjustment
;
5998 show_oops(NULL
, "create_browser invalid parameters");
6002 t
->sb_h
= GTK_SCROLLBAR(gtk_hscrollbar_new(NULL
));
6003 t
->sb_v
= GTK_SCROLLBAR(gtk_vscrollbar_new(NULL
));
6004 t
->adjust_h
= gtk_range_get_adjustment(GTK_RANGE(t
->sb_h
));
6005 t
->adjust_v
= gtk_range_get_adjustment(GTK_RANGE(t
->sb_v
));
6007 w
= gtk_scrolled_window_new(t
->adjust_h
, t
->adjust_v
);
6008 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w
),
6009 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
6011 t
->wv
= WEBKIT_WEB_VIEW(webkit_web_view_new());
6012 gtk_container_add(GTK_CONTAINER(w
), GTK_WIDGET(t
->wv
));
6015 t
->settings
= webkit_web_settings_new();
6017 g_object_set(t
->settings
, "default-encoding", encoding
, (char *)NULL
);
6019 if (user_agent
== NULL
) {
6020 g_object_get(G_OBJECT(t
->settings
), "user-agent", &strval
,
6022 t
->user_agent
= g_strdup_printf("%s %s+", strval
, version
);
6025 t
->user_agent
= g_strdup(user_agent
->value
);
6027 t
->stylesheet
= g_strdup_printf("file://%s/style.css", resource_dir
);
6028 t
->load_images
= auto_load_images
;
6031 gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(w
));
6032 g_signal_connect(G_OBJECT(adjustment
), "value-changed",
6033 G_CALLBACK(update_statusbar_position
), NULL
);
6042 create_kiosk_toolbar(struct tab
*t
)
6044 GtkWidget
*toolbar
= NULL
, *b
;
6046 b
= gtk_hbox_new(FALSE
, 0);
6048 gtk_container_set_border_width(GTK_CONTAINER(toolbar
), 0);
6050 /* backward button */
6051 t
->backward
= create_button("Back", GTK_STOCK_GO_BACK
, 0);
6052 gtk_widget_set_sensitive(t
->backward
, FALSE
);
6053 g_signal_connect(G_OBJECT(t
->backward
), "clicked",
6054 G_CALLBACK(backward_cb
), t
);
6055 gtk_box_pack_start(GTK_BOX(b
), t
->backward
, TRUE
, TRUE
, 0);
6057 /* forward button */
6058 t
->forward
= create_button("Forward", GTK_STOCK_GO_FORWARD
, 0);
6059 gtk_widget_set_sensitive(t
->forward
, FALSE
);
6060 g_signal_connect(G_OBJECT(t
->forward
), "clicked",
6061 G_CALLBACK(forward_cb
), t
);
6062 gtk_box_pack_start(GTK_BOX(b
), t
->forward
, TRUE
, TRUE
, 0);
6065 t
->gohome
= create_button("Home", GTK_STOCK_HOME
, 0);
6066 gtk_widget_set_sensitive(t
->gohome
, true);
6067 g_signal_connect(G_OBJECT(t
->gohome
), "clicked",
6068 G_CALLBACK(home_cb
), t
);
6069 gtk_box_pack_start(GTK_BOX(b
), t
->gohome
, TRUE
, TRUE
, 0);
6071 /* create widgets but don't use them */
6072 t
->uri_entry
= gtk_entry_new();
6073 t
->stop
= create_button("Stop", GTK_STOCK_STOP
, 0);
6074 t
->js_toggle
= create_button("JS-Toggle", enable_scripts
?
6075 GTK_STOCK_MEDIA_PLAY
: GTK_STOCK_MEDIA_PAUSE
, 0);
6081 create_toolbar(struct tab
*t
)
6083 GtkWidget
*toolbar
= NULL
, *b
, *eb1
;
6085 b
= gtk_hbox_new(FALSE
, 0);
6087 gtk_container_set_border_width(GTK_CONTAINER(toolbar
), 0);
6089 /* backward button */
6090 t
->backward
= create_button("Back", GTK_STOCK_GO_BACK
, 0);
6091 gtk_widget_set_sensitive(t
->backward
, FALSE
);
6092 g_signal_connect(G_OBJECT(t
->backward
), "clicked",
6093 G_CALLBACK(backward_cb
), t
);
6094 gtk_box_pack_start(GTK_BOX(b
), t
->backward
, FALSE
, FALSE
, 0);
6096 /* forward button */
6097 t
->forward
= create_button("Forward",GTK_STOCK_GO_FORWARD
, 0);
6098 gtk_widget_set_sensitive(t
->forward
, FALSE
);
6099 g_signal_connect(G_OBJECT(t
->forward
), "clicked",
6100 G_CALLBACK(forward_cb
), t
);
6101 gtk_box_pack_start(GTK_BOX(b
), t
->forward
, FALSE
,
6105 t
->stop
= create_button("Stop", GTK_STOCK_STOP
, 0);
6106 gtk_widget_set_sensitive(t
->stop
, FALSE
);
6107 g_signal_connect(G_OBJECT(t
->stop
), "clicked",
6108 G_CALLBACK(stop_cb
), t
);
6109 gtk_box_pack_start(GTK_BOX(b
), t
->stop
, FALSE
,
6113 t
->js_toggle
= create_button("JS-Toggle", enable_scripts
?
6114 GTK_STOCK_MEDIA_PLAY
: GTK_STOCK_MEDIA_PAUSE
, 0);
6115 gtk_widget_set_sensitive(t
->js_toggle
, TRUE
);
6116 g_signal_connect(G_OBJECT(t
->js_toggle
), "clicked",
6117 G_CALLBACK(js_toggle_cb
), t
);
6118 gtk_box_pack_start(GTK_BOX(b
), t
->js_toggle
, FALSE
, FALSE
, 0);
6120 t
->uri_entry
= gtk_entry_new();
6121 g_signal_connect(G_OBJECT(t
->uri_entry
), "activate",
6122 G_CALLBACK(activate_uri_entry_cb
), t
);
6123 g_signal_connect(G_OBJECT(t
->uri_entry
), "key-press-event",
6124 G_CALLBACK(entry_key_cb
), t
);
6126 eb1
= gtk_hbox_new(FALSE
, 0);
6127 gtk_container_set_border_width(GTK_CONTAINER(eb1
), 1);
6128 gtk_box_pack_start(GTK_BOX(eb1
), t
->uri_entry
, TRUE
, TRUE
, 0);
6129 gtk_box_pack_start(GTK_BOX(b
), eb1
, TRUE
, TRUE
, 0);
6132 if (search_string
) {
6134 t
->search_entry
= gtk_entry_new();
6135 gtk_entry_set_width_chars(GTK_ENTRY(t
->search_entry
), 30);
6136 g_signal_connect(G_OBJECT(t
->search_entry
), "activate",
6137 G_CALLBACK(activate_search_entry_cb
), t
);
6138 g_signal_connect(G_OBJECT(t
->search_entry
), "key-press-event",
6139 G_CALLBACK(entry_key_cb
), t
);
6140 gtk_widget_set_size_request(t
->search_entry
, -1, -1);
6141 eb2
= gtk_hbox_new(FALSE
, 0);
6142 gtk_container_set_border_width(GTK_CONTAINER(eb2
), 1);
6143 gtk_box_pack_start(GTK_BOX(eb2
), t
->search_entry
, TRUE
, TRUE
,
6145 gtk_box_pack_start(GTK_BOX(b
), eb2
, FALSE
, FALSE
, 0);
6152 create_buffers(struct tab
*t
)
6154 GtkCellRenderer
*renderer
;
6157 view
= gtk_tree_view_new();
6159 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view
), FALSE
);
6161 renderer
= gtk_cell_renderer_text_new();
6162 gtk_tree_view_insert_column_with_attributes
6163 (GTK_TREE_VIEW(view
), -1, "Id", renderer
, "text", COL_ID
, (char *)NULL
);
6165 renderer
= gtk_cell_renderer_pixbuf_new();
6166 gtk_tree_view_insert_column_with_attributes
6167 (GTK_TREE_VIEW(view
), -1, "Favicon", renderer
, "pixbuf", COL_FAVICON
,
6170 renderer
= gtk_cell_renderer_text_new();
6171 gtk_tree_view_insert_column_with_attributes
6172 (GTK_TREE_VIEW(view
), -1, "Title", renderer
, "text", COL_TITLE
,
6175 gtk_tree_view_set_model
6176 (GTK_TREE_VIEW(view
), GTK_TREE_MODEL(buffers_store
));
6182 row_activated_cb(GtkTreeView
*view
, GtkTreePath
*path
,
6183 GtkTreeViewColumn
*col
, struct tab
*t
)
6188 gtk_widget_grab_focus(GTK_WIDGET(t
->wv
));
6190 if (gtk_tree_model_get_iter(GTK_TREE_MODEL(buffers_store
), &iter
,
6193 (GTK_TREE_MODEL(buffers_store
), &iter
, COL_ID
, &id
, -1);
6194 set_current_tab(id
- 1);
6200 /* after tab reordering/creation/removal */
6207 TAILQ_FOREACH(t
, &tabs
, entry
) {
6208 t
->tab_id
= gtk_notebook_page_num(notebook
, t
->vbox
);
6209 if (t
->tab_id
> maxid
)
6212 gtk_widget_show(t
->tab_elems
.sep
);
6215 TAILQ_FOREACH(t
, &tabs
, entry
) {
6216 if (t
->tab_id
== maxid
) {
6217 gtk_widget_hide(t
->tab_elems
.sep
);
6223 /* after active tab change */
6225 recolor_compact_tabs(void)
6231 gdk_color_parse(XT_COLOR_CT_INACTIVE
, &color
);
6232 TAILQ_FOREACH(t
, &tabs
, entry
)
6233 gtk_widget_modify_fg(t
->tab_elems
.label
, GTK_STATE_NORMAL
,
6236 curid
= gtk_notebook_get_current_page(notebook
);
6237 TAILQ_FOREACH(t
, &tabs
, entry
)
6238 if (t
->tab_id
== curid
) {
6239 gdk_color_parse(XT_COLOR_CT_ACTIVE
, &color
);
6240 gtk_widget_modify_fg(t
->tab_elems
.label
,
6241 GTK_STATE_NORMAL
, &color
);
6247 set_current_tab(int page_num
)
6249 buffercmd_abort(get_current_tab());
6250 gtk_notebook_set_current_page(notebook
, page_num
);
6251 recolor_compact_tabs();
6255 undo_close_tab_save(struct tab
*t
)
6259 struct undo
*u1
, *u2
;
6261 WebKitWebHistoryItem
*item
;
6263 if ((uri
= get_uri(t
)) == NULL
)
6266 u1
= g_malloc0(sizeof(struct undo
));
6267 u1
->uri
= g_strdup(uri
);
6269 t
->bfl
= webkit_web_view_get_back_forward_list(t
->wv
);
6271 m
= webkit_web_back_forward_list_get_forward_length(t
->bfl
);
6272 n
= webkit_web_back_forward_list_get_back_length(t
->bfl
);
6275 /* forward history */
6276 items
= webkit_web_back_forward_list_get_forward_list_with_limit(t
->bfl
, m
);
6280 u1
->history
= g_list_prepend(u1
->history
,
6281 webkit_web_history_item_copy(item
));
6282 items
= g_list_next(items
);
6287 item
= webkit_web_back_forward_list_get_current_item(t
->bfl
);
6288 u1
->history
= g_list_prepend(u1
->history
,
6289 webkit_web_history_item_copy(item
));
6293 items
= webkit_web_back_forward_list_get_back_list_with_limit(t
->bfl
, n
);
6297 u1
->history
= g_list_prepend(u1
->history
,
6298 webkit_web_history_item_copy(item
));
6299 items
= g_list_next(items
);
6302 TAILQ_INSERT_HEAD(&undos
, u1
, entry
);
6304 if (undo_count
> XT_MAX_UNDO_CLOSE_TAB
) {
6305 u2
= TAILQ_LAST(&undos
, undo_tailq
);
6306 TAILQ_REMOVE(&undos
, u2
, entry
);
6308 g_list_free(u2
->history
);
6317 delete_tab(struct tab
*t
)
6321 DNPRINTF(XT_D_TAB
, "delete_tab: %p\n", t
);
6327 * no need to join thread here because it won't access t on completion
6330 TAILQ_REMOVE(&tabs
, t
, entry
);
6333 /* Halt all webkit activity. */
6334 abort_favicon_download(t
);
6335 webkit_web_view_stop_loading(t
->wv
);
6337 /* Save the tab, so we can undo the close. */
6338 undo_close_tab_save(t
);
6342 g_source_remove(t
->search_id
);
6345 bzero(&a
, sizeof a
);
6347 inspector_cmd(t
, &a
);
6349 if (browser_mode
== XT_BM_KIOSK
) {
6350 gtk_widget_destroy(t
->uri_entry
);
6351 gtk_widget_destroy(t
->stop
);
6352 gtk_widget_destroy(t
->js_toggle
);
6355 gtk_widget_destroy(t
->tab_elems
.eventbox
);
6356 gtk_widget_destroy(t
->vbox
);
6358 g_free(t
->user_agent
);
6359 g_free(t
->stylesheet
);
6364 if (TAILQ_EMPTY(&tabs
)) {
6365 if (browser_mode
== XT_BM_KIOSK
)
6366 create_new_tab(home
, NULL
, 1, -1);
6368 create_new_tab(NULL
, NULL
, 1, -1);
6371 /* recreate session */
6372 if (session_autosave
) {
6373 bzero(&a
, sizeof a
);
6375 save_tabs(NULL
, &a
);
6379 recolor_compact_tabs();
6383 update_statusbar_zoom(struct tab
*t
)
6386 char s
[16] = { '\0' };
6388 g_object_get(G_OBJECT(t
->wv
), "zoom-level", &zoom
, (char *)NULL
);
6389 if ((zoom
<= 0.99 || zoom
>= 1.01))
6390 snprintf(s
, sizeof s
, "%d%%", (int)(zoom
* 100));
6391 gtk_entry_set_text(GTK_ENTRY(t
->sbe
.zoom
), s
);
6395 setzoom_webkit(struct tab
*t
, int adjust
)
6397 #define XT_ZOOMPERCENT 0.04
6402 show_oops(NULL
, "setzoom_webkit invalid parameters");
6406 g_object_get(G_OBJECT(t
->wv
), "zoom-level", &zoom
, (char *)NULL
);
6407 if (adjust
== XT_ZOOM_IN
)
6408 zoom
+= XT_ZOOMPERCENT
;
6409 else if (adjust
== XT_ZOOM_OUT
)
6410 zoom
-= XT_ZOOMPERCENT
;
6411 else if (adjust
> 0)
6412 zoom
= default_zoom_level
+ adjust
/ 100.0 - 1.0;
6414 show_oops(t
, "setzoom_webkit invalid zoom value");
6418 if (zoom
< XT_ZOOMPERCENT
)
6419 zoom
= XT_ZOOMPERCENT
;
6420 g_object_set(G_OBJECT(t
->wv
), "zoom-level", zoom
, (char *)NULL
);
6421 update_statusbar_zoom(t
);
6425 tab_clicked_cb(GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
6427 struct tab
*t
= (struct tab
*) data
;
6429 DNPRINTF(XT_D_TAB
, "tab_clicked_cb: tab: %d\n", t
->tab_id
);
6431 switch (event
->button
) {
6433 set_current_tab(t
->tab_id
);
6444 append_tab(struct tab
*t
)
6449 TAILQ_INSERT_TAIL(&tabs
, t
, entry
);
6450 t
->tab_id
= gtk_notebook_append_page(notebook
, t
->vbox
, t
->tab_content
);
6454 create_sbe(int width
)
6458 sbe
= gtk_entry_new();
6459 gtk_entry_set_inner_border(GTK_ENTRY(sbe
), NULL
);
6460 gtk_entry_set_has_frame(GTK_ENTRY(sbe
), FALSE
);
6461 gtk_widget_set_can_focus(GTK_WIDGET(sbe
), FALSE
);
6462 gtk_widget_modify_font(GTK_WIDGET(sbe
), statusbar_font
);
6463 gtk_entry_set_alignment(GTK_ENTRY(sbe
), 1.0);
6464 gtk_widget_set_size_request(sbe
, width
, -1);
6470 create_new_tab(char *title
, struct undo
*u
, int focus
, int position
)
6475 WebKitWebHistoryItem
*item
;
6479 int sbe_p
= 0, sbe_b
= 0,
6482 DNPRINTF(XT_D_TAB
, "create_new_tab: title %s focus %d\n", title
, focus
);
6484 if (tabless
&& !TAILQ_EMPTY(&tabs
)) {
6485 DNPRINTF(XT_D_TAB
, "create_new_tab: new tab rejected\n");
6489 t
= g_malloc0(sizeof *t
);
6491 if (title
== NULL
) {
6492 title
= "(untitled)";
6496 t
->vbox
= gtk_vbox_new(FALSE
, 0);
6498 /* label + button for tab */
6499 b
= gtk_hbox_new(FALSE
, 0);
6502 #if GTK_CHECK_VERSION(2, 20, 0)
6503 t
->spinner
= gtk_spinner_new();
6505 t
->label
= gtk_label_new(title
);
6506 bb
= create_button("Close", GTK_STOCK_CLOSE
, 1);
6507 gtk_widget_set_size_request(t
->label
, 100, 0);
6508 gtk_label_set_max_width_chars(GTK_LABEL(t
->label
), 20);
6509 gtk_label_set_ellipsize(GTK_LABEL(t
->label
), PANGO_ELLIPSIZE_END
);
6510 gtk_widget_set_size_request(b
, 130, 0);
6512 gtk_box_pack_start(GTK_BOX(b
), bb
, FALSE
, FALSE
, 0);
6513 gtk_box_pack_start(GTK_BOX(b
), t
->label
, FALSE
, FALSE
, 0);
6514 #if GTK_CHECK_VERSION(2, 20, 0)
6515 gtk_box_pack_start(GTK_BOX(b
), t
->spinner
, FALSE
, FALSE
, 0);
6519 if (browser_mode
== XT_BM_KIOSK
) {
6520 t
->toolbar
= create_kiosk_toolbar(t
);
6521 gtk_box_pack_start(GTK_BOX(t
->vbox
), t
->toolbar
, FALSE
, FALSE
,
6524 t
->toolbar
= create_toolbar(t
);
6526 gtk_box_pack_start(GTK_BOX(t
->vbox
), t
->toolbar
, FALSE
,
6534 t
->browser_win
= create_browser(t
);
6535 gtk_box_pack_start(GTK_BOX(t
->vbox
), t
->browser_win
, TRUE
, TRUE
, 0);
6537 /* oops message for user feedback */
6538 t
->oops
= gtk_entry_new();
6539 gtk_entry_set_inner_border(GTK_ENTRY(t
->oops
), NULL
);
6540 gtk_entry_set_has_frame(GTK_ENTRY(t
->oops
), FALSE
);
6541 gtk_widget_set_can_focus(GTK_WIDGET(t
->oops
), FALSE
);
6542 gdk_color_parse(XT_COLOR_RED
, &color
);
6543 gtk_widget_modify_base(t
->oops
, GTK_STATE_NORMAL
, &color
);
6544 gtk_box_pack_end(GTK_BOX(t
->vbox
), t
->oops
, FALSE
, FALSE
, 0);
6545 gtk_widget_modify_font(GTK_WIDGET(t
->oops
), oops_font
);
6548 t
->cmd
= gtk_entry_new();
6549 gtk_entry_set_inner_border(GTK_ENTRY(t
->cmd
), NULL
);
6550 gtk_entry_set_has_frame(GTK_ENTRY(t
->cmd
), FALSE
);
6551 gtk_box_pack_end(GTK_BOX(t
->vbox
), t
->cmd
, FALSE
, FALSE
, 0);
6552 gtk_widget_modify_font(GTK_WIDGET(t
->cmd
), cmd_font
);
6555 t
->statusbar_box
= gtk_hbox_new(FALSE
, 0);
6557 t
->sbe
.statusbar
= gtk_entry_new();
6558 gtk_entry_set_inner_border(GTK_ENTRY(t
->sbe
.statusbar
), NULL
);
6559 gtk_entry_set_has_frame(GTK_ENTRY(t
->sbe
.statusbar
), FALSE
);
6560 gtk_widget_set_can_focus(GTK_WIDGET(t
->sbe
.statusbar
), FALSE
);
6561 gtk_widget_modify_font(GTK_WIDGET(t
->sbe
.statusbar
), statusbar_font
);
6563 /* create these widgets only if specified in statusbar_elems */
6565 t
->sbe
.position
= create_sbe(40);
6566 t
->sbe
.zoom
= create_sbe(40);
6567 t
->sbe
.buffercmd
= create_sbe(60);
6569 statusbar_modify_attr(t
, XT_COLOR_WHITE
, XT_COLOR_BLACK
);
6571 gtk_box_pack_start(GTK_BOX(t
->statusbar_box
), t
->sbe
.statusbar
, TRUE
,
6574 /* gtk widgets cannot be added to a box twice. sbe_* variables
6575 make sure of this */
6576 for (p
= statusbar_elems
; *p
!= '\0'; p
++) {
6580 GtkWidget
*sep
= gtk_vseparator_new();
6582 gdk_color_parse(XT_COLOR_SB_SEPARATOR
, &color
);
6583 gtk_widget_modify_bg(sep
, GTK_STATE_NORMAL
, &color
);
6584 gtk_box_pack_start(GTK_BOX(t
->statusbar_box
), sep
,
6585 FALSE
, FALSE
, FALSE
);
6590 warnx("flag \"%c\" specified more than "
6591 "once in statusbar_elems\n", *p
);
6595 gtk_box_pack_start(GTK_BOX(t
->statusbar_box
),
6596 t
->sbe
.position
, FALSE
, FALSE
, FALSE
);
6600 warnx("flag \"%c\" specified more than "
6601 "once in statusbar_elems\n", *p
);
6605 gtk_box_pack_start(GTK_BOX(t
->statusbar_box
),
6606 t
->sbe
.buffercmd
, FALSE
, FALSE
, FALSE
);
6610 warnx("flag \"%c\" specified more than "
6611 "once in statusbar_elems\n", *p
);
6615 gtk_box_pack_start(GTK_BOX(t
->statusbar_box
),
6616 t
->sbe
.zoom
, FALSE
, FALSE
, FALSE
);
6619 warnx("illegal flag \"%c\" in statusbar_elems\n", *p
);
6624 gtk_box_pack_end(GTK_BOX(t
->vbox
), t
->statusbar_box
, FALSE
, FALSE
, 0);
6627 t
->buffers
= create_buffers(t
);
6628 gtk_box_pack_end(GTK_BOX(t
->vbox
), t
->buffers
, FALSE
, FALSE
, 0);
6630 /* xtp meaning is normal by default */
6631 t
->xtp_meaning
= XT_XTP_TAB_MEANING_NORMAL
;
6633 /* set empty favicon */
6634 xt_icon_from_name(t
, "text-html");
6636 /* and show it all */
6637 gtk_widget_show_all(b
);
6638 gtk_widget_show_all(t
->vbox
);
6640 /* compact tab bar */
6641 t
->tab_elems
.label
= gtk_label_new(title
);
6642 t
->tab_elems
.favicon
= gtk_image_new();
6643 gtk_label_set_width_chars(GTK_LABEL(t
->tab_elems
.label
), 1.0);
6644 gtk_misc_set_alignment(GTK_MISC(t
->tab_elems
.label
), 0.0, 0.0);
6645 gtk_misc_set_padding(GTK_MISC(t
->tab_elems
.label
), 4.0, 4.0);
6646 gtk_widget_modify_font(GTK_WIDGET(t
->tab_elems
.label
), tabbar_font
);
6648 t
->tab_elems
.eventbox
= gtk_event_box_new();
6649 t
->tab_elems
.box
= gtk_hbox_new(FALSE
, 0);
6650 t
->tab_elems
.sep
= gtk_vseparator_new();
6652 gdk_color_parse(XT_COLOR_CT_BACKGROUND
, &color
);
6653 gtk_widget_modify_bg(t
->tab_elems
.eventbox
, GTK_STATE_NORMAL
, &color
);
6654 gdk_color_parse(XT_COLOR_CT_INACTIVE
, &color
);
6655 gtk_widget_modify_fg(t
->tab_elems
.label
, GTK_STATE_NORMAL
, &color
);
6656 gdk_color_parse(XT_COLOR_CT_SEPARATOR
, &color
);
6657 gtk_widget_modify_bg(t
->tab_elems
.sep
, GTK_STATE_NORMAL
, &color
);
6659 gtk_box_pack_start(GTK_BOX(t
->tab_elems
.box
), t
->tab_elems
.favicon
, FALSE
,
6661 gtk_box_pack_start(GTK_BOX(t
->tab_elems
.box
), t
->tab_elems
.label
, TRUE
,
6663 gtk_box_pack_start(GTK_BOX(t
->tab_elems
.box
), t
->tab_elems
.sep
, FALSE
,
6665 gtk_container_add(GTK_CONTAINER(t
->tab_elems
.eventbox
),
6668 gtk_box_pack_start(GTK_BOX(tab_bar
), t
->tab_elems
.eventbox
, TRUE
,
6670 gtk_widget_show_all(t
->tab_elems
.eventbox
);
6672 if (append_next
== 0 || gtk_notebook_get_n_pages(notebook
) == 0)
6675 id
= position
>= 0 ? position
:
6676 gtk_notebook_get_current_page(notebook
) + 1;
6677 if (id
> gtk_notebook_get_n_pages(notebook
))
6680 TAILQ_INSERT_TAIL(&tabs
, t
, entry
);
6681 gtk_notebook_insert_page(notebook
, t
->vbox
, b
, id
);
6682 gtk_box_reorder_child(GTK_BOX(tab_bar
),
6683 t
->tab_elems
.eventbox
, id
);
6688 #if GTK_CHECK_VERSION(2, 20, 0)
6689 /* turn spinner off if we are a new tab without uri */
6691 gtk_spinner_stop(GTK_SPINNER(t
->spinner
));
6692 gtk_widget_hide(t
->spinner
);
6695 /* make notebook tabs reorderable */
6696 gtk_notebook_set_tab_reorderable(notebook
, t
->vbox
, TRUE
);
6698 /* compact tabs clickable */
6699 g_signal_connect(G_OBJECT(t
->tab_elems
.eventbox
),
6700 "button_press_event", G_CALLBACK(tab_clicked_cb
), t
);
6702 g_object_connect(G_OBJECT(t
->cmd
),
6703 "signal::key-press-event", G_CALLBACK(cmd_keypress_cb
), t
,
6704 "signal::key-release-event", G_CALLBACK(cmd_keyrelease_cb
), t
,
6705 "signal::focus-out-event", G_CALLBACK(cmd_focusout_cb
), t
,
6706 "signal::activate", G_CALLBACK(cmd_activate_cb
), t
,
6707 "signal::populate-popup", G_CALLBACK(cmd_popup_cb
), t
,
6710 /* reuse wv_button_cb to hide oops */
6711 g_object_connect(G_OBJECT(t
->oops
),
6712 "signal::button_press_event", G_CALLBACK(wv_button_cb
), t
,
6715 g_signal_connect(t
->buffers
,
6716 "row-activated", G_CALLBACK(row_activated_cb
), t
);
6717 g_object_connect(G_OBJECT(t
->buffers
),
6718 "signal::key-press-event", G_CALLBACK(wv_keypress_cb
), t
, (char *)NULL
);
6720 g_object_connect(G_OBJECT(t
->wv
),
6721 "signal::key-press-event", G_CALLBACK(wv_keypress_cb
), t
,
6722 "signal::hovering-over-link", G_CALLBACK(webview_hover_cb
), t
,
6723 "signal::download-requested", G_CALLBACK(webview_download_cb
), t
,
6724 "signal::mime-type-policy-decision-requested", G_CALLBACK(webview_mimetype_cb
), t
,
6725 "signal::navigation-policy-decision-requested", G_CALLBACK(webview_npd_cb
), t
,
6726 "signal::new-window-policy-decision-requested", G_CALLBACK(webview_npd_cb
), t
,
6727 "signal::create-web-view", G_CALLBACK(webview_cwv_cb
), t
,
6728 "signal::close-web-view", G_CALLBACK(webview_closewv_cb
), t
,
6729 "signal::event", G_CALLBACK(webview_event_cb
), t
,
6730 "signal::load-finished", G_CALLBACK(webview_load_finished_cb
), t
,
6731 "signal::load-progress-changed", G_CALLBACK(webview_progress_changed_cb
), t
,
6732 "signal::icon-loaded", G_CALLBACK(notify_icon_loaded_cb
), t
,
6733 "signal::button_press_event", G_CALLBACK(wv_button_cb
), t
,
6734 "signal::button_release_event", G_CALLBACK(wv_release_button_cb
), t
,
6735 "signal::populate-popup", G_CALLBACK(wv_popup_cb
), t
,
6737 g_signal_connect(t
->wv
,
6738 "notify::load-status", G_CALLBACK(notify_load_status_cb
), t
);
6739 g_signal_connect(t
->wv
,
6740 "notify::title", G_CALLBACK(notify_title_cb
), t
);
6742 /* hijack the unused keys as if we were the browser */
6743 //g_object_connect(G_OBJECT(t->toolbar),
6744 // "signal-after::key-press-event", G_CALLBACK(wv_keypress_after_cb), t,
6747 g_signal_connect(G_OBJECT(bb
), "button_press_event",
6748 G_CALLBACK(tab_close_cb
), t
);
6751 t
->bfl
= webkit_web_view_get_back_forward_list(t
->wv
);
6752 /* restore the tab's history */
6753 if (u
&& u
->history
) {
6757 webkit_web_back_forward_list_add_item(t
->bfl
, item
);
6758 items
= g_list_next(items
);
6761 item
= g_list_nth_data(u
->history
, u
->back
);
6763 webkit_web_view_go_to_back_forward_item(t
->wv
, item
);
6766 g_list_free(u
->history
);
6768 webkit_web_back_forward_list_clear(t
->bfl
);
6774 url_set_visibility();
6775 statusbar_set_visibility();
6778 set_current_tab(t
->tab_id
);
6779 DNPRINTF(XT_D_TAB
, "create_new_tab: going to tab: %d\n",
6783 gtk_entry_set_text(GTK_ENTRY(t
->uri_entry
), title
);
6787 gtk_widget_grab_focus(GTK_WIDGET(t
->uri_entry
));
6794 if (userstyle_global
)
6797 recolor_compact_tabs();
6798 setzoom_webkit(t
, XT_ZOOM_NORMAL
);
6803 notebook_switchpage_cb(GtkNotebook
*nb
, GtkWidget
*nbp
, guint pn
,
6809 DNPRINTF(XT_D_TAB
, "notebook_switchpage_cb: tab: %d\n", pn
);
6811 if (gtk_notebook_get_current_page(notebook
) == -1)
6814 TAILQ_FOREACH(t
, &tabs
, entry
) {
6815 if (t
->tab_id
== pn
) {
6816 DNPRINTF(XT_D_TAB
, "notebook_switchpage_cb: going to "
6819 uri
= get_title(t
, TRUE
);
6820 gtk_window_set_title(GTK_WINDOW(main_window
), uri
);
6826 /* can't use focus_webview here */
6827 gtk_widget_grab_focus(GTK_WIDGET(t
->wv
));
6834 notebook_pagereordered_cb(GtkNotebook
*nb
, GtkWidget
*nbp
, guint pn
,
6837 struct tab
*t
= NULL
, *tt
;
6841 TAILQ_FOREACH(tt
, &tabs
, entry
)
6842 if (tt
->tab_id
== pn
) {
6848 DNPRINTF(XT_D_TAB
, "page_reordered_cb: tab: %d\n", t
->tab_id
);
6850 gtk_box_reorder_child(GTK_BOX(tab_bar
), t
->tab_elems
.eventbox
,
6855 menuitem_response(struct tab
*t
)
6857 gtk_notebook_set_current_page(notebook
, t
->tab_id
);
6861 arrow_cb(GtkWidget
*w
, GdkEventButton
*event
, gpointer user_data
)
6863 GtkWidget
*menu
, *menu_items
;
6864 GdkEventButton
*bevent
;
6868 if (event
->type
== GDK_BUTTON_PRESS
) {
6869 bevent
= (GdkEventButton
*) event
;
6870 menu
= gtk_menu_new();
6872 TAILQ_FOREACH(ti
, &tabs
, entry
) {
6873 if ((uri
= get_uri(ti
)) == NULL
)
6874 /* XXX make sure there is something to print */
6875 /* XXX add gui pages in here to look purdy */
6877 menu_items
= gtk_menu_item_new_with_label(uri
);
6878 gtk_menu_shell_append(GTK_MENU_SHELL(menu
), menu_items
);
6879 gtk_widget_show(menu_items
);
6881 g_signal_connect_swapped((menu_items
),
6882 "activate", G_CALLBACK(menuitem_response
),
6886 gtk_menu_popup(GTK_MENU(menu
), NULL
, NULL
, NULL
, NULL
,
6887 bevent
->button
, bevent
->time
);
6889 /* unref object so it'll free itself when popped down */
6890 #if !GTK_CHECK_VERSION(3, 0, 0)
6891 /* XXX does not need unref with gtk+3? */
6892 g_object_ref_sink(menu
);
6893 g_object_unref(menu
);
6896 return (TRUE
/* eat event */);
6899 return (FALSE
/* propagate */);
6903 icon_size_map(int iconsz
)
6905 if (iconsz
<= GTK_ICON_SIZE_INVALID
||
6906 iconsz
> GTK_ICON_SIZE_DIALOG
)
6907 return (GTK_ICON_SIZE_SMALL_TOOLBAR
);
6913 create_button(char *name
, char *stockid
, int size
)
6915 GtkWidget
*button
, *image
;
6919 rcstring
= g_strdup_printf(
6920 "style \"%s-style\"\n"
6922 " GtkWidget::focus-padding = 0\n"
6923 " GtkWidget::focus-line-width = 0\n"
6927 "widget \"*.%s\" style \"%s-style\"", name
, name
, name
);
6928 gtk_rc_parse_string(rcstring
);
6930 button
= gtk_button_new();
6931 gtk_button_set_focus_on_click(GTK_BUTTON(button
), FALSE
);
6932 gtk_icon_size
= icon_size_map(size
? size
: icon_size
);
6934 image
= gtk_image_new_from_stock(stockid
, gtk_icon_size
);
6935 gtk_widget_set_size_request(GTK_WIDGET(image
), -1, -1);
6936 gtk_container_set_border_width(GTK_CONTAINER(button
), 1);
6937 gtk_container_add(GTK_CONTAINER(button
), GTK_WIDGET(image
));
6938 gtk_widget_set_name(button
, name
);
6939 gtk_button_set_relief(GTK_BUTTON(button
), GTK_RELIEF_NONE
);
6945 button_set_stockid(GtkWidget
*button
, char *stockid
)
6949 image
= gtk_image_new_from_stock(stockid
, icon_size_map(icon_size
));
6950 gtk_widget_set_size_request(GTK_WIDGET(image
), -1, -1);
6951 gtk_button_set_image(GTK_BUTTON(button
), image
);
6955 clipb_primary_cb(GtkClipboard
*primary
, GdkEvent
*event
, gpointer notused
)
6958 GdkAtom atom
= gdk_atom_intern("CUT_BUFFER0", FALSE
);
6961 if (xterm_workaround
== 0)
6965 * xterm doesn't play nice with clipboards because it clears the
6966 * primary when clicked. We rely on primary being set to properly
6967 * handle middle mouse button clicks (paste). So when someone clears
6968 * primary copy whatever is in CUT_BUFFER0 into primary to simualte
6969 * other application behavior (as in DON'T clear primary).
6972 p
= gtk_clipboard_wait_for_text(primary
);
6974 if (gdk_property_get(gdk_get_default_root_window(),
6976 gdk_atom_intern("STRING", FALSE
),
6978 1024 * 1024 /* picked out of my butt */,
6986 /* yes sir, we need to NUL the string */
6988 gtk_clipboard_set_text(primary
, p
, -1);
7002 char file
[PATH_MAX
];
7005 vbox
= gtk_vbox_new(FALSE
, 0);
7006 gtk_box_set_spacing(GTK_BOX(vbox
), 0);
7007 notebook
= GTK_NOTEBOOK(gtk_notebook_new());
7008 #if !GTK_CHECK_VERSION(3, 0, 0)
7009 /* XXX seems to be needed with gtk+2 */
7010 gtk_notebook_set_tab_hborder(notebook
, 0);
7011 gtk_notebook_set_tab_vborder(notebook
, 0);
7013 gtk_notebook_set_scrollable(notebook
, TRUE
);
7014 gtk_notebook_set_show_border(notebook
, FALSE
);
7015 gtk_widget_set_can_focus(GTK_WIDGET(notebook
), FALSE
);
7017 abtn
= gtk_button_new();
7018 arrow
= gtk_arrow_new(GTK_ARROW_DOWN
, GTK_SHADOW_NONE
);
7019 gtk_widget_set_size_request(arrow
, -1, -1);
7020 gtk_container_add(GTK_CONTAINER(abtn
), arrow
);
7021 gtk_widget_set_size_request(abtn
, -1, 20);
7023 #if GTK_CHECK_VERSION(2, 20, 0)
7024 gtk_notebook_set_action_widget(notebook
, abtn
, GTK_PACK_END
);
7026 gtk_widget_set_size_request(GTK_WIDGET(notebook
), -1, -1);
7028 /* compact tab bar */
7029 tab_bar
= gtk_hbox_new(TRUE
, 0);
7031 gtk_box_pack_start(GTK_BOX(vbox
), tab_bar
, FALSE
, FALSE
, 0);
7032 gtk_box_pack_start(GTK_BOX(vbox
), GTK_WIDGET(notebook
), TRUE
, TRUE
, 0);
7033 gtk_widget_set_size_request(vbox
, -1, -1);
7035 g_object_connect(G_OBJECT(notebook
),
7036 "signal::switch-page", G_CALLBACK(notebook_switchpage_cb
), NULL
,
7038 g_object_connect(G_OBJECT(notebook
),
7039 "signal::page-reordered", G_CALLBACK(notebook_pagereordered_cb
),
7040 NULL
, (char *)NULL
);
7041 g_signal_connect(G_OBJECT(abtn
), "button_press_event",
7042 G_CALLBACK(arrow_cb
), NULL
);
7044 main_window
= create_window("xxxterm");
7045 gtk_container_add(GTK_CONTAINER(main_window
), vbox
);
7046 g_signal_connect(G_OBJECT(main_window
), "delete_event",
7047 G_CALLBACK(gtk_main_quit
), NULL
);
7050 for (i
= 0; i
< LENGTH(icons
); i
++) {
7051 snprintf(file
, sizeof file
, "%s" PS
"%s", resource_dir
, icons
[i
]);
7052 pb
= gdk_pixbuf_new_from_file(file
, NULL
);
7053 l
= g_list_append(l
, pb
);
7055 gtk_window_set_default_icon_list(l
);
7057 /* clipboard work around */
7058 if (xterm_workaround
)
7060 G_OBJECT(gtk_clipboard_get(GDK_SELECTION_PRIMARY
)),
7061 "owner-change", G_CALLBACK(clipb_primary_cb
), NULL
);
7063 gtk_widget_show_all(abtn
);
7064 gtk_widget_show_all(main_window
);
7065 notebook_tab_set_visibility();
7068 #ifndef XT_SOCKET_DISABLE
7070 send_cmd_to_socket(char *cmd
)
7073 struct sockaddr_un sa
;
7075 if ((s
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
7076 warnx("%s: socket", __func__
);
7080 sa
.sun_family
= AF_UNIX
;
7081 snprintf(sa
.sun_path
, sizeof(sa
.sun_path
), "%s" PS
"%s",
7082 work_dir
, XT_SOCKET_FILE
);
7085 if (connect(s
, (struct sockaddr
*)&sa
, len
) == -1) {
7086 warnx("%s: connect", __func__
);
7090 if (send(s
, cmd
, strlen(cmd
) + 1, 0) == -1) {
7091 warnx("%s: send", __func__
);
7102 socket_watcher(GIOChannel
*source
, GIOCondition condition
, gpointer data
)
7105 char str
[XT_MAX_URL_LENGTH
];
7106 socklen_t t
= sizeof(struct sockaddr_un
);
7107 struct sockaddr_un sa
;
7112 gint fd
= g_io_channel_unix_get_fd(source
);
7114 if ((s
= accept(fd
, (struct sockaddr
*)&sa
, &t
)) == -1) {
7119 if (getpeereid(s
, &uid
, &gid
) == -1) {
7123 if (uid
!= getuid() || gid
!= getgid()) {
7124 warnx("unauthorized user");
7130 warnx("not a valid user");
7134 n
= recv(s
, str
, sizeof(str
), 0);
7138 tt
= TAILQ_LAST(&tabs
, tab_list
);
7139 cmd_execute(tt
, str
);
7147 struct sockaddr_un sa
;
7149 if ((s
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
7150 warn("is_running: socket");
7154 sa
.sun_family
= AF_UNIX
;
7155 snprintf(sa
.sun_path
, sizeof(sa
.sun_path
), "%s" PS
"%s",
7156 work_dir
, XT_SOCKET_FILE
);
7159 /* connect to see if there is a listener */
7160 if (connect(s
, (struct sockaddr
*)&sa
, len
) == -1)
7161 rv
= 0; /* not running */
7163 rv
= 1; /* already running */
7174 struct sockaddr_un sa
;
7176 if ((s
= socket(AF_UNIX
, SOCK_STREAM
, 0)) == -1) {
7177 warn("build_socket: socket");
7181 sa
.sun_family
= AF_UNIX
;
7182 snprintf(sa
.sun_path
, sizeof(sa
.sun_path
), "%s" PS
"%s",
7183 work_dir
, XT_SOCKET_FILE
);
7186 /* connect to see if there is a listener */
7187 if (connect(s
, (struct sockaddr
*)&sa
, len
) == -1) {
7188 /* no listener so we will */
7189 unlink(sa
.sun_path
);
7191 if (bind(s
, (struct sockaddr
*)&sa
, len
) == -1) {
7192 warn("build_socket: bind");
7196 if (listen(s
, 1) == -1) {
7197 warn("build_socket: listen");
7215 if (stat(dir
, &sb
)) {
7216 #if defined __MINGW32__
7217 printf("making: %s\n", dir
);
7218 if (mkdir(dir
) == -1)
7220 if (mkdir(dir
, S_IRWXU
) == -1)
7222 err(1, "mkdir %s", dir
);
7224 err(1, "stat %s", dir
);
7226 if (S_ISDIR(sb
.st_mode
) == 0)
7227 errx(1, "%s not a dir", dir
);
7228 #if !defined __MINGW32__
7229 if (((sb
.st_mode
& (S_IRWXU
| S_IRWXG
| S_IRWXO
))) != S_IRWXU
) {
7230 warnx("fixing invalid permissions on %s", dir
);
7231 if (chmod(dir
, S_IRWXU
) == -1)
7232 err(1, "chmod %s", dir
);
7241 "%s [-nSTVt][-f file][-s session] url ...\n", __progname
);
7245 GStaticRecMutex my_gdk_mtx
= G_STATIC_REC_MUTEX_INIT
;
7246 volatile int mtx_depth
;
7250 * The linux flash plugin violates the gdk locking mechanism.
7251 * Work around the issue by using a recursive mutex with some match applied
7252 * to see if we hit a buggy condition.
7254 * The following code is painful so just don't read it. It really doesn't
7255 * make much sense but seems to work.
7260 g_static_rec_mutex_lock(&my_gdk_mtx
);
7263 if (mtx_depth
<= 0) {
7264 /* should not happen */
7265 show_oops(NULL
, "negative mutex locking bug, trying to "
7267 fprintf(stderr
, "negative mutex locking bug, trying to "
7269 g_static_rec_mutex_unlock_full(&my_gdk_mtx
);
7270 g_static_rec_mutex_lock(&my_gdk_mtx
);
7275 if (mtx_depth
!= 1) {
7276 /* decrease mutext depth to 1 */
7278 g_static_rec_mutex_unlock(&my_gdk_mtx
);
7280 } while (mtx_depth
> 1);
7289 /* if mutex depth isn't 1 then something went bad */
7290 if (mtx_depth
!= 1) {
7291 x
= g_static_rec_mutex_unlock_full(&my_gdk_mtx
);
7293 /* should not happen */
7294 show_oops(NULL
, "mutex unlocking bug, trying to "
7296 fprintf(stderr
, "mutex unlocking bug, trying to "
7300 if (mtx_complain
== 0) {
7301 show_oops(NULL
, "buggy mutex implementation detected, "
7302 "work around implemented");
7303 fprintf(stderr
, "buggy mutex implementation detected, "
7304 "work around implemented");
7311 g_static_rec_mutex_unlock(&my_gdk_mtx
);
7315 main(int argc
, char **argv
)
7318 int c
, optn
= 0, opte
= 0, focus
= 1;
7319 char conf
[PATH_MAX
] = { '\0' };
7320 char file
[PATH_MAX
];
7321 char *env_proxy
= NULL
;
7325 start_argv
= (char * const *)argv
;
7329 g_thread_init(NULL
);
7330 gdk_threads_set_lock_functions(mtx_lock
, mtx_unlock
);
7332 gdk_threads_enter();
7334 gcry_control (GCRYCTL_SET_THREAD_CBS
, &gcry_threads_pthread
);
7336 gtk_init(&argc
, &argv
);
7338 gnutls_global_init();
7340 strlcpy(named_session
, XT_SAVED_TABS_FILE
, sizeof named_session
);
7345 RB_INIT(&downloads
);
7347 TAILQ_INIT(&sessions
);
7350 TAILQ_INIT(&aliases
);
7356 TAILQ_INIT(&ua_list
);
7358 #ifndef XT_RESOURCE_LIMITS_DISABLE
7362 GIOChannel
*channel
;
7364 /* fiddle with ulimits */
7365 if (getrlimit(RLIMIT_NOFILE
, &rlp
) == -1)
7368 /* just use them all */
7369 rlp
.rlim_cur
= rlp
.rlim_max
;
7370 if (setrlimit(RLIMIT_NOFILE
, &rlp
) == -1)
7372 if (getrlimit(RLIMIT_NOFILE
, &rlp
) == -1)
7374 else if (rlp
.rlim_cur
<= 256)
7375 startpage_add("%s requires at least 256 file "
7376 "descriptors, currently it has up to %d available",
7377 __progname
, rlp
.rlim_cur
);
7381 while ((c
= getopt(argc
, argv
, "STVf:s:tne")) != -1) {
7390 #ifdef XXXTERM_BUILDSTR
7391 errx(0 , "Version: %s Build: %s",
7392 version
, XXXTERM_BUILDSTR
);
7394 errx(0 , "Version: %s", version
);
7398 strlcpy(conf
, optarg
, sizeof(conf
));
7401 strlcpy(named_session
, optarg
, sizeof(named_session
));
7422 xtp_generate_keys();
7424 /* XXX this hammer is way too big but treat all signaling the same */
7425 #ifndef XT_SIGNALS_DISABLE
7427 struct sigaction sact
;
7429 bzero(&sact
, sizeof(sact
));
7430 sigemptyset(&sact
.sa_mask
);
7431 sact
.sa_handler
= sigchild
;
7432 sact
.sa_flags
= SA_NOCLDSTOP
;
7433 sigaction(SIGCHLD
, &sact
, NULL
);
7436 /* set download dir */
7437 pwd
= getpwuid(getuid());
7439 errx(1, "invalid user %d", getuid());
7440 strlcpy(download_dir
, pwd
->pw_dir
, sizeof download_dir
);
7442 /* compile buffer command regexes */
7445 /* set default string settings */
7446 home
= g_strdup("https://www.cyphertite.com");
7447 search_string
= g_strdup("https://ssl.scroogle.org/cgi-bin/nbbwssl.cgi?Gw=%s");
7448 resource_dir
= g_strdup("/usr/local/share/xxxterm/");
7449 strlcpy(runtime_settings
, "runtime", sizeof runtime_settings
);
7450 cmd_font_name
= g_strdup("monospace normal 9");
7451 oops_font_name
= g_strdup("monospace normal 9");
7452 statusbar_font_name
= g_strdup("monospace normal 9");
7453 tabbar_font_name
= g_strdup("monospace normal 9");
7454 statusbar_elems
= g_strdup("BP");
7455 spell_check_languages
= g_strdup("en_US");
7456 encoding
= g_strdup("UTF-8");
7458 /* read config file */
7459 if (strlen(conf
) == 0)
7460 snprintf(conf
, sizeof conf
, "%s" PS
".%s",
7461 pwd
->pw_dir
, XT_CONF_FILE
);
7462 config_parse(conf
, 0);
7465 cmd_font
= pango_font_description_from_string(cmd_font_name
);
7466 oops_font
= pango_font_description_from_string(oops_font_name
);
7467 statusbar_font
= pango_font_description_from_string(statusbar_font_name
);
7468 tabbar_font
= pango_font_description_from_string(tabbar_font_name
);
7470 /* working directory */
7471 if (strlen(work_dir
) == 0)
7472 snprintf(work_dir
, sizeof work_dir
, "%s" PS
"%s",
7473 pwd
->pw_dir
, XT_DIR
);
7476 /* icon cache dir */
7477 snprintf(cache_dir
, sizeof cache_dir
, "%s" PS
"%s", work_dir
, XT_CACHE_DIR
);
7481 snprintf(certs_dir
, sizeof certs_dir
, "%s" PS
"%s", work_dir
, XT_CERT_DIR
);
7485 snprintf(sessions_dir
, sizeof sessions_dir
, "%s" PS
"%s",
7486 work_dir
, XT_SESSIONS_DIR
);
7487 xxx_dir(sessions_dir
);
7490 snprintf(js_dir
, sizeof js_dir
, "%s" PS
"%s", work_dir
, XT_JS_DIR
);
7494 snprintf(temp_dir
, sizeof temp_dir
, "%s" PS
"%s", work_dir
, XT_TEMP_DIR
);
7497 /* runtime settings that can override config file */
7498 if (runtime_settings
[0] != '\0')
7499 config_parse(runtime_settings
, 1);
7502 if (!strcmp(download_dir
, pwd
->pw_dir
))
7503 strlcat(download_dir
, PS
"downloads", sizeof download_dir
);
7504 xxx_dir(download_dir
);
7506 /* favorites file */
7507 snprintf(file
, sizeof file
, "%s" PS
"%s", work_dir
, XT_FAVS_FILE
);
7508 if (stat(file
, &sb
)) {
7509 warnx("favorites file doesn't exist, creating it");
7510 if ((f
= fopen(file
, "w")) == NULL
)
7511 err(1, "favorites");
7515 /* quickmarks file */
7516 snprintf(file
, sizeof file
, "%s" PS
"%s", work_dir
, XT_QMARKS_FILE
);
7517 if (stat(file
, &sb
)) {
7518 warnx("quickmarks file doesn't exist, creating it");
7519 if ((f
= fopen(file
, "w")) == NULL
)
7520 err(1, "quickmarks");
7524 /* search history */
7525 if (history_autosave
) {
7526 snprintf(search_file
, sizeof search_file
, "%s" PS
"%s",
7527 work_dir
, XT_SEARCH_FILE
);
7528 if (stat(search_file
, &sb
)) {
7529 warnx("search history file doesn't exist, creating it");
7530 if ((f
= fopen(search_file
, "w")) == NULL
)
7531 err(1, "search_history");
7534 history_read(&shl
, search_file
, &search_history_count
);
7537 /* command history */
7538 if (history_autosave
) {
7539 snprintf(command_file
, sizeof command_file
, "%s" PS
"%s",
7540 work_dir
, XT_COMMAND_FILE
);
7541 if (stat(command_file
, &sb
)) {
7542 warnx("command history file doesn't exist, creating it");
7543 if ((f
= fopen(command_file
, "w")) == NULL
)
7544 err(1, "command_history");
7547 history_read(&chl
, command_file
, &cmd_history_count
);
7551 session
= webkit_get_default_session();
7556 if (stat(ssl_ca_file
, &sb
)) {
7557 warnx("no CA file: %s", ssl_ca_file
);
7558 g_free(ssl_ca_file
);
7561 g_object_set(session
,
7562 SOUP_SESSION_SSL_CA_FILE
, ssl_ca_file
,
7563 SOUP_SESSION_SSL_STRICT
, ssl_strict_certs
,
7567 /* guess_search regex */
7568 if (url_regex
== NULL
)
7569 url_regex
= g_strdup(XT_URL_REGEX
);
7571 if (regcomp(&url_re
, url_regex
, REG_EXTENDED
| REG_NOSUB
))
7572 startpage_add("invalid url regex %s", url_regex
);
7575 env_proxy
= getenv("http_proxy");
7577 setup_proxy(env_proxy
);
7579 env_proxy
= getenv("HTTP_PROXY");
7581 setup_proxy(env_proxy
);
7583 setup_proxy(http_proxy
);
7585 #ifndef XT_SOCKET_DISABLE
7587 send_cmd_to_socket(argv
[0]);
7591 opte
= opte
; /* shut mingw up */
7593 /* set some connection parameters */
7594 g_object_set(session
, "max-conns", max_connections
, (char *)NULL
);
7595 g_object_set(session
, "max-conns-per-host", max_host_connections
,
7598 g_signal_connect(session
, "request-queued", G_CALLBACK(session_rq_cb
),
7601 #ifndef XT_SOCKET_DISABLE
7602 /* see if there is already an xxxterm running */
7603 if (single_instance
&& is_running()) {
7605 warnx("already running");
7610 cmd
= g_strdup_printf("%s %s", "tabnew", argv
[0]);
7611 send_cmd_to_socket(cmd
);
7621 optn
= optn
; /* shut mingw up */
7626 /* uri completion */
7627 completion_model
= gtk_list_store_new(1, G_TYPE_STRING
);
7630 buffers_store
= gtk_list_store_new
7631 (NUM_COLS
, G_TYPE_UINT
, GDK_TYPE_PIXBUF
, G_TYPE_STRING
);
7637 notebook_tab_set_visibility();
7639 if (save_global_history
)
7640 restore_global_history();
7642 /* restore session list */
7643 restore_sessions_list();
7645 if (!strcmp(named_session
, XT_SAVED_TABS_FILE
))
7646 restore_saved_tabs();
7648 a
.s
= named_session
;
7649 a
.i
= XT_SES_DONOTHING
;
7650 open_tabs(NULL
, &a
);
7653 /* see if we have an exception */
7654 if (!TAILQ_EMPTY(&spl
)) {
7655 create_new_tab("about:startpage", NULL
, focus
, -1);
7660 create_new_tab(argv
[0], NULL
, focus
, -1);
7667 if (TAILQ_EMPTY(&tabs
))
7668 create_new_tab(home
, NULL
, 1, -1);
7669 #ifndef XT_SOCKET_DISABLE
7671 if ((s
= build_socket()) != -1) {
7672 channel
= g_io_channel_unix_new(s
);
7673 g_io_add_watch(channel
, G_IO_IN
, socket_watcher
, NULL
);
7680 gdk_threads_leave();
7681 g_static_rec_mutex_unlock_full(&my_gdk_mtx
); /* just in case */
7684 gnutls_global_deinit();