2013-05-06 21:10:28 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
(function () { // bug 673569 workaround :(
|
|
|
|
|
|
|
|
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/PageThumbs.jsm");
|
|
|
|
|
|
|
|
const backgroundPageThumbsContent = {
|
|
|
|
|
|
|
|
init: function () {
|
2013-05-30 18:17:41 -07:00
|
|
|
// Arrange to prevent (most) popup dialogs for this window - popups done
|
|
|
|
// in the parent (eg, auth) aren't prevented, but alert() etc are.
|
|
|
|
let dwu = content.
|
|
|
|
QueryInterface(Ci.nsIInterfaceRequestor).
|
|
|
|
getInterface(Ci.nsIDOMWindowUtils);
|
|
|
|
dwu.preventFurtherDialogs();
|
|
|
|
|
2013-07-11 20:59:16 -07:00
|
|
|
// We want a low network priority for this service - lower than b/g tabs
|
|
|
|
// etc - so set it to the lowest priority available.
|
|
|
|
this._webNav.QueryInterface(Ci.nsIDocumentLoader).
|
|
|
|
loadGroup.QueryInterface(Ci.nsISupportsPriority).
|
|
|
|
priority = Ci.nsISupportsPriority.PRIORITY_LOWEST;
|
|
|
|
|
2013-06-24 22:07:12 -07:00
|
|
|
docShell.allowMedia = false;
|
|
|
|
docShell.allowPlugins = false;
|
|
|
|
|
2013-05-06 21:10:28 -07:00
|
|
|
addMessageListener("BackgroundPageThumbs:capture",
|
|
|
|
this._onCapture.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
get _webNav() {
|
|
|
|
return docShell.QueryInterface(Ci.nsIWebNavigation);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onCapture: function (msg) {
|
2013-07-03 17:44:38 -07:00
|
|
|
this._webNav.stop(Ci.nsIWebNavigation.STOP_NETWORK);
|
|
|
|
if (this._onLoad)
|
2013-05-06 21:10:28 -07:00
|
|
|
removeEventListener("load", this._onLoad, true);
|
|
|
|
|
|
|
|
this._onLoad = function onLoad(event) {
|
|
|
|
if (event.target != content.document)
|
|
|
|
return;
|
2013-07-12 21:03:18 -07:00
|
|
|
let pageLoadTime = new Date() - loadDate;
|
2013-05-06 21:10:28 -07:00
|
|
|
removeEventListener("load", this._onLoad, true);
|
|
|
|
delete this._onLoad;
|
|
|
|
|
|
|
|
let canvas = PageThumbs._createCanvas(content);
|
2013-07-12 21:03:18 -07:00
|
|
|
let captureDate = new Date();
|
2013-05-06 21:10:28 -07:00
|
|
|
PageThumbs._captureToCanvas(content, canvas);
|
2013-07-12 21:03:18 -07:00
|
|
|
let captureTime = new Date() - captureDate;
|
2013-05-06 21:10:28 -07:00
|
|
|
|
|
|
|
let finalURL = this._webNav.currentURI.spec;
|
|
|
|
let fileReader = Cc["@mozilla.org/files/filereader;1"].
|
|
|
|
createInstance(Ci.nsIDOMFileReader);
|
|
|
|
fileReader.onloadend = function onArrayBufferLoad() {
|
|
|
|
sendAsyncMessage("BackgroundPageThumbs:didCapture", {
|
|
|
|
id: msg.json.id,
|
|
|
|
imageData: fileReader.result,
|
|
|
|
finalURL: finalURL,
|
2013-07-12 21:03:18 -07:00
|
|
|
telemetry: {
|
|
|
|
CAPTURE_PAGE_LOAD_TIME_MS: pageLoadTime,
|
|
|
|
CAPTURE_CANVAS_DRAW_TIME_MS: captureTime,
|
|
|
|
},
|
2013-05-06 21:10:28 -07:00
|
|
|
});
|
|
|
|
};
|
|
|
|
canvas.toBlob(blob => fileReader.readAsArrayBuffer(blob));
|
2013-07-03 17:44:38 -07:00
|
|
|
|
|
|
|
// Load about:blank to cause the captured window to be collected...
|
|
|
|
// eventually.
|
|
|
|
this._webNav.loadURI("about:blank", Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
|
|
|
|
null, null, null);
|
2013-05-06 21:10:28 -07:00
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
addEventListener("load", this._onLoad, true);
|
|
|
|
this._webNav.loadURI(msg.json.url, Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
|
|
|
|
null, null, null);
|
2013-07-12 21:03:18 -07:00
|
|
|
let loadDate = new Date();
|
2013-05-06 21:10:28 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
backgroundPageThumbsContent.init();
|
|
|
|
|
|
|
|
})();
|