示例#1
0
文件: gethar2.c 项目: fengidri/gethar
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);
}
示例#2
0
bool WebViewTest::javascriptResultIsUndefined(WebKitJavascriptResult* javascriptResult)
{
    JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult);
    g_assert(context);
    JSValueRef value = webkit_javascript_result_get_value(javascriptResult);
    g_assert(value);

    return JSValueIsUndefined(context, value);
}
示例#3
0
double WebViewTest::javascriptResultToNumber(WebKitJavascriptResult* javascriptResult)
{
    JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult);
    g_assert(context);
    JSValueRef value = webkit_javascript_result_get_value(javascriptResult);
    g_assert(value);
    g_assert(JSValueIsNumber(context, value));

    return JSValueToNumber(context, value, 0);
}
示例#4
0
char* WebViewTest::javascriptResultToCString(WebKitJavascriptResult* javascriptResult)
{
    JSGlobalContextRef context = webkit_javascript_result_get_global_context(javascriptResult);
    g_assert(context);
    return jsValueToCString(context, webkit_javascript_result_get_value(javascriptResult));
}
static void get_javascript_result(
    GObject *object,
    GAsyncResult *result,
    gpointer user_data)
{
  g_printf("Here? Surely?\n");
  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;
  }

  g_printf("I'm here innit 1\n");
  context = webkit_javascript_result_get_global_context (js_result);
  g_printf("I'm here innit 2\n");
  value = webkit_javascript_result_get_value (js_result);
  int value_type = JSValueGetType(context, value);
  switch (value_type) {
    case kJSTypeUndefined:
      g_printf("Value undefined!\n");
      break;
    case kJSTypeNull:
      g_printf("Value null!\n");
      break;
    case kJSTypeBoolean:
      g_printf("Value boolean!\n");
      break;
    case kJSTypeNumber:
      g_printf("Value number!\n");
      break;
    case kJSTypeString:
      g_printf("Value string!\n");
      break;
    case kJSTypeObject:
      g_printf("Value object!\n");
      break;
  }

  if (JSValueIsString (context, value)) {
    g_printf("I'm here innit 3\n");
    JSStringRef js_str_value = JSValueToStringCopy(context, value, NULL);
    gsize       str_length = JSStringGetMaximumUTF8CStringSize(js_str_value);
    gchar      *str_value;

    g_printf("String length: %d\n", str_length);
    str_value = (gchar *)g_malloc (str_length);
    JSStringGetUTF8CString (js_str_value, str_value, str_length);
    JSStringRelease (js_str_value);

    g_print ("Script result: %s\n", str_value);
    g_free (str_value);
  } else {
    g_warning ("Error running javascript: unexpected return value");
  }
  webkit_javascript_result_unref (js_result);
}
示例#6
0
gchar* caravel_window_js_result_string(WebKitJavascriptResult* result)
{
    return js_to_string(webkit_javascript_result_get_global_context(result),
                        webkit_javascript_result_get_value(result));
}