// 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;
}
Example #2
0
static bool testEnumerate(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
    if (argCount != 2 || !NPVARIANT_IS_OBJECT(args[0]) || !NPVARIANT_IS_OBJECT(args[1]))
        return false;

    uint32_t count;
    NPIdentifier* identifiers;
    if (browser->enumerate(obj->npp, NPVARIANT_TO_OBJECT(args[0]), &identifiers, &count)) {
        NPObject* outArray = NPVARIANT_TO_OBJECT(args[1]);
        NPIdentifier pushIdentifier = browser->getstringidentifier("push");

        for (uint32_t i = 0; i < count; i++) {
            NPUTF8* string = browser->utf8fromidentifier(identifiers[i]);

            if (!string)
                continue;

            NPVariant args[1];
            STRINGZ_TO_NPVARIANT(string, args[0]);
            NPVariant browserResult;
            if (browser->invoke(obj->npp, outArray, pushIdentifier, args, 1, &browserResult))
                browser->releasevariantvalue(&browserResult);
            browser->memfree(string);
        }

        browser->memfree(identifiers);
    }

    VOID_TO_NPVARIANT(*result);
    return true;
}
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;
}
Example #4
0
static bool objectsAreSame(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
    if (argCount != 2 || !NPVARIANT_IS_OBJECT(args[0]) || !NPVARIANT_IS_OBJECT(args[1]))
        return false;

    BOOLEAN_TO_NPVARIANT(NPVARIANT_TO_OBJECT(args[0]) == NPVARIANT_TO_OBJECT(args[1]), *result);
    return true;
}
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;
}
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;
}
Example #7
0
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;
}
Example #8
0
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;
}
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])));
}
Example #10
0
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;
	}
}
Example #11
0
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;
	}
Example #12
0
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;
	}
