doQueryInterface of a new tab (nsIAccessible) returns NS_ERROR_INVALID_POINTER

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

doQueryInterface of a new tab (nsIAccessible) returns NS_ERROR_INVALID_POINTER

ian.alistair.mason
Hi,

I'm using accessibility to get the HWNDs of various DOM nodes within
the ff browser, and recently (ff3) I'm getting invalid pointer errors
back from QI-ing the accessible node returned by GetAccessibleFor.


Here for example is the scenario, the node is the new tab
(obtained from a javascript TabOpen event, or the subsequent TabSelect
event)
the following snippet will fail with NS_ERROR_INVALID_POINTER

nsresult snippet(nsIDOMNode *node){
  nsresult rv;
  nsCOMPtr<nsIAccessibleRetrieval> refp;
  refp = do_CreateInstance(accRetCID, &rv);
  if (NS_FAILED(rv)){ return NS_ERROR_FAILURE; }
  nsCOMPtr<nsIAccessible> accnode;
  rv = refp->GetAccessibleFor(node, getter_AddRefs(accnode));
  if(NS_FAILED(rv)){  return NS_ERROR_FAILURE; }
  nsCOMPtr<nsIAccessibleDocument> accdocnode;
  accdocnode = do_QueryInterface(accnode, &rv);  //<---  fails; rv =
0x80004003
  if(NS_FAILED(rv)){ return NS_ERROR_FAILURE; }
}

If I select another tab, then reselect the new tab, things no longer
fail.

The question is what am I doing wrong, or what has changed?

For more details on the snippet I wrote a little dity describing it,
and
related issues here:

http://developer.mozilla.org/en/docs/Working_with_Multiple_Versions_of_Interfaces




_______________________________________________
dev-accessibility mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-accessibility
Reply | Threaded
Open this post in threaded view
|

Re: doQueryInterface of a new tab (nsIAccessible) returns NS_ERROR_INVALID_POINTER

Aaron Leventhal-3
The tab element is not a document node, so QI wouldn't work there.

If we knew more about your project and how you are building and
distributing it we could recommend the best interface for this.

In the mean time you can QI to nsIAccessNode and use
139   /**
140    * The OS window handle for the window this node
141    * is being displayed in.
142    */
143   [noscript] readonly attribute voidPtr ownerWindow;

http://mxr.mozilla.org/seamonkey/source/accessible/public/nsIAccessNode.idl

Just cast the result to an HWND.

- Aaron

Ian wrote:

> Hi,
>
> I'm using accessibility to get the HWNDs of various DOM nodes within
> the ff browser, and recently (ff3) I'm getting invalid pointer errors
> back from QI-ing the accessible node returned by GetAccessibleFor.
>
>
> Here for example is the scenario, the node is the new tab
> (obtained from a javascript TabOpen event, or the subsequent TabSelect
> event)
> the following snippet will fail with NS_ERROR_INVALID_POINTER
>
> nsresult snippet(nsIDOMNode *node){
>    nsresult rv;
>    nsCOMPtr<nsIAccessibleRetrieval>  refp;
>    refp = do_CreateInstance(accRetCID,&rv);
>    if (NS_FAILED(rv)){ return NS_ERROR_FAILURE; }
>    nsCOMPtr<nsIAccessible>  accnode;
>    rv = refp->GetAccessibleFor(node, getter_AddRefs(accnode));
>    if(NS_FAILED(rv)){  return NS_ERROR_FAILURE; }
>    nsCOMPtr<nsIAccessibleDocument>  accdocnode;
>    accdocnode = do_QueryInterface(accnode,&rv);  //<---  fails; rv =
> 0x80004003
>    if(NS_FAILED(rv)){ return NS_ERROR_FAILURE; }
> }
>
> If I select another tab, then reselect the new tab, things no longer
> fail.
>
> The question is what am I doing wrong, or what has changed?
>
> For more details on the snippet I wrote a little dity describing it,
> and
> related issues here:
>
> http://developer.mozilla.org/en/docs/Working_with_Multiple_Versions_of_Interfaces
>
>
>
>

_______________________________________________
dev-accessibility mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-accessibility
Reply | Threaded
Open this post in threaded view
|

Re: doQueryInterface of a new tab (nsIAccessible) returns NS_ERROR_INVALID_POINTER

ian.alistair.mason
Hi Aaron,

Thanks for taking the time to address my problem. Alas though I was a
little sloppy
in explaining it. Let me go into a little more detail. I'm watching
browser events
within my extension, and, for example, when I see a TabOpen event I
attempt
to obtain tha HWND of the associated document, to be explicit I try
and find
the HWND of:

