Hi Niky,
I have written a small sample code to navigate to URL. I have put it
inline with this mail.
When I call LoadURI on a nsIWebNavigation object, I get an
NS_ERROR_UNEXPECTED error. Can you tell me what am I missing?
Thanks,
Raghu
/*********************** Header File Begin ****************************/
#ifndef __REmbedBrowser_h
#define __REmbedBrowser_h
#include <nsString.h>
#include <nsISupports.h>
#include <nsIWebBrowser.h>
#include <nsCOMPtr.h>
#include <nsIWebNavigation.h>
#include <nsISHistory.h>
#include <nsIInterfaceRequestor.h>
class REmbedBrowser : public nsISupports
{
public:
REmbedBrowser();
virtual ~REmbedBrowser();
nsresult Init (void);
nsresult Deinit (void);
NS_DECL_ISUPPORTS
nsresult LoadURI(const char *uri);
private:
nsCOMPtr<nsIWebBrowser> mWebBrowser; // [OWNER]
nsCOMPtr<nsIWebNavigation> mNavigation;
nsCOMPtr<nsISHistory> mSessionHistory;
};
#endif /* __REmbedBrowser_h */
/*********************** Header File End ******************************/
/*********************** Source File Begin ****************************/
//for NS_WEBBROWSER_CONTRACTID
#include <nsCWebBrowser.h>
//for nsIWebBrowser
#include <nsIWebBrowser.h>
//for do_CreateInstance
#include <nsIComponentManager.h>
// for do_GetInterface
#include <nsIInterfaceRequestor.h>
#include <nsString.h>
#include "nsNativeCharsetUtils.h"
#include <nsEmbedAPI.h>
#include "REmbedBrowser.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
REmbedBrowser::REmbedBrowser(void)
{
mWebBrowser = nsnull;
mNavigation = nsnull;
mSessionHistory = nsnull;
}
REmbedBrowser::~REmbedBrowser()
{
}
NS_IMPL_ISUPPORTS0(REmbedBrowser)
nsresult REmbedBrowser::Init(void)
{
nsresult rv = NS_InitEmbedding(nsnull, nsnull);
if (NS_FAILED(rv))
return rv;
// create our nsIWebBrowser object
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
if (NS_FAILED(rv))
return rv;
if (!mWebBrowser)
return NS_ERROR_FAILURE;
// get a handle on the navigation object
mNavigation = do_QueryInterface(mWebBrowser, &rv);
if (NS_FAILED(rv))
return rv;
// Create our session history object and tell the
// navigation object to use it.We need to do this
// before we create the web browser window.
mSessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID,
&rv);
if (NS_FAILED(rv))
return rv;
mNavigation->SetSessionHistory(mSessionHistory);
return NS_OK;
}
nsresult REmbedBrowser::Deinit(void)
{
NS_TermEmbedding();
return NS_OK;
}
nsresult REmbedBrowser::LoadURI(const char *uri)
{
nsString mURI;
uri = "www.yahoo.com";
NS_CopyNativeToUnicode(nsDependentCString(uri), mURI);
//mNavigation->LoadURI(NS_ConvertASCIItoUCS2(uri).get(),
nsresult rv = mNavigation->LoadURI(mURI.get(),
nsIWebNavigation::LOAD_FLAGS_NONE,
nsnull,
nsnull,
nsnull);
printf("LoadURI rv = %08X\n", rv);
uri = "www.google.com";
NS_CopyNativeToUnicode(nsDependentCString(uri), mURI);
//mNavigation->LoadURI(NS_ConvertASCIItoUCS2(uri).get(),
mNavigation->LoadURI(mURI.get(),
nsIWebNavigation::LOAD_FLAGS_NONE,
nsnull,
nsnull,
nsnull);
printf("LoadURI rv = %08X\n", rv);
return NS_OK;
}
/*********************** Source File End ******************************/
/*********************** Helper File Begin ****************************/
#include <stdio.h>
#include "REmbedBrowser.h"
int r_embed_run(void)
{
nsresult rv = NS_OK;
REmbedBrowser *browser = new REmbedBrowser();
rv = browser->Init();
printf("Init rv = %08X\n", rv);
rv = browser->LoadURI("www.yahoo.com");
if(rv == NS_OK)
{
printf("URL loaded successfully\n");
}
else
{
printf("URL load failed\n");
return rv;
}
browser->Deinit();
return NS_OK;
}
/*********************** Helper File End ******************************/
/*********************** Test File Begin ******************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "rmozembed.h"
int main(void)
{
int res;
res = r_embed_run();
printf("res = %08X\n", res);
}
/*********************** Test File End ********************************/
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding