Gnash
0.8.10
|
00001 // 00002 // Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc 00003 // 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software 00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00017 // 00018 00019 00020 // Test: 00021 // Use browser to open plugin/scriptable-test.html. 00022 // 00023 // Notes: 00024 // 1. In order not to rewrite the whole Plugin, just be _scriptObject 00025 // of nsPluginInstance. 00026 // 2. GnashPluginScriptObject is the marshal object to response 00027 // JavaScript, no function to gtk-gnash yet. 00028 // 3. Once gnash::Player support multiple instance, it's possible to 00029 // the bridge between JavaScript and ActionScript. 00030 // 00031 // Todo: 00032 // Support the methods listed in 00033 // http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_03.html 00034 00035 #ifndef GNASH_PLUGIN_SCRIPT_OBJECT_H 00036 #define GNASH_PLUGIN_SCRIPT_OBJECT_H 00037 00038 #include <map> 00039 #include <string> 00040 00041 #include <glib.h> 00042 #include "npapi.h" 00043 #include "npruntime.h" 00044 #include "GnashNPVariant.h" 00045 00046 #define READFD 0 00047 #define WRITEFD 1 00048 00049 namespace gnash { 00050 00054 void 00055 CopyVariantValue(const NPVariant& from, NPVariant& to); 00056 00057 class GnashPluginScriptObject : public NPObject 00058 { 00059 public: 00060 00061 GnashPluginScriptObject(); 00062 GnashPluginScriptObject(NPP npp); 00063 ~GnashPluginScriptObject(); 00064 00065 static NPClass *marshalGetNPClass(); 00066 00067 // NPObject static Functions. These get used by the browser, which is 00068 // why they have to be static. 00069 static NPObject *marshalAllocate (NPP npp, NPClass *aClass); 00070 static void marshalDeallocate (NPObject *npobj); 00071 static void marshalInvalidate (NPObject *npobj); 00072 static bool marshalHasMethod (NPObject *npobj, NPIdentifier name); 00073 static bool marshalInvoke (NPObject *npobj, NPIdentifier name, 00074 const NPVariant *args, uint32_t argCount, 00075 NPVariant *result); 00076 static bool marshalInvokeDefault (NPObject *npobj, const NPVariant *args, 00077 uint32_t argCount, NPVariant *result); 00078 static bool marshalHasProperty (NPObject *npobj, NPIdentifier name); 00079 static bool marshalGetProperty (NPObject *npobj, NPIdentifier name, 00080 NPVariant *result); 00081 static bool marshalSetProperty (NPObject *npobj, NPIdentifier name, 00082 const NPVariant *value); 00083 static bool marshalRemoveProperty (NPObject *npobj, NPIdentifier name); 00084 static bool marshalEnumerate (NPObject *npobj, void***identifier, 00085 uint32_t *count); 00086 static bool marshalConstruct (NPObject *npobj, const NPVariant *data, 00087 uint32_t count, NPVariant *result); 00088 00089 static NPClass _npclass; 00090 00093 00097 void setControlFD(int x); 00098 int getControlFD(); 00099 00103 void setHostFD(int x); 00104 int getHostFD(); 00105 00113 bool SetVariable(const std::string &name, const NPVariant& value); 00114 00120 GnashNPVariant GetVariable(const std::string &name); 00121 00122 00123 int getReadFD() { return _hostfd; }; 00124 int getWriteFD() { return _controlfd; }; 00125 00126 // Write to the standalone player over the control socket 00127 int writePlayer(const std::string &data); 00128 int writePlayer(int fd, const std::string &data); 00129 00130 // Read the standalone player over the control socket 00131 std::string readPlayer(); 00132 std::string readPlayer(int fd); 00133 00134 bool Invoke(NPObject *npobj, NPIdentifier name, const NPVariant *args, 00135 uint32_t argCount, NPVariant *result); 00136 bool AddMethod(NPIdentifier name, NPInvokeFunctionPtr func); 00137 void AddProperty(const std::string &name, const std::string &str); 00138 void AddProperty(const std::string &name, double num); 00139 void AddProperty(const std::string &name, int num); 00140 00141 protected: 00142 // Internal functions for the API 00143 void Deallocate(); 00144 void Invalidate(); 00145 bool HasMethod(NPIdentifier name); 00146 00147 bool InvokeDefault(const NPVariant *args, uint32_t argCount, 00148 NPVariant *result); 00149 bool HasProperty(NPIdentifier name); 00150 bool GetProperty(NPIdentifier name, NPVariant *result); 00151 bool SetProperty(NPIdentifier name, const NPVariant& value); 00152 bool RemoveProperty(NPIdentifier name); 00153 bool Enumerate(NPIdentifier **identifier, uint32_t *count); 00154 bool Construct(const NPVariant *data, uint32_t argCount, NPVariant *result); 00155 00156 private: 00157 void initializeIdentifiers(); 00158 void setInstance(NPP inst) { _nppinstance = inst; }; 00159 00160 // _nppinstance->pdata should be the nsPluginInstance once NPP_New() is finished. 00161 NPP _nppinstance; 00162 00163 std::map<NPIdentifier, GnashNPVariant> _properties; 00164 std::map<NPIdentifier, NPInvokeFunctionPtr> _methods; 00165 // 0 for reading, 1 for writing 00166 00170 int _controlfd; 00174 int _hostfd; 00175 }; 00176 00177 } // end of gnash namespace 00178 00179 #endif // GNASH_PLUGIN_SCRIPT_OBJECT_H 00180 00181 // local Variables: 00182 // mode: C++ 00183 // indent-tabs-mode: nil 00184 // End: