Adding DOM classes to CEF

Think CEF could benefit from a new feature or capability? Discuss CEF feature requests here.

Adding DOM classes to CEF

Postby ayoung24 » Sat Oct 17, 2009 6:30 pm

I'd like to work on adding DOM classes to CEF but I am unsure of where to start... any assistance would be appreciated... thanks.
ayoung24
Techie
 
Posts: 13
Joined: Sat Oct 17, 2009 6:26 pm

Re: Adding DOM classes to CEF

Postby magreenblatt » Sat Oct 17, 2009 11:51 pm

Here's what we'll need to do in order to support direct DOM access from CEF:

1. Identify the capabilities that we want to expose. See the WebCore::Document definition in third_party\WebKit\WebCore\dom\Document.h for what's supported by WebKit.
2. Work with the Chromium team to provide wrappers for WebCore::Document with an accessor from WebKit::WebFrame.
3. Add corresponding interfaces to CEF.

Note that it's currently possible to access the DOM using JavaScript and V8 handlers. See http://code.google.com/p/chromiumembedd ... tail?id=32 for an example of this approach.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Adding DOM classes to CEF

Postby ayoung24 » Mon Oct 19, 2009 4:15 pm

So we'd need to wrap everything in WebKit namespace classes? For example, instead of exposing WebCore::Document directly, we'd need to wrap it in a WebDocument (or something like that) before wrapping it with a CefDocument? Seems like a bit of overkill to me.

Is the DOM not exposed at all by WebFrame? The Objective-C WebFrame class has a 'DOMDocument' property which provides exactly what we need, but it doesn't seem to be in the C++ interface.
ayoung24
Techie
 
Posts: 13
Joined: Sat Oct 17, 2009 6:26 pm

Re: Adding DOM classes to CEF

Postby magreenblatt » Mon Oct 19, 2009 6:20 pm

So we'd need to wrap everything in WebKit namespace classes? For example, instead of exposing WebCore::Document directly, we'd need to wrap it in a WebDocument (or something like that) before wrapping it with a CefDocument?

The purpose of the Chromium WebKit API layer (hereafter referred to as "WebKit") is to insulate us from changes to the underlying WebCore framework. From a design standpoint WebKit is therefore the correct place to put these classes. From a support standpoint having Chromium developers helping to maintain this code would be wonderful. From a practical standpoint WebKit is controlled by Google and has been historically limited to functionality that the Chrome browser actually uses. This all means that, while we should make an effort to dialog with the Chromium developers about adding DOM support to WebKit, it shouldn't come as a surprise to us if they're not interested.

Assuming the Chromium developers decline we're left with two options. The first option is to integrate WebCore DOM wrappers directly into CEF. This option may be the easiest/fastest approach but could lead to significant maintenance headaches in the future. The second option is to create a "WebKit Extensions" library to hold this and other pieces of rejected WebKit API as may become necessary over time. This option requires more work initially (creating the WebKit classes) and has the same short-term maintenance headaches as the first option. It does, however, offer the potential to become less of a headache in the future if other consumers of WebKit find our "WebKit Extensions" library useful and choose to help out.

Is the DOM not exposed at all by WebFrame?

Nothing more than an NPObject. http://src.chromium.org/viewvc/chrome/t ... iew=markup
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Adding DOM classes to CEF

Postby magreenblatt » Tue Oct 20, 2009 3:56 pm

I've started a thread on this topic on chromium-dev:

http://groups.google.com/group/chromium ... c366daca09
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Adding DOM classes to CEF

Postby magreenblatt » Thu Oct 22, 2009 9:17 am

We're on our own with adding this functionality for now. I've created an issue to track our progress:
http://code.google.com/p/chromiumembedd ... tail?id=60
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Adding DOM classes to CEF

Postby magreenblatt » Thu Oct 22, 2009 12:36 pm

I think adding DOM support should be broken into two phases. The 1st phase should allow navigation and creation of DOM objects. The 2nd phase should add support for listeners. Here are the proposed interface changes for the 1st phase:

Code: Select all
class CefFrame : public CefBase
{
public:
  ...
 
  // Return the document contained in this frame. Only returns
  // successfully for HTML documents.
  /*--cef()--*/
  virtual CefRefPtr<CefDOMElement> GetDocument() =0;
};

