本文整理汇总了C++中NPVARIANT_IS_STRING函数的典型用法代码示例。如果您正苦于以下问题:C++ NPVARIANT_IS_STRING函数的具体用法?C++ NPVARIANT_IS_STRING怎么用?C++ NPVARIANT_IS_STRING使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NPVARIANT_IS_STRING函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: g_assert
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);
}
示例2: onLoad
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);
}
示例3: VOID_TO_NPVARIANT
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;
}
示例4: Echo
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])));
}
示例5: stringVariantToIdentifier
NPIdentifier stringVariantToIdentifier(NPVariant variant) {
assert(NPVARIANT_IS_STRING(variant));
NPUTF8* utf8String = createCStringFromNPVariant(&variant);
NPIdentifier identifier = NPN_GetStringIdentifier(utf8String);
free(utf8String);
return identifier;
}
示例6: NPN_GetStringIdentifier
// 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;
}
}
}
}
示例7: pluginSetProperty
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;
}
示例8: CopyNPVariant
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;
}
示例9: get_string_property
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;
}
示例10: SetProperty
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;
}
示例11: plugin_object_invoke
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;
}
示例12: Close
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;
}
示例13: variantToIdentifier
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;
}
示例14: InvokeJavascript_TwoArgs
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;
}
示例15: getInterfaceName
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;
}