diff options
Diffstat (limited to 'src/controls/js-bridge-plugin-deprecated/FWebCtrl_JsBridgePlugin.cpp')
-rwxr-xr-x | src/controls/js-bridge-plugin-deprecated/FWebCtrl_JsBridgePlugin.cpp | 327 |
1 files changed, 327 insertions, 0 deletions
diff --git a/src/controls/js-bridge-plugin-deprecated/FWebCtrl_JsBridgePlugin.cpp b/src/controls/js-bridge-plugin-deprecated/FWebCtrl_JsBridgePlugin.cpp new file mode 100755 index 0000000..c564715 --- /dev/null +++ b/src/controls/js-bridge-plugin-deprecated/FWebCtrl_JsBridgePlugin.cpp @@ -0,0 +1,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; +} |