* 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.
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
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
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.
+
\f
* Changes in Emacs 29.1 on Non-Free Operating Systems
(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."
: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.
(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)))
|| !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");
}
#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)
{
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);