event.target.linkedBrowser.contentDocument


which is an

[object XPCNativeWrapper [object HTMLDocument]]

So it is the creature that is getting passed to the snippet I included
in my previous post. In FF2, and even way back in FF1.5, the
alogorithm I used to obtain the HWND was reliable. This was to get it
via the corresponding nsIAccessibleDocument GetWindowHandle method.

But now in FF3 it seems that when the HTMLDocument is very young (the
first TabOpen event, and the subsequent TabSelect event) the attempt
to get the nsIAccessibleDocument from the HTMLDocument's nsIAccessible
(obtained via GetAccessibleFor) fails with the invalid pointer error
code.

Are you now saying that I'b be better off getting it from the
nsIAccessNode?
If so  I'll look into getting the HWND from the nsIAccessNode.

Thanks for any advice you have to offer.

Cheers, Ian.





On Jul 23, 1:45 am, Aaron Leventhal <[hidden email]>
wrote:

> The tab element is not a document node, so QI wouldn't work there.
>
> If we knew more about your project and how you are building and
> distributing it we could recommend the best interface for this.
>
> In the mean time you can QI to nsIAccessNode and use
> 139   /**
> 140    * The OS window handle for the window this node
> 141    * is being displayed in.
> 142    */
> 143   [noscript] readonly attribute voidPtr ownerWindow;
>
> http://mxr.mozilla.org/seamonkey/source/accessible/public/nsIAccessNo...
>
> Just cast the result to an HWND.
>
> - Aaron
>
>
>
> Ian wrote:
> > Hi,
>
> > I'm using accessibility to get the HWNDs of various DOM nodes within
> > the ff browser, and recently (ff3) I'm getting invalid pointer errors
> > back from QI-ing the accessible node returned by GetAccessibleFor.
>
> > Here for example is the scenario, the node is the new tab
> > (obtained from a javascript TabOpen event, or the subsequent TabSelect
> > event)
> > the following snippet will fail with NS_ERROR_INVALID_POINTER
>
> > nsresult snippet(nsIDOMNode *node){
> >    nsresult rv;
> >    nsCOMPtr<nsIAccessibleRetrieval>  refp;
> >    refp = do_CreateInstance(accRetCID,&rv);
> >    if (NS_FAILED(rv)){ return NS_ERROR_FAILURE; }
> >    nsCOMPtr<nsIAccessible>  accnode;
> >    rv = refp->GetAccessibleFor(node, getter_AddRefs(accnode));
> >    if(NS_FAILED(rv)){  return NS_ERROR_FAILURE; }
> >    nsCOMPtr<nsIAccessibleDocument>  accdocnode;
> >    accdocnode = do_QueryInterface(accnode,&rv);  //<---  fails; rv =
> > 0x80004003
> >    if(NS_FAILED(rv)){ return NS_ERROR_FAILURE; }
> > }
>
> > If I select another tab, then reselect the new tab, things no longer
> > fail.
>
> > The question is what am I doing wrong, or what has changed?
>
> > For more details on the snippet I wrote a little dity describing it,
> > and
> > related issues here:
>
> >http://developer.mozilla.org/en/docs/Working_with_Multiple_Versions_o...- Hide quoted text -
>
> - Show quoted text -

_______________________________________________
dev-accessibility mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-accessibility
Reply | Threaded
Open this post in threaded view
|

Re: doQueryInterface of a new tab (nsIAccessible) returns NS_ERROR_INVALID_POINTER

Aaron Leventhal-3
I'm a bit confused about whether you are in JS or C++.

- Aaron

Ian wrote:

