aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2012-05-30 01:11:56 +0800
committerCarlos Garcia Campos <carlosgc@gnome.org>2012-06-25 18:00:31 +0800
commit6f24b1f37b9f53907a848b4531ac90a7b830a206 (patch)
treee1ccc05e43645acd9fe6c94275c0321f0a87797f /embed
parentd5a3f08cb80d85dd9924d7d3a2cb828ad481c2e2 (diff)
downloadgsoc2013-epiphany-6f24b1f37b9f53907a848b4531ac90a7b830a206.tar
gsoc2013-epiphany-6f24b1f37b9f53907a848b4531ac90a7b830a206.tar.gz
gsoc2013-epiphany-6f24b1f37b9f53907a848b4531ac90a7b830a206.tar.bz2
gsoc2013-epiphany-6f24b1f37b9f53907a848b4531ac90a7b830a206.tar.lz
gsoc2013-epiphany-6f24b1f37b9f53907a848b4531ac90a7b830a206.tar.xz
gsoc2013-epiphany-6f24b1f37b9f53907a848b4531ac90a7b830a206.tar.zst
gsoc2013-epiphany-6f24b1f37b9f53907a848b4531ac90a7b830a206.zip
Port policy client to WebKit2
https://bugzilla.gnome.org/show_bug.cgi?id=678591
Diffstat (limited to 'embed')
-rw-r--r--embed/ephy-web-view.c62
1 files changed, 60 insertions, 2 deletions
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index ff3788cb7..93f79aa90 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1690,7 +1690,63 @@ ge_popup_blocked_cb (EphyWebView *view,
}
#ifdef HAVE_WEBKIT2
-/* TODO: Policy Client */
+static gboolean
+decide_policy_cb (WebKitWebView *web_view,
+ WebKitPolicyDecision *decision,
+ WebKitPolicyDecisionType decision_type,
+ gpointer user_data)
+{
+ WebKitResponsePolicyDecision *response_decision;
+ WebKitURIResponse *response;
+ EphyWebViewDocumentType type;
+ const gchar *mime_type;
+
+ if (decision_type != WEBKIT_POLICY_DECISION_TYPE_RESPONSE)
+ return FALSE;
+
+ response_decision = WEBKIT_RESPONSE_POLICY_DECISION (decision);
+ response = webkit_response_policy_decision_get_response (response_decision);
+ mime_type = webkit_uri_response_get_mime_type (response);
+
+ type = EPHY_WEB_VIEW_DOCUMENT_OTHER;
+ if (!strcmp (mime_type, "text/html") || !strcmp (mime_type, "text/plain"))
+ type = EPHY_WEB_VIEW_DOCUMENT_HTML;
+ else if (!strcmp (mime_type, "application/xhtml+xml"))
+ type = EPHY_WEB_VIEW_DOCUMENT_XML;
+ else if (!strncmp (mime_type, "image/", 6))
+ type = EPHY_WEB_VIEW_DOCUMENT_IMAGE;
+
+ /* FIXME: maybe it makes more sense to have an API to query the mime
+ * type when the load of a page starts than doing this here.
+ */
+ if (EPHY_WEB_VIEW (web_view)->priv->document_type != type) {
+ EPHY_WEB_VIEW (web_view)->priv->document_type = type;
+
+ g_object_notify (G_OBJECT (web_view), "document-type");
+ }
+
+ /* TODO: Check also Content-Disposition header before emitting
+ * handle-content signal. We need API for that in WebKit2.
+ */
+ if (!webkit_web_view_can_show_mime_type (web_view, mime_type)) {
+ GObject *single;
+ WebKitURIRequest *request;
+ const char *uri;
+ gboolean handled = FALSE;
+
+ single = ephy_embed_shell_get_embed_single (embed_shell);
+ request = webkit_response_policy_decision_get_request (response_decision);
+ g_signal_emit_by_name (single, "handle-content", mime_type, uri, &handled);
+
+ if (handled) {
+ webkit_policy_decision_ignore (decision);
+
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
#else
static gboolean
mime_type_policy_decision_requested_cb (WebKitWebView *web_view,
@@ -2578,7 +2634,9 @@ ephy_web_view_init (EphyWebView *web_view)
web_view);
#ifdef HAVE_WEBKIT2
- /* TODO: Policy Client */
+ g_signal_connect (web_view, "decide-policy",
+ G_CALLBACK (decide_policy_cb),
+ NULL);
#else
g_signal_connect (web_view, "mime-type-policy-decision-requested",
G_CALLBACK (mime_type_policy_decision_requested_cb),