2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FWebCtrl_JsBridgePlugin.cpp
20 * @brief The file contains the implmentation of npapi plugin callbacks.
22 * The file contains the implmentation of npapi plugin callbacks.
28 #define ENABLE_TIZEN_JSBRIDGE_PLUGIN 1
29 #define HAS_SCRIPT_SUPPORT 1
32 #include "FWebCtrl_JsBridgePlugin.h"
34 #ifdef __PLUGIN_DEBUG_PRINT
39 #define LOG_TAG "JsBridgePlugin"
40 #define __PLUGIN_DEBUG_TRACE(format, ARG...) \
42 LOGD(format "[%d]", ## ARG, __LINE__); \
45 #define __PLUGIN_DEBUG_TRACE(format, ARG...);
49 _CreateScriptPlayer(NPP instance, NPClass* pNPClass)
52 // set up our our instance data
53 requestToNativeScriptPlayer = g_pBrowserFuncs->getstringidentifier("requestToNative");
54 RuntimeObject* pObject = (RuntimeObject*) g_pBrowserFuncs->memalloc(sizeof(RuntimeObject));
57 pObject->instance = instance;
58 instance->pdata = pObject;
61 return (NPObject*) pObject;
65 _DestroyScriptPlayer(NPObject* pNPobj)
67 RuntimeObject* pObj = (RuntimeObject*) pNPobj;
70 pObj->instance->pdata = NULL;
71 g_pBrowserFuncs->memfree(pObj);
76 _HasMethod(NPObject* pNPobj, NPIdentifier name)
78 return name == requestToNativeScriptPlayer;
82 _Invoke(NPObject* pNPobj, NPIdentifier name, const NPVariant* pArgs, uint32_t argCount, NPVariant* result)
84 if (pArgs->type == NPVariantType_String)
86 char* pString = (char*) g_pBrowserFuncs->memalloc(pArgs->value.stringValue.UTF8Length + 1);
90 memset(pString, 0x00, pArgs->value.stringValue.UTF8Length + 1);
91 memcpy(pString, pArgs->value.stringValue.UTF8Characters, pArgs->value.stringValue.UTF8Length);
93 RuntimeObject* pObj = (RuntimeObject*) pNPobj;
94 g_pBrowserFuncs->setvalue(pObj->instance, NPPAppNotify, pString);
95 g_pBrowserFuncs->memfree(pString);
104 GetJavaClassOfPlugin(void)
106 jref clazz = NULL; //NPP_GetJavaClass();
109 JRIEnv* pEnv = g_pBrowserFuncs->getJavaEnv();
110 return JRI_NewGlobalRef(pEnv, clazz);
116 struct NPClass classScriptPlayer = {
117 NP_CLASS_STRUCT_VERSION, /* uint32_t structVersion; */
118 _CreateScriptPlayer, /* NPAllocateFunctionPtr allocate; */
119 _DestroyScriptPlayer, /* NPDeallocateFunctionPtr deallocate; */
120 NULL, /* NPInvalidateFunctionPtr invalidate; */
121 _HasMethod, /* NPHasMethodFunctionPtr hasMethod; */
122 _Invoke, /* NPInvokeFunctionPtr invoke; */
123 NULL, /* NPInvokeDefaultFunctionPtr invokeDefault; */
124 NULL, /* NPHasPropertyFunctionPtr hasProperty; */
125 NULL, /* NPGetPropertyFunctionPtr getProperty; */
126 NULL, /* NPSetPropertyFunctionPtr setProperty; */
127 NULL, /* NPRemovePropertyFunctionPtr removeProperty; */
131 NP_Initialize(NPNetscapeFuncs* pNsTable, NPPluginFuncs* pFuncs)
134 __PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
135 NPError err = NPERR_INVALID_PARAM;
137 if (pNsTable != NULL && pFuncs != NULL)
139 g_pBrowserFuncs = pNsTable;
142 // Set up the plugin function table that Netscape will use to
143 // call us. Netscape needs to know about our version and size
144 // and have a UniversalProcPointer for every function we
147 pFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
148 pFuncs->size = sizeof(NPPluginFuncs);
149 pFuncs->newp = Plugin_New;
150 pFuncs->destroy = Plugin_Destroy;
151 pFuncs->setwindow = Plugin_SetWindow;
152 pFuncs->newstream = Plugin_NewStream;
153 pFuncs->destroystream = Plugin_DestroyStream;
154 pFuncs->asfile = Plugin_StreamAsFile;
155 pFuncs->writeready = Plugin_WriteReady;
156 pFuncs->write = Plugin_Write;
157 pFuncs->print = Plugin_Print;
158 pFuncs->event = Plugin_HandleEvent;
159 pFuncs->urlnotify = Plugin_URLNotify;
162 pFuncs->javaClass = GetJavaClassOfPlugin();
164 pFuncs->getvalue = Plugin_GetValue;
165 pFuncs->setvalue = Plugin_SetValue;
166 err = NPERR_NO_ERROR;
172 NP_GetMIMEDescription()
174 __PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
175 return (char*) "application/x-tizen-jsbridge:jsb:TizenJsBridgePlugin";
179 NP_GetValue(void* pFuture, NPPVariable variable, void* pValue)
181 __PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
182 return Plugin_GetValue(static_cast< NPP_t* >(pFuture), variable, pValue);
188 __PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
189 return NPERR_NO_ERROR;
193 Plugin_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
195 __PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
196 if (instance != NULL)
198 instance->pdata = NULL;
200 g_pBrowserFuncs->setvalue(instance, NPPVpluginWindowBool, (void*)false);
201 return NPERR_NO_ERROR;
205 Plugin_Destroy(NPP instance, NPSavedData** save)
207 __PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
208 NPObject* pObj = (NPObject*) instance->pdata;
212 g_pBrowserFuncs->releaseobject(pObj);
214 return NPERR_NO_ERROR;
218 Plugin_SetWindow(NPP instance, NPWindow* window)
220 __PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
221 return NPERR_NO_ERROR;
225 Plugin_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype)
227 return NPERR_NO_ERROR;
231 Plugin_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
233 return NPERR_NO_ERROR;
237 Plugin_WriteReady(NPP instance, NPStream* stream)
243 Plugin_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer)
249 Plugin_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
255 Plugin_Print(NPP instance, NPPrint* platformPrint)
261 Plugin_HandleEvent(NPP instance, void* event)
267 Plugin_URLNotify(NPP instance, const char* URL, NPReason reason, void* notifyData)
273 Plugin_GetValue(NPP instance, NPPVariable variable, void* pValue)
275 __PLUGIN_DEBUG_TRACE("%s", __FUNCTION__);
277 NPObject* pNPObject = NULL;
278 NPError retErr = NPERR_INVALID_PARAM;
282 retErr = NPERR_NO_ERROR;
285 case NPPVpluginNeedsXEmbed:
287 *((bool*) pValue) = true;
291 case NPPVpluginNameString:
293 static char name[] = "x-tizen-jsbridge";
294 *((char**) pValue) = name;
298 case NPPVpluginDescriptionString:
300 static char desc[] = "The Plugin for x-tizen-jsbridge";
301 *((char**) pValue) = desc;
305 case NPPVpluginScriptableNPObject:
307 pNPObject = g_pBrowserFuncs->createobject(instance, &classScriptPlayer);
308 g_pBrowserFuncs->retainobject(pNPObject);
309 *((NPObject**) pValue) = pNPObject;
315 retErr = NPERR_INVALID_PARAM;
324 Plugin_SetValue(NPP instance, NPNVariable variable, void* value)
326 return NPERR_NO_ERROR;