1 /* 2 * Copyright (C) 2010 Igalia S.L. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 #include "config.h" 20 #include "webkitwebplugindatabase.h" 21 22 #include "PluginDatabase.h" 23 #include "webkitglobalsprivate.h" 24 #include "webkitwebplugindatabaseprivate.h" 25 #include "webkitwebpluginprivate.h" 26 27 /** 28 * SECTION:webkitwebplugindatabase 29 * @short_description: Provides information about the plugins the engine knows about 30 * @see_also: #WebKitWebPlugin 31 * 32 * This object allows you to query information about the plugins found 33 * by the engine while scanning the usual directories. You can then 34 * use the #WebKitWebPlugin objects to get more information or 35 * enable/disable individual plugins. 36 */ 37 38 using namespace WebKit; 39 using namespace WebCore; 40 41 G_DEFINE_TYPE(WebKitWebPluginDatabase, webkit_web_plugin_database, G_TYPE_OBJECT) 42 43 static void webkit_web_plugin_database_dispose(GObject* object) 44 { 45 G_OBJECT_CLASS(webkit_web_plugin_database_parent_class)->dispose(object); 46 } 47 48 static void webkit_web_plugin_database_class_init(WebKitWebPluginDatabaseClass* klass) 49 { 50 webkitInit(); 51 52 GObjectClass* gobjectClass = reinterpret_cast<GObjectClass*>(klass); 53 54 gobjectClass->dispose = webkit_web_plugin_database_dispose; 55 56 g_type_class_add_private(klass, sizeof(WebKitWebPluginDatabasePrivate)); 57 } 58 59 static void webkit_web_plugin_database_init(WebKitWebPluginDatabase* database) 60 { 61 WebKitWebPluginDatabasePrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(database, WEBKIT_TYPE_WEB_PLUGIN_DATABASE, WebKitWebPluginDatabasePrivate); 62 database->priv = priv; 63 64 priv->coreDatabase = PluginDatabase::installedPlugins(); 65 } 66 67 /** 68 * webkit_web_plugin_database_list_free: 69 * @list: a #WebKitWebPluginDatabasePluginList 70 * 71 * Frees @list. 72 * 73 * Since: 1.3.8 74 */ 75 void webkit_web_plugin_database_plugins_list_free(GSList* list) 76 { 77 if (!list) 78 return; 79 80 for (GSList* p = list; p; p = p->next) 81 g_object_unref(p->data); 82 83 g_slist_free(list); 84 } 85 86 /** 87 * webkit_web_plugin_database_get_plugins: 88 * @database: a #WebKitWebPluginDatabase 89 * 90 * Returns all #WebKitWebPlugin available in @database. 91 * The returned list must be freed with webkit_web_plugin_database_plugins_list_free() 92 * 93 * Returns: (transfer full) (element-type WebKitWebPlugin): a #GSList of #WebKitWebPlugin 94 * 95 * Since: 1.3.8 96 */ 97 GSList* webkit_web_plugin_database_get_plugins(WebKitWebPluginDatabase* database) 98 { 99 g_return_val_if_fail(WEBKIT_IS_WEB_PLUGIN_DATABASE(database), 0); 100 101 GSList* gPlugins = 0; 102 const Vector<PluginPackage*>& plugins = database->priv->coreDatabase->plugins(); 103 104 for (unsigned int i = 0; i < plugins.size(); ++i) { 105 PluginPackage* plugin = plugins[i]; 106 gPlugins = g_slist_append(gPlugins, kitNew(plugin)); 107 } 108 109 return gPlugins; 110 } 111 112 /** 113 * webkit_web_plugin_database_get_plugin_for_mimetype: 114 * @database: a #WebKitWebPluginDatabase 115 * @mimeType: a mime type 116 * 117 * Returns the #WebKitWebPlugin that is handling @mimeType in the 118 * @database, or %NULL if there's none doing so. 119 * 120 * Returns: (transfer full): a #WebKitWebPlugin 121 * 122 * Since: 1.3.8 123 */ 124 WebKitWebPlugin* webkit_web_plugin_database_get_plugin_for_mimetype(WebKitWebPluginDatabase* database, const char* mimeType) 125 { 126 g_return_val_if_fail(WEBKIT_IS_WEB_PLUGIN_DATABASE(database), 0); 127 g_return_val_if_fail(mimeType, 0); 128 129 return kitNew(database->priv->coreDatabase->pluginForMIMEType(mimeType)); 130 } 131 132 /** 133 * webkit_web_plugin_database_refresh: 134 * @database: a #WebKitWebPluginDatabase 135 * 136 * Refreshes @database adding new plugins that are now in use and 137 * removing those that have been disabled or are otherwise no longer 138 * available. 139 * 140 * Since: 1.3.8 141 */ 142 void webkit_web_plugin_database_refresh(WebKitWebPluginDatabase* database) 143 { 144 g_return_if_fail(WEBKIT_IS_WEB_PLUGIN_DATABASE(database)); 145 146 database->priv->coreDatabase->refresh(); 147 } 148 149 WebKitWebPluginDatabase* webkit_web_plugin_database_new(void) 150 { 151 return WEBKIT_WEB_PLUGIN_DATABASE(g_object_new(WEBKIT_TYPE_WEB_PLUGIN_DATABASE, 0)); 152 } 153