Unable to override window.external

RESOLVED WORKSFORME

Status

()

Core
DOM
RESOLVED WORKSFORME
7 years ago
6 months ago

People

(Reporter: mkaply, Unassigned)

Tracking

({regression})

Trunk
x86
Mac OS X
regression
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

7 years ago
Created attachment 516160 [details]
XPI to demonstrate window.external problem

In Firefox 3.6, you could override window.external to implement your own custom handling.

In Firefox 4, that doesn't appear to be possible.

I'm attaching an XPI that demonstrates this.

I've created a function, msAddTrackingProtectionList

If in my chrome.manifest, I use:

category JavaScript-global-property externa @microsoft.com/external;1

and call window.externa.msAddTrackingProtectionList, it works fine.

If I change externa to external, it says the function is not found.
Keywords: regression
(Reporter)

Comment 1

7 years ago
So I've been looking at this more, and well this is definitely a bug/regression, there is aanother way to override window.external that does work in FF4.

So I'll take this as a WONTFIX if someone says the better way is the right way.

Better way is following the code in the console API:

http://mxr.mozilla.org/mozilla-central/source/dom/base/ConsoleAPI.js?force=1

Before I was following the code in the sidebar external API:

http://mxr.mozilla.org/mozilla-central/source/browser/components/sidebar/src/nsSidebar.js


Using Javascript-global-property is mostly voodoo anyway, so I'm not sure what the correct voodoo is.
We currently have two mechanisms, nsIClassInfo with DOM_OBJECT and nsIDOMGlobalPropertyInitializer
(Reporter)

Comment 2

7 years ago
Side note on the nsIDOMGlobalPropertyInitialize method (from console API).

It only works if I explicitly install an XPI.

I can't get it to work in an add-on development environment (file in profile points to add-on), no matter how many things I remove/purge.

I even tried creating a new profile and as the first thing, pointing to the dev env. No luck. But if I build and install the XPI, it works. Weird.

Comment 3

7 years ago
What does the category value actually end up as? Obviously the browser manifest registers an alternate category entry: http://mxr.mozilla.org/mozilla-central/source/browser/components/sidebar/src/nsSidebar.manifest#4

Assuming that the entry is correct, the code in here is "at fault":

http://mxr.mozilla.org/mozilla-central/source/dom/base/nsScriptNameSpaceManager.cpp#725

It will not overwrite an existing entry (found during startup before extension are registered) with a new entry. I'm not sure why the code was written this way, but I'm pretty sure this is a DOM bug if it's a bug at all.

volkmar made the change to do the correct dynamic category entries in bug 597809.
Component: XPCOM → DOM: Mozilla Extensions
QA Contact: xpcom → general
(Assignee)

Updated

5 years ago
Component: DOM: Mozilla Extensions → DOM
Product: Core → Core
(Reporter)

Comment 4

2 years ago
This is quite easy to do by defining functions on the wrappedJSObject, so i'm marking WORKSFORME.
Status: NEW → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.