Пример #1
0
static JSValueRef setMarkedTextCallback(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
{
    WebKitWebView* view = webkit_web_frame_get_web_view(mainFrame);
    if (!view)
        return JSValueMakeUndefined(context);

    if (argumentCount < 3)
        return JSValueMakeUndefined(context);

    JSStringRef string = JSValueToStringCopy(context, arguments[0], exception);
    g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));

    size_t bufferSize = JSStringGetMaximumUTF8CStringSize(string);
    GOwnPtr<gchar> stringBuffer(static_cast<gchar*>(g_malloc(bufferSize)));
    JSStringGetUTF8CString(string, stringBuffer.get(), bufferSize);
    JSStringRelease(string);

    int start = static_cast<int>(JSValueToNumber(context, arguments[1], exception));
    g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));

    int end = static_cast<int>(JSValueToNumber(context, arguments[2], exception));
    g_return_val_if_fail((!exception || !*exception), JSValueMakeUndefined(context));

    DumpRenderTreeSupportGtk::setComposition(view, stringBuffer.get(), start, end);

    return JSValueMakeUndefined(context);
}
static gboolean element_text_equal_to(JSContextRef context, const gchar* text)
{
    JSStringRef scriptString = JSStringCreateWithUTF8CString(
      "window.document.getElementById(\"in\").value;");
    JSValueRef value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
    JSStringRelease(scriptString);

    // If the value isn't a string, the element is probably a div
    // so grab the innerText instead.
    if (!JSValueIsString(context, value)) {
        JSStringRef scriptString = JSStringCreateWithUTF8CString(
          "window.document.getElementById(\"in\").innerText;");
        value = JSEvaluateScript(context, scriptString, 0, 0, 0, 0);
        JSStringRelease(scriptString);
    }

    g_assert(JSValueIsString(context, value));
    JSStringRef inputString = JSValueToStringCopy(context, value, 0);
    g_assert(inputString);

    gint size = JSStringGetMaximumUTF8CStringSize(inputString);
    gchar* cString = g_malloc(size);
    JSStringGetUTF8CString(inputString, cString, size);
    JSStringRelease(inputString);

    gboolean result = g_utf8_collate(cString, text) == 0;
    g_free(cString);
    return result;
}
Пример #3
0
static gchar* js_extract_string(JSStringRef string)
{
    gsize size = JSStringGetMaximumUTF8CStringSize(string);
    gchar* gstr = (gchar*) g_malloc(size);
    JSStringGetUTF8CString(string, gstr, size);
    return gstr;
}
Пример #4
0
char *pdf_jsimp_to_string(pdf_jsimp *imp, pdf_jsimp_obj *obj)
{
	fz_context *ctx = imp->ctx;
	JSStringRef jstr = JSValueToStringCopy(imp->jscore_ctx, obj->ref, NULL);
	int len;

	if (jstr == NULL)
		return "";

	fz_try(ctx)
	{
		len = JSStringGetMaximumUTF8CStringSize(jstr);
		fz_free(ctx, obj->str);
		obj->str = NULL;
		obj->str = fz_malloc(ctx, len+1);
		JSStringGetUTF8CString(jstr, obj->str, len+1);
	}
	fz_always(ctx)
	{
		JSStringRelease(jstr);
	}
	fz_catch(ctx)
	{
		fz_rethrow(ctx);
	}

	return obj->str;
}
Пример #5
0
JSValueRef JSCCharacterData::appendDataCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) {

	struct JSCCharacterDataPrivate* privData = (struct JSCCharacterDataPrivate*)JSObjectGetPrivate(thisObj);

	if (false) {
	} else if (argumentCount == 1 &&
	           JSValueIsString(ctx, arguments[0])) {
		JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[0], exception);
		size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg);
		char* localArgBuffer = new char[localArgMaxSize];
		JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize);
		std::string localArg(localArgBuffer);
		JSStringRelease(stringReflocalArg);
		free(localArgBuffer);


		privData->nativeObj->appendData(localArg);

		JSValueRef jscRetVal = JSValueMakeUndefined(ctx);
		return jscRetVal;
	}

	JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling appendData");
	*exception = JSValueMakeString(ctx, exceptionString);
	JSStringRelease(exceptionString);
	return JSValueMakeUndefined(ctx);
}
Пример #6
0
JSValueRef ej_getNativeClass(JSContextRef ctx, JSObjectRef object, JSStringRef propertyNameJS, JSValueRef* exception) {
    size_t classNameSize = JSStringGetMaximumUTF8CStringSize(propertyNameJS);
    char* className = (char*)malloc(classNameSize);
    JSStringGetUTF8CString(propertyNameJS, className, classNameSize);

    JSObjectRef obj = NULL;
    NSString * fullClassName = new NSString();

    NSLOG("ej_getNativeClass : EJBinding%s", className);

    fullClassName->initWithFormat("EJBinding%s",className);
    EJBindingBase* pClass = (EJBindingBase*)NSClassFromString(fullClassName->getCString());
    if( pClass ) {
        obj = JSObjectMake( ctx, ej_constructorClass, (void *)pClass );
    } else {
        NSLOG("%s is NULL ... ", fullClassName->getCString());
    }

    if (obj)
    {
        NSLOG("constructor js-obj for %s", className);
    }

    free(className);
    fullClassName->autorelease();
    return obj ? obj : ej_global_undefined;
}
Пример #7
0
static void web_view_javascript_finished(GObject      *object,
                              GAsyncResult *result,
                              gpointer      user_data)
{
    WebKitJavascriptResult *js_result;
    JSValueRef              value;
    JSGlobalContextRef      context;
    GError                 *error = NULL;

    js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object), result, &error);
    if (!js_result) {
        g_warning ("Error running javascript: %s", error->message);
        g_error_free (error);
        return;
    }

    context = webkit_javascript_result_get_global_context(js_result);
    value = webkit_javascript_result_get_value(js_result);
    if (JSValueIsString(context, value)) {
        JSStringRef js_str_value;
        gchar      *str_value;
        gsize       str_length;

        js_str_value = JSValueToStringCopy(context, value, NULL);
        str_length = JSStringGetMaximumUTF8CStringSize(js_str_value);
        str_value = (gchar *)g_malloc(str_length);
        JSStringGetUTF8CString(js_str_value, str_value, str_length);
        JSStringRelease(js_str_value);
        g_free (str_value);
    } else {
        g_warning("Error running javascript: unexpected return value");
    }
    webkit_javascript_result_unref(js_result);
}
Пример #8
0
// has property methods for callbacks. method parameter definitions( e.message, e.otp, e.data)
bool spjsdata_has_property_cb(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
{
    bool ret = false;
    int propertySize = JSStringGetMaximumUTF8CStringSize(propertyName);
    char* property = (char *)malloc(propertySize * sizeof(char));
    JSStringGetUTF8CString(propertyName, property, propertySize);
 	if(strcmp(kParamOTP,property) == 0)
    {
        ret = true;
    }
    if(strcmp(kParamCode,property) == 0)
    {
        ret = true;
    }
    if(strcmp(kParamMessage,property) == 0)
    {
        ret = true;
    }
    if(strcmp(kParamData,property) == 0)
    {
        ret = true;
    }
    
    free(property);
    return ret;
}
Пример #9
0
char* jsstring_to_cstr(JSContextRef ctx, JSStringRef js_string)
{
  size_t len = JSStringGetMaximumUTF8CStringSize(js_string);
  char *c_str = g_new(char, len);
  JSStringGetUTF8CString(js_string, c_str, len);
  return c_str;
}
Пример #10
0
/**
 * return a char* from a JSStringRef as string which must be delete when finished
 */
EXPORTAPI char * HyperloopJSStringToStringCopy(JSContextRef ctx, JSStringRef str, JSValueRef *exception)
{
    auto size = JSStringGetMaximumUTF8CStringSize(str);
    auto buf = new char[size];
    JSStringGetUTF8CString(str,buf,size);
    return buf;
}
/*
 * Converts an argument to a string.
 *
 * Convert a JSValueRef argument to a g_malloc'd gchar string. Calling function
 * is responsible for g_freeing the string.
 */
static gchar *
arg_to_string(JSContextRef context, JSValueRef arg, JSValueRef *exception) {
	JSStringRef string;
	size_t size;
	gchar *result;

	if (JSValueGetType(context, arg) != kJSTypeString) {
		_mkexception(context, exception, EXPECTSTRING);

		return NULL;
	}

	string = JSValueToStringCopy(context, arg, exception);

	if (!string) {

		return NULL;
	}

	size = JSStringGetMaximumUTF8CStringSize(string);
	result = g_malloc(size);

	if (!result) {

		return NULL;
	}

	JSStringGetUTF8CString(string, result, size);
	JSStringRelease(string);

	return result;
}
Пример #12
0
Platform::String^ Utils::getPlatformString(JSStringRef sValue) {
	size_t sLength = JSStringGetMaximumUTF8CStringSize(sValue);
	char* cValue = new char[sLength];
	JSStringGetUTF8CString(sValue, cValue, sLength);
	std::string s_str = cValue;
	std::wstring w_str(s_str.begin(), s_str.end());
	return ref new Platform::String(w_str.c_str());
}
Пример #13
0
std::wstring hyperloop::getWString(JSStringRef sValue) {
	size_t sLength = JSStringGetMaximumUTF8CStringSize(sValue);
	char* cValue = new char[sLength];
	JSStringGetUTF8CString(sValue, cValue, sLength);
	std::string s_str = cValue;
	std::wstring w_str(s_str.begin(), s_str.end());
	return w_str;
}
Пример #14
0
// Returns a newly allocated UTF-8 character buffer which must be freed with g_free()
char* JSStringCopyUTF8CString(JSStringRef jsString)
{
    size_t dataSize = JSStringGetMaximumUTF8CStringSize(jsString);
    char* utf8 = (char*)malloc(dataSize);
    JSStringGetUTF8CString(jsString, utf8, dataSize);

    return utf8;
}
JNIEXPORT jintLong JNICALL WebKit_win32_NATIVE(JSStringGetMaximumUTF8CStringSize)
	(JNIEnv *env, jclass that, jintLong arg0)
{
	jintLong rc = 0;
	WebKit_win32_NATIVE_ENTER(env, that, JSStringGetMaximumUTF8CStringSize_FUNC);
	rc = (jintLong)JSStringGetMaximumUTF8CStringSize((JSStringRef)arg0);
	WebKit_win32_NATIVE_EXIT(env, that, JSStringGetMaximumUTF8CStringSize_FUNC);
	return rc;
}
Пример #16
0
static String coreAttributeToAtkAttribute(JSStringRef attribute)
{
    size_t bufferSize = JSStringGetMaximumUTF8CStringSize(attribute);
    GOwnPtr<gchar> buffer(static_cast<gchar*>(g_malloc(bufferSize)));
    JSStringGetUTF8CString(attribute, buffer.get(), bufferSize);

    String attributeString = String::fromUTF8(buffer.get());
    return attributeString == "AXPlaceholderValue" ? "placeholder-text" : String();
}
Пример #17
0
String JSStringToString(JSStringRef str)
{
    size_t len = JSStringGetMaximumUTF8CStringSize(str);
    char* buf = new char[len + 1];
    JSStringGetUTF8CString(str, buf, len + 1);

    String result(buf);
    delete[] buf;

    return result;
}
Пример #18
0
::testing::AssertionResult runJSTest(const char*, const char*, const char*, WKPageRef page, const char* script, const char* expectedResult)
{
    JavaScriptCallbackContext context;
    WKPageRunJavaScriptInMainFrame(page, Util::toWK(script).get(), &context, javaScriptCallback);
    Util::run(&context.didFinish);

    size_t bufferSize = JSStringGetMaximumUTF8CStringSize(context.actualString.get());
    auto buffer = std::make_unique<char[]>(bufferSize);
    JSStringGetUTF8CString(context.actualString.get(), buffer.get(), bufferSize);
    
    return compareJSResult(script, buffer.get(), expectedResult);
}
Пример #19
0
// has property method for callback parameters
JSValueRef spjsdata_get_property_cb(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception)
{
    bool ret = false;
    JSValueRef retval;
    int propertySize = JSStringGetMaximumUTF8CStringSize(propertyName);
    char* property = (char*)malloc(propertySize*sizeof(char));
    JSStringGetUTF8CString(propertyName, property, propertySize);
    char* data = (char*)JSObjectGetPrivate(object);
    if(strcmp(kParamOTP,property) == 0)
    {

        JSStringRef sref = JSStringCreateWithUTF8CString(data);
		JSValueRef ref = JSValueMakeString(ctx, sref);
        retval = ref;
        ret = true;
    }
    if(strcmp(kParamCode,property) == 0)
    {
        JSStringRef sref = JSStringCreateWithUTF8CString(data);
		JSValueRef ref = JSValueMakeString(ctx, sref);
        retval = ref;
        ret = true;
    }
    if(strcmp(kParamMessage,property) == 0)
    {
        JSStringRef sref = JSStringCreateWithUTF8CString(data);
		JSValueRef ref = JSValueMakeString(ctx, sref);
        retval = ref;
        ret = true;
    }
    if(strcmp(kParamData,property) == 0)
    {
        //JSStringRef sref = JSStringCreateWithUTF8CString(data);
  //JSValueRef ref = JSValueMakeString(ctx, sref);
        
        // json object is passed to e.data
        DPInfo* info = (DPInfo*)JSObjectGetPrivate(object);
//        std::string json = "{\"status\":\"" + (char)info->status + "\",\"version\":\"" + info->version + "\",\"serial\":\"" + info->serial + "\"}";

        char *jsonBuffer = new char[256];
        memset(jsonBuffer, 0, 256);
        sprintf(jsonBuffer, "{\"status\":\"%u\",\"version\":\"%u\",\"serial\":\"%s\",\"passwordFatalCounter\":\"%u\",\"appEventCounter\":\"%lu\"}", info->status, info->version, info->serial.c_str(), info->fatalCounter, info->appEventCounter);
        JSStringRef sref = JSStringCreateWithUTF8CString(jsonBuffer);
        delete []jsonBuffer;

        JSValueRef ref = JSValueMakeFromJSONString(ctx, sref);
        retval = ref;
        ret = true;
    }

    free(property);
    return retval;
}
Пример #20
0
static gchar *
js_string (JSStringRef js_string)
{
  gsize size;
  gchar *string;

  size = JSStringGetMaximumUTF8CStringSize (js_string);
  string = g_malloc (size + 1);
  JSStringGetUTF8CString (js_string, string, size);

  return string;
}
Пример #21
0
static JSValueRef
zs__                (JSContextRef     js_context,
                     JSObjectRef      js_function,
                     JSObjectRef      js_this,
                     size_t           argument_count,
                     const JSValueRef js_arguments[],
                     JSValueRef*      js_exception)
{
	if(argument_count<=0){
		return JSValueMakeNull (js_context);
	}
	const char*ret;
	{
		window___* w=reinterpret_cast<window___*>(JSObjectGetPrivate(js_function));
		if(!w){
			return JSValueMakeNull (js_context);
		}
		char** argv=new char*[argument_count+1];
		JSStringRef* jsr=new JSStringRef[argument_count];
		for(size_t i=0;i<argument_count;i++){
			jsr[i]=JSValueToStringCopy(js_context, js_arguments[i], js_exception);
			size_t jsSize = JSStringGetMaximumUTF8CStringSize(jsr[i]);
			argv[i]=new char[jsSize];
			JSStringGetUTF8CString(jsr[i], argv[i], jsSize);
		}
		if(!argv[0][0]){
			ret=NULL;
			for(size_t i=1;i<argument_count;i++)
				cout<<argv[i];
			cout<<endl;
		}else
			ret=call4__(argv[0],NULL,argument_count,(const char**)argv,1);
		for(size_t i=0;i<argument_count;i++){
			delete argv[i];
			JSStringRelease(jsr[i]);
		}
		delete jsr;
		delete argv;
	}

	if(!ret)
		return JSValueMakeNull (js_context);
	JSValueRef ret2;
	if(true_==ret||false_==ret){
		ret2=JSValueMakeBoolean(js_context,true_==ret);
	}else{
		JSStringRef ret1=JSStringCreateWithUTF8CString(ret);
		ret2=JSValueMakeString(js_context,ret1);
		JSStringRelease (ret1);
	}
	return ret2;
}
Пример #22
0
static char* jsValueToCString(JSGlobalContextRef context, JSValueRef value)
{
    g_assert(value);
    g_assert(JSValueIsString(context, value));

    JSRetainPtr<JSStringRef> stringValue(Adopt, JSValueToStringCopy(context, value, 0));
    g_assert(stringValue);

    size_t cStringLength = JSStringGetMaximumUTF8CStringSize(stringValue.get());
    char* cString = static_cast<char*>(g_malloc(cStringLength));
    JSStringGetUTF8CString(stringValue.get(), cString, cStringLength);
    return cString;
}
Пример #23
0
bool LoadItem::invoke() const
{
    size_t targetArrSize = JSStringGetMaximumUTF8CStringSize(m_target.get());
    size_t urlArrSize = JSStringGetMaximumUTF8CStringSize(m_url.get());
    OwnArrayPtr<char> target(new char[targetArrSize]);
    OwnArrayPtr<char> url(new char[urlArrSize]);
    size_t targetLen = JSStringGetUTF8CString(m_target.get(), target.get(), targetArrSize) - 1;
    JSStringGetUTF8CString(m_url.get(), url.get(), urlArrSize);

    WebCore::Frame* frame;
    if (target && targetLen)
        frame = mainFrame->tree()->find(target.get());
    else
        frame = mainFrame;

    if (!frame)
        return false;

    WebCore::KURL kurl = WebCore::KURL(WebCore::KURL(), url.get());
    frame->loader()->load(kurl, false);
    return true;
}
Пример #24
0
static gchar*
sokoke_js_string_utf8 (JSStringRef js_string)
{
    size_t size_utf8;
    gchar* string_utf8;

    g_return_val_if_fail (js_string, NULL);
#if 0
    size_utf8 = JSStringGetMaximumUTF8CStringSize (js_string);
    string_utf8 = g_new (gchar, size_utf8);
    JSStringGetUTF8CString (js_string, string_utf8, size_utf8);
#endif
    return string_utf8;
}
Пример #25
0
bool JSCProcessingInstruction::dataAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) {
	struct JSCProcessingInstructionPrivate* privData = (struct JSCProcessingInstructionPrivate*)JSObjectGetPrivate(thisObj);

	JSStringRef stringReflocalData = JSValueToStringCopy(ctx, value, exception);
	size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData);
	char* localDataBuffer = new char[localDataMaxSize];
	JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize);
	std::string localData(localDataBuffer);
	JSStringRelease(stringReflocalData);
	free(localDataBuffer);

	privData->nativeObj->setData(localData);
	return true;
}
Пример #26
0
bool spjsdpplugin_set_property_cb(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception)
{
    bool ret = false;
    int propertySize = JSStringGetMaximumUTF8CStringSize(propertyName);
    char* property = (char*)malloc(propertySize*sizeof(char));
    JSStringGetUTF8CString(propertyName, property, propertySize);
	if(strcmp("customProperty",property) == 0)
    {
		ret = true;
    }
    
    free(property);
    return ret;
}
Пример #27
0
bool JSCArrayBuffer::mimeTypeAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) {
	struct JSCArrayBufferPrivate* privData = (struct JSCArrayBufferPrivate*)JSObjectGetPrivate(thisObj);

	JSStringRef stringReflocalMimeType = JSValueToStringCopy(ctx, value, exception);
	size_t localMimeTypeMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalMimeType);
	char* localMimeTypeBuffer = new char[localMimeTypeMaxSize];
	JSStringGetUTF8CString(stringReflocalMimeType, localMimeTypeBuffer, localMimeTypeMaxSize);
	std::string localMimeType(localMimeTypeBuffer);
	JSStringRelease(stringReflocalMimeType);
	free(localMimeTypeBuffer);

	privData->nativeObj->setMimeType(localMimeType);
	return true;
}
Пример #28
0
/* Sys.print implementation */
static JSValueRef cb_sysclass_print(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception) {
	/* At least, one argument must be received */
	if (argumentCount == 1 && JSValueIsString(context, arguments[0])) {
		/* Converts JSValue to char */
		size_t len;
		char * cstr;
		JSStringRef jsstr = JSValueToStringCopy(context, arguments[0], NULL);
		len = JSStringGetMaximumUTF8CStringSize(jsstr);
		cstr = g_new(char, len);
		JSStringGetUTF8CString(jsstr, cstr, len);
		g_print("%s\n\n", cstr);
		g_free(cstr);
		JSStringRelease(jsstr);
	}
Пример #29
0
JSRetainPtr<JSStringRef> TestRunner::pathToLocalResource(JSStringRef url)
{
    size_t urlSize = JSStringGetMaximumUTF8CStringSize(url);
    GOwnPtr<gchar> urlString(static_cast<gchar*>(g_malloc(urlSize)));
    JSStringGetUTF8CString(url, urlString.get(), urlSize);

    if (!g_str_has_prefix(urlString.get(), "file:///tmp/LayoutTests/"))
        return JSStringRetain(url);

    const gchar* layoutTestsSuffix = urlString.get() + strlen("file:///tmp/");
    GOwnPtr<gchar> testPath(g_build_filename(WTR::topLevelPath().data(), layoutTestsSuffix, NULL));
    GOwnPtr<gchar> testURI(g_filename_to_uri(testPath.get(), 0, 0));
    return JSStringCreateWithUTF8CString(testURI.get());
}
Пример #30
0
bool spjsdpplugin_has_property_cb(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName)
{
    bool ret = false;
    int propertySize = JSStringGetMaximumUTF8CStringSize(propertyName);
    char* property = (char *)malloc(propertySize * sizeof(char));
    JSStringGetUTF8CString(propertyName, property, propertySize);
 	if(strcmp(kMethodActivateOnline,property) == 0)
    {
        ret = true;
    }
    else if(strcmp(kMethodValidatePassword,property) == 0)
    {
        ret = true;
    }
    else if(strcmp(kMethodGenerateOTP,property) == 0)
    {
        ret = true;
    }
    else if(strcmp(kMethodGenerateDerivationCode,property) == 0)
    {
        ret = true;
    }
    else if(strcmp(kMethodChangePassword,property) == 0)
    {
        ret = true;
    }
    else if(strcmp(kMethodGetInfo,property) == 0)
    {
        ret = true;
    }
    else if(strcmp(kMethodComputeTimeShift,property) == 0)
    {
        ret = true;
    }
    else if(strcmp(kMethodInitializeRegistrationDataV2,property) == 0)
    {
        ret = true;
    }
    else if(strcmp(kMethodDecryptActivationData,property) == 0)
    {
        ret = true;
    }
    else if(strcmp(kMethodValidateSharedDataChecksum,property) == 0)
    {
        ret = true;
    }
    free(property);
    return ret;
}