- if(!(c = calloc(1, sizeof(Client))))
- die("Cannot malloc!\n");
- /* Window */
- if(embed) {
- c->win = gtk_plug_new(0);
- }
- else {
- c->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_wmclass(GTK_WINDOW(c->win), "surf", "surf");
- }
- gtk_window_set_default_size(GTK_WINDOW(c->win), 800, 600);
- g_signal_connect(G_OBJECT(c->win), "destroy", G_CALLBACK(destroywin), c);
- g_signal_connect(G_OBJECT(c->win), "key-press-event", G_CALLBACK(keypress), c);
-
- /* VBox */
- c->vbox = gtk_vbox_new(FALSE, 0);
-
- /* scrolled window */
- c->scroll = gtk_scrolled_window_new(NULL, NULL);
- gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(c->scroll),
- GTK_POLICY_NEVER, GTK_POLICY_NEVER);
-
- /* webview */
- c->view = WEBKIT_WEB_VIEW(webkit_web_view_new());
- g_signal_connect(G_OBJECT(c->view), "title-changed", G_CALLBACK(titlechange), c);
- g_signal_connect(G_OBJECT(c->view), "load-progress-changed", G_CALLBACK(progresschange), c);
- g_signal_connect(G_OBJECT(c->view), "load-committed", G_CALLBACK(loadcommit), c);
- g_signal_connect(G_OBJECT(c->view), "load-started", G_CALLBACK(loadstart), c);
- g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c);
- g_signal_connect(G_OBJECT(c->view), "create-web-view", G_CALLBACK(newwindow), c);
- g_signal_connect(G_OBJECT(c->view), "download-requested", G_CALLBACK(initdownload), c);
- g_signal_connect_after(session, "request-started", G_CALLBACK(request), c);
-
- /* urlbar */
- c->urlbar = gtk_entry_new();
- gtk_entry_set_has_frame(GTK_ENTRY(c->urlbar), FALSE);
- g_signal_connect(G_OBJECT(c->urlbar), "focus-out-event", G_CALLBACK(unfocusbar), c);
-
- /* searchbar */
- c->searchbar = gtk_entry_new();
- gtk_entry_set_has_frame(GTK_ENTRY(c->searchbar), FALSE);
- g_signal_connect(G_OBJECT(c->searchbar), "focus-out-event", G_CALLBACK(unfocusbar), c);
-
- /* indicator */
- c->indicator = gtk_drawing_area_new();
- gtk_widget_set_size_request(c->indicator, 0, 2);
- g_signal_connect (G_OBJECT (c->indicator), "expose_event",
- G_CALLBACK (exposeindicator), c);
-
- /* downloadbar */
-
- /* Arranging */
- gtk_container_add(GTK_CONTAINER(c->scroll), GTK_WIDGET(c->view));
- gtk_container_add(GTK_CONTAINER(c->win), c->vbox);
- gtk_container_add(GTK_CONTAINER(c->vbox), c->scroll);
- gtk_container_add(GTK_CONTAINER(c->vbox), c->searchbar);
- gtk_container_add(GTK_CONTAINER(c->vbox), c->urlbar);
- gtk_container_add(GTK_CONTAINER(c->vbox), c->indicator);
-
- /* Setup */
- gtk_box_set_child_packing(GTK_BOX(c->vbox), c->urlbar, FALSE, FALSE, 0, GTK_PACK_START);
- gtk_box_set_child_packing(GTK_BOX(c->vbox), c->searchbar, FALSE, FALSE, 0, GTK_PACK_START);
- gtk_box_set_child_packing(GTK_BOX(c->vbox), c->indicator, FALSE, FALSE, 0, GTK_PACK_START);
- gtk_box_set_child_packing(GTK_BOX(c->vbox), c->scroll, TRUE, TRUE, 0, GTK_PACK_START);
- gtk_widget_grab_focus(GTK_WIDGET(c->view));
- gtk_widget_hide_all(c->searchbar);
- gtk_widget_hide_all(c->urlbar);
- gtk_widget_show(c->vbox);
- gtk_widget_show(c->indicator);
- gtk_widget_show(c->scroll);
- gtk_widget_show(GTK_WIDGET(c->view));
- gtk_widget_show(c->win);
- gdk_window_set_events(GTK_WIDGET(c->win)->window, GDK_ALL_EVENTS_MASK);
- gdk_window_add_filter(GTK_WIDGET(c->win)->window, processx, c);
- webkit_web_view_set_full_content_zoom(c->view, TRUE);
- settings = webkit_web_view_get_settings(c->view);
- g_object_set (G_OBJECT(settings), "user-agent", "surf", NULL);
- filename = g_build_filename(workdir, "style.css", NULL);
- filename = g_strdup_printf("file://%s", filename);
- g_object_set (G_OBJECT(settings), "user-stylesheet-uri", filename, NULL);
-
- c->download = NULL;
- c->title = NULL;
- c->next = clients;
- clients = c;
- if(showxid) {
- gdk_display_sync(gtk_widget_get_display(c->win));
- printf("%u\n", (guint)GDK_WINDOW_XID(GTK_WIDGET(c->win)->window));
- fflush(NULL);
+WebKitWebView *
+newview(Client *c, WebKitWebView *rv)
+{
+ WebKitWebView *v;
+ WebKitSettings *settings;
+ WebKitUserContentManager *contentmanager;
+ WebKitWebContext *context;
+
+ /* Webview */
+ if (rv) {
+ v = WEBKIT_WEB_VIEW(
+ webkit_web_view_new_with_related_view(rv));
+ } else {
+ settings = webkit_settings_new_with_settings(
+ "auto-load-images", loadimages,
+ "default-font-size", defaultfontsize,
+ "enable-caret-browsing", enablecaretbrowsing,
+ "enable-developer-extras", enableinspector,
+ "enable-dns-prefetching", enablednsprefetching,
+ "enable-frame-flattening", enableframeflattening,
+ "enable-html5-database", enablecache,
+ "enable-html5-local-storage", enablecache,
+ "enable-javascript", enablescripts,
+ "enable-plugins", enableplugins,
+ NULL);
+/* For mor interesting settings, have a look at
+ * http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html */
+
+ if (strcmp(fulluseragent, "")) {
+ webkit_settings_set_user_agent(settings, fulluseragent);
+ } else if (surfuseragent) {
+ webkit_settings_set_user_agent_with_application_details(
+ settings, "Surf", VERSION);
+ }
+ useragent = webkit_settings_get_user_agent(settings);
+
+ contentmanager = webkit_user_content_manager_new();
+
+ context = webkit_web_context_new_with_website_data_manager(
+ webkit_website_data_manager_new(
+ "base-cache-directory", cachedir,
+ "base-data-directory", cachedir,
+ NULL));
+
+ /* rendering process model, can be a shared unique one
+ * or one for each view */
+ webkit_web_context_set_process_model(context,
+ WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
+ /* ssl */
+ webkit_web_context_set_tls_errors_policy(context, strictssl ?
+ WEBKIT_TLS_ERRORS_POLICY_FAIL :
+ WEBKIT_TLS_ERRORS_POLICY_IGNORE);
+ /* disk cache */
+ webkit_web_context_set_cache_model(context, enablecache ?
+ WEBKIT_CACHE_MODEL_WEB_BROWSER :
+ WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER);
+
+ /* Currently only works with text file to be compatible with curl */
+ webkit_cookie_manager_set_persistent_storage(
+ webkit_web_context_get_cookie_manager(context), cookiefile,
+ WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
+ /* cookie policy */
+ webkit_cookie_manager_set_accept_policy(
+ webkit_web_context_get_cookie_manager(context),
+ cookiepolicy_get());
+
+ g_signal_connect(G_OBJECT(context), "download-started",
+ G_CALLBACK(downloadstarted), c);
+
+ v = g_object_new(WEBKIT_TYPE_WEB_VIEW,
+ "settings", settings,
+ "user-content-manager", contentmanager,
+ "web-context", context,
+ NULL);