[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master b4f0c4c: Allow controlling where xwidget-webkit stores cookies
From: |
Po Lu |
Subject: |
master b4f0c4c: Allow controlling where xwidget-webkit stores cookies |
Date: |
Fri, 19 Nov 2021 07:04:45 -0500 (EST) |
branch: master
commit b4f0c4c694e1c00b4025fe16039b8940d97c66aa
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
Allow controlling where xwidget-webkit stores cookies
* doc/lispref/display.texi (Xwidgets): Document new function.
* etc/NEWS: Announce `xwidget-webkit-cookie-file' and
`xwidget-webkit-set-cookie-storage-file'.
* lisp/xwidget.el (xwidget-webkit-cookie-file): New user
option.
(xwidget-webkit-new-session): Set cookie storage file.
* src/xwidget.c (Fmake_xwidget): Create new context for
each unrelated widget.
(Fxwidget_webkit_set_cookie_storage_file): New function.
(syms_of_xwidget): Define new subr.
---
doc/lispref/display.texi | 12 ++++++++++++
etc/NEWS | 10 ++++++++++
lisp/xwidget.el | 13 +++++++++++++
src/xwidget.c | 38 +++++++++++++++++++++++++++++++++++++-
4 files changed, 72 insertions(+), 1 deletion(-)
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index e9b5070..a90be50 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -7012,6 +7012,18 @@ loaded.
The value returned is a float ranging between 0.0 and 1.0.
@end defun
+@defun xwidget-webkit-set-cookie-storage-file xwidget file
+Make the WebKit widget @var{xwidget} store cookies in @var{file}.
+
+@var{file} must be an absolute file path. The new setting will also
+take effect on any xwidget that was created with @var{xwidget} as the
+@code{related} argument to @code{make-xwidget}, and widgets related to
+those as well.
+
+If this function is not called at least once on @var{xwidget} or a
+related widget, @var{xwidget} will not store cookies on disk at all.
+@end defun
+
@node Buttons
@section Buttons
@cindex buttons in buffers
diff --git a/etc/NEWS b/etc/NEWS
index ad31b23..2d3f9da 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -493,6 +493,11 @@ This is a convenience function to extract the field data
from
Using this option you can control how the xwidget-webkit buffers are
named.
+---
+*** New user option 'xwidget-webkit-cookie-file'.
+Using this option you can set where and if the xwidget-webkit buffers
+save cookies set by web pages.
+
+++
*** New minor mode 'xwidget-webkit-edit-mode'.
When this mode is enabled, self-inserting characters and other common
@@ -882,6 +887,11 @@ These events are sent whenever an xwidget requests that
Emacs display
another xwidget. The only argument to this event is the xwidget that
should be displayed.
++++
+*** New function 'xwidget-webkit-set-cookie-storage-file'.
+This function is used to control where and if an xwidget stores
+cookies set by web pages on disk.
+
* Changes in Emacs 29.1 on Non-Free Operating Systems
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index b74e332..056315a 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -57,6 +57,7 @@
(declare-function xwidget-query-on-exit-flag "xwidget.c" (xwidget))
(declare-function xwidget-webkit-back-forward-list "xwidget.c" (xwidget
&optional limit))
(declare-function xwidget-webkit-estimated-load-progress "xwidget.c" (xwidget))
+(declare-function xwidget-webkit-set-cookie-storage-file "xwidget.c" (xwidget
file))
(defgroup xwidget nil
"Displaying native widgets in Emacs buffers."
@@ -107,6 +108,15 @@ It can use the following special constructs:
:type 'string
:version "29.1")
+(defcustom xwidget-webkit-cookie-file
+ (file-name-concat user-emacs-directory
+ "xwidget-webkit-cookies.txt")
+ "A path to the file where xwidget-webkit-browse-url will store cookies.
+They will be stored as plain text in Mozilla `cookies.txt'
+format. If nil, cookies will not be stored."
+ :type 'string
+ :version "29.1")
+
;;;###autoload
(defun xwidget-webkit-browse-url (url &optional new-session)
"Ask xwidget-webkit to browse URL.
@@ -794,6 +804,9 @@ For example, use this to display an anchor."
(xwidget-window-inside-pixel-width (selected-window))
(xwidget-window-inside-pixel-height (selected-window))
nil current-session)))
+ (when xwidget-webkit-cookie-file
+ (xwidget-webkit-set-cookie-storage-file
+ xw (expand-file-name xwidget-webkit-cookie-file)))
(xwidget-put xw 'callback callback)
(xwidget-webkit-mode)
(xwidget-webkit-goto-uri (xwidget-webkit-last-session) url)))
diff --git a/src/xwidget.c b/src/xwidget.c
index 2f930dc..4e84d43 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -188,7 +188,9 @@ fails. */)
|| !XWIDGETP (related)
|| !EQ (XXWIDGET (related)->type, Qwebkit))
{
- xw->widget_osr = webkit_web_view_new ();
+ WebKitWebContext *ctx = webkit_web_context_new ();
+ xw->widget_osr = webkit_web_view_new_with_context (ctx);
+ g_object_unref (ctx);
webkit_web_view_load_uri (WEBKIT_WEB_VIEW (xw->widget_osr),
"about:blank");
@@ -2580,6 +2582,39 @@ is to completely loading its page. */)
}
#endif
+DEFUN ("xwidget-webkit-set-cookie-storage-file",
+ Fxwidget_webkit_set_cookie_storage_file,
Sxwidget_webkit_set_cookie_storage_file,
+ 2, 2, 0, doc: /* Make the WebKit widget XWIDGET load and store cookies
in FILE.
+
+Cookies will be stored as plain text in FILE, which must be an
+absolute file path. All xwidgets related to XWIDGET will also be
+changed to store and load cookies in FILE. */)
+ (Lisp_Object xwidget, Lisp_Object file)
+{
+#ifdef USE_GTK
+ struct xwidget *xw;
+ WebKitWebView *webview;
+ WebKitWebContext *context;
+ WebKitCookieManager *manager;
+
+ CHECK_LIVE_XWIDGET (xwidget);
+ xw = XXWIDGET (xwidget);
+ CHECK_WEBKIT_WIDGET (xw);
+ CHECK_STRING (file);
+
+ block_input ();
+ webview = WEBKIT_WEB_VIEW (xw->widget_osr);
+ context = webkit_web_view_get_context (webview);
+ manager = webkit_web_context_get_cookie_manager (context);
+ webkit_cookie_manager_set_persistent_storage (manager,
+ SSDATA (ENCODE_UTF_8 (file)),
+
WEBKIT_COOKIE_PERSISTENT_STORAGE_TEXT);
+ unblock_input ();
+#endif
+
+ return Qnil;
+}
+
void
syms_of_xwidget (void)
{
@@ -2620,6 +2655,7 @@ syms_of_xwidget (void)
defsubr (&Sxwidget_webkit_next_result);
defsubr (&Sxwidget_webkit_previous_result);
defsubr (&Sset_xwidget_buffer);
+ defsubr (&Sxwidget_webkit_set_cookie_storage_file);
#ifdef USE_GTK
defsubr (&Sxwidget_webkit_load_html);
defsubr (&Sxwidget_webkit_back_forward_list);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master b4f0c4c: Allow controlling where xwidget-webkit stores cookies,
Po Lu <=