Exemplo n.º 1
0
int main(int argc, gchar* argv[]) {
    gtk_init(&argc, &argv);

    GError *error = NULL;
    GOptionContext *context;
    context = g_option_context_new("URL");
    g_option_context_add_main_entries(context, entries, NULL);
    g_option_context_add_group(context, gtk_get_option_group(TRUE));
    if (!g_option_context_parse(context, &argc, &argv, &error)) {
        errx(1, "option parsing failed: %s", error->message);
    }

    if (argc < 2) {
        printf("Usage: %s [OPTION...] URL\n", argv[0]);
        printf("Try '%s --help' for more information.\n", argv[0]);
        return 1;
    }

    todo = (mhtml_file != NULL) + (html_file != NULL) + (png_file != NULL) + (title_file != NULL);
    if (!todo) {
        printf("Specify at least one of: --mhtml, --html, --png, --title\n");
        printf("Try '%s --help' for more information.\n", argv[0]);
        return 1;
    }

    const gchar *url = argv[1];
    if (g_uri_parse_scheme(url) == NULL) {
        errx(1, "invalid URI: %s", url);
    }

    WebKitWebView *web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
    g_signal_connect(web_view, "load-changed", G_CALLBACK(load_changed), NULL);
    g_signal_connect(web_view, "load-failed", G_CALLBACK(load_failed), NULL);

    WebKitSettings *settings = webkit_settings_new_with_settings(
        "user-agent", USER_AGENT,
        "enable-javascript", enable_js,
        "enable-java", FALSE,
        "enable-plugins", FALSE,
        "enable-private-browsing", TRUE,
        "enable-offline-web-application-cache", FALSE,
        "enable-page-cache", FALSE,
        NULL
    );
    webkit_web_view_set_settings(web_view, settings);

    GtkWidget *window = gtk_offscreen_window_new();
    gtk_window_set_default_size(GTK_WINDOW(window), 1280, 1024);
    gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(web_view));
    gtk_widget_show_all(window);

    webkit_web_view_load_uri(web_view, url);
    gtk_main();

    return 0;
}
void testWebKitSettingsNewWithSettings(Test* test, gconstpointer)
{
    GRefPtr<WebKitSettings> settings = adoptGRef(webkit_settings_new_with_settings("enable-javascript", FALSE,
                                                                                   "auto-load-images", FALSE,
                                                                                   "load-icons-ignoring-image-load-setting", TRUE,
                                                                                   NULL));
    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(settings.get()));
    g_assert(!webkit_settings_get_enable_javascript(settings.get()));
    g_assert(!webkit_settings_get_auto_load_images(settings.get()));
    g_assert(webkit_settings_get_load_icons_ignoring_image_load_setting(settings.get()));
}
static void testWebViewGroupSettings(Test* test, gconstpointer)
{
    GRefPtr<WebKitWebViewGroup> viewGroup1 = adoptGRef(webkit_web_view_group_new("TestGroup1"));
    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(viewGroup1.get()));
    GRefPtr<WebKitSettings> newSettings = adoptGRef(webkit_settings_new_with_settings("enable-javascript", FALSE, nullptr));
    test->assertObjectIsDeletedWhenTestFinishes(G_OBJECT(newSettings.get()));
    webkit_web_view_group_set_settings(viewGroup1.get(), newSettings.get());
    g_assert(webkit_web_view_group_get_settings(viewGroup1.get()) == newSettings.get());

    GRefPtr<WebKitWebView> webView1 = WEBKIT_WEB_VIEW(webkit_web_view_new_with_group(viewGroup1.get()));
    GRefPtr<WebKitWebView> webView2 = WEBKIT_WEB_VIEW(webkit_web_view_new());
    WebKitSettings* webView1Settings = webkit_web_view_get_settings(webView1.get());
    WebKitSettings* webView2Settings = webkit_web_view_get_settings(webView2.get());
    g_assert(webView1Settings != webView2Settings);
    g_assert(webkit_settings_get_enable_javascript(webView1Settings) != webkit_settings_get_enable_javascript(webView2Settings));

    webkit_web_view_set_settings(webView1.get(), webView2Settings);
    g_assert(webkit_web_view_get_settings(webView1.get()) == webView2Settings);
    g_assert(webkit_web_view_group_get_settings(webkit_web_view_get_group(webView1.get())) == webView2Settings);
}
Exemplo n.º 4
0
static gpointer
ephy_embed_prefs_init (gpointer user_data)
{
  guint i;

  webkit_settings = webkit_settings_new_with_settings ("enable-developer-extras", TRUE,
                                                       "enable-fullscreen", TRUE,
                                                       "enable-javascript", TRUE,
                                                       "enable-dns-prefetching", TRUE,
                                                       "javascript-can-open-windows-automatically", TRUE,
                                                       NULL);

  for (i = 0; i < G_N_ELEMENTS (webkit_pref_entries); i++) {
    GSettings *settings;
    char *key;

    settings = ephy_settings_get (webkit_pref_entries[i].schema);
    key = g_strconcat ("changed::", webkit_pref_entries[i].key, NULL);

    webkit_pref_entries[i].callback (settings,
                                     webkit_pref_entries[i].key,
                                     (gpointer)webkit_pref_entries[i].webkit_pref);

    g_signal_connect (settings, key,
                      G_CALLBACK (webkit_pref_entries[i].callback),
                      (gpointer)webkit_pref_entries[i].webkit_pref);
    g_free (key);
  }

  g_settings_bind (EPHY_SETTINGS_MAIN,
                   EPHY_PREFS_ENABLE_CARET_BROWSING,
                   webkit_settings, "enable-caret-browsing",
                   G_SETTINGS_BIND_GET);
  g_settings_bind (EPHY_SETTINGS_WEB,
                   EPHY_PREFS_WEB_ENABLE_PLUGINS,
                   webkit_settings, "enable-plugins",
                   G_SETTINGS_BIND_GET);
  g_settings_bind (EPHY_SETTINGS_WEB,
                   EPHY_PREFS_WEB_FONT_MIN_SIZE,
                   webkit_settings, "minimum-font-size",
                   G_SETTINGS_BIND_GET);
  g_settings_bind (EPHY_SETTINGS_WEB,
                   EPHY_PREFS_WEB_DEFAULT_ENCODING,
                   webkit_settings, DEFAULT_ENCODING_SETTING,
                   G_SETTINGS_BIND_GET);
  g_settings_bind (EPHY_SETTINGS_WEB,
                   EPHY_PREFS_WEB_ENABLE_WEBGL,
                   webkit_settings, "enable-webgl",
                   G_SETTINGS_BIND_GET);
  g_settings_bind (EPHY_SETTINGS_WEB,
                   EPHY_PREFS_WEB_ENABLE_WEBAUDIO,
                   webkit_settings, "enable-webaudio",
                   G_SETTINGS_BIND_GET);
  g_settings_bind (EPHY_SETTINGS_WEB,
                   EPHY_PREFS_WEB_ENABLE_SMOOTH_SCROLLING,
                   webkit_settings, "enable-smooth-scrolling",
                   G_SETTINGS_BIND_GET);
  g_settings_bind (EPHY_SETTINGS_WEB,
                   EPHY_PREFS_WEB_ENABLE_SITE_SPECIFIC_QUIRKS,
                   webkit_settings, "enable-site-specific-quirks",
                   G_SETTINGS_BIND_GET);
  return webkit_settings;
}