Re: get current content document inside Firefox cpp code
DONG Xinshu <[email protected]>
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Message-ID | <[email protected]> |
Dear Boris,
Sorry if I confused you. Thanks for your kind help.
My intention is to monitor the change of URI of current content document
in the selected tab.
For example in Gmail, after you login, the URI is
"http://mail.google.com/mail/?shva=1#inbox", after you click "Compose
Mail", it becomes "http://mail.google.com/mail/?shva=1#compose" as
displayed in the Address Bar. So whenever this change happens, I want to
get notified.
Hope this time I made it clear to you. So do you have some idea how to
do this? Thanks.
Regards,
Xinshu
Boris Zbarsky wrote:
> On 11/9/09 8:52 PM, DONG Xinshu wrote:
>> When 'http-on-modify-request' notifies the observer, get current
>> top-level URI by
>> content.document.location.href.
>
> This URI might have nothing to do with the channel the
> http-on-modify-request is for, of course....
>
>> I tried in nsHttpChannel::Init with
>
> Like I said, you can't get a document in nsHttpChannel
>
>> rvx =
>> servMan->GetServiceByContractID("@mozilla.org/embedding/browser/nsWebBrowser;1",
>>
>
> Uh... whatever gave you the idea that nsWebBrowser is a service? It's
> not.
>
>> nsCOMPtr<nsIDOMWindow> domWin;
>> rvx = webBrowser->GetContentDOMWindow(getter_AddRefs(domWin));
>>
>> But webBrowser->GetContentDOMWindow(getter_AddRefs(domWin)) always
>> returned failure result.
>
> Sure. nsWebBrowser is what you can use to instantiate a web browser.
> If you then set it up correctly (which you didn't) and then browse
> somewhere in it (which you also didn't), then GetContentDOMWindow will
> hand back the window of the content loaded in that web browser. This
> is used, e.g in Camino (one nsWebBrowser per tab).
>
>> 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));
>
> I'm surprised this compiled....
>
>> 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
>
> In the case when you have multiple windows they don't have to match by
> any means.
>
>> So I guess GetMostRecentWindow is not entirely the same
>> thing as currently selected tab.
>
> It's a window, not a tab...
>
>> Could you please advise the correct way to do it in Firefox code?
>
> You can't do what you want to do. Not only that, but whatever you're
> trying to do doesn't make sense to me so far. So what are you
> _actually_ trying to do. Not on the "I want a document" level, but on
> the "explain it to your grandmother" level.
>
> -Boris
> _______________________________________________
> dev-tech-dom mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-dom