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: Re: fine grained control of webkit browsing Date: Tue, 19 Jun 2018 18:19:07 +0200 Message-ID: <87po0mvjes.fsf@elephly.net> References: <20180619114906.4437a1f6@jabberwock.cb.piermont.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1529425552 6248 195.159.176.226 (19 Jun 2018 16:25:52 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 19 Jun 2018 16:25:52 +0000 (UTC) User-Agent: mu4e 1.0; emacs 26.1 Cc: emacs-devel@gnu.org To: "Perry E. Metzger" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 19 18:25:47 2018 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 1fVJRt-0001NY-Hk for ged-emacs-devel@m.gmane.org; Tue, 19 Jun 2018 18:25:41 +0200 Original-Received: from localhost ([::1]:43630 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVJU0-00009G-MA for ged-emacs-devel@m.gmane.org; Tue, 19 Jun 2018 12:27:52 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVJLr-0001oF-8A for emacs-devel@gnu.org; Tue, 19 Jun 2018 12:19:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVJLn-0004Jn-W6 for emacs-devel@gnu.org; Tue, 19 Jun 2018 12:19:27 -0400 Original-Received: from sender-of-o51.zoho.com ([135.84.80.216]:21026) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fVJLn-0004HZ-I1 for emacs-devel@gnu.org; Tue, 19 Jun 2018 12:19:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1529425155; s=zoho; d=elephly.net; i=rekado@elephly.net; h=References:From:To:Cc:Subject:In-reply-to:Date:Message-ID:MIME-Version:Content-Type; l=8344; bh=/sAAqnRXI4vIzDGoUG8qFztaqAVAK6wPX4Vx3J8XjhU=; b=XB32DtSr8LAKtRX/quIrSkFIqGRJ5Em9XMJGqDCjZvui1YGofh+A9ePWr94ZvGDK IGtAMfHVswVMJJ5/UwYlkPBjTQ/5lU5yWUxs92vvR/GuCb6+04seV0z98uJT7lsrH7x EH29m3i/McUQ853WIKP3Th/xdLnU5GNyUlQbgMbY= Original-Received: from localhost (141.80.247.141 [141.80.247.141]) by mx.zohomail.com with SMTPS id 1529425154980216.50741731737003; Tue, 19 Jun 2018 09:19:14 -0700 (PDT) In-reply-to: <20180619114906.4437a1f6@jabberwock.cb.piermont.com> X-URL: https://elephly.net X-PGP-Key: https://elephly.net/rekado.pubkey X-PGP-Fingerprint: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC X-ZohoMailClient: External X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 135.84.80.216 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:226515 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Perry E. Metzger writes: > 2) Say one wants to do things like viewing something with javascript > off and without loading remote elements (say because one wants to > safely view some HTML email). What does one need to do to get this > to work? The widget is not fully integrated into Emacs. The extent to which one can conveniently communicate with the widget is by sending a string containing a JavaScript program to the widget and have it return a value. Everything else requires exposing Webkit API features to Elisp. Attached is an old patch that I never submitted that allows one to set webkit settings via Elisp. Unfortunately, disabling JavaScript for the widget also disables JavaScript evaluation of strings that are sent from Emacs =E2=80=93 we use JavaScript for telling the widget to scroll, for exa= mple. (See =E2=80=9Cxwidget-webkit-scroll-bottom=E2=80=9D or =E2=80=9Cxwidget-web= kit-show-element=E2=80=9D.) --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=settings.patch commit b1d2a1ad4a489838027e2f897f65190509a3c34f Author: Ricardo Wurmus Date: Sat Oct 29 19:08:54 2016 +0200 webkit set settings diff --git a/lisp/xwidget.el b/lisp/xwidget.el index a4214f054a..11dfc061f2 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el @@ -39,6 +39,8 @@ (declare-function xwidget-buffer "xwidget.c" (xwidget)) (declare-function xwidget-size-request "xwidget.c" (xwidget)) (declare-function xwidget-resize "xwidget.c" (xwidget new-width new-height)) +(declare-function xwidget-webkit-set-settings "xwidget.c" + (xwidget settings)) (declare-function xwidget-webkit-execute-script "xwidget.c" (xwidget script &optional callback)) (declare-function xwidget-webkit-goto-uri "xwidget.c" (xwidget uri)) diff --git a/src/xwidget.c b/src/xwidget.c index 4fa906a9f0..fd0ca3edf1 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -751,6 +751,84 @@ argument procedure FUN.*/) return Qnil; } +DEFUN ("xwidget-webkit-set-settings", + Fxwidget_webkit_set_settings, Sxwidget_webkit_set_settings, + 2, 2, 0, + doc: /* Set the settings of the Webkit XWIDGET view to the +values specified in ALIST.*/) + (Lisp_Object xwidget, Lisp_Object alist) +{ + WEBKIT_FN_INIT (); + CHECK_LIST (alist); + + WebKitSettings *settings = webkit_web_view_get_settings (WEBKIT_WEB_VIEW (xw->widget_osr)); + + for (int i = 0; CONSP (alist); alist = XCDR (alist)) + { + Lisp_Object elt, key, val; + + elt = XCAR (alist); + key = Fcar (elt); + CHECK_SYMBOL (key); + val = Fcdr (elt); + + // TODO: use a macro instead? + if (EQ (key, Qwebkit_allow_file_access_from_file_urls)) + webkit_settings_set_allow_file_access_from_file_urls (settings, !NILP (val)); + else if (EQ (key, Qwebkit_allow_modal_dialogs)) + webkit_settings_set_allow_modal_dialogs (settings, !NILP (val)); + else if (EQ (key, Qwebkit_allow_file_access_from_file_urls)) + webkit_settings_set_allow_file_access_from_file_urls (settings, !NILP (val)); + else if (EQ (key, Qwebkit_allow_modal_dialogs)) + webkit_settings_set_allow_modal_dialogs (settings, !NILP (val)); + else if (EQ (key, Qwebkit_allow_universal_access_from_file_urls)) + webkit_settings_set_allow_universal_access_from_file_urls (settings, !NILP (val)); + else if (EQ (key, Qwebkit_auto_load_images)) + webkit_settings_set_auto_load_images (settings, !NILP (val)); + else if (EQ (key, Qwebkit_draw_compositing_indicators)) + webkit_settings_set_draw_compositing_indicators (settings, !NILP (val)); + else if (EQ (key, Qwebkit_enable_accelerated_2d_canvas)) + webkit_settings_set_enable_accelerated_2d_canvas (settings, !NILP (val)); + else if (EQ (key, Qwebkit_enable_caret_browsing)) + webkit_settings_set_enable_caret_browsing (settings, !NILP (val)); + else if (EQ (key, Qwebkit_enable_developer_extras)) + webkit_settings_set_enable_developer_extras (settings, !NILP (val)); + else if (EQ (key, Qwebkit_enable_dns_prefetching)) + webkit_settings_set_enable_dns_prefetching (settings, !NILP (val)); + else if (EQ (key, Qwebkit_enable_frame_flattening)) + webkit_settings_set_enable_frame_flattening (settings, !NILP (val)); + else if (EQ (key, Qwebkit_enable_javascript)) + webkit_settings_set_enable_javascript (settings, !NILP (val)); + else if (EQ (key, Qwebkit_enable_private_browsing)) + webkit_settings_set_enable_private_browsing (settings, !NILP (val)); + else if (EQ (key, Qwebkit_enable_webaudio)) + webkit_settings_set_enable_webaudio (settings, !NILP (val)); + else if (EQ (key, Qwebkit_enable_webgl)) + webkit_settings_set_enable_webgl (settings, !NILP (val)); + else if (EQ (key, Qwebkit_enable_write_console_messages_to_stdout)) + webkit_settings_set_enable_write_console_messages_to_stdout (settings, !NILP (val)); + else if (EQ (key, Qwebkit_enable_xss_auditor)) + webkit_settings_set_enable_xss_auditor (settings, !NILP (val)); + else if (EQ (key, Qwebkit_javascript_can_access_clipboard)) + webkit_settings_set_javascript_can_access_clipboard (settings, !NILP (val)); + else if (EQ (key, Qwebkit_javascript_can_open_windows_automatically)) + webkit_settings_set_javascript_can_open_windows_automatically (settings, !NILP (val)); + else if (EQ (key, Qwebkit_load_icons_ignoring_image_load_setting)) + webkit_settings_set_load_icons_ignoring_image_load_setting (settings, !NILP (val)); + else if (EQ (key, Qwebkit_media_playback_requires_user_gesture)) + webkit_settings_set_media_playback_requires_user_gesture (settings, !NILP (val)); + else if (EQ (key, Qwebkit_zoom_text_only)) + webkit_settings_set_zoom_text_only (settings, !NILP (val)); + else + signal_error ("Invalid webkit setting", key); + i++; + } + + webkit_web_view_set_settings (WEBKIT_WEB_VIEW (xw->widget_osr), settings); + return Qnil; +} + + DEFUN ("xwidget-resize", Fxwidget_resize, Sxwidget_resize, 3, 3, 0, doc: /* Resize XWIDGET. NEW_WIDTH, NEW_HEIGHT define the new size. */ ) (Lisp_Object xwidget, Lisp_Object new_width, Lisp_Object new_height) @@ -999,8 +1077,32 @@ syms_of_xwidget (void) defsubr (&Sxwidget_webkit_get_uri); defsubr (&Sxwidget_webkit_zoom); defsubr (&Sxwidget_webkit_execute_script); + defsubr (&Sxwidget_webkit_set_settings); DEFSYM (Qwebkit, "webkit"); + /* Symbols used for Webkit view settings */ + DEFSYM (Qwebkit_allow_file_access_from_file_urls, "webkit-allow-file-access-from-file-urls"); + DEFSYM (Qwebkit_allow_modal_dialogs, "webkit-allow-modal-dialogs"); + DEFSYM (Qwebkit_allow_universal_access_from_file_urls, "webkit-allow-universal-access-from-file-urls"); + DEFSYM (Qwebkit_auto_load_images, "webkit-auto-load-images"); + DEFSYM (Qwebkit_draw_compositing_indicators, "webkit-draw-compositing-indicators"); + DEFSYM (Qwebkit_enable_accelerated_2d_canvas, "webkit-enable-accelerated-2d-canvas"); + DEFSYM (Qwebkit_enable_caret_browsing, "webkit-enable-caret-browsing"); + DEFSYM (Qwebkit_enable_developer_extras, "webkit-enable-developer-extras"); + DEFSYM (Qwebkit_enable_dns_prefetching, "webkit-enable-dns-prefetching"); + DEFSYM (Qwebkit_enable_frame_flattening, "webkit-enable-frame-flattening"); + DEFSYM (Qwebkit_enable_javascript, "webkit-enable-javascript"); + DEFSYM (Qwebkit_enable_private_browsing, "webkit-enable-private-browsing"); + DEFSYM (Qwebkit_enable_webaudio, "webkit-enable-webaudio"); + DEFSYM (Qwebkit_enable_webgl, "webkit-enable-webgl"); + DEFSYM (Qwebkit_enable_write_console_messages_to_stdout, "webkit-enable-write-console-messages-to-stdout"); + DEFSYM (Qwebkit_enable_xss_auditor, "webkit-enable-xss-auditor"); + DEFSYM (Qwebkit_javascript_can_access_clipboard, "webkit-javascript-can-access-clipboard"); + DEFSYM (Qwebkit_javascript_can_open_windows_automatically, "webkit-javascript-can-open-windows-automatically"); + DEFSYM (Qwebkit_load_icons_ignoring_image_load_setting, "webkit-load-icons-ignoring-image-load-setting"); + DEFSYM (Qwebkit_media_playback_requires_user_gesture, "webkit-media-playback-requires-user-gesture"); + DEFSYM (Qwebkit_zoom_text_only, "webkit-zoom-text-only"); + defsubr (&Sxwidget_size_request); defsubr (&Sdelete_xwidget_view); --=-=-= Content-Type: text/plain -- Ricardo --=-=-=--