void ShockerScriptableControlObject::CaptureMultipleImages (const NPVariant *args, uint32_t arg_count, NPVariant *result) { const char *path; g_assert (arg_count == 9); g_assert (NPVARIANT_IS_STRING (args [0])); g_assert (NPVARIANT_IS_STRING (args [1])); g_assert (NPVARIANT_IS_NUMBER (args [2])); g_assert (NPVARIANT_IS_NUMBER (args [3])); g_assert (NPVARIANT_IS_NUMBER (args [4])); g_assert (NPVARIANT_IS_NUMBER (args [5])); g_assert (NPVARIANT_IS_NUMBER (args [6])); g_assert (NPVARIANT_IS_NUMBER (args [7])); g_assert (NPVARIANT_IS_NUMBER (args [8])); path = STR_FROM_VARIANT (args [1]); if (path == NULL || path [0] == 0) path = GetTestPath (); LOG_PLUGIN ("[%i shocker] ShockerScriptableControlObject::CaptureMultipleImages (base_dir: '%s', file_name: '%s', x: %i, y: %i, width: %i, height: %i, count: %i, interval: %i, initial_delay: %i)\n", getpid (), STR_FROM_VARIANT (args [0]), STR_FROM_VARIANT (args [1]), NUMBER_TO_INT32 (args [2]), NUMBER_TO_INT32 (args [3]), NUMBER_TO_INT32 (args [4]), NUMBER_TO_INT32 (args [5]),NUMBER_TO_INT32 (args [6]), NUMBER_TO_INT32 (args [7]), NUMBER_TO_INT32 (args [8])); GetImageCaptureProvider ()->CaptureMultipleImages (path, NUMBER_TO_INT32 (args [2]), NUMBER_TO_INT32 (args [3]), NUMBER_TO_INT32 (args [4]), NUMBER_TO_INT32 (args [5]),NUMBER_TO_INT32 (args [6]), NUMBER_TO_INT32 (args [7]), NUMBER_TO_INT32 (args [8])); BOOLEAN_TO_NPVARIANT (true, *result); }
static bool testPostURLFile(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (argCount != 4 || !NPVARIANT_IS_STRING(args[0]) || !NPVARIANT_IS_STRING(args[1]) || !NPVARIANT_IS_STRING(args[2]) || !NPVARIANT_IS_STRING(args[3])) return false; NPString urlString = NPVARIANT_TO_STRING(args[0]); char* url = toCString(urlString); NPString targetString = NPVARIANT_TO_STRING(args[1]); char* target = toCString(targetString); NPString pathString = NPVARIANT_TO_STRING(args[2]); char* path = toCString(pathString); NPString contentsString = NPVARIANT_TO_STRING(args[3]); FILE* tempFile = fopen(path, "w"); if (!tempFile) return false; if (!fwrite(contentsString.UTF8Characters, contentsString.UTF8Length, 1, tempFile)) return false; fclose(tempFile); NPError error = browser->posturl(obj->npp, url, target, pathString.UTF8Length, path, TRUE); free(path); free(target); free(url); BOOLEAN_TO_NPVARIANT(error == NPERR_NO_ERROR, *result); return true; }
bool JsAgent::onLoad(const NPVariant* args, unsigned argCount) { Debug::println("JsAgent::onLoad"); if(argCount != 4) { Debug::println("JsAgent::onLoad> argCount != 4"); return false; } if( !NPVARIANT_IS_OBJECT(args[0]) || !NPVARIANT_IS_STRING(args[1]) || !NPVARIANT_IS_INT32(args[2]) || !NPVARIANT_IS_STRING(args[3]) ) { Debug::println("JsAgent::onLoad> arg types wrong"); return false; } NPObject* pObject = NPVARIANT_TO_OBJECT(args[0]); m_helper = NPN_RetainObject(pObject); NPObject* pDebug = NPN_CreateObject(getNPP(), GetNPClass<JsDebug>()); NPN_RetainObject(pDebug); Variant var; var.set(pDebug); if(!NPN_SetProperty(getNPP(), m_window, methods.debug, var.ptr())) { Debug::println("JsAgent::onLoad> set property failed"); return false; } NPString npstr = NPVARIANT_TO_STRING(args[1]); std::string host(npstr.UTF8Characters, npstr.UTF8Length); int port = NPVARIANT_TO_INT32(args[2]); npstr = NPVARIANT_TO_STRING(args[3]); std::string typeName(npstr.UTF8Characters, npstr.UTF8Length); if(!m_channel->connect(host.c_str(), port)) { Debug::println("JsAgent::onLoad> could not connect"); return false; } LoadMessage msg; msg.typeName = typeName; ArchiveWriter<Channel> ar(*m_channel); if(!Message::send(msg, ar)) { Debug::println("JsAgent::onLoad> send failed"); return false; } JsValue ret; return dispatchAndReturn(ret); }
// Invoke a script callback to get a script NPObject. Then call a method on the // script NPObject passing it a freshly created NPObject. static bool testScriptObjectInvoke(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (argCount != 2 || !NPVARIANT_IS_STRING(args[0]) || !NPVARIANT_IS_STRING(args[1])) return false; NPObject* windowScriptObject; browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject); // Arg1 is the name of the callback NPUTF8* callbackString = createCStringFromNPVariant(&args[0]); NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString); free(callbackString); // Invoke a callback that returns a script object NPVariant object_result; browser->invoke(obj->npp, windowScriptObject, callbackIdentifier, &args[1], 1, &object_result); // Script object returned NPObject* script_object = object_result.value.objectValue; // Arg2 is the name of the method to be called on the script object NPUTF8* object_mehod_string = createCStringFromNPVariant(&args[1]); NPIdentifier object_method = browser->getstringidentifier(object_mehod_string); free(object_mehod_string); // Create a fresh NPObject to be passed as an argument NPObject* object_arg = browser->createobject(obj->npp, &pluginClass); NPVariant invoke_args[1]; OBJECT_TO_NPVARIANT(object_arg, invoke_args[0]); // Invoke the script method NPVariant object_method_result; browser->invoke(obj->npp, script_object, object_method, invoke_args, 1, &object_method_result); browser->releasevariantvalue(&object_result); VOID_TO_NPVARIANT(*result); if (NPVARIANT_IS_OBJECT(object_method_result)) { // Now return the callbacks return value back to our caller. // BUG 897451: This should be the same as the // windowScriptObject, but its not (in Chrome) - or at least, it // has a different refcount. This means Chrome will delete the // object before returning it and the calling JS gets a garbage // value. Firefox handles it fine. OBJECT_TO_NPVARIANT(NPVARIANT_TO_OBJECT(object_method_result), *result); } else { browser->releasevariantvalue(&object_method_result); VOID_TO_NPVARIANT(*result); } browser->releaseobject(object_arg); return true; }
CString CPlugin::GetNavigateParam(const NPUTF8* name) const { CString strParam; NPVariant vParam; VOID_TO_NPVARIANT(vParam); try { NPObject* pContainer = GetContainer(); if (!NPN_Invoke(m_pNPInstance, pContainer, GetIdentifier(name), NULL, 0, &vParam)) { throw(CString(_T("Cannot invoke window.Container.getXXX()"))); } if (!NPVARIANT_IS_STRING(vParam)) { throw(CString(_T("Invalid return value."))); } strParam = NPStringToCString(vParam.value.stringValue); } catch (const CString& strMessage) { UNUSED(strMessage); TRACE(_T("[CPlugin::GetNavigateHeaders Exception] %s\n"), strMessage); } if (!NPVARIANT_IS_VOID(vParam)) NPN_ReleaseVariantValue(&vParam); return strParam; }
bool nsScriptableObjectOverwolfSample::Echo( NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { if (argCount < 2 || !NPVARIANT_IS_STRING(args[0]) || !NPVARIANT_IS_OBJECT(args[1])) { NPN_SetException(this, "invalid params passed to function"); return true; } // add ref count to callback object so it won't delete NPN_RetainObject(NPVARIANT_TO_OBJECT(args[1])); // convert into std::string std::string message; message.append( NPVARIANT_TO_STRING(args[0]).UTF8Characters, NPVARIANT_TO_STRING(args[0]).UTF8Length); // post to separate thread so that we are responsive return thread_->PostTask( std::bind( &nsScriptableObjectOverwolfSample::EchoTask, this, message, NPVARIANT_TO_OBJECT(args[1]))); }
NPIdentifier stringVariantToIdentifier(NPVariant variant) { assert(NPVARIANT_IS_STRING(variant)); NPUTF8* utf8String = createCStringFromNPVariant(&variant); NPIdentifier identifier = NPN_GetStringIdentifier(utf8String); free(utf8String); return identifier; }
// XXX FIXME See comment at the other parseOptions variant. void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options) { /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */ NPVariant value; /* we are expecting to have a Javascript Array object */ NPIdentifier propId = NPN_GetStringIdentifier("length"); if( NPN_GetProperty(_instance, obj, propId, &value) ) { int count = numberValue(value); NPN_ReleaseVariantValue(&value); if( count ) { long capacity = 16; char **options = (char **)malloc(capacity*sizeof(char *)); if( options ) { int nOptions = 0; while( nOptions < count ) { propId = NPN_GetIntIdentifier(nOptions); if( ! NPN_GetProperty(_instance, obj, propId, &value) ) /* return what we got so far */ break; if( ! NPVARIANT_IS_STRING(value) ) { /* return what we got so far */ NPN_ReleaseVariantValue(&value); break; } if( nOptions == capacity ) { capacity += 16; char **moreOptions = (char **)realloc(options, capacity*sizeof(char*)); if( ! moreOptions ) { /* failed to allocate more memory */ NPN_ReleaseVariantValue(&value); /* return what we got so far */ *i_options = nOptions; *ppsz_options = options; break; } options = moreOptions; } options[nOptions++] = stringValue(value); } *i_options = nOptions; *ppsz_options = options; } } } }
bool pluginSetProperty (NPObject *npobj, NPIdentifier name, const NPVariant *value) { PluginObject *obj = (PluginObject *)npobj; if (name == pluginPropertyIdentifiers[ID_PORT_PROPERTY]) { if(NPVARIANT_IS_STRING(*value)) { if(obj->port.UTF8Length > 0) { free((void *)(obj->port.UTF8Characters)); obj->port.UTF8Length = 0; } NPUTF8 *s = (NPUTF8 *)malloc((value->value.stringValue.UTF8Length)+1); memcpy(s, value->value.stringValue.UTF8Characters, value->value.stringValue.UTF8Length); s[value->value.stringValue.UTF8Length] = '\0'; obj->port.UTF8Characters = s; obj->port.UTF8Length = value->value.stringValue.UTF8Length; // when user sets port, connect to it if(obj->socket >= 0) { mcpClose(obj->socket); obj->socket = -1; } if(obj->port.UTF8Length > 0) { obj->socket = mcpOpen((char *)(obj->port.UTF8Characters)); } return true; } } return false; }
static bool CopyNPVariant(NPVariant *dst, const NPVariant *src) { dst->type = src->type; if (NPVARIANT_IS_STRING(*src)) { NPUTF8 *str = (NPUTF8 *)NPNFuncs.memalloc((src->value.stringValue.UTF8Length + 1) * sizeof(NPUTF8)); if (NULL == str) { return false; } dst->value.stringValue.UTF8Length = src->value.stringValue.UTF8Length; memcpy(str, src->value.stringValue.UTF8Characters, src->value.stringValue.UTF8Length); str[dst->value.stringValue.UTF8Length] = 0; dst->value.stringValue.UTF8Characters = str; } else if (NPVARIANT_IS_OBJECT(*src)) { NPNFuncs.retainobject(NPVARIANT_TO_OBJECT(*src)); dst->value.objectValue = src->value.objectValue; } else { dst->value = src->value; } return true; }
static bool testGetProperty(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (!argCount) return false; NPObject* object; browser->getvalue(obj->npp, NPNVWindowNPObject, &object); for (uint32_t i = 0; i < argCount; i++) { assert(NPVARIANT_IS_STRING(args[i])); NPUTF8* propertyString = createCStringFromNPVariant(&args[i]); NPIdentifier propertyIdentifier = browser->getstringidentifier(propertyString); free(propertyString); NPVariant variant; bool retval = browser->getproperty(obj->npp, object, propertyIdentifier, &variant); browser->releaseobject(object); if (!retval) break; if (i + 1 < argCount) { assert(NPVARIANT_IS_OBJECT(variant)); object = NPVARIANT_TO_OBJECT(variant); } else { *result = variant; return true; } } VOID_TO_NPVARIANT(*result); return false; }
static inline gchar * get_string_property (NPP instance, NPObject *obj, const char *name) { NPVariant result = { NPVariantType_Void }; NPString result_str; gchar *result_copy; result_copy = NULL; if (!funcs.getproperty (instance, obj, funcs.getstringidentifier (name), &result)) goto out; if (!NPVARIANT_IS_STRING (result)) goto out; result_str = NPVARIANT_TO_STRING (result); result_copy = g_strndup (result_str.UTF8Characters, result_str.UTF8Length); out: funcs.releasevariantvalue (&result); return result_copy; }
bool ScriptablePluginObject::SetProperty(NPIdentifier name, const NPVariant *value) { if (!m_plugin) return false; std::string str; std::stringstream ss; bool boolean = false; unsigned short val = -1; if (NPVARIANT_IS_STRING(*value)) { str.assign(NPVARIANT_TO_STRING(*value).UTF8Characters, NPVARIANT_TO_STRING(*value).UTF8Length); } else if (NPVARIANT_IS_BOOLEAN(*value)) { boolean = NPVARIANT_TO_BOOLEAN(*value); } else if (NPVARIANT_IS_INT32(*value)) { val = NPVARIANT_TO_INT32(*value); ss << val; ss >> str; }
static bool testCallbackReturn(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (argCount != 1 || !NPVARIANT_IS_STRING(args[0])) return false; NPObject* windowScriptObject; browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject); NPUTF8* callbackString = createCStringFromNPVariant(&args[0]); NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString); free(callbackString); NPVariant callbackArgs[1]; OBJECT_TO_NPVARIANT(windowScriptObject, callbackArgs[0]); NPVariant browserResult; browser->invoke(obj->npp, windowScriptObject, callbackIdentifier, callbackArgs, 1, &browserResult); if (NPVARIANT_IS_OBJECT(browserResult)) OBJECT_TO_NPVARIANT(NPVARIANT_TO_OBJECT(browserResult), *result); else { browser->releasevariantvalue(&browserResult); VOID_TO_NPVARIANT(*result); } return true; }
static bool plugin_object_invoke (NPObject *npobj, NPIdentifier name, const NPVariant *args, uint32_t argc, NPVariant *result) { PluginObject *obj; g_return_val_if_fail (plugin_object_has_method (npobj, name), FALSE); g_debug ("invoking plugin object method"); obj = (PluginObject*) npobj; VOID_TO_NPVARIANT (*result); if (name == list_extensions_id) return plugin_list_extensions (obj, result); else if (name == get_metadata_id) { g_return_val_if_fail (argc >= 1, FALSE); g_return_val_if_fail (NPVARIANT_IS_STRING(args[0]), FALSE); return plugin_get_metadata (obj, NPVARIANT_TO_STRING(args[0]), result); } else if (name == enable_extension_id) { g_return_val_if_fail (argc >= 2, FALSE); g_return_val_if_fail (NPVARIANT_IS_STRING(args[0]), FALSE); g_return_val_if_fail (NPVARIANT_IS_BOOLEAN(args[1]), FALSE); return plugin_enable_extension (obj, NPVARIANT_TO_STRING(args[0]), NPVARIANT_TO_BOOLEAN(args[1])); } else if (name == install_extension_id) { g_return_val_if_fail (argc >= 1, FALSE); g_return_val_if_fail (NPVARIANT_IS_STRING(args[0]), FALSE); return plugin_install_extension (obj, NPVARIANT_TO_STRING(args[0])); } return TRUE; }
static NPIdentifier stringVariantToIdentifier(NPVariant variant) { assert(NPVARIANT_IS_STRING(variant)); NPUTF8* utf8String = createCStringFromNPVariant(&variant); NPIdentifier identifier = browser->getstringidentifier(utf8String); free(utf8String); return identifier; }
void StatementObject::GetProcedureColumns(const NPVariant *arg0, const NPVariant *arg1, const NPVariant *arg2, const NPVariant *arg3) { NPString *cat = NULL; NPString *sch = NULL; NPString *prc = NULL; NPString *col = NULL; if (NPVARIANT_IS_STRING(*arg0)) cat = (NPString*)&NPVARIANT_TO_STRING(*arg0); if (NPVARIANT_IS_STRING(*arg1)) sch = (NPString*)&NPVARIANT_TO_STRING(*arg1); if (NPVARIANT_IS_STRING(*arg2)) prc = (NPString*)&NPVARIANT_TO_STRING(*arg2); if (NPVARIANT_IS_STRING(*arg3)) col = (NPString*)&NPVARIANT_TO_STRING(*arg3); if (!m_hstmt) { NPN_SetException(this, "Statement isn't initialized"); return; } NPError rc = Close(); if (rc != NPERR_NO_ERROR) return; SQLRETURN code = SQLProcedureColumnsW(m_hstmt, (cat?nsWString(cat).Data():NULL), (cat?SQL_NTS:0), (sch?nsWString(sch).Data():NULL), (sch?SQL_NTS:0), (prc?nsWString(prc).Data():NULL), (prc?SQL_NTS:0), (col?nsWString(col).Data():NULL), (col?SQL_NTS:0)); if (!SQL_SUCCEEDED(code) && code != SQL_NO_DATA) { StoreError(SQL_HANDLE_STMT, m_hstmt); return; } SQLSMALLINT cols; if (SQL_SUCCEEDED(SQLNumResultCols(m_hstmt, &cols))) m_columnCount = cols; SQLLEN rcnt; if (SQL_SUCCEEDED(SQLRowCount(m_hstmt, &rcnt))) m_rowCount = rcnt; }
NPIdentifier variantToIdentifier(NPVariant variant) { if (NPVARIANT_IS_STRING(variant)) return stringVariantToIdentifier(variant); else if (NPVARIANT_IS_INT32(variant)) return int32VariantToIdentifier(variant); else if (NPVARIANT_IS_DOUBLE(variant)) return doubleVariantToIdentifier(variant); return 0; }
bool InvokeJavascript_TwoArgs(NPObject *npobj, const char *methodName, const NPVariant &arg1, const NPVariant &arg2, NPVariant *&result) { bool success = false; if (!strcmp(methodName, "saveTextFile") && NPVARIANT_IS_STRING(arg1) && NPVARIANT_IS_STRING(arg2)) { const char *filename = stringFromNpVariant(arg1); const char *contents = stringFromNpVariant(arg2); success = saveText(filename, contents, arg2.value.stringValue.UTF8Length); delete[] contents; delete[] filename; } else if (!strcmp(methodName, "saveBinaryFile") && NPVARIANT_IS_STRING(arg1) && NPVARIANT_IS_OBJECT(arg2)) { const char *filename = stringFromNpVariant(arg1); size_t length; const char *bytes = byteArrayFromNpVariant(arg2, GetInstance(npobj), length); success = saveBinaryFile(filename, bytes, length); delete[] bytes; delete[] filename; } return success; }
std::string getInterfaceName(NPP npp, NPObject* object) { std::string className; NPVariant result; bool asConstructor = true; // true if object can be a constructor VOID_TO_NPVARIANT(result); NPN_Invoke(npp, object, NPN_GetStringIdentifier("toString"), 0, 0, &result); for (;;) { if (NPVARIANT_IS_STRING(result)) { className = std::string(NPVARIANT_TO_STRING(result).utf8characters, NPVARIANT_TO_STRING(result).utf8length); } NPN_ReleaseVariantValue(&result); if (className.compare(0, 9, "function ") == 0) { // In Chrome, a [Constructor] object is represented as a 'Function'. className = className.substr(9); size_t pos = className.find('('); if (pos != std::string::npos) { className = className.substr(0, pos); break; } return "Function"; } if (className.compare(0, 8, "[object ", 8) == 0 && className[className.length() - 1] == ']') { className = className.substr(8, className.length() - 9); break; } // This object is likely to have a stringifier. Check the constructor name directly. NPVariant constructor; VOID_TO_NPVARIANT(constructor); if (asConstructor && NPN_GetProperty(npp, object, NPN_GetStringIdentifier("constructor"), &constructor)) { if (NPVARIANT_IS_OBJECT(constructor) && NPN_Invoke(npp, NPVARIANT_TO_OBJECT(constructor), NPN_GetStringIdentifier("toString"), 0, 0, &result)) { NPN_ReleaseVariantValue(&constructor); asConstructor = false; continue; } NPN_ReleaseVariantValue(&constructor); } return "Object"; } // In Firefox, the constructor and an instance object cannot be distinguished by toString(). // Check if object has a 'prototype' to see if it is a constructor. if (asConstructor && NPN_HasProperty(npp, object, NPN_GetStringIdentifier("prototype"))) { className += "_Constructor"; } return className; }
char* RuntimeNPObject::stringValue(const NPVariant &v) { char *s = NULL; if( NPVARIANT_IS_STRING(v) ) { return stringValue(NPVARIANT_TO_STRING(v)); } return s; }
bool PluginMethodListenOnFile::ExecuteListenOnFile( const NPVariant *args, uint32_t argCount, NPVariant *result) { std::string filename; bool skip_to_end = false; try { if (argCount < 3 || !NPVARIANT_IS_STRING(args[0]) || !NPVARIANT_IS_BOOLEAN(args[1]) || !NPVARIANT_IS_OBJECT(args[2])) { NPN_SetException( object_, "invalid or missing params passed to function - expecting 3 params: " "filename, skipToEnd, callback(status, data)"); return false; } callback_ = NPVARIANT_TO_OBJECT(args[2]); skip_to_end = NPVARIANT_TO_BOOLEAN(args[1]); // add ref count to callback object so it won't delete NPN_RetainObject(callback_); filename.append( NPVARIANT_TO_STRING(args[0]).UTF8Characters, NPVARIANT_TO_STRING(args[0]).UTF8Length); } catch(...) { } if (nullptr == thread_.get()) { thread_.reset(new utils::Thread); if (!thread_->Start()) { NPN_SetException( __super::object_, "an unexpected error occurred - couldn't start file listening thread"); return false; } } std::wstring wide_filename = utils::Encoders::utf8_decode(filename); if (!file_stream_.Initialize(wide_filename.c_str(), this, skip_to_end)) { NPN_SetException( __super::object_, "an unexpected error occurred - couldn't open the file for read access"); return false; } return thread_->PostTask( std::bind( &PluginMethodListenOnFile::StartListening, this)); }
void ShockerScriptableControlObject::CaptureSingleImage (const NPVariant *args, uint32_t arg_count, NPVariant *result) { g_assert (arg_count == 6); g_assert (NPVARIANT_IS_STRING (args [0])); g_assert (NPVARIANT_IS_STRING (args [1])); g_assert (NPVARIANT_IS_NUMBER (args [2])); g_assert (NPVARIANT_IS_NUMBER (args [3])); g_assert (NPVARIANT_IS_NUMBER (args [4])); g_assert (NPVARIANT_IS_NUMBER (args [5])); LOG_PLUGIN ("[%i shocker] ShockerScriptableControlObject::CaptureSingleImage (image_dir: '%s', file_name: '%s', x: %i, y: %i, width: %i, height: %i)\n", getpid (), STR_FROM_VARIANT (args [0]), STR_FROM_VARIANT (args [1]), NUMBER_TO_INT32 (args [2]), NUMBER_TO_INT32 (args [3]), NUMBER_TO_INT32 (args [4]), NUMBER_TO_INT32 (args [5])); GetImageCaptureProvider ()->CaptureSingleImage (STR_FROM_VARIANT (args [0]), STR_FROM_VARIANT (args [1]), NUMBER_TO_INT32 (args [2]), NUMBER_TO_INT32 (args [3]), NUMBER_TO_INT32 (args [4]), NUMBER_TO_INT32 (args [5])); BOOLEAN_TO_NPVARIANT (true, *result); }
bool InvokeJavascript_OneArg(NPObject *npobj, const char *methodName, const NPVariant &arg, NPVariant *&result) { if (!(NPVARIANT_IS_STRING(arg))) { return false; } bool success = false; const char *argStringValue = stringFromNpVariant(arg); if (!strcmp(methodName, "fileExists")) { //fileExists(filename : string) : bool success = SetReturnValue(fileExists(argStringValue), *result); } else if (!strcmp(methodName, "isDirectory")) { //isDirectory(filename : string) : bool success = SetReturnValue(isDirectory(argStringValue), *result); } else if (!strcmp(methodName, "createDirectory")) { if (!createDirectory(argStringValue)) { //TODO: Throw a particular exception success = false; } else { success = true; } } else if (!strcmp(methodName, "getTextFile")) { //getTextFile(filename : string) : string char *value = NULL; size_t len = 0; if (getFile(argStringValue, value, len, false)) { success = SetReturnValue(value, len, *result); delete[] value; } } else if (!strcmp(methodName, "getBinaryFile")) { //getBinaryFile(filename : string) : array<byte> char *value = NULL; size_t len = 0; if (getFile(argStringValue, value, len, true)) { success = SetArrayReturnValue(value, len, GetInstance(npobj), result); delete[] value; } } else if (!strcmp(methodName, "removeFile")) { //removeFile(filename : string) : void success = removeFile(argStringValue); } else if (!strcmp(methodName, "listFiles")) { //listFiles(filename : string) : array<object> std::vector<FileEntry *> *entries; if (listFiles(argStringValue, entries)) { success = SetArrayReturnValue(*entries, GetInstance(npobj), result); deleteFileEntries(entries); } else { success = false; } } delete[] argStringValue; return success; }
void m_strFromVar(char **dst, NPVariant var) { if (!dst) return; if (!((NPVARIANT_IS_STRING(var)) || (NPVARIANT_IS_VOID(var)))) return; if (*dst) { NPN_MemFree(*dst); *dst = NULL; } if (NPVARIANT_IS_STRING(var)) { NPString src = NPVARIANT_TO_STRING(var); int len = src.UTF8Length; *dst = (char*) NPN_MemAlloc(len+1); memcpy(*dst, src.UTF8Characters, len); (*dst)[len] = '\0'; } else { *dst = NULL; } }
void ShockerScriptableControlObject::LogDebug (const NPVariant *args, uint32_t arg_count, NPVariant *result) { g_assert (arg_count == 1); g_assert (NPVARIANT_IS_STRING (args [0])); LOG_PLUGIN ("[%i shocker] ShockerScriptableControlObject::LogDebug ('%s')\n", getpid (), STR_FROM_VARIANT (args [0])); GetLogProvider ()->LogDebug (STR_FROM_VARIANT (args [0])); BOOLEAN_TO_NPVARIANT (true, *result); }
static bool getURL(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (argCount == 2 && NPVARIANT_IS_STRING(args[0]) && NPVARIANT_IS_STRING(args[1])) { NPUTF8* urlString = createCStringFromNPVariant(&args[0]); NPUTF8* targetString = createCStringFromNPVariant(&args[1]); NPError npErr = browser->geturl(obj->npp, urlString, targetString); free(urlString); free(targetString); INT32_TO_NPVARIANT(npErr, *result); return true; } else if (argCount == 1 && NPVARIANT_IS_STRING(args[0])) { NPUTF8* urlString = createCStringFromNPVariant(&args[0]); NPError npErr = browser->geturl(obj->npp, urlString, 0); free(urlString); INT32_TO_NPVARIANT(npErr, *result); return true; } return false; }
bool PluginMethodListenOnFile::ExecuteStopFileListen( const NPVariant *args, uint32_t argCount, NPVariant *result) { std::string id; try { if (argCount < 1 || !NPVARIANT_IS_STRING(args[0])) { NPN_SetException( object_, "invalid or missing params passed to function - expecting 1 params: " "id"); return false; } id.append( NPVARIANT_TO_STRING(args[0]).UTF8Characters, NPVARIANT_TO_STRING(args[0]).UTF8Length); } catch (...) { } TextFileThreadMap::iterator iter = threads_.find(id); if (iter != threads_.end()) { if (!iter->second.first->StopListening()) { NPN_SetException( __super::object_, "an unexpected error occurred - couldn't stop existing listener"); return false; } if (!iter->second.second->Stop()) { NPN_SetException( __super::object_, "an unexpected error occurred - couldn't stop existing listener thread"); return false; } delete iter->second.first; delete iter->second.second; threads_.erase(id); if (nullptr != ids_to_callbacks_[id]) { NPN_ReleaseObject(ids_to_callbacks_[id]); ids_to_callbacks_[id] = nullptr; ids_to_callbacks_.erase(id); } } return true; }
void Any::Set(ptr<Script::Any> index, ptr<Script::Any> value) { NPVariant indexVariant = fast_cast<Any*>(&*index)->variant; if(NPVARIANT_IS_STRING(indexVariant)) InternalSet( Platform::NpapiPlugin::browserFuncs.getstringidentifier( NPVARIANT_TO_STRING(indexVariant).UTF8Characters), value); else if(NPVARIANT_IS_INT32(indexVariant)) Set(NPVARIANT_TO_INT32(indexVariant), value); }
static bool getURLNotify(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result) { if (argCount != 3 || !NPVARIANT_IS_STRING(args[0]) || (!NPVARIANT_IS_STRING(args[1]) && !NPVARIANT_IS_NULL(args[1])) || !NPVARIANT_IS_STRING(args[2])) return false; NPUTF8* urlString = createCStringFromNPVariant(&args[0]); NPUTF8* targetString = (NPVARIANT_IS_STRING(args[1]) ? createCStringFromNPVariant(&args[1]) : 0); NPUTF8* callbackString = createCStringFromNPVariant(&args[2]); NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString); browser->geturlnotify(obj->npp, urlString, targetString, callbackIdentifier); free(urlString); free(targetString); free(callbackString); VOID_TO_NPVARIANT(*result); return true; }