I’ve developed an extension for firefox and google chrome, safari and ie8+. It inserts a button into the google mail interface . The button is supposed to insert some custom text into the email footer. It works fine on all of the four if i access the standard google mail address (you can watch it here and here).
Instead, if i access gmail through google apps, it almost all goes down the pipe. The only addon hat works well is the google chrome one. In all the others, the button is correctly added but when i click it this doesn’t add anything into the email footer and produces the following errors.
In firefox i get the following jquery error console:
Error: Permission denied to access property 'ownerDocument' Source File: chrome://sendsecurefree/content/jquery.js Line: 16
In firebug :
uncaught exception: [Exception... "Security Manager vetoed action" nsresult: "0x80570027 (NS_ERROR_XPC_SECURITY_MANAGER_VETO)" location: "JS frame :: chrome://sendsecurefree/content/jquery.js :: anonymous :: line 16" data: no] Line 0
Also, in Safari :
ReferenceError: Can't find variable: toggleEncryptFooter
In internet explorer only composing the mail works, forwarding and replying doesn’t.
Here’s my jquery code that is injected into the gmail webpage :
function toggleEncryptFooter() {
var canvasBody = getGmailCanvasBody();
// get the button element
var documentul = getGmailCanvasDoc();
divul = jQuery(".dX.J-Jw", documentul);
var encryptButton = divul.find("#encrypt");
//first, check if we already have an encrypt footer
var encryptFooter = jQuery("#encrypt_footer", canvasBody);
if(encryptFooter.length != 0) {
//we have the footer inserted, delete it
encryptFooter.remove();
// style the button to no footer
encryptButton.html('Enable Encryption');
encryptButton.removeClass('downer');
encryptButton.addClass('upper');
} else {
//add the footer
var doc = document;
var head = jQuery('head', doc);
var textul = head.find("div#textul",head);
// text was inserted in injectScript / gmailadder.js into head of canvas_frame
getGmailCanvasBody().append('<div id="encrypt_footer">' + textul.html() + '</div>');
// style the button to footer added
encryptButton.html('Disable Encryption');
encryptButton.removeClass('upper');
encryptButton.addClass('downer');
}
}
// gets the head element of the document
function getGmailHead(){
var doc = document;
var body = jQuery('head', doc);
return body;
}
// gets the body element of the document
function getGmailCanvasBody() {
var doc = document;
gmailInst = jQuery("iframe", doc);
if(gmailInst.length==0) {
//exit now, we are not on compose
return null;
}
return gmailInst.contents().find('body');
}
// get the document object
function getGmailCanvasDoc() {
var doc = document;
var body = jQuery('body', doc);
var canvas_frame = jQuery('iframe#canvas_frame', body);
if(canvas_frame.length==0) {
//exit now, we are not on gmail
return null;
}
var canvas_doc = canvas_frame[0].contentDocument;
return canvas_doc;
}
I had to replace
with
It seems that in the normal Google mail interface there is only one sub-iframe inside the iframe I’m working in, so gmailInst = jQuery(“iframe”, doc) does its job as long as this condition maintains.
If i activate a few labs gadgets that are implemented with iframes, then gmailInst = jQuery(“iframe”, doc) passes the first sub-iframe in the list which is probably not the one i’m looking for so i have to use extra filtering: in this case, the class name of the sub-iframe i’m searching.
Assumptions are devils in disguise.