annotate pidgin/gtkwebview.c @ 32446:aeaf9eebd5ec

If we handle a navigation request, then we should tell WebKit to ignore it.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Wed, 04 Jan 2012 02:49:34 +0000
parents 072e2329b659
children 692d5408983d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32065
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
1 /*
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
2 * @file gtkwebview.c GTK+ WebKitWebView wrapper class.
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
3 * @ingroup pidgin
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
4 */
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
5
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
6 /* pidgin
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
7 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
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: 32061
diff changeset
9 * to list here. Please refer to the COPYRIGHT file distributed with this
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
10 * source distribution.
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
11 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
12 * This program is free software; you can redistribute it and/or modify
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
13 * it under the terms of the GNU General Public License as published by
32065
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
14 * the Free Software Foundation; either version 2 of the License, or
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
15 * (at your option) any later version.
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
16 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
17 * This program is distributed in the hope that it will be useful,
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
20 * GNU General Public License for more details.
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
21 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
22 * You should have received a copy of the GNU General Public License
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
23 * along with this program; if not, write to the Free Software
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
25 *
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
26 */
a2fd5f08ed49 cleaning up code.
tdrhq@soc.pidgin.im
parents: 32061
diff changeset
27
32437
5dea9a26078d Use internal.h for less (conditional) #includes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32421
diff changeset
28 #include "internal.h"
5dea9a26078d Use internal.h for less (conditional) #includes.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32421
diff changeset
29 #include "pidgin.h"
32061
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 #include "gtkwebview.h"
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
32
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
33 #define MAX_SCROLL_TIME 0.4 /* seconds */
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
34 #define SCROLL_DELAY 33 /* milliseconds */
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
35
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
36 #define GTK_WEBVIEW_GET_PRIVATE(obj) \
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
37 (G_TYPE_INSTANCE_GET_PRIVATE((obj), GTK_TYPE_WEBVIEW, GtkWebViewPriv))
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
38
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
39 /******************************************************************************
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
40 * Structs
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
41 *****************************************************************************/
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
42
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
43 typedef struct _GtkWebViewPriv {
32080
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: 32066
diff changeset
44 GHashTable *images; /**< a map from id to temporary file for the image */
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
45 gboolean empty; /**< whether anything has been appended **/
32080
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: 32066
diff changeset
46
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: 32066
diff changeset
47 /* 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: 32066
diff changeset
48 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: 32066
diff changeset
49 gboolean is_loading;
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
50
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
51 /* Scroll adjustments */
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
52 GtkAdjustment *vadj;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
53 guint scroll_src;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
54 GTimer *scroll_time;
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
55 } GtkWebViewPriv;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
56
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
57 /******************************************************************************
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
58 * Globals
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
59 *****************************************************************************/
32080
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: 32066
diff changeset
60
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
61 static WebKitWebViewClass *parent_class = NULL;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
62
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
63 /******************************************************************************
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
64 * Helpers
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
65 *****************************************************************************/
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
66
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
67 static const char *
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
68 get_image_src_from_id(GtkWebViewPriv *priv, int id)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
69 {
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
70 char *src;
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
71 PurpleStoredImage *img;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
72
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
73 if (priv->images) {
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
74 /* Check for already loaded image */
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
75 src = (char *)g_hash_table_lookup(priv->images, GINT_TO_POINTER(id));
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
76 if (src)
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
77 return src;
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
78 } else {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
79 priv->images = g_hash_table_new_full(g_direct_hash, g_direct_equal,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
80 NULL, g_free);
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
81 }
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
82
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
83 /* Find image in store */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
84 img = purple_imgstore_find_by_id(id);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
85
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
86 src = (char *)purple_imgstore_get_filename(img);
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
87 if (src) {
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
88 src = g_strdup_printf("file://%s", src);
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
89 } else {
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
90 char *tmp;
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
91 tmp = purple_base64_encode(purple_imgstore_get_data(img),
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
92 purple_imgstore_get_size(img));
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
93 src = g_strdup_printf("data:base64,%s", tmp);
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
94 g_free(tmp);
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
95 }
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
96
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
97 g_hash_table_insert(priv->images, GINT_TO_POINTER(id), src);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
98
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
99 return src;
32061
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
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
102 /*
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
103 * Replace all <img id=""> tags with <img src="">. I hoped to never
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
104 * write any HTML parsing code, but I'm forced to do this, until
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
105 * purple changes the way it works.
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
106 */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
107 static char *
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
108 replace_img_id_with_src(GtkWebViewPriv *priv, const char *html)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
109 {
32440
1809d65d4f92 This strlen seems redundant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32439
diff changeset
110 GString *buffer = g_string_new(NULL);
1809d65d4f92 This strlen seems redundant.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32439
diff changeset
111 const char *cur = html;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
112 char *id;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
113 int nid;
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 while (*cur) {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
116 const char *img = strstr(cur, "<img");
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
117 if (!img) {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
118 g_string_append(buffer, cur);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
119 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
120 } else
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
121 g_string_append_len(buffer, cur, img - cur);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
122
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
123 cur = strstr(img, "/>");
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
124 if (!cur)
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
125 cur = strstr(img, ">");
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
126
32066
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
127 if (!cur) { /* invalid html? */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
128 g_string_printf(buffer, "%s", html);
32061
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
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
132 if (strstr(img, "src=") || !strstr(img, "id=")) {
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
133 g_string_printf(buffer, "%s", html);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
134 break;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
135 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
136
32066
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
137 /*
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
138 * if this is valid HTML, then I can be sure that it
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
139 * has an id= and does not have an src=, since
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
140 * '=' cannot appear in parameters.
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
141 */
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
142
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
143 id = strstr(img, "id=") + 3;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
144
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
145 /* *id can't be \0, since a ">" appears after this */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
146 if (isdigit(*id))
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
147 nid = atoi(id);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
148 else
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
149 nid = atoi(id + 1);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
150
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
151 /* let's dump this, tag and then dump the src information */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
152 g_string_append_len(buffer, img, cur - img);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
153
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
154 g_string_append_printf(buffer, " src='%s' ", get_image_src_from_id(priv, nid));
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
155 }
32066
2af29d62cfde more cleanup.
tdrhq@soc.pidgin.im
parents: 32065
diff changeset
156
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
157 return g_string_free(buffer, FALSE);
32061
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
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
160 static gboolean
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
161 process_js_script_queue(GtkWebView *webview)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
162 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
163 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
164 char *script;
32081
3bd8fb942ea4 Yep, tested, and changed some code from previous commit. This is a hard
tdrhq@soc.pidgin.im
parents: 32080
diff changeset
165
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
166 if (priv->is_loading)
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
167 return FALSE; /* we will be called when loaded */
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
168 if (!priv->js_queue || g_queue_is_empty(priv->js_queue))
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
169 return FALSE; /* nothing to do! */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
170
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
171 script = g_queue_pop_head(priv->js_queue);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
172 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(webview), script);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
173 g_free(script);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
174
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
175 return TRUE; /* there may be more for now */
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
176 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
177
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
178 static void
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
179 webview_load_started(WebKitWebView *webview, WebKitWebFrame *frame,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
180 gpointer userdata)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
181 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
182 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
183
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
184 /* is there a better way to test for is_loading? */
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
185 priv->is_loading = TRUE;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
186 }
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
187
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
188 static void
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
189 webview_load_finished(WebKitWebView *webview, WebKitWebFrame *frame,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
190 gpointer userdata)
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
191 {
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
192 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
193
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
194 priv->is_loading = FALSE;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
195 g_idle_add((GSourceFunc)process_js_script_queue, webview);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
196 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
197
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
198 static gboolean
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
199 webview_link_clicked(WebKitWebView *webview,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
200 WebKitWebFrame *frame,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
201 WebKitNetworkRequest *request,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
202 WebKitWebNavigationAction *navigation_action,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
203 WebKitWebPolicyDecision *policy_decision,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
204 gpointer userdata)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
205 {
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
206 const gchar *uri;
32126
a17de1f525a9 Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
masca@cpw.pidgin.im
parents: 32122
diff changeset
207 WebKitWebNavigationReason reason;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
208
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
209 uri = webkit_network_request_get_uri(request);
32126
a17de1f525a9 Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
masca@cpw.pidgin.im
parents: 32122
diff changeset
210 reason = webkit_web_navigation_action_get_reason(navigation_action);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
211
32126
a17de1f525a9 Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
masca@cpw.pidgin.im
parents: 32122
diff changeset
212 if (reason == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
a17de1f525a9 Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
masca@cpw.pidgin.im
parents: 32122
diff changeset
213 /* the gtk imhtml way was to create an idle cb, not sure
a17de1f525a9 Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
masca@cpw.pidgin.im
parents: 32122
diff changeset
214 * why, so right now just using purple_notify_uri directly */
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
215 purple_notify_uri(NULL, uri);
32446
aeaf9eebd5ec If we handle a navigation request, then we should tell WebKit
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32445
diff changeset
216 webkit_web_policy_decision_ignore(policy_decision);
32143
e7eba7a6a989 Let webview manage the navigation ONLY if the reason is the user clicked a link.
masca@cpw.pidgin.im
parents: 32133
diff changeset
217 } else
e7eba7a6a989 Let webview manage the navigation ONLY if the reason is the user clicked a link.
masca@cpw.pidgin.im
parents: 32133
diff changeset
218 webkit_web_policy_decision_use(policy_decision);
32126
a17de1f525a9 Handle better webkit's navigation-policy-decision-requested signal to be able to manage external files, links and theme files.
masca@cpw.pidgin.im
parents: 32122
diff changeset
219
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
220 return TRUE;
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
221 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
222
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
223 /*
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
224 * Smoothly scroll a WebView.
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
225 *
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
226 * @return TRUE if the window needs to be scrolled further, FALSE if we're at the bottom.
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
227 */
32080
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: 32066
diff changeset
228 static gboolean
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
229 smooth_scroll_cb(gpointer data)
32080
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: 32066
diff changeset
230 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
231 GtkWebViewPriv *priv = data;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
232 GtkAdjustment *adj;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
233 gdouble max_val;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
234 gdouble scroll_val;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
235
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
236 g_return_val_if_fail(priv->scroll_time != NULL, FALSE);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
237
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
238 adj = priv->vadj;
32443
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
239 #if GTK_CHECK_VERSION(2,14,0)
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
240 max_val = gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj);
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
241 #else
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
242 max_val = adj->upper - adj->page_size;
32443
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
243 #endif
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
244 scroll_val = gtk_adjustment_get_value(adj) +
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
245 ((max_val - gtk_adjustment_get_value(adj)) / 3);
32080
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: 32066
diff changeset
246
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
247 if (g_timer_elapsed(priv->scroll_time, NULL) > MAX_SCROLL_TIME
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
248 || scroll_val >= max_val) {
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
249 /* time's up. jump to the end and kill the timer */
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
250 gtk_adjustment_set_value(adj, max_val);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
251 g_timer_destroy(priv->scroll_time);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
252 priv->scroll_time = NULL;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
253 g_source_remove(priv->scroll_src);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
254 priv->scroll_src = 0;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
255 return FALSE;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
256 }
32080
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: 32066
diff changeset
257
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
258 /* scroll by 1/3rd the remaining distance */
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
259 gtk_adjustment_set_value(adj, scroll_val);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
260 return TRUE;
32080
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: 32066
diff changeset
261 }
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: 32066
diff changeset
262
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
263 static gboolean
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
264 scroll_idle_cb(gpointer data)
32080
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: 32066
diff changeset
265 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
266 GtkWebViewPriv *priv = data;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
267 GtkAdjustment *adj = priv->vadj;
32443
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
268 gdouble max_val;
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
269
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
270 if (adj) {
32443
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
271 #if GTK_CHECK_VERSION(2,14,0)
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
272 max_val = gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj);
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
273 #else
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
274 max_val = adj->upper - adj->page_size;
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
275 #endif
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
276 gtk_adjustment_set_value(adj, max_val);
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
277 }
32443
16925948a003 Use accessor functions where available.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32442
diff changeset
278
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
279 priv->scroll_src = 0;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
280 return FALSE;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
281 }
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
282
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
283 /******************************************************************************
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
284 * GObject Stuff
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
285 *****************************************************************************/
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
286
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
287 GtkWidget *
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
288 gtk_webview_new(void)
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
289 {
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
290 return GTK_WIDGET(g_object_new(gtk_webview_get_type(), NULL));
32080
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: 32066
diff changeset
291 }
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: 32066
diff changeset
292
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: 32066
diff changeset
293 static void
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
294 gtk_webview_finalize(GObject *webview)
32080
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: 32066
diff changeset
295 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
296 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
297 gpointer temp;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
298
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
299 while ((temp = g_queue_pop_head(priv->js_queue)))
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
300 g_free(temp);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
301 g_queue_free(priv->js_queue);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
302
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
303 if (priv->images)
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
304 g_hash_table_unref(priv->images);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
305
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
306 G_OBJECT_CLASS(parent_class)->finalize(G_OBJECT(webview));
32080
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: 32066
diff changeset
307 }
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: 32066
diff changeset
308
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
309 static void
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
310 gtk_webview_class_init(GtkWebViewClass *klass, gpointer userdata)
32080
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: 32066
diff changeset
311 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
312 parent_class = g_type_class_ref(webkit_web_view_get_type());
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
313
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
314 g_type_class_add_private(klass, sizeof(GtkWebViewPriv));
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
315
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
316 G_OBJECT_CLASS(klass)->finalize = gtk_webview_finalize;
32080
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: 32066
diff changeset
317 }
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: 32066
diff changeset
318
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
319 static void
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
320 gtk_webview_init(GtkWebView *webview, gpointer userdata)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
321 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
322 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
323
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
324 priv->empty = TRUE;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
325 priv->js_queue = g_queue_new();
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
326
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
327 g_signal_connect(webview, "navigation-policy-decision-requested",
32445
072e2329b659 Passing the webview as userdata when the webview is the object
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32443
diff changeset
328 G_CALLBACK(webview_link_clicked), NULL);
32080
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: 32066
diff changeset
329
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
330 g_signal_connect(webview, "load-started",
32445
072e2329b659 Passing the webview as userdata when the webview is the object
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32443
diff changeset
331 G_CALLBACK(webview_load_started), NULL);
32080
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: 32066
diff changeset
332
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
333 g_signal_connect(webview, "load-finished",
32445
072e2329b659 Passing the webview as userdata when the webview is the object
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32443
diff changeset
334 G_CALLBACK(webview_load_finished), NULL);
32061
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
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
337 GType
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
338 gtk_webview_get_type(void)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
339 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
340 static GType mview_type = 0;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
341 if (G_UNLIKELY(mview_type == 0)) {
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
342 static const GTypeInfo mview_info = {
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
343 sizeof(GtkWebViewClass),
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
344 NULL,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
345 NULL,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
346 (GClassInitFunc)gtk_webview_class_init,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
347 NULL,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
348 NULL,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
349 sizeof(GtkWebView),
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
350 0,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
351 (GInstanceInitFunc)gtk_webview_init,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
352 NULL
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
353 };
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
354 mview_type = g_type_register_static(webkit_web_view_get_type(),
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
355 "GtkWebView", &mview_info, 0);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
356 }
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
357 return mview_type;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
358 }
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
359
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
360 /*****************************************************************************
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
361 * Public API functions
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
362 *****************************************************************************/
32439
5022cf604d6e Avoid creating temporary files for images in a webview.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32437
diff changeset
363
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
364 gboolean
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
365 gtk_webview_is_empty(GtkWebView *webview)
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
366 {
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
367 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
368 return priv->empty;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
369 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
370
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
371 char *
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
372 gtk_webview_quote_js_string(const char *text)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
373 {
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
374 GString *str = g_string_new("\"");
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
375 const char *cur = text;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
376
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
377 while (cur && *cur) {
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
378 switch (*cur) {
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
379 case '\\':
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
380 g_string_append(str, "\\\\");
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
381 break;
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
382 case '\"':
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
383 g_string_append(str, "\\\"");
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
384 break;
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
385 case '\r':
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
386 g_string_append(str, "<br/>");
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
387 break;
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
388 case '\n':
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
389 break;
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
390 default:
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
391 g_string_append_c(str, *cur);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
392 }
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
393 cur++;
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
394 }
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
395
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
396 g_string_append_c(str, '"');
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
397
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
398 return g_string_free(str, FALSE);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
399 }
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
400 void
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
401 gtk_webview_safe_execute_script(GtkWebView *webview, const char *script)
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
402 {
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
403 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
404 g_queue_push_tail(priv->js_queue, g_strdup(script));
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
405 g_idle_add((GSourceFunc)process_js_script_queue, webview);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
406 }
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
407
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
408 void
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
409 gtk_webview_load_html_string_with_imgstore(GtkWebView *webview, const char *html)
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
410 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
411 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
412 char *html_imged;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
413
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
414 if (priv->images) {
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
415 g_hash_table_unref(priv->images);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
416 priv->images = NULL;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
417 }
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
418
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
419 html_imged = replace_img_id_with_src(priv, html);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
420 webkit_web_view_load_string(WEBKIT_WEB_VIEW(webview), html_imged, NULL,
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
421 NULL, "file:///");
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
422 g_free(html_imged);
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
423 }
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
424
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
425 /* this is a "hack", my plan is to eventually handle this
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
426 * 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
427 * 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
428 * wrong to hardcode that here.
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
429 */
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
430 void
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
431 gtk_webview_append_html(GtkWebView *webview, const char *html)
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
432 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
433 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
434 char *escaped = gtk_webview_quote_js_string(html);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
435 char *script = g_strdup_printf("document.write(%s)", escaped);
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
436 webkit_web_view_execute_script(WEBKIT_WEB_VIEW(webview), script);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
437 priv->empty = FALSE;
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
438 gtk_webview_scroll_to_end(webview, TRUE);
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
439 g_free(script);
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
440 g_free(escaped);
32061
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
441 }
ac42a0dfda48 Apparently I missed these in my previous commit.
tdrhq@soc.pidgin.im
parents:
diff changeset
442
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
443 void
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
444 gtk_webview_set_vadjustment(GtkWebView *webview, GtkAdjustment *vadj)
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
445 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
446 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
447 priv->vadj = vadj;
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
448 }
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
449
32133
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
450 void
8e1ec44ede75 Clean up this WebKit stuff. Fix up broken merging, mark unfinished
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32126
diff changeset
451 gtk_webview_scroll_to_end(GtkWebView *webview, gboolean smooth)
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
452 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
453 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
454 if (priv->scroll_time)
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
455 g_timer_destroy(priv->scroll_time);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
456 if (priv->scroll_src)
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
457 g_source_remove(priv->scroll_src);
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
458 if (smooth) {
32120
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
459 priv->scroll_time = g_timer_new();
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
460 priv->scroll_src = g_timeout_add_full(G_PRIORITY_LOW, SCROLL_DELAY, smooth_scroll_cb, priv, NULL);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
461 } else {
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
462 priv->scroll_time = NULL;
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
463 priv->scroll_src = g_idle_add_full(G_PRIORITY_LOW, scroll_idle_cb, priv, NULL);
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
464 }
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
465 }
24c8a98a6acc webkit: Scroll to end when appending html.
masca@cpw.pidgin.im
parents: 32109
diff changeset
466
32419
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
467 void gtk_webview_page_up(GtkWebView *webview)
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
468 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
469 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
470 GtkAdjustment *vadj = priv->vadj;
32419
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
471 gdouble scroll_val;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
472
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
473 #if GTK_CHECK_VERSION(2,14,0)
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
474 scroll_val = gtk_adjustment_get_value(vadj) - gtk_adjustment_get_page_size(vadj);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
475 scroll_val = MAX(scroll_val, gtk_adjustment_get_lower(vadj));
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
476 #else
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
477 scroll_val = gtk_adjustment_get_value(vadj) - vadj->page_size;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
478 scroll_val = MAX(scroll_val, vadj->lower);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
479 #endif
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
480
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
481 gtk_adjustment_set_value(vadj, scroll_val);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
482 }
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
483
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
484 void gtk_webview_page_down(GtkWebView *webview)
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
485 {
32442
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
486 GtkWebViewPriv *priv = GTK_WEBVIEW_GET_PRIVATE(webview);
fb8447f6649c Rearrange these files a bit to group common functions
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32440
diff changeset
487 GtkAdjustment *vadj = priv->vadj;
32419
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
488 gdouble scroll_val;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
489 gdouble page_size;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
490
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
491 #if GTK_CHECK_VERSION(2,14,0)
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
492 page_size = gtk_adjustment_get_page_size(vadj);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
493 scroll_val = gtk_adjustment_get_value(vadj) + page_size;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
494 scroll_val = MIN(scroll_val, gtk_adjustment_get_upper(vadj) - page_size);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
495 #else
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
496 page_size = vadj->page_size;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
497 scroll_val = gtk_adjustment_get_value(vadj) + page_size;
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
498 scroll_val = MIN(scroll_val, vadj->upper - page_size);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
499 #endif
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
500
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
501 gtk_adjustment_set_value(vadj, scroll_val);
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
502 }
7b9566b77501 Add page up/down for WebKit view.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 32199
diff changeset
503