Re: Embedding Gecko/XULRunner

moz_embedder <[email protected]>
Newsgroups gmane.comp.mozilla.devel.embedding
Organization http://groups.google.com
Message-ID <[email protected]>
I think am able to initialise the browser by QI-ing for nsBaseWindow
and then init and then create. I think it s initialised properly
because the return code on loading a URL through nsIWebNavigation is
OK.
I am not displaying anything since I am trying to run offscreen and I
only have the codes to work with. However, I cannot get to the
nsIDOMWindow (I get null) by doing:

nsCOMPtr<nsIDOMWindow> mDomWin;
mWebBrowser->GetContentDOMWindow(getter_AddRefs(mDomWin));

Any suggestions??
Here is a snippet with all the initialisations going on:


nsCOMPtr<nsIWebBrowser> mWebBrowser =
do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
    if (NS_FAILED(rv)) {
        std::cout << "Couldn't create Web Browser" << std::endl;
        exit(1);
    }

    nsCOMPtr<nsIWebNavigation> mWebNav =
do_QueryInterface(mWebBrowser, &rv);
    if (NS_FAILED(rv)) {
        std::cout << "Couldn't create Web Nav" << std::endl;
        exit(1);
    }

    nsCOMPtr<nsIBaseWindow> baseWindow =
do_QueryInterface(mWebBrowser, &rv);
    if (NS_FAILED(rv)) {
        std::cout << "Couldn't QI base win" << std::endl;
        exit(1);
    }

    WebBrowserChrome *cw = new WebBrowserChrome();
    mWebBrowser->SetContainerWindow(static_cast<nsIWebBrowserChrome*>
(cw));

    WebBrowserChromeUI *nw = new WebBrowserChromeUI(); //empty - I
dont want to display stuff
    rv = baseWindow->InitWindow(nw, nsnull, 0, 0, 0, 0);
    if (NS_FAILED(rv)) {
        std::cout << "Couldn't init base win" << std::endl;
        exit(1);
    }

    rv = baseWindow->Create();
    if (NS_FAILED(rv)) {
        std::cout << "Couldn't create base win" << std::endl;
        exit(1);
    }

    rv = mWebNav->LoadURI(
            NS_ConvertASCIItoUTF16("http://www.google.com/").get(),
            nsIWebNavigation::LOAD_FLAGS_NONE,
            nsnull,
            nsnull,
            nsnull);
    if (NS_FAILED(rv)) {
        std::cout << "Couldn't load URL: " << std::endl;
        exit(1);
    } else {
        std::cout << "Maybe loaded url" << std::endl; //reaches
here :) :) :)
    }



    nsCOMPtr<nsIDOMDocument> mDomDoc;
    nsCOMPtr<nsIDOMWindow> mDomWin;
    rv = mWebBrowser->GetContentDOMWindow(getter_AddRefs(mDomWin));
    if(mDomWin) { // mDomWin is NULL here :( :( :(
        mDomWin->GetDocument(getter_AddRefs(mDomDoc));
        if(!mDomDoc)
            std::cout << "Cannot get DOM doc" << std::endl;
    } else {
        std::cout << "Cannot get dom win " << std::endl;
    }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.