2017-09-29 18:29:36 +01:00
|
|
|
/** Inject an input element into unsuspecting webpages and provide an API for interaction with tridactyl */
|
|
|
|
|
2017-10-13 22:10:33 -07:00
|
|
|
/* TODO:
|
2017-09-29 18:29:36 +01:00
|
|
|
CSS
|
|
|
|
Friendliest-to-webpage way of injecting commandline bar?
|
|
|
|
Security: how to prevent other people's JS from seeing or accessing the bar or its output?
|
|
|
|
- Method here is isolation via iframe
|
|
|
|
- Web content can replace the iframe, but can't view or edit its content.
|
|
|
|
- see doc/escalating-privilege.md for other approaches.
|
|
|
|
*/
|
|
|
|
|
2017-10-02 00:59:51 +01:00
|
|
|
// inject the commandline iframe into a content page
|
2017-09-29 18:29:36 +01:00
|
|
|
|
2017-10-05 15:27:45 +01:00
|
|
|
let cmdline_iframe: HTMLIFrameElement = undefined
|
|
|
|
|
|
|
|
function init(){
|
2017-10-23 09:42:50 +01:00
|
|
|
if (cmdline_iframe === undefined && window.document.body !== null) {
|
|
|
|
try {
|
|
|
|
console.log("INIT")
|
|
|
|
cmdline_iframe = window.document.createElement("iframe")
|
|
|
|
cmdline_iframe.setAttribute("src", browser.extension.getURL("static/commandline.html"))
|
|
|
|
hide()
|
|
|
|
window.document.body.appendChild(cmdline_iframe)
|
|
|
|
} catch (e) {
|
|
|
|
console.error("Couldn't initialise cmdline_iframe!", e)
|
|
|
|
}
|
|
|
|
}
|
2017-10-05 15:27:45 +01:00
|
|
|
}
|
2017-10-05 12:34:18 +01:00
|
|
|
|
2017-10-06 04:16:02 +01:00
|
|
|
// TODO: Propagate awaits back through messaging system or resend
|
|
|
|
// commandline_frame messages from excmd_content if you want to avoid init'ing
|
|
|
|
// every time.
|
2017-10-23 02:57:39 +01:00
|
|
|
document.addEventListener("DOMContentLoaded", init)
|
2017-10-23 09:42:50 +01:00
|
|
|
// This second call will fail in the most common case, but makes web-ext reloads effective.
|
|
|
|
init()
|
2017-10-06 04:16:02 +01:00
|
|
|
|
2017-10-22 11:08:43 +01:00
|
|
|
// The CSS in this file should probably go in static/
|
2017-10-05 12:34:18 +01:00
|
|
|
export function show(){
|
2017-10-22 11:08:43 +01:00
|
|
|
// I don't understand how CSS works - but this ensures that the commandline is always at the bottom of the page.
|
|
|
|
cmdline_iframe.setAttribute("style", "position: fixed; bottom: 0; left: 0; z-index: 10000; width: 100%; height: 24px; border: 0; padding: 0; margin: 0;");
|
|
|
|
const height = cmdline_iframe.contentWindow.document.body.offsetHeight + 'px'
|
|
|
|
cmdline_iframe.setAttribute("style", `position: fixed; bottom: 0; left: 0; z-index: 10000; width: 100%; height: ${height}; border: 0; padding: 0; margin: 0;`);
|
2017-10-13 22:10:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export function resize() {
|
|
|
|
const height = cmdline_iframe.contentWindow.document.body.offsetHeight + 'px'
|
2017-10-22 11:08:43 +01:00
|
|
|
cmdline_iframe.setAttribute("style", `position: fixed; bottom: 0; left: 0; z-index: 10000; width: 100%; height: ${height}; border: 0; padding: 0; margin: 0;`);
|
2017-10-05 15:27:45 +01:00
|
|
|
}
|
2017-09-29 18:29:36 +01:00
|
|
|
|
2017-10-05 15:27:45 +01:00
|
|
|
export function hide(){
|
2017-10-28 19:20:31 +08:00
|
|
|
cmdline_iframe.setAttribute("style", `position: fixed; bottom: 0; left: 0; z-index: 10000; width: 100%; height: 0px; border: 0; padding: 0; margin: 0;`);
|
2017-10-04 21:35:52 +01:00
|
|
|
}
|
2017-10-05 12:34:18 +01:00
|
|
|
|
|
|
|
export function focus(){
|
2017-10-05 15:27:45 +01:00
|
|
|
cmdline_iframe.focus()
|
2017-10-05 12:34:18 +01:00
|
|
|
}
|
2017-10-28 19:20:31 +08:00
|
|
|
|
|
|
|
export function blur() {
|
|
|
|
cmdline_iframe.blur()
|
|
|
|
}
|
2017-10-28 13:42:54 +01:00
|
|
|
|
|
|
|
import * as Messaging from './messaging'
|
|
|
|
import * as SELF from './commandline_content'
|
|
|
|
Messaging.addListener('commandline_content', Messaging.attributeCaller(SELF))
|