swapnil wrote:
I am not making a window as my app is a server. The args to loadURI I
listed are bad, I tried these because the intial code did not work.
here's the code -
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <nsISupports.h>
#include <nsEmbedAPI.h>
#include <nsIWebBrowser.h>
#include <nsIWebNavigation.h>
#include <nsISHistory.h>
#include <nsCOMPtr.h>
#include <nsIInterfaceRequestor.h>
#include <nsString.h>
#include "nsNativeCharsetUtils.h"
#include <nsCWebBrowser.h>
#include <nsIComponentManager.h>
#define NS_WEBBROWSER_CID \
{ 0xf1eac761, 0x87e9, 0x11d3, { 0xaf, 0x80, 0x00, 0xa0, 0x24, 0xff,
0xc0, 0x8c } }
#define NS_WEBBROWSER_CONTRACTID \
"@mozilla.org/embedding/browser/nsWebBrowser;1"
class myHTMLParser : public nsISupports
{
public:
myHTMLParser();
virtual ~myHTMLParser();
nsresult Init();
NS_DECL_ISUPPORTS
nsresult LoadURI(const char *uri);
private:
nsCOMPtr<nsIWebBrowser> mWebBrowser;
nsCOMPtr<nsIWebNavigation> mNavigation;
nsCOMPtr<nsISHistory> mSessionHistory;
};
myHTMLParser::myHTMLParser() : mWebBrowser(nsnull),
mNavigation (nsnull),
mSessionHistory(nsnull)
{
}
myHTMLParser::~myHTMLParser()
{
NS_TermEmbedding();
}
NS_IMPL_ISUPPORTS0(myHTMLParser)
nsresult myHTMLParser::Init()
{
nsresult rv = NS_InitEmbedding(nsnull, nsnull);
if (NS_FAILED(rv))
return rv;
else
printf(" NS_InitEmbedding Succeeded\n");
// create nsIWebBrowser
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
if (NS_FAILED(rv))
return rv;
else
printf(" do_CreateInstance Succeeded\n");
// Create nsIWebNavigation
mNavigation = do_QueryInterface(mWebBrowser, &rv);
if (NS_FAILED(rv))
return rv;
else
printf("do_QueryInterface to get mNavigation Succeeded\n");
mSessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID,
&rv);
if (NS_FAILED(rv))
return rv;
else
printf("do_CreateInstance of mSessionHistory Succeeded\n");
mNavigation->SetSessionHistory(mSessionHistory);
return NS_OK;
}
nsresult myHTMLParser::LoadURI(const char *uri)
{
nsString mURI;
uri = "http://www.google.com";
NS_CopyNativeToUnicode(nsDependentCString(uri), mURI);
nsresult rv = mNavigation->LoadURI(mURI.get(),
nsIWebNavigation::LOAD_FLAGS_NONE,
nsnull,
nsnull,
nsnull);
printf("LoadURI rv = %08X\n", rv);
return NS_OK;
}
int main(int argc, char* const* argv)
{
nsresult rv = NS_OK;
myHTMLParser *parser = new myHTMLParser();
rv = parser->Init();
printf("Init rv = %08X\n", rv);
if (NS_FAILED(rv)) return -1;
rv = parser->LoadURI("http://www.google.com");
if(rv == NS_OK)
{
printf("LoadURI succeeded\n");
}
else
{
printf("LoadURI failed rv = %08X\n", rv);
return rv;
}
return NS_OK;
}
I've replicated the code you have here, but just condensed it to the
main () function just so I could try and load an URI. I get an error too
(NS_ERROR_UNEXPECTED 0x8000ffff) on nsIWebNavigation::LoadURI (). So, I
still believe you have to implement the bare minimum for embedding Gecko
as stated in their embedding guide...even if you don't want a UI, I
think it still needs the other implementations. Also, you don't have to
implement a pretty interface, just get the guts going. Can any Gecko
Gurus confirm or deny this supposition? I've posted the code I used
below (Sorry, not commented, just thrown together ;-)):
int main (int argc, char *argv[])
{
nsresult rv = NS_OK;
nsString sBinDir;
nsString sURI;
nsCOMPtr<nsILocalFile> pCOM_lf;
nsCOMPtr<nsIWebBrowser> pCOM_wb;
nsCOMPtr<nsIWebNavigation> pCOM_wn;
sBinDir.Assign (NS_ConvertUTF8toUTF16
("C:\\Dev\\Source\\mozilla\\ff-release-shared\\dist\\bin"));
NS_NewLocalFile (sBinDir, PR_TRUE, getter_AddRefs (pCOM_lf));
rv = NS_InitEmbedding (pCOM_lf, nsnull);
pCOM_wb = do_CreateInstance (NS_WEBBROWSER_CONTRACTID, &rv);
pCOM_wn = do_QueryInterface (pCOM_wb, &rv);
sURI.Assign (NS_ConvertUTF8toUTF16 ("http://www.google.com"));
rv = pCOM_wn->LoadURI (sURI.get (), nsIWebNavigation::LOAD_FLAGS_NONE,
nsnull, nsnull, nsnull);
NS_TermEmbedding ();
return (0);
}
Niky Williams
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding