I've been trying to figure out a way to stream an html document to the
embedded Mozilla browser. So, first off if anyone knows a better way of
doing this please tell me. Anyway, I already have code to do his for an
embedded IE Browser. I do this by searializing the text in an editor and
then getting an IPersistStreamInit interface pointer of the embedded browser
's  HTML document interface. I then call IPersistStreamInit::Load() method
and pass a IStream interface pointer. So, I had to add the
IPersistStreamInit interface to the CIEHtmlDocument class in order to get
and IPersistStreamInit interface from the embedded Mozilla browser's
document. This part works great! I get the IPersistStreamInit interface, and
I even enter the proper methods when I call them. The following is the steps
I did to do this:



  1.. Added public IPersistSteamInit to CIEHtmlDocument class declaration.
  2.. Added the IPersistStreamInit method declarations to CIEHtmlDocument:
    1.. virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID);
    2.. virtual HRESULT STDMETHODCALLTYPE IsDirty();
    3.. virtual HRESULT STDMETHODCALLTYPE Load(LPSTREAM pStm);
    4.. virtual HRESULT STDMETHODCALLTYPE Save(LPSTREAM pStm, BOOL
fClearDirty);
    5.. virtual HRESULT STDMETHODCALLTYPE GetSizeMax(ULARGE_INTEGER FAR*);
    6.. virtual HRESULT STDMETHODCALLTYPE InitNew();
  3.. Finally define the above methods in the cpp file. Currently I have
most of them returning E_NOTIMPL.


The following is the implementation for the Load method:



HRESULT STDMETHODCALLTYPE CIEHtmlDocument::Load(LPSTREAM pStm)
{
   nsresult rv;
   PRUint32 bytesWritten;



   nsCOMPtr<nsIStorageStream> storageStream;
   nsCOMPtr<nsIOutputStream> outputStream;



   // Init: (block size, maximum length)
   rv = NS_NewStorageStream(256, (PRUint32)-1,
getter_AddRefs(storageStream));
   if (NS_FAILED(rv)) return rv;



   rv = storageStream->GetOutputStream(0, getter_AddRefs(outputStream));
   if (NS_FAILED(rv)) return rv;



   char* pStreamBuf = (char*)calloc(1, sizeof(char));



   char buf[255 + 1];
   memset((LPVOID)buf, 0, (255 + 1)*sizeof(char));



   ULONG cbRead = 255;

   PRInt32 iLength = 0;



   while(SUCCEEDED(pStm->Read((LPVOID)buf, READBLOCK, &cbRead)) && cbRead >=
READBLOCK)
   {
      pStreamBuf = strcat(pStreamBuf, buf);
      iLength += cbRead;
   }


   pStreamBuf = strcat(pStreamBuf, buf);
   iLength += cbRead;



   nsCString buffer(pStreamBuf, iLength);

   outputStream->Write(buffer.get(), buffer.Length(), &bytesWritten);


   nsCOMPtr<nsIInputStream> inStr;

   rv = storageStream->NewInputStream(0, getter_AddRefs(inStr));
   free(pStreamBuf);
   if (NS_FAILED(rv)) return rv;


   nsIWebBrowser *browser = NULL;
   mControl->GetWebBrowser((LPVOID*)&browser);



   nsCOMPtr<nsIDocShell> docShell = do_GetInterface(browser);



   nsCString aContentType, aContentCharSet;
   rv = docShell->LoadStream(inStr, NULL, aContentType, aContentCharSet,
NULL);
   if (NS_FAILED(rv)) return rv;



   return S_OK;
}



My problem area is the nsCString. I can't seem to set it to my char* I have
tried several approaches with the same assertion. It asserts at
PR_ASSERT(self->lock) in the PL_InitEvent function call. If anyone can help
me work around this I would be greatly appreciative.



Robert



Reply via email to