Title: [117305] trunk/Source/WebKit2
Revision
117305
Author
carlo...@webkit.org
Date
2012-05-16 10:29:31 -0700 (Wed, 16 May 2012)

Log Message

[GTK] Add API to get plugins to WebKit2 GTK+
https://bugs.webkit.org/show_bug.cgi?id=86356

Reviewed by Martin Robinson.

* GNUmakefile.list.am: Add new files to compilation.
* UIProcess/API/gtk/WebKitMimeInfo.cpp: Added.
(_WebKitMimeInfo): Boxed type to represent MIME type information.
(webkitMimeInfoCreate): Ceate a new WebKitMimeInfo.
(webkit_mime_info_ref):
(webkit_mime_info_unref):
(webkit_mime_info_get_mime_type): Return the mime type.
(webkit_mime_info_get_description): Return the mime type
description.
(webkit_mime_info_get_extensions): Return the list of extensions
associated to the mime type.
* UIProcess/API/gtk/WebKitMimeInfo.h: Added.
* UIProcess/API/gtk/WebKitMimeInfoPrivate.h: Added.
* UIProcess/API/gtk/WebKitPlugin.cpp: Added.
(webkitPluginFinalize):
(webkit_plugin_init):
(webkit_plugin_class_init):
(webkitPluginCreate): Create a new WebKitPlugin for the given
PluginModuleInfo.
(webkit_plugin_get_name): Return the plugin name.
(webkit_plugin_get_description): Return the plugin description.
(webkit_plugin_get_path): Return the path where the plugin is
installed.
(webkit_plugin_get_mime_info_list): Return the list of mime types
handled by the plugin.
* UIProcess/API/gtk/WebKitPlugin.h: Added.
* UIProcess/API/gtk/WebKitPluginPrivate.h: Added.
* UIProcess/API/gtk/WebKitWebContext.cpp:
(webkit_web_context_set_additional_plugins_directory): Set an
additional directory to be scanned for plugins.
(GetPluginsAsyncData): Helper struct used to asynchronously get
the list of plugins.
(getPluginsAsyncDataCreate): Create a GetPluginsAsyncData struct.
(getPluginsAsyncDataDestroy): Destroy a GetPluginsAsyncData
struct.
(webkitWebContextGetPluginThread): Thread body to get the list of
plugins installed.
(webkit_web_context_get_plugins): Asynchronously get the list of
plugins installed.
(webkit_web_context_get_plugins_finish): Finish async operation
started by webkit_web_context_get_plugins() returning a list of
WebKitPlugin.
* UIProcess/API/gtk/WebKitWebContext.h:
* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section for
WebKitPlugin.
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
* UIProcess/API/gtk/docs/webkit2gtk.types: Add new types.
* UIProcess/API/gtk/tests/GNUmakefile.am:
* UIProcess/API/gtk/tests/TestWebKitWebContext.cpp:
(testWebContextGetPlugins):
(beforeAll):
* UIProcess/API/gtk/webkit2.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (117304 => 117305)


