unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Po Lu <luangruo@yahoo.com>
To: Qiantan Hong <qthong@stanford.edu>
Cc: Andrew De Angelis <bobodeangelis@gmail.com>,
	 "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Re: [PATCH] Add user content APIs for WebKit Xwidgets
Date: Sun, 23 Oct 2022 18:58:10 +0800	[thread overview]
Message-ID: <874jvu6c3h.fsf@yahoo.com> (raw)
In-Reply-To: <B9632193-A02B-41C9-9443-C6B390A025AA@stanford.edu> (Qiantan Hong's message of "Sun, 23 Oct 2022 09:11:39 +0000")

Qiantan Hong <qthong@stanford.edu> writes:

> 1. I think that connecting signal to scriptor (now called manager)
> doesn't require xw to be marked, because it is also destroyed when xw
> is killed? Suppose that now I reference count correctly, manager
> should be owned by xw, just like the WebKitWebContext at line 363.

No, because webkit_web_view_new_with_related_view is used to create
WebKitWebView objects when an existing live xwidget is specified as the
related argument to `make-xwidget', and those will hold further
references to the content manager beyond the lifetime of the
WebKitWebView holding the initial reference to said content manager.  In
fact, won't userscripts apply to every WebKitWebView with the same
content manager?

I think I would prefer documenting and implementing userscripts as
applying to all related xwidgets: you could link each related xwidget
onto a circular queue, designate one as the "head", and hold a reference
to the head, replacing it with a different xwidget on the queue each
time the head is killed, until there are no more xwidgets on that queue,
at which point it becomes safe to free the userscript data.

> 2. I didn't fix the ARC assumption in NS port. I hope it can be fixed
> in one batch by Andrew. Thank you Andrew!

Sure, but please fix the redundant braces here:

> +      if ([message.body isEqualToString:@"C-g"])
> +        {
> +          /* Just give up focus, no relay "C-g" to emacs, another "C-g"
> +             follows will be handled by emacs.  */
> +          [self.window makeFirstResponder:self.xw->xv->emacswindow];
> +        }
> +    }
> +  else
> +    {
> +      store_xwidget_script_message_event (self.xw,
> +                                          message.name.UTF8String,
> +                                          js_to_lisp (message.body));
>      }

And some more comments below:

> +User scripts are custom JavaScript code that is automatically run in

This should read "User scripts are custom JavaScript code automatically
run in designated WebKit xwidgets as pages are being loaded".

> +void nsxwidget_webkit_add_user_script (struct xwidget *xw, const char *script,
> +                                       int injection_time_start, int main_frame_only);

I have a feeling the types here are also not supposed to be "int".

> +  WKUserScriptInjectionTime injectionTime = injection_time_start?
> +    WKUserScriptInjectionTimeAtDocumentStart : WKUserScriptInjectionTimeAtDocumentEnd;

Coding style warning: this should probably be

  (injection_time_start
   ? WKUserScriptInjectionTimeAtDocumentStart
   : WKUserScriptInjectionTimeAtDocumentEnd)

> +  Bool start;

Why this X library type, and not `bool'?

> +  if (EQ (when, Qstart))
> +    start = true;
> +  else if (EQ (when, Qend))
> +    start = false;

If you are going to use Bool, then the boolean constants used should be
True and False, but since Bool is only available on X Windows, that is
likely not what you want.

> +  else
> +    error ("Unknown Xwidget Webkit user script injection time: %s",
> +           SDATA (SYMBOL_NAME (when)));

"Xwidget Webkit" is not the correct capitalization.  The error message
should probably also be reworded, as I think I explained earlier.  Also,
since there are only two possible values here, this should be a boolean.

> +    = (!NILP (main_frame_only))
> +    ? WEBKIT_USER_CONTENT_INJECT_TOP_FRAME
> +    : WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES;

This should be:

  = (!NILP (main_frame_only)
     ? WEBKIT_USER_CONTENT_INJECT_TOP_FRAME
     : WEBKIT_USER_CONTENT_INJECT_ALL_FRAMES)

> +  WebKitUserScriptInjectionTime webkit_injection_time = start
> +    ? WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START
> +    : WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END;

Likewise.  (!NILP (start)
            ? WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START
            : WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_END)

> +#elif defined NS_IMPL_COCOA
> +  nsxwidget_webkit_add_user_script (xw, SSDATA (script), injection_time_start, mfo);
> +#endif

80 columns alert; I thought I also explained why not to use variable
names such as "mfo".

> +#elif defined NS_IMPL_COCOA
> +  nsxwidget_webkit_remove_all_user_scripts(xw);
> +#endif

Please put a space between the "ts" and "(".

> +This operation fails if NAME has already been registered for XWIDGET.  */)

