gecko-dev/browser/extensions/webcompat-reporter/content/wc-frame.js
Mark Banner e5c2479848 Bug 1336070 - Enable eslint no-undef for browser/, apart from components/ and base/content/. r=mossop
MozReview-Commit-ID: CJtpm8zlLxa

--HG--
extra : rebase_source : c6a834d5aaba0f84f5e147333085883de1a118e8
2017-02-02 09:08:42 +00:00

25 lines
1.1 KiB
JavaScript

/* 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/. */
/* global content:false, addMessageListener:false, removeMessageListener: false */
let { utils: Cu } = Components;
const SCREENSHOT_MESSAGE = "WebCompat:SendScreenshot";
addMessageListener(SCREENSHOT_MESSAGE, function handleMessage(message) {
removeMessageListener(SCREENSHOT_MESSAGE, handleMessage);
// postMessage the screenshot blob from a content Sandbox so message event.origin
// is what we expect on the client-side (i.e., https://webcompat.com)
try {
let sb = new Cu.Sandbox(content.document.nodePrincipal);
sb.win = content;
sb.screenshotBlob = Cu.cloneInto(message.data.screenshot, content);
sb.wcOrigin = Cu.cloneInto(message.data.origin, content);
Cu.evalInSandbox("win.postMessage(screenshotBlob, wcOrigin);", sb);
Cu.nukeSandbox(sb);
} catch (ex) {
Cu.reportError(`WebCompatReporter: sending a screenshot failed: ${ex}`);
}
});