> Hi Aaron,
>
> Thanks for taking the time to address my problem. Alas though I was a
> little sloppy
> in explaining it. Let me go into a little more detail. I'm watching
> browser events
> within my extension, and, for example, when I see a TabOpen event I
> attempt
> to obtain tha HWND of the associated document, to be explicit I try
> and find
> the HWND of:
>
> event.target.linkedBrowser.contentDocument
>
>
> which is an
>
> [object XPCNativeWrapper [object HTMLDocument]]
>
> So it is the creature that is getting passed to the snippet I included
> in my previous post. In FF2, and even way back in FF1.5, the
> alogorithm I used to obtain the HWND was reliable. This was to get it
> via the corresponding nsIAccessibleDocument GetWindowHandle method.
>
> But now in FF3 it seems that when the HTMLDocument is very young (the
> first TabOpen event, and the subsequent TabSelect event) the attempt
> to get the nsIAccessibleDocument from the HTMLDocument's nsIAccessible
> (obtained via GetAccessibleFor) fails with the invalid pointer error
> code.
>
> Are you now saying that I'b be better off getting it from the
> nsIAccessNode?
> If so  I'll look into getting the HWND from the nsIAccessNode.
>
> Thanks for any advice you have to offer.
>
> Cheers, Ian.
>
>
>
>
>
> On Jul 23, 1:45 am, Aaron Leventhal<[hidden email]>
> wrote:
>> The tab element is not a document node, so QI wouldn't work there.
>>
>> If we knew more about your project and how you are building and
>> distributing it we could recommend the best interface for this.
>>
>> In the mean time you can QI to nsIAccessNode and use
>> 139   /**
>> 140    * The OS window handle for the window this node
>> 141    * is being displayed in.
>> 142    */
>> 143   [noscript] readonly attribute voidPtr ownerWindow;
>>
>> http://mxr.mozilla.org/seamonkey/source/accessible/public/nsIAccessNo...
>>
>> Just cast the result to an HWND.
>>
>> - Aaron
>>
>>
>>
>> Ian wrote:
>>> Hi,
>>> I'm using accessibility to get the HWNDs of various DOM nodes within
>>> the ff browser, and recently (ff3) I'm getting invalid pointer errors
>>> back from QI-ing the accessible node returned by GetAccessibleFor.
>>> Here for example is the scenario, the node is the new tab
>>> (obtained from a javascript TabOpen event, or the subsequent TabSelect
>>> event)
>>> the following snippet will fail with NS_ERROR_INVALID_POINTER
>>> nsresult snippet(nsIDOMNode *node){
>>>     nsresult rv;
>>>     nsCOMPtr<nsIAccessibleRetrieval>    refp;
>>>     refp = do_CreateInstance(accRetCID,&rv);
>>>     if (NS_FAILED(rv)){ return NS_ERROR_FAILURE; }
>>>     nsCOMPtr<nsIAccessible>    accnode;
>>>     rv = refp->GetAccessibleFor(node, getter_AddRefs(accnode));
>>>     if(NS_FAILED(rv)){  return NS_ERROR_FAILURE; }
>>>     nsCOMPtr<nsIAccessibleDocument>    accdocnode;
>>>     accdocnode = do_QueryInterface(accnode,&rv);  //<---  fails; rv =
>>> 0x80004003
>>>     if(NS_FAILED(rv)){ return NS_ERROR_FAILURE; }
>>> }
>>> If I select another tab, then reselect the new tab, things no longer
>>> fail.
>>> The question is what am I doing wrong, or what has changed?
>>> For more details on the snippet I wrote a little dity describing it,
>>> and
>>> related issues here:
>>> http://developer.mozilla.org/en/docs/Working_with_Multiple_Versions_o...- Hide quoted text -
>> - Show quoted text -
>

_______________________________________________
dev-accessibility mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-accessibility
Reply | Threaded
Open this post in threaded view
|

Re: doQueryInterface of a new tab (nsIAccessible) returns NS_ERROR_INVALID_POINTER

ian.alistair.mason
Aaron,

I start out in javascript (I'm a toolbar), but to get the HWND (which
I use solely for the
purpose of IPC identification) I pass through to C++ and XPCOM.  Hence
the snippet
starts out being passed the

nsIDOMNode *node

that corresponds to the

event.target.linkedBrowser.contentDocument

which is an

[object XPCNativeWrapper [object HTMLDocument]]

the snippet can thus be described in idl speak as:

long snippet(in nsIDOMNode node);

Make sense now? Sorry to be such trouble...

Cheers, Ian.
_______________________________________________
dev-accessibility mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-accessibility
Reply | Threaded
Open this post in threaded view
|

Re: doQueryInterface of a new tab (nsIAccessible) returns NS_ERROR_INVALID_POINTER

Aaron Leventhal-3
No problem. It's probably easier if you visited our IRC channel on
irc.mozilla.org #accessibility

- Aaron

Ian wrote:

> Aaron,
>
> I start out in javascript (I'm a toolbar), but to get the HWND (which
> I use solely for the
> purpose of IPC identification) I pass through to C++ and XPCOM.  Hence
> the snippet
> starts out being passed the
>
> nsIDOMNode *node
>
> that corresponds to the
>
> event.target.linkedBrowser.contentDocument
>
> which is an
>
> [object XPCNativeWrapper [object HTMLDocument]]
>
> the snippet can thus be described in idl speak as:
>
> long snippet(in nsIDOMNode node);
>
> Make sense now? Sorry to be such trouble...
>
> Cheers, Ian.

