1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
--- embed/webkit/webkit-embed.cpp.orig 2007-10-21 23:15:17.980341634 -0400
+++ embed/webkit/webkit-embed.cpp 2007-10-21 23:20:01.971961239 -0400
@@ -27,6 +27,7 @@
#include "ephy-string.h"
#include "ephy-embed-event.h"
+#include <webkitgtkframe.h>
#include <webkitgtkpage.h>
#include <webkitgtkglobal.h>
#include <string.h>
@@ -40,34 +41,6 @@
static void webkit_embed_finalize (GObject *object);
static void ephy_embed_iface_init (EphyEmbedIface *iface);
-#if 0
-static void load_started_cb (WebKitGtkPage *page,
- WebKitGtkFrame *frame,
- WebKitEmbed *wembed);
-
-static void webkit_embed_location_changed_cb (GtkMozEmbed *embed,
- WebKitEmbed *membed);
-static void webkit_embed_net_state_all_cb (GtkMozEmbed *embed,
- const char *aURI,
- gint state,
- guint status,
- WebKitEmbed *membed);
-static gboolean webkit_embed_dom_mouse_click_cb(GtkMozEmbed *embed,
- gpointer dom_event,
- WebKitEmbed *membed);
-static gboolean webkit_embed_dom_mouse_down_cb (GtkMozEmbed *embed,
-
-
- WebKitEmbed *membed);
-static gboolean webkit_embed_dom_key_press_cb (GtkMozEmbed *embed,
- gpointer dom_event,
- WebKitEmbed *membed);
-static void webkit_embed_new_window_cb (GtkMozEmbed *embed,
- GtkMozEmbed **newEmbed,
- guint chrome_mask,
- WebKitEmbed *membed);
-#endif
-
#define WEBKIT_EMBED_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), WEBKIT_TYPE_EMBED, WebKitEmbedPrivate))
typedef enum
@@ -80,8 +53,9 @@
struct WebKitEmbedPrivate
{
- WebKitGtkPage *page;
+ WebKitPage *page;
WebKitEmbedLoadState load_state;
+ char *loading_uri;
};
static void
@@ -121,14 +95,95 @@
}
static void
+webkit_embed_title_changed_cb (WebKitFrame *frame,
+ gchar *title,
+ gchar *location,
+ EphyEmbed *embed)
+{
+ /* FIXME: We emit ge-location signal here, but it should really belong
+ * to a "location_changed" signal by WebKit, as we can change title
+ * without changing location or change location without changing title
+ */
+
+ g_signal_emit_by_name (embed, "ge-location", location);
+}
+
+static void
+update_load_state (WebKitEmbed *embed, WebKitPage *page)
+{
+ EphyEmbedNetState estate = EPHY_EMBED_STATE_UNKNOWN;
+
+ if (embed->priv->load_state == WEBKIT_EMBED_LOAD_STARTED)
+ estate = (EphyEmbedNetState) (estate |
+ EPHY_EMBED_STATE_START |
+ EPHY_EMBED_STATE_NEGOTIATING |
+ EPHY_EMBED_STATE_IS_REQUEST |
+ EPHY_EMBED_STATE_IS_NETWORK);
+
+ if (embed->priv->load_state == WEBKIT_EMBED_LOAD_LOADING)
+ estate = (EphyEmbedNetState) (estate |
+ EPHY_EMBED_STATE_TRANSFERRING |
+ EPHY_EMBED_STATE_IS_REQUEST |
+ EPHY_EMBED_STATE_IS_NETWORK);
+
+ if (embed->priv->load_state == WEBKIT_EMBED_LOAD_STOPPED)
+ estate = (EphyEmbedNetState) (estate |
+ EPHY_EMBED_STATE_STOP |
+ EPHY_EMBED_STATE_IS_DOCUMENT |
+ EPHY_EMBED_STATE_IS_NETWORK);
+
+ g_signal_emit_by_name (EPHY_EMBED (embed), "ge_net_state",
+ embed->priv->loading_uri, estate);
+}
+
+static void
+webkit_embed_load_started_cb (WebKitPage *page,
+ WebKitFrame *frame,
+ EphyEmbed *embed)
+{
+ WebKitEmbed *wembed = WEBKIT_EMBED (embed);
+ wembed->priv->load_state = WEBKIT_EMBED_LOAD_STARTED;
+
+ update_load_state (wembed, page);
+}
+
+static void
+webkit_embed_load_progress_changed_cb (WebKitPage *page,
+ int progress,
+ EphyEmbed *embed)
+{
+ WebKitEmbed *wembed = WEBKIT_EMBED (embed);
+
+ if (wembed->priv->load_state == WEBKIT_EMBED_LOAD_STARTED)
+ wembed->priv->load_state = WEBKIT_EMBED_LOAD_LOADING;
+
+ /* FIXME: EphyTab seems to have a strange way of calculating progress,
+ * and it's not compatible with the simple integer value WebKit emits.
+ * EphyTab IMHO should use "progress" signal from GtkMozEmbed. That way,
+ * we could use the same functions for WebKit too.
+ */
+
+ update_load_state (wembed, page);
+}
+
+static void
+webkit_embed_load_finished_cb (WebKitPage *page,
+ WebKitFrame *frame,
+ EphyEmbed *embed)
+{
+ WebKitEmbed *wembed = WEBKIT_EMBED (embed);
+ wembed->priv->load_state = WEBKIT_EMBED_LOAD_STOPPED;
+
+ update_load_state (wembed, page);
+}
+
+static void
webkit_embed_class_init (WebKitEmbedClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- webkit_embed_parent_class = (GObjectClass *) g_type_class_peek_parent (klass);
-
object_class->finalize = webkit_embed_finalize;
gtk_object_class->destroy = webkit_embed_destroy;
@@ -141,29 +196,30 @@
static void
webkit_embed_init (WebKitEmbed *embed)
{
- WebKitGtkPage *page;
+ WebKitPage *page;
embed->priv = WEBKIT_EMBED_GET_PRIVATE (embed);
+ embed->priv->loading_uri = NULL;
gtk_scrolled_window_set_vadjustment (GTK_SCROLLED_WINDOW (embed), NULL);
gtk_scrolled_window_set_hadjustment (GTK_SCROLLED_WINDOW (embed), NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (embed),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- webkit_gtk_init ();
- page = WEBKIT_GTK_PAGE (webkit_gtk_page_new ());
+ webkit_init ();
+ page = WEBKIT_PAGE (webkit_page_new ());
embed->priv->page = page;
gtk_container_add (GTK_CONTAINER (embed), GTK_WIDGET (page));
gtk_widget_show (GTK_WIDGET (page));
-#if 0
g_signal_connect (G_OBJECT (page), "load-started",
- G_CALLBACK (load_started_cb), embed);
+ G_CALLBACK (webkit_embed_load_started_cb), embed);
+ g_signal_connect (G_OBJECT (page), "load_finished",
+ G_CALLBACK (webkit_embed_load_finished_cb), embed);
g_signal_connect (G_OBJECT (page), "title-changed",
- G_CALLBACK (title_changed_cb), page);
+ G_CALLBACK (webkit_embed_title_changed_cb), embed);
g_signal_connect (G_OBJECT (page), "load-progress-changed",
- G_CALLBACK (load_progress_changed), page);
-#endif
+ G_CALLBACK (webkit_embed_load_progress_changed_cb), embed);
}
static void
@@ -175,19 +231,12 @@
static void
webkit_embed_finalize (GObject *object)
{
- G_OBJECT_CLASS (webkit_embed_parent_class)->finalize (object);
-}
+ WebKitEmbed *wembed = WEBKIT_EMBED (object);
-#if 0
-static void
-load_started_cb (WebKitGtkPage *page,
- WebKitGtkFrame *frame,
- WebKitEmbed *wembed)
-{
- g_debug("load-started, emitting ge_location with www.google.com as location");
- g_signal_emit_by_name (wembed, "ge_location", "www.google.com");
+ g_free (wembed->priv->loading_uri);
+
+ G_OBJECT_CLASS (webkit_embed_parent_class)->finalize (object);
}
-#endif
static void
impl_load_url (EphyEmbed *embed,
@@ -195,13 +244,9 @@
{
WebKitEmbed *wembed = WEBKIT_EMBED (embed);
- g_debug ("a url %s", url);
-
- webkit_gtk_page_open (wembed->priv->page, url);
+ webkit_page_open (wembed->priv->page, url);
}
-static char * impl_get_location (EphyEmbed *embed, gboolean toplevel);
-
static void
impl_load (EphyEmbed *embed,
const char *url,
@@ -209,27 +254,45 @@
EphyEmbed *preview_embed)
{
WebKitEmbed *wembed = WEBKIT_EMBED (embed);
+ char *effective_url = NULL;
- g_debug ("url %s", url);
- webkit_gtk_page_open (wembed->priv->page, url);
+ /* FIXME: WebKit has some strange bug for which there must be
+ * protocol prefix into the parsed URL, or it will not show images
+ * and lock badly. I copied this function from WebKit's
+ * GdkLauncher.
+ */
+ if (strncmp ("http://", url, 7) != 0 &&
+ strncmp ("https://", url, 8) != 0 &&
+ strncmp ("file://", url, 7) != 0 &&
+ strncmp ("ftp://", url, 6) != 0)
+ effective_url = g_strconcat ("http://", url, NULL);
+ else
+ effective_url = g_strdup (url);
+
+ g_free (wembed->priv->loading_uri);
+ wembed->priv->loading_uri = g_strdup (effective_url);
+
+ webkit_page_open (wembed->priv->page, effective_url);
+
+ g_free (effective_url);
}
static void
impl_stop_load (EphyEmbed *embed)
{
- webkit_gtk_page_stop_loading (WEBKIT_EMBED (embed)->priv->page);
+ webkit_page_stop_loading (WEBKIT_EMBED (embed)->priv->page);
}
static gboolean
impl_can_go_back (EphyEmbed *embed)
{
- return webkit_gtk_page_can_go_backward (WEBKIT_EMBED (embed)->priv->page);
+ return webkit_page_can_go_backward (WEBKIT_EMBED (embed)->priv->page);
}
static gboolean
impl_can_go_forward (EphyEmbed *embed)
{
- return webkit_gtk_page_can_go_forward (WEBKIT_EMBED (embed)->priv->page);
+ return webkit_page_can_go_forward (WEBKIT_EMBED (embed)->priv->page);
}
static gboolean
@@ -247,13 +310,13 @@
static void
impl_go_back (EphyEmbed *embed)
{
- webkit_gtk_page_go_backward (WEBKIT_EMBED (embed)->priv->page);
+ webkit_page_go_backward (WEBKIT_EMBED (embed)->priv->page);
}
static void
impl_go_forward (EphyEmbed *embed)
{
- webkit_gtk_page_go_forward (WEBKIT_EMBED (embed)->priv->page);
+ webkit_page_go_forward (WEBKIT_EMBED (embed)->priv->page);
}
static void
@@ -264,7 +327,8 @@
static char *
impl_get_title (EphyEmbed *embed)
{
- return NULL;
+ WebKitFrame *frame = webkit_page_get_main_frame (WEBKIT_EMBED (embed)->priv->page);
+ return g_strdup (webkit_frame_get_title (frame));
}
static char *
@@ -283,14 +347,15 @@
impl_get_location (EphyEmbed *embed,
gboolean toplevel)
{
- return NULL;
+ WebKitFrame *frame = webkit_page_get_main_frame (WEBKIT_EMBED (embed)->priv->page);
+ return g_strdup (webkit_frame_get_location (frame));
}
static void
impl_reload (EphyEmbed *embed,
gboolean force)
{
- webkit_gtk_page_reload (WEBKIT_EMBED (embed)->priv->page);
+ webkit_page_reload (WEBKIT_EMBED (embed)->priv->page);
}
static void
|