コード例 #1
0
ファイル: module.cpp プロジェクト: Aeva/webkit2gtk-experiment
//
//  Boilerplate code / signal callback for attaching methods when a
//  new javascript context is created.
//
static void 
window_object_cleared_callback (WebKitScriptWorld *world, 
                                WebKitWebPage *web_page, 
                                WebKitFrame *frame, 
                                gpointer user_data)
{
  std::cout << "attempting to set up custom c function bindings\n";
  JSGlobalContextRef js_ctx;
  js_ctx = webkit_frame_get_javascript_context_for_script_world (frame, world);
  
  JSStringRef function_name = JSStringCreateWithUTF8CString("whatever");
  JSObjectRef boiler_plate = JSObjectMakeFunctionWithCallback(js_ctx,
                                                              function_name,
                                                              some_method);
  JSValueRef exception = 0;
  JSObjectRef global = JSContextGetGlobalObject(js_ctx);
  JSObjectSetProperty(js_ctx,
                      global,
                      JSStringCreateWithUTF8CString("myCFunction"),
                      boiler_plate,
                      kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly,
                      &exception);
  if (exception) {
    std::cout << "Argh! an exception!!!!\n";
  }
}
コード例 #2
0
ファイル: ext-main.c プロジェクト: cdlscpmv/vimb
/**
 * Handle dbus method calls.
 */
