* mu-msg-body-view: use the navigation-policy-decision-requested signal so we

can distinguish user clicks (open externally) and things like iframes (open
  internally); require webkit >= 1.0.3
This commit is contained in:
Dirk-Jan C. Binnema 2011-01-16 13:53:39 +02:00
parent cc556dad8a
commit 6473546ef2
2 changed files with 30 additions and 12 deletions

View File

@ -117,7 +117,7 @@ AC_SUBST(GMIME_LIBS)
# webkit? needed for the fancy web widget
PKG_CHECK_MODULES(WEBKIT,webkit-1.0,[have_webkit=yes],[have_webkit=no])
PKG_CHECK_MODULES(WEBKIT,webkit-1.0 >= 1.0.3,[have_webkit=yes],[have_webkit=no])
AS_IF([test "x$have_webkit" = "xyes"],[
webkit_version="`pkg-config --modversion webkit-1.0`"])
AC_SUBST(WEBKIT_CFLAGS)

View File

@ -18,6 +18,9 @@
*/
#include <webkit/webkitwebview.h>
#include <webkit/webkitnetworkresponse.h>
#include <webkit/webkitwebnavigationaction.h>
#include <webkit/webkitwebpolicydecision.h>
#include "mu-msg-body-view.h"
#include <mu-msg-part.h>
@ -110,14 +113,29 @@ save_file_for_cid (MuMsg *msg, const char* cid)
return filepath;
}
static WebKitNavigationResponse
on_navigation_requested (MuMsgBodyView *self, WebKitWebFrame *frame,
WebKitNetworkRequest *request, gpointer data)
static gboolean
on_navigation_policy_decision_requested (MuMsgBodyView *self, WebKitWebFrame *frame,
WebKitNetworkRequest *request,
WebKitWebNavigationAction *nav_action,
WebKitWebPolicyDecision *policy_decision,
gpointer data)
{
const char* uri;
WebKitWebNavigationReason reason;
uri = webkit_network_request_get_uri (request);
reason = webkit_web_navigation_action_get_reason (nav_action);
/* if it wasn't a user click, do the navigation */
if (reason != WEBKIT_WEB_NAVIGATION_REASON_LINK_CLICKED) {
webkit_web_policy_decision_ignore (policy_decision);
return TRUE;
}
/* we handle links clicked ourselves, no need for navigation */
webkit_web_policy_decision_ignore (policy_decision);
/* if there are 'cmd:<action>" links in the body text of
* mu-internal messages (ie., notification from mu, not real
* e-mail messages), we emit the 'action requested'
@ -130,17 +148,19 @@ on_navigation_requested (MuMsgBodyView *self, WebKitWebFrame *frame,
signals[ACTION_REQUESTED], 0,
uri + 4);
}
return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
return TRUE;
}
/* don't try to play files on our local file system, this is not something
* external content should do.*/
if (!mu_util_is_local_file(uri))
mu_util_play (uri, FALSE, TRUE);
return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
return TRUE;
}
static void
on_resource_request_starting (MuMsgBodyView *self, WebKitWebFrame *frame,
WebKitWebResource *resource, WebKitNetworkRequest *request,
@ -188,11 +208,9 @@ mu_msg_body_view_init (MuMsgBodyView *obj)
/* to support cid: */
g_signal_connect (obj, "resource-request-starting",
G_CALLBACK (on_resource_request_starting), NULL);
/* handle navigation requests */
g_signal_connect (obj, "navigation-requested",
G_CALLBACK (on_navigation_requested), (void*)0x666);
g_signal_connect (obj, "navigation-policy-decision-requested",
G_CALLBACK (on_navigation_policy_decision_requested), NULL);
}
static void