summaryrefslogtreecommitdiff
path: root/src/controls/js-bridge-plugin-deprecated/FWebCtrl_JsBridgePlugin.cpp
blob: c56471595fd56af68e730aa0809d37393c0f23b0 (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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
//
// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

/**
 * @file		FWebCtrl_JsBridgePlugin.cpp
 * @brief		The file contains the implmentation of npapi plugin callbacks.
 *
 * The file contains the implmentation of npapi plugin callbacks.
 */

#define XP_TIZEN 1
#define XP_UNIX 1
#define MOZ_X11 1
#define ENABLE_TIZEN_JSBRIDGE_PLUGIN 1
#define HAS_SCRIPT_SUPPORT 1

#include <string.h>
#include "FWebCtrl_JsBridgePlugin.h"

#ifdef __PLUGIN_DEBUG_PRINT
#include <dlog.h>
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "JsBridgePlugin"
#define __PLUGIN_DEBUG_TRACE(format, ARG...)  \
	{ \
		LOGD(format "[%d]", ## ARG, __LINE__); \
	}
#else
#define __PLUGIN_DEBUG_TRACE(format, ARG...);
#endif

static NPObject*
_CreateScriptPlayer(NPP instance, NPClass* pNPClass)
{

	// set up our our instance data
	requestToNativeScriptPlayer = g_pBrowserFuncs->getstringidentifier("requestToNative");
	RuntimeObject* pObject = (RuntimeObject*) g_pBrowserFuncs->memalloc(sizeof(RuntimeObject));
	if (pObject != NULL)
	{
		pObject->instance = instance;
		instance->pdata = pObject;
	}

	return (NPObject*) pObject;
}

static void
_DestroyScriptPlayer(NPObject* pNPobj)
{
	RuntimeObject* pObj = (RuntimeObject*) pNPobj;
	if (pObj)
	{
		pObj->instance->pdata = NULL;
		g_pBrowserFuncs->memfree(pObj);
	}
}

static bool
_HasMethod(NPObject* pNPobj, NPIdentifier name)
{
	return name == requestToNativeScriptPlayer;
}

static bool
_Invoke(NPObject* pNPobj, NPIdentifier name, const NPVariant* pArgs, uint32_t argCount, NPVariant* result)
{
	if (pArgs->type == NPVariantType_String)
	{
		char* pString = (char*) g_pBrowserFuncs->memalloc(pArgs->value.stringValue.UTF8Length + 1);

		if (pString != NULL)
		{
			memset(pString, 0x00, pArgs->value.stringValue.UTF8Length + 1);
			memcpy(pString, pArgs->value.stringValue.UTF8Characters, pArgs->value.stringValue.UTF8Length);

			RuntimeObject* pObj = (RuntimeObject*) pNPobj;
			g_pBrowserFuncs->setvalue(pObj->instance, NPPAppNotify, pString);
			g_pBrowserFuncs->memfree(pString);
		}
	}

	return true;
}

#ifdef OJI
JRIGlobalRef
GetJavaClassOfPlugin(void)
{
	jref clazz = NULL; //NPP_GetJavaClass();
	if (clazz)
	{
		JRIEnv* pEnv = g_pBrowserFuncs->getJavaEnv();
		return JRI_NewGlobalRef(pEnv, clazz);
	}
	return NULL;
}
#endif

struct NPClass classScriptPlayer = {
	NP_CLASS_STRUCT_VERSION,   /* uint32_t structVersion; */
	_CreateScriptPlayer,       /* NPAllocateFunctionPtr allocate; */
	_DestroyScriptPlayer,      /* NPDeallocateFunctionPtr deallocate; */
	NULL,                      /* NPInvalidateFunctionPtr invalidate; */
	_HasMethod,                /* NPHasMethodFunctionPtr hasMethod; */
	_Invoke,                   /* NPInvokeFunctionPtr invoke; */
	NULL,                      /* NPInvokeDefaultFunctionPtr invokeDefault; */
	NULL,                      /* NPHasPropertyFunctionPtr hasProperty; */
	NULL,                      /* NPGetPropertyFunctionPtr getProperty; */
	NULL,                      /* NPSetPropertyFunctionPtr setProperty; */
	NULL,                      /* NPRemovePropertyFunctionPtr removeProperty; */
};

NPError
NP_Initialize(NPNetscapeFuncs* pNsTable, NPPluginFuncs* pFuncs)
{

	__PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
	NPError err = NPERR_INVALID_PARAM;

	if (pNsTable != NULL && pFuncs != NULL)
	{
		g_pBrowserFuncs = pNsTable;

		//
		// Set up the plugin function table that Netscape will use to
		// call us.  Netscape needs to know about our version and size
		// and have a UniversalProcPointer for every function we
		// implement.
		//
		pFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
		pFuncs->size = sizeof(NPPluginFuncs);
		pFuncs->newp = Plugin_New;
		pFuncs->destroy = Plugin_Destroy;
		pFuncs->setwindow = Plugin_SetWindow;
		pFuncs->newstream = Plugin_NewStream;
		pFuncs->destroystream = Plugin_DestroyStream;
		pFuncs->asfile = Plugin_StreamAsFile;
		pFuncs->writeready = Plugin_WriteReady;
		pFuncs->write = Plugin_Write;
		pFuncs->print = Plugin_Print;
		pFuncs->event = Plugin_HandleEvent;
		pFuncs->urlnotify = Plugin_URLNotify;

#ifdef OJI
		pFuncs->javaClass = GetJavaClassOfPlugin();
#endif
		pFuncs->getvalue = Plugin_GetValue;
		pFuncs->setvalue = Plugin_SetValue;
		err = NPERR_NO_ERROR;
	}
	return err;
}

char*
NP_GetMIMEDescription()
{
	__PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
	return (char*) "application/x-osp-jsbridge:jsb:SamsungJsBridgePlugin";
}

NPError
NP_GetValue(void* pFuture, NPPVariable variable, void* pValue)
{
	__PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
	return Plugin_GetValue(static_cast< NPP_t* >(pFuture), variable, pValue);
}

NPError
NP_Shutdown(void)
{
	__PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
	return NPERR_NO_ERROR;
}

NPError
Plugin_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
{
	__PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
	if (instance != NULL)
	{
		instance->pdata = NULL;
	}
	g_pBrowserFuncs->setvalue(instance, NPPVpluginWindowBool, (void*)false);
	return NPERR_NO_ERROR;
}

NPError
Plugin_Destroy(NPP instance, NPSavedData** save)
{
	__PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
	NPObject* pObj = (NPObject*) instance->pdata;

	if (pObj)
	{
		g_pBrowserFuncs->releaseobject(pObj);
	}
	return NPERR_NO_ERROR;
}

NPError
Plugin_SetWindow(NPP instance, NPWindow* window)
{
	__PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
	return NPERR_NO_ERROR;
}

NPError
Plugin_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype)
{
	return NPERR_NO_ERROR;
}

NPError
Plugin_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
{
	return NPERR_NO_ERROR;
}

int32_t
Plugin_WriteReady(NPP instance, NPStream* stream)
{
	return 0;
}

int32_t
Plugin_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer)
{
	return 0;
}

