]> git.armaanb.net Git - chorizo.git/blobdiff - browser.c
Fix build with non-GNU sed, lint variables
[chorizo.git] / browser.c
index 2390b1cba0f4cdc862e72c81478e09bc4bb0ed5f..8df0e330777700e743a953d9cd7123db95e30109 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -38,12 +38,15 @@ void grab_environment_configuration(void);
 void grab_feeds_finished(GObject *, GAsyncResult *, gpointer);
 void hover_web_view(WebKitWebView *, WebKitHitTestResult *, guint, gpointer);
 void icon_location(GtkEntry *, GtkEntryIconPosition, GdkEvent *, gpointer);
+void init_default_web_context(void);
 gboolean key_common(GtkWidget *, GdkEvent *, gpointer);
 gboolean key_downloadmanager(GtkWidget *, GdkEvent *, gpointer);
 gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
 gboolean key_tablabel(GtkWidget *, GdkEvent *, gpointer);
 gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
 void mainwindow_setup(void);
+void mainwindow_title(gint);
+void notebook_switch_page(GtkNotebook *, GtkWidget *, guint, gpointer);
 gboolean quit_if_nothing_active(void);
 gboolean remote_msg(GIOChannel *, GIOCondition, gpointer);
 void run_user_scripts(WebKitWebView *);
@@ -90,7 +93,6 @@ gchar *fifo_suffix = "main";
 gdouble global_zoom = 1.0;
 gchar *history_file = NULL;
 gchar *home_uri = "about:blank";
-gboolean initial_wc_setup_done = FALSE;
 gchar *search_text = NULL;
 GtkPositionType tab_pos = GTK_POS_TOP;
 gint tab_width_chars = 20;
@@ -123,7 +125,6 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
            gboolean focus_tab)
 {
     struct Client *c;
-    WebKitWebContext *wc;
     gchar *f;
     GtkWidget *evbox, *tabbox;
 
@@ -149,7 +150,6 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
         c->web_view = webkit_web_view_new();
     else
         c->web_view = webkit_web_view_new_with_related_view(related_wv);
-    wc = webkit_web_view_get_context(WEBKIT_WEB_VIEW(c->web_view));
 
     webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(c->web_view), global_zoom);
     g_signal_connect(G_OBJECT(c->web_view), "notify::favicon",
@@ -177,21 +177,6 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
     g_signal_connect(G_OBJECT(c->web_view), "web-process-crashed",
                      G_CALLBACK(crashed_web_view), c);
 
-    if (!initial_wc_setup_done)
-    {
-        if (accepted_language[0] != NULL)
-            webkit_web_context_set_preferred_languages(wc, accepted_language);
-
-        g_signal_connect(G_OBJECT(wc), "download-started",
-                         G_CALLBACK(download_handle_start), NULL);
-
-        trust_user_certs(wc);
-
-        webkit_web_context_set_favicon_database_directory(wc, NULL);
-
-        initial_wc_setup_done = TRUE;
-    }
-
     if (user_agent != NULL)
         g_object_set(G_OBJECT(webkit_web_view_get_settings(WEBKIT_WEB_VIEW(c->web_view))),
                      "user-agent", user_agent, NULL);
@@ -242,6 +227,9 @@ client_new(const gchar *uri, WebKitWebView *related_wv, gboolean show,
     g_signal_connect(G_OBJECT(evbox), "scroll-event",
                      G_CALLBACK(key_tablabel), c);
 
+    /* For easy access, store a reference to our label. */
+    g_object_set_data(G_OBJECT(evbox), "lariza-tab-label", c->tablabel);
+
     /* This only shows the event box and the label inside, nothing else.
      * Needed because the evbox/label is "internal" to the notebook and
      * not part of the normal "widget tree" (IIUC). */
@@ -444,6 +432,7 @@ changed_title(GObject *obj, GParamSpec *pspec, gpointer data)
 
     gtk_label_set_text(GTK_LABEL(c->tablabel), t);
     gtk_widget_set_tooltip_text(c->tablabel, t);
+    mainwindow_title(gtk_notebook_get_current_page(GTK_NOTEBOOK(mw.notebook)));
 }
 
 void
@@ -643,7 +632,8 @@ ensure_uri_scheme(const gchar *t)
         !g_str_has_prefix(f, "https:") &&
         !g_str_has_prefix(f, "file:") &&
         !g_str_has_prefix(f, "about:") &&
-        !g_str_has_prefix(f, "data:"))
+        !g_str_has_prefix(f, "data:") &&
+        !g_str_has_prefix(f, "webkit:"))
     {
         g_free(f);
         fabs = realpath(t, NULL);
@@ -844,6 +834,38 @@ icon_location(GtkEntry *entry, GtkEntryIconPosition icon_pos, GdkEvent *event,
     }
 }
 
