Hello Niky, thnx for your help.

We have access to service manager inside the mozilla plug-in and maybe
we have an error with quering interface nsIComponentManager instead
of using nsComponentManager.
We are using nsIComponentManager from mozilla SDK.
But we still can't get URI, below is our code:

nsresult res;
nsIComponentManager * picmCM = nsnull;
gServiceManager->QueryInterface(NS_GET_IID(nsIComponentManager), (void **)&picmCM);
 if(picmCM)
{
 nsIWebBrowser *piwbWebBrowser = nsnull;
 res = 
picmCM->CreateInstanceByContractID("@mozilla.org/embedding/browser/nsWebBrowser;1",
  nsnull, NS_GET_IID(nsIWebBrowser), (void**) &piwbWebBrowser);

 if(NS_OK == res)
 {
  nsIWebNavigation *piwnWebNavigation = nsnull;
  nsIURI *piuURI = nsnull;
  nsCString csString;

  res = piwbWebBrowser->QueryInterface(NS_GET_IID (nsIWebNavigation),
   (void**)&piwnWebNavigation);
  if(NS_OK == res)
  {
   res = piwnWebNavigation->GetCurrentURI(&piuURI); //res == NS_ERROR_UNEXPECTED
   if(NS_OK == res)
   {
    res = piuURI->GetSpec(csString);

    piuURI->Release();
   }
else if(NS_ERROR_UNEXPECTED == res) MessageBox(NULL, "Error with URI", "Error", MB_OK);
   piwnWebNavigation->Release();
  }
 }
 picmCM->Release();
}

We just can't get - what wrong with this nsIURI....

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/browse
r/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]
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