void
Plugin_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
{

}

void
Plugin_Print(NPP instance, NPPrint* platformPrint)
{

}

int16_t
Plugin_HandleEvent(NPP instance, void* event)
{
	return 1;
}

void
Plugin_URLNotify(NPP instance, const char* URL, NPReason reason, void* notifyData)
{

}

NPError
Plugin_GetValue(NPP instance, NPPVariable variable, void* pValue)
{
	__PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);

	NPObject* pNPObject = NULL;
	NPError retErr = NPERR_INVALID_PARAM;

	if (pValue != NULL)
	{
		retErr = NPERR_NO_ERROR;
		switch (variable)
		{
		case NPPVpluginNeedsXEmbed:
		{
			*((bool*) pValue) = true;
			break;
		}

		case NPPVpluginNameString:
		{
			static char name[] = "x-osp-jsbridge";
			*((char**) pValue) = name;
			break;
		}

		case NPPVpluginDescriptionString:
		{
			static char desc[] = "The Plugin for x-osp-jsbridge";
			*((char**) pValue) = desc;
			break;
		}

		case NPPVpluginScriptableNPObject:
		{
			pNPObject = g_pBrowserFuncs->createobject(instance, &classScriptPlayer);
			g_pBrowserFuncs->retainobject(pNPObject);
			*((NPObject**) pValue) = pNPObject;
			break;
		}

		default:
		{
			retErr = NPERR_INVALID_PARAM;
			break;
		}
		}
	}
	return retErr;
}

NPError
Plugin_SetValue(NPP instance, NPNVariable variable, void* value)
{
	return NPERR_NO_ERROR;
}