2 * Copyright (c) 2011 Conformal Systems LLC <info@conformal.com>
3 * Copyright (c) 2011 Marco Peereboom <marco@peereboom.us>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 inspector_attach_window(WebKitWebInspector
*inspector
, struct tab
*t
)
23 DNPRINTF(XT_D_INSPECTOR
, "%s: tab %d\n", __func__
, t
->tab_id
);
25 return (FALSE
); /* NOT handled */
29 inspector_close_window(WebKitWebInspector
*inspector
, struct tab
*t
)
31 DNPRINTF(XT_D_INSPECTOR
, "%s: tab %d\n", __func__
, t
->tab_id
);
33 if (t
->inspector_window
) {
34 gtk_widget_hide(t
->inspector_window
);
35 return (TRUE
); /* handled */
38 return (FALSE
); /* NOT handled */
42 inspector_detach_window(WebKitWebInspector
*inspector
, struct tab
*t
)
44 DNPRINTF(XT_D_INSPECTOR
, "%s: tab %d\n", __func__
, t
->tab_id
);
46 return (FALSE
); /* NOT handled */
50 inspector_delete(GtkWidget
*inspector_window
, GdkEvent
*e
, struct tab
*t
)
52 inspector_close_window(t
->inspector
, t
);
54 return (TRUE
); /* handled */
58 inspector_inspect_web_view_cb(WebKitWebInspector
*inspector
, WebKitWebView
* wv
,
61 DNPRINTF(XT_D_INSPECTOR
, "%s: tab %d\n", __func__
, t
->tab_id
);
63 if (t
->inspector_window
)
66 t
->inspector_window
= create_window("inspector");
67 t
->inspector_view
= webkit_web_view_new();
68 gtk_container_add(GTK_CONTAINER(t
->inspector_window
), t
->inspector_view
);
70 g_signal_connect(t
->inspector_window
,
71 "delete-event", G_CALLBACK(inspector_delete
), t
);
73 return WEBKIT_WEB_VIEW(t
->inspector_view
);
77 inspector_show_window(WebKitWebInspector
*inspector
, struct tab
*t
)
79 DNPRINTF(XT_D_INSPECTOR
, "%s: tab %d\n", __func__
, t
->tab_id
);
81 if (t
->inspector_window
) {
82 g_signal_emit_by_name(inspector
, "attach-window", t
, NULL
);
83 gtk_widget_show_all(t
->inspector_window
);
84 gtk_window_present(GTK_WINDOW(t
->inspector_window
));
85 return (TRUE
); /* handled */
88 return (FALSE
); /* NOT handled */
92 inspector_finished(WebKitWebInspector
*inspector
, struct tab
*t
)
94 DNPRINTF(XT_D_INSPECTOR
, "%s: tab %d\n", __func__
, t
->tab_id
);
96 if (t
->inspector_window
) {
97 g_signal_handlers_disconnect_by_func(
98 t
->inspector
, inspector_attach_window
, t
);
99 g_signal_handlers_disconnect_by_func(
100 t
->inspector
, inspector_close_window
, t
);
101 g_signal_handlers_disconnect_by_func(
102 t
->inspector
, inspector_detach_window
, t
);
103 g_signal_handlers_disconnect_by_func(
104 t
->inspector
, inspector_finished
, t
);
105 g_signal_handlers_disconnect_by_func(
106 t
->inspector
, inspector_inspect_web_view_cb
, t
);
107 g_signal_handlers_disconnect_by_func(
108 t
->inspector
, inspector_show_window
, t
);
110 gtk_widget_hide(t
->inspector_window
);
112 /* XXX it seems that the window is disposed automatically */
113 t
->inspector_window
= NULL
;
114 t
->inspector_view
= NULL
;
119 setup_inspector(struct tab
*t
)
122 DNPRINTF(XT_D_INSPECTOR
, "%s: tab %d\n", __func__
, t
->tab_id
);
124 t
->inspector
= webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(t
->wv
));
125 g_object_connect(G_OBJECT(t
->inspector
),
126 "signal::attach-window", G_CALLBACK(inspector_attach_window
), t
,
127 "signal::close-window", G_CALLBACK(inspector_close_window
), t
,
128 "signal::detach-window", G_CALLBACK(inspector_detach_window
), t
,
129 "signal::finished", G_CALLBACK(inspector_finished
), t
,
130 "signal::inspect-web-view", G_CALLBACK(inspector_inspect_web_view_cb
), t
,
131 "signal::show-window", G_CALLBACK(inspector_show_window
), t
,
137 inspector_cmd(struct tab
*t
, struct karg
*args
)
139 DNPRINTF(XT_D_INSPECTOR
, "%s: tab %d\n", __func__
, t
->tab_id
);
144 if (args
->i
& XT_INS_SHOW
)
145 webkit_web_inspector_show(t
->inspector
);
146 else if (args
->i
& XT_INS_HIDE
)
147 webkit_web_inspector_close(t
->inspector
);
148 else if (args
->i
& XT_INS_CLOSE
)
149 inspector_finished(t
->inspector
, t
);
151 return (XT_CB_PASSTHROUGH
);