Bug 666643 - convert snapshotWindow to SpecialPowers. r=ted

This commit is contained in:
Joel Maher 2011-10-14 07:52:02 -04:00
parent fd8629a74b
commit d46dfae76b
3 changed files with 17 additions and 20 deletions

View File

@ -20,7 +20,7 @@
<script type="application/javascript"> <script type="application/javascript">
<![CDATA[ <![CDATA[
var imports = [ "SimpleTest", "is", "isnot", "ok" ]; var imports = [ "SimpleTest", "is", "isnot", "ok", "SpecialPowers" ];
for each (var name in imports) { for each (var name in imports) {
window[name] = window.opener.wrappedJSObject[name]; window[name] = window.opener.wrappedJSObject[name];
} }

View File

@ -1,9 +1,7 @@
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var gWindowUtils; var gWindowUtils;
try { try {
gWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils); gWindowUtils = SpecialPowers.getDOMWindowUtils(window);
if (gWindowUtils && !gWindowUtils.compareCanvases) if (gWindowUtils && !gWindowUtils.compareCanvases)
gWindowUtils = null; gWindowUtils = null;
} catch (e) { } catch (e) {
@ -11,28 +9,13 @@ try {
} }
function snapshotWindow(win, withCaret) { function snapshotWindow(win, withCaret) {
// drawWindow requires privileges, as might innerWidth/innerHeight if it's return SpecialPowers.snapshotWindow(win, withCaret);
// a cross domain window
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var el = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
el.width = win.innerWidth;
el.height = win.innerHeight;
var ctx = el.getContext("2d");
ctx.drawWindow(win, win.scrollX, win.scrollY,
win.innerWidth, win.innerHeight,
"rgb(255,255,255)",
withCaret ? ctx.DRAWWINDOW_DRAW_CARET : 0);
return el;
} }
// If the two snapshots don't compare as expected (true for equal, false for // If the two snapshots don't compare as expected (true for equal, false for
// unequal), returns their serializations as data URIs. In all cases, returns // unequal), returns their serializations as data URIs. In all cases, returns
// whether the comparison was as expected. // whether the comparison was as expected.
function compareSnapshots(s1, s2, expected) { function compareSnapshots(s1, s2, expected) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var s1Str, s2Str; var s1Str, s2Str;
var correct = false; var correct = false;
if (gWindowUtils) { if (gWindowUtils) {

View File

@ -662,5 +662,19 @@ SpecialPowersAPI.prototype = {
getService(Components.interfaces.nsIClipboardHelper); getService(Components.interfaces.nsIClipboardHelper);
cbHelperSvc.copyString(preExpectedVal); cbHelperSvc.copyString(preExpectedVal);
}, },
snapshotWindow: function (win, withCaret) {
var el = this.window.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
el.width = win.innerWidth;
el.height = win.innerHeight;
var ctx = el.getContext("2d");
var flags = 0;
ctx.drawWindow(win, win.scrollX, win.scrollY,
win.innerWidth, win.innerHeight,
"rgb(255,255,255)",
withCaret ? ctx.DRAWWINDOW_DRAW_CARET : 0);
return el;
},
}; };