views:

158

answers:

1

I'm seeking C++ help in writing HTML code to a new tab in Firefox within an extension.

Our C++ code has been partially wrapped by an XPCOM wrapper and embedded within a Firefox extension thanks to the work of a consultant we have lost contact with, and still partially implemented by calling out to a standalone executable.

To get our output displayed from the standalone executable, the C++ code writes the output to a file and simply calls system(firefox file.html) which then comes up with a file:-based URI.

This no longer works in all situations, based on a report from a user running Vista. So it seems to be time to do it right, and navigate the DOM, likely integrating the rest of the C++ code into the XPCOM-wrapped part. Perhaps there's a right way to do it from the standalone executable using the DOM model?

The "current working directory" seems to no longer match the directory in which the extension installed the standalone executable, with a "VirtualStore" path element.

We also generate parallel output in a different MIME type, VRML to be specific.

Any suggestions or examples for how to properly generate output into a Firefox browser pane under C++ programmatic control would be very much appreciated.

A: 
  1. You could call Firefox with a fully specified file:/// URL, not a relative URL (file.html).
  2. Or you if you want to dump a separate executable, you could implement a protocol handler or a simpler about module (where ios.newChannel would be replaced by your own channel implementation that generates the data).

I'd say keeping the file-generation solution is OK and doesn't seem very bad, so I'd go with (1), perhaps changing the generated file location to a temporary folder and specifying it fully both for the executable that generates it and for Firefox.

Nickolay
Your first suggestion makes sense, but I would think that the current working directory context would make that moot.Given the space and backslash characters in a microsoft directory specification, any suggestions for the correct way to map (like url-encode) a microsoft full file specification to a file-based URI?
Using a modified URL-encoding for the Microsoft getcwd() output can be made to work but it actually suffers the exact same problem as initially reported.The output of getcwd() under Vista 64-bit gives some sort of virtualized path that is not based on the user profile, and the URI doesn't open.So back to the original problem, or any pointers to sample implementations of scribbling HTML from C++ through a channel, I'm all ears.
Sample implementations in C++ are scarce and I wouldn't recommend writing it in C++ anyway. You can definitely find examples in the Mozilla source code, but it's not going to be an easy copy/paste exercise.
Nickolay
Re: my suggestion. I mean in the extension get a temporary path (google "TmpD mozilla"), convert it to a windows path, pass it to the executable, then convert it to a file:// URI (there's a standard API for that with examples on MDC) to pass it to Firefox.
Nickolay