Esempio n. 1
0
static
void
run_node_command(Command *self, Context *context)
{
	fprintf(stderr, "Started Node\n");
	cef_string_t name = {};
	cef_string_set(u"CapybaraInvocation", 18, &name, 0);
	cef_process_message_t *message = cef_process_message_create(&name);

	cef_list_value_t *args = message->get_argument_list(message);

	cef_string_t value = {};
	cef_string_utf8_to_utf16(self->arguments[0], strlen(self->arguments[0]), &value);
	args->set_string(args, 0, &value);

	args->set_bool(args, 1, strcmp(self->arguments[1], "true") == 0);

	for (int i = 2; i < self->argument_count; i++) {
		cef_string_utf8_to_utf16(self->arguments[i], strlen(self->arguments[i]), &value);
		args->set_string(args, i, &value);
		cef_string_clear(&value);
	}

	context->browser->send_process_message(context->browser, PID_RENDERER, message);
}
Esempio n. 2
0
static
void
run_visit_command(Command *self, Context *context)
{
	fprintf(stderr, "Started Visit\n");
	cef_string_t url = {};
	cef_string_utf8_to_utf16(self->arguments[0], strlen(self->arguments[0]), &url);
	cef_frame_t *frame = context->browser->get_main_frame(context->browser);
	frame->load_url(frame, &url);
	frame->base.release((cef_base_t *)frame);
	cef_string_clear(&url);
	context->finish(context, NULL);
}
Esempio n. 3
0
static
void
run_find_css_command(Command *self, Context *context)
{
	fprintf(stderr, "Started FindCss\n");
	cef_string_t name = {};
	cef_string_set(u"CapybaraInvocation", 18, &name, 0);
	cef_process_message_t *message = cef_process_message_create(&name);

	cef_list_value_t *args = message->get_argument_list(message);

	cef_string_t value = {};
	cef_string_set(u"findCss", 7, &value, 0);
	args->set_string(args, 0, &value);

	args->set_bool(args, 1, 1);

	cef_string_utf8_to_utf16(self->arguments[0], strlen(self->arguments[0]), &value);
	args->set_string(args, 2, &value);
	cef_string_clear(&value);

	context->browser->send_process_message(context->browser, PID_RENDERER, message);
}
Esempio n. 4
0
static
void
run_execute_command(Command *self, Context *context)
{
	fprintf(stderr, "Started Execute\n");

	char *script = self->arguments[0];

	cef_browser_host_t *host = context->browser->get_host(context->browser);
	host->was_resized(host);
	host->base.release((cef_base_t *)host);

	cef_string_t code = {};
	cef_string_utf8_to_utf16(script, strlen(script), &code);

	cef_frame_t *frame = context->browser->get_main_frame(context->browser);
	frame->execute_java_script(frame, &code, NULL, 0);
	frame->base.release((cef_base_t *)frame);

	cef_string_clear(&code);

	context->finish(context, NULL);
}
Esempio n. 5
0
int main(int argc, char** argv) {
    // This executable is called many times, because it
    // is also used for subprocesses. Let's print args
    // so we can differentiate between main process and
    // subprocesses. If one of the first args is for
    // example "--type=renderer" then it means that
    // this is a Renderer process. There may be more
    // subprocesses like GPU (--type=gpu-process) and
    // others. On Linux there are also special Zygote
    // processes.
    printf("\nProcess args: ");
    if (argc == 1) {
        printf("none (Main process)");
    } else {
        for (int i = 1; i < argc; i++) {
            if (strlen(argv[i]) > 128)
                printf("... ");
            else
                printf("%s ", argv[i]);
        }
    }
    printf("\n\n");

    // CEF version
    if (argc == 0) {
        printf("CEF version: %s\n", CEF_VERSION);
    }

    // Main args
    cef_main_args_t main_args = {};
    main_args.instance = GetModuleHandle(NULL);

    // Cef app
    cef_app_t app = {};
    initialize_cef_app(&app);
    
    // Execute subprocesses. It is also possible to have
    // a separate executable for subprocesses by setting
    // cef_settings_t.browser_subprocess_path. In such
    // case cef_execute_process should not be called here.
    printf("cef_execute_process, argc=%d\n", argc);
    int code = cef_execute_process(&main_args, &app, NULL);
    if (code >= 0) {
        _exit(code);
    }
    
    // Application settings. It is mandatory to set the
    // "size" member.
    cef_settings_t settings = {};
    settings.size = sizeof(cef_settings_t);
    settings.log_severity = LOGSEVERITY_WARNING; // Show only warnings/errors
    settings.no_sandbox = 1;

    // Initialize CEF
    printf("cef_initialize\n");
    cef_initialize(&main_args, &settings, &app, NULL);

    // Window info
    cef_window_info_t window_info = {};
    window_info.style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN \
            | WS_CLIPSIBLINGS | WS_VISIBLE;
    window_info.parent_window = NULL;
    window_info.x = CW_USEDEFAULT;
    window_info.y = CW_USEDEFAULT;
    window_info.width = CW_USEDEFAULT;
    window_info.height = CW_USEDEFAULT;

    // Window info - window title
    char window_name[] = "cefcapi example";
    cef_string_t cef_window_name = {};
    cef_string_utf8_to_utf16(window_name, strlen(window_name),
                             &cef_window_name);
    window_info.window_name = cef_window_name;

    // Initial url
    char url[] = "https://www.google.com/ncr";
    cef_string_t cef_url = {};
    cef_string_utf8_to_utf16(url, strlen(url), &cef_url);

    // Browser settings. It is mandatory to set the
    // "size" member.
    cef_browser_settings_t browser_settings = {};
    browser_settings.size = sizeof(cef_browser_settings_t);
    
    // Client handlers
    cef_client_t client = {};
    initialize_cef_client(&client);
    initialize_cef_life_span_handler(&g_life_span_handler);

    // Create browser asynchronously. There is also a
    // synchronous version of this function available.
    printf("cef_browser_host_create_browser\n");
    cef_browser_host_create_browser(&window_info, &client, &cef_url,
                                    &browser_settings, NULL);

    // Message loop. There is also cef_do_message_loop_work()
    // that allow for integrating with existing message loops.
    // On Windows for best performance you should set
    // cef_settings_t.multi_threaded_message_loop to true.
    // Note however that when you do that CEF UI thread is no
    // more application main thread and using CEF API is more
    // difficult and require using functions like cef_post_task
    // for running tasks on CEF UI thread.
    printf("cef_run_message_loop\n");
    cef_run_message_loop();

    // Shutdown CEF
    printf("cef_shutdown\n");
    cef_shutdown();

    return 0;
}
Esempio n. 6
0
	virtual void SetPath(const char* path)
	{
		cef_string_utf8_to_utf16(path, strlen(path), &m_rCookie.path);
	}
