Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Problems with the Mozilla binding

Christophe,

Can you hint me as to why you guys use what you use to feed the Browser/Gecko widget with text?

I'm referring to the approach, where in Browser.setText(..) you ask the browser to load the blank page ("about:blank") and then, in the listener, you feed the browser with the real content, going through nsIStreamChannel/nsILoadGroup & further complications.

I wouldn't have asked, but on Linux, this method doesn't work for me when I try to load content which has a stylesheet links (like the JavaDocs in Eclipse3). Only the first time when I load such content it is displayed. The second time I got a blank white page. Strangley enough, on Windows I don't have this issue.

Any particular reason as to why you don't use nsIDocShell::LoadStream(), like JRex does?

<snip>
FXbool FXGeckoEngine::setContent(const FXuchar* content, FXuint length, const FXchar* _contentType, const FXchar* _encoding) {
nsresult nr;

nsCOMPtr<nsIDocShellTreeItem> browserAsItem;
nr = webBrowser->QueryInterface(nsIDocShellTreeItem::GetIID(), getter_AddRefs(browserAsItem));
FXASSERT(NS_SUCCEEDED(nr));
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
nr = browserAsItem->GetTreeOwner(getter_AddRefs(treeOwner));
FXASSERT(NS_SUCCEEDED(nr));
nsCOMPtr<nsIDocShellTreeItem> contentItem;
nr = treeOwner->GetPrimaryContentShell(getter_AddRefs(contentItem));
FXASSERT(NS_SUCCEEDED(nr));
nsCOMPtr<nsIDocShell> docShell;
nr = contentItem->QueryInterface(nsIDocShell::GetIID(), getter_AddRefs(docShell));
FXASSERT(NS_SUCCEEDED(nr));
nsCOMPtr<nsIServiceManager> serviceManager;
nr = NS_GetServiceManager_p(getter_AddRefs(serviceManager));
FXASSERT(NS_SUCCEEDED(nr));
 
nsCOMPtr<nsIIOService> ioService;
nr = serviceManager->GetService(NS_IOSERVICE_CID, nsIIOService::GetIID(), getter_AddRefs(ioService));
FXASSERT(NS_SUCCEEDED(nr));

/*
* Note. Mozilla ignores LINK tags used to load CSS stylesheets
* when the URI protocol for the nsInputStreamChannel
* is about:blank. The fix is to specify the file protocol.
*/
nsCOMPtr<nsIURI> uri;
nsEmbedCString protocol("file:");
nr = ioService->NewURI(protocol, nsnull, 0, getter_AddRefs(uri));
FXASSERT(NS_SUCCEEDED(nr));
nsCOMPtr<nsIInputStream> inputStream = new MemoryInputStream(content, length);
nsEmbedCString contentType(_contentType);
nsEmbedCString encoding(_encoding);
nr = docShell->LoadStream(inputStream, uri, contentType, encoding, nsnull);
FXASSERT(NS_SUCCEEDED(nr));
return nr == NS_OK;
}

</snip>


Regards,
Ivan

Back to the top