gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r12141: add crude support for JavaSc


From: Rob Savoye
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r12141: add crude support for JavaScript/Flash Variables. This is a work in progress...
Date: Fri, 09 Apr 2010 10:54:11 -0600
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 12141 [merge]
committer: Rob Savoye <address@hidden>
branch nick: trunk
timestamp: Fri 2010-04-09 10:54:11 -0600
message:
  add crude support for JavaScript/Flash Variables. This is a work in 
progress...
modified:
  plugin/npapi/plugin.cpp
  plugin/npapi/pluginScriptObject.cpp
  plugin/npapi/pluginScriptObject.h
  plugin/npapi/scriptable-test.html
=== modified file 'plugin/npapi/plugin.cpp'
--- a/plugin/npapi/plugin.cpp   2010-04-08 23:11:33 +0000
+++ b/plugin/npapi/plugin.cpp   2010-04-09 16:48:11 +0000
@@ -23,6 +23,7 @@
 
 #include <cstdlib> // getenv
 #include <stdlib.h> // putenv
+#include <sys/socket.h> // shutdown
 
 #define MIME_TYPES_HANDLED  "application/x-shockwave-flash"
 // The name must be this value to get flash movies that check the
@@ -456,9 +457,14 @@
         }
     }
 
-    int ret = close(_controlfd);
-    if (ret != 0) {
-        GnashLogDebug("Gnash plugin failed to close the control socket!");
+    if (_controlfd != -1) {
+        if (shutdown(_controlfd, SHUT_RDWR) !=0) {
+            GnashLogError("Gnash plugin failed to shutdown the control 
socket!");
+        }
+
+        if (close(_controlfd) != 0) {
+            GnashLogError("Gnash plugin failed to close the control socket!");
+        }
     }
 }
 /// \brief Set the window to be used to render in

=== modified file 'plugin/npapi/pluginScriptObject.cpp'
--- a/plugin/npapi/pluginScriptObject.cpp       2010-04-08 22:39:09 +0000
+++ b/plugin/npapi/pluginScriptObject.cpp       2010-04-09 16:50:12 +0000
@@ -24,6 +24,7 @@
 #include <fstream>
 #include <sstream>
 #include <map>
+#include <string>
 
 #include "npapi.h"
 #include "npruntime.h"
@@ -48,18 +49,77 @@
     GnashPluginScriptObject::marshalHasProperty,
     GnashPluginScriptObject::marshalGetProperty,
     GnashPluginScriptObject::marshalSetProperty,
-    GnashPluginScriptObject::marshalRemoveProperty
+    GnashPluginScriptObject::marshalRemoveProperty,
+    GnashPluginScriptObject::marshalEnumerate,
+    GnashPluginScriptObject::marshalConstruct
 };
 
+// FIXME: The Flash variables should be changed in the standalone player,
+// but for now we're going to cheat and store them locally.
+std::map<std::string, NPVariant *> _variables;
+
 #if 0
 
-#define NUM_METHOD_IDENTIFIERS       3
+// From 
http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_03.html
+// var movie = window.document.movie
+
+#define NUM_METHOD_IDENTIFIERS       13
 static NPIdentifier pluginMethodIdentifiers[NUM_METHOD_IDENTIFIERS];
+// Standard Methods
 static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = {
-   "setVariable",
-   "getVariable",
-   "showFoobar"
+   "SetVariable",
+   "GetVariable",
+   "GotoFrame",
+   "IsPlaying",
+   "LoadMovie",
+   "Pan",
+   "PercentLoaded",
+   "Play",
+   "Rewind",
+   "SetZoomRect",
+   "StopPlay",
+   "Zoom",
+   "TotalFrames"
 };