--- trunk/Source/WebKit2/ChangeLog	2012-05-16 17:22:38 UTC (rev 117304)
+++ trunk/Source/WebKit2/ChangeLog	2012-05-16 17:29:31 UTC (rev 117305)
@@ -1,3 +1,63 @@
+2012-05-16  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add API to get plugins to WebKit2 GTK+
+        https://bugs.webkit.org/show_bug.cgi?id=86356
+
+        Reviewed by Martin Robinson.
+
+        * GNUmakefile.list.am: Add new files to compilation.
+        * UIProcess/API/gtk/WebKitMimeInfo.cpp: Added.
+        (_WebKitMimeInfo): Boxed type to represent MIME type information.
+        (webkitMimeInfoCreate): Ceate a new WebKitMimeInfo.
+        (webkit_mime_info_ref):
+        (webkit_mime_info_unref):
+        (webkit_mime_info_get_mime_type): Return the mime type.
+        (webkit_mime_info_get_description): Return the mime type
+        description.
+        (webkit_mime_info_get_extensions): Return the list of extensions
+        associated to the mime type.
+        * UIProcess/API/gtk/WebKitMimeInfo.h: Added.
+        * UIProcess/API/gtk/WebKitMimeInfoPrivate.h: Added.
+        * UIProcess/API/gtk/WebKitPlugin.cpp: Added.
+        (webkitPluginFinalize):
+        (webkit_plugin_init):
+        (webkit_plugin_class_init):
+        (webkitPluginCreate): Create a new WebKitPlugin for the given
+        PluginModuleInfo.
+        (webkit_plugin_get_name): Return the plugin name.
+        (webkit_plugin_get_description): Return the plugin description.
+        (webkit_plugin_get_path): Return the path where the plugin is
+        installed.
+        (webkit_plugin_get_mime_info_list): Return the list of mime types
+        handled by the plugin.
+        * UIProcess/API/gtk/WebKitPlugin.h: Added.
+        * UIProcess/API/gtk/WebKitPluginPrivate.h: Added.
+        * UIProcess/API/gtk/WebKitWebContext.cpp:
+        (webkit_web_context_set_additional_plugins_directory): Set an
+        additional directory to be scanned for plugins.
+        (GetPluginsAsyncData): Helper struct used to asynchronously get
+        the list of plugins.
+        (getPluginsAsyncDataCreate): Create a GetPluginsAsyncData struct.
+        (getPluginsAsyncDataDestroy): Destroy a GetPluginsAsyncData
+        struct.
+        (webkitWebContextGetPluginThread): Thread body to get the list of
+        plugins installed.
+        (webkit_web_context_get_plugins): Asynchronously get the list of
+        plugins installed.
+        (webkit_web_context_get_plugins_finish): Finish async operation
+        started by webkit_web_context_get_plugins() returning a list of
+        WebKitPlugin.
+        * UIProcess/API/gtk/WebKitWebContext.h:
+        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section for
+        WebKitPlugin.
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
+        * UIProcess/API/gtk/docs/webkit2gtk.types: Add new types.
+        * UIProcess/API/gtk/tests/GNUmakefile.am:
+        * UIProcess/API/gtk/tests/TestWebKitWebContext.cpp:
+        (testWebContextGetPlugins):
+        (beforeAll):
+        * UIProcess/API/gtk/webkit2.h:
+
 2012-05-16  Brady Eidson  <beid...@apple.com>
 
         https://bugs.webkit.org/show_bug.cgi?id=86638

Modified: trunk/Source/WebKit2/GNUmakefile.list.am (117304 => 117305)


--- trunk/Source/WebKit2/GNUmakefile.list.am	2012-05-16 17:22:38 UTC (rev 117304)
+++ trunk/Source/WebKit2/GNUmakefile.list.am	2012-05-16 17:29:31 UTC (rev 117305)
@@ -96,7 +96,9 @@
 	$(WebKit2)/UIProcess/API/gtk/WebKitFindController.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitHitTestResult.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitJavascriptResult.h \
+	$(WebKit2)/UIProcess/API/gtk/WebKitMimeInfo.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitNavigationPolicyDecision.h \
+	$(WebKit2)/UIProcess/API/gtk/WebKitPlugin.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitPolicyDecision.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitPrintOperation.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitResponsePolicyDecision.h \
@@ -583,11 +585,17 @@
 	Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResultPrivate.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitLoaderClient.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitLoaderClient.cpp \
