From 26991988cb76a9bd2f43700a98212099bdb023fb Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Wed, 25 Jan 2012 01:33:40 -0500 Subject: [PATCH] browser-plugin: Refactor plugin_object_set_property, and fix a bug If the user did "obj.onchanged = 1;" or passed another sort of invalid type, then we would clear the old listener as well as throw an exception. https://bugzilla.gnome.org/show_bug.cgi?id=668517 --- browser-plugin/browser-plugin.c | 55 +++++++++++++-------------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/browser-plugin/browser-plugin.c b/browser-plugin/browser-plugin.c index da08a0576..17a895592 100644 --- a/browser-plugin/browser-plugin.c +++ b/browser-plugin/browser-plugin.c @@ -809,6 +809,26 @@ plugin_object_get_property (NPObject *npobj, return TRUE; } +static bool +plugin_object_set_callback (NPObject **listener, + const NPVariant *value) +{ + if (!NPVARIANT_IS_OBJECT (*value) && !NPVARIANT_IS_NULL (*value)) + return FALSE; + + if (*listener) + funcs.releaseobject (*listener); + *listener = NULL; + + if (NPVARIANT_IS_OBJECT (*value)) + { + funcs.retainobject (*listener); + *listener = NPVARIANT_TO_OBJECT (*value); + } + + return TRUE; +} + static bool plugin_object_set_property (NPObject *npobj, NPIdentifier name, @@ -816,42 +836,11 @@ plugin_object_set_property (NPObject *npobj, { PluginObject *obj; - if (!plugin_object_has_property (npobj, name)) - return FALSE; - if (name == onextension_changed_id) - { - obj = (PluginObject*) npobj; - if (obj->listener) - funcs.releaseobject (obj->listener); - - obj->listener = NULL; - if (NPVARIANT_IS_OBJECT (*value)) - { - obj->listener = NPVARIANT_TO_OBJECT (*value); - funcs.retainobject (obj->listener); - return TRUE; - } - else if (NPVARIANT_IS_NULL (*value)) - return TRUE; - } + return plugin_object_set_callback (&obj->listener, value); if (name == onrestart_id) - { - obj = (PluginObject*) npobj; - if (obj->restart_listener) - funcs.releaseobject (obj->restart_listener); - - obj->restart_listener = NULL; - if (NPVARIANT_IS_OBJECT (*value)) - { - obj->restart_listener = NPVARIANT_TO_OBJECT (*value); - funcs.retainobject (obj->restart_listener); - return TRUE; - } - else if (NPVARIANT_IS_NULL (*value)) - return TRUE; - } + return plugin_object_set_callback (&obj->restart_listener, value); return FALSE; }