+void
+init_default_web_context(void)
+{
+    gchar *p;
+    WebKitWebContext *wc;
+
+    wc = webkit_web_context_get_default();
+
+    p = g_build_filename(g_get_user_config_dir(), __NAME__, "adblock.black", NULL);
+    webkit_web_context_set_sandbox_enabled(wc, TRUE);
+    webkit_web_context_add_path_to_sandbox(wc, p, TRUE);
+    g_free(p);
+
+    webkit_web_context_set_process_model(wc,
+        WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
+
+    p = g_build_filename(g_get_user_config_dir(), __NAME__, "web_extensions",
+                         NULL);
+    webkit_web_context_set_web_extensions_directory(wc, p);
+    g_free(p);
+
+    if (accepted_language[0] != NULL)
+        webkit_web_context_set_preferred_languages(wc, accepted_language);
+
+    g_signal_connect(G_OBJECT(wc), "download-started",
+                     G_CALLBACK(download_handle_start), NULL);
+
+    trust_user_certs(wc);
+
+    webkit_web_context_set_favicon_database_directory(wc, NULL);
+}
+
 gboolean
 key_common(GtkWidget *widget, GdkEvent *event, gpointer data)
 {
@@ -1082,6 +1104,30 @@ mainwindow_setup(void)
     gtk_notebook_set_scrollable(GTK_NOTEBOOK(mw.notebook), TRUE);
     gtk_notebook_set_tab_pos(GTK_NOTEBOOK(mw.notebook), tab_pos);
     gtk_container_add(GTK_CONTAINER(mw.win), mw.notebook);
+    g_signal_connect(G_OBJECT(mw.notebook), "switch-page",
+                     G_CALLBACK(notebook_switch_page), NULL);
+}
+
+void
+mainwindow_title(gint idx)
+{
+    GtkWidget *child, *widg, *tablabel;
+    const gchar *text;
+
+    child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(mw.notebook), idx);
+    if (child == NULL)
+        return;
+
+    widg = gtk_notebook_get_tab_label(GTK_NOTEBOOK(mw.notebook), child);
+    tablabel = (GtkWidget *)g_object_get_data(G_OBJECT(widg), "lariza-tab-label");
+    text = gtk_label_get_text(GTK_LABEL(tablabel));
+    gtk_window_set_title(GTK_WINDOW(mw.win), text);
+}
+
+void
+notebook_switch_page(GtkNotebook *nb, GtkWidget *p, guint idx, gpointer data)
+{
+    mainwindow_title(idx);
 }
 
 gboolean
@@ -1224,13 +1270,9 @@ trust_user_certs(WebKitWebContext *wc)
 int
 main(int argc, char **argv)
 {
-    gchar *c;
     int opt, i;
 
     gtk_init(&argc, &argv);
-    webkit_web_context_set_process_model(webkit_web_context_get_default(),
-        WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
-
     grab_environment_configuration();
 
     while ((opt = getopt(argc, argv, "C")) != -1)
@@ -1248,18 +1290,12 @@ main(int argc, char **argv)
 
     if (cooperative_instances)
         cooperation_setup();
-    downloadmanager_setup();
-
-    mainwindow_setup();
 
     if (!cooperative_instances || cooperative_alone)
-    {
-        c = g_build_filename(g_get_user_config_dir(), __NAME__, "web_extensions",
-                             NULL);
-        webkit_web_context_set_web_extensions_directory(
-            webkit_web_context_get_default(), c
-        );
-    }
+        init_default_web_context();
+
+    downloadmanager_setup();
+    mainwindow_setup();
 
     if (optind >= argc)
         client_new(home_uri, NULL, TRUE, TRUE);
@@ -1271,5 +1307,6 @@ main(int argc, char **argv)
 
     if (!cooperative_instances || cooperative_alone)
         gtk_main();
+
     exit(EXIT_SUCCESS);
 }