Author: toshok
Date: 2007-10-18 15:55:28 -0400 (Thu, 18 Oct 2007)
New Revision: 87795
Modified:
trunk/moon/plugin/ChangeLog
trunk/moon/plugin/debug.js
trunk/moon/plugin/plugin-class.cpp
trunk/moon/plugin/plugin.cpp
trunk/moon/plugin/plugin.h
Log:
2007-10-18 Chris Toshok <[EMAIL PROTECTED]>
* plugin-class.cpp (moonlight_dependency_object_invoke): make the
debug "printf" method its own method, instead of a hack on
setValue.
(MoonlightEventObjectObject::Dispose): remove the wrapped object
from the cache.
(MoonlightEventObjectObject::SetEventObject): update the cache.
(EventObjectCreateWrapper): check the cache before creating a new
js wrapper object.
* debug.js: convert from
printf_proxy.setValue ("printf", message);
to
printf_proxy.printf (message);
* plugin.cpp, plugin.h: add {Add,Remove,Lookup}WrappedObject
methods to cache the JS objects we use for a given EventObject*.
Modified: trunk/moon/plugin/ChangeLog
===================================================================
--- trunk/moon/plugin/ChangeLog 2007-10-18 19:55:25 UTC (rev 87794)
+++ trunk/moon/plugin/ChangeLog 2007-10-18 19:55:28 UTC (rev 87795)
@@ -1,3 +1,22 @@
+2007-10-18 Chris Toshok <[EMAIL PROTECTED]>
+
+ * plugin-class.cpp (moonlight_dependency_object_invoke): make the
+ debug "printf" method its own method, instead of a hack on
+ setValue.
+ (MoonlightEventObjectObject::Dispose): remove the wrapped object
+ from the cache.
+ (MoonlightEventObjectObject::SetEventObject): update the cache.
+ (EventObjectCreateWrapper): check the cache before creating a new
+ js wrapper object.
+
+ * debug.js: convert from
+ printf_proxy.setValue ("printf", message);
+ to
+ printf_proxy.printf (message);
+
+ * plugin.cpp, plugin.h: add {Add,Remove,Lookup}WrappedObject
+ methods to cache the JS objects we use for a given EventObject*.
+
2007-10-17 Chris Toshok <[EMAIL PROTECTED]>
* plugin.cpp (PluginXamlLoader::TryLoad): use ->Attach instead of
Modified: trunk/moon/plugin/debug.js
===================================================================
--- trunk/moon/plugin/debug.js 2007-10-18 19:55:25 UTC (rev 87794)
+++ trunk/moon/plugin/debug.js 2007-10-18 19:55:28 UTC (rev 87795)
@@ -25,5 +25,5 @@
}
}
- printf_proxy.setValue ("printf", message);
+ printf_proxy.printf (message);
}
Modified: trunk/moon/plugin/plugin-class.cpp
===================================================================
--- trunk/moon/plugin/plugin-class.cpp 2007-10-18 19:55:25 UTC (rev 87794)
+++ trunk/moon/plugin/plugin-class.cpp 2007-10-18 19:55:28 UTC (rev 87795)
@@ -1540,7 +1540,10 @@
"findName",
"setValue",
"getValue",
- "toString"
+ "toString",
+#if DEBUG_JAVASCRIPT
+ "printf"
+#endif
};
static NPObject*
@@ -1722,6 +1725,17 @@
{
DependencyObject *dob =
((MoonlightDependencyObjectObject*)npobj)->GetDependencyObject ();
+#if DEBUG_JAVASCRIPT
+ // Some debug code...
+ // with this it is possible to do obj.printf ("msg") from js
+ if (name_matches (name, "printf")) {
+ printf ("JS message: %s\n", NPVARIANT_TO_STRING (args
[0]).utf8characters);
+ VOID_TO_NPVARIANT (*result);
+ return true;
+ }
+#endif
+
+
if (name_matches (name, "setValue")) {
/* obj.setValue (prop, val) is another way of writing obj[prop]
= val (or obj.prop = val) */
if (argCount < 2
@@ -1729,22 +1743,6 @@
return true;
}
-#if DEBUG_JAVASCRIPT
- // Some debug code...
- // with this it is possible to do obj.setValue ("printf",
"msg") from js
- const NPUTF8* pf = NPVARIANT_TO_STRING (args[0]).utf8characters;
- if (strcmp ((char*) pf, "printf") == 0) {
- NPIdentifier message = NPID (NPVARIANT_TO_STRING (args
[1]).utf8characters);
- NPUTF8 *strname = NPN_UTF8FromIdentifier (message);
- strname[0] = toupper(strname[0]);
- printf ("JS message: %s\n", strname);
- NPN_MemFree (strname);
-
- VOID_TO_NPVARIANT (*result);
- return true;
- }
-#endif
-
moonlight_dependency_object_set_property (npobj,
NPID
(NPVARIANT_TO_STRING (args[0]).utf8characters),
&args[1]);
@@ -1763,8 +1761,6 @@
return true;
}
else if (name_matches (name, "findName")) {
- PluginInstance *plugin = (PluginInstance*)
((MoonlightObject*)npobj)->instance->pdata;
-
if (!argCount)
return true;
@@ -1794,7 +1790,7 @@
DependencyObject *parent = dob->GetParent();
if (parent) {
MoonlightEventObjectObject *depobj =
EventObjectCreateWrapper (((MoonlightObject*)npobj)->instance,
-
dob->GetParent());
+
dob->GetParent());
OBJECT_TO_NPVARIANT (depobj, *result);
}
@@ -1891,21 +1887,32 @@
{
MoonlightObject::Dispose ();
- if (eo)
+ if (eo) {
+ PluginInstance *plugin = (PluginInstance*) instance->pdata;
+ plugin->RemoveWrappedObject (eo);
eo->unref ();
+ }
eo = NULL;
}
void
MoonlightEventObjectObject::SetEventObject (EventObject *eventobject)
{
- if (eo)
+ PluginInstance *plugin = (PluginInstance*) instance->pdata;
+
+ // we shouldn't need to worry about this case, right? we create
+ // wrapper objects whenever we need them, and don't reuse them...
+ if (eo) {
+ plugin->RemoveWrappedObject (eo);
eo->unref ();
+ }
eo = eventobject;
- if (eo)
+ if (eo) {
+ plugin->AddWrappedObject (eo, this);
eo->ref ();
+ }
}
static bool
@@ -1956,8 +1963,17 @@
MoonlightEventObjectObject*
EventObjectCreateWrapper (NPP instance, EventObject *obj)
{
+ PluginInstance *plugin = (PluginInstance*) instance->pdata;
NPClass *np_class;
+ MoonlightEventObjectObject *depobj;
+ depobj = (MoonlightEventObjectObject *)plugin->LookupWrappedObject
(obj);
+
+ if (depobj) {
+ NPN_RetainObject (depobj);
+ return depobj;
+ }
+
/* for EventObject subclasses which have special plugin classes, check
here */
if (Type::Find (obj->GetObjectType ())->IsSubclassOf (Type::COLLECTION))
np_class = MoonlightCollectionClass;
@@ -1993,9 +2009,8 @@
}
}
- MoonlightEventObjectObject *depobj
- = (MoonlightEventObjectObject*)NPN_CreateObject (instance,
- np_class);
+ depobj = (MoonlightEventObjectObject*)NPN_CreateObject (instance,
+ np_class);
depobj->SetEventObject (obj);
@@ -2003,7 +2018,7 @@
switch (obj->GetObjectType()) {
case Type::CONTROL:
((MoonlightControlObject *)depobj)->real_object =
EventObjectCreateWrapper (instance,
-
((Control*)obj)->real_object);
+
((Control*)obj)->real_object);
break;
default:
/* nothing to do */
@@ -2140,7 +2155,7 @@
Collection::Node *n = (Collection::Node*)col->list->Index
(index);
MoonlightEventObjectObject *depobj = EventObjectCreateWrapper
(((MoonlightObject*)npobj)->instance,
-
n->obj);
+
n->obj);
OBJECT_TO_NPVARIANT ((NPObject*)depobj, *result);
Modified: trunk/moon/plugin/plugin.cpp
===================================================================
--- trunk/moon/plugin/plugin.cpp 2007-10-18 19:55:25 UTC (rev 87794)
+++ trunk/moon/plugin/plugin.cpp 2007-10-18 19:55:28 UTC (rev 87795)
@@ -144,6 +144,8 @@
this->timers = NULL;
+ this->wrapped_objects = g_hash_table_new (g_direct_hash,
g_direct_equal);
+
plugin_instances = g_slist_append (plugin_instances, this->instance);
/* back pointer to us */
@@ -161,6 +163,8 @@
}
g_slist_free (p);
+ g_hash_table_destroy (wrapped_objects);
+
// Remove us from the list.
plugin_instances = g_slist_remove (plugin_instances, this->instance);
@@ -778,6 +782,24 @@
return 0;
}
+void
+PluginInstance::AddWrappedObject (EventObject *obj, NPObject *wrapper)
+{
+ g_hash_table_insert (wrapped_objects, obj, wrapper);
+}
+
+void
+PluginInstance::RemoveWrappedObject (EventObject *obj)
+{
+ g_hash_table_remove (wrapped_objects, obj);
+}
+
+NPObject*
+PluginInstance::LookupWrappedObject (EventObject *obj)
+{
+ return (NPObject*)g_hash_table_lookup (wrapped_objects, obj);
+}
+
/*** Getters and Setters
******************************************************/
void
Modified: trunk/moon/plugin/plugin.h
===================================================================
--- trunk/moon/plugin/plugin.h 2007-10-18 19:55:25 UTC (rev 87794)
+++ trunk/moon/plugin/plugin.h 2007-10-18 19:55:28 UTC (rev 87795)
@@ -30,6 +30,8 @@
NPObject* rootobject; // Mozilla jscript object wrapper
bool xembed_supported; // XEmbed Extension supported
+ GHashTable *wrapped_objects; // wrapped object cache
+
// Property fields
char *initParams;
bool isLoaded;
@@ -82,6 +84,10 @@
void ReportException (char *msg, char *details, char **stack_trace, int
num_frames);
void *LoadUrl (char *url, gint32 *length);
+ void AddWrappedObject (EventObject *obj, NPObject *wrapper);
+ void RemoveWrappedObject (EventObject *obj);
+ NPObject* LookupWrappedObject (EventObject *obj);
+
NPP getNPP () { return instance; }
static Downloader* CreateDownloader (PluginInstance* instance)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches