all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ricardo Wurmus <rekado@elephly.net>
To: "Perry E. Metzger" <perry@piermont.com>
Cc: emacs-devel@gnu.org
Subject: Re: fine grained control of webkit browsing
Date: Tue, 19 Jun 2018 18:19:07 +0200	[thread overview]
Message-ID: <87po0mvjes.fsf@elephly.net> (raw)
In-Reply-To: <20180619114906.4437a1f6@jabberwock.cb.piermont.com>

[-- Attachment #1: Type: text/plain, Size: 938 bytes --]


Perry E. Metzger <perry@piermont.com> 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 – we use JavaScript for telling the widget to scroll, for example.
(See “xwidget-webkit-scroll-bottom” or “xwidget-webkit-show-element”.)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: settings.patch --]
[-- Type: text/x-patch, Size: 7418 bytes --]

commit b1d2a1ad4a489838027e2f897f65190509a3c34f
Author: Ricardo Wurmus <rekado@elephly.net>
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);
 

[-- Attachment #3: Type: text/plain, Size: 12 bytes --]


--
Ricardo

  reply	other threads:[~2018-06-19 16:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-19 15:49 fine grained control of webkit browsing Perry E. Metzger
2018-06-19 16:19 ` Ricardo Wurmus [this message]
2018-06-19 16:37   ` Perry E. Metzger
2018-06-19 18:58     ` joakim
2018-06-19 20:51       ` Perry E. Metzger
2018-06-19 21:31         ` joakim
2018-06-20  0:19     ` T.V Raman
2018-06-19 22:57   ` Richard Stallman
2018-06-20  1:20     ` Perry E. Metzger
2018-06-20 23:26       ` Richard Stallman
2018-06-21  0:00         ` Perry E. Metzger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87po0mvjes.fsf@elephly.net \
    --to=rekado@elephly.net \
    --cc=emacs-devel@gnu.org \
    --cc=perry@piermont.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.