Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/browser-plugin/scriptable.h
blob: 1c0203db13d7b2ed2bf7d5305ea5119eca2ac70e (plain)
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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/* this file is part of evince, a gnome document viewer
 *
 *  Copyright (C) 2009 litl, LLC
 *
 * Evince is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Evince 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __SCRIPTABLE_PLUGIN_H__
#define __SCRIPTABLE_PLUGIN_H__

#include <npapi.h>
#include <npupp.h>

NPObject *AllocateScriptablePluginObject (NPP npp, NPClass *aClass);
NPObject *AllocateConstructablePluginObject (NPP npp, NPClass *aClass);

class ScriptablePluginObjectBase : public NPObject
{
	public:
		ScriptablePluginObjectBase (NPP npp) : mNpp(npp)
		{
		}

		virtual ~ScriptablePluginObjectBase ()
		{
		}

		virtual void Invalidate ();
		virtual bool HasMethod (NPIdentifier name);
		virtual bool Invoke (NPIdentifier name, const NPVariant *args,
				     uint32_t argCount, NPVariant *result);
		virtual bool InvokeDefault (const NPVariant *args, uint32_t argCount,
					    NPVariant *result);
		virtual bool HasProperty (NPIdentifier name);
		virtual bool GetProperty (NPIdentifier name, NPVariant *result);
		virtual bool SetProperty (NPIdentifier name, const NPVariant *value);
		virtual bool RemoveProperty (NPIdentifier name);
		virtual bool Enumerate (NPIdentifier **identifier, uint32_t *count);
		virtual bool Construct (const NPVariant *args, uint32_t argCount,
					NPVariant *result);

		static void _Deallocate (NPObject *npobj);
		static void _Invalidate (NPObject *npobj);
		static bool _HasMethod (NPObject *npobj, NPIdentifier name);
		static bool _Invoke (NPObject *npobj, NPIdentifier name,
				     const NPVariant *args, uint32_t argCount,
				     NPVariant *result);
		static bool _InvokeDefault (NPObject *npobj, const NPVariant *args,
					    uint32_t argCount, NPVariant *result);
		static bool _HasProperty (NPObject * npobj, NPIdentifier name);
		static bool _GetProperty (NPObject *npobj, NPIdentifier name,
					  NPVariant *result);
		static bool _SetProperty (NPObject *npobj, NPIdentifier name,
					  const NPVariant *value);
		static bool _RemoveProperty (NPObject *npobj, NPIdentifier name);
		static bool _Enumerate (NPObject *npobj, NPIdentifier **identifier,
					uint32_t *count);
		static bool _Construct (NPObject *npobj, const NPVariant *args,
					uint32_t argCount, NPVariant *result);

	protected:
		NPP mNpp;
};

class ScriptablePluginObject : public ScriptablePluginObjectBase
{
	public:
		ScriptablePluginObject (NPP npp);
  
		virtual bool HasMethod (NPIdentifier name);
		virtual bool HasProperty (NPIdentifier name);
		virtual bool GetProperty (NPIdentifier name, NPVariant *result);
		virtual bool Invoke (NPIdentifier name, const NPVariant *args,
				     uint32_t argCount, NPVariant *result);
		virtual bool InvokeDefault (const NPVariant *args, uint32_t argCount,
					    NPVariant *result);

	private:
		NPIdentifier mZoomInID;
		NPIdentifier mZoomOutID;
		NPIdentifier mFindPreviousID;
		NPIdentifier mFindNextID;
};

class ConstructablePluginObject : public ScriptablePluginObjectBase
{
	public:
		ConstructablePluginObject (NPP npp) : ScriptablePluginObjectBase (npp)
		{
		}

		virtual bool Construct (const NPVariant *args, uint32_t argCount,
					NPVariant *result);
};

#define DECLARE_NPOBJECT_CLASS_WITH_BASE(_class, ctor)	\
static NPClass s##_class##_NPClass = {			\
	NP_CLASS_STRUCT_VERSION_CTOR,			\
	ctor,						\
	ScriptablePluginObjectBase::_Deallocate,	\
	ScriptablePluginObjectBase::_Invalidate,	\
	ScriptablePluginObjectBase::_HasMethod,		\
	ScriptablePluginObjectBase::_Invoke,		\
	ScriptablePluginObjectBase::_InvokeDefault,	\
	ScriptablePluginObjectBase::_HasProperty,	\
	ScriptablePluginObjectBase::_GetProperty,	\
	ScriptablePluginObjectBase::_SetProperty,	\
	ScriptablePluginObjectBase::_RemoveProperty,	\
	ScriptablePluginObjectBase::_Enumerate,		\
	ScriptablePluginObjectBase::_Construct		\
}

#define GET_NPOBJECT_CLASS(_class) &s##_class##_NPClass

DECLARE_NPOBJECT_CLASS_WITH_BASE (ScriptablePluginObject,
				  AllocateScriptablePluginObject);

DECLARE_NPOBJECT_CLASS_WITH_BASE (ConstructablePluginObject,
				  AllocateConstructablePluginObject);

#endif // __SCRIPTABLE_PLUGIN_H__