annotate pidgin/gtkwebview.c @ 32522:ac42a0dfda48

Apparently I missed these in my previous commit. Also changed the gtkwebview.h to be javadoc'ed.
author tdrhq@soc.pidgin.im
date Fri, 07 Aug 2009 18:27:41 +0000
parents
children a2fd5f08ed49
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32522
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
1
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
2 #include <ctype.h>
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
3 #include <string.h>
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
4 #include <glib.h>
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
5 #include <glib/gstdio.h>
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
6 #include <JavaScriptCore/JavaScript.h>
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
7
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
8 #include "util.h"
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
9 #include "gtkwebview.h"
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
10
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
11 static WebKitWebViewClass *parent_class = NULL;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
12
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
13 GtkWidget* gtk_webview_new ()
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
14 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
15 return GTK_WIDGET(g_object_new(gtk_webview_get_type(), NULL));
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
16 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
17
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
18 static char*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
19 get_img_filename_by_id (GtkWebView* view, int id)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
20 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
21 char *filename = NULL;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
22 FILE *file;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
23 PurpleStoredImage* img;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
24
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
25 if (!view->images)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
26 view->images = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
27
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
28 filename = (char*) g_hash_table_lookup (view->images, GINT_TO_POINTER (id));
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
29 if (filename) return filename;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
30
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
31 /* else get from img store */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
32 file = purple_mkstemp (&filename, TRUE);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
33
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
34 img = purple_imgstore_find_by_id (id);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
35
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
36 fwrite (purple_imgstore_get_data (img), purple_imgstore_get_size (img), 1, file);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
37 g_hash_table_insert (view->images, GINT_TO_POINTER (id), filename);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
38 fclose (file);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
39 return filename;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
40 }
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 void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
43 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
44 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
45 g_unlink ((char*) value);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
46 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
47
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
48 static void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
49 clear_images (GtkWebView* view)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
50 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
51 if (!view->images) return;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
52 g_hash_table_foreach (view->images, clear_single_image, NULL);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
53 g_hash_table_unref (view->images);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
54 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
55
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
56 /*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
57 * 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
58 * 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
59 * purple changes the way it works.
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
60 */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
61 static char*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
62 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
63 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
64 GString *buffer = g_string_sized_new (strlen (html));
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
65 const char* cur = html;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
66 char *id;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
67 int nid;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
68
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
69 while (*cur) {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
70 const char* img = strstr (cur, "<img");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
71 if (!img) {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
72 g_string_append (buffer, cur);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
73 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
74 } else
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
75 g_string_append_len (buffer, cur, img - cur);
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 cur = strstr (img, "/>");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
78 if (!cur)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
79 cur = strstr (img, ">");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
80
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
81 if (!cur) { /*oops, invalid html */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
82 g_string_printf (buffer, "%s", html);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
83 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
84 }
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 if (strstr (img, "src=") || !strstr (img, "id=")) {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
87 g_string_printf (buffer, "%s", html);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
88 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
89 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
90
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
91 /* now I _kinda_ know that it has an id=, and does not have a src= */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
92 /* todo: take care of src= and id= appearing in strings? */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
93 id = strstr (img, "id=") + 3;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
94
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
95 /* *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
96 if (isdigit (*id))
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
97 nid = atoi (id);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
98 else
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
99 nid = atoi (id+1);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
100
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
101 /* 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
102 g_string_append_len (buffer, img, cur - img);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
103
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
104 g_string_append_printf (buffer, " src='file://%s' ", get_img_filename_by_id (view, nid));
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
105 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
106 return g_string_free (buffer, FALSE);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
107 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
108
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
109 static void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
110 gtk_webview_finalize (GObject *view)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
111 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
112 clear_images (GTK_WEBVIEW (view));
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
113 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
114 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
115
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
116 static void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
117 gtk_webview_class_init (GtkWebViewClass *klass, gpointer userdata)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
118 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
119 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
120 G_OBJECT_CLASS (klass)->finalize = gtk_webview_finalize;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
121 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
122
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
123 static gboolean
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
124 webview_link_clicked (WebKitWebView *view,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
125 WebKitWebFrame *frame,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
126 WebKitNetworkRequest *request,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
127 WebKitWebNavigationAction *navigation_action,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
128 WebKitWebPolicyDecision *policy_decision)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
129 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
130 const gchar *uri;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
131
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
132 uri = webkit_network_request_get_uri (request);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
133
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
134 /* 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
135 * 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
136 purple_notify_uri (NULL, uri);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
137 return TRUE;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
138 }
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 char*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
141 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
142 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
143 JSStringRef js_script = JSStringCreateWithUTF8CString (script);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
144 JSContextRef ctxt = webkit_web_frame_get_global_context (
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
145 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
146 );
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
147 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
148 JSStringRef ret_as_str = JSValueToStringCopy (ctxt, ret, NULL);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
149
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
150 size_t cstr_len = JSStringGetMaximumUTF8CStringSize (ret_as_str);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
151 char *cstr = g_new0(char, cstr_len + 1);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
152
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
153 JSStringGetUTF8CString (ret_as_str, cstr, cstr_len);
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 /* 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
156 return cstr;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
157 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
158
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
159 static void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
160 gtk_webview_init (GtkWebView *view, gpointer userdata)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
161 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
162 g_signal_connect (view, "navigation-policy-decision-requested",
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
163 G_CALLBACK (webview_link_clicked),
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
164 view);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
165 view->empty = TRUE;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
166 }
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 void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
170 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
171 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
172 char* html_imged;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
173
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
174 clear_images (view);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
175 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
176 printf ("%s\n", html_imged);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
177 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
178 g_free (html_imged);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
179 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
180
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
181 /* taken from sean's webkit plugin */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
182 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
183 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
184 GString *str = g_string_new("\"");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
185 const char *cur = text;
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 while (cur && *cur) {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
188 switch (*cur) {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
189 case '\\':
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
190 g_string_append(str, "\\\\");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
191 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
192 case '\"':
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
193 g_string_append(str, "\\\"");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
194 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
195 case '\r':
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
196 g_string_append(str, "<br/>");
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
197 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
198 case '\n':
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
199 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
200 default:
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
201 g_string_append_c(str, *cur);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
202 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
203 cur ++;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
204 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
205 g_string_append_c (str, '"');
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
206 return g_string_free (str, FALSE);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
207 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
208
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
209
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
210 /* 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
211 * 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
212 * 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
213 * wrong to hardcode that here.
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
214 */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
215 void
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
216 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
217 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
218 char* escaped = gtk_webview_quote_js_string (html);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
219 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
220 printf ("script: %s\n", script);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
221 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (view), script);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
222 view->empty = FALSE;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
223 g_free (script);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
224 g_free (escaped);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
225 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
226
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
227 char*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
228 gtk_webview_get_markup (GtkWebView *view)
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
229 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
230 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
231 }
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 char*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
234 gtk_webview_get_text (GtkWebView *view)
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 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
237 }
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 gboolean gtk_webview_is_empty (GtkWebView *view)
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 return view->empty;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
242 }
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 GType gtk_webview_get_type ()
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
245 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
246 static GType mview_type = 0;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
247 if (!mview_type) {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
248 static const GTypeInfo mview_info = {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
249 sizeof (GtkWebViewClass),
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
250 NULL,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
251 NULL,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
252 (GClassInitFunc) gtk_webview_class_init,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
253 NULL,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
254 NULL,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
255 sizeof (GtkWebView),
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
256 0,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
257 (GInstanceInitFunc) gtk_webview_init,
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
258 NULL
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
259 };
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
260 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
261 "GtkWebView", &mview_info, 0);
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
262 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
263 return mview_type;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
264 }