1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
/*
* Copyright © 2008 Christian Persch
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __TOTEM_NPOBJECT_H__
#define __TOTEM_NPOBJECT_H__
#include <assert.h>
#include "npapi.h"
#include "npruntime.h"
class totemPlugin;
class totemNPObject;
class totemNPClass_base;
template<class T> class totemNPClass;
class totemNPObject : public NPObject {
public:
totemNPObject (NPP);
virtual ~totemNPObject ();
void* operator new (size_t aSize) throw ();
protected:
friend class totemNPClass_base;
/* NPObject methods */
virtual void Invalidate ();
virtual bool HasMethod (NPIdentifier aName);
virtual bool Invoke (NPIdentifier aName, const NPVariant *argv, uint32_t argc, NPVariant *_result);
virtual bool InvokeDefault (const NPVariant *argv, uint32_t argc, NPVariant *_result);
virtual bool HasProperty (NPIdentifier aName);
virtual bool GetProperty (NPIdentifier aName, NPVariant *_result);
virtual bool SetProperty (NPIdentifier aName, const NPVariant *aValue);
virtual bool RemoveProperty (NPIdentifier aName);
virtual bool Enumerate (NPIdentifier **_result, uint32_t *_count);
virtual bool Construct (const NPVariant *argv, uint32_t argc, NPVariant *_result);
/* By Index methods */
virtual bool InvokeByIndex (int aIndex, const NPVariant *argv, uint32_t argc, NPVariant *_result);
virtual bool GetPropertyByIndex (int aIndex, NPVariant *_result);
virtual bool SetPropertyByIndex (int aIndex, const NPVariant *aValue);
virtual bool RemovePropertyByIndex (int aIndex);
private:
NPP mNPP;
totemPlugin *mPlugin;
protected:
bool IsValid () const { return mPlugin != 0; }
totemPlugin* Plugin () const { assert (IsValid ()); return mPlugin; }
bool Throw (const char*);
bool ThrowPropertyNotWritable ();
bool ThrowSecurityError ();
bool CheckArgc (uint32_t, uint32_t, uint32_t = uint32_t(-1), bool = true);
bool CheckArgType (NPVariantType, NPVariantType, uint32_t = 0);
bool CheckArg (const NPVariant*, uint32_t, uint32_t, NPVariantType);
bool CheckArgv (const NPVariant*, uint32_t, uint32_t, ...);
bool GetBoolFromArguments (const NPVariant*, uint32_t, uint32_t, bool&);
bool GetInt32FromArguments (const NPVariant*, uint32_t, uint32_t, int32_t&);
bool GetDoubleFromArguments (const NPVariant*, uint32_t, uint32_t, double&);
bool GetNPStringFromArguments (const NPVariant*, uint32_t, uint32_t, NPString&);
bool DupStringFromArguments (const NPVariant*, uint32_t, uint32_t, char*&);
bool GetObjectFromArguments (const NPVariant*, uint32_t, uint32_t, NPObject*&);
bool VoidVariant (NPVariant*);
bool NullVariant (NPVariant*);
bool BoolVariant (NPVariant*, bool);
bool Int32Variant (NPVariant*, int32_t);
bool DoubleVariant (NPVariant*, double);
bool StringVariant (NPVariant*, const char*, int32_t = -1);
bool ObjectVariant (NPVariant*, NPObject*);
private:
totemNPClass_base* GetClass() const { return static_cast<totemNPClass_base*>(_class); }
};
/* Helper macros */
#define TOTEM_LOG_CTOR() g_debug ("%s [%p]", __func__, (void*) this)
#define TOTEM_LOG_DTOR() g_debug ("%s [%p]", __func__, (void*) this)
#define TOTEM_LOG_INVOKE(i, T) \
{\
static bool logAccess[G_N_ELEMENTS (methodNames)];\
if (!logAccess[i]) {\
g_debug ("NOTE: site calls function %s::%s", #T, methodNames[i]);\
logAccess[i] = true;\
}\
}
#define TOTEM_LOG_GETTER(i, T) \
{\
static bool logAccess[G_N_ELEMENTS (propertyNames)];\
if (!logAccess[i]) {\
g_debug ("NOTE: site gets property %s::%s", #T, propertyNames[i]);\
logAccess[i] = true;\
}\
}
#define TOTEM_LOG_SETTER(i, T) \
{\
static bool logAccess[G_N_ELEMENTS (propertyNames)];\
if (!logAccess[i]) {\
g_debug ("NOTE: site sets property %s::%s", #T, propertyNames[i]);\
logAccess[i] = true;\
}\
}
#define TOTEM_WARN_INVOKE_UNIMPLEMENTED(i, T) \
{\
static bool logWarning[G_N_ELEMENTS (methodNames)];\
if (!logWarning[i]) {\
g_warning ("WARNING: function %s::%s is unimplemented", #T, methodNames[i]);\
logWarning[i] = true;\
}\
}
#define TOTEM_WARN_1_INVOKE_UNIMPLEMENTED(i, T) \
{\
static bool logWarning;\
if (!logWarning) {\
g_warning ("WARNING: function %s::%s is unimplemented", #T, methodNames[i]);\
logWarning = true;\
}\
}
#define TOTEM_WARN_GETTER_UNIMPLEMENTED(i, T) \
{\
static bool logWarning[G_N_ELEMENTS (propertyNames)];\
if (!logWarning[i]) {\
g_warning ("WARNING: getter for property %s::%s is unimplemented", #T, propertyNames[i]);\
logWarning[i] = true;\
}\
}
#define TOTEM_WARN_1_GETTER_UNIMPLEMENTED(i, T) \
{\
static bool logWarning;\
if (!logWarning) {\
g_warning ("WARNING: getter for property %s::%s is unimplemented", #T, propertyNames[i]);\
logWarning = true;\
}\
}
#define TOTEM_WARN_SETTER_UNIMPLEMENTED(i, T) \
{\
static bool logWarning[G_N_ELEMENTS (propertyNames)];\
if (!logWarning[i]) {\
g_warning ("WARNING: setter for property %s::%s is unimplemented", #T, propertyNames[i]);\
logWarning[i] = true;\
}\
}
#define TOTEM_WARN_1_SETTER_UNIMPLEMENTED(i, T) \
{\
static bool logWarning;\
if (!logWarning) {\
g_warning ("WARNING: setter for property %s::%s is unimplemented", #T, propertyNames[i]);\
logWarning = true;\
}\
}
#endif /* __TOTEM_NPOBJECT_H__ */
|