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 decide_policy(WebKitWebView *, WebKitPolicyDecision *,
26 WebKitPolicyDecisionType, gpointer);
27 static gboolean download_handle(WebKitDownload *, gchar *, gpointer);
28 static void download_handle_start(WebKitWebView *, WebKitDownload *, gpointer);
29 static void downloadmanager_cancel(GtkToolButton *, gpointer data);
30 static void downloadmanager_setup(void);
31 static gchar *ensure_uri_scheme(const gchar *);
32 static void grab_environment_configuration(void);
33 static void hover_web_view(WebKitWebView *, WebKitHitTestResult *, guint, gpointer);
34 static gboolean key_downloadmanager(GtkWidget *, GdkEvent *, gpointer);
35 static gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
36 static gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
37 static void keywords_load(void);
38 static gboolean keywords_try_search(WebKitWebView *, const gchar *);
39 static gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
40 static void search(gpointer, gint);
41 static Window tabbed_launch(void);
42 static void usage(void);
57 struct DownloadManager
65 static const gchar *accepted_language[2] = { NULL, NULL };
66 static gint clients = 0;
67 static gboolean cooperative_alone = TRUE;
68 static gboolean cooperative_instances = TRUE;
69 static int cooperative_pipe_fp = 0;
70 static gchar *download_dir = "/tmp";
71 static Window embed = 0;
72 static gchar *fifo_suffix = "main";
73 static gdouble global_zoom = 1.0;
74 static gchar *home_uri = "about:blank";
75 static gboolean initial_wc_setup_done = FALSE;
76 static GHashTable *keywords = NULL;
77 static gchar *search_text = NULL;
78 static gboolean tabbed_automagic = TRUE;
79 static gchar *user_agent = NULL;
80 static gchar *web_extensions_dir = NULL;
84 client_destroy(GtkWidget *obj, gpointer data)
86 struct Client *c = (struct Client *)data;
88 g_signal_handlers_disconnect_by_func(G_OBJECT(c->web_view),
89 changed_load_progress, c);
99 client_destroy_request(WebKitWebView *web_view, gpointer data)
101 struct Client *c = (struct Client *)data;
103 gtk_widget_destroy(c->win);
109 client_new(const gchar *uri)
112 WebKitWebContext *wc;
115 if (uri != NULL && cooperative_instances && !cooperative_alone)
117 write(cooperative_pipe_fp, uri, strlen(uri));
118 write(cooperative_pipe_fp, "\n", 1);
122 c = malloc(sizeof(struct Client));
125 fprintf(stderr, __NAME__": fatal: malloc failed\n");
133 c->win = gtk_plug_new(embed);
134 if (!gtk_plug_get_embedded(GTK_PLUG(c->win)))
136 fprintf(stderr, __NAME__": Can't plug-in to XID %ld.\n", embed);
137 gtk_widget_destroy(c->win);
145 c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
146 gtk_window_set_wmclass(GTK_WINDOW(c->win), __NAME__, __NAME_CAPITALIZED__);
149 g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(client_destroy), c);
150 gtk_window_set_title(GTK_WINDOW(c->win), __NAME__);
152 c->web_view = webkit_web_view_new();
153 wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
155 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), global_zoom);
156 g_signal_connect(G_OBJECT(c->web_view), "notify::title",
157 G_CALLBACK(changed_title), c);
158 g_signal_connect(G_OBJECT(c->web_view), "notify::uri",
159 G_CALLBACK(changed_uri), c);
160 g_signal_connect(G_OBJECT(c->web_view), "notify::estimated-load-progress",
161 G_CALLBACK(changed_load_progress), c);
162 g_signal_connect(G_OBJECT(c->web_view), "create",
163 G_CALLBACK(client_new_request), NULL);
164 g_signal_connect(G_OBJECT(c->web_view), "close",
165 G_CALLBACK(client_destroy_request), c);
166 g_signal_connect(G_OBJECT(c->web_view), "decide-policy",
167 G_CALLBACK(decide_policy), NULL);
168 g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
169 G_CALLBACK(key_web_view), c);
170 g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
171 G_CALLBACK(key_web_view), c);
172 g_signal_connect(G_OBJECT(c->web_view), "scroll-event",
173 G_CALLBACK(key_web_view), c);
174 g_signal_connect(G_OBJECT(c->web_view), "mouse-target-changed",
175 G_CALLBACK(hover_web_view), c);
177 if (!initial_wc_setup_done)
179 if (accepted_language[0] != NULL)
180 webkit_web_context_set_preferred_languages(wc, accepted_language);
182 g_signal_connect(G_OBJECT(wc), "download-started",
183 G_CALLBACK(download_handle_start), NULL);
185 initial_wc_setup_done = TRUE;
188 if (user_agent != NULL)
189 g_object_set(G_OBJECT(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view))),
190 "user-agent", user_agent, NULL);
192 c->scroll = gtk_scrolled_window_new(NULL, NULL);
194 gtk_container_add(GTK_CONTAINER(c->scroll), c->web_view);
196 c->location = gtk_entry_new();
197 g_signal_connect(G_OBJECT(c->location), "key-press-event",
198 G_CALLBACK(key_location), c);
200 /* XXX Progress bars don't work/look as intended anymore. Level bars
201 * are a dirty workaround (kind of). */
202 c->progress = gtk_level_bar_new();
203 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
204 gtk_widget_set_size_request(c->progress, 100, -1);
206 c->top_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
207 gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 2);
208 gtk_box_pack_start(GTK_BOX(c->top_box), c->progress, FALSE, FALSE, 2);
210 c->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
211 gtk_box_pack_start(GTK_BOX(c->vbox), c->top_box, FALSE, FALSE, 2);
212 gtk_box_pack_start(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 2);
214 gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
216 gtk_widget_grab_focus(c->web_view);
217 gtk_widget_show_all(c->win);
221 f = ensure_uri_scheme(uri);
222 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
228 return WEBKIT_WEB_VIEW(c->web_view);
232 client_new_request(WebKitWebView *web_view,
233 WebKitNavigationAction *navigation_action, gpointer data)
235 return client_new(NULL);
239 cooperation_setup(void)
242 gchar *fifofilename, *fifopath;
244 fifofilename = g_strdup_printf("%s-%s", __NAME__".fifo", fifo_suffix);
245 fifopath = g_build_filename(g_get_user_runtime_dir(), fifofilename, NULL);
246 g_free(fifofilename);
248 if (!g_file_test(fifopath, G_FILE_TEST_EXISTS))
249 mkfifo(fifopath, 0600);
251 cooperative_pipe_fp = open(fifopath, O_WRONLY | O_NONBLOCK);
252 if (!cooperative_pipe_fp)
254 fprintf(stderr, __NAME__": Can't open FIFO at all.\n");
258 if (write(cooperative_pipe_fp, "", 0) == -1)
260 /* Could not do an empty write to the FIFO which means there's
261 * no one listening. */
262 close(cooperative_pipe_fp);
263 towatch = g_io_channel_new_file(fifopath, "r+", NULL);
264 g_io_add_watch(towatch, G_IO_IN, (GIOFunc)remote_msg, NULL);
267 cooperative_alone = FALSE;
274 changed_download_progress(GObject *obj, GParamSpec *pspec, gpointer data)
276 WebKitDownload *download = WEBKIT_DOWNLOAD(obj);
277 WebKitURIResponse *resp;
278 GtkToolItem *tb = GTK_TOOL_ITEM(data);
281 gchar *t, *filename, *base;
283 p = webkit_download_get_estimated_progress(download) * 100;
284 resp = webkit_download_get_response(download);
285 size_mb = webkit_uri_response_get_content_length(resp) / 1e6;
287 uri = webkit_download_get_destination(download);
288 filename = g_filename_from_uri(uri, NULL, NULL);
289 if (filename == NULL)
291 /* This really should not happen because WebKit uses that URI to
292 * write to a file... */
293 fprintf(stderr, __NAME__": Could not construct file name from URI!\n");
294 t = g_strdup_printf("%s (%.0f%% of %.1f MB)",
295 webkit_uri_response_get_uri(resp), p, size_mb);
299 base = g_path_get_basename(filename);
300 t = g_strdup_printf("%s (%.0f%% of %.1f MB)", base, p, size_mb);
304 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), t);
309 changed_load_progress(GObject *obj, GParamSpec *pspec, gpointer data)
311 struct Client *c = (struct Client *)data;
314 p = webkit_web_view_get_estimated_load_progress(WEBKIT_WEB_VIEW(c->web_view));
315 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), p);
319 changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
322 struct Client *c = (struct Client *)data;
324 t = webkit_web_view_get_title(WEBKIT_WEB_VIEW(c->web_view));
325 gtk_window_set_title(GTK_WINDOW(c->win), (t == NULL ? __NAME__ : t));
329 changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
332 struct Client *c = (struct Client *)data;
334 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
335 gtk_entry_set_text(GTK_ENTRY(c->location), (t == NULL ? __NAME__ : t));
339 decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision,
340 WebKitPolicyDecisionType type, gpointer data)
342 WebKitResponsePolicyDecision *r;
346 case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:
347 r = WEBKIT_RESPONSE_POLICY_DECISION(decision);
348 if (!webkit_response_policy_decision_is_mime_type_supported(r))
349 webkit_policy_decision_download(decision);
351 webkit_policy_decision_use(decision);
354 /* Use whatever default there is. */
361 download_handle_start(WebKitWebView *web_view, WebKitDownload *download,
364 g_signal_connect(G_OBJECT(download), "decide-destination",
365 G_CALLBACK(download_handle), data);
369 download_handle(WebKitDownload *download, gchar *suggested_filename, gpointer data)
371 gchar *path, *path2 = NULL, *uri;
375 path = g_build_filename(download_dir, suggested_filename, NULL);
376 path2 = g_strdup(path);
377 while (g_file_test(path2, G_FILE_TEST_EXISTS) && suffix < 1000)
381 path2 = g_strdup_printf("%s.%d", path, suffix);
387 fprintf(stderr, __NAME__": Suffix reached limit for download.\n");
388 webkit_download_cancel(download);
392 uri = g_filename_to_uri(path2, NULL, NULL);
393 webkit_download_set_destination(download, uri);
396 tb = gtk_tool_button_new(NULL, NULL);
397 gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(tb), "gtk-delete");
398 gtk_tool_button_set_label(GTK_TOOL_BUTTON(tb), suggested_filename);
399 gtk_toolbar_insert(GTK_TOOLBAR(dm.toolbar), tb, 0);
400 gtk_widget_show_all(dm.toolbar);
402 g_signal_connect(G_OBJECT(download), "notify::estimated-progress",
403 G_CALLBACK(changed_download_progress), tb);
405 g_object_ref(download);
406 g_signal_connect(G_OBJECT(tb), "clicked",
407 G_CALLBACK(downloadmanager_cancel), download);
413 /* Propagate -- to whom it may concern. */
418 downloadmanager_cancel(GtkToolButton *tb, gpointer data)
420 WebKitDownload *download = WEBKIT_DOWNLOAD(data);
422 webkit_download_cancel(download);
423 g_object_unref(download);
425 gtk_widget_destroy(GTK_WIDGET(tb));
429 downloadmanager_setup(void)
431 dm.win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
432 gtk_window_set_type_hint(GTK_WINDOW(dm.win), GDK_WINDOW_TYPE_HINT_DIALOG);
433 gtk_window_set_default_size(GTK_WINDOW(dm.win), 500, 250);
434 gtk_window_set_title(GTK_WINDOW(dm.win), __NAME__" - Download Manager");
435 g_signal_connect(G_OBJECT(dm.win), "delete-event",
436 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
437 g_signal_connect(G_OBJECT(dm.win), "key-press-event",
438 G_CALLBACK(key_downloadmanager), NULL);
440 dm.toolbar = gtk_toolbar_new();
441 gtk_orientable_set_orientation(GTK_ORIENTABLE(dm.toolbar),
442 GTK_ORIENTATION_VERTICAL);
443 gtk_toolbar_set_style(GTK_TOOLBAR(dm.toolbar), GTK_TOOLBAR_BOTH_HORIZ);
444 gtk_toolbar_set_show_arrow(GTK_TOOLBAR(dm.toolbar), FALSE);
446 dm.scroll = gtk_scrolled_window_new(NULL, NULL);
447 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(dm.scroll),
448 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
449 gtk_container_add(GTK_CONTAINER(dm.scroll), dm.toolbar);
451 gtk_container_add(GTK_CONTAINER(dm.win), dm.scroll);
455 ensure_uri_scheme(const gchar *t)
459 f = g_ascii_strdown(t, -1);
460 if (!g_str_has_prefix(f, "http:") &&
461 !g_str_has_prefix(f, "https:") &&
462 !g_str_has_prefix(f, "file:") &&
463 !g_str_has_prefix(f, "about:"))
466 f = g_strdup_printf("http://%s", t);
474 grab_environment_configuration(void)
478 e = g_getenv(__NAME_UPPERCASE__"_ACCEPTED_LANGUAGE");
480 accepted_language[0] = g_strdup(e);
482 e = g_getenv(__NAME_UPPERCASE__"_DOWNLOAD_DIR");
484 download_dir = g_strdup(e);
486 e = g_getenv(__NAME_UPPERCASE__"_FIFO_SUFFIX");
488 fifo_suffix = g_strdup(e);
490 e = g_getenv(__NAME_UPPERCASE__"_HOME_URI");
492 home_uri = g_strdup(e);
494 e = g_getenv(__NAME_UPPERCASE__"_USER_AGENT");
496 user_agent = g_strdup(e);
498 e = g_getenv(__NAME_UPPERCASE__"_WEB_EXTENSIONS_DIR");
500 web_extensions_dir = g_strdup(e);
502 web_extensions_dir = g_build_filename(g_get_user_data_dir(), __NAME__,
503 "web_extensions", NULL);
505 e = g_getenv(__NAME_UPPERCASE__"_ZOOM");
507 global_zoom = atof(e);
511 hover_web_view(WebKitWebView *web_view, WebKitHitTestResult *ht, guint modifiers,
514 struct Client *c = (struct Client *)data;
516 if (!gtk_widget_is_focus(c->location))
518 if (webkit_hit_test_result_context_is_link(ht))
520 gtk_entry_set_text(GTK_ENTRY(c->location),
521 webkit_hit_test_result_get_link_uri(ht));
523 if (c->hover_uri != NULL)
524 g_free(c->hover_uri);
525 c->hover_uri = g_strdup(webkit_hit_test_result_get_link_uri(ht));
529 gtk_entry_set_text(GTK_ENTRY(c->location),
530 webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view)));
532 if (c->hover_uri != NULL)
533 g_free(c->hover_uri);
540 key_downloadmanager(GtkWidget *widget, GdkEvent *event, gpointer data)
542 if (event->type == GDK_KEY_PRESS)
544 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
546 switch (((GdkEventKey *)event)->keyval)
548 case GDK_KEY_d: /* close window (left hand) */
549 gtk_widget_hide(dm.win);
559 key_location(GtkWidget *widget, GdkEvent *event, gpointer data)
561 struct Client *c = (struct Client *)data;
565 if (event->type == GDK_KEY_PRESS)
567 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
569 switch (((GdkEventKey *)event)->keyval)
571 case GDK_KEY_q: /* close window (left hand) */
572 gtk_widget_destroy(c->win);
574 case GDK_KEY_d: /* download manager (left hand) */
575 gtk_widget_show_all(dm.win);
577 case GDK_KEY_r: /* reload (left hand) */
578 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
581 case GDK_KEY_k: /* initiate search (BOTH hands) */
582 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
583 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
589 switch (((GdkEventKey *)event)->keyval)
592 gtk_widget_grab_focus(c->web_view);
593 t = gtk_entry_get_text(GTK_ENTRY(c->location));
594 if (t != NULL && t[0] == '/')
596 if (search_text != NULL)
598 search_text = g_strdup(t + 1); /* XXX whacky */
601 else if (!keywords_try_search(WEBKIT_WEB_VIEW(c->web_view), t))
603 f = ensure_uri_scheme(t);
604 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
609 t = webkit_web_view_get_uri(WEBKIT_WEB_VIEW(c->web_view));
610 gtk_entry_set_text(GTK_ENTRY(c->location),
611 (t == NULL ? __NAME__ : t));
621 key_web_view(GtkWidget *widget, GdkEvent *event, gpointer data)
623 struct Client *c = (struct Client *)data;
628 if (event->type == GDK_KEY_PRESS)
630 if (((GdkEventKey *)event)->state & GDK_MOD1_MASK)
632 switch (((GdkEventKey *)event)->keyval)
634 case GDK_KEY_q: /* close window (left hand) */
635 gtk_widget_destroy(c->win);
637 case GDK_KEY_w: /* home (left hand) */
638 f = ensure_uri_scheme(home_uri);
639 webkit_web_view_load_uri(WEBKIT_WEB_VIEW(c->web_view), f);
642 case GDK_KEY_e: /* new tab (left hand) */
643 f = ensure_uri_scheme(home_uri);
647 case GDK_KEY_r: /* reload (left hand) */
648 webkit_web_view_reload_bypass_cache(WEBKIT_WEB_VIEW(
651 case GDK_KEY_d: /* download manager (left hand) */
652 gtk_widget_show_all(dm.win);
654 case GDK_KEY_2: /* search forward (left hand) */
655 case GDK_KEY_n: /* search forward (maybe both hands) */
658 case GDK_KEY_3: /* search backward (left hand) */
661 case GDK_KEY_l: /* location (BOTH hands) */
662 gtk_widget_grab_focus(c->location);
664 case GDK_KEY_k: /* initiate search (BOTH hands) */
665 gtk_widget_grab_focus(c->location);
666 gtk_entry_set_text(GTK_ENTRY(c->location), "/");
667 gtk_editable_set_position(GTK_EDITABLE(c->location), -1);
671 else if (((GdkEventKey *)event)->keyval == GDK_KEY_Escape)
673 webkit_web_view_stop_loading(WEBKIT_WEB_VIEW(c->web_view));
674 gtk_level_bar_set_value(GTK_LEVEL_BAR(c->progress), 0);
677 else if (event->type == GDK_BUTTON_PRESS)
679 switch (((GdkEventButton *)event)->button)
682 if (c->hover_uri != NULL)
684 client_new(c->hover_uri);
689 webkit_web_view_go_back(WEBKIT_WEB_VIEW(c->web_view));
692 webkit_web_view_go_forward(WEBKIT_WEB_VIEW(c->web_view));
696 else if (event->type == GDK_SCROLL)
698 if (((GdkEventScroll *)event)->state & GDK_MOD1_MASK ||
699 ((GdkEventScroll *)event)->state & GDK_CONTROL_MASK)
701 gdk_event_get_scroll_deltas(event, &dx, &dy);
702 z = webkit_web_view_get_zoom_level(WEBKIT_WEB_VIEW(c->web_view));
704 z = dx != 0 ? global_zoom : z;
705 webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), z);
717 GIOChannel *channel = NULL;
718 gchar *path = NULL, *buf = NULL;
719 gchar **tokens = NULL;
721 keywords = g_hash_table_new(g_str_hash, g_str_equal);
723 path = g_build_filename(g_get_user_config_dir(), __NAME__, "keywordsearch",
725 channel = g_io_channel_new_file(path, "r", &err);
728 while (g_io_channel_read_line(channel, &buf, NULL, NULL, NULL)
729 == G_IO_STATUS_NORMAL)
734 tokens = g_strsplit(buf, " ", 2);
735 if (tokens[0] != NULL && tokens[1] != NULL)
736 g_hash_table_insert(keywords, g_strdup(tokens[0]),
737 g_strdup(tokens[1]));
742 g_io_channel_shutdown(channel, FALSE, NULL);
748 keywords_try_search(WebKitWebView *web_view, const gchar *t)
750 gboolean ret = FALSE;
751 gchar **tokens = NULL;
752 gchar *val = NULL, *uri = NULL;
754 tokens = g_strsplit(t, " ", 2);
755 if (tokens[0] != NULL && tokens[1] != NULL)
757 val = g_hash_table_lookup(keywords, tokens[0]);
760 uri = g_strdup_printf((gchar *)val, tokens[1]);
761 webkit_web_view_load_uri(web_view, uri);
772 remote_msg(GIOChannel *channel, GIOCondition condition, gpointer data)
776 g_io_channel_read_line(channel, &uri, NULL, NULL, NULL);
787 search(gpointer data, gint direction)
789 struct Client *c = (struct Client *)data;
790 WebKitWebView *web_view = WEBKIT_WEB_VIEW(c->web_view);
791 WebKitFindController *fc = webkit_web_view_get_find_controller(web_view);
793 if (search_text == NULL)
799 webkit_find_controller_search(fc, search_text,
800 WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE |
801 WEBKIT_FIND_OPTIONS_WRAP_AROUND,
805 webkit_find_controller_search_next(fc);
808 webkit_find_controller_search_previous(fc);
817 GIOChannel *tabbed_stdout_channel;
819 gchar *output = NULL;
820 char *argv[] = { "tabbed", "-c", "-d", "-p", "s1", "-n", __NAME__, NULL };
823 if (!g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL,
824 NULL, NULL, NULL, &tabbed_stdout, NULL,
827 fprintf(stderr, __NAME__": Could not launch tabbed: %s\n", err->message);
832 tabbed_stdout_channel = g_io_channel_unix_new(tabbed_stdout);
833 if (tabbed_stdout_channel == NULL)
835 fprintf(stderr, __NAME__": Could open tabbed's stdout\n");
838 g_io_channel_read_line(tabbed_stdout_channel, &output, NULL, NULL, NULL);
839 g_io_channel_shutdown(tabbed_stdout_channel, FALSE, NULL);
842 fprintf(stderr, __NAME__": Could not read XID from tabbed\n");
846 plug_into = strtol(output, NULL, 16);
849 fprintf(stderr, __NAME__": The XID from tabbed is 0\n");
856 fprintf(stderr, "Usage: "__NAME__" [OPTION]... [URI]...\n");
862 main(int argc, char **argv)
866 gtk_init(&argc, &argv);
868 grab_environment_configuration();
870 while ((opt = getopt(argc, argv, "e:CT")) != -1)
875 embed = atol(optarg);
876 tabbed_automagic = FALSE;
879 cooperative_instances = FALSE;
882 tabbed_automagic = FALSE;
891 downloadmanager_setup();
893 if (tabbed_automagic && !(cooperative_instances && !cooperative_alone))
894 embed = tabbed_launch();
896 if (!cooperative_instances || cooperative_alone)
897 webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(),
901 client_new(home_uri);
904 for (i = optind; i < argc; i++)
908 if (!cooperative_instances || cooperative_alone)