예제 #1
0
void ConvertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject *owner,
                                NPVariant* result) {
  VOID_TO_NPVARIANT(*result);

  // It is really the caller's responsibility to deal with the empty handle
  // case because there could be different actions to take in different
  // contexts.
  ASSERT(!object.IsEmpty());

  if (object.IsEmpty()) return;

  if (object->IsNumber()) {
    DOUBLE_TO_NPVARIANT(object->NumberValue(), *result);

  } else if (object->IsBoolean()) {
    BOOLEAN_TO_NPVARIANT(object->BooleanValue(), *result);

  } else if (object->IsNull()) {
    NULL_TO_NPVARIANT(*result);

  } else if (object->IsUndefined()) {
    VOID_TO_NPVARIANT(*result);

  } else if (object->IsString()) {
    v8::Handle<v8::String> str = object->ToString();
    uint16_t *buf = new uint16_t[str->Length()+1];
    str->Write(buf);
    std::string utf8 = WideToUTF8(reinterpret_cast<wchar_t*>(buf));
    char* utf8_chars = strdup(utf8.c_str());
    STRINGN_TO_NPVARIANT(utf8_chars, utf8.length(), *result);
    delete[] buf;

  } else if (object->IsObject()) {
    WebCore::DOMWindow* window = WebCore::V8Proxy::retrieveWindow();
    NPObject* npobject = NPN_CreateScriptObject(
        0, v8::Handle<v8::Object>::Cast(object), window);
    if (npobject) {
      _NPN_RegisterObject(npobject, owner);
    }
    OBJECT_TO_NPVARIANT(npobject, *result);
  }
}
예제 #2
0
파일: shocker.cpp 프로젝트: 499940913/moon
void
ShockerScriptableControlObject::ActivateKeyboardLayout (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	const char *friendlyName;
	int x, y;
	guint8 res = false;

	g_assert (arg_count >= 3);
	g_assert (NPVARIANT_IS_STRING (args [0]));
	g_assert (NPVARIANT_IS_NUMBER (args [1]));
	g_assert (NPVARIANT_IS_NUMBER (args [2]));

	friendlyName = STR_FROM_VARIANT (args [0]);
	x = NUMBER_TO_INT32 (args [1]);
	y = NUMBER_TO_INT32 (args [2]);

	printf ("[%i shocker] ShockerScriptableControlObject::ActivateKeyboardLayout (friendlyName: '%s' x: %i y: %i)\n", getpid (), friendlyName, x, y);

	Shocker_FailTestFast ("ActivateKeyboardLayout: Not implemented");
	BOOLEAN_TO_NPVARIANT (res != 0, *result);
}
예제 #3
0
void NPRuntimeObjectMap::convertJSValueToNPVariant(ExecState* exec, JSValue value, NPVariant& variant)
{
    JSLockHolder lock(exec);

    VOID_TO_NPVARIANT(variant);
    
    if (value.isNull()) {
        NULL_TO_NPVARIANT(variant);
        return;
    }

    if (value.isUndefined()) {
        VOID_TO_NPVARIANT(variant);
        return;
    }

    if (value.isBoolean()) {
        BOOLEAN_TO_NPVARIANT(value.toBoolean(exec), variant);
        return;
    }

    if (value.isNumber()) {
        DOUBLE_TO_NPVARIANT(value.toNumber(exec), variant);
        return;
    }

    if (value.isString()) {
        NPString npString = createNPString(value.toString(exec)->value(exec).utf8());
        STRINGN_TO_NPVARIANT(npString.UTF8Characters, npString.UTF8Length, variant);
        return;
    }

    if (value.isObject()) {
        NPObject* npObject = getOrCreateNPObject(exec->vm(), asObject(value));
        OBJECT_TO_NPVARIANT(npObject, variant);
        return;
    }

    ASSERT_NOT_REACHED();
}
예제 #4
0
파일: shocker.cpp 프로젝트: 499940913/moon
void
ShockerScriptableControlObject::CompareImages (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	guint8 res = false;

	g_assert (arg_count >= 5);
	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_STRING (args [3]));
	g_assert (NPVARIANT_IS_BOOLEAN (args [4]));

	LOG_PLUGIN ("[%i shocker] ShockerScriptableControlObject::CompareImages (imageFile1: '%s', imageFile2: '%s', tolerance: %i, diffFileName: '%s', copySourceFiles: %i)\n", getpid (),
		STR_FROM_VARIANT (args [0]), STR_FROM_VARIANT (args [1]), NUMBER_TO_INT32 (args [2]),
		STR_FROM_VARIANT (args [3]), NPVARIANT_TO_BOOLEAN (args [4]));


	::CompareImages (STR_FROM_VARIANT (args [0]), STR_FROM_VARIANT (args [1]), NUMBER_TO_INT32 (args [2]),
		STR_FROM_VARIANT (args [3]), NPVARIANT_TO_BOOLEAN (args [4]), &res);
	
	BOOLEAN_TO_NPVARIANT ((bool) res, *result);
}
예제 #5
0
bool        APPLICATION_GetProperty(NPObject* obj, NPIdentifier name, NPVariant* result)
{
    TRACEINFO;
   
    bool fctresult = false;
    NPObj_Application* AppliObj = (NPObj_Application*)obj;
    
    if (name == v_APPLICATIONPropertyIdentifiers[kAPPLICATION_ID_PROPERTY_PRIVATEDATA])
    {    			
		sBrowserFuncs->retainobject(AppliObj->privateData);
		OBJECT_TO_NPVARIANT(AppliObj->privateData, *result);	
    	fctresult = true;
    }
    else  if (name == v_APPLICATIONPropertyIdentifiers[kAPPLICATION_ID_PROPERTY_VISIBLE])
    {    			
		BOOLEAN_TO_NPVARIANT(AppliObj->visible, *result);
		fctresult = true;
    }
    else
		
    return fctresult;
}
예제 #6
0
// Variant value must be released with NPReleaseVariantValue()
void convertValueToNPVariant(ExecState* exec, JSValue value, NPVariant* result)
{
    JSLockHolder lock(exec);

    VOID_TO_NPVARIANT(*result);

    if (value.isString()) {
        UString ustring = value.toString(exec)->value(exec);
        CString cstring = ustring.utf8();
        NPString string = { (const NPUTF8*)cstring.data(), static_cast<uint32_t>(cstring.length()) };
        NPN_InitializeVariantWithStringCopy(result, &string);
    } else if (value.isNumber()) {
        DOUBLE_TO_NPVARIANT(value.toNumber(exec), *result);
    } else if (value.isBoolean()) {
        BOOLEAN_TO_NPVARIANT(value.toBoolean(exec), *result);
    } else if (value.isNull()) {
        NULL_TO_NPVARIANT(*result);
    } else if (value.isObject()) {
        JSObject* object = asObject(value);
        if (object->classInfo() == &CRuntimeObject::s_info) {
            CRuntimeObject* runtimeObject = static_cast<CRuntimeObject*>(object);
            CInstance* instance = runtimeObject->getInternalCInstance();
            if (instance) {
                NPObject* obj = instance->getObject();
                _NPN_RetainObject(obj);
                OBJECT_TO_NPVARIANT(obj, *result);
            }
        } else {
            JSGlobalObject* globalObject = exec->dynamicGlobalObject();

            RootObject* rootObject = findRootObject(globalObject);
            if (rootObject) {
                NPObject* npObject = _NPN_CreateScriptObject(0, object, rootObject);
                OBJECT_TO_NPVARIANT(npObject, *result);
            }
        }
    }
}
예제 #7
0
// Variant value must be released with NPReleaseVariantValue()
void convertValueToNPVariant(ExecState* exec, JSValue* value, NPVariant* result)
{
    JSLock lock(false);

    VOID_TO_NPVARIANT(*result);

    if (value->isString()) {
        UString ustring = value->toString(exec);
        CString cstring = ustring.UTF8String();
        NPString string = { (const NPUTF8*)cstring.c_str(), static_cast<uint32_t>(cstring.size()) };
        NPN_InitializeVariantWithStringCopy(result, &string);
    } else if (value->isNumber()) {
        DOUBLE_TO_NPVARIANT(value->toNumber(exec), *result);
    } else if (value->isBoolean()) {
        BOOLEAN_TO_NPVARIANT(value->toBoolean(exec), *result);
    } else if (value->isNull()) {
        NULL_TO_NPVARIANT(*result);
    } else if (value->isObject()) {
        JSObject* object = static_cast<JSObject*>(value);
        if (object->classInfo() == &RuntimeObjectImp::s_info) {
            RuntimeObjectImp* imp = static_cast<RuntimeObjectImp*>(value);
            CInstance* instance = static_cast<CInstance*>(imp->getInternalInstance());
            if (instance) {
                NPObject* obj = instance->getObject();
                _NPN_RetainObject(obj);
                OBJECT_TO_NPVARIANT(obj, *result);
            }
        } else {
            JSGlobalObject* globalObject = exec->dynamicGlobalObject();

            RootObject* rootObject = findRootObject(globalObject);
            if (rootObject) {
                NPObject* npObject = _NPN_CreateScriptObject(0, object, rootObject);
                OBJECT_TO_NPVARIANT(npObject, *result);
            }
        }
    }
}
예제 #8
0
파일: ewk_js.cpp 프로젝트: dog-god/iptv
static Eina_Bool ewk_js_variant_to_npvariant(const Ewk_JS_Variant* data, NPVariant* result)
{
    EINA_SAFETY_ON_NULL_RETURN_VAL(data, false);
    EINA_SAFETY_ON_NULL_RETURN_VAL(result, false);
    const char* string_value;

    switch (data->type) {
    case EWK_JS_VARIANT_VOID:
        VOID_TO_NPVARIANT(*result);
        break;
    case EWK_JS_VARIANT_NULL:
        NULL_TO_NPVARIANT(*result);
        break;
    case EWK_JS_VARIANT_INT32:
        INT32_TO_NPVARIANT(data->value.i, *result);
        break;
    case EWK_JS_VARIANT_DOUBLE:
        DOUBLE_TO_NPVARIANT(data->value.d, *result);
        break;
    case EWK_JS_VARIANT_STRING:
        string_value = eina_stringshare_add(data->value.s);
        if (string_value)
            STRINGZ_TO_NPVARIANT(string_value, *result);
        else
            return false;
        break;
    case EWK_JS_VARIANT_BOOL:
        BOOLEAN_TO_NPVARIANT(data->value.b, *result);
        break;
    case EWK_JS_VARIANT_OBJECT:
        OBJECT_TO_NPVARIANT(reinterpret_cast<NPObject*>(data->value.o), *result);
        break;
    default:
        return false;
    }

    return true;
}
예제 #9
0
bool
xplayerConeVideo::InvokeByIndex (int aIndex,
                                 const NPVariant *argv,
                                 uint32_t argc,
                                 NPVariant *_result)
{
    XPLAYER_LOG_INVOKE (aIndex, xplayerConeVideo);

    switch (Methods (aIndex)) {
    case eToggleFullscreen: {
        /* FIXMEchpe this sucks */
        NPVariant fullscreen;
        BOOLEAN_TO_NPVARIANT (!Plugin()->IsFullscreen(), fullscreen);
        return SetPropertyByIndex (eFullscreen, &fullscreen);
    }

    case eToggleTeletext:
        XPLAYER_WARN_INVOKE_UNIMPLEMENTED (aIndex, xplayerConeVideo);
        return VoidVariant (_result);
    }

    return false;
}
예제 #10
0
static bool pluginGetProperty(NPObject* obj, NPIdentifier name, NPVariant* result)
{
    PluginObject* plugin = reinterpret_cast<PluginObject*>(obj);
    if (name == pluginPropertyIdentifiers[ID_PROPERTY_PROPERTY]) {
        STRINGZ_TO_NPVARIANT("property", *result);
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_EVENT_LOGGING]) {
        BOOLEAN_TO_NPVARIANT(plugin->eventLogging, *result);
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_LOG_DESTROY]) {
        BOOLEAN_TO_NPVARIANT(plugin->logDestroy, *result);
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_HAS_STREAM]) {
        BOOLEAN_TO_NPVARIANT(plugin->stream != 0, *result);
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_TEST_OBJECT]) {
        NPObject* testObject = plugin->testObject;
        browser->retainobject(testObject);
        OBJECT_TO_NPVARIANT(testObject, *result);
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_RETURN_ERROR_FROM_NEWSTREAM]) {
        BOOLEAN_TO_NPVARIANT(plugin->returnErrorFromNewStream, *result);
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_PRIVATE_BROWSING_ENABLED]) {
        NPBool privateBrowsingEnabled = FALSE;
        browser->getvalue(plugin->npp, NPNVprivateModeBool, &privateBrowsingEnabled);
        BOOLEAN_TO_NPVARIANT(privateBrowsingEnabled, *result);
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_CACHED_PRIVATE_BROWSING_ENABLED]) {
        BOOLEAN_TO_NPVARIANT(plugin->cachedPrivateBrowsingMode, *result);
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_PROPERTY_THROW_EXCEPTION_PROPERTY]) {
        browser->setexception(obj, "plugin object testThrowExceptionProperty SUCCESS");
        return true;
    } else if (name == pluginPropertyIdentifiers[ID_LAST_SET_WINDOW_ARGUMENTS]) {
        char* buf = static_cast<char*>(browser->memalloc(256));
        snprintf(buf, 256, "x: %d, y: %d, width: %u, height: %u, clipRect: (%u, %u, %u, %u)", (int)plugin->lastWindow.x, (int)plugin->lastWindow.y, (unsigned)plugin->lastWindow.width, (unsigned)plugin->lastWindow.height,
            plugin->lastWindow.clipRect.left, plugin->lastWindow.clipRect.top, plugin->lastWindow.clipRect.right - plugin->lastWindow.clipRect.left, plugin->lastWindow.clipRect.bottom - plugin->lastWindow.clipRect.top);

        STRINGZ_TO_NPVARIANT(buf, *result);
        return true;
    }

    return false;
}
예제 #11
0
void testNPRuntime(NPP npp)
{
    NPObject* windowScriptObject;
    browser->getvalue(npp, NPNVWindowNPObject, &windowScriptObject);

    // Invoke
    NPIdentifier testNPInvoke = browser->getstringidentifier("testNPInvoke");
    NPVariant args[7];
    
    VOID_TO_NPVARIANT(args[0]);
    NULL_TO_NPVARIANT(args[1]);
    BOOLEAN_TO_NPVARIANT(true, args[2]);
    INT32_TO_NPVARIANT(242, args[3]);
    DOUBLE_TO_NPVARIANT(242.242, args[4]);
    STRINGZ_TO_NPVARIANT("Hello, World", args[5]);
    OBJECT_TO_NPVARIANT(windowScriptObject, args[6]);
    
    NPVariant result;
    if (browser->invoke(npp, windowScriptObject, testNPInvoke, args, 7, &result))
        browser->releasevariantvalue(&result);
    
    browser->releaseobject(windowScriptObject);
}
//virtual 
void PluginMethodListenOnFile::OnError(const char* message, unsigned int len) {
  NPVariant args[2];
  NPVariant ret_val;

  BOOLEAN_TO_NPVARIANT(
    false,
    args[0]);

  STRINGN_TO_NPVARIANT(
    message,
    len,
    args[1]);

  // fire callback
  NPN_InvokeDefault(
    npp_,
    callback_,
    args,
    2,
    &ret_val);

  NPN_ReleaseVariantValue(&ret_val);
}
예제 #13
0
파일: plugin.cpp 프로젝트: jiaofeng/COBA
// This function is equivalent to the following JavaScript function:
// function FireEvent(strEventType, strDetail) {
//   var event = document.createEvent("CustomEvent");
//   event.initCustomEvent(strEventType, true, true, strDetail);
//   pluginObject.dispatchEvent(event);
// }
// 
// Uses following JavaScript code to listen to the event fired:
// pluginObject.addEventListener(strEventType, function(event) {
//    alert(event.detail);
// }
BOOL CPlugin::FireEvent(const CString &strEventType, const CString &strDetail)
{
  BOOL bOK = FALSE;
  NPObject* pWindow = NULL;
  NPVariant vDocument;
  VOID_TO_NPVARIANT(vDocument);
  NPVariant vEvent;
  NPObject* pDocument = NULL;
  VOID_TO_NPVARIANT(vEvent);
  NPObject *pEvent = NULL;
  NPObject* pPlugin = NULL;

  try
  {
    // get window object
    if (NPN_GetValue(m_pNPInstance, NPNVWindowNPObject, &pWindow) != NPERR_NO_ERROR || pWindow == NULL)
    {
      throw CString(_T("Cannot get window"));
    }

    // get window.document
    bOK = NPN_GetProperty(m_pNPInstance, pWindow, NPN_GetStringIdentifier("document"), &vDocument);
    if (!NPVARIANT_IS_OBJECT(vDocument) || !bOK)
    {
      throw CString(_T("Cannot get window.document"));
    }
    pDocument = NPVARIANT_TO_OBJECT(vDocument);

    // var event = document.createEvent("CustomEvent");
    if (pDocument) 
    {
      NPVariant arg;
      STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(_T("CustomEvent")), arg);
      bOK = NPN_Invoke(m_pNPInstance, pDocument, NPN_GetStringIdentifier("createEvent"), &arg, 1, &vEvent);
      NPN_ReleaseVariantValue(&arg);
      if (!NPVARIANT_IS_OBJECT(vEvent) || !bOK)
      {
        throw CString(_T("Cannot document.createEvent"));
      }
    }
    else 
    {
      throw CString(_T("window.document is null"));
    }
    pEvent = NPVARIANT_TO_OBJECT(vEvent);;

    // event.initCustomEvent(strEventType, true, true, strDetail);
    if (pEvent)
    {
      NPVariant args[4];
      STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(strEventType), args[0]);
      BOOLEAN_TO_NPVARIANT(true, args[1]);
      BOOLEAN_TO_NPVARIANT(true, args[2]);
      STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(strDetail), args[3]);
      NPVariant vResult;
      bOK = NPN_Invoke(m_pNPInstance, pEvent, NPN_GetStringIdentifier("initCustomEvent"), args, 4, &vResult);
      for (int i=0; i<4; i++)
      {
        NPN_ReleaseVariantValue(&args[i]);
      }
      NPN_ReleaseVariantValue(&vResult);
      if (!bOK)
      {
        throw CString(_T("Cannot event.initCustomEvent"));
      }
    }
    else
    {
      throw CString(_T("event is null"));
    }

    // get plugin object
    if (NPN_GetValue(m_pNPInstance, NPNVPluginElementNPObject, &pPlugin) != NPERR_NO_ERROR || pPlugin == NULL)
    {
      throw CString(_T("Cannot get window"));
    }


    // pluginObject.dispatchEvent(event);
    NPVariant vNotCanceled; 
    bOK = NPN_Invoke(m_pNPInstance, pPlugin, NPN_GetStringIdentifier("dispatchEvent"), &vEvent, 1, &vNotCanceled);
    NPN_ReleaseVariantValue(&vEvent);
    if (!bOK || !NPVARIANT_IS_BOOLEAN(vNotCanceled)) 
    {
      throw CString(_T("Cannot dispatchEvent"));
    }
    if (NPVARIANT_TO_BOOLEAN(vNotCanceled) != true)
    {
      throw CString(_T("Event is canceled"));
    }
  }
  catch (CString strMessage)
  {
    TRACE(_T("[CPlugin::FireEvent Exception] %s"), strMessage);
    bOK = FALSE;
  }
  if (pPlugin != NULL) NPN_ReleaseObject(pPlugin);
  if (!NPVARIANT_IS_VOID(vEvent))	NPN_ReleaseVariantValue(&vEvent);
  if (!NPVARIANT_IS_VOID(vDocument))	NPN_ReleaseVariantValue(&vDocument);
  if (pWindow != NULL) NPN_ReleaseObject(pWindow);
  return bOK;
}
예제 #14
0
bool SetReturnValue(const bool value, NPVariant &result) {
  BOOLEAN_TO_NPVARIANT(value, result);
  return true;
}
예제 #15
0
void convertJavaValueToNPVariant(JavaValue value, NPVariant* result)
{
    switch (value.m_type) {
    case JavaTypeVoid:
        {
            VOID_TO_NPVARIANT(*result);
        }
        break;

    case JavaTypeObject:
        {
            // If the JavaValue is a String object, it should have type JavaTypeString.
            if (value.m_objectValue)
                OBJECT_TO_NPVARIANT(JavaInstanceToNPObject(value.m_objectValue.get()), *result);
            else
                VOID_TO_NPVARIANT(*result);
        }
        break;

    case JavaTypeString:
        {
            const char* utf8String = strdup(value.m_stringValue.utf8().data());
            // The copied string is freed in NPN_ReleaseVariantValue (see npruntime.cpp)
            STRINGZ_TO_NPVARIANT(utf8String, *result);
        }
        break;

    case JavaTypeBoolean:
        {
            BOOLEAN_TO_NPVARIANT(value.m_booleanValue, *result);
        }
        break;

    case JavaTypeByte:
        {
            INT32_TO_NPVARIANT(value.m_byteValue, *result);
        }
        break;

    case JavaTypeChar:
        {
            INT32_TO_NPVARIANT(value.m_charValue, *result);
        }
        break;

    case JavaTypeShort:
        {
            INT32_TO_NPVARIANT(value.m_shortValue, *result);
        }
        break;

    case JavaTypeInt:
        {
            INT32_TO_NPVARIANT(value.m_intValue, *result);
        }
        break;

        // TODO: Check if cast to double is needed.
    case JavaTypeLong:
        {
            DOUBLE_TO_NPVARIANT(value.m_longValue, *result);
        }
        break;

    case JavaTypeFloat:
        {
            DOUBLE_TO_NPVARIANT(value.m_floatValue, *result);
        }
        break;

    case JavaTypeDouble:
        {
            DOUBLE_TO_NPVARIANT(value.m_doubleValue, *result);
        }
        break;

    case JavaTypeInvalid:
    default:
        {
            VOID_TO_NPVARIANT(*result);
        }
        break;
    }
}
예제 #16
0
파일: shocker.cpp 프로젝트: 499940913/moon
void
ShockerScriptableControlObject::LogPerfEvent (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	Shocker_FailTestFast ("LogPerfEvent (): Not implemented");
	BOOLEAN_TO_NPVARIANT (true, *result);
}
예제 #17
0
	bool ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant *result)
	{
		if (m_pMainWindow == NULL)
			return false;

		// readonly property {string} URL
		if (name == m_URLID) 
		{
			CString URL = m_pMainWindow->GetURL();
			STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(URL), *result);
			return true;
		} 
		// readonly property {title} LocationURL
		else if (name == m_TitleID)
		{
			CString title = m_pMainWindow->GetTitle();
			STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(title), *result);
			return true;
		}
		// readonly property {boolean} CanRefresh
		else if (name == m_CanRefreshID)
		{
			BOOL canRefresh = m_pMainWindow->GetCanRefresh();
			BOOLEAN_TO_NPVARIANT(canRefresh, *result);
			return true;
		}
		// readonly property {boolean} CanStop
		else if (name == m_CanStopID)
		{
			BOOL canStop = m_pMainWindow->GetCanStop();
			BOOLEAN_TO_NPVARIANT(canStop, *result);
			return true;
		}
		// readonly property {boolean} CanBack
		else if (name == m_CanBackID)
		{
			BOOL canBack = m_pMainWindow->GetCanBack();
			BOOLEAN_TO_NPVARIANT(canBack, *result);
			return true;
		}
		// readonly property {boolean} CanForward
		else if (name == m_CanForwardID)
		{
			BOOL canForward = m_pMainWindow->GetCanForward();
			BOOLEAN_TO_NPVARIANT(canForward, *result);
			return true;
		}
		// readonly property {boolean} CanCopy
		else if (name == m_CanCopyID)
		{
			BOOL canCopy = m_pMainWindow->GetCanCopy();
			BOOLEAN_TO_NPVARIANT(canCopy, *result);
			return true;
		}
		// readonly property {boolean} CanCut
		else if (name == m_CanCutID)
		{
			BOOL canCut = m_pMainWindow->GetCanCut();
			BOOLEAN_TO_NPVARIANT(canCut, *result);
			return true;
		}
		// readonly property {boolean} CanPaste
		else if (name == m_CanPasteID)
		{
			BOOL canPaste = m_pMainWindow->GetCanPaste();
			BOOLEAN_TO_NPVARIANT(canPaste, *result);
			return true;
		}
		// readonly property {boolean} CanSelectAll
		else if (name == m_CanSelectAllID)
		{
			BOOL canSelectAll = m_pMainWindow->GetCanSelectAll();
			BOOLEAN_TO_NPVARIANT(canSelectAll, *result);
			return true;
		}
		// readonly property {boolean} Progress
		else if (name == m_ProgressID)
		{
			INT32_TO_NPVARIANT(m_pMainWindow->GetProgress(),*result);
			return true;
		}

		VOID_TO_NPVARIANT(*result);
		return true;
	}