+
+// 
http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_04.html
+// Tell Target Methods. Use TGetProperty, TGetPropertyAsNumber, TSetProperty
+TCallLabel
+TCurrentFrame
+TCurrentLabel
+TGetProperty
+TGetPropertyAsNumber
+TGotoFrame
+TGotoLabel
+TPlay
+TSetProperty
+TStopPlay
+
+// Target Properties
+X_POS
+Y_POS
+X_SCALE
+Y_SCALE
+CURRENT_FRAME                   // read-only
+TOTAL_FRAMES                    // read-only
+ALPHA
+VISIBLE
+WIDTH                           // read-only
+HEIGHT                          // read-only
+ROTATE
+TARGET                          // read-only
+FRAMES_LOADED                   // read-only
+NAME
+DROP_TARGET                     // read-only
+URL                             // read-only
+HIGH_QUALITY
+FOCUS_RECT
+SOUND_BUF_TIME
+
+// Standard Events
+OnProgress
+OnReadyStateChange
+FSCommand
 #endif
 
 bool
@@ -73,6 +133,159 @@
     return true;
 }
 
+// Callbacks for the default methods
+bool
+SetVariableCallback (NPObject *npobj, NPIdentifier /* name */, const NPVariant 
*args,
+          uint32_t argCount, NPVariant */* result */)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+
+    GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)npobj;
+
+    std::string varname;
+    if (argCount == 2) {
+        varname = NPVARIANT_TO_STRING(args[0]).UTF8Characters;
+        NPVariant *value = const_cast<NPVariant *>(&args[1]);
+        // printf("Setting Variable \"%s\"\n", varname.c_str());
+        gpso->SetVariable(varname, value);
+        return true;
+    }
+    
+    return false;
+}
+
+bool
+GetVariableCallback (NPObject */* npobj */, NPIdentifier /* name */, const 
NPVariant */*args */,
+          uint32_t /* argCount */, NPVariant *result)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    
+    DOUBLE_TO_NPVARIANT(122333.4444, *result);
+    
+    return true;
+}
+
+bool
+GotoFrame (NPObject */* npobj */, NPIdentifier /* name */, const NPVariant 
*/*args */,
+          uint32_t /* argCount */, NPVariant *result)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    
+    DOUBLE_TO_NPVARIANT(122333.4444, *result);
+    
+    return true;
+}
+
+bool
+IsPlaying (NPObject */* npobj */, NPIdentifier /* name */, const NPVariant 
*/*args */,
+          uint32_t /* argCount */, NPVariant *result)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    
+    DOUBLE_TO_NPVARIANT(122333.4444, *result);
+    
+    return true;
+}
+
+bool
+LoadMovie (NPObject */* npobj */, NPIdentifier /* name */, const NPVariant 
*/*args */,
+          uint32_t /* argCount */, NPVariant *result)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    
+    DOUBLE_TO_NPVARIANT(122333.4444, *result);
+    
+    return true;
+}
+
+bool
+Pan (NPObject */* npobj */, NPIdentifier /* name */, const NPVariant */*args 
*/,
+          uint32_t /* argCount */, NPVariant *result)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    
+    DOUBLE_TO_NPVARIANT(122333.4444, *result);
+    
+    return true;
+}
+
+bool
+PercentLoaded (NPObject */* npobj */, NPIdentifier /* name */, const NPVariant 
*/*args */,
+          uint32_t /* argCount */, NPVariant *result)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    
+    DOUBLE_TO_NPVARIANT(122333.4444, *result);
+    
+    return true;
+}
+
+bool
+Play (NPObject */* npobj */, NPIdentifier /* name */, const NPVariant */*args 
*/,
+          uint32_t /* argCount */, NPVariant *result)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    
+    DOUBLE_TO_NPVARIANT(122333.4444, *result);
+    
+    return true;
+}
+
+bool
+Rewind (NPObject */* npobj */, NPIdentifier /* name */, const NPVariant 
*/*args */,
+          uint32_t /* argCount */, NPVariant *result)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    
+    DOUBLE_TO_NPVARIANT(122333.4444, *result);
+    
+    return true;
+}
+
+bool
+SetZoomRect (NPObject */* npobj */, NPIdentifier /* name */, const NPVariant 
*/*args */,
+          uint32_t /* argCount */, NPVariant *result)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    
+    DOUBLE_TO_NPVARIANT(122333.4444, *result);
+    
+    return true;
+}
+
+bool
+StopPlay (NPObject */* npobj */, NPIdentifier /* name */, const NPVariant 
*/*args */,
+          uint32_t /* argCount */, NPVariant *result)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    
+    DOUBLE_TO_NPVARIANT(122333.4444, *result);
+    
+    return true;
+}
+
+bool
+Zoom (NPObject */* npobj */, NPIdentifier /* name */, const NPVariant */* args 
*/,
+          uint32_t /* argCount */, NPVariant *result)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    
+    DOUBLE_TO_NPVARIANT(122333.4444, *result);
+    
+    return true;
+}
+
+bool
+TotalFrames (NPObject */* npobj */, NPIdentifier /* name */, const NPVariant 
*/*args */,
+          uint32_t /* argCount */, NPVariant *result)
+{   
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    
+    DOUBLE_TO_NPVARIANT(122333.4444, *result);
+    
+    return true;
+}
+
 void
 GnashPluginScriptObject::AddProperty(const std::string &name,
                                      const std::string &str)
