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 = "/var/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 gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
154 g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(client_destroy), c);
155 gtk_window_set_title(GTK_WINDOW(c->win), __NAME__);
157 c->web_view = webkit_web_view_new();
158 wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
160 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), global_zoom);
161 g_signal_connect(G_OBJECT(c->web_view), "notify::title",
162 G_CALLBACK(changed_title), c);
163 g_signal_connect(G_OBJECT(c->web_view), "notify::uri",
164 G_CALLBACK(changed_uri), c);
165 g_signal_connect(G_OBJECT(c->web_view), "notify::estimated-load-progress",
166 G_CALLBACK(changed_load_progress), c);
167 g_signal_connect(G_OBJECT(c->web_view), "create",
168 G_CALLBACK(client_new_request), NULL);
169 g_signal_connect(G_OBJECT(c->web_view), "close",
170 G_CALLBACK(client_destroy_request), c);
171 g_signal_connect(G_OBJECT(c->web_view), "decide-policy",
172 G_CALLBACK(decide_policy), NULL);
173 g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
174 G_CALLBACK(key_web_view), c);
175 g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
176 G_CALLBACK(key_web_view), c);
177 g_signal_connect(G_OBJECT(c->web_view), "scroll-event",
178 G_CALLBACK(key_web_view), c);
179 g_signal_connect(G_OBJECT(c->web_view), "mouse-target-changed",
180 G_CALLBACK(hover_web_view), c);
181 g_signal_connect(G_OBJECT(c->web_view), "web-process-crashed",
182 G_CALLBACK(crashed_web_view), c);
184 if (!initial_wc_setup_done)
186 if (accepted_language[0] != NULL)
187 webkit_web_context_set_preferred_languages(wc, accepted_language);
189 g_signal_connect(G_OBJECT(wc), "download-started",
190 G_CALLBACK(download_handle_start), NULL);
192 trust_user_certs(wc);
194 initial_wc_setup_done = TRUE;
197 if (user_agent != NULL)
198 g_object_set(G_OBJECT(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view))),
199 "user-agent", user_agent, NULL);
201 c->scroll = gtk_scrolled_window_new(NULL, NULL);
203 gtk_container_add(GTK_CONTAINER(c->scroll), c->web_view);
205 c->location = gtk_entry_new();
206 g_signal_connect(G_OBJECT(c->location), "key-press-event",
207 G_CALLBACK(key_location), c);
209 /* XXX Progress bars don't work/look as intended anymore. Level bars
210 * are a dirty workaround (kind of). */
211 c->progress = gtk_level_bar_new();
212 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
213 gtk_widget_set_size_request(c->progress, 100, -1);
215 c->top_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
216 gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 0);
217 gtk_box_pack_start(GTK_BOX(c->top_box), c->progress, FALSE, FALSE, 0);
219 c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
220 gtk_box_pack_start(GTK_BOX(c->vbox), c->top_box, FALSE, FALSE, 0);
221 gtk_box_pack_start(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 0);
223 gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
225 gtk_widget_grab_focus(c->web_view);
226 gtk_widget_show_all(c->win);
230 f = ensure_uri_scheme(uri);
231 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
237 return WEBKIT_WEB_VIEW(c->web_view);
241 client_new_request(WebKitWebView *web_view,
242 WebKitNavigationAction *navigation_action, gpointer data)
244 return client_new(NULL);
248 cooperation_setup(void)
251 gchar *fifofilename, *fifopath;
253 fifofilename = g_strdup_printf("%s-%s", __NAME__".fifo", fifo_suffix);
254 fifopath = g_build_filename(g_get_user_runtime_dir(), fifofilename, NULL);
255 g_free(fifofilename);
257 if (!g_file_test(fifopath, G_FILE_TEST_EXISTS))
258 mkfifo(fifopath, 0600);
260 cooperative_pipe_fp = open(fifopath, O_WRONLY | O_NONBLOCK);
261 if (!cooperative_pipe_fp)
263 fprintf(stderr, __NAME__": Can't open FIFO at all.\n");
267 if (write(cooperative_pipe_fp, "", 0) == -1)
269 /* Could not do an empty write to the FIFO which means there's
270 * no one listening. */
271 close(cooperative_pipe_fp);
272 towatch = g_io_channel_new_file(fifopath, "r+", NULL);
273 g_io_add_watch(towatch, G_IO_IN, (GIOFunc)remote_msg, NULL);
276 cooperative_alone = FALSE;
283 changed_download_progress(GObject *obj, GParamSpec *pspec, gpointer data)
285 WebKitDownload *download = WEBKIT_DOWNLOAD(obj);
286 WebKitURIResponse *resp;
287 GtkToolItem *tb = GTK_TOOL_ITEM(data);
290 gchar *t, *filename, *base;
292 p = webkit_download_get_estimated_progress(download) * 100;
293 resp = webkit_download_get_response(download);
294 size_mb = webkit_uri_response_get_content_length(resp) / 1e6;
296 uri = webkit_download_get_destination(download);
297 filename = g_filename_from_uri(uri, NULL, NULL);
298 if (filename == NULL)
300 /* This really should not happen because WebKit uses that URI to
301 * write to a file... */
302 fprintf(stderr, __NAME__": Could not construct file name from URI!\n");
303 t = g_strdup_printf("%s (%.0f%% of %.1f MB)",
304 webkit_uri_response_get_uri(resp), p, size_mb);
308 base = g_path_get_basename(filename);
309 t = g_strdup_printf("%s (%.0f%% of %.1f MB)", base, p, size_mb);
313 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), t);
318 changed_load_progress(GObject *obj, GParamSpec *pspec, gpointer data)
320 struct Client *c = (struct Client *)data;
323 p = webkit_web_view_get_estimated_load_progress(WEBKIT_WEB_VIEW(c->web_view));
324 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), p);
328 changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
331 struct Client *c = (struct Client *)data;
333 t = webkit_web_view_get_title(WEBKIT_WEB_VIEW(c->web_view));
334 gtk_window_set_title(GTK_WINDOW(c->win), (t == NULL ? __NAME__ : t));
338 changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
341 struct Client *c = (struct Client *)data;
343 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
344 gtk_entry_set_text(GTK_ENTRY(c->location), (t == NULL ? __NAME__ : t));
348 crashed_web_view(WebKitWebView *web_view, gpointer data)
350 fprintf(stderr, __NAME__": WebView crashed!\n");
351 if (crash_autoreload_delay >= 1)
353 fprintf(stderr, __NAME__": Reloading WebView in %d seconds.\n",
354 crash_autoreload_delay);
355 g_timeout_add_seconds(crash_autoreload_delay, crashed_web_view_reload,
363 crashed_web_view_reload(gpointer data)
365 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(data));
367 return G_SOURCE_REMOVE;
371 decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision,
372 WebKitPolicyDecisionType type, gpointer data)
374 WebKitResponsePolicyDecision *r;
378 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
379 r = WEBKIT_RESPONSE_POLICY_DECISION(decision);
380 if (!webkit_response_policy_decision_is_mime_type_supported(r))
381 webkit_policy_decision_download(decision);
383 webkit_policy_decision_use(decision);
386 /* Use whatever default there is. */
393 download_handle_start(WebKitWebView *web_view, WebKitDownload *download,
396 g_signal_connect(G_OBJECT(download), "decide-destination",
397 G_CALLBACK(download_handle), data);
401 download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer data)
403 gchar *path, *path2 = NULL, *uri;
407 path = g_build_filename(download_dir, suggested_filename, NULL);
408 path2 = g_strdup(path);
409 while (g_file_test(path2, G_FILE_TEST_EXISTS) && suffix < 1000)
413 path2 = g_strdup_printf("%s.%d", path, suffix);
419 fprintf(stderr, __NAME__": Suffix reached limit for download.\n");
420 webkit_download_cancel(download);
424 uri = g_filename_to_uri(path2, NULL, NULL);
425 webkit_download_set_destination(download, uri);
428 tb = gtk_tool_button_new(NULL, NULL);
429 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(tb), "gtk-delete");
430 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), suggested_filename);
431 gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0);
432 gtk_widget_show_all(dm.win);
434 g_signal_connect(G_OBJECT(download), "notify::estimated-progress",
435 G_CALLBACK(changed_download_progress), tb);
437 g_object_ref(download);
438 g_signal_connect(G_OBJECT(tb), "clicked",
439 G_CALLBACK(downloadmanager_cancel), download);
445 /* Propagate -- to whom it may concern. */
450 downloadmanager_cancel(GtkToolButton *tb, gpointer data)
452 WebKitDownload *download = WEBKIT_DOWNLOAD(data);
454 webkit_download_cancel(download);
455 g_object_unref(download);
457 gtk_widget_destroy(GTK_WIDGET(tb));
461 downloadmanager_setup(void)
463 dm.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
464 gtk_window_set_type_hint(GTK_WINDOW(dm.win), GDK_WINDOW_TYPE_HINT_DIALOG);
465 gtk_window_set_default_size(GTK_WINDOW(dm.win), 500, 250);
466 gtk_window_set_title(GTK_WINDOW(dm.win), __NAME__" - Download Manager");
467 g_signal_connect(G_OBJECT(dm.win), "delete-event",
468 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
469 g_signal_connect(G_OBJECT(dm.win), "key-press-event",
470 G_CALLBACK(key_downloadmanager), NULL);
472 dm.toolbar = gtk_toolbar_new();
473 gtk_orientable_set_orientation(GTK_ORIENTABLE(dm.toolbar),
474 GTK_ORIENTATION_VERTICAL);
475 gtk_toolbar_set_style(GTK_TOOLBAR(dm.toolbar), GTK_TOOLBAR_BOTH_HORIZ);
476 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(dm.toolbar), FALSE);
478 dm.scroll = gtk_scrolled_window_new(NULL, NULL);
479 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dm.scroll),
480 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
481 gtk_container_add(GTK_CONTAINER(dm.scroll), dm.toolbar);
483 gtk_container_add(GTK_CONTAINER(dm.win), dm.scroll);
487 ensure_uri_scheme(const gchar *t)
491 f = g_ascii_strdown(t, -1);
492 if (!g_str_has_prefix(f, "http:") &&
493 !g_str_has_prefix(f, "https:") &&
494 !g_str_has_prefix(f, "file:") &&
495 !g_str_has_prefix(f, "about:"))
498 f = g_strdup_printf("http://%s", t);
506 grab_environment_configuration(void)
510 e = g_getenv(__NAME_UPPERCASE__"_ACCEPTED_LANGUAGE");
512 accepted_language[0] = g_strdup(e);
514 e = g_getenv(__NAME_UPPERCASE__"_CRASH_AUTORELOAD_DELAY");
516 crash_autoreload_delay = atoi(e);
518 e = g_getenv(__NAME_UPPERCASE__"_DOWNLOAD_DIR");
520 download_dir = g_strdup(e);
522 e = g_getenv(__NAME_UPPERCASE__"_FIFO_SUFFIX");
524 fifo_suffix = g_strdup(e);
526 e = g_getenv(__NAME_UPPERCASE__"_HOME_URI");
528 home_uri = g_strdup(e);
530 e = g_getenv(__NAME_UPPERCASE__"_USER_AGENT");
532 user_agent = g_strdup(e);
534 e = g_getenv(__NAME_UPPERCASE__"_WEB_EXTENSIONS_DIR");
536 web_extensions_dir = g_strdup(e);
538 web_extensions_dir = g_build_filename(g_get_user_data_dir(), __NAME__,
539 "web_extensions", NULL);
541 e = g_getenv(__NAME_UPPERCASE__"_ZOOM");
543 global_zoom = atof(e);
547 hover_web_view(WebKitWebView *web_view, WebKitHitTestResult *ht, guint modifiers,
550 struct Client *c = (struct Client *)data;
552 if (!gtk_widget_is_focus(c->location))
554 if (webkit_hit_test_result_context_is_link(ht))
556 gtk_entry_set_text(GTK_ENTRY(c->location),
557 webkit_hit_test_result_get_link_uri(ht));
559 if (c->hover_uri != NULL)
560 g_free(c->hover_uri);
561 c->hover_uri = g_strdup(webkit_hit_test_result_get_link_uri(ht));
565 gtk_entry_set_text(GTK_ENTRY(c->location),
566 webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)));
568 if (c->hover_uri != NULL)
569 g_free(c->hover_uri);
576 key_downloadmanager(GtkWidget *widget, GdkEvent *event, gpointer data)
578 if (event->type == GDK_KEY_PRESS)
580 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
582 switch (((GdkEventKey *)event)->keyval)
584 case GDK_KEY_d: /* close window (left hand) */
585 gtk_widget_hide(dm.win);
595 key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
597 struct Client *c = (struct Client *)data;
600 WebKitWebContext *wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
602 if (event->type == GDK_KEY_PRESS)
604 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
606 switch (((GdkEventKey *)event)->keyval)
608 case GDK_KEY_q: /* close window (left hand) */
609 gtk_widget_destroy(c->win);
611 case GDK_KEY_d: /* download manager (left hand) */
612 gtk_widget_show_all(dm.win);
614 case GDK_KEY_r: /* reload (left hand) */
615 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
618 case GDK_KEY_k: /* initiate search (BOTH hands) */
619 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
620 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
622 case GDK_KEY_c: /* reload trusted certs (left hand) */
623 trust_user_certs(wc);
629 switch (((GdkEventKey *)event)->keyval)
632 gtk_widget_grab_focus(c->web_view);
633 t = gtk_entry_get_text(GTK_ENTRY(c->location));
634 if (t != NULL && t[0] == '/')
636 if (search_text != NULL)
638 search_text = g_strdup(t + 1); /* XXX whacky */
641 else if (!keywords_try_search(WEBKIT_WEB_VIEW(c->web_view), t))
643 f = ensure_uri_scheme(t);
644 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
649 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
650 gtk_entry_set_text(GTK_ENTRY(c->location),
651 (t == NULL ? __NAME__ : t));
661 key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
663 struct Client *c = (struct Client *)data;
667 WebKitWebContext *wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
669 if (event->type == GDK_KEY_PRESS)
671 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
673 switch (((GdkEventKey *)event)->keyval)
675 case GDK_KEY_q: /* close window (left hand) */
676 gtk_widget_destroy(c->win);
678 case GDK_KEY_w: /* home (left hand) */
679 f = ensure_uri_scheme(home_uri);
680 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
683 case GDK_KEY_e: /* new tab (left hand) */
684 f = ensure_uri_scheme(home_uri);
688 case GDK_KEY_r: /* reload (left hand) */
689 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
692 case GDK_KEY_d: /* download manager (left hand) */
693 gtk_widget_show_all(dm.win);
695 case GDK_KEY_2: /* search forward (left hand) */
696 case GDK_KEY_n: /* search forward (maybe both hands) */
699 case GDK_KEY_3: /* search backward (left hand) */
702 case GDK_KEY_l: /* location (BOTH hands) */
703 gtk_widget_grab_focus(c->location);
705 case GDK_KEY_k: /* initiate search (BOTH hands) */
706 gtk_widget_grab_focus(c->location);
707 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
708 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
710 case GDK_KEY_c: /* reload trusted certs (left hand) */
711 trust_user_certs(wc);
715 else if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape)
717 webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(c->web_view));
718 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
721 else if (event->type == GDK_BUTTON_PRESS)
723 switch (((GdkEventButton *)event)->button)
726 if (c->hover_uri != NULL)
728 client_new(c->hover_uri);
733 webkit_web_view_go_back(WEBKIT_WEB_VIEW(c->web_view));
736 webkit_web_view_go_forward(WEBKIT_WEB_VIEW(c->web_view));
740 else if (event->type == GDK_SCROLL)
742 if (((GdkEventScroll *)event)->state & GDK_MOD1_MASK ||
743 ((GdkEventScroll *)event)->state & GDK_CONTROL_MASK)
745 gdk_event_get_scroll_deltas(event, &dx, &dy);
746 z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
748 z = dx != 0 ? global_zoom : z;
749 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
761 GIOChannel *channel = NULL;
762 gchar *path = NULL, *buf = NULL;
763 gchar **tokens = NULL;
765 keywords = g_hash_table_new(g_str_hash, g_str_equal);
767 path = g_build_filename(g_get_user_config_dir(), __NAME__, "keywordsearch",
769 channel = g_io_channel_new_file(path, "r", &err);
772 while (g_io_channel_read_line(channel, &buf, NULL, NULL, NULL)
773 == G_IO_STATUS_NORMAL)
778 tokens = g_strsplit(buf, " ", 2);
779 if (tokens[0] != NULL && tokens[1] != NULL)
780 g_hash_table_insert(keywords, g_strdup(tokens[0]),
781 g_strdup(tokens[1]));
786 g_io_channel_shutdown(channel, FALSE, NULL);
792 keywords_try_search(WebKitWebView *web_view, const gchar *t)
794 gboolean ret = FALSE;
795 gchar **tokens = NULL;
796 gchar *val = NULL, *uri = NULL;
798 tokens = g_strsplit(t, " ", 2);
799 if (tokens[0] != NULL && tokens[1] != NULL)
801 val = g_hash_table_lookup(keywords, tokens[0]);
804 uri = g_strdup_printf((gchar *)val, tokens[1]);
805 webkit_web_view_load_uri(web_view, uri);
816 remote_msg(GIOChannel *channel, GIOCondition condition, gpointer data)
820 g_io_channel_read_line(channel, &uri, NULL, NULL, NULL);
831 search(gpointer data, gint direction)
833 struct Client *c = (struct Client *)data;
834 WebKitWebView *web_view = WEBKIT_WEB_VIEW(c->web_view);
835 WebKitFindController *fc = webkit_web_view_get_find_controller(web_view);
837 if (search_text == NULL)
843 webkit_find_controller_search(fc, search_text,
844 WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
845 WEBKIT_FIND_OPTIONS_WRAP_AROUND,
849 webkit_find_controller_search_next(fc);
852 webkit_find_controller_search_previous(fc);
861 GIOChannel *tabbed_stdout_channel;
863 gchar *output = NULL;
864 char *argv[] = { "tabbed", "-c", "-d", "-p", "s1", "-n", __NAME__, NULL };
867 if (!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
868 NULL, NULL, NULL, &tabbed_stdout, NULL,
871 fprintf(stderr, __NAME__": Could not launch tabbed: %s\n", err->message);
876 tabbed_stdout_channel = g_io_channel_unix_new(tabbed_stdout);
877 if (tabbed_stdout_channel == NULL)
879 fprintf(stderr, __NAME__": Could open tabbed's stdout\n");
882 g_io_channel_read_line(tabbed_stdout_channel, &output, NULL, NULL, NULL);
883 g_io_channel_shutdown(tabbed_stdout_channel, FALSE, NULL);
886 fprintf(stderr, __NAME__": Could not read XID from tabbed\n");
890 plug_into = strtol(output, NULL, 16);
893 fprintf(stderr, __NAME__": The XID from tabbed is 0\n");
898 trust_user_certs(WebKitWebContext *wc)
900 GTlsCertificate *cert;
901 const gchar *basedir, *file, *absfile;
904 basedir = g_build_filename(g_get_user_config_dir(), __NAME__, "certs", NULL);
905 dir = g_dir_open(basedir, 0, NULL);
908 file = g_dir_read_name(dir);
911 absfile = g_build_filename(g_get_user_config_dir(), __NAME__, "certs",
913 cert = g_tls_certificate_new_from_file(absfile, NULL);
915 fprintf(stderr, __NAME__": Could not load trusted cert '%s'\n", file);
917 webkit_web_context_allow_tls_certificate_for_host(wc, cert, file);
918 file = g_dir_read_name(dir);
926 main(int argc, char **argv)
930 gtk_init(&argc, &argv);
932 grab_environment_configuration();
934 while ((opt = getopt(argc, argv, "e:CT")) != -1)
939 embed = atol(optarg);
940 tabbed_automagic = FALSE;
943 cooperative_instances = FALSE;
946 tabbed_automagic = FALSE;
949 fprintf(stderr, "Usage: "__NAME__" [OPTION]... [URI]...\n");
955 if (cooperative_instances)
957 downloadmanager_setup();
959 if (tabbed_automagic && !(cooperative_instances && !cooperative_alone))
960 embed = tabbed_launch();
962 if (!cooperative_instances || cooperative_alone)
963 webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(),
967 client_new(home_uri);
970 for (i = optind; i < argc; i++)
974 if (!cooperative_instances || cooperative_alone)