Mercurial > pidgin.yaz
comparison pidgin/plugins/webkit.c @ 32779:d72f2f13b60f
merge of 'c8c73eea7431e6f940916315ace40a41c8da3faa'
and 'fec428131bde0ae8247941bd6a3d996c984c9189'
| author | Ethan Blanton <elb@pidgin.im> |
|---|---|
| date | Fri, 21 Oct 2011 14:36:18 +0000 |
| parents | afd256914830 |
| children |
comparison
equal
deleted
inserted
replaced
| 32778:14787acaf9d7 | 32779:d72f2f13b60f |
|---|---|
| 1 /* | |
| 2 * WebKit - Open the inspector on any WebKit views. | |
| 3 * Copyright (C) 2011 Elliott Sales de Andrade <qulogic@pidgin.im> | |
| 4 * | |
| 5 * This program is free software; you can redistribute it and/or | |
| 6 * modify it under the terms of the GNU General Public License | |
| 7 * as published by the Free Software Foundation; either version 2 | |
| 8 * of the License, or (at your option) any later version. | |
| 9 * | |
| 10 * This program is distributed in the hope that it will be useful, | |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 * GNU General Public License for more details. | |
| 14 * | |
| 15 * You should have received a copy of the GNU General Public License | |
| 16 * along with this program; if not, write to the Free Software | |
| 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 18 */ | |
| 19 | |
| 20 #ifdef HAVE_CONFIG_H | |
| 21 #include <config.h> | |
| 22 #endif | |
| 23 | |
| 24 #include "internal.h" | |
| 25 | |
| 26 #include "version.h" | |
| 27 | |
| 28 #include "pidgin.h" | |
| 29 | |
| 30 #include "gtkconv.h" | |
| 31 #include "gtkplugin.h" | |
| 32 #include "gtkwebview.h" | |
| 33 | |
| 34 static WebKitWebView * | |
| 35 create_gtk_window_around_it(WebKitWebInspector *inspector, | |
| 36 WebKitWebView *webview, | |
| 37 PidginConversation *gtkconv) | |
| 38 { | |
| 39 GtkWidget *win; | |
| 40 GtkWidget *view; | |
| 41 char *title; | |
| 42 | |
| 43 win = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 44 title = g_strdup_printf(_("%s - Inspector"), | |
| 45 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label))); | |
| 46 gtk_window_set_title(GTK_WINDOW(win), title); | |
| 47 g_free(title); | |
| 48 gtk_window_set_default_size(GTK_WINDOW(win), 600, 400); | |
| 49 g_signal_connect_swapped(G_OBJECT(gtkconv->tab_cont), "destroy", G_CALLBACK(gtk_widget_destroy), win); | |
| 50 | |
| 51 view = webkit_web_view_new(); | |
| 52 gtk_container_add(GTK_CONTAINER(win), view); | |
| 53 g_object_set_data(G_OBJECT(webview), "inspector-window", win); | |
| 54 | |
| 55 return WEBKIT_WEB_VIEW(view); | |
| 56 } | |
| 57 | |
| 58 static gboolean | |
| 59 show_inspector_window(WebKitWebInspector *inspector, | |
| 60 GtkWidget *webview) | |
| 61 { | |
| 62 GtkWidget *win; | |
| 63 | |
| 64 win = g_object_get_data(G_OBJECT(webview), "inspector-window"); | |
| 65 | |
| 66 gtk_widget_show_all(win); | |
| 67 | |
| 68 return TRUE; | |
| 69 } | |
| 70 | |
| 71 static void | |
| 72 setup_inspector(PidginConversation *gtkconv) | |
| 73 { | |
| 74 GtkWidget *webview = gtkconv->webview; | |
| 75 WebKitWebSettings *settings; | |
| 76 WebKitWebInspector *inspector; | |
| 77 | |
| 78 settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview)); | |
| 79 inspector = webkit_web_view_get_inspector(WEBKIT_WEB_VIEW(webview)); | |
| 80 | |
| 81 g_object_set(G_OBJECT(settings), "enable-developer-extras", TRUE, NULL); | |
| 82 | |
| 83 g_signal_connect(G_OBJECT(inspector), "inspect-web-view", | |
| 84 G_CALLBACK(create_gtk_window_around_it), gtkconv); | |
| 85 g_signal_connect(G_OBJECT(inspector), "show-window", | |
| 86 G_CALLBACK(show_inspector_window), webview); | |
| 87 } | |
| 88 | |
| 89 static void | |
| 90 remove_inspector(PidginConversation *gtkconv) | |
| 91 { | |
| 92 GtkWidget *webview = gtkconv->webview; | |
| 93 GtkWidget *win; | |
| 94 WebKitWebSettings *settings; | |
| 95 | |
| 96 win = g_object_get_data(G_OBJECT(webview), "inspector-window"); | |
| 97 gtk_widget_destroy(win); | |
| 98 g_object_set_data(G_OBJECT(webview), "inspector-window", NULL); | |
| 99 | |
| 100 settings = webkit_web_view_get_settings(WEBKIT_WEB_VIEW(webview)); | |
| 101 | |
| 102 g_object_set(G_OBJECT(settings), "enable-developer-extras", FALSE, NULL); | |
| 103 } | |
| 104 | |
| 105 static void | |
| 106 conversation_displayed_cb(PidginConversation *gtkconv) | |
| 107 { | |
| 108 GtkWidget *inspect = NULL; | |
| 109 | |
| 110 inspect = g_object_get_data(G_OBJECT(gtkconv->webview), | |
| 111 "inspector-window"); | |
| 112 if (inspect == NULL) { | |
| 113 setup_inspector(gtkconv); | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 static gboolean | |
| 118 plugin_load(PurplePlugin *plugin) | |
| 119 { | |
| 120 GList *convs = purple_get_conversations(); | |
| 121 void *gtk_conv_handle = pidgin_conversations_get_handle(); | |
| 122 | |
| 123 purple_signal_connect(gtk_conv_handle, "conversation-displayed", plugin, | |
| 124 PURPLE_CALLBACK(conversation_displayed_cb), NULL); | |
| 125 | |
| 126 while (convs) { | |
| 127 PurpleConversation *conv = (PurpleConversation *)convs->data; | |
| 128 | |
| 129 /* Setup WebKit Inspector */ | |
| 130 if (PIDGIN_IS_PIDGIN_CONVERSATION(conv)) { | |
| 131 setup_inspector(PIDGIN_CONVERSATION(conv)); | |
| 132 } | |
| 133 | |
| 134 convs = convs->next; | |
| 135 } | |
| 136 | |
| 137 return TRUE; | |
| 138 } | |
| 139 | |
| 140 static gboolean | |
| 141 plugin_unload(PurplePlugin *plugin) | |
| 142 { | |
| 143 GList *convs = purple_get_conversations(); | |
| 144 | |
| 145 while (convs) { | |
| 146 PurpleConversation *conv = (PurpleConversation *)convs->data; | |
| 147 | |
| 148 /* Remove WebKit Inspector */ | |
| 149 if (PIDGIN_IS_PIDGIN_CONVERSATION(conv)) { | |
| 150 remove_inspector(PIDGIN_CONVERSATION(conv)); | |
| 151 } | |
| 152 | |
| 153 convs = convs->next; | |
| 154 } | |
| 155 | |
| 156 return TRUE; | |
| 157 } | |
| 158 | |
| 159 static PurplePluginInfo info = | |
| 160 { | |
| 161 PURPLE_PLUGIN_MAGIC, | |
| 162 PURPLE_MAJOR_VERSION, /**< major version */ | |
| 163 PURPLE_MINOR_VERSION, /**< minor version */ | |
| 164 PURPLE_PLUGIN_STANDARD, /**< type */ | |
| 165 PIDGIN_PLUGIN_TYPE, /**< ui_requirement */ | |
| 166 0, /**< flags */ | |
| 167 NULL, /**< dependencies */ | |
| 168 PURPLE_PRIORITY_DEFAULT, /**< priority */ | |
| 169 | |
| 170 "gtkwebkit-inspect", /**< id */ | |
| 171 N_("WebKit Development"), /**< name */ | |
| 172 DISPLAY_VERSION, /**< version */ | |
| 173 N_("Enables WebKit Inspector."), /**< summary */ | |
| 174 N_("Enables WebKit's built-in inspector in a " | |
| 175 "conversation window. This may be viewed " | |
| 176 "by right-clicking a WebKit widget and " | |
| 177 "selecting 'Inspect Element'."), /**< description */ | |
| 178 "Elliott Sales de Andrade <qulogic@pidgin.im>", /**< author */ | |
| 179 PURPLE_WEBSITE, /**< homepage */ | |
| 180 plugin_load, /**< load */ | |
| 181 plugin_unload, /**< unload */ | |
| 182 NULL, /**< destroy */ | |
| 183 NULL, /**< ui_info */ | |
| 184 NULL, /**< extra_info */ | |
| 185 NULL, /**< prefs_info */ | |
| 186 NULL, /**< actions */ | |
| 187 | |
| 188 /* padding */ | |
| 189 NULL, | |
| 190 NULL, | |
| 191 NULL, | |
| 192 NULL | |
| 193 }; | |
| 194 | |
| 195 static void | |
| 196 init_plugin(PurplePlugin *plugin) | |
| 197 { | |
| 198 } | |
| 199 | |
| 200 PURPLE_INIT_PLUGIN(webkit-devel, init_plugin, info) | |
| 201 |
