Author: toshok
Date: 2007-07-19 15:36:16 -0400 (Thu, 19 Jul 2007)
New Revision: 82319
Modified:
trunk/moon/plugin/ChangeLog
trunk/moon/plugin/moonlight.h
trunk/moon/plugin/plugin-class.cpp
trunk/moon/plugin/plugin-class.h
trunk/moon/plugin/plugin-glue.cpp
trunk/moon/plugin/plugin.cpp
Log:
2007-07-19 Chris Toshok <[EMAIL PROTECTED]>
* plugin-class.h: add some scriptable object event stuff.
* plugin-class.cpp: a couple of things.
1) fix the _invalidate and _deallocate methods. _invalidate
shouldn't release objects. and _deallocate can now call delete
again, so we don't leak all our wrapper objects.
2) add some initial scriptable object event methods (add/remove),
but they don't actually do much yet.
* plugin.cpp: fix the refcounting of the rootobject, and remove
some RUNTIME ifdefs.
* plugin-glue.cpp (NPP_Initialize): remove the RUNTIME ifdefs.
* moonlight.h: remove some of the unused ifdefs. also, we're not
going to ever build this with RUNTIME or SCRIPTING not defined, so
remove them.
Modified: trunk/moon/plugin/ChangeLog
===================================================================
--- trunk/moon/plugin/ChangeLog 2007-07-19 19:36:02 UTC (rev 82318)
+++ trunk/moon/plugin/ChangeLog 2007-07-19 19:36:16 UTC (rev 82319)
@@ -1,3 +1,25 @@
+2007-07-19 Chris Toshok <[EMAIL PROTECTED]>
+
+ * plugin-class.h: add some scriptable object event stuff.
+
+ * plugin-class.cpp: a couple of things.
+
+ 1) fix the _invalidate and _deallocate methods. _invalidate
+ shouldn't release objects. and _deallocate can now call delete
+ again, so we don't leak all our wrapper objects.
+
+ 2) add some initial scriptable object event methods (add/remove),
+ but they don't actually do much yet.
+
+ * plugin.cpp: fix the refcounting of the rootobject, and remove
+ some RUNTIME ifdefs.
+
+ * plugin-glue.cpp (NPP_Initialize): remove the RUNTIME ifdefs.
+
+ * moonlight.h: remove some of the unused ifdefs. also, we're not
+ going to ever build this with RUNTIME or SCRIPTING not defined, so
+ remove them.
+
2007-07-18 Jackson Harper <[EMAIL PROTECTED]>
* plugin-class.cpp: Build fix.
Modified: trunk/moon/plugin/moonlight.h
===================================================================
--- trunk/moon/plugin/moonlight.h 2007-07-19 19:36:02 UTC (rev 82318)
+++ trunk/moon/plugin/moonlight.h 2007-07-19 19:36:16 UTC (rev 82319)
@@ -33,12 +33,7 @@
// Definitions
#define DEBUG
-#define SCRIPTING
-#define RUNTIME
-#define MOON_1_0
-#define MOON_1_1
-
// Plugin information
#define PLUGIN_NAME "WPFe Plug-In"
#define PLUGIN_VERSION "0.99.0"
Modified: trunk/moon/plugin/plugin-class.cpp
===================================================================
--- trunk/moon/plugin/plugin-class.cpp 2007-07-19 19:36:02 UTC (rev 82318)
+++ trunk/moon/plugin/plugin-class.cpp 2007-07-19 19:36:16 UTC (rev 82319)
@@ -12,12 +12,7 @@
// XXXXXXXXXXx
//
-// we leak a lot in this file.
-//
-// all of the wrapper objects we create are leaked, since for some
-// reason delete'ing them doesn't work.
-//
-// Also, the listener proxies we create for dealing with events are
+// The listener proxies we create for dealing with events are
// leaked. we need to figure out how to deal with them (where to
// store them so we can free them on removeListener, etc.)
//
@@ -242,8 +237,7 @@
static void
point_deallocate (NPObject *npobject)
{
- // XXX is delete broken in plugins?
- // delete (MoonlightPoint*)npobject;
+ delete (MoonlightPoint*)npobject;
}
static bool
@@ -307,8 +301,7 @@
static void
rect_deallocate (NPObject *npobject)
{
- // XXX is delete broken in plugins?
- // delete (MoonlightRect*)npobject;
+ delete (MoonlightRect*)npobject;
}
static bool
@@ -391,16 +384,16 @@
static void
mouse_event_deallocate (NPObject *npobject)
{
- // XXX is delete broken in plugins?
- // delete (MoonlightMouseEventArgs*)npobject;
+ delete (MoonlightMouseEventArgsObject*)npobject;
}
static void
mouse_event_invalidate (NPObject *npobject)
{
MoonlightMouseEventArgsObject *ea =
(MoonlightMouseEventArgsObject*)npobject;
- if (ea->position)
- NPN_ReleaseObject (ea->position);
+// XXX apparently we don't need to do this?
+// if (ea->position)
+// NPN_ReleaseObject (ea->position);
ea->position = NULL;
}
@@ -500,8 +493,7 @@
static void
_deallocate (NPObject *npobj)
{
- // XXX is delete broken in plugins?
- // delete (MoonlightObject*)npobj;
+ delete (MoonlightObject*)npobj;
}
static void
@@ -587,8 +579,7 @@
static void
moonlight_control_deallocate (NPObject *npobj)
{
- // XXX is delete broken in plugins?
- // delete (MoonlightControlObject*)npobj;
+ delete (MoonlightControlObject*)npobj;
}
static void
@@ -596,12 +587,14 @@
{
MoonlightControlObject *control = (MoonlightControlObject*)npobj;
- if (control->settings)
- NPN_ReleaseObject (control->settings);
+// XXX apparently we don't need to do this?
+// if (control->settings)
+// NPN_ReleaseObject (control->settings);
control->settings = NULL;
- if (control->content)
- NPN_ReleaseObject (control->content);
+// XXX apparently we don't need to do this?
+// if (control->content)
+// NPN_ReleaseObject (control->content);
control->content = NULL;
}
@@ -839,8 +832,7 @@
static void
moonlight_content_deallocate (NPObject *npobj)
{
- // XXX is delete broken in plugins?
- // delete (MoonlightContentObject*)npobj;
+ delete (MoonlightContentObject*)npobj;
}
static void
@@ -853,8 +845,9 @@
/* XXX free resizeMethodName */
- if (content->resizeScript)
- NPN_ReleaseObject (content->resizeScript);
+// XXX apparently we don't need to do this?
+// if (content->resizeScript)
+// NPN_ReleaseObject (content->resizeScript);
content->resizeScript = NULL;
}
@@ -882,8 +875,12 @@
MoonlightContentObject *content = (MoonlightContentObject*)npobj;
- return g_hash_table_lookup (content->registered_scriptable_objects,
- name) != NULL;
+ gpointer p = g_hash_table_lookup
(content->registered_scriptable_objects,
+ name);
+
+ NPUTF8 *strname = NPN_UTF8FromIdentifier (name);
+ DEBUGMSG ("******** OBJECT %s AT %p\n", strname, p);
+ return p != NULL;
}
static bool
@@ -1054,8 +1051,7 @@
static void
moonlight_dependency_object_deallocate (NPObject *npobj)
{
- // XXX is delete broken in plugins?
- // delete (MoonlightDependencyObjectObject*)npobj;
+ delete (MoonlightDependencyObjectObject*)npobj;
}
static void
@@ -1722,6 +1718,10 @@
bool can_write;
};
+struct ScriptableEvent {
+ gpointer event_handle;
+};
+
struct ScriptableMethod {
gpointer method_handle;
int method_return_type;
@@ -1739,8 +1739,7 @@
static void
moonlight_scriptable_object_deallocate (NPObject *npobj)
{
- // XXX is delete broken in plugins?
- // delete (MoonlightScriptableObjectObject*)npobj;
+ delete (MoonlightScriptableObjectObject*)npobj;
}
static void
@@ -1753,7 +1752,7 @@
}
sobj->managed_scriptable = NULL;
- // XXX free the properties and methods hashes.
+ // XXX free the properties, events, and methods hashes.
}
static bool
@@ -1761,7 +1760,8 @@
{
MoonlightScriptableObjectObject *sobj =
(MoonlightScriptableObjectObject*)npobj;
- return g_hash_table_lookup (sobj->properties, name) != NULL;
+ return (g_hash_table_lookup (sobj->properties, name) != NULL
+ || g_hash_table_lookup (sobj->events, name));
}
static bool
@@ -1784,16 +1784,27 @@
moonlight_scriptable_object_set_property (NPObject *npobj, NPIdentifier name,
const NPVariant *value)
{
MoonlightScriptableObjectObject *sobj =
(MoonlightScriptableObjectObject*)npobj;
+
+ // first we try the property hash
ScriptableProperty *prop = (ScriptableProperty*)g_hash_table_lookup
(sobj->properties, name);
- if (!prop)
- return false;
+ if (prop) {
+ NPUTF8 *strname = NPN_UTF8FromIdentifier (name);
+ DEBUGMSG ("***************** setting scriptable object property
%s", strname);
+ NPN_MemFree (strname);
- NPUTF8 *strname = NPN_UTF8FromIdentifier (name);
- DEBUGMSG ("***************** setting scriptable object property %s",
strname);
- NPN_MemFree (strname);
+ DEBUG_WARN_NOTIMPLEMENTED ();
+ return true;
+ }
+ // if that fails, look for the event of that name
+ ScriptableEvent *event = (ScriptableEvent*)g_hash_table_lookup
(sobj->events, name);
+ if (event) {
+ NPUTF8 *strname = NPN_UTF8FromIdentifier (name);
+ DEBUGMSG ("***************** adding scriptable object event
%s", strname);
+ NPN_MemFree (strname);
- DEBUG_WARN_NOTIMPLEMENTED ();
- return true;
+ DEBUG_WARN_NOTIMPLEMENTED ();
+ return true;
+ }
}
static bool
@@ -1832,8 +1843,9 @@
sobj->invoke (sobj->managed_scriptable, method->method_handle, vargs,
argCount, &rv);
delete [] vargs;
- /* XXX do something with rv here if the return type is something other
than void */
- DEBUG_WARN_NOTIMPLEMENTED ();
+ if (method->method_return_type != 1 /* XXX this 1 is "void" */) {
+ value_to_variant (sobj, &rv, result);
+ }
return true;
}
@@ -1858,7 +1870,10 @@
moonlight_scriptable_object_wrapper_create (PluginInstance *plugin, gpointer
scriptable,
InvokeDelegate invoke_func,
SetPropertyDelegate setprop_func,
- GetPropertyDelegate getprop_func)
+ GetPropertyDelegate getprop_func,
+ EventHandlerDelegate addevent_func,
+ EventHandlerDelegate
removeevent_func)
+
{
MoonlightControlObject *root_object = plugin->getRootObject ();
@@ -1869,6 +1884,8 @@
obj->invoke = invoke_func;
obj->setprop = setprop_func;
obj->getprop = getprop_func;
+ obj->addevent = addevent_func;
+ obj->removeevent = removeevent_func;
DEBUGMSG ("creating scriptable object wrapper => %p", obj);
return obj;
@@ -1883,7 +1900,7 @@
bool can_read,
bool can_write)
{
- DEBUGMSG ("adding property named %s to scriptable object %p\n",
property_name, obj);
+ DEBUGMSG ("adding property named %s to scriptable object %p",
property_name, obj);
ScriptableProperty *prop = new ScriptableProperty ();
prop->property_handle = property_handle;
@@ -1895,6 +1912,20 @@
}
void
+moonlight_scriptable_object_add_event (PluginInstance *plugin,
+ MoonlightScriptableObjectObject *obj,
+ gpointer event_handle,
+ char *event_name)
+{
+ DEBUGMSG ("adding event named %s to scriptable object %p", event_name,
obj);
+
+ ScriptableEvent *event = new ScriptableEvent ();
+ event->event_handle = event_handle;
+
+ g_hash_table_insert (obj->events, NPID(event_name), event);
+}
+
+void
moonlight_scriptable_object_add_method (PluginInstance *plugin,
MoonlightScriptableObjectObject *obj,
gpointer method_handle,
@@ -1904,7 +1935,7 @@
int parameter_count)
{
- DEBUGMSG ("adding method named %s to scriptable object %p\n",
method_name, obj);
+ DEBUGMSG ("adding method named %s (return type = %d) to scriptable
object %p", method_name, method_return_type, obj);
ScriptableMethod *method = new ScriptableMethod ();
method->method_handle = method_handle;
@@ -1914,7 +1945,6 @@
method->parameter_count = parameter_count;
g_hash_table_insert (obj->methods, NPID(method_name), method);
-
}
void
Modified: trunk/moon/plugin/plugin-class.h
===================================================================
--- trunk/moon/plugin/plugin-class.h 2007-07-19 19:36:02 UTC (rev 82318)
+++ trunk/moon/plugin/plugin-class.h 2007-07-19 19:36:16 UTC (rev 82319)
@@ -193,6 +193,7 @@
typedef void (*InvokeDelegate) (gpointer obj_handle, gpointer method_handle,
Value* args, int arg_count, Value* return_value);
typedef void (*SetPropertyDelegate) (gpointer obj_handle, gpointer
property_handle, Value value);
typedef void (*GetPropertyDelegate) (gpointer obj_handle, gpointer
property_handle, Value *value);
+typedef void (*EventHandlerDelegate) (gpointer obj_handle, gpointer
event_handle);
struct MoonlightScriptableObjectType : MoonlightObjectType {
MoonlightScriptableObjectType ();
@@ -207,15 +208,19 @@
managed_scriptable = NULL;
properties = g_hash_table_new (g_direct_hash, g_direct_equal);
methods = g_hash_table_new (g_direct_hash, g_direct_equal);
+ events = g_hash_table_new (g_direct_hash, g_direct_equal);
}
gpointer managed_scriptable;
GHashTable *properties;
GHashTable *methods;
+ GHashTable *events;
InvokeDelegate invoke;
SetPropertyDelegate setprop;
GetPropertyDelegate getprop;
+ EventHandlerDelegate addevent;
+ EventHandlerDelegate removeevent;
};
extern "C" {
@@ -224,7 +229,9 @@
MoonlightScriptableObjectObject*
moonlight_scriptable_object_wrapper_create (PluginInstance *plugin, gpointer
scriptable,
InvokeDelegate invoke,
SetPropertyDelegate setprop,
-
GetPropertyDelegate getprop);
+
GetPropertyDelegate getprop,
+
EventHandlerDelegate addevent,
+
EventHandlerDelegate removeevent);
void moonlight_scriptable_object_add_property (PluginInstance *plugin,
MoonlightScriptableObjectObject *obj,
@@ -234,6 +241,11 @@
bool can_read,
bool can_write);
+ void moonlight_scriptable_object_add_event (PluginInstance *plugin,
+
MoonlightScriptableObjectObject *obj,
+ gpointer event_handle,
+ char *event_name);
+
void moonlight_scriptable_object_add_method (PluginInstance *plugin,
MoonlightScriptableObjectObject *obj,
gpointer method_handle,
Modified: trunk/moon/plugin/plugin-glue.cpp
===================================================================
--- trunk/moon/plugin/plugin-glue.cpp 2007-07-19 19:36:02 UTC (rev 82318)
+++ trunk/moon/plugin/plugin-glue.cpp 2007-07-19 19:36:16 UTC (rev 82319)
@@ -220,9 +220,7 @@
already_initialized = true;
gtk_init (0, 0);
downloader_initialize ();
-#ifdef RUNTIME
vm_init ();
-#endif
runtime_init ();
plugin_init_classes ();
Modified: trunk/moon/plugin/plugin.cpp
===================================================================
--- trunk/moon/plugin/plugin.cpp 2007-07-19 19:36:02 UTC (rev 82318)
+++ trunk/moon/plugin/plugin.cpp 2007-07-19 19:36:16 UTC (rev 82319)
@@ -272,13 +272,8 @@
if (NPN_Evaluate(this->instance, object, &reference, &result)) {
if (NPVARIANT_IS_STRING (result)) {
-#ifdef RUNTIME
mono_loader_object = vm_xaml_str_loader_new (this,
this->surface, NPVARIANT_TO_STRING (result).utf8characters);
TryLoad ();
-#else
- UIElement * element = xaml_create_from_str
(NPVARIANT_TO_STRING (result).utf8characters, true, NULL, NULL, NULL, NULL);
- this->surface->Attach (element);
-#endif
}
NPN_ReleaseVariantValue (&result);
@@ -390,13 +385,8 @@
if (IS_NOTIFY_SOURCE (stream->notifyData)) {
DEBUGMSG ("LoadFromXaml: %s", fname);
-#ifdef RUNTIME
- mono_loader_object = vm_xaml_file_loader_new (this,
this->surface, fname);
- TryLoad ();
-#else
- UIElement *element = xaml_create_from_file (fname,
true, NULL, NULL, NULL, NULL);
- this->surface->Attach (element);
-#endif
+ mono_loader_object = vm_xaml_file_loader_new (this,
this->surface, fname);
+ TryLoad ();
if (!this->isLoaded) {
this->isLoaded = true;
@@ -411,7 +401,6 @@
downloader_notify_finished (dl, fname);
}
-#ifdef RUNTIME
if (IS_NOTIFY_REQUEST (stream->notifyData)) {
vm_insert_mapping (mono_loader_object, vm_missing_file, fname);
vm_insert_mapping (mono_loader_object, stream->url, fname);
@@ -421,7 +410,6 @@
// retry to load
TryLoad ();
}
-#endif
}
int32
@@ -547,8 +535,8 @@
{
if (rootobject == NULL)
rootobject = NPN_CreateObject (instance, MoonlightControlClass);
- else
- NPN_RetainObject (rootobject);
+
+ NPN_RetainObject (rootobject);
return (MoonlightControlObject*)rootobject;
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches