Gnash  0.8.11dev
pluginScriptObject.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2010, 2011, 2012, 2016 Free Software Foundation, Inc
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 //
18 
19 
20 // Test:
21 // Use browser to open plugin/scriptable-test.html.
22 //
23 // Notes:
24 // 1. In order not to rewrite the whole Plugin, just be _scriptObject
25 // of nsPluginInstance.
26 // 2. GnashPluginScriptObject is the marshal object to response
27 // JavaScript, no function to gtk-gnash yet.
28 // 3. Once gnash::Player support multiple instance, it's possible to
29 // the bridge between JavaScript and ActionScript.
30 //
31 // Todo:
32 // Support the methods listed in
33 // http://www.adobe.com/support/flash/publishexport/scriptingwithflash/scriptingwithflash_03.html
34 
35 #ifndef GNASH_PLUGIN_SCRIPT_OBJECT_H
36 #define GNASH_PLUGIN_SCRIPT_OBJECT_H
37 
38 #include <map>
39 #include <string>
40 
41 #include <glib.h>
42 #include "npapi.h"
43 #include "npruntime.h"
44 #include "GnashNPVariant.h"
45 
46 #define READFD 0
47 #define WRITEFD 1
48 
49 namespace gnash {
50 
54 void
55 CopyVariantValue(const NPVariant& from, NPVariant& to);
56 
57 class GnashPluginScriptObject : public NPObject
58 {
59 public:
60 
62  GnashPluginScriptObject(NPP npp);
64 
65  static NPClass *marshalGetNPClass();
66 
67  // NPObject static Functions. These get used by the browser, which is
68  // why they have to be static.
69  static NPObject *marshalAllocate (NPP npp, NPClass *aClass);
70  static void marshalDeallocate (NPObject *npobj);
71  static void marshalInvalidate (NPObject *npobj);
72  static bool marshalHasMethod (NPObject *npobj, NPIdentifier name);
73  static bool marshalInvoke (NPObject *npobj, NPIdentifier name,
74  const NPVariant *args, uint32_t argCount,
75  NPVariant *result);
76  static bool marshalInvokeDefault (NPObject *npobj, const NPVariant *args,
77  uint32_t argCount, NPVariant *result);
78  static bool marshalHasProperty (NPObject *npobj, NPIdentifier name);
79  static bool marshalGetProperty (NPObject *npobj, NPIdentifier name,
80  NPVariant *result);
81  static bool marshalSetProperty (NPObject *npobj, NPIdentifier name,
82  const NPVariant *value);
83  static bool marshalRemoveProperty (NPObject *npobj, NPIdentifier name);
84  static bool marshalEnumerate (NPObject *npobj, void***identifier,
85  uint32_t *count);
86  static bool marshalConstruct (NPObject *npobj, const NPVariant *data,
87  uint32_t count, NPVariant *result);
88 
89  static NPClass _npclass;
90 
93 
97  void setControlFD(int x);
98  int getControlFD();
99 
103  void setHostFD(int x);
104  int getHostFD();
105 
113  bool SetVariable(const std::string &name, const NPVariant& value);
114 
120  GnashNPVariant GetVariable(const std::string &name);
121 
122 
123  int getReadFD() { return _hostfd; };
124  int getWriteFD() { return _controlfd; };
125 
126  // Write to the standalone player over the control socket
127  int writePlayer(const std::string &data);
128  int writePlayer(int fd, const std::string &data);
129 
130  // Read the standalone player over the control socket
131  std::string readPlayer();
132  std::string readPlayer(int fd);
133 
134  bool Invoke(NPObject *npobj, NPIdentifier name, const NPVariant *args,
135  uint32_t argCount, NPVariant *result);
136  bool AddMethod(NPIdentifier name, NPInvokeFunctionPtr func);
137  void AddProperty(const std::string &name, const std::string &str);
138  void AddProperty(const std::string &name, double num);
139  void AddProperty(const std::string &name, int num);
140 
142  // nppinstance->pdata should be the nsPluginInstance once NPP_New() is finished.
144 
145 protected:
146  // Internal functions for the API
147  void Deallocate();
148  void Invalidate();
149  bool HasMethod(NPIdentifier name);
150 
151  bool InvokeDefault(const NPVariant *args, uint32_t argCount,
152  NPVariant *result);
153  bool HasProperty(NPIdentifier name);
154  bool GetProperty(NPIdentifier name, NPVariant *result);
155  bool SetProperty(NPIdentifier name, const NPVariant& value);
156  bool RemoveProperty(NPIdentifier name);
157  bool Enumerate(NPIdentifier **identifier, uint32_t *count);
158  bool Construct(const NPVariant *data, uint32_t argCount, NPVariant *result);
159 
160 private:
161  void initializeIdentifiers();
162  void setInstance(NPP inst) { nppinstance = inst; };
163 
164  std::map<NPIdentifier, GnashNPVariant> _properties;
165  std::map<NPIdentifier, NPInvokeFunctionPtr> _methods;
166  // 0 for reading, 1 for writing
167 
171  int _controlfd;
175  int _hostfd;
176 };
177 
178 } // end of gnash namespace
179 
180 #endif // GNASH_PLUGIN_SCRIPT_OBJECT_H
181 
182 // local Variables:
183 // mode: C++
184 // indent-tabs-mode: nil
185 // End:
gnash::GnashPluginScriptObject::setHostFD
void setHostFD(int x)
Definition: pluginScriptObject.cpp:647
NPN_UTF8FromIdentifier
NPUTF8 * NPN_UTF8FromIdentifier(NPIdentifier identifier)
Definition: gshell.cpp:209
gnash::NPStringToString
std::string NPStringToString(const NPString &str)
Construct a std::string from an NPString.
Definition: GnashNPVariant.h:87
gnash::GnashPluginScriptObject::Deallocate
void Deallocate()
gnash::GnashPluginScriptObject::Invoke
bool Invoke(NPObject *npobj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)
Definition: pluginScriptObject.cpp:494
gnash::SetZoomRect
bool SetZoomRect(NPObject *npobj, NPIdentifier, const NPVariant *args, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:481
name
std::string name
Definition: LocalConnection_as.cpp:149
NPNFuncs
NPNetscapeFuncs NPNFuncs
gnash::GnashPluginScriptObject::Invalidate
void Invalidate()
gnash::GnashPluginScriptObject::marshalSetProperty
static bool marshalSetProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value)
Definition: pluginScriptObject.cpp:366
gnash::TotalFrames
bool TotalFrames(NPObject *npobj, NPIdentifier, const NPVariant *, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:605
gnash::PercentLoaded
bool PercentLoaded(NPObject *npobj, NPIdentifier, const NPVariant *, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:351
gnash::GnashPluginScriptObject::marshalHasMethod
static bool marshalHasMethod(NPObject *npobj, NPIdentifier name)
Definition: pluginScriptObject.cpp:309
gnash::GnashPluginScriptObject::readPlayer
std::string readPlayer()
Definition: pluginScriptObject.cpp:684
gnash::GnashPluginScriptObject::marshalHasProperty
static bool marshalHasProperty(NPObject *npobj, NPIdentifier name)
Definition: pluginScriptObject.cpp:349
gnash::GnashPluginScriptObject::marshalGetProperty
static bool marshalGetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result)
Definition: pluginScriptObject.cpp:357
external.h
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::GnashPluginScriptObject::InvokeDefault
bool InvokeDefault(const NPVariant *args, uint32_t argCount, NPVariant *result)
Definition: pluginScriptObject.cpp:526
gnash::GnashPluginScriptObject::getHostFD
int getHostFD()
Definition: pluginScriptObject.cpp:654
gnash::GnashPluginScriptObject::marshalGetNPClass
static NPClass * marshalGetNPClass()
Definition: pluginScriptObject.cpp:280
gnash::GnashPluginScriptObject::getControlFD
int getControlFD()
Definition: pluginScriptObject.cpp:639
gnash::GnashPluginScriptObject::Enumerate
bool Enumerate(NPIdentifier **identifier, uint32_t *count)
Definition: pluginScriptObject.cpp:462
gnash::LoadMovie
bool LoadMovie(NPObject *npobj, NPIdentifier, const NPVariant *args, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:260
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::GnashPluginScriptObject::marshalInvokeDefault
static bool marshalInvokeDefault(NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
Definition: pluginScriptObject.cpp:338
gnash::GnashPluginScriptObject::SetVariable
bool SetVariable(const std::string &name, const NPVariant &value)
Definition: pluginScriptObject.cpp:563
gnash::GnashPluginScriptObject::nppinstance
NPP nppinstance
Plugin instance object.
Definition: pluginScriptObject.h:143
gnash::Rewind
bool Rewind(NPObject *npobj, NPIdentifier, const NPVariant *, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:439
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::SetVariableCallback
bool SetVariableCallback(NPObject *npobj, NPIdentifier, const NPVariant *args, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:99
gnash::GnashPluginScriptObject::AddMethod
bool AddMethod(NPIdentifier name, NPInvokeFunctionPtr func)
Definition: pluginScriptObject.cpp:543
gnash::GnashPluginScriptObject::marshalConstruct
static bool marshalConstruct(NPObject *npobj, const NPVariant *data, uint32_t count, NPVariant *result)
Definition: pluginScriptObject.cpp:393
gnash::GnashNPVariant::get
const NPVariant & get() const
Obtain a reference to the contained NPVariant.
Definition: GnashNPVariant.h:162
gnash::GnashPluginScriptObject::HasMethod
bool HasMethod(NPIdentifier name)
Definition: pluginScriptObject.cpp:479
gnash::GnashPluginScriptObject::getWriteFD
int getWriteFD()
Definition: pluginScriptObject.h:124
gnash::Pan
bool Pan(NPObject *npobj, NPIdentifier, const NPVariant *args, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:308
callbacks.h
gnash::GnashPluginScriptObject::AddProperty
void AddProperty(const std::string &name, const std::string &str)
Definition: pluginScriptObject.cpp:93
gnash::amf::write
void write(SimpleBuffer &buf, const std::string &str)
Write a string to an AMF buffer.
Definition: AMF.cpp:161
NPN_GetStringIdentifier
NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
Definition: gshell.cpp:222
gnash::GnashPluginScriptObject::marshalInvoke
static bool marshalInvoke(NPObject *npobj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)
Definition: pluginScriptObject.cpp:328
gnash::Zoom
bool Zoom(NPObject *npobj, NPIdentifier, const NPVariant *args, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:566
gnash::GnashPluginScriptObject::RemoveProperty
bool RemoveProperty(NPIdentifier name)
Definition: pluginScriptObject.cpp:449
pluginScriptObject.h
gnash::GnashNPVariant
This class holds ownership of (a copy of) an NPVariant.
Definition: GnashNPVariant.h:116
GnashNPVariant.h
gnash::GnashPluginScriptObject::GetProperty
bool GetProperty(NPIdentifier name, NPVariant *result)
Definition: pluginScriptObject.cpp:420
gnash::GnashPluginScriptObject::marshalDeallocate
static void marshalDeallocate(NPObject *npobj)
Definition: pluginScriptObject.cpp:295
NPN_IntFromIdentifier
int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
Definition: gshell.cpp:215
gnash::printNPVariant
void printNPVariant(const NPVariant *value)
Definition: pluginScriptObject.cpp:65
__PRETTY_FUNCTION__
#define __PRETTY_FUNCTION__
Definition: log.h:444
gnash::plugin::ExternalInterface::convertNPVariant
static std::string convertNPVariant(const NPVariant *npv)
Definition: external.cpp:369
plugin.h
gnash::GnashPluginScriptObject::marshalEnumerate
static bool marshalEnumerate(NPObject *npobj, void ***identifier, uint32_t *count)
Definition: pluginScriptObject.cpp:381
gnash::plugin::ExternalInterface::parseXML
static GnashNPVariant parseXML(GnashPluginScriptObject *scriptobj, const std::string &xml)
Definition: external.cpp:266
gnash::IsPlaying
bool IsPlaying(NPObject *npobj, NPIdentifier, const NPVariant *, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:207
gnash::GnashPluginScriptObject::GetVariable
GnashNPVariant GetVariable(const std::string &name)
Definition: pluginScriptObject.cpp:591
gnash::StopPlay
bool StopPlay(NPObject *npobj, NPIdentifier, const NPVariant *, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:526
gnash::GnashPluginScriptObject::marshalInvalidate
static void marshalInvalidate(NPObject *npobj)
Definition: pluginScriptObject.cpp:302
gnash::GotoFrame
bool GotoFrame(NPObject *npobj, NPIdentifier, const NPVariant *args, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:166
gnash::GnashPluginScriptObject::_npclass
static NPClass _npclass
Definition: pluginScriptObject.h:89
gnashconfig.h
gnash::GnashPluginScriptObject::setControlFD
void setControlFD(int x)
Definition: pluginScriptObject.cpp:632
gnash::Play
bool Play(NPObject *npobj, NPIdentifier, const NPVariant *, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:401
gnash::GnashPluginScriptObject::SetProperty
bool SetProperty(NPIdentifier name, const NPVariant &value)
Definition: pluginScriptObject.cpp:441
gnash::GetVariableCallback
bool GetVariableCallback(NPObject *npobj, NPIdentifier, const NPVariant *args, uint32_t argCount, NPVariant *result)
Definition: callbacks.cpp:132
gnash::CopyVariantValue
void CopyVariantValue(const NPVariant &from, NPVariant &to)
Definition: GnashNPVariant.h:55
gnash::GnashPluginScriptObject::getReadFD
int getReadFD()
Definition: pluginScriptObject.h:123
gnash::GnashPluginScriptObject::writePlayer
int writePlayer(const std::string &data)
Definition: pluginScriptObject.cpp:664
gnash::GnashNPVariant::copy
void copy(NPVariant &dest) const
Copy the contained NPVariant into another NPVariant.
Definition: GnashNPVariant.h:152
gnash::plugin::ExternalInterface::makeString
static std::string makeString(const std::string &str)
Definition: external.cpp:96
gnash::GnashPluginScriptObject::GnashPluginScriptObject
GnashPluginScriptObject()
Definition: pluginScriptObject.cpp:249
gnash::GnashPluginScriptObject::HasProperty
bool HasProperty(NPIdentifier name)
Definition: pluginScriptObject.cpp:405
gnash::GnashPluginScriptObject
Definition: pluginScriptObject.h:58
gnash::GnashPluginScriptObject::marshalAllocate
static NPObject * marshalAllocate(NPP npp, NPClass *aClass)
Definition: pluginScriptObject.cpp:287
gnash::GnashPluginScriptObject::marshalRemoveProperty
static bool marshalRemoveProperty(NPObject *npobj, NPIdentifier name)
Definition: pluginScriptObject.cpp:374
x
std::int32_t x
Definition: BitmapData_as.cpp:434
data
SimpleBuffer data
Definition: LocalConnection_as.cpp:151
gnash::GnashPluginScriptObject::~GnashPluginScriptObject
~GnashPluginScriptObject()
Definition: pluginScriptObject.cpp:273
NPN_IdentifierIsString
bool NPN_IdentifierIsString(NPIdentifier identifier)
Definition: gshell.cpp:507
gnash::GnashPluginScriptObject::Construct
bool Construct(const NPVariant *data, uint32_t argCount, NPVariant *result)
Definition: pluginScriptObject.cpp:470
gnash::plugin::ExternalInterface::makeInvoke
static std::string makeInvoke(const std::string &method, std::vector< std::string > args)
Definition: external.cpp:43