Re: get current content document inside Firefox cpp code

DONG Xinshu <[email protected]>
Newsgroups gmane.comp.mozilla.devel.dom
Message-ID <[email protected]>
Thanks, Boris. Sorry I forgot to append the code.

Basically I just want to do something in Firefox code similar as the 
following in extensions:

When 'http-on-modify-request' notifies the observer, get current 
top-level URI by
content.document.location.href. (At that time, new HTTP request is about 
to be sent)

I tried in nsHttpChannel::Init with

  rvx = 
servMan->GetServiceByContractID("@mozilla.org/embedding/browser/nsWebBrowser;1",
                                        NS_GET_IID(nsIWebBrowser),
                                        getter_AddRefs(webBrowser));
  nsCAutoString curHref;
  if (!NS_FAILED(rvx)) {
      nsCOMPtr<nsIDOMWindow> domWin;
      rvx = webBrowser->GetContentDOMWindow(getter_AddRefs(domWin));

But webBrowser->GetContentDOMWindow(getter_AddRefs(domWin)) always 
returned failure result.

Also in nsHttpChannel::Init, I tried

  nsCOMPtr<nsIWindowMediator> winMd;
  rvx = 
servMan->GetServiceByContractID("@mozilla.org/appshell/window-mediator;1",
                                        NS_GET_IID(nsIWindowMediator),
                                        getter_AddRefs(winMd));
  nsCOMPtr<nsIDOMWindowInternal> domWinInt;
  rvx = winMd->GetMostRecentWindow(0, getter_AddRefs(domWinInt));
  nsCOMPtr<nsIDOMWindow> domWin;
  rvx = domWinInt->GetContent(getter_AddRefs(domWin));
  nsCOMPtr<nsIDOMDocument> domDoc;
  rvx = domWin->GetDocument(getter_AddRefs(domDoc));
  nsCOMPtr<nsIDocument> curDoc = do_QueryInterface(domDoc);
  nsCAutoString curHref;
  curDoc->GetDocumentURI()->GetSpec(curHref);

For static web pages, 'curHref' could give the correct URI, but for AJAX 
applications, 'curHref' was not correct (different from what I got from 
content.document.location.href from 'http-on-modify-request' observer in 
extension). So I guess GetMostRecentWindow is not entirely the same 
thing as currently selected tab.

Could you please advise the correct way to do it in Firefox code? And 
the correct interception function other than nsHttpChannel::Init? Thanks.

Regards,
Xinshu

Boris Zbarsky wrote:
>  On 11/9/09 9:10 AM, DONG Xinshu wrote:
> > However, if I want to get this info inside Firefox code base
> > (nsHttpChannel::Init), what shall I do?
>
>  You can't get the document from that code: necko can't depend on
>  content.
>
> > I tried with the following piece of code,
>
>  Which you didn't include....
>
> > My purpose is just to get the original URI of a page before it's
> > changed
>
>  Meaning what?
>
>  -Boris
>
>  _______________________________________________ dev-tech-dom mailing
>  list [email protected]
>  https://lists.mozilla.org/listinfo/dev-tech-dom
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.