2008-08-18 12:22:19 -07:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
|
2008-12-02 17:34:07 -08:00
|
|
|
var gWindowUtils;
|
2008-08-18 12:22:19 -07:00
|
|
|
|
|
|
|
try {
|
2008-12-02 17:34:07 -08:00
|
|
|
gWindowUtils = window.QueryInterface(CI.nsIInterfaceRequestor).getInterface(CI.nsIDOMWindowUtils);
|
|
|
|
if (gWindowUtils && !gWindowUtils.compareCanvases)
|
|
|
|
gWindowUtils = null;
|
2008-08-18 12:22:19 -07:00
|
|
|
} catch (e) {
|
2008-12-02 17:34:07 -08:00
|
|
|
gWindowUtils = null;
|
2008-08-18 12:22:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function snapshotWindow(win) {
|
|
|
|
var el = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
|
|
|
|
el.width = win.innerWidth;
|
|
|
|
el.height = win.innerHeight;
|
|
|
|
|
|
|
|
// drawWindow requires privileges
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
2008-12-02 17:34:07 -08:00
|
|
|
|
2008-08-18 12:22:19 -07:00
|
|
|
el.getContext("2d").drawWindow(win, win.scrollX, win.scrollY,
|
|
|
|
win.innerWidth, win.innerHeight,
|
|
|
|
"rgb(255,255,255)");
|
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the two snapshots aren't equal, returns their serializations as data URIs.
|
|
|
|
function compareSnapshots(s1, s2) {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
|
|
|
|
|
|
|
var s1Str, s2Str;
|
|
|
|
var equal = false;
|
2008-12-02 17:34:07 -08:00
|
|
|
if (gWindowUtils) {
|
|
|
|
equal = (gWindowUtils.compareCanvases(s1, s2, {}) == 0);
|
2008-08-18 12:22:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!equal) {
|
|
|
|
s1Str = s1.toDataURL();
|
|
|
|
s2Str = s2.toDataURL();
|
|
|
|
|
2008-12-02 17:34:07 -08:00
|
|
|
if (!gWindowUtils) {
|
2008-08-18 12:22:19 -07:00
|
|
|
equal = (s1Str == s2Str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [equal, s1Str, s2Str];
|
|
|
|
}
|