commit: 045639a21a6a93cb1bff37a8ddc5bd090e43d8b3
parent: 6fdbc560a5c6aad0569ddf1fdc1ae8eb08e5f3bf
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sun, 10 Mar 2019 13:43:16 +0100
badwolf.c: Fix opening a new tab & use multi-processing
Diffstat:
M | badwolf.c | 34 | ++++++++++++++++++++-------------- |
1 file changed, 20 insertions(+), 14 deletions(-)
diff --git a/badwolf.c b/badwolf.c
@@ -40,7 +40,7 @@ static gboolean SearchEntryCb_next__match(GtkSearchEntry *search, gpointer user_
static gboolean SearchEntryCb_previous__match(GtkSearchEntry *search, gpointer user_data);
static gboolean SearchEntryCb_search__changed(GtkSearchEntry *search, gpointer user_data);
static gboolean SearchEntryCb_stop__search(GtkSearchEntry *search, gpointer user_data);
-struct Client *new_browser(struct Window *window, gchar *target_url);
+struct Client *new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view);
void new_tabCb_clicked(GtkButton *new_tab, gpointer user_data);
int badwolf_new_tab(GtkNotebook *notebook, GtkWidget *box);
int main(int argc, char *argv[]);
@@ -142,12 +142,11 @@ static gboolean WebViewCb_mouse_target_changed(WebKitWebView *webView,
return TRUE;
}
-static WebKitWebView *WebViewCb_create(WebKitWebView *webView, WebKitNavigationAction *navigation_action, gpointer user_data)
+static WebKitWebView *WebViewCb_create(WebKitWebView *related_web_view, WebKitNavigationAction *navigation_action, gpointer user_data)
{
- (void)webView;
(void)navigation_action;
struct Window *window = (struct Window *)user_data;
- struct Client *browser = new_browser(window, NULL);
+ struct Client *browser = new_browser(window, NULL, related_web_view);
if(badwolf_new_tab(GTK_NOTEBOOK(window->notebook), browser->box) < 0) {
return NULL;
@@ -228,12 +227,10 @@ static gboolean SearchEntryCb_stop__search(GtkSearchEntry *search, gpointer user
return TRUE;
}
-struct Client *new_browser(struct Window *window, gchar *target_url)
+struct Client *new_browser(struct Window *window, gchar *target_url, WebKitWebView *related_web_view)
{
struct Client *browser = malloc(sizeof(struct Client));
- if(target_url == NULL) { target_url = "about:blank"; }
-
browser->window = window;
browser->box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
browser->toolbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
@@ -241,7 +238,18 @@ struct Client *new_browser(struct Window *window, gchar *target_url)
browser->search = gtk_search_entry_new();
browser->javascript = gtk_check_button_new();
browser->statusbar = gtk_label_new(NULL);
- browser->webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
+
+ if(related_web_view == NULL) {
+ WebKitWebContext *web_context = webkit_web_context_new_ephemeral();
+
+ webkit_web_context_set_process_model(web_context, WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES);
+
+ browser->webView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_context(web_context));
+
+ if(target_url == NULL) { target_url = "about:blank"; }
+ } else {
+ browser->webView = WEBKIT_WEB_VIEW(webkit_web_view_new_with_related_view(related_web_view));
+ }
gtk_box_pack_start(GTK_BOX(browser->toolbar), GTK_WIDGET(browser->javascript), FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(browser->toolbar), GTK_WIDGET(browser->location), TRUE, TRUE, 0);
@@ -254,7 +262,7 @@ struct Client *new_browser(struct Window *window, gchar *target_url)
gtk_widget_set_halign(browser->statusbar, GTK_ALIGN_START);
gtk_label_set_single_line_mode(GTK_LABEL(browser->statusbar), TRUE);
- gtk_entry_set_text(GTK_ENTRY(browser->location), target_url);
+ if(target_url != NULL) gtk_entry_set_text(GTK_ENTRY(browser->location), target_url);
gtk_entry_set_has_frame(GTK_ENTRY(browser->location), FALSE);
gtk_entry_set_input_purpose(GTK_ENTRY(browser->location), GTK_INPUT_PURPOSE_URL);
@@ -302,9 +310,7 @@ struct Client *new_browser(struct Window *window, gchar *target_url)
webkit_web_view_set_settings(browser->webView, settings);
- webkit_web_view_load_uri(browser->webView, target_url);
-
- // gtk_widget_grab_focus(GTK_WIDGET(browser->webView));
+ if(target_url != NULL) webkit_web_view_load_uri(browser->webView, target_url);
return browser;
}
@@ -329,7 +335,7 @@ void new_tabCb_clicked(GtkButton *new_tab, gpointer user_data)
{
(void)new_tab;
struct Window *window = (struct Window *)user_data;
- struct Client *browser = new_browser(window, NULL);
+ struct Client *browser = new_browser(window, NULL, NULL);
badwolf_new_tab(GTK_NOTEBOOK(window->notebook), browser->box);
}
@@ -354,7 +360,7 @@ int main(int argc, char *argv[])
gtk_container_add(GTK_CONTAINER(window->main_window), window->notebook);
- badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, target_url)->box);
+ badwolf_new_tab(GTK_NOTEBOOK(window->notebook), new_browser(window, target_url, NULL)->box);
g_signal_connect(window->main_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(window->new_tab, "clicked", G_CALLBACK(new_tabCb_clicked), window);