Migrating an old Add-on from XUL
to Add-ons-SDK
in preparation for WebExtensions
. Would still like to support some older browsers with this add-on, so that is why I am not jumping right to WebExtensions
.
What I'd like to do is control minimize, maximize full screen and restore functions. These seem to be implemented right on the window object, since FF 45.0, which is great, but no help when trying to support older browsers. Not sure if that functionality existed before, or how to access it in a XUL-migration friendly context ( Step 1: use Services.jsm ). See Migrate from XUL Overlay to Restartless.
To best I could find is to use Components.interfaces.nsIDOMChromeWindow.windowState
of the STATE_*
attributes to detect the minimized, maximized, normal or fullscreen states, and then issue the methods minimize()
, maximize()
and restore()
found on the same object ( nsIDOMChromeWindow ).
But I can't seem to find the precise way to load the equivalent
Components.interfaces.nsIDOMChromeWindow.windowState
using a resource://
like Services.jsm
.
For example, the old add-on also used:
Components.interfaces.nsIPrefBranchInternal
which was later renamed to
Components.interfaces.nsIPrefBranch2
and later folded into
Components.interfaces.nsIPrefBranch
which can now be accessed by:
Components.utils.import( 'resource://gre/modules/Services.jsm' );
var prefsService = Services.prefs;
See Services.jsm on MDN for options.
| Service accessor | Service interface | Service name |
|-------------------|----------------------|-------------------------|
| domStorageManager | nsIDOMStorageManager | DOM Storage Manager |
| DOMRequest | nsIDOMRequestService | DOMRequest service |
| wm | nsIWindowMediator | Window mediator service |
| ww | nsIWindowWatcher | Window watcher service |
There's two things that start with nsIDOM*
(Request and Storage), but don't seem to be related, or have any path to the desired object. nsIWindow*
(Mediator and Watcher) both have some methods that return a similarly named nsIDOMWindow
object (deprecated in FF 44), including a confusingly named getChromeForWindow()
method, but that is NOT THE SAME OBJECT, and indeed, doesn't have any of the desired state attributes or window management toggle methods.
I am not sure what I am missing here. Is this simply one of the things the developers decided was "low level" and thus refused to provide any high level access via Services.jsm? Or is the access there but documentation incomplete? Or is it documented but buried? Or is it blogged about somewhere? I could only find one single post on all of StackOverflow that even had nsIDOMChromeWindow
in it!
As I initially stated, I know there's a simple way to do this in both the "old" style XUL/Overlay, as well as the "new" FF >= 45, but I am looking to support that in-between area, at least for another year or two, until they absolutely drop XUL. By then, I will have the Add-ons-SDK version ready to go, and the WebExtensions well underway.