本文整理汇总了C++中NPVARIANT_IS_OBJECT函数的典型用法代码示例。如果您正苦于以下问题:C++ NPVARIANT_IS_OBJECT函数的具体用法?C++ NPVARIANT_IS_OBJECT怎么用?C++ NPVARIANT_IS_OBJECT使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NPVARIANT_IS_OBJECT函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
// This method is also called before the JS engine attempts to add a new
// property, most likely it's trying to check that the key is supported.
// It only returns false if the string name was not found, or does not
// hold a callable object
bool GenericNPObject::HasProperty(NPIdentifier name) {
if (invalid) return false;
if (NPNFuncs.identifierisstring(name)) {
char *key = NPNFuncs.utf8fromidentifier(name);
if (immutables.count(key) > 0) {
if (NPVARIANT_IS_OBJECT(immutables[key])) {
return (NULL == immutables[key].value.objectValue->_class->invokeDefault);
}
}
else if (alpha_mapper.count(key) > 0) {
if (NPVARIANT_IS_OBJECT(alpha_mapper[key])) {
return (NULL == alpha_mapper[key].value.objectValue->_class->invokeDefault);
}
}
return false;
}
return true;
}
示例2: if
bool GenericNPObject::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) {
if (invalid) return false;
if (NPNFuncs.identifierisstring(name)) {
char *key = NPNFuncs.utf8fromidentifier(name);
if (immutables.count(key) > 0) {
if ( NPVARIANT_IS_OBJECT(immutables[key])
&& immutables[key].value.objectValue->_class->invokeDefault) {
return immutables[key].value.objectValue->_class->invokeDefault(immutables[key].value.objectValue, args, argCount, result);
}
}
else if (alpha_mapper.count(key) > 0) {
if ( NPVARIANT_IS_OBJECT(alpha_mapper[key])
&& alpha_mapper[key].value.objectValue->_class->invokeDefault) {
return alpha_mapper[key].value.objectValue->_class->invokeDefault(alpha_mapper[key].value.objectValue, args, argCount, result);
}
}
}
return true;
}
示例3: DeleteInstance
bool nsScriptableObjectRawInput::DeleteInstance(
NPIdentifier name,
const NPVariant *args,
uint32_t argCount,
NPVariant *result) {
if (argCount != 2 ||
!NPVARIANT_IS_DOUBLE(args[0]) ||
!NPVARIANT_IS_OBJECT(args[1])) {
NPN_SetException(this, "(DeleteInstance) invalid params passed to function");
return true;
}
int32_t id = (int32_t)(int)floor(NPVARIANT_TO_DOUBLE(args[0]) + 0.5); // all numbers come in as double in chrome...
bool foundAndDeleted = PluginMethodKeyCapture::DeleteInstance(id);
NPVariant out_args[2];
NPVariant ret_val;
BOOLEAN_TO_NPVARIANT(foundAndDeleted, out_args[0]);
INT32_TO_NPVARIANT(id, out_args[1]);
// fire callback
NPN_InvokeDefault(
__super::npp_,
NPVARIANT_TO_OBJECT(args[1]),
out_args,
2,
&ret_val);
NPN_ReleaseVariantValue(&ret_val);
return true;
}
示例4: plugin_object_set_property
static bool
plugin_object_set_property (NPObject *npobj,
NPIdentifier name,
const NPVariant *value)
{
PluginObject *obj;
g_return_val_if_fail (plugin_object_has_property (npobj, name), FALSE);
obj = (PluginObject*) npobj;
if (obj->listener)
funcs.releaseobject (obj->listener);
obj->listener = NULL;
if (NPVARIANT_IS_OBJECT (*value))
{
obj->listener = NPVARIANT_TO_OBJECT (*value);
funcs.retainobject (obj->listener);
return TRUE;
}
else if (NPVARIANT_IS_NULL (*value))
return TRUE;
return FALSE;
}
示例5: Add
bool nsScriptableObjectOverwolfSample::Add(
NPIdentifier name,
const NPVariant *args,
uint32_t argCount,
NPVariant *result) {
if (argCount < 3 ||
!NPVARIANT_IS_DOUBLE(args[0]) ||
!NPVARIANT_IS_DOUBLE(args[1]) ||
!NPVARIANT_IS_OBJECT(args[2])) {
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[2]));
// post to separate thread so that we are responsive
return thread_->PostTask(
std::bind(
&nsScriptableObjectOverwolfSample::AddTask,
this,
NPVARIANT_TO_DOUBLE(args[0]),
NPVARIANT_TO_DOUBLE(args[1]),
NPVARIANT_TO_OBJECT(args[2])));
}
示例6: doSign
bool doSign(PluginInstance *obj, NPVariant *args, unsigned argCount, NPVariant *result) {
EstEID_log("obj=%p, name=sign argCount=%u", obj, argCount);
FAIL_IF_NOT_ALLOWED_SITE;
if (argCount < 2) {
browserFunctions->setexception(&obj->header, "Missing arguments");
return false;
}
if(argCount > 2 && NPVARIANT_IS_OBJECT(args[2])){
strncpy(pluginLanguage, getLanguageFromOptions(obj, args[2]), 2);
}
EstEID_setLocale(pluginLanguage);
void* wnd = getNativeWindowHandle(obj);
EstEID_PINPromptData pinPromptData = {promptForPIN, showAlert, wnd};
NPUTF8* certId = createStringFromNPVariant(&args[0]);
NPUTF8* hash = createStringFromNPVariant(&args[1]);
char *signature = NULL;
#ifdef _WIN32
DialogData dialogData;
dialogData.pin2[0] = '\0';
dialogData.minPin2Length = 5;
dialogData.certId = certId;
dialogData.hash = hash;
dialogData.signature[0] = '\0';
CK_SLOT_ID slotId;
if(EstEID_getSlotId(certId, &slotId)){
if(EstEID_isPinPad(slotId)) {
signature = EstEID_sign(certId, hash, pinPromptData);
}
else {
DialogBoxParam(pluginInstance, MAKEINTRESOURCEW(IDD_PIN_DIALOG), (HWND)wnd, Pin2DialogProc, (LPARAM)&dialogData);
LOG_LOCATION;
signature = (char*)malloc(SIGNATURE_BUFFER_SIZE); // check?
strcpy(signature, dialogData.signature);
}
}
else {
return false;
}
#else
signature = EstEID_sign(certId, hash, pinPromptData);
#endif
LOG_LOCATION
if (signature) {
copyStringToNPVariant(signature, result);
free(signature);
return true;
}
else {
EstEID_log("EstEID_error=%s", EstEID_error);
browserFunctions->setexception(&obj->header, EstEID_error);
return false;
}
}
示例7: debug
static NPObject *get_scroller_mojo(NPP instance, NPObject *scroller)
{
if(!scroller)
{
debug(DBG_MAIN, "get_scroller_mojo: no scroller");
return 0;
}
//debug(DBG_MAIN, "get_scroller_mojo");
NPIdentifier mojoID = NPNFuncs.getstringidentifier("mojo");
//debug(DBG_MAIN, "get_scroller_mojo npp:%p, scroller:%p, id:%p", instance, scroller, mojoID);
if(!NPNFuncs.hasproperty(instance, scroller, mojoID) && !NPNFuncs.hasmethod(instance, scroller, mojoID))
{
debug(DBG_MAIN, "get_scroller_mojo: no property/method mojo");
return 0;
}
NPVariant var;
int ok = NPNFuncs.getproperty(instance, scroller, mojoID, &var);
if(!ok || !NPVARIANT_IS_OBJECT(var))
{
debug(DBG_MAIN, "get_scroller_mojo: ok:%d, mojo - var.type:%d (not object)", ok, var.type);
return 0;
}
//debug(DBG_MAIN, "get_scroller_mojo");
NPObject *mojoObj = NPVARIANT_TO_OBJECT(var);
return mojoObj;
}
示例8: getScrollPosition
int getScrollPosition(NPP instance, NPObject *scroller)
{
NPVariant var;
//var.type = NPVariantType_Void;
scrollCommon(instance, scroller, "getScrollPosition", 0, 0, &var);
NPObject *obj = NPVARIANT_TO_OBJECT(var);
if(!NPVARIANT_IS_OBJECT(var) || !obj)
{
debug(DBG_MAIN, "getScrollPosition() expected obj, got %d (obj:%p)", var.type, obj);
return -1;
}
// Get the current position of the scroller. Returns {left: nnn px, top: nnn px}
NPIdentifier id = NPNFuncs.getstringidentifier("top");
//debug(DBG_MAIN, "getScrollPosition()");
if(!NPNFuncs.hasproperty(instance, obj, id) && !NPNFuncs.hasmethod(instance, obj, id))
{
debug(DBG_MAIN, "getScrollPosition: no property/method: top, obj:%p", obj);
return -2;
}
#ifdef DEBUG_OUTPUT
bool ok =
#endif
NPNFuncs.getproperty(instance, obj, id, &var);
int val = IntValue(&var);
debug(DBG_MAIN, "getScrollPosition() %s val:%d, type:%d", ok ? "OK" : "ERROR", val, var.type);
//if(NPVARIANT_IS_DOUBLE(var))
// debug(DBG_MAIN, "+++++ getScrollPosition() = double:%g", NPVARIANT_TO_DOUBLE(var));
//else if(NPVARIANT_IS_INT32(var))
// debug(DBG_MAIN, "----- getScrollPosition() = int:%d", NPVARIANT_TO_INT32(var));
return val;
}
示例9: 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;
}
示例10: 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])));
}
示例11: CallJSMethod
bool CJSMethods::GetLanguage(ChromeTrayIconLanguage &language)
{
if(m_pScriptableObject == NULL)
{
return false;
}
NPP pluginInstance = m_pScriptableObject->GetPluginInstance();
NPNetscapeFuncs *pBrowserFuncs = m_pScriptableObject->GetBrowserFuncs();
if(pluginInstance == NULL || pBrowserFuncs == NULL)
{
return false;
}
NPVariant varResults;
NPVariant varArgs;
bool bResult = CallJSMethod(pBrowserFuncs, pluginInstance, "getLanguage", &varArgs, 0, varResults);
if(bResult)
{
if(NPVARIANT_IS_OBJECT(varResults))
{
NPObject *pArray = NPVARIANT_TO_OBJECT(varResults);
if(pArray != NULL)
{
wstring strValue;
if(CJSValue::GetProperty(pBrowserFuncs, pluginInstance, pArray, "lngOptions", strValue))
{
language.strOptions = strValue;
}
if(CJSValue::GetProperty(pBrowserFuncs, pluginInstance, pArray, "lngNewTab", strValue))
{
language.strNewTab = strValue;
}
if(CJSValue::GetProperty(pBrowserFuncs, pluginInstance, pArray, "lngNewWindow", strValue))
{
language.strNewWindow = strValue;
}
if(CJSValue::GetProperty(pBrowserFuncs, pluginInstance, pArray, "lngFavorites", strValue))
{
language.strFavorites = strValue;
}
}
}
}
pBrowserFuncs->releasevariantvalue(&varArgs);
pBrowserFuncs->releasevariantvalue(&varResults);
return bResult;
}
示例12: DeferNPVariantLastRelease
void DeferNPVariantLastRelease(const NPNetscapeFuncs* f, NPVariant* v)
{
if (!NPVARIANT_IS_OBJECT(*v)) {
f->releasevariantvalue(v);
return;
}
DeferNPObjectLastRelease(f, v->value.objectValue);
VOID_TO_NPVARIANT(*v);
}
示例13: 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;
}
示例14: ExecuteListenOnFile
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));
}
示例15: plugin_object_set_callback
static bool
plugin_object_set_callback (NPObject **listener,
const NPVariant *value)
{
if (!NPVARIANT_IS_OBJECT (*value) && !NPVARIANT_IS_NULL (*value))
return FALSE;
if (*listener)
funcs.releaseobject (*listener);
*listener = NULL;
if (NPVARIANT_IS_OBJECT (*value))
{
*listener = NPVARIANT_TO_OBJECT (*value);
funcs.retainobject (*listener);
}
return TRUE;
}