Пример #1
0
Файл: test.c Проект: zmike/ecef
int
main(int argc, char *argv[])
{
   cef_main_args_t args = { .argc = argc, .argv = argv };
   cef_app_t *app;
   cef_settings_t settings;
   cef_window_info_t window_info = {0};
   cef_client_t *client;
   cef_browser_settings_t browser_settings;
   int ex;

   app = CEF_NEW(cef_app_t);
   cef_addref(app);

   ex = cef_execute_process(&args, app, NULL);
   if (ex >= 0)
     return ex;

   memset(&settings, 0, sizeof(cef_settings_t));
   memset(&browser_settings, 0, sizeof(cef_browser_settings_t));
   settings.size = sizeof(cef_settings_t);
   settings.windowless_rendering_enabled = 0;
   browser_settings.size = sizeof(cef_browser_settings_t);
   if (!cef_initialize(&args, &settings, app, NULL))
     return -1;
   window_info.width = 640;
   window_info.height = 480;
   client = CEF_NEW(cef_client_t);
   client->get_life_span_handler = client_life_span_handler_get;
   window_info.windowless_rendering_enabled = 0;
Пример #2
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;
}
Пример #3
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;
}