642aa8e1be22072cc454065d9506249907765f3e
[claws.git] / src / plugins / fancy / fancy_viewer.c
1 /*
2  * Claws Mail -- A GTK+ based, lightweight, and fast e-mail client
3  * == Fancy Plugin ==
4  * Copyright(C) 1999-2013 the Claws Mail Team
5  * This file Copyright (C) 2009-2013 Salvatore De Paolis
6  * <iwkse@claws-mail.org> and the Claws Mail Team
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write tothe Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #include "claws-features.h"
24 #endif
25
26 #include <fancy_viewer.h>
27 #include <fancy_prefs.h>
28 #include <alertpanel.h>
29
30 #include <printing.h>
31
32
33 static void
34 load_start_cb (WebKitWebView *view, gint progress, FancyViewer *viewer);
35
36 static void
37 load_finished_cb (WebKitWebView *view, gint progress, FancyViewer *viewer);
38
39 static void
40 over_link_cb (WebKitWebView *view, const gchar *wtf, const gchar *link,
41               FancyViewer *viewer, void *wtfa);
42
43 static void
44 load_progress_cb (WebKitWebView *view, gint progress, FancyViewer *viewer);
45
46 static WebKitNavigationResponse
47 navigation_requested_cb (WebKitWebView *view, WebKitWebFrame *frame,
48                          WebKitNetworkRequest *netreq, FancyViewer *viewer);
49
50 static MimeViewerFactory fancy_viewer_factory;
51
52 static gboolean
53 fancy_text_search(MimeViewer *_viewer, gboolean backward, const gchar *str,
54                   gboolean case_sens);
55
56 static void
57 viewer_menu_handler(GtkWidget *menuitem, FancyViewer *viewer);
58
59 static gint keypress_events_cb (GtkWidget *widget, GdkEventKey *event,
60                                                                 FancyViewer *viewer);
61 static void zoom_in_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer);
62 static void zoom_out_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer);
63 static gboolean fancy_prefs_cb(GtkWidget *widget, GdkEventButton *ev, FancyViewer *viewer);
64 static void zoom_100_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer);
65 static void open_in_browser_cb(GtkWidget *widget, FancyViewer *viewer);
66 static void fancy_create_popup_prefs_menu(FancyViewer *viewer);
67 static void fancy_show_notice(FancyViewer *viewer, const gchar *message);
68 static size_t download_file_curl_write_cb(void *buffer, size_t size,
69                                           size_t nmemb, void *data);
70 static void *download_file_curl (void *data);
71 static void download_file_cb(GtkWidget *widget, FancyViewer *viewer);
72
73 #if !WEBKIT_CHECK_VERSION (1,5,1)
74 gchar* webkit_web_view_get_selected_text(WebKitWebView* web_view);
75 #endif
76
77 /*------*/
78 static GtkWidget *fancy_get_widget(MimeViewer *_viewer)
79 {
80         FancyViewer *viewer = (FancyViewer *) _viewer;
81         debug_print("fancy_get_widget: %p\n", viewer->vbox);
82
83         return GTK_WIDGET(viewer->vbox);
84 }
85
86 static void fancy_apply_prefs(FancyViewer *viewer)
87 {
88         g_object_set(viewer->settings,
89                 "auto-load-images", viewer->override_prefs_images,
90                 "enable-scripts", viewer->override_prefs_scripts,
91                 "enable-plugins", viewer->override_prefs_plugins,
92                 "enable-java-applet", viewer->override_prefs_java,
93 #ifdef G_OS_WIN32
94                 "default-font-family", "Arial",
95                 "cursive-font-family", "Comic Sans MS",
96                 "fantasy-font-family", "Comic Sans MS",
97                 "monospace-font-family", "Courier New",
98                 "sans-serif-font-family", "Arial",
99                 "serif-font-family", "Times New Roman",
100 #endif
101                 NULL); 
102         webkit_web_view_set_settings(viewer->view, viewer->settings);
103 }
104
105 static void fancy_auto_load_images_activated(GtkCheckMenuItem *item, FancyViewer *viewer) {
106         viewer->override_prefs_images = gtk_check_menu_item_get_active(item);
107         fancy_apply_prefs(viewer);
108         webkit_web_view_reload (viewer->view);
109 }
110
111 static void fancy_enable_remote_content_activated(GtkCheckMenuItem *item, FancyViewer *viewer) {
112         viewer->override_prefs_remote_content = gtk_check_menu_item_get_active(item);
113         fancy_apply_prefs(viewer);
114         webkit_web_view_reload (viewer->view);
115 }
116
117 static void fancy_enable_scripts_activated(GtkCheckMenuItem *item, FancyViewer *viewer) {
118         viewer->override_prefs_scripts = gtk_check_menu_item_get_active(item);
119         fancy_apply_prefs(viewer);
120         webkit_web_view_reload (viewer->view);
121 }
122
123 static void fancy_enable_plugins_activated(GtkCheckMenuItem *item, FancyViewer *viewer) {
124         viewer->override_prefs_plugins = gtk_check_menu_item_get_active(item);
125         fancy_apply_prefs(viewer);
126         webkit_web_view_reload (viewer->view);
127 }
128
129 static void fancy_enable_java_activated(GtkCheckMenuItem *item, FancyViewer *viewer) {
130         viewer->override_prefs_java = gtk_check_menu_item_get_active(item);
131         fancy_apply_prefs(viewer);
132         webkit_web_view_reload (viewer->view);
133 }
134
135 static void fancy_open_external_activated(GtkCheckMenuItem *item, FancyViewer *viewer) {
136         viewer->override_prefs_external = gtk_check_menu_item_get_active(item);
137         fancy_apply_prefs(viewer);
138 }
139
140 static void fancy_set_defaults(FancyViewer *viewer)
141 {
142         viewer->override_prefs_remote_content = fancy_prefs.enable_remote_content;
143         viewer->override_prefs_external = fancy_prefs.open_external;
144         viewer->override_prefs_images = fancy_prefs.enable_images;
145         viewer->override_prefs_scripts = fancy_prefs.enable_scripts;
146         viewer->override_prefs_plugins = fancy_prefs.enable_plugins;
147         viewer->override_prefs_java = fancy_prefs.enable_java;
148
149         g_signal_handlers_block_by_func(G_OBJECT(viewer->enable_images),
150                 fancy_auto_load_images_activated, viewer);
151         g_signal_handlers_block_by_func(G_OBJECT(viewer->enable_remote_content),
152                 fancy_enable_remote_content_activated, viewer);
153         g_signal_handlers_block_by_func(G_OBJECT(viewer->enable_scripts),
154                 fancy_enable_scripts_activated, viewer);
155         g_signal_handlers_block_by_func(G_OBJECT(viewer->enable_plugins),
156                 fancy_enable_plugins_activated, viewer);
157         g_signal_handlers_block_by_func(G_OBJECT(viewer->enable_java),
158                 fancy_enable_java_activated, viewer);
159         g_signal_handlers_block_by_func(G_OBJECT(viewer->open_external),
160                 fancy_open_external_activated, viewer);
161
162         gtk_check_menu_item_set_active(
163                 GTK_CHECK_MENU_ITEM(viewer->enable_images),
164                 viewer->override_prefs_images);
165         gtk_check_menu_item_set_active(
166                 GTK_CHECK_MENU_ITEM(viewer->enable_scripts),
167                 viewer->override_prefs_scripts);
168         gtk_check_menu_item_set_active(
169                 GTK_CHECK_MENU_ITEM(viewer->enable_plugins),
170                 viewer->override_prefs_plugins);
171         gtk_check_menu_item_set_active(
172                 GTK_CHECK_MENU_ITEM(viewer->enable_java),
173                 viewer->override_prefs_java);
174         gtk_check_menu_item_set_active(
175                 GTK_CHECK_MENU_ITEM(viewer->enable_remote_content),
176                 viewer->override_prefs_remote_content);
177         gtk_check_menu_item_set_active(
178                 GTK_CHECK_MENU_ITEM(viewer->open_external),
179                 viewer->override_prefs_external);
180
181         g_signal_handlers_unblock_by_func(G_OBJECT(viewer->enable_images),
182                 fancy_auto_load_images_activated, viewer);
183         g_signal_handlers_unblock_by_func(G_OBJECT(viewer->enable_remote_content),
184                 fancy_enable_remote_content_activated, viewer);
185         g_signal_handlers_unblock_by_func(G_OBJECT(viewer->enable_scripts),
186                 fancy_enable_scripts_activated, viewer);
187         g_signal_handlers_unblock_by_func(G_OBJECT(viewer->enable_plugins),
188                 fancy_enable_plugins_activated, viewer);
189         g_signal_handlers_unblock_by_func(G_OBJECT(viewer->enable_java),
190                 fancy_enable_java_activated, viewer);
191         g_signal_handlers_unblock_by_func(G_OBJECT(viewer->open_external),
192                 fancy_open_external_activated, viewer);
193
194         fancy_apply_prefs(viewer);
195 }
196
197 static void fancy_load_uri(FancyViewer *viewer, const gchar *uri)
198 {
199 #if WEBKIT_CHECK_VERSION(1,1,1)
200         webkit_web_view_load_uri(viewer->view, uri);
201 #else
202         webkit_web_view_open(viewer->view, uri);
203 #endif
204 }
205
206 static gboolean fancy_show_mimepart_real(MimeViewer *_viewer)
207 {
208         FancyViewer *viewer = (FancyViewer *) _viewer;
209         MessageView *messageview = ((MimeViewer *)viewer)->mimeview
210                                         ? ((MimeViewer *)viewer)->mimeview->messageview
211                                         : NULL;
212         MimeInfo *partinfo = viewer->to_load;
213
214         messageview->updating = TRUE;
215
216         if (viewer->filename != NULL) {
217                 g_unlink(viewer->filename);
218                 g_free(viewer->filename);
219                 viewer->filename = NULL;
220         }
221
222         if (messageview) {
223                 NoticeView *noticeview = messageview->noticeview;
224                 noticeview_hide(noticeview);
225         }
226         if (partinfo)
227                 viewer->filename = procmime_get_tmp_file_name(partinfo);
228         debug_print("filename: %s\n", viewer->filename);
229         if (!viewer->filename) {
230                 return FALSE;
231         }
232         if (procmime_get_part(viewer->filename, partinfo) < 0) {
233                 g_free(viewer->filename);
234                 viewer->filename = NULL;
235         }
236         else {
237                 const gchar *charset = NULL;
238                 if (_viewer && _viewer->mimeview &&
239                         _viewer->mimeview->messageview->forced_charset)
240                         charset = _viewer->mimeview->messageview->forced_charset;
241                 else
242                         charset = procmime_mimeinfo_get_parameter(partinfo, "charset");
243                 if (!charset)
244                         charset = conv_get_locale_charset_str();
245                 debug_print("using %s charset\n", charset);
246                 g_object_set(viewer->settings, "default-encoding", charset, NULL);
247                 gchar *tmp = g_filename_to_uri(viewer->filename, NULL, NULL);
248                 debug_print("zoom_level: %i\n", fancy_prefs.zoom_level);
249                 webkit_web_view_set_zoom_level(viewer->view, (fancy_prefs.zoom_level / 100.0));
250
251                 fancy_set_defaults(viewer);
252                 fancy_load_uri(viewer, tmp);
253
254                 g_free(tmp);
255         }
256         viewer->loading = FALSE;
257         return FALSE;
258 }
259 static void fancy_show_notice(FancyViewer *viewer, const gchar *message)
260 {
261         gtk_label_set_text(GTK_LABEL(viewer->l_link), message);
262 }
263 static gint fancy_show_mimepart_prepare(MimeViewer *_viewer)
264 {
265         FancyViewer *viewer = (FancyViewer *) _viewer;
266
267         if (viewer->tag > 0) {
268                 gtk_timeout_remove(viewer->tag);
269                 viewer->tag = -1;
270                 if (viewer->loading) {
271                         viewer->stop_previous = TRUE;
272                 }
273         }
274
275         viewer->tag = g_timeout_add(5, (GSourceFunc)fancy_show_mimepart_real, viewer);
276         return FALSE;
277 }
278
279 static void fancy_show_mimepart(MimeViewer *_viewer, const gchar *infile,
280                                                                 MimeInfo *partinfo)
281 {
282         FancyViewer *viewer = (FancyViewer *) _viewer;
283         viewer->to_load = partinfo;
284         viewer->loading = TRUE;
285         g_timeout_add(5, (GtkFunction)fancy_show_mimepart_prepare, viewer);
286 }
287
288 static void fancy_print(MimeViewer *_viewer)
289 {
290         FancyViewer *viewer = (FancyViewer *) _viewer;
291         GtkPrintOperationResult res;
292         GError *error = NULL;
293         GtkPrintOperation *op;
294
295         gtk_widget_realize(GTK_WIDGET(viewer->view));
296
297         while (viewer->loading)
298                 claws_do_idle();
299
300         op = gtk_print_operation_new();
301
302         /* Config for printing */
303         gtk_print_operation_set_print_settings(op, printing_get_settings());
304         gtk_print_operation_set_default_page_setup(op, printing_get_page_setup());
305 #if GTK_CHECK_VERSION(2,18,0)
306         /* enable Page Size and Orientation in the print dialog */
307         gtk_print_operation_set_embed_page_setup(op, TRUE);
308 #endif
309
310         /* Start printing process */
311         res = webkit_web_frame_print_full(webkit_web_view_get_main_frame(viewer->view),
312                                           op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
313                                           &error);
314
315         if (res == GTK_PRINT_OPERATION_RESULT_ERROR) {
316                 gtk_print_operation_get_error(op, &error);
317                 debug_print("Error printing message: %s\n",
318                             error ? error->message : "no details");
319         } else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
320                 /* store settings for next printing session */
321                 printing_store_settings(gtk_print_operation_get_print_settings(op));
322         }
323 }
324
325 static gchar *fancy_get_selection (MimeViewer *_viewer)
326 {
327         debug_print("fancy_get_selection\n");
328         FancyViewer *viewer = (FancyViewer *) _viewer;
329 #if WEBKIT_CHECK_VERSION(1,5,1)
330         viewer->doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(viewer->view));
331         viewer->window = webkit_dom_document_get_default_view (viewer->doc);
332         viewer->selection = webkit_dom_dom_window_get_selection (viewer->window);
333         if (viewer->selection == NULL)
334                 return NULL;
335         viewer->range = webkit_dom_dom_selection_get_range_at(viewer->selection, 0, NULL);
336         if (viewer->range == NULL)
337                 return NULL;
338         gchar *sel = webkit_dom_range_get_text (viewer->range);
339 #else
340         gchar *sel = webkit_web_view_get_selected_text(viewer->view);
341 #endif
342         if (!viewer->view || strlen(sel) == 0) {
343                 g_free(sel);
344                 return NULL;
345         }
346         return sel;
347 }
348
349 static void fancy_clear_viewer(MimeViewer *_viewer)
350 {
351         FancyViewer *viewer = (FancyViewer *) _viewer;
352         GtkAdjustment *vadj;
353         viewer->cur_link = NULL;
354         fancy_set_defaults(viewer);
355
356         fancy_load_uri(viewer, "about:blank");
357
358         debug_print("fancy_clear_viewer\n");
359         fancy_prefs.zoom_level = webkit_web_view_get_zoom_level(viewer->view) * 100;
360         viewer->to_load = NULL;
361         vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
362         gtk_adjustment_set_value(vadj, 0.0);
363         g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
364 }
365
366 static void fancy_destroy_viewer(MimeViewer *_viewer)
367 {
368         FancyViewer *viewer = (FancyViewer *) _viewer;
369         fancy_prefs.zoom_level = webkit_web_view_get_zoom_level(viewer->view) * 100;
370         debug_print("fancy_destroy_viewer\n");
371         g_free(viewer->filename);
372         g_free(viewer);
373 }
374
375 static WebKitNavigationResponse
376 navigation_requested_cb(WebKitWebView *view, WebKitWebFrame *frame,
377                                                 WebKitNetworkRequest *netreq, FancyViewer *viewer)
378 {
379         const gchar *uri = webkit_network_request_get_uri(netreq);
380
381         debug_print("navigation requested to %s\n", uri);
382
383         if (!strncmp(uri, "mailto:", 7)) {
384                 compose_new(NULL, uri + 7, NULL);
385                 return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
386         } else if (!strncmp(uri, "file://", 7)) {
387                 return WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
388         } else if (viewer->override_prefs_remote_content)
389                 return WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
390         else {
391                 fancy_show_notice(viewer, _("Remote content loading is disabled."));
392                 return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
393         }
394 }
395
396 static void resource_request_starting_cb(WebKitWebView          *view,
397                                          WebKitWebFrame         *frame,
398                                          WebKitWebResource      *resource,
399                                          WebKitNetworkRequest   *request,
400                                          WebKitNetworkResponse  *response,
401                                          FancyViewer            *viewer)
402 {
403         const gchar *uri = webkit_network_request_get_uri(request);
404         gchar *filename;
405         gchar *image;
406         gint err;
407         MimeInfo *partinfo = viewer->to_load;
408         
409         filename = viewer->filename;
410         if ((!g_ascii_strncasecmp(uri, "cid:", 4)) || (!g_ascii_strncasecmp(uri, "mid:", 4))) {
411                 image = g_strconcat("<", uri + 4, ">", NULL);
412                 while ((partinfo = procmime_mimeinfo_next(partinfo)) != NULL) {
413                         if (!g_ascii_strcasecmp(image, partinfo->id)) {
414                                 filename = procmime_get_tmp_file_name(partinfo);
415                                 if (!filename) {
416                                         g_free(image);
417                                         return;
418                                 }
419                                 if ((err = procmime_get_part(filename, partinfo)) < 0)
420                                         alertpanel_error(_("Couldn't save the part of multipart message: %s"),
421                                                                                 strerror(-err));
422                                 gchar *file_uri = g_filename_to_uri(filename, NULL, NULL);
423                                 webkit_network_request_set_uri(request, file_uri);
424                                 g_free(file_uri);
425                                 g_free(filename);
426                                 break;
427                         }
428                 }
429                 g_free(image);
430         }
431         
432         /* refresh URI that may have changed */
433         uri = webkit_network_request_get_uri(request);
434         if (!viewer->override_prefs_remote_content
435             && strncmp(uri, "file://", 7) && strncmp(uri, "data:", 5)) {
436                 debug_print("Preventing load of %s\n", uri);
437                 webkit_network_request_set_uri(request, "about:blank");
438         }
439         else
440                 debug_print("Starting request of %d %s\n", strlen(uri), uri);
441 }
442
443 static gboolean fancy_text_search(MimeViewer *_viewer, gboolean backward,
444                                   const gchar *str, gboolean case_sens)
445 {
446         return webkit_web_view_search_text(((FancyViewer*)_viewer)->view, str,
447                                            case_sens, !backward, TRUE);
448 }
449
450 static gboolean fancy_prefs_cb(GtkWidget *widget, GdkEventButton *ev, FancyViewer *viewer)
451 {
452         if ((ev->button == 1) && (ev->type == GDK_BUTTON_PRESS)) {
453                 gtk_menu_popup(GTK_MENU(viewer->fancy_prefs_menu), NULL, NULL, NULL, NULL,
454                                 ev->button, ev->time);
455                 return TRUE;
456         }
457         return FALSE;
458 }
459
460 static void fancy_create_popup_prefs_menu(FancyViewer *viewer) {
461         GtkWidget *enable_images;
462         GtkWidget *enable_remote_content;
463         GtkWidget *enable_scripts;
464         GtkWidget *enable_plugins;
465         GtkWidget *enable_java;
466         GtkWidget *open_external;
467
468         enable_images = gtk_check_menu_item_new_with_label(_("Load images"));
469
470         enable_remote_content = gtk_check_menu_item_new_with_label(_("Enable remote content"));
471
472         enable_scripts = gtk_check_menu_item_new_with_label(_("Enable Javascript"));
473
474         enable_plugins = gtk_check_menu_item_new_with_label(_("Enable Plugins"));
475
476         enable_java = gtk_check_menu_item_new_with_label(_("Enable Java"));
477
478         open_external = gtk_check_menu_item_new_with_label(_("Open links with external browser"));
479
480         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_images);
481         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_remote_content);
482         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_scripts);
483         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_plugins);
484         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_java);
485         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), open_external);
486
487         gtk_menu_attach_to_widget(GTK_MENU(viewer->fancy_prefs_menu), viewer->ev_fancy_prefs, NULL);
488         gtk_widget_show_all(viewer->fancy_prefs_menu);
489
490         viewer->enable_images = enable_images;
491         viewer->enable_scripts = enable_scripts;
492         viewer->enable_plugins = enable_plugins;
493         viewer->enable_java = enable_java;
494         viewer->enable_remote_content = enable_remote_content;
495         viewer->open_external = open_external;
496
497         /* Set sensitivity according to preferences and overrides */
498
499         g_signal_connect(G_OBJECT(enable_images), "toggled",
500                          G_CALLBACK (fancy_auto_load_images_activated), viewer);
501         g_signal_connect(G_OBJECT(enable_remote_content), "toggled",
502                          G_CALLBACK (fancy_enable_remote_content_activated), viewer);
503         g_signal_connect(G_OBJECT(enable_scripts), "toggled",
504                          G_CALLBACK (fancy_enable_scripts_activated), viewer);
505         g_signal_connect(G_OBJECT(enable_plugins), "toggled",
506                          G_CALLBACK (fancy_enable_plugins_activated), viewer);
507         g_signal_connect(G_OBJECT(enable_java), "toggled",
508                          G_CALLBACK (fancy_enable_java_activated), viewer);
509         g_signal_connect(G_OBJECT(open_external), "toggled",
510                          G_CALLBACK (fancy_open_external_activated), viewer);
511
512         fancy_apply_prefs(viewer);
513 }
514
515 static gboolean fancy_scroll_page(MimeViewer *_viewer, gboolean up)
516 {
517         FancyViewer *viewer = (FancyViewer *)_viewer;
518         GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
519                                         GTK_SCROLLED_WINDOW(viewer->scrollwin));
520
521         if (viewer->view == NULL)
522                 return FALSE;
523
524         return gtkutils_scroll_page(GTK_WIDGET(viewer->view), vadj, up);
525 }
526
527 static void fancy_scroll_one_line(MimeViewer *_viewer, gboolean up)
528 {
529         FancyViewer *viewer = (FancyViewer *)_viewer;
530         GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
531                                         GTK_SCROLLED_WINDOW(viewer->scrollwin));
532
533         if (viewer->view == NULL)
534                 return;
535
536         gtkutils_scroll_one_line(GTK_WIDGET(viewer->view), vadj, up);
537 }
538
539 static void load_start_cb(WebKitWebView *view, gint progress,
540                           FancyViewer *viewer)
541 {
542         gtk_widget_show(viewer->progress);
543         gtk_widget_show(viewer->ev_stop_loading);
544 }
545
546 static void load_finished_cb(WebKitWebView *view, gint progress,
547                              FancyViewer *viewer)
548 {
549         gtk_widget_hide(viewer->progress);
550         gtk_widget_hide(viewer->ev_stop_loading);
551         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(viewer->progress),
552                                       (gdouble) 0.0);
553         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(viewer->progress), "");
554 }
555
556 static void over_link_cb(WebKitWebView *view, const gchar *wtf,
557                          const gchar *link, FancyViewer *viewer, void *wtfa)
558 {
559         gtk_label_set_text(GTK_LABEL(viewer->l_link), link);
560         g_free(viewer->cur_link);
561         viewer->cur_link = NULL;
562         if(link) {
563                 viewer->cur_link = g_strdup(link);
564         }
565 }
566
567 static void load_progress_cb(WebKitWebView *view, gint progress,
568                              FancyViewer *viewer)
569 {
570         gdouble pbar;
571         gchar *label = g_strdup_printf("%d%% Loading...", progress);
572         pbar = (gdouble) progress / 100;
573         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(viewer->progress), pbar);
574         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(viewer->progress),
575                                   (const gchar*)label);
576         g_free(label);
577 }
578 static void stop_loading_cb(GtkWidget *widget, GdkEvent *ev,
579                                                         FancyViewer *viewer)
580 {
581         webkit_web_view_stop_loading (viewer->view);
582         gtk_widget_hide(viewer->progress);
583         gtk_widget_hide(viewer->ev_stop_loading);
584 }
585
586 static void search_the_web_cb(GtkWidget *widget, FancyViewer *viewer)
587 {
588         debug_print("Clicked on Search on Web\n");
589         if (webkit_web_view_has_selection(viewer->view)) {
590                 gchar *search;
591 #if WEBKIT_CHECK_VERSION(1,5,1)
592                 viewer->doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(viewer->view));
593                 viewer->window = webkit_dom_document_get_default_view (viewer->doc);
594                 viewer->selection = webkit_dom_dom_window_get_selection (viewer->window);
595                 viewer->range = webkit_dom_dom_selection_get_range_at(viewer->selection, 0, NULL);
596                 gchar *tmp = webkit_dom_range_get_text (viewer->range);
597 #else
598                 gchar *tmp = webkit_web_view_get_selected_text(viewer->view);
599 #endif
600                 search = g_strconcat(GOOGLE_SEARCH, tmp, NULL);
601 #if WEBKIT_CHECK_VERSION(1,1,1)
602                 webkit_web_view_load_uri(viewer->view, search);
603 #else
604                 webkit_web_view_open(viewer->view, search);
605 #endif
606                 g_free(search);
607                 g_free(tmp);
608         }
609 }
610
611 static void open_in_browser_cb(GtkWidget *widget, FancyViewer *viewer)
612 {
613         debug_print("open outer: %s\n", viewer->cur_link);
614         if(viewer->cur_link)
615                 open_uri(viewer->cur_link, prefs_common_get_uri_cmd());
616 }
617
618 static size_t download_file_curl_write_cb(void *buffer, size_t size,
619                                           size_t nmemb, void *data)
620 {
621         FancyViewer *viewer = (FancyViewer *)data;
622         if (!viewer->stream) {
623                 viewer->stream = fopen(viewer->curlfile, "wb");
624                 if (!viewer->stream)
625                         return -1;
626         }
627         return fwrite(buffer, size, nmemb, viewer->stream);
628 }
629 static void *download_file_curl (void *data)
630 {
631         CURL *curl;
632         CURLcode res;
633         FancyViewer *viewer = (FancyViewer *)data;
634
635         curl_global_init(CURL_GLOBAL_DEFAULT);
636         curl = curl_easy_init();
637
638         if (curl) {
639                 curl_easy_setopt(curl, CURLOPT_URL, viewer->cur_link);
640                 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, download_file_curl_write_cb);
641                 curl_easy_setopt(curl, CURLOPT_WRITEDATA, viewer);
642                 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
643                 res = curl_easy_perform(curl);
644                 curl_easy_cleanup(curl);
645
646                 if (CURLE_OK != res)
647                         alertpanel_error(_("An error occurred: %d\n"), res);
648                 if (viewer->stream)
649                         fclose(viewer->stream);
650                 curl_global_cleanup();
651         }
652 #ifdef USE_PTHREAD
653         pthread_exit(NULL);
654 #else
655         return NULL;
656 #endif
657 }
658 static void download_file_cb(GtkWidget *widget, FancyViewer *viewer)
659 {
660 #ifdef USE_PTHREAD
661         pthread_t curljob;
662         gint result;
663 #endif
664         const gchar *link = (const gchar *)viewer->cur_link;
665         gchar *filename = g_utf8_strchr(link, -1, g_utf8_get_char("/"));
666         filename = g_strconcat(g_get_home_dir(), filename, NULL);
667         gchar *fname = filesel_select_file_save(_("Save as"), filename);
668
669         if (viewer->curlfile) viewer->curlfile = NULL;
670         if (viewer->stream) viewer->stream = NULL;
671         viewer->curlfile = (const gchar *)g_strdup(fname);
672         g_free(filename);
673         g_free(fname);
674
675         if (!viewer->curlfile) return;
676
677 #ifdef USE_PTHREAD
678         result = pthread_create(&curljob, NULL, download_file_curl, (void *)viewer);
679         if (result)
680                 alertpanel_error("ERROR; return code from pthread_create() is %d\n", result);
681 #else
682         download_file_curl((void *)viewer);
683 #endif
684 }
685
686 static void open_image_cb(GtkWidget *widget, FancyViewer *viewer)
687 {
688         debug_print("Not Yet Implemented\n");
689 }
690
691 static void copy_image_cb(GtkWidget *widget, FancyViewer *viewer)
692 {
693         debug_print("Not Yet Implemented\n");
694 }
695 static void import_feed_cb(GtkWidget *widget, FancyViewer *viewer)
696 {
697         if (!folder_subscribe(viewer->cur_link))
698                 alertpanel_error(_("%s is a malformed or not supported feed"), viewer->cur_link);
699 }
700 static void viewer_menu_handler(GtkWidget *menuitem, FancyViewer *viewer)
701 {
702         const gchar *g_name = gtk_widget_get_name(GTK_WIDGET(menuitem));
703         if (!g_ascii_strcasecmp(g_name, "GtkImageMenuItem")) {
704
705                 GtkWidget *menul = gtk_bin_get_child(GTK_BIN(menuitem));
706
707         if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)),
708                                 "Search the Web")) {
709                         gtk_label_set_text(GTK_LABEL(menul), _("Search the Web"));
710                         viewer->cur_link = NULL;
711                         GtkImageMenuItem *m_search = GTK_IMAGE_MENU_ITEM(menuitem);
712                         g_signal_connect(G_OBJECT(m_search), "activate",
713                                          G_CALLBACK(search_the_web_cb),
714                                          (gpointer *) viewer);
715                 }
716
717                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)),
718                                         "Open Link" )) {
719
720                         if (viewer->override_prefs_remote_content)
721                                 gtk_label_set_text(GTK_LABEL(menul), _("Open in Viewer"));
722                         else
723                                 gtk_label_set_text(GTK_LABEL(menul), _("Open in Viewer (enable remote content)"));
724
725                         GtkImageMenuItem *m_new = GTK_IMAGE_MENU_ITEM(menuitem);
726                         gtk_widget_set_sensitive(GTK_WIDGET(m_new), viewer->override_prefs_remote_content);
727                 }
728
729                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)),
730                                                                 "Open Link in New Window" )) {
731
732                         gtk_label_set_text(GTK_LABEL(menul), _("Open in Browser"));
733
734                         GtkImageMenuItem *m_new = GTK_IMAGE_MENU_ITEM(menuitem);
735                         g_signal_connect(G_OBJECT(m_new), "activate",
736                                          G_CALLBACK(open_in_browser_cb),
737                                          (gpointer *) viewer);
738                 }
739
740                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)),
741                                         "Open Image in New Window" )) {
742                         gtk_label_set_text(GTK_LABEL(menul), _("Open Image"));
743                         GtkImageMenuItem *m_image = GTK_IMAGE_MENU_ITEM(menuitem);
744                         g_signal_connect(G_OBJECT(m_image), "activate",
745                                          G_CALLBACK(open_image_cb),
746                                          (gpointer *) viewer);
747                 }
748
749                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)),
750                                         "Copy Link Location" )) {
751                         gtk_label_set_text(GTK_LABEL(menul), _("Copy Link"));
752                 }
753         if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)),
754                                 "Download Linked File" )) {
755                         gtk_label_set_text(GTK_LABEL(menul), _("Download Link"));
756
757                         GtkImageMenuItem *m_dlink = GTK_IMAGE_MENU_ITEM(menuitem);
758                         g_signal_connect(G_OBJECT(m_dlink), "activate",
759                                          G_CALLBACK(download_file_cb),
760                                          (gpointer *) viewer);
761                 }
762
763                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)),
764                                         "Save Image As" )) {
765
766                         gtk_label_set_text(GTK_LABEL(menul), _("Save Image As"));
767
768                         GtkImageMenuItem *m_simage = GTK_IMAGE_MENU_ITEM(menuitem);
769                         g_signal_connect(G_OBJECT(m_simage), "activate",
770                                          G_CALLBACK(download_file_cb),
771                                          (gpointer *) viewer);
772                 }
773
774                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)),
775                                         "Copy Image" )) {
776                         gtk_label_set_text(GTK_LABEL(menul), _("Copy Image"));
777                         GtkImageMenuItem *m_cimage = GTK_IMAGE_MENU_ITEM(menuitem);
778                         g_signal_connect(G_OBJECT(m_cimage), "activate",
779                                          G_CALLBACK(copy_image_cb),
780                                          (gpointer *) viewer);
781                 }
782
783         }
784 }
785
786 static gboolean populate_popup_cb (WebKitWebView *view, GtkWidget *menu,
787                                    FancyViewer *viewer)
788 {
789         Plugin *plugin = plugin_get_loaded_by_name("RSSyl");
790         gtk_container_foreach(GTK_CONTAINER(menu),
791                               (GtkCallback)viewer_menu_handler,
792                               viewer);
793         if (plugin) {
794                 GtkWidget *rssyl = gtk_image_menu_item_new_with_label(_("Import feed"));
795                 GtkWidget *img = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU);
796                 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(rssyl), img);
797                 gtk_widget_show(GTK_WIDGET(rssyl));
798                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), rssyl);
799                 g_signal_connect(G_OBJECT(rssyl), "activate",
800                                  G_CALLBACK(import_feed_cb),
801                                  (gpointer *) viewer);
802         }
803         return TRUE;
804 }
805
806 static gint keypress_events_cb (GtkWidget *widget, GdkEventKey *event,
807                                                                 FancyViewer *viewer)
808 {
809         if (event->state == CTRL_KEY) {
810                 switch (event->keyval) {
811                 case GDK_plus:
812                         zoom_in_cb(viewer->ev_zoom_in, NULL, viewer);
813                         break;
814                 case GDK_period:
815                         zoom_100_cb(viewer->ev_zoom_100, NULL, viewer);
816                         break;
817                 case GDK_minus:
818                         zoom_out_cb(viewer->ev_zoom_out, NULL, viewer);
819                         break;
820                 }
821         }
822         return FALSE;
823 }
824
825 static gboolean release_button_cb (WebKitWebView *view, GdkEvent *ev,
826                                    FancyViewer *viewer)
827 {
828         if (ev->button.button == 1 && viewer->cur_link && viewer->override_prefs_external) {
829                 open_uri(viewer->cur_link, prefs_common_get_uri_cmd());
830                 return TRUE;
831         }
832         return FALSE;
833 }
834 static void zoom_100_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer)
835 {
836         gtk_widget_grab_focus(widget);
837         webkit_web_view_set_zoom_level(viewer->view, 1);
838 }
839
840 static void zoom_in_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer)
841 {
842         gtk_widget_grab_focus(widget);
843         webkit_web_view_zoom_in(viewer->view);
844 }
845 static void zoom_out_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer)
846 {
847         gtk_widget_grab_focus(widget);
848         webkit_web_view_zoom_out(viewer->view);
849 }
850
851 static MimeViewer *fancy_viewer_create(void)
852 {
853         FancyViewer    *viewer;
854         GtkWidget      *hbox;
855
856         debug_print("fancy_viewer_create\n");
857
858         viewer = g_new0(FancyViewer, 1);
859         viewer->mimeviewer.factory = &fancy_viewer_factory;
860         viewer->mimeviewer.get_widget = fancy_get_widget;
861         viewer->mimeviewer.get_selection = fancy_get_selection;
862         viewer->mimeviewer.show_mimepart = fancy_show_mimepart;
863         viewer->mimeviewer.print = fancy_print;
864         viewer->mimeviewer.clear_viewer = fancy_clear_viewer;
865         viewer->mimeviewer.destroy_viewer = fancy_destroy_viewer;
866         viewer->mimeviewer.text_search = fancy_text_search;
867         viewer->mimeviewer.scroll_page = fancy_scroll_page;
868         viewer->mimeviewer.scroll_one_line = fancy_scroll_one_line;
869         viewer->view = WEBKIT_WEB_VIEW(webkit_web_view_new());
870
871 #ifdef HAVE_LIBSOUP_GNOME
872  /* Use GNOME proxy settings through libproxy */
873         if (fancy_prefs.enable_gnome_proxy) {
874                 SoupSession *session = webkit_get_default_session();
875                 soup_session_add_feature_by_type (session, SOUP_TYPE_PROXY_RESOLVER_GNOME);
876         }
877 #endif
878         
879         if (fancy_prefs.enable_proxy) {
880                 SoupSession *session = webkit_get_default_session();
881                 SoupURI* pURI = soup_uri_new(fancy_prefs.proxy_str);
882                 g_object_set(session, "proxy-uri", pURI, NULL);
883         }
884
885         viewer->settings = webkit_web_settings_new();
886         g_object_set(viewer->settings, "user-agent", "Fancy Viewer", NULL);
887         viewer->scrollwin = gtk_scrolled_window_new(NULL, NULL);
888         viewer->tag = -1;
889         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(viewer->scrollwin),
890                                        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
891         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(viewer->scrollwin),
892                                             GTK_SHADOW_IN);
893         gtk_container_add(GTK_CONTAINER(viewer->scrollwin),
894                           GTK_WIDGET(viewer->view));
895
896         viewer->vbox = gtk_vbox_new(FALSE, 0);
897         hbox = gtk_hbox_new(FALSE, 0);
898         viewer->progress = gtk_progress_bar_new();
899         /* Zoom Widgets */
900         viewer->zoom_100 = gtk_image_new_from_stock(GTK_STOCK_ZOOM_100, GTK_ICON_SIZE_MENU);
901         viewer->zoom_in = gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_MENU);
902         viewer->zoom_out = gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_MENU);
903         viewer->stop_loading = gtk_image_new_from_stock(GTK_STOCK_CANCEL, GTK_ICON_SIZE_MENU);
904         /* Event Widgets for the Zoom Widgets  */
905         viewer->ev_zoom_100 = gtk_event_box_new();
906         viewer->ev_zoom_in = gtk_event_box_new();
907         viewer->ev_zoom_out = gtk_event_box_new();
908         viewer->ev_stop_loading = gtk_event_box_new();
909
910         /* Link Label */
911         viewer->l_link = gtk_label_new("");
912
913         /* Preferences Widgets to override preferences on the fly  */
914         viewer->fancy_prefs = gtk_image_new_from_stock(GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU);
915         viewer->ev_fancy_prefs = gtk_event_box_new();
916
917         /* Popup Menu for preferences  */
918         viewer->fancy_prefs_menu = gtk_menu_new();
919         fancy_create_popup_prefs_menu(viewer);
920
921         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_zoom_100), FALSE);
922         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_zoom_in), FALSE);
923         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_zoom_out), FALSE);
924         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_fancy_prefs), FALSE);
925         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_stop_loading), FALSE);
926
927         gtk_container_add(GTK_CONTAINER(viewer->ev_zoom_100), viewer->zoom_100);
928         gtk_container_add(GTK_CONTAINER(viewer->ev_zoom_in), viewer->zoom_in);
929         gtk_container_add(GTK_CONTAINER(viewer->ev_zoom_out), viewer->zoom_out);
930         gtk_container_add(GTK_CONTAINER(viewer->ev_fancy_prefs), viewer->fancy_prefs);
931         gtk_container_add(GTK_CONTAINER(viewer->ev_stop_loading), viewer->stop_loading);
932
933         gtk_box_pack_start(GTK_BOX(hbox), viewer->ev_zoom_100, FALSE, FALSE, 1);
934         gtk_box_pack_start(GTK_BOX(hbox), viewer->ev_zoom_in, FALSE, FALSE, 2);
935         gtk_box_pack_start(GTK_BOX(hbox), viewer->ev_zoom_out, FALSE, FALSE, 2);
936         gtk_box_pack_start(GTK_BOX(hbox), viewer->ev_fancy_prefs, FALSE, FALSE, 2);
937         gtk_box_pack_start(GTK_BOX(hbox), viewer->l_link, FALSE, FALSE, 8);
938         gtk_box_pack_end(GTK_BOX(hbox), viewer->progress, FALSE, FALSE, 0);
939         gtk_box_pack_end(GTK_BOX(hbox), viewer->ev_stop_loading, FALSE, FALSE, 0);
940
941         gtk_box_pack_start(GTK_BOX(viewer->vbox), viewer->scrollwin, TRUE, TRUE,
942                        1);
943         gtk_box_pack_start(GTK_BOX(viewer->vbox), hbox, FALSE, FALSE, 0);
944
945         gtk_widget_show(viewer->ev_zoom_100);
946         gtk_widget_show(viewer->ev_zoom_in);
947         gtk_widget_show(viewer->ev_zoom_out);
948         gtk_widget_show(viewer->ev_fancy_prefs);
949
950         gtk_widget_show(viewer->scrollwin);
951         gtk_widget_show(viewer->zoom_100);
952         gtk_widget_show(viewer->zoom_in);
953         gtk_widget_show(viewer->zoom_out);
954         gtk_widget_show(viewer->fancy_prefs);
955         gtk_widget_show(viewer->stop_loading);
956
957         gtk_widget_show(viewer->l_link);
958         gtk_widget_show(viewer->vbox);
959         gtk_widget_show(hbox);
960         gtk_widget_show(GTK_WIDGET(viewer->view));
961
962         g_signal_connect(G_OBJECT(viewer->view), "load-started",
963                          G_CALLBACK(load_start_cb), viewer);
964         g_signal_connect(G_OBJECT(viewer->view), "load-finished",
965                          G_CALLBACK(load_finished_cb), viewer);
966         g_signal_connect(G_OBJECT(viewer->view), "hovering-over-link",
967                          G_CALLBACK(over_link_cb), viewer);
968         g_signal_connect(G_OBJECT(viewer->view), "load-progress-changed",
969                          G_CALLBACK(load_progress_cb), viewer);
970         g_signal_connect(G_OBJECT(viewer->view), "navigation-requested",
971                          G_CALLBACK(navigation_requested_cb), viewer);
972         g_signal_connect(G_OBJECT(viewer->view), "resource-request-starting",
973                         G_CALLBACK(resource_request_starting_cb), viewer);
974         g_signal_connect(G_OBJECT(viewer->view), "populate-popup",
975                          G_CALLBACK(populate_popup_cb), viewer);
976         g_signal_connect(G_OBJECT(viewer->view), "button-release-event",
977                          G_CALLBACK(release_button_cb), viewer);
978         g_signal_connect(G_OBJECT(viewer->ev_zoom_100), "button-press-event",
979                          G_CALLBACK(zoom_100_cb), (gpointer*)viewer);
980         g_signal_connect(G_OBJECT(viewer->ev_zoom_in), "button-press-event",
981                          G_CALLBACK(zoom_in_cb), (gpointer *)viewer);
982         g_signal_connect(G_OBJECT(viewer->ev_zoom_out), "button-press-event",
983                          G_CALLBACK(zoom_out_cb), (gpointer *)viewer);
984         g_signal_connect(G_OBJECT(viewer->ev_fancy_prefs), "button-press-event",
985                          G_CALLBACK(fancy_prefs_cb), (gpointer *)viewer);
986         g_signal_connect(G_OBJECT(viewer->ev_stop_loading), "button-press-event",
987                          G_CALLBACK(stop_loading_cb), viewer);
988         g_signal_connect(G_OBJECT(viewer->view), "key_press_event",
989                          G_CALLBACK(keypress_events_cb), viewer);
990
991         viewer->filename = NULL;
992         return (MimeViewer *) viewer;
993 }
994
995 static gchar *content_types[] = {"text/html", NULL};
996
997 static MimeViewerFactory fancy_viewer_factory =
998 {
999         content_types,
1000         0,
1001         fancy_viewer_create,
1002 };
1003
1004 gint plugin_init(gchar **error)
1005 {
1006         if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
1007                                   VERSION_NUMERIC, _("Fancy"), error))
1008                 return -1;
1009         gchar *directory = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
1010                                 "fancy", NULL);
1011         if (!is_dir_exist(directory))
1012                 make_dir (directory);
1013         g_free(directory);
1014
1015         fancy_prefs_init();
1016
1017         mimeview_register_viewer_factory(&fancy_viewer_factory);
1018
1019         return 0;
1020 }
1021
1022 gboolean plugin_done(void)
1023 {
1024         mimeview_unregister_viewer_factory(&fancy_viewer_factory);
1025         fancy_prefs_done();
1026         return FALSE;
1027 }
1028
1029 const gchar *plugin_name(void)
1030 {
1031         /* i18n: 'Fancy' here is name of the plugin, not the english word. */
1032         return _("Fancy HTML Viewer");
1033 }
1034
1035 const gchar *plugin_desc(void)
1036 {
1037         return g_strdup_printf(_("This plugin renders HTML mail using the WebKit "
1038                                "%d.%d.%d library.\nBy default all remote content is "
1039                                "blocked and images are not automatically loaded. Options "
1040                                "can be found in /Configuration/Preferences/Plugins/Fancy"),
1041                                WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION,
1042                                WEBKIT_MICRO_VERSION);
1043 }
1044
1045 const gchar *plugin_type(void)
1046 {
1047         return "GTK2";
1048 }
1049
1050 const gchar *plugin_licence(void)
1051 {
1052         return "GPL3";
1053 }
1054
1055 const gchar *plugin_version(void)
1056 {
1057         return VERSION;
1058 }
1059
1060 struct PluginFeature *plugin_provides(void)
1061 {
1062         static struct PluginFeature features[] = {
1063                                         {PLUGIN_MIMEVIEWER, "text/html"},
1064                                 {PLUGIN_NOTHING, NULL}
1065         };
1066         return features;
1067 }