aboutsummaryrefslogtreecommitdiff
path: root/third_party/websockify/include
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-10-30 10:52:24 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-10-30 10:52:24 -0700
commitfcb6c33bac763d7a8246674eff33b599c28c1b6e (patch)
tree15fc927f186a0de2476729a1c1e1906478f82e7e /third_party/websockify/include
parent5ba8486b1cd87d31f3d911cbfeb126717e0865b1 (diff)
update websockify to latest trunk
Diffstat (limited to 'third_party/websockify/include')
-rw-r--r--third_party/websockify/include/base64.js99
-rw-r--r--third_party/websockify/include/util.js62
-rw-r--r--third_party/websockify/include/websock.js25
-rw-r--r--third_party/websockify/include/webutil.js88
4 files changed, 180 insertions, 94 deletions
diff --git a/third_party/websockify/include/base64.js b/third_party/websockify/include/base64.js
index e9b3c522..87336127 100644
--- a/third_party/websockify/include/base64.js
+++ b/third_party/websockify/include/base64.js
@@ -1,45 +1,8 @@
-/*
- * Modified from:
- * http://lxr.mozilla.org/mozilla/source/extensions/xml-rpc/src/nsXmlRpcClient.js#956
- */
-
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Mozilla XML-RPC Client component.
- *
- * The Initial Developer of the Original Code is
- * Digital Creations 2, Inc.
- * Portions created by the Initial Developer are Copyright (C) 2000
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Martijn Pieters <mj@digicool.com> (original author)
- * Samuel Sieb <samuel@sieb.net>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// From: http://hg.mozilla.org/mozilla-central/raw-file/ec10630b1a54/js/src/devtools/jint/sunspider/string-base64.js
/*jslint white: false, bitwise: false, plusplus: false */
/*global console */
@@ -47,35 +10,37 @@
var Base64 = {
/* Convert data (an array of integers) to a Base64 string. */
-toBase64Table : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
+toBase64Table : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''),
base64Pad : '=',
encode: function (data) {
"use strict";
- var result = '',
- chrTable = Base64.toBase64Table.split(''),
- pad = Base64.base64Pad,
- length = data.length,
- i;
+ var result = '';
+ var toBase64Table = Base64.toBase64Table;
+ var base64Pad = Base64.base64Pad;
+ var length = data.length;
+ var i;
// Convert every three bytes to 4 ascii characters.
+ /* BEGIN LOOP */
for (i = 0; i < (length - 2); i += 3) {
- result += chrTable[data[i] >> 2];
- result += chrTable[((data[i] & 0x03) << 4) + (data[i+1] >> 4)];
- result += chrTable[((data[i+1] & 0x0f) << 2) + (data[i+2] >> 6)];
- result += chrTable[data[i+2] & 0x3f];
+ result += toBase64Table[data[i] >> 2];
+ result += toBase64Table[((data[i] & 0x03) << 4) + (data[i+1] >> 4)];
+ result += toBase64Table[((data[i+1] & 0x0f) << 2) + (data[i+2] >> 6)];
+ result += toBase64Table[data[i+2] & 0x3f];
}
+ /* END LOOP */
// Convert the remaining 1 or 2 bytes, pad out to 4 characters.
if (length%3) {
i = length - (length%3);
- result += chrTable[data[i] >> 2];
+ result += toBase64Table[data[i] >> 2];
if ((length%3) === 2) {
- result += chrTable[((data[i] & 0x03) << 4) + (data[i+1] >> 4)];
- result += chrTable[(data[i+1] & 0x0f) << 2];
- result += pad;
+ result += toBase64Table[((data[i] & 0x03) << 4) + (data[i+1] >> 4)];
+ result += toBase64Table[(data[i+1] & 0x0f) << 2];
+ result += base64Pad;
} else {
- result += chrTable[(data[i] & 0x03) << 4];
- result += pad + pad;
+ result += toBase64Table[(data[i] & 0x03) << 4];
+ result += base64Pad + base64Pad;
}
}
@@ -97,12 +62,12 @@ toBinaryTable : [
decode: function (data, offset) {
"use strict";
offset = typeof(offset) !== 'undefined' ? offset : 0;
- var binTable = Base64.toBinaryTable,
- pad = Base64.base64Pad,
- result, result_length, idx, i, c, padding,
- leftbits = 0, // number of bits decoded, but yet to be appended
- leftdata = 0, // bits decoded, but yet to be appended
- data_length = data.indexOf('=') - offset;
+ var toBinaryTable = Base64.toBinaryTable;
+ var base64Pad = Base64.base64Pad;
+ var result, result_length, idx, i, c, padding;
+ var leftbits = 0; // number of bits decoded, but yet to be appended
+ var leftdata = 0; // bits decoded, but yet to be appended
+ var data_length = data.indexOf('=') - offset;
if (data_length < 0) { data_length = data.length - offset; }
@@ -111,9 +76,10 @@ decode: function (data, offset) {
result = new Array(result_length);
// Convert one by one.
+ /* BEGIN LOOP */
for (idx = 0, i = offset; i < data.length; i++) {
- c = binTable[data.charCodeAt(i) & 0x7f];
- padding = (data.charAt(i) === pad);
+ c = toBinaryTable[data.charCodeAt(i) & 0x7f];
+ padding = (data.charAt(i) === base64Pad);
// Skip illegal characters and whitespace
if (c === -1) {
console.error("Illegal character code " + data.charCodeAt(i) + " at position " + i);
@@ -134,6 +100,7 @@ decode: function (data, offset) {
leftdata &= (1 << leftbits) - 1;
}
}
+ /* END LOOP */
// If there are any bits left, the base64 string was corrupted
if (leftbits) {
diff --git a/third_party/websockify/include/util.js b/third_party/websockify/include/util.js
index ddc1914c..ab2e1c1e 100644
--- a/third_party/websockify/include/util.js
+++ b/third_party/websockify/include/util.js
@@ -1,7 +1,7 @@
/*
- * noVNC: HTML5 VNC client
- * Copyright (C) 2011 Joel Martin
- * Licensed under LGPL-3 (see LICENSE.txt)
+ * from noVNC: HTML5 VNC client
+ * Copyright (C) 2012 Joel Martin
+ * Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
*/
@@ -57,6 +57,21 @@ if (!Array.prototype.map)
};
}
+//
+// requestAnimationFrame shim with setTimeout fallback
+//
+
+window.requestAnimFrame = (function(){
+ return window.requestAnimationFrame ||
+ window.webkitRequestAnimationFrame ||
+ window.mozRequestAnimationFrame ||
+ window.oRequestAnimationFrame ||
+ window.msRequestAnimationFrame ||
+ function(callback){
+ window.setTimeout(callback, 1000 / 60);
+ };
+})();
+
/*
* ------------------------------------------------------
* Namespaced in Util
@@ -131,6 +146,8 @@ Util.conf_default = function(cfg, api, defaults, v, mode, type, defval, desc) {
}
} else if (type in {'integer':1, 'int':1}) {
val = parseInt(val, 10);
+ } else if (type === 'str') {
+ val = String(val);
} else if (type === 'func') {
if (!val) {
val = function () {};
@@ -190,6 +207,45 @@ Util.conf_defaults = function(cfg, api, defaults, arr) {
* Cross-browser routines
*/
+
+// Dynamically load scripts without using document.write()
+// Reference: http://unixpapa.com/js/dyna.html
+//
+// Handles the case where load_scripts is invoked from a script that
+// itself is loaded via load_scripts. Once all scripts are loaded the
+// window.onscriptsloaded handler is called (if set).
+Util.get_include_uri = function() {
+ return (typeof INCLUDE_URI !== "undefined") ? INCLUDE_URI : "include/";
+}
+Util._pending_scripts = [];
+Util.load_scripts = function(files) {
+ var head = document.getElementsByTagName('head')[0],
+ ps = Util._pending_scripts;
+ for (var f=0; f<files.length; f++) {
+ var script = document.createElement('script');
+ script.type = 'text/javascript';
+ script.src = Util.get_include_uri() + files[f];
+ //console.log("loading script: " + Util.get_include_uri() + files[f]);
+ head.appendChild(script);
+ ps.push(script);
+ script.onload = script.onreadystatechange = function (e) {
+ if (!this.readyState ||
+ this.readyState == 'complete' ||
+ this.readyState == 'loaded') {
+ this.onload = this.onreadystatechange = null;
+ if (ps.indexOf(this) >= 0) {
+ //console.log("loaded script: " + this.src);
+ ps.splice(ps.indexOf(this), 1);
+ }
+ // Call window.onscriptsload after last script loads
+ if (ps.length === 0 && window.onscriptsload) {
+ window.onscriptsload();
+ }
+ }
+ }
+ }
+}
+
// Get DOM element position on page
Util.getPosition = function (obj) {
var x = 0, y = 0;
diff --git a/third_party/websockify/include/websock.js b/third_party/websockify/include/websock.js
index ccb7d4c1..7d12644e 100644
--- a/third_party/websockify/include/websock.js
+++ b/third_party/websockify/include/websock.js
@@ -1,7 +1,7 @@
/*
* Websock: high-performance binary WebSockets
* Copyright (C) 2012 Joel Martin
- * Licensed under LGPL-3 (see LICENSE.txt)
+ * Licensed under MPL 2.0 (see LICENSE.txt)
*
* Websock is similar to the standard WebSocket object but Websock
* enables communication with raw TCP sockets (i.e. the binary stream)
@@ -35,23 +35,14 @@ if (window.WebSocket && !window.WEB_SOCKET_FORCE_FLASH) {
Websock_native = false;
(function () {
- function get_INCLUDE_URI() {
- return (typeof INCLUDE_URI !== "undefined") ?
- INCLUDE_URI : "include/";
- }
-
- var start = "<script src='" + get_INCLUDE_URI(),
- end = "'><\/script>", extra = "";
-
- window.WEB_SOCKET_SWF_LOCATION = get_INCLUDE_URI() +
+ window.WEB_SOCKET_SWF_LOCATION = Util.get_include_uri() +
"web-socket-js/WebSocketMain.swf";
if (Util.Engine.trident) {
Util.Debug("Forcing uncached load of WebSocketMain.swf");
window.WEB_SOCKET_SWF_LOCATION += "?" + Math.random();
}
- extra += start + "web-socket-js/swfobject.js" + end;
- extra += start + "web-socket-js/web_socket.js" + end;
- document.write(extra);
+ Util.load_scripts(["web-socket-js/swfobject.js",
+ "web-socket-js/web_socket.js"]);
}());
}
@@ -181,7 +172,10 @@ function decode_message(data) {
//Util.Debug(">> decode_message: " + data);
if (mode === 'binary') {
// push arraybuffer values onto the end
- rQ.push.apply(rQ, (new Uint8Array(data)));
+ var u8 = new Uint8Array(data);
+ for (var i = 0; i < u8.length; i++) {
+ rQ.push(u8[i]);
+ }
} else {
// base64 decode and concat to the end
rQ = rQ.concat(Base64.decode(data, 0));
@@ -380,8 +374,9 @@ function close() {
// Override internal functions for testing
// Takes a send function, returns reference to recv function
-function testMode(override_send) {
+function testMode(override_send, data_mode) {
test_mode = true;
+ mode = data_mode;
api.send = override_send;
api.close = function () {};
return recv_message;
diff --git a/third_party/websockify/include/webutil.js b/third_party/websockify/include/webutil.js
index 2966cd79..2c82c73c 100644
--- a/third_party/websockify/include/webutil.js
+++ b/third_party/websockify/include/webutil.js
@@ -1,7 +1,7 @@
/*
* from noVNC: HTML5 VNC client
- * Copyright (C) 2010 Joel Martin
- * Licensed under LGPL-3 (see LICENSE.txt)
+ * Copyright (C) 2012 Joel Martin
+ * Licensed under MPL 2.0 (see LICENSE.txt)
*
* See README.md for usage and integration instructions.
*/
@@ -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) {
@@ -75,9 +77,14 @@ WebUtil.dirObj = function (obj, depth, parent) {
// Read a query string variable
WebUtil.getQueryVar = function(name, defVal) {
- var re = new RegExp('[?][^#]*' + name + '=([^&#]*)');
+ var re = new RegExp('[?][^#]*' + name + '=([^&#]*)'),
+ match = document.location.href.match(re);
if (typeof defVal === 'undefined') { defVal = null; }
- return (document.location.href.match(re) || ['',defVal])[1];
+ if (match) {
+ return decodeURIComponent(match[1]);
+ } else {
+ return defVal;
+ }
};
@@ -114,6 +121,67 @@ WebUtil.eraseCookie = function(name) {
};
/*
+ * Setting handling.
+ */
+
+WebUtil.initSettings = function(callback) {
+ var callbackArgs = Array.prototype.slice.call(arguments, 1);
+ if (window.chrome && window.chrome.storage) {
+ window.chrome.storage.sync.get(function (cfg) {
+ WebUtil.settings = cfg;
+ console.log(WebUtil.settings);
+ if (callback) {
+ callback.apply(this, callbackArgs);
+ }
+ });
+ } else {
+ // No-op
+ if (callback) {
+ callback.apply(this, callbackArgs);
+ }
+ }
+};
+
+// No days means only for this browser session
+WebUtil.writeSetting = function(name, value) {
+ if (window.chrome && window.chrome.storage) {
+ //console.log("writeSetting:", name, value);
+ if (WebUtil.settings[name] !== value) {
+ WebUtil.settings[name] = value;
+ window.chrome.storage.sync.set(WebUtil.settings);
+ }
+ } else {
+ localStorage.setItem(name, value);
+ }
+};
+
+WebUtil.readSetting = function(name, defaultValue) {
+ var value;
+ if (window.chrome && window.chrome.storage) {
+ value = WebUtil.settings[name];
+ } else {
+ value = localStorage.getItem(name);
+ }
+ if (typeof value === "undefined") {
+ value = null;
+ }
+ if (value === null && typeof defaultValue !== undefined) {
+ return defaultValue;
+ } else {
+ return value;
+ }
+};
+
+WebUtil.eraseSetting = function(name) {
+ if (window.chrome && window.chrome.storage) {
+ window.chrome.storage.sync.remove(name);
+ delete WebUtil.settings[name];
+ } else {
+ localStorage.removeItem(name);
+ }
+};
+
+/*
* Alternate stylesheet selection
*/
WebUtil.getStylesheets = function() { var i, links, sheets = [];