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.
This commit is contained in:
Joel Martin 2012-09-14 16:29:35 -05:00
parent 26945049be
commit 2cde6e4380
3 changed files with 25 additions and 30 deletions

View File

@ -15,29 +15,21 @@
function get_INCLUDE_URI() { function get_INCLUDE_URI() {
return (typeof INCLUDE_URI !== "undefined") ? INCLUDE_URI : "include/"; 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<files.length; i++) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = base + files[i];
head.appendChild(script);
}
}
(function () { load_scripts(get_INCLUDE_URI(),
"use strict"; ["util.js", "webutil.js", "base64.js", "websock.js", "des.js",
"input.js", "display.js", "rfb.js", "jsunzip.js"]);
var extra = "", start, end;
start = "<script src='" + get_INCLUDE_URI();
end = "'><\/script>";
// Uncomment to activate firebug lite
//extra += "<script src='http://getfirebug.com/releases/lite/1.2/" +
// "firebug-lite-compressed.js'><\/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);
}());

View File

@ -37,14 +37,16 @@ if (!window.$D) {
*/ */
// init log level reading the logging HTTP param // init log level reading the logging HTTP param
WebUtil.init_logging = function() { WebUtil.init_logging = function(level) {
Util._log_level = (document.location.href.match( if (typeof level !== "undefined") {
/logging=([A-Za-z0-9\._\-]*)/) || Util._log_level = level;
['', Util._log_level])[1]; } else {
Util._log_level = (document.location.href.match(
/logging=([A-Za-z0-9\._\-]*)/) ||
['', Util._log_level])[1];
}
Util.init_logging(); Util.init_logging();
}; };
WebUtil.init_logging();
WebUtil.dirObj = function (obj, depth, parent) { WebUtil.dirObj = function (obj, depth, parent) {

View File

@ -90,6 +90,7 @@
$D('sendCtrlAltDelButton').style.display = "inline"; $D('sendCtrlAltDelButton').style.display = "inline";
$D('sendCtrlAltDelButton').onclick = sendCtrlAltDel; $D('sendCtrlAltDelButton').onclick = sendCtrlAltDel;
WebUtil.init_logging(WebUtil.getQueryVar('logging', 'warn'));
document.title = unescape(WebUtil.getQueryVar('title', 'noVNC')); document.title = unescape(WebUtil.getQueryVar('title', 'noVNC'));
// By default, use the host and port of server that served this file // By default, use the host and port of server that served this file
host = WebUtil.getQueryVar('host', window.location.hostname); host = WebUtil.getQueryVar('host', window.location.hostname);