2016-01-13 22:08:20 +03:00
|
|
|
const FRAME_URL = "http://example.org/";
|
|
|
|
|
|
|
|
const METHODS = {
|
|
|
|
setVisible: {},
|
|
|
|
getVisible: {},
|
|
|
|
setActive: {},
|
|
|
|
getActive: {},
|
|
|
|
addNextPaintListener: {},
|
|
|
|
removeNextPaintListener: {},
|
|
|
|
sendMouseEvent: {},
|
|
|
|
sendTouchEvent: {},
|
|
|
|
goBack: {},
|
|
|
|
goForward: {},
|
|
|
|
reload: {},
|
|
|
|
stop: {},
|
|
|
|
download: {},
|
|
|
|
purgeHistory: {},
|
|
|
|
getScreenshot: {},
|
|
|
|
zoom: {},
|
|
|
|
getCanGoBack: {},
|
|
|
|
getCanGoForward: {},
|
|
|
|
getContentDimensions: {},
|
2016-04-21 16:48:59 +03:00
|
|
|
setInputMethodActive: {},
|
2016-01-13 22:08:20 +03:00
|
|
|
findAll: {},
|
|
|
|
findNext: {},
|
|
|
|
clearMatch: {},
|
2016-04-21 16:48:59 +03:00
|
|
|
executeScript: {},
|
2016-01-13 22:08:20 +03:00
|
|
|
getWebManifest: {},
|
|
|
|
mute: {},
|
|
|
|
unmute: {},
|
|
|
|
getMuted: {},
|
|
|
|
setVolume: {},
|
|
|
|
getVolume: {},
|
|
|
|
};
|
|
|
|
|
|
|
|
const ATTRIBUTES = [
|
|
|
|
"allowedAudioChannels",
|
|
|
|
];
|
|
|
|
|
|
|
|
function once(target, eventName, useCapture = false) {
|
2016-04-21 16:48:59 +03:00
|
|
|
info("Waiting for event: '" + JSON.stringify(eventName) + "' on " + target + ".");
|
2016-01-13 22:08:20 +03:00
|
|
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
for (let [add, remove] of [
|
|
|
|
["addEventListener", "removeEventListener"],
|
|
|
|
["addMessageListener", "removeMessageListener"],
|
|
|
|
]) {
|
|
|
|
if ((add in target) && (remove in target)) {
|
2016-04-21 16:48:59 +03:00
|
|
|
eventName.forEach(evName => {
|
|
|
|
target[add](evName, function onEvent(...aArgs) {
|
|
|
|
info("Got event: '" + evName + "' on " + target + ".");
|
|
|
|
target[remove](evName, onEvent, useCapture);
|
|
|
|
resolve(aArgs);
|
|
|
|
}, useCapture);
|
|
|
|
});
|
2016-01-13 22:08:20 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function* loadFrame(attributes = {}) {
|
|
|
|
let iframe = document.createElement("iframe");
|
|
|
|
iframe.setAttribute("src", FRAME_URL);
|
|
|
|
for (let key in attributes) {
|
|
|
|
iframe.setAttribute(key, attributes[key]);
|
|
|
|
}
|
2016-04-21 16:48:59 +03:00
|
|
|
let loaded = once(iframe, [ "load", "mozbrowserloadend" ]);
|
2016-01-13 22:08:20 +03:00
|
|
|
document.body.appendChild(iframe);
|
|
|
|
yield loaded;
|
|
|
|
return iframe;
|
|
|
|
}
|