@@ -111,6 +324,8 @@
 {
     GnashLogDebug("initializeIdentifiers");
 
+//    
http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_04.html
+    
     AddProperty("src", "example");
     AddProperty("align", "middle");
     AddProperty("quality", "high");
@@ -120,7 +335,7 @@
     AddProperty("codebase", "http://www.getgnash.org";);
     AddProperty("pluginspage", "http://www.getgnash.org";);
 
-    AddProperty("classid", "unneeded for free software");
+    AddProperty("classid", "2b70f2b1-fc72-4734-bb81-4eb2a7713e49");
     AddProperty("movie", "unknown");
     AddProperty("id", "id unknown");
     AddProperty("width", 0);
@@ -172,7 +387,7 @@
     AddProperty("onactivate", "unknown");
     AddProperty("onbeforedeactivate", "unknown");
     AddProperty("ondeactivate", "unknown");
-
+    
 #if 0
    for (int i = 0; i < NUM_METHOD_IDENTIFIERS; i++) {
        SetProperty(pluginMethodIdentifiers[i], value);
@@ -188,11 +403,49 @@
    AddProperty("version", 456.789);
    AddProperty("hello", "Hello World");
    
-   NPIdentifier fid = NPN_GetStringIdentifier("showFoobar");
-   NPInvokeFunctionPtr func = testfunc;
+   NPIdentifier id = NPN_GetStringIdentifier("showFoobar");
+   NPInvokeFunctionPtr func = testfunc;   
+   AddMethod(id, func);
+
+   id = NPN_GetStringIdentifier("SetVariable");
+   AddMethod(id, SetVariableCallback);
+
+   id = NPN_GetStringIdentifier("GetVariable");
+   AddMethod(id, GetVariableCallback);
+
+   id = NPN_GetStringIdentifier("GotoFrame");
+   AddMethod(id, GotoFrame);
+
+   id = NPN_GetStringIdentifier("IsPlaying");
+   AddMethod(id, IsPlaying);
+
+   id = NPN_GetStringIdentifier("LoadMovie");
+   AddMethod(id, LoadMovie);
+
+   id = NPN_GetStringIdentifier("Pan");
+   AddMethod(id, Pan);
+
+   id = NPN_GetStringIdentifier("PercentLoaded");
+   AddMethod(id, PercentLoaded);
+
+   id = NPN_GetStringIdentifier("Play");
+   AddMethod(id, Play);
+
+   id = NPN_GetStringIdentifier("Rewind");
+   AddMethod(id, Rewind);
+
+   id = NPN_GetStringIdentifier("SetZoomRect");
+   AddMethod(id, SetZoomRect);
+
+   id = NPN_GetStringIdentifier("StopPlay");
+   AddMethod(id, StopPlay);
+
+   id = NPN_GetStringIdentifier("Zoom");
+   AddMethod(id, Zoom);
+
+   id = NPN_GetStringIdentifier("TotalFrames");
+   AddMethod(id, TotalFrames);
    
-   AddMethod(fid, func);
-
 };
 
 // Constructor
@@ -244,10 +497,9 @@
 }
 
 void 