static void dbus_handle_method_call(GDBusConnection *conn, const char *sender,
        const char *object_path, const char *interface_name, const char *method,
        GVariant *parameters, GDBusMethodInvocation *invocation, gpointer extension)
{
    char *value;
    guint64 pageid;
    WebKitWebPage *page;

    if (g_str_has_prefix(method, "EvalJs")) {
        char *result       = NULL;
        gboolean success;
        gboolean no_result;
        JSValueRef ref     = NULL;
        JSGlobalContextRef jsContext;

        g_variant_get(parameters, "(ts)", &pageid, &value);
        page = get_web_page_or_return_dbus_error(invocation, WEBKIT_WEB_EXTENSION(extension), pageid);
        if (!page) {
            return;
        }

        no_result = !g_strcmp0(method, "EvalJsNoResult");
        jsContext = webkit_frame_get_javascript_context_for_script_world(
            webkit_web_page_get_main_frame(page),
            webkit_script_world_get_default()
        );

        success = ext_util_js_eval(jsContext, value, &ref);

        if (no_result) {
            g_dbus_method_invocation_return_value(invocation, NULL);
        } else {
            result = ext_util_js_ref_to_string(jsContext, ref);
            g_dbus_method_invocation_return_value(invocation, g_variant_new("(bs)", success, result));
            g_free(result);
        }
    } else if (!g_strcmp0(method, "FocusInput")) {
        g_variant_get(parameters, "(t)", &pageid);
        page = get_web_page_or_return_dbus_error(invocation, WEBKIT_WEB_EXTENSION(extension), pageid);
        if (!page) {
            return;
        }
        ext_dom_focus_input(webkit_web_page_get_dom_document(page));
        g_dbus_method_invocation_return_value(invocation, NULL);
    } else if (!g_strcmp0(method, "SetHeaderSetting")) {
        g_variant_get(parameters, "(s)", &value);

        if (ext.headers) {
            soup_header_free_param_list(ext.headers);
            ext.headers = NULL;
        }
        ext.headers = soup_header_parse_param_list(value);
        g_dbus_method_invocation_return_value(invocation, NULL);
    }
}
コード例 #3
0
static void windowObjectCleared(WebKitScriptWorld* world, WebKitWebPage* page, WebKitFrame* frame, gpointer)
{
    JSGlobalContextRef jsContext = webkit_frame_get_javascript_context_for_script_world(frame, world);
    g_assert(jsContext);
    JSObjectRef globalObject = JSContextGetGlobalObject(jsContext);
    g_assert(globalObject);

    JSRetainPtr<JSStringRef> functionName(Adopt, JSStringCreateWithUTF8CString("echo"));
    JSObjectRef function = JSObjectMakeFunctionWithCallback(jsContext, functionName.get(), echoCallback);
    JSObjectSetProperty(jsContext, globalObject, functionName.get(), function, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly, 0);
}
コード例 #4
0
static void windowObjectClearedCallback(WebKitScriptWorld* world, WebKitWebPage* webPage, WebKitFrame* frame, WebKitWebExtension* extension)
{
    JSGlobalContextRef context = webkit_frame_get_javascript_context_for_script_world(frame, world);
    JSObjectRef globalObject = JSContextGetGlobalObject(context);

    JSClassDefinition classDefinition = kJSClassDefinitionEmpty;
    classDefinition.className = "WebProcessTestRunner";
    classDefinition.staticFunctions = webProcessTestRunnerStaticFunctions;
    classDefinition.finalize = webProcessTestRunnerFinalize;

    JSClassRef jsClass = JSClassCreate(&classDefinition);
    JSObjectRef classObject = JSObjectMake(context, jsClass, g_object_ref(webPage));
    JSRetainPtr<JSStringRef> propertyString(Adopt, JSStringCreateWithUTF8CString("WebProcessTestRunner"));
    JSObjectSetProperty(context, globalObject, propertyString.get(), classObject, kJSPropertyAttributeNone, nullptr);
    JSClassRelease(jsClass);
}
コード例 #5
0
ファイル: WebExtensionTest.cpp プロジェクト: MYSHLIFE/webkit
static void methodCallCallback(GDBusConnection* connection, const char* sender, const char* objectPath, const char* interfaceName, const char* methodName, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer userData)
{
    if (g_strcmp0(interfaceName, "org.webkit.gtk.WebExtensionTest"))
        return;

    if (!g_strcmp0(methodName, "GetTitle")) {
        uint64_t pageID;
        g_variant_get(parameters, "(t)", &pageID);
        WebKitWebPage* page = getWebPage(WEBKIT_WEB_EXTENSION(userData), pageID, invocation);
        if (!page)
            return;

        WebKitDOMDocument* document = webkit_web_page_get_dom_document(page);
        GUniquePtr<char> title(webkit_dom_document_get_title(document));
        g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)", title.get()));
    } else if (!g_strcmp0(methodName, "RunJavaScriptInIsolatedWorld")) {
        uint64_t pageID;
        const char* script;
        g_variant_get(parameters, "(t&s)", &pageID, &script);
        WebKitWebPage* page = getWebPage(WEBKIT_WEB_EXTENSION(userData), pageID, invocation);
        if (!page)
            return;

        GRefPtr<WebKitScriptWorld> world = adoptGRef(webkit_script_world_new());
        g_assert(webkit_script_world_get_default() != world.get());
        WebKitFrame* frame = webkit_web_page_get_main_frame(page);
        JSGlobalContextRef jsContext = webkit_frame_get_javascript_context_for_script_world(frame, world.get());
        JSRetainPtr<JSStringRef> jsScript(Adopt, JSStringCreateWithUTF8CString(script));
        JSEvaluateScript(jsContext, jsScript.get(), 0, 0, 0, 0);
        g_dbus_method_invocation_return_value(invocation, 0);
    } else if (!g_strcmp0(methodName, "AbortProcess")) {
        abort();
    } else if (!g_strcmp0(methodName, "GetInitializationUserData")) {
        g_assert(initializationUserData);
        g_assert(g_variant_is_of_type(initializationUserData.get(), G_VARIANT_TYPE_STRING));
        g_dbus_method_invocation_return_value(invocation, g_variant_new("(s)",
            g_variant_get_string(initializationUserData.get(), nullptr)));
    } else if (!g_strcmp0(methodName, "GetProcessIdentifier")) {
        g_dbus_method_invocation_return_value(invocation,
            g_variant_new("(u)", static_cast<guint32>(getCurrentProcessID())));
    }
}
コード例 #6
0
static void
window_object_cleared_callback(WebKitScriptWorld *world,
							   WebKitWebPage *web_page,
							   WebKitFrame *frame,
							   LightDMGreeter *greeter) {

	JSObjectRef gettext_object, lightdm_greeter_object, config_file_object, greeter_util_object;
	JSGlobalContextRef jsContext;
	JSObjectRef globalObject;
	WebKitDOMDocument *dom_document;
	WebKitDOMDOMWindow *dom_window;
	gchar *message = "LockHint";

	page_id = webkit_web_page_get_id(web_page);

	jsContext = webkit_frame_get_javascript_context_for_script_world(frame, world);
	globalObject = JSContextGetGlobalObject(jsContext);

	gettext_class = JSClassCreate(&gettext_definition);
	lightdm_greeter_class = JSClassCreate(&lightdm_greeter_definition);
	lightdm_user_class = JSClassCreate(&lightdm_user_definition);
	lightdm_language_class = JSClassCreate(&lightdm_language_definition);
	lightdm_layout_class = JSClassCreate(&lightdm_layout_definition);
	lightdm_session_class = JSClassCreate(&lightdm_session_definition);
	config_file_class = JSClassCreate(&config_file_definition);
	greeter_util_class = JSClassCreate(&greeter_util_definition);

	gettext_object = JSObjectMake(jsContext, gettext_class, NULL);

	JSObjectSetProperty(jsContext,
						globalObject,
						JSStringCreateWithUTF8CString("gettext"),
						gettext_object,
						kJSPropertyAttributeNone,
						NULL);

	lightdm_greeter_object = JSObjectMake(jsContext, lightdm_greeter_class, greeter);

	JSObjectSetProperty(jsContext,
						globalObject,
						JSStringCreateWithUTF8CString("lightdm"),
						lightdm_greeter_object,
						kJSPropertyAttributeNone,
						NULL);

	config_file_object = JSObjectMake(jsContext, config_file_class, greeter);

	JSObjectSetProperty(jsContext,
						globalObject,
						JSStringCreateWithUTF8CString("config"),
						config_file_object,
						kJSPropertyAttributeNone,
						NULL);

	greeter_util_object = JSObjectMake(jsContext, greeter_util_class, NULL);

	JSObjectSetProperty(jsContext,
						globalObject,
						JSStringCreateWithUTF8CString("greeterutil"),
						greeter_util_object,
						kJSPropertyAttributeNone,
						NULL);



	/* If the greeter was started as a lock-screen, send message to our UI process. */
	if (lightdm_greeter_get_lock_hint(greeter)) {
		dom_document = webkit_web_page_get_dom_document(web_page);
		dom_window = webkit_dom_document_get_default_view(dom_document);

		if (dom_window) {
			webkit_dom_dom_window_webkit_message_handlers_post_message(dom_window,
																	   "GreeterBridge", message);
		}
	}

}