File: inspector.c

package info (click to toggle)
xombrero 2%3A1.6.4-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,860 kB
  • ctags: 2,631
  • sloc: ansic: 17,051; makefile: 465; perl: 387; sh: 120
file content (152 lines) | stat: -rw-r--r-- 4,567 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
 * Copyright (c) 2011 Conformal Systems LLC <info@conformal.com>
 * Copyright (c) 2011 Marco Peereboom <marco@peereboom.us>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <xombrero.h>

gboolean
inspector_attach_window(WebKitWebInspector *inspector, struct tab *t)
{
	DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);

	return (FALSE); /* NOT handled */
}

gboolean
inspector_close_window(WebKitWebInspector *inspector, struct tab *t)
{
	DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);

	if (t->inspector_window) {
		gtk_widget_hide(t->inspector_window);
		return (TRUE); /* handled */
	}

	return (FALSE); /* NOT handled */
}

gboolean
inspector_detach_window(WebKitWebInspector *inspector, struct tab *t)
{
	DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);

	return (FALSE); /* NOT handled */
}

gboolean
inspector_delete(GtkWidget *inspector_window, GdkEvent *e, struct tab *t)
{
	inspector_close_window(t->inspector, t);

	return (TRUE); /* handled */
}

WebKitWebView*
inspector_inspect_web_view_cb(WebKitWebInspector *inspector, WebKitWebView* wv,
    struct tab *t)
{
	DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);

	if (t->inspector_window)
		goto done;

	t->inspector_window = create_window("inspector");
	t->inspector_view = webkit_web_view_new();
	gtk_container_add(GTK_CONTAINER(t->inspector_window), t->inspector_view);

	g_signal_connect(t->inspector_window,
	    "delete-event", G_CALLBACK(inspector_delete), t);
done:
	return WEBKIT_WEB_VIEW(t->inspector_view);
}

gboolean
inspector_show_window(WebKitWebInspector *inspector, struct tab *t)
{
	DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);

	if (t->inspector_window) {
		g_signal_emit_by_name(inspector, "attach-window", t, NULL);
		gtk_widget_show_all(t->inspector_window);
		gtk_window_present(GTK_WINDOW(t->inspector_window));
		return (TRUE); /* handled */
	}

	return (FALSE); /* NOT handled */
}

void
inspector_finished(WebKitWebInspector *inspector, struct tab *t)
{
	DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);

	if (t->inspector_window) {
		g_signal_handlers_disconnect_by_func(
		    t->inspector, inspector_attach_window, t);
		g_signal_handlers_disconnect_by_func(
		    t->inspector, inspector_close_window, t);
		g_signal_handlers_disconnect_by_func(
		    t->inspector, inspector_detach_window, t);
		g_signal_handlers_disconnect_by_func(
		    t->inspector, inspector_finished, t);
		g_signal_handlers_disconnect_by_func(
		    t->inspector, inspector_inspect_web_view_cb, t);
		g_signal_handlers_disconnect_by_func(
		    t->inspector, inspector_show_window, t);

		gtk_widget_hide(t->inspector_window);

		/* XXX it seems that the window is disposed automatically */
		t->inspector_window = NULL;
		t->inspector_view = NULL;
	}
}

void
setup_inspector(struct tab *t)
{

	DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);

	t->inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(t->wv));
	g_object_connect(G_OBJECT(t->inspector),
	    "signal::attach-window", G_CALLBACK(inspector_attach_window), t,
	    "signal::close-window", G_CALLBACK(inspector_close_window), t,
	    "signal::detach-window", G_CALLBACK(inspector_detach_window), t,
	    "signal::finished", G_CALLBACK(inspector_finished), t,
	    "signal::inspect-web-view", G_CALLBACK(inspector_inspect_web_view_cb), t,
	    "signal::show-window", G_CALLBACK(inspector_show_window), t,
	    (char *)NULL);

}

int
inspector_cmd(struct tab *t, struct karg *args)
{
	DNPRINTF(XT_D_INSPECTOR, "%s: tab %d\n", __func__, t->tab_id);

	if (t == NULL)
		return (1);

	if (args->i & XT_INS_SHOW)
		webkit_web_inspector_show(t->inspector);
	else if (args->i & XT_INS_HIDE)
		webkit_web_inspector_close(t->inspector);
	else if (args->i & XT_INS_CLOSE)
		inspector_finished(t->inspector, t);

	return (XT_CB_PASSTHROUGH);
}