| 1 | /* |
| 2 | * Copyright (C) 2012 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 Library 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 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public License |
| 15 | * along with this library; see the file COPYING.LIB. If not, write to |
| 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "config.h" |
| 21 | #include "WebKitPlugin.h" |
| 22 | |
| 23 | #include "WebKitMimeInfoPrivate.h" |
| 24 | #include "WebKitPluginPrivate.h" |
| 25 | #include <wtf/glib/WTFGType.h> |
| 26 | #include <wtf/text/CString.h> |
| 27 | |
| 28 | using namespace WebKit; |
| 29 | |
| 30 | /** |
| 31 | * SECTION: WebKitPlugin |
| 32 | * @Short_description: Represents a plugin, enabling fine-grained control |
| 33 | * @Title: WebKitPlugin |
| 34 | * |
| 35 | * This object represents a single plugin, found while scanning the |
| 36 | * various platform plugin directories. This object can be used to get |
| 37 | * more information about a plugin, and enable/disable it, allowing |
| 38 | * fine-grained control of plugins. The list of available plugins can |
| 39 | * be obtained from the #WebKitWebContext, with |
| 40 | * webkit_web_context_get_plugins(). |
| 41 | * |
| 42 | */ |
| 43 | |
| 44 | struct _WebKitPluginPrivate { |
| 45 | ~_WebKitPluginPrivate() |
| 46 | { |
| 47 | g_list_free_full(mimeInfoList, reinterpret_cast<GDestroyNotify>(webkit_mime_info_unref)); |
| 48 | } |
| 49 | |
| 50 | PluginModuleInfo pluginInfo; |
| 51 | CString name; |
| 52 | CString description; |
| 53 | CString path; |
| 54 | GList* mimeInfoList; |
| 55 | }; |
| 56 | |
| 57 | WEBKIT_DEFINE_TYPE(WebKitPlugin, webkit_plugin, G_TYPE_OBJECT) |
| 58 | |
| 59 | static void webkit_plugin_class_init(WebKitPluginClass*) |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | WebKitPlugin* webkitPluginCreate(const PluginModuleInfo& pluginInfo) |
| 64 | { |
| 65 | WebKitPlugin* plugin = WEBKIT_PLUGIN(g_object_new(WEBKIT_TYPE_PLUGIN, NULL)); |
| 66 | plugin->priv->pluginInfo = pluginInfo; |
| 67 | return plugin; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * webkit_plugin_get_name: |
| 72 | * @plugin: a #WebKitPlugin |
| 73 | * |
| 74 | * Returns: the name of the plugin. |
| 75 | */ |
| 76 | const char* webkit_plugin_get_name(WebKitPlugin* plugin) |
| 77 | { |
| 78 | g_return_val_if_fail(WEBKIT_IS_PLUGIN(plugin), 0); |
| 79 | |
| 80 | if (!plugin->priv->name.isNull()) |
| 81 | return plugin->priv->name.data(); |
| 82 | |
| 83 | if (plugin->priv->pluginInfo.info.name.isEmpty()) |
| 84 | return 0; |
| 85 | |
| 86 | plugin->priv->name = plugin->priv->pluginInfo.info.name.utf8(); |
| 87 | return plugin->priv->name.data(); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * webkit_plugin_get_description: |
| 92 | * @plugin: a #WebKitPlugin |
| 93 | * |
| 94 | * Returns: the description of the plugin. |
| 95 | */ |
| 96 | const char* webkit_plugin_get_description(WebKitPlugin* plugin) |
| 97 | { |
| 98 | g_return_val_if_fail(WEBKIT_IS_PLUGIN(plugin), 0); |
| 99 | |
| 100 | if (!plugin->priv->description.isNull()) |
| 101 | return plugin->priv->description.data(); |
| 102 | |
| 103 | if (plugin->priv->pluginInfo.info.desc.isEmpty()) |
| 104 | return 0; |
| 105 | |
| 106 | plugin->priv->description = plugin->priv->pluginInfo.info.desc.utf8(); |
| 107 | return plugin->priv->description.data(); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * webkit_plugin_get_path: |
| 112 | * @plugin: a #WebKitPlugin |
| 113 | * |
| 114 | * Returns: the absolute path where the plugin is installed. |
| 115 | */ |
| 116 | const char* webkit_plugin_get_path(WebKitPlugin* plugin) |
| 117 | { |
| 118 | g_return_val_if_fail(WEBKIT_IS_PLUGIN(plugin), 0); |
| 119 | |
| 120 | if (!plugin->priv->path.isNull()) |
| 121 | return plugin->priv->path.data(); |
| 122 | |
| 123 | if (plugin->priv->pluginInfo.path.isEmpty()) |
| 124 | return 0; |
| 125 | |
| 126 | plugin->priv->path = plugin->priv->pluginInfo.path.utf8(); |
| 127 | return plugin->priv->path.data(); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * webkit_plugin_get_mime_info_list: |
| 132 | * @plugin: a #WebKitPlugin |
| 133 | * |
| 134 | * Get information about MIME types handled by the plugin, |
| 135 | * as a list of #WebKitMimeInfo. |
| 136 | * |
| 137 | * Returns: (element-type WebKitMimeInfo) (transfer none): a #GList of #WebKitMimeInfo. |
| 138 | */ |
| 139 | GList* webkit_plugin_get_mime_info_list(WebKitPlugin* plugin) |
| 140 | { |
| 141 | g_return_val_if_fail(WEBKIT_IS_PLUGIN(plugin), 0); |
| 142 | |
| 143 | if (plugin->priv->mimeInfoList) |
| 144 | return plugin->priv->mimeInfoList; |
| 145 | |
| 146 | if (plugin->priv->pluginInfo.info.mimes.isEmpty()) |
| 147 | return 0; |
| 148 | |
| 149 | for (size_t i = 0; i < plugin->priv->pluginInfo.info.mimes.size(); ++i) |
| 150 | plugin->priv->mimeInfoList = g_list_prepend(plugin->priv->mimeInfoList, webkitMimeInfoCreate(plugin->priv->pluginInfo.info.mimes[i])); |
| 151 | return plugin->priv->mimeInfoList; |
| 152 | } |
| 153 | |