Fails?  How?  This should mention that an error is signalled under that
situation.

> +  stpcpy (stpcpy (signal_name, "script-message-received::"), sname);

Maybe lispstpcpy is what you want here.

> +  if (webkit_user_content_manager_register_script_message_handler (manager, sname))
> +    {
> +      g_object_set_data (G_OBJECT (manager), XG_XWIDGET, xw);
> +    }

The braces here are redundant.  Please remove them.

> +DEFUN ("xwidget-webkit-unregister-script-message",
> +       Fxwidget_webkit_unregister_script_message, Sxwidget_webkit_unregister_script_message,
> +       2, 2, 0,
> +       doc: /* Unregister script message with NAME in Webkit XWIDGET.  */)
> +  (Lisp_Object xwidget, Lisp_Object name)

"Unregister the script message named NAME from the given WebKit widget..."

The library we use is capitalized "WebKit", not "Webkit".

> +  nsxwidget_webkit_unregister_script_message(xw, sname);

As I said earlier, there should be a space here.

> +  SAFE_FREE();

And here.

> +  defsubr (&Sxwidget_webkit_add_user_script);
> +  DEFSYM (Qstart, "start");
> +  DEFSYM (Qend, "end");
> +  defsubr (&Sxwidget_webkit_remove_all_user_scripts);
> +
> +  DEFSYM (Qscript_message, "script-message");
> +  defsubr (&Sxwidget_webkit_register_script_message);
> +  defsubr (&Sxwidget_webkit_unregister_script_message);

Why not make it so the DEFSYMS are placed together, away from the
defsubrs?



  reply	other threads:[~2022-10-23 10:58 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14  6:34 [PATCH] Add user content APIs for WebKit Xwidgets Qiantan Hong
2022-10-14  7:01 ` Po Lu
2022-10-14  7:12   ` Qiantan Hong
2022-10-14  7:35     ` Po Lu
2022-10-14 21:13       ` Qiantan Hong
2022-10-15  1:37         ` Qiantan Hong
2022-10-15  7:53           ` Qiantan Hong
2022-10-15 11:23             ` Po Lu
2022-10-15 18:29               ` Qiantan Hong
2022-10-16  0:26                 ` Po Lu
2022-10-15 23:33               ` Qiantan Hong
2022-10-16  4:32                 ` Po Lu
2022-10-16  6:29                   ` Qiantan Hong
2022-10-16  6:41                     ` Po Lu
2022-10-16  6:45                       ` Po Lu
2022-10-23  9:11                       ` Qiantan Hong
2022-10-23 10:58                         ` Po Lu [this message]
2022-10-23 22:16                           ` Qiantan Hong
2022-10-24  0:30                             ` Po Lu
2022-10-24  4:17                               ` Qiantan Hong
2022-10-24  5:38                                 ` Po Lu
2022-10-24  5:44                                   ` Qiantan Hong
2022-10-24  7:20                                     ` Po Lu
2022-10-16 20:51             ` [PATCH] Add user extension " Richard Stallman
2022-10-16 21:13               ` Alan Mackenzie
2022-10-18 11:58                 ` Richard Stallman
2022-10-17  5:31               ` Eli Zaretskii
2022-10-17  8:28                 ` Jean Louis
2022-10-19 17:04                   ` Richard Stallman
2022-10-19 19:06                     ` Eli Zaretskii
2022-10-20 19:46                 ` Richard Stallman
2022-10-21  5:51                   ` Eli Zaretskii
2022-10-21  6:02                     ` Po Lu
2022-10-23 19:14                     ` Richard Stallman
  -- strict thread matches above, loose matches on Subject: below --
2020-08-28  2:25 [PATCH] Add user content " Qiantan Hong
2020-08-28 14:37 ` Lars Ingebrigtsen
2020-08-28 15:41   ` Qiantan Hong
2020-08-30 13:43     ` Lars Ingebrigtsen
2020-08-29  4:07   ` Richard Stallman
2020-08-29  4:10 ` Richard Stallman
2020-08-29  4:45   ` Qiantan Hong

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=874jvu6c3h.fsf@yahoo.com \
    --to=luangruo@yahoo.com \
    --cc=bobodeangelis@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=qthong@stanford.edu \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).