ソースを参照

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.
Joel Martin 13 年 前
コミット
2cde6e4380
3 ファイル変更25 行追加30 行削除
  1. 16 24
      include/vnc.js
  2. 8 6
      include/webutil.js
  3. 1 0
      vnc_auto.html

+ 16 - 24
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<files.length; i++) {
+        var script = document.createElement('script');
+        script.type = 'text/javascript';
+        script.src = base + files[i];
+        head.appendChild(script);
+    }
+}
 
-(function () {
-    "use strict";
-
-    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);
-}());
+load_scripts(get_INCLUDE_URI(),
+    ["util.js", "webutil.js", "base64.js", "websock.js", "des.js",
+     "input.js", "display.js", "rfb.js", "jsunzip.js"]);
 

+ 8 - 6
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) {

+ 1 - 0
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);