From 2cde6e4380db727ce81aae9b0d718a1bcafd3233 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Fri, 14 Sep 2012 16:29:35 -0500 Subject: [PATCH] include/vnc.js: dynamic load without document.write. Instead of using document.write to load scripts, use createElement to create and append script tags. document.write is problematic in a lot of situation and in particular is not allowed in a Chrome extension/packaged app. Also, in webutil.js, instead of calling init_logging during parsing of include/webutil.js, rely on the caller to do this. The problem is that calling init_logging on parse tries to call Util logging functions and the new model of dynamic load may not having Util loaded by the time webutil is parsed. --- include/vnc.js | 40 ++++++++++++++++------------------------ include/webutil.js | 14 ++++++++------ vnc_auto.html | 1 + 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/include/vnc.js b/include/vnc.js index 7679d845..435fdc47 100644 --- a/include/vnc.js +++ b/include/vnc.js @@ -15,29 +15,21 @@ function get_INCLUDE_URI() { return (typeof INCLUDE_URI !== "undefined") ? INCLUDE_URI : "include/"; } +/* + * Dynamically load a script without using document.write() + * Reference: http://unixpapa.com/js/dyna.html + */ +function load_scripts(base, files) { + var head = document.getElementsByTagName('head')[0]; + for (var i=0; i<\/script>"; - - extra += start + "util.js" + end; - extra += start + "webutil.js" + end; - extra += start + "base64.js" + end; - extra += start + "websock.js" + end; - extra += start + "des.js" + end; - extra += start + "input.js" + end; - extra += start + "display.js" + end; - extra += start + "rfb.js" + end; - extra += start + "jsunzip.js" + end; - - document.write(extra); -}()); +load_scripts(get_INCLUDE_URI(), + ["util.js", "webutil.js", "base64.js", "websock.js", "des.js", + "input.js", "display.js", "rfb.js", "jsunzip.js"]); diff --git a/include/webutil.js b/include/webutil.js index 70a0e8ff..c12805f1 100644 --- a/include/webutil.js +++ b/include/webutil.js @@ -37,14 +37,16 @@ if (!window.$D) { */ // init log level reading the logging HTTP param -WebUtil.init_logging = function() { - Util._log_level = (document.location.href.match( - /logging=([A-Za-z0-9\._\-]*)/) || - ['', Util._log_level])[1]; - +WebUtil.init_logging = function(level) { + if (typeof level !== "undefined") { + Util._log_level = level; + } else { + Util._log_level = (document.location.href.match( + /logging=([A-Za-z0-9\._\-]*)/) || + ['', Util._log_level])[1]; + } Util.init_logging(); }; -WebUtil.init_logging(); WebUtil.dirObj = function (obj, depth, parent) { diff --git a/vnc_auto.html b/vnc_auto.html index 2b60d779..f5d28257 100644 --- a/vnc_auto.html +++ b/vnc_auto.html @@ -90,6 +90,7 @@ $D('sendCtrlAltDelButton').style.display = "inline"; $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel; + WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn')); document.title = unescape(WebUtil.getQueryVar('title', 'noVNC')); // By default, use the host and port of server that served this file host = WebUtil.getQueryVar('host', window.location.hostname);