+	Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfo.cpp \
+	Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfo.h \
+	Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfoPrivate.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitFindController.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitFindController.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecision.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitNavigationPolicyDecisionPrivate.h \
+	Source/WebKit2/UIProcess/API/gtk/WebKitPlugin.cpp \
+	Source/WebKit2/UIProcess/API/gtk/WebKitPlugin.h \
+	Source/WebKit2/UIProcess/API/gtk/WebKitPluginPrivate.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitPolicyDecision.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitPolicyDecision.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitPolicyDecisionPrivate.h \

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfo.cpp (0 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfo.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfo.cpp	2012-05-16 17:29:31 UTC (rev 117305)
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitMimeInfo.h"
+
+#include "WebKitMimeInfoPrivate.h"
+#include <wtf/gobject/GRefPtr.h>
+#include <wtf/text/CString.h>
+
+struct _WebKitMimeInfo {
+    _WebKitMimeInfo(const WebCore::MimeClassInfo& mimeInfo)
+        : mimeInfo(mimeInfo)
+    {
+    }
+
+    WebCore::MimeClassInfo mimeInfo;
+    CString mimeType;
+    CString description;
+    GRefPtr<GPtrArray> extensions;
+
+    int referenceCount;
+};
+
+G_DEFINE_BOXED_TYPE(WebKitMimeInfo, webkit_mime_info, webkit_mime_info_ref, webkit_mime_info_unref)
+
+WebKitMimeInfo* webkitMimeInfoCreate(const WebCore::MimeClassInfo& mimeInfo)
+{
+    WebKitMimeInfo* info = g_slice_new(WebKitMimeInfo);
+    new (info) WebKitMimeInfo(mimeInfo);
+    return info;
+}
+
+/**
+ * webkit_mime_info_ref:
+ * @info: a #WebKitMimeInfo
+ *
+ * Atomically increments the reference count of @info by one. This
+ * function is MT-safe and may be called from any thread.
+ *
+ * Returns: The passed in #WebKitMimeInfo
+ */
+WebKitMimeInfo* webkit_mime_info_ref(WebKitMimeInfo* info)
+{
+    g_atomic_int_inc(&info->referenceCount);
+    return info;
+}
+
+/**
+ * webkit_mime_info_unref:
+ * @info: a #WebKitMimeInfo
+ *
+ * Atomically decrements the reference count of @info by one. If the
+ * reference count drops to 0, all memory allocated by the #WebKitMimeInfo is
+ * released. This function is MT-safe and may be called from any
+ * thread.
+ */
+void webkit_mime_info_unref(WebKitMimeInfo* info)
+{
+    if (g_atomic_int_dec_and_test(&info->referenceCount)) {
+        info->~WebKitMimeInfo();
+        g_slice_free(WebKitMimeInfo, info);
+    }
+}
+
+/**
+ * webkit_mime_info_get_mime_type:
+ * @info: a #WebKitMimeInfo
+ *
+ * Returns: the MIME type of @info
+ */
+const char* webkit_mime_info_get_mime_type(WebKitMimeInfo* info)
+{
+    if (!info->mimeType.isNull())
+        return info->mimeType.data();
+
+    if (info->mimeInfo.type.isEmpty())
+        return 0;
+
+    info->mimeType = info->mimeInfo.type.utf8();
+    return info->mimeType.data();
+}
+
+/**
+ * webkit_mime_info_get_description:
+ * @info: a #WebKitMimeInfo
+ *
+ * Returns: the description of the MIME type of @info
+ */
+const char* webkit_mime_info_get_description(WebKitMimeInfo* info)
+{
+    if (!info->description.isNull())
+        return info->description.data();
+
+    if (info->mimeInfo.desc.isEmpty())
+        return 0;
+
+    info->description = info->mimeInfo.desc.utf8();
+    return info->description.data();
+}
+
+/**
+ * webkit_mime_info_get_extensions:
+ * @info: a #WebKitMimeInfo
+ *
+ * Get the list of file extensions associated to the
+ * MIME type of @info
+ *
+ * Returns: (array zero-terminated=1) (transfer none): a
+ *     %NULL-terminated array of strings
+ */
+const char* const* webkit_mime_info_get_extensions(WebKitMimeInfo* info)
+{
+    if (info->extensions)
+        return reinterpret_cast<gchar**>(info->extensions->pdata);
+
+    if (info->mimeInfo.extensions.isEmpty())
+        return 0;
+
+    info->extensions = adoptGRef(g_ptr_array_new_with_free_func(g_free));
+    for (size_t i = 0; i < info->mimeInfo.extensions.size(); ++i) {
+        if (info->mimeInfo.extensions[i].isEmpty())
+            continue;
+        g_ptr_array_add(info->extensions.get(), g_strdup(info->mimeInfo.extensions[i].utf8().data()));
+    }
+    g_ptr_array_add(info->extensions.get(), 0);
+
+    return reinterpret_cast<gchar**>(info->extensions->pdata);
+}

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfo.h (0 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfo.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfo.h	2012-05-16 17:29:31 UTC (rev 117305)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitMimeInfo_h
+#define WebKitMimeInfo_h
+
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_MIME_INFO (webkit_mime_info_get_type())
+
+typedef struct _WebKitMimeInfo WebKitMimeInfo;
+
+
+WEBKIT_API GType
+webkit_mime_info_get_type        (void);
+
+WEBKIT_API WebKitMimeInfo *
+webkit_mime_info_ref             (WebKitMimeInfo *info);
+
+WEBKIT_API void
+webkit_mime_info_unref           (WebKitMimeInfo *info);
+
+WEBKIT_API const gchar *
+webkit_mime_info_get_mime_type   (WebKitMimeInfo *info);
+
+WEBKIT_API const gchar *
+webkit_mime_info_get_description (WebKitMimeInfo *info);
+
+WEBKIT_API const gchar * const *
+webkit_mime_info_get_extensions  (WebKitMimeInfo *info);
+
+G_END_DECLS
+
+#endif

Copied: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfoPrivate.h (from rev 117304, trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp) (0 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfoPrivate.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitMimeInfoPrivate.h	2012-05-16 17:29:31 UTC (rev 117305)
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebKitMimeInfoPrivate_h
+#define WebKitMimeInfoPrivate_h
+
+#include "WebKitMimeInfo.h"
+#include "WebKitPrivate.h"
+#include <WebCore/PluginData.h>
+
+WebKitMimeInfo* webkitMimeInfoCreate(const WebCore::MimeClassInfo&);
+
+#endif // WebKitMimeInfoPrivate_h

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPlugin.cpp (0 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPlugin.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPlugin.cpp	2012-05-16 17:29:31 UTC (rev 117305)
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitPlugin.h"
+
+#include "WebKitMimeInfoPrivate.h"
+#include "WebKitPluginPrivate.h"
+#include <wtf/text/CString.h>
+
+using namespace WebKit;
+
+struct _WebKitPluginPrivate {
+    PluginModuleInfo pluginInfo;
+    CString name;
+    CString description;
+    CString path;
+    GList* mimeInfoList;
+};
+
+G_DEFINE_TYPE(WebKitPlugin, webkit_plugin, G_TYPE_OBJECT)
+
+static void webkitPluginFinalize(GObject* object)
+{
+    WebKitPluginPrivate* priv = WEBKIT_PLUGIN(object)->priv;
+    g_list_free_full(priv->mimeInfoList, reinterpret_cast<GDestroyNotify>(webkit_mime_info_unref));
+    priv->~WebKitPluginPrivate();
+    G_OBJECT_CLASS(webkit_plugin_parent_class)->finalize(object);
+}
+
+static void webkit_plugin_init(WebKitPlugin* plugin)
+{
+    WebKitPluginPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(plugin, WEBKIT_TYPE_PLUGIN, WebKitPluginPrivate);
+    plugin->priv = priv;
+    new (priv) WebKitPluginPrivate();
+}
+
+static void webkit_plugin_class_init(WebKitPluginClass* pluginClass)
+{
+    GObjectClass* gObjectClass = G_OBJECT_CLASS(pluginClass);
+    gObjectClass->finalize = webkitPluginFinalize;
+
+    g_type_class_add_private(pluginClass, sizeof(WebKitPluginPrivate));
+}
+
+WebKitPlugin* webkitPluginCreate(const PluginModuleInfo& pluginInfo)
+{
+    WebKitPlugin* plugin = WEBKIT_PLUGIN(g_object_new(WEBKIT_TYPE_PLUGIN, NULL));
+    plugin->priv->pluginInfo = pluginInfo;
+    return plugin;
+}
+
+/**
+ * webkit_plugin_get_name:
+ * @plugin: a #WebKitPlugin
+ *
+ * Returns: the name of the plugin.
+ */
+const char* webkit_plugin_get_name(WebKitPlugin* plugin)
+{
+    g_return_val_if_fail(WEBKIT_IS_PLUGIN(plugin), 0);
+
+    if (!plugin->priv->name.isNull())
+        return plugin->priv->name.data();
+
+    if (plugin->priv->pluginInfo.info.name.isEmpty())
+        return 0;
+
+    plugin->priv->name = plugin->priv->pluginInfo.info.name.utf8();
+    return plugin->priv->name.data();
+}
+
+/**
+ * webkit_plugin_get_description:
+ * @plugin: a #WebKitPlugin
+ *
+ * Returns: the description of the plugin.
+ */
+const char* webkit_plugin_get_description(WebKitPlugin* plugin)
+{
+    g_return_val_if_fail(WEBKIT_IS_PLUGIN(plugin), 0);
+
+    if (!plugin->priv->description.isNull())
+        plugin->priv->description.data();
+
+    if (plugin->priv->pluginInfo.info.desc.isEmpty())
+        return 0;
+
+    plugin->priv->description = plugin->priv->pluginInfo.info.desc.utf8();
+    return plugin->priv->description.data();
+}
+
+/**
+ * webkit_plugin_get_path:
+ * @plugin: a #WebKitPlugin
+ *
+ * Returns: the absolute path where the plugin is installed.
+ */
+const char* webkit_plugin_get_path(WebKitPlugin* plugin)
+{
+    g_return_val_if_fail(WEBKIT_IS_PLUGIN(plugin), 0);
+
+    if (!plugin->priv->path.isNull())
+        return plugin->priv->path.data();
+
+    if (plugin->priv->pluginInfo.path.isEmpty())
+        return 0;
+
+    plugin->priv->path = plugin->priv->pluginInfo.path.utf8();
+    return plugin->priv->path.data();
+}
+
+/**
+ * webkit_plugin_get_mime_info_list:
+ * @plugin: a #WebKitPlugin
+ *
+ * Get information about MIME types handled by the plugin,
+ * as a list of #WebKitMimeInfo.
+ *
+ * Returns: (element-type WebKitMimeInfo) (transfer none): a #GList of #WebKitMimeInfo.
+ */
+GList* webkit_plugin_get_mime_info_list(WebKitPlugin* plugin)
+{
+    g_return_val_if_fail(WEBKIT_IS_PLUGIN(plugin), 0);
+
+    if (plugin->priv->mimeInfoList)
+        return plugin->priv->mimeInfoList;
+
+    if (plugin->priv->pluginInfo.info.mimes.isEmpty())
+        return 0;
+
+    for (size_t i = 0; i < plugin->priv->pluginInfo.info.mimes.size(); ++i)
+        plugin->priv->mimeInfoList = g_list_prepend(plugin->priv->mimeInfoList, webkitMimeInfoCreate(plugin->priv->pluginInfo.info.mimes[i]));
+    return plugin->priv->mimeInfoList;
+}

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPlugin.h (0 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPlugin.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPlugin.h	2012-05-16 17:29:31 UTC (rev 117305)
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitPlugin_h
+#define WebKitPlugin_h
+
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_PLUGIN            (webkit_plugin_get_type())
+#define WEBKIT_PLUGIN(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_PLUGIN, WebKitPlugin))
+#define WEBKIT_IS_PLUGIN(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_PLUGIN))
+#define WEBKIT_PLUGIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_PLUGIN, WebKitPluginClass))
+#define WEBKIT_IS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_PLUGIN))
+#define WEBKIT_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_PLUGIN, WebKitPluginClass))
+
+typedef struct _WebKitPlugin        WebKitPlugin;
+typedef struct _WebKitPluginClass   WebKitPluginClass;
+typedef struct _WebKitPluginPrivate WebKitPluginPrivate;
+
+struct _WebKitPlugin {
+    GObject parent;
+
+    WebKitPluginPrivate *priv;
+};
+
+struct _WebKitPluginClass {
+    GObjectClass parent_class;
+};
+
+WEBKIT_API GType
+webkit_plugin_get_type           (void);
+
+WEBKIT_API const gchar *
+webkit_plugin_get_name           (WebKitPlugin *plugin);
+
+WEBKIT_API const gchar *
+webkit_plugin_get_description    (WebKitPlugin *plugin);
+
+WEBKIT_API const gchar *
+webkit_plugin_get_path           (WebKitPlugin *plugin);
+
+WEBKIT_API GList *
+webkit_plugin_get_mime_info_list (WebKitPlugin *plugin);
+
+G_END_DECLS
+
+#endif

Copied: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPluginPrivate.h (from rev 117304, trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp) (0 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPluginPrivate.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPluginPrivate.h	2012-05-16 17:29:31 UTC (rev 117305)
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebKitPluginPrivate_h
+#define WebKitPluginPrivate_h
+
+#include "PluginModuleInfo.h"
+#include "WebKitPlugin.h"
+#include "WebKitPrivate.h"
+
+WebKitPlugin* webkitPluginCreate(const WebKit::PluginModuleInfo&);
+
+#endif // WebKitPluginPrivate_h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp (117304 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp	2012-05-16 17:22:38 UTC (rev 117304)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp	2012-05-16 17:29:31 UTC (rev 117305)
@@ -24,8 +24,10 @@
 #include "WebKitCookieManagerPrivate.h"
 #include "WebKitDownloadClient.h"
 #include "WebKitDownloadPrivate.h"
+#include "WebKitPluginPrivate.h"
 #include "WebKitPrivate.h"
 #include "WebKitWebContextPrivate.h"
+#include <WebCore/FileSystem.h>
 #include <wtf/HashMap.h>
 #include <wtf/gobject/GRefPtr.h>
 #include <wtf/text/CString.h>
@@ -236,6 +238,97 @@
     return priv->cookieManager.get();
 }
 
+/**
+ * webkit_web_context_set_additional_plugins_directory:
+ * @context: a #WebKitWebContext
+ * @directory: the directory to add
+ *
+ * Set an additional directory where WebKit will look for plugins.
+ */
+void webkit_web_context_set_additional_plugins_directory(WebKitWebContext* context, const char* directory)
+{
+    g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
+    g_return_if_fail(directory);
+
+    toImpl(context->priv->context.get())->setAdditionalPluginsDirectory(WebCore::filenameToString(directory));
+}
+
+struct GetPluginsAsyncData {
+    Vector<PluginModuleInfo> plugins;
+};
+
+static GetPluginsAsyncData* getPluginsAsyncDataCreate()
+{
+    GetPluginsAsyncData* data = ""
+    new (data) GetPluginsAsyncData();
+    return data;
+}
+
+static void getPluginsAsyncDataDestroy(GetPluginsAsyncData* data)
+{
+    data->~GetPluginsAsyncData();
+    g_slice_free(GetPluginsAsyncData, data);
+}
+
+static void webkitWebContextGetPluginThread(GSimpleAsyncResult* result, GObject* object, GCancellable*)
+{
+    GetPluginsAsyncData* data = ""
+    data->plugins = toImpl(WEBKIT_WEB_CONTEXT(object)->priv->context.get())->pluginInfoStore().plugins();
+}
+
+/**
+ * webkit_web_context_get_plugins:
+ * @context: a #WebKitWebContext
+ * @cancellable: (allow-none): a #GCancellable or %NULL to ignore
+ * @callback: (scope async): a #GAsyncReadyCallback to call when the request is satisfied
+ * @user_data: (closure): the data to pass to callback function
+ *
+ * Asynchronously get the list of installed plugins.
+ *
+ * When the operation is finished, @callback will be called. You can then call
+ * webkit_web_context_get_plugins_finish() to get the result of the operation.
+ */
+void webkit_web_context_get_plugins(WebKitWebContext* context, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData)
+{
+    g_return_if_fail(WEBKIT_IS_WEB_CONTEXT(context));
+
+    GRefPtr<GSimpleAsyncResult> result = adoptGRef(g_simple_async_result_new(G_OBJECT(context), callback, userData,
+                                                                             reinterpret_cast<gpointer>(webkit_web_context_get_plugins)));
+    g_simple_async_result_set_op_res_gpointer(result.get(), getPluginsAsyncDataCreate(),
+                                              reinterpret_cast<GDestroyNotify>(getPluginsAsyncDataDestroy));
+    g_simple_async_result_run_in_thread(result.get(), webkitWebContextGetPluginThread, G_PRIORITY_DEFAULT, cancellable);
+}
+
+/**
+ * webkit_web_context_get_plugins_finish:
+ * @context: a #WebKitWebContext
+ * @result: a #GAsyncResult
+ * @error: return location for error or %NULL to ignore
+ *
+ * Finish an asynchronous operation started with webkit_web_context_get_plugins.
+ *
+ * Returns: (element-type WebKitPlugin) (transfer full): a #GList of #WebKitPlugin. You must free the #GList with
+ *    g_list_free() and unref the #WebKitPlugin<!-- -->s with g_object_unref() when you're done with them.
+ */
+GList* webkit_web_context_get_plugins_finish(WebKitWebContext* context, GAsyncResult* result, GError** error)
+{
+    g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0);
+    g_return_val_if_fail(G_IS_ASYNC_RESULT(result), 0);
+
+    GSimpleAsyncResult* simpleResult = G_SIMPLE_ASYNC_RESULT(result);
+    g_warn_if_fail(g_simple_async_result_get_source_tag(simpleResult) == webkit_web_context_get_plugins);
+
+    if (g_simple_async_result_propagate_error(simpleResult, error))
+        return 0;
+
+    GetPluginsAsyncData* data = ""
+    GList* plugins = 0;
+    for (size_t i = 0; i < data->plugins.size(); ++i)
+        plugins = g_list_prepend(plugins, webkitPluginCreate(data->plugins[i]));
+
+    return plugins;
+}
+
 WebKitDownload* webkitWebContextGetOrCreateDownload(WKDownloadRef wkDownload)
 {
     GRefPtr<WebKitDownload> download = downloadsMap().get(wkDownload);

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h (117304 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h	2012-05-16 17:22:38 UTC (rev 117304)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.h	2012-05-16 17:29:31 UTC (rev 117305)
@@ -80,24 +80,39 @@
 };
 
 WEBKIT_API GType
-webkit_web_context_get_type           (void);
+webkit_web_context_get_type                         (void);
 
 WEBKIT_API WebKitWebContext *
-webkit_web_context_get_default        (void);
+webkit_web_context_get_default                      (void);
 
 WEBKIT_API void
-webkit_web_context_set_cache_model    (WebKitWebContext *context,
-                                       WebKitCacheModel  cache_model);
+webkit_web_context_set_cache_model                  (WebKitWebContext   *context,
+                                                     WebKitCacheModel    cache_model);
 WEBKIT_API WebKitCacheModel
-webkit_web_context_get_cache_model    (WebKitWebContext *context);
+webkit_web_context_get_cache_model                  (WebKitWebContext   *context);
 
 WEBKIT_API WebKitDownload *
-webkit_web_context_download_uri       (WebKitWebContext *context,
-                                       const gchar      *uri);
+webkit_web_context_download_uri                     (WebKitWebContext   *context,
+                                                     const gchar        *uri);
 
 WEBKIT_API WebKitCookieManager *
-webkit_web_context_get_cookie_manager (WebKitWebContext *context);
+webkit_web_context_get_cookie_manager               (WebKitWebContext   *context);
 
+WEBKIT_API void
+webkit_web_context_set_additional_plugins_directory (WebKitWebContext   *context,
+                                                     const gchar        *directory);
+
+WEBKIT_API void
+webkit_web_context_get_plugins                      (WebKitWebContext   *context,
+                                                     GCancellable       *cancellable,
+                                                     GAsyncReadyCallback callback,
+                                                     gpointer            user_data);
+
+WEBKIT_API GList *
+webkit_web_context_get_plugins_finish               (WebKitWebContext   *context,
+                                                     GAsyncResult       *result,
+                                                     GError            **error);
+
 G_END_DECLS
 
 #endif

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml (117304 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml	2012-05-16 17:22:38 UTC (rev 117304)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml	2012-05-16 17:29:31 UTC (rev 117305)
@@ -31,6 +31,7 @@
     <xi:include href=""
     <xi:include href=""
     <xi:include href=""
+    <xi:include href=""
   </chapter>
 
   <index id="index-all">

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (117304 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2012-05-16 17:22:38 UTC (rev 117304)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2012-05-16 17:29:31 UTC (rev 117305)
@@ -29,6 +29,9 @@
 webkit_web_context_set_cache_model
 webkit_web_context_download_uri
 webkit_web_context_get_cookie_manager
+webkit_web_context_set_additional_plugins_directory
+webkit_web_context_get_plugins
+webkit_web_context_get_plugins_finish
 
 <SUBSECTION Standard>
 WebKitWebContextClass
@@ -601,3 +604,35 @@
 WebKitCookieManagerPrivate
 webkit_cookie_manager_get_type
 </SECTION>
+
+<SECTION>
+<FILE>WebKitPlugin</FILE>
+WebKitPlugin
+webkit_plugin_get_name
+webkit_plugin_get_description
+webkit_plugin_get_path
+webkit_plugin_get_mime_info_list
+
+<SUBSECTION WebKitMimeInfo>
+WebKitMimeInfo
+webkit_mime_info_ref
+webkit_mime_info_unref
+webkit_mime_info_get_mime_type
+webkit_mime_info_get_description
+webkit_mime_info_get_extensions
+
+<SUBSECTION Standard>
+WebKitPluginClass
+WEBKIT_TYPE_PLUGIN
+WEBKIT_PLUGIN
+WEBKIT_IS_PLUGIN
+WEBKIT_PLUGIN_CLASS
+WEBKIT_IS_PLUGIN_CLASS
+WEBKIT_PLUGIN_GET_CLASS
+WEBKIT_TYPE_MIME_INFO
+
+<SUBSECTION Private>
+webkit_plugin_get_type
+webkit_mime_info_get_type
+WebKitPluginPrivate
+</SECTION>

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types (117304 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types	2012-05-16 17:22:38 UTC (rev 117304)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types	2012-05-16 17:29:31 UTC (rev 117305)
@@ -15,3 +15,5 @@
 webkit_javascript_result_get_type
 webkit_web_resource_get_type
 webkit_cookie_manager_get_type
+webkit_plugin_get_type
+webkit_mime_info_get_type

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am (117304 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am	2012-05-16 17:22:38 UTC (rev 117304)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am	2012-05-16 17:29:31 UTC (rev 117305)
@@ -65,7 +65,9 @@
 
 Programs_WebKit2APITests_TestWebKitWebContext_SOURCES = \
 	Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp
-Programs_WebKit2APITests_TestWebKitWebContext_CPPFLAGS = $(webkit2_tests_cppflags)
+Programs_WebKit2APITests_TestWebKitWebContext_CPPFLAGS = \
+	-DWEBKIT_TEST_PLUGIN_DIR=\"${shell pwd}/${top_builddir}/TestNetscapePlugin/.libs\" \
+	$(webkit2_tests_cppflags)
 Programs_WebKit2APITests_TestWebKitWebContext_LDADD = $(webkit2_tests_ldadd)
 Programs_WebKit2APITests_TestWebKitWebContext_LDFLAGS = $(webkit2_tests_ldflags)
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp (117304 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp	2012-05-16 17:22:38 UTC (rev 117304)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp	2012-05-16 17:29:31 UTC (rev 117305)
@@ -22,6 +22,7 @@
 #include "TestMain.h"
 #include <gtk/gtk.h>
 #include <webkit2/webkit2.h>
+#include <wtf/gobject/GRefPtr.h>
 
 static void testWebContextDefault(Test* test, gconstpointer)
 {
@@ -29,9 +30,86 @@
     g_assert(webkit_web_context_get_default() == webkit_web_context_get_default());
 }
 
+class PluginsTest: public Test {
+public:
+    MAKE_GLIB_TEST_FIXTURE(PluginsTest);
+
+    PluginsTest()
+        : m_context(webkit_web_context_get_default())
+        , m_mainLoop(g_main_loop_new(0, TRUE))
+        , m_plugins(0)
+    {
+        webkit_web_context_set_additional_plugins_directory(m_context, WEBKIT_TEST_PLUGIN_DIR);
+    }
+
+    ~PluginsTest()
+    {
+        g_main_loop_unref(m_mainLoop);
+        g_list_free_full(m_plugins, g_object_unref);
+    }
+
+    static void getPluginsAsyncReadyCallback(GObject*, GAsyncResult* result, PluginsTest* test)
+    {
+        test->m_plugins = webkit_web_context_get_plugins_finish(test->m_context, result, 0);
+        g_main_loop_quit(test->m_mainLoop);
+    }
+
+    GList* getPlugins()
+    {
+        g_list_free_full(m_plugins, g_object_unref);
+        webkit_web_context_get_plugins(m_context, 0, reinterpret_cast<GAsyncReadyCallback>(getPluginsAsyncReadyCallback), this);
+        g_main_loop_run(m_mainLoop);
+        return m_plugins;
+    }
+
+    WebKitWebContext* m_context;
+    GMainLoop* m_mainLoop;
+    GList* m_plugins;
+};
+
+static void testWebContextGetPlugins(PluginsTest* test, gconstpointer)
+{
+    GList* plugins = test->getPlugins();
+    g_assert(plugins);
+
+    GRefPtr<WebKitPlugin> testPlugin;
+    for (GList* item = plugins; item; item = g_list_next(item)) {
+        WebKitPlugin* plugin = WEBKIT_PLUGIN(item->data);
+        test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(plugin));
+        if (!g_strcmp0(webkit_plugin_get_name(plugin), "WebKit Test PlugIn")) {
+            testPlugin = plugin;
+            break;
+        }
+    }
+    g_assert(WEBKIT_IS_PLUGIN(testPlugin.get()));
+
+    GOwnPtr<char> pluginPath(g_build_filename(WEBKIT_TEST_PLUGIN_DIR, "libtestnetscapeplugin.so", NULL));
+    g_assert_cmpstr(webkit_plugin_get_path(testPlugin.get()), ==, pluginPath.get());
+    g_assert_cmpstr(webkit_plugin_get_description(testPlugin.get()), ==, "Simple Netscape® plug-in that handles test content for WebKit");
+    GList* mimeInfoList = webkit_plugin_get_mime_info_list(testPlugin.get());
+    g_assert(mimeInfoList);
+    g_assert_cmpuint(g_list_length(mimeInfoList), ==, 2);
+
+    WebKitMimeInfo* mimeInfo = static_cast<WebKitMimeInfo*>(mimeInfoList->data);
+    g_assert_cmpstr(webkit_mime_info_get_mime_type(mimeInfo), ==, "image/png");
+    g_assert_cmpstr(webkit_mime_info_get_description(mimeInfo), ==, "png image");
+    const gchar* const* extensions = webkit_mime_info_get_extensions(mimeInfo);
+    g_assert(extensions);
+    g_assert_cmpstr(extensions[0], ==, "png");
+
+    mimeInfoList = g_list_next(mimeInfoList);
+    mimeInfo = static_cast<WebKitMimeInfo*>(mimeInfoList->data);
+    g_assert_cmpstr(webkit_mime_info_get_mime_type(mimeInfo), ==, "application/x-webkit-test-netscape");
+    g_assert_cmpstr(webkit_mime_info_get_description(mimeInfo), ==, "test netscape content");
+    extensions = webkit_mime_info_get_extensions(mimeInfo);
+    g_assert(extensions);
+    g_assert_cmpstr(extensions[0], ==, "testnetscape");
+}
+
 void beforeAll()
 {
     Test::add("WebKitWebContext", "default-context", testWebContextDefault);
+    PluginsTest::add("WebKitWebContext", "get-plugins", testWebContextGetPlugins);
 }
 
 void afterAll()

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h (117304 => 117305)


--- trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h	2012-05-16 17:22:38 UTC (rev 117304)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h	2012-05-16 17:29:31 UTC (rev 117305)
@@ -35,6 +35,8 @@
 #include <webkit2/WebKitFindController.h>
 #include <webkit2/WebKitHitTestResult.h>
 #include <webkit2/WebKitJavascriptResult.h>
+#include <webkit2/WebKitMimeInfo.h>
+#include <webkit2/WebKitPlugin.h>
 #include <webkit2/WebKitPrintOperation.h>
 #include <webkit2/WebKitScriptDialog.h>
 #include <webkit2/WebKitSettings.h>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to