guys, I am trying to implement a save webpage functionallity for my
mozilla embedding project with no much success so far. That's my
snipped code (I am using running gtk_moz_embed widget)

(...)
   g_return_val_if_fail (engine != NULL, FALSE);
   nsIWebBrowser *webBrowser = nsnull;
   gtk_moz_embed_get_nsIWebBrowser (GTK_MOZ_EMBED (engine), &webBrowser);
   g_return_val_if_fail  (webBrowser != NULL, FALSE);

   nsCOMPtr<nsIDOMWindow> DOMWindow;
   webBrowser->GetContentDOMWindow(getter_AddRefs(DOMWindow));
   g_return_val_if_fail (DOMWindow != NULL, FALSE);

   nsCOMPtr<nsIDOMDocument> doc;
   DOMWindow->GetDocument (getter_AddRefs(doc));
   g_return_val_if_fail (doc != NULL, FALSE);

   nsCOMPtr<nsIWebBrowserPersist> persist (do_QueryInterface(webBrowser));
   if (!persist) {
       printf ("[MOZ_EAL] No persist object, hanging ...\n");
       return FALSE;

   } else {

       nsCString fileName (file_name_with_path);

       // Sanitize the title of all illegal characters
       fileName.CompressWhitespace();     // Remove whitespace from the ends
       fileName.StripChars("\\*|:\"><?"); // Strip illegal characters
       fileName.ReplaceChar('.', L'_');   // Dots become underscores
       fileName.ReplaceChar('/', L'-');   // Forward slashes become hyphens

       // Copy filename to a character buffer
       char szFile[50];
       memset(szFile, 0, sizeof(szFile));
       PL_strncpyz(szFile, fileName.get(), sizeof(szFile) - 1); //
XXXldb probably should be just sizeof(szfile)

       nsCOMPtr<nsILocalFile> file;
       nsCOMPtr<nsILocalFile> relative = nsnull;

//         nsAutoString s; s.AssignWithConversion(file_name_with_path);
//         NS_NewLocalFile(s,PR_TRUE,getter_AddRefs(file));

       file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);
       file->InitWithNativePath(nsDependentCString (szFile));
       file->Create(nsIFile::NORMAL_FILE_TYPE, 0644);

       nsresult rv;

      // IT FAILS HERE. ....
       if (file) rv= persist->SaveDocument(doc, file, relative, nsnull, 0, 0);
       else printf ("[MOZ_EAL] fuck ! leaving at the right exit :)\n");

       if (rv = NS_OK)
           printf ("[MOZ_EAL] leaving at the right exit :)\n");
       else printf ("[MOZ_EAL] not leaving at the right exit :)\n");

       return (TRUE);
   }

It's a simple code, I know, but it hangs ... what am I missing ?

regards

--
--Antonio Gomes
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to