예제 #18
0
bool NP_Invoke(NPObject* obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result){
	char * name = npnfuncs->utf8fromidentifier(methodName);

	if(strcmp(name, METHOD_TIME) == 0 && argCount > 0 && 
	NPVARIANT_IS_STRING(args[0])
	){

		char * filename = ArgToStr(args[0]);
		struct stat * buf = (struct stat *)malloc(sizeof(struct stat));

		stat(filename, buf);
		free(filename);

		INT32_TO_NPVARIANT(buf->st_mtime, *result);
		free(buf);

		return true;
	}else 
	if(strcmp(name, METHOD_GET) == 0 && argCount > 0 &&
	NPVARIANT_IS_STRING(args[0])
	){
		char * filename = ArgToStr(args[0]);

		//logmsg(filename);
		FILE * f = fopen(filename, "r");
		if(f) {
			fseek(f, 0 , SEEK_END);
			long int size = ftell(f);

			rewind(f);

			char * buf = (char *)npnfuncs->memalloc(size);
			memset(buf, 0, size);
			fread(buf, 1, size, f);
			fclose(f);

			//logmsg(buf);
			

			STRINGN_TO_NPVARIANT(buf, size, *result);

			//npnfuncs->memfree(buf);
		}

		free(filename);
		return true;
	}else 
	if(strcmp(name, METHOD_SET) == 0 && argCount > 1 &&
	NPVARIANT_IS_STRING(args[0]) && NPVARIANT_IS_STRING(args[1])
	){
		char * filename = ArgToStr(args[0]);
		char * content = ArgToStr(args[1]);

		FILE * f = fopen(filename, "w");
		bool succ = false;
		if(f) {
			fputs(content, f);
			succ = ferror(f) == 0;
			fclose(f);
		}

		free(filename);
		free(content);

		BOOLEAN_TO_NPVARIANT(succ, *result);
		return true;
	}
	return false;	
}
예제 #19
0
파일: shocker.cpp 프로젝트: 499940913/moon
void
ShockerScriptableControlObject::IsInputLocaleInstalled (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	Shocker_FailTestFast ("IsInputLocaleInstalled: Not implemented");
	BOOLEAN_TO_NPVARIANT (true, *result);
}
예제 #20
0
파일: shocker.cpp 프로젝트: 499940913/moon
void
RenderDataCapturerObject::GetFrameData (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	Shocker_FailTestFast ("RenderDataCapturerObject::GetFrameData (): Not implemented");
	BOOLEAN_TO_NPVARIANT (true, *result);
}
예제 #21
0
파일: shocker.cpp 프로젝트: 499940913/moon
void
ShockerScriptableControlObject::StopWebCamWriter (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	Shocker_FailTestFast ("StopWebCamWriter (): Not implemented");
	BOOLEAN_TO_NPVARIANT (true, *result);
}
예제 #22
0
파일: shocker.cpp 프로젝트: 499940913/moon
void
ShockerScriptableControlObject::UninitializePerfProvider (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	Shocker_FailTestFast ("UninitializePerfProvider (): Not implemented");
	BOOLEAN_TO_NPVARIANT (true, *result);
}
예제 #23
0
/**
 * Read process output data
 *
 * @param p Process to read data from
 * @param result Result string on success, false otherwise
 * @return True on success, false otherwise
 */
