2 * Copyright (C) 2010 Igalia S.L.
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.
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.
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
20 #include "webkitwebplugindatabase.h"
22 #include "PluginDatabase.h"
23 #include "webkitglobalsprivate.h"
24 #include "webkitwebplugindatabaseprivate.h"
25 #include "webkitwebpluginprivate.h"
28 * SECTION:webkitwebplugindatabase
29 * @short_description: Provides information about the plugins the engine knows about
30 * @see_also: #WebKitWebPlugin
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.
38 using namespace WebKit;
39 using namespace WebCore;
41 G_DEFINE_TYPE(WebKitWebPluginDatabase, webkit_web_plugin_database, G_TYPE_OBJECT)
43 static void webkit_web_plugin_database_dispose(GObject* object)
45 G_OBJECT_CLASS(webkit_web_plugin_database_parent_class)->dispose(object);
48 static void webkit_web_plugin_database_class_init(WebKitWebPluginDatabaseClass* klass)
52 GObjectClass* gobjectClass = reinterpret_cast<GObjectClass*>(klass);
54 gobjectClass->dispose = webkit_web_plugin_database_dispose;
56 g_type_class_add_private(klass, sizeof(WebKitWebPluginDatabasePrivate));
59 static void webkit_web_plugin_database_init(WebKitWebPluginDatabase* database)
61 WebKitWebPluginDatabasePrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(database, WEBKIT_TYPE_WEB_PLUGIN_DATABASE, WebKitWebPluginDatabasePrivate);
62 database->priv = priv;
64 priv->coreDatabase = PluginDatabase::installedPlugins();
68 * webkit_web_plugin_database_list_free:
69 * @list: a #WebKitWebPluginDatabasePluginList
75 void webkit_web_plugin_database_plugins_list_free(GSList* list)
80 for (GSList* p = list; p; p = p->next)
81 g_object_unref(p->data);
87 * webkit_web_plugin_database_get_plugins:
88 * @database: a #WebKitWebPluginDatabase
90 * Returns all #WebKitWebPlugin available in @database.
91 * The returned list must be freed with webkit_web_plugin_database_plugins_list_free()
93 * Returns: (transfer full) (element-type WebKitWebPlugin): a #GSList of #WebKitWebPlugin
97 GSList* webkit_web_plugin_database_get_plugins(WebKitWebPluginDatabase* database)
99 g_return_val_if_fail(WEBKIT_IS_WEB_PLUGIN_DATABASE(database), 0);
101 GSList* gPlugins = 0;
102 const Vector<PluginPackage*>& plugins = database->priv->coreDatabase->plugins();
104 for (unsigned int i = 0; i < plugins.size(); ++i) {
105 PluginPackage* plugin = plugins[i];
106 gPlugins = g_slist_append(gPlugins, kitNew(plugin));
113 * webkit_web_plugin_database_get_plugin_for_mimetype:
114 * @database: a #WebKitWebPluginDatabase
115 * @mime_type: a mime type
117 * Returns the #WebKitWebPlugin that is handling @mimeType in the
118 * @database, or %NULL if there's none doing so.
120 * Returns: (transfer full): a #WebKitWebPlugin
124 WebKitWebPlugin* webkit_web_plugin_database_get_plugin_for_mimetype(WebKitWebPluginDatabase* database, const char* mimeType)
126 g_return_val_if_fail(WEBKIT_IS_WEB_PLUGIN_DATABASE(database), 0);
127 g_return_val_if_fail(mimeType, 0);
129 return kitNew(database->priv->coreDatabase->pluginForMIMEType(mimeType));
133 * webkit_web_plugin_database_refresh:
134 * @database: a #WebKitWebPluginDatabase
136 * Refreshes @database adding new plugins that are now in use and
137 * removing those that have been disabled or are otherwise no longer
142 void webkit_web_plugin_database_refresh(WebKitWebPluginDatabase* database)
144 g_return_if_fail(WEBKIT_IS_WEB_PLUGIN_DATABASE(database));
146 database->priv->coreDatabase->refresh();
149 WebKitWebPluginDatabase* webkit_web_plugin_database_new(void)
151 return WEBKIT_WEB_PLUGIN_DATABASE(g_object_new(WEBKIT_TYPE_WEB_PLUGIN_DATABASE, 0));