Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calling a function from chrome addon code to none-addon code (but still chrome location)

1 view
Skip to first unread message

fuzzys...@gmail.com

unread,
Oct 9, 2008, 11:16:49 PM10/9/08
to
JS code in addon: http://pastebin.mozilla.org/551714
XUL code opened in window and processed by addon code above:
http://pastebin.mozilla.org/551717

Results in:
Fired DOMContentLoaded!
Target!
Fired DOMContentLoaded!
Target!
Fired DOMContentLoaded!
Target!
Fired DOMContentLoaded!
Target!
Fired DOMContentLoaded!
Target!
Fired inline!
Fired DOMContentLoaded!
Target!
Fired onload!

The order seems to be:
1. inline
2. DOMContentLoaded
3. onload=""

So inline code should be in place... However line 14 in the JS code
results in
"Error: event.originalTarget.defaultView.whopzer is not a function"
If I try to do the same in JSShell with a globalevent (var globalevent
outside and globalevent = event inside) and do
globalevent.originalTarget.defaultView.whopzer("test\n") then it dumps
"Fired test\n"
So alright, I go ahead a put EventListeners on the doc at line 12
(#document) and 13 (<window>). These doesn't fire at all.

Any ideas to getting the inline function whopzer fired from the addon?

John J. Barton

unread,
Oct 9, 2008, 11:50:54 PM10/9/08
to
...

>
> Any ideas to getting the inline function whopzer fired from the addon?

event.originalTarget.defaultView.whopzer("direct addon!\n");

Issue window.dump(event.originalTarget.defaultView);
I guess you'll see a wrapped window.

jjb

fuzzys...@gmail.com

unread,
Oct 10, 2008, 9:33:14 PM10/10/08
to
On Oct 10, 5:50 am, "John J. Barton" <johnjbar...@johnjbarton.com>
wrote:

This is what I got. Text after # are my comments and not part of the
actual output
test loaded! # The test code is started
Fired inline # That is from previous
Fired DOMContentLoaded! # That is same from previous code
Found Target As [object XPCNativeWrapper [object Window]]! # This is
the previous dump("Target!") changed to: dump("Found Target As
"+event.originalTarget.defaultView+"!\n");
Fired onload # That is the same from previous code
# At this point the document is fully loaded and nothing else happens.
[object Window] # I open JavaScript Shell (from the developer
extension) and type in
window.dump(globalevent.originalTarget.defaultView)

What I see is that the event.originalTarget.defaultView from when the
code is running is changed from [object XPCNativeWrapper [object
Window]] to [object Window].

fuzzys...@gmail.com

unread,
Oct 10, 2008, 9:44:36 PM10/10/08
to

It seems the XPCNativeWrapper was the way to go looking. Found this:
http://developer.mozilla.org/en/Chrome_Registration#xpcnativewrappers
All the [object XPCNativeWrapper [object Window]] became [object
Window] :-)

John J. Barton

unread,
Oct 11, 2008, 12:57:09 PM10/11/08
to
fuzzys...@gmail.com wrote:
> On Oct 10, 5:50 am, "John J. Barton" <johnjbar...@johnjbarton.com>
> wrote:
...

> Found Target As [object XPCNativeWrapper [object Window]]! # This is
> the previous dump("Target!") changed to: dump("Found Target As
> "+event.originalTarget.defaultView+"!\n");
> Fired onload # That is the same from previous code
> # At this point the document is fully loaded and nothing else happens.
> [object Window] # I open JavaScript Shell (from the developer
> extension) and type in
> window.dump(globalevent.originalTarget.defaultView)
>
> What I see is that the event.originalTarget.defaultView from when the
> code is running is changed from [object XPCNativeWrapper [object
> Window]] to [object Window].

I'm not following all of what you are saying, but when you get Window
objects in extensions they can be wrapped in two ways. XPCNativeWrapper
or XPCSafeJSObjectWrapper (or some such). Since I can't tell which I
will get, I've started to add tests like
if (obj.wrappedJSObject)
var unwrapped = obj.wrappedJSObject;
else
var unwrapped = obj;
I guess you got one of each.

jjb

fuzzys...@gmail.com

unread,
Oct 11, 2008, 6:07:23 PM10/11/08
to
On Oct 11, 6:57 pm, "John J. Barton" <johnjbar...@johnjbarton.com>
wrote:

hmm, I don't see the wrappedJSObject on the window. Could it be
because of the XPCNativeWrapper is changed quickly after the window is
done loading everything that its removed?

0 new messages