Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help with nsISSLStatusProvider

24 views
Skip to first unread message

MkFly

unread,
Apr 28, 2009, 12:11:24 AM4/28/09
to
I'm trying to do this inside of an extension:

// 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?

MkFly

unread,
Apr 28, 2009, 6:48:52 PM4/28/09
to
Tried this as well, same results. Although I note that if I change
target to always look a specific browser (say index 0, the first),
then I can get cipherName and everything else just fine, but only if
it is loaded in the foreground. If I then leave it open but select
another tab, wait 10-20 seconds, and attempt to query index 0 again
_without_ selecting it, all the values go to "undefined"!! Once I
select it again, the values are back for another 10-20 seconds.

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";

Neil

unread,
Apr 28, 2009, 7:12:05 PM4/28/09
to
MkFly wrote:

> 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.

MkFly

unread,
Apr 30, 2009, 2:04:05 AM4/30/09
to
Thanks Neil for the response.

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.

Neil

unread,
May 1, 2009, 7:13:06 AM5/1/09
to
MkFly wrote:

Sure, but you have to use instanceof or QueryInterface to tell XPConnect
that you really want an nsISSLStatus object, just in case.

MkFly

unread,
May 3, 2009, 2:12:21 PM5/3/09
to
Neil wrote:
> 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);

0 new messages