Fixed non working 'open in new window' from right click menu (#29).
authorDaniel Carl <danielcarl@gmx.de>
Tue, 28 May 2013 20:59:09 +0000 (22:59 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Tue, 28 May 2013 20:59:09 +0000 (22:59 +0200)
I'm not happy with this implementation. At the moment I can see any other way
than creating a new webview and wait until it receives it's new URL and than
to destroy the webview to use the common logic to open a new instance of vimb.

src/main.c

index 8d790fa..e68e055 100644 (file)
@@ -52,6 +52,8 @@ static gboolean button_relase_cb(WebKitWebView *webview, GdkEventButton *event);
 static gboolean new_window_policy_cb(
     WebKitWebView *view, WebKitWebFrame *frame, WebKitNetworkRequest *request,
     WebKitWebNavigationAction *navig, WebKitWebPolicyDecision *policy);
+static WebKitWebView *create_web_view_cb(WebKitWebView *view, WebKitWebFrame *frame);
+static void create_web_view_received_uri_cb(WebKitWebView *view);
 static void hover_link_cb(WebKitWebView *webview, const char *title, const char *link);
 static void title_changed_cb(WebKitWebView *webview, WebKitWebFrame *frame, const char *title);
 static gboolean mimetype_decision_cb(WebKitWebView *webview,
@@ -742,6 +744,7 @@ static void setup_signals()
         "signal::notify::load-status", G_CALLBACK(webview_load_status_cb), NULL,
         "signal::button-release-event", G_CALLBACK(button_relase_cb), NULL,
         "signal::new-window-policy-decision-requested", G_CALLBACK(new_window_policy_cb), NULL,
+        "signal::create-web-view", G_CALLBACK(create_web_view_cb), NULL,
         "signal::hovering-over-link", G_CALLBACK(hover_link_cb), NULL,
         "signal::title-changed", G_CALLBACK(title_changed_cb), NULL,
         "signal::mime-type-policy-decision-requested", G_CALLBACK(mimetype_decision_cb), NULL,
@@ -858,6 +861,25 @@ static gboolean new_window_policy_cb(
     return false;
 }
 
+static WebKitWebView *create_web_view_cb(WebKitWebView *view, WebKitWebFrame *frame)
+{
+    WebKitWebView *new = WEBKIT_WEB_VIEW(webkit_web_view_new());
+
+    /* wait until the new webview receives its new URI */
+    g_signal_connect(new, "notify::uri", G_CALLBACK(create_web_view_received_uri_cb), NULL);
+
+    return new;
+}
+
+static void create_web_view_received_uri_cb(WebKitWebView *view)
+{
+    Arg a = {VB_TARGET_NEW, (char*)webkit_web_view_get_uri(view)};
+    /* destroy temporary webview */
+    webkit_web_view_stop_loading(view);
+    gtk_widget_destroy(GTK_WIDGET(view));
+    vb_load_uri(&a);
+}
+
 static void hover_link_cb(WebKitWebView *webview, const char *title, const char *link)
 {
     char *message;