Author: everaldo
Date: 2007-06-20 16:53:43 -0400 (Wed, 20 Jun 2007)
New Revision: 80365

Modified:
   trunk/moon/plugin/ChangeLog
   trunk/moon/plugin/plugin.cpp
   trunk/moon/plugin/plugin.h
Log:
2007-06-20  Everaldo Canuto  <[EMAIL PROTECTED]>

        * plugin.cpp, plugin.h: Implement JsExecute method and use it to call 
onload
        event specified in control creation. onLoad and onError field is also 
        created.



Modified: trunk/moon/plugin/ChangeLog
===================================================================
--- trunk/moon/plugin/ChangeLog 2007-06-20 20:49:35 UTC (rev 80364)
+++ trunk/moon/plugin/ChangeLog 2007-06-20 20:53:43 UTC (rev 80365)
@@ -1,3 +1,9 @@
+2007-06-20  Everaldo Canuto  <[EMAIL PROTECTED]>
+
+       * plugin.cpp, plugin.h: Implement JsExecute method and use it to call 
onload
+       event specified in control creation. onLoad and onError field is also 
+       created.
+
 2007-06-20  Jackson Harper  <[EMAIL PROTECTED]>
 
        * moonlight.cs: Tie into events.

Modified: trunk/moon/plugin/plugin.cpp
===================================================================
--- trunk/moon/plugin/plugin.cpp        2007-06-20 20:49:35 UTC (rev 80364)
+++ trunk/moon/plugin/plugin.cpp        2007-06-20 20:53:43 UTC (rev 80365)
@@ -80,6 +80,8 @@
        this->initParams = false;
        this->isLoaded = false;
        this->source = NULL;
+       this->onLoad = NULL;
+       this->onError = NULL;
 
        this->windowless = false;
        
@@ -110,6 +112,16 @@
                        this->initParams = argv[i];
                }
 
+               // onLoad.
+               if (!strcasecmp (argn[i], "onLoad")) {
+                       this->onLoad = argv[i];
+               }
+
+               // onError.
+               if (!strcasecmp (argn[i], "onError")) {
+                       this->onError = argv[i];
+               }
+
                // Source url handle.
                if (!strcasecmp (argn[i], "src") || !strcasecmp (argn[i], 
"source")) {
                        this->source = argv[i];
@@ -238,7 +250,7 @@
 void 
 PluginInstance::UpdateSourceByReference (const char *value)
 {
-       NPObject *object;
+       NPObject *object = NULL;
        NPString reference;
        NPVariant result;
 
@@ -272,6 +284,39 @@
        NPN_ReleaseObject (object);
 }
 
+bool
+PluginInstance::JsExecute (const char *expression)
+{
+       bool retval = false;
+       NPObject *object = NULL;
+       NPString reference;
+       NPVariant result;
+
+       if (NPERR_NO_ERROR != NPN_GetValue(this->instance, NPNVWindowNPObject, 
&object)) {
+               DEBUGMSG ("*** Failed to get window object");
+               return false;
+       }
+
+       char jscript [strlen (expression) + 4];
+
+       g_strlcpy (jscript, expression, sizeof (jscript));
+       g_strlcat (jscript, "();", sizeof (jscript));
+
+       reference.utf8characters = jscript;
+       reference.utf8length = strlen (jscript);
+
+       if (NPN_Evaluate(this->instance, object, &reference, &result)) {
+               if (&result)
+                       retval = true;
+
+               NPN_ReleaseVariantValue (&result);
+       }
+
+       NPN_ReleaseObject (object);
+       
+       return retval;
+}
+
 NPError
 PluginInstance::NewStream (NPMIMEType type, NPStream* stream, NPBool seekable, 
uint16* stype)
 {
@@ -341,7 +386,10 @@
                        surface_attach (this->surface, element);
                #endif
 
-               this->isLoaded = true;
+               if (!this->isLoaded) {
+                       this->isLoaded = true;
+                       JsExecute (this->onLoad);
+               }
        }
 
 #ifdef RUNTIME

Modified: trunk/moon/plugin/plugin.h
===================================================================
--- trunk/moon/plugin/plugin.h  2007-06-20 20:49:35 UTC (rev 80364)
+++ trunk/moon/plugin/plugin.h  2007-06-20 20:53:43 UTC (rev 80365)
@@ -28,6 +28,8 @@
        char *initParams;
        bool isLoaded;
        char *source;
+       char *onLoad;
+       char *onError;
 
        bool windowless;
 
@@ -63,7 +65,9 @@
        void UrlNotify (const char* url, NPReason reason, void* notifyData);
        void Print (NPPrint* platformPrint);
        int16 EventHandle (void* event);
+       bool JsExecute (const char *expression);
 
+
        // Gtk controls
        GtkWidget *container;  // plugin container object
        Surface *surface;      // plugin surface object

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to