I've been writing a Mac NPAPI-based browser plugin to convert a file of custom mimetype (say, "application/x-foo") into an HTML representation, which can then be viewed directly in a browser. These files are usually directly served, so I'm more concerned about supporting full-page viewing, rather than embedded views via <object>
tags.
On Firefox, this has been relatively simple: I make a call to NPN_NewStream
with the text/html
mimetype, write the converted HTML into the stream, and then clean it up with NPN_DestroySteam
. The browser automatically handles the request for a new HTML stream and renders the given HTML into a tab or window. Pretty standard.
For Safari, though, NPN_NewStream
does not appear to be implemented (and I did check the WebKit source code). Previously, I was able to use the WebKitPlugin API. With Safari 5.1, this API is gone.
I thought I would be able to create a WebView in a drawing event handler, like this:
NSRect rect = NSMakeRect(0, 0, obj->window.width, obj->window.height);
//...
WebView* webView = [[WebView alloc] initWithFrame:rect frameName:nil groupName:nil];
[[webView mainFrame] loadHTMLString:@"<html><head><title>This is a message from my plug-in!</title></head><body><p><strong>This is a message from my plug-in!</strong></p></body>/html>" baseURL:[NSURL URLWithString:@"http://example.com"]];
[webView drawRect:rect];
and see it in browser. But all that does is render a gray screen with no content, as if not drawn. If I replace the WebView
with an NSTextView
and set its string to the HTML, everything draws just fine, but of course the HTML is not rendered by an NSTextView
.
My question boils down to: is there a good way to render some HTML into a Safari window from an NPAPI plugin? Or if that won't work, into a Google Chrome window? Or some other approach that lets me handle a custom MIME type and display some HTML representation of it?