// Class used to represent a DOM element.
/*--cef(source=library)--*/
class CefDOMElement : public CefBase
{
public:
  // Return the parent element.
  /*--cef()--*/
  virtual CefRefPtr<CefDOMElement> GetParent() =0;
 
  // Return the previous sibling element.
  /*--cef()--*/
  virtual CefRefPtr<CefDOMElement> GetPreviousSibling() =0;
 
  // Return the next sibling element.
  /*--cef()--*/
  virtual CefRefPtr<CefDOMElement> GetNextSibling() =0;
 
  // Return the tag name for this element.
  /*--cef()--*/
  virtual std::wstring GetTagName(); =0;

  // Return the number of child elements.
  /*--cef()--*/
  virtual size_t GetChildCount() =0;
 
  // Return the first child element.
  /*--cef()--*/
  virtual CefRefPtr<CefDOMElement> GetFirstChild() =0;
 
  // Return the last child element.
  /*--cef()--*/
  virtual CefRefPtr<CefDOMElement> GetLastChild() =0;
 
  // Create a new child element before the specified |refElement|.  If
  // |refElement| is empty the child element will be added at the end of the
  // list.
  /*--cef()--*/
  virtual CefRefPtr<CefDOMElement> CreateChildBefore(const std::wstring& tagName,
                                                     CefRefPtr<CefDOMElement> refElement) =0;
 
  // Remove an existing child element.
  /*--cef()--*/
  virtual CefRefPtr<CefDOMElement> RemoveChild(CefRefPtr<CefDOMElement> child) =0;
 
  // Remove all existing child elements.
  /*--cef()--*/
  virtual CefRefPtr<CefDOMElement> RemoveChildren() =0;
 
  // Return the number of existing attributes for this element.
  /*--cef()--*/
  virtual size_t GetAttributeCount() =0;

  // Test if an attribute exists for this element.
  /*--cef()--*/
  virtual bool HasAttribute(const std::wstring& name); =0;

  // Set the value of an attribute for this element.
  /*--cef()--*/
  virtual bool SetAttribute(const std::wstring& name, const std::wstring& value) =0;
 
  // Retrieve the value of an attribute for this element.
  /*--cef()--*/
  virtual std::wstring GetAttribute(const std::wstring& name); =0;
 
  // Remove an attribute from this element.
  /*--cef()--*/
  virtual bool RemoveAttribute(const std::wstring& name) =0;
 
  // Remove all attributes from this element.
  /*--cef()--*/
  virtual bool RemoveAttributes() =0;
 
  // Return the names of all existing attributes for this element.
  /*--cef()--*/
  virtual void GetAttributeNames(std::vector<std::wstring>& names) =0;
};
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Adding DOM classes to CEF

Postby emerick » Sun Feb 21, 2010 8:14 pm

Has any progress been made on this front? This is something that I'd also find useful, particularly since I'm looking to use WebKit / CEF in an HTML editing application. My application will need to navigate and modify the DOM, so the more I can do this via a C++ interface, the better.

I take it that WebCore supports this functionality on Windows, it just hasn't bubbled up to the WebKit API (and therefore hasn't bubbled up to CEF either). Is that correct?

Thanks,

Emerick
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Re: Adding DOM classes to CEF

Postby magreenblatt » Mon Feb 22, 2010 9:59 pm

Hi Emerick,

I take it that WebCore supports this functionality on Windows, it just hasn't bubbled up to the WebKit API (and therefore hasn't bubbled up to CEF either). Is that correct?

That is correct. I haven't done any work on this beyond what is documented in this thread. If you'd like to develop this functionality further I'd be happy to provide guidance.

Regards,
Marshall
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Adding DOM classes to CEF

Postby emerick » Tue Feb 23, 2010 9:23 am

Marshall,

Thanks for the feedback. Now that I've looked at Chromium a bit more, it seems that they've made some recent additions to it on the DOM front (e.g., WebDocument, WebNode, WebElement, etc.) These classes may fit the bill for me, assuming they work as intended.
emerick
Expert
 
Posts: 154
Joined: Sun Feb 21, 2010 7:57 pm
Location: Belmont, MA

Next

Return to Feature Request Forum

Who is online

Users browsing this forum: No registered users and 26 guests