10 #include <gdk/gdkkeysyms.h>
12 #include <webkit2/webkit2.h>
15 static void client_destroy(GtkWidget *, gpointer);
16 static gboolean client_destroy_request(WebKitWebView *, gpointer);
17 static WebKitWebView *client_new(const gchar *);
18 static WebKitWebView *client_new_request(WebKitWebView *, WebKitNavigationAction *,
20 static void cooperation_setup(void);
21 static void changed_download_progress(GObject *, GParamSpec *, gpointer);
22 static void changed_load_progress(GObject *, GParamSpec *, gpointer);
23 static void changed_title(GObject *, GParamSpec *, gpointer);
24 static void changed_uri(GObject *, GParamSpec *, gpointer);
25 static gboolean crashed_web_view(WebKitWebView *, gpointer);
26 static gboolean crashed_web_view_reload(gpointer);
27 static gboolean decide_policy(WebKitWebView *, WebKitPolicyDecision *,
28 WebKitPolicyDecisionType, gpointer);
29 static gboolean download_handle(WebKitDownload *, gchar *, gpointer);
30 static void download_handle_start(WebKitWebView *, WebKitDownload *, gpointer);
31 static void downloadmanager_cancel(GtkToolButton *, gpointer data);
32 static void downloadmanager_setup(void);
33 static gchar *ensure_uri_scheme(const gchar *);
34 static void grab_environment_configuration(void);
35 static void hover_web_view(WebKitWebView *, WebKitHitTestResult *, guint, gpointer);
36 static gboolean key_downloadmanager(GtkWidget *, GdkEvent *, gpointer);
37 static gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
38 static gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
39 static void keywords_load(void);
40 static gboolean keywords_try_search(WebKitWebView *, const gchar *);
41 static gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
42 static void search(gpointer, gint);
43 static Window tabbed_launch(void);
44 static void trust_user_certs(WebKitWebContext *);
59 struct DownloadManager
67 static const gchar *accepted_language[2] = { NULL, NULL };
68 static gint clients = 0;
69 static gboolean cooperative_alone = TRUE;
70 static gboolean cooperative_instances = TRUE;
71 static int cooperative_pipe_fp = 0;
72 static int crash_autoreload_delay = 2;
73 static gchar *download_dir = "/tmp";
74 static Window embed = 0;
75 static gchar *fifo_suffix = "main";
76 static gdouble global_zoom = 1.0;
77 static gchar *home_uri = "about:blank";
78 static gboolean initial_wc_setup_done = FALSE;
79 static GHashTable *keywords = NULL;
80 static gchar *search_text = NULL;
81 static gboolean tabbed_automagic = TRUE;
82 static gchar *user_agent = NULL;
83 static gchar *web_extensions_dir = NULL;
87 client_destroy(GtkWidget *obj, gpointer data)
89 struct Client *c = (struct Client *)data;
91 g_signal_handlers_disconnect_by_func(G_OBJECT(c->web_view),
92 changed_load_progress, c);
102 client_destroy_request(WebKitWebView *web_view, gpointer data)
104 struct Client *c = (struct Client *)data;
106 gtk_widget_destroy(c->win);
112 client_new(const gchar *uri)
115 WebKitWebContext *wc;
118 if (uri != NULL && cooperative_instances && !cooperative_alone)
120 write(cooperative_pipe_fp, uri, strlen(uri));
121 write(cooperative_pipe_fp, "\n", 1);
125 c = malloc(sizeof(struct Client));
128 fprintf(stderr, __NAME__": fatal: malloc failed\n");
136 c->win = gtk_plug_new(embed);
137 if (!gtk_plug_get_embedded(GTK_PLUG(c->win)))
139 fprintf(stderr, __NAME__": Can't plug-in to XID %ld.\n", embed);
140 gtk_widget_destroy(c->win);
148 c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
149 gtk_window_set_wmclass(GTK_WINDOW(c->win), __NAME__, __NAME_CAPITALIZED__);
152 g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(client_destroy), c);
153 gtk_window_set_title(GTK_WINDOW(c->win), __NAME__);
155 c->web_view = webkit_web_view_new();
156 wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
158 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), global_zoom);
159 g_signal_connect(G_OBJECT(c->web_view), "notify::title",
160 G_CALLBACK(changed_title), c);
161 g_signal_connect(G_OBJECT(c->web_view), "notify::uri",
162 G_CALLBACK(changed_uri), c);
163 g_signal_connect(G_OBJECT(c->web_view), "notify::estimated-load-progress",
164 G_CALLBACK(changed_load_progress), c);
165 g_signal_connect(G_OBJECT(c->web_view), "create",
166 G_CALLBACK(client_new_request), NULL);
167 g_signal_connect(G_OBJECT(c->web_view), "close",
168 G_CALLBACK(client_destroy_request), c);
169 g_signal_connect(G_OBJECT(c->web_view), "decide-policy",
170 G_CALLBACK(decide_policy), NULL);
171 g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
172 G_CALLBACK(key_web_view), c);
173 g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
174 G_CALLBACK(key_web_view), c);
175 g_signal_connect(G_OBJECT(c->web_view), "scroll-event",
176 G_CALLBACK(key_web_view), c);
177 g_signal_connect(G_OBJECT(c->web_view), "mouse-target-changed",
178 G_CALLBACK(hover_web_view), c);
179 g_signal_connect(G_OBJECT(c->web_view), "web-process-crashed",
180 G_CALLBACK(crashed_web_view), c);
182 if (!initial_wc_setup_done)
184 if (accepted_language[0] != NULL)
185 webkit_web_context_set_preferred_languages(wc, accepted_language);
187 g_signal_connect(G_OBJECT(wc), "download-started",
188 G_CALLBACK(download_handle_start), NULL);
190 trust_user_certs(wc);
192 initial_wc_setup_done = TRUE;
195 if (user_agent != NULL)
196 g_object_set(G_OBJECT(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view))),
197 "user-agent", user_agent, NULL);
199 c->scroll = gtk_scrolled_window_new(NULL, NULL);
201 gtk_container_add(GTK_CONTAINER(c->scroll), c->web_view);
203 c->location = gtk_entry_new();
204 g_signal_connect(G_OBJECT(c->location), "key-press-event",
205 G_CALLBACK(key_location), c);
207 /* XXX Progress bars don't work/look as intended anymore. Level bars
208 * are a dirty workaround (kind of). */
209 c->progress = gtk_level_bar_new();
210 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
211 gtk_widget_set_size_request(c->progress, 100, -1);
213 c->top_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
214 gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 2);
215 gtk_box_pack_start(GTK_BOX(c->top_box), c->progress, FALSE, FALSE, 2);
217 c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
218 gtk_box_pack_start(GTK_BOX(c->vbox), c->top_box, FALSE, FALSE, 2);
219 gtk_box_pack_start(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 2);
221 gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
223 gtk_widget_grab_focus(c->web_view);
224 gtk_widget_show_all(c->win);
228 f = ensure_uri_scheme(uri);
229 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
235 return WEBKIT_WEB_VIEW(c->web_view);
239 client_new_request(WebKitWebView *web_view,
240 WebKitNavigationAction *navigation_action, gpointer data)
242 return client_new(NULL);
246 cooperation_setup(void)
249 gchar *fifofilename, *fifopath;
251 fifofilename = g_strdup_printf("%s-%s", __NAME__".fifo", fifo_suffix);
252 fifopath = g_build_filename(g_get_user_runtime_dir(), fifofilename, NULL);
253 g_free(fifofilename);
255 if (!g_file_test(fifopath, G_FILE_TEST_EXISTS))
256 mkfifo(fifopath, 0600);
258 cooperative_pipe_fp = open(fifopath, O_WRONLY | O_NONBLOCK);
259 if (!cooperative_pipe_fp)
261 fprintf(stderr, __NAME__": Can't open FIFO at all.\n");
265 if (write(cooperative_pipe_fp, "", 0) == -1)
267 /* Could not do an empty write to the FIFO which means there's
268 * no one listening. */
269 close(cooperative_pipe_fp);
270 towatch = g_io_channel_new_file(fifopath, "r+", NULL);
271 g_io_add_watch(towatch, G_IO_IN, (GIOFunc)remote_msg, NULL);
274 cooperative_alone = FALSE;
281 changed_download_progress(GObject *obj, GParamSpec *pspec, gpointer data)
283 WebKitDownload *download = WEBKIT_DOWNLOAD(obj);
284 WebKitURIResponse *resp;
285 GtkToolItem *tb = GTK_TOOL_ITEM(data);
288 gchar *t, *filename, *base;
290 p = webkit_download_get_estimated_progress(download) * 100;
291 resp = webkit_download_get_response(download);
292 size_mb = webkit_uri_response_get_content_length(resp) / 1e6;
294 uri = webkit_download_get_destination(download);
295 filename = g_filename_from_uri(uri, NULL, NULL);
296 if (filename == NULL)
298 /* This really should not happen because WebKit uses that URI to
299 * write to a file... */
300 fprintf(stderr, __NAME__": Could not construct file name from URI!\n");
301 t = g_strdup_printf("%s (%.0f%% of %.1f MB)",
302 webkit_uri_response_get_uri(resp), p, size_mb);
306 base = g_path_get_basename(filename);
307 t = g_strdup_printf("%s (%.0f%% of %.1f MB)", base, p, size_mb);
311 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), t);
316 changed_load_progress(GObject *obj, GParamSpec *pspec, gpointer data)
318 struct Client *c = (struct Client *)data;
321 p = webkit_web_view_get_estimated_load_progress(WEBKIT_WEB_VIEW(c->web_view));
322 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), p);
326 changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
329 struct Client *c = (struct Client *)data;
331 t = webkit_web_view_get_title(WEBKIT_WEB_VIEW(c->web_view));
332 gtk_window_set_title(GTK_WINDOW(c->win), (t == NULL ? __NAME__ : t));
336 changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
339 struct Client *c = (struct Client *)data;
341 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
342 gtk_entry_set_text(GTK_ENTRY(c->location), (t == NULL ? __NAME__ : t));
346 crashed_web_view(WebKitWebView *web_view, gpointer data)
348 fprintf(stderr, __NAME__": WebView crashed!\n");
349 if (crash_autoreload_delay >= 1)
351 fprintf(stderr, __NAME__": Reloading WebView in %d seconds.\n",
352 crash_autoreload_delay);
353 g_timeout_add_seconds(crash_autoreload_delay, crashed_web_view_reload,
361 crashed_web_view_reload(gpointer data)
363 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(data));
365 return G_SOURCE_REMOVE;
369 decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision,
370 WebKitPolicyDecisionType type, gpointer data)
372 WebKitResponsePolicyDecision *r;
376 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
377 r = WEBKIT_RESPONSE_POLICY_DECISION(decision);
378 if (!webkit_response_policy_decision_is_mime_type_supported(r))
379 webkit_policy_decision_download(decision);
381 webkit_policy_decision_use(decision);
384 /* Use whatever default there is. */
391 download_handle_start(WebKitWebView *web_view, WebKitDownload *download,
394 g_signal_connect(G_OBJECT(download), "decide-destination",
395 G_CALLBACK(download_handle), data);
399 download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer data)
401 gchar *path, *path2 = NULL, *uri;
405 path = g_build_filename(download_dir, suggested_filename, NULL);
406 path2 = g_strdup(path);
407 while (g_file_test(path2, G_FILE_TEST_EXISTS) && suffix < 1000)
411 path2 = g_strdup_printf("%s.%d", path, suffix);
417 fprintf(stderr, __NAME__": Suffix reached limit for download.\n");
418 webkit_download_cancel(download);
422 uri = g_filename_to_uri(path2, NULL, NULL);
423 webkit_download_set_destination(download, uri);
426 tb = gtk_tool_button_new(NULL, NULL);
427 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(tb), "gtk-delete");
428 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), suggested_filename);
429 gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0);
430 gtk_widget_show_all(dm.win);
432 g_signal_connect(G_OBJECT(download), "notify::estimated-progress",
433 G_CALLBACK(changed_download_progress), tb);
435 g_object_ref(download);
436 g_signal_connect(G_OBJECT(tb), "clicked",
437 G_CALLBACK(downloadmanager_cancel), download);
443 /* Propagate -- to whom it may concern. */
448 downloadmanager_cancel(GtkToolButton *tb, gpointer data)
450 WebKitDownload *download = WEBKIT_DOWNLOAD(data);
452 webkit_download_cancel(download);
453 g_object_unref(download);
455 gtk_widget_destroy(GTK_WIDGET(tb));
459 downloadmanager_setup(void)
461 dm.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
462 gtk_window_set_type_hint(GTK_WINDOW(dm.win), GDK_WINDOW_TYPE_HINT_DIALOG);
463 gtk_window_set_default_size(GTK_WINDOW(dm.win), 500, 250);
464 gtk_window_set_title(GTK_WINDOW(dm.win), __NAME__" - Download Manager");
465 g_signal_connect(G_OBJECT(dm.win), "delete-event",
466 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
467 g_signal_connect(G_OBJECT(dm.win), "key-press-event",
468 G_CALLBACK(key_downloadmanager), NULL);
470 dm.toolbar = gtk_toolbar_new();
471 gtk_orientable_set_orientation(GTK_ORIENTABLE(dm.toolbar),
472 GTK_ORIENTATION_VERTICAL);
473 gtk_toolbar_set_style(GTK_TOOLBAR(dm.toolbar), GTK_TOOLBAR_BOTH_HORIZ);
474 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(dm.toolbar), FALSE);
476 dm.scroll = gtk_scrolled_window_new(NULL, NULL);
477 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dm.scroll),
478 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
479 gtk_container_add(GTK_CONTAINER(dm.scroll), dm.toolbar);
481 gtk_container_add(GTK_CONTAINER(dm.win), dm.scroll);
485 ensure_uri_scheme(const gchar *t)
489 f = g_ascii_strdown(t, -1);
490 if (!g_str_has_prefix(f, "http:") &&
491 !g_str_has_prefix(f, "https:") &&
492 !g_str_has_prefix(f, "file:") &&
493 !g_str_has_prefix(f, "about:"))
496 f = g_strdup_printf("http://%s", t);
504 grab_environment_configuration(void)
508 e = g_getenv(__NAME_UPPERCASE__"_ACCEPTED_LANGUAGE");
510 accepted_language[0] = g_strdup(e);
512 e = g_getenv(__NAME_UPPERCASE__"_CRASH_AUTORELOAD_DELAY");
514 crash_autoreload_delay = atoi(e);
516 e = g_getenv(__NAME_UPPERCASE__"_DOWNLOAD_DIR");
518 download_dir = g_strdup(e);
520 e = g_getenv(__NAME_UPPERCASE__"_FIFO_SUFFIX");
522 fifo_suffix = g_strdup(e);
524 e = g_getenv(__NAME_UPPERCASE__"_HOME_URI");
526 home_uri = g_strdup(e);
528 e = g_getenv(__NAME_UPPERCASE__"_USER_AGENT");
530 user_agent = g_strdup(e);
532 e = g_getenv(__NAME_UPPERCASE__"_WEB_EXTENSIONS_DIR");
534 web_extensions_dir = g_strdup(e);
536 web_extensions_dir = g_build_filename(g_get_user_data_dir(), __NAME__,
537 "web_extensions", NULL);
539 e = g_getenv(__NAME_UPPERCASE__"_ZOOM");
541 global_zoom = atof(e);
545 hover_web_view(WebKitWebView *web_view, WebKitHitTestResult *ht, guint modifiers,
548 struct Client *c = (struct Client *)data;
550 if (!gtk_widget_is_focus(c->location))
552 if (webkit_hit_test_result_context_is_link(ht))
554 gtk_entry_set_text(GTK_ENTRY(c->location),
555 webkit_hit_test_result_get_link_uri(ht));
557 if (c->hover_uri != NULL)
558 g_free(c->hover_uri);
559 c->hover_uri = g_strdup(webkit_hit_test_result_get_link_uri(ht));
563 gtk_entry_set_text(GTK_ENTRY(c->location),
564 webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)));
566 if (c->hover_uri != NULL)
567 g_free(c->hover_uri);
574 key_downloadmanager(GtkWidget *widget, GdkEvent *event, gpointer data)
576 if (event->type == GDK_KEY_PRESS)
578 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
580 switch (((GdkEventKey *)event)->keyval)
582 case GDK_KEY_d: /* close window (left hand) */
583 gtk_widget_hide(dm.win);
593 key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
595 struct Client *c = (struct Client *)data;
598 WebKitWebContext *wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
600 if (event->type == GDK_KEY_PRESS)
602 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
604 switch (((GdkEventKey *)event)->keyval)
606 case GDK_KEY_q: /* close window (left hand) */
607 gtk_widget_destroy(c->win);
609 case GDK_KEY_d: /* download manager (left hand) */
610 gtk_widget_show_all(dm.win);
612 case GDK_KEY_r: /* reload (left hand) */
613 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
616 case GDK_KEY_k: /* initiate search (BOTH hands) */
617 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
618 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
620 case GDK_KEY_c: /* reload trusted certs (left hand) */
621 trust_user_certs(wc);
627 switch (((GdkEventKey *)event)->keyval)
630 gtk_widget_grab_focus(c->web_view);
631 t = gtk_entry_get_text(GTK_ENTRY(c->location));
632 if (t != NULL && t[0] == '/')
634 if (search_text != NULL)
636 search_text = g_strdup(t + 1); /* XXX whacky */
639 else if (!keywords_try_search(WEBKIT_WEB_VIEW(c->web_view), t))
641 f = ensure_uri_scheme(t);
642 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
647 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
648 gtk_entry_set_text(GTK_ENTRY(c->location),
649 (t == NULL ? __NAME__ : t));
659 key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
661 struct Client *c = (struct Client *)data;
665 WebKitWebContext *wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
667 if (event->type == GDK_KEY_PRESS)
669 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
671 switch (((GdkEventKey *)event)->keyval)
673 case GDK_KEY_q: /* close window (left hand) */
674 gtk_widget_destroy(c->win);
676 case GDK_KEY_w: /* home (left hand) */
677 f = ensure_uri_scheme(home_uri);
678 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
681 case GDK_KEY_e: /* new tab (left hand) */
682 f = ensure_uri_scheme(home_uri);
686 case GDK_KEY_r: /* reload (left hand) */
687 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
690 case GDK_KEY_d: /* download manager (left hand) */
691 gtk_widget_show_all(dm.win);
693 case GDK_KEY_2: /* search forward (left hand) */
694 case GDK_KEY_n: /* search forward (maybe both hands) */
697 case GDK_KEY_3: /* search backward (left hand) */
700 case GDK_KEY_l: /* location (BOTH hands) */
701 gtk_widget_grab_focus(c->location);
703 case GDK_KEY_k: /* initiate search (BOTH hands) */
704 gtk_widget_grab_focus(c->location);
705 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
706 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
708 case GDK_KEY_c: /* reload trusted certs (left hand) */
709 trust_user_certs(wc);
713 else if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape)
715 webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(c->web_view));
716 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
719 else if (event->type == GDK_BUTTON_PRESS)
721 switch (((GdkEventButton *)event)->button)
724 if (c->hover_uri != NULL)
726 client_new(c->hover_uri);
731 webkit_web_view_go_back(WEBKIT_WEB_VIEW(c->web_view));
734 webkit_web_view_go_forward(WEBKIT_WEB_VIEW(c->web_view));
738 else if (event->type == GDK_SCROLL)
740 if (((GdkEventScroll *)event)->state & GDK_MOD1_MASK ||
741 ((GdkEventScroll *)event)->state & GDK_CONTROL_MASK)
743 gdk_event_get_scroll_deltas(event, &dx, &dy);
744 z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
746 z = dx != 0 ? global_zoom : z;
747 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
759 GIOChannel *channel = NULL;
760 gchar *path = NULL, *buf = NULL;
761 gchar **tokens = NULL;
763 keywords = g_hash_table_new(g_str_hash, g_str_equal);
765 path = g_build_filename(g_get_user_config_dir(), __NAME__, "keywordsearch",
767 channel = g_io_channel_new_file(path, "r", &err);
770 while (g_io_channel_read_line(channel, &buf, NULL, NULL, NULL)
771 == G_IO_STATUS_NORMAL)
776 tokens = g_strsplit(buf, " ", 2);
777 if (tokens[0] != NULL && tokens[1] != NULL)
778 g_hash_table_insert(keywords, g_strdup(tokens[0]),
779 g_strdup(tokens[1]));
784 g_io_channel_shutdown(channel, FALSE, NULL);
790 keywords_try_search(WebKitWebView *web_view, const gchar *t)
792 gboolean ret = FALSE;
793 gchar **tokens = NULL;
794 gchar *val = NULL, *uri = NULL;
796 tokens = g_strsplit(t, " ", 2);
797 if (tokens[0] != NULL && tokens[1] != NULL)
799 val = g_hash_table_lookup(keywords, tokens[0]);
802 uri = g_strdup_printf((gchar *)val, tokens[1]);
803 webkit_web_view_load_uri(web_view, uri);
814 remote_msg(GIOChannel *channel, GIOCondition condition, gpointer data)
818 g_io_channel_read_line(channel, &uri, NULL, NULL, NULL);
829 search(gpointer data, gint direction)
831 struct Client *c = (struct Client *)data;
832 WebKitWebView *web_view = WEBKIT_WEB_VIEW(c->web_view);
833 WebKitFindController *fc = webkit_web_view_get_find_controller(web_view);
835 if (search_text == NULL)
841 webkit_find_controller_search(fc, search_text,
842 WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
843 WEBKIT_FIND_OPTIONS_WRAP_AROUND,
847 webkit_find_controller_search_next(fc);
850 webkit_find_controller_search_previous(fc);
859 GIOChannel *tabbed_stdout_channel;
861 gchar *output = NULL;
862 char *argv[] = { "tabbed", "-c", "-d", "-p", "s1", "-n", __NAME__, NULL };
865 if (!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
866 NULL, NULL, NULL, &tabbed_stdout, NULL,
869 fprintf(stderr, __NAME__": Could not launch tabbed: %s\n", err->message);
874 tabbed_stdout_channel = g_io_channel_unix_new(tabbed_stdout);
875 if (tabbed_stdout_channel == NULL)
877 fprintf(stderr, __NAME__": Could open tabbed's stdout\n");
880 g_io_channel_read_line(tabbed_stdout_channel, &output, NULL, NULL, NULL);
881 g_io_channel_shutdown(tabbed_stdout_channel, FALSE, NULL);
884 fprintf(stderr, __NAME__": Could not read XID from tabbed\n");
888 plug_into = strtol(output, NULL, 16);
891 fprintf(stderr, __NAME__": The XID from tabbed is 0\n");
896 trust_user_certs(WebKitWebContext *wc)
898 GTlsCertificate *cert;
899 const gchar *basedir, *file, *absfile;
902 basedir = g_build_filename(g_get_user_config_dir(), __NAME__, "certs", NULL);
903 dir = g_dir_open(basedir, 0, NULL);
906 file = g_dir_read_name(dir);
909 absfile = g_build_filename(g_get_user_config_dir(), __NAME__, "certs",
911 cert = g_tls_certificate_new_from_file(absfile, NULL);
913 fprintf(stderr, __NAME__": Could not load trusted cert '%s'\n", file);
915 webkit_web_context_allow_tls_certificate_for_host(wc, cert, file);
916 file = g_dir_read_name(dir);
924 main(int argc, char **argv)
928 gtk_init(&argc, &argv);
930 grab_environment_configuration();
932 while ((opt = getopt(argc, argv, "e:CT")) != -1)
937 embed = atol(optarg);
938 tabbed_automagic = FALSE;
941 cooperative_instances = FALSE;
944 tabbed_automagic = FALSE;
947 fprintf(stderr, "Usage: "__NAME__" [OPTION]... [URI]...\n");
954 downloadmanager_setup();
956 if (tabbed_automagic && !(cooperative_instances && !cooperative_alone))
957 embed = tabbed_launch();
959 if (!cooperative_instances || cooperative_alone)
960 webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(),
964 client_new(home_uri);
967 for (i = optind; i < argc; i++)
971 if (!cooperative_instances || cooperative_alone)