-GnashPluginScriptObject::marshalInvalidate (NPObject *npobj)
+GnashPluginScriptObject::marshalInvalidate (NPObject */* npobj */)
 {
     GnashLogDebug(__PRETTY_FUNCTION__);
-    GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)npobj;
 
 //    gpso->Invalidate();
 }
@@ -336,6 +588,30 @@
     return gpso->RemoveProperty(name);
 }
 
+bool 
+GnashPluginScriptObject::marshalEnumerate (NPObject *npobj, void***identifier,
+                                           uint32_t *count)
+{
+    GnashLogDebug(__PRETTY_FUNCTION__);
+
+    GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)npobj;
+    return gpso->Enumerate(identifier, count);
+
+    return false;
+}
+
+bool 
+GnashPluginScriptObject::marshalConstruct (NPObject *npobj, const NPVariant 
*data,
+                                  uint32_t count, NPVariant *result)
+{
+    GnashLogDebug(__PRETTY_FUNCTION__);
+
+    GnashPluginScriptObject *gpso = (GnashPluginScriptObject *)npobj;    
+    return gpso->Construct(data, count, result);
+
+    return false;
+}
+
 bool
 GnashPluginScriptObject::HasProperty(NPIdentifier name)
 {
@@ -382,10 +658,10 @@
         NPVariant *value = it->second;
         if (NPVARIANT_IS_DOUBLE(*value)) {
             double num = NPVARIANT_TO_DOUBLE(*value);
-            printf(" %g\n", num);
+            printf(" %g", num);
             DOUBLE_TO_NPVARIANT(num, *result);
         } else if (NPVARIANT_IS_STRING(*value)) {
-            printf(" %s\n", NPVARIANT_TO_STRING(*value).UTF8Characters);
+            printf(" %s", NPVARIANT_TO_STRING(*value).UTF8Characters);
             STRINGN_TO_NPVARIANT(NPVARIANT_TO_STRING(*value).UTF8Characters,
                                  NPVARIANT_TO_STRING(*value).UTF8Length,
                                  *result);
@@ -405,9 +681,11 @@
             printf(" object\n");
             OBJECT_TO_NPVARIANT(NPVARIANT_TO_OBJECT(*value), *result);
         }
+        printf("\n");
         return true;
     }
 
+    printf("\n");
     return false;
 };
 
@@ -437,6 +715,23 @@
 }
 
 bool
+GnashPluginScriptObject::Enumerate(NPIdentifier **/*identifier */, uint32_t 
*/* count */)
+{
+    GnashLogDebug(__PRETTY_FUNCTION__);
+
+    return false;
+}
+
+bool
+GnashPluginScriptObject::Construct(const NPVariant */* args */, uint32_t /* 
argCount */,
+                                   NPVariant */* result */)
+{
+    GnashLogDebug(__PRETTY_FUNCTION__);
+
+    return false;
+}
+
+bool
 GnashPluginScriptObject::HasMethod(NPIdentifier name)
 {
 //    GnashLogDebug(__PRETTY_FUNCTION__);
@@ -485,7 +780,8 @@
 }
 
 bool
-GnashPluginScriptObject::InvokeDefault(const NPVariant *args, uint32_t 
argCount, NPVariant *result)
+GnashPluginScriptObject::InvokeDefault(const NPVariant */* args */,
+                          uint32_t /* argCount */, NPVariant */* result */)
 {
     GnashLogDebug(__PRETTY_FUNCTION__);
 #if 0
@@ -519,6 +815,33 @@
     return true;
 }
 
