// on event from DOMContentLoaded
getCipher: function(event) {
var gb = getBrowser();
var targetBrowser = gb.getBrowserForDocument(event.target);
var ui = targetBrowser.securityUI;
var sslStatus = ui.QueryInterface
(Components.interfaces.nsISSLStatusProvider).SSLStatus;
alert(sslStatus.cipherName);
}
This works when loading a page in the foreground, but when a page
loads in the background, I get "undefined." Any idea why? Is this a
bug?
Can I get any help with this issue? :(
// event called from DOMContentLoaded
function tryToGetCipher(event) {
var gb = getBrowser();
var ci = Components.interfaces;
if (event.target instanceof XULDocument) {
var target = gb.selectedBrowser; //
foreground
} else {
var target = gb.getBrowserForDocument(event.target); //
background
}
var targetUI = target.securityUI;
var sslStatus = targetUI.QueryInterface
(ci.nsISSLStatusProvider).SSLStatus;
if(sslStatus) {
return sslStatus.cipherName; // or any SSLStatus attribute
} else return "no SSLStatus";
> var sslStatus = ui.QueryInterface(Components.interfaces.nsISSLStatusProvider).SSLStatus;
>
> alert(sslStatus.cipherName);
>
>
The SSLStatus property is only defined as an nsISupports which has no
cipherName attribute.
>This works when loading a page in the foreground, but when a page loads in the background, I get "undefined." Any idea why?
>
Every time the browser gets the SSL status, XPConnect creates a
temporary JavaScript object. The browser then checks that it's an
nsISSLStatus so it can update the lock icon. Later, the object gets
garbage-collected. However, there is then a time window during which,
when your code retrieves the SSL status, XPConnect will say "wait,
here's one I made earlier" and hands you the nsISSLStatus object.
Of course the browser only updates the lock icon for the active tab, so
that when you retrieve the SSL status for a background tab you get a
plain nsISupports object.
--
Warning: May contain traces of nuts.
Neil wrote:
> However, there is then a time window during which,
> when your code retrieves the SSL status, XPConnect will say "wait,
> here's one I made earlier" and hands you the nsISSLStatus object.
That makes sense, since in another test I set up, I would focus a tab,
then after unfocusing it, I could still access the SSL status for
about 10 to 20 seconds without refocusing it. I assume now that that
is when the garbage collector trashed it.
> Of course the browser only updates the lock icon for the active tab, so
> that when you retrieve the SSL status for a background tab you get a
> plain nsISupports object.
So am I going about this entirely wrong? Is there any way to access
the SSL attributes such as cipherName of a document loaded in the
background?
Thanks again.
Sure, but you have to use instanceof or QueryInterface to tell XPConnect
that you really want an nsISSLStatus object, just in case.
Ahhhh ... perfect. Thanks Neil, that was exactly what I was missing.
It works great after I changed it to:
if (sslStatus instanceof ci.nsISSLStatus) alert(sslStatus.cipherName);