Esempio n. 7
0
	virtual void SetData(const char* data)
	{
		cef_string_utf8_to_utf16(data, strlen(data), &m_rCookie.value);
	}
Esempio n. 8
0
	virtual void SetName(const char* name)
	{
		cef_string_utf8_to_utf16(name, strlen(name), &m_rCookie.name);
	}
Esempio n. 9
0
	virtual void SetDomain(const char* domain)
	{
		cef_string_utf8_to_utf16(domain, strlen(domain), &m_rCookie.domain);
	}
Esempio n. 10
0
int main(int argc, char** argv) {
    // Main args.
    cef_main_args_t mainArgs = {};
    mainArgs.instance = GetModuleHandle(NULL);
    
    // Application handler and its callbacks.
    // cef_app_t structure must be filled. It must implement
    // reference counting. You cannot pass a structure 
    // initialized with zeroes.
    cef_app_t app = {};
    initialize_app_handler(&app);
    
    // Execute subprocesses.
    printf("cef_execute_process, argc=%d\n", argc);
    int code = cef_execute_process(&mainArgs, &app, NULL);
    if (code >= 0) {
        _exit(code);
    }
    
    // Application settings.
    // It is mandatory to set the "size" member.
    cef_settings_t settings = {};
    settings.size = sizeof(cef_settings_t);
    settings.no_sandbox = 1;

    // Initialize CEF.
    printf("cef_initialize\n");
    cef_initialize(&mainArgs, &settings, &app, NULL);

    // Create GTK window. You can pass a NULL handle 
    // to CEF and then it will create a window of its own.
    //initialize_gtk();
    //GtkWidget* hwnd = create_gtk_window("cefcapi example", 1024, 768);
    //cef_window_info_t windowInfo = {};
    //windowInfo.parent_widget = hwnd;

    cef_window_info_t windowInfo = {};
    windowInfo.style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN \
            | WS_CLIPSIBLINGS | WS_VISIBLE;
    windowInfo.parent_window = NULL;
    windowInfo.x = CW_USEDEFAULT;
    windowInfo.y = CW_USEDEFAULT;
    windowInfo.width = CW_USEDEFAULT;
    windowInfo.height = CW_USEDEFAULT;

    // Initial url.
    char cwd[1024] = "";
    if (getcwd(cwd, sizeof(cwd)) == '\0') {
        printf("ERROR: getcwd() failed\n");
    }
    char url[1024];
    snprintf(url, sizeof(url), "file://%s/example.html", cwd);
    // There is no _cef_string_t type.
    cef_string_t cefUrl = {};
    cef_string_utf8_to_utf16(url, strlen(url), &cefUrl);
    
    // Browser settings.
    // It is mandatory to set the "size" member.
    cef_browser_settings_t browserSettings = {};
    browserSettings.size = sizeof(cef_browser_settings_t);
    
    // Client handler and its callbacks.
    // cef_client_t structure must be filled. It must implement
    // reference counting. You cannot pass a structure 
    // initialized with zeroes.
    cef_client_t client = {};
    initialize_client_handler(&client);

    // Create browser.
    printf("cef_browser_host_create_browser\n");
    cef_browser_host_create_browser(&windowInfo, &client, &cefUrl,
            &browserSettings, NULL);

    // Message loop.
    printf("cef_run_message_loop\n");
    cef_run_message_loop();

    // Shutdown CEF.
    printf("cef_shutdown\n");
    cef_shutdown();

    return 0;
}