_______________________________________________
dev-accessibility mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-accessibility
Reply | Threaded
Open this post in threaded view
|

Re: doQueryInterface of a new tab (nsIAccessible) returns NS_ERROR_INVALID_POINTER

Aaron Leventhal-3
In reply to this post by ian.alistair.mason
Okay, I don't think using nsIAccessNode will help. I think you were
right that in Firefox 3 the timing is different, and you get the TabOpen
event too early. The old document is still there. IIRC tere is even an
old document for a new tab (it's about:blank). What you really want is a
TabOpen followed by a PageShow or a DOMContentLoaded or something that
makes sure you end up with the actual document, not the old one.

At that point either nsIAccessibleDocument or nsIAccessNode should get
what you want.

BTW, are you building your extension to match with specific Firefox
versions? If not, you could get burned by binary incompatibilities. And
if you are, you can probably use a more direct interface than the
accessibility ones, so that the whole a11y service wouldn't need to get
instantiated and bog you down.

- Aaron
_______________________________________________
dev-accessibility mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-accessibility
Reply | Threaded
Open this post in threaded view
|

Re: doQueryInterface of a new tab (nsIAccessible) returns NS_ERROR_INVALID_POINTER

ian.alistair.mason
Hi Aaron,

Yes it does have the feel of a timing race, and thanks for the tip,
I'll see
if I can resort to waiting for a subsequent event on the new tab to
resolve haste, and
trying to get the HWND too soon.

> BTW, are you building your extension to match with specific Firefox
> versions?

I try the new interfaces first, then if they fail I try the older
ones. Currently
I only have two possible interfaces, so this is managable :-)

*But* if you can point me to a way of getting HWND's of firefox tabs
and
windows that doesn't use accessibility, you'll get my thanks, and
probably
never be bothered by me again! How can you turn down such an offer?!?

Cheers, Ian
_______________________________________________
dev-accessibility mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-accessibility
Reply | Threaded
Open this post in threaded view
|

Re: doQueryInterface of a new tab (nsIAccessible) returns NS_ERROR_INVALID_POINTER

Aaron Leventhal-3
Something like this:

    nsCOMPtr<nsIDocument> doc = do_QueryInterface(docAsNode);
    nsIPresShell *shell = doc->GetPrimaryShell(doc);
    if (shell) {
      // Find hWnd
      nsIViewManager* vm = shell->GetViewManager();
      if (vm) {
        nsCOMPtr<nsIWidget> widget;
        vm->GetWidget(getter_AddRefs(widget));
        if (widget) {
          HWND hWnd = static_cast<HWND>
            (widget->GetNativeData(NS_NATIVE_WINDOW));
        }
      }
    }



Ian wrote:

> Hi Aaron,
>
> Yes it does have the feel of a timing race, and thanks for the tip,
> I'll see
> if I can resort to waiting for a subsequent event on the new tab to
> resolve haste, and
> trying to get the HWND too soon.
>
>> BTW, are you building your extension to match with specific Firefox
>> versions?
>
> I try the new interfaces first, then if they fail I try the older
> ones. Currently
> I only have two possible interfaces, so this is managable :-)
>
> *But* if you can point me to a way of getting HWND's of firefox tabs
> and
> windows that doesn't use accessibility, you'll get my thanks, and
> probably
> never be bothered by me again! How can you turn down such an offer?!?
>
> Cheers, Ian

_______________________________________________
dev-accessibility mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-accessibility
Reply | Threaded
Open this post in threaded view
|

Re: doQueryInterface of a new tab (nsIAccessible) returns NS_ERROR_INVALID_POINTER

ian.alistair.mason
Excellent Aaron, I'll try that method out asap, and post a conclusion
in a few days.
You have been a great help,  as always! Ian.
_______________________________________________
dev-accessibility mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-accessibility
Reply | Threaded
Open this post in threaded view
|

Re: doQueryInterface of a new tab (nsIAccessible) returns NS_ERROR_INVALID_POINTER

ian.alistair.mason

Aaron, That works like an absolute  charm, and just in time for the
weekend!
Kudos and karma for you in copius volumes!

Cheers, Ian.

P.s. GetPrimaryShell takes no arguments.
_______________________________________________
dev-accessibility mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-accessibility