Last Comment Bug 653531 - Shared knowledge of selected node in highlighter and web console
: Shared knowledge of selected node in highlighter and web console
Status: RESOLVED FIXED
[best: 1h, likely: 2h, worst: 1d][con...
:
Product: Firefox
Classification: Client Software
Component: Developer Tools (show other bugs)
: unspecified
: All All
: P2 normal (vote)
: Firefox 8
Assigned To: Panos Astithas [:past]
:
Mentors:
Depends on: 642471
Blocks:
  Show dependency treegraph
 
Reported: 2011-04-28 12:19 PDT by Rob Campbell [:rc] (:robcee)
Modified: 2011-08-22 10:51 PDT (History)
2 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Not working idea (1.13 KB, patch)
2011-07-28 03:42 PDT, Panos Astithas [:past]
no flags Details | Diff | Splinter Review
Not working idea v2 (999 bytes, patch)
2011-07-28 10:19 PDT, Panos Astithas [:past]
no flags Details | Diff | Splinter Review
Working version (7.74 KB, patch)
2011-07-29 09:32 PDT, Panos Astithas [:past]
rcampbell: review+
Details | Diff | Splinter Review
[in-fx-team] Simpler working patch (7.30 KB, patch)
2011-07-30 02:00 PDT, Panos Astithas [:past]
no flags Details | Diff | Splinter Review

Description Rob Campbell [:rc] (:robcee) 2011-04-28 12:19:33 PDT
We need to implement the $0 helper for the Web Console to gain access to the currently-selected node in the highlighter. This should also be available via the InspectorUI.selection property.
Comment 1 Panos Astithas [:past] 2011-07-28 03:42:29 PDT
Created attachment 549057 [details] [diff] [review]
Not working idea

I thought that something like this patch would suffice, but for the life of me I can't find a way to get a reference to the InspectorUI object. The console logging calls are some of my attempts at this. How can I get a reference to something #included in browser.js from a jsm?
Comment 2 Rob Campbell [:rc] (:robcee) 2011-07-28 06:21:04 PDT
I had a similar "not working" idea earlier. If you do a search through HUDService.jsm, you should find a reference to gBrowser. InspectorUI is a property attached to gBrowser so if you can get to that, you'll get to InspectorUI.
Comment 3 Panos Astithas [:past] 2011-07-28 10:19:01 PDT
Created attachment 549158 [details] [diff] [review]
Not working idea v2

(In reply to comment #2)
> I had a similar "not working" idea earlier. If you do a search through
> HUDService.jsm, you should find a reference to gBrowser. InspectorUI is a
> property attached to gBrowser so if you can get to that, you'll get to
> InspectorUI.

This doesn't seem to work either :-/
Comment 4 Panos Astithas [:past] 2011-07-29 09:32:14 PDT
Created attachment 549400 [details] [diff] [review]
Working version

It was so simple after all, only 7 LOC to get a bloody reference...
Comment 5 Rob Campbell [:rc] (:robcee) 2011-07-29 14:32:12 PDT
Comment on attachment 549400 [details] [diff] [review]
Working version

+      let window = HUDService.currentContext().window;
+      let mw = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+                     .getInterface(Components.interfaces.nsIWebNavigation)
+                     .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
+                     .rootTreeItem
+                   .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+                     .getInterface(Components.interfaces.nsIDOMWindow);

wah, that' a lotta QI!

Note, you can use the Ci constant for Components.interfaces.

I'm not sure we need to access through the contentWindow. The hudReference has a chromeWindow property which is the XUL window. I think you can access the InspectorUI property directly.

Or HUDService.currentContext() returns the current browser window.

return HUDService.currentContext().InspectorUI.selection *might* work?
Comment 6 Rob Campbell [:rc] (:robcee) 2011-07-29 17:46:24 PDT
yup, replacing all that with:

Object.defineProperty(aJSTerm.sandbox, "$0", {
    get: function() {
      let mw = HUDService.currentContext();
      try {
        return mw.InspectorUI.selection;
      }
      catch (ex) {
        aJSTerm.console.error(ex.message);
      }
    },
    enumerable: true,
    configurable: false
  });

works.
Comment 7 Rob Campbell [:rc] (:robcee) 2011-07-29 17:56:34 PDT
Comment on attachment 549400 [details] [diff] [review]
Working version

r+ with the above change
Comment 8 Panos Astithas [:past] 2011-07-30 02:00:44 PDT
Created attachment 549557 [details] [diff] [review]
[in-fx-team] Simpler working patch

Doh, thanks for that, it should help restore my faith in humanity, and Mozillians in particular...
Comment 9 Rob Campbell [:rc] (:robcee) 2011-08-02 07:34:30 PDT
Comment on attachment 549557 [details] [diff] [review]
[in-fx-team] Simpler working patch

http://hg.mozilla.org/integration/fx-team/rev/0d0395cb99ff
Comment 10 Tim Taubert [:ttaubert] (on PTO, back Aug 29th) 2011-08-03 07:58:06 PDT
http://hg.mozilla.org/mozilla-central/rev/0d0395cb99ff
Comment 11 Panos Astithas [:past] 2011-08-20 03:34:46 PDT
Does this bug need a dev-doc-needed keyword, or should we wait for the Highlighter to be enabled first?
Comment 12 Rob Campbell [:rc] (:robcee) 2011-08-22 10:51:37 PDT
(In reply to Panos Astithas [:past] from comment #11)
> Does this bug need a dev-doc-needed keyword, or should we wait for the
> Highlighter to be enabled first?

Yes, I think we should wait until this is turned on.

Note You need to log in before you can comment on or make changes to this bug.