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 usage(void);
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 initial_wc_setup_done = TRUE;
193 if (user_agent != NULL)
194 g_object_set(G_OBJECT(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view))),
195 "user-agent", user_agent, NULL);
197 c->scroll = gtk_scrolled_window_new(NULL, NULL);
199 gtk_container_add(GTK_CONTAINER(c->scroll), c->web_view);
201 c->location = gtk_entry_new();
202 g_signal_connect(G_OBJECT(c->location), "key-press-event",
203 G_CALLBACK(key_location), c);
205 /* XXX Progress bars don't work/look as intended anymore. Level bars
206 * are a dirty workaround (kind of). */
207 c->progress = gtk_level_bar_new();
208 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
209 gtk_widget_set_size_request(c->progress, 100, -1);
211 c->top_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
212 gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 2);
213 gtk_box_pack_start(GTK_BOX(c->top_box), c->progress, FALSE, FALSE, 2);
215 c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
216 gtk_box_pack_start(GTK_BOX(c->vbox), c->top_box, FALSE, FALSE, 2);
217 gtk_box_pack_start(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 2);
219 gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
221 gtk_widget_grab_focus(c->web_view);
222 gtk_widget_show_all(c->win);
226 f = ensure_uri_scheme(uri);
227 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
233 return WEBKIT_WEB_VIEW(c->web_view);
237 client_new_request(WebKitWebView *web_view,
238 WebKitNavigationAction *navigation_action, gpointer data)
240 return client_new(NULL);
244 cooperation_setup(void)
247 gchar *fifofilename, *fifopath;
249 fifofilename = g_strdup_printf("%s-%s", __NAME__".fifo", fifo_suffix);
250 fifopath = g_build_filename(g_get_user_runtime_dir(), fifofilename, NULL);
251 g_free(fifofilename);
253 if (!g_file_test(fifopath, G_FILE_TEST_EXISTS))
254 mkfifo(fifopath, 0600);
256 cooperative_pipe_fp = open(fifopath, O_WRONLY | O_NONBLOCK);
257 if (!cooperative_pipe_fp)
259 fprintf(stderr, __NAME__": Can't open FIFO at all.\n");
263 if (write(cooperative_pipe_fp, "", 0) == -1)
265 /* Could not do an empty write to the FIFO which means there's
266 * no one listening. */
267 close(cooperative_pipe_fp);
268 towatch = g_io_channel_new_file(fifopath, "r+", NULL);
269 g_io_add_watch(towatch, G_IO_IN, (GIOFunc)remote_msg, NULL);
272 cooperative_alone = FALSE;
279 changed_download_progress(GObject *obj, GParamSpec *pspec, gpointer data)
281 WebKitDownload *download = WEBKIT_DOWNLOAD(obj);
282 WebKitURIResponse *resp;
283 GtkToolItem *tb = GTK_TOOL_ITEM(data);
286 gchar *t, *filename, *base;
288 p = webkit_download_get_estimated_progress(download) * 100;
289 resp = webkit_download_get_response(download);
290 size_mb = webkit_uri_response_get_content_length(resp) / 1e6;
292 uri = webkit_download_get_destination(download);
293 filename = g_filename_from_uri(uri, NULL, NULL);
294 if (filename == NULL)
296 /* This really should not happen because WebKit uses that URI to
297 * write to a file... */
298 fprintf(stderr, __NAME__": Could not construct file name from URI!\n");
299 t = g_strdup_printf("%s (%.0f%% of %.1f MB)",
300 webkit_uri_response_get_uri(resp), p, size_mb);
304 base = g_path_get_basename(filename);
305 t = g_strdup_printf("%s (%.0f%% of %.1f MB)", base, p, size_mb);
309 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), t);
314 changed_load_progress(GObject *obj, GParamSpec *pspec, gpointer data)
316 struct Client *c = (struct Client *)data;
319 p = webkit_web_view_get_estimated_load_progress(WEBKIT_WEB_VIEW(c->web_view));
320 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), p);
324 changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
327 struct Client *c = (struct Client *)data;
329 t = webkit_web_view_get_title(WEBKIT_WEB_VIEW(c->web_view));
330 gtk_window_set_title(GTK_WINDOW(c->win), (t == NULL ? __NAME__ : t));
334 changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
337 struct Client *c = (struct Client *)data;
339 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
340 gtk_entry_set_text(GTK_ENTRY(c->location), (t == NULL ? __NAME__ : t));
344 crashed_web_view(WebKitWebView *web_view, gpointer data)
346 fprintf(stderr, __NAME__": WebView crashed!\n");
347 if (crash_autoreload_delay >= 1)
349 fprintf(stderr, __NAME__": Reloading WebView in %d seconds.\n",
350 crash_autoreload_delay);
351 g_timeout_add_seconds(crash_autoreload_delay, crashed_web_view_reload,
359 crashed_web_view_reload(gpointer data)
361 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(data));
363 return G_SOURCE_REMOVE;
367 decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision,
368 WebKitPolicyDecisionType type, gpointer data)
370 WebKitResponsePolicyDecision *r;
374 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
375 r = WEBKIT_RESPONSE_POLICY_DECISION(decision);
376 if (!webkit_response_policy_decision_is_mime_type_supported(r))
377 webkit_policy_decision_download(decision);
379 webkit_policy_decision_use(decision);
382 /* Use whatever default there is. */
389 download_handle_start(WebKitWebView *web_view, WebKitDownload *download,
392 g_signal_connect(G_OBJECT(download), "decide-destination",
393 G_CALLBACK(download_handle), data);
397 download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer data)
399 gchar *path, *path2 = NULL, *uri;
403 path = g_build_filename(download_dir, suggested_filename, NULL);
404 path2 = g_strdup(path);
405 while (g_file_test(path2, G_FILE_TEST_EXISTS) && suffix < 1000)
409 path2 = g_strdup_printf("%s.%d", path, suffix);
415 fprintf(stderr, __NAME__": Suffix reached limit for download.\n");
416 webkit_download_cancel(download);
420 uri = g_filename_to_uri(path2, NULL, NULL);
421 webkit_download_set_destination(download, uri);
424 tb = gtk_tool_button_new(NULL, NULL);
425 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(tb), "gtk-delete");
426 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), suggested_filename);
427 gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0);
428 gtk_widget_show_all(dm.win);
430 g_signal_connect(G_OBJECT(download), "notify::estimated-progress",
431 G_CALLBACK(changed_download_progress), tb);
433 g_object_ref(download);
434 g_signal_connect(G_OBJECT(tb), "clicked",
435 G_CALLBACK(downloadmanager_cancel), download);
441 /* Propagate -- to whom it may concern. */
446 downloadmanager_cancel(GtkToolButton *tb, gpointer data)
448 WebKitDownload *download = WEBKIT_DOWNLOAD(data);
450 webkit_download_cancel(download);
451 g_object_unref(download);
453 gtk_widget_destroy(GTK_WIDGET(tb));
457 downloadmanager_setup(void)
459 dm.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
460 gtk_window_set_type_hint(GTK_WINDOW(dm.win), GDK_WINDOW_TYPE_HINT_DIALOG);
461 gtk_window_set_default_size(GTK_WINDOW(dm.win), 500, 250);
462 gtk_window_set_title(GTK_WINDOW(dm.win), __NAME__" - Download Manager");
463 g_signal_connect(G_OBJECT(dm.win), "delete-event",
464 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
465 g_signal_connect(G_OBJECT(dm.win), "key-press-event",
466 G_CALLBACK(key_downloadmanager), NULL);
468 dm.toolbar = gtk_toolbar_new();
469 gtk_orientable_set_orientation(GTK_ORIENTABLE(dm.toolbar),
470 GTK_ORIENTATION_VERTICAL);
471 gtk_toolbar_set_style(GTK_TOOLBAR(dm.toolbar), GTK_TOOLBAR_BOTH_HORIZ);
472 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(dm.toolbar), FALSE);
474 dm.scroll = gtk_scrolled_window_new(NULL, NULL);
475 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dm.scroll),
476 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
477 gtk_container_add(GTK_CONTAINER(dm.scroll), dm.toolbar);
479 gtk_container_add(GTK_CONTAINER(dm.win), dm.scroll);
483 ensure_uri_scheme(const gchar *t)
487 f = g_ascii_strdown(t, -1);
488 if (!g_str_has_prefix(f, "http:") &&
489 !g_str_has_prefix(f, "https:") &&
490 !g_str_has_prefix(f, "file:") &&
491 !g_str_has_prefix(f, "about:"))
494 f = g_strdup_printf("http://%s", t);
502 grab_environment_configuration(void)
506 e = g_getenv(__NAME_UPPERCASE__"_ACCEPTED_LANGUAGE");
508 accepted_language[0] = g_strdup(e);
510 e = g_getenv(__NAME_UPPERCASE__"_CRASH_AUTORELOAD_DELAY");
512 crash_autoreload_delay = atoi(e);
514 e = g_getenv(__NAME_UPPERCASE__"_DOWNLOAD_DIR");
516 download_dir = g_strdup(e);
518 e = g_getenv(__NAME_UPPERCASE__"_FIFO_SUFFIX");
520 fifo_suffix = g_strdup(e);
522 e = g_getenv(__NAME_UPPERCASE__"_HOME_URI");
524 home_uri = g_strdup(e);
526 e = g_getenv(__NAME_UPPERCASE__"_USER_AGENT");
528 user_agent = g_strdup(e);
530 e = g_getenv(__NAME_UPPERCASE__"_WEB_EXTENSIONS_DIR");
532 web_extensions_dir = g_strdup(e);
534 web_extensions_dir = g_build_filename(g_get_user_data_dir(), __NAME__,
535 "web_extensions", NULL);
537 e = g_getenv(__NAME_UPPERCASE__"_ZOOM");
539 global_zoom = atof(e);
543 hover_web_view(WebKitWebView *web_view, WebKitHitTestResult *ht, guint modifiers,
546 struct Client *c = (struct Client *)data;
548 if (!gtk_widget_is_focus(c->location))
550 if (webkit_hit_test_result_context_is_link(ht))
552 gtk_entry_set_text(GTK_ENTRY(c->location),
553 webkit_hit_test_result_get_link_uri(ht));
555 if (c->hover_uri != NULL)
556 g_free(c->hover_uri);
557 c->hover_uri = g_strdup(webkit_hit_test_result_get_link_uri(ht));
561 gtk_entry_set_text(GTK_ENTRY(c->location),
562 webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)));
564 if (c->hover_uri != NULL)
565 g_free(c->hover_uri);
572 key_downloadmanager(GtkWidget *widget, GdkEvent *event, gpointer data)
574 if (event->type == GDK_KEY_PRESS)
576 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
578 switch (((GdkEventKey *)event)->keyval)
580 case GDK_KEY_d: /* close window (left hand) */
581 gtk_widget_hide(dm.win);
591 key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
593 struct Client *c = (struct Client *)data;
597 if (event->type == GDK_KEY_PRESS)
599 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
601 switch (((GdkEventKey *)event)->keyval)
603 case GDK_KEY_q: /* close window (left hand) */
604 gtk_widget_destroy(c->win);
606 case GDK_KEY_d: /* download manager (left hand) */
607 gtk_widget_show_all(dm.win);
609 case GDK_KEY_r: /* reload (left hand) */
610 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
613 case GDK_KEY_k: /* initiate search (BOTH hands) */
614 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
615 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
621 switch (((GdkEventKey *)event)->keyval)
624 gtk_widget_grab_focus(c->web_view);
625 t = gtk_entry_get_text(GTK_ENTRY(c->location));
626 if (t != NULL && t[0] == '/')
628 if (search_text != NULL)
630 search_text = g_strdup(t + 1); /* XXX whacky */
633 else if (!keywords_try_search(WEBKIT_WEB_VIEW(c->web_view), t))
635 f = ensure_uri_scheme(t);
636 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
641 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
642 gtk_entry_set_text(GTK_ENTRY(c->location),
643 (t == NULL ? __NAME__ : t));
653 key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
655 struct Client *c = (struct Client *)data;
660 if (event->type == GDK_KEY_PRESS)
662 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
664 switch (((GdkEventKey *)event)->keyval)
666 case GDK_KEY_q: /* close window (left hand) */
667 gtk_widget_destroy(c->win);
669 case GDK_KEY_w: /* home (left hand) */
670 f = ensure_uri_scheme(home_uri);
671 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
674 case GDK_KEY_e: /* new tab (left hand) */
675 f = ensure_uri_scheme(home_uri);
679 case GDK_KEY_r: /* reload (left hand) */
680 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
683 case GDK_KEY_d: /* download manager (left hand) */
684 gtk_widget_show_all(dm.win);
686 case GDK_KEY_2: /* search forward (left hand) */
687 case GDK_KEY_n: /* search forward (maybe both hands) */
690 case GDK_KEY_3: /* search backward (left hand) */
693 case GDK_KEY_l: /* location (BOTH hands) */
694 gtk_widget_grab_focus(c->location);
696 case GDK_KEY_k: /* initiate search (BOTH hands) */
697 gtk_widget_grab_focus(c->location);
698 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
699 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
703 else if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape)
705 webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(c->web_view));
706 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
709 else if (event->type == GDK_BUTTON_PRESS)
711 switch (((GdkEventButton *)event)->button)
714 if (c->hover_uri != NULL)
716 client_new(c->hover_uri);
721 webkit_web_view_go_back(WEBKIT_WEB_VIEW(c->web_view));
724 webkit_web_view_go_forward(WEBKIT_WEB_VIEW(c->web_view));
728 else if (event->type == GDK_SCROLL)
730 if (((GdkEventScroll *)event)->state & GDK_MOD1_MASK ||
731 ((GdkEventScroll *)event)->state & GDK_CONTROL_MASK)
733 gdk_event_get_scroll_deltas(event, &dx, &dy);
734 z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
736 z = dx != 0 ? global_zoom : z;
737 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
749 GIOChannel *channel = NULL;
750 gchar *path = NULL, *buf = NULL;
751 gchar **tokens = NULL;
753 keywords = g_hash_table_new(g_str_hash, g_str_equal);
755 path = g_build_filename(g_get_user_config_dir(), __NAME__, "keywordsearch",
757 channel = g_io_channel_new_file(path, "r", &err);
760 while (g_io_channel_read_line(channel, &buf, NULL, NULL, NULL)
761 == G_IO_STATUS_NORMAL)
766 tokens = g_strsplit(buf, " ", 2);
767 if (tokens[0] != NULL && tokens[1] != NULL)
768 g_hash_table_insert(keywords, g_strdup(tokens[0]),
769 g_strdup(tokens[1]));
774 g_io_channel_shutdown(channel, FALSE, NULL);
780 keywords_try_search(WebKitWebView *web_view, const gchar *t)
782 gboolean ret = FALSE;
783 gchar **tokens = NULL;
784 gchar *val = NULL, *uri = NULL;
786 tokens = g_strsplit(t, " ", 2);
787 if (tokens[0] != NULL && tokens[1] != NULL)
789 val = g_hash_table_lookup(keywords, tokens[0]);
792 uri = g_strdup_printf((gchar *)val, tokens[1]);
793 webkit_web_view_load_uri(web_view, uri);
804 remote_msg(GIOChannel *channel, GIOCondition condition, gpointer data)
808 g_io_channel_read_line(channel, &uri, NULL, NULL, NULL);
819 search(gpointer data, gint direction)
821 struct Client *c = (struct Client *)data;
822 WebKitWebView *web_view = WEBKIT_WEB_VIEW(c->web_view);
823 WebKitFindController *fc = webkit_web_view_get_find_controller(web_view);
825 if (search_text == NULL)
831 webkit_find_controller_search(fc, search_text,
832 WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
833 WEBKIT_FIND_OPTIONS_WRAP_AROUND,
837 webkit_find_controller_search_next(fc);
840 webkit_find_controller_search_previous(fc);
849 GIOChannel *tabbed_stdout_channel;
851 gchar *output = NULL;
852 char *argv[] = { "tabbed", "-c", "-d", "-p", "s1", "-n", __NAME__, NULL };
855 if (!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
856 NULL, NULL, NULL, &tabbed_stdout, NULL,
859 fprintf(stderr, __NAME__": Could not launch tabbed: %s\n", err->message);
864 tabbed_stdout_channel = g_io_channel_unix_new(tabbed_stdout);
865 if (tabbed_stdout_channel == NULL)
867 fprintf(stderr, __NAME__": Could open tabbed's stdout\n");
870 g_io_channel_read_line(tabbed_stdout_channel, &output, NULL, NULL, NULL);
871 g_io_channel_shutdown(tabbed_stdout_channel, FALSE, NULL);
874 fprintf(stderr, __NAME__": Could not read XID from tabbed\n");
878 plug_into = strtol(output, NULL, 16);
881 fprintf(stderr, __NAME__": The XID from tabbed is 0\n");
888 fprintf(stderr, "Usage: "__NAME__" [OPTION]... [URI]...\n");
894 main(int argc, char **argv)
898 gtk_init(&argc, &argv);
900 grab_environment_configuration();
902 while ((opt = getopt(argc, argv, "e:CT")) != -1)
907 embed = atol(optarg);
908 tabbed_automagic = FALSE;
911 cooperative_instances = FALSE;
914 tabbed_automagic = FALSE;
923 downloadmanager_setup();
925 if (tabbed_automagic && !(cooperative_instances && !cooperative_alone))
926 embed = tabbed_launch();
928 if (!cooperative_instances || cooperative_alone)
929 webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(),
933 client_new(home_uri);
936 for (i = optind; i < argc; i++)
940 if (!cooperative_instances || cooperative_alone)