예제 #1
0
파일: setting.c 프로젝트: fanglingsu/vimb
static int user_scripts(Client *c, const char *name, DataType type, void *value, void *data)
{
    WebKitUserContentManager *ucm;
    WebKitUserScript *script;
    gchar *source;

    gboolean enabled = *(gboolean*)value;

    ucm = webkit_web_view_get_user_content_manager(c->webview);
    webkit_user_content_manager_remove_all_scripts(ucm);

    if (enabled) {
        if (vb.files[FILES_SCRIPT]
                && g_file_get_contents(vb.files[FILES_SCRIPT], &source, NULL, NULL)) {

            script = webkit_user_script_new(
                source, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES,
                WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END, NULL, NULL
            );

            webkit_user_content_manager_add_script(ucm, script);
            webkit_user_script_unref(script);
            g_free(source);
        }
    }

    /* Inject the global scripts. */
    script = webkit_user_script_new(JS_HINTS " " JS_SCROLL,
            WEBKIT_USER_CONTENT_INJECT_TOP_FRAME,
            WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END, NULL, NULL);
    webkit_user_content_manager_add_script(ucm, script);
    webkit_user_script_unref(script);

    return CMD_SUCCESS;
}
예제 #2
0
파일: main.c 프로젝트: macrat/rusk
int addScriptByFileName(WebKitUserContentManager *contentManager, const char *scriptPath, WebKitUserScriptInjectionTime InjectionTime)
{
	if(access(scriptPath, F_OK) != 0)
	{
		return 1;
	}else
	{
		char *scriptStr = loadFile(scriptPath);
		if(scriptStr == NULL)
		{
			return -1;
		}

		WebKitUserScript *script = webkit_user_script_new(scriptStr, WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES, InjectionTime, NULL, NULL);

		free(scriptStr);

		if(script == NULL)
		{
			return -1;
		}

		webkit_user_content_manager_add_script(contentManager, script);
	}

	return 0;
}