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; 

}

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

Reply via email to