static bool
process_read(process *p, NPVariant *result)
{
    int len;
    int status;
    NPString str;
    NPUTF8 *chars;

    /* return if the process is not running */
    if (!p->running) {
        DEBUG_STR("shell->read(): false (not running)");
        BOOLEAN_TO_NPVARIANT(false, *result);
        return true;
    }

    /* read from pipe */
    if ((len = read(p->pipe[0], buffer, BUFLEN - 1)) > 0) {
        /* data read successfully */

        /* be sure to terminate string by null-character */
        buffer[len] = '\0';

        /* allocate fill the result string */
        chars = browser->memalloc((len + 1) * sizeof(*chars));
        memcpy(chars, buffer, len + 1);
        STRING_UTF8CHARACTERS(str) = chars;
        STRING_UTF8LENGTH(str) = len;

        result->type = NPVariantType_String;
        result->value.stringValue = str;

        DEBUG_STR("shell->read(): string(len=%d)", len);

        return true;

    } else if (len == -1) {
        /* error */

        if (errno == EAGAIN || errno == EWOULDBLOCK) {
            /* non-blocking reading, continue */

            DEBUG_STR("shell->read(): false (no data, continue)");

            BOOLEAN_TO_NPVARIANT(false, *result);
            return true;

        } else {
            /* error */

            DEBUG_STR("shell->read(): false (read error %d)", errno);

            BOOLEAN_TO_NPVARIANT(false, *result);
            return false;
        }

    } else if (len == 0) {
        /* no data available */

        /* test if child became a zombie */
        waitpid(p->pid, &status, WNOHANG);

        if (WIFEXITED(status)) {
            /* child has finished */

            /* close read pipe */
            close(p->pipe[0]);
            p->running = false;

            DEBUG_STR("shell->read(): false (process has finished) ");

            /* clean it's status from process table */
            waitpid(p->pid, NULL, 0);

        } else {

            DEBUG_STR("shell->read(): false (NOT IMPLEMENTED - end of file) ");

        }

        BOOLEAN_TO_NPVARIANT(false, *result);
        return true;
    }
}
예제 #24
0
NPError 
StatementObject::GetVariant(int index, NPVariant *value)
{
  if (!m_hstmt) {
    NPN_SetException(this, "Statement isn't initialized");
    return NPERR_GENERIC_ERROR;
  }

  if (index < 0 || index >= m_columnCount) {
    NPN_SetException(this, "Column index is out of range");
    return NPERR_GENERIC_ERROR;
  }

  SQLLEN cbInd;
  int type;
  NPError rc;

  GetColumnType(index, &type);
  index++;


  NULL_TO_NPVARIANT(*value);

  switch (type) {
    case VALUE_TYPE_BIT:
      {
        bool v_bool;
        rc = CheckStmtRC(SQLGetData(m_hstmt, index, SQL_C_BIT, &v_bool, 0, &cbInd));
        if (rc != NPERR_NO_ERROR)
          return rc;
        if (cbInd != SQL_NULL_DATA) 
          BOOLEAN_TO_NPVARIANT(v_bool, *value);
        break;
      }
    case VALUE_TYPE_TINYINT:
    case VALUE_TYPE_SMALLINT:
    case VALUE_TYPE_BIGINT:
    case VALUE_TYPE_INTEGER:
      {
        SQLINTEGER v_int32;
        rc = CheckStmtRC(SQLGetData(m_hstmt, index, SQL_C_LONG, &v_int32, 0, &cbInd));
        if (rc != NPERR_NO_ERROR)
          return rc;
        if (cbInd != SQL_NULL_DATA)
          INT32_TO_NPVARIANT(v_int32, *value);
        break;
      }

    case VALUE_TYPE_FLOAT:
    case VALUE_TYPE_REAL:
    case VALUE_TYPE_DOUBLE:
      {
        double v_double;
        rc = CheckStmtRC(SQLGetData(m_hstmt, index, SQL_C_DOUBLE, &v_double, 0, &cbInd));
        if (rc != NPERR_NO_ERROR)
          return rc;
        if (cbInd != SQL_NULL_DATA)
          DOUBLE_TO_NPVARIANT(v_double, *value);
        break;
      }

/**
    case VALUE_TYPE_BINARY:
    case VALUE_TYPE_VARBINARY:
    case VALUE_TYPE_LONGVARBINARY:
      {
        const char hexString[] = "0123456789ABCDEF";
        SQLLEN len;
        SQLWCHAR buf[32];
        unsigned char *pin;
        char *pout;

        rc = CheckStmtRC(SQLGetData(m_hstmt, index, SQL_C_BINARY, buf, 0, &len));
        if (rc != NPERR_NO_ERROR)
          return rc;

        if (len == SQL_NO_TOTAL) 
          {
            const SQLLEN dwUnit = 8192;
            unsigned char *pBuff;
            unsigned char *pData = NULL;
            SQLLEN dwAvialable;
            SQLLEN bufSize = dwUnit;
            char *data = NULL;

            pData = (unsigned char *)NPN_MemAlloc(bufSize);
            if (!pData) {
              NPN_SetException(this, "Memory allocation error");
              return NPERR_GENERIC_ERROR;
            }

            len = 0;
            pBuff = pData;
            while(1) {
              SQLRETURN ret;
              pBuff = pData + len;
              ret = SQLGetData(m_hstmt, index, SQL_C_BINARY, pBuff, dwUnit, &dwAvialable);
              if (ret == SQL_NO_DATA_FOUND)
                break;
              if ((rc = CheckStmtRC(ret)) != NPERR_NO_ERROR)
                return rc;
              if (dwAvialable < dwUnit) {
                len += dwAvialable;
                break;
              }
              len += dwUnit;
              bufSize += dwUnit;
              unsigned char* tmp = (unsigned char*)NPN_MemAlloc(bufSize);
              if (!pBuff) {
                NPN_SetException(this, "Memory allocation error");
                return NPERR_GENERIC_ERROR;
              }
              memcpy(pBuff, pData, len);
              NPN_MemFree(pData);
              pData = pBuff;
              pBuff = pData + len;
            }

            data = (char*)NPN_MemAlloc(len*2+1);
            if (!data) {
              NPN_MemFree(pData);
              NPN_SetException(this, "Memory allocation error");
              return NPERR_GENERIC_ERROR;
            }
            pout = data;
            pin = pData;
            while(len--) {
              unsigned char binVal = *pin++;
              *pout++ = hexString[(binVal >> 4) & 0xf];
              *pout++ = hexString[binVal & 0xf];
            }
            *pout = 0;
            NPN_MemFree(pData);
            STRING_TO_NPVARIANT(data, *value);

          }
          else if (len != SQL_NULL_DATA) 
          {
            unsigned char *pData;
            SQLLEN bufSize = len + 1;
            char *data = NULL;

            pData = (unsigned char *)NPN_MemAlloc(bufSize);
            if (!pData) {
              NPN_SetException(this, "Memory allocation error");
              return NPERR_GENERIC_ERROR;
            }

            rc = CheckStmtRC(SQLGetData(m_hstmt, index, SQL_C_BINARY, pData, bufSize, &len));
            if (rc != NPERR_NO_ERROR)
              return rc;

            data = (char*)NPN_MemAlloc(len*2+1);
            if (!data) {
              NPN_MemFree(pData);
              NPN_SetException(this, "Memory allocation error");
              return NPERR_GENERIC_ERROR;
            }
            pout = data;
            pin = pData;
            while(len--) {
              unsigned char binVal = *pin++;
              *pout++ = hexString[(binVal >> 4) & 0xf];
              *pout++ = hexString[binVal & 0xf];
            }
            *pout = 0;
            NPN_MemFree(pData);
            STRING_TO_NPVARIANT(data, *value);
          }

        break;
      }
**/

    case VALUE_TYPE_BINARY:
    case VALUE_TYPE_VARBINARY:
    case VALUE_TYPE_LONGVARBINARY:

    case VALUE_TYPE_GUID:

    case VALUE_TYPE_CHAR:
    case VALUE_TYPE_VARCHAR:
    case VALUE_TYPE_LONGVARCHAR:
    case VALUE_TYPE_WCHAR:
    case VALUE_TYPE_WVARCHAR:
    case VALUE_TYPE_WLONGVARCHAR:

    case VALUE_TYPE_UNKNOWN:

    case VALUE_TYPE_NUMERIC:
    case VALUE_TYPE_DECIMAL:

    case VALUE_TYPE_DATE:
    case VALUE_TYPE_TIME:
    case VALUE_TYPE_TIMESTAMP:
    default:
      {
        SQLLEN len;
        SQLLEN dtype;
        SQLWCHAR buf[32];

        rc = CheckStmtRC(SQLColAttributesW (m_hstmt, index, SQL_COLUMN_TYPE, NULL, 0, NULL, &dtype));
        if (rc != NPERR_NO_ERROR)
          return rc;

        if (dtype == SQL_LONGVARBINARY || dtype == SQL_VARBINARY || dtype == SQL_BINARY ||
            dtype == SQL_LONGVARCHAR || dtype == SQL_VARCHAR || dtype == SQL_CHAR ||
            dtype == SQL_WLONGVARCHAR || dtype == SQL_WVARCHAR || dtype == SQL_WCHAR)
        {
          rc = CheckStmtRC(SQLGetData(m_hstmt, index, SQL_C_WCHAR, buf, 0, &len));
          if (rc != NPERR_NO_ERROR)
            return rc;

          if (len == SQL_NO_TOTAL) 
          {
            const SQLLEN dwUnit = 4096*sizeof(SQLWCHAR)+sizeof(SQLWCHAR);
            unsigned char *pBuff = NULL;
            unsigned char *pData = NULL;
            SQLLEN dwAvialable;
            SQLLEN bufSize = dwUnit;
            char *data = NULL;
            SQLRETURN ret;

            pData = (unsigned char *)NPN_MemAlloc(bufSize);
            if (!pData) {
              NPN_SetException(this, "Memory allocation error");
              return NPERR_GENERIC_ERROR;
            }

            len = 0;
            while(1) {
              pBuff = pData + len;
              ret = SQLGetData(m_hstmt, index, SQL_C_WCHAR, pBuff, dwUnit, &dwAvialable);
              if (ret == SQL_NO_DATA_FOUND)
                break;
              if ((rc = CheckStmtRC(ret)) != NPERR_NO_ERROR)
                return rc;
              if (dwAvialable < dwUnit) {
                len += dwAvialable;
                break;
              }
              len += dwUnit - sizeof(SQLWCHAR);
              bufSize += dwUnit - sizeof(SQLWCHAR);
              unsigned char* tmp = (unsigned char*)NPN_MemAlloc(bufSize);
              if (!tmp) {
                NPN_SetException(this, "Memory allocation error");
                return NPERR_GENERIC_ERROR;
              }
              memcpy(tmp, pData, len);
              NPN_MemFree(pData);
              pData = tmp;
            }

            data = strdup_WtoU8((SQLWCHAR *)pData);
            if (!data) {
              NPN_MemFree(pData);
              NPN_SetException(this, "Memory allocation error");
              return NPERR_GENERIC_ERROR;
            }
            NPN_MemFree(pData);
            STRING_TO_NPVARIANT(data, *value);

          }
          else if (len != SQL_NULL_DATA) 
          {
            unsigned char *pData;
            SQLLEN bufSize = len + sizeof(SQLWCHAR);
            char *data = NULL;

            pData = (unsigned char *)NPN_MemAlloc(bufSize);
            if (!pData) {
              NPN_SetException(this, "Memory allocation error");
              return NPERR_GENERIC_ERROR;
            }

            rc = CheckStmtRC(SQLGetData(m_hstmt, index, SQL_C_WCHAR, pData, bufSize, &len));
            if (rc != NPERR_NO_ERROR)
              return rc;

            data = strdup_WtoU8((SQLWCHAR *)pData);
            if (!data) {
              NPN_MemFree(pData);
              NPN_SetException(this, "Memory allocation error");
              return NPERR_GENERIC_ERROR;
            }
            NPN_MemFree(pData);
            STRING_TO_NPVARIANT(data, *value);
          }
        } else {
          rc = CheckStmtRC(SQLGetData(m_hstmt, index, SQL_C_WCHAR, buf, sizeof(buf), &len));
          if (rc != NPERR_NO_ERROR)
            return rc;
          if (len != SQL_NULL_DATA) {
            const char *data = strdup_WtoU8(buf);
            if (!data) {
              NPN_SetException(this, "Memory allocation error");
              return NPERR_GENERIC_ERROR;
            }
            STRING_TO_NPVARIANT(data, *value);
          }
        }  
        break;
      }
    }

  return NPERR_NO_ERROR;
}
예제 #25
0
static bool pluginInvoke(NPObject *header, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result)
{
    PluginObject *obj = (PluginObject *)header;
    if (name == pluginMethodIdentifiers[ID_TEST_CALLBACK_METHOD]) {
        // call whatever method name we're given
        if (argCount > 0 && NPVARIANT_IS_STRING(args[0])) {
            NPObject *windowScriptObject;
            browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject);

            NPUTF8* callbackString = createCStringFromNPVariant(&args[0]);
            NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString);
            free(callbackString);

            NPVariant browserResult;
            browser->invoke(obj->npp, windowScriptObject, callbackIdentifier, 0, 0, &browserResult);
            browser->releasevariantvalue(&browserResult);

            VOID_TO_NPVARIANT(*result);
            return true;
        }
    } else if (name == pluginMethodIdentifiers[ID_TEST_GETURL]) {
        if (argCount == 2 && NPVARIANT_IS_STRING(args[0]) && NPVARIANT_IS_STRING(args[1])) {
            NPUTF8* urlString = createCStringFromNPVariant(&args[0]);
            NPUTF8* targetString = createCStringFromNPVariant(&args[1]);
            browser->geturl(obj->npp, urlString, targetString);
            free(urlString);
            free(targetString);

            VOID_TO_NPVARIANT(*result);
            return true;
        } else if (argCount == 1 && NPVARIANT_IS_STRING(args[0])) {
            NPUTF8* urlString = createCStringFromNPVariant(&args[0]);
            browser->geturl(obj->npp, urlString, 0);
            free(urlString);

            VOID_TO_NPVARIANT(*result);
            return true;
        }
    } else if (name == pluginMethodIdentifiers[ID_REMOVE_DEFAULT_METHOD]) {
        pluginClass.invokeDefault = 0;
        VOID_TO_NPVARIANT(*result);
        return true;
    } else if (name == pluginMethodIdentifiers[ID_TEST_DOM_ACCESS]) {
        testDOMAccess(obj);
        VOID_TO_NPVARIANT(*result);
        return true;
    } else if (name == pluginMethodIdentifiers[ID_TEST_GET_URL_NOTIFY]) {
        if (argCount == 3
          && NPVARIANT_IS_STRING(args[0])
          && (NPVARIANT_IS_STRING(args[1]) || NPVARIANT_IS_NULL(args[1]))
          && NPVARIANT_IS_STRING(args[2])) {
            NPUTF8* urlString = createCStringFromNPVariant(&args[0]);
            NPUTF8* targetString = (NPVARIANT_IS_STRING(args[1]) ? createCStringFromNPVariant(&args[1]) : NULL);
            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;
        }
    } else if (name == pluginMethodIdentifiers[ID_TEST_INVOKE_DEFAULT] && NPVARIANT_IS_OBJECT(args[0])) {
        NPObject *callback = NPVARIANT_TO_OBJECT(args[0]);
        
        NPVariant args[1];
        NPVariant browserResult;
        
        STRINGZ_TO_NPVARIANT("test", args[0]);
        bool retval = browser->invokeDefault(obj->npp, callback, args, 1, &browserResult);
        
        if (retval)
            browser->releasevariantvalue(&browserResult);
        
        BOOLEAN_TO_NPVARIANT(retval, *result);
        return true;
    } else if (name == pluginMethodIdentifiers[ID_TEST_ENUMERATE]) {
        if (argCount == 2 && NPVARIANT_IS_OBJECT(args[0]) && NPVARIANT_IS_OBJECT(args[1])) {
            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;
                    browser->invoke(obj->npp, outArray, pushIdentifier, args, 1, &browserResult);
                    browser->releasevariantvalue(&browserResult);
                    browser->memfree(string);
                }
                
                browser->memfree(identifiers);
            }
            
            VOID_TO_NPVARIANT(*result);
            return true;            
        }
        return false;
    } else if (name == pluginMethodIdentifiers[ID_DESTROY_STREAM]) {
        NPError npError = browser->destroystream(obj->npp, obj->stream, NPRES_USER_BREAK);
        INT32_TO_NPVARIANT(npError, *result);
        return true;        
    } else if (name == pluginMethodIdentifiers[ID_TEST_GETINTIDENTIFIER]) {
        if (argCount == 1) {
            NPIdentifier identifier;

            if (NPVARIANT_IS_DOUBLE(args[0])) {
                identifier = browser->getintidentifier((int)NPVARIANT_TO_DOUBLE(args[0]));
                INT32_TO_NPVARIANT((int32)identifier, *result);
                return true;
            } else if (NPVARIANT_IS_INT32(args[0])) {
                identifier = browser->getintidentifier((int)NPVARIANT_TO_INT32(args[0]));
                INT32_TO_NPVARIANT((int32)identifier, *result);
                return true;
            }
        }
    } else if (name == pluginMethodIdentifiers[ID_TEST_EVALUATE] && 
               argCount == 1 && NPVARIANT_IS_STRING(args[0])) {
        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;
    } else if (name == pluginMethodIdentifiers[ID_TEST_GET_PROPERTY] &&
               argCount > 0) {
        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;
    } else if (name == pluginMethodIdentifiers[ID_TEST_GET_PROPERTY_RETURN_VALUE] &&
        argCount == 2 && NPVARIANT_IS_OBJECT(args[0]) && NPVARIANT_IS_STRING(args[1])) {
        NPUTF8* propertyString = createCStringFromNPVariant(&args[1]);
        NPIdentifier propertyIdentifier = browser->getstringidentifier(propertyString);
        free(propertyString);

        NPVariant variant;
        bool retval = browser->getproperty(obj->npp, NPVARIANT_TO_OBJECT(args[0]), propertyIdentifier, &variant);
        if (retval)
            browser->releasevariantvalue(&variant);

        BOOLEAN_TO_NPVARIANT(retval, *result);
        return true;
    } else if (name == pluginMethodIdentifiers[ID_TEST_CALLBACK_METHOD_RET]) {
        // call whatever method name we're given, and pass it the 'window' obj.
        // we expect the function to return its argument.
        if (argCount > 0 && NPVARIANT_IS_STRING(args[0])) {
            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)) {
                // 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(browserResult), *result);
            } else {                
                browser->releasevariantvalue(&browserResult);
                VOID_TO_NPVARIANT(*result);
            }

            return true;
        }
    } else if (name == pluginMethodIdentifiers[ID_TEST_CREATE_TEST_OBJECT]) {
        NPObject *testObject = browser->createobject(obj->npp, getTestClass());
        //assert(testObject->referenceCount == 1);
        OBJECT_TO_NPVARIANT(testObject, *result);
        return true;
    } else if (name == pluginMethodIdentifiers[ID_TEST_PASS_TEST_OBJECT]) {
        // call whatever method name we're given, and pass it our second
        // argument.
        if (argCount > 1 && NPVARIANT_IS_STRING(args[0])) {
            NPObject *windowScriptObject;
            browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject);

            NPUTF8* callbackString = createCStringFromNPVariant(&args[0]);
            NPIdentifier callbackIdentifier = browser->getstringidentifier(callbackString);
            free(callbackString);

            NPVariant browserResult;
            browser->invoke(obj->npp, windowScriptObject, callbackIdentifier, &args[1], 1, &browserResult);
            browser->releasevariantvalue(&browserResult);

            VOID_TO_NPVARIANT(*result);
            return true;
        }
    } else if (name == pluginMethodIdentifiers[ID_TEST_CLONE_OBJECT]) {
        // Create another instance of the same class
        NPObject *new_object = browser->createobject(obj->npp, &pluginClass);
        //assert(new_object->referenceCount == 1);
        OBJECT_TO_NPVARIANT(new_object, *result);
        return true;
    } else if (name == pluginMethodIdentifiers[ID_TEST_SCRIPT_OBJECT_INVOKE]) {
        if (argCount > 1 && NPVARIANT_IS_STRING(args[0])) {
            // Invoke a script callback to get a script NPObject. Then call
            // a method on the script NPObject passing it a freshly created
            // NPObject.
            // Arguments:
            // arg1:  Callback that returns a script object.
            // arg2:  Name of the method to call on the script object returned 
            //        from the callback
            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);
            }
            return true;
        }
    }
    return false;
}
예제 #26
0
파일: shocker.cpp 프로젝트: 499940913/moon
void
ShockerScriptableControlObject::SwitchToHighContrastScheme (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	Shocker_FailTestFast ("SwitchToHighContrastScheme: Not implemented");
	BOOLEAN_TO_NPVARIANT (true, *result);
}
예제 #27
0
bool
StatementObject::Invoke(NPIdentifier name, const NPVariant *args,
                               uint32_t argCount, NPVariant *result)
{
//sprintf(tmp, "stmt Invoke [%s]\n", NPN_UTF8FromIdentifier(name)); log(tmp);
  NPError rc;
  VOID_TO_NPVARIANT(*result);
  int index = 0;

  if (name == mc_Init_id) {

    if (argCount < 2) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }
#if 0
    if (!(NPVARIANT_IS_INT32(args[0]) && NPVARIANT_IS_OBJECT(args[1]))) {
      NPN_SetException(this, "Wrong argument type");
      return true;
    }

    SQLHANDLE hdbc = (SQLHANDLE)(long)NPVARIANT_TO_INT32(args[0]);
#else
    if (!(NPVARIANT_IS_OBJECT(args[0]) && NPVARIANT_IS_OBJECT(args[1]))) {
      NPN_SetException(this, "Wrong argument type");
      return true;
    }

    SQLHANDLE hdbc = (SQLHANDLE)NPVARIANT_TO_OBJECT(args[0]);
#endif

    Init(hdbc, NPVARIANT_TO_OBJECT(args[1]));

    return true;

  } else if (name == mc_AddParameter_id) {
    if (argCount < 1) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }

    AddParam(args);
    return true;

  } else if (name == mc_Execute_id) {
    if (argCount < 1) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }
    if (!NPVARIANT_IS_STRING(args[0])) {
      NPN_SetException(this, "Wrong argument type");
      return true;
    }

    Execute((NPString*)&NPVARIANT_TO_STRING(args[0]));
    return true;

  } else if (name == mc_Close_id) {
    Close();
    return true;

  } else if (name == mc_Fetch_id) {
    bool ret;
    rc = Fetch(&ret);
    if (rc != NPERR_NO_ERROR)
      return true;
    BOOLEAN_TO_NPVARIANT(ret, *result);
    return true;

  } else if (name == mc_MoreResults_id) {
    bool ret;
    rc = MoreResults(&ret);
    if (rc != NPERR_NO_ERROR)
      return true;
    BOOLEAN_TO_NPVARIANT(ret, *result);
    return true;

  } else if (name == mc_GetColumnName_id) {
    const char *ret;
    if (argCount < 1) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }

    if (NPVARIANT_IS_INT32(args[0]))
      index = NPVARIANT_TO_INT32(args[0]);
    else if (NPVARIANT_IS_DOUBLE(args[0]))
      index = (int)NPVARIANT_TO_DOUBLE(args[0]);
    else {
      NPN_SetException(this, "Wrong argument type");
      return true;
    }

    rc = GetColumnName(index, &ret);
    if (rc != NPERR_NO_ERROR)
      return true;
    STRING_TO_NPVARIANT(ret, *result);
    return true;

  } else if (name == mc_GetVariant_id) {
    if (argCount < 1) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }

    if (NPVARIANT_IS_INT32(args[0]))
      index = NPVARIANT_TO_INT32(args[0]);
    else if (NPVARIANT_IS_DOUBLE(args[0]))
      index = (int)NPVARIANT_TO_DOUBLE(args[0]);
    else {
      NPN_SetException(this, "Wrong argument type");
      return true;
    }

    GetVariant(index, result);
    return true;

  } else if (name == mc_GetColumnType_id) {
    int ret;
    if (argCount < 1) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }

    if (NPVARIANT_IS_INT32(args[0]))
      index = NPVARIANT_TO_INT32(args[0]);
    else if (NPVARIANT_IS_DOUBLE(args[0]))
      index = (int)NPVARIANT_TO_DOUBLE(args[0]);
    else {
      NPN_SetException(this, "Wrong argument type");
      return true;
    }

    rc = GetColumnType(index, &ret);
    if (rc != NPERR_NO_ERROR)
      return true;
    INT32_TO_NPVARIANT(ret, *result);
    return true;

  } else if (name == mc_IsColumnNullable_id) {
    bool ret;
    if (argCount < 1) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }

    if (NPVARIANT_IS_INT32(args[0]))
      index = NPVARIANT_TO_INT32(args[0]);
    else if (NPVARIANT_IS_DOUBLE(args[0]))
      index = (int)NPVARIANT_TO_DOUBLE(args[0]);
    else {
      NPN_SetException(this, "Wrong argument type");
      return true;
    }

    rc = IsColumnNullable(index, &ret);
    if (rc != NPERR_NO_ERROR)
      return true;
    BOOLEAN_TO_NPVARIANT(ret, *result);
    return true;

  } else if (name == mc_GetTables_id) {
    if (argCount < 4) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[0]) || NPVARIANT_IS_STRING(args[0]))) {
      NPN_SetException(this, "Wrong 1 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[1]) || NPVARIANT_IS_STRING(args[1]))) {
      NPN_SetException(this, "Wrong 2 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[2]) || NPVARIANT_IS_STRING(args[2]))) {
      NPN_SetException(this, "Wrong 3 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[3]) || NPVARIANT_IS_STRING(args[3]))) {
      NPN_SetException(this, "Wrong 4 argument type");
      return true;
    }

    GetTables(&args[0], &args[1], &args[2], &args[3]);
    return true;

  } else if (name == mc_GetColumns_id) {
    if (argCount < 4) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[0]) || NPVARIANT_IS_STRING(args[0]))) {
      NPN_SetException(this, "Wrong 1 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[1]) || NPVARIANT_IS_STRING(args[1]))) {
      NPN_SetException(this, "Wrong 2 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[2]) || NPVARIANT_IS_STRING(args[2]))) {
      NPN_SetException(this, "Wrong 3 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[3]) || NPVARIANT_IS_STRING(args[3]))) {
      NPN_SetException(this, "Wrong 4 argument type");
      return true;
    }

    GetColumns(&args[0], &args[1], &args[2], &args[3]);
    return true;

  } else if (name == mc_GetTypeInfo_id) {
    if (argCount < 1) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }

    if (NPVARIANT_IS_INT32(args[0]))
      index = NPVARIANT_TO_INT32(args[0]);
    else if (NPVARIANT_IS_DOUBLE(args[0]))
      index = (int)NPVARIANT_TO_DOUBLE(args[0]);
    else {
      NPN_SetException(this, "Wrong argument type");
      return true;
    }

    GetTypeInfo(index);
    return true;

  } else if (name == mc_GetPrimaryKeys_id) {
    if (argCount < 3) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[0]) || NPVARIANT_IS_STRING(args[0]))) {
      NPN_SetException(this, "Wrong 1 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[1]) || NPVARIANT_IS_STRING(args[1]))) {
      NPN_SetException(this, "Wrong 2 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[2]) || NPVARIANT_IS_STRING(args[2]))) {
      NPN_SetException(this, "Wrong 3 argument type");
      return true;
    }

    GetPrimaryKeys(&args[0], &args[1], &args[2]);
    return true;

  } else if (name == mc_GetForeignKeys_id) {
    if (argCount < 6) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[0]) || NPVARIANT_IS_STRING(args[0]))) {
      NPN_SetException(this, "Wrong 1 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[1]) || NPVARIANT_IS_STRING(args[1]))) {
      NPN_SetException(this, "Wrong 2 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[2]) || NPVARIANT_IS_STRING(args[2]))) {
      NPN_SetException(this, "Wrong 3 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[3]) || NPVARIANT_IS_STRING(args[3]))) {
      NPN_SetException(this, "Wrong 4 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[4]) || NPVARIANT_IS_STRING(args[4]))) {
      NPN_SetException(this, "Wrong 5 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[5]) || NPVARIANT_IS_STRING(args[5]))) {
      NPN_SetException(this, "Wrong 6 argument type");
      return true;
    }

    GetForeignKeys(&args[0], &args[1], &args[2], &args[3], &args[4], &args[5]);
    return true;

  } else if (name == mc_GetProcedures_id) {
    if (argCount < 3) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[0]) || NPVARIANT_IS_STRING(args[0]))) {
      NPN_SetException(this, "Wrong 1 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[1]) || NPVARIANT_IS_STRING(args[1]))) {
      NPN_SetException(this, "Wrong 2 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[2]) || NPVARIANT_IS_STRING(args[2]))) {
      NPN_SetException(this, "Wrong 3 argument type");
      return true;
    }

    GetProcedures(&args[0], &args[1], &args[2]);
    return true;

  } else if (name == mc_GetProcedureColumns_id) {
    if (argCount < 4) {
      NPN_SetException(this, "Too few parameters count");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[0]) || NPVARIANT_IS_STRING(args[0]))) {
      NPN_SetException(this, "Wrong 1 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[1]) || NPVARIANT_IS_STRING(args[1]))) {
      NPN_SetException(this, "Wrong 2 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[2]) || NPVARIANT_IS_STRING(args[2]))) {
      NPN_SetException(this, "Wrong 3 argument type");
      return true;
    }
    if (!(NPVARIANT_IS_NULL(args[3]) || NPVARIANT_IS_STRING(args[3]))) {
      NPN_SetException(this, "Wrong 4 argument type");
      return true;
    }

    GetProcedureColumns(&args[0], &args[1], &args[2], &args[3]);
    return true;
  
  }  

  return false;
}
예제 #28
0
파일: shocker.cpp 프로젝트: 499940913/moon
void
ShockerScriptableControlObject::EnablePrivacyPrompts (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	Shocker_FailTestFast ("EnablePrivacyPrompts (): Not implemented");
	BOOLEAN_TO_NPVARIANT (true, *result);
}
예제 #29
0
void convertJValueToNPVariant(jvalue value, JNIType jniType, const char* javaTypeName, NPVariant* result)
{
    switch (jniType) {
    case void_type:
        {
            VOID_TO_NPVARIANT(*result);
        }
        break;

    case object_type:
        {
            if (value.l) {
                if (!strcmp(javaTypeName, "java.lang.String")) {
                    const char* v = getCharactersFromJString(static_cast<jstring>(value.l));
                    // s is freed in NPN_ReleaseVariantValue (see npruntime.cpp)
                    const char* s = strdup(v);
                    releaseCharactersForJString(static_cast<jstring>(value.l), v);
                    STRINGZ_TO_NPVARIANT(s, *result);
                } else
                    OBJECT_TO_NPVARIANT(JavaInstanceToNPObject(new JavaInstance(value.l)), *result);
            } else
                VOID_TO_NPVARIANT(*result);
        }
        break;

    case boolean_type:
        {
            BOOLEAN_TO_NPVARIANT(value.z, *result);
        }
        break;

    case byte_type:
        {
            INT32_TO_NPVARIANT(value.b, *result);
        }
        break;

    case char_type:
        {
            INT32_TO_NPVARIANT(value.c, *result);
        }
        break;

    case short_type:
        {
            INT32_TO_NPVARIANT(value.s, *result);
        }
        break;

    case int_type:
        {
            INT32_TO_NPVARIANT(value.i, *result);
        }
        break;

        // TODO: Check if cast to double is needed.
    case long_type:
        {
            DOUBLE_TO_NPVARIANT(value.j, *result);
        }
        break;

    case float_type:
        {
            DOUBLE_TO_NPVARIANT(value.f, *result);
        }
        break;

    case double_type:
        {
            DOUBLE_TO_NPVARIANT(value.d, *result);
        }
        break;

    case invalid_type:
    default:
        {
            VOID_TO_NPVARIANT(*result);
        }
        break;
    }
}
예제 #30
0
파일: shocker.cpp 프로젝트: 499940913/moon
void
ShockerScriptableControlObject::SetRuntimePropertyValue (const NPVariant *args, uint32_t arg_count, NPVariant *result)
{
	Shocker_FailTestFast ("SetRuntimePropertyValue: Not implemented");
	BOOLEAN_TO_NPVARIANT (true, *result);
}