From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ricardo Wurmus Newsgroups: gmane.emacs.devel Subject: [PATCH 01/15] xwidget: Use WebKit2 API Date: Mon, 24 Oct 2016 18:40:47 +0200 Message-ID: <20161024164101.26043-2-rekado@elephly.net> References: <20161024164101.26043-1-rekado@elephly.net> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1477327447 29035 195.159.176.226 (24 Oct 2016 16:44:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 24 Oct 2016 16:44:07 +0000 (UTC) Cc: Ricardo Wurmus To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 24 18:44:01 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1byiLe-0004dl-Ml for ged-emacs-devel@m.gmane.org; Mon, 24 Oct 2016 18:43:42 +0200 Original-Received: from localhost ([::1]:48141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byiLh-0008DV-14 for ged-emacs-devel@m.gmane.org; Mon, 24 Oct 2016 12:43:45 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byiJs-0006aJ-Va for emacs-devel@gnu.org; Mon, 24 Oct 2016 12:41:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byiJo-00022e-FB for emacs-devel@gnu.org; Mon, 24 Oct 2016 12:41:53 -0400 Original-Received: from sender163-mail.zoho.com ([74.201.84.163]:21435) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1byiJo-00022I-6m for emacs-devel@gnu.org; Mon, 24 Oct 2016 12:41:48 -0400 Original-Received: from localhost (89.204.138.233 [89.204.138.233]) by mx.zohomail.com with SMTPS id 1477327306215698.759120999654; Mon, 24 Oct 2016 09:41:46 -0700 (PDT) X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161024164101.26043-1-rekado@elephly.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 74.201.84.163 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:208709 Archived-At: * configure.ac: Check for webkit2gtk-4.0. * src/xwidget.c: Adjust to use WebKit2 API. * lisp/xwidget.el (xwidget-webkit-callback): Adjust matches for `xwidget-event-type'. --- configure.ac | 4 +- lisp/xwidget.el | 5 +- src/xwidget.c | 186 ++++++++++++++++++++++++-------------------------------- 3 files changed, 84 insertions(+), 111 deletions(-) diff --git a/configure.ac b/configure.ac index 3f06eff..e16384b 100644 --- a/configure.ac +++ b/configure.ac @@ -2630,8 +2630,8 @@ if test "$with_xwidgets" != "no"; then test "$USE_GTK_TOOLKIT" = "GTK3" && test "$window_system" != "none" || AC_MSG_ERROR([xwidgets requested but gtk3 not used.]) - WEBKIT_REQUIRED=1.4.0 - WEBKIT_MODULES="webkitgtk-3.0 >= $WEBKIT_REQUIRED" + WEBKIT_REQUIRED=2.12 + WEBKIT_MODULES="webkit2gtk-4.0 >= $WEBKIT_REQUIRED" EMACS_CHECK_MODULES([WEBKIT], [$WEBKIT_MODULES]) HAVE_XWIDGETS=$HAVE_WEBKIT test $HAVE_XWIDGETS = yes || diff --git a/lisp/xwidget.el b/lisp/xwidget.el index 7a0ca8b..1bae6bb 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el @@ -187,7 +187,7 @@ XWIDGET instance, XWIDGET-EVENT-TYPE depends on the originating xwidget." "error: callback called for xwidget with dead buffer") (with-current-buffer (xwidget-buffer xwidget) (let* ((strarg (nth 3 last-input-event))) - (cond ((eq xwidget-event-type 'document-load-finished) + (cond ((eq xwidget-event-type 'load-changed) (xwidget-log "webkit finished loading: '%s'" (xwidget-webkit-get-title xwidget)) ;;TODO - check the native/internal scroll @@ -196,8 +196,7 @@ XWIDGET instance, XWIDGET-EVENT-TYPE depends on the originating xwidget." (rename-buffer (format "*xwidget webkit: %s *" (xwidget-webkit-get-title xwidget))) (pop-to-buffer (current-buffer))) - ((eq xwidget-event-type - 'navigation-policy-decision-requested) + ((eq xwidget-event-type 'decide-policy) (if (string-match ".*#\\(.*\\)" strarg) (xwidget-webkit-show-id-or-named-element xwidget diff --git a/src/xwidget.c b/src/xwidget.c index f5f4da0..78349a8 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -27,10 +27,7 @@ along with GNU Emacs. If not, see . */ #include "keyboard.h" #include "gtkutil.h" -#include -#include -#include -#include +#include static struct xwidget * allocate_xwidget (void) @@ -50,34 +47,16 @@ allocate_xwidget_view (void) static struct xwidget_view *xwidget_view_lookup (struct xwidget *, struct window *); -static void webkit_document_load_finished_cb (WebKitWebView *, WebKitWebFrame *, - gpointer); -static gboolean webkit_download_cb (WebKitWebView *, WebKitDownload *, gpointer); +static void webkit_view_load_changed_cb (WebKitWebView *, + WebKitLoadEvent, + gpointer); +static gboolean webkit_download_cb (WebKitWebContext *, WebKitDownload *, gpointer); static gboolean -webkit_mime_type_policy_typedecision_requested_cb (WebKitWebView *, - WebKitWebFrame *, - WebKitNetworkRequest *, - gchar *, - WebKitWebPolicyDecision *, - gpointer); - -static gboolean -webkit_new_window_policy_decision_requested_cb (WebKitWebView *, - WebKitWebFrame *, - WebKitNetworkRequest *, - WebKitWebNavigationAction *, - WebKitWebPolicyDecision *, - gpointer); - -static gboolean -webkit_navigation_policy_decision_requested_cb (WebKitWebView *, - WebKitWebFrame *, - WebKitNetworkRequest *, - WebKitWebNavigationAction *, - WebKitWebPolicyDecision *, - gpointer); - +webkit_decide_policy_cb (WebKitWebView *, + WebKitPolicyDecision *, + WebKitPolicyDecisionType, + gpointer); DEFUN ("make-xwidget", @@ -168,29 +147,17 @@ Returns the newly constructed xwidget, or nil if construction fails. */) if (EQ (xw->type, Qwebkit)) { g_signal_connect (G_OBJECT (xw->widget_osr), - "document-load-finished", - G_CALLBACK (webkit_document_load_finished_cb), xw); + "load-changed", + G_CALLBACK (webkit_view_load_changed_cb), xw); - g_signal_connect (G_OBJECT (xw->widget_osr), - "download-requested", + g_signal_connect (G_OBJECT (webkit_web_context_get_default ()), + "download-started", G_CALLBACK (webkit_download_cb), xw); g_signal_connect (G_OBJECT (xw->widget_osr), - "mime-type-policy-decision-requested", - G_CALLBACK - (webkit_mime_type_policy_typedecision_requested_cb), - xw); - - g_signal_connect (G_OBJECT (xw->widget_osr), - "new-window-policy-decision-requested", - G_CALLBACK - (webkit_new_window_policy_decision_requested_cb), - xw); - - g_signal_connect (G_OBJECT (xw->widget_osr), - "navigation-policy-decision-requested", + "decide-policy", G_CALLBACK - (webkit_navigation_policy_decision_requested_cb), + (webkit_decide_policy_cb), xw); } @@ -284,81 +251,83 @@ store_xwidget_event_string (struct xwidget *xw, const char *eventname, kbd_buffer_store_event (&event); } -/* TODO deprecated, use load-status. */ void -webkit_document_load_finished_cb (WebKitWebView *webkitwebview, - WebKitWebFrame *arg1, - gpointer data) +webkit_view_load_changed_cb (WebKitWebView *webkitwebview, + WebKitLoadEvent load_event, + gpointer data) { - struct xwidget *xw = g_object_get_data (G_OBJECT (webkitwebview), - XG_XWIDGET); - - store_xwidget_event_string (xw, "document-load-finished", ""); + switch (load_event) { + case WEBKIT_LOAD_FINISHED: + { + struct xwidget *xw = g_object_get_data (G_OBJECT (webkitwebview), + XG_XWIDGET); + store_xwidget_event_string (xw, "load-changed", ""); + break; + } + default: + break; + } } gboolean -webkit_download_cb (WebKitWebView *webkitwebview, +webkit_download_cb (WebKitWebContext *webkitwebcontext, WebKitDownload *arg1, gpointer data) { - struct xwidget *xw = g_object_get_data (G_OBJECT (webkitwebview), + WebKitWebView *view = webkit_download_get_web_view(arg1); + WebKitURIRequest *request = webkit_download_get_request(arg1); + struct xwidget *xw = g_object_get_data (G_OBJECT (view), XG_XWIDGET); - store_xwidget_event_string (xw, "download-requested", - webkit_download_get_uri (arg1)); + + store_xwidget_event_string (xw, "download-started", + webkit_uri_request_get_uri(request)); return FALSE; } static gboolean -webkit_mime_type_policy_typedecision_requested_cb (WebKitWebView *webView, - WebKitWebFrame *frame, - WebKitNetworkRequest *request, - gchar *mimetype, - WebKitWebPolicyDecision *policy_decision, - gpointer user_data) +webkit_decide_policy_cb (WebKitWebView *webView, + WebKitPolicyDecision *decision, + WebKitPolicyDecisionType type, + gpointer user_data) { - /* This function makes webkit send a download signal for all unknown - mime types. TODO: Defer the decision to Lisp, so that it's - possible to make Emacs handle mime text for instance. */ - if (!webkit_web_view_can_show_mime_type (webView, mimetype)) + switch (type) { + case WEBKIT_POLICY_DECISION_TYPE_RESPONSE: + /* This function makes webkit send a download signal for all unknown + mime types. TODO: Defer the decision to Lisp, so that it's + possible to make Emacs handle mime text for instance. */ { - webkit_web_policy_decision_download (policy_decision); - return TRUE; + WebKitResponsePolicyDecision *response = + WEBKIT_RESPONSE_POLICY_DECISION (decision); + if (!webkit_response_policy_decision_is_mime_type_supported (response)) + { + webkit_policy_decision_download (decision); + return TRUE; + } + else + return FALSE; + break; } - else + case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION: + case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: + { + WebKitNavigationPolicyDecision *navigation_decision = + WEBKIT_NAVIGATION_POLICY_DECISION (decision); + WebKitNavigationAction *navigation_action = + webkit_navigation_policy_decision_get_navigation_action (navigation_decision); + WebKitURIRequest *request = + webkit_navigation_action_get_request (navigation_action); + + struct xwidget *xw = g_object_get_data (G_OBJECT (webView), XG_XWIDGET); + store_xwidget_event_string (xw, "decide-policy", + webkit_uri_request_get_uri (request)); + return FALSE; + break; + } + default: return FALSE; + } } -static gboolean -webkit_new_window_policy_decision_requested_cb (WebKitWebView *webView, - WebKitWebFrame *frame, - WebKitNetworkRequest *request, - WebKitWebNavigationAction *navigation_action, - WebKitWebPolicyDecision *policy_decision, - gpointer user_data) -{ - struct xwidget *xw = g_object_get_data (G_OBJECT (webView), XG_XWIDGET); - webkit_web_navigation_action_get_original_uri (navigation_action); - - store_xwidget_event_string (xw, "new-window-policy-decision-requested", - webkit_web_navigation_action_get_original_uri - (navigation_action)); - return FALSE; -} - -static gboolean -webkit_navigation_policy_decision_requested_cb (WebKitWebView *webView, - WebKitWebFrame *frame, - WebKitNetworkRequest *request, - WebKitWebNavigationAction *navigation_action, - WebKitWebPolicyDecision *policy_decision, - gpointer user_data) -{ - struct xwidget *xw = g_object_get_data (G_OBJECT (webView), XG_XWIDGET); - store_xwidget_event_string (xw, "navigation-policy-decision-requested", - webkit_web_navigation_action_get_original_uri - (navigation_action)); - return FALSE; -} /* For gtk3 offscreen rendered widgets. */ static gboolean @@ -599,8 +568,13 @@ DEFUN ("xwidget-webkit-execute-script", { WEBKIT_FN_INIT (); CHECK_STRING (script); - webkit_web_view_execute_script (WEBKIT_WEB_VIEW (xw->widget_osr), - SSDATA (script)); + // TODO: provide callback function to do something with the return + // value! This allows us to get rid of the title hack. + webkit_web_view_run_javascript (WEBKIT_WEB_VIEW (xw->widget_osr), + SSDATA (script), + NULL, /*cancellable*/ + NULL, /*callback*/ + NULL /*user data*/); return Qnil; } -- 2.10.1