Closed Bug 612405 Opened 14 years ago Closed 14 years ago

Devise a better way to determine the web console is a 'native' console object

Categories

(DevTools :: General, defect, P3)

defect

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 4.0b8

People

(Reporter: ddahl, Assigned: Gavin)

References

Details

Attachments

(1 file, 2 obsolete files)

We want to notify the enduser if the console object has been paved over. We currently do that by checking if the console is instanceof HUDConsole. With the landing of the lazy console and integration patches ( bug 587734 ) we seem to not be able to check instanceof when the object is a nsIDOMGlobalPropertyInitializer. The current, cheezy approach is to do:

if (!(aContentWindow.wrappedJSObject.console.classID == CLASS_ID_VALUE)) {
       this.logWarningAboutReplacedAPI(hudId);
     } 

Of course the classID is not enumerable from content pages, a developer who would like to fool this check would have to figure it out from the HUDConsole.jsm source code. Still a pretty weak check though.
Blocks: devtools4
Is this bug to fix cheezyness or does this mean that the "console has been paved over" message won't get displayed after the lazy console lands? (the priority of the latter is higher than the former, to be sure!)
(In reply to comment #1)
> Is this bug to fix cheezyness or does this mean that the "console has been
> paved over" message won't get displayed after the lazy console lands? (the
> priority of the latter is higher than the former, to be sure!)

The message will get displayed - it is just a less than meaningful check if it truly is "our" console.
Right - as landed it could theoretically be replaced by the page in a way that we wouldn't detect, but the page would need to go through efforts to "hide" the replacement from us, so it isn't a huge issue in practice.
Assignee: nobody → gavin.sharp
Attached patch WIP (obsolete) — Splinter Review
This is what I had in mind, but it doesn't work. Will need to find a better way.
so the .classID check didn't work for this? Disappointing.

Any idea why the instanceof check isn't working in your version, gavin?
I tried:

if (!(consoleObject instanceof Ci.nsISupports)) { 

as well. we should ask jst why this does not work.
Why not make |console| a a getter/setter prop on the window and have the setter display the message then overwrite |console|?
We want to continue making use of the "JavaScript Global Property" functionality, rather than having to define setters on every window global like we used to, so that's not a feasible solution.

Fixing bug 613315 and using getGlobalForObject seems like it could work, though.
Attached patch patch (obsolete) — Splinter Review
Actually, it works fine now even without that. I also changed the test so that it actually tests the warning (rather than calling logWarningAboutReplacedAPI directly...), and also covers the other case (making sure the warning doesn't appear when it shouldn't). I also simplified testLogEntry() a bit.
Attachment #491076 - Attachment is obsolete: true
Comment on attachment 492198 [details] [diff] [review]
patch

sweet. Cu.getGlobalForObject is pretty damn useful!
mass change: filter on PRIORITYSETTING
Priority: -- → P3
Attached patch patchSplinter Review
Attachment #492198 - Attachment is obsolete: true
Attachment #494253 - Flags: review?
Attachment #494253 - Flags: review? → review?(ddahl)
Attachment #494253 - Flags: review?(ddahl) → review+
Attachment #494253 - Flags: approval2.0?
Requesting approval because this is well tested (in addition to simplifying a bunch of existing tests), and removes cruft from a newly-added web-exposed API (good to do now lest people somehow manage to start depending on it).
Attachment #494253 - Flags: approval2.0? → approval2.0+
http://hg.mozilla.org/mozilla-central/rev/5928e59882b6
Status: NEW → RESOLVED
Closed: 14 years ago
Flags: in-testsuite+
Hardware: x86 → All
Resolution: --- → FIXED
Target Milestone: --- → Firefox 4.0b8
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: