Changeset 73936 in webkit


Ignore:
Timestamp:
Dec 13, 2010 11:29:25 AM (13 years ago)
Author:
xan@webkit.org
Message:

2010-12-13 Xan Lopez <xlopez@igalia.com>

Reviewed by Martin Robinson.

[GTK] Add API to enable/disable plugins at runtime
https://bugs.webkit.org/show_bug.cgi?id=50891

  • tests/testwebplugindatabase.c: (test_webkit_web_plugin_database_get_plugins): test that disabling a plugin works.
  • webkit/webkitwebplugin.cpp: (webkit_web_plugin_get_property): hook 'enabled' property. (webkit_web_plugin_set_property): ditto. (webkit_web_plugin_class_init): define 'enabled' property. (webkit_web_plugin_set_enabled): setter for the property. (webkit_web_plugin_get_enabled): getter for the property.
  • webkit/webkitwebplugin.h: add the APIs to the header.
Location:
trunk/WebKit/gtk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/gtk/ChangeLog

    r73906 r73936  
     12010-12-13  Xan Lopez  <xlopez@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Add API to enable/disable plugins at runtime
     6        https://bugs.webkit.org/show_bug.cgi?id=50891
     7
     8        * tests/testwebplugindatabase.c:
     9        (test_webkit_web_plugin_database_get_plugins): test that disabling
     10        a plugin works.
     11        * webkit/webkitwebplugin.cpp:
     12        (webkit_web_plugin_get_property): hook 'enabled' property.
     13        (webkit_web_plugin_set_property): ditto.
     14        (webkit_web_plugin_class_init): define 'enabled' property.
     15        (webkit_web_plugin_set_enabled): setter for the property.
     16        (webkit_web_plugin_get_enabled): getter for the property.
     17        * webkit/webkitwebplugin.h: add the APIs to the header.
     18
    1192010-12-13  Carlos Garcia Campos  <cgarcia@igalia.com>
    220
  • trunk/WebKit/gtk/tests/testwebplugindatabase.c

    r73858 r73936  
    3535    GSList* pluginList, *p;
    3636    gboolean found = FALSE;
     37    gboolean enabled = FALSE;
    3738
    3839    webkit_web_settings_add_extra_plugin_directory(view, TEST_PLUGIN_DIR);
     
    4445        WebKitWebPlugin* plugin = (WebKitWebPlugin*)p->data;
    4546        if (!g_strcmp0(webkit_web_plugin_get_name(plugin), "WebKit Test PlugIn") &&
    46             !g_strcmp0(webkit_web_plugin_get_description(plugin), "Simple Netscape plug-in that handles test content for WebKit"))
     47            !g_strcmp0(webkit_web_plugin_get_description(plugin), "Simple Netscape plug-in that handles test content for WebKit")) {
    4748            found = TRUE;
     49            enabled = webkit_web_plugin_get_enabled(plugin);
     50            webkit_web_plugin_set_enabled(plugin, FALSE);
     51        }
    4852    }
    4953    webkit_web_plugin_database_plugins_list_free(pluginList);
    5054    g_assert(found);
     55    g_assert(enabled);
     56
     57    webkit_web_plugin_database_refresh(database);
     58    pluginList = webkit_web_plugin_database_get_plugins(database);
     59
     60    for (p = pluginList; p; p = p->next) {
     61        WebKitWebPlugin* plugin = (WebKitWebPlugin*)p->data;
     62        if (!g_strcmp0(webkit_web_plugin_get_name(plugin), "WebKit Test PlugIn") &&
     63            !g_strcmp0(webkit_web_plugin_get_description(plugin), "Simple Netscape plug-in that handles test content for WebKit"))
     64            enabled = webkit_web_plugin_get_enabled(plugin);
     65    }
     66    webkit_web_plugin_database_plugins_list_free(pluginList);
     67    g_assert(!enabled);
    5168
    5269    g_object_unref(view);
  • trunk/WebKit/gtk/webkit/webkitwebplugin.cpp

    r73906 r73936  
    2323#include "webkitprivate.h"
    2424#include "webkitwebpluginprivate.h"
     25#include <glib/gi18n-lib.h>
    2526
    2627using namespace WebCore;
     28
     29enum {
     30    PROP_0,
     31
     32    PROP_ENABLED
     33};
    2734
    2835G_DEFINE_TYPE(WebKitWebPlugin, webkit_web_plugin, G_TYPE_OBJECT)
     
    5865}
    5966
     67static void webkit_web_plugin_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* paramSpec)
     68{
     69    WebKitWebPlugin* plugin = WEBKIT_WEB_PLUGIN(object);
     70
     71    switch (prop_id) {
     72    case PROP_ENABLED:
     73        g_value_set_boolean(value, webkit_web_plugin_get_enabled(plugin));
     74        break;
     75    default:
     76        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, paramSpec);
     77    }
     78}
     79
     80static void webkit_web_plugin_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* paramSpec)
     81{
     82    WebKitWebPlugin* plugin = WEBKIT_WEB_PLUGIN(object);
     83
     84    switch (prop_id) {
     85    case PROP_ENABLED:
     86        webkit_web_plugin_set_enabled(plugin, g_value_get_boolean(value));
     87        break;
     88    default:
     89        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, paramSpec);
     90    }
     91}
     92
    6093static void webkit_web_plugin_class_init(WebKitWebPluginClass* klass)
    6194{
     
    6598
    6699    gobjectClass->finalize = webkit_web_plugin_finalize;
     100    gobjectClass->get_property = webkit_web_plugin_get_property;
     101    gobjectClass->set_property = webkit_web_plugin_set_property;
     102
     103    g_object_class_install_property(gobjectClass,
     104                                    PROP_ENABLED,
     105                                    g_param_spec_boolean("enabled",
     106                                                         _("Enabled"),
     107                                                         _("Whether the plugin is enabled"),
     108                                                         FALSE,
     109                                                         WEBKIT_PARAM_READWRITE));
    67110
    68111    g_type_class_add_private(klass, sizeof(WebKitWebPluginPrivate));
     
    164207    return priv->mimeTypes;
    165208}
     209
     210/**
     211 * webkit_web_plugin_set_enabled:
     212 * @plugin: a #WebKitWebPlugin
     213 * @enabled: whether to enable the plugin
     214 *
     215 * Sets the enabled status of the @plugin.
     216 *
     217 * Since: 1.3.8
     218 */
     219void webkit_web_plugin_set_enabled(WebKitWebPlugin* plugin, gboolean enabled)
     220{
     221    g_return_if_fail(WEBKIT_IS_WEB_PLUGIN(plugin));
     222    WebKitWebPluginPrivate* priv = plugin->priv;
     223
     224    ASSERT(priv->corePlugin);
     225    if (priv->corePlugin->isEnabled() == enabled)
     226        return;
     227
     228    priv->corePlugin->setEnabled(enabled);
     229
     230    g_object_notify(G_OBJECT(plugin), "enabled");
     231}
     232
     233/**
     234 * webkit_web_plugin_get_enabled:
     235 * @plugin: a #WebKitWebPlugin
     236 *
     237 * Returns: %TRUE if the plugin is enabled, %FALSE otherwise
     238 *
     239 * Since: 1.3.8
     240 */
     241gboolean webkit_web_plugin_get_enabled(WebKitWebPlugin* plugin)
     242{
     243    g_return_val_if_fail(WEBKIT_IS_WEB_PLUGIN(plugin), FALSE);
     244
     245    ASSERT(plugin->priv->corePlugin);
     246    return plugin->priv->corePlugin->isEnabled();
     247}
  • trunk/WebKit/gtk/webkit/webkitwebplugin.h

    r73875 r73936  
    8080webkit_web_plugin_get_mimetypes   (WebKitWebPlugin*);
    8181
     82WEBKIT_API void
     83webkit_web_plugin_set_enabled     (WebKitWebPlugin*, gboolean);
     84
     85WEBKIT_API gboolean
     86webkit_web_plugin_get_enabled     (WebKitWebPlugin*);
     87
    8288G_END_DECLS
    8389
Note: See TracChangeset for help on using the changeset viewer.