+void
+GnashPluginScriptObject::SetVariable(const std::string &name,
+                                     NPVariant *value)
+{
+    GnashLogDebug(__PRETTY_FUNCTION__);
+    printf("Set Variable \"%s\" to ", name.c_str());
+    
+#if 1
+    if (NPVARIANT_IS_STRING(*value)) {
+        std::string varname = NPVARIANT_TO_STRING(*value).UTF8Characters;
+        printf("%s\n", varname.c_str());
+    } else if (NPVARIANT_IS_DOUBLE(*value)) {
+        printf("%g\n", NPVARIANT_TO_DOUBLE(*value));
+    }
+#endif
+
+    _variables[name] = value;
+}
+
+NPVariant *
+GnashPluginScriptObject::GetVariable(const std::string &name)
+{
+    GnashLogDebug(__PRETTY_FUNCTION__);
+
+    return _variables[name];
+}
+
 // local Variables:
 // mode: C++
 // indent-tabs-mode: nil

=== modified file 'plugin/npapi/pluginScriptObject.h'
--- a/plugin/npapi/pluginScriptObject.h 2010-04-08 22:39:09 +0000
+++ b/plugin/npapi/pluginScriptObject.h 2010-04-09 16:50:12 +0000
@@ -39,6 +39,7 @@
 #define GNASH_PLUGIN_SCRIPT_OBJECT_H
 
 #include <map>
+#include <string>
 
 #include "npapi.h"
 #include "npruntime.h"
@@ -70,8 +71,15 @@
     static bool marshalSetProperty (NPObject *npobj, NPIdentifier name,
                                     const NPVariant *value);
     static bool marshalRemoveProperty (NPObject *npobj, NPIdentifier name);
+    static bool marshalEnumerate (NPObject *npobj, void***identifier,
+                                  uint32_t *count);
+    static bool marshalConstruct (NPObject *npobj, const NPVariant *data,
+                                  uint32_t count, NPVariant *result);
     
     static NPClass _npclass;
+
+    void SetVariable(const std::string &name, NPVariant *value);
+    NPVariant *GetVariable(const std::string &name);
     
 protected:
     bool AddMethod(NPIdentifier name, NPInvokeFunctionPtr func);
@@ -79,7 +87,7 @@
     void AddProperty(const std::string &name, double num);
     void AddProperty(const std::string &name, int num);
 
-    // Internal functions
+    // Internal functions for the API
     void Deallocate();
     void Invalidate();
     bool HasMethod(NPIdentifier name);
@@ -91,7 +99,7 @@
     bool SetProperty(NPIdentifier name, const NPVariant *value);
     bool RemoveProperty(NPIdentifier name);
     bool Enumerate(NPIdentifier **identifier, uint32_t *count);
-    bool Construct(const NPVariant *args, uint32_t argCount, NPVariant 
*result);
+    bool Construct(const NPVariant *data, uint32_t argCount, NPVariant 
*result);
 private:
     void initializeIdentifiers();
     // _nppinstance->pdata should be the nsPluginInstance once NPP_New() is 
finished.

=== modified file 'plugin/npapi/scriptable-test.html'
--- a/plugin/npapi/scriptable-test.html 2010-04-08 22:39:09 +0000
+++ b/plugin/npapi/scriptable-test.html 2010-04-09 16:48:41 +0000
@@ -82,6 +82,10 @@
 
 function ShowFoobar(msg)
 {
+        document.write(embed.SetVariable("foo", "bar") + "<br>");
+        document.write(embed.SetVariable("fuby", 1.1) + "<br>");
+        document.write(embed.GetVariable("foo") + "<br>");
+
        alert(embed.showFoobar(msg));
 }
 </script>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]