Esempio n. 1
1
int main(int argc, char *argv[])
{
  //GtkBuilder *builder;
  //GtkWidget *scrolledWindow;

  //gtk_init (&argc, &argv);

  ///* Construct a GtkBuilder instance and load our UI description */
  //builder = gtk_builder_new ();
  //gtk_builder_add_from_file (builder, "builder.ui", NULL);

  // Create a browser instance

  /* Connect signal handlers to the constructed widgets. */
  //main_window = gtk_builder_get_object (builder, "main_window");
  //g_signal_connect (main_window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

  //scrolledWindow = GTK_WIDGET(gtk_builder_get_object (builder, "scrolledWindow"));
  //gtk_container_add(GTK_CONTAINER(scrolledWindow), GTK_WIDGET(webView));

  //// Set up callbacks so that if either the main window or the browser instance is
  //// closed, the program will exit
  //g_signal_connect(main_window, "destroy", G_CALLBACK(destroyWindowCb), NULL);
  //g_signal_connect(webView, "close-web-view", G_CALLBACK(closeWebViewCb), main_window);

  // Load a web page into the browser instance
  gtk_init(0, NULL);
  GtkWidget *main_window = gtk_offscreen_window_new();
  WebKitWebView *webView = WEBKIT_WEB_VIEW(webkit_web_view_new());

  gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(webView));
  webkit_web_view_load_uri(webView, "http://www.baidu.com/");



    gtk_widget_grab_focus(GTK_WIDGET(webView));
  // webView in not shown yet
  gtk_widget_show_all(GTK_WIDGET(main_window));

  webkit_web_view_get_snapshot(webView,
          WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT,
          WEBKIT_SNAPSHOT_OPTIONS_NONE,
          NULL,
          get_snapshot_finish,
          webView
          );
  gtk_main();
  return 0;
}
Esempio n. 2
0
cairo_surface_t* WebViewTest::getSnapshotAndWaitUntilReady(WebKitSnapshotRegion region, WebKitSnapshotOptions options)
{
    if (m_surface)
        cairo_surface_destroy(m_surface);
    m_surface = 0;
    webkit_web_view_get_snapshot(m_webView, region, options, 0, reinterpret_cast<GAsyncReadyCallback>(onSnapshotReady), this);
    g_main_loop_run(m_mainLoop);
    return m_surface;
}
Esempio n. 3
0
static void web_view_load_changed(WebKitWebView  *web_view,
                                   WebKitLoadEvent load_event,
                                   gpointer        user_data)
{
    switch (load_event) {
    case WEBKIT_LOAD_STARTED:
        /* New load, we have now a provisional URI */
        printf("%s: load start\n", webkit_web_view_get_uri(web_view));
        /* Here we could start a spinner or update the
         * location bar with the provisional URI */
        break;
    case WEBKIT_LOAD_REDIRECTED:
        printf("%s: redirect\n", webkit_web_view_get_uri(web_view));
        break;
    case WEBKIT_LOAD_COMMITTED:
        /* The load is being performed. Current URI is
         * the final one and it won't change unless a new
         * load is requested or a navigation within the
         * same page is performed */
        printf("%s: commit\n", webkit_web_view_get_uri(web_view));
        break;
    case WEBKIT_LOAD_FINISHED:
        printf("%s: finished\n", webkit_web_view_get_uri(web_view));
        /* Load finished, we can now stop the spinner */
        webkit_web_view_get_snapshot(web_view,
                WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT,
                WEBKIT_SNAPSHOT_OPTIONS_NONE,
                NULL,
                get_snapshot_finish,
                web_view

                );
        gchar *script;
        script = get_jsfile(config->jsfile);
        //const gchar *script = "JSON.stringify(window.performance.timing)";
        //script = "console.log('@#@#@#----console-')";
        webkit_web_view_run_javascript(web_view, script, NULL, web_view_javascript_finished, NULL);
        free(script);
        break;
    }
}
Esempio n. 4
0
static void load_changed(WebKitWebView *web_view, WebKitLoadEvent load_event, gpointer user_data) {
    if (load_event != WEBKIT_LOAD_FINISHED) {
        return;
    }

    if (mhtml_file != NULL) {
        GFile *f = g_file_new_for_path(mhtml_file);
        webkit_web_view_save_to_file(web_view, f, WEBKIT_SAVE_MODE_MHTML, NULL, mhtml_finished, NULL);
    }

    if (html_file != NULL) {
        WebKitWebResource *wr = webkit_web_view_get_main_resource(web_view);
        webkit_web_resource_get_data(wr, NULL, html_finished, NULL);
    }

    if (png_file != NULL) {
        webkit_web_view_get_snapshot(
            web_view,
            WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT,
            WEBKIT_SNAPSHOT_OPTIONS_NONE,
            NULL,
            png_finished,
            NULL
        );
    }

    if (title_file != NULL) {
        const gchar *title = webkit_web_view_get_title(web_view);
        GString *s = g_string_new(title);
        g_string_append_c(s, '\n');
        FILE *f = open_file(title_file, "w");
        if (fwrite(s->str, s->len, 1, f) != 1) {
            errx(1, "error saving title");
        }
        fclose(f);
        done();
    }
}
Esempio n. 5
0
static gboolean
load_finished_idle (gpointer data)
{
  static gint count = 0;

  gimp_progress_update ((gdouble) count * 0.025);

  count++;

  if (count < 10)
    return G_SOURCE_CONTINUE;

  webkit_web_view_get_snapshot (WEBKIT_WEB_VIEW (data),
                                WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT,
                                WEBKIT_SNAPSHOT_OPTIONS_NONE,
                                NULL,
                                snapshot_ready,
                                NULL);

  count = 0;

  return G_SOURCE_REMOVE;
}