annotate pidgin/gtkwebview.c @ 32542:3bd8fb942ea4

Yep, tested, and changed some code from previous commit. This is a hard to test code, so I just hope it works flawlessly. :)
author tdrhq@soc.pidgin.im
date Mon, 10 Aug 2009 07:42:54 +0000
parents b89351c7580b
children 25d99f3621bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32526
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
1 /*
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
2 * @file gtkwebview.c GTK+ WebKitWebView wrapper class.
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
3 * @ingroup pidgin
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
4 */
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
5
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
6 /* pidgin
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
7 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
8 * Pidgin is the legal property of its developers, whose names are too numerous
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
10 * source distribution.
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
11 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
12 * This program is free software; you can redistribute it and/or modify
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
13 * under the terms of the GNU General Public License as published by
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
15 * (at your option) any later version.
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
16 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
17 * This program is distributed in the hope that it will be useful,
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
20 * GNU General Public License for more details.
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
21 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
22 * You should have received a copy of the GNU General Public License
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
23 * along with this program; if not, write to the Free Software
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
25 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
26 */
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
27
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
28 #ifdef HAVE_CONFIG_H
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
29 #include <config.h>
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
30 #endif
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
31
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
32 #include <ctype.h>
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
33 #include <string.h>
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
34 #include <glib.h>
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
35 #include <glib/gstdio.h>
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
36 #include <JavaScriptCore/JavaScript.h>
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
37
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
38 #include "util.h"
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
39 #include "gtkwebview.h"
32526
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
40 #include "imgstore.h"
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
41
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
42 static WebKitWebViewClass *parent_class = NULL;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
43
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
44 struct GtkWebViewPriv {
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
45 GHashTable *images; /**< a map from id to temporary file for the image */
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
46 gboolean empty; /**< whether anything has been appended **/
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
47
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
48 /* JS execute queue */
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
49 GQueue *js_queue;
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
50 gboolean is_loading;
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
51 };
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
52
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
53 GtkWidget* gtk_webview_new ()
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
54 {
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
55 GtkWebView* ret = GTK_WEBVIEW (g_object_new(gtk_webview_get_type(), NULL));
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
56 return GTK_WIDGET (ret);
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
57 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
58
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
59 static char*
32526
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
60 get_image_filename_from_id (GtkWebView* view, int id)
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
61 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
62 char *filename = NULL;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
63 FILE *file;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
64 PurpleStoredImage* img;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
65
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
66 if (!view->priv->images)
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
67 view->priv->images = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
68
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
69 filename = (char*) g_hash_table_lookup (view->priv->images, GINT_TO_POINTER (id));
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
70 if (filename) return filename;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
71
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
72 /* else get from img store */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
73 file = purple_mkstemp (&filename, TRUE);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
74
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
75 img = purple_imgstore_find_by_id (id);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
76
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
77 fwrite (purple_imgstore_get_data (img), purple_imgstore_get_size (img), 1, file);
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
78 g_hash_table_insert (view->priv->images, GINT_TO_POINTER (id), filename);
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
79 fclose (file);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
80 return filename;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
81 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
82
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
83 static void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
84 clear_single_image (gpointer key, gpointer value, gpointer userdata)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
85 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
86 g_unlink ((char*) value);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
87 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
88
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
89 static void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
90 clear_images (GtkWebView* view)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
91 {
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
92 if (!view->priv->images) return;
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
93 g_hash_table_foreach (view->priv->images, clear_single_image, NULL);
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
94 g_hash_table_unref (view->priv->images);
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
95 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
96
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
97 /*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
98 * Replace all <img id=""> tags with <img src="">. I hoped to never
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
99 * write any HTML parsing code, but I'm forced to do this, until
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
100 * purple changes the way it works.
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
101 */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
102 static char*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
103 replace_img_id_with_src (GtkWebView *view, const char* html)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
104 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
105 GString *buffer = g_string_sized_new (strlen (html));
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
106 const char* cur = html;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
107 char *id;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
108 int nid;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
109
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
110 while (*cur) {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
111 const char* img = strstr (cur, "<img");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
112 if (!img) {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
113 g_string_append (buffer, cur);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
114 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
115 } else
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
116 g_string_append_len (buffer, cur, img - cur);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
117
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
118 cur = strstr (img, "/>");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
119 if (!cur)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
120 cur = strstr (img, ">");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
121
32527
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32526
diff changeset
122 if (!cur) { /* invalid html? */
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
123 g_string_printf (buffer, "%s", html);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
124 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
125 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
126
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
127 if (strstr (img, "src=") || !strstr (img, "id=")) {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
128 g_string_printf (buffer, "%s", html);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
129 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
130 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
131
32527
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32526
diff changeset
132 /*
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32526
diff changeset
133 * if this is valid HTML, then I can be sure that it
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32526
diff changeset
134 * has an id= and does not have an src=, since
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32526
diff changeset
135 * '=' cannot appear in parameters.
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32526
diff changeset
136 */
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32526
diff changeset
137
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
138 id = strstr (img, "id=") + 3;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
139
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
140 /* *id can't be \0, since a ">" appears after this */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
141 if (isdigit (*id))
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
142 nid = atoi (id);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
143 else
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
144 nid = atoi (id+1);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
145
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
146 /* let's dump this, tag and then dump the src information */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
147 g_string_append_len (buffer, img, cur - img);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
148
32526
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32522
diff changeset
149 g_string_append_printf (buffer, " src='file://%s' ", get_image_filename_from_id (view, nid));
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
150 }
32527
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32526
diff changeset
151
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
152 return g_string_free (buffer, FALSE);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
153 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
154
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
155 static void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
156 gtk_webview_finalize (GObject *view)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
157 {
32542
3bd8fb942ea4 Yep, tested, and changed some code from previous commit. This is a hard
tdrhq@soc.pidgin.im
parents: 32541
diff changeset
158 gpointer temp;
3bd8fb942ea4 Yep, tested, and changed some code from previous commit. This is a hard
tdrhq@soc.pidgin.im
parents: 32541
diff changeset
159
3bd8fb942ea4 Yep, tested, and changed some code from previous commit. This is a hard
tdrhq@soc.pidgin.im
parents: 32541
diff changeset
160 while ((temp = g_queue_pop_head (GTK_WEBVIEW(view)->priv->js_queue)))
3bd8fb942ea4 Yep, tested, and changed some code from previous commit. This is a hard
tdrhq@soc.pidgin.im
parents: 32541
diff changeset
161 g_free (temp);
3bd8fb942ea4 Yep, tested, and changed some code from previous commit. This is a hard
tdrhq@soc.pidgin.im
parents: 32541
diff changeset
162 g_queue_free (GTK_WEBVIEW(view)->priv->js_queue);
3bd8fb942ea4 Yep, tested, and changed some code from previous commit. This is a hard
tdrhq@soc.pidgin.im
parents: 32541
diff changeset
163
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
164 clear_images (GTK_WEBVIEW (view));
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
165 g_free (GTK_WEBVIEW(view)->priv);
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
166 G_OBJECT_CLASS (parent_class)->finalize (G_OBJECT(view));
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
167 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
168
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
169 static void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
170 gtk_webview_class_init (GtkWebViewClass *klass, gpointer userdata)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
171 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
172 parent_class = g_type_class_ref (webkit_web_view_get_type ());
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
173 G_OBJECT_CLASS (klass)->finalize = gtk_webview_finalize;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
174 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
175
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
176 static gboolean
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
177 webview_link_clicked (WebKitWebView *view,
32527
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32526
diff changeset
178 WebKitWebFrame *frame,
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32526
diff changeset
179 WebKitNetworkRequest *request,
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32526
diff changeset
180 WebKitWebNavigationAction *navigation_action,
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
181 WebKitWebPolicyDecision *policy_decision)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
182 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
183 const gchar *uri;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
184
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
185 uri = webkit_network_request_get_uri (request);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
186
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
187 /* the gtk imhtml way was to create an idle cb, not sure
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
188 * why, so right now just using purple_notify_uri directly */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
189 purple_notify_uri (NULL, uri);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
190 return TRUE;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
191 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
192
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
193 static gboolean
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
194 process_js_script_queue (GtkWebView *view)
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
195 {
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
196 char *script;
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
197 if (view->priv->is_loading) return FALSE; /* we will be called when loaded */
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
198 if (!view->priv->js_queue || g_queue_is_empty (view->priv->js_queue))
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
199 return FALSE; /* nothing to do! */
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
200
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
201 script = g_queue_pop_head (view->priv->js_queue);
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
202 webkit_web_view_execute_script (WEBKIT_WEB_VIEW(view), script);
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
203 g_free (script);
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
204
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
205 return TRUE; /* there may be more for now */
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
206 }
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
207
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
208 static void
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
209 webview_load_started (WebKitWebView *view,
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
210 WebKitWebFrame *frame,
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
211 gpointer userdata)
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
212 {
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
213 /* is there a better way to test for is_loading? */
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
214 GTK_WEBVIEW(view)->priv->is_loading = true;
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
215 }
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
216
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
217 static void
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
218 webview_load_finished (WebKitWebView *view,
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
219 WebKitWebFrame *frame,
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
220 gpointer userdata)
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
221 {
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
222 GTK_WEBVIEW(view)->priv->is_loading = false;
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
223 g_idle_add ((GSourceFunc) process_js_script_queue, view);
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
224 }
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
225
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
226 char*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
227 gtk_webview_execute_script (GtkWebView *view, const char *script)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
228 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
229 JSStringRef js_script = JSStringCreateWithUTF8CString (script);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
230 JSContextRef ctxt = webkit_web_frame_get_global_context (
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
231 webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view))
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
232 );
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
233 JSValueRef ret = JSEvaluateScript (ctxt, js_script, NULL, NULL, 0, NULL);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
234 JSStringRef ret_as_str = JSValueToStringCopy (ctxt, ret, NULL);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
235
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
236 size_t cstr_len = JSStringGetMaximumUTF8CStringSize (ret_as_str);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
237 char *cstr = g_new0(char, cstr_len + 1);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
238
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
239 JSStringGetUTF8CString (ret_as_str, cstr, cstr_len);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
240
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
241 /* TODO: I'm not sure what, if at all, I need to free here! */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
242 return cstr;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
243 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
244
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
245 void
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
246 gtk_webview_safe_execute_script (GtkWebView *view, const char* script)
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
247 {
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
248 g_queue_push_tail (view->priv->js_queue, g_strdup (script));
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
249 g_idle_add ((GSourceFunc)process_js_script_queue, view);
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
250 }
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
251
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
252 static void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
253 gtk_webview_init (GtkWebView *view, gpointer userdata)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
254 {
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
255 view->priv = g_new0 (struct GtkWebViewPriv, 1);
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
256 g_signal_connect (view, "navigation-policy-decision-requested",
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
257 G_CALLBACK (webview_link_clicked),
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
258 view);
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
259
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
260 g_signal_connect (view, "load-started",
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
261 G_CALLBACK (webview_load_started),
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
262 view);
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
263
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
264 g_signal_connect (view, "load-finished",
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
265 G_CALLBACK (webview_load_finished),
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
266 view);
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
267
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
268 view->priv->empty = TRUE;
32542
3bd8fb942ea4 Yep, tested, and changed some code from previous commit. This is a hard
tdrhq@soc.pidgin.im
parents: 32541
diff changeset
269 view->priv->js_queue = g_queue_new ();
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
270 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
271
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
272
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
273 void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
274 gtk_webview_load_html_string_with_imgstore (GtkWebView* view, const char* html)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
275 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
276 char* html_imged;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
277
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
278 clear_images (view);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
279 html_imged = replace_img_id_with_src (view, html);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
280 printf ("%s\n", html_imged);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
281 webkit_web_view_load_html_string (WEBKIT_WEB_VIEW (view), html_imged, "file:///");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
282 g_free (html_imged);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
283 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
284
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
285 char *gtk_webview_quote_js_string(const char *text)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
286 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
287 GString *str = g_string_new("\"");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
288 const char *cur = text;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
289
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
290 while (cur && *cur) {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
291 switch (*cur) {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
292 case '\\':
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
293 g_string_append(str, "\\\\");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
294 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
295 case '\"':
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
296 g_string_append(str, "\\\"");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
297 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
298 case '\r':
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
299 g_string_append(str, "<br/>");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
300 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
301 case '\n':
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
302 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
303 default:
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
304 g_string_append_c(str, *cur);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
305 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
306 cur ++;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
307 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
308 g_string_append_c (str, '"');
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
309 return g_string_free (str, FALSE);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
310 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
311
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
312
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
313 /* this is a "hack", my plan is to eventually handle this
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
314 * correctly using a signals and a plugin: the plugin will have
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
315 * the information as to what javascript function to call. It seems
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
316 * wrong to hardcode that here.
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
317 */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
318 void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
319 gtk_webview_append_html (GtkWebView* view, const char* html)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
320 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
321 char* escaped = gtk_webview_quote_js_string (html);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
322 char* script = g_strdup_printf ("document.write(%s)", escaped);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
323 printf ("script: %s\n", script);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
324 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (view), script);
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
325 view->priv->empty = FALSE;
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
326 g_free (script);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
327 g_free (escaped);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
328 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
329
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
330 char*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
331 gtk_webview_get_markup (GtkWebView *view)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
332 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
333 return gtk_webview_execute_script (view, "document.body.innerHTML");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
334 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
335
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
336 char*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
337 gtk_webview_get_text (GtkWebView *view)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
338 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
339 return gtk_webview_execute_script (view, "document.body.textContent");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
340 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
341
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
342 gboolean gtk_webview_is_empty (GtkWebView *view)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
343 {
32541
b89351c7580b safely execute JS scripts only after loading is done. Untested code as of now, will test it in next commit.
tdrhq@soc.pidgin.im
parents: 32527
diff changeset
344 return view->priv->empty;
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
345 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
346
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
347 GType gtk_webview_get_type ()
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
348 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
349 static GType mview_type = 0;
32527
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32526
diff changeset
350 if (G_UNLIKELY (mview_type == 0)) {
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
351 static const GTypeInfo mview_info = {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
352 sizeof (GtkWebViewClass),
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
353 NULL,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
354 NULL,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
355 (GClassInitFunc) gtk_webview_class_init,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
356 NULL,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
357 NULL,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
358 sizeof (GtkWebView),
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
359 0,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
360 (GInstanceInitFunc) gtk_webview_init,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
361 NULL
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
362 };
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
363 mview_type = g_type_register_static(webkit_web_view_get_type (),
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
364 "GtkWebView", &mview_info, 0);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
365 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
366 return mview_type;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
367 }