Here is what we use in our embedded Gecko app, and it seems to work fine:

//---------------------------------------------------------
//Temp vars
nsIWebNavigation *piwnWebNavigation = nsnull;
nsIURI *piuURI = nsnull;
nsCString csString;

//QIing for the web navigation object
piwbWebBrowser->QueryInterface (NS_GET_IID (nsIWebNavigation), (void**)
&piwnWebNavigation);

//Getting the URI object
piwnWebNavigation->GetCurrentURI (&piuURI);

//Getting URL from URI object
piuURI->GetSpec (csString);

//Releasing
piuURI->Release ();
piwnWebNavigation->Release ();

**NOTE**
"piwbWebBrowser" is an nsIWebBrowser object created earlier in the app with:

rv = nsComponentManager::CreateInstance
("@mozilla.org/embedding/browser/nsWebBrowser;1", nsnull, NS_GET_IID
(nsIWebBrowser), (void**) &piwbWebBrowser);
//---------------------------------------------------------


Also, I noticed that if I tried to get the nsIURI object BEFORE the web page
had completely loaded, I got NULL for that object.  So I had to wait till I
was notified that the web page was completely loaded before I tried to do
this.  This could maybe be your problem?

Hope this helps.

Niky Williams


"Anatoly Kaverin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> hi to everyone.
> i'm newbie to XPCOM and faced with problem of getting current url from
page
> and control over navigation. We decided to use nsIWebNavigation interface
> for these purposes.
>
> below is our code:
>
> nsIWebNavigation * nsWN = NULL;
>
> if (gServiceManager)
> {
> nsresult res;
> res =
gServiceManager->GetServiceByContractID("@mozilla.org/embedding/browser/nsWe
bBrowser;1",
> NS_GET_IID(nsIWebNavigation), (void **)&nsWN);
>   if(NS_OK == res)
>             {
> MessageBox(NULL, "Interface Pointer Received Succesfully",
"WebNavigation",
> MB_OK);
> nsIURI *url = NULL;
> res = nsWN->GetCurrentURI(&url);                   //res =
NS_ERROR_UNEXPECTED
> if(NS_OK == res)
> MessageBox(NULL, "URI received", "URI msg", MB_OK);
> res = nsWN->GetReferringURI(&url);                 //res =
NS_ERROR_UNEXPECTED
> if(NS_OK == res)
> MessageBox(NULL, "URI REF received", "URI msg", MB_OK);
> nsEmbedCString path;
> if(url)
> url->GetPath(path);
> MessageBox(NULL, path.get(), "path of page", MB_OK);
> }
> else if (NS_NOINTERFACE == res)
>         MessageBox(NULL, "NOINTERFACE", "WebNavigation", MB_OK);
>   }
>   NS_IF_RELEASE(nsWN);
>
> -------------------------
>
> With Best Regards,
> Anatoly Kaverin,
> VerificationEngine developer
> http://www.vengine.com
> C O M O D O group
> [EMAIL PROTECTED]
> MSN: [EMAIL PROTECTED]
>
>


_______________________________________________
Mozilla-xpcom mailing list
Mozilla-xpcom@mozilla.org
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to