emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XWidget/WebKit: Getting Web Content From Webkit To Emacs


From: joakim
Subject: Re: XWidget/WebKit: Getting Web Content From Webkit To Emacs
Date: Sat, 23 Jan 2016 22:56:56 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

address@hidden writes:

> Now that we have XWidget/Webkit --- I was wondering what it would take
> to get content from Webkit into Emacs --- this time in the form of
> "real content" rather than "What You See Is All You Have Content".
>
> Some Thoughts:
>
> 1. Would it be possible to get the DOM (as an html DOM a la EWW) from
> Webkit? That would give us content that Emacs ordinarily cannot get --
> e.g. content generated through script evaluation.

When I wrote the code there were some problems with that area of the
webkit api.

There is a start of an implementation of this functionality in the main
xwidget branch(not the xwidget_branch): xwidget-webkit-dom-dump

I attach the partial implementation below.


> 2. Ability to send events / scripts from Emacs to WebKit -- I see that
> some of this might already be possible from looking at the code in
> xwidget.el. It's not clear how Emacs can get at structured content
> returned by JS.


You can have a look at xwidget-webkit-execute-script-rv.

Sadly there wasn't a good function for returning values from webkit in
their api when I wrote the code. I haven't checked if that situation has
changed recently. The return value is pased by setting the
document.title. Ahem... I'm not sure about the limits of this mechanism,
it has been working for the things I've done anyway.



>
>
> 3. Function xwidget-webkit-copy-selection-as-kill will hopefully let
> me get the rendered text contents into the kill ring -- but how do I
> select the contents of a webkit buffer (without using a mouse)?

You will need to code something that moves the selection about by
sending js code to the webkit through xwidget-webkit-execute-script.

I haven't done something like that yet. 

Initial DOM dump experimental code.

-#ifdef HAVE_XLXW_DOMDUMP
-/* dom dumping is work in progress.
-   2 of the methods used from webkit are deprecated nowm and replacements 
sought
- */
-static void
-xwidget_webkit_dom_dump (WebKitDOMNode * parent)
-{
-  WebKitDOMNodeList *list;
-  int length;
-  WebKitDOMNode *attribute;
-  WebKitDOMNamedNodeMap *attrs;
-  WebKitDOMNode *child;
-  printf ("node:%d type:%d name:%s content:%s\n", parent,
-          webkit_dom_node_get_node_type (parent),
-          //1 element 3 text 8 comment 2 attribute
-          webkit_dom_node_get_local_name (parent),
-          webkit_dom_node_get_text_content (parent));
-
-  if (webkit_dom_node_has_attributes (parent))
-    {
-      attrs = webkit_dom_node_get_attributes (parent);
-
-      length = webkit_dom_named_node_map_get_length (attrs);
-      for (int i = 0; i < length; i++)
-        {
-          attribute = webkit_dom_named_node_map_item (attrs, i);
-          printf (" attr node:%d type:%d name:%s content:%s\n",
-                  attribute, webkit_dom_node_get_node_type (attribute),
-                  //1 element 3 text 8 comment
-                  webkit_dom_node_get_local_name (attribute),
-                  webkit_dom_node_get_text_content (attribute));
-        }
-    }
-  list = webkit_dom_node_get_child_nodes (parent);
-  length = webkit_dom_node_list_get_length (list);
-
-  for (int i = 0; i < length; i++)
-    {
-      child = webkit_dom_node_list_item (list, i);
-      //if(webkit_dom_node_has_child_nodes(child))
-      xwidget_webkit_dom_dump (child);
-    }
-}
-
-
-DEFUN ("xwidget-webkit-dom-dump",
-       Fxwidget_webkit_dom_dump, Sxwidget_webkit_dom_dump,
-       1, 1, 0, doc:   /*Dump the DOM contained in the webkit
-                          instance in XWIDGET. */
-       )
-  (Lisp_Object xwidget)
-{
-  WEBKIT_FN_INIT ();
-  xwidget_webkit_dom_dump (WEBKIT_DOM_NODE
-                           (webkit_web_view_get_dom_document
-                            (WEBKIT_WEB_VIEW (xw->widget_osr))));
-  return Qnil;
-}
-
-#endif /* HAVE_XLXW_DOMDUMP */

> -- 

-- 
Joakim Verona



reply via email to

[Prev in Thread] Current Thread [Next in Thread]