X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fwidgets%2Fmodest-webkit-mime-part-view.c;h=fa1dd8de56c5bc90902eadaa329cd2e88b73f8ac;hb=0ca412c0351f777d1fb3e3ff12317a3068b01642;hp=5f2f4b5223f5d7f3fbeef45bf1667040212aa3bd;hpb=6a8fe003371ecec7cebacae8da72450b5adef4a3;p=modest diff --git a/src/widgets/modest-webkit-mime-part-view.c b/src/widgets/modest-webkit-mime-part-view.c index 5f2f4b5..fa1dd8d 100644 --- a/src/widgets/modest-webkit-mime-part-view.c +++ b/src/widgets/modest-webkit-mime-part-view.c @@ -62,6 +62,22 @@ static void on_resource_request_starting (WebKitWebView *webview, WebKitNetworkRequest *request, WebKitNetworkResponse *response, gpointer userdata); +static gboolean on_new_window_policy_decision_requested (WebKitWebView *web_view, + WebKitWebFrame *frame, + WebKitNetworkRequest *request, + WebKitWebNavigationAction *navigation_action, + WebKitWebPolicyDecision *policy_decision, + gpointer user_data); +static gboolean on_navigation_policy_decision_requested (WebKitWebView *web_view, + WebKitWebFrame *frame, + WebKitNetworkRequest *request, + WebKitWebNavigationAction *navigation_action, + WebKitWebPolicyDecision *policy_decision, + gpointer user_data); +static WebKitNavigationResponse on_navigation_requested (WebKitWebView *web_view, + WebKitWebFrame *frame, + WebKitNetworkRequest *request, + gpointer user_data); static void on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata); static gboolean update_style (ModestWebkitMimePartView *self); /* TnyMimePartView implementation */ @@ -124,6 +140,7 @@ struct _ModestWebkitMimePartViewPrivate { gboolean view_images; gboolean has_external_images; GSList *sighandlers; + gchar *last_search; }; #define MODEST_WEBKIT_MIME_PART_VIEW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \ @@ -295,8 +312,18 @@ modest_webkit_mime_part_view_init (ModestWebkitMimePartView *self) priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers, G_OBJECT (self), "resource-request-starting", G_CALLBACK (on_resource_request_starting), (gpointer) self); + priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers, + G_OBJECT (self), "navigation-policy-decision-requested", + G_CALLBACK (on_navigation_policy_decision_requested), (gpointer) self); + priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers, + G_OBJECT (self), "new-window-policy-decision-requested", + G_CALLBACK (on_new_window_policy_decision_requested), (gpointer) self); + priv->sighandlers = modest_signal_mgr_connect (priv->sighandlers, + G_OBJECT (self), "navigation-requested", + G_CALLBACK (on_navigation_requested), (gpointer) self); priv->part = NULL; + priv->last_search = NULL; priv->current_zoom = 1.0; priv->view_images = FALSE; priv->has_external_images = FALSE; @@ -325,6 +352,7 @@ modest_webkit_mime_part_view_finalize (GObject *obj) modest_signal_mgr_disconnect_all_and_destroy (priv->sighandlers); priv->sighandlers = NULL; + g_free (priv->last_search); G_OBJECT_CLASS (parent_class)->finalize (obj); } @@ -346,6 +374,24 @@ modest_webkit_mime_part_view_dispose (GObject *obj) /* WEBKIT SIGNALS HANDLERS */ +static WebKitNavigationResponse +on_navigation_requested (WebKitWebView *web_view, + WebKitWebFrame *frame, + WebKitNetworkRequest *request, + gpointer user_data) +{ + const gchar *uri; + + uri = webkit_network_request_get_uri (request); + if (g_strcmp0 (uri, "about:blank") == 0) { + return WEBKIT_NAVIGATION_RESPONSE_ACCEPT; + } else if (g_str_has_prefix (uri, "cid:") == 0) { + return WEBKIT_NAVIGATION_RESPONSE_DOWNLOAD; + } else { + return WEBKIT_NAVIGATION_RESPONSE_ACCEPT; + } +} + static void on_resource_request_starting (WebKitWebView *webview, WebKitWebFrame *frame, @@ -367,6 +413,58 @@ on_resource_request_starting (WebKitWebView *webview, webkit_network_request_set_uri (request, "about:blank"); } +static gboolean +on_navigation_policy_decision_requested (WebKitWebView *web_view, + WebKitWebFrame *frame, + WebKitNetworkRequest *request, + WebKitWebNavigationAction *navigation_action, + WebKitWebPolicyDecision *policy_decision, + gpointer user_data) +{ + WebKitWebNavigationReason reason; + reason = webkit_web_navigation_action_get_reason (navigation_action); + if (reason == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) { + const gchar *uri; + gboolean result; + + webkit_web_policy_decision_ignore (policy_decision); + uri = webkit_network_request_get_uri (WEBKIT_NETWORK_REQUEST (request)); + g_signal_emit_by_name (G_OBJECT (user_data), "activate-link", uri, &result); + + return TRUE; + } else if (reason != WEBKIT_WEB_NAVIGATION_REASON_OTHER) { + webkit_web_policy_decision_ignore (policy_decision); + return TRUE; + } + return FALSE; +} + +static gboolean +on_new_window_policy_decision_requested (WebKitWebView *web_view, + WebKitWebFrame *frame, + WebKitNetworkRequest *request, + WebKitWebNavigationAction *navigation_action, + WebKitWebPolicyDecision *policy_decision, + gpointer user_data) +{ + WebKitWebNavigationReason reason; + reason = webkit_web_navigation_action_get_reason (navigation_action); + if (reason == WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) { + const gchar *uri; + gboolean result; + + webkit_web_policy_decision_ignore (policy_decision); + uri = webkit_network_request_get_uri (WEBKIT_NETWORK_REQUEST (request)); + g_signal_emit_by_name (G_OBJECT (user_data), "activate-link", uri, &result); + + return TRUE; + } else if (reason != WEBKIT_WEB_NAVIGATION_REASON_OTHER) { + webkit_web_policy_decision_ignore (policy_decision); + return TRUE; + } + return FALSE; +} + static void on_notify_style (GObject *obj, GParamSpec *spec, gpointer userdata) { @@ -633,6 +731,7 @@ set_zoom (ModestWebkitMimePartView *self, gdouble zoom) priv = MODEST_WEBKIT_MIME_PART_VIEW_GET_PRIVATE (self); priv->current_zoom = zoom; + webkit_web_view_set_zoom_level (WEBKIT_WEB_VIEW (self), zoom); gtk_widget_queue_resize (GTK_WIDGET (self)); } @@ -652,13 +751,29 @@ static gboolean search (ModestWebkitMimePartView *self, const gchar *string) { - return FALSE; + ModestWebkitMimePartViewPrivate *priv; + + g_return_val_if_fail (MODEST_IS_WEBKIT_MIME_PART_VIEW (self), FALSE); + + priv = MODEST_WEBKIT_MIME_PART_VIEW_GET_PRIVATE (self); + g_free (priv->last_search); + priv->last_search = g_strdup (string); + webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (self), priv->last_search, FALSE, 0); + webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (self), TRUE); + return webkit_web_view_search_text (WEBKIT_WEB_VIEW (self), priv->last_search, FALSE, TRUE, TRUE); } static gboolean search_next (ModestWebkitMimePartView *self) { - return FALSE; + ModestWebkitMimePartViewPrivate *priv; + + g_return_val_if_fail (MODEST_IS_WEBKIT_MIME_PART_VIEW (self), FALSE); + + priv = MODEST_WEBKIT_MIME_PART_VIEW_GET_PRIVATE (self); + webkit_web_view_mark_text_matches (WEBKIT_WEB_VIEW (self), priv->last_search, FALSE, 0); + webkit_web_view_set_highlight_text_matches (WEBKIT_WEB_VIEW (self), TRUE); + return webkit_web_view_search_text (WEBKIT_WEB_VIEW (self), priv->last_search, FALSE, TRUE, FALSE); } static gboolean