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;
    }
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 #3
0
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;
}
Example #4
0
bool convert_js_to_mrb(NPP npp, const NPVariant &variant, mrb_state *mrb, mrb_value *result)
{
    switch(variant.type){
      case NPVariantType_Void:
      case NPVariantType_Null:
        *result = mrb_nil_value();
        return true;
      case NPVariantType_Bool:
        if (NPVARIANT_TO_BOOLEAN(variant)){
            *result = mrb_true_value();
        }else{
            *result = mrb_false_value();
        }
        return true;
      case NPVariantType_Int32:
        *result = mrb_fixnum_value(NPVARIANT_TO_INT32(variant));
        return true;
      case NPVariantType_Double:
        *result = mrb_float_value(NPVARIANT_TO_DOUBLE(variant));
        return true;
      case NPVariantType_String:
        *result = mrb_str_new(mrb, NPVARIANT_TO_STRING(variant).UTF8Characters,
                              NPVARIANT_TO_STRING(variant).UTF8Length);
        return true;
      case NPVariantType_Object:
        return convert_js_to_mrb_object(npp, variant, mrb, result);
      default:
        break;
    }
    return false;
}
Example #5
0
NPUTF8* createCStringFromNPVariant(const NPVariant* variant) {
  size_t length = NPVARIANT_TO_STRING(*variant).UTF8Length;
  NPUTF8* result = (NPUTF8*)malloc(length + 1);
  memcpy(result, NPVARIANT_TO_STRING(*variant).UTF8Characters, length);
  result[length] = '\0';
  return result;
}
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));
}
Example #8
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 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;
}
Any convertToAny(NPP npp, const NPVariant* variant)
{
    switch (variant->type)
    {
    case NPVariantType_Void:
    case NPVariantType_Null:
        return Any();
        break;
    case NPVariantType_Bool:
        return NPVARIANT_TO_BOOLEAN(*variant);
        break;
    case NPVariantType_Int32:
        return NPVARIANT_TO_INT32(*variant);
        break;
    case NPVariantType_Double:
        return NPVARIANT_TO_DOUBLE(*variant);
        break;
    case NPVariantType_String:
        return std::string(NPVARIANT_TO_STRING(*variant).utf8characters, NPVARIANT_TO_STRING(*variant).utf8length);
        break;
    case NPVariantType_Object:
    {
        NPObject* object = NPVARIANT_TO_OBJECT(*variant);
        if (!object)
        {
            break;
        }
        if (StubObject::isStub(object))
        {
            StubObject* stub = static_cast<StubObject*>(object);
            return stub->getObject();
        }
        PluginInstance* instance = static_cast<PluginInstance*>(npp->pdata);
        if (instance)
        {
            ProxyControl* proxyControl = instance->getProxyControl();
            if (proxyControl)
            {
                return proxyControl->createProxy(object);
            }
        }
        break;
    }
    default:
        break;
    }
    return Any();
}
Example #11
0
char * ArgToStr(const NPVariant arg) {
	NPString str = NPVARIANT_TO_STRING(arg);
	char * r = (char *)malloc(str.UTF8Length + 1);
	memcpy(r, str.UTF8Characters, str.UTF8Length);
	r[str.UTF8Length] = '\0';
	return r;
}
Example #12
0
v8::Handle<v8::Value> convertNPVariantToV8Object(const NPVariant* variant, NPObject* npobject)
{
    NPVariantType type = variant->type;

    switch (type) {
    case NPVariantType_Int32:
        return v8Integer(NPVARIANT_TO_INT32(*variant));
    case NPVariantType_Double:
        return v8::Number::New(NPVARIANT_TO_DOUBLE(*variant));
    case NPVariantType_Bool:
        return v8Boolean(NPVARIANT_TO_BOOLEAN(*variant));
    case NPVariantType_Null:
        return v8::Null();
    case NPVariantType_Void:
        return v8::Undefined();
    case NPVariantType_String: {
        NPString src = NPVARIANT_TO_STRING(*variant);
        return v8::String::New(src.UTF8Characters, src.UTF8Length);
    }
    case NPVariantType_Object: {
        NPObject* obj = NPVARIANT_TO_OBJECT(*variant);
        if (obj->_class == npScriptObjectClass)
            return reinterpret_cast<V8NPObject*>(obj)->v8Object;
        return createV8ObjectForNPObject(obj, npobject);
    }
    default:
        return v8::Undefined();
    }
}
Example #13
0
bool
ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args,
                               uint32_t argCount, NPVariant *result)
{
  if (name == sendCmd_id)
  {
	if ( argCount < 1 )
	{
		return false;
	}

	PString strParam = "";
	NPString npStr = NPVARIANT_TO_STRING( args[0] );
	for (unsigned int i=0; i<npStr.utf8length; i++)
	{
		strParam += npStr.utf8characters[ i ];
	}


	PString strResult = g_NativeLogic.InvokeFunction( strParam );

	char* pszName = (char*)NPN_MemAlloc( strResult.GetSize() + 1 );
	strcpy( pszName, strResult );
    STRINGZ_TO_NPVARIANT(pszName, *result);

    return PR_TRUE;
  }

  return PR_FALSE;
}
Example #14
0
bool
xplayerNPObject::Invoke (NPIdentifier aName,
                       const NPVariant *argv,
                       uint32_t argc,
                       NPVariant *_result)
{
  if (!IsValid ())
    return false;

  NOTE (g_print ("xplayerNPObject::Invoke [%p] %s\n", (void*) this, NPN_UTF8FromIdentifier (aName)));
  int methodIndex = GetClass()->GetMethodIndex (aName);
  if (methodIndex >= 0)
    return InvokeByIndex (methodIndex, argv, argc, _result);

  if (aName == NPN_GetStringIdentifier ("__noSuchMethod__")) {
    /* http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Object:_noSuchMethod */
    if (!CheckArgv (argv, argc, 2, NPVariantType_String, NPVariantType_Object))
      return false;

    const char *id = NPVARIANT_TO_STRING (argv[0]).UTF8Characters;
    g_message ("NOTE: site calls unknown function \"%s\" on xplayerNPObject %p\n", id ? id : "(null)", (void*) this);

    /* Silently ignore the invocation */
    VOID_TO_NPVARIANT (*_result);
    return true;
  }

  return Throw ("No method with this name exists.");
}
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;
}
Example #16
0
v8::Handle<v8::Value> convertNPVariantToV8Object(const NPVariant* variant, NPObject* owner, v8::Isolate* isolate)
{
    NPVariantType type = variant->type;

    switch (type) {
    case NPVariantType_Int32:
        return v8::Integer::New(NPVARIANT_TO_INT32(*variant), isolate);
    case NPVariantType_Double:
        return v8::Number::New(isolate, NPVARIANT_TO_DOUBLE(*variant));
    case NPVariantType_Bool:
        return v8Boolean(NPVARIANT_TO_BOOLEAN(*variant), isolate);
    case NPVariantType_Null:
        return v8::Null(isolate);
    case NPVariantType_Void:
        return v8::Undefined(isolate);
    case NPVariantType_String: {
        NPString src = NPVARIANT_TO_STRING(*variant);
        return v8::String::NewFromUtf8(isolate, src.UTF8Characters, v8::String::kNormalString, src.UTF8Length);
    }
    case NPVariantType_Object: {
        NPObject* object = NPVARIANT_TO_OBJECT(*variant);
        if (V8NPObject* v8Object = npObjectToV8NPObject(object))
            return v8::Local<v8::Object>::New(isolate, v8Object->v8Object);
        return createV8ObjectForNPObject(object, owner, isolate);
    }
    default:
        return v8::Undefined(isolate);
    }
}
Example #17
0
v8::Handle<v8::Value> ConvertNPVariantToV8Object(const NPVariant* variant,
                                                 NPObject* npobject) {
  NPVariantType type = variant->type;

  if (type == NPVariantType_Int32) {
    return v8::Integer::New(NPVARIANT_TO_INT32(*variant));
  }
  if (type == NPVariantType_Double) {
    return v8::Number::New(NPVARIANT_TO_DOUBLE(*variant));
  }
  if (type == NPVariantType_Bool) {
    return NPVARIANT_TO_BOOLEAN(*variant) ? v8::True() : v8::False();
  }
  if (type == NPVariantType_Null) {
    return v8::Null();
  }
  if (type == NPVariantType_Void) {
    return v8::Undefined();
  }
  if (type == NPVariantType_String) {
    NPString src = NPVARIANT_TO_STRING(*variant);
    return v8::String::New(src.UTF8Characters, src.UTF8Length);
  }
  if (type == NPVariantType_Object) {
    NPObject* obj = NPVARIANT_TO_OBJECT(*variant);
    if (obj->_class == NPScriptObjectClass) {
      return reinterpret_cast<V8NPObject*>(obj)->v8_object;
    }
    return CreateV8ObjectForNPObject(obj, npobject);
  }
  return v8::Undefined();
}
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;
}
Example #19
0
bool convert_js_to_mrb_object(NPP npp, const NPVariant &variant, mrb_state *mrb, mrb_value *result)
{
    if (NPVARIANT_IS_MRB_JS_OBJECT(variant)){
        MrbJsObject *obj = static_cast< MrbJsObject* >(NPVARIANT_TO_OBJECT(variant));
        *result = obj->Value();
        return true;
    }

    NPObject *window;
    NPN_GetValue(npp, NPNVWindowNPObject, &window);

    NPVariant object;
    NPN_GetProperty(npp, window, NPN_GetStringIdentifier("Object"), &object);
    NPN_ReleaseObject(window);

    NPVariant prototype;
    NPN_GetProperty(npp, NPVARIANT_TO_OBJECT(object), NPN_GetStringIdentifier("prototype"), &prototype);
    NPN_ReleaseVariantValue(&object);

    NPVariant to_string;
    NPN_GetProperty(npp, NPVARIANT_TO_OBJECT(prototype), NPN_GetStringIdentifier("toString"), &to_string);
    NPN_ReleaseVariantValue(&prototype);

    NPVariant type_string;
    NPN_Invoke(npp, NPVARIANT_TO_OBJECT(to_string), NPN_GetStringIdentifier("call"), &variant, 1, &type_string);
    NPN_ReleaseVariantValue(&to_string);

    if (!NPVARIANT_IS_STRING(type_string)){
        NPN_ReleaseVariantValue(&type_string);
        return false;
    }

    std::string type(NPVARIANT_TO_STRING(type_string).UTF8Characters, NPVARIANT_TO_STRING(type_string).UTF8Length);
    NPN_ReleaseVariantValue(&type_string);
    if (type == "[object Array]"){
        return convert_js_to_mrb_array(npp, variant, mrb, result);
    }else if (type == "[object Object]"){
        return convert_js_to_mrb_hash(npp, variant, mrb, result);
    }else if (type == "[object Function]"){
        return convert_js_to_mrb_function(npp, variant, mrb, result);
    }else{
        *result = mrb_js_obj_class_new(mrb, NPVARIANT_TO_OBJECT(variant));
        return true;
    }

    return true;
}
Example #20
0
void
cloud_spy_init_npvariant_with_other (NPVariant * var, const NPVariant * other)
{
  memcpy (var, other, sizeof (NPVariant));

  if (other->type == NPVariantType_String)
  {
    const NPString * from = &NPVARIANT_TO_STRING (*other);
    NPString * to = &NPVARIANT_TO_STRING (*var);
    to->UTF8Characters = static_cast<NPUTF8 *> (cloud_spy_nsfuncs->memalloc (from->UTF8Length));
    memcpy (const_cast<NPUTF8 *> (to->UTF8Characters), from->UTF8Characters, from->UTF8Length);
  }
  else if (other->type == NPVariantType_Object)
  {
    cloud_spy_nsfuncs->retainobject (NPVARIANT_TO_OBJECT (*var));
  }
}
Example #21
0
vector<string> CppVariant::toStringVector() const
{

    WEBKIT_ASSERT(isObject());
    vector<string> stringVector;
    NPObject* npValue = value.objectValue;
    NPIdentifier lengthId = WebBindings::getStringIdentifier("length");

    if (!WebBindings::hasProperty(0, npValue, lengthId))
        return stringVector;

    NPVariant lengthValue;
    if (!WebBindings::getProperty(0, npValue, lengthId, &lengthValue))
        return stringVector;

    int length = 0;
    // The length is a double in some cases.
    if (NPVARIANT_IS_DOUBLE(lengthValue))
        length = static_cast<int>(NPVARIANT_TO_DOUBLE(lengthValue));
    else if (NPVARIANT_IS_INT32(lengthValue))
        length = NPVARIANT_TO_INT32(lengthValue);
    WebBindings::releaseVariantValue(&lengthValue);

    // For sanity, only allow 100 items.
    length = min(100, length);
    for (int i = 0; i < length; ++i) {
        // Get each of the items.
        char indexInChar[20]; // Enough size to store 32-bit integer
        snprintf(indexInChar, 20, "%d", i);
        string index(indexInChar);
        NPIdentifier indexId = WebBindings::getStringIdentifier(index.c_str());
        if (!WebBindings::hasProperty(0, npValue, indexId))
            continue;
        NPVariant indexValue;
        if (!WebBindings::getProperty(0, npValue, indexId, &indexValue))
            continue;
        if (NPVARIANT_IS_STRING(indexValue)) {
            string item(NPVARIANT_TO_STRING(indexValue).UTF8Characters,
                        NPVARIANT_TO_STRING(indexValue).UTF8Length);
            stringVector.push_back(item);
        }
        WebBindings::releaseVariantValue(&indexValue);
    }
    return stringVector;
}
Example #22
0
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;
}
Example #23
0
char* RuntimeNPObject::stringValue(const NPVariant &v)
{
    char *s = NULL;
    if( NPVARIANT_IS_STRING(v) )
    {
        return stringValue(NPVARIANT_TO_STRING(v));
    }
    return s;
}
Example #24
0
char *_npapi_get_page_url(NPP instance) {
	NPObject *window = 0;
	npnfuncs->getvalue( instance, NPNVWindowNPObject, &window );
	NPIdentifier identifier = npnfuncs->getstringidentifier( "location" );
	NPVariant variant;
	int b1 = npnfuncs->getproperty( instance, window , identifier, &variant);
	NPObject *location = variant.value.objectValue;
	identifier = npnfuncs->getstringidentifier( "href" );
	int b2 = npnfuncs->getproperty( instance, location, identifier, &variant);
	return (char*)NPVARIANT_TO_STRING(variant).UTF8Characters;
}
Example #25
0
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);
}
bool pluginSetProperty(PluginInstance *obj, NPIdentifier name, const NPVariant *variant) {
	LOG_LOCATION;
	if(isSameIdentifier(name, "pluginLanguage")) {
		memset(pluginLanguage, '\0', 3);
		if(NPVARIANT_IS_STRING(*variant)) {
			strncpy(pluginLanguage, NPVARIANT_TO_STRING(*variant).UTF8Characters, 2);
			return true;
		}
		return true;
	}
	return false;
}
bool ObjectManager::Invoke(NPObject *npobj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) {
	ScriptManager *obj = static_cast<ScriptManager*>(npobj);
	if (name == NPNFuncs.getstringidentifier("CreateControlByProgId")) {
		if (argCount != 1 || !NPVARIANT_IS_STRING(args[0])) {
			NPNFuncs.setexception(npobj, "Invalid arguments");
			return false;
		}
		CAxHost* host = new CAxHost(obj->instance);
		CStringA str(NPVARIANT_TO_STRING(args[0]).UTF8Characters, NPVARIANT_TO_STRING(args[0]).UTF8Length);
		host->setClsIDFromProgID(str.GetString());
		if (!host->CreateControl(false)) {
			NPNFuncs.setexception(npobj, "Error creating object");
			return false;
		}
		ObjectManager *manager = static_cast<ObjectManager*>(obj->host);
		manager->dynamic_hosts.push_back(host);
		OBJECT_TO_NPVARIANT(host->CreateScriptableObject(), *result);
		return true;
	}
	return false;
}
Example #28
0
static bool testSetStatus(PluginObject* obj, const NPVariant* args, uint32_t argCount, NPVariant* result)
{
    char* message = 0;
    if (argCount && NPVARIANT_IS_STRING(args[0])) {
        NPString statusString = NPVARIANT_TO_STRING(args[0]);
        message = toCString(statusString);
    }
    
    browser->status(obj->npp, message);

    free(message);
    return true;
}
Example #29
0
static bool testEvaluate(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);

    NPString s = NPVARIANT_TO_STRING(args[0]);

    bool retval = browser->evaluate(obj->npp, windowScriptObject, &s, result);
    browser->releaseobject(windowScriptObject);
    return retval;
}
Example #30
0
void
StatementObject::GetForeignKeys(const NPVariant *arg0, const NPVariant *arg1, 
	const NPVariant *arg2, const NPVariant *arg3, const NPVariant *arg4, 
	const NPVariant *arg5)
{
  NPString *pcat = NULL;
  NPString *psch = NULL; 
  NPString *ptbl = NULL;
  NPString *fcat = NULL;
  NPString *fsch = NULL; 
  NPString *ftbl = NULL;

  if (NPVARIANT_IS_STRING(*arg0))
    pcat = (NPString*)&NPVARIANT_TO_STRING(*arg0);
  if (NPVARIANT_IS_STRING(*arg1))
    psch = (NPString*)&NPVARIANT_TO_STRING(*arg1);
  if (NPVARIANT_IS_STRING(*arg2))
    ptbl = (NPString*)&NPVARIANT_TO_STRING(*arg2);

  if (NPVARIANT_IS_STRING(*arg3))
    fcat = (NPString*)&NPVARIANT_TO_STRING(*arg3);
  if (NPVARIANT_IS_STRING(*arg4))
    fsch = (NPString*)&NPVARIANT_TO_STRING(*arg4);
  if (NPVARIANT_IS_STRING(*arg5))
    ftbl = (NPString*)&NPVARIANT_TO_STRING(*arg5);

  if (!m_hstmt) {
    NPN_SetException(this, "Statement isn't initialized");
    return;
  }

  NPError rc = Close();
  if (rc != NPERR_NO_ERROR)
    return;

  SQLRETURN code = SQLForeignKeysW(m_hstmt, 
  	(pcat?nsWString(pcat).Data():NULL), (pcat?SQL_NTS:0),
  	(psch?nsWString(psch).Data():NULL), (psch?SQL_NTS:0),
  	(ptbl?nsWString(ptbl).Data():NULL), (ptbl?SQL_NTS:0),
  	(fcat?nsWString(fcat).Data():NULL), (fcat?SQL_NTS:0),
  	(fsch?nsWString(fsch).Data():NULL), (fsch?SQL_NTS:0),
  	(ftbl?nsWString(ftbl).Data():NULL), (ftbl?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;
}