3

I found a few questions similar to mine but none of the answers are satisfactory and they are a few years old. So I am hoping that perhaps some progress has been made on that front since then.

What I am interested in is the ability to access the content of an active Firefox window and copy it to the clipboard -- using C or C++ code.

In Internet Explorer I can use COM's IHTMLDocument2 to access the broswer's contents DOM.

Is there something similar in Firefox? If so, how do I do that?

BTW, my current (ugly) workaround is to mimic Ctrl+A, Ctrl+C by sending virtual keystrokes, but this is not a truly robust and elegant solution.

Ideas, tips, insight, knowledge would be greatly appreciated.

Thanks.

Note: To further clarify the challenge, I would like to note that I am not interested in a Javascript based or Flash based solution. Instead, I am interested in a C/C++ solution, even if it is limited to the Microsoft Windows platform only.

Community
  • 1
  • 1
Android Eve
  • 14,864
  • 26
  • 71
  • 96
  • 1
    Do you really need to "steal" the content from Firefox? The content in **my** firefox is very different than what the authors intended for some pages. Maybe you really want the data available at a certain URL ... – pmg Oct 07 '10 at 13:38
  • LOL, "steal" is not the correct term for what I am trying to do. Yes, I need to display to the user the same page she is currently viewing, but in a different way. Some pages have no unique URL, you know... so, my only recourse is to grab the browser's content via copy & paste and then re-interpret it. I originally let the user copy & paste manually (Ctrl+A, Ctrl+C) but they complained that this is not really user friendly. +1 for thinking out of the box. :) – Android Eve Oct 08 '10 at 13:49

1 Answers1

3

The DOM in firefox is exposed to C++ via XPCOM but beware, unlike MSHTML (in IE) the interfaces in Mozilla are not always frozen the unfrozen interfaces are version specific and may change from release to release.

The XPCOM equivalent of IHTMLDocument2 is nsIDOMDocument.

XPCOM is very similar to COM, the base class is called nsISupports and has exactly the same semantics as IUnknown (including the same binary layout and GUID) but don't assume that everything maps from COM to XPCOM (for example there is no IDispatch in XPCOM).

Motti
  • 110,860
  • 49
  • 189
  • 262
  • This is a remarkable answer, thanks so much! I already gave you a +1 for that and I intend to set it as the accepted answer. I just need one more piece of information: Since XPCOM is open source, does it mean that if I use it (as is, without any modification), I have to make available the source code of my application, as well? – Android Eve Oct 08 '10 at 13:53
  • 1
    @Android the Mozilla Public License isn't that strict, if you make changes to Firefox's code you have to return it to the community but any code that is your own you can keep private. Here's [the FAQ](http://www.mozilla.org/MPL/mpl-faq.html) which covers this. – Motti Oct 09 '10 at 18:55