Example #13
0
static bool testConstruct(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
    if (!argCount || !NPVARIANT_IS_OBJECT(args[0]))
        return false;
    
    return browser->construct(obj->npp, NPVARIANT_TO_OBJECT(args[0]), args + 1, argCount - 1, result);
}
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;
}
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])));
}
Example #16
0
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;
}
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);
}
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;
}
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));
}
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;
}
Example #21
0
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);
}
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);

	if(argCount > 3 && NPVARIANT_IS_OBJECT(args[3])){
		strcpy(promptMessage, createStringFromNPVariant(args[3]));
	}

	void* wnd = getNativeWindowHandle(obj);

	EstEID_PINPromptData pinPromptData = {promptForPIN, showAlert, wnd, promptMessage, NULL};
	NPUTF8* certId = createStringFromNPVariant(&args[0]);
	NPUTF8* hash = createStringFromNPVariant(&args[1]);
	char *signature = NULL;

	signature = EstEID_sign(certId, hash, pinPromptData);

	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;
	}
}
Example #23
0
// 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;
}
Example #24
0
static gboolean
get_element_property_object (NPP npp, NPObject *object, NPIdentifier property, NPVariant *child)
{
	VOID_TO_NPVARIANT (*child);

	if (!NPN_GetProperty (npp, object, property, child) ||
		!NPVARIANT_IS_OBJECT (*child)) {
		NPN_ReleaseVariantValue (child);
		return FALSE;
	}

	return TRUE;
}
Example #25
0
static bool testHasMethod(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
    if (argCount != 2 || !NPVARIANT_IS_OBJECT(args[0]) || !NPVARIANT_IS_STRING(args[1]))
        return false;

    NPUTF8* propertyString = createCStringFromNPVariant(&args[1]);
    NPIdentifier propertyIdentifier = browser->getstringidentifier(propertyString);
    free(propertyString);

    bool retval = browser->hasmethod(obj->npp, NPVARIANT_TO_OBJECT(args[0]), propertyIdentifier);

    BOOLEAN_TO_NPVARIANT(retval, *result);
    return true;
}
static
void
topmost_rect_ptac(void *param)
{
    struct topmost_rect_param_s *p = param;
    struct pp_instance_s *pp_i = tables_get_pp_instance(p->instance);
    if (!pp_i) {
        trace_error("%s, no instance\n", __func__);
        goto err_1;
    }

    p->result = PP_FALSE;

    NPString topmost_func_src = NPString_literal(
        "(function(elem, x, y) {"
            "var r = elem.getBoundingClientRect();"
            "return document.elementFromPoint(x + r.left, y + r.top) == elem;"
        "})");
    NPVariant topmost_func;

    if (!npn.evaluate(pp_i->npp, pp_i->np_window_obj, &topmost_func_src, &topmost_func))
        goto err_1;

    if (!NPVARIANT_IS_OBJECT(topmost_func))
        goto err_1;

    NPObject *topmost_func_obj = NPVARIANT_TO_OBJECT(topmost_func);

    NPVariant is_topmost;
    NPVariant args[3];

    OBJECT_TO_NPVARIANT(pp_i->np_plugin_element_obj, args[0]);
    INT32_TO_NPVARIANT(p->rect.point.x + p->rect.size.width / 2, args[1]);
    INT32_TO_NPVARIANT(p->rect.point.y + p->rect.size.height / 2, args[2]);

    if (!npn.invokeDefault(pp_i->npp, topmost_func_obj, args, 3, &is_topmost))
        goto err_2;

    if (!NPVARIANT_IS_BOOLEAN(is_topmost))
        goto err_3;

    p->result = NPVARIANT_TO_BOOLEAN(is_topmost);

err_3:
    npn.releasevariantvalue(&is_topmost);
err_2:
    npn.releasevariantvalue(&topmost_func);
err_1:
    ppb_message_loop_post_quit_depth(p->m_loop, PP_FALSE, p->depth);
}
Example #27
0
static gboolean
invoke_in_s_out_o (NPP npp, NPVariant *object, NPIdentifier method, const gchar *in_s, NPVariant *out_o)
{
	NPVariant string;
	STRINGZ_TO_NPVARIANT (in_s, string);
	VOID_TO_NPVARIANT (*out_o);

	if (!NPN_Invoke (npp, NPVARIANT_TO_OBJECT (*object), method, &string, 1, out_o) ||
		!NPVARIANT_IS_OBJECT (*out_o)) {
		NPN_ReleaseVariantValue (out_o);
		return FALSE;
	}

	return TRUE;
}
ObjectManager* ObjectManager::GetManager(NPP npp) {
	NPObjectProxy window;
	NPNFuncs.getvalue(npp, NPNVWindowNPObject, &window);
	NPVariantProxy document, obj;
	NPVariant par;
	STRINGZ_TO_NPVARIANT(MANAGER_OBJECT_ID, par);
	if (!NPNFuncs.getproperty(npp, window, NPNFuncs.getstringidentifier("document"), &document))
		return NULL;
	if (!NPNFuncs.invoke(npp, document.value.objectValue, NPNFuncs.getstringidentifier("getElementById"), &par, 1, &obj))
		return NULL;
	if (NPVARIANT_IS_OBJECT(obj)) {
		NPObject *manager = NPVARIANT_TO_OBJECT(obj);
		CHost *host = GetInternalObject(npp, manager);
		if (host)
			return dynamic_cast<ObjectManager*>(host);
	}
	return NULL;
}
Example #29
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;
}
Example #30
0
static bool testInvokeDefault(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
    if (!NPVARIANT_IS_OBJECT(args[0]))
        return false;

    NPObject* callback = NPVARIANT_TO_OBJECT(args[0]);

    NPVariant invokeArgs[1];
    NPVariant browserResult;

    STRINGZ_TO_NPVARIANT("test", invokeArgs[0]);
    bool retval = browser->invokeDefault(obj->npp, callback, invokeArgs, 1, &browserResult);

    if (retval)
        browser->releasevariantvalue(&browserResult);

    BOOLEAN_TO_NPVARIANT(retval, *result);
    return true;
}