mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 15:15:22 +00:00
Adde novnc js
This commit is contained in:
parent
9b02c64ff4
commit
da6a2d7e29
55 changed files with 19437 additions and 0 deletions
BIN
static/js/novnc/Orbitron700.ttf
Normal file
BIN
static/js/novnc/Orbitron700.ttf
Normal file
Binary file not shown.
BIN
static/js/novnc/Orbitron700.woff
Normal file
BIN
static/js/novnc/Orbitron700.woff
Normal file
Binary file not shown.
405
static/js/novnc/base.css
Normal file
405
static/js/novnc/base.css
Normal file
|
@ -0,0 +1,405 @@
|
||||||
|
/*
|
||||||
|
* noVNC base CSS
|
||||||
|
* Copyright (C) 2012 Joel Martin
|
||||||
|
* noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
|
||||||
|
* This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
|
||||||
|
*/
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin:0;
|
||||||
|
padding:0;
|
||||||
|
font-family: Helvetica;
|
||||||
|
/*Background image with light grey curve.*/
|
||||||
|
background-color:#494949;
|
||||||
|
background-repeat:no-repeat;
|
||||||
|
background-position:right bottom;
|
||||||
|
height:100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
height:100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_controls ul {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0px;
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
#noVNC_controls li {
|
||||||
|
padding-bottom:8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_host {
|
||||||
|
width:150px;
|
||||||
|
}
|
||||||
|
#noVNC_port {
|
||||||
|
width: 80px;
|
||||||
|
}
|
||||||
|
#noVNC_password {
|
||||||
|
width: 150px;
|
||||||
|
}
|
||||||
|
#noVNC_encrypt {
|
||||||
|
}
|
||||||
|
#noVNC_connectTimeout {
|
||||||
|
width: 30px;
|
||||||
|
}
|
||||||
|
#noVNC_path {
|
||||||
|
width: 100px;
|
||||||
|
}
|
||||||
|
#noVNC_connect_button {
|
||||||
|
width: 110px;
|
||||||
|
float:right;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#noVNC_view_drag_button {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
#sendCtrlAltDelButton {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
#noVNC_mobile_buttons {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.noVNC-buttons-left {
|
||||||
|
float: left;
|
||||||
|
padding-left:10px;
|
||||||
|
padding-top:4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.noVNC-buttons-right {
|
||||||
|
float:right;
|
||||||
|
right: 0px;
|
||||||
|
padding-right:10px;
|
||||||
|
padding-top:4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_status_bar {
|
||||||
|
margin-top: 0px;
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_status_bar div {
|
||||||
|
font-size: 12px;
|
||||||
|
padding-top: 4px;
|
||||||
|
width:100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_status {
|
||||||
|
height:20px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
#noVNC_settings_menu {
|
||||||
|
margin: 3px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
#noVNC_settings_menu ul {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0px;
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_apply {
|
||||||
|
float:right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.noVNC_status_normal {
|
||||||
|
background: #eee;
|
||||||
|
}
|
||||||
|
.noVNC_status_error {
|
||||||
|
background: #f44;
|
||||||
|
}
|
||||||
|
.noVNC_status_warn {
|
||||||
|
background: #ff4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do not set width/height for VNC_screen or VNC_canvas or incorrect
|
||||||
|
* scaling will occur. Canvas resizes to remote VNC settings */
|
||||||
|
#noVNC_screen_pad {
|
||||||
|
margin: 0px;
|
||||||
|
padding: 0px;
|
||||||
|
height: 44px;
|
||||||
|
}
|
||||||
|
#noVNC_screen {
|
||||||
|
text-align: center;
|
||||||
|
display: table;
|
||||||
|
width:100%;
|
||||||
|
height:100%;
|
||||||
|
background-color:#313131;
|
||||||
|
border-bottom-right-radius: 800px 600px;
|
||||||
|
/*border-top-left-radius: 800px 600px;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_container, #noVNC_canvas {
|
||||||
|
margin: 0px;
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_canvas {
|
||||||
|
left: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#VNC_clipboard_clear_button {
|
||||||
|
float:right;
|
||||||
|
}
|
||||||
|
#VNC_clipboard_text {
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_clipboard_clear_button {
|
||||||
|
float:right;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Bubble contents divs*/
|
||||||
|
#noVNC_settings {
|
||||||
|
display:none;
|
||||||
|
margin-top:77px;
|
||||||
|
right:20px;
|
||||||
|
position:fixed;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_controls {
|
||||||
|
display:none;
|
||||||
|
margin-top:77px;
|
||||||
|
right:12px;
|
||||||
|
position:fixed;
|
||||||
|
}
|
||||||
|
#noVNC_controls.top:after {
|
||||||
|
right:15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_description {
|
||||||
|
display:none;
|
||||||
|
position:fixed;
|
||||||
|
|
||||||
|
margin-top:77px;
|
||||||
|
right:20px;
|
||||||
|
left:20px;
|
||||||
|
padding:15px;
|
||||||
|
color:#000;
|
||||||
|
background:#eee; /* default background for browsers without gradient support */
|
||||||
|
|
||||||
|
border:2px solid #E0E0E0;
|
||||||
|
-webkit-border-radius:10px;
|
||||||
|
-moz-border-radius:10px;
|
||||||
|
border-radius:10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_clipboard {
|
||||||
|
display:none;
|
||||||
|
margin-top:77px;
|
||||||
|
right:30px;
|
||||||
|
position:fixed;
|
||||||
|
}
|
||||||
|
#noVNC_clipboard.top:after {
|
||||||
|
right:85px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#keyboardinput {
|
||||||
|
width:1px;
|
||||||
|
height:1px;
|
||||||
|
background-color:#fff;
|
||||||
|
color:#fff;
|
||||||
|
border:0;
|
||||||
|
position: relative;
|
||||||
|
left: -40px;
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.noVNC_status_warn {
|
||||||
|
background-color:yellow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Advanced Styling
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Control bar */
|
||||||
|
#noVNC-control-bar {
|
||||||
|
position:fixed;
|
||||||
|
background: #b2bdcd; /* Old browsers */
|
||||||
|
background: -moz-linear-gradient(top, #b2bdcd 0%, #899cb3 49%, #7e93af 51%, #6e84a3 100%); /* FF3.6+ */
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b2bdcd), color-stop(49%,#899cb3), color-stop(51%,#7e93af), color-stop(100%,#6e84a3)); /* Chrome,Safari4+ */
|
||||||
|
background: -webkit-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Chrome10+,Safari5.1+ */
|
||||||
|
background: -o-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Opera11.10+ */
|
||||||
|
background: -ms-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* IE10+ */
|
||||||
|
background: linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* W3C */
|
||||||
|
|
||||||
|
display:block;
|
||||||
|
height:44px;
|
||||||
|
left:0;
|
||||||
|
top:0;
|
||||||
|
width:100%;
|
||||||
|
z-index:200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.noVNC_status_button {
|
||||||
|
padding: 4px 4px;
|
||||||
|
vertical-align: middle;
|
||||||
|
border:1px solid #869dbc;
|
||||||
|
-webkit-border-radius: 6px;
|
||||||
|
-moz-border-radius: 6px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #b2bdcd; /* Old browsers */
|
||||||
|
background: -moz-linear-gradient(top, #b2bdcd 0%, #899cb3 49%, #7e93af 51%, #6e84a3 100%); /* FF3.6+ */
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b2bdcd), color-stop(49%,#899cb3), color-stop(51%,#7e93af), color-stop(100%,#6e84a3)); /* Chrome,Safari4+ */
|
||||||
|
background: -webkit-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Chrome10+,Safari5.1+ */
|
||||||
|
background: -o-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* Opera11.10+ */
|
||||||
|
background: -ms-linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* IE10+ */
|
||||||
|
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b2bdcd', endColorstr='#6e84a3',GradientType=0 ); /* IE6-9 */
|
||||||
|
background: linear-gradient(top, #b2bdcd 0%,#899cb3 49%,#7e93af 51%,#6e84a3 100%); /* W3C */
|
||||||
|
/*box-shadow:inset 0.4px 0.4px 0.4px #000000;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
.noVNC_status_button_selected {
|
||||||
|
padding: 4px 4px;
|
||||||
|
vertical-align: middle;
|
||||||
|
border:1px solid #4366a9;
|
||||||
|
-webkit-border-radius: 6px;
|
||||||
|
-moz-border-radius: 6px;
|
||||||
|
background: #779ced; /* Old browsers */
|
||||||
|
background: -moz-linear-gradient(top, #779ced 0%, #3970e0 49%, #2160dd 51%, #2463df 100%); /* FF3.6+ */
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#779ced), color-stop(49%,#3970e0), color-stop(51%,#2160dd), color-stop(100%,#2463df)); /* Chrome,Safari4+ */
|
||||||
|
background: -webkit-linear-gradient(top, #779ced 0%,#3970e0 49%,#2160dd 51%,#2463df 100%); /* Chrome10+,Safari5.1+ */
|
||||||
|
background: -o-linear-gradient(top, #779ced 0%,#3970e0 49%,#2160dd 51%,#2463df 100%); /* Opera11.10+ */
|
||||||
|
background: -ms-linear-gradient(top, #779ced 0%,#3970e0 49%,#2160dd 51%,#2463df 100%); /* IE10+ */
|
||||||
|
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#779ced', endColorstr='#2463df',GradientType=0 ); /* IE6-9 */
|
||||||
|
background: linear-gradient(top, #779ced 0%,#3970e0 49%,#2160dd 51%,#2463df 100%); /* W3C */
|
||||||
|
/*box-shadow:inset 0.4px 0.4px 0.4px #000000;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*Settings Bubble*/
|
||||||
|
.triangle-right {
|
||||||
|
position:relative;
|
||||||
|
padding:15px;
|
||||||
|
margin:1em 0 3em;
|
||||||
|
color:#fff;
|
||||||
|
background:#fff; /* default background for browsers without gradient support */
|
||||||
|
/* css3 */
|
||||||
|
/*background:-webkit-gradient(linear, 0 0, 0 100%, from(#2e88c4), to(#075698));
|
||||||
|
background:-moz-linear-gradient(#2e88c4, #075698);
|
||||||
|
background:-o-linear-gradient(#2e88c4, #075698);
|
||||||
|
background:linear-gradient(#2e88c4, #075698);*/
|
||||||
|
-webkit-border-radius:10px;
|
||||||
|
-moz-border-radius:10px;
|
||||||
|
border-radius:10px;
|
||||||
|
color:#000;
|
||||||
|
border:2px solid #E0E0E0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.triangle-right.top:after {
|
||||||
|
border-color: transparent #E0E0E0;
|
||||||
|
border-width: 20px 20px 0 0;
|
||||||
|
bottom: auto;
|
||||||
|
left: auto;
|
||||||
|
right: 50px;
|
||||||
|
top: -20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.triangle-right:after {
|
||||||
|
content:"";
|
||||||
|
position:absolute;
|
||||||
|
bottom:-20px; /* value = - border-top-width - border-bottom-width */
|
||||||
|
left:50px; /* controls horizontal position */
|
||||||
|
border-width:20px 0 0 20px; /* vary these values to change the angle of the vertex */
|
||||||
|
border-style:solid;
|
||||||
|
border-color:#E0E0E0 transparent;
|
||||||
|
/* reduce the damage in FF3.0 */
|
||||||
|
display:block;
|
||||||
|
width:0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.triangle-right.top:after {
|
||||||
|
top:-40px; /* value = - border-top-width - border-bottom-width */
|
||||||
|
right:50px; /* controls horizontal position */
|
||||||
|
bottom:auto;
|
||||||
|
left:auto;
|
||||||
|
border-width:40px 40px 0 0; /* vary these values to change the angle of the vertex */
|
||||||
|
border-color:transparent #E0E0E0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*Default noVNC logo.*/
|
||||||
|
/* From: http://fonts.googleapis.com/css?family=Orbitron:700 */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Orbitron';
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 700;
|
||||||
|
src: local('?'), url('Orbitron700.woff') format('woff'),
|
||||||
|
url('Orbitron700.ttf') format('truetype');
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_logo {
|
||||||
|
margin-top: 170px;
|
||||||
|
margin-left: 10px;
|
||||||
|
color:yellow;
|
||||||
|
text-align:left;
|
||||||
|
font-family: 'Orbitron', 'OrbitronTTF', sans-serif;
|
||||||
|
line-height:90%;
|
||||||
|
text-shadow:
|
||||||
|
5px 5px 0 #000,
|
||||||
|
-1px -1px 0 #000,
|
||||||
|
1px -1px 0 #000,
|
||||||
|
-1px 1px 0 #000,
|
||||||
|
1px 1px 0 #000;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#noVNC_logo span{
|
||||||
|
color:green;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------
|
||||||
|
* Media sizing
|
||||||
|
* ----------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
.noVNC_status_button {
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_clipboard_text {
|
||||||
|
width: 500px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC_logo {
|
||||||
|
font-size: 180px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 481px) and (max-width: 640px) {
|
||||||
|
.noVNC_status_button {
|
||||||
|
font-size: 10px;
|
||||||
|
}
|
||||||
|
#noVNC_clipboard_text {
|
||||||
|
width: 410px;
|
||||||
|
}
|
||||||
|
#noVNC_logo {
|
||||||
|
font-size: 150px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (min-width: 321px) and (max-width: 480px) {
|
||||||
|
.noVNC_status_button {
|
||||||
|
font-size: 10px;
|
||||||
|
}
|
||||||
|
#noVNC_clipboard_text {
|
||||||
|
width: 250px;
|
||||||
|
}
|
||||||
|
#noVNC_logo {
|
||||||
|
font-size: 110px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 320px) {
|
||||||
|
.noVNC_status_button {
|
||||||
|
font-size: 9px;
|
||||||
|
}
|
||||||
|
#noVNC_clipboard_text {
|
||||||
|
width: 220px;
|
||||||
|
}
|
||||||
|
#noVNC_logo {
|
||||||
|
font-size: 90px;
|
||||||
|
}
|
||||||
|
}
|
115
static/js/novnc/base64.js
Normal file
115
static/js/novnc/base64.js
Normal file
|
@ -0,0 +1,115 @@
|
||||||
|
/* 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 */
|
||||||
|
|
||||||
|
var Base64 = {
|
||||||
|
|
||||||
|
/* Convert data (an array of integers) to a Base64 string. */
|
||||||
|
toBase64Table : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split(''),
|
||||||
|
base64Pad : '=',
|
||||||
|
|
||||||
|
encode: function (data) {
|
||||||
|
"use strict";
|
||||||
|
var result = '';
|
||||||
|
var toBase64Table = Base64.toBase64Table;
|
||||||
|
var length = data.length
|
||||||
|
var lengthpad = (length%3);
|
||||||
|
var i = 0, j = 0;
|
||||||
|
// Convert every three bytes to 4 ascii characters.
|
||||||
|
/* BEGIN LOOP */
|
||||||
|
for (i = 0; i < (length - 2); i += 3) {
|
||||||
|
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 (lengthpad === 2) {
|
||||||
|
j = length - lengthpad;
|
||||||
|
result += toBase64Table[data[j] >> 2];
|
||||||
|
result += toBase64Table[((data[j] & 0x03) << 4) + (data[j+1] >> 4)];
|
||||||
|
result += toBase64Table[(data[j+1] & 0x0f) << 2];
|
||||||
|
result += toBase64Table[64];
|
||||||
|
} else if (lengthpad === 1) {
|
||||||
|
j = length - lengthpad;
|
||||||
|
result += toBase64Table[data[j] >> 2];
|
||||||
|
result += toBase64Table[(data[j] & 0x03) << 4];
|
||||||
|
result += toBase64Table[64];
|
||||||
|
result += toBase64Table[64];
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Convert Base64 data to a string */
|
||||||
|
toBinaryTable : [
|
||||||
|
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
|
||||||
|
-1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,62, -1,-1,-1,63,
|
||||||
|
52,53,54,55, 56,57,58,59, 60,61,-1,-1, -1, 0,-1,-1,
|
||||||
|
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11,12,13,14,
|
||||||
|
15,16,17,18, 19,20,21,22, 23,24,25,-1, -1,-1,-1,-1,
|
||||||
|
-1,26,27,28, 29,30,31,32, 33,34,35,36, 37,38,39,40,
|
||||||
|
41,42,43,44, 45,46,47,48, 49,50,51,-1, -1,-1,-1,-1
|
||||||
|
],
|
||||||
|
|
||||||
|
decode: function (data, offset) {
|
||||||
|
"use strict";
|
||||||
|
offset = typeof(offset) !== 'undefined' ? offset : 0;
|
||||||
|
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; }
|
||||||
|
|
||||||
|
/* Every four characters is 3 resulting numbers */
|
||||||
|
result_length = (data_length >> 2) * 3 + Math.floor((data_length%4)/1.5);
|
||||||
|
result = new Array(result_length);
|
||||||
|
|
||||||
|
// Convert one by one.
|
||||||
|
/* BEGIN LOOP */
|
||||||
|
for (idx = 0, i = offset; i < data.length; i++) {
|
||||||
|
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);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect data into leftdata, update bitcount
|
||||||
|
leftdata = (leftdata << 6) | c;
|
||||||
|
leftbits += 6;
|
||||||
|
|
||||||
|
// If we have 8 or more bits, append 8 bits to the result
|
||||||
|
if (leftbits >= 8) {
|
||||||
|
leftbits -= 8;
|
||||||
|
// Append if not padding.
|
||||||
|
if (!padding) {
|
||||||
|
result[idx++] = (leftdata >> leftbits) & 0xff;
|
||||||
|
}
|
||||||
|
leftdata &= (1 << leftbits) - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* END LOOP */
|
||||||
|
|
||||||
|
// If there are any bits left, the base64 string was corrupted
|
||||||
|
if (leftbits) {
|
||||||
|
throw {name: 'Base64-Error',
|
||||||
|
message: 'Corrupted base64 string'};
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}; /* End of Base64 namespace */
|
52
static/js/novnc/black.css
Normal file
52
static/js/novnc/black.css
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* noVNC black CSS
|
||||||
|
* Copyright (C) 2012 Joel Martin
|
||||||
|
* noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
|
||||||
|
* This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#keyboardinput {
|
||||||
|
background-color:#000;
|
||||||
|
}
|
||||||
|
|
||||||
|
#noVNC-control-bar {
|
||||||
|
background: #4c4c4c; /* Old browsers */
|
||||||
|
background: -moz-linear-gradient(top, #4c4c4c 0%, #2c2c2c 50%, #000000 51%, #131313 100%); /* FF3.6+ */
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4c4c4c), color-stop(50%,#2c2c2c), color-stop(51%,#000000), color-stop(100%,#131313)); /* Chrome,Safari4+ */
|
||||||
|
background: -webkit-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Chrome10+,Safari5.1+ */
|
||||||
|
background: -o-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Opera11.10+ */
|
||||||
|
background: -ms-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* IE10+ */
|
||||||
|
background: linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* W3C */
|
||||||
|
}
|
||||||
|
|
||||||
|
.triangle-right {
|
||||||
|
border:2px solid #fff;
|
||||||
|
background:#000;
|
||||||
|
color:#fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.noVNC_status_button {
|
||||||
|
font-size: 12px;
|
||||||
|
vertical-align: middle;
|
||||||
|
border:1px solid #4c4c4c;
|
||||||
|
|
||||||
|
background: #4c4c4c; /* Old browsers */
|
||||||
|
background: -moz-linear-gradient(top, #4c4c4c 0%, #2c2c2c 50%, #000000 51%, #131313 100%); /* FF3.6+ */
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4c4c4c), color-stop(50%,#2c2c2c), color-stop(51%,#000000), color-stop(100%,#131313)); /* Chrome,Safari4+ */
|
||||||
|
background: -webkit-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Chrome10+,Safari5.1+ */
|
||||||
|
background: -o-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* Opera11.10+ */
|
||||||
|
background: -ms-linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* IE10+ */
|
||||||
|
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#4c4c4c', endColorstr='#131313',GradientType=0 ); /* IE6-9 */
|
||||||
|
background: linear-gradient(top, #4c4c4c 0%,#2c2c2c 50%,#000000 51%,#131313 100%); /* W3C */
|
||||||
|
}
|
||||||
|
|
||||||
|
.noVNC_status_button_selected {
|
||||||
|
background: #9dd53a; /* Old browsers */
|
||||||
|
background: -moz-linear-gradient(top, #9dd53a 0%, #a1d54f 50%, #80c217 51%, #7cbc0a 100%); /* FF3.6+ */
|
||||||
|
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#9dd53a), color-stop(50%,#a1d54f), color-stop(51%,#80c217), color-stop(100%,#7cbc0a)); /* Chrome,Safari4+ */
|
||||||
|
background: -webkit-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* Chrome10+,Safari5.1+ */
|
||||||
|
background: -o-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* Opera11.10+ */
|
||||||
|
background: -ms-linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* IE10+ */
|
||||||
|
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#9dd53a', endColorstr='#7cbc0a',GradientType=0 ); /* IE6-9 */
|
||||||
|
background: linear-gradient(top, #9dd53a 0%,#a1d54f 50%,#80c217 51%,#7cbc0a 100%); /* W3C */
|
||||||
|
}
|
33
static/js/novnc/blue.css
Normal file
33
static/js/novnc/blue.css
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* noVNC blue CSS
|
||||||
|
* Copyright (C) 2012 Joel Martin
|
||||||
|
* noVNC is licensed under the MPL 2.0 (see LICENSE.txt)
|
||||||
|
* This file is licensed under the 2-Clause BSD license (see LICENSE.txt).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#noVNC-control-bar {
|
||||||
|
background-color:#04073d;
|
||||||
|
background-image: -webkit-gradient(
|
||||||
|
linear,
|
||||||
|
left bottom,
|
||||||
|
left top,
|
||||||
|
color-stop(0.54, rgb(10,15,79)),
|
||||||
|
color-stop(0.5, rgb(4,7,61))
|
||||||
|
);
|
||||||
|
background-image: -moz-linear-gradient(
|
||||||
|
center bottom,
|
||||||
|
rgb(10,15,79) 54%,
|
||||||
|
rgb(4,7,61) 50%
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
.triangle-right {
|
||||||
|
border:2px solid #fff;
|
||||||
|
background:#04073d;
|
||||||
|
color:#fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
#keyboardinput {
|
||||||
|
background-color:#04073d;
|
||||||
|
}
|
||||||
|
|
321
static/js/novnc/chrome-app/tcp-client.js
Normal file
321
static/js/novnc/chrome-app/tcp-client.js
Normal file
|
@ -0,0 +1,321 @@
|
||||||
|
/*
|
||||||
|
Copyright 2012 Google Inc.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
Author: Boris Smus (smus@chromium.org)
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function(exports) {
|
||||||
|
|
||||||
|
// Define some local variables here.
|
||||||
|
var socket = chrome.socket || chrome.experimental.socket;
|
||||||
|
var dns = chrome.experimental.dns;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of the client
|
||||||
|
*
|
||||||
|
* @param {String} host The remote host to connect to
|
||||||
|
* @param {Number} port The port to connect to at the remote host
|
||||||
|
*/
|
||||||
|
function TcpClient(host, port, pollInterval) {
|
||||||
|
this.host = host;
|
||||||
|
this.port = port;
|
||||||
|
this.pollInterval = pollInterval || 15;
|
||||||
|
|
||||||
|
// Callback functions.
|
||||||
|
this.callbacks = {
|
||||||
|
connect: null, // Called when socket is connected.
|
||||||
|
disconnect: null, // Called when socket is disconnected.
|
||||||
|
recvBuffer: null, // Called (as ArrayBuffer) when client receives data from server.
|
||||||
|
recvString: null, // Called (as string) when client receives data from server.
|
||||||
|
sent: null // Called when client sends data to server.
|
||||||
|
};
|
||||||
|
|
||||||
|
// Socket.
|
||||||
|
this.socketId = null;
|
||||||
|
this.isConnected = false;
|
||||||
|
|
||||||
|
log('initialized tcp client');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connects to the TCP socket, and creates an open socket.
|
||||||
|
*
|
||||||
|
* @see http://developer.chrome.com/trunk/apps/socket.html#method-create
|
||||||
|
* @param {Function} callback The function to call on connection
|
||||||
|
*/
|
||||||
|
TcpClient.prototype.connect = function(callback) {
|
||||||
|
// First resolve the hostname to an IP.
|
||||||
|
dns.resolve(this.host, function(result) {
|
||||||
|
this.addr = result.address;
|
||||||
|
socket.create('tcp', {}, this._onCreate.bind(this));
|
||||||
|
|
||||||
|
// Register connect callback.
|
||||||
|
this.callbacks.connect = callback;
|
||||||
|
}.bind(this));
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an arraybuffer/view down the wire to the remote side
|
||||||
|
*
|
||||||
|
* @see http://developer.chrome.com/trunk/apps/socket.html#method-write
|
||||||
|
* @param {String} msg The arraybuffer/view to send
|
||||||
|
* @param {Function} callback The function to call when the message has sent
|
||||||
|
*/
|
||||||
|
TcpClient.prototype.sendBuffer = function(buf, callback) {
|
||||||
|
if (buf.buffer) {
|
||||||
|
buf = buf.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Debug
|
||||||
|
var bytes = [], u8 = new Uint8Array(buf);
|
||||||
|
for (var i = 0; i < u8.length; i++) {
|
||||||
|
bytes.push(u8[i]);
|
||||||
|
}
|
||||||
|
log("sending bytes: " + (bytes.join(',')));
|
||||||
|
*/
|
||||||
|
|
||||||
|
socket.write(this.socketId, buf, this._onWriteComplete.bind(this));
|
||||||
|
|
||||||
|
// Register sent callback.
|
||||||
|
this.callbacks.sent = callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a string down the wire to the remote side
|
||||||
|
*
|
||||||
|
* @see http://developer.chrome.com/trunk/apps/socket.html#method-write
|
||||||
|
* @param {String} msg The string to send
|
||||||
|
* @param {Function} callback The function to call when the message has sent
|
||||||
|
*/
|
||||||
|
TcpClient.prototype.sendString = function(msg, callback) {
|
||||||
|
/*
|
||||||
|
// Debug
|
||||||
|
log("sending string: " + msg);
|
||||||
|
*/
|
||||||
|
|
||||||
|
this._stringToArrayBuffer(msg, function(arrayBuffer) {
|
||||||
|
socket.write(this.socketId, arrayBuffer, this._onWriteComplete.bind(this));
|
||||||
|
}.bind(this));
|
||||||
|
|
||||||
|
// Register sent callback.
|
||||||
|
this.callbacks.sent = callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the callback for when a message is received
|
||||||
|
*
|
||||||
|
* @param {Function} callback The function to call when a message has arrived
|
||||||
|
* @param {String} type The callback argument type: "arraybuffer" or "string"
|
||||||
|
*/
|
||||||
|
TcpClient.prototype.addResponseListener = function(callback, type) {
|
||||||
|
if (typeof type === "undefined") {
|
||||||
|
type = "arraybuffer";
|
||||||
|
}
|
||||||
|
// Register received callback.
|
||||||
|
if (type === "string") {
|
||||||
|
this.callbacks.recvString = callback;
|
||||||
|
} else {
|
||||||
|
this.callbacks.recvBuffer = callback;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the callback for when the socket disconnects
|
||||||
|
*
|
||||||
|
* @param {Function} callback The function to call when the socket disconnects
|
||||||
|
* @param {String} type The callback argument type: "arraybuffer" or "string"
|
||||||
|
*/
|
||||||
|
TcpClient.prototype.addDisconnectListener = function(callback) {
|
||||||
|
// Register disconnect callback.
|
||||||
|
this.callbacks.disconnect = callback;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disconnects from the remote side
|
||||||
|
*
|
||||||
|
* @see http://developer.chrome.com/trunk/apps/socket.html#method-disconnect
|
||||||
|
*/
|
||||||
|
TcpClient.prototype.disconnect = function() {
|
||||||
|
if (this.isConnected) {
|
||||||
|
this.isConnected = false;
|
||||||
|
socket.disconnect(this.socketId);
|
||||||
|
if (this.callbacks.disconnect) {
|
||||||
|
this.callbacks.disconnect();
|
||||||
|
}
|
||||||
|
log('socket disconnected');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The callback function used for when we attempt to have Chrome
|
||||||
|
* create a socket. If the socket is successfully created
|
||||||
|
* we go ahead and connect to the remote side.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @see http://developer.chrome.com/trunk/apps/socket.html#method-connect
|
||||||
|
* @param {Object} createInfo The socket details
|
||||||
|
*/
|
||||||
|
TcpClient.prototype._onCreate = function(createInfo) {
|
||||||
|
this.socketId = createInfo.socketId;
|
||||||
|
if (this.socketId > 0) {
|
||||||
|
socket.connect(this.socketId, this.addr, this.port, this._onConnectComplete.bind(this));
|
||||||
|
} else {
|
||||||
|
error('Unable to create socket');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The callback function used for when we attempt to have Chrome
|
||||||
|
* connect to the remote side. If a successful connection is
|
||||||
|
* made then polling starts to check for data to read
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Number} resultCode Indicates whether the connection was successful
|
||||||
|
*/
|
||||||
|
TcpClient.prototype._onConnectComplete = function(resultCode) {
|
||||||
|
// Start polling for reads.
|
||||||
|
this.isConnected = true;
|
||||||
|
setTimeout(this._periodicallyRead.bind(this), this.pollInterval);
|
||||||
|
|
||||||
|
if (this.callbacks.connect) {
|
||||||
|
log('connect complete');
|
||||||
|
this.callbacks.connect();
|
||||||
|
}
|
||||||
|
log('onConnectComplete');
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks for new data to read from the socket
|
||||||
|
*
|
||||||
|
* @see http://developer.chrome.com/trunk/apps/socket.html#method-read
|
||||||
|
*/
|
||||||
|
TcpClient.prototype._periodicallyRead = function() {
|
||||||
|
var that = this;
|
||||||
|
socket.getInfo(this.socketId, function (info) {
|
||||||
|
if (info.connected) {
|
||||||
|
setTimeout(that._periodicallyRead.bind(that), that.pollInterval);
|
||||||
|
socket.read(that.socketId, null, that._onDataRead.bind(that));
|
||||||
|
} else if (that.isConnected) {
|
||||||
|
log('socket disconnect detected');
|
||||||
|
that.disconnect();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback function for when data has been read from the socket.
|
||||||
|
* Converts the array buffer that is read in to a string
|
||||||
|
* and sends it on for further processing by passing it to
|
||||||
|
* the previously assigned callback function.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @see TcpClient.prototype.addResponseListener
|
||||||
|
* @param {Object} readInfo The incoming message
|
||||||
|
*/
|
||||||
|
TcpClient.prototype._onDataRead = function(readInfo) {
|
||||||
|
// Call received callback if there's data in the response.
|
||||||
|
if (readInfo.resultCode > 0) {
|
||||||
|
log('onDataRead');
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Debug
|
||||||
|
var bytes = [], u8 = new Uint8Array(readInfo.data);
|
||||||
|
for (var i = 0; i < u8.length; i++) {
|
||||||
|
bytes.push(u8[i]);
|
||||||
|
}
|
||||||
|
log("received bytes: " + (bytes.join(',')));
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (this.callbacks.recvBuffer) {
|
||||||
|
// Return raw ArrayBuffer directly.
|
||||||
|
this.callbacks.recvBuffer(readInfo.data);
|
||||||
|
}
|
||||||
|
if (this.callbacks.recvString) {
|
||||||
|
// Convert ArrayBuffer to string.
|
||||||
|
this._arrayBufferToString(readInfo.data, function(str) {
|
||||||
|
this.callbacks.recvString(str);
|
||||||
|
}.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger another read right away
|
||||||
|
setTimeout(this._periodicallyRead.bind(this), 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback for when data has been successfully
|
||||||
|
* written to the socket.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} writeInfo The outgoing message
|
||||||
|
*/
|
||||||
|
TcpClient.prototype._onWriteComplete = function(writeInfo) {
|
||||||
|
log('onWriteComplete');
|
||||||
|
// Call sent callback.
|
||||||
|
if (this.callbacks.sent) {
|
||||||
|
this.callbacks.sent(writeInfo);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an array buffer to a string
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {ArrayBuffer} buf The buffer to convert
|
||||||
|
* @param {Function} callback The function to call when conversion is complete
|
||||||
|
*/
|
||||||
|
TcpClient.prototype._arrayBufferToString = function(buf, callback) {
|
||||||
|
var bb = new Blob([new Uint8Array(buf)]);
|
||||||
|
var f = new FileReader();
|
||||||
|
f.onload = function(e) {
|
||||||
|
callback(e.target.result);
|
||||||
|
};
|
||||||
|
f.readAsText(bb);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a string to an array buffer
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {String} str The string to convert
|
||||||
|
* @param {Function} callback The function to call when conversion is complete
|
||||||
|
*/
|
||||||
|
TcpClient.prototype._stringToArrayBuffer = function(str, callback) {
|
||||||
|
var bb = new Blob([str]);
|
||||||
|
var f = new FileReader();
|
||||||
|
f.onload = function(e) {
|
||||||
|
callback(e.target.result);
|
||||||
|
};
|
||||||
|
f.readAsArrayBuffer(bb);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper function for logging
|
||||||
|
*/
|
||||||
|
function log(msg) {
|
||||||
|
console.log(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper function for error logging
|
||||||
|
*/
|
||||||
|
function error(msg) {
|
||||||
|
console.error(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.TcpClient = TcpClient;
|
||||||
|
|
||||||
|
})(window);
|
273
static/js/novnc/des.js
Normal file
273
static/js/novnc/des.js
Normal file
|
@ -0,0 +1,273 @@
|
||||||
|
/*
|
||||||
|
* Ported from Flashlight VNC ActionScript implementation:
|
||||||
|
* http://www.wizhelp.com/flashlight-vnc/
|
||||||
|
*
|
||||||
|
* Full attribution follows:
|
||||||
|
*
|
||||||
|
* -------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* This DES class has been extracted from package Acme.Crypto for use in VNC.
|
||||||
|
* The unnecessary odd parity code has been removed.
|
||||||
|
*
|
||||||
|
* These changes are:
|
||||||
|
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
|
||||||
|
* DesCipher - the DES encryption method
|
||||||
|
*
|
||||||
|
* The meat of this code is by Dave Zimmerman <dzimm@widget.com>, and is:
|
||||||
|
*
|
||||||
|
* Copyright (c) 1996 Widget Workshop, Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software
|
||||||
|
* and its documentation for NON-COMMERCIAL or COMMERCIAL purposes and
|
||||||
|
* without fee is hereby granted, provided that this copyright notice is kept
|
||||||
|
* intact.
|
||||||
|
*
|
||||||
|
* WIDGET WORKSHOP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
|
||||||
|
* OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||||
|
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. WIDGET WORKSHOP SHALL NOT BE LIABLE
|
||||||
|
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||||||
|
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
|
||||||
|
* CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
|
||||||
|
* PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
|
||||||
|
* NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
|
||||||
|
* SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
|
||||||
|
* SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
|
||||||
|
* PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES"). WIDGET WORKSHOP
|
||||||
|
* SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
|
||||||
|
* HIGH RISK ACTIVITIES.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* The rest is:
|
||||||
|
*
|
||||||
|
* Copyright (C) 1996 by Jef Poskanzer <jef@acme.com>. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* Visit the ACME Labs Java page for up-to-date versions of this and other
|
||||||
|
* fine Java utilities: http://www.acme.com/java/
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
/*jslint white: false, bitwise: false, plusplus: false */
|
||||||
|
|
||||||
|
function DES(passwd) {
|
||||||
|
|
||||||
|
// Tables, permutations, S-boxes, etc.
|
||||||
|
var PC2 = [13,16,10,23, 0, 4, 2,27,14, 5,20, 9,22,18,11, 3,
|
||||||
|
25, 7,15, 6,26,19,12, 1,40,51,30,36,46,54,29,39,
|
||||||
|
50,44,32,47,43,48,38,55,33,52,45,41,49,35,28,31 ],
|
||||||
|
totrot = [ 1, 2, 4, 6, 8,10,12,14,15,17,19,21,23,25,27,28],
|
||||||
|
z = 0x0, a,b,c,d,e,f, SP1,SP2,SP3,SP4,SP5,SP6,SP7,SP8,
|
||||||
|
keys = [];
|
||||||
|
|
||||||
|
a=1<<16; b=1<<24; c=a|b; d=1<<2; e=1<<10; f=d|e;
|
||||||
|
SP1 = [c|e,z|z,a|z,c|f,c|d,a|f,z|d,a|z,z|e,c|e,c|f,z|e,b|f,c|d,b|z,z|d,
|
||||||
|
z|f,b|e,b|e,a|e,a|e,c|z,c|z,b|f,a|d,b|d,b|d,a|d,z|z,z|f,a|f,b|z,
|
||||||
|
a|z,c|f,z|d,c|z,c|e,b|z,b|z,z|e,c|d,a|z,a|e,b|d,z|e,z|d,b|f,a|f,
|
||||||
|
c|f,a|d,c|z,b|f,b|d,z|f,a|f,c|e,z|f,b|e,b|e,z|z,a|d,a|e,z|z,c|d];
|
||||||
|
a=1<<20; b=1<<31; c=a|b; d=1<<5; e=1<<15; f=d|e;
|
||||||
|
SP2 = [c|f,b|e,z|e,a|f,a|z,z|d,c|d,b|f,b|d,c|f,c|e,b|z,b|e,a|z,z|d,c|d,
|
||||||
|
a|e,a|d,b|f,z|z,b|z,z|e,a|f,c|z,a|d,b|d,z|z,a|e,z|f,c|e,c|z,z|f,
|
||||||
|
z|z,a|f,c|d,a|z,b|f,c|z,c|e,z|e,c|z,b|e,z|d,c|f,a|f,z|d,z|e,b|z,
|
||||||
|
z|f,c|e,a|z,b|d,a|d,b|f,b|d,a|d,a|e,z|z,b|e,z|f,b|z,c|d,c|f,a|e];
|
||||||
|
a=1<<17; b=1<<27; c=a|b; d=1<<3; e=1<<9; f=d|e;
|
||||||
|
SP3 = [z|f,c|e,z|z,c|d,b|e,z|z,a|f,b|e,a|d,b|d,b|d,a|z,c|f,a|d,c|z,z|f,
|
||||||
|
b|z,z|d,c|e,z|e,a|e,c|z,c|d,a|f,b|f,a|e,a|z,b|f,z|d,c|f,z|e,b|z,
|
||||||
|
c|e,b|z,a|d,z|f,a|z,c|e,b|e,z|z,z|e,a|d,c|f,b|e,b|d,z|e,z|z,c|d,
|
||||||
|
b|f,a|z,b|z,c|f,z|d,a|f,a|e,b|d,c|z,b|f,z|f,c|z,a|f,z|d,c|d,a|e];
|
||||||
|
a=1<<13; b=1<<23; c=a|b; d=1<<0; e=1<<7; f=d|e;
|
||||||
|
SP4 = [c|d,a|f,a|f,z|e,c|e,b|f,b|d,a|d,z|z,c|z,c|z,c|f,z|f,z|z,b|e,b|d,
|
||||||
|
z|d,a|z,b|z,c|d,z|e,b|z,a|d,a|e,b|f,z|d,a|e,b|e,a|z,c|e,c|f,z|f,
|
||||||
|
b|e,b|d,c|z,c|f,z|f,z|z,z|z,c|z,a|e,b|e,b|f,z|d,c|d,a|f,a|f,z|e,
|
||||||
|
c|f,z|f,z|d,a|z,b|d,a|d,c|e,b|f,a|d,a|e,b|z,c|d,z|e,b|z,a|z,c|e];
|
||||||
|
a=1<<25; b=1<<30; c=a|b; d=1<<8; e=1<<19; f=d|e;
|
||||||
|
SP5 = [z|d,a|f,a|e,c|d,z|e,z|d,b|z,a|e,b|f,z|e,a|d,b|f,c|d,c|e,z|f,b|z,
|
||||||
|
a|z,b|e,b|e,z|z,b|d,c|f,c|f,a|d,c|e,b|d,z|z,c|z,a|f,a|z,c|z,z|f,
|
||||||
|
z|e,c|d,z|d,a|z,b|z,a|e,c|d,b|f,a|d,b|z,c|e,a|f,b|f,z|d,a|z,c|e,
|
||||||
|
c|f,z|f,c|z,c|f,a|e,z|z,b|e,c|z,z|f,a|d,b|d,z|e,z|z,b|e,a|f,b|d];
|
||||||
|
a=1<<22; b=1<<29; c=a|b; d=1<<4; e=1<<14; f=d|e;
|
||||||
|
SP6 = [b|d,c|z,z|e,c|f,c|z,z|d,c|f,a|z,b|e,a|f,a|z,b|d,a|d,b|e,b|z,z|f,
|
||||||
|
z|z,a|d,b|f,z|e,a|e,b|f,z|d,c|d,c|d,z|z,a|f,c|e,z|f,a|e,c|e,b|z,
|
||||||
|
b|e,z|d,c|d,a|e,c|f,a|z,z|f,b|d,a|z,b|e,b|z,z|f,b|d,c|f,a|e,c|z,
|
||||||
|
a|f,c|e,z|z,c|d,z|d,z|e,c|z,a|f,z|e,a|d,b|f,z|z,c|e,b|z,a|d,b|f];
|
||||||
|
a=1<<21; b=1<<26; c=a|b; d=1<<1; e=1<<11; f=d|e;
|
||||||
|
SP7 = [a|z,c|d,b|f,z|z,z|e,b|f,a|f,c|e,c|f,a|z,z|z,b|d,z|d,b|z,c|d,z|f,
|
||||||
|
b|e,a|f,a|d,b|e,b|d,c|z,c|e,a|d,c|z,z|e,z|f,c|f,a|e,z|d,b|z,a|e,
|
||||||
|
b|z,a|e,a|z,b|f,b|f,c|d,c|d,z|d,a|d,b|z,b|e,a|z,c|e,z|f,a|f,c|e,
|
||||||
|
z|f,b|d,c|f,c|z,a|e,z|z,z|d,c|f,z|z,a|f,c|z,z|e,b|d,b|e,z|e,a|d];
|
||||||
|
a=1<<18; b=1<<28; c=a|b; d=1<<6; e=1<<12; f=d|e;
|
||||||
|
SP8 = [b|f,z|e,a|z,c|f,b|z,b|f,z|d,b|z,a|d,c|z,c|f,a|e,c|e,a|f,z|e,z|d,
|
||||||
|
c|z,b|d,b|e,z|f,a|e,a|d,c|d,c|e,z|f,z|z,z|z,c|d,b|d,b|e,a|f,a|z,
|
||||||
|
a|f,a|z,c|e,z|e,z|d,c|d,z|e,a|f,b|e,z|d,b|d,c|z,c|d,b|z,a|z,b|f,
|
||||||
|
z|z,c|f,a|d,b|d,c|z,b|e,b|f,z|z,c|f,a|e,a|e,z|f,z|f,a|d,b|z,c|e];
|
||||||
|
|
||||||
|
// Set the key.
|
||||||
|
function setKeys(keyBlock) {
|
||||||
|
var i, j, l, m, n, o, pc1m = [], pcr = [], kn = [],
|
||||||
|
raw0, raw1, rawi, KnLi;
|
||||||
|
|
||||||
|
for (j = 0, l = 56; j < 56; ++j, l-=8) {
|
||||||
|
l += l<-5 ? 65 : l<-3 ? 31 : l<-1 ? 63 : l===27 ? 35 : 0; // PC1
|
||||||
|
m = l & 0x7;
|
||||||
|
pc1m[j] = ((keyBlock[l >>> 3] & (1<<m)) !== 0) ? 1: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 16; ++i) {
|
||||||
|
m = i << 1;
|
||||||
|
n = m + 1;
|
||||||
|
kn[m] = kn[n] = 0;
|
||||||
|
for (o=28; o<59; o+=28) {
|
||||||
|
for (j = o-28; j < o; ++j) {
|
||||||
|
l = j + totrot[i];
|
||||||
|
if (l < o) {
|
||||||
|
pcr[j] = pc1m[l];
|
||||||
|
} else {
|
||||||
|
pcr[j] = pc1m[l - 28];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (j = 0; j < 24; ++j) {
|
||||||
|
if (pcr[PC2[j]] !== 0) {
|
||||||
|
kn[m] |= 1<<(23-j);
|
||||||
|
}
|
||||||
|
if (pcr[PC2[j + 24]] !== 0) {
|
||||||
|
kn[n] |= 1<<(23-j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// cookey
|
||||||
|
for (i = 0, rawi = 0, KnLi = 0; i < 16; ++i) {
|
||||||
|
raw0 = kn[rawi++];
|
||||||
|
raw1 = kn[rawi++];
|
||||||
|
keys[KnLi] = (raw0 & 0x00fc0000) << 6;
|
||||||
|
keys[KnLi] |= (raw0 & 0x00000fc0) << 10;
|
||||||
|
keys[KnLi] |= (raw1 & 0x00fc0000) >>> 10;
|
||||||
|
keys[KnLi] |= (raw1 & 0x00000fc0) >>> 6;
|
||||||
|
++KnLi;
|
||||||
|
keys[KnLi] = (raw0 & 0x0003f000) << 12;
|
||||||
|
keys[KnLi] |= (raw0 & 0x0000003f) << 16;
|
||||||
|
keys[KnLi] |= (raw1 & 0x0003f000) >>> 4;
|
||||||
|
keys[KnLi] |= (raw1 & 0x0000003f);
|
||||||
|
++KnLi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encrypt 8 bytes of text
|
||||||
|
function enc8(text) {
|
||||||
|
var i = 0, b = text.slice(), fval, keysi = 0,
|
||||||
|
l, r, x; // left, right, accumulator
|
||||||
|
|
||||||
|
// Squash 8 bytes to 2 ints
|
||||||
|
l = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
|
||||||
|
r = b[i++]<<24 | b[i++]<<16 | b[i++]<<8 | b[i++];
|
||||||
|
|
||||||
|
x = ((l >>> 4) ^ r) & 0x0f0f0f0f;
|
||||||
|
r ^= x;
|
||||||
|
l ^= (x << 4);
|
||||||
|
x = ((l >>> 16) ^ r) & 0x0000ffff;
|
||||||
|
r ^= x;
|
||||||
|
l ^= (x << 16);
|
||||||
|
x = ((r >>> 2) ^ l) & 0x33333333;
|
||||||
|
l ^= x;
|
||||||
|
r ^= (x << 2);
|
||||||
|
x = ((r >>> 8) ^ l) & 0x00ff00ff;
|
||||||
|
l ^= x;
|
||||||
|
r ^= (x << 8);
|
||||||
|
r = (r << 1) | ((r >>> 31) & 1);
|
||||||
|
x = (l ^ r) & 0xaaaaaaaa;
|
||||||
|
l ^= x;
|
||||||
|
r ^= x;
|
||||||
|
l = (l << 1) | ((l >>> 31) & 1);
|
||||||
|
|
||||||
|
for (i = 0; i < 8; ++i) {
|
||||||
|
x = (r << 28) | (r >>> 4);
|
||||||
|
x ^= keys[keysi++];
|
||||||
|
fval = SP7[x & 0x3f];
|
||||||
|
fval |= SP5[(x >>> 8) & 0x3f];
|
||||||
|
fval |= SP3[(x >>> 16) & 0x3f];
|
||||||
|
fval |= SP1[(x >>> 24) & 0x3f];
|
||||||
|
x = r ^ keys[keysi++];
|
||||||
|
fval |= SP8[x & 0x3f];
|
||||||
|
fval |= SP6[(x >>> 8) & 0x3f];
|
||||||
|
fval |= SP4[(x >>> 16) & 0x3f];
|
||||||
|
fval |= SP2[(x >>> 24) & 0x3f];
|
||||||
|
l ^= fval;
|
||||||
|
x = (l << 28) | (l >>> 4);
|
||||||
|
x ^= keys[keysi++];
|
||||||
|
fval = SP7[x & 0x3f];
|
||||||
|
fval |= SP5[(x >>> 8) & 0x3f];
|
||||||
|
fval |= SP3[(x >>> 16) & 0x3f];
|
||||||
|
fval |= SP1[(x >>> 24) & 0x3f];
|
||||||
|
x = l ^ keys[keysi++];
|
||||||
|
fval |= SP8[x & 0x0000003f];
|
||||||
|
fval |= SP6[(x >>> 8) & 0x3f];
|
||||||
|
fval |= SP4[(x >>> 16) & 0x3f];
|
||||||
|
fval |= SP2[(x >>> 24) & 0x3f];
|
||||||
|
r ^= fval;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = (r << 31) | (r >>> 1);
|
||||||
|
x = (l ^ r) & 0xaaaaaaaa;
|
||||||
|
l ^= x;
|
||||||
|
r ^= x;
|
||||||
|
l = (l << 31) | (l >>> 1);
|
||||||
|
x = ((l >>> 8) ^ r) & 0x00ff00ff;
|
||||||
|
r ^= x;
|
||||||
|
l ^= (x << 8);
|
||||||
|
x = ((l >>> 2) ^ r) & 0x33333333;
|
||||||
|
r ^= x;
|
||||||
|
l ^= (x << 2);
|
||||||
|
x = ((r >>> 16) ^ l) & 0x0000ffff;
|
||||||
|
l ^= x;
|
||||||
|
r ^= (x << 16);
|
||||||
|
x = ((r >>> 4) ^ l) & 0x0f0f0f0f;
|
||||||
|
l ^= x;
|
||||||
|
r ^= (x << 4);
|
||||||
|
|
||||||
|
// Spread ints to bytes
|
||||||
|
x = [r, l];
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
b[i] = (x[i>>>2] >>> (8*(3 - (i%4)))) % 256;
|
||||||
|
if (b[i] < 0) { b[i] += 256; } // unsigned
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Encrypt 16 bytes of text using passwd as key
|
||||||
|
function encrypt(t) {
|
||||||
|
return enc8(t.slice(0,8)).concat(enc8(t.slice(8,16)));
|
||||||
|
}
|
||||||
|
|
||||||
|
setKeys(passwd); // Setup keys
|
||||||
|
return {'encrypt': encrypt}; // Public interface
|
||||||
|
|
||||||
|
} // function DES
|
770
static/js/novnc/display.js
Normal file
770
static/js/novnc/display.js
Normal file
|
@ -0,0 +1,770 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*jslint browser: true, white: false, bitwise: false */
|
||||||
|
/*global Util, Base64, changeCursor */
|
||||||
|
|
||||||
|
function Display(defaults) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var that = {}, // Public API methods
|
||||||
|
conf = {}, // Configuration attributes
|
||||||
|
|
||||||
|
// Private Display namespace variables
|
||||||
|
c_ctx = null,
|
||||||
|
c_forceCanvas = false,
|
||||||
|
|
||||||
|
// Queued drawing actions for in-order rendering
|
||||||
|
renderQ = [],
|
||||||
|
|
||||||
|
// Predefine function variables (jslint)
|
||||||
|
imageDataGet, rgbImageData, bgrxImageData, cmapImageData,
|
||||||
|
setFillColor, rescale, scan_renderQ,
|
||||||
|
|
||||||
|
// The full frame buffer (logical canvas) size
|
||||||
|
fb_width = 0,
|
||||||
|
fb_height = 0,
|
||||||
|
// The visible "physical canvas" viewport
|
||||||
|
viewport = {'x': 0, 'y': 0, 'w' : 0, 'h' : 0 },
|
||||||
|
cleanRect = {'x1': 0, 'y1': 0, 'x2': -1, 'y2': -1},
|
||||||
|
|
||||||
|
c_prevStyle = "",
|
||||||
|
tile = null,
|
||||||
|
tile16x16 = null,
|
||||||
|
tile_x = 0,
|
||||||
|
tile_y = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// Configuration attributes
|
||||||
|
Util.conf_defaults(conf, that, defaults, [
|
||||||
|
['target', 'wo', 'dom', null, 'Canvas element for rendering'],
|
||||||
|
['context', 'ro', 'raw', null, 'Canvas 2D context for rendering (read-only)'],
|
||||||
|
['logo', 'rw', 'raw', null, 'Logo to display when cleared: {"width": width, "height": height, "data": data}'],
|
||||||
|
['true_color', 'rw', 'bool', true, 'Use true-color pixel data'],
|
||||||
|
['colourMap', 'rw', 'arr', [], 'Colour map array (when not true-color)'],
|
||||||
|
['scale', 'rw', 'float', 1.0, 'Display area scale factor 0.0 - 1.0'],
|
||||||
|
['viewport', 'rw', 'bool', false, 'Use a viewport set with viewportChange()'],
|
||||||
|
['width', 'rw', 'int', null, 'Display area width'],
|
||||||
|
['height', 'rw', 'int', null, 'Display area height'],
|
||||||
|
|
||||||
|
['render_mode', 'ro', 'str', '', 'Canvas rendering mode (read-only)'],
|
||||||
|
|
||||||
|
['prefer_js', 'rw', 'str', null, 'Prefer Javascript over canvas methods'],
|
||||||
|
['cursor_uri', 'rw', 'raw', null, 'Can we render cursor using data URI']
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Override some specific getters/setters
|
||||||
|
that.get_context = function () { return c_ctx; };
|
||||||
|
|
||||||
|
that.set_scale = function(scale) { rescale(scale); };
|
||||||
|
|
||||||
|
that.set_width = function (val) { that.resize(val, fb_height); };
|
||||||
|
that.get_width = function() { return fb_width; };
|
||||||
|
|
||||||
|
that.set_height = function (val) { that.resize(fb_width, val); };
|
||||||
|
that.get_height = function() { return fb_height; };
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Private functions
|
||||||
|
//
|
||||||
|
|
||||||
|
// Create the public API interface
|
||||||
|
function constructor() {
|
||||||
|
Util.Debug(">> Display.constructor");
|
||||||
|
|
||||||
|
var c, func, i, curDat, curSave,
|
||||||
|
has_imageData = false, UE = Util.Engine;
|
||||||
|
|
||||||
|
if (! conf.target) { throw("target must be set"); }
|
||||||
|
|
||||||
|
if (typeof conf.target === 'string') {
|
||||||
|
throw("target must be a DOM element");
|
||||||
|
}
|
||||||
|
|
||||||
|
c = conf.target;
|
||||||
|
|
||||||
|
if (! c.getContext) { throw("no getContext method"); }
|
||||||
|
|
||||||
|
if (! c_ctx) { c_ctx = c.getContext('2d'); }
|
||||||
|
|
||||||
|
Util.Debug("User Agent: " + navigator.userAgent);
|
||||||
|
if (UE.gecko) { Util.Debug("Browser: gecko " + UE.gecko); }
|
||||||
|
if (UE.webkit) { Util.Debug("Browser: webkit " + UE.webkit); }
|
||||||
|
if (UE.trident) { Util.Debug("Browser: trident " + UE.trident); }
|
||||||
|
if (UE.presto) { Util.Debug("Browser: presto " + UE.presto); }
|
||||||
|
|
||||||
|
that.clear();
|
||||||
|
|
||||||
|
// Check canvas features
|
||||||
|
if ('createImageData' in c_ctx) {
|
||||||
|
conf.render_mode = "canvas rendering";
|
||||||
|
} else {
|
||||||
|
throw("Canvas does not support createImageData");
|
||||||
|
}
|
||||||
|
if (conf.prefer_js === null) {
|
||||||
|
Util.Info("Prefering javascript operations");
|
||||||
|
conf.prefer_js = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize cached tile imageData
|
||||||
|
tile16x16 = c_ctx.createImageData(16, 16);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Determine browser support for setting the cursor via data URI
|
||||||
|
* scheme
|
||||||
|
*/
|
||||||
|
curDat = [];
|
||||||
|
for (i=0; i < 8 * 8 * 4; i += 1) {
|
||||||
|
curDat.push(255);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
curSave = c.style.cursor;
|
||||||
|
changeCursor(conf.target, curDat, curDat, 2, 2, 8, 8);
|
||||||
|
if (c.style.cursor) {
|
||||||
|
if (conf.cursor_uri === null) {
|
||||||
|
conf.cursor_uri = true;
|
||||||
|
}
|
||||||
|
Util.Info("Data URI scheme cursor supported");
|
||||||
|
} else {
|
||||||
|
if (conf.cursor_uri === null) {
|
||||||
|
conf.cursor_uri = false;
|
||||||
|
}
|
||||||
|
Util.Warn("Data URI scheme cursor not supported");
|
||||||
|
}
|
||||||
|
c.style.cursor = curSave;
|
||||||
|
} catch (exc2) {
|
||||||
|
Util.Error("Data URI scheme cursor test exception: " + exc2);
|
||||||
|
conf.cursor_uri = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Util.Debug("<< Display.constructor");
|
||||||
|
return that ;
|
||||||
|
}
|
||||||
|
|
||||||
|
rescale = function(factor) {
|
||||||
|
var c, tp, x, y,
|
||||||
|
properties = ['transform', 'WebkitTransform', 'MozTransform', null];
|
||||||
|
c = conf.target;
|
||||||
|
tp = properties.shift();
|
||||||
|
while (tp) {
|
||||||
|
if (typeof c.style[tp] !== 'undefined') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tp = properties.shift();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tp === null) {
|
||||||
|
Util.Debug("No scaling support");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof(factor) === "undefined") {
|
||||||
|
factor = conf.scale;
|
||||||
|
} else if (factor > 1.0) {
|
||||||
|
factor = 1.0;
|
||||||
|
} else if (factor < 0.1) {
|
||||||
|
factor = 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conf.scale === factor) {
|
||||||
|
//Util.Debug("Display already scaled to '" + factor + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
conf.scale = factor;
|
||||||
|
x = c.width - c.width * factor;
|
||||||
|
y = c.height - c.height * factor;
|
||||||
|
c.style[tp] = "scale(" + conf.scale + ") translate(-" + x + "px, -" + y + "px)";
|
||||||
|
};
|
||||||
|
|
||||||
|
setFillColor = function(color) {
|
||||||
|
var bgr, newStyle;
|
||||||
|
if (conf.true_color) {
|
||||||
|
bgr = color;
|
||||||
|
} else {
|
||||||
|
bgr = conf.colourMap[color[0]];
|
||||||
|
}
|
||||||
|
newStyle = "rgb(" + bgr[2] + "," + bgr[1] + "," + bgr[0] + ")";
|
||||||
|
if (newStyle !== c_prevStyle) {
|
||||||
|
c_ctx.fillStyle = newStyle;
|
||||||
|
c_prevStyle = newStyle;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Public API interface functions
|
||||||
|
//
|
||||||
|
|
||||||
|
// Shift and/or resize the visible viewport
|
||||||
|
that.viewportChange = function(deltaX, deltaY, width, height) {
|
||||||
|
var c = conf.target, v = viewport, cr = cleanRect,
|
||||||
|
saveImg = null, saveStyle, x1, y1, vx2, vy2, w, h;
|
||||||
|
|
||||||
|
if (!conf.viewport) {
|
||||||
|
Util.Debug("Setting viewport to full display region");
|
||||||
|
deltaX = -v.w; // Clamped later if out of bounds
|
||||||
|
deltaY = -v.h; // Clamped later if out of bounds
|
||||||
|
width = fb_width;
|
||||||
|
height = fb_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof(deltaX) === "undefined") { deltaX = 0; }
|
||||||
|
if (typeof(deltaY) === "undefined") { deltaY = 0; }
|
||||||
|
if (typeof(width) === "undefined") { width = v.w; }
|
||||||
|
if (typeof(height) === "undefined") { height = v.h; }
|
||||||
|
|
||||||
|
// Size change
|
||||||
|
|
||||||
|
if (width > fb_width) { width = fb_width; }
|
||||||
|
if (height > fb_height) { height = fb_height; }
|
||||||
|
|
||||||
|
if ((v.w !== width) || (v.h !== height)) {
|
||||||
|
// Change width
|
||||||
|
if ((width < v.w) && (cr.x2 > v.x + width -1)) {
|
||||||
|
cr.x2 = v.x + width - 1;
|
||||||
|
}
|
||||||
|
v.w = width;
|
||||||
|
|
||||||
|
// Change height
|
||||||
|
if ((height < v.h) && (cr.y2 > v.y + height -1)) {
|
||||||
|
cr.y2 = v.y + height - 1;
|
||||||
|
}
|
||||||
|
v.h = height;
|
||||||
|
|
||||||
|
|
||||||
|
if (v.w > 0 && v.h > 0 && c.width > 0 && c.height > 0) {
|
||||||
|
saveImg = c_ctx.getImageData(0, 0,
|
||||||
|
(c.width < v.w) ? c.width : v.w,
|
||||||
|
(c.height < v.h) ? c.height : v.h);
|
||||||
|
}
|
||||||
|
|
||||||
|
c.width = v.w;
|
||||||
|
c.height = v.h;
|
||||||
|
|
||||||
|
if (saveImg) {
|
||||||
|
c_ctx.putImageData(saveImg, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vx2 = v.x + v.w - 1;
|
||||||
|
vy2 = v.y + v.h - 1;
|
||||||
|
|
||||||
|
|
||||||
|
// Position change
|
||||||
|
|
||||||
|
if ((deltaX < 0) && ((v.x + deltaX) < 0)) {
|
||||||
|
deltaX = - v.x;
|
||||||
|
}
|
||||||
|
if ((vx2 + deltaX) >= fb_width) {
|
||||||
|
deltaX -= ((vx2 + deltaX) - fb_width + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((v.y + deltaY) < 0) {
|
||||||
|
deltaY = - v.y;
|
||||||
|
}
|
||||||
|
if ((vy2 + deltaY) >= fb_height) {
|
||||||
|
deltaY -= ((vy2 + deltaY) - fb_height + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((deltaX === 0) && (deltaY === 0)) {
|
||||||
|
//Util.Debug("skipping viewport change");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Util.Debug("viewportChange deltaX: " + deltaX + ", deltaY: " + deltaY);
|
||||||
|
|
||||||
|
v.x += deltaX;
|
||||||
|
vx2 += deltaX;
|
||||||
|
v.y += deltaY;
|
||||||
|
vy2 += deltaY;
|
||||||
|
|
||||||
|
// Update the clean rectangle
|
||||||
|
if (v.x > cr.x1) {
|
||||||
|
cr.x1 = v.x;
|
||||||
|
}
|
||||||
|
if (vx2 < cr.x2) {
|
||||||
|
cr.x2 = vx2;
|
||||||
|
}
|
||||||
|
if (v.y > cr.y1) {
|
||||||
|
cr.y1 = v.y;
|
||||||
|
}
|
||||||
|
if (vy2 < cr.y2) {
|
||||||
|
cr.y2 = vy2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deltaX < 0) {
|
||||||
|
// Shift viewport left, redraw left section
|
||||||
|
x1 = 0;
|
||||||
|
w = - deltaX;
|
||||||
|
} else {
|
||||||
|
// Shift viewport right, redraw right section
|
||||||
|
x1 = v.w - deltaX;
|
||||||
|
w = deltaX;
|
||||||
|
}
|
||||||
|
if (deltaY < 0) {
|
||||||
|
// Shift viewport up, redraw top section
|
||||||
|
y1 = 0;
|
||||||
|
h = - deltaY;
|
||||||
|
} else {
|
||||||
|
// Shift viewport down, redraw bottom section
|
||||||
|
y1 = v.h - deltaY;
|
||||||
|
h = deltaY;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the valid part of the viewport to the shifted location
|
||||||
|
saveStyle = c_ctx.fillStyle;
|
||||||
|
c_ctx.fillStyle = "rgb(255,255,255)";
|
||||||
|
if (deltaX !== 0) {
|
||||||
|
//that.copyImage(0, 0, -deltaX, 0, v.w, v.h);
|
||||||
|
//that.fillRect(x1, 0, w, v.h, [255,255,255]);
|
||||||
|
c_ctx.drawImage(c, 0, 0, v.w, v.h, -deltaX, 0, v.w, v.h);
|
||||||
|
c_ctx.fillRect(x1, 0, w, v.h);
|
||||||
|
}
|
||||||
|
if (deltaY !== 0) {
|
||||||
|
//that.copyImage(0, 0, 0, -deltaY, v.w, v.h);
|
||||||
|
//that.fillRect(0, y1, v.w, h, [255,255,255]);
|
||||||
|
c_ctx.drawImage(c, 0, 0, v.w, v.h, 0, -deltaY, v.w, v.h);
|
||||||
|
c_ctx.fillRect(0, y1, v.w, h);
|
||||||
|
}
|
||||||
|
c_ctx.fillStyle = saveStyle;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Return a map of clean and dirty areas of the viewport and reset the
|
||||||
|
// tracking of clean and dirty areas.
|
||||||
|
//
|
||||||
|
// Returns: {'cleanBox': {'x': x, 'y': y, 'w': w, 'h': h},
|
||||||
|
// 'dirtyBoxes': [{'x': x, 'y': y, 'w': w, 'h': h}, ...]}
|
||||||
|
that.getCleanDirtyReset = function() {
|
||||||
|
var v = viewport, c = cleanRect, cleanBox, dirtyBoxes = [],
|
||||||
|
vx2 = v.x + v.w - 1, vy2 = v.y + v.h - 1;
|
||||||
|
|
||||||
|
|
||||||
|
// Copy the cleanRect
|
||||||
|
cleanBox = {'x': c.x1, 'y': c.y1,
|
||||||
|
'w': c.x2 - c.x1 + 1, 'h': c.y2 - c.y1 + 1};
|
||||||
|
|
||||||
|
if ((c.x1 >= c.x2) || (c.y1 >= c.y2)) {
|
||||||
|
// Whole viewport is dirty
|
||||||
|
dirtyBoxes.push({'x': v.x, 'y': v.y, 'w': v.w, 'h': v.h});
|
||||||
|
} else {
|
||||||
|
// Redraw dirty regions
|
||||||
|
if (v.x < c.x1) {
|
||||||
|
// left side dirty region
|
||||||
|
dirtyBoxes.push({'x': v.x, 'y': v.y,
|
||||||
|
'w': c.x1 - v.x + 1, 'h': v.h});
|
||||||
|
}
|
||||||
|
if (vx2 > c.x2) {
|
||||||
|
// right side dirty region
|
||||||
|
dirtyBoxes.push({'x': c.x2 + 1, 'y': v.y,
|
||||||
|
'w': vx2 - c.x2, 'h': v.h});
|
||||||
|
}
|
||||||
|
if (v.y < c.y1) {
|
||||||
|
// top/middle dirty region
|
||||||
|
dirtyBoxes.push({'x': c.x1, 'y': v.y,
|
||||||
|
'w': c.x2 - c.x1 + 1, 'h': c.y1 - v.y});
|
||||||
|
}
|
||||||
|
if (vy2 > c.y2) {
|
||||||
|
// bottom/middle dirty region
|
||||||
|
dirtyBoxes.push({'x': c.x1, 'y': c.y2 + 1,
|
||||||
|
'w': c.x2 - c.x1 + 1, 'h': vy2 - c.y2});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset the cleanRect to the whole viewport
|
||||||
|
cleanRect = {'x1': v.x, 'y1': v.y,
|
||||||
|
'x2': v.x + v.w - 1, 'y2': v.y + v.h - 1};
|
||||||
|
|
||||||
|
return {'cleanBox': cleanBox, 'dirtyBoxes': dirtyBoxes};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Translate viewport coordinates to absolute coordinates
|
||||||
|
that.absX = function(x) {
|
||||||
|
return x + viewport.x;
|
||||||
|
};
|
||||||
|
that.absY = function(y) {
|
||||||
|
return y + viewport.y;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
that.resize = function(width, height) {
|
||||||
|
c_prevStyle = "";
|
||||||
|
|
||||||
|
fb_width = width;
|
||||||
|
fb_height = height;
|
||||||
|
|
||||||
|
rescale(conf.scale);
|
||||||
|
that.viewportChange();
|
||||||
|
};
|
||||||
|
|
||||||
|
that.clear = function() {
|
||||||
|
|
||||||
|
if (conf.logo) {
|
||||||
|
that.resize(conf.logo.width, conf.logo.height);
|
||||||
|
that.blitStringImage(conf.logo.data, 0, 0);
|
||||||
|
} else {
|
||||||
|
that.resize(640, 20);
|
||||||
|
c_ctx.clearRect(0, 0, viewport.w, viewport.h);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderQ = [];
|
||||||
|
|
||||||
|
// No benefit over default ("source-over") in Chrome and firefox
|
||||||
|
//c_ctx.globalCompositeOperation = "copy";
|
||||||
|
};
|
||||||
|
|
||||||
|
that.fillRect = function(x, y, width, height, color) {
|
||||||
|
setFillColor(color);
|
||||||
|
c_ctx.fillRect(x - viewport.x, y - viewport.y, width, height);
|
||||||
|
};
|
||||||
|
|
||||||
|
that.copyImage = function(old_x, old_y, new_x, new_y, w, h) {
|
||||||
|
var x1 = old_x - viewport.x, y1 = old_y - viewport.y,
|
||||||
|
x2 = new_x - viewport.x, y2 = new_y - viewport.y;
|
||||||
|
c_ctx.drawImage(conf.target, x1, y1, w, h, x2, y2, w, h);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Start updating a tile
|
||||||
|
that.startTile = function(x, y, width, height, color) {
|
||||||
|
var data, bgr, red, green, blue, i;
|
||||||
|
tile_x = x;
|
||||||
|
tile_y = y;
|
||||||
|
if ((width === 16) && (height === 16)) {
|
||||||
|
tile = tile16x16;
|
||||||
|
} else {
|
||||||
|
tile = c_ctx.createImageData(width, height);
|
||||||
|
}
|
||||||
|
data = tile.data;
|
||||||
|
if (conf.prefer_js) {
|
||||||
|
if (conf.true_color) {
|
||||||
|
bgr = color;
|
||||||
|
} else {
|
||||||
|
bgr = conf.colourMap[color[0]];
|
||||||
|
}
|
||||||
|
red = bgr[2];
|
||||||
|
green = bgr[1];
|
||||||
|
blue = bgr[0];
|
||||||
|
for (i = 0; i < (width * height * 4); i+=4) {
|
||||||
|
data[i ] = red;
|
||||||
|
data[i + 1] = green;
|
||||||
|
data[i + 2] = blue;
|
||||||
|
data[i + 3] = 255;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
that.fillRect(x, y, width, height, color);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Update sub-rectangle of the current tile
|
||||||
|
that.subTile = function(x, y, w, h, color) {
|
||||||
|
var data, p, bgr, red, green, blue, width, j, i, xend, yend;
|
||||||
|
if (conf.prefer_js) {
|
||||||
|
data = tile.data;
|
||||||
|
width = tile.width;
|
||||||
|
if (conf.true_color) {
|
||||||
|
bgr = color;
|
||||||
|
} else {
|
||||||
|
bgr = conf.colourMap[color[0]];
|
||||||
|
}
|
||||||
|
red = bgr[2];
|
||||||
|
green = bgr[1];
|
||||||
|
blue = bgr[0];
|
||||||
|
xend = x + w;
|
||||||
|
yend = y + h;
|
||||||
|
for (j = y; j < yend; j += 1) {
|
||||||
|
for (i = x; i < xend; i += 1) {
|
||||||
|
p = (i + (j * width) ) * 4;
|
||||||
|
data[p ] = red;
|
||||||
|
data[p + 1] = green;
|
||||||
|
data[p + 2] = blue;
|
||||||
|
data[p + 3] = 255;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
that.fillRect(tile_x + x, tile_y + y, w, h, color);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Draw the current tile to the screen
|
||||||
|
that.finishTile = function() {
|
||||||
|
if (conf.prefer_js) {
|
||||||
|
c_ctx.putImageData(tile, tile_x - viewport.x, tile_y - viewport.y);
|
||||||
|
}
|
||||||
|
// else: No-op, if not prefer_js then already done by setSubTile
|
||||||
|
};
|
||||||
|
|
||||||
|
rgbImageData = function(x, y, vx, vy, width, height, arr, offset) {
|
||||||
|
var img, i, j, data;
|
||||||
|
/*
|
||||||
|
if ((x - v.x >= v.w) || (y - v.y >= v.h) ||
|
||||||
|
(x - v.x + width < 0) || (y - v.y + height < 0)) {
|
||||||
|
// Skipping because outside of viewport
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
img = c_ctx.createImageData(width, height);
|
||||||
|
data = img.data;
|
||||||
|
for (i=0, j=offset; i < (width * height * 4); i=i+4, j=j+3) {
|
||||||
|
data[i ] = arr[j ];
|
||||||
|
data[i + 1] = arr[j + 1];
|
||||||
|
data[i + 2] = arr[j + 2];
|
||||||
|
data[i + 3] = 255; // Set Alpha
|
||||||
|
}
|
||||||
|
c_ctx.putImageData(img, x - vx, y - vy);
|
||||||
|
};
|
||||||
|
|
||||||
|
bgrxImageData = function(x, y, vx, vy, width, height, arr, offset) {
|
||||||
|
var img, i, j, data;
|
||||||
|
/*
|
||||||
|
if ((x - v.x >= v.w) || (y - v.y >= v.h) ||
|
||||||
|
(x - v.x + width < 0) || (y - v.y + height < 0)) {
|
||||||
|
// Skipping because outside of viewport
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
img = c_ctx.createImageData(width, height);
|
||||||
|
data = img.data;
|
||||||
|
for (i=0, j=offset; i < (width * height * 4); i=i+4, j=j+4) {
|
||||||
|
data[i ] = arr[j + 2];
|
||||||
|
data[i + 1] = arr[j + 1];
|
||||||
|
data[i + 2] = arr[j ];
|
||||||
|
data[i + 3] = 255; // Set Alpha
|
||||||
|
}
|
||||||
|
c_ctx.putImageData(img, x - vx, y - vy);
|
||||||
|
};
|
||||||
|
|
||||||
|
cmapImageData = function(x, y, vx, vy, width, height, arr, offset) {
|
||||||
|
var img, i, j, data, bgr, cmap;
|
||||||
|
img = c_ctx.createImageData(width, height);
|
||||||
|
data = img.data;
|
||||||
|
cmap = conf.colourMap;
|
||||||
|
for (i=0, j=offset; i < (width * height * 4); i+=4, j+=1) {
|
||||||
|
bgr = cmap[arr[j]];
|
||||||
|
data[i ] = bgr[2];
|
||||||
|
data[i + 1] = bgr[1];
|
||||||
|
data[i + 2] = bgr[0];
|
||||||
|
data[i + 3] = 255; // Set Alpha
|
||||||
|
}
|
||||||
|
c_ctx.putImageData(img, x - vx, y - vy);
|
||||||
|
};
|
||||||
|
|
||||||
|
that.blitImage = function(x, y, width, height, arr, offset) {
|
||||||
|
if (conf.true_color) {
|
||||||
|
bgrxImageData(x, y, viewport.x, viewport.y, width, height, arr, offset);
|
||||||
|
} else {
|
||||||
|
cmapImageData(x, y, viewport.x, viewport.y, width, height, arr, offset);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
that.blitRgbImage = function(x, y, width, height, arr, offset) {
|
||||||
|
if (conf.true_color) {
|
||||||
|
rgbImageData(x, y, viewport.x, viewport.y, width, height, arr, offset);
|
||||||
|
} else {
|
||||||
|
// prolly wrong...
|
||||||
|
cmapImageData(x, y, viewport.x, viewport.y, width, height, arr, offset);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
that.blitStringImage = function(str, x, y) {
|
||||||
|
var img = new Image();
|
||||||
|
img.onload = function () {
|
||||||
|
c_ctx.drawImage(img, x - viewport.x, y - viewport.y);
|
||||||
|
};
|
||||||
|
img.src = str;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Wrap ctx.drawImage but relative to viewport
|
||||||
|
that.drawImage = function(img, x, y) {
|
||||||
|
c_ctx.drawImage(img, x - viewport.x, y - viewport.y);
|
||||||
|
};
|
||||||
|
|
||||||
|
that.renderQ_push = function(action) {
|
||||||
|
renderQ.push(action);
|
||||||
|
if (renderQ.length === 1) {
|
||||||
|
// If this can be rendered immediately it will be, otherwise
|
||||||
|
// the scanner will start polling the queue (every
|
||||||
|
// requestAnimationFrame interval)
|
||||||
|
scan_renderQ();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
scan_renderQ = function() {
|
||||||
|
var a, ready = true;
|
||||||
|
while (ready && renderQ.length > 0) {
|
||||||
|
a = renderQ[0];
|
||||||
|
switch (a.type) {
|
||||||
|
case 'copy':
|
||||||
|
that.copyImage(a.old_x, a.old_y, a.x, a.y, a.width, a.height);
|
||||||
|
break;
|
||||||
|
case 'fill':
|
||||||
|
that.fillRect(a.x, a.y, a.width, a.height, a.color);
|
||||||
|
break;
|
||||||
|
case 'blit':
|
||||||
|
that.blitImage(a.x, a.y, a.width, a.height, a.data, 0);
|
||||||
|
break;
|
||||||
|
case 'blitRgb':
|
||||||
|
that.blitRgbImage(a.x, a.y, a.width, a.height, a.data, 0);
|
||||||
|
break;
|
||||||
|
case 'img':
|
||||||
|
if (a.img.complete) {
|
||||||
|
that.drawImage(a.img, a.x, a.y);
|
||||||
|
} else {
|
||||||
|
// We need to wait for this image to 'load'
|
||||||
|
// to keep things in-order
|
||||||
|
ready = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ready) {
|
||||||
|
a = renderQ.shift();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (renderQ.length > 0) {
|
||||||
|
requestAnimFrame(scan_renderQ);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
that.changeCursor = function(pixels, mask, hotx, hoty, w, h) {
|
||||||
|
if (conf.cursor_uri === false) {
|
||||||
|
Util.Warn("changeCursor called but no cursor data URI support");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conf.true_color) {
|
||||||
|
changeCursor(conf.target, pixels, mask, hotx, hoty, w, h);
|
||||||
|
} else {
|
||||||
|
changeCursor(conf.target, pixels, mask, hotx, hoty, w, h, conf.colourMap);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
that.defaultCursor = function() {
|
||||||
|
conf.target.style.cursor = "default";
|
||||||
|
};
|
||||||
|
|
||||||
|
return constructor(); // Return the public API interface
|
||||||
|
|
||||||
|
} // End of Display()
|
||||||
|
|
||||||
|
|
||||||
|
/* Set CSS cursor property using data URI encoded cursor file */
|
||||||
|
function changeCursor(target, pixels, mask, hotx, hoty, w0, h0, cmap) {
|
||||||
|
"use strict";
|
||||||
|
var cur = [], rgb, IHDRsz, RGBsz, ANDsz, XORsz, url, idx, alpha, x, y;
|
||||||
|
//Util.Debug(">> changeCursor, x: " + hotx + ", y: " + hoty + ", w0: " + w0 + ", h0: " + h0);
|
||||||
|
|
||||||
|
var w = w0;
|
||||||
|
var h = h0;
|
||||||
|
if (h < w)
|
||||||
|
h = w; // increase h to make it square
|
||||||
|
else
|
||||||
|
w = h; // increace w to make it square
|
||||||
|
|
||||||
|
// Push multi-byte little-endian values
|
||||||
|
cur.push16le = function (num) {
|
||||||
|
this.push((num ) & 0xFF,
|
||||||
|
(num >> 8) & 0xFF );
|
||||||
|
};
|
||||||
|
cur.push32le = function (num) {
|
||||||
|
this.push((num ) & 0xFF,
|
||||||
|
(num >> 8) & 0xFF,
|
||||||
|
(num >> 16) & 0xFF,
|
||||||
|
(num >> 24) & 0xFF );
|
||||||
|
};
|
||||||
|
|
||||||
|
IHDRsz = 40;
|
||||||
|
RGBsz = w * h * 4;
|
||||||
|
XORsz = Math.ceil( (w * h) / 8.0 );
|
||||||
|
ANDsz = Math.ceil( (w * h) / 8.0 );
|
||||||
|
|
||||||
|
// Main header
|
||||||
|
cur.push16le(0); // 0: Reserved
|
||||||
|
cur.push16le(2); // 2: .CUR type
|
||||||
|
cur.push16le(1); // 4: Number of images, 1 for non-animated ico
|
||||||
|
|
||||||
|
// Cursor #1 header (ICONDIRENTRY)
|
||||||
|
cur.push(w); // 6: width
|
||||||
|
cur.push(h); // 7: height
|
||||||
|
cur.push(0); // 8: colors, 0 -> true-color
|
||||||
|
cur.push(0); // 9: reserved
|
||||||
|
cur.push16le(hotx); // 10: hotspot x coordinate
|
||||||
|
cur.push16le(hoty); // 12: hotspot y coordinate
|
||||||
|
cur.push32le(IHDRsz + RGBsz + XORsz + ANDsz);
|
||||||
|
// 14: cursor data byte size
|
||||||
|
cur.push32le(22); // 18: offset of cursor data in the file
|
||||||
|
|
||||||
|
|
||||||
|
// Cursor #1 InfoHeader (ICONIMAGE/BITMAPINFO)
|
||||||
|
cur.push32le(IHDRsz); // 22: Infoheader size
|
||||||
|
cur.push32le(w); // 26: Cursor width
|
||||||
|
cur.push32le(h*2); // 30: XOR+AND height
|
||||||
|
cur.push16le(1); // 34: number of planes
|
||||||
|
cur.push16le(32); // 36: bits per pixel
|
||||||
|
cur.push32le(0); // 38: Type of compression
|
||||||
|
|
||||||
|
cur.push32le(XORsz + ANDsz); // 43: Size of Image
|
||||||
|
// Gimp leaves this as 0
|
||||||
|
|
||||||
|
cur.push32le(0); // 46: reserved
|
||||||
|
cur.push32le(0); // 50: reserved
|
||||||
|
cur.push32le(0); // 54: reserved
|
||||||
|
cur.push32le(0); // 58: reserved
|
||||||
|
|
||||||
|
// 62: color data (RGBQUAD icColors[])
|
||||||
|
for (y = h-1; y >= 0; y -= 1) {
|
||||||
|
for (x = 0; x < w; x += 1) {
|
||||||
|
if (x >= w0 || y >= h0) {
|
||||||
|
cur.push(0); // blue
|
||||||
|
cur.push(0); // green
|
||||||
|
cur.push(0); // red
|
||||||
|
cur.push(0); // alpha
|
||||||
|
} else {
|
||||||
|
idx = y * Math.ceil(w0 / 8) + Math.floor(x/8);
|
||||||
|
alpha = (mask[idx] << (x % 8)) & 0x80 ? 255 : 0;
|
||||||
|
if (cmap) {
|
||||||
|
idx = (w0 * y) + x;
|
||||||
|
rgb = cmap[pixels[idx]];
|
||||||
|
cur.push(rgb[2]); // blue
|
||||||
|
cur.push(rgb[1]); // green
|
||||||
|
cur.push(rgb[0]); // red
|
||||||
|
cur.push(alpha); // alpha
|
||||||
|
} else {
|
||||||
|
idx = ((w0 * y) + x) * 4;
|
||||||
|
cur.push(pixels[idx + 2]); // blue
|
||||||
|
cur.push(pixels[idx + 1]); // green
|
||||||
|
cur.push(pixels[idx ]); // red
|
||||||
|
cur.push(alpha); // alpha
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// XOR/bitmask data (BYTE icXOR[])
|
||||||
|
// (ignored, just needs to be right size)
|
||||||
|
for (y = 0; y < h; y += 1) {
|
||||||
|
for (x = 0; x < Math.ceil(w / 8); x += 1) {
|
||||||
|
cur.push(0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AND/bitmask data (BYTE icAND[])
|
||||||
|
// (ignored, just needs to be right size)
|
||||||
|
for (y = 0; y < h; y += 1) {
|
||||||
|
for (x = 0; x < Math.ceil(w / 8); x += 1) {
|
||||||
|
cur.push(0x00);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url = "data:image/x-icon;base64," + Base64.encode(cur);
|
||||||
|
target.style.cursor = "url(" + url + ") " + hotx + " " + hoty + ", default";
|
||||||
|
//Util.Debug("<< changeCursor, cur.length: " + cur.length);
|
||||||
|
}
|
1946
static/js/novnc/input.js
Normal file
1946
static/js/novnc/input.js
Normal file
File diff suppressed because it is too large
Load diff
676
static/js/novnc/jsunzip.js
Executable file
676
static/js/novnc/jsunzip.js
Executable file
|
@ -0,0 +1,676 @@
|
||||||
|
/*
|
||||||
|
* JSUnzip
|
||||||
|
*
|
||||||
|
* Copyright (c) 2011 by Erik Moller
|
||||||
|
* All Rights Reserved
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express
|
||||||
|
* or implied warranty. In no event will the authors be
|
||||||
|
* held liable for any damages arising from the use of
|
||||||
|
* this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software
|
||||||
|
* for any purpose, including commercial applications,
|
||||||
|
* and to alter it and redistribute it freely, subject to
|
||||||
|
* the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be
|
||||||
|
* misrepresented; you must not claim that you
|
||||||
|
* wrote the original software. If you use this
|
||||||
|
* software in a product, an acknowledgment in
|
||||||
|
* the product documentation would be appreciated
|
||||||
|
* but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked
|
||||||
|
* as such, and must not be misrepresented as
|
||||||
|
* being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from
|
||||||
|
* any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var tinf;
|
||||||
|
|
||||||
|
function JSUnzip() {
|
||||||
|
|
||||||
|
this.getInt = function(offset, size) {
|
||||||
|
switch (size) {
|
||||||
|
case 4:
|
||||||
|
return (this.data.charCodeAt(offset + 3) & 0xff) << 24 |
|
||||||
|
(this.data.charCodeAt(offset + 2) & 0xff) << 16 |
|
||||||
|
(this.data.charCodeAt(offset + 1) & 0xff) << 8 |
|
||||||
|
(this.data.charCodeAt(offset + 0) & 0xff);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
return (this.data.charCodeAt(offset + 1) & 0xff) << 8 |
|
||||||
|
(this.data.charCodeAt(offset + 0) & 0xff);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return this.data.charCodeAt(offset) & 0xff;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.getDOSDate = function(dosdate, dostime) {
|
||||||
|
var day = dosdate & 0x1f;
|
||||||
|
var month = ((dosdate >> 5) & 0xf) - 1;
|
||||||
|
var year = 1980 + ((dosdate >> 9) & 0x7f)
|
||||||
|
var second = (dostime & 0x1f) * 2;
|
||||||
|
var minute = (dostime >> 5) & 0x3f;
|
||||||
|
hour = (dostime >> 11) & 0x1f;
|
||||||
|
return new Date(year, month, day, hour, minute, second);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.open = function(data) {
|
||||||
|
this.data = data;
|
||||||
|
this.files = [];
|
||||||
|
|
||||||
|
if (this.data.length < 22)
|
||||||
|
return { 'status' : false, 'error' : 'Invalid data' };
|
||||||
|
var endOfCentralDirectory = this.data.length - 22;
|
||||||
|
while (endOfCentralDirectory >= 0 && this.getInt(endOfCentralDirectory, 4) != 0x06054b50)
|
||||||
|
--endOfCentralDirectory;
|
||||||
|
if (endOfCentralDirectory < 0)
|
||||||
|
return { 'status' : false, 'error' : 'Invalid data' };
|
||||||
|
if (this.getInt(endOfCentralDirectory + 4, 2) != 0 || this.getInt(endOfCentralDirectory + 6, 2) != 0)
|
||||||
|
return { 'status' : false, 'error' : 'No multidisk support' };
|
||||||
|
|
||||||
|
var entriesInThisDisk = this.getInt(endOfCentralDirectory + 8, 2);
|
||||||
|
var centralDirectoryOffset = this.getInt(endOfCentralDirectory + 16, 4);
|
||||||
|
var globalCommentLength = this.getInt(endOfCentralDirectory + 20, 2);
|
||||||
|
this.comment = this.data.slice(endOfCentralDirectory + 22, endOfCentralDirectory + 22 + globalCommentLength);
|
||||||
|
|
||||||
|
var fileOffset = centralDirectoryOffset;
|
||||||
|
|
||||||
|
for (var i = 0; i < entriesInThisDisk; ++i) {
|
||||||
|
if (this.getInt(fileOffset + 0, 4) != 0x02014b50)
|
||||||
|
return { 'status' : false, 'error' : 'Invalid data' };
|
||||||
|
if (this.getInt(fileOffset + 6, 2) > 20)
|
||||||
|
return { 'status' : false, 'error' : 'Unsupported version' };
|
||||||
|
if (this.getInt(fileOffset + 8, 2) & 1)
|
||||||
|
return { 'status' : false, 'error' : 'Encryption not implemented' };
|
||||||
|
|
||||||
|
var compressionMethod = this.getInt(fileOffset + 10, 2);
|
||||||
|
if (compressionMethod != 0 && compressionMethod != 8)
|
||||||
|
return { 'status' : false, 'error' : 'Unsupported compression method' };
|
||||||
|
|
||||||
|
var lastModFileTime = this.getInt(fileOffset + 12, 2);
|
||||||
|
var lastModFileDate = this.getInt(fileOffset + 14, 2);
|
||||||
|
var lastModifiedDate = this.getDOSDate(lastModFileDate, lastModFileTime);
|
||||||
|
|
||||||
|
var crc = this.getInt(fileOffset + 16, 4);
|
||||||
|
// TODO: crc
|
||||||
|
|
||||||
|
var compressedSize = this.getInt(fileOffset + 20, 4);
|
||||||
|
var uncompressedSize = this.getInt(fileOffset + 24, 4);
|
||||||
|
|
||||||
|
var fileNameLength = this.getInt(fileOffset + 28, 2);
|
||||||
|
var extraFieldLength = this.getInt(fileOffset + 30, 2);
|
||||||
|
var fileCommentLength = this.getInt(fileOffset + 32, 2);
|
||||||
|
|
||||||
|
var relativeOffsetOfLocalHeader = this.getInt(fileOffset + 42, 4);
|
||||||
|
|
||||||
|
var fileName = this.data.slice(fileOffset + 46, fileOffset + 46 + fileNameLength);
|
||||||
|
var fileComment = this.data.slice(fileOffset + 46 + fileNameLength + extraFieldLength, fileOffset + 46 + fileNameLength + extraFieldLength + fileCommentLength);
|
||||||
|
|
||||||
|
if (this.getInt(relativeOffsetOfLocalHeader + 0, 4) != 0x04034b50)
|
||||||
|
return { 'status' : false, 'error' : 'Invalid data' };
|
||||||
|
var localFileNameLength = this.getInt(relativeOffsetOfLocalHeader + 26, 2);
|
||||||
|
var localExtraFieldLength = this.getInt(relativeOffsetOfLocalHeader + 28, 2);
|
||||||
|
var localFileContent = relativeOffsetOfLocalHeader + 30 + localFileNameLength + localExtraFieldLength;
|
||||||
|
|
||||||
|
this.files[fileName] =
|
||||||
|
{
|
||||||
|
'fileComment' : fileComment,
|
||||||
|
'compressionMethod' : compressionMethod,
|
||||||
|
'compressedSize' : compressedSize,
|
||||||
|
'uncompressedSize' : uncompressedSize,
|
||||||
|
'localFileContent' : localFileContent,
|
||||||
|
'lastModifiedDate' : lastModifiedDate
|
||||||
|
};
|
||||||
|
|
||||||
|
fileOffset += 46 + fileNameLength + extraFieldLength + fileCommentLength;
|
||||||
|
}
|
||||||
|
return { 'status' : true }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.read = function(fileName) {
|
||||||
|
var fileInfo = this.files[fileName];
|
||||||
|
if (fileInfo) {
|
||||||
|
if (fileInfo.compressionMethod == 8) {
|
||||||
|
if (!tinf) {
|
||||||
|
tinf = new TINF();
|
||||||
|
tinf.init();
|
||||||
|
}
|
||||||
|
var result = tinf.uncompress(this.data, fileInfo.localFileContent);
|
||||||
|
if (result.status == tinf.OK)
|
||||||
|
return { 'status' : true, 'data' : result.data };
|
||||||
|
else
|
||||||
|
return { 'status' : false, 'error' : result.error };
|
||||||
|
} else {
|
||||||
|
return { 'status' : true, 'data' : this.data.slice(fileInfo.localFileContent, fileInfo.localFileContent + fileInfo.uncompressedSize) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { 'status' : false, 'error' : "File '" + fileName + "' doesn't exist in zip" };
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* tinflate - tiny inflate
|
||||||
|
*
|
||||||
|
* Copyright (c) 2003 by Joergen Ibsen / Jibz
|
||||||
|
* All Rights Reserved
|
||||||
|
*
|
||||||
|
* http://www.ibsensoftware.com/
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express
|
||||||
|
* or implied warranty. In no event will the authors be
|
||||||
|
* held liable for any damages arising from the use of
|
||||||
|
* this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software
|
||||||
|
* for any purpose, including commercial applications,
|
||||||
|
* and to alter it and redistribute it freely, subject to
|
||||||
|
* the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be
|
||||||
|
* misrepresented; you must not claim that you
|
||||||
|
* wrote the original software. If you use this
|
||||||
|
* software in a product, an acknowledgment in
|
||||||
|
* the product documentation would be appreciated
|
||||||
|
* but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked
|
||||||
|
* as such, and must not be misrepresented as
|
||||||
|
* being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from
|
||||||
|
* any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* tinflate javascript port by Erik Moller in May 2011.
|
||||||
|
* emoller@opera.com
|
||||||
|
*
|
||||||
|
* read_bits() patched by mike@imidio.com to allow
|
||||||
|
* reading more then 8 bits (needed in some zlib streams)
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function TINF() {
|
||||||
|
|
||||||
|
this.OK = 0;
|
||||||
|
this.DATA_ERROR = (-3);
|
||||||
|
this.WINDOW_SIZE = 32768;
|
||||||
|
|
||||||
|
/* ------------------------------ *
|
||||||
|
* -- internal data structures -- *
|
||||||
|
* ------------------------------ */
|
||||||
|
|
||||||
|
this.TREE = function() {
|
||||||
|
this.table = new Array(16); /* table of code length counts */
|
||||||
|
this.trans = new Array(288); /* code -> symbol translation table */
|
||||||
|
};
|
||||||
|
|
||||||
|
this.DATA = function(that) {
|
||||||
|
this.source = '';
|
||||||
|
this.sourceIndex = 0;
|
||||||
|
this.tag = 0;
|
||||||
|
this.bitcount = 0;
|
||||||
|
|
||||||
|
this.dest = [];
|
||||||
|
|
||||||
|
this.history = [];
|
||||||
|
|
||||||
|
this.ltree = new that.TREE(); /* dynamic length/symbol tree */
|
||||||
|
this.dtree = new that.TREE(); /* dynamic distance tree */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* --------------------------------------------------- *
|
||||||
|
* -- uninitialized global data (static structures) -- *
|
||||||
|
* --------------------------------------------------- */
|
||||||
|
|
||||||
|
this.sltree = new this.TREE(); /* fixed length/symbol tree */
|
||||||
|
this.sdtree = new this.TREE(); /* fixed distance tree */
|
||||||
|
|
||||||
|
/* extra bits and base tables for length codes */
|
||||||
|
this.length_bits = new Array(30);
|
||||||
|
this.length_base = new Array(30);
|
||||||
|
|
||||||
|
/* extra bits and base tables for distance codes */
|
||||||
|
this.dist_bits = new Array(30);
|
||||||
|
this.dist_base = new Array(30);
|
||||||
|
|
||||||
|
/* special ordering of code length codes */
|
||||||
|
this.clcidx = [
|
||||||
|
16, 17, 18, 0, 8, 7, 9, 6,
|
||||||
|
10, 5, 11, 4, 12, 3, 13, 2,
|
||||||
|
14, 1, 15
|
||||||
|
];
|
||||||
|
|
||||||
|
/* ----------------------- *
|
||||||
|
* -- utility functions -- *
|
||||||
|
* ----------------------- */
|
||||||
|
|
||||||
|
/* build extra bits and base tables */
|
||||||
|
this.build_bits_base = function(bits, base, delta, first)
|
||||||
|
{
|
||||||
|
var i, sum;
|
||||||
|
|
||||||
|
/* build bits table */
|
||||||
|
for (i = 0; i < delta; ++i) bits[i] = 0;
|
||||||
|
for (i = 0; i < 30 - delta; ++i) bits[i + delta] = Math.floor(i / delta);
|
||||||
|
|
||||||
|
/* build base table */
|
||||||
|
for (sum = first, i = 0; i < 30; ++i)
|
||||||
|
{
|
||||||
|
base[i] = sum;
|
||||||
|
sum += 1 << bits[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* build the fixed huffman trees */
|
||||||
|
this.build_fixed_trees = function(lt, dt)
|
||||||
|
{
|
||||||
|
var i;
|
||||||
|
|
||||||
|
/* build fixed length tree */
|
||||||
|
for (i = 0; i < 7; ++i) lt.table[i] = 0;
|
||||||
|
|
||||||
|
lt.table[7] = 24;
|
||||||
|
lt.table[8] = 152;
|
||||||
|
lt.table[9] = 112;
|
||||||
|
|
||||||
|
for (i = 0; i < 24; ++i) lt.trans[i] = 256 + i;
|
||||||
|
for (i = 0; i < 144; ++i) lt.trans[24 + i] = i;
|
||||||
|
for (i = 0; i < 8; ++i) lt.trans[24 + 144 + i] = 280 + i;
|
||||||
|
for (i = 0; i < 112; ++i) lt.trans[24 + 144 + 8 + i] = 144 + i;
|
||||||
|
|
||||||
|
/* build fixed distance tree */
|
||||||
|
for (i = 0; i < 5; ++i) dt.table[i] = 0;
|
||||||
|
|
||||||
|
dt.table[5] = 32;
|
||||||
|
|
||||||
|
for (i = 0; i < 32; ++i) dt.trans[i] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* given an array of code lengths, build a tree */
|
||||||
|
this.build_tree = function(t, lengths, loffset, num)
|
||||||
|
{
|
||||||
|
var offs = new Array(16);
|
||||||
|
var i, sum;
|
||||||
|
|
||||||
|
/* clear code length count table */
|
||||||
|
for (i = 0; i < 16; ++i) t.table[i] = 0;
|
||||||
|
|
||||||
|
/* scan symbol lengths, and sum code length counts */
|
||||||
|
for (i = 0; i < num; ++i) t.table[lengths[loffset + i]]++;
|
||||||
|
|
||||||
|
t.table[0] = 0;
|
||||||
|
|
||||||
|
/* compute offset table for distribution sort */
|
||||||
|
for (sum = 0, i = 0; i < 16; ++i)
|
||||||
|
{
|
||||||
|
offs[i] = sum;
|
||||||
|
sum += t.table[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* create code->symbol translation table (symbols sorted by code) */
|
||||||
|
for (i = 0; i < num; ++i)
|
||||||
|
{
|
||||||
|
if (lengths[loffset + i]) t.trans[offs[lengths[loffset + i]]++] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------- *
|
||||||
|
* -- decode functions -- *
|
||||||
|
* ---------------------- */
|
||||||
|
|
||||||
|
/* get one bit from source stream */
|
||||||
|
this.getbit = function(d)
|
||||||
|
{
|
||||||
|
var bit;
|
||||||
|
|
||||||
|
/* check if tag is empty */
|
||||||
|
if (!d.bitcount--)
|
||||||
|
{
|
||||||
|
/* load next tag */
|
||||||
|
d.tag = d.source[d.sourceIndex++] & 0xff;
|
||||||
|
d.bitcount = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* shift bit out of tag */
|
||||||
|
bit = d.tag & 0x01;
|
||||||
|
d.tag >>= 1;
|
||||||
|
|
||||||
|
return bit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* read a num bit value from a stream and add base */
|
||||||
|
function read_bits_direct(source, bitcount, tag, idx, num)
|
||||||
|
{
|
||||||
|
var val = 0;
|
||||||
|
while (bitcount < 24) {
|
||||||
|
tag = tag | (source[idx++] & 0xff) << bitcount;
|
||||||
|
bitcount += 8;
|
||||||
|
}
|
||||||
|
val = tag & (0xffff >> (16 - num));
|
||||||
|
tag >>= num;
|
||||||
|
bitcount -= num;
|
||||||
|
return [bitcount, tag, idx, val];
|
||||||
|
}
|
||||||
|
this.read_bits = function(d, num, base)
|
||||||
|
{
|
||||||
|
if (!num)
|
||||||
|
return base;
|
||||||
|
|
||||||
|
var ret = read_bits_direct(d.source, d.bitcount, d.tag, d.sourceIndex, num);
|
||||||
|
d.bitcount = ret[0];
|
||||||
|
d.tag = ret[1];
|
||||||
|
d.sourceIndex = ret[2];
|
||||||
|
return ret[3] + base;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* given a data stream and a tree, decode a symbol */
|
||||||
|
this.decode_symbol = function(d, t)
|
||||||
|
{
|
||||||
|
while (d.bitcount < 16) {
|
||||||
|
d.tag = d.tag | (d.source[d.sourceIndex++] & 0xff) << d.bitcount;
|
||||||
|
d.bitcount += 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
var sum = 0, cur = 0, len = 0;
|
||||||
|
do {
|
||||||
|
cur = 2 * cur + ((d.tag & (1 << len)) >> len);
|
||||||
|
|
||||||
|
++len;
|
||||||
|
|
||||||
|
sum += t.table[len];
|
||||||
|
cur -= t.table[len];
|
||||||
|
|
||||||
|
} while (cur >= 0);
|
||||||
|
|
||||||
|
d.tag >>= len;
|
||||||
|
d.bitcount -= len;
|
||||||
|
|
||||||
|
return t.trans[sum + cur];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* given a data stream, decode dynamic trees from it */
|
||||||
|
this.decode_trees = function(d, lt, dt)
|
||||||
|
{
|
||||||
|
var code_tree = new this.TREE();
|
||||||
|
var lengths = new Array(288+32);
|
||||||
|
var hlit, hdist, hclen;
|
||||||
|
var i, num, length;
|
||||||
|
|
||||||
|
/* get 5 bits HLIT (257-286) */
|
||||||
|
hlit = this.read_bits(d, 5, 257);
|
||||||
|
|
||||||
|
/* get 5 bits HDIST (1-32) */
|
||||||
|
hdist = this.read_bits(d, 5, 1);
|
||||||
|
|
||||||
|
/* get 4 bits HCLEN (4-19) */
|
||||||
|
hclen = this.read_bits(d, 4, 4);
|
||||||
|
|
||||||
|
for (i = 0; i < 19; ++i) lengths[i] = 0;
|
||||||
|
|
||||||
|
/* read code lengths for code length alphabet */
|
||||||
|
for (i = 0; i < hclen; ++i)
|
||||||
|
{
|
||||||
|
/* get 3 bits code length (0-7) */
|
||||||
|
var clen = this.read_bits(d, 3, 0);
|
||||||
|
|
||||||
|
lengths[this.clcidx[i]] = clen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* build code length tree */
|
||||||
|
this.build_tree(code_tree, lengths, 0, 19);
|
||||||
|
|
||||||
|
/* decode code lengths for the dynamic trees */
|
||||||
|
for (num = 0; num < hlit + hdist; )
|
||||||
|
{
|
||||||
|
var sym = this.decode_symbol(d, code_tree);
|
||||||
|
|
||||||
|
switch (sym)
|
||||||
|
{
|
||||||
|
case 16:
|
||||||
|
/* copy previous code length 3-6 times (read 2 bits) */
|
||||||
|
{
|
||||||
|
var prev = lengths[num - 1];
|
||||||
|
for (length = this.read_bits(d, 2, 3); length; --length)
|
||||||
|
{
|
||||||
|
lengths[num++] = prev;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 17:
|
||||||
|
/* repeat code length 0 for 3-10 times (read 3 bits) */
|
||||||
|
for (length = this.read_bits(d, 3, 3); length; --length)
|
||||||
|
{
|
||||||
|
lengths[num++] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 18:
|
||||||
|
/* repeat code length 0 for 11-138 times (read 7 bits) */
|
||||||
|
for (length = this.read_bits(d, 7, 11); length; --length)
|
||||||
|
{
|
||||||
|
lengths[num++] = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* values 0-15 represent the actual code lengths */
|
||||||
|
lengths[num++] = sym;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* build dynamic trees */
|
||||||
|
this.build_tree(lt, lengths, 0, hlit);
|
||||||
|
this.build_tree(dt, lengths, hlit, hdist);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------- *
|
||||||
|
* -- block inflate functions -- *
|
||||||
|
* ----------------------------- */
|
||||||
|
|
||||||
|
/* given a stream and two trees, inflate a block of data */
|
||||||
|
this.inflate_block_data = function(d, lt, dt)
|
||||||
|
{
|
||||||
|
// js optimization.
|
||||||
|
var ddest = d.dest;
|
||||||
|
var ddestlength = ddest.length;
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
var sym = this.decode_symbol(d, lt);
|
||||||
|
|
||||||
|
/* check for end of block */
|
||||||
|
if (sym == 256)
|
||||||
|
{
|
||||||
|
return this.OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sym < 256)
|
||||||
|
{
|
||||||
|
ddest[ddestlength++] = sym; // ? String.fromCharCode(sym);
|
||||||
|
d.history.push(sym);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
var length, dist, offs;
|
||||||
|
var i;
|
||||||
|
|
||||||
|
sym -= 257;
|
||||||
|
|
||||||
|
/* possibly get more bits from length code */
|
||||||
|
length = this.read_bits(d, this.length_bits[sym], this.length_base[sym]);
|
||||||
|
|
||||||
|
dist = this.decode_symbol(d, dt);
|
||||||
|
|
||||||
|
/* possibly get more bits from distance code */
|
||||||
|
offs = d.history.length - this.read_bits(d, this.dist_bits[dist], this.dist_base[dist]);
|
||||||
|
|
||||||
|
if (offs < 0)
|
||||||
|
throw ("Invalid zlib offset " + offs);
|
||||||
|
|
||||||
|
/* copy match */
|
||||||
|
for (i = offs; i < offs + length; ++i) {
|
||||||
|
//ddest[ddestlength++] = ddest[i];
|
||||||
|
ddest[ddestlength++] = d.history[i];
|
||||||
|
d.history.push(d.history[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* inflate an uncompressed block of data */
|
||||||
|
this.inflate_uncompressed_block = function(d)
|
||||||
|
{
|
||||||
|
var length, invlength;
|
||||||
|
var i;
|
||||||
|
|
||||||
|
if (d.bitcount > 7) {
|
||||||
|
var overflow = Math.floor(d.bitcount / 8);
|
||||||
|
d.sourceIndex -= overflow;
|
||||||
|
d.bitcount = 0;
|
||||||
|
d.tag = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* get length */
|
||||||
|
length = d.source[d.sourceIndex+1];
|
||||||
|
length = 256*length + d.source[d.sourceIndex];
|
||||||
|
|
||||||
|
/* get one's complement of length */
|
||||||
|
invlength = d.source[d.sourceIndex+3];
|
||||||
|
invlength = 256*invlength + d.source[d.sourceIndex+2];
|
||||||
|
|
||||||
|
/* check length */
|
||||||
|
if (length != (~invlength & 0x0000ffff)) return this.DATA_ERROR;
|
||||||
|
|
||||||
|
d.sourceIndex += 4;
|
||||||
|
|
||||||
|
/* copy block */
|
||||||
|
for (i = length; i; --i) {
|
||||||
|
d.history.push(d.source[d.sourceIndex]);
|
||||||
|
d.dest[d.dest.length] = d.source[d.sourceIndex++];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* make sure we start next block on a byte boundary */
|
||||||
|
d.bitcount = 0;
|
||||||
|
|
||||||
|
return this.OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* inflate a block of data compressed with fixed huffman trees */
|
||||||
|
this.inflate_fixed_block = function(d)
|
||||||
|
{
|
||||||
|
/* decode block using fixed trees */
|
||||||
|
return this.inflate_block_data(d, this.sltree, this.sdtree);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* inflate a block of data compressed with dynamic huffman trees */
|
||||||
|
this.inflate_dynamic_block = function(d)
|
||||||
|
{
|
||||||
|
/* decode trees from stream */
|
||||||
|
this.decode_trees(d, d.ltree, d.dtree);
|
||||||
|
|
||||||
|
/* decode block using decoded trees */
|
||||||
|
return this.inflate_block_data(d, d.ltree, d.dtree);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------- *
|
||||||
|
* -- public functions -- *
|
||||||
|
* ---------------------- */
|
||||||
|
|
||||||
|
/* initialize global (static) data */
|
||||||
|
this.init = function()
|
||||||
|
{
|
||||||
|
/* build fixed huffman trees */
|
||||||
|
this.build_fixed_trees(this.sltree, this.sdtree);
|
||||||
|
|
||||||
|
/* build extra bits and base tables */
|
||||||
|
this.build_bits_base(this.length_bits, this.length_base, 4, 3);
|
||||||
|
this.build_bits_base(this.dist_bits, this.dist_base, 2, 1);
|
||||||
|
|
||||||
|
/* fix a special case */
|
||||||
|
this.length_bits[28] = 0;
|
||||||
|
this.length_base[28] = 258;
|
||||||
|
|
||||||
|
this.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.reset = function()
|
||||||
|
{
|
||||||
|
this.d = new this.DATA(this);
|
||||||
|
delete this.header;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* inflate stream from source to dest */
|
||||||
|
this.uncompress = function(source, offset)
|
||||||
|
{
|
||||||
|
|
||||||
|
var d = this.d;
|
||||||
|
var bfinal;
|
||||||
|
|
||||||
|
/* initialise data */
|
||||||
|
d.source = source;
|
||||||
|
d.sourceIndex = offset;
|
||||||
|
d.bitcount = 0;
|
||||||
|
|
||||||
|
d.dest = [];
|
||||||
|
|
||||||
|
// Skip zlib header at start of stream
|
||||||
|
if (typeof this.header == 'undefined') {
|
||||||
|
this.header = this.read_bits(d, 16, 0);
|
||||||
|
/* byte 0: 0x78, 7 = 32k window size, 8 = deflate */
|
||||||
|
/* byte 1: check bits for header and other flags */
|
||||||
|
}
|
||||||
|
|
||||||
|
var blocks = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
var btype;
|
||||||
|
var res;
|
||||||
|
|
||||||
|
/* read final block flag */
|
||||||
|
bfinal = this.getbit(d);
|
||||||
|
|
||||||
|
/* read block type (2 bits) */
|
||||||
|
btype = this.read_bits(d, 2, 0);
|
||||||
|
|
||||||
|
/* decompress block */
|
||||||
|
switch (btype)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
/* decompress uncompressed block */
|
||||||
|
res = this.inflate_uncompressed_block(d);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
/* decompress block with fixed huffman trees */
|
||||||
|
res = this.inflate_fixed_block(d);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
/* decompress block with dynamic huffman trees */
|
||||||
|
res = this.inflate_dynamic_block(d);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return { 'status' : this.DATA_ERROR };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res != this.OK) return { 'status' : this.DATA_ERROR };
|
||||||
|
blocks++;
|
||||||
|
|
||||||
|
} while (!bfinal && d.sourceIndex < d.source.length);
|
||||||
|
|
||||||
|
d.history = d.history.slice(-this.WINDOW_SIZE);
|
||||||
|
|
||||||
|
return { 'status' : this.OK, 'data' : d.dest };
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
1
static/js/novnc/logo.js
Normal file
1
static/js/novnc/logo.js
Normal file
File diff suppressed because one or more lines are too long
102
static/js/novnc/playback.js
Normal file
102
static/js/novnc/playback.js
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
* noVNC: HTML5 VNC client
|
||||||
|
* Copyright (C) 2012 Joel Martin
|
||||||
|
* Licensed under MPL 2.0 (see LICENSE.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
/*jslint browser: true, white: false */
|
||||||
|
/*global Util, VNC_frame_data, finish */
|
||||||
|
|
||||||
|
var rfb, mode, test_state, frame_idx, frame_length,
|
||||||
|
iteration, iterations, istart_time,
|
||||||
|
|
||||||
|
// Pre-declarations for jslint
|
||||||
|
send_array, next_iteration, queue_next_packet, do_packet;
|
||||||
|
|
||||||
|
// Override send_array
|
||||||
|
send_array = function (arr) {
|
||||||
|
// Stub out send_array
|
||||||
|
};
|
||||||
|
|
||||||
|
next_iteration = function () {
|
||||||
|
if (iteration === 0) {
|
||||||
|
frame_length = VNC_frame_data.length;
|
||||||
|
test_state = 'running';
|
||||||
|
} else {
|
||||||
|
rfb.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (test_state !== 'running') { return; }
|
||||||
|
|
||||||
|
iteration += 1;
|
||||||
|
if (iteration > iterations) {
|
||||||
|
finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
frame_idx = 0;
|
||||||
|
istart_time = (new Date()).getTime();
|
||||||
|
rfb.connect('test', 0, "bogus");
|
||||||
|
|
||||||
|
queue_next_packet();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
queue_next_packet = function () {
|
||||||
|
var frame, foffset, toffset, delay;
|
||||||
|
if (test_state !== 'running') { return; }
|
||||||
|
|
||||||
|
frame = VNC_frame_data[frame_idx];
|
||||||
|
while ((frame_idx < frame_length) && (frame.charAt(0) === "}")) {
|
||||||
|
//Util.Debug("Send frame " + frame_idx);
|
||||||
|
frame_idx += 1;
|
||||||
|
frame = VNC_frame_data[frame_idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame === 'EOF') {
|
||||||
|
Util.Debug("Finished, found EOF");
|
||||||
|
next_iteration();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (frame_idx >= frame_length) {
|
||||||
|
Util.Debug("Finished, no more frames");
|
||||||
|
next_iteration();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode === 'realtime') {
|
||||||
|
foffset = frame.slice(1, frame.indexOf('{', 1));
|
||||||
|
toffset = (new Date()).getTime() - istart_time;
|
||||||
|
delay = foffset - toffset;
|
||||||
|
if (delay < 1) {
|
||||||
|
delay = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(do_packet, delay);
|
||||||
|
} else {
|
||||||
|
setTimeout(do_packet, 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var bytes_processed = 0;
|
||||||
|
|
||||||
|
do_packet = function () {
|
||||||
|
//Util.Debug("Processing frame: " + frame_idx);
|
||||||
|
var frame = VNC_frame_data[frame_idx],
|
||||||
|
start = frame.indexOf('{', 1) + 1;
|
||||||
|
bytes_processed += frame.length - start;
|
||||||
|
if (VNC_frame_encoding === 'binary') {
|
||||||
|
var u8 = new Uint8Array(frame.length - start);
|
||||||
|
for (var i = 0; i < frame.length - start; i++) {
|
||||||
|
u8[i] = frame.charCodeAt(start + i);
|
||||||
|
}
|
||||||
|
rfb.recv_message({'data' : u8});
|
||||||
|
} else {
|
||||||
|
rfb.recv_message({'data' : frame.slice(start)});
|
||||||
|
}
|
||||||
|
frame_idx += 1;
|
||||||
|
|
||||||
|
queue_next_packet();
|
||||||
|
};
|
||||||
|
|
1866
static/js/novnc/rfb.js
Normal file
1866
static/js/novnc/rfb.js
Normal file
File diff suppressed because it is too large
Load diff
712
static/js/novnc/ui.js
Normal file
712
static/js/novnc/ui.js
Normal file
|
@ -0,0 +1,712 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
/*jslint white: false, browser: true */
|
||||||
|
/*global window, $D, Util, WebUtil, RFB, Display */
|
||||||
|
|
||||||
|
// Load supporting scripts
|
||||||
|
window.onscriptsload = function () { UI.load(); };
|
||||||
|
Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
|
||||||
|
"input.js", "display.js", "jsunzip.js", "rfb.js"]);
|
||||||
|
|
||||||
|
var UI = {
|
||||||
|
|
||||||
|
rfb_state : 'loaded',
|
||||||
|
settingsOpen : false,
|
||||||
|
connSettingsOpen : false,
|
||||||
|
clipboardOpen: false,
|
||||||
|
keyboardVisible: false,
|
||||||
|
|
||||||
|
// Setup rfb object, load settings from browser storage, then call
|
||||||
|
// UI.init to setup the UI/menus
|
||||||
|
load: function (callback) {
|
||||||
|
WebUtil.initSettings(UI.start, callback);
|
||||||
|
},
|
||||||
|
|
||||||
|
// Render default UI and initialize settings menu
|
||||||
|
start: function(callback) {
|
||||||
|
var html = '', i, sheet, sheets, llevels;
|
||||||
|
|
||||||
|
// Stylesheet selection dropdown
|
||||||
|
sheet = WebUtil.selectStylesheet();
|
||||||
|
sheets = WebUtil.getStylesheets();
|
||||||
|
for (i = 0; i < sheets.length; i += 1) {
|
||||||
|
UI.addOption($D('noVNC_stylesheet'),sheets[i].title, sheets[i].title);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logging selection dropdown
|
||||||
|
llevels = ['error', 'warn', 'info', 'debug'];
|
||||||
|
for (i = 0; i < llevels.length; i += 1) {
|
||||||
|
UI.addOption($D('noVNC_logging'),llevels[i], llevels[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Settings with immediate effects
|
||||||
|
UI.initSetting('logging', 'warn');
|
||||||
|
WebUtil.init_logging(UI.getSetting('logging'));
|
||||||
|
|
||||||
|
UI.initSetting('stylesheet', 'default');
|
||||||
|
WebUtil.selectStylesheet(null);
|
||||||
|
// call twice to get around webkit bug
|
||||||
|
WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
|
||||||
|
|
||||||
|
/* Populate the controls if defaults are provided in the URL */
|
||||||
|
UI.initSetting('host', window.location.hostname);
|
||||||
|
UI.initSetting('port', window.location.port);
|
||||||
|
UI.initSetting('password', '');
|
||||||
|
UI.initSetting('encrypt', (window.location.protocol === "https:"));
|
||||||
|
UI.initSetting('true_color', true);
|
||||||
|
UI.initSetting('cursor', false);
|
||||||
|
UI.initSetting('shared', true);
|
||||||
|
UI.initSetting('view_only', false);
|
||||||
|
UI.initSetting('connectTimeout', 2);
|
||||||
|
UI.initSetting('path', 'websockify');
|
||||||
|
UI.initSetting('repeaterID', '');
|
||||||
|
|
||||||
|
UI.rfb = RFB({'target': $D('noVNC_canvas'),
|
||||||
|
'onUpdateState': UI.updateState,
|
||||||
|
'onClipboard': UI.clipReceive});
|
||||||
|
UI.updateVisualState();
|
||||||
|
|
||||||
|
// Unfocus clipboard when over the VNC area
|
||||||
|
//$D('VNC_screen').onmousemove = function () {
|
||||||
|
// var keyboard = UI.rfb.get_keyboard();
|
||||||
|
// if ((! keyboard) || (! keyboard.get_focused())) {
|
||||||
|
// $D('VNC_clipboard_text').blur();
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// Show mouse selector buttons on touch screen devices
|
||||||
|
if ('ontouchstart' in document.documentElement) {
|
||||||
|
// Show mobile buttons
|
||||||
|
$D('noVNC_mobile_buttons').style.display = "inline";
|
||||||
|
UI.setMouseButton();
|
||||||
|
// Remove the address bar
|
||||||
|
setTimeout(function() { window.scrollTo(0, 1); }, 100);
|
||||||
|
UI.forceSetting('clip', true);
|
||||||
|
$D('noVNC_clip').disabled = true;
|
||||||
|
} else {
|
||||||
|
UI.initSetting('clip', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//iOS Safari does not support CSS position:fixed.
|
||||||
|
//This detects iOS devices and enables javascript workaround.
|
||||||
|
if ((navigator.userAgent.match(/iPhone/i)) ||
|
||||||
|
(navigator.userAgent.match(/iPod/i)) ||
|
||||||
|
(navigator.userAgent.match(/iPad/i))) {
|
||||||
|
//UI.setOnscroll();
|
||||||
|
//UI.setResize();
|
||||||
|
}
|
||||||
|
UI.setBarPosition();
|
||||||
|
|
||||||
|
$D('noVNC_host').focus();
|
||||||
|
|
||||||
|
UI.setViewClip();
|
||||||
|
Util.addEvent(window, 'resize', UI.setViewClip);
|
||||||
|
|
||||||
|
Util.addEvent(window, 'beforeunload', function () {
|
||||||
|
if (UI.rfb_state === 'normal') {
|
||||||
|
return "You are currently connected.";
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
// Show description by default when hosted at for kanaka.github.com
|
||||||
|
if (location.host === "kanaka.github.com") {
|
||||||
|
// Open the description dialog
|
||||||
|
$D('noVNC_description').style.display = "block";
|
||||||
|
} else {
|
||||||
|
// Open the connect panel on first load
|
||||||
|
UI.toggleConnectPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add mouse event click/focus/blur event handlers to the UI
|
||||||
|
UI.addMouseHandlers();
|
||||||
|
|
||||||
|
if (typeof callback === "function") {
|
||||||
|
callback(UI.rfb);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
addMouseHandlers: function() {
|
||||||
|
// Setup interface handlers that can't be inline
|
||||||
|
$D("noVNC_view_drag_button").onclick = UI.setViewDrag;
|
||||||
|
$D("noVNC_mouse_button0").onclick = function () { UI.setMouseButton(1); };
|
||||||
|
$D("noVNC_mouse_button1").onclick = function () { UI.setMouseButton(2); };
|
||||||
|
$D("noVNC_mouse_button2").onclick = function () { UI.setMouseButton(4); };
|
||||||
|
$D("noVNC_mouse_button4").onclick = function () { UI.setMouseButton(0); };
|
||||||
|
$D("showKeyboard").onclick = UI.showKeyboard;
|
||||||
|
//$D("keyboardinput").onkeydown = function (event) { onKeyDown(event); };
|
||||||
|
$D("keyboardinput").onblur = UI.keyInputBlur;
|
||||||
|
|
||||||
|
$D("sendCtrlAltDelButton").onclick = UI.sendCtrlAltDel;
|
||||||
|
$D("clipboardButton").onclick = UI.toggleClipboardPanel;
|
||||||
|
$D("settingsButton").onclick = UI.toggleSettingsPanel;
|
||||||
|
$D("connectButton").onclick = UI.toggleConnectPanel;
|
||||||
|
$D("disconnectButton").onclick = UI.disconnect;
|
||||||
|
$D("descriptionButton").onclick = UI.toggleConnectPanel;
|
||||||
|
|
||||||
|
$D("noVNC_clipboard_text").onfocus = UI.displayBlur;
|
||||||
|
$D("noVNC_clipboard_text").onblur = UI.displayFocus;
|
||||||
|
$D("noVNC_clipboard_text").onchange = UI.clipSend;
|
||||||
|
$D("noVNC_clipboard_clear_button").onclick = UI.clipClear;
|
||||||
|
|
||||||
|
$D("noVNC_settings_menu").onmouseover = UI.displayBlur;
|
||||||
|
$D("noVNC_settings_menu").onmouseover = UI.displayFocus;
|
||||||
|
$D("noVNC_apply").onclick = UI.settingsApply;
|
||||||
|
|
||||||
|
$D("noVNC_connect_button").onclick = UI.connect;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Read form control compatible setting from cookie
|
||||||
|
getSetting: function(name) {
|
||||||
|
var val, ctrl = $D('noVNC_' + name);
|
||||||
|
val = WebUtil.readSetting(name);
|
||||||
|
if (val !== null && ctrl.type === 'checkbox') {
|
||||||
|
if (val.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
|
||||||
|
val = false;
|
||||||
|
} else {
|
||||||
|
val = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Update cookie and form control setting. If value is not set, then
|
||||||
|
// updates from control to current cookie setting.
|
||||||
|
updateSetting: function(name, value) {
|
||||||
|
|
||||||
|
var i, ctrl = $D('noVNC_' + name);
|
||||||
|
// Save the cookie for this session
|
||||||
|
if (typeof value !== 'undefined') {
|
||||||
|
WebUtil.writeSetting(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the settings control
|
||||||
|
value = UI.getSetting(name);
|
||||||
|
|
||||||
|
if (ctrl.type === 'checkbox') {
|
||||||
|
ctrl.checked = value;
|
||||||
|
|
||||||
|
} else if (typeof ctrl.options !== 'undefined') {
|
||||||
|
for (i = 0; i < ctrl.options.length; i += 1) {
|
||||||
|
if (ctrl.options[i].value === value) {
|
||||||
|
ctrl.selectedIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*Weird IE9 error leads to 'null' appearring
|
||||||
|
in textboxes instead of ''.*/
|
||||||
|
if (value === null) {
|
||||||
|
value = "";
|
||||||
|
}
|
||||||
|
ctrl.value = value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Save control setting to cookie
|
||||||
|
saveSetting: function(name) {
|
||||||
|
var val, ctrl = $D('noVNC_' + name);
|
||||||
|
if (ctrl.type === 'checkbox') {
|
||||||
|
val = ctrl.checked;
|
||||||
|
} else if (typeof ctrl.options !== 'undefined') {
|
||||||
|
val = ctrl.options[ctrl.selectedIndex].value;
|
||||||
|
} else {
|
||||||
|
val = ctrl.value;
|
||||||
|
}
|
||||||
|
WebUtil.writeSetting(name, val);
|
||||||
|
//Util.Debug("Setting saved '" + name + "=" + val + "'");
|
||||||
|
return val;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Initial page load read/initialization of settings
|
||||||
|
initSetting: function(name, defVal) {
|
||||||
|
var val;
|
||||||
|
|
||||||
|
// Check Query string followed by cookie
|
||||||
|
val = WebUtil.getQueryVar(name);
|
||||||
|
if (val === null) {
|
||||||
|
val = WebUtil.readSetting(name, defVal);
|
||||||
|
}
|
||||||
|
UI.updateSetting(name, val);
|
||||||
|
//Util.Debug("Setting '" + name + "' initialized to '" + val + "'");
|
||||||
|
return val;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Force a setting to be a certain value
|
||||||
|
forceSetting: function(name, val) {
|
||||||
|
UI.updateSetting(name, val);
|
||||||
|
return val;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Show the clipboard panel
|
||||||
|
toggleClipboardPanel: function() {
|
||||||
|
// Close the description panel
|
||||||
|
$D('noVNC_description').style.display = "none";
|
||||||
|
//Close settings if open
|
||||||
|
if (UI.settingsOpen === true) {
|
||||||
|
UI.settingsApply();
|
||||||
|
UI.closeSettingsMenu();
|
||||||
|
}
|
||||||
|
//Close connection settings if open
|
||||||
|
if (UI.connSettingsOpen === true) {
|
||||||
|
UI.toggleConnectPanel();
|
||||||
|
}
|
||||||
|
//Toggle Clipboard Panel
|
||||||
|
if (UI.clipboardOpen === true) {
|
||||||
|
$D('noVNC_clipboard').style.display = "none";
|
||||||
|
$D('clipboardButton').className = "noVNC_status_button";
|
||||||
|
UI.clipboardOpen = false;
|
||||||
|
} else {
|
||||||
|
$D('noVNC_clipboard').style.display = "block";
|
||||||
|
$D('clipboardButton').className = "noVNC_status_button_selected";
|
||||||
|
UI.clipboardOpen = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Show the connection settings panel/menu
|
||||||
|
toggleConnectPanel: function() {
|
||||||
|
// Close the description panel
|
||||||
|
$D('noVNC_description').style.display = "none";
|
||||||
|
//Close connection settings if open
|
||||||
|
if (UI.settingsOpen === true) {
|
||||||
|
UI.settingsApply();
|
||||||
|
UI.closeSettingsMenu();
|
||||||
|
$D('connectButton').className = "noVNC_status_button";
|
||||||
|
}
|
||||||
|
if (UI.clipboardOpen === true) {
|
||||||
|
UI.toggleClipboardPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Toggle Connection Panel
|
||||||
|
if (UI.connSettingsOpen === true) {
|
||||||
|
$D('noVNC_controls').style.display = "none";
|
||||||
|
$D('connectButton').className = "noVNC_status_button";
|
||||||
|
UI.connSettingsOpen = false;
|
||||||
|
UI.saveSetting('host');
|
||||||
|
UI.saveSetting('port');
|
||||||
|
//UI.saveSetting('password');
|
||||||
|
} else {
|
||||||
|
$D('noVNC_controls').style.display = "block";
|
||||||
|
$D('connectButton').className = "noVNC_status_button_selected";
|
||||||
|
UI.connSettingsOpen = true;
|
||||||
|
$D('noVNC_host').focus();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Toggle the settings menu:
|
||||||
|
// On open, settings are refreshed from saved cookies.
|
||||||
|
// On close, settings are applied
|
||||||
|
toggleSettingsPanel: function() {
|
||||||
|
// Close the description panel
|
||||||
|
$D('noVNC_description').style.display = "none";
|
||||||
|
if (UI.settingsOpen) {
|
||||||
|
UI.settingsApply();
|
||||||
|
UI.closeSettingsMenu();
|
||||||
|
} else {
|
||||||
|
UI.updateSetting('encrypt');
|
||||||
|
UI.updateSetting('true_color');
|
||||||
|
if (UI.rfb.get_display().get_cursor_uri()) {
|
||||||
|
UI.updateSetting('cursor');
|
||||||
|
} else {
|
||||||
|
UI.updateSetting('cursor', false);
|
||||||
|
$D('noVNC_cursor').disabled = true;
|
||||||
|
}
|
||||||
|
UI.updateSetting('clip');
|
||||||
|
UI.updateSetting('shared');
|
||||||
|
UI.updateSetting('view_only');
|
||||||
|
UI.updateSetting('connectTimeout');
|
||||||
|
UI.updateSetting('path');
|
||||||
|
UI.updateSetting('repeaterID');
|
||||||
|
UI.updateSetting('stylesheet');
|
||||||
|
UI.updateSetting('logging');
|
||||||
|
|
||||||
|
UI.openSettingsMenu();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Open menu
|
||||||
|
openSettingsMenu: function() {
|
||||||
|
// Close the description panel
|
||||||
|
$D('noVNC_description').style.display = "none";
|
||||||
|
if (UI.clipboardOpen === true) {
|
||||||
|
UI.toggleClipboardPanel();
|
||||||
|
}
|
||||||
|
//Close connection settings if open
|
||||||
|
if (UI.connSettingsOpen === true) {
|
||||||
|
UI.toggleConnectPanel();
|
||||||
|
}
|
||||||
|
$D('noVNC_settings').style.display = "block";
|
||||||
|
$D('settingsButton').className = "noVNC_status_button_selected";
|
||||||
|
UI.settingsOpen = true;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Close menu (without applying settings)
|
||||||
|
closeSettingsMenu: function() {
|
||||||
|
$D('noVNC_settings').style.display = "none";
|
||||||
|
$D('settingsButton').className = "noVNC_status_button";
|
||||||
|
UI.settingsOpen = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
// Save/apply settings when 'Apply' button is pressed
|
||||||
|
settingsApply: function() {
|
||||||
|
//Util.Debug(">> settingsApply");
|
||||||
|
UI.saveSetting('encrypt');
|
||||||
|
UI.saveSetting('true_color');
|
||||||
|
if (UI.rfb.get_display().get_cursor_uri()) {
|
||||||
|
UI.saveSetting('cursor');
|
||||||
|
}
|
||||||
|
UI.saveSetting('clip');
|
||||||
|
UI.saveSetting('shared');
|
||||||
|
UI.saveSetting('view_only');
|
||||||
|
UI.saveSetting('connectTimeout');
|
||||||
|
UI.saveSetting('path');
|
||||||
|
UI.saveSetting('repeaterID');
|
||||||
|
UI.saveSetting('stylesheet');
|
||||||
|
UI.saveSetting('logging');
|
||||||
|
|
||||||
|
// Settings with immediate (non-connected related) effect
|
||||||
|
WebUtil.selectStylesheet(UI.getSetting('stylesheet'));
|
||||||
|
WebUtil.init_logging(UI.getSetting('logging'));
|
||||||
|
UI.setViewClip();
|
||||||
|
UI.setViewDrag(UI.rfb.get_viewportDrag());
|
||||||
|
//Util.Debug("<< settingsApply");
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
setPassword: function() {
|
||||||
|
UI.rfb.sendPassword($D('noVNC_password').value);
|
||||||
|
//Reset connect button.
|
||||||
|
$D('noVNC_connect_button').value = "Connect";
|
||||||
|
$D('noVNC_connect_button').onclick = UI.Connect;
|
||||||
|
//Hide connection panel.
|
||||||
|
UI.toggleConnectPanel();
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
sendCtrlAltDel: function() {
|
||||||
|
UI.rfb.sendCtrlAltDel();
|
||||||
|
},
|
||||||
|
|
||||||
|
setMouseButton: function(num) {
|
||||||
|
var b, blist = [0, 1,2,4], button;
|
||||||
|
|
||||||
|
if (typeof num === 'undefined') {
|
||||||
|
// Disable mouse buttons
|
||||||
|
num = -1;
|
||||||
|
}
|
||||||
|
if (UI.rfb) {
|
||||||
|
UI.rfb.get_mouse().set_touchButton(num);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (b = 0; b < blist.length; b++) {
|
||||||
|
button = $D('noVNC_mouse_button' + blist[b]);
|
||||||
|
if (blist[b] === num) {
|
||||||
|
button.style.display = "";
|
||||||
|
} else {
|
||||||
|
button.style.display = "none";
|
||||||
|
/*
|
||||||
|
button.style.backgroundColor = "black";
|
||||||
|
button.style.color = "lightgray";
|
||||||
|
button.style.backgroundColor = "";
|
||||||
|
button.style.color = "";
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updateState: function(rfb, state, oldstate, msg) {
|
||||||
|
var s, sb, c, d, cad, vd, klass;
|
||||||
|
UI.rfb_state = state;
|
||||||
|
s = $D('noVNC_status');
|
||||||
|
sb = $D('noVNC_status_bar');
|
||||||
|
switch (state) {
|
||||||
|
case 'failed':
|
||||||
|
case 'fatal':
|
||||||
|
klass = "noVNC_status_error";
|
||||||
|
break;
|
||||||
|
case 'normal':
|
||||||
|
klass = "noVNC_status_normal";
|
||||||
|
break;
|
||||||
|
case 'disconnected':
|
||||||
|
$D('noVNC_logo').style.display = "block";
|
||||||
|
// Fall through
|
||||||
|
case 'loaded':
|
||||||
|
klass = "noVNC_status_normal";
|
||||||
|
break;
|
||||||
|
case 'password':
|
||||||
|
UI.toggleConnectPanel();
|
||||||
|
|
||||||
|
$D('noVNC_connect_button').value = "Send Password";
|
||||||
|
$D('noVNC_connect_button').onclick = UI.setPassword;
|
||||||
|
$D('noVNC_password').focus();
|
||||||
|
|
||||||
|
klass = "noVNC_status_warn";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
klass = "noVNC_status_warn";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof(msg) !== 'undefined') {
|
||||||
|
s.setAttribute("class", klass);
|
||||||
|
sb.setAttribute("class", klass);
|
||||||
|
s.innerHTML = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
UI.updateVisualState();
|
||||||
|
},
|
||||||
|
|
||||||
|
// Disable/enable controls depending on connection state
|
||||||
|
updateVisualState: function() {
|
||||||
|
var connected = UI.rfb_state === 'normal' ? true : false;
|
||||||
|
|
||||||
|
//Util.Debug(">> updateVisualState");
|
||||||
|
$D('noVNC_encrypt').disabled = connected;
|
||||||
|
$D('noVNC_true_color').disabled = connected;
|
||||||
|
if (UI.rfb && UI.rfb.get_display() &&
|
||||||
|
UI.rfb.get_display().get_cursor_uri()) {
|
||||||
|
$D('noVNC_cursor').disabled = connected;
|
||||||
|
} else {
|
||||||
|
UI.updateSetting('cursor', false);
|
||||||
|
$D('noVNC_cursor').disabled = true;
|
||||||
|
}
|
||||||
|
$D('noVNC_shared').disabled = connected;
|
||||||
|
$D('noVNC_view_only').disabled = connected;
|
||||||
|
$D('noVNC_connectTimeout').disabled = connected;
|
||||||
|
$D('noVNC_path').disabled = connected;
|
||||||
|
$D('noVNC_repeaterID').disabled = connected;
|
||||||
|
|
||||||
|
if (connected) {
|
||||||
|
UI.setViewClip();
|
||||||
|
UI.setMouseButton(1);
|
||||||
|
$D('clipboardButton').style.display = "inline";
|
||||||
|
$D('showKeyboard').style.display = "inline";
|
||||||
|
$D('sendCtrlAltDelButton').style.display = "inline";
|
||||||
|
} else {
|
||||||
|
UI.setMouseButton();
|
||||||
|
$D('clipboardButton').style.display = "none";
|
||||||
|
$D('showKeyboard').style.display = "none";
|
||||||
|
$D('sendCtrlAltDelButton').style.display = "none";
|
||||||
|
}
|
||||||
|
// State change disables viewport dragging.
|
||||||
|
// It is enabled (toggled) by direct click on the button
|
||||||
|
UI.setViewDrag(false);
|
||||||
|
|
||||||
|
switch (UI.rfb_state) {
|
||||||
|
case 'fatal':
|
||||||
|
case 'failed':
|
||||||
|
case 'loaded':
|
||||||
|
case 'disconnected':
|
||||||
|
$D('connectButton').style.display = "";
|
||||||
|
$D('disconnectButton').style.display = "none";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$D('connectButton').style.display = "none";
|
||||||
|
$D('disconnectButton').style.display = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Util.Debug("<< updateVisualState");
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
clipReceive: function(rfb, text) {
|
||||||
|
Util.Debug(">> UI.clipReceive: " + text.substr(0,40) + "...");
|
||||||
|
$D('noVNC_clipboard_text').value = text;
|
||||||
|
Util.Debug("<< UI.clipReceive");
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
connect: function() {
|
||||||
|
var host, port, password, path;
|
||||||
|
|
||||||
|
UI.closeSettingsMenu();
|
||||||
|
UI.toggleConnectPanel();
|
||||||
|
|
||||||
|
host = $D('noVNC_host').value;
|
||||||
|
port = $D('noVNC_port').value;
|
||||||
|
password = $D('noVNC_password').value;
|
||||||
|
path = $D('noVNC_path').value;
|
||||||
|
if ((!host) || (!port)) {
|
||||||
|
throw("Must set host and port");
|
||||||
|
}
|
||||||
|
|
||||||
|
UI.rfb.set_encrypt(UI.getSetting('encrypt'));
|
||||||
|
UI.rfb.set_true_color(UI.getSetting('true_color'));
|
||||||
|
UI.rfb.set_local_cursor(UI.getSetting('cursor'));
|
||||||
|
UI.rfb.set_shared(UI.getSetting('shared'));
|
||||||
|
UI.rfb.set_view_only(UI.getSetting('view_only'));
|
||||||
|
UI.rfb.set_connectTimeout(UI.getSetting('connectTimeout'));
|
||||||
|
UI.rfb.set_repeaterID(UI.getSetting('repeaterID'));
|
||||||
|
|
||||||
|
UI.rfb.connect(host, port, password, path);
|
||||||
|
|
||||||
|
//Close dialog.
|
||||||
|
setTimeout(UI.setBarPosition, 100);
|
||||||
|
$D('noVNC_logo').style.display = "none";
|
||||||
|
},
|
||||||
|
|
||||||
|
disconnect: function() {
|
||||||
|
UI.closeSettingsMenu();
|
||||||
|
UI.rfb.disconnect();
|
||||||
|
|
||||||
|
$D('noVNC_logo').style.display = "block";
|
||||||
|
UI.connSettingsOpen = false;
|
||||||
|
UI.toggleConnectPanel();
|
||||||
|
},
|
||||||
|
|
||||||
|
displayBlur: function() {
|
||||||
|
UI.rfb.get_keyboard().set_focused(false);
|
||||||
|
UI.rfb.get_mouse().set_focused(false);
|
||||||
|
},
|
||||||
|
|
||||||
|
displayFocus: function() {
|
||||||
|
UI.rfb.get_keyboard().set_focused(true);
|
||||||
|
UI.rfb.get_mouse().set_focused(true);
|
||||||
|
},
|
||||||
|
|
||||||
|
clipClear: function() {
|
||||||
|
$D('noVNC_clipboard_text').value = "";
|
||||||
|
UI.rfb.clipboardPasteFrom("");
|
||||||
|
},
|
||||||
|
|
||||||
|
clipSend: function() {
|
||||||
|
var text = $D('noVNC_clipboard_text').value;
|
||||||
|
Util.Debug(">> UI.clipSend: " + text.substr(0,40) + "...");
|
||||||
|
UI.rfb.clipboardPasteFrom(text);
|
||||||
|
Util.Debug("<< UI.clipSend");
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
// Enable/disable and configure viewport clipping
|
||||||
|
setViewClip: function(clip) {
|
||||||
|
var display, cur_clip, pos, new_w, new_h;
|
||||||
|
|
||||||
|
if (UI.rfb) {
|
||||||
|
display = UI.rfb.get_display();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cur_clip = display.get_viewport();
|
||||||
|
|
||||||
|
if (typeof(clip) !== 'boolean') {
|
||||||
|
// Use current setting
|
||||||
|
clip = UI.getSetting('clip');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clip && !cur_clip) {
|
||||||
|
// Turn clipping on
|
||||||
|
UI.updateSetting('clip', true);
|
||||||
|
} else if (!clip && cur_clip) {
|
||||||
|
// Turn clipping off
|
||||||
|
UI.updateSetting('clip', false);
|
||||||
|
display.set_viewport(false);
|
||||||
|
$D('noVNC_canvas').style.position = 'static';
|
||||||
|
display.viewportChange();
|
||||||
|
}
|
||||||
|
if (UI.getSetting('clip')) {
|
||||||
|
// If clipping, update clipping settings
|
||||||
|
$D('noVNC_canvas').style.position = 'absolute';
|
||||||
|
pos = Util.getPosition($D('noVNC_canvas'));
|
||||||
|
new_w = window.innerWidth - pos.x;
|
||||||
|
new_h = window.innerHeight - pos.y;
|
||||||
|
display.set_viewport(true);
|
||||||
|
display.viewportChange(0, 0, new_w, new_h);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// Toggle/set/unset the viewport drag/move button
|
||||||
|
setViewDrag: function(drag) {
|
||||||
|
var vmb = $D('noVNC_view_drag_button');
|
||||||
|
if (!UI.rfb) { return; }
|
||||||
|
|
||||||
|
if (UI.rfb_state === 'normal' &&
|
||||||
|
UI.rfb.get_display().get_viewport()) {
|
||||||
|
vmb.style.display = "inline";
|
||||||
|
} else {
|
||||||
|
vmb.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof(drag) === "undefined" ||
|
||||||
|
typeof(drag) === "object") {
|
||||||
|
// If not specified, then toggle
|
||||||
|
drag = !UI.rfb.get_viewportDrag();
|
||||||
|
}
|
||||||
|
if (drag) {
|
||||||
|
vmb.className = "noVNC_status_button_selected";
|
||||||
|
UI.rfb.set_viewportDrag(true);
|
||||||
|
} else {
|
||||||
|
vmb.className = "noVNC_status_button";
|
||||||
|
UI.rfb.set_viewportDrag(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// On touch devices, show the OS keyboard
|
||||||
|
showKeyboard: function() {
|
||||||
|
if(UI.keyboardVisible === false) {
|
||||||
|
$D('keyboardinput').focus();
|
||||||
|
UI.keyboardVisible = true;
|
||||||
|
$D('showKeyboard').className = "noVNC_status_button_selected";
|
||||||
|
} else if(UI.keyboardVisible === true) {
|
||||||
|
$D('keyboardinput').blur();
|
||||||
|
$D('showKeyboard').className = "noVNC_status_button";
|
||||||
|
UI.keyboardVisible = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
keyInputBlur: function() {
|
||||||
|
$D('showKeyboard').className = "noVNC_status_button";
|
||||||
|
//Weird bug in iOS if you change keyboardVisible
|
||||||
|
//here it does not actually occur so next time
|
||||||
|
//you click keyboard icon it doesnt work.
|
||||||
|
setTimeout(function() { UI.setKeyboard(); },100);
|
||||||
|
},
|
||||||
|
|
||||||
|
setKeyboard: function() {
|
||||||
|
UI.keyboardVisible = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
// iOS < Version 5 does not support position fixed. Javascript workaround:
|
||||||
|
setOnscroll: function() {
|
||||||
|
window.onscroll = function() {
|
||||||
|
UI.setBarPosition();
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
setResize: function () {
|
||||||
|
window.onResize = function() {
|
||||||
|
UI.setBarPosition();
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
//Helper to add options to dropdown.
|
||||||
|
addOption: function(selectbox,text,value )
|
||||||
|
{
|
||||||
|
var optn = document.createElement("OPTION");
|
||||||
|
optn.text = text;
|
||||||
|
optn.value = value;
|
||||||
|
selectbox.options.add(optn);
|
||||||
|
},
|
||||||
|
|
||||||
|
setBarPosition: function() {
|
||||||
|
$D('noVNC-control-bar').style.top = (window.pageYOffset) + 'px';
|
||||||
|
$D('noVNC_mobile_buttons').style.left = (window.pageXOffset) + 'px';
|
||||||
|
|
||||||
|
var vncwidth = $D('noVNC_screen').style.offsetWidth;
|
||||||
|
$D('noVNC-control-bar').style.width = vncwidth + 'px';
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
381
static/js/novnc/util.js
Normal file
381
static/js/novnc/util.js
Normal file
|
@ -0,0 +1,381 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
/*jslint bitwise: false, white: false */
|
||||||
|
/*global window, console, document, navigator, ActiveXObject */
|
||||||
|
|
||||||
|
// Globals defined here
|
||||||
|
var Util = {};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Make arrays quack
|
||||||
|
*/
|
||||||
|
|
||||||
|
Array.prototype.push8 = function (num) {
|
||||||
|
this.push(num & 0xFF);
|
||||||
|
};
|
||||||
|
|
||||||
|
Array.prototype.push16 = function (num) {
|
||||||
|
this.push((num >> 8) & 0xFF,
|
||||||
|
(num ) & 0xFF );
|
||||||
|
};
|
||||||
|
Array.prototype.push32 = function (num) {
|
||||||
|
this.push((num >> 24) & 0xFF,
|
||||||
|
(num >> 16) & 0xFF,
|
||||||
|
(num >> 8) & 0xFF,
|
||||||
|
(num ) & 0xFF );
|
||||||
|
};
|
||||||
|
|
||||||
|
// IE does not support map (even in IE9)
|
||||||
|
//This prototype is provided by the Mozilla foundation and
|
||||||
|
//is distributed under the MIT license.
|
||||||
|
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
|
||||||
|
if (!Array.prototype.map)
|
||||||
|
{
|
||||||
|
Array.prototype.map = function(fun /*, thisp*/)
|
||||||
|
{
|
||||||
|
var len = this.length;
|
||||||
|
if (typeof fun != "function")
|
||||||
|
throw new TypeError();
|
||||||
|
|
||||||
|
var res = new Array(len);
|
||||||
|
var thisp = arguments[1];
|
||||||
|
for (var i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
if (i in this)
|
||||||
|
res[i] = fun.call(thisp, this[i], i, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
* ------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Logging/debug routines
|
||||||
|
*/
|
||||||
|
|
||||||
|
Util._log_level = 'warn';
|
||||||
|
Util.init_logging = function (level) {
|
||||||
|
if (typeof level === 'undefined') {
|
||||||
|
level = Util._log_level;
|
||||||
|
} else {
|
||||||
|
Util._log_level = level;
|
||||||
|
}
|
||||||
|
if (typeof window.console === "undefined") {
|
||||||
|
if (typeof window.opera !== "undefined") {
|
||||||
|
window.console = {
|
||||||
|
'log' : window.opera.postError,
|
||||||
|
'warn' : window.opera.postError,
|
||||||
|
'error': window.opera.postError };
|
||||||
|
} else {
|
||||||
|
window.console = {
|
||||||
|
'log' : function(m) {},
|
||||||
|
'warn' : function(m) {},
|
||||||
|
'error': function(m) {}};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Util.Debug = Util.Info = Util.Warn = Util.Error = function (msg) {};
|
||||||
|
switch (level) {
|
||||||
|
case 'debug': Util.Debug = function (msg) { console.log(msg); };
|
||||||
|
case 'info': Util.Info = function (msg) { console.log(msg); };
|
||||||
|
case 'warn': Util.Warn = function (msg) { console.warn(msg); };
|
||||||
|
case 'error': Util.Error = function (msg) { console.error(msg); };
|
||||||
|
case 'none':
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw("invalid logging type '" + level + "'");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Util.get_logging = function () {
|
||||||
|
return Util._log_level;
|
||||||
|
};
|
||||||
|
// Initialize logging level
|
||||||
|
Util.init_logging();
|
||||||
|
|
||||||
|
|
||||||
|
// Set configuration default for Crockford style function namespaces
|
||||||
|
Util.conf_default = function(cfg, api, defaults, v, mode, type, defval, desc) {
|
||||||
|
var getter, setter;
|
||||||
|
|
||||||
|
// Default getter function
|
||||||
|
getter = function (idx) {
|
||||||
|
if ((type in {'arr':1, 'array':1}) &&
|
||||||
|
(typeof idx !== 'undefined')) {
|
||||||
|
return cfg[v][idx];
|
||||||
|
} else {
|
||||||
|
return cfg[v];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Default setter function
|
||||||
|
setter = function (val, idx) {
|
||||||
|
if (type in {'boolean':1, 'bool':1}) {
|
||||||
|
if ((!val) || (val in {'0':1, 'no':1, 'false':1})) {
|
||||||
|
val = false;
|
||||||
|
} else {
|
||||||
|
val = true;
|
||||||
|
}
|
||||||
|
} 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 () {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof idx !== 'undefined') {
|
||||||
|
cfg[v][idx] = val;
|
||||||
|
} else {
|
||||||
|
cfg[v] = val;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set the description
|
||||||
|
api[v + '_description'] = desc;
|
||||||
|
|
||||||
|
// Set the getter function
|
||||||
|
if (typeof api['get_' + v] === 'undefined') {
|
||||||
|
api['get_' + v] = getter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the setter function with extra sanity checks
|
||||||
|
if (typeof api['set_' + v] === 'undefined') {
|
||||||
|
api['set_' + v] = function (val, idx) {
|
||||||
|
if (mode in {'RO':1, 'ro':1}) {
|
||||||
|
throw(v + " is read-only");
|
||||||
|
} else if ((mode in {'WO':1, 'wo':1}) &&
|
||||||
|
(typeof cfg[v] !== 'undefined')) {
|
||||||
|
throw(v + " can only be set once");
|
||||||
|
}
|
||||||
|
setter(val, idx);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the default value
|
||||||
|
if (typeof defaults[v] !== 'undefined') {
|
||||||
|
defval = defaults[v];
|
||||||
|
} else if ((type in {'arr':1, 'array':1}) &&
|
||||||
|
(! (defval instanceof Array))) {
|
||||||
|
defval = [];
|
||||||
|
}
|
||||||
|
// Coerce existing setting to the right type
|
||||||
|
//Util.Debug("v: " + v + ", defval: " + defval + ", defaults[v]: " + defaults[v]);
|
||||||
|
setter(defval);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set group of configuration defaults
|
||||||
|
Util.conf_defaults = function(cfg, api, defaults, arr) {
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < arr.length; i++) {
|
||||||
|
Util.conf_default(cfg, api, defaults, arr[i][0], arr[i][1],
|
||||||
|
arr[i][2], arr[i][3], arr[i][4]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 : "/static/js/novnc/";
|
||||||
|
}
|
||||||
|
Util._loading_scripts = [];
|
||||||
|
Util._pending_scripts = [];
|
||||||
|
Util.load_scripts = function(files) {
|
||||||
|
var head = document.getElementsByTagName('head')[0], script,
|
||||||
|
ls = Util._loading_scripts, ps = Util._pending_scripts;
|
||||||
|
for (var f=0; f<files.length; f++) {
|
||||||
|
script = document.createElement('script');
|
||||||
|
script.type = 'text/javascript';
|
||||||
|
script.src = Util.get_include_uri() + files[f];
|
||||||
|
//console.log("loading script: " + script.src);
|
||||||
|
script.onload = script.onreadystatechange = function (e) {
|
||||||
|
while (ls.length > 0 && (ls[0].readyState === 'loaded' ||
|
||||||
|
ls[0].readyState === 'complete')) {
|
||||||
|
// For IE, append the script to trigger execution
|
||||||
|
var s = ls.shift();
|
||||||
|
//console.log("loaded script: " + s.src);
|
||||||
|
head.appendChild(s);
|
||||||
|
}
|
||||||
|
if (!this.readyState ||
|
||||||
|
(Util.Engine.presto && this.readyState === 'loaded') ||
|
||||||
|
this.readyState === 'complete') {
|
||||||
|
if (ps.indexOf(this) >= 0) {
|
||||||
|
this.onload = this.onreadystatechange = null;
|
||||||
|
//console.log("completed script: " + this.src);
|
||||||
|
ps.splice(ps.indexOf(this), 1);
|
||||||
|
|
||||||
|
// Call window.onscriptsload after last script loads
|
||||||
|
if (ps.length === 0 && window.onscriptsload) {
|
||||||
|
window.onscriptsload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// In-order script execution tricks
|
||||||
|
if (Util.Engine.trident) {
|
||||||
|
// For IE wait until readyState is 'loaded' before
|
||||||
|
// appending it which will trigger execution
|
||||||
|
// http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
|
||||||
|
ls.push(script);
|
||||||
|
} else {
|
||||||
|
// For webkit and firefox set async=false and append now
|
||||||
|
// https://developer.mozilla.org/en-US/docs/HTML/Element/script
|
||||||
|
script.async = false;
|
||||||
|
head.appendChild(script);
|
||||||
|
}
|
||||||
|
ps.push(script);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get DOM element position on page
|
||||||
|
Util.getPosition = function (obj) {
|
||||||
|
var x = 0, y = 0;
|
||||||
|
if (obj.offsetParent) {
|
||||||
|
do {
|
||||||
|
x += obj.offsetLeft;
|
||||||
|
y += obj.offsetTop;
|
||||||
|
obj = obj.offsetParent;
|
||||||
|
} while (obj);
|
||||||
|
}
|
||||||
|
return {'x': x, 'y': y};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get mouse event position in DOM element
|
||||||
|
Util.getEventPosition = function (e, obj, scale) {
|
||||||
|
var evt, docX, docY, pos;
|
||||||
|
//if (!e) evt = window.event;
|
||||||
|
evt = (e ? e : window.event);
|
||||||
|
evt = (evt.changedTouches ? evt.changedTouches[0] : evt.touches ? evt.touches[0] : evt);
|
||||||
|
if (evt.pageX || evt.pageY) {
|
||||||
|
docX = evt.pageX;
|
||||||
|
docY = evt.pageY;
|
||||||
|
} else if (evt.clientX || evt.clientY) {
|
||||||
|
docX = evt.clientX + document.body.scrollLeft +
|
||||||
|
document.documentElement.scrollLeft;
|
||||||
|
docY = evt.clientY + document.body.scrollTop +
|
||||||
|
document.documentElement.scrollTop;
|
||||||
|
}
|
||||||
|
pos = Util.getPosition(obj);
|
||||||
|
if (typeof scale === "undefined") {
|
||||||
|
scale = 1;
|
||||||
|
}
|
||||||
|
var x = Math.max(Math.min(docX - pos.x, obj.width-1), 0);
|
||||||
|
var y = Math.max(Math.min(docY - pos.y, obj.height-1), 0);
|
||||||
|
return {'x': x / scale, 'y': y / scale};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Event registration. Based on: http://www.scottandrew.com/weblog/articles/cbs-events
|
||||||
|
Util.addEvent = function (obj, evType, fn){
|
||||||
|
if (obj.attachEvent){
|
||||||
|
var r = obj.attachEvent("on"+evType, fn);
|
||||||
|
return r;
|
||||||
|
} else if (obj.addEventListener){
|
||||||
|
obj.addEventListener(evType, fn, false);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
throw("Handler could not be attached");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Util.removeEvent = function(obj, evType, fn){
|
||||||
|
if (obj.detachEvent){
|
||||||
|
var r = obj.detachEvent("on"+evType, fn);
|
||||||
|
return r;
|
||||||
|
} else if (obj.removeEventListener){
|
||||||
|
obj.removeEventListener(evType, fn, false);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
throw("Handler could not be removed");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Util.stopEvent = function(e) {
|
||||||
|
if (e.stopPropagation) { e.stopPropagation(); }
|
||||||
|
else { e.cancelBubble = true; }
|
||||||
|
|
||||||
|
if (e.preventDefault) { e.preventDefault(); }
|
||||||
|
else { e.returnValue = false; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Set browser engine versions. Based on mootools.
|
||||||
|
Util.Features = {xpath: !!(document.evaluate), air: !!(window.runtime), query: !!(document.querySelector)};
|
||||||
|
|
||||||
|
Util.Engine = {
|
||||||
|
// Version detection break in Opera 11.60 (errors on arguments.callee.caller reference)
|
||||||
|
//'presto': (function() {
|
||||||
|
// return (!window.opera) ? false : ((arguments.callee.caller) ? 960 : ((document.getElementsByClassName) ? 950 : 925)); }()),
|
||||||
|
'presto': (function() { return (!window.opera) ? false : true; }()),
|
||||||
|
|
||||||
|
'trident': (function() {
|
||||||
|
return (!window.ActiveXObject) ? false : ((window.XMLHttpRequest) ? ((document.querySelectorAll) ? 6 : 5) : 4); }()),
|
||||||
|
'webkit': (function() {
|
||||||
|
try { return (navigator.taintEnabled) ? false : ((Util.Features.xpath) ? ((Util.Features.query) ? 525 : 420) : 419); } catch (e) { return false; } }()),
|
||||||
|
//'webkit': (function() {
|
||||||
|
// return ((typeof navigator.taintEnabled !== "unknown") && navigator.taintEnabled) ? false : ((Util.Features.xpath) ? ((Util.Features.query) ? 525 : 420) : 419); }()),
|
||||||
|
'gecko': (function() {
|
||||||
|
return (!document.getBoxObjectFor && window.mozInnerScreenX == null) ? false : ((document.getElementsByClassName) ? 19 : 18); }())
|
||||||
|
};
|
||||||
|
if (Util.Engine.webkit) {
|
||||||
|
// Extract actual webkit version if available
|
||||||
|
Util.Engine.webkit = (function(v) {
|
||||||
|
var re = new RegExp('WebKit/([0-9\.]*) ');
|
||||||
|
v = (navigator.userAgent.match(re) || ['', v])[1];
|
||||||
|
return parseFloat(v, 10);
|
||||||
|
})(Util.Engine.webkit);
|
||||||
|
}
|
||||||
|
|
||||||
|
Util.Flash = (function(){
|
||||||
|
var v, version;
|
||||||
|
try {
|
||||||
|
v = navigator.plugins['Shockwave Flash'].description;
|
||||||
|
} catch(err1) {
|
||||||
|
try {
|
||||||
|
v = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
|
||||||
|
} catch(err2) {
|
||||||
|
v = '0 r0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
version = v.match(/\d+/g);
|
||||||
|
return {version: parseInt(version[0] || 0 + '.' + version[1], 10) || 0, build: parseInt(version[2], 10) || 0};
|
||||||
|
}());
|
109
static/js/novnc/web-socket-js/README.txt
Normal file
109
static/js/novnc/web-socket-js/README.txt
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
* How to try
|
||||||
|
|
||||||
|
Assuming you have Web server (e.g. Apache) running at http://example.com/ .
|
||||||
|
|
||||||
|
- Download web_socket.rb from:
|
||||||
|
http://github.com/gimite/web-socket-ruby/tree/master
|
||||||
|
- Run sample Web Socket server (echo server) in example.com with: (#1)
|
||||||
|
$ ruby web-socket-ruby/samples/echo_server.rb example.com 10081
|
||||||
|
- If your server already provides socket policy file at port 843, modify the file to allow access to port 10081. Otherwise you can skip this step. See below for details.
|
||||||
|
- Publish the web-socket-js directory with your Web server (e.g. put it in ~/public_html).
|
||||||
|
- Change ws://localhost:10081 to ws://example.com:10081 in sample.html.
|
||||||
|
- Open sample.html in your browser.
|
||||||
|
- After "onopen" is shown, input something, click [Send] and confirm echo back.
|
||||||
|
|
||||||
|
#1: First argument of echo_server.rb means that it accepts Web Socket connection from HTML pages in example.com.
|
||||||
|
|
||||||
|
|
||||||
|
* Troubleshooting
|
||||||
|
|
||||||
|
If it doesn't work, try these:
|
||||||
|
|
||||||
|
1. Try Chrome and Firefox 3.x.
|
||||||
|
- It doesn't work on Chrome:
|
||||||
|
-- It's likely an issue of your code or the server. Debug your code as usual e.g. using console.log.
|
||||||
|
- It works on Chrome but it doesn't work on Firefox:
|
||||||
|
-- It's likely an issue of web-socket-js specific configuration (e.g. 3 and 4 below).
|
||||||
|
- It works on both Chrome and Firefox, but it doesn't work on your browser:
|
||||||
|
-- Check "Supported environment" section below. Your browser may not be supported by web-socket-js.
|
||||||
|
|
||||||
|
2. Add this line before your code:
|
||||||
|
WEB_SOCKET_DEBUG = true;
|
||||||
|
and use Developer Tools (Chrome/Safari) or Firebug (Firefox) to see if console.log outputs any errors.
|
||||||
|
|
||||||
|
3. Make sure you do NOT open your HTML page as local file e.g. file:///.../sample.html. web-socket-js doesn't work on local file. Open it via Web server e.g. http:///.../sample.html.
|
||||||
|
|
||||||
|
4. If you are NOT using web-socket-ruby as your WebSocket server, you need to place Flash socket policy file on your server. See "Flash socket policy file" section below for details.
|
||||||
|
|
||||||
|
5. Check if sample.html bundled with web-socket-js works.
|
||||||
|
|
||||||
|
6. Make sure the port used for WebSocket (10081 in example above) is not blocked by your server/client's firewall.
|
||||||
|
|
||||||
|
7. Install debugger version of Flash Player available here to see Flash errors:
|
||||||
|
http://www.adobe.com/support/flashplayer/downloads.html
|
||||||
|
|
||||||
|
|
||||||
|
* Supported environments
|
||||||
|
|
||||||
|
It should work on:
|
||||||
|
- Google Chrome 4 or later (just uses native implementation)
|
||||||
|
- Firefox 3.x, Internet Explorer 8 + Flash Player 9 or later
|
||||||
|
|
||||||
|
It may or may not work on other browsers such as Safari, Opera or IE 6. Patch for these browsers are appreciated, but I will not work on fixing issues specific to these browsers by myself.
|
||||||
|
|
||||||
|
|
||||||
|
* Flash socket policy file
|
||||||
|
|
||||||
|
This implementation uses Flash's socket, which means that your server must provide Flash socket policy file to declare the server accepts connections from Flash.
|
||||||
|
|
||||||
|
If you use web-socket-ruby available at
|
||||||
|
http://github.com/gimite/web-socket-ruby/tree/master
|
||||||
|
, you don't need anything special, because web-socket-ruby handles Flash socket policy file request. But if you already provide socket policy file at port 843, you need to modify the file to allow access to Web Socket port, because it precedes what web-socket-ruby provides.
|
||||||
|
|
||||||
|
If you use other Web Socket server implementation, you need to provide socket policy file yourself. See
|
||||||
|
http://www.lightsphere.com/dev/articles/flash_socket_policy.html
|
||||||
|
for details and sample script to run socket policy file server. node.js implementation is available here:
|
||||||
|
http://github.com/LearnBoost/Socket.IO-node/blob/master/lib/socket.io/transports/flashsocket.js
|
||||||
|
|
||||||
|
Actually, it's still better to provide socket policy file at port 843 even if you use web-socket-ruby. Flash always try to connect to port 843 first, so providing the file at port 843 makes startup faster.
|
||||||
|
|
||||||
|
|
||||||
|
* Cookie considerations
|
||||||
|
|
||||||
|
Cookie is sent if Web Socket host is the same as the origin of JavaScript. Otherwise it is not sent, because I don't know way to send right Cookie (which is Cookie of the host of Web Socket, I heard).
|
||||||
|
|
||||||
|
Note that it's technically possible that client sends arbitrary string as Cookie and any other headers (by modifying this library for example) once you place Flash socket policy file in your server. So don't trust Cookie and other headers if you allow connection from untrusted origin.
|
||||||
|
|
||||||
|
|
||||||
|
* Proxy considerations
|
||||||
|
|
||||||
|
The WebSocket spec (http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol) specifies instructions for User Agents to support proxied connections by implementing the HTTP CONNECT method.
|
||||||
|
|
||||||
|
The AS3 Socket class doesn't implement this mechanism, which renders it useless for the scenarios where the user trying to open a socket is behind a proxy.
|
||||||
|
|
||||||
|
The class RFC2817Socket (by Christian Cantrell) effectively lets us implement this, as long as the proxy settings are known and provided by the interface that instantiates the WebSocket. As such, if you want to support proxied conncetions, you'll have to supply this information to the WebSocket constructor when Flash is being used. One way to go about it would be to ask the user for proxy settings information if the initial connection fails.
|
||||||
|
|
||||||
|
|
||||||
|
* How to host HTML file and SWF file in different domains
|
||||||
|
|
||||||
|
By default, HTML file and SWF file must be in the same domain. You can follow steps below to allow hosting them in different domain.
|
||||||
|
|
||||||
|
WARNING: If you use the method below, HTML files in ANY domains can send arbitrary TCP data to your WebSocket server, regardless of configuration in Flash socket policy file. Arbitrary TCP data means that they can even fake request headers including Origin and Cookie.
|
||||||
|
|
||||||
|
- Unzip WebSocketMainInsecure.zip to extract WebSocketMainInsecure.swf.
|
||||||
|
- Put WebSocketMainInsecure.swf on your server, instead of WebSocketMain.swf.
|
||||||
|
- In JavaScript, set WEB_SOCKET_SWF_LOCATION to URL of your WebSocketMainInsecure.swf.
|
||||||
|
|
||||||
|
|
||||||
|
* How to build WebSocketMain.swf
|
||||||
|
|
||||||
|
Install Flex 4 SDK:
|
||||||
|
http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4
|
||||||
|
|
||||||
|
$ cd flash-src
|
||||||
|
$ ./build.sh
|
||||||
|
|
||||||
|
|
||||||
|
* License
|
||||||
|
|
||||||
|
New BSD License.
|
BIN
static/js/novnc/web-socket-js/WebSocketMain.swf
Normal file
BIN
static/js/novnc/web-socket-js/WebSocketMain.swf
Normal file
Binary file not shown.
4
static/js/novnc/web-socket-js/swfobject.js
Normal file
4
static/js/novnc/web-socket-js/swfobject.js
Normal file
File diff suppressed because one or more lines are too long
391
static/js/novnc/web-socket-js/web_socket.js
Normal file
391
static/js/novnc/web-socket-js/web_socket.js
Normal file
|
@ -0,0 +1,391 @@
|
||||||
|
// Copyright: Hiroshi Ichikawa <http://gimite.net/en/>
|
||||||
|
// License: New BSD License
|
||||||
|
// Reference: http://dev.w3.org/html5/websockets/
|
||||||
|
// Reference: http://tools.ietf.org/html/rfc6455
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
if (window.WEB_SOCKET_FORCE_FLASH) {
|
||||||
|
// Keeps going.
|
||||||
|
} else if (window.WebSocket) {
|
||||||
|
return;
|
||||||
|
} else if (window.MozWebSocket) {
|
||||||
|
// Firefox.
|
||||||
|
window.WebSocket = MozWebSocket;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var logger;
|
||||||
|
if (window.WEB_SOCKET_LOGGER) {
|
||||||
|
logger = WEB_SOCKET_LOGGER;
|
||||||
|
} else if (window.console && window.console.log && window.console.error) {
|
||||||
|
// In some environment, console is defined but console.log or console.error is missing.
|
||||||
|
logger = window.console;
|
||||||
|
} else {
|
||||||
|
logger = {log: function(){ }, error: function(){ }};
|
||||||
|
}
|
||||||
|
|
||||||
|
// swfobject.hasFlashPlayerVersion("10.0.0") doesn't work with Gnash.
|
||||||
|
if (swfobject.getFlashPlayerVersion().major < 10) {
|
||||||
|
logger.error("Flash Player >= 10.0.0 is required.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (location.protocol == "file:") {
|
||||||
|
logger.error(
|
||||||
|
"WARNING: web-socket-js doesn't work in file:///... URL " +
|
||||||
|
"unless you set Flash Security Settings properly. " +
|
||||||
|
"Open the page via Web server i.e. http://...");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Our own implementation of WebSocket class using Flash.
|
||||||
|
* @param {string} url
|
||||||
|
* @param {array or string} protocols
|
||||||
|
* @param {string} proxyHost
|
||||||
|
* @param {int} proxyPort
|
||||||
|
* @param {string} headers
|
||||||
|
*/
|
||||||
|
window.WebSocket = function(url, protocols, proxyHost, proxyPort, headers) {
|
||||||
|
var self = this;
|
||||||
|
self.__id = WebSocket.__nextId++;
|
||||||
|
WebSocket.__instances[self.__id] = self;
|
||||||
|
self.readyState = WebSocket.CONNECTING;
|
||||||
|
self.bufferedAmount = 0;
|
||||||
|
self.__events = {};
|
||||||
|
if (!protocols) {
|
||||||
|
protocols = [];
|
||||||
|
} else if (typeof protocols == "string") {
|
||||||
|
protocols = [protocols];
|
||||||
|
}
|
||||||
|
// Uses setTimeout() to make sure __createFlash() runs after the caller sets ws.onopen etc.
|
||||||
|
// Otherwise, when onopen fires immediately, onopen is called before it is set.
|
||||||
|
self.__createTask = setTimeout(function() {
|
||||||
|
WebSocket.__addTask(function() {
|
||||||
|
self.__createTask = null;
|
||||||
|
WebSocket.__flash.create(
|
||||||
|
self.__id, url, protocols, proxyHost || null, proxyPort || 0, headers || null);
|
||||||
|
});
|
||||||
|
}, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send data to the web socket.
|
||||||
|
* @param {string} data The data to send to the socket.
|
||||||
|
* @return {boolean} True for success, false for failure.
|
||||||
|
*/
|
||||||
|
WebSocket.prototype.send = function(data) {
|
||||||
|
if (this.readyState == WebSocket.CONNECTING) {
|
||||||
|
throw "INVALID_STATE_ERR: Web Socket connection has not been established";
|
||||||
|
}
|
||||||
|
// We use encodeURIComponent() here, because FABridge doesn't work if
|
||||||
|
// the argument includes some characters. We don't use escape() here
|
||||||
|
// because of this:
|
||||||
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Functions#escape_and_unescape_Functions
|
||||||
|
// But it looks decodeURIComponent(encodeURIComponent(s)) doesn't
|
||||||
|
// preserve all Unicode characters either e.g. "\uffff" in Firefox.
|
||||||
|
// Note by wtritch: Hopefully this will not be necessary using ExternalInterface. Will require
|
||||||
|
// additional testing.
|
||||||
|
var result = WebSocket.__flash.send(this.__id, encodeURIComponent(data));
|
||||||
|
if (result < 0) { // success
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
this.bufferedAmount += result;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close this web socket gracefully.
|
||||||
|
*/
|
||||||
|
WebSocket.prototype.close = function() {
|
||||||
|
if (this.__createTask) {
|
||||||
|
clearTimeout(this.__createTask);
|
||||||
|
this.__createTask = null;
|
||||||
|
this.readyState = WebSocket.CLOSED;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.readyState == WebSocket.CLOSED || this.readyState == WebSocket.CLOSING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.readyState = WebSocket.CLOSING;
|
||||||
|
WebSocket.__flash.close(this.__id);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
||||||
|
*
|
||||||
|
* @param {string} type
|
||||||
|
* @param {function} listener
|
||||||
|
* @param {boolean} useCapture
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
WebSocket.prototype.addEventListener = function(type, listener, useCapture) {
|
||||||
|
if (!(type in this.__events)) {
|
||||||
|
this.__events[type] = [];
|
||||||
|
}
|
||||||
|
this.__events[type].push(listener);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
||||||
|
*
|
||||||
|
* @param {string} type
|
||||||
|
* @param {function} listener
|
||||||
|
* @param {boolean} useCapture
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
WebSocket.prototype.removeEventListener = function(type, listener, useCapture) {
|
||||||
|
if (!(type in this.__events)) return;
|
||||||
|
var events = this.__events[type];
|
||||||
|
for (var i = events.length - 1; i >= 0; --i) {
|
||||||
|
if (events[i] === listener) {
|
||||||
|
events.splice(i, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of {@link <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-registration">DOM 2 EventTarget Interface</a>}
|
||||||
|
*
|
||||||
|
* @param {Event} event
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
WebSocket.prototype.dispatchEvent = function(event) {
|
||||||
|
var events = this.__events[event.type] || [];
|
||||||
|
for (var i = 0; i < events.length; ++i) {
|
||||||
|
events[i](event);
|
||||||
|
}
|
||||||
|
var handler = this["on" + event.type];
|
||||||
|
if (handler) handler.apply(this, [event]);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles an event from Flash.
|
||||||
|
* @param {Object} flashEvent
|
||||||
|
*/
|
||||||
|
WebSocket.prototype.__handleEvent = function(flashEvent) {
|
||||||
|
|
||||||
|
if ("readyState" in flashEvent) {
|
||||||
|
this.readyState = flashEvent.readyState;
|
||||||
|
}
|
||||||
|
if ("protocol" in flashEvent) {
|
||||||
|
this.protocol = flashEvent.protocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
var jsEvent;
|
||||||
|
if (flashEvent.type == "open" || flashEvent.type == "error") {
|
||||||
|
jsEvent = this.__createSimpleEvent(flashEvent.type);
|
||||||
|
} else if (flashEvent.type == "close") {
|
||||||
|
jsEvent = this.__createSimpleEvent("close");
|
||||||
|
jsEvent.wasClean = flashEvent.wasClean ? true : false;
|
||||||
|
jsEvent.code = flashEvent.code;
|
||||||
|
jsEvent.reason = flashEvent.reason;
|
||||||
|
} else if (flashEvent.type == "message") {
|
||||||
|
var data = decodeURIComponent(flashEvent.message);
|
||||||
|
jsEvent = this.__createMessageEvent("message", data);
|
||||||
|
} else {
|
||||||
|
throw "unknown event type: " + flashEvent.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.dispatchEvent(jsEvent);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
WebSocket.prototype.__createSimpleEvent = function(type) {
|
||||||
|
if (document.createEvent && window.Event) {
|
||||||
|
var event = document.createEvent("Event");
|
||||||
|
event.initEvent(type, false, false);
|
||||||
|
return event;
|
||||||
|
} else {
|
||||||
|
return {type: type, bubbles: false, cancelable: false};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
WebSocket.prototype.__createMessageEvent = function(type, data) {
|
||||||
|
if (document.createEvent && window.MessageEvent && !window.opera) {
|
||||||
|
var event = document.createEvent("MessageEvent");
|
||||||
|
event.initMessageEvent("message", false, false, data, null, null, window, null);
|
||||||
|
return event;
|
||||||
|
} else {
|
||||||
|
// IE and Opera, the latter one truncates the data parameter after any 0x00 bytes.
|
||||||
|
return {type: type, data: data, bubbles: false, cancelable: false};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the WebSocket readyState enumeration.
|
||||||
|
*/
|
||||||
|
WebSocket.CONNECTING = 0;
|
||||||
|
WebSocket.OPEN = 1;
|
||||||
|
WebSocket.CLOSING = 2;
|
||||||
|
WebSocket.CLOSED = 3;
|
||||||
|
|
||||||
|
// Field to check implementation of WebSocket.
|
||||||
|
WebSocket.__isFlashImplementation = true;
|
||||||
|
WebSocket.__initialized = false;
|
||||||
|
WebSocket.__flash = null;
|
||||||
|
WebSocket.__instances = {};
|
||||||
|
WebSocket.__tasks = [];
|
||||||
|
WebSocket.__nextId = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a new flash security policy file.
|
||||||
|
* @param {string} url
|
||||||
|
*/
|
||||||
|
WebSocket.loadFlashPolicyFile = function(url){
|
||||||
|
WebSocket.__addTask(function() {
|
||||||
|
WebSocket.__flash.loadManualPolicyFile(url);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads WebSocketMain.swf and creates WebSocketMain object in Flash.
|
||||||
|
*/
|
||||||
|
WebSocket.__initialize = function() {
|
||||||
|
|
||||||
|
if (WebSocket.__initialized) return;
|
||||||
|
WebSocket.__initialized = true;
|
||||||
|
|
||||||
|
if (WebSocket.__swfLocation) {
|
||||||
|
// For backword compatibility.
|
||||||
|
window.WEB_SOCKET_SWF_LOCATION = WebSocket.__swfLocation;
|
||||||
|
}
|
||||||
|
if (!window.WEB_SOCKET_SWF_LOCATION) {
|
||||||
|
logger.error("[WebSocket] set WEB_SOCKET_SWF_LOCATION to location of WebSocketMain.swf");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!window.WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR &&
|
||||||
|
!WEB_SOCKET_SWF_LOCATION.match(/(^|\/)WebSocketMainInsecure\.swf(\?.*)?$/) &&
|
||||||
|
WEB_SOCKET_SWF_LOCATION.match(/^\w+:\/\/([^\/]+)/)) {
|
||||||
|
var swfHost = RegExp.$1;
|
||||||
|
if (location.host != swfHost) {
|
||||||
|
logger.error(
|
||||||
|
"[WebSocket] You must host HTML and WebSocketMain.swf in the same host " +
|
||||||
|
"('" + location.host + "' != '" + swfHost + "'). " +
|
||||||
|
"See also 'How to host HTML file and SWF file in different domains' section " +
|
||||||
|
"in README.md. If you use WebSocketMainInsecure.swf, you can suppress this message " +
|
||||||
|
"by WEB_SOCKET_SUPPRESS_CROSS_DOMAIN_SWF_ERROR = true;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var container = document.createElement("div");
|
||||||
|
container.id = "webSocketContainer";
|
||||||
|
// Hides Flash box. We cannot use display: none or visibility: hidden because it prevents
|
||||||
|
// Flash from loading at least in IE. So we move it out of the screen at (-100, -100).
|
||||||
|
// But this even doesn't work with Flash Lite (e.g. in Droid Incredible). So with Flash
|
||||||
|
// Lite, we put it at (0, 0). This shows 1x1 box visible at left-top corner but this is
|
||||||
|
// the best we can do as far as we know now.
|
||||||
|
container.style.position = "absolute";
|
||||||
|
if (WebSocket.__isFlashLite()) {
|
||||||
|
container.style.left = "0px";
|
||||||
|
container.style.top = "0px";
|
||||||
|
} else {
|
||||||
|
container.style.left = "-100px";
|
||||||
|
container.style.top = "-100px";
|
||||||
|
}
|
||||||
|
var holder = document.createElement("div");
|
||||||
|
holder.id = "webSocketFlash";
|
||||||
|
container.appendChild(holder);
|
||||||
|
document.body.appendChild(container);
|
||||||
|
// See this article for hasPriority:
|
||||||
|
// http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
|
||||||
|
swfobject.embedSWF(
|
||||||
|
WEB_SOCKET_SWF_LOCATION,
|
||||||
|
"webSocketFlash",
|
||||||
|
"1" /* width */,
|
||||||
|
"1" /* height */,
|
||||||
|
"10.0.0" /* SWF version */,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
{hasPriority: true, swliveconnect : true, allowScriptAccess: "always"},
|
||||||
|
null,
|
||||||
|
function(e) {
|
||||||
|
if (!e.success) {
|
||||||
|
logger.error("[WebSocket] swfobject.embedSWF failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by Flash to notify JS that it's fully loaded and ready
|
||||||
|
* for communication.
|
||||||
|
*/
|
||||||
|
WebSocket.__onFlashInitialized = function() {
|
||||||
|
// We need to set a timeout here to avoid round-trip calls
|
||||||
|
// to flash during the initialization process.
|
||||||
|
setTimeout(function() {
|
||||||
|
WebSocket.__flash = document.getElementById("webSocketFlash");
|
||||||
|
WebSocket.__flash.setCallerUrl(location.href);
|
||||||
|
WebSocket.__flash.setDebug(!!window.WEB_SOCKET_DEBUG);
|
||||||
|
for (var i = 0; i < WebSocket.__tasks.length; ++i) {
|
||||||
|
WebSocket.__tasks[i]();
|
||||||
|
}
|
||||||
|
WebSocket.__tasks = [];
|
||||||
|
}, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called by Flash to notify WebSockets events are fired.
|
||||||
|
*/
|
||||||
|
WebSocket.__onFlashEvent = function() {
|
||||||
|
setTimeout(function() {
|
||||||
|
try {
|
||||||
|
// Gets events using receiveEvents() instead of getting it from event object
|
||||||
|
// of Flash event. This is to make sure to keep message order.
|
||||||
|
// It seems sometimes Flash events don't arrive in the same order as they are sent.
|
||||||
|
var events = WebSocket.__flash.receiveEvents();
|
||||||
|
for (var i = 0; i < events.length; ++i) {
|
||||||
|
WebSocket.__instances[events[i].webSocketId].__handleEvent(events[i]);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
logger.error(e);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Called by Flash.
|
||||||
|
WebSocket.__log = function(message) {
|
||||||
|
logger.log(decodeURIComponent(message));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Called by Flash.
|
||||||
|
WebSocket.__error = function(message) {
|
||||||
|
logger.error(decodeURIComponent(message));
|
||||||
|
};
|
||||||
|
|
||||||
|
WebSocket.__addTask = function(task) {
|
||||||
|
if (WebSocket.__flash) {
|
||||||
|
task();
|
||||||
|
} else {
|
||||||
|
WebSocket.__tasks.push(task);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test if the browser is running flash lite.
|
||||||
|
* @return {boolean} True if flash lite is running, false otherwise.
|
||||||
|
*/
|
||||||
|
WebSocket.__isFlashLite = function() {
|
||||||
|
if (!window.navigator || !window.navigator.mimeTypes) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var mimeType = window.navigator.mimeTypes["application/x-shockwave-flash"];
|
||||||
|
if (!mimeType || !mimeType.enabledPlugin || !mimeType.enabledPlugin.filename) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return mimeType.enabledPlugin.filename.match(/flashlite/i) ? true : false;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION) {
|
||||||
|
// NOTE:
|
||||||
|
// This fires immediately if web_socket.js is dynamically loaded after
|
||||||
|
// the document is loaded.
|
||||||
|
swfobject.addDomLoadEvent(function() {
|
||||||
|
WebSocket.__initialize();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
422
static/js/novnc/websock.js
Normal file
422
static/js/novnc/websock.js
Normal file
|
@ -0,0 +1,422 @@
|
||||||
|
/*
|
||||||
|
* Websock: high-performance binary WebSockets
|
||||||
|
* Copyright (C) 2012 Joel Martin
|
||||||
|
* 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)
|
||||||
|
* via websockify. This is accomplished by base64 encoding the data
|
||||||
|
* stream between Websock and websockify.
|
||||||
|
*
|
||||||
|
* Websock has built-in receive queue buffering; the message event
|
||||||
|
* does not contain actual data but is simply a notification that
|
||||||
|
* there is new data available. Several rQ* methods are available to
|
||||||
|
* read binary data off of the receive queue.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*jslint browser: true, bitwise: false, plusplus: false */
|
||||||
|
/*global Util, Base64 */
|
||||||
|
|
||||||
|
|
||||||
|
// Load Flash WebSocket emulator if needed
|
||||||
|
|
||||||
|
// To force WebSocket emulator even when native WebSocket available
|
||||||
|
//window.WEB_SOCKET_FORCE_FLASH = true;
|
||||||
|
// To enable WebSocket emulator debug:
|
||||||
|
//window.WEB_SOCKET_DEBUG=1;
|
||||||
|
|
||||||
|
if (window.WebSocket && !window.WEB_SOCKET_FORCE_FLASH) {
|
||||||
|
Websock_native = true;
|
||||||
|
} else if (window.MozWebSocket && !window.WEB_SOCKET_FORCE_FLASH) {
|
||||||
|
Websock_native = true;
|
||||||
|
window.WebSocket = window.MozWebSocket;
|
||||||
|
} else {
|
||||||
|
/* no builtin WebSocket so load web_socket.js */
|
||||||
|
|
||||||
|
Websock_native = false;
|
||||||
|
(function () {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
Util.load_scripts(["web-socket-js/swfobject.js",
|
||||||
|
"web-socket-js/web_socket.js"]);
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function Websock() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var api = {}, // Public API
|
||||||
|
websocket = null, // WebSocket object
|
||||||
|
mode = 'base64', // Current WebSocket mode: 'binary', 'base64'
|
||||||
|
rQ = [], // Receive queue
|
||||||
|
rQi = 0, // Receive queue index
|
||||||
|
rQmax = 10000, // Max receive queue size before compacting
|
||||||
|
sQ = [], // Send queue
|
||||||
|
|
||||||
|
eventHandlers = {
|
||||||
|
'message' : function() {},
|
||||||
|
'open' : function() {},
|
||||||
|
'close' : function() {},
|
||||||
|
'error' : function() {}
|
||||||
|
},
|
||||||
|
|
||||||
|
test_mode = false;
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Queue public functions
|
||||||
|
//
|
||||||
|
|
||||||
|
function get_sQ() {
|
||||||
|
return sQ;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_rQ() {
|
||||||
|
return rQ;
|
||||||
|
}
|
||||||
|
function get_rQi() {
|
||||||
|
return rQi;
|
||||||
|
}
|
||||||
|
function set_rQi(val) {
|
||||||
|
rQi = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rQlen() {
|
||||||
|
return rQ.length - rQi;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rQpeek8() {
|
||||||
|
return (rQ[rQi] );
|
||||||
|
}
|
||||||
|
function rQshift8() {
|
||||||
|
return (rQ[rQi++] );
|
||||||
|
}
|
||||||
|
function rQunshift8(num) {
|
||||||
|
if (rQi === 0) {
|
||||||
|
rQ.unshift(num);
|
||||||
|
} else {
|
||||||
|
rQi -= 1;
|
||||||
|
rQ[rQi] = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
function rQshift16() {
|
||||||
|
return (rQ[rQi++] << 8) +
|
||||||
|
(rQ[rQi++] );
|
||||||
|
}
|
||||||
|
function rQshift32() {
|
||||||
|
return (rQ[rQi++] << 24) +
|
||||||
|
(rQ[rQi++] << 16) +
|
||||||
|
(rQ[rQi++] << 8) +
|
||||||
|
(rQ[rQi++] );
|
||||||
|
}
|
||||||
|
function rQshiftStr(len) {
|
||||||
|
if (typeof(len) === 'undefined') { len = rQlen(); }
|
||||||
|
var arr = rQ.slice(rQi, rQi + len);
|
||||||
|
rQi += len;
|
||||||
|
return String.fromCharCode.apply(null, arr);
|
||||||
|
}
|
||||||
|
function rQshiftBytes(len) {
|
||||||
|
if (typeof(len) === 'undefined') { len = rQlen(); }
|
||||||
|
rQi += len;
|
||||||
|
return rQ.slice(rQi-len, rQi);
|
||||||
|
}
|
||||||
|
|
||||||
|
function rQslice(start, end) {
|
||||||
|
if (end) {
|
||||||
|
return rQ.slice(rQi + start, rQi + end);
|
||||||
|
} else {
|
||||||
|
return rQ.slice(rQi + start);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check to see if we must wait for 'num' bytes (default to FBU.bytes)
|
||||||
|
// to be available in the receive queue. Return true if we need to
|
||||||
|
// wait (and possibly print a debug message), otherwise false.
|
||||||
|
function rQwait(msg, num, goback) {
|
||||||
|
var rQlen = rQ.length - rQi; // Skip rQlen() function call
|
||||||
|
if (rQlen < num) {
|
||||||
|
if (goback) {
|
||||||
|
if (rQi < goback) {
|
||||||
|
throw("rQwait cannot backup " + goback + " bytes");
|
||||||
|
}
|
||||||
|
rQi -= goback;
|
||||||
|
}
|
||||||
|
//Util.Debug(" waiting for " + (num-rQlen) +
|
||||||
|
// " " + msg + " byte(s)");
|
||||||
|
return true; // true means need more data
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Private utility routines
|
||||||
|
//
|
||||||
|
|
||||||
|
function encode_message() {
|
||||||
|
if (mode === 'binary') {
|
||||||
|
// Put in a binary arraybuffer
|
||||||
|
return (new Uint8Array(sQ)).buffer;
|
||||||
|
} else {
|
||||||
|
// base64 encode
|
||||||
|
return Base64.encode(sQ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function decode_message(data) {
|
||||||
|
//Util.Debug(">> decode_message: " + data);
|
||||||
|
if (mode === 'binary') {
|
||||||
|
// push arraybuffer values onto the end
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
//Util.Debug(">> decode_message, rQ: " + rQ);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Public Send functions
|
||||||
|
//
|
||||||
|
|
||||||
|
function flush() {
|
||||||
|
if (websocket.bufferedAmount !== 0) {
|
||||||
|
Util.Debug("bufferedAmount: " + websocket.bufferedAmount);
|
||||||
|
}
|
||||||
|
if (websocket.bufferedAmount < api.maxBufferedAmount) {
|
||||||
|
//Util.Debug("arr: " + arr);
|
||||||
|
//Util.Debug("sQ: " + sQ);
|
||||||
|
if (sQ.length > 0) {
|
||||||
|
websocket.send(encode_message(sQ));
|
||||||
|
sQ = [];
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
Util.Info("Delaying send, bufferedAmount: " +
|
||||||
|
websocket.bufferedAmount);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// overridable for testing
|
||||||
|
function send(arr) {
|
||||||
|
//Util.Debug(">> send_array: " + arr);
|
||||||
|
sQ = sQ.concat(arr);
|
||||||
|
return flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
function send_string(str) {
|
||||||
|
//Util.Debug(">> send_string: " + str);
|
||||||
|
api.send(str.split('').map(
|
||||||
|
function (chr) { return chr.charCodeAt(0); } ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Other public functions
|
||||||
|
|
||||||
|
function recv_message(e) {
|
||||||
|
//Util.Debug(">> recv_message: " + e.data.length);
|
||||||
|
|
||||||
|
try {
|
||||||
|
decode_message(e.data);
|
||||||
|
if (rQlen() > 0) {
|
||||||
|
eventHandlers.message();
|
||||||
|
// Compact the receive queue
|
||||||
|
if (rQ.length > rQmax) {
|
||||||
|
//Util.Debug("Compacting receive queue");
|
||||||
|
rQ = rQ.slice(rQi);
|
||||||
|
rQi = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Util.Debug("Ignoring empty message");
|
||||||
|
}
|
||||||
|
} catch (exc) {
|
||||||
|
if (typeof exc.stack !== 'undefined') {
|
||||||
|
Util.Warn("recv_message, caught exception: " + exc.stack);
|
||||||
|
} else if (typeof exc.description !== 'undefined') {
|
||||||
|
Util.Warn("recv_message, caught exception: " + exc.description);
|
||||||
|
} else {
|
||||||
|
Util.Warn("recv_message, caught exception:" + exc);
|
||||||
|
}
|
||||||
|
if (typeof exc.name !== 'undefined') {
|
||||||
|
eventHandlers.error(exc.name + ": " + exc.message);
|
||||||
|
} else {
|
||||||
|
eventHandlers.error(exc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Util.Debug("<< recv_message");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Set event handlers
|
||||||
|
function on(evt, handler) {
|
||||||
|
eventHandlers[evt] = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
function init(protocols) {
|
||||||
|
rQ = [];
|
||||||
|
rQi = 0;
|
||||||
|
sQ = [];
|
||||||
|
websocket = null;
|
||||||
|
|
||||||
|
var bt = false,
|
||||||
|
wsbt = false,
|
||||||
|
try_binary = false;
|
||||||
|
|
||||||
|
// Check for full typed array support
|
||||||
|
if (('Uint8Array' in window) &&
|
||||||
|
('set' in Uint8Array.prototype)) {
|
||||||
|
bt = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for full binary type support in WebSockets
|
||||||
|
// TODO: this sucks, the property should exist on the prototype
|
||||||
|
// but it does not.
|
||||||
|
try {
|
||||||
|
if (bt && ('binaryType' in (new WebSocket("ws://localhost:17523")))) {
|
||||||
|
Util.Info("Detected binaryType support in WebSockets");
|
||||||
|
wsbt = true;
|
||||||
|
}
|
||||||
|
} catch (exc) {
|
||||||
|
// Just ignore failed test localhost connections
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default protocols if not specified
|
||||||
|
if (typeof(protocols) === "undefined") {
|
||||||
|
if (wsbt) {
|
||||||
|
protocols = ['binary', 'base64'];
|
||||||
|
} else {
|
||||||
|
protocols = 'base64';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no binary support, make sure it was not requested
|
||||||
|
if (!wsbt) {
|
||||||
|
if (protocols === 'binary') {
|
||||||
|
throw("WebSocket binary sub-protocol requested but not supported");
|
||||||
|
}
|
||||||
|
if (typeof(protocols) === "object") {
|
||||||
|
var new_protocols = [];
|
||||||
|
for (var i = 0; i < protocols.length; i++) {
|
||||||
|
if (protocols[i] === 'binary') {
|
||||||
|
Util.Error("Skipping unsupported WebSocket binary sub-protocol");
|
||||||
|
} else {
|
||||||
|
new_protocols.push(protocols[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (new_protocols.length > 0) {
|
||||||
|
protocols = new_protocols;
|
||||||
|
} else {
|
||||||
|
throw("Only WebSocket binary sub-protocol was requested and not supported.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return protocols;
|
||||||
|
}
|
||||||
|
|
||||||
|
function open(uri, protocols) {
|
||||||
|
protocols = init(protocols);
|
||||||
|
|
||||||
|
if (test_mode) {
|
||||||
|
websocket = {};
|
||||||
|
} else {
|
||||||
|
websocket = new WebSocket(uri, protocols);
|
||||||
|
if (protocols.indexOf('binary') >= 0) {
|
||||||
|
websocket.binaryType = 'arraybuffer';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
websocket.onmessage = recv_message;
|
||||||
|
websocket.onopen = function() {
|
||||||
|
Util.Debug(">> WebSock.onopen");
|
||||||
|
if (websocket.protocol) {
|
||||||
|
mode = websocket.protocol;
|
||||||
|
Util.Info("Server chose sub-protocol: " + websocket.protocol);
|
||||||
|
} else {
|
||||||
|
mode = 'base64';
|
||||||
|
Util.Error("Server select no sub-protocol!: " + websocket.protocol);
|
||||||
|
}
|
||||||
|
eventHandlers.open();
|
||||||
|
Util.Debug("<< WebSock.onopen");
|
||||||
|
};
|
||||||
|
websocket.onclose = function(e) {
|
||||||
|
Util.Debug(">> WebSock.onclose");
|
||||||
|
eventHandlers.close(e);
|
||||||
|
Util.Debug("<< WebSock.onclose");
|
||||||
|
};
|
||||||
|
websocket.onerror = function(e) {
|
||||||
|
Util.Debug(">> WebSock.onerror: " + e);
|
||||||
|
eventHandlers.error(e);
|
||||||
|
Util.Debug("<< WebSock.onerror");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
if (websocket) {
|
||||||
|
if ((websocket.readyState === WebSocket.OPEN) ||
|
||||||
|
(websocket.readyState === WebSocket.CONNECTING)) {
|
||||||
|
Util.Info("Closing WebSocket connection");
|
||||||
|
websocket.close();
|
||||||
|
}
|
||||||
|
websocket.onmessage = function (e) { return; };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Override internal functions for testing
|
||||||
|
// Takes a send function, returns reference to recv function
|
||||||
|
function testMode(override_send, data_mode) {
|
||||||
|
test_mode = true;
|
||||||
|
mode = data_mode;
|
||||||
|
api.send = override_send;
|
||||||
|
api.close = function () {};
|
||||||
|
return recv_message;
|
||||||
|
}
|
||||||
|
|
||||||
|
function constructor() {
|
||||||
|
// Configuration settings
|
||||||
|
api.maxBufferedAmount = 200;
|
||||||
|
|
||||||
|
// Direct access to send and receive queues
|
||||||
|
api.get_sQ = get_sQ;
|
||||||
|
api.get_rQ = get_rQ;
|
||||||
|
api.get_rQi = get_rQi;
|
||||||
|
api.set_rQi = set_rQi;
|
||||||
|
|
||||||
|
// Routines to read from the receive queue
|
||||||
|
api.rQlen = rQlen;
|
||||||
|
api.rQpeek8 = rQpeek8;
|
||||||
|
api.rQshift8 = rQshift8;
|
||||||
|
api.rQunshift8 = rQunshift8;
|
||||||
|
api.rQshift16 = rQshift16;
|
||||||
|
api.rQshift32 = rQshift32;
|
||||||
|
api.rQshiftStr = rQshiftStr;
|
||||||
|
api.rQshiftBytes = rQshiftBytes;
|
||||||
|
api.rQslice = rQslice;
|
||||||
|
api.rQwait = rQwait;
|
||||||
|
|
||||||
|
api.flush = flush;
|
||||||
|
api.send = send;
|
||||||
|
api.send_string = send_string;
|
||||||
|
|
||||||
|
api.on = on;
|
||||||
|
api.init = init;
|
||||||
|
api.open = open;
|
||||||
|
api.close = close;
|
||||||
|
api.testMode = testMode;
|
||||||
|
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
|
||||||
|
return constructor();
|
||||||
|
|
||||||
|
}
|
216
static/js/novnc/webutil.js
Normal file
216
static/js/novnc/webutil.js
Normal file
|
@ -0,0 +1,216 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
/*jslint bitwise: false, white: false */
|
||||||
|
/*global Util, window, document */
|
||||||
|
|
||||||
|
// Globals defined here
|
||||||
|
var WebUtil = {}, $D;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Simple DOM selector by ID
|
||||||
|
*/
|
||||||
|
if (!window.$D) {
|
||||||
|
window.$D = function (id) {
|
||||||
|
if (document.getElementById) {
|
||||||
|
return document.getElementById(id);
|
||||||
|
} else if (document.all) {
|
||||||
|
return document.all[id];
|
||||||
|
} else if (document.layers) {
|
||||||
|
return document.layers[id];
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ------------------------------------------------------
|
||||||
|
* Namespaced in WebUtil
|
||||||
|
* ------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
// init log level reading the logging HTTP param
|
||||||
|
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.dirObj = function (obj, depth, parent) {
|
||||||
|
var i, msg = "", val = "";
|
||||||
|
if (! depth) { depth=2; }
|
||||||
|
if (! parent) { parent= ""; }
|
||||||
|
|
||||||
|
// Print the properties of the passed-in object
|
||||||
|
for (i in obj) {
|
||||||
|
if ((depth > 1) && (typeof obj[i] === "object")) {
|
||||||
|
// Recurse attributes that are objects
|
||||||
|
msg += WebUtil.dirObj(obj[i], depth-1, parent + "." + i);
|
||||||
|
} else {
|
||||||
|
//val = new String(obj[i]).replace("\n", " ");
|
||||||
|
if (typeof(obj[i]) === "undefined") {
|
||||||
|
val = "undefined";
|
||||||
|
} else {
|
||||||
|
val = obj[i].toString().replace("\n", " ");
|
||||||
|
}
|
||||||
|
if (val.length > 30) {
|
||||||
|
val = val.substr(0,30) + "...";
|
||||||
|
}
|
||||||
|
msg += parent + "." + i + ": " + val + "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Read a query string variable
|
||||||
|
WebUtil.getQueryVar = function(name, defVal) {
|
||||||
|
var re = new RegExp('[?][^#]*' + name + '=([^&#]*)'),
|
||||||
|
match = document.location.href.match(re);
|
||||||
|
if (typeof defVal === 'undefined') { defVal = null; }
|
||||||
|
if (match) {
|
||||||
|
return decodeURIComponent(match[1]);
|
||||||
|
} else {
|
||||||
|
return defVal;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cookie handling. Dervied from: http://www.quirksmode.org/js/cookies.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
// No days means only for this browser session
|
||||||
|
WebUtil.createCookie = function(name,value,days) {
|
||||||
|
var date, expires;
|
||||||
|
if (days) {
|
||||||
|
date = new Date();
|
||||||
|
date.setTime(date.getTime()+(days*24*60*60*1000));
|
||||||
|
expires = "; expires="+date.toGMTString();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
expires = "";
|
||||||
|
}
|
||||||
|
document.cookie = name+"="+value+expires+"; path=/";
|
||||||
|
};
|
||||||
|
|
||||||
|
WebUtil.readCookie = function(name, defaultValue) {
|
||||||
|
var i, c, nameEQ = name + "=", ca = document.cookie.split(';');
|
||||||
|
for(i=0; i < ca.length; i += 1) {
|
||||||
|
c = ca[i];
|
||||||
|
while (c.charAt(0) === ' ') { c = c.substring(1,c.length); }
|
||||||
|
if (c.indexOf(nameEQ) === 0) { return c.substring(nameEQ.length,c.length); }
|
||||||
|
}
|
||||||
|
return (typeof defaultValue !== 'undefined') ? defaultValue : null;
|
||||||
|
};
|
||||||
|
|
||||||
|
WebUtil.eraseCookie = function(name) {
|
||||||
|
WebUtil.createCookie(name,"",-1);
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 = [];
|
||||||
|
links = document.getElementsByTagName("link");
|
||||||
|
for (i = 0; i < links.length; i += 1) {
|
||||||
|
if (links[i].title &&
|
||||||
|
links[i].rel.toUpperCase().indexOf("STYLESHEET") > -1) {
|
||||||
|
sheets.push(links[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sheets;
|
||||||
|
};
|
||||||
|
|
||||||
|
// No sheet means try and use value from cookie, null sheet used to
|
||||||
|
// clear all alternates.
|
||||||
|
WebUtil.selectStylesheet = function(sheet) {
|
||||||
|
var i, link, sheets = WebUtil.getStylesheets();
|
||||||
|
if (typeof sheet === 'undefined') {
|
||||||
|
sheet = 'default';
|
||||||
|
}
|
||||||
|
for (i=0; i < sheets.length; i += 1) {
|
||||||
|
link = sheets[i];
|
||||||
|
if (link.title === sheet) {
|
||||||
|
Util.Debug("Using stylesheet " + sheet);
|
||||||
|
link.disabled = false;
|
||||||
|
} else {
|
||||||
|
//Util.Debug("Skipping stylesheet " + link.title);
|
||||||
|
link.disabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sheet;
|
||||||
|
};
|
183
static/js/spice-html5/atKeynames.js
Normal file
183
static/js/spice-html5/atKeynames.js
Normal file
|
@ -0,0 +1,183 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Aric Stewart <aric@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
||||||
|
* documentation for any purpose is hereby granted without fee, provided that
|
||||||
|
* the above copyright notice appear in all copies and that both that
|
||||||
|
* copyright notice and this permission notice appear in supporting
|
||||||
|
* documentation, and that the name of Thomas Roell not be used in
|
||||||
|
* advertising or publicity pertaining to distribution of the software without
|
||||||
|
* specific, written prior permission. Thomas Roell makes no representations
|
||||||
|
* about the suitability of this software for any purpose. It is provided
|
||||||
|
* "as is" without express or implied warranty.
|
||||||
|
*
|
||||||
|
* THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
||||||
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
||||||
|
* EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
||||||
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
||||||
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
||||||
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1994-2003 by The XFree86 Project, Inc.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the "Software"),
|
||||||
|
* to deal in the Software without restriction, including without limitation
|
||||||
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
* and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
* Software is furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||||
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
* OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* Except as contained in this notice, the name of the copyright holder(s)
|
||||||
|
* and author(s) shall not be used in advertising or otherwise to promote
|
||||||
|
* the sale, use or other dealings in this Software without prior written
|
||||||
|
* authorization from the copyright holder(s) and author(s).
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NOTE: The AT/MF keyboards can generate (via the 8042) two (MF: three)
|
||||||
|
* sets of scancodes. Set3 can only be generated by a MF keyboard.
|
||||||
|
* Set2 sends a makecode for keypress, and the same code prefixed by a
|
||||||
|
* F0 for keyrelease. This is a little bit ugly to handle. Thus we use
|
||||||
|
* here for X386 the PC/XT compatible Set1. This set uses 8bit scancodes.
|
||||||
|
* Bit 7 ist set if the key is released. The code E0 switches to a
|
||||||
|
* different meaning to add the new MF cursorkeys, while not breaking old
|
||||||
|
* applications. E1 is another special prefix. Since I assume that there
|
||||||
|
* will be further versions of PC/XT scancode compatible keyboards, we
|
||||||
|
* may be in trouble one day.
|
||||||
|
*
|
||||||
|
* IDEA: 1) Use Set2 on AT84 keyboards and translate it to MF Set3.
|
||||||
|
* 2) Use the keyboards native set and translate it to common keysyms.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* definition of the AT84/MF101/MF102 Keyboard:
|
||||||
|
* ============================================================
|
||||||
|
* Defined Key Cap Glyphs Pressed value
|
||||||
|
* Key Name Main Also (hex) (dec)
|
||||||
|
* ---------------- ---------- ------- ------ ------
|
||||||
|
*/
|
||||||
|
|
||||||
|
var KEY_Escape =/* Escape 0x01 */ 1
|
||||||
|
var KEY_1 =/* 1 ! 0x02 */ 2
|
||||||
|
var KEY_2 =/* 2 @ 0x03 */ 3
|
||||||
|
var KEY_3 =/* 3 # 0x04 */ 4
|
||||||
|
var KEY_4 =/* 4 $ 0x05 */ 5
|
||||||
|
var KEY_5 =/* 5 % 0x06 */ 6
|
||||||
|
var KEY_6 =/* 6 ^ 0x07 */ 7
|
||||||
|
var KEY_7 =/* 7 & 0x08 */ 8
|
||||||
|
var KEY_8 =/* 8 * 0x09 */ 9
|
||||||
|
var KEY_9 =/* 9 ( 0x0a */ 10
|
||||||
|
var KEY_0 =/* 0 ) 0x0b */ 11
|
||||||
|
var KEY_Minus =/* - (Minus) _ (Under) 0x0c */ 12
|
||||||
|
var KEY_Equal =/* = (Equal) + 0x0d */ 13
|
||||||
|
var KEY_BackSpace =/* Back Space 0x0e */ 14
|
||||||
|
var KEY_Tab =/* Tab 0x0f */ 15
|
||||||
|
var KEY_Q =/* Q 0x10 */ 16
|
||||||
|
var KEY_W =/* W 0x11 */ 17
|
||||||
|
var KEY_E =/* E 0x12 */ 18
|
||||||
|
var KEY_R =/* R 0x13 */ 19
|
||||||
|
var KEY_T =/* T 0x14 */ 20
|
||||||
|
var KEY_Y =/* Y 0x15 */ 21
|
||||||
|
var KEY_U =/* U 0x16 */ 22
|
||||||
|
var KEY_I =/* I 0x17 */ 23
|
||||||
|
var KEY_O =/* O 0x18 */ 24
|
||||||
|
var KEY_P =/* P 0x19 */ 25
|
||||||
|
var KEY_LBrace =/* [ { 0x1a */ 26
|
||||||
|
var KEY_RBrace =/* ] } 0x1b */ 27
|
||||||
|
var KEY_Enter =/* Enter 0x1c */ 28
|
||||||
|
var KEY_LCtrl =/* Ctrl(left) 0x1d */ 29
|
||||||
|
var KEY_A =/* A 0x1e */ 30
|
||||||
|
var KEY_S =/* S 0x1f */ 31
|
||||||
|
var KEY_D =/* D 0x20 */ 32
|
||||||
|
var KEY_F =/* F 0x21 */ 33
|
||||||
|
var KEY_G =/* G 0x22 */ 34
|
||||||
|
var KEY_H =/* H 0x23 */ 35
|
||||||
|
var KEY_J =/* J 0x24 */ 36
|
||||||
|
var KEY_K =/* K 0x25 */ 37
|
||||||
|
var KEY_L =/* L 0x26 */ 38
|
||||||
|
var KEY_SemiColon =/* ;(SemiColon) :(Colon) 0x27 */ 39
|
||||||
|
var KEY_Quote =/* ' (Apostr) " (Quote) 0x28 */ 40
|
||||||
|
var KEY_Tilde =/* ` (Accent) ~ (Tilde) 0x29 */ 41
|
||||||
|
var KEY_ShiftL =/* Shift(left) 0x2a */ 42
|
||||||
|
var KEY_BSlash =/* \(BckSlash) |(VertBar)0x2b */ 43
|
||||||
|
var KEY_Z =/* Z 0x2c */ 44
|
||||||
|
var KEY_X =/* X 0x2d */ 45
|
||||||
|
var KEY_C =/* C 0x2e */ 46
|
||||||
|
var KEY_V =/* V 0x2f */ 47
|
||||||
|
var KEY_B =/* B 0x30 */ 48
|
||||||
|
var KEY_N =/* N 0x31 */ 49
|
||||||
|
var KEY_M =/* M 0x32 */ 50
|
||||||
|
var KEY_Comma =/* , (Comma) < (Less) 0x33 */ 51
|
||||||
|
var KEY_Period =/* . (Period) >(Greater)0x34 */ 52
|
||||||
|
var KEY_Slash =/* / (Slash) ? 0x35 */ 53
|
||||||
|
var KEY_ShiftR =/* Shift(right) 0x36 */ 54
|
||||||
|
var KEY_KP_Multiply =/* * 0x37 */ 55
|
||||||
|
var KEY_Alt =/* Alt(left) 0x38 */ 56
|
||||||
|
var KEY_Space =/* (SpaceBar) 0x39 */ 57
|
||||||
|
var KEY_CapsLock =/* CapsLock 0x3a */ 58
|
||||||
|
var KEY_F1 =/* F1 0x3b */ 59
|
||||||
|
var KEY_F2 =/* F2 0x3c */ 60
|
||||||
|
var KEY_F3 =/* F3 0x3d */ 61
|
||||||
|
var KEY_F4 =/* F4 0x3e */ 62
|
||||||
|
var KEY_F5 =/* F5 0x3f */ 63
|
||||||
|
var KEY_F6 =/* F6 0x40 */ 64
|
||||||
|
var KEY_F7 =/* F7 0x41 */ 65
|
||||||
|
var KEY_F8 =/* F8 0x42 */ 66
|
||||||
|
var KEY_F9 =/* F9 0x43 */ 67
|
||||||
|
var KEY_F10 =/* F10 0x44 */ 68
|
||||||
|
var KEY_NumLock =/* NumLock 0x45 */ 69
|
||||||
|
var KEY_ScrollLock =/* ScrollLock 0x46 */ 70
|
||||||
|
var KEY_KP_7 =/* 7 Home 0x47 */ 71
|
||||||
|
var KEY_KP_8 =/* 8 Up 0x48 */ 72
|
||||||
|
var KEY_KP_9 =/* 9 PgUp 0x49 */ 73
|
||||||
|
var KEY_KP_Minus =/* - (Minus) 0x4a */ 74
|
||||||
|
var KEY_KP_4 =/* 4 Left 0x4b */ 75
|
||||||
|
var KEY_KP_5 =/* 5 0x4c */ 76
|
||||||
|
var KEY_KP_6 =/* 6 Right 0x4d */ 77
|
||||||
|
var KEY_KP_Plus =/* + (Plus) 0x4e */ 78
|
||||||
|
var KEY_KP_1 =/* 1 End 0x4f */ 79
|
||||||
|
var KEY_KP_2 =/* 2 Down 0x50 */ 80
|
||||||
|
var KEY_KP_3 =/* 3 PgDown 0x51 */ 81
|
||||||
|
var KEY_KP_0 =/* 0 Insert 0x52 */ 82
|
||||||
|
var KEY_KP_Decimal =/* . (Decimal) Delete 0x53 */ 83
|
||||||
|
var KEY_SysReqest =/* SysReqest 0x54 */ 84
|
||||||
|
/* NOTUSED 0x55 */
|
||||||
|
var KEY_Less =/* < (Less) >(Greater) 0x56 */ 86
|
||||||
|
var KEY_F11 =/* F11 0x57 */ 87
|
||||||
|
var KEY_F12 =/* F12 0x58 */ 88
|
||||||
|
|
||||||
|
var KEY_Prefix0 =/* special 0x60 */ 96
|
||||||
|
var KEY_Prefix1 =/* specail 0x61 */ 97
|
51
static/js/spice-html5/bitmap.js
Normal file
51
static/js/spice-html5/bitmap.js
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** bitmap.js
|
||||||
|
** Handle SPICE_IMAGE_TYPE_BITMAP
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function convert_spice_bitmap_to_web(context, spice_bitmap)
|
||||||
|
{
|
||||||
|
var ret;
|
||||||
|
var offset, x;
|
||||||
|
var u8 = new Uint8Array(spice_bitmap.data);
|
||||||
|
if (spice_bitmap.format != SPICE_BITMAP_FMT_32BIT &&
|
||||||
|
spice_bitmap.format != SPICE_BITMAP_FMT_RGBA)
|
||||||
|
return undefined;
|
||||||
|
|
||||||
|
ret = context.createImageData(spice_bitmap.x, spice_bitmap.y);
|
||||||
|
for (offset = 0; offset < (spice_bitmap.y * spice_bitmap.stride); )
|
||||||
|
for (x = 0; x < spice_bitmap.x; x++, offset += 4)
|
||||||
|
{
|
||||||
|
ret.data[offset + 0 ] = u8[offset + 2];
|
||||||
|
ret.data[offset + 1 ] = u8[offset + 1];
|
||||||
|
ret.data[offset + 2 ] = u8[offset + 0];
|
||||||
|
|
||||||
|
// FIXME - We effectively treat all images as having SPICE_IMAGE_FLAGS_HIGH_BITS_SET
|
||||||
|
if (spice_bitmap.format == SPICE_BITMAP_FMT_32BIT)
|
||||||
|
ret.data[offset + 3] = 255;
|
||||||
|
else
|
||||||
|
ret.data[offset + 3] = u8[offset];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
110
static/js/spice-html5/cursor.js
Normal file
110
static/js/spice-html5/cursor.js
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** SpiceCursorConn
|
||||||
|
** Drive the Spice Cursor Channel
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function SpiceCursorConn()
|
||||||
|
{
|
||||||
|
SpiceConn.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceCursorConn.prototype = Object.create(SpiceConn.prototype);
|
||||||
|
SpiceCursorConn.prototype.process_channel_message = function(msg)
|
||||||
|
{
|
||||||
|
if (msg.type == SPICE_MSG_CURSOR_INIT)
|
||||||
|
{
|
||||||
|
var cursor_init = new SpiceMsgCursorInit(msg.data);
|
||||||
|
DEBUG > 1 && console.log("SpiceMsgCursorInit");
|
||||||
|
if (this.parent && this.parent.inputs &&
|
||||||
|
this.parent.inputs.mouse_mode == SPICE_MOUSE_MODE_SERVER)
|
||||||
|
{
|
||||||
|
// FIXME - this imagines that the server actually
|
||||||
|
// provides the current cursor position,
|
||||||
|
// instead of 0,0. As of May 11, 2012,
|
||||||
|
// that assumption was false :-(.
|
||||||
|
this.parent.inputs.mousex = cursor_init.position.x;
|
||||||
|
this.parent.inputs.mousey = cursor_init.position.y;
|
||||||
|
}
|
||||||
|
// FIXME - We don't handle most of the parameters here...
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_CURSOR_SET)
|
||||||
|
{
|
||||||
|
var cursor_set = new SpiceMsgCursorSet(msg.data);
|
||||||
|
DEBUG > 1 && console.log("SpiceMsgCursorSet");
|
||||||
|
if (cursor_set.flags & SPICE_CURSOR_FLAGS_NONE)
|
||||||
|
{
|
||||||
|
document.getElementById(this.parent.screen_id).style.cursor = "none";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cursor_set.flags > 0)
|
||||||
|
this.log_warn("FIXME: No support for cursor flags " + cursor_set.flags);
|
||||||
|
|
||||||
|
if (cursor_set.cursor.header.type != SPICE_CURSOR_TYPE_ALPHA)
|
||||||
|
{
|
||||||
|
this.log_warn("FIXME: No support for cursor type " + cursor_set.cursor.header.type);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.set_cursor(cursor_set.cursor);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_CURSOR_HIDE)
|
||||||
|
{
|
||||||
|
DEBUG > 1 && console.log("SpiceMsgCursorHide");
|
||||||
|
document.getElementById(this.parent.screen_id).style.cursor = "none";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_CURSOR_RESET)
|
||||||
|
{
|
||||||
|
DEBUG > 1 && console.log("SpiceMsgCursorReset");
|
||||||
|
document.getElementById(this.parent.screen_id).style.cursor = "auto";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_CURSOR_INVAL_ALL)
|
||||||
|
{
|
||||||
|
DEBUG > 1 && console.log("SpiceMsgCursorInvalAll");
|
||||||
|
// FIXME - There may be something useful to do here...
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceCursorConn.prototype.set_cursor = function(cursor)
|
||||||
|
{
|
||||||
|
var pngstr = create_rgba_png(cursor.header.height, cursor.header.width, cursor.data);
|
||||||
|
var curstr = 'url(data:image/png,' + pngstr + ') ' +
|
||||||
|
cursor.header.hot_spot_x + ' ' + cursor.header.hot_spot_y + ", default";
|
||||||
|
var screen = document.getElementById(this.parent.screen_id);
|
||||||
|
screen.style.cursor = 'auto';
|
||||||
|
screen.style.cursor = curstr;
|
||||||
|
if (window.getComputedStyle(screen, null).cursor == 'auto')
|
||||||
|
SpiceSimulateCursor.simulate_cursor(this, cursor, screen, pngstr);
|
||||||
|
}
|
823
static/js/spice-html5/display.js
Normal file
823
static/js/spice-html5/display.js
Normal file
|
@ -0,0 +1,823 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** FIXME: putImageData does not support Alpha blending
|
||||||
|
** or compositing. So if we have data in an ImageData
|
||||||
|
** format, we have to draw it onto a context,
|
||||||
|
** and then use drawImage to put it onto the target,
|
||||||
|
** as drawImage does alpha.
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function putImageDataWithAlpha(context, d, x, y)
|
||||||
|
{
|
||||||
|
var c = document.createElement("canvas");
|
||||||
|
var t = c.getContext("2d");
|
||||||
|
c.setAttribute('width', d.width);
|
||||||
|
c.setAttribute('height', d.height);
|
||||||
|
t.putImageData(d, 0, 0);
|
||||||
|
context.drawImage(c, x, y, d.width, d.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** FIXME: Spice will send an image with '0' alpha when it is intended to
|
||||||
|
** go on a surface w/no alpha. So in that case, we have to strip
|
||||||
|
** out the alpha. The test case for this was flux box; in a Xspice
|
||||||
|
** server, right click on the desktop to get the menu; the top bar
|
||||||
|
** doesn't paint/highlight correctly w/out this change.
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function stripAlpha(d)
|
||||||
|
{
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < (d.width * d.height * 4); i += 4)
|
||||||
|
d.data[i + 3] = 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** SpiceDisplayConn
|
||||||
|
** Drive the Spice Display Channel
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function SpiceDisplayConn()
|
||||||
|
{
|
||||||
|
SpiceConn.apply(this, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceDisplayConn.prototype = Object.create(SpiceConn.prototype);
|
||||||
|
SpiceDisplayConn.prototype.process_channel_message = function(msg)
|
||||||
|
{
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_MARK)
|
||||||
|
{
|
||||||
|
// FIXME - DISPLAY_MARK not implemented (may be hard or impossible)
|
||||||
|
this.known_unimplemented(msg.type, "Display Mark");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_RESET)
|
||||||
|
{
|
||||||
|
DEBUG > 2 && console.log("Display reset");
|
||||||
|
this.surfaces[this.primary_surface].canvas.context.restore();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_DRAW_COPY)
|
||||||
|
{
|
||||||
|
var draw_copy = new SpiceMsgDisplayDrawCopy(msg.data);
|
||||||
|
|
||||||
|
DEBUG > 1 && this.log_draw("DrawCopy", draw_copy);
|
||||||
|
|
||||||
|
if (! draw_copy.base.box.is_same_size(draw_copy.data.src_area))
|
||||||
|
this.log_warn("FIXME: DrawCopy src_area is a different size than base.box; we do not handle that yet.");
|
||||||
|
if (draw_copy.base.clip.type != SPICE_CLIP_TYPE_NONE)
|
||||||
|
this.log_warn("FIXME: DrawCopy we don't handle clipping yet");
|
||||||
|
if (draw_copy.data.rop_descriptor != SPICE_ROPD_OP_PUT)
|
||||||
|
this.log_warn("FIXME: DrawCopy we don't handle ropd type: " + draw_copy.data.rop_descriptor);
|
||||||
|
if (draw_copy.data.mask.flags)
|
||||||
|
this.log_warn("FIXME: DrawCopy we don't handle mask flag: " + draw_copy.data.mask.flags);
|
||||||
|
if (draw_copy.data.mask.bitmap)
|
||||||
|
this.log_warn("FIXME: DrawCopy we don't handle mask");
|
||||||
|
|
||||||
|
if (draw_copy.data && draw_copy.data.src_bitmap)
|
||||||
|
{
|
||||||
|
if (draw_copy.data.src_bitmap.descriptor.flags &&
|
||||||
|
draw_copy.data.src_bitmap.descriptor.flags != SPICE_IMAGE_FLAGS_CACHE_ME &&
|
||||||
|
draw_copy.data.src_bitmap.descriptor.flags != SPICE_IMAGE_FLAGS_HIGH_BITS_SET)
|
||||||
|
{
|
||||||
|
this.log_warn("FIXME: DrawCopy unhandled image flags: " + draw_copy.data.src_bitmap.descriptor.flags);
|
||||||
|
DEBUG <= 1 && this.log_draw("DrawCopy", draw_copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_QUIC)
|
||||||
|
{
|
||||||
|
var canvas = this.surfaces[draw_copy.base.surface_id].canvas;
|
||||||
|
if (! draw_copy.data.src_bitmap.quic)
|
||||||
|
{
|
||||||
|
this.log_warn("FIXME: DrawCopy could not handle this QUIC file.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var source_img = convert_spice_quic_to_web(canvas.context,
|
||||||
|
draw_copy.data.src_bitmap.quic);
|
||||||
|
|
||||||
|
return this.draw_copy_helper(
|
||||||
|
{ base: draw_copy.base,
|
||||||
|
src_area: draw_copy.data.src_area,
|
||||||
|
image_data: source_img,
|
||||||
|
tag: "copyquic." + draw_copy.data.src_bitmap.quic.type,
|
||||||
|
has_alpha: (draw_copy.data.src_bitmap.quic.type == QUIC_IMAGE_TYPE_RGBA ? true : false) ,
|
||||||
|
descriptor : draw_copy.data.src_bitmap.descriptor
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_FROM_CACHE ||
|
||||||
|
draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS)
|
||||||
|
{
|
||||||
|
if (! this.cache || ! this.cache[draw_copy.data.src_bitmap.descriptor.id])
|
||||||
|
{
|
||||||
|
this.log_warn("FIXME: DrawCopy did not find image id " + draw_copy.data.src_bitmap.descriptor.id + " in cache.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.draw_copy_helper(
|
||||||
|
{ base: draw_copy.base,
|
||||||
|
src_area: draw_copy.data.src_area,
|
||||||
|
image_data: this.cache[draw_copy.data.src_bitmap.descriptor.id],
|
||||||
|
tag: "copycache." + draw_copy.data.src_bitmap.descriptor.id,
|
||||||
|
has_alpha: true, /* FIXME - may want this to be false... */
|
||||||
|
descriptor : draw_copy.data.src_bitmap.descriptor
|
||||||
|
});
|
||||||
|
|
||||||
|
/* FIXME - LOSSLESS CACHE ramifications not understood or handled */
|
||||||
|
}
|
||||||
|
else if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_SURFACE)
|
||||||
|
{
|
||||||
|
var source_context = this.surfaces[draw_copy.data.src_bitmap.surface_id].canvas.context;
|
||||||
|
var target_context = this.surfaces[draw_copy.base.surface_id].canvas.context;
|
||||||
|
|
||||||
|
var source_img = source_context.getImageData(
|
||||||
|
draw_copy.data.src_area.left, draw_copy.data.src_area.top,
|
||||||
|
draw_copy.data.src_area.right - draw_copy.data.src_area.left,
|
||||||
|
draw_copy.data.src_area.bottom - draw_copy.data.src_area.top);
|
||||||
|
var computed_src_area = new SpiceRect;
|
||||||
|
computed_src_area.top = computed_src_area.left = 0;
|
||||||
|
computed_src_area.right = source_img.width;
|
||||||
|
computed_src_area.bottom = source_img.height;
|
||||||
|
|
||||||
|
/* FIXME - there is a potential optimization here.
|
||||||
|
That is, if the surface is from 0,0, and
|
||||||
|
both surfaces are alpha surfaces, you should
|
||||||
|
be able to just do a drawImage, which should
|
||||||
|
save time. */
|
||||||
|
|
||||||
|
return this.draw_copy_helper(
|
||||||
|
{ base: draw_copy.base,
|
||||||
|
src_area: computed_src_area,
|
||||||
|
image_data: source_img,
|
||||||
|
tag: "copysurf." + draw_copy.data.src_bitmap.surface_id,
|
||||||
|
has_alpha: this.surfaces[draw_copy.data.src_bitmap.surface_id].format == SPICE_SURFACE_FMT_32_xRGB ? false : true,
|
||||||
|
descriptor : draw_copy.data.src_bitmap.descriptor
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_JPEG)
|
||||||
|
{
|
||||||
|
if (! draw_copy.data.src_bitmap.jpeg)
|
||||||
|
{
|
||||||
|
this.log_warn("FIXME: DrawCopy could not handle this JPEG file.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME - how lame is this. Be have it in binary format, and we have
|
||||||
|
// to put it into string to get it back into jpeg. Blech.
|
||||||
|
var tmpstr = "data:image/jpeg,";
|
||||||
|
var img = new Image;
|
||||||
|
var i;
|
||||||
|
var qdv = new Uint8Array(draw_copy.data.src_bitmap.jpeg.data);
|
||||||
|
for (i = 0; i < qdv.length; i++)
|
||||||
|
{
|
||||||
|
tmpstr += '%';
|
||||||
|
if (qdv[i] < 16)
|
||||||
|
tmpstr += '0';
|
||||||
|
tmpstr += qdv[i].toString(16);
|
||||||
|
}
|
||||||
|
|
||||||
|
img.o =
|
||||||
|
{ base: draw_copy.base,
|
||||||
|
tag: "jpeg." + draw_copy.data.src_bitmap.surface_id,
|
||||||
|
descriptor : draw_copy.data.src_bitmap.descriptor,
|
||||||
|
sc : this,
|
||||||
|
};
|
||||||
|
img.onload = handle_draw_jpeg_onload;
|
||||||
|
img.src = tmpstr;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_JPEG_ALPHA)
|
||||||
|
{
|
||||||
|
if (! draw_copy.data.src_bitmap.jpeg_alpha)
|
||||||
|
{
|
||||||
|
this.log_warn("FIXME: DrawCopy could not handle this JPEG ALPHA file.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME - how lame is this. Be have it in binary format, and we have
|
||||||
|
// to put it into string to get it back into jpeg. Blech.
|
||||||
|
var tmpstr = "data:image/jpeg,";
|
||||||
|
var img = new Image;
|
||||||
|
var i;
|
||||||
|
var qdv = new Uint8Array(draw_copy.data.src_bitmap.jpeg_alpha.data);
|
||||||
|
for (i = 0; i < qdv.length; i++)
|
||||||
|
{
|
||||||
|
tmpstr += '%';
|
||||||
|
if (qdv[i] < 16)
|
||||||
|
tmpstr += '0';
|
||||||
|
tmpstr += qdv[i].toString(16);
|
||||||
|
}
|
||||||
|
|
||||||
|
img.o =
|
||||||
|
{ base: draw_copy.base,
|
||||||
|
tag: "jpeg." + draw_copy.data.src_bitmap.surface_id,
|
||||||
|
descriptor : draw_copy.data.src_bitmap.descriptor,
|
||||||
|
sc : this,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.surfaces[draw_copy.base.surface_id].format == SPICE_SURFACE_FMT_32_ARGB)
|
||||||
|
{
|
||||||
|
|
||||||
|
var canvas = this.surfaces[draw_copy.base.surface_id].canvas;
|
||||||
|
img.alpha_img = convert_spice_lz_to_web(canvas.context,
|
||||||
|
draw_copy.data.src_bitmap.jpeg_alpha.alpha);
|
||||||
|
}
|
||||||
|
img.onload = handle_draw_jpeg_onload;
|
||||||
|
img.src = tmpstr;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_BITMAP)
|
||||||
|
{
|
||||||
|
var canvas = this.surfaces[draw_copy.base.surface_id].canvas;
|
||||||
|
if (! draw_copy.data.src_bitmap.bitmap)
|
||||||
|
{
|
||||||
|
this.log_err("null bitmap");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var source_img = convert_spice_bitmap_to_web(canvas.context,
|
||||||
|
draw_copy.data.src_bitmap.bitmap);
|
||||||
|
if (! source_img)
|
||||||
|
{
|
||||||
|
this.log_warn("FIXME: Unable to interpret bitmap of format: " +
|
||||||
|
draw_copy.data.src_bitmap.bitmap.format);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.draw_copy_helper(
|
||||||
|
{ base: draw_copy.base,
|
||||||
|
src_area: draw_copy.data.src_area,
|
||||||
|
image_data: source_img,
|
||||||
|
tag: "bitmap." + draw_copy.data.src_bitmap.bitmap.format,
|
||||||
|
has_alpha: draw_copy.data.src_bitmap.bitmap == SPICE_BITMAP_FMT_32BIT ? false : true,
|
||||||
|
descriptor : draw_copy.data.src_bitmap.descriptor
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (draw_copy.data.src_bitmap.descriptor.type == SPICE_IMAGE_TYPE_LZ_RGB)
|
||||||
|
{
|
||||||
|
var canvas = this.surfaces[draw_copy.base.surface_id].canvas;
|
||||||
|
if (! draw_copy.data.src_bitmap.lz_rgb)
|
||||||
|
{
|
||||||
|
this.log_err("null lz_rgb ");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (draw_copy.data.src_bitmap.lz_rgb.top_down != 1)
|
||||||
|
this.log_warn("FIXME: Implement non top down support for lz_rgb");
|
||||||
|
|
||||||
|
var source_img = convert_spice_lz_to_web(canvas.context,
|
||||||
|
draw_copy.data.src_bitmap.lz_rgb);
|
||||||
|
if (! source_img)
|
||||||
|
{
|
||||||
|
this.log_warn("FIXME: Unable to interpret bitmap of type: " +
|
||||||
|
draw_copy.data.src_bitmap.lz_rgb.type);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.draw_copy_helper(
|
||||||
|
{ base: draw_copy.base,
|
||||||
|
src_area: draw_copy.data.src_area,
|
||||||
|
image_data: source_img,
|
||||||
|
tag: "lz_rgb." + draw_copy.data.src_bitmap.lz_rgb.type,
|
||||||
|
has_alpha: draw_copy.data.src_bitmap.lz_rgb.type == LZ_IMAGE_TYPE_RGBA ? true : false ,
|
||||||
|
descriptor : draw_copy.data.src_bitmap.descriptor
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.log_warn("FIXME: DrawCopy unhandled image type: " + draw_copy.data.src_bitmap.descriptor.type);
|
||||||
|
this.log_draw("DrawCopy", draw_copy);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.log_warn("FIXME: DrawCopy no src_bitmap.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_DRAW_FILL)
|
||||||
|
{
|
||||||
|
var draw_fill = new SpiceMsgDisplayDrawFill(msg.data);
|
||||||
|
|
||||||
|
DEBUG > 1 && this.log_draw("DrawFill", draw_fill);
|
||||||
|
|
||||||
|
if (draw_fill.data.rop_descriptor != SPICE_ROPD_OP_PUT)
|
||||||
|
this.log_warn("FIXME: DrawFill we don't handle ropd type: " + draw_fill.data.rop_descriptor);
|
||||||
|
if (draw_fill.data.mask.flags)
|
||||||
|
this.log_warn("FIXME: DrawFill we don't handle mask flag: " + draw_fill.data.mask.flags);
|
||||||
|
if (draw_fill.data.mask.bitmap)
|
||||||
|
this.log_warn("FIXME: DrawFill we don't handle mask");
|
||||||
|
|
||||||
|
if (draw_fill.data.brush.type == SPICE_BRUSH_TYPE_SOLID)
|
||||||
|
{
|
||||||
|
// FIXME - do brushes ever have alpha?
|
||||||
|
var color = draw_fill.data.brush.color & 0xffffff;
|
||||||
|
var color_str = "rgb(" + (color >> 16) + ", " + ((color >> 8) & 0xff) + ", " + (color & 0xff) + ")";
|
||||||
|
this.surfaces[draw_fill.base.surface_id].canvas.context.fillStyle = color_str;
|
||||||
|
|
||||||
|
this.surfaces[draw_fill.base.surface_id].canvas.context.fillRect(
|
||||||
|
draw_fill.base.box.left, draw_fill.base.box.top,
|
||||||
|
draw_fill.base.box.right - draw_fill.base.box.left,
|
||||||
|
draw_fill.base.box.bottom - draw_fill.base.box.top);
|
||||||
|
|
||||||
|
if (DUMP_DRAWS && this.parent.dump_id)
|
||||||
|
{
|
||||||
|
var debug_canvas = document.createElement("canvas");
|
||||||
|
debug_canvas.setAttribute('width', this.surfaces[draw_fill.base.surface_id].canvas.width);
|
||||||
|
debug_canvas.setAttribute('height', this.surfaces[draw_fill.base.surface_id].canvas.height);
|
||||||
|
debug_canvas.setAttribute('id', "fillbrush." + draw_fill.base.surface_id + "." + this.surfaces[draw_fill.base.surface_id].draw_count);
|
||||||
|
debug_canvas.getContext("2d").fillStyle = color_str;
|
||||||
|
debug_canvas.getContext("2d").fillRect(
|
||||||
|
draw_fill.base.box.left, draw_fill.base.box.top,
|
||||||
|
draw_fill.base.box.right - draw_fill.base.box.left,
|
||||||
|
draw_fill.base.box.bottom - draw_fill.base.box.top);
|
||||||
|
document.getElementById(this.parent.dump_id).appendChild(debug_canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.surfaces[draw_fill.base.surface_id].draw_count++;
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.log_warn("FIXME: DrawFill can't handle brush type: " + draw_fill.data.brush.type);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_COPY_BITS)
|
||||||
|
{
|
||||||
|
var copy_bits = new SpiceMsgDisplayCopyBits(msg.data);
|
||||||
|
|
||||||
|
DEBUG > 1 && this.log_draw("CopyBits", copy_bits);
|
||||||
|
|
||||||
|
var source_canvas = this.surfaces[copy_bits.base.surface_id].canvas;
|
||||||
|
var source_context = source_canvas.context;
|
||||||
|
|
||||||
|
var width = source_canvas.width - copy_bits.src_pos.x;
|
||||||
|
var height = source_canvas.height - copy_bits.src_pos.y;
|
||||||
|
if (width > (copy_bits.base.box.right - copy_bits.base.box.left))
|
||||||
|
width = copy_bits.base.box.right - copy_bits.base.box.left;
|
||||||
|
if (height > (copy_bits.base.box.bottom - copy_bits.base.box.top))
|
||||||
|
height = copy_bits.base.box.bottom - copy_bits.base.box.top;
|
||||||
|
|
||||||
|
var source_img = source_context.getImageData(
|
||||||
|
copy_bits.src_pos.x, copy_bits.src_pos.y, width, height);
|
||||||
|
//source_context.putImageData(source_img, copy_bits.base.box.left, copy_bits.base.box.top);
|
||||||
|
putImageDataWithAlpha(source_context, source_img, copy_bits.base.box.left, copy_bits.base.box.top);
|
||||||
|
|
||||||
|
if (DUMP_DRAWS && this.parent.dump_id)
|
||||||
|
{
|
||||||
|
var debug_canvas = document.createElement("canvas");
|
||||||
|
debug_canvas.setAttribute('width', width);
|
||||||
|
debug_canvas.setAttribute('height', height);
|
||||||
|
debug_canvas.setAttribute('id', "copybits" + copy_bits.base.surface_id + "." + this.surfaces[copy_bits.base.surface_id].draw_count);
|
||||||
|
debug_canvas.getContext("2d").putImageData(source_img, 0, 0);
|
||||||
|
document.getElementById(this.parent.dump_id).appendChild(debug_canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
this.surfaces[copy_bits.base.surface_id].draw_count++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES)
|
||||||
|
{
|
||||||
|
this.known_unimplemented(msg.type, "Inval All Palettes");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_SURFACE_CREATE)
|
||||||
|
{
|
||||||
|
if (! ("surfaces" in this))
|
||||||
|
this.surfaces = [];
|
||||||
|
|
||||||
|
var m = new SpiceMsgSurfaceCreate(msg.data);
|
||||||
|
DEBUG > 1 && console.log(this.type + ": MsgSurfaceCreate id " + m.surface.surface_id
|
||||||
|
+ "; " + m.surface.width + "x" + m.surface.height
|
||||||
|
+ "; format " + m.surface.format
|
||||||
|
+ "; flags " + m.surface.flags);
|
||||||
|
if (m.surface.format != SPICE_SURFACE_FMT_32_xRGB &&
|
||||||
|
m.surface.format != SPICE_SURFACE_FMT_32_ARGB)
|
||||||
|
{
|
||||||
|
this.log_warn("FIXME: cannot handle surface format " + m.surface.format + " yet.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var canvas = document.createElement("canvas");
|
||||||
|
canvas.setAttribute('width', m.surface.width);
|
||||||
|
canvas.setAttribute('height', m.surface.height);
|
||||||
|
canvas.setAttribute('id', "spice_surface_" + m.surface.surface_id);
|
||||||
|
canvas.setAttribute('tabindex', m.surface.surface_id);
|
||||||
|
canvas.context = canvas.getContext("2d");
|
||||||
|
|
||||||
|
if (DUMP_CANVASES && this.parent.dump_id)
|
||||||
|
document.getElementById(this.parent.dump_id).appendChild(canvas);
|
||||||
|
|
||||||
|
m.surface.canvas = canvas;
|
||||||
|
m.surface.draw_count = 0;
|
||||||
|
this.surfaces[m.surface.surface_id] = m.surface;
|
||||||
|
|
||||||
|
if (m.surface.flags & SPICE_SURFACE_FLAGS_PRIMARY)
|
||||||
|
{
|
||||||
|
this.primary_surface = m.surface.surface_id;
|
||||||
|
|
||||||
|
/* This .save() is done entirely to enable SPICE_MSG_DISPLAY_RESET */
|
||||||
|
canvas.context.save();
|
||||||
|
document.getElementById(this.parent.screen_id).appendChild(canvas);
|
||||||
|
|
||||||
|
/* We're going to leave width dynamic, but correctly set the height */
|
||||||
|
document.getElementById(this.parent.screen_id).style.height = m.surface.height + "px";
|
||||||
|
this.hook_events();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_SURFACE_DESTROY)
|
||||||
|
{
|
||||||
|
var m = new SpiceMsgSurfaceDestroy(msg.data);
|
||||||
|
DEBUG > 1 && console.log(this.type + ": MsgSurfaceDestroy id " + m.surface_id);
|
||||||
|
this.delete_surface(m.surface_id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_STREAM_CREATE)
|
||||||
|
{
|
||||||
|
var m = new SpiceMsgDisplayStreamCreate(msg.data);
|
||||||
|
DEBUG > 1 && console.log(this.type + ": MsgStreamCreate id" + m.id);
|
||||||
|
if (!this.streams)
|
||||||
|
this.streams = new Array();
|
||||||
|
if (this.streams[m.id])
|
||||||
|
console.log("Stream already exists");
|
||||||
|
else
|
||||||
|
this.streams[m.id] = m;
|
||||||
|
if (m.codec_type != SPICE_VIDEO_CODEC_TYPE_MJPEG)
|
||||||
|
console.log("Unhandled stream codec: "+m.codec_type);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_STREAM_DATA)
|
||||||
|
{
|
||||||
|
var m = new SpiceMsgDisplayStreamData(msg.data);
|
||||||
|
if (!this.streams[m.base.id])
|
||||||
|
{
|
||||||
|
console.log("no stream for data");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.streams[m.base.id].codec_type === SPICE_VIDEO_CODEC_TYPE_MJPEG)
|
||||||
|
{
|
||||||
|
var tmpstr = "data:image/jpeg,";
|
||||||
|
var img = new Image;
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < m.data.length; i++)
|
||||||
|
{
|
||||||
|
tmpstr += '%';
|
||||||
|
if (m.data[i] < 16)
|
||||||
|
tmpstr += '0';
|
||||||
|
tmpstr += m.data[i].toString(16);
|
||||||
|
}
|
||||||
|
var strm_base = new SpiceMsgDisplayBase();
|
||||||
|
strm_base.surface_id = this.streams[m.base.id].surface_id;
|
||||||
|
strm_base.box = this.streams[m.base.id].dest;
|
||||||
|
strm_base.clip = this.streams[m.base.id].clip;
|
||||||
|
img.o =
|
||||||
|
{ base: strm_base,
|
||||||
|
tag: "mjpeg." + m.base.id,
|
||||||
|
descriptor: null,
|
||||||
|
sc : this,
|
||||||
|
};
|
||||||
|
img.onload = handle_draw_jpeg_onload;
|
||||||
|
img.src = tmpstr;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_STREAM_CLIP)
|
||||||
|
{
|
||||||
|
var m = new SpiceMsgDisplayStreamClip(msg.data);
|
||||||
|
DEBUG > 1 && console.log(this.type + ": MsgStreamClip id" + m.id);
|
||||||
|
this.streams[m.id].clip = m.clip;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_STREAM_DESTROY)
|
||||||
|
{
|
||||||
|
var m = new SpiceMsgDisplayStreamDestroy(msg.data);
|
||||||
|
DEBUG > 1 && console.log(this.type + ": MsgStreamDestroy id" + m.id);
|
||||||
|
this.streams[m.id] = undefined;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (msg.type == SPICE_MSG_DISPLAY_INVAL_LIST)
|
||||||
|
{
|
||||||
|
var m = new SpiceMsgDisplayInvalList(msg.data);
|
||||||
|
var i;
|
||||||
|
DEBUG > 1 && console.log(this.type + ": MsgInvalList " + m.count + " items");
|
||||||
|
for (i = 0; i < m.count; i++)
|
||||||
|
if (this.cache[m.resources[i].id] != undefined)
|
||||||
|
delete this.cache[m.resources[i].id];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceDisplayConn.prototype.delete_surface = function(surface_id)
|
||||||
|
{
|
||||||
|
var canvas = document.getElementById("spice_surface_" + surface_id);
|
||||||
|
if (DUMP_CANVASES && this.parent.dump_id)
|
||||||
|
document.getElementById(this.parent.dump_id).removeChild(canvas);
|
||||||
|
if (this.primary_surface == surface_id)
|
||||||
|
{
|
||||||
|
this.unhook_events();
|
||||||
|
this.primary_surface = undefined;
|
||||||
|
document.getElementById(this.parent.screen_id).removeChild(canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete this.surfaces[surface_id];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SpiceDisplayConn.prototype.draw_copy_helper = function(o)
|
||||||
|
{
|
||||||
|
|
||||||
|
var canvas = this.surfaces[o.base.surface_id].canvas;
|
||||||
|
if (o.has_alpha)
|
||||||
|
{
|
||||||
|
/* FIXME - This is based on trial + error, not a serious thoughtful
|
||||||
|
analysis of what Spice requires. See display.js for more. */
|
||||||
|
if (this.surfaces[o.base.surface_id].format == SPICE_SURFACE_FMT_32_xRGB)
|
||||||
|
{
|
||||||
|
stripAlpha(o.image_data);
|
||||||
|
canvas.context.putImageData(o.image_data, o.base.box.left, o.base.box.top);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
putImageDataWithAlpha(canvas.context, o.image_data,
|
||||||
|
o.base.box.left, o.base.box.top);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
canvas.context.putImageData(o.image_data, o.base.box.left, o.base.box.top);
|
||||||
|
|
||||||
|
if (o.src_area.left > 0 || o.src_area.top > 0)
|
||||||
|
{
|
||||||
|
this.log_warn("FIXME: DrawCopy not shifting draw copies just yet...");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (o.descriptor && (o.descriptor.flags & SPICE_IMAGE_FLAGS_CACHE_ME))
|
||||||
|
{
|
||||||
|
if (! ("cache" in this))
|
||||||
|
this.cache = {};
|
||||||
|
this.cache[o.descriptor.id] = o.image_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DUMP_DRAWS && this.parent.dump_id)
|
||||||
|
{
|
||||||
|
var debug_canvas = document.createElement("canvas");
|
||||||
|
debug_canvas.setAttribute('width', o.image_data.width);
|
||||||
|
debug_canvas.setAttribute('height', o.image_data.height);
|
||||||
|
debug_canvas.setAttribute('id', o.tag + "." +
|
||||||
|
this.surfaces[o.base.surface_id].draw_count + "." +
|
||||||
|
o.base.surface_id + "@" + o.base.box.left + "x" + o.base.box.top);
|
||||||
|
debug_canvas.getContext("2d").putImageData(o.image_data, 0, 0);
|
||||||
|
document.getElementById(this.parent.dump_id).appendChild(debug_canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.surfaces[o.base.surface_id].draw_count++;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SpiceDisplayConn.prototype.log_draw = function(prefix, draw)
|
||||||
|
{
|
||||||
|
var str = prefix + "." + draw.base.surface_id + "." + this.surfaces[draw.base.surface_id].draw_count + ": ";
|
||||||
|
str += "base.box " + draw.base.box.left + ", " + draw.base.box.top + " to " +
|
||||||
|
draw.base.box.right + ", " + draw.base.box.bottom;
|
||||||
|
str += "; clip.type " + draw.base.clip.type;
|
||||||
|
|
||||||
|
if (draw.data)
|
||||||
|
{
|
||||||
|
if (draw.data.src_area)
|
||||||
|
str += "; src_area " + draw.data.src_area.left + ", " + draw.data.src_area.top + " to "
|
||||||
|
+ draw.data.src_area.right + ", " + draw.data.src_area.bottom;
|
||||||
|
|
||||||
|
if (draw.data.src_bitmap && draw.data.src_bitmap != null)
|
||||||
|
{
|
||||||
|
str += "; src_bitmap id: " + draw.data.src_bitmap.descriptor.id;
|
||||||
|
str += "; src_bitmap width " + draw.data.src_bitmap.descriptor.width + ", height " + draw.data.src_bitmap.descriptor.height;
|
||||||
|
str += "; src_bitmap type " + draw.data.src_bitmap.descriptor.type + ", flags " + draw.data.src_bitmap.descriptor.flags;
|
||||||
|
if (draw.data.src_bitmap.surface_id !== undefined)
|
||||||
|
str += "; src_bitmap surface_id " + draw.data.src_bitmap.surface_id;
|
||||||
|
if (draw.data.src_bitmap.quic)
|
||||||
|
str += "; QUIC type " + draw.data.src_bitmap.quic.type +
|
||||||
|
"; width " + draw.data.src_bitmap.quic.width +
|
||||||
|
"; height " + draw.data.src_bitmap.quic.height ;
|
||||||
|
if (draw.data.src_bitmap.lz_rgb)
|
||||||
|
str += "; LZ_RGB length " + draw.data.src_bitmap.lz_rgb.length +
|
||||||
|
"; magic " + draw.data.src_bitmap.lz_rgb.magic +
|
||||||
|
"; version 0x" + draw.data.src_bitmap.lz_rgb.version.toString(16) +
|
||||||
|
"; type " + draw.data.src_bitmap.lz_rgb.type +
|
||||||
|
"; width " + draw.data.src_bitmap.lz_rgb.width +
|
||||||
|
"; height " + draw.data.src_bitmap.lz_rgb.height +
|
||||||
|
"; stride " + draw.data.src_bitmap.lz_rgb.stride +
|
||||||
|
"; top down " + draw.data.src_bitmap.lz_rgb.top_down;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
str += "; src_bitmap is null";
|
||||||
|
|
||||||
|
if (draw.data.brush)
|
||||||
|
{
|
||||||
|
if (draw.data.brush.type == SPICE_BRUSH_TYPE_SOLID)
|
||||||
|
str += "; brush.color 0x" + draw.data.brush.color.toString(16);
|
||||||
|
if (draw.data.brush.type == SPICE_BRUSH_TYPE_PATTERN)
|
||||||
|
{
|
||||||
|
str += "; brush.pat ";
|
||||||
|
if (draw.data.brush.pattern.pat != null)
|
||||||
|
str += "[SpiceImage]";
|
||||||
|
else
|
||||||
|
str += "[null]";
|
||||||
|
str += " at " + draw.data.brush.pattern.pos.x + ", " + draw.data.brush.pattern.pos.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
str += "; rop_descriptor " + draw.data.rop_descriptor;
|
||||||
|
if (draw.data.scale_mode !== undefined)
|
||||||
|
str += "; scale_mode " + draw.data.scale_mode;
|
||||||
|
str += "; mask.flags " + draw.data.mask.flags;
|
||||||
|
str += "; mask.pos " + draw.data.mask.pos.x + ", " + draw.data.mask.pos.y;
|
||||||
|
if (draw.data.mask.bitmap != null)
|
||||||
|
{
|
||||||
|
str += "; mask.bitmap width " + draw.data.mask.bitmap.descriptor.width + ", height " + draw.data.mask.bitmap.descriptor.height;
|
||||||
|
str += "; mask.bitmap type " + draw.data.mask.bitmap.descriptor.type + ", flags " + draw.data.mask.bitmap.descriptor.flags;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
str += "; mask.bitmap is null";
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceDisplayConn.prototype.hook_events = function()
|
||||||
|
{
|
||||||
|
if (this.primary_surface !== undefined)
|
||||||
|
{
|
||||||
|
var canvas = this.surfaces[this.primary_surface].canvas;
|
||||||
|
canvas.sc = this.parent;
|
||||||
|
canvas.addEventListener('mousemove', handle_mousemove);
|
||||||
|
canvas.addEventListener('mousedown', handle_mousedown);
|
||||||
|
canvas.addEventListener('contextmenu', handle_contextmenu);
|
||||||
|
canvas.addEventListener('mouseup', handle_mouseup);
|
||||||
|
canvas.addEventListener('keydown', handle_keydown);
|
||||||
|
canvas.addEventListener('keyup', handle_keyup);
|
||||||
|
canvas.addEventListener('mouseout', handle_mouseout);
|
||||||
|
canvas.addEventListener('mouseover', handle_mouseover);
|
||||||
|
canvas.addEventListener('wheel', handle_mousewheel);
|
||||||
|
canvas.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceDisplayConn.prototype.unhook_events = function()
|
||||||
|
{
|
||||||
|
if (this.primary_surface !== undefined)
|
||||||
|
{
|
||||||
|
var canvas = this.surfaces[this.primary_surface].canvas;
|
||||||
|
canvas.removeEventListener('mousemove', handle_mousemove);
|
||||||
|
canvas.removeEventListener('mousedown', handle_mousedown);
|
||||||
|
canvas.removeEventListener('contextmenu', handle_contextmenu);
|
||||||
|
canvas.removeEventListener('mouseup', handle_mouseup);
|
||||||
|
canvas.removeEventListener('keydown', handle_keydown);
|
||||||
|
canvas.removeEventListener('keyup', handle_keyup);
|
||||||
|
canvas.removeEventListener('mouseout', handle_mouseout);
|
||||||
|
canvas.removeEventListener('mouseover', handle_mouseover);
|
||||||
|
canvas.removeEventListener('wheel', handle_mousewheel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SpiceDisplayConn.prototype.destroy_surfaces = function()
|
||||||
|
{
|
||||||
|
for (var s in this.surfaces)
|
||||||
|
{
|
||||||
|
this.delete_surface(this.surfaces[s].surface_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.surfaces = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function handle_mouseover(e)
|
||||||
|
{
|
||||||
|
this.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_mouseout(e)
|
||||||
|
{
|
||||||
|
if (this.sc && this.sc.cursor && this.sc.cursor.spice_simulated_cursor)
|
||||||
|
this.sc.cursor.spice_simulated_cursor.style.display = 'none';
|
||||||
|
this.blur();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_draw_jpeg_onload()
|
||||||
|
{
|
||||||
|
var temp_canvas = null;
|
||||||
|
var context;
|
||||||
|
|
||||||
|
/*------------------------------------------------------------
|
||||||
|
** FIXME:
|
||||||
|
** The helper should be extended to be able to handle actual HtmlImageElements
|
||||||
|
** ...and the cache should be modified to do so as well
|
||||||
|
**----------------------------------------------------------*/
|
||||||
|
if (this.o.sc.surfaces[this.o.base.surface_id] === undefined)
|
||||||
|
{
|
||||||
|
// This can happen; if the jpeg image loads after our surface
|
||||||
|
// has been destroyed (e.g. open a menu, close it quickly),
|
||||||
|
// we'll find we have no surface.
|
||||||
|
DEBUG > 2 && this.o.sc.log_info("Discarding jpeg; presumed lost surface " + this.o.base.surface_id);
|
||||||
|
temp_canvas = document.createElement("canvas");
|
||||||
|
temp_canvas.setAttribute('width', this.o.base.box.right);
|
||||||
|
temp_canvas.setAttribute('height', this.o.base.box.bottom);
|
||||||
|
context = temp_canvas.getContext("2d");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
context = this.o.sc.surfaces[this.o.base.surface_id].canvas.context;
|
||||||
|
|
||||||
|
if (this.alpha_img)
|
||||||
|
{
|
||||||
|
var c = document.createElement("canvas");
|
||||||
|
var t = c.getContext("2d");
|
||||||
|
c.setAttribute('width', this.alpha_img.width);
|
||||||
|
c.setAttribute('height', this.alpha_img.height);
|
||||||
|
t.putImageData(this.alpha_img, 0, 0);
|
||||||
|
t.globalCompositeOperation = 'source-in';
|
||||||
|
t.drawImage(this, 0, 0);
|
||||||
|
|
||||||
|
context.drawImage(c, this.o.base.box.left, this.o.base.box.top);
|
||||||
|
|
||||||
|
if (this.o.descriptor &&
|
||||||
|
(this.o.descriptor.flags & SPICE_IMAGE_FLAGS_CACHE_ME))
|
||||||
|
{
|
||||||
|
if (! ("cache" in this.o.sc))
|
||||||
|
this.o.sc.cache = {};
|
||||||
|
|
||||||
|
this.o.sc.cache[this.o.descriptor.id] =
|
||||||
|
t.getImageData(0, 0,
|
||||||
|
this.alpha_img.width,
|
||||||
|
this.alpha_img.height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.drawImage(this, this.o.base.box.left, this.o.base.box.top);
|
||||||
|
|
||||||
|
// Give the Garbage collector a clue to recycle this; avoids
|
||||||
|
// fairly massive memory leaks during video playback
|
||||||
|
this.src = null;
|
||||||
|
|
||||||
|
if (this.o.descriptor &&
|
||||||
|
(this.o.descriptor.flags & SPICE_IMAGE_FLAGS_CACHE_ME))
|
||||||
|
{
|
||||||
|
if (! ("cache" in this.o.sc))
|
||||||
|
this.o.sc.cache = {};
|
||||||
|
|
||||||
|
this.o.sc.cache[this.o.descriptor.id] =
|
||||||
|
context.getImageData(this.o.base.box.left, this.o.base.box.top,
|
||||||
|
this.o.base.box.right - this.o.base.box.left,
|
||||||
|
this.o.base.box.bottom - this.o.base.box.top);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (temp_canvas == null)
|
||||||
|
{
|
||||||
|
if (DUMP_DRAWS && this.o.sc.parent.dump_id)
|
||||||
|
{
|
||||||
|
var debug_canvas = document.createElement("canvas");
|
||||||
|
debug_canvas.setAttribute('id', this.o.tag + "." +
|
||||||
|
this.o.sc.surfaces[this.o.base.surface_id].draw_count + "." +
|
||||||
|
this.o.base.surface_id + "@" + this.o.base.box.left + "x" + this.o.base.box.top);
|
||||||
|
debug_canvas.getContext("2d").drawImage(this, 0, 0);
|
||||||
|
document.getElementById(this.o.sc.parent.dump_id).appendChild(debug_canvas);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.o.sc.surfaces[this.o.base.surface_id].draw_count++;
|
||||||
|
}
|
||||||
|
}
|
348
static/js/spice-html5/enums.js
Normal file
348
static/js/spice-html5/enums.js
Normal file
|
@ -0,0 +1,348 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** enums.js
|
||||||
|
** 'constants' for Spice
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
var SPICE_MAGIC = "REDQ";
|
||||||
|
var SPICE_VERSION_MAJOR = 2;
|
||||||
|
var SPICE_VERSION_MINOR = 2;
|
||||||
|
|
||||||
|
var SPICE_CONNECT_TIMEOUT = (30 * 1000);
|
||||||
|
|
||||||
|
var SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION = 0;
|
||||||
|
var SPICE_COMMON_CAP_AUTH_SPICE = 1;
|
||||||
|
var SPICE_COMMON_CAP_AUTH_SASL = 2;
|
||||||
|
var SPICE_COMMON_CAP_MINI_HEADER = 3;
|
||||||
|
|
||||||
|
var SPICE_TICKET_KEY_PAIR_LENGTH = 1024;
|
||||||
|
var SPICE_TICKET_PUBKEY_BYTES = (SPICE_TICKET_KEY_PAIR_LENGTH / 8 + 34);
|
||||||
|
|
||||||
|
var SPICE_LINK_ERR_OK = 0,
|
||||||
|
SPICE_LINK_ERR_ERROR = 1,
|
||||||
|
SPICE_LINK_ERR_INVALID_MAGIC = 2,
|
||||||
|
SPICE_LINK_ERR_INVALID_DATA = 3,
|
||||||
|
SPICE_LINK_ERR_VERSION_MISMATCH = 4,
|
||||||
|
SPICE_LINK_ERR_NEED_SECURED = 5,
|
||||||
|
SPICE_LINK_ERR_NEED_UNSECURED = 6,
|
||||||
|
SPICE_LINK_ERR_PERMISSION_DENIED = 7,
|
||||||
|
SPICE_LINK_ERR_BAD_CONNECTION_ID = 8,
|
||||||
|
SPICE_LINK_ERR_CHANNEL_NOT_AVAILABLE = 9;
|
||||||
|
|
||||||
|
var SPICE_MSG_MIGRATE = 1;
|
||||||
|
var SPICE_MSG_MIGRATE_DATA = 2;
|
||||||
|
var SPICE_MSG_SET_ACK = 3;
|
||||||
|
var SPICE_MSG_PING = 4;
|
||||||
|
var SPICE_MSG_WAIT_FOR_CHANNELS = 5;
|
||||||
|
var SPICE_MSG_DISCONNECTING = 6;
|
||||||
|
var SPICE_MSG_NOTIFY = 7;
|
||||||
|
var SPICE_MSG_LIST = 8;
|
||||||
|
|
||||||
|
var SPICE_MSG_MAIN_MIGRATE_BEGIN = 101;
|
||||||
|
var SPICE_MSG_MAIN_MIGRATE_CANCEL = 102;
|
||||||
|
var SPICE_MSG_MAIN_INIT = 103;
|
||||||
|
var SPICE_MSG_MAIN_CHANNELS_LIST = 104;
|
||||||
|
var SPICE_MSG_MAIN_MOUSE_MODE = 105;
|
||||||
|
var SPICE_MSG_MAIN_MULTI_MEDIA_TIME = 106;
|
||||||
|
var SPICE_MSG_MAIN_AGENT_CONNECTED = 107;
|
||||||
|
var SPICE_MSG_MAIN_AGENT_DISCONNECTED = 108;
|
||||||
|
var SPICE_MSG_MAIN_AGENT_DATA = 109;
|
||||||
|
var SPICE_MSG_MAIN_AGENT_TOKEN = 110;
|
||||||
|
var SPICE_MSG_MAIN_MIGRATE_SWITCH_HOST = 111;
|
||||||
|
var SPICE_MSG_MAIN_MIGRATE_END = 112;
|
||||||
|
var SPICE_MSG_MAIN_NAME = 113;
|
||||||
|
var SPICE_MSG_MAIN_UUID = 114;
|
||||||
|
var SPICE_MSG_MAIN_AGENT_CONNECTED_TOKENS = 115;
|
||||||
|
var SPICE_MSG_MAIN_MIGRATE_BEGIN_SEAMLESS = 116;
|
||||||
|
var SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_ACK = 117;
|
||||||
|
var SPICE_MSG_MAIN_MIGRATE_DST_SEAMLESS_NACK = 118;
|
||||||
|
var SPICE_MSG_END_MAIN = 119;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var SPICE_MSGC_ACK_SYNC = 1;
|
||||||
|
var SPICE_MSGC_ACK = 2;
|
||||||
|
var SPICE_MSGC_PONG = 3;
|
||||||
|
var SPICE_MSGC_MIGRATE_FLUSH_MARK = 4;
|
||||||
|
var SPICE_MSGC_MIGRATE_DATA = 5;
|
||||||
|
var SPICE_MSGC_DISCONNECTING = 6;
|
||||||
|
|
||||||
|
|
||||||
|
var SPICE_MSGC_MAIN_CLIENT_INFO = 101;
|
||||||
|
var SPICE_MSGC_MAIN_MIGRATE_CONNECTED = 102;
|
||||||
|
var SPICE_MSGC_MAIN_MIGRATE_CONNECT_ERROR = 103;
|
||||||
|
var SPICE_MSGC_MAIN_ATTACH_CHANNELS = 104;
|
||||||
|
var SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST = 105;
|
||||||
|
var SPICE_MSGC_MAIN_AGENT_START = 106;
|
||||||
|
var SPICE_MSGC_MAIN_AGENT_DATA = 107;
|
||||||
|
var SPICE_MSGC_MAIN_AGENT_TOKEN = 108;
|
||||||
|
var SPICE_MSGC_MAIN_MIGRATE_END = 109;
|
||||||
|
var SPICE_MSGC_END_MAIN = 110;
|
||||||
|
|
||||||
|
var SPICE_MSG_DISPLAY_MODE = 101;
|
||||||
|
var SPICE_MSG_DISPLAY_MARK = 102;
|
||||||
|
var SPICE_MSG_DISPLAY_RESET = 103;
|
||||||
|
var SPICE_MSG_DISPLAY_COPY_BITS = 104;
|
||||||
|
var SPICE_MSG_DISPLAY_INVAL_LIST = 105;
|
||||||
|
var SPICE_MSG_DISPLAY_INVAL_ALL_PIXMAPS = 106;
|
||||||
|
var SPICE_MSG_DISPLAY_INVAL_PALETTE = 107;
|
||||||
|
var SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES= 108;
|
||||||
|
|
||||||
|
var SPICE_MSG_DISPLAY_STREAM_CREATE = 122;
|
||||||
|
var SPICE_MSG_DISPLAY_STREAM_DATA = 123;
|
||||||
|
var SPICE_MSG_DISPLAY_STREAM_CLIP = 124;
|
||||||
|
var SPICE_MSG_DISPLAY_STREAM_DESTROY = 125;
|
||||||
|
var SPICE_MSG_DISPLAY_STREAM_DESTROY_ALL= 126;
|
||||||
|
|
||||||
|
var SPICE_MSG_DISPLAY_DRAW_FILL = 302;
|
||||||
|
var SPICE_MSG_DISPLAY_DRAW_OPAQUE = 303;
|
||||||
|
var SPICE_MSG_DISPLAY_DRAW_COPY = 304;
|
||||||
|
var SPICE_MSG_DISPLAY_DRAW_BLEND = 305;
|
||||||
|
var SPICE_MSG_DISPLAY_DRAW_BLACKNESS = 306;
|
||||||
|
var SPICE_MSG_DISPLAY_DRAW_WHITENESS = 307;
|
||||||
|
var SPICE_MSG_DISPLAY_DRAW_INVERS = 308;
|
||||||
|
var SPICE_MSG_DISPLAY_DRAW_ROP3 = 309;
|
||||||
|
var SPICE_MSG_DISPLAY_DRAW_STROKE = 310;
|
||||||
|
var SPICE_MSG_DISPLAY_DRAW_TEXT = 311;
|
||||||
|
var SPICE_MSG_DISPLAY_DRAW_TRANSPARENT = 312;
|
||||||
|
var SPICE_MSG_DISPLAY_DRAW_ALPHA_BLEND = 313;
|
||||||
|
var SPICE_MSG_DISPLAY_SURFACE_CREATE = 314;
|
||||||
|
var SPICE_MSG_DISPLAY_SURFACE_DESTROY = 315;
|
||||||
|
|
||||||
|
var SPICE_MSGC_DISPLAY_INIT = 101;
|
||||||
|
|
||||||
|
var SPICE_MSG_INPUTS_INIT = 101;
|
||||||
|
var SPICE_MSG_INPUTS_KEY_MODIFIERS = 102;
|
||||||
|
|
||||||
|
var SPICE_MSG_INPUTS_MOUSE_MOTION_ACK = 111;
|
||||||
|
|
||||||
|
var SPICE_MSGC_INPUTS_KEY_DOWN = 101;
|
||||||
|
var SPICE_MSGC_INPUTS_KEY_UP = 102;
|
||||||
|
var SPICE_MSGC_INPUTS_KEY_MODIFIERS = 103;
|
||||||
|
|
||||||
|
var SPICE_MSGC_INPUTS_MOUSE_MOTION = 111;
|
||||||
|
var SPICE_MSGC_INPUTS_MOUSE_POSITION = 112;
|
||||||
|
var SPICE_MSGC_INPUTS_MOUSE_PRESS = 113;
|
||||||
|
var SPICE_MSGC_INPUTS_MOUSE_RELEASE = 114;
|
||||||
|
|
||||||
|
var SPICE_MSG_CURSOR_INIT = 101;
|
||||||
|
var SPICE_MSG_CURSOR_RESET = 102;
|
||||||
|
var SPICE_MSG_CURSOR_SET = 103;
|
||||||
|
var SPICE_MSG_CURSOR_MOVE = 104;
|
||||||
|
var SPICE_MSG_CURSOR_HIDE = 105;
|
||||||
|
var SPICE_MSG_CURSOR_TRAIL = 106;
|
||||||
|
var SPICE_MSG_CURSOR_INVAL_ONE = 107;
|
||||||
|
var SPICE_MSG_CURSOR_INVAL_ALL = 108;
|
||||||
|
|
||||||
|
var SPICE_MSG_PLAYBACK_DATA = 101;
|
||||||
|
var SPICE_MSG_PLAYBACK_MODE = 102;
|
||||||
|
var SPICE_MSG_PLAYBACK_START = 103;
|
||||||
|
var SPICE_MSG_PLAYBACK_STOP = 104;
|
||||||
|
var SPICE_MSG_PLAYBACK_VOLUME = 105;
|
||||||
|
var SPICE_MSG_PLAYBACK_MUTE = 106;
|
||||||
|
var SPICE_MSG_PLAYBACK_LATENCY = 107;
|
||||||
|
|
||||||
|
var SPICE_PLAYBACK_CAP_CELT_0_5_1 = 0;
|
||||||
|
var SPICE_PLAYBACK_CAP_VOLUME = 1;
|
||||||
|
var SPICE_PLAYBACK_CAP_LATENCY = 2;
|
||||||
|
var SPICE_PLAYBACK_CAP_OPUS = 3;
|
||||||
|
|
||||||
|
var SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE = 0;
|
||||||
|
var SPICE_MAIN_CAP_NAME_AND_UUID = 1;
|
||||||
|
var SPICE_MAIN_CAP_AGENT_CONNECTED_TOKENS = 2;
|
||||||
|
var SPICE_MAIN_CAP_SEAMLESS_MIGRATE = 3;
|
||||||
|
|
||||||
|
var SPICE_AUDIO_DATA_MODE_INVALID = 0;
|
||||||
|
var SPICE_AUDIO_DATA_MODE_RAW = 1;
|
||||||
|
var SPICE_AUDIO_DATA_MODE_CELT_0_5_1 = 2;
|
||||||
|
var SPICE_AUDIO_DATA_MODE_OPUS = 3;
|
||||||
|
|
||||||
|
var SPICE_AUDIO_FMT_INVALID = 0;
|
||||||
|
var SPICE_AUDIO_FMT_S16 = 1;
|
||||||
|
|
||||||
|
var SPICE_CHANNEL_MAIN = 1;
|
||||||
|
var SPICE_CHANNEL_DISPLAY = 2;
|
||||||
|
var SPICE_CHANNEL_INPUTS = 3;
|
||||||
|
var SPICE_CHANNEL_CURSOR = 4;
|
||||||
|
var SPICE_CHANNEL_PLAYBACK = 5;
|
||||||
|
var SPICE_CHANNEL_RECORD = 6;
|
||||||
|
var SPICE_CHANNEL_TUNNEL = 7;
|
||||||
|
var SPICE_CHANNEL_SMARTCARD = 8;
|
||||||
|
var SPICE_CHANNEL_USBREDIR = 9;
|
||||||
|
|
||||||
|
var SPICE_SURFACE_FLAGS_PRIMARY = (1 << 0);
|
||||||
|
|
||||||
|
var SPICE_NOTIFY_SEVERITY_INFO = 0;
|
||||||
|
var SPICE_NOTIFY_SEVERITY_WARN = 1;
|
||||||
|
var SPICE_NOTIFY_SEVERITY_ERROR = 2;
|
||||||
|
|
||||||
|
var SPICE_MOUSE_MODE_SERVER = (1 << 0),
|
||||||
|
SPICE_MOUSE_MODE_CLIENT = (1 << 1),
|
||||||
|
SPICE_MOUSE_MODE_MASK = 0x3;
|
||||||
|
|
||||||
|
var SPICE_CLIP_TYPE_NONE = 0;
|
||||||
|
var SPICE_CLIP_TYPE_RECTS = 1;
|
||||||
|
|
||||||
|
var SPICE_IMAGE_TYPE_BITMAP = 0;
|
||||||
|
var SPICE_IMAGE_TYPE_QUIC = 1;
|
||||||
|
var SPICE_IMAGE_TYPE_RESERVED = 2;
|
||||||
|
var SPICE_IMAGE_TYPE_LZ_PLT = 100;
|
||||||
|
var SPICE_IMAGE_TYPE_LZ_RGB = 101;
|
||||||
|
var SPICE_IMAGE_TYPE_GLZ_RGB = 102;
|
||||||
|
var SPICE_IMAGE_TYPE_FROM_CACHE = 103;
|
||||||
|
var SPICE_IMAGE_TYPE_SURFACE = 104;
|
||||||
|
var SPICE_IMAGE_TYPE_JPEG = 105;
|
||||||
|
var SPICE_IMAGE_TYPE_FROM_CACHE_LOSSLESS = 106;
|
||||||
|
var SPICE_IMAGE_TYPE_ZLIB_GLZ_RGB = 107;
|
||||||
|
var SPICE_IMAGE_TYPE_JPEG_ALPHA = 108;
|
||||||
|
|
||||||
|
var SPICE_IMAGE_FLAGS_CACHE_ME = (1 << 0),
|
||||||
|
SPICE_IMAGE_FLAGS_HIGH_BITS_SET = (1 << 1),
|
||||||
|
SPICE_IMAGE_FLAGS_CACHE_REPLACE_ME = (1 << 2);
|
||||||
|
|
||||||
|
var SPICE_BITMAP_FLAGS_PAL_CACHE_ME = (1 << 0),
|
||||||
|
SPICE_BITMAP_FLAGS_PAL_FROM_CACHE = (1 << 1),
|
||||||
|
SPICE_BITMAP_FLAGS_TOP_DOWN = (1 << 2),
|
||||||
|
SPICE_BITMAP_FLAGS_MASK = 0x7;
|
||||||
|
|
||||||
|
var SPICE_BITMAP_FMT_INVALID = 0,
|
||||||
|
SPICE_BITMAP_FMT_1BIT_LE = 1,
|
||||||
|
SPICE_BITMAP_FMT_1BIT_BE = 2,
|
||||||
|
SPICE_BITMAP_FMT_4BIT_LE = 3,
|
||||||
|
SPICE_BITMAP_FMT_4BIT_BE = 4,
|
||||||
|
SPICE_BITMAP_FMT_8BIT = 5,
|
||||||
|
SPICE_BITMAP_FMT_16BIT = 6,
|
||||||
|
SPICE_BITMAP_FMT_24BIT = 7,
|
||||||
|
SPICE_BITMAP_FMT_32BIT = 8,
|
||||||
|
SPICE_BITMAP_FMT_RGBA = 9;
|
||||||
|
|
||||||
|
|
||||||
|
var SPICE_CURSOR_FLAGS_NONE = (1 << 0),
|
||||||
|
SPICE_CURSOR_FLAGS_CACHE_ME = (1 << 1),
|
||||||
|
SPICE_CURSOR_FLAGS_FROM_CACHE = (1 << 2),
|
||||||
|
SPICE_CURSOR_FLAGS_MASK = 0x7;
|
||||||
|
|
||||||
|
var SPICE_MOUSE_BUTTON_MASK_LEFT = (1 << 0),
|
||||||
|
SPICE_MOUSE_BUTTON_MASK_MIDDLE = (1 << 1),
|
||||||
|
SPICE_MOUSE_BUTTON_MASK_RIGHT = (1 << 2),
|
||||||
|
SPICE_MOUSE_BUTTON_MASK_MASK = 0x7;
|
||||||
|
|
||||||
|
var SPICE_MOUSE_BUTTON_INVALID = 0;
|
||||||
|
var SPICE_MOUSE_BUTTON_LEFT = 1;
|
||||||
|
var SPICE_MOUSE_BUTTON_MIDDLE = 2;
|
||||||
|
var SPICE_MOUSE_BUTTON_RIGHT = 3;
|
||||||
|
var SPICE_MOUSE_BUTTON_UP = 4;
|
||||||
|
var SPICE_MOUSE_BUTTON_DOWN = 5;
|
||||||
|
|
||||||
|
var SPICE_BRUSH_TYPE_NONE = 0,
|
||||||
|
SPICE_BRUSH_TYPE_SOLID = 1,
|
||||||
|
SPICE_BRUSH_TYPE_PATTERN = 2;
|
||||||
|
|
||||||
|
var SPICE_SURFACE_FMT_INVALID = 0,
|
||||||
|
SPICE_SURFACE_FMT_1_A = 1,
|
||||||
|
SPICE_SURFACE_FMT_8_A = 8,
|
||||||
|
SPICE_SURFACE_FMT_16_555 = 16,
|
||||||
|
SPICE_SURFACE_FMT_32_xRGB = 32,
|
||||||
|
SPICE_SURFACE_FMT_16_565 = 80,
|
||||||
|
SPICE_SURFACE_FMT_32_ARGB = 96;
|
||||||
|
|
||||||
|
var SPICE_ROPD_INVERS_SRC = (1 << 0),
|
||||||
|
SPICE_ROPD_INVERS_BRUSH = (1 << 1),
|
||||||
|
SPICE_ROPD_INVERS_DEST = (1 << 2),
|
||||||
|
SPICE_ROPD_OP_PUT = (1 << 3),
|
||||||
|
SPICE_ROPD_OP_OR = (1 << 4),
|
||||||
|
SPICE_ROPD_OP_AND = (1 << 5),
|
||||||
|
SPICE_ROPD_OP_XOR = (1 << 6),
|
||||||
|
SPICE_ROPD_OP_BLACKNESS = (1 << 7),
|
||||||
|
SPICE_ROPD_OP_WHITENESS = (1 << 8),
|
||||||
|
SPICE_ROPD_OP_INVERS = (1 << 9),
|
||||||
|
SPICE_ROPD_INVERS_RES = (1 << 10),
|
||||||
|
SPICE_ROPD_MASK = 0x7ff;
|
||||||
|
|
||||||
|
var LZ_IMAGE_TYPE_INVALID = 0,
|
||||||
|
LZ_IMAGE_TYPE_PLT1_LE = 1,
|
||||||
|
LZ_IMAGE_TYPE_PLT1_BE = 2, // PLT stands for palette
|
||||||
|
LZ_IMAGE_TYPE_PLT4_LE = 3,
|
||||||
|
LZ_IMAGE_TYPE_PLT4_BE = 4,
|
||||||
|
LZ_IMAGE_TYPE_PLT8 = 5,
|
||||||
|
LZ_IMAGE_TYPE_RGB16 = 6,
|
||||||
|
LZ_IMAGE_TYPE_RGB24 = 7,
|
||||||
|
LZ_IMAGE_TYPE_RGB32 = 8,
|
||||||
|
LZ_IMAGE_TYPE_RGBA = 9,
|
||||||
|
LZ_IMAGE_TYPE_XXXA = 10;
|
||||||
|
|
||||||
|
|
||||||
|
var QUIC_IMAGE_TYPE_INVALID = 0,
|
||||||
|
QUIC_IMAGE_TYPE_GRAY = 1,
|
||||||
|
QUIC_IMAGE_TYPE_RGB16 = 2,
|
||||||
|
QUIC_IMAGE_TYPE_RGB24 = 3,
|
||||||
|
QUIC_IMAGE_TYPE_RGB32 = 4,
|
||||||
|
QUIC_IMAGE_TYPE_RGBA = 5;
|
||||||
|
|
||||||
|
var SPICE_INPUT_MOTION_ACK_BUNCH = 4;
|
||||||
|
|
||||||
|
|
||||||
|
var SPICE_CURSOR_TYPE_ALPHA = 0,
|
||||||
|
SPICE_CURSOR_TYPE_MONO = 1,
|
||||||
|
SPICE_CURSOR_TYPE_COLOR4 = 2,
|
||||||
|
SPICE_CURSOR_TYPE_COLOR8 = 3,
|
||||||
|
SPICE_CURSOR_TYPE_COLOR16 = 4,
|
||||||
|
SPICE_CURSOR_TYPE_COLOR24 = 5,
|
||||||
|
SPICE_CURSOR_TYPE_COLOR32 = 6;
|
||||||
|
|
||||||
|
var SPICE_VIDEO_CODEC_TYPE_MJPEG = 1;
|
||||||
|
|
||||||
|
var VD_AGENT_PROTOCOL = 1;
|
||||||
|
var VD_AGENT_MAX_DATA_SIZE = 2048;
|
||||||
|
|
||||||
|
var VD_AGENT_MOUSE_STATE = 1,
|
||||||
|
VD_AGENT_MONITORS_CONFIG = 2,
|
||||||
|
VD_AGENT_REPLY = 3,
|
||||||
|
VD_AGENT_CLIPBOARD = 4,
|
||||||
|
VD_AGENT_DISPLAY_CONFIG = 5,
|
||||||
|
VD_AGENT_ANNOUNCE_CAPABILITIES = 6,
|
||||||
|
VD_AGENT_CLIPBOARD_GRAB = 7,
|
||||||
|
VD_AGENT_CLIPBOARD_REQUEST = 8,
|
||||||
|
VD_AGENT_CLIPBOARD_RELEASE = 9,
|
||||||
|
VD_AGENT_FILE_XFER_START =10,
|
||||||
|
VD_AGENT_FILE_XFER_STATUS =11,
|
||||||
|
VD_AGENT_FILE_XFER_DATA =12,
|
||||||
|
VD_AGENT_CLIENT_DISCONNECTED =13,
|
||||||
|
VD_AGENT_MAX_CLIPBOARD =14;
|
||||||
|
|
||||||
|
var VD_AGENT_CAP_MOUSE_STATE = 0,
|
||||||
|
VD_AGENT_CAP_MONITORS_CONFIG = 1,
|
||||||
|
VD_AGENT_CAP_REPLY = 2,
|
||||||
|
VD_AGENT_CAP_CLIPBOARD = 3,
|
||||||
|
VD_AGENT_CAP_DISPLAY_CONFIG = 4,
|
||||||
|
VD_AGENT_CAP_CLIPBOARD_BY_DEMAND = 5,
|
||||||
|
VD_AGENT_CAP_CLIPBOARD_SELECTION = 6,
|
||||||
|
VD_AGENT_CAP_SPARSE_MONITORS_CONFIG = 7,
|
||||||
|
VD_AGENT_CAP_GUEST_LINEEND_LF = 8,
|
||||||
|
VD_AGENT_CAP_GUEST_LINEEND_CRLF = 9,
|
||||||
|
VD_AGENT_CAP_MAX_CLIPBOARD = 10,
|
||||||
|
VD_AGENT_END_CAP = 11;
|
||||||
|
|
||||||
|
var VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA = 0,
|
||||||
|
VD_AGENT_FILE_XFER_STATUS_CANCELLED = 1,
|
||||||
|
VD_AGENT_FILE_XFER_STATUS_ERROR = 2,
|
||||||
|
VD_AGENT_FILE_XFER_STATUS_SUCCESS = 3;
|
88
static/js/spice-html5/filexfer.js
Normal file
88
static/js/spice-html5/filexfer.js
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2014 Red Hat, Inc.
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function SpiceFileXferTask(id, file)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceFileXferTask.prototype.create_progressbar = function()
|
||||||
|
{
|
||||||
|
var _this = this;
|
||||||
|
var cancel = document.createElement("input");
|
||||||
|
this.progressbar_container = document.createElement("div");
|
||||||
|
this.progressbar = document.createElement("progress");
|
||||||
|
|
||||||
|
cancel.type = 'button';
|
||||||
|
cancel.value = 'Cancel';
|
||||||
|
cancel.style.float = 'right';
|
||||||
|
cancel.onclick = function()
|
||||||
|
{
|
||||||
|
_this.cancelled = true;
|
||||||
|
_this.remove_progressbar();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.progressbar.setAttribute('max', this.file.size);
|
||||||
|
this.progressbar.setAttribute('value', 0);
|
||||||
|
this.progressbar.style.width = '100%';
|
||||||
|
this.progressbar.style.margin = '4px auto';
|
||||||
|
this.progressbar.style.display = 'inline-block';
|
||||||
|
this.progressbar_container.style.width = '90%';
|
||||||
|
this.progressbar_container.style.margin = 'auto';
|
||||||
|
this.progressbar_container.style.padding = '4px';
|
||||||
|
this.progressbar_container.textContent = this.file.name;
|
||||||
|
this.progressbar_container.appendChild(cancel);
|
||||||
|
this.progressbar_container.appendChild(this.progressbar);
|
||||||
|
document.getElementById('spice-xfer-area').appendChild(this.progressbar_container);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceFileXferTask.prototype.update_progressbar = function(value)
|
||||||
|
{
|
||||||
|
this.progressbar.setAttribute('value', value);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceFileXferTask.prototype.remove_progressbar = function()
|
||||||
|
{
|
||||||
|
if (this.progressbar_container && this.progressbar_container.parentNode)
|
||||||
|
this.progressbar_container.parentNode.removeChild(this.progressbar_container);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_file_dragover(e)
|
||||||
|
{
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
e.dataTransfer.dropEffect = 'copy';
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_file_drop(e)
|
||||||
|
{
|
||||||
|
var sc = window.spice_connection;
|
||||||
|
var files = e.dataTransfer.files;
|
||||||
|
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
for (var i = files.length - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
if (files[i].type); // do not copy a directory
|
||||||
|
sc.file_xfer_start(files[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
280
static/js/spice-html5/inputs.js
Normal file
280
static/js/spice-html5/inputs.js
Normal file
|
@ -0,0 +1,280 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** Modifier Keystates
|
||||||
|
** These need to be tracked because focus in and out can get the keyboard
|
||||||
|
** out of sync.
|
||||||
|
**------------------------------------------------------------------------*/
|
||||||
|
var Shift_state = -1;
|
||||||
|
var Ctrl_state = -1;
|
||||||
|
var Alt_state = -1;
|
||||||
|
var Meta_state = -1;
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** SpiceInputsConn
|
||||||
|
** Drive the Spice Inputs channel (e.g. mouse + keyboard)
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function SpiceInputsConn()
|
||||||
|
{
|
||||||
|
SpiceConn.apply(this, arguments);
|
||||||
|
|
||||||
|
this.mousex = undefined;
|
||||||
|
this.mousey = undefined;
|
||||||
|
this.button_state = 0;
|
||||||
|
this.waiting_for_ack = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceInputsConn.prototype = Object.create(SpiceConn.prototype);
|
||||||
|
SpiceInputsConn.prototype.process_channel_message = function(msg)
|
||||||
|
{
|
||||||
|
if (msg.type == SPICE_MSG_INPUTS_INIT)
|
||||||
|
{
|
||||||
|
var inputs_init = new SpiceMsgInputsInit(msg.data);
|
||||||
|
this.keyboard_modifiers = inputs_init.keyboard_modifiers;
|
||||||
|
DEBUG > 1 && console.log("MsgInputsInit - modifier " + this.keyboard_modifiers);
|
||||||
|
// FIXME - We don't do anything with the keyboard modifiers...
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (msg.type == SPICE_MSG_INPUTS_KEY_MODIFIERS)
|
||||||
|
{
|
||||||
|
var key = new SpiceMsgInputsKeyModifiers(msg.data);
|
||||||
|
this.keyboard_modifiers = key.keyboard_modifiers;
|
||||||
|
DEBUG > 1 && console.log("MsgInputsKeyModifiers - modifier " + this.keyboard_modifiers);
|
||||||
|
// FIXME - We don't do anything with the keyboard modifiers...
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (msg.type == SPICE_MSG_INPUTS_MOUSE_MOTION_ACK)
|
||||||
|
{
|
||||||
|
DEBUG > 1 && console.log("mouse motion ack");
|
||||||
|
this.waiting_for_ack -= SPICE_INPUT_MOTION_ACK_BUNCH;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function handle_mousemove(e)
|
||||||
|
{
|
||||||
|
var msg = new SpiceMiniData();
|
||||||
|
var move;
|
||||||
|
if (this.sc.mouse_mode == SPICE_MOUSE_MODE_CLIENT)
|
||||||
|
{
|
||||||
|
move = new SpiceMsgcMousePosition(this.sc, e)
|
||||||
|
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_POSITION, move);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
move = new SpiceMsgcMouseMotion(this.sc, e)
|
||||||
|
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_MOTION, move);
|
||||||
|
}
|
||||||
|
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
|
||||||
|
{
|
||||||
|
if (this.sc.inputs.waiting_for_ack < (2 * SPICE_INPUT_MOTION_ACK_BUNCH))
|
||||||
|
{
|
||||||
|
this.sc.inputs.send_msg(msg);
|
||||||
|
this.sc.inputs.waiting_for_ack++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DEBUG > 0 && this.sc.log_info("Discarding mouse motion");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.sc && this.sc.cursor && this.sc.cursor.spice_simulated_cursor)
|
||||||
|
{
|
||||||
|
this.sc.cursor.spice_simulated_cursor.style.display = 'block';
|
||||||
|
this.sc.cursor.spice_simulated_cursor.style.left = e.pageX - this.sc.cursor.spice_simulated_cursor.spice_hot_x + 'px';
|
||||||
|
this.sc.cursor.spice_simulated_cursor.style.top = e.pageY - this.sc.cursor.spice_simulated_cursor.spice_hot_y + 'px';
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_mousedown(e)
|
||||||
|
{
|
||||||
|
var press = new SpiceMsgcMousePress(this.sc, e)
|
||||||
|
var msg = new SpiceMiniData();
|
||||||
|
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_PRESS, press);
|
||||||
|
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
|
||||||
|
this.sc.inputs.send_msg(msg);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_contextmenu(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_mouseup(e)
|
||||||
|
{
|
||||||
|
var release = new SpiceMsgcMouseRelease(this.sc, e)
|
||||||
|
var msg = new SpiceMiniData();
|
||||||
|
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_RELEASE, release);
|
||||||
|
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
|
||||||
|
this.sc.inputs.send_msg(msg);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_mousewheel(e)
|
||||||
|
{
|
||||||
|
var press = new SpiceMsgcMousePress;
|
||||||
|
var release = new SpiceMsgcMouseRelease;
|
||||||
|
if (e.deltaY < 0)
|
||||||
|
press.button = release.button = SPICE_MOUSE_BUTTON_UP;
|
||||||
|
else
|
||||||
|
press.button = release.button = SPICE_MOUSE_BUTTON_DOWN;
|
||||||
|
press.buttons_state = 0;
|
||||||
|
release.buttons_state = 0;
|
||||||
|
|
||||||
|
var msg = new SpiceMiniData();
|
||||||
|
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_PRESS, press);
|
||||||
|
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
|
||||||
|
this.sc.inputs.send_msg(msg);
|
||||||
|
|
||||||
|
msg.build_msg(SPICE_MSGC_INPUTS_MOUSE_RELEASE, release);
|
||||||
|
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
|
||||||
|
this.sc.inputs.send_msg(msg);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_keydown(e)
|
||||||
|
{
|
||||||
|
var key = new SpiceMsgcKeyDown(e)
|
||||||
|
var msg = new SpiceMiniData();
|
||||||
|
check_and_update_modifiers(e, key.code, this.sc);
|
||||||
|
msg.build_msg(SPICE_MSGC_INPUTS_KEY_DOWN, key);
|
||||||
|
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
|
||||||
|
this.sc.inputs.send_msg(msg);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_keyup(e)
|
||||||
|
{
|
||||||
|
var key = new SpiceMsgcKeyUp(e)
|
||||||
|
var msg = new SpiceMiniData();
|
||||||
|
check_and_update_modifiers(e, key.code, this.sc);
|
||||||
|
msg.build_msg(SPICE_MSGC_INPUTS_KEY_UP, key);
|
||||||
|
if (this.sc && this.sc.inputs && this.sc.inputs.state === "ready")
|
||||||
|
this.sc.inputs.send_msg(msg);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendCtrlAltDel()
|
||||||
|
{
|
||||||
|
if (sc && sc.inputs && sc.inputs.state === "ready"){
|
||||||
|
var key = new SpiceMsgcKeyDown();
|
||||||
|
var msg = new SpiceMiniData();
|
||||||
|
|
||||||
|
update_modifier(true, KEY_LCtrl, sc);
|
||||||
|
update_modifier(true, KEY_Alt, sc);
|
||||||
|
|
||||||
|
key.code = KEY_KP_Decimal;
|
||||||
|
msg.build_msg(SPICE_MSGC_INPUTS_KEY_DOWN, key);
|
||||||
|
sc.inputs.send_msg(msg);
|
||||||
|
msg.build_msg(SPICE_MSGC_INPUTS_KEY_UP, key);
|
||||||
|
sc.inputs.send_msg(msg);
|
||||||
|
|
||||||
|
if(Ctrl_state == false) update_modifier(false, KEY_LCtrl, sc);
|
||||||
|
if(Alt_state == false) update_modifier(false, KEY_Alt, sc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function update_modifier(state, code, sc)
|
||||||
|
{
|
||||||
|
var msg = new SpiceMiniData();
|
||||||
|
if (!state)
|
||||||
|
{
|
||||||
|
var key = new SpiceMsgcKeyUp()
|
||||||
|
key.code =(0x80|code);
|
||||||
|
msg.build_msg(SPICE_MSGC_INPUTS_KEY_UP, key);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var key = new SpiceMsgcKeyDown()
|
||||||
|
key.code = code;
|
||||||
|
msg.build_msg(SPICE_MSGC_INPUTS_KEY_DOWN, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
sc.inputs.send_msg(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_and_update_modifiers(e, code, sc)
|
||||||
|
{
|
||||||
|
if (Shift_state === -1)
|
||||||
|
{
|
||||||
|
Shift_state = e.shiftKey;
|
||||||
|
Ctrl_state = e.ctrlKey;
|
||||||
|
Alt_state = e.altKey;
|
||||||
|
Meta_state = e.metaKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code === KEY_ShiftL)
|
||||||
|
Shift_state = true;
|
||||||
|
else if (code === KEY_Alt)
|
||||||
|
Alt_state = true;
|
||||||
|
else if (code === KEY_LCtrl)
|
||||||
|
Ctrl_state = true;
|
||||||
|
else if (code === 0xE0B5)
|
||||||
|
Meta_state = true;
|
||||||
|
else if (code === (0x80|KEY_ShiftL))
|
||||||
|
Shift_state = false;
|
||||||
|
else if (code === (0x80|KEY_Alt))
|
||||||
|
Alt_state = false;
|
||||||
|
else if (code === (0x80|KEY_LCtrl))
|
||||||
|
Ctrl_state = false;
|
||||||
|
else if (code === (0x80|0xE0B5))
|
||||||
|
Meta_state = false;
|
||||||
|
|
||||||
|
if (sc && sc.inputs && sc.inputs.state === "ready")
|
||||||
|
{
|
||||||
|
if (Shift_state != e.shiftKey)
|
||||||
|
{
|
||||||
|
console.log("Shift state out of sync");
|
||||||
|
update_modifier(e.shiftKey, KEY_ShiftL, sc);
|
||||||
|
Shift_state = e.shiftKey;
|
||||||
|
}
|
||||||
|
if (Alt_state != e.altKey)
|
||||||
|
{
|
||||||
|
console.log("Alt state out of sync");
|
||||||
|
update_modifier(e.altKey, KEY_Alt, sc);
|
||||||
|
Alt_state = e.altKey;
|
||||||
|
}
|
||||||
|
if (Ctrl_state != e.ctrlKey)
|
||||||
|
{
|
||||||
|
console.log("Ctrl state out of sync");
|
||||||
|
update_modifier(e.ctrlKey, KEY_LCtrl, sc);
|
||||||
|
Ctrl_state = e.ctrlKey;
|
||||||
|
}
|
||||||
|
if (Meta_state != e.metaKey)
|
||||||
|
{
|
||||||
|
console.log("Meta state out of sync");
|
||||||
|
update_modifier(e.metaKey, 0xE0B5, sc);
|
||||||
|
Meta_state = e.metaKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
589
static/js/spice-html5/jsbn.js
Normal file
589
static/js/spice-html5/jsbn.js
Normal file
|
@ -0,0 +1,589 @@
|
||||||
|
// Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2003-2005 Tom Wu
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||||
|
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||||
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||||
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||||
|
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||||
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* In addition, the following condition applies:
|
||||||
|
*
|
||||||
|
* All redistributions must retain an intact copy of this copyright notice
|
||||||
|
* and disclaimer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// Basic JavaScript BN library - subset useful for RSA encryption.
|
||||||
|
|
||||||
|
// Bits per digit
|
||||||
|
var dbits;
|
||||||
|
|
||||||
|
// JavaScript engine analysis
|
||||||
|
var canary = 0xdeadbeefcafe;
|
||||||
|
var j_lm = ((canary&0xffffff)==0xefcafe);
|
||||||
|
|
||||||
|
// (public) Constructor
|
||||||
|
function BigInteger(a,b,c) {
|
||||||
|
if(a != null)
|
||||||
|
if("number" == typeof a) this.fromNumber(a,b,c);
|
||||||
|
else if(b == null && "string" != typeof a) this.fromString(a,256);
|
||||||
|
else this.fromString(a,b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// return new, unset BigInteger
|
||||||
|
function nbi() { return new BigInteger(null); }
|
||||||
|
|
||||||
|
// am: Compute w_j += (x*this_i), propagate carries,
|
||||||
|
// c is initial carry, returns final carry.
|
||||||
|
// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
|
||||||
|
// We need to select the fastest one that works in this environment.
|
||||||
|
|
||||||
|
// am1: use a single mult and divide to get the high bits,
|
||||||
|
// max digit bits should be 26 because
|
||||||
|
// max internal value = 2*dvalue^2-2*dvalue (< 2^53)
|
||||||
|
function am1(i,x,w,j,c,n) {
|
||||||
|
while(--n >= 0) {
|
||||||
|
var v = x*this[i++]+w[j]+c;
|
||||||
|
c = Math.floor(v/0x4000000);
|
||||||
|
w[j++] = v&0x3ffffff;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
// am2 avoids a big mult-and-extract completely.
|
||||||
|
// Max digit bits should be <= 30 because we do bitwise ops
|
||||||
|
// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
|
||||||
|
function am2(i,x,w,j,c,n) {
|
||||||
|
var xl = x&0x7fff, xh = x>>15;
|
||||||
|
while(--n >= 0) {
|
||||||
|
var l = this[i]&0x7fff;
|
||||||
|
var h = this[i++]>>15;
|
||||||
|
var m = xh*l+h*xl;
|
||||||
|
l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);
|
||||||
|
c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);
|
||||||
|
w[j++] = l&0x3fffffff;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
// Alternately, set max digit bits to 28 since some
|
||||||
|
// browsers slow down when dealing with 32-bit numbers.
|
||||||
|
function am3(i,x,w,j,c,n) {
|
||||||
|
var xl = x&0x3fff, xh = x>>14;
|
||||||
|
while(--n >= 0) {
|
||||||
|
var l = this[i]&0x3fff;
|
||||||
|
var h = this[i++]>>14;
|
||||||
|
var m = xh*l+h*xl;
|
||||||
|
l = xl*l+((m&0x3fff)<<14)+w[j]+c;
|
||||||
|
c = (l>>28)+(m>>14)+xh*h;
|
||||||
|
w[j++] = l&0xfffffff;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
|
||||||
|
BigInteger.prototype.am = am2;
|
||||||
|
dbits = 30;
|
||||||
|
}
|
||||||
|
else if(j_lm && (navigator.appName != "Netscape")) {
|
||||||
|
BigInteger.prototype.am = am1;
|
||||||
|
dbits = 26;
|
||||||
|
}
|
||||||
|
else { // Mozilla/Netscape seems to prefer am3
|
||||||
|
BigInteger.prototype.am = am3;
|
||||||
|
dbits = 28;
|
||||||
|
}
|
||||||
|
|
||||||
|
BigInteger.prototype.DB = dbits;
|
||||||
|
BigInteger.prototype.DM = ((1<<dbits)-1);
|
||||||
|
BigInteger.prototype.DV = (1<<dbits);
|
||||||
|
|
||||||
|
var BI_FP = 52;
|
||||||
|
BigInteger.prototype.FV = Math.pow(2,BI_FP);
|
||||||
|
BigInteger.prototype.F1 = BI_FP-dbits;
|
||||||
|
BigInteger.prototype.F2 = 2*dbits-BI_FP;
|
||||||
|
|
||||||
|
// Digit conversions
|
||||||
|
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||||
|
var BI_RC = new Array();
|
||||||
|
var rr,vv;
|
||||||
|
rr = "0".charCodeAt(0);
|
||||||
|
for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
|
||||||
|
rr = "a".charCodeAt(0);
|
||||||
|
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
||||||
|
rr = "A".charCodeAt(0);
|
||||||
|
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
||||||
|
|
||||||
|
function int2char(n) { return BI_RM.charAt(n); }
|
||||||
|
function intAt(s,i) {
|
||||||
|
var c = BI_RC[s.charCodeAt(i)];
|
||||||
|
return (c==null)?-1:c;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) copy this to r
|
||||||
|
function bnpCopyTo(r) {
|
||||||
|
for(var i = this.t-1; i >= 0; --i) r[i] = this[i];
|
||||||
|
r.t = this.t;
|
||||||
|
r.s = this.s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) set from integer value x, -DV <= x < DV
|
||||||
|
function bnpFromInt(x) {
|
||||||
|
this.t = 1;
|
||||||
|
this.s = (x<0)?-1:0;
|
||||||
|
if(x > 0) this[0] = x;
|
||||||
|
else if(x < -1) this[0] = x+DV;
|
||||||
|
else this.t = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return bigint initialized to value
|
||||||
|
function nbv(i) { var r = nbi(); r.fromInt(i); return r; }
|
||||||
|
|
||||||
|
// (protected) set from string and radix
|
||||||
|
function bnpFromString(s,b) {
|
||||||
|
var k;
|
||||||
|
if(b == 16) k = 4;
|
||||||
|
else if(b == 8) k = 3;
|
||||||
|
else if(b == 256) k = 8; // byte array
|
||||||
|
else if(b == 2) k = 1;
|
||||||
|
else if(b == 32) k = 5;
|
||||||
|
else if(b == 4) k = 2;
|
||||||
|
else { this.fromRadix(s,b); return; }
|
||||||
|
this.t = 0;
|
||||||
|
this.s = 0;
|
||||||
|
var i = s.length, mi = false, sh = 0;
|
||||||
|
while(--i >= 0) {
|
||||||
|
var x = (k==8)?s[i]&0xff:intAt(s,i);
|
||||||
|
if(x < 0) {
|
||||||
|
if(s.charAt(i) == "-") mi = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
mi = false;
|
||||||
|
if(sh == 0)
|
||||||
|
this[this.t++] = x;
|
||||||
|
else if(sh+k > this.DB) {
|
||||||
|
this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh;
|
||||||
|
this[this.t++] = (x>>(this.DB-sh));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this[this.t-1] |= x<<sh;
|
||||||
|
sh += k;
|
||||||
|
if(sh >= this.DB) sh -= this.DB;
|
||||||
|
}
|
||||||
|
if(k == 8 && (s[0]&0x80) != 0) {
|
||||||
|
this.s = -1;
|
||||||
|
if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh;
|
||||||
|
}
|
||||||
|
this.clamp();
|
||||||
|
if(mi) BigInteger.ZERO.subTo(this,this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) clamp off excess high words
|
||||||
|
function bnpClamp() {
|
||||||
|
var c = this.s&this.DM;
|
||||||
|
while(this.t > 0 && this[this.t-1] == c) --this.t;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (public) return string representation in given radix
|
||||||
|
function bnToString(b) {
|
||||||
|
if(this.s < 0) return "-"+this.negate().toString(b);
|
||||||
|
var k;
|
||||||
|
if(b == 16) k = 4;
|
||||||
|
else if(b == 8) k = 3;
|
||||||
|
else if(b == 2) k = 1;
|
||||||
|
else if(b == 32) k = 5;
|
||||||
|
else if(b == 4) k = 2;
|
||||||
|
else return this.toRadix(b);
|
||||||
|
var km = (1<<k)-1, d, m = false, r = "", i = this.t;
|
||||||
|
var p = this.DB-(i*this.DB)%k;
|
||||||
|
if(i-- > 0) {
|
||||||
|
if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }
|
||||||
|
while(i >= 0) {
|
||||||
|
if(p < k) {
|
||||||
|
d = (this[i]&((1<<p)-1))<<(k-p);
|
||||||
|
d |= this[--i]>>(p+=this.DB-k);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
d = (this[i]>>(p-=k))&km;
|
||||||
|
if(p <= 0) { p += this.DB; --i; }
|
||||||
|
}
|
||||||
|
if(d > 0) m = true;
|
||||||
|
if(m) r += int2char(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m?r:"0";
|
||||||
|
}
|
||||||
|
|
||||||
|
// (public) -this
|
||||||
|
function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; }
|
||||||
|
|
||||||
|
// (public) |this|
|
||||||
|
function bnAbs() { return (this.s<0)?this.negate():this; }
|
||||||
|
|
||||||
|
// (public) return + if this > a, - if this < a, 0 if equal
|
||||||
|
function bnCompareTo(a) {
|
||||||
|
var r = this.s-a.s;
|
||||||
|
if(r != 0) return r;
|
||||||
|
var i = this.t;
|
||||||
|
r = i-a.t;
|
||||||
|
if(r != 0) return r;
|
||||||
|
while(--i >= 0) if((r=this[i]-a[i]) != 0) return r;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns bit length of the integer x
|
||||||
|
function nbits(x) {
|
||||||
|
var r = 1, t;
|
||||||
|
if((t=x>>>16) != 0) { x = t; r += 16; }
|
||||||
|
if((t=x>>8) != 0) { x = t; r += 8; }
|
||||||
|
if((t=x>>4) != 0) { x = t; r += 4; }
|
||||||
|
if((t=x>>2) != 0) { x = t; r += 2; }
|
||||||
|
if((t=x>>1) != 0) { x = t; r += 1; }
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (public) return the number of bits in "this"
|
||||||
|
function bnBitLength() {
|
||||||
|
if(this.t <= 0) return 0;
|
||||||
|
return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM));
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this << n*DB
|
||||||
|
function bnpDLShiftTo(n,r) {
|
||||||
|
var i;
|
||||||
|
for(i = this.t-1; i >= 0; --i) r[i+n] = this[i];
|
||||||
|
for(i = n-1; i >= 0; --i) r[i] = 0;
|
||||||
|
r.t = this.t+n;
|
||||||
|
r.s = this.s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this >> n*DB
|
||||||
|
function bnpDRShiftTo(n,r) {
|
||||||
|
for(var i = n; i < this.t; ++i) r[i-n] = this[i];
|
||||||
|
r.t = Math.max(this.t-n,0);
|
||||||
|
r.s = this.s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this << n
|
||||||
|
function bnpLShiftTo(n,r) {
|
||||||
|
var bs = n%this.DB;
|
||||||
|
var cbs = this.DB-bs;
|
||||||
|
var bm = (1<<cbs)-1;
|
||||||
|
var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i;
|
||||||
|
for(i = this.t-1; i >= 0; --i) {
|
||||||
|
r[i+ds+1] = (this[i]>>cbs)|c;
|
||||||
|
c = (this[i]&bm)<<bs;
|
||||||
|
}
|
||||||
|
for(i = ds-1; i >= 0; --i) r[i] = 0;
|
||||||
|
r[ds] = c;
|
||||||
|
r.t = this.t+ds+1;
|
||||||
|
r.s = this.s;
|
||||||
|
r.clamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this >> n
|
||||||
|
function bnpRShiftTo(n,r) {
|
||||||
|
r.s = this.s;
|
||||||
|
var ds = Math.floor(n/this.DB);
|
||||||
|
if(ds >= this.t) { r.t = 0; return; }
|
||||||
|
var bs = n%this.DB;
|
||||||
|
var cbs = this.DB-bs;
|
||||||
|
var bm = (1<<bs)-1;
|
||||||
|
r[0] = this[ds]>>bs;
|
||||||
|
for(var i = ds+1; i < this.t; ++i) {
|
||||||
|
r[i-ds-1] |= (this[i]&bm)<<cbs;
|
||||||
|
r[i-ds] = this[i]>>bs;
|
||||||
|
}
|
||||||
|
if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs;
|
||||||
|
r.t = this.t-ds;
|
||||||
|
r.clamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this - a
|
||||||
|
function bnpSubTo(a,r) {
|
||||||
|
var i = 0, c = 0, m = Math.min(a.t,this.t);
|
||||||
|
while(i < m) {
|
||||||
|
c += this[i]-a[i];
|
||||||
|
r[i++] = c&this.DM;
|
||||||
|
c >>= this.DB;
|
||||||
|
}
|
||||||
|
if(a.t < this.t) {
|
||||||
|
c -= a.s;
|
||||||
|
while(i < this.t) {
|
||||||
|
c += this[i];
|
||||||
|
r[i++] = c&this.DM;
|
||||||
|
c >>= this.DB;
|
||||||
|
}
|
||||||
|
c += this.s;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
c += this.s;
|
||||||
|
while(i < a.t) {
|
||||||
|
c -= a[i];
|
||||||
|
r[i++] = c&this.DM;
|
||||||
|
c >>= this.DB;
|
||||||
|
}
|
||||||
|
c -= a.s;
|
||||||
|
}
|
||||||
|
r.s = (c<0)?-1:0;
|
||||||
|
if(c < -1) r[i++] = this.DV+c;
|
||||||
|
else if(c > 0) r[i++] = c;
|
||||||
|
r.t = i;
|
||||||
|
r.clamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this * a, r != this,a (HAC 14.12)
|
||||||
|
// "this" should be the larger one if appropriate.
|
||||||
|
function bnpMultiplyTo(a,r) {
|
||||||
|
var x = this.abs(), y = a.abs();
|
||||||
|
var i = x.t;
|
||||||
|
r.t = i+y.t;
|
||||||
|
while(--i >= 0) r[i] = 0;
|
||||||
|
for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t);
|
||||||
|
r.s = 0;
|
||||||
|
r.clamp();
|
||||||
|
if(this.s != a.s) BigInteger.ZERO.subTo(r,r);
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this^2, r != this (HAC 14.16)
|
||||||
|
function bnpSquareTo(r) {
|
||||||
|
var x = this.abs();
|
||||||
|
var i = r.t = 2*x.t;
|
||||||
|
while(--i >= 0) r[i] = 0;
|
||||||
|
for(i = 0; i < x.t-1; ++i) {
|
||||||
|
var c = x.am(i,x[i],r,2*i,0,1);
|
||||||
|
if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) {
|
||||||
|
r[i+x.t] -= x.DV;
|
||||||
|
r[i+x.t+1] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1);
|
||||||
|
r.s = 0;
|
||||||
|
r.clamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
|
||||||
|
// r != q, this != m. q or r may be null.
|
||||||
|
function bnpDivRemTo(m,q,r) {
|
||||||
|
var pm = m.abs();
|
||||||
|
if(pm.t <= 0) return;
|
||||||
|
var pt = this.abs();
|
||||||
|
if(pt.t < pm.t) {
|
||||||
|
if(q != null) q.fromInt(0);
|
||||||
|
if(r != null) this.copyTo(r);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(r == null) r = nbi();
|
||||||
|
var y = nbi(), ts = this.s, ms = m.s;
|
||||||
|
var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus
|
||||||
|
if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); }
|
||||||
|
else { pm.copyTo(y); pt.copyTo(r); }
|
||||||
|
var ys = y.t;
|
||||||
|
var y0 = y[ys-1];
|
||||||
|
if(y0 == 0) return;
|
||||||
|
var yt = y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0);
|
||||||
|
var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2;
|
||||||
|
var i = r.t, j = i-ys, t = (q==null)?nbi():q;
|
||||||
|
y.dlShiftTo(j,t);
|
||||||
|
if(r.compareTo(t) >= 0) {
|
||||||
|
r[r.t++] = 1;
|
||||||
|
r.subTo(t,r);
|
||||||
|
}
|
||||||
|
BigInteger.ONE.dlShiftTo(ys,t);
|
||||||
|
t.subTo(y,y); // "negative" y so we can replace sub with am later
|
||||||
|
while(y.t < ys) y[y.t++] = 0;
|
||||||
|
while(--j >= 0) {
|
||||||
|
// Estimate quotient digit
|
||||||
|
var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);
|
||||||
|
if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out
|
||||||
|
y.dlShiftTo(j,t);
|
||||||
|
r.subTo(t,r);
|
||||||
|
while(r[i] < --qd) r.subTo(t,r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(q != null) {
|
||||||
|
r.drShiftTo(ys,q);
|
||||||
|
if(ts != ms) BigInteger.ZERO.subTo(q,q);
|
||||||
|
}
|
||||||
|
r.t = ys;
|
||||||
|
r.clamp();
|
||||||
|
if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder
|
||||||
|
if(ts < 0) BigInteger.ZERO.subTo(r,r);
|
||||||
|
}
|
||||||
|
|
||||||
|
// (public) this mod a
|
||||||
|
function bnMod(a) {
|
||||||
|
var r = nbi();
|
||||||
|
this.abs().divRemTo(a,null,r);
|
||||||
|
if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modular reduction using "classic" algorithm
|
||||||
|
function Classic(m) { this.m = m; }
|
||||||
|
function cConvert(x) {
|
||||||
|
if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
|
||||||
|
else return x;
|
||||||
|
}
|
||||||
|
function cRevert(x) { return x; }
|
||||||
|
function cReduce(x) { x.divRemTo(this.m,null,x); }
|
||||||
|
function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||||||
|
function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||||||
|
|
||||||
|
Classic.prototype.convert = cConvert;
|
||||||
|
Classic.prototype.revert = cRevert;
|
||||||
|
Classic.prototype.reduce = cReduce;
|
||||||
|
Classic.prototype.mulTo = cMulTo;
|
||||||
|
Classic.prototype.sqrTo = cSqrTo;
|
||||||
|
|
||||||
|
// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
|
||||||
|
// justification:
|
||||||
|
// xy == 1 (mod m)
|
||||||
|
// xy = 1+km
|
||||||
|
// xy(2-xy) = (1+km)(1-km)
|
||||||
|
// x[y(2-xy)] = 1-k^2m^2
|
||||||
|
// x[y(2-xy)] == 1 (mod m^2)
|
||||||
|
// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
|
||||||
|
// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
|
||||||
|
// JS multiply "overflows" differently from C/C++, so care is needed here.
|
||||||
|
function bnpInvDigit() {
|
||||||
|
if(this.t < 1) return 0;
|
||||||
|
var x = this[0];
|
||||||
|
if((x&1) == 0) return 0;
|
||||||
|
var y = x&3; // y == 1/x mod 2^2
|
||||||
|
y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4
|
||||||
|
y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8
|
||||||
|
y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16
|
||||||
|
// last step - calculate inverse mod DV directly;
|
||||||
|
// assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
|
||||||
|
y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits
|
||||||
|
// we really want the negative inverse, and -DV < y < DV
|
||||||
|
return (y>0)?this.DV-y:-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Montgomery reduction
|
||||||
|
function Montgomery(m) {
|
||||||
|
this.m = m;
|
||||||
|
this.mp = m.invDigit();
|
||||||
|
this.mpl = this.mp&0x7fff;
|
||||||
|
this.mph = this.mp>>15;
|
||||||
|
this.um = (1<<(m.DB-15))-1;
|
||||||
|
this.mt2 = 2*m.t;
|
||||||
|
}
|
||||||
|
|
||||||
|
// xR mod m
|
||||||
|
function montConvert(x) {
|
||||||
|
var r = nbi();
|
||||||
|
x.abs().dlShiftTo(this.m.t,r);
|
||||||
|
r.divRemTo(this.m,null,r);
|
||||||
|
if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// x/R mod m
|
||||||
|
function montRevert(x) {
|
||||||
|
var r = nbi();
|
||||||
|
x.copyTo(r);
|
||||||
|
this.reduce(r);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// x = x/R mod m (HAC 14.32)
|
||||||
|
function montReduce(x) {
|
||||||
|
while(x.t <= this.mt2) // pad x so am has enough room later
|
||||||
|
x[x.t++] = 0;
|
||||||
|
for(var i = 0; i < this.m.t; ++i) {
|
||||||
|
// faster way of calculating u0 = x[i]*mp mod DV
|
||||||
|
var j = x[i]&0x7fff;
|
||||||
|
var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM;
|
||||||
|
// use am to combine the multiply-shift-add into one call
|
||||||
|
j = i+this.m.t;
|
||||||
|
x[j] += this.m.am(0,u0,x,i,0,this.m.t);
|
||||||
|
// propagate carry
|
||||||
|
while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; }
|
||||||
|
}
|
||||||
|
x.clamp();
|
||||||
|
x.drShiftTo(this.m.t,x);
|
||||||
|
if(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// r = "x^2/R mod m"; x != r
|
||||||
|
function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||||||
|
|
||||||
|
// r = "xy/R mod m"; x,y != r
|
||||||
|
function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||||||
|
|
||||||
|
Montgomery.prototype.convert = montConvert;
|
||||||
|
Montgomery.prototype.revert = montRevert;
|
||||||
|
Montgomery.prototype.reduce = montReduce;
|
||||||
|
Montgomery.prototype.mulTo = montMulTo;
|
||||||
|
Montgomery.prototype.sqrTo = montSqrTo;
|
||||||
|
|
||||||
|
// (protected) true iff this is even
|
||||||
|
function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }
|
||||||
|
|
||||||
|
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
||||||
|
function bnpExp(e,z) {
|
||||||
|
if(e > 0xffffffff || e < 1) return BigInteger.ONE;
|
||||||
|
var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
|
||||||
|
g.copyTo(r);
|
||||||
|
while(--i >= 0) {
|
||||||
|
z.sqrTo(r,r2);
|
||||||
|
if((e&(1<<i)) > 0) z.mulTo(r2,g,r);
|
||||||
|
else { var t = r; r = r2; r2 = t; }
|
||||||
|
}
|
||||||
|
return z.revert(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
// (public) this^e % m, 0 <= e < 2^32
|
||||||
|
function bnModPowInt(e,m) {
|
||||||
|
var z;
|
||||||
|
if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
|
||||||
|
return this.exp(e,z);
|
||||||
|
}
|
||||||
|
|
||||||
|
// protected
|
||||||
|
BigInteger.prototype.copyTo = bnpCopyTo;
|
||||||
|
BigInteger.prototype.fromInt = bnpFromInt;
|
||||||
|
BigInteger.prototype.fromString = bnpFromString;
|
||||||
|
BigInteger.prototype.clamp = bnpClamp;
|
||||||
|
BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
|
||||||
|
BigInteger.prototype.drShiftTo = bnpDRShiftTo;
|
||||||
|
BigInteger.prototype.lShiftTo = bnpLShiftTo;
|
||||||
|
BigInteger.prototype.rShiftTo = bnpRShiftTo;
|
||||||
|
BigInteger.prototype.subTo = bnpSubTo;
|
||||||
|
BigInteger.prototype.multiplyTo = bnpMultiplyTo;
|
||||||
|
BigInteger.prototype.squareTo = bnpSquareTo;
|
||||||
|
BigInteger.prototype.divRemTo = bnpDivRemTo;
|
||||||
|
BigInteger.prototype.invDigit = bnpInvDigit;
|
||||||
|
BigInteger.prototype.isEven = bnpIsEven;
|
||||||
|
BigInteger.prototype.exp = bnpExp;
|
||||||
|
|
||||||
|
// public
|
||||||
|
BigInteger.prototype.toString = bnToString;
|
||||||
|
BigInteger.prototype.negate = bnNegate;
|
||||||
|
BigInteger.prototype.abs = bnAbs;
|
||||||
|
BigInteger.prototype.compareTo = bnCompareTo;
|
||||||
|
BigInteger.prototype.bitLength = bnBitLength;
|
||||||
|
BigInteger.prototype.mod = bnMod;
|
||||||
|
BigInteger.prototype.modPowInt = bnModPowInt;
|
||||||
|
|
||||||
|
// "constants"
|
||||||
|
BigInteger.ZERO = nbv(0);
|
||||||
|
BigInteger.ONE = nbv(1);
|
166
static/js/spice-html5/lz.js
Normal file
166
static/js/spice-html5/lz.js
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** lz.js
|
||||||
|
** Functions for handling SPICE_IMAGE_TYPE_LZ_RGB
|
||||||
|
** Adapted from lz.c .
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function lz_rgb32_decompress(in_buf, at, out_buf, type, default_alpha)
|
||||||
|
{
|
||||||
|
var encoder = at;
|
||||||
|
var op = 0;
|
||||||
|
var ctrl;
|
||||||
|
var ctr = 0;
|
||||||
|
|
||||||
|
for (ctrl = in_buf[encoder++]; (op * 4) < out_buf.length; ctrl = in_buf[encoder++])
|
||||||
|
{
|
||||||
|
var ref = op;
|
||||||
|
var len = ctrl >> 5;
|
||||||
|
var ofs = (ctrl & 31) << 8;
|
||||||
|
|
||||||
|
//if (type == LZ_IMAGE_TYPE_RGBA)
|
||||||
|
//console.log(ctr++ + ": from " + (encoder + 28) + ", ctrl " + ctrl + ", len " + len + ", ofs " + ofs + ", op " + op);
|
||||||
|
if (ctrl >= 32) {
|
||||||
|
|
||||||
|
var code;
|
||||||
|
len--;
|
||||||
|
|
||||||
|
if (len == 7 - 1) {
|
||||||
|
do {
|
||||||
|
code = in_buf[encoder++];
|
||||||
|
len += code;
|
||||||
|
} while (code == 255);
|
||||||
|
}
|
||||||
|
code = in_buf[encoder++];
|
||||||
|
ofs += code;
|
||||||
|
|
||||||
|
|
||||||
|
if (code == 255) {
|
||||||
|
if ((ofs - code) == (31 << 8)) {
|
||||||
|
ofs = in_buf[encoder++] << 8;
|
||||||
|
ofs += in_buf[encoder++];
|
||||||
|
ofs += 8191;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
len += 1;
|
||||||
|
if (type == LZ_IMAGE_TYPE_RGBA)
|
||||||
|
len += 2;
|
||||||
|
|
||||||
|
ofs += 1;
|
||||||
|
|
||||||
|
ref -= ofs;
|
||||||
|
if (ref == (op - 1)) {
|
||||||
|
var b = ref;
|
||||||
|
//if (type == LZ_IMAGE_TYPE_RGBA) console.log("alpha " + out_buf[(b*4)+3] + " dupped into pixel " + op + " through pixel " + (op + len));
|
||||||
|
for (; len; --len) {
|
||||||
|
if (type == LZ_IMAGE_TYPE_RGBA)
|
||||||
|
{
|
||||||
|
out_buf[(op*4) + 3] = out_buf[(b*4)+3];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
out_buf[(op*4) + i] = out_buf[(b*4)+i];
|
||||||
|
}
|
||||||
|
op++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//if (type == LZ_IMAGE_TYPE_RGBA) console.log("alpha copied to pixel " + op + " through " + (op + len) + " from " + ref);
|
||||||
|
for (; len; --len) {
|
||||||
|
if (type == LZ_IMAGE_TYPE_RGBA)
|
||||||
|
{
|
||||||
|
out_buf[(op*4) + 3] = out_buf[(ref*4)+3];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = 0; i < 4; i++)
|
||||||
|
out_buf[(op*4) + i] = out_buf[(ref*4)+i];
|
||||||
|
}
|
||||||
|
op++; ref++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctrl++;
|
||||||
|
|
||||||
|
if (type == LZ_IMAGE_TYPE_RGBA)
|
||||||
|
{
|
||||||
|
//console.log("alpha " + in_buf[encoder] + " set into pixel " + op);
|
||||||
|
out_buf[(op*4) + 3] = in_buf[encoder++];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out_buf[(op*4) + 0] = in_buf[encoder + 2];
|
||||||
|
out_buf[(op*4) + 1] = in_buf[encoder + 1];
|
||||||
|
out_buf[(op*4) + 2] = in_buf[encoder + 0];
|
||||||
|
if (default_alpha)
|
||||||
|
out_buf[(op*4) + 3] = 255;
|
||||||
|
encoder += 3;
|
||||||
|
}
|
||||||
|
op++;
|
||||||
|
|
||||||
|
|
||||||
|
for (--ctrl; ctrl; ctrl--) {
|
||||||
|
if (type == LZ_IMAGE_TYPE_RGBA)
|
||||||
|
{
|
||||||
|
//console.log("alpha " + in_buf[encoder] + " set into pixel " + op);
|
||||||
|
out_buf[(op*4) + 3] = in_buf[encoder++];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
out_buf[(op*4) + 0] = in_buf[encoder + 2];
|
||||||
|
out_buf[(op*4) + 1] = in_buf[encoder + 1];
|
||||||
|
out_buf[(op*4) + 2] = in_buf[encoder + 0];
|
||||||
|
if (default_alpha)
|
||||||
|
out_buf[(op*4) + 3] = 255;
|
||||||
|
encoder += 3;
|
||||||
|
}
|
||||||
|
op++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return encoder - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function convert_spice_lz_to_web(context, lz_image)
|
||||||
|
{
|
||||||
|
var at;
|
||||||
|
if (lz_image.type === LZ_IMAGE_TYPE_RGB32 || lz_image.type === LZ_IMAGE_TYPE_RGBA)
|
||||||
|
{
|
||||||
|
var u8 = new Uint8Array(lz_image.data);
|
||||||
|
var ret = context.createImageData(lz_image.width, lz_image.height);
|
||||||
|
|
||||||
|
at = lz_rgb32_decompress(u8, 0, ret.data, LZ_IMAGE_TYPE_RGB32, lz_image.type != LZ_IMAGE_TYPE_RGBA);
|
||||||
|
if (lz_image.type == LZ_IMAGE_TYPE_RGBA)
|
||||||
|
lz_rgb32_decompress(u8, at, ret.data, LZ_IMAGE_TYPE_RGBA, false);
|
||||||
|
}
|
||||||
|
else if (lz_image.type === LZ_IMAGE_TYPE_XXXA)
|
||||||
|
{
|
||||||
|
var u8 = new Uint8Array(lz_image.data);
|
||||||
|
var ret = context.createImageData(lz_image.width, lz_image.height);
|
||||||
|
lz_rgb32_decompress(u8, 0, ret.data, LZ_IMAGE_TYPE_RGBA, false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return undefined;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
417
static/js/spice-html5/main.js
Normal file
417
static/js/spice-html5/main.js
Normal file
|
@ -0,0 +1,417 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** SpiceMainConn
|
||||||
|
** This is the master Javascript class for establishing and
|
||||||
|
** managing a connection to a Spice Server.
|
||||||
|
**
|
||||||
|
** Invocation: You must pass an object with properties as follows:
|
||||||
|
** uri (required) Uri of a WebSocket listener that is
|
||||||
|
** connected to a spice server.
|
||||||
|
** password (required) Password to send to the spice server
|
||||||
|
** message_id (optional) Identifier of an element in the DOM
|
||||||
|
** where SpiceConn will write messages.
|
||||||
|
** It will use classes spice-messages-x,
|
||||||
|
** where x is one of info, warning, or error.
|
||||||
|
** screen_id (optional) Identifier of an element in the DOM
|
||||||
|
** where SpiceConn will create any new
|
||||||
|
** client screens. This is the main UI.
|
||||||
|
** dump_id (optional) If given, an element to use for
|
||||||
|
** dumping every single image + canvas drawn.
|
||||||
|
** Sometimes useful for debugging.
|
||||||
|
** onerror (optional) If given, a function to receive async
|
||||||
|
** errors. Note that you should also catch
|
||||||
|
** errors for ones that occur inline
|
||||||
|
** onagent (optional) If given, a function to be called when
|
||||||
|
** a VD agent is connected; a good opportunity
|
||||||
|
** to request a resize
|
||||||
|
**
|
||||||
|
** Throws error if there are troubles. Requires a modern (by 2012 standards)
|
||||||
|
** browser, including WebSocket and WebSocket.binaryType == arraybuffer
|
||||||
|
**
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function SpiceMainConn()
|
||||||
|
{
|
||||||
|
if (typeof WebSocket === "undefined")
|
||||||
|
throw new Error("WebSocket unavailable. You need to use a different browser.");
|
||||||
|
|
||||||
|
SpiceConn.apply(this, arguments);
|
||||||
|
|
||||||
|
this.agent_msg_queue = [];
|
||||||
|
this.file_xfer_tasks = {};
|
||||||
|
this.file_xfer_task_id = 0;
|
||||||
|
this.file_xfer_read_queue = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceMainConn.prototype = Object.create(SpiceConn.prototype);
|
||||||
|
SpiceMainConn.prototype.process_channel_message = function(msg)
|
||||||
|
{
|
||||||
|
if (msg.type == SPICE_MSG_MAIN_INIT)
|
||||||
|
{
|
||||||
|
this.log_info("Connected to " + this.ws.url);
|
||||||
|
this.report_success("Connected")
|
||||||
|
this.main_init = new SpiceMsgMainInit(msg.data);
|
||||||
|
this.connection_id = this.main_init.session_id;
|
||||||
|
this.agent_tokens = this.main_init.agent_tokens;
|
||||||
|
|
||||||
|
if (DEBUG > 0)
|
||||||
|
{
|
||||||
|
// FIXME - there is a lot here we don't handle; mouse modes, agent,
|
||||||
|
// ram_hint, multi_media_time
|
||||||
|
this.log_info("session id " + this.main_init.session_id +
|
||||||
|
" ; display_channels_hint " + this.main_init.display_channels_hint +
|
||||||
|
" ; supported_mouse_modes " + this.main_init.supported_mouse_modes +
|
||||||
|
" ; current_mouse_mode " + this.main_init.current_mouse_mode +
|
||||||
|
" ; agent_connected " + this.main_init.agent_connected +
|
||||||
|
" ; agent_tokens " + this.main_init.agent_tokens +
|
||||||
|
" ; multi_media_time " + this.main_init.multi_media_time +
|
||||||
|
" ; ram_hint " + this.main_init.ram_hint);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.handle_mouse_mode(this.main_init.current_mouse_mode,
|
||||||
|
this.main_init.supported_mouse_modes);
|
||||||
|
|
||||||
|
if (this.main_init.agent_connected)
|
||||||
|
this.connect_agent();
|
||||||
|
|
||||||
|
var attach = new SpiceMiniData;
|
||||||
|
attach.type = SPICE_MSGC_MAIN_ATTACH_CHANNELS;
|
||||||
|
attach.size = attach.buffer_size();
|
||||||
|
this.send_msg(attach);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_MAIN_MOUSE_MODE)
|
||||||
|
{
|
||||||
|
var mode = new SpiceMsgMainMouseMode(msg.data);
|
||||||
|
DEBUG > 0 && this.log_info("Mouse supported modes " + mode.supported_modes + "; current " + mode.current_mode);
|
||||||
|
this.handle_mouse_mode(mode.current_mode, mode.supported_modes);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_MAIN_CHANNELS_LIST)
|
||||||
|
{
|
||||||
|
var i;
|
||||||
|
var chans;
|
||||||
|
DEBUG > 0 && console.log("channels");
|
||||||
|
chans = new SpiceMsgChannels(msg.data);
|
||||||
|
for (i = 0; i < chans.channels.length; i++)
|
||||||
|
{
|
||||||
|
var conn = {
|
||||||
|
uri: this.ws.url,
|
||||||
|
parent: this,
|
||||||
|
connection_id : this.connection_id,
|
||||||
|
type : chans.channels[i].type,
|
||||||
|
chan_id : chans.channels[i].id
|
||||||
|
};
|
||||||
|
if (chans.channels[i].type == SPICE_CHANNEL_DISPLAY)
|
||||||
|
this.display = new SpiceDisplayConn(conn);
|
||||||
|
else if (chans.channels[i].type == SPICE_CHANNEL_INPUTS)
|
||||||
|
{
|
||||||
|
this.inputs = new SpiceInputsConn(conn);
|
||||||
|
this.inputs.mouse_mode = this.mouse_mode;
|
||||||
|
}
|
||||||
|
else if (chans.channels[i].type == SPICE_CHANNEL_CURSOR)
|
||||||
|
this.cursor = new SpiceCursorConn(conn);
|
||||||
|
else if (chans.channels[i].type == SPICE_CHANNEL_PLAYBACK)
|
||||||
|
this.cursor = new SpicePlaybackConn(conn);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.log_err("Channel type " + chans.channels[i].type + " unknown.");
|
||||||
|
if (! ("extra_channels" in this))
|
||||||
|
this.extra_channels = [];
|
||||||
|
this.extra_channels[i] = new SpiceConn(conn);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_MAIN_AGENT_CONNECTED)
|
||||||
|
{
|
||||||
|
this.connect_agent();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_MAIN_AGENT_CONNECTED_TOKENS)
|
||||||
|
{
|
||||||
|
var connected_tokens = new SpiceMsgMainAgentTokens(msg.data);
|
||||||
|
this.agent_tokens = connected_tokens.num_tokens;
|
||||||
|
this.connect_agent();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_MAIN_AGENT_TOKEN)
|
||||||
|
{
|
||||||
|
var remaining_tokens, tokens = new SpiceMsgMainAgentTokens(msg.data);
|
||||||
|
this.agent_tokens += tokens.num_tokens;
|
||||||
|
this.send_agent_message_queue();
|
||||||
|
|
||||||
|
remaining_tokens = this.agent_tokens;
|
||||||
|
while (remaining_tokens > 0 && this.file_xfer_read_queue.length > 0)
|
||||||
|
{
|
||||||
|
var xfer_task = this.file_xfer_read_queue.shift();
|
||||||
|
this.file_xfer_read(xfer_task, xfer_task.read_bytes);
|
||||||
|
remaining_tokens--;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_MAIN_AGENT_DISCONNECTED)
|
||||||
|
{
|
||||||
|
this.agent_connected = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_MAIN_AGENT_DATA)
|
||||||
|
{
|
||||||
|
var agent_data = new SpiceMsgMainAgentData(msg.data);
|
||||||
|
if (agent_data.type == VD_AGENT_ANNOUNCE_CAPABILITIES)
|
||||||
|
{
|
||||||
|
var agent_caps = new VDAgentAnnounceCapabilities(agent_data.data);
|
||||||
|
if (agent_caps.request)
|
||||||
|
this.announce_agent_capabilities(0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (agent_data.type == VD_AGENT_FILE_XFER_STATUS)
|
||||||
|
{
|
||||||
|
this.handle_file_xfer_status(new VDAgentFileXferStatusMessage(agent_data.data));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceMainConn.prototype.stop = function(msg)
|
||||||
|
{
|
||||||
|
this.state = "closing";
|
||||||
|
|
||||||
|
if (this.inputs)
|
||||||
|
{
|
||||||
|
this.inputs.cleanup();
|
||||||
|
this.inputs = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.cursor)
|
||||||
|
{
|
||||||
|
this.cursor.cleanup();
|
||||||
|
this.cursor = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.display)
|
||||||
|
{
|
||||||
|
this.display.cleanup();
|
||||||
|
this.display.destroy_surfaces();
|
||||||
|
this.display = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cleanup();
|
||||||
|
|
||||||
|
if ("extra_channels" in this)
|
||||||
|
for (var e in this.extra_channels)
|
||||||
|
this.extra_channels[e].cleanup();
|
||||||
|
this.extra_channels = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceMainConn.prototype.send_agent_message_queue = function(message)
|
||||||
|
{
|
||||||
|
if (!this.agent_connected)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (message)
|
||||||
|
this.agent_msg_queue.push(message);
|
||||||
|
|
||||||
|
while (this.agent_tokens > 0 && this.agent_msg_queue.length > 0)
|
||||||
|
{
|
||||||
|
var mr = this.agent_msg_queue.shift();
|
||||||
|
this.send_msg(mr);
|
||||||
|
this.agent_tokens--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceMainConn.prototype.send_agent_message = function(type, message)
|
||||||
|
{
|
||||||
|
var agent_data = new SpiceMsgcMainAgentData(type, message);
|
||||||
|
var sb = 0, maxsize = VD_AGENT_MAX_DATA_SIZE - SpiceMiniData.prototype.buffer_size();
|
||||||
|
var data = new ArrayBuffer(agent_data.buffer_size());
|
||||||
|
agent_data.to_buffer(data);
|
||||||
|
while (sb < agent_data.buffer_size())
|
||||||
|
{
|
||||||
|
var eb = Math.min(sb + maxsize, agent_data.buffer_size());
|
||||||
|
var mr = new SpiceMiniData();
|
||||||
|
mr.type = SPICE_MSGC_MAIN_AGENT_DATA;
|
||||||
|
mr.size = eb - sb;
|
||||||
|
mr.data = data.slice(sb, eb);
|
||||||
|
this.send_agent_message_queue(mr);
|
||||||
|
sb = eb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceMainConn.prototype.announce_agent_capabilities = function(request)
|
||||||
|
{
|
||||||
|
var caps = new VDAgentAnnounceCapabilities(request, (1 << VD_AGENT_CAP_MOUSE_STATE) |
|
||||||
|
(1 << VD_AGENT_CAP_MONITORS_CONFIG) |
|
||||||
|
(1 << VD_AGENT_CAP_REPLY));
|
||||||
|
this.send_agent_message(VD_AGENT_ANNOUNCE_CAPABILITIES, caps);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceMainConn.prototype.resize_window = function(flags, width, height, depth, x, y)
|
||||||
|
{
|
||||||
|
var monitors_config = new VDAgentMonitorsConfig(flags, width, height, depth, x, y);
|
||||||
|
this.send_agent_message(VD_AGENT_MONITORS_CONFIG, monitors_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceMainConn.prototype.file_xfer_start = function(file)
|
||||||
|
{
|
||||||
|
var task_id, xfer_start, task;
|
||||||
|
|
||||||
|
task_id = this.file_xfer_task_id++;
|
||||||
|
task = new SpiceFileXferTask(task_id, file);
|
||||||
|
task.create_progressbar();
|
||||||
|
this.file_xfer_tasks[task_id] = task;
|
||||||
|
xfer_start = new VDAgentFileXferStartMessage(task_id, file.name, file.size);
|
||||||
|
this.send_agent_message(VD_AGENT_FILE_XFER_START, xfer_start);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceMainConn.prototype.handle_file_xfer_status = function(file_xfer_status)
|
||||||
|
{
|
||||||
|
var xfer_error, xfer_task;
|
||||||
|
if (!this.file_xfer_tasks[file_xfer_status.id])
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xfer_task = this.file_xfer_tasks[file_xfer_status.id];
|
||||||
|
switch (file_xfer_status.result)
|
||||||
|
{
|
||||||
|
case VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA:
|
||||||
|
this.file_xfer_read(xfer_task);
|
||||||
|
return;
|
||||||
|
case VD_AGENT_FILE_XFER_STATUS_CANCELLED:
|
||||||
|
xfer_error = "transfer is cancelled by spice agent";
|
||||||
|
break;
|
||||||
|
case VD_AGENT_FILE_XFER_STATUS_ERROR:
|
||||||
|
xfer_error = "some errors occurred in the spice agent";
|
||||||
|
break;
|
||||||
|
case VD_AGENT_FILE_XFER_STATUS_SUCCESS:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
xfer_error = "unhandled status type: " + file_xfer_status.result;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.file_xfer_completed(xfer_task, xfer_error)
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceMainConn.prototype.file_xfer_read = function(file_xfer_task, start_byte)
|
||||||
|
{
|
||||||
|
var FILE_XFER_CHUNK_SIZE = 32 * VD_AGENT_MAX_DATA_SIZE;
|
||||||
|
var _this = this;
|
||||||
|
var sb, eb;
|
||||||
|
var slice, reader;
|
||||||
|
|
||||||
|
if (!file_xfer_task ||
|
||||||
|
!this.file_xfer_tasks[file_xfer_task.id] ||
|
||||||
|
(start_byte > 0 && start_byte == file_xfer_task.file.size))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_xfer_task.cancelled)
|
||||||
|
{
|
||||||
|
var xfer_status = new VDAgentFileXferStatusMessage(file_xfer_task.id,
|
||||||
|
VD_AGENT_FILE_XFER_STATUS_CANCELLED);
|
||||||
|
this.send_agent_message(VD_AGENT_FILE_XFER_STATUS, xfer_status);
|
||||||
|
delete this.file_xfer_tasks[file_xfer_task.id];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sb = start_byte || 0,
|
||||||
|
eb = Math.min(sb + FILE_XFER_CHUNK_SIZE, file_xfer_task.file.size);
|
||||||
|
|
||||||
|
if (!this.agent_tokens)
|
||||||
|
{
|
||||||
|
file_xfer_task.read_bytes = sb;
|
||||||
|
this.file_xfer_read_queue.push(file_xfer_task);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
reader = new FileReader();
|
||||||
|
reader.onload = function(e)
|
||||||
|
{
|
||||||
|
var xfer_data = new VDAgentFileXferDataMessage(file_xfer_task.id,
|
||||||
|
e.target.result.byteLength,
|
||||||
|
e.target.result);
|
||||||
|
_this.send_agent_message(VD_AGENT_FILE_XFER_DATA, xfer_data);
|
||||||
|
_this.file_xfer_read(file_xfer_task, eb);
|
||||||
|
file_xfer_task.update_progressbar(eb);
|
||||||
|
};
|
||||||
|
|
||||||
|
slice = file_xfer_task.file.slice(sb, eb);
|
||||||
|
reader.readAsArrayBuffer(slice);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceMainConn.prototype.file_xfer_completed = function(file_xfer_task, error)
|
||||||
|
{
|
||||||
|
if (error)
|
||||||
|
this.log_err(error);
|
||||||
|
else
|
||||||
|
this.log_info("transfer of '" + file_xfer_task.file.name +"' was successful");
|
||||||
|
|
||||||
|
file_xfer_task.remove_progressbar();
|
||||||
|
|
||||||
|
delete this.file_xfer_tasks[file_xfer_task.id];
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceMainConn.prototype.connect_agent = function()
|
||||||
|
{
|
||||||
|
this.agent_connected = true;
|
||||||
|
|
||||||
|
var agent_start = new SpiceMsgcMainAgentStart(~0);
|
||||||
|
var mr = new SpiceMiniData();
|
||||||
|
mr.build_msg(SPICE_MSGC_MAIN_AGENT_START, agent_start);
|
||||||
|
this.send_msg(mr);
|
||||||
|
|
||||||
|
this.announce_agent_capabilities(1);
|
||||||
|
|
||||||
|
if (this.onagent !== undefined)
|
||||||
|
this.onagent(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceMainConn.prototype.handle_mouse_mode = function(current, supported)
|
||||||
|
{
|
||||||
|
this.mouse_mode = current;
|
||||||
|
if (current != SPICE_MOUSE_MODE_CLIENT && (supported & SPICE_MOUSE_MODE_CLIENT))
|
||||||
|
{
|
||||||
|
var mode_request = new SpiceMsgcMainMouseModeRequest(SPICE_MOUSE_MODE_CLIENT);
|
||||||
|
var mr = new SpiceMiniData();
|
||||||
|
mr.build_msg(SPICE_MSGC_MAIN_MOUSE_MODE_REQUEST, mode_request);
|
||||||
|
this.send_msg(mr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.inputs)
|
||||||
|
this.inputs.mouse_mode = current;
|
||||||
|
}
|
||||||
|
|
278
static/js/spice-html5/playback.js
Normal file
278
static/js/spice-html5/playback.js
Normal file
|
@ -0,0 +1,278 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2014 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** SpicePlaybackConn
|
||||||
|
** Drive the Spice Playback channel (sound out)
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function SpicePlaybackConn()
|
||||||
|
{
|
||||||
|
SpiceConn.apply(this, arguments);
|
||||||
|
|
||||||
|
this.queue = new Array();
|
||||||
|
this.append_okay = false;
|
||||||
|
this.start_time = 0;
|
||||||
|
this.skip_until = 0;
|
||||||
|
this.gap_time = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpicePlaybackConn.prototype = Object.create(SpiceConn.prototype);
|
||||||
|
SpicePlaybackConn.prototype.process_channel_message = function(msg)
|
||||||
|
{
|
||||||
|
if (!!!window.MediaSource)
|
||||||
|
{
|
||||||
|
this.log_err('MediaSource API is not available');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_PLAYBACK_START)
|
||||||
|
{
|
||||||
|
var start = new SpiceMsgPlaybackStart(msg.data);
|
||||||
|
|
||||||
|
DEBUG > 0 && console.log("PlaybackStart; frequency " + start.frequency);
|
||||||
|
|
||||||
|
if (start.frequency != OPUS_FREQUENCY)
|
||||||
|
{
|
||||||
|
this.log_err('This player cannot handle frequency ' + start.frequency);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start.channels != OPUS_CHANNELS)
|
||||||
|
{
|
||||||
|
this.log_err('This player cannot handle ' + start.channels + ' channels');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start.format != SPICE_AUDIO_FMT_S16)
|
||||||
|
{
|
||||||
|
this.log_err('This player cannot format ' + start.format);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! this.source_buffer)
|
||||||
|
{
|
||||||
|
this.media_source = new MediaSource();
|
||||||
|
this.media_source.spiceconn = this;
|
||||||
|
|
||||||
|
this.audio = document.createElement("audio");
|
||||||
|
this.audio.setAttribute('autoplay', true);
|
||||||
|
this.audio.src = window.URL.createObjectURL(this.media_source);
|
||||||
|
document.getElementById(this.parent.screen_id).appendChild(this.audio);
|
||||||
|
|
||||||
|
this.media_source.addEventListener('sourceopen', handle_source_open, false);
|
||||||
|
this.media_source.addEventListener('sourceended', handle_source_ended, false);
|
||||||
|
this.media_source.addEventListener('sourceclosed', handle_source_closed, false);
|
||||||
|
|
||||||
|
this.bytes_written = 0;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_PLAYBACK_DATA)
|
||||||
|
{
|
||||||
|
var data = new SpiceMsgPlaybackData(msg.data);
|
||||||
|
|
||||||
|
// If this packet has the same time as the last, just bump up by one.
|
||||||
|
if (this.last_data_time && data.time <= this.last_data_time)
|
||||||
|
{
|
||||||
|
// FIXME - this is arguably wrong. But delaying the transmission was worse,
|
||||||
|
// in initial testing. Could use more research.
|
||||||
|
DEBUG > 1 && console.log("Hacking time of " + data.time + " to " + this.last_data_time + 1);
|
||||||
|
data.time = this.last_data_time + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Gap detection: If there has been a delay since our last packet, then audio must
|
||||||
|
have paused. Handling that gets tricky. In Chrome, you can seek forward,
|
||||||
|
but you cannot in Firefox. And seeking forward in Chrome is nice, as it keeps
|
||||||
|
Chrome from being overly cautious in it's buffer strategy.
|
||||||
|
|
||||||
|
So we do two things. First, we seek forward. Second, we compute how much of a gap
|
||||||
|
there would have been, and essentially eliminate it.
|
||||||
|
*/
|
||||||
|
if (this.last_data_time && data.time >= (this.last_data_time + GAP_DETECTION_THRESHOLD))
|
||||||
|
{
|
||||||
|
this.skip_until = data.time;
|
||||||
|
this.gap_time = (data.time - this.start_time) -
|
||||||
|
(this.source_buffer.buffered.end(this.source_buffer.buffered.end.length - 1) * 1000.0).toFixed(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.last_data_time = data.time;
|
||||||
|
|
||||||
|
|
||||||
|
DEBUG > 1 && console.log("PlaybackData; time " + data.time + "; length " + data.data.byteLength);
|
||||||
|
|
||||||
|
if (! this.source_buffer)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (this.start_time == 0)
|
||||||
|
this.start_playback(data);
|
||||||
|
|
||||||
|
else if (data.time - this.cluster_time >= MAX_CLUSTER_TIME || this.skip_until > 0)
|
||||||
|
this.new_cluster(data);
|
||||||
|
|
||||||
|
else
|
||||||
|
this.simple_block(data, false);
|
||||||
|
|
||||||
|
if (this.skip_until > 0)
|
||||||
|
{
|
||||||
|
this.audio.currentTime = (this.skip_until - this.start_time - this.gap_time) / 1000.0;
|
||||||
|
this.skip_until = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.audio.paused)
|
||||||
|
this.audio.play();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_PLAYBACK_MODE)
|
||||||
|
{
|
||||||
|
var mode = new SpiceMsgPlaybackMode(msg.data);
|
||||||
|
if (mode.mode != SPICE_AUDIO_DATA_MODE_OPUS)
|
||||||
|
{
|
||||||
|
this.log_err('This player cannot handle mode ' + mode.mode);
|
||||||
|
delete this.source_buffer;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_PLAYBACK_STOP)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SpicePlaybackConn.prototype.start_playback = function(data)
|
||||||
|
{
|
||||||
|
this.start_time = data.time;
|
||||||
|
|
||||||
|
var h = new webm_Header();
|
||||||
|
|
||||||
|
var mb = new ArrayBuffer(h.buffer_size())
|
||||||
|
|
||||||
|
this.bytes_written = h.to_buffer(mb);
|
||||||
|
|
||||||
|
this.source_buffer.addEventListener('error', handle_sourcebuffer_error, false);
|
||||||
|
this.source_buffer.addEventListener('updateend', handle_append_buffer_done, false);
|
||||||
|
playback_append_buffer(this, mb);
|
||||||
|
|
||||||
|
this.new_cluster(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpicePlaybackConn.prototype.new_cluster = function(data)
|
||||||
|
{
|
||||||
|
this.cluster_time = data.time;
|
||||||
|
|
||||||
|
var c = new webm_Cluster(data.time - this.start_time - this.gap_time);
|
||||||
|
|
||||||
|
var mb = new ArrayBuffer(c.buffer_size());
|
||||||
|
this.bytes_written += c.to_buffer(mb);
|
||||||
|
|
||||||
|
if (this.append_okay)
|
||||||
|
playback_append_buffer(this, mb);
|
||||||
|
else
|
||||||
|
this.queue.push(mb);
|
||||||
|
|
||||||
|
this.simple_block(data, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpicePlaybackConn.prototype.simple_block = function(data, keyframe)
|
||||||
|
{
|
||||||
|
var sb = new webm_SimpleBlock(data.time - this.cluster_time, data.data, keyframe);
|
||||||
|
var mb = new ArrayBuffer(sb.buffer_size());
|
||||||
|
|
||||||
|
this.bytes_written += sb.to_buffer(mb);
|
||||||
|
|
||||||
|
if (this.append_okay)
|
||||||
|
playback_append_buffer(this, mb);
|
||||||
|
else
|
||||||
|
this.queue.push(mb);
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_source_open(e)
|
||||||
|
{
|
||||||
|
var p = this.spiceconn;
|
||||||
|
|
||||||
|
if (p.source_buffer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
p.source_buffer = this.addSourceBuffer(SPICE_PLAYBACK_CODEC);
|
||||||
|
if (! p.source_buffer)
|
||||||
|
{
|
||||||
|
p.log_err('Codec ' + SPICE_PLAYBACK_CODEC + ' not available.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
p.source_buffer.spiceconn = p;
|
||||||
|
p.source_buffer.mode = "segments";
|
||||||
|
|
||||||
|
// FIXME - Experimentation with segments and sequences was unsatisfying.
|
||||||
|
// Switching to sequence did not solve our gap problem,
|
||||||
|
// but the browsers didn't fully support the time seek capability
|
||||||
|
// we would expect to gain from 'segments'.
|
||||||
|
// Segments worked at the time of this patch, so segments it is for now.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_source_ended(e)
|
||||||
|
{
|
||||||
|
var p = this.spiceconn;
|
||||||
|
p.log_err('Audio source unexpectedly ended.');
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_source_closed(e)
|
||||||
|
{
|
||||||
|
var p = this.spiceconn;
|
||||||
|
p.log_err('Audio source unexpectedly closed.');
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_append_buffer_done(b)
|
||||||
|
{
|
||||||
|
var p = this.spiceconn;
|
||||||
|
if (p.queue.length > 0)
|
||||||
|
{
|
||||||
|
var mb = p.queue.shift();
|
||||||
|
playback_append_buffer(p, mb);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
p.append_okay = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_sourcebuffer_error(e)
|
||||||
|
{
|
||||||
|
var p = this.spiceconn;
|
||||||
|
p.log_err('source_buffer error ' + e.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
function playback_append_buffer(p, b)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
p.source_buffer.appendBuffer(b);
|
||||||
|
p.append_okay = false;
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
p.log_err("Error invoking appendBuffer: " + e.message);
|
||||||
|
}
|
||||||
|
}
|
256
static/js/spice-html5/png.js
Normal file
256
static/js/spice-html5/png.js
Normal file
|
@ -0,0 +1,256 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** crc logic from rfc2083 ported to Javascript
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
var rfc2083_crc_table = Array(256);
|
||||||
|
var rfc2083_crc_table_computed = 0;
|
||||||
|
/* Make the table for a fast CRC. */
|
||||||
|
function rfc2083_make_crc_table()
|
||||||
|
{
|
||||||
|
var c;
|
||||||
|
var n, k;
|
||||||
|
for (n = 0; n < 256; n++)
|
||||||
|
{
|
||||||
|
c = n;
|
||||||
|
for (k = 0; k < 8; k++)
|
||||||
|
{
|
||||||
|
if (c & 1)
|
||||||
|
c = ((0xedb88320 ^ (c >>> 1)) >>> 0) & 0xffffffff;
|
||||||
|
else
|
||||||
|
c = c >>> 1;
|
||||||
|
}
|
||||||
|
rfc2083_crc_table[n] = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
rfc2083_crc_table_computed = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Update a running CRC with the bytes buf[0..len-1]--the CRC
|
||||||
|
should be initialized to all 1's, and the transmitted value
|
||||||
|
is the 1's complement of the final running CRC (see the
|
||||||
|
crc() routine below)). */
|
||||||
|
|
||||||
|
function rfc2083_update_crc(crc, u8buf, at, len)
|
||||||
|
{
|
||||||
|
var c = crc;
|
||||||
|
var n;
|
||||||
|
|
||||||
|
if (!rfc2083_crc_table_computed)
|
||||||
|
rfc2083_make_crc_table();
|
||||||
|
|
||||||
|
for (n = 0; n < len; n++)
|
||||||
|
{
|
||||||
|
c = rfc2083_crc_table[(c ^ u8buf[at + n]) & 0xff] ^ (c >>> 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rfc2083_crc(u8buf, at, len)
|
||||||
|
{
|
||||||
|
return rfc2083_update_crc(0xffffffff, u8buf, at, len) ^ 0xffffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
function crc32(mb, at, len)
|
||||||
|
{
|
||||||
|
var u8 = new Uint8Array(mb);
|
||||||
|
return rfc2083_crc(u8, at, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
function PngIHDR(width, height)
|
||||||
|
{
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.depth = 8;
|
||||||
|
this.type = 6;
|
||||||
|
this.compression = 0;
|
||||||
|
this.filter = 0;
|
||||||
|
this.interlace = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PngIHDR.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var orig = at;
|
||||||
|
var dv = new SpiceDataView(a);
|
||||||
|
dv.setUint32(at, this.buffer_size() - 12); at += 4;
|
||||||
|
dv.setUint8(at, 'I'.charCodeAt(0)); at++;
|
||||||
|
dv.setUint8(at, 'H'.charCodeAt(0)); at++;
|
||||||
|
dv.setUint8(at, 'D'.charCodeAt(0)); at++;
|
||||||
|
dv.setUint8(at, 'R'.charCodeAt(0)); at++;
|
||||||
|
dv.setUint32(at, this.width); at += 4;
|
||||||
|
dv.setUint32(at, this.height); at += 4;
|
||||||
|
dv.setUint8(at, this.depth); at++;
|
||||||
|
dv.setUint8(at, this.type); at++;
|
||||||
|
dv.setUint8(at, this.compression); at++;
|
||||||
|
dv.setUint8(at, this.filter); at++;
|
||||||
|
dv.setUint8(at, this.interlace); at++;
|
||||||
|
dv.setUint32(at, crc32(a, orig + 4, this.buffer_size() - 8)); at += 4;
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return 12 + 13;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function adler()
|
||||||
|
{
|
||||||
|
this.s1 = 1;
|
||||||
|
this.s2 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
adler.prototype.update = function(b)
|
||||||
|
{
|
||||||
|
this.s1 += b;
|
||||||
|
this.s1 %= 65521;
|
||||||
|
this.s2 += this.s1;
|
||||||
|
this.s2 %= 65521;
|
||||||
|
}
|
||||||
|
|
||||||
|
function PngIDAT(width, height, bytes)
|
||||||
|
{
|
||||||
|
if (bytes.byteLength > 65535)
|
||||||
|
{
|
||||||
|
throw new Error("Cannot handle more than 64K");
|
||||||
|
}
|
||||||
|
this.data = bytes;
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
PngIDAT.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var orig = at;
|
||||||
|
var x, y, i, j;
|
||||||
|
var dv = new SpiceDataView(a);
|
||||||
|
var zsum = new adler();
|
||||||
|
dv.setUint32(at, this.buffer_size() - 12); at += 4;
|
||||||
|
dv.setUint8(at, 'I'.charCodeAt(0)); at++;
|
||||||
|
dv.setUint8(at, 'D'.charCodeAt(0)); at++;
|
||||||
|
dv.setUint8(at, 'A'.charCodeAt(0)); at++;
|
||||||
|
dv.setUint8(at, 'T'.charCodeAt(0)); at++;
|
||||||
|
|
||||||
|
/* zlib header. */
|
||||||
|
dv.setUint8(at, 0x78); at++;
|
||||||
|
dv.setUint8(at, 0x01); at++;
|
||||||
|
|
||||||
|
/* Deflate header. Specifies uncompressed, final bit */
|
||||||
|
dv.setUint8(at, 0x80); at++;
|
||||||
|
dv.setUint16(at, this.data.byteLength + this.height); at += 2;
|
||||||
|
dv.setUint16(at, ~(this.data.byteLength + this.height)); at += 2;
|
||||||
|
var u8 = new Uint8Array(this.data);
|
||||||
|
for (i = 0, y = 0; y < this.height; y++)
|
||||||
|
{
|
||||||
|
/* Filter type 0 - uncompressed */
|
||||||
|
dv.setUint8(at, 0); at++;
|
||||||
|
zsum.update(0);
|
||||||
|
for (x = 0; x < this.width && i < this.data.byteLength; x++)
|
||||||
|
{
|
||||||
|
zsum.update(u8[i]);
|
||||||
|
dv.setUint8(at, u8[i++]); at++;
|
||||||
|
zsum.update(u8[i]);
|
||||||
|
dv.setUint8(at, u8[i++]); at++;
|
||||||
|
zsum.update(u8[i]);
|
||||||
|
dv.setUint8(at, u8[i++]); at++;
|
||||||
|
zsum.update(u8[i]);
|
||||||
|
dv.setUint8(at, u8[i++]); at++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* zlib checksum. */
|
||||||
|
dv.setUint16(at, zsum.s2); at+=2;
|
||||||
|
dv.setUint16(at, zsum.s1); at+=2;
|
||||||
|
|
||||||
|
/* FIXME - something is not quite right with the zlib code;
|
||||||
|
you get an error from libpng if you open the image in
|
||||||
|
gimp. But it works, so it's good enough for now... */
|
||||||
|
|
||||||
|
dv.setUint32(at, crc32(a, orig + 4, this.buffer_size() - 8)); at += 4;
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return 12 + this.data.byteLength + this.height + 4 + 2 + 1 + 2 + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function PngIEND()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PngIEND.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var orig = at;
|
||||||
|
var i;
|
||||||
|
var dv = new SpiceDataView(a);
|
||||||
|
dv.setUint32(at, this.buffer_size() - 12); at += 4;
|
||||||
|
dv.setUint8(at, 'I'.charCodeAt(0)); at++;
|
||||||
|
dv.setUint8(at, 'E'.charCodeAt(0)); at++;
|
||||||
|
dv.setUint8(at, 'N'.charCodeAt(0)); at++;
|
||||||
|
dv.setUint8(at, 'D'.charCodeAt(0)); at++;
|
||||||
|
dv.setUint32(at, crc32(a, orig + 4, this.buffer_size() - 8)); at += 4;
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return 12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function create_rgba_png(width, height, bytes)
|
||||||
|
{
|
||||||
|
var i;
|
||||||
|
var ihdr = new PngIHDR(width, height);
|
||||||
|
var idat = new PngIDAT(width, height, bytes);
|
||||||
|
var iend = new PngIEND;
|
||||||
|
|
||||||
|
var mb = new ArrayBuffer(ihdr.buffer_size() + idat.buffer_size() + iend.buffer_size());
|
||||||
|
var at = ihdr.to_buffer(mb);
|
||||||
|
at = idat.to_buffer(mb, at);
|
||||||
|
at = iend.to_buffer(mb, at);
|
||||||
|
|
||||||
|
var u8 = new Uint8Array(mb);
|
||||||
|
var str = "";
|
||||||
|
for (i = 0; i < at; i++)
|
||||||
|
{
|
||||||
|
str += "%";
|
||||||
|
if (u8[i] < 16)
|
||||||
|
str += "0";
|
||||||
|
str += u8[i].toString(16);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return "%89PNG%0D%0A%1A%0A" + str;
|
||||||
|
}
|
79
static/js/spice-html5/prng4.js
Normal file
79
static/js/spice-html5/prng4.js
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
// Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2003-2005 Tom Wu
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||||
|
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||||
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||||
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||||
|
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||||
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* In addition, the following condition applies:
|
||||||
|
*
|
||||||
|
* All redistributions must retain an intact copy of this copyright notice
|
||||||
|
* and disclaimer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// prng4.js - uses Arcfour as a PRNG
|
||||||
|
|
||||||
|
function Arcfour() {
|
||||||
|
this.i = 0;
|
||||||
|
this.j = 0;
|
||||||
|
this.S = new Array();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize arcfour context from key, an array of ints, each from [0..255]
|
||||||
|
function ARC4init(key) {
|
||||||
|
var i, j, t;
|
||||||
|
for(i = 0; i < 256; ++i)
|
||||||
|
this.S[i] = i;
|
||||||
|
j = 0;
|
||||||
|
for(i = 0; i < 256; ++i) {
|
||||||
|
j = (j + this.S[i] + key[i % key.length]) & 255;
|
||||||
|
t = this.S[i];
|
||||||
|
this.S[i] = this.S[j];
|
||||||
|
this.S[j] = t;
|
||||||
|
}
|
||||||
|
this.i = 0;
|
||||||
|
this.j = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ARC4next() {
|
||||||
|
var t;
|
||||||
|
this.i = (this.i + 1) & 255;
|
||||||
|
this.j = (this.j + this.S[this.i]) & 255;
|
||||||
|
t = this.S[this.i];
|
||||||
|
this.S[this.i] = this.S[this.j];
|
||||||
|
this.S[this.j] = t;
|
||||||
|
return this.S[(t + this.S[this.i]) & 255];
|
||||||
|
}
|
||||||
|
|
||||||
|
Arcfour.prototype.init = ARC4init;
|
||||||
|
Arcfour.prototype.next = ARC4next;
|
||||||
|
|
||||||
|
// Plug in your RNG constructor here
|
||||||
|
function prng_newstate() {
|
||||||
|
return new Arcfour();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pool size must be a multiple of 4 and greater than 32.
|
||||||
|
// An array of bytes the size of the pool will be passed to init()
|
||||||
|
var rng_psize = 256;
|
1335
static/js/spice-html5/quic.js
Normal file
1335
static/js/spice-html5/quic.js
Normal file
File diff suppressed because it is too large
Load diff
70
static/js/spice-html5/resize.js
Normal file
70
static/js/spice-html5/resize.js
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2014 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** resize.js
|
||||||
|
** This bit of Javascript is a set of logic to help with window
|
||||||
|
** resizing, using the agent channel to request screen resizes.
|
||||||
|
**
|
||||||
|
** It's a bit tricky, as we want to wait for resizing to settle down
|
||||||
|
** before sending a size. Further, while horizontal resizing to use the whole
|
||||||
|
** browser width is fairly easy to arrange with css, resizing an element to use
|
||||||
|
** the whole vertical space (or to force a middle div to consume the bulk of the browser
|
||||||
|
** window size) is tricky, and the consensus seems to be that Javascript is
|
||||||
|
** the only right way to do it.
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function resize_helper(sc)
|
||||||
|
{
|
||||||
|
var w = document.getElementById(sc.screen_id).clientWidth;
|
||||||
|
var h = document.getElementById(sc.screen_id).clientHeight;
|
||||||
|
|
||||||
|
var m = document.getElementById(sc.message_id);
|
||||||
|
|
||||||
|
/* Resize vertically; basically we leave a 20 pixel margin
|
||||||
|
at the bottom, and use the position of the message window
|
||||||
|
to figure out how to resize */
|
||||||
|
var hd = window.innerHeight - m.offsetHeight - m.offsetTop - 20;
|
||||||
|
|
||||||
|
/* Xorg requires height be a multiple of 8; round up */
|
||||||
|
h = h + hd;
|
||||||
|
if (h % 8 > 0)
|
||||||
|
h += (8 - (h % 8));
|
||||||
|
|
||||||
|
/* Xorg requires width be a multiple of 8; round up */
|
||||||
|
if (w % 8 > 0)
|
||||||
|
w += (8 - (w % 8));
|
||||||
|
|
||||||
|
|
||||||
|
sc.resize_window(0, w, h, 32, 0, 0);
|
||||||
|
sc.spice_resize_timer = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_resize(e)
|
||||||
|
{
|
||||||
|
var sc = window.spice_connection;
|
||||||
|
|
||||||
|
if (sc && sc.spice_resize_timer)
|
||||||
|
{
|
||||||
|
window.clearTimeout(sc.spice_resize_timer);
|
||||||
|
sc.spice_resize_timer = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
sc.spice_resize_timer = window.setTimeout(resize_helper, 200, sc);
|
||||||
|
}
|
102
static/js/spice-html5/rng.js
Normal file
102
static/js/spice-html5/rng.js
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
// Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2003-2005 Tom Wu
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||||
|
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||||
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||||
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||||
|
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||||
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* In addition, the following condition applies:
|
||||||
|
*
|
||||||
|
* All redistributions must retain an intact copy of this copyright notice
|
||||||
|
* and disclaimer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// Random number generator - requires a PRNG backend, e.g. prng4.js
|
||||||
|
|
||||||
|
// For best results, put code like
|
||||||
|
// <body onClick='rng_seed_time();' onKeyPress='rng_seed_time();'>
|
||||||
|
// in your main HTML document.
|
||||||
|
|
||||||
|
var rng_state;
|
||||||
|
var rng_pool;
|
||||||
|
var rng_pptr;
|
||||||
|
|
||||||
|
// Mix in a 32-bit integer into the pool
|
||||||
|
function rng_seed_int(x) {
|
||||||
|
rng_pool[rng_pptr++] ^= x & 255;
|
||||||
|
rng_pool[rng_pptr++] ^= (x >> 8) & 255;
|
||||||
|
rng_pool[rng_pptr++] ^= (x >> 16) & 255;
|
||||||
|
rng_pool[rng_pptr++] ^= (x >> 24) & 255;
|
||||||
|
if(rng_pptr >= rng_psize) rng_pptr -= rng_psize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mix in the current time (w/milliseconds) into the pool
|
||||||
|
function rng_seed_time() {
|
||||||
|
rng_seed_int(new Date().getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the pool with junk if needed.
|
||||||
|
if(rng_pool == null) {
|
||||||
|
rng_pool = new Array();
|
||||||
|
rng_pptr = 0;
|
||||||
|
var t;
|
||||||
|
if(navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto) {
|
||||||
|
// Extract entropy (256 bits) from NS4 RNG if available
|
||||||
|
var z = window.crypto.random(32);
|
||||||
|
for(t = 0; t < z.length; ++t)
|
||||||
|
rng_pool[rng_pptr++] = z.charCodeAt(t) & 255;
|
||||||
|
}
|
||||||
|
while(rng_pptr < rng_psize) { // extract some randomness from Math.random()
|
||||||
|
t = Math.floor(65536 * Math.random());
|
||||||
|
rng_pool[rng_pptr++] = t >>> 8;
|
||||||
|
rng_pool[rng_pptr++] = t & 255;
|
||||||
|
}
|
||||||
|
rng_pptr = 0;
|
||||||
|
rng_seed_time();
|
||||||
|
//rng_seed_int(window.screenX);
|
||||||
|
//rng_seed_int(window.screenY);
|
||||||
|
}
|
||||||
|
|
||||||
|
function rng_get_byte() {
|
||||||
|
if(rng_state == null) {
|
||||||
|
rng_seed_time();
|
||||||
|
rng_state = prng_newstate();
|
||||||
|
rng_state.init(rng_pool);
|
||||||
|
for(rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)
|
||||||
|
rng_pool[rng_pptr] = 0;
|
||||||
|
rng_pptr = 0;
|
||||||
|
//rng_pool = null;
|
||||||
|
}
|
||||||
|
// TODO: allow reseeding after first request
|
||||||
|
return rng_state.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
function rng_get_bytes(ba) {
|
||||||
|
var i;
|
||||||
|
for(i = 0; i < ba.length; ++i) ba[i] = rng_get_byte();
|
||||||
|
}
|
||||||
|
|
||||||
|
function SecureRandom() {}
|
||||||
|
|
||||||
|
SecureRandom.prototype.nextBytes = rng_get_bytes;
|
146
static/js/spice-html5/rsa.js
Normal file
146
static/js/spice-html5/rsa.js
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
// Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2003-2005 Tom Wu
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||||
|
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||||
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||||
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||||
|
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||||
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* In addition, the following condition applies:
|
||||||
|
*
|
||||||
|
* All redistributions must retain an intact copy of this copyright notice
|
||||||
|
* and disclaimer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// Depends on jsbn.js and rng.js
|
||||||
|
|
||||||
|
// Version 1.1: support utf-8 encoding in pkcs1pad2
|
||||||
|
|
||||||
|
// convert a (hex) string to a bignum object
|
||||||
|
function parseBigInt(str,r) {
|
||||||
|
return new BigInteger(str,r);
|
||||||
|
}
|
||||||
|
|
||||||
|
function linebrk(s,n) {
|
||||||
|
var ret = "";
|
||||||
|
var i = 0;
|
||||||
|
while(i + n < s.length) {
|
||||||
|
ret += s.substring(i,i+n) + "\n";
|
||||||
|
i += n;
|
||||||
|
}
|
||||||
|
return ret + s.substring(i,s.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
function byte2Hex(b) {
|
||||||
|
if(b < 0x10)
|
||||||
|
return "0" + b.toString(16);
|
||||||
|
else
|
||||||
|
return b.toString(16);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint
|
||||||
|
function pkcs1pad2(s,n) {
|
||||||
|
if(n < s.length + 11) { // TODO: fix for utf-8
|
||||||
|
alert("Message too long for RSA");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var ba = new Array();
|
||||||
|
var i = s.length - 1;
|
||||||
|
while(i >= 0 && n > 0) {
|
||||||
|
var c = s.charCodeAt(i--);
|
||||||
|
if(c < 128) { // encode using utf-8
|
||||||
|
ba[--n] = c;
|
||||||
|
}
|
||||||
|
else if((c > 127) && (c < 2048)) {
|
||||||
|
ba[--n] = (c & 63) | 128;
|
||||||
|
ba[--n] = (c >> 6) | 192;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ba[--n] = (c & 63) | 128;
|
||||||
|
ba[--n] = ((c >> 6) & 63) | 128;
|
||||||
|
ba[--n] = (c >> 12) | 224;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ba[--n] = 0;
|
||||||
|
var rng = new SecureRandom();
|
||||||
|
var x = new Array();
|
||||||
|
while(n > 2) { // random non-zero pad
|
||||||
|
x[0] = 0;
|
||||||
|
while(x[0] == 0) rng.nextBytes(x);
|
||||||
|
ba[--n] = x[0];
|
||||||
|
}
|
||||||
|
ba[--n] = 2;
|
||||||
|
ba[--n] = 0;
|
||||||
|
return new BigInteger(ba);
|
||||||
|
}
|
||||||
|
|
||||||
|
// "empty" RSA key constructor
|
||||||
|
function RSAKey() {
|
||||||
|
this.n = null;
|
||||||
|
this.e = 0;
|
||||||
|
this.d = null;
|
||||||
|
this.p = null;
|
||||||
|
this.q = null;
|
||||||
|
this.dmp1 = null;
|
||||||
|
this.dmq1 = null;
|
||||||
|
this.coeff = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the public key fields N and e from hex strings
|
||||||
|
function RSASetPublic(N,E) {
|
||||||
|
if(N != null && E != null && N.length > 0 && E.length > 0) {
|
||||||
|
this.n = parseBigInt(N,16);
|
||||||
|
this.e = parseInt(E,16);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
alert("Invalid RSA public key");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform raw public operation on "x": return x^e (mod n)
|
||||||
|
function RSADoPublic(x) {
|
||||||
|
return x.modPowInt(this.e, this.n);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the PKCS#1 RSA encryption of "text" as an even-length hex string
|
||||||
|
function RSAEncrypt(text) {
|
||||||
|
var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3);
|
||||||
|
if(m == null) return null;
|
||||||
|
var c = this.doPublic(m);
|
||||||
|
if(c == null) return null;
|
||||||
|
var h = c.toString(16);
|
||||||
|
if((h.length & 1) == 0) return h; else return "0" + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the PKCS#1 RSA encryption of "text" as a Base64-encoded string
|
||||||
|
//function RSAEncryptB64(text) {
|
||||||
|
// var h = this.encrypt(text);
|
||||||
|
// if(h) return hex2b64(h); else return null;
|
||||||
|
//}
|
||||||
|
|
||||||
|
// protected
|
||||||
|
RSAKey.prototype.doPublic = RSADoPublic;
|
||||||
|
|
||||||
|
// public
|
||||||
|
RSAKey.prototype.setPublic = RSASetPublic;
|
||||||
|
RSAKey.prototype.encrypt = RSAEncrypt;
|
||||||
|
//RSAKey.prototype.encrypt_b64 = RSAEncryptB64;
|
346
static/js/spice-html5/sha1.js
Normal file
346
static/js/spice-html5/sha1.js
Normal file
|
@ -0,0 +1,346 @@
|
||||||
|
/*
|
||||||
|
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
|
||||||
|
* in FIPS 180-1
|
||||||
|
* Version 2.2 Copyright Paul Johnston 2000 - 2009.
|
||||||
|
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||||
|
* Distributed under the BSD License
|
||||||
|
* See http://pajhome.org.uk/crypt/md5 for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Downloaded 6/1/2012 from the above address by Jeremy White.
|
||||||
|
License reproduce here for completeness:
|
||||||
|
|
||||||
|
Copyright (c) 1998 - 2009, Paul Johnston & Contributors
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Configurable variables. You may need to tweak these to be compatible with
|
||||||
|
* the server-side, but the defaults work in most cases.
|
||||||
|
*/
|
||||||
|
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
|
||||||
|
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These are the functions you'll usually want to call
|
||||||
|
* They take string arguments and return either hex or base-64 encoded strings
|
||||||
|
*/
|
||||||
|
function hex_sha1(s) { return rstr2hex(rstr_sha1(str2rstr_utf8(s))); }
|
||||||
|
function b64_sha1(s) { return rstr2b64(rstr_sha1(str2rstr_utf8(s))); }
|
||||||
|
function any_sha1(s, e) { return rstr2any(rstr_sha1(str2rstr_utf8(s)), e); }
|
||||||
|
function hex_hmac_sha1(k, d)
|
||||||
|
{ return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }
|
||||||
|
function b64_hmac_sha1(k, d)
|
||||||
|
{ return rstr2b64(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }
|
||||||
|
function any_hmac_sha1(k, d, e)
|
||||||
|
{ return rstr2any(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)), e); }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perform a simple self-test to see if the VM is working
|
||||||
|
*/
|
||||||
|
function sha1_vm_test()
|
||||||
|
{
|
||||||
|
return hex_sha1("abc").toLowerCase() == "a9993e364706816aba3e25717850c26c9cd0d89d";
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate the SHA1 of a raw string
|
||||||
|
*/
|
||||||
|
function rstr_sha1(s)
|
||||||
|
{
|
||||||
|
return binb2rstr(binb_sha1(rstr2binb(s), s.length * 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate the HMAC-SHA1 of a key and some data (raw strings)
|
||||||
|
*/
|
||||||
|
function rstr_hmac_sha1(key, data)
|
||||||
|
{
|
||||||
|
var bkey = rstr2binb(key);
|
||||||
|
if(bkey.length > 16) bkey = binb_sha1(bkey, key.length * 8);
|
||||||
|
|
||||||
|
var ipad = Array(16), opad = Array(16);
|
||||||
|
for(var i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
ipad[i] = bkey[i] ^ 0x36363636;
|
||||||
|
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||||
|
}
|
||||||
|
|
||||||
|
var hash = binb_sha1(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
|
||||||
|
return binb2rstr(binb_sha1(opad.concat(hash), 512 + 160));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a raw string to a hex string
|
||||||
|
*/
|
||||||
|
function rstr2hex(input)
|
||||||
|
{
|
||||||
|
try { hexcase } catch(e) { hexcase=0; }
|
||||||
|
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||||
|
var output = "";
|
||||||
|
var x;
|
||||||
|
for(var i = 0; i < input.length; i++)
|
||||||
|
{
|
||||||
|
x = input.charCodeAt(i);
|
||||||
|
output += hex_tab.charAt((x >>> 4) & 0x0F)
|
||||||
|
+ hex_tab.charAt( x & 0x0F);
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a raw string to a base-64 string
|
||||||
|
*/
|
||||||
|
function rstr2b64(input)
|
||||||
|
{
|
||||||
|
try { b64pad } catch(e) { b64pad=''; }
|
||||||
|
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
var output = "";
|
||||||
|
var len = input.length;
|
||||||
|
for(var i = 0; i < len; i += 3)
|
||||||
|
{
|
||||||
|
var triplet = (input.charCodeAt(i) << 16)
|
||||||
|
| (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
|
||||||
|
| (i + 2 < len ? input.charCodeAt(i+2) : 0);
|
||||||
|
for(var j = 0; j < 4; j++)
|
||||||
|
{
|
||||||
|
if(i * 8 + j * 6 > input.length * 8) output += b64pad;
|
||||||
|
else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a raw string to an arbitrary string encoding
|
||||||
|
*/
|
||||||
|
function rstr2any(input, encoding)
|
||||||
|
{
|
||||||
|
var divisor = encoding.length;
|
||||||
|
var remainders = Array();
|
||||||
|
var i, q, x, quotient;
|
||||||
|
|
||||||
|
/* Convert to an array of 16-bit big-endian values, forming the dividend */
|
||||||
|
var dividend = Array(Math.ceil(input.length / 2));
|
||||||
|
for(i = 0; i < dividend.length; i++)
|
||||||
|
{
|
||||||
|
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Repeatedly perform a long division. The binary array forms the dividend,
|
||||||
|
* the length of the encoding is the divisor. Once computed, the quotient
|
||||||
|
* forms the dividend for the next step. We stop when the dividend is zero.
|
||||||
|
* All remainders are stored for later use.
|
||||||
|
*/
|
||||||
|
while(dividend.length > 0)
|
||||||
|
{
|
||||||
|
quotient = Array();
|
||||||
|
x = 0;
|
||||||
|
for(i = 0; i < dividend.length; i++)
|
||||||
|
{
|
||||||
|
x = (x << 16) + dividend[i];
|
||||||
|
q = Math.floor(x / divisor);
|
||||||
|
x -= q * divisor;
|
||||||
|
if(quotient.length > 0 || q > 0)
|
||||||
|
quotient[quotient.length] = q;
|
||||||
|
}
|
||||||
|
remainders[remainders.length] = x;
|
||||||
|
dividend = quotient;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert the remainders to the output string */
|
||||||
|
var output = "";
|
||||||
|
for(i = remainders.length - 1; i >= 0; i--)
|
||||||
|
output += encoding.charAt(remainders[i]);
|
||||||
|
|
||||||
|
/* Append leading zero equivalents */
|
||||||
|
var full_length = Math.ceil(input.length * 8 /
|
||||||
|
(Math.log(encoding.length) / Math.log(2)))
|
||||||
|
for(i = output.length; i < full_length; i++)
|
||||||
|
output = encoding[0] + output;
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Encode a string as utf-8.
|
||||||
|
* For efficiency, this assumes the input is valid utf-16.
|
||||||
|
*/
|
||||||
|
function str2rstr_utf8(input)
|
||||||
|
{
|
||||||
|
var output = "";
|
||||||
|
var i = -1;
|
||||||
|
var x, y;
|
||||||
|
|
||||||
|
while(++i < input.length)
|
||||||
|
{
|
||||||
|
/* Decode utf-16 surrogate pairs */
|
||||||
|
x = input.charCodeAt(i);
|
||||||
|
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
|
||||||
|
if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
|
||||||
|
{
|
||||||
|
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Encode output as utf-8 */
|
||||||
|
if(x <= 0x7F)
|
||||||
|
output += String.fromCharCode(x);
|
||||||
|
else if(x <= 0x7FF)
|
||||||
|
output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
|
||||||
|
0x80 | ( x & 0x3F));
|
||||||
|
else if(x <= 0xFFFF)
|
||||||
|
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
|
||||||
|
0x80 | ((x >>> 6 ) & 0x3F),
|
||||||
|
0x80 | ( x & 0x3F));
|
||||||
|
else if(x <= 0x1FFFFF)
|
||||||
|
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
|
||||||
|
0x80 | ((x >>> 12) & 0x3F),
|
||||||
|
0x80 | ((x >>> 6 ) & 0x3F),
|
||||||
|
0x80 | ( x & 0x3F));
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Encode a string as utf-16
|
||||||
|
*/
|
||||||
|
function str2rstr_utf16le(input)
|
||||||
|
{
|
||||||
|
var output = "";
|
||||||
|
for(var i = 0; i < input.length; i++)
|
||||||
|
output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
|
||||||
|
(input.charCodeAt(i) >>> 8) & 0xFF);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function str2rstr_utf16be(input)
|
||||||
|
{
|
||||||
|
var output = "";
|
||||||
|
for(var i = 0; i < input.length; i++)
|
||||||
|
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
|
||||||
|
input.charCodeAt(i) & 0xFF);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a raw string to an array of big-endian words
|
||||||
|
* Characters >255 have their high-byte silently ignored.
|
||||||
|
*/
|
||||||
|
function rstr2binb(input)
|
||||||
|
{
|
||||||
|
var output = Array(input.length >> 2);
|
||||||
|
for(var i = 0; i < output.length; i++)
|
||||||
|
output[i] = 0;
|
||||||
|
for(var i = 0; i < input.length * 8; i += 8)
|
||||||
|
output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert an array of big-endian words to a string
|
||||||
|
*/
|
||||||
|
function binb2rstr(input)
|
||||||
|
{
|
||||||
|
var output = "";
|
||||||
|
for(var i = 0; i < input.length * 32; i += 8)
|
||||||
|
output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate the SHA-1 of an array of big-endian words, and a bit length
|
||||||
|
*/
|
||||||
|
function binb_sha1(x, len)
|
||||||
|
{
|
||||||
|
/* append padding */
|
||||||
|
x[len >> 5] |= 0x80 << (24 - len % 32);
|
||||||
|
x[((len + 64 >> 9) << 4) + 15] = len;
|
||||||
|
|
||||||
|
var w = Array(80);
|
||||||
|
var a = 1732584193;
|
||||||
|
var b = -271733879;
|
||||||
|
var c = -1732584194;
|
||||||
|
var d = 271733878;
|
||||||
|
var e = -1009589776;
|
||||||
|
|
||||||
|
for(var i = 0; i < x.length; i += 16)
|
||||||
|
{
|
||||||
|
var olda = a;
|
||||||
|
var oldb = b;
|
||||||
|
var oldc = c;
|
||||||
|
var oldd = d;
|
||||||
|
var olde = e;
|
||||||
|
|
||||||
|
for(var j = 0; j < 80; j++)
|
||||||
|
{
|
||||||
|
if(j < 16) w[j] = x[i + j];
|
||||||
|
else w[j] = bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
|
||||||
|
var t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),
|
||||||
|
safe_add(safe_add(e, w[j]), sha1_kt(j)));
|
||||||
|
e = d;
|
||||||
|
d = c;
|
||||||
|
c = bit_rol(b, 30);
|
||||||
|
b = a;
|
||||||
|
a = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
a = safe_add(a, olda);
|
||||||
|
b = safe_add(b, oldb);
|
||||||
|
c = safe_add(c, oldc);
|
||||||
|
d = safe_add(d, oldd);
|
||||||
|
e = safe_add(e, olde);
|
||||||
|
}
|
||||||
|
return Array(a, b, c, d, e);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perform the appropriate triplet combination function for the current
|
||||||
|
* iteration
|
||||||
|
*/
|
||||||
|
function sha1_ft(t, b, c, d)
|
||||||
|
{
|
||||||
|
if(t < 20) return (b & c) | ((~b) & d);
|
||||||
|
if(t < 40) return b ^ c ^ d;
|
||||||
|
if(t < 60) return (b & c) | (b & d) | (c & d);
|
||||||
|
return b ^ c ^ d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Determine the appropriate additive constant for the current iteration
|
||||||
|
*/
|
||||||
|
function sha1_kt(t)
|
||||||
|
{
|
||||||
|
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
|
||||||
|
(t < 60) ? -1894007588 : -899497514;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
||||||
|
* to work around bugs in some JS interpreters.
|
||||||
|
*/
|
||||||
|
function safe_add(x, y)
|
||||||
|
{
|
||||||
|
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
|
||||||
|
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
||||||
|
return (msw << 16) | (lsw & 0xFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bitwise rotate a 32-bit number to the left.
|
||||||
|
*/
|
||||||
|
function bit_rol(num, cnt)
|
||||||
|
{
|
||||||
|
return (num << cnt) | (num >>> (32 - cnt));
|
||||||
|
}
|
202
static/js/spice-html5/simulatecursor.js
Normal file
202
static/js/spice-html5/simulatecursor.js
Normal file
|
@ -0,0 +1,202 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2013 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** SpiceSimulateCursor
|
||||||
|
** Internet Explorer 10 does not support data uri's in cursor assignment.
|
||||||
|
** This file provides a number of gimmicks to compensate. First, if there
|
||||||
|
** is a preloaded cursor available, we will use that. Failing that, we will
|
||||||
|
** simulate a cursor using an image that is moved around the screen.
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
var SpiceSimulateCursor = {
|
||||||
|
|
||||||
|
cursors : new Array(),
|
||||||
|
unknown_cursors : new Array(),
|
||||||
|
warned: false,
|
||||||
|
|
||||||
|
add_cursor: function(sha1, value)
|
||||||
|
{
|
||||||
|
SpiceSimulateCursor.cursors[sha1] = value;
|
||||||
|
},
|
||||||
|
|
||||||
|
unknown_cursor: function(sha1, curdata)
|
||||||
|
{
|
||||||
|
if (! SpiceSimulateCursor.warned)
|
||||||
|
{
|
||||||
|
SpiceSimulateCursor.warned = true;
|
||||||
|
alert("Internet Explorer does not support dynamic cursors. " +
|
||||||
|
"This page will now simulate cursors with images, " +
|
||||||
|
"which will be imperfect. We recommend using Chrome or Firefox instead. " +
|
||||||
|
"\n\nIf you need to use Internet Explorer, you can create a static cursor " +
|
||||||
|
"file for each cursor your application uses. " +
|
||||||
|
"View the console log for more information on creating static cursors for your environment.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! SpiceSimulateCursor.unknown_cursors[sha1])
|
||||||
|
{
|
||||||
|
SpiceSimulateCursor.unknown_cursors[sha1] = curdata;
|
||||||
|
console.log('Unknown cursor. Simulation required. To avoid simulation for this cursor, create and include a custom javascript file, and add the following line:');
|
||||||
|
console.log('SpiceCursorSimulator.add_cursor("' + sha1 + '"), "<your filename here>.cur");');
|
||||||
|
console.log('And then run following command, redirecting output into <your filename here>.cur:');
|
||||||
|
console.log('php -r "echo urldecode(\'' + curdata + '\');"');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
simulate_cursor: function (spicecursor, cursor, screen, pngstr)
|
||||||
|
{
|
||||||
|
var cursor_sha = hex_sha1(pngstr + ' ' + cursor.header.hot_spot_x + ' ' + cursor.header.hot_spot_y);
|
||||||
|
if (typeof SpiceSimulateCursor.cursors != 'undefined')
|
||||||
|
if (typeof SpiceSimulateCursor.cursors[cursor_sha] != 'undefined')
|
||||||
|
{
|
||||||
|
var curstr = 'url(' + SpiceSimulateCursor.cursors[cursor_sha] + '), default';
|
||||||
|
screen.style.cursor = curstr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.getComputedStyle(screen, null).cursor == 'auto')
|
||||||
|
{
|
||||||
|
SpiceSimulateCursor.unknown_cursor(cursor_sha,
|
||||||
|
SpiceSimulateCursor.create_icondir(cursor.header.width, cursor.header.height,
|
||||||
|
cursor.data.byteLength, cursor.header.hot_spot_x, cursor.header.hot_spot_y) + pngstr);
|
||||||
|
|
||||||
|
document.getElementById(spicecursor.parent.screen_id).style.cursor = 'none';
|
||||||
|
if (! spicecursor.spice_simulated_cursor)
|
||||||
|
{
|
||||||
|
spicecursor.spice_simulated_cursor = document.createElement('img');
|
||||||
|
|
||||||
|
spicecursor.spice_simulated_cursor.style.position = 'absolute';
|
||||||
|
spicecursor.spice_simulated_cursor.style.display = 'none';
|
||||||
|
spicecursor.spice_simulated_cursor.style.overflow = 'hidden';
|
||||||
|
|
||||||
|
spicecursor.spice_simulated_cursor.spice_screen = document.getElementById(spicecursor.parent.screen_id);
|
||||||
|
|
||||||
|
spicecursor.spice_simulated_cursor.addEventListener('mousemove', SpiceSimulateCursor.handle_sim_mousemove);
|
||||||
|
|
||||||
|
spicecursor.spice_simulated_cursor.spice_screen.appendChild(spicecursor.spice_simulated_cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
spicecursor.spice_simulated_cursor.src = 'data:image/png,' + pngstr;
|
||||||
|
|
||||||
|
spicecursor.spice_simulated_cursor.spice_hot_x = cursor.header.hot_spot_x;
|
||||||
|
spicecursor.spice_simulated_cursor.spice_hot_y = cursor.header.hot_spot_y;
|
||||||
|
|
||||||
|
spicecursor.spice_simulated_cursor.style.pointerEvents = "none";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (spicecursor.spice_simulated_cursor)
|
||||||
|
{
|
||||||
|
spicecursor.spice_simulated_cursor.spice_screen.removeChild(spicecursor.spice_simulated_cursor);
|
||||||
|
delete spicecursor.spice_simulated_cursor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
handle_sim_mousemove: function(e)
|
||||||
|
{
|
||||||
|
var retval;
|
||||||
|
var f = SpiceSimulateCursor.duplicate_mouse_event(e, this.spice_screen);
|
||||||
|
return this.spice_screen.dispatchEvent(f);
|
||||||
|
},
|
||||||
|
|
||||||
|
duplicate_mouse_event: function(e, target)
|
||||||
|
{
|
||||||
|
var evt = document.createEvent("mouseevent");
|
||||||
|
evt.initMouseEvent(e.type, true, true, e.view, e.detail,
|
||||||
|
e.screenX, e.screenY, e.clientX, e.clientY,
|
||||||
|
e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget);
|
||||||
|
return evt;
|
||||||
|
},
|
||||||
|
|
||||||
|
ICONDIR: function ()
|
||||||
|
{
|
||||||
|
},
|
||||||
|
|
||||||
|
ICONDIRENTRY: function(width, height, bytes, hot_x, hot_y)
|
||||||
|
{
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
this.bytes = bytes;
|
||||||
|
this.hot_x = hot_x;
|
||||||
|
this.hot_y = hot_y;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
create_icondir: function (width, height, bytes, hot_x, hot_y)
|
||||||
|
{
|
||||||
|
var i;
|
||||||
|
var header = new SpiceSimulateCursor.ICONDIR();
|
||||||
|
var entry = new SpiceSimulateCursor.ICONDIRENTRY(width, height, bytes, hot_x, hot_y);
|
||||||
|
|
||||||
|
var mb = new ArrayBuffer(header.buffer_size() + entry.buffer_size());
|
||||||
|
var at = header.to_buffer(mb);
|
||||||
|
at = entry.to_buffer(mb, at);
|
||||||
|
|
||||||
|
var u8 = new Uint8Array(mb);
|
||||||
|
var str = "";
|
||||||
|
for (i = 0; i < at; i++)
|
||||||
|
{
|
||||||
|
str += "%";
|
||||||
|
if (u8[i] < 16)
|
||||||
|
str += "0";
|
||||||
|
str += u8[i].toString(16);
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
SpiceSimulateCursor.ICONDIR.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var dv = new SpiceDataView(a);
|
||||||
|
dv.setUint16(at, 0, true); at += 2;
|
||||||
|
dv.setUint16(at, 2, true); at += 2;
|
||||||
|
dv.setUint16(at, 1, true); at += 2;
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return 6;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
SpiceSimulateCursor.ICONDIRENTRY.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var dv = new SpiceDataView(a);
|
||||||
|
dv.setUint8(at, this.width); at++;
|
||||||
|
dv.setUint8(at, this.height); at++;
|
||||||
|
dv.setUint8(at, 0); at++; /* color palette count, unused */
|
||||||
|
dv.setUint8(at, 0); at++; /* reserved */
|
||||||
|
dv.setUint16(at, this.hot_x, true); at += 2;
|
||||||
|
dv.setUint16(at, this.hot_y, true); at += 2;
|
||||||
|
dv.setUint32(at, this.bytes, true); at += 4;
|
||||||
|
dv.setUint32(at, at + 4, true); at += 4; /* Offset to bytes */
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
};
|
58
static/js/spice-html5/spicearraybuffer.js
Normal file
58
static/js/spice-html5/spicearraybuffer.js
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** SpiceArrayBufferSlice
|
||||||
|
** This function is a work around for IE 10, which has no slice()
|
||||||
|
** method in it's subclass.
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function SpiceArrayBufferSlice(start, end)
|
||||||
|
{
|
||||||
|
start = start || 0;
|
||||||
|
end = end || this.byteLength;
|
||||||
|
if (end < 0)
|
||||||
|
end = this.byteLength + end;
|
||||||
|
if (start < 0)
|
||||||
|
start = this.byteLength + start;
|
||||||
|
if (start < 0)
|
||||||
|
start = 0;
|
||||||
|
if (end < 0)
|
||||||
|
end = 0;
|
||||||
|
if (end > this.byteLength)
|
||||||
|
end = this.byteLength;
|
||||||
|
if (start > end)
|
||||||
|
start = end;
|
||||||
|
|
||||||
|
var ret = new ArrayBuffer(end - start);
|
||||||
|
var in1 = new Uint8Array(this, start, end - start);
|
||||||
|
var out = new Uint8Array(ret);
|
||||||
|
var i;
|
||||||
|
|
||||||
|
for (i = 0; i < end - start; i++)
|
||||||
|
out[i] = in1[i];
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! ArrayBuffer.prototype.slice)
|
||||||
|
{
|
||||||
|
ArrayBuffer.prototype.slice = SpiceArrayBufferSlice;
|
||||||
|
console.log("WARNING: ArrayBuffer.slice() is missing; we are extending ArrayBuffer to compensate");
|
||||||
|
}
|
466
static/js/spice-html5/spiceconn.js
Normal file
466
static/js/spice-html5/spiceconn.js
Normal file
|
@ -0,0 +1,466 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** SpiceConn
|
||||||
|
** This is the base Javascript class for establishing and
|
||||||
|
** managing a connection to a Spice Server.
|
||||||
|
** It is used to provide core functionality to the Spice main,
|
||||||
|
** display, inputs, and cursor channels. See main.js for
|
||||||
|
** usage.
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function SpiceConn(o)
|
||||||
|
{
|
||||||
|
if (o === undefined || o.uri === undefined || ! o.uri)
|
||||||
|
throw new Error("You must specify a uri");
|
||||||
|
|
||||||
|
this.ws = new WebSocket(o.uri, 'binary');
|
||||||
|
|
||||||
|
if (! this.ws.binaryType)
|
||||||
|
throw new Error("WebSocket doesn't support binaryType. Try a different browser.");
|
||||||
|
|
||||||
|
this.connection_id = o.connection_id !== undefined ? o.connection_id : 0;
|
||||||
|
this.type = o.type !== undefined ? o.type : SPICE_CHANNEL_MAIN;
|
||||||
|
this.chan_id = o.chan_id !== undefined ? o.chan_id : 0;
|
||||||
|
if (o.parent !== undefined)
|
||||||
|
{
|
||||||
|
this.parent = o.parent;
|
||||||
|
this.message_id = o.parent.message_id;
|
||||||
|
this.password = o.parent.password;
|
||||||
|
}
|
||||||
|
if (o.screen_id !== undefined)
|
||||||
|
this.screen_id = o.screen_id;
|
||||||
|
if (o.dump_id !== undefined)
|
||||||
|
this.dump_id = o.dump_id;
|
||||||
|
if (o.message_id !== undefined)
|
||||||
|
this.message_id = o.message_id;
|
||||||
|
if (o.password !== undefined)
|
||||||
|
this.password = o.password;
|
||||||
|
if (o.onerror !== undefined)
|
||||||
|
this.onerror = o.onerror;
|
||||||
|
if (o.onsuccess !== undefined)
|
||||||
|
this.onsuccess = o.onsuccess;
|
||||||
|
if (o.onagent !== undefined)
|
||||||
|
this.onagent = o.onagent;
|
||||||
|
|
||||||
|
this.state = "connecting";
|
||||||
|
this.ws.parent = this;
|
||||||
|
this.wire_reader = new SpiceWireReader(this, this.process_inbound);
|
||||||
|
this.messages_sent = 0;
|
||||||
|
this.warnings = [];
|
||||||
|
|
||||||
|
this.ws.addEventListener('open', function(e) {
|
||||||
|
DEBUG > 0 && console.log(">> WebSockets.onopen");
|
||||||
|
DEBUG > 0 && console.log("id " + this.parent.connection_id +"; type " + this.parent.type);
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
** WHERE IT ALL REALLY BEGINS
|
||||||
|
***********************************************************************/
|
||||||
|
this.parent.send_hdr();
|
||||||
|
this.parent.wire_reader.request(SpiceLinkHeader.prototype.buffer_size());
|
||||||
|
this.parent.state = "start";
|
||||||
|
});
|
||||||
|
this.ws.addEventListener('error', function(e) {
|
||||||
|
if ('url' in e.target) {
|
||||||
|
this.parent.log_err("WebSocket error: Can't connect to websocket on URL: " + e.target.url);
|
||||||
|
}
|
||||||
|
this.parent.report_error(e);
|
||||||
|
});
|
||||||
|
this.ws.addEventListener('close', function(e) {
|
||||||
|
DEBUG > 0 && console.log(">> WebSockets.onclose");
|
||||||
|
DEBUG > 0 && console.log("id " + this.parent.connection_id +"; type " + this.parent.type);
|
||||||
|
DEBUG > 0 && console.log(e);
|
||||||
|
if (this.parent.state != "closing" && this.parent.state != "error" && this.parent.onerror !== undefined)
|
||||||
|
{
|
||||||
|
var e;
|
||||||
|
if (this.parent.state == "connecting")
|
||||||
|
e = new Error("Connection refused.");
|
||||||
|
else if (this.parent.state == "start" || this.parent.state == "link")
|
||||||
|
e = new Error("Unexpected protocol mismatch.");
|
||||||
|
else if (this.parent.state == "ticket")
|
||||||
|
e = new Error("Bad password.");
|
||||||
|
else
|
||||||
|
e = new Error("Unexpected close while " + this.parent.state);
|
||||||
|
|
||||||
|
this.parent.onerror(e);
|
||||||
|
this.parent.log_err(e.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.ws.readyState == 2 || this.ws.readyState == 3)
|
||||||
|
throw new Error("Unable to connect to " + o.uri);
|
||||||
|
|
||||||
|
this.timeout = window.setTimeout(spiceconn_timeout, SPICE_CONNECT_TIMEOUT, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceConn.prototype =
|
||||||
|
{
|
||||||
|
send_hdr : function ()
|
||||||
|
{
|
||||||
|
var hdr = new SpiceLinkHeader;
|
||||||
|
var msg = new SpiceLinkMess;
|
||||||
|
|
||||||
|
msg.connection_id = this.connection_id;
|
||||||
|
msg.channel_type = this.type;
|
||||||
|
// FIXME - we're not setting a channel_id...
|
||||||
|
msg.common_caps.push(
|
||||||
|
(1 << SPICE_COMMON_CAP_PROTOCOL_AUTH_SELECTION) |
|
||||||
|
(1 << SPICE_COMMON_CAP_MINI_HEADER)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (msg.channel_type == SPICE_CHANNEL_PLAYBACK)
|
||||||
|
msg.channel_caps.push(
|
||||||
|
(1 << SPICE_PLAYBACK_CAP_OPUS)
|
||||||
|
);
|
||||||
|
else if (msg.channel_type == SPICE_CHANNEL_MAIN)
|
||||||
|
msg.channel_caps.push(
|
||||||
|
(1 << SPICE_MAIN_CAP_AGENT_CONNECTED_TOKENS)
|
||||||
|
);
|
||||||
|
|
||||||
|
hdr.size = msg.buffer_size();
|
||||||
|
|
||||||
|
var mb = new ArrayBuffer(hdr.buffer_size() + msg.buffer_size());
|
||||||
|
hdr.to_buffer(mb);
|
||||||
|
msg.to_buffer(mb, hdr.buffer_size());
|
||||||
|
|
||||||
|
DEBUG > 1 && console.log("Sending header:");
|
||||||
|
DEBUG > 2 && hexdump_buffer(mb);
|
||||||
|
this.ws.send(mb);
|
||||||
|
},
|
||||||
|
|
||||||
|
send_ticket: function(ticket)
|
||||||
|
{
|
||||||
|
var hdr = new SpiceLinkAuthTicket();
|
||||||
|
hdr.auth_mechanism = SPICE_COMMON_CAP_AUTH_SPICE;
|
||||||
|
// FIXME - we need to implement RSA to make this work right
|
||||||
|
hdr.encrypted_data = ticket;
|
||||||
|
var mb = new ArrayBuffer(hdr.buffer_size());
|
||||||
|
|
||||||
|
hdr.to_buffer(mb);
|
||||||
|
DEBUG > 1 && console.log("Sending ticket:");
|
||||||
|
DEBUG > 2 && hexdump_buffer(mb);
|
||||||
|
this.ws.send(mb);
|
||||||
|
},
|
||||||
|
|
||||||
|
send_msg: function(msg)
|
||||||
|
{
|
||||||
|
var mb = new ArrayBuffer(msg.buffer_size());
|
||||||
|
msg.to_buffer(mb);
|
||||||
|
this.messages_sent++;
|
||||||
|
DEBUG > 0 && console.log(">> hdr " + this.channel_type() + " type " + msg.type + " size " + mb.byteLength);
|
||||||
|
DEBUG > 2 && hexdump_buffer(mb);
|
||||||
|
this.ws.send(mb);
|
||||||
|
},
|
||||||
|
|
||||||
|
process_inbound: function(mb, saved_header)
|
||||||
|
{
|
||||||
|
DEBUG > 2 && console.log(this.type + ": processing message of size " + mb.byteLength + "; state is " + this.state);
|
||||||
|
if (this.state == "ready")
|
||||||
|
{
|
||||||
|
if (saved_header == undefined)
|
||||||
|
{
|
||||||
|
var msg = new SpiceMiniData(mb);
|
||||||
|
|
||||||
|
if (msg.type > 500)
|
||||||
|
{
|
||||||
|
alert("Something has gone very wrong; we think we have message of type " + msg.type);
|
||||||
|
debugger;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.size == 0)
|
||||||
|
{
|
||||||
|
this.process_message(msg);
|
||||||
|
this.wire_reader.request(SpiceMiniData.prototype.buffer_size());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.wire_reader.request(msg.size);
|
||||||
|
this.wire_reader.save_header(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
saved_header.data = mb;
|
||||||
|
this.process_message(saved_header);
|
||||||
|
this.wire_reader.request(SpiceMiniData.prototype.buffer_size());
|
||||||
|
this.wire_reader.save_header(undefined);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (this.state == "start")
|
||||||
|
{
|
||||||
|
this.reply_hdr = new SpiceLinkHeader(mb);
|
||||||
|
if (this.reply_hdr.magic != SPICE_MAGIC)
|
||||||
|
{
|
||||||
|
this.state = "error";
|
||||||
|
var e = new Error('Error: magic mismatch: ' + this.reply_hdr.magic);
|
||||||
|
this.report_error(e);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// FIXME - Determine major/minor version requirements
|
||||||
|
this.wire_reader.request(this.reply_hdr.size);
|
||||||
|
this.state = "link";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (this.state == "link")
|
||||||
|
{
|
||||||
|
this.reply_link = new SpiceLinkReply(mb);
|
||||||
|
// FIXME - Screen the caps - require minihdr at least, right?
|
||||||
|
if (this.reply_link.error)
|
||||||
|
{
|
||||||
|
this.state = "error";
|
||||||
|
var e = new Error('Error: reply link error ' + this.reply_link.error);
|
||||||
|
this.report_error(e);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.send_ticket(rsa_encrypt(this.reply_link.pub_key, this.password + String.fromCharCode(0)));
|
||||||
|
this.state = "ticket";
|
||||||
|
this.wire_reader.request(SpiceLinkAuthReply.prototype.buffer_size());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (this.state == "ticket")
|
||||||
|
{
|
||||||
|
this.auth_reply = new SpiceLinkAuthReply(mb);
|
||||||
|
if (this.auth_reply.auth_code == SPICE_LINK_ERR_OK)
|
||||||
|
{
|
||||||
|
DEBUG > 0 && console.log(this.type + ': Connected');
|
||||||
|
|
||||||
|
if (this.type == SPICE_CHANNEL_DISPLAY)
|
||||||
|
{
|
||||||
|
// FIXME - pixmap and glz dictionary config info?
|
||||||
|
var dinit = new SpiceMsgcDisplayInit();
|
||||||
|
var reply = new SpiceMiniData();
|
||||||
|
reply.build_msg(SPICE_MSGC_DISPLAY_INIT, dinit);
|
||||||
|
DEBUG > 0 && console.log("Request display init");
|
||||||
|
this.send_msg(reply);
|
||||||
|
}
|
||||||
|
this.state = "ready";
|
||||||
|
this.wire_reader.request(SpiceMiniData.prototype.buffer_size());
|
||||||
|
if (this.timeout)
|
||||||
|
{
|
||||||
|
window.clearTimeout(this.timeout);
|
||||||
|
delete this.timeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.state = "error";
|
||||||
|
if (this.auth_reply.auth_code == SPICE_LINK_ERR_PERMISSION_DENIED)
|
||||||
|
{
|
||||||
|
var e = new Error("Permission denied.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var e = new Error("Unexpected link error " + this.auth_reply.auth_code);
|
||||||
|
}
|
||||||
|
this.report_error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
process_common_messages : function(msg)
|
||||||
|
{
|
||||||
|
if (msg.type == SPICE_MSG_SET_ACK)
|
||||||
|
{
|
||||||
|
var ack = new SpiceMsgSetAck(msg.data);
|
||||||
|
// FIXME - what to do with generation?
|
||||||
|
this.ack_window = ack.window;
|
||||||
|
DEBUG > 1 && console.log(this.type + ": set ack to " + ack.window);
|
||||||
|
this.msgs_until_ack = this.ack_window;
|
||||||
|
var ackack = new SpiceMsgcAckSync(ack);
|
||||||
|
var reply = new SpiceMiniData();
|
||||||
|
reply.build_msg(SPICE_MSGC_ACK_SYNC, ackack);
|
||||||
|
this.send_msg(reply);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_PING)
|
||||||
|
{
|
||||||
|
DEBUG > 1 && console.log("ping!");
|
||||||
|
var pong = new SpiceMiniData;
|
||||||
|
pong.type = SPICE_MSGC_PONG;
|
||||||
|
if (msg.data)
|
||||||
|
{
|
||||||
|
pong.data = msg.data.slice(0, 12);
|
||||||
|
}
|
||||||
|
pong.size = pong.buffer_size();
|
||||||
|
this.send_msg(pong);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.type == SPICE_MSG_NOTIFY)
|
||||||
|
{
|
||||||
|
// FIXME - Visibility + what
|
||||||
|
var notify = new SpiceMsgNotify(msg.data);
|
||||||
|
if (notify.severity == SPICE_NOTIFY_SEVERITY_ERROR)
|
||||||
|
this.log_err(notify.message);
|
||||||
|
else if (notify.severity == SPICE_NOTIFY_SEVERITY_WARN )
|
||||||
|
this.log_warn(notify.message);
|
||||||
|
else
|
||||||
|
this.log_info(notify.message);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
process_message: function(msg)
|
||||||
|
{
|
||||||
|
var rc;
|
||||||
|
DEBUG > 0 && console.log("<< hdr " + this.channel_type() + " type " + msg.type + " size " + (msg.data && msg.data.byteLength));
|
||||||
|
rc = this.process_common_messages(msg);
|
||||||
|
if (! rc)
|
||||||
|
{
|
||||||
|
if (this.process_channel_message)
|
||||||
|
{
|
||||||
|
rc = this.process_channel_message(msg);
|
||||||
|
if (! rc)
|
||||||
|
this.log_warn(this.type + ": Unknown message type " + msg.type + "!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this.log_err(this.type + ": No message handlers for this channel; message " + msg.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.msgs_until_ack !== undefined && this.ack_window)
|
||||||
|
{
|
||||||
|
this.msgs_until_ack--;
|
||||||
|
if (this.msgs_until_ack <= 0)
|
||||||
|
{
|
||||||
|
this.msgs_until_ack = this.ack_window;
|
||||||
|
var ack = new SpiceMiniData();
|
||||||
|
ack.type = SPICE_MSGC_ACK;
|
||||||
|
this.send_msg(ack);
|
||||||
|
DEBUG > 1 && console.log(this.type + ": sent ack");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
},
|
||||||
|
|
||||||
|
channel_type: function()
|
||||||
|
{
|
||||||
|
if (this.type == SPICE_CHANNEL_MAIN)
|
||||||
|
return "main";
|
||||||
|
else if (this.type == SPICE_CHANNEL_DISPLAY)
|
||||||
|
return "display";
|
||||||
|
else if (this.type == SPICE_CHANNEL_INPUTS)
|
||||||
|
return "inputs";
|
||||||
|
else if (this.type == SPICE_CHANNEL_CURSOR)
|
||||||
|
return "cursor";
|
||||||
|
return "unknown-" + this.type;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
log_info: function()
|
||||||
|
{
|
||||||
|
var msg = Array.prototype.join.call(arguments, " ");
|
||||||
|
console.log(msg);
|
||||||
|
if (this.message_id)
|
||||||
|
{
|
||||||
|
var p = document.createElement("p");
|
||||||
|
p.appendChild(document.createTextNode(msg));
|
||||||
|
p.className += "spice-message-info";
|
||||||
|
document.getElementById(this.message_id).appendChild(p);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
log_warn: function()
|
||||||
|
{
|
||||||
|
var msg = Array.prototype.join.call(arguments, " ");
|
||||||
|
console.log("WARNING: " + msg);
|
||||||
|
if (this.message_id)
|
||||||
|
{
|
||||||
|
var p = document.createElement("p");
|
||||||
|
p.appendChild(document.createTextNode(msg));
|
||||||
|
p.className += "spice-message-warning";
|
||||||
|
document.getElementById(this.message_id).appendChild(p);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
log_err: function()
|
||||||
|
{
|
||||||
|
var msg = Array.prototype.join.call(arguments, " ");
|
||||||
|
console.log("ERROR: " + msg);
|
||||||
|
if (this.message_id)
|
||||||
|
{
|
||||||
|
var p = document.createElement("p");
|
||||||
|
p.appendChild(document.createTextNode(msg));
|
||||||
|
p.className += "spice-message-error";
|
||||||
|
document.getElementById(this.message_id).appendChild(p);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
known_unimplemented: function(type, msg)
|
||||||
|
{
|
||||||
|
if ( (!this.warnings[type]) || DEBUG > 1)
|
||||||
|
{
|
||||||
|
var str = "";
|
||||||
|
if (DEBUG <= 1)
|
||||||
|
str = " [ further notices suppressed ]";
|
||||||
|
this.log_warn("Unimplemented function " + type + "(" + msg + ")" + str);
|
||||||
|
this.warnings[type] = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
report_error: function(e)
|
||||||
|
{
|
||||||
|
this.log_err(e.toString());
|
||||||
|
if (this.onerror != undefined)
|
||||||
|
this.onerror(e);
|
||||||
|
else
|
||||||
|
throw(e);
|
||||||
|
},
|
||||||
|
|
||||||
|
report_success: function(m)
|
||||||
|
{
|
||||||
|
if (this.onsuccess != undefined)
|
||||||
|
this.onsuccess(m);
|
||||||
|
},
|
||||||
|
|
||||||
|
cleanup: function()
|
||||||
|
{
|
||||||
|
if (this.timeout)
|
||||||
|
{
|
||||||
|
window.clearTimeout(this.timeout);
|
||||||
|
delete this.timeout;
|
||||||
|
}
|
||||||
|
if (this.ws)
|
||||||
|
{
|
||||||
|
this.ws.close();
|
||||||
|
this.ws = undefined;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
handle_timeout: function()
|
||||||
|
{
|
||||||
|
var e = new Error("Connection timed out.");
|
||||||
|
this.report_error(e);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function spiceconn_timeout(sc)
|
||||||
|
{
|
||||||
|
SpiceConn.prototype.handle_timeout.call(sc);
|
||||||
|
}
|
120
static/js/spice-html5/spicedataview.js
Normal file
120
static/js/spice-html5/spicedataview.js
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** SpiceDataView
|
||||||
|
** FIXME FIXME
|
||||||
|
** This is used because Firefox does not have DataView yet.
|
||||||
|
** We should use DataView if we have it, because it *has* to
|
||||||
|
** be faster than this code
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function SpiceDataView(buffer, byteOffset, byteLength)
|
||||||
|
{
|
||||||
|
if (byteOffset !== undefined)
|
||||||
|
{
|
||||||
|
if (byteLength !== undefined)
|
||||||
|
this.u8 = new Uint8Array(buffer, byteOffset, byteLength);
|
||||||
|
else
|
||||||
|
this.u8 = new Uint8Array(buffer, byteOffset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this.u8 = new Uint8Array(buffer);
|
||||||
|
};
|
||||||
|
|
||||||
|
SpiceDataView.prototype = {
|
||||||
|
getUint8: function(byteOffset)
|
||||||
|
{
|
||||||
|
return this.u8[byteOffset];
|
||||||
|
},
|
||||||
|
getUint16: function(byteOffset, littleEndian)
|
||||||
|
{
|
||||||
|
var low = 1, high = 0;
|
||||||
|
if (littleEndian)
|
||||||
|
{
|
||||||
|
low = 0;
|
||||||
|
high = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (this.u8[byteOffset + high] << 8) | this.u8[byteOffset + low];
|
||||||
|
},
|
||||||
|
getUint32: function(byteOffset, littleEndian)
|
||||||
|
{
|
||||||
|
var low = 2, high = 0;
|
||||||
|
if (littleEndian)
|
||||||
|
{
|
||||||
|
low = 0;
|
||||||
|
high = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (this.getUint16(byteOffset + high, littleEndian) << 16) |
|
||||||
|
this.getUint16(byteOffset + low, littleEndian);
|
||||||
|
},
|
||||||
|
getUint64: function (byteOffset, littleEndian)
|
||||||
|
{
|
||||||
|
var low = 4, high = 0;
|
||||||
|
if (littleEndian)
|
||||||
|
{
|
||||||
|
low = 0;
|
||||||
|
high = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (this.getUint32(byteOffset + high, littleEndian) << 32) |
|
||||||
|
this.getUint32(byteOffset + low, littleEndian);
|
||||||
|
},
|
||||||
|
setUint8: function(byteOffset, b)
|
||||||
|
{
|
||||||
|
this.u8[byteOffset] = (b & 0xff);
|
||||||
|
},
|
||||||
|
setUint16: function(byteOffset, i, littleEndian)
|
||||||
|
{
|
||||||
|
var low = 1, high = 0;
|
||||||
|
if (littleEndian)
|
||||||
|
{
|
||||||
|
low = 0;
|
||||||
|
high = 1;
|
||||||
|
}
|
||||||
|
this.u8[byteOffset + high] = (i & 0xffff) >> 8;
|
||||||
|
this.u8[byteOffset + low] = (i & 0x00ff);
|
||||||
|
},
|
||||||
|
setUint32: function(byteOffset, w, littleEndian)
|
||||||
|
{
|
||||||
|
var low = 2, high = 0;
|
||||||
|
if (littleEndian)
|
||||||
|
{
|
||||||
|
low = 0;
|
||||||
|
high = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setUint16(byteOffset + high, (w & 0xffffffff) >> 16, littleEndian);
|
||||||
|
this.setUint16(byteOffset + low, (w & 0x0000ffff), littleEndian);
|
||||||
|
},
|
||||||
|
setUint64: function(byteOffset, w, littleEndian)
|
||||||
|
{
|
||||||
|
var low = 4, high = 0;
|
||||||
|
if (littleEndian)
|
||||||
|
{
|
||||||
|
low = 0;
|
||||||
|
high = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setUint32(byteOffset + high, (w & 0xffffffffffffffff) >> 32, littleEndian);
|
||||||
|
this.setUint32(byteOffset + low, (w & 0x00000000ffffffff), littleEndian);
|
||||||
|
},
|
||||||
|
}
|
1203
static/js/spice-html5/spicemsg.js
Normal file
1203
static/js/spice-html5/spicemsg.js
Normal file
File diff suppressed because it is too large
Load diff
473
static/js/spice-html5/spicetype.js
Normal file
473
static/js/spice-html5/spicetype.js
Normal file
|
@ -0,0 +1,473 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** Spice types
|
||||||
|
** This file contains classes for common spice types.
|
||||||
|
** Generally, they are used as helpers in reading and writing messages
|
||||||
|
** to and from the server.
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
function SpiceChannelId()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
SpiceChannelId.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.type = dv.getUint8(at, true); at ++;
|
||||||
|
this.id = dv.getUint8(at, true); at ++;
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpiceRect()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceRect.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.top = dv.getUint32(at, true); at += 4;
|
||||||
|
this.left = dv.getUint32(at, true); at += 4;
|
||||||
|
this.bottom = dv.getUint32(at, true); at += 4;
|
||||||
|
this.right = dv.getUint32(at, true); at += 4;
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
is_same_size : function(r)
|
||||||
|
{
|
||||||
|
if ((this.bottom - this.top) == (r.bottom - r.top) &&
|
||||||
|
(this.right - this.left) == (r.right - r.left) )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpiceClipRects()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceClipRects.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
var i;
|
||||||
|
this.num_rects = dv.getUint32(at, true); at += 4;
|
||||||
|
if (this.num_rects > 0)
|
||||||
|
this.rects = [];
|
||||||
|
for (i = 0; i < this.num_rects; i++)
|
||||||
|
{
|
||||||
|
this.rects[i] = new SpiceRect();
|
||||||
|
at = this.rects[i].from_dv(dv, at, mb);
|
||||||
|
}
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpiceClip()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceClip.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.type = dv.getUint8(at, true); at ++;
|
||||||
|
if (this.type == SPICE_CLIP_TYPE_RECTS)
|
||||||
|
{
|
||||||
|
this.rects = new SpiceClipRects();
|
||||||
|
at = this.rects.from_dv(dv, at, mb);
|
||||||
|
}
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpiceImageDescriptor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceImageDescriptor.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.id = dv.getUint64(at, true); at += 8;
|
||||||
|
this.type = dv.getUint8(at, true); at ++;
|
||||||
|
this.flags = dv.getUint8(at, true); at ++;
|
||||||
|
this.width = dv.getUint32(at, true); at += 4;
|
||||||
|
this.height= dv.getUint32(at, true); at += 4;
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpicePalette()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpicePalette.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
var i;
|
||||||
|
this.unique = dv.getUint64(at, true); at += 8;
|
||||||
|
this.num_ents = dv.getUint16(at, true); at += 2;
|
||||||
|
this.ents = [];
|
||||||
|
for (i = 0; i < this.num_ents; i++)
|
||||||
|
{
|
||||||
|
this.ents[i] = dv.getUint32(at, true); at += 4;
|
||||||
|
}
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpiceBitmap()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceBitmap.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.format = dv.getUint8(at, true); at++;
|
||||||
|
this.flags = dv.getUint8(at, true); at++;
|
||||||
|
this.x = dv.getUint32(at, true); at += 4;
|
||||||
|
this.y = dv.getUint32(at, true); at += 4;
|
||||||
|
this.stride = dv.getUint32(at, true); at += 4;
|
||||||
|
if (this.flags & SPICE_BITMAP_FLAGS_PAL_FROM_CACHE)
|
||||||
|
{
|
||||||
|
this.palette_id = dv.getUint64(at, true); at += 8;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var offset = dv.getUint32(at, true); at += 4;
|
||||||
|
if (offset == 0)
|
||||||
|
this.palette = null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.palette = new SpicePalette;
|
||||||
|
this.palette.from_dv(dv, offset, mb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// FIXME - should probably constrain this to the offset
|
||||||
|
// of palette, if non zero
|
||||||
|
this.data = mb.slice(at);
|
||||||
|
at += this.data.byteLength;
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpiceImage()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceImage.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.descriptor = new SpiceImageDescriptor;
|
||||||
|
at = this.descriptor.from_dv(dv, at, mb);
|
||||||
|
|
||||||
|
if (this.descriptor.type == SPICE_IMAGE_TYPE_LZ_RGB)
|
||||||
|
{
|
||||||
|
this.lz_rgb = new Object();
|
||||||
|
this.lz_rgb.length = dv.getUint32(at, true); at += 4;
|
||||||
|
var initial_at = at;
|
||||||
|
this.lz_rgb.magic = "";
|
||||||
|
for (var i = 3; i >= 0; i--)
|
||||||
|
this.lz_rgb.magic += String.fromCharCode(dv.getUint8(at + i));
|
||||||
|
at += 4;
|
||||||
|
|
||||||
|
// NOTE: The endian change is *correct*
|
||||||
|
this.lz_rgb.version = dv.getUint32(at); at += 4;
|
||||||
|
this.lz_rgb.type = dv.getUint32(at); at += 4;
|
||||||
|
this.lz_rgb.width = dv.getUint32(at); at += 4;
|
||||||
|
this.lz_rgb.height = dv.getUint32(at); at += 4;
|
||||||
|
this.lz_rgb.stride = dv.getUint32(at); at += 4;
|
||||||
|
this.lz_rgb.top_down = dv.getUint32(at); at += 4;
|
||||||
|
|
||||||
|
var header_size = at - initial_at;
|
||||||
|
|
||||||
|
this.lz_rgb.data = mb.slice(at, this.lz_rgb.length + at - header_size);
|
||||||
|
at += this.lz_rgb.data.byteLength;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.descriptor.type == SPICE_IMAGE_TYPE_BITMAP)
|
||||||
|
{
|
||||||
|
this.bitmap = new SpiceBitmap;
|
||||||
|
at = this.bitmap.from_dv(dv, at, mb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.descriptor.type == SPICE_IMAGE_TYPE_SURFACE)
|
||||||
|
{
|
||||||
|
this.surface_id = dv.getUint32(at, true); at += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.descriptor.type == SPICE_IMAGE_TYPE_JPEG)
|
||||||
|
{
|
||||||
|
this.jpeg = new Object;
|
||||||
|
this.jpeg.data_size = dv.getUint32(at, true); at += 4;
|
||||||
|
this.jpeg.data = mb.slice(at);
|
||||||
|
at += this.jpeg.data.byteLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.descriptor.type == SPICE_IMAGE_TYPE_JPEG_ALPHA)
|
||||||
|
{
|
||||||
|
this.jpeg_alpha = new Object;
|
||||||
|
this.jpeg_alpha.flags = dv.getUint8(at, true); at += 1;
|
||||||
|
this.jpeg_alpha.jpeg_size = dv.getUint32(at, true); at += 4;
|
||||||
|
this.jpeg_alpha.data_size = dv.getUint32(at, true); at += 4;
|
||||||
|
this.jpeg_alpha.data = mb.slice(at, this.jpeg_alpha.jpeg_size + at);
|
||||||
|
at += this.jpeg_alpha.data.byteLength;
|
||||||
|
// Alpha channel is an LZ image
|
||||||
|
this.jpeg_alpha.alpha = new Object();
|
||||||
|
this.jpeg_alpha.alpha.length = this.jpeg_alpha.data_size - this.jpeg_alpha.jpeg_size;
|
||||||
|
var initial_at = at;
|
||||||
|
this.jpeg_alpha.alpha.magic = "";
|
||||||
|
for (var i = 3; i >= 0; i--)
|
||||||
|
this.jpeg_alpha.alpha.magic += String.fromCharCode(dv.getUint8(at + i));
|
||||||
|
at += 4;
|
||||||
|
|
||||||
|
// NOTE: The endian change is *correct*
|
||||||
|
this.jpeg_alpha.alpha.version = dv.getUint32(at); at += 4;
|
||||||
|
this.jpeg_alpha.alpha.type = dv.getUint32(at); at += 4;
|
||||||
|
this.jpeg_alpha.alpha.width = dv.getUint32(at); at += 4;
|
||||||
|
this.jpeg_alpha.alpha.height = dv.getUint32(at); at += 4;
|
||||||
|
this.jpeg_alpha.alpha.stride = dv.getUint32(at); at += 4;
|
||||||
|
this.jpeg_alpha.alpha.top_down = dv.getUint32(at); at += 4;
|
||||||
|
|
||||||
|
var header_size = at - initial_at;
|
||||||
|
|
||||||
|
this.jpeg_alpha.alpha.data = mb.slice(at, this.jpeg_alpha.alpha.length + at - header_size);
|
||||||
|
at += this.jpeg_alpha.alpha.data.byteLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.descriptor.type == SPICE_IMAGE_TYPE_QUIC)
|
||||||
|
{
|
||||||
|
this.quic = new SpiceQuic;
|
||||||
|
at = this.quic.from_dv(dv, at, mb);
|
||||||
|
}
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function SpiceQMask()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceQMask.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.flags = dv.getUint8(at, true); at++;
|
||||||
|
this.pos = new SpicePoint;
|
||||||
|
at = this.pos.from_dv(dv, at, mb);
|
||||||
|
var offset = dv.getUint32(at, true); at += 4;
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
this.bitmap = null;
|
||||||
|
return at;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.bitmap = new SpiceImage;
|
||||||
|
return this.bitmap.from_dv(dv, offset, mb);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function SpicePattern()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpicePattern.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
var offset = dv.getUint32(at, true); at += 4;
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
this.pat = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.pat = new SpiceImage;
|
||||||
|
this.pat.from_dv(dv, offset, mb);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.pos = new SpicePoint;
|
||||||
|
return this.pos.from_dv(dv, at, mb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpiceBrush()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceBrush.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.type = dv.getUint8(at, true); at ++;
|
||||||
|
if (this.type == SPICE_BRUSH_TYPE_SOLID)
|
||||||
|
{
|
||||||
|
this.color = dv.getUint32(at, true); at += 4;
|
||||||
|
}
|
||||||
|
else if (this.type == SPICE_BRUSH_TYPE_PATTERN)
|
||||||
|
{
|
||||||
|
this.pattern = new SpicePattern;
|
||||||
|
at = this.pattern.from_dv(dv, at, mb);
|
||||||
|
}
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpiceFill()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceFill.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.brush = new SpiceBrush;
|
||||||
|
at = this.brush.from_dv(dv, at, mb);
|
||||||
|
this.rop_descriptor = dv.getUint16(at, true); at += 2;
|
||||||
|
this.mask = new SpiceQMask;
|
||||||
|
return this.mask.from_dv(dv, at, mb);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function SpiceCopy()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceCopy.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
var offset = dv.getUint32(at, true); at += 4;
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
this.src_bitmap = null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.src_bitmap = new SpiceImage;
|
||||||
|
this.src_bitmap.from_dv(dv, offset, mb);
|
||||||
|
}
|
||||||
|
this.src_area = new SpiceRect;
|
||||||
|
at = this.src_area.from_dv(dv, at, mb);
|
||||||
|
this.rop_descriptor = dv.getUint16(at, true); at += 2;
|
||||||
|
this.scale_mode = dv.getUint8(at, true); at ++;
|
||||||
|
this.mask = new SpiceQMask;
|
||||||
|
return this.mask.from_dv(dv, at, mb);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpicePoint16()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpicePoint16.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.x = dv.getUint16(at, true); at += 2;
|
||||||
|
this.y = dv.getUint16(at, true); at += 2;
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpicePoint()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpicePoint.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.x = dv.getUint32(at, true); at += 4;
|
||||||
|
this.y = dv.getUint32(at, true); at += 4;
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpiceCursorHeader()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceCursorHeader.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.unique = dv.getUint64(at, true); at += 8;
|
||||||
|
this.type = dv.getUint8(at, true); at ++;
|
||||||
|
this.width = dv.getUint16(at, true); at += 2;
|
||||||
|
this.height = dv.getUint16(at, true); at += 2;
|
||||||
|
this.hot_spot_x = dv.getUint16(at, true); at += 2;
|
||||||
|
this.hot_spot_y = dv.getUint16(at, true); at += 2;
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpiceCursor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceCursor.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.flags = dv.getUint16(at, true); at += 2;
|
||||||
|
if (this.flags & SPICE_CURSOR_FLAGS_NONE)
|
||||||
|
this.header = null;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.header = new SpiceCursorHeader;
|
||||||
|
at = this.header.from_dv(dv, at, mb);
|
||||||
|
this.data = mb.slice(at);
|
||||||
|
at += this.data.byteLength;
|
||||||
|
}
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function SpiceSurface()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceSurface.prototype =
|
||||||
|
{
|
||||||
|
from_dv: function(dv, at, mb)
|
||||||
|
{
|
||||||
|
this.surface_id = dv.getUint32(at, true); at += 4;
|
||||||
|
this.width = dv.getUint32(at, true); at += 4;
|
||||||
|
this.height = dv.getUint32(at, true); at += 4;
|
||||||
|
this.format = dv.getUint32(at, true); at += 4;
|
||||||
|
this.flags = dv.getUint32(at, true); at += 4;
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
/* FIXME - SpiceImage types lz_plt, jpeg, zlib_glz, and jpeg_alpha are
|
||||||
|
completely unimplemented */
|
589
static/js/spice-html5/thirdparty/jsbn.js
vendored
Normal file
589
static/js/spice-html5/thirdparty/jsbn.js
vendored
Normal file
|
@ -0,0 +1,589 @@
|
||||||
|
// Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2003-2005 Tom Wu
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||||
|
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||||
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||||
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||||
|
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||||
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* In addition, the following condition applies:
|
||||||
|
*
|
||||||
|
* All redistributions must retain an intact copy of this copyright notice
|
||||||
|
* and disclaimer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// Basic JavaScript BN library - subset useful for RSA encryption.
|
||||||
|
|
||||||
|
// Bits per digit
|
||||||
|
var dbits;
|
||||||
|
|
||||||
|
// JavaScript engine analysis
|
||||||
|
var canary = 0xdeadbeefcafe;
|
||||||
|
var j_lm = ((canary&0xffffff)==0xefcafe);
|
||||||
|
|
||||||
|
// (public) Constructor
|
||||||
|
function BigInteger(a,b,c) {
|
||||||
|
if(a != null)
|
||||||
|
if("number" == typeof a) this.fromNumber(a,b,c);
|
||||||
|
else if(b == null && "string" != typeof a) this.fromString(a,256);
|
||||||
|
else this.fromString(a,b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// return new, unset BigInteger
|
||||||
|
function nbi() { return new BigInteger(null); }
|
||||||
|
|
||||||
|
// am: Compute w_j += (x*this_i), propagate carries,
|
||||||
|
// c is initial carry, returns final carry.
|
||||||
|
// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
|
||||||
|
// We need to select the fastest one that works in this environment.
|
||||||
|
|
||||||
|
// am1: use a single mult and divide to get the high bits,
|
||||||
|
// max digit bits should be 26 because
|
||||||
|
// max internal value = 2*dvalue^2-2*dvalue (< 2^53)
|
||||||
|
function am1(i,x,w,j,c,n) {
|
||||||
|
while(--n >= 0) {
|
||||||
|
var v = x*this[i++]+w[j]+c;
|
||||||
|
c = Math.floor(v/0x4000000);
|
||||||
|
w[j++] = v&0x3ffffff;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
// am2 avoids a big mult-and-extract completely.
|
||||||
|
// Max digit bits should be <= 30 because we do bitwise ops
|
||||||
|
// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
|
||||||
|
function am2(i,x,w,j,c,n) {
|
||||||
|
var xl = x&0x7fff, xh = x>>15;
|
||||||
|
while(--n >= 0) {
|
||||||
|
var l = this[i]&0x7fff;
|
||||||
|
var h = this[i++]>>15;
|
||||||
|
var m = xh*l+h*xl;
|
||||||
|
l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);
|
||||||
|
c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);
|
||||||
|
w[j++] = l&0x3fffffff;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
// Alternately, set max digit bits to 28 since some
|
||||||
|
// browsers slow down when dealing with 32-bit numbers.
|
||||||
|
function am3(i,x,w,j,c,n) {
|
||||||
|
var xl = x&0x3fff, xh = x>>14;
|
||||||
|
while(--n >= 0) {
|
||||||
|
var l = this[i]&0x3fff;
|
||||||
|
var h = this[i++]>>14;
|
||||||
|
var m = xh*l+h*xl;
|
||||||
|
l = xl*l+((m&0x3fff)<<14)+w[j]+c;
|
||||||
|
c = (l>>28)+(m>>14)+xh*h;
|
||||||
|
w[j++] = l&0xfffffff;
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
|
||||||
|
BigInteger.prototype.am = am2;
|
||||||
|
dbits = 30;
|
||||||
|
}
|
||||||
|
else if(j_lm && (navigator.appName != "Netscape")) {
|
||||||
|
BigInteger.prototype.am = am1;
|
||||||
|
dbits = 26;
|
||||||
|
}
|
||||||
|
else { // Mozilla/Netscape seems to prefer am3
|
||||||
|
BigInteger.prototype.am = am3;
|
||||||
|
dbits = 28;
|
||||||
|
}
|
||||||
|
|
||||||
|
BigInteger.prototype.DB = dbits;
|
||||||
|
BigInteger.prototype.DM = ((1<<dbits)-1);
|
||||||
|
BigInteger.prototype.DV = (1<<dbits);
|
||||||
|
|
||||||
|
var BI_FP = 52;
|
||||||
|
BigInteger.prototype.FV = Math.pow(2,BI_FP);
|
||||||
|
BigInteger.prototype.F1 = BI_FP-dbits;
|
||||||
|
BigInteger.prototype.F2 = 2*dbits-BI_FP;
|
||||||
|
|
||||||
|
// Digit conversions
|
||||||
|
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||||
|
var BI_RC = new Array();
|
||||||
|
var rr,vv;
|
||||||
|
rr = "0".charCodeAt(0);
|
||||||
|
for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
|
||||||
|
rr = "a".charCodeAt(0);
|
||||||
|
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
||||||
|
rr = "A".charCodeAt(0);
|
||||||
|
for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
|
||||||
|
|
||||||
|
function int2char(n) { return BI_RM.charAt(n); }
|
||||||
|
function intAt(s,i) {
|
||||||
|
var c = BI_RC[s.charCodeAt(i)];
|
||||||
|
return (c==null)?-1:c;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) copy this to r
|
||||||
|
function bnpCopyTo(r) {
|
||||||
|
for(var i = this.t-1; i >= 0; --i) r[i] = this[i];
|
||||||
|
r.t = this.t;
|
||||||
|
r.s = this.s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) set from integer value x, -DV <= x < DV
|
||||||
|
function bnpFromInt(x) {
|
||||||
|
this.t = 1;
|
||||||
|
this.s = (x<0)?-1:0;
|
||||||
|
if(x > 0) this[0] = x;
|
||||||
|
else if(x < -1) this[0] = x+DV;
|
||||||
|
else this.t = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return bigint initialized to value
|
||||||
|
function nbv(i) { var r = nbi(); r.fromInt(i); return r; }
|
||||||
|
|
||||||
|
// (protected) set from string and radix
|
||||||
|
function bnpFromString(s,b) {
|
||||||
|
var k;
|
||||||
|
if(b == 16) k = 4;
|
||||||
|
else if(b == 8) k = 3;
|
||||||
|
else if(b == 256) k = 8; // byte array
|
||||||
|
else if(b == 2) k = 1;
|
||||||
|
else if(b == 32) k = 5;
|
||||||
|
else if(b == 4) k = 2;
|
||||||
|
else { this.fromRadix(s,b); return; }
|
||||||
|
this.t = 0;
|
||||||
|
this.s = 0;
|
||||||
|
var i = s.length, mi = false, sh = 0;
|
||||||
|
while(--i >= 0) {
|
||||||
|
var x = (k==8)?s[i]&0xff:intAt(s,i);
|
||||||
|
if(x < 0) {
|
||||||
|
if(s.charAt(i) == "-") mi = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
mi = false;
|
||||||
|
if(sh == 0)
|
||||||
|
this[this.t++] = x;
|
||||||
|
else if(sh+k > this.DB) {
|
||||||
|
this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh;
|
||||||
|
this[this.t++] = (x>>(this.DB-sh));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
this[this.t-1] |= x<<sh;
|
||||||
|
sh += k;
|
||||||
|
if(sh >= this.DB) sh -= this.DB;
|
||||||
|
}
|
||||||
|
if(k == 8 && (s[0]&0x80) != 0) {
|
||||||
|
this.s = -1;
|
||||||
|
if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh;
|
||||||
|
}
|
||||||
|
this.clamp();
|
||||||
|
if(mi) BigInteger.ZERO.subTo(this,this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) clamp off excess high words
|
||||||
|
function bnpClamp() {
|
||||||
|
var c = this.s&this.DM;
|
||||||
|
while(this.t > 0 && this[this.t-1] == c) --this.t;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (public) return string representation in given radix
|
||||||
|
function bnToString(b) {
|
||||||
|
if(this.s < 0) return "-"+this.negate().toString(b);
|
||||||
|
var k;
|
||||||
|
if(b == 16) k = 4;
|
||||||
|
else if(b == 8) k = 3;
|
||||||
|
else if(b == 2) k = 1;
|
||||||
|
else if(b == 32) k = 5;
|
||||||
|
else if(b == 4) k = 2;
|
||||||
|
else return this.toRadix(b);
|
||||||
|
var km = (1<<k)-1, d, m = false, r = "", i = this.t;
|
||||||
|
var p = this.DB-(i*this.DB)%k;
|
||||||
|
if(i-- > 0) {
|
||||||
|
if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }
|
||||||
|
while(i >= 0) {
|
||||||
|
if(p < k) {
|
||||||
|
d = (this[i]&((1<<p)-1))<<(k-p);
|
||||||
|
d |= this[--i]>>(p+=this.DB-k);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
d = (this[i]>>(p-=k))&km;
|
||||||
|
if(p <= 0) { p += this.DB; --i; }
|
||||||
|
}
|
||||||
|
if(d > 0) m = true;
|
||||||
|
if(m) r += int2char(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m?r:"0";
|
||||||
|
}
|
||||||
|
|
||||||
|
// (public) -this
|
||||||
|
function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; }
|
||||||
|
|
||||||
|
// (public) |this|
|
||||||
|
function bnAbs() { return (this.s<0)?this.negate():this; }
|
||||||
|
|
||||||
|
// (public) return + if this > a, - if this < a, 0 if equal
|
||||||
|
function bnCompareTo(a) {
|
||||||
|
var r = this.s-a.s;
|
||||||
|
if(r != 0) return r;
|
||||||
|
var i = this.t;
|
||||||
|
r = i-a.t;
|
||||||
|
if(r != 0) return r;
|
||||||
|
while(--i >= 0) if((r=this[i]-a[i]) != 0) return r;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns bit length of the integer x
|
||||||
|
function nbits(x) {
|
||||||
|
var r = 1, t;
|
||||||
|
if((t=x>>>16) != 0) { x = t; r += 16; }
|
||||||
|
if((t=x>>8) != 0) { x = t; r += 8; }
|
||||||
|
if((t=x>>4) != 0) { x = t; r += 4; }
|
||||||
|
if((t=x>>2) != 0) { x = t; r += 2; }
|
||||||
|
if((t=x>>1) != 0) { x = t; r += 1; }
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (public) return the number of bits in "this"
|
||||||
|
function bnBitLength() {
|
||||||
|
if(this.t <= 0) return 0;
|
||||||
|
return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM));
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this << n*DB
|
||||||
|
function bnpDLShiftTo(n,r) {
|
||||||
|
var i;
|
||||||
|
for(i = this.t-1; i >= 0; --i) r[i+n] = this[i];
|
||||||
|
for(i = n-1; i >= 0; --i) r[i] = 0;
|
||||||
|
r.t = this.t+n;
|
||||||
|
r.s = this.s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this >> n*DB
|
||||||
|
function bnpDRShiftTo(n,r) {
|
||||||
|
for(var i = n; i < this.t; ++i) r[i-n] = this[i];
|
||||||
|
r.t = Math.max(this.t-n,0);
|
||||||
|
r.s = this.s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this << n
|
||||||
|
function bnpLShiftTo(n,r) {
|
||||||
|
var bs = n%this.DB;
|
||||||
|
var cbs = this.DB-bs;
|
||||||
|
var bm = (1<<cbs)-1;
|
||||||
|
var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i;
|
||||||
|
for(i = this.t-1; i >= 0; --i) {
|
||||||
|
r[i+ds+1] = (this[i]>>cbs)|c;
|
||||||
|
c = (this[i]&bm)<<bs;
|
||||||
|
}
|
||||||
|
for(i = ds-1; i >= 0; --i) r[i] = 0;
|
||||||
|
r[ds] = c;
|
||||||
|
r.t = this.t+ds+1;
|
||||||
|
r.s = this.s;
|
||||||
|
r.clamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this >> n
|
||||||
|
function bnpRShiftTo(n,r) {
|
||||||
|
r.s = this.s;
|
||||||
|
var ds = Math.floor(n/this.DB);
|
||||||
|
if(ds >= this.t) { r.t = 0; return; }
|
||||||
|
var bs = n%this.DB;
|
||||||
|
var cbs = this.DB-bs;
|
||||||
|
var bm = (1<<bs)-1;
|
||||||
|
r[0] = this[ds]>>bs;
|
||||||
|
for(var i = ds+1; i < this.t; ++i) {
|
||||||
|
r[i-ds-1] |= (this[i]&bm)<<cbs;
|
||||||
|
r[i-ds] = this[i]>>bs;
|
||||||
|
}
|
||||||
|
if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs;
|
||||||
|
r.t = this.t-ds;
|
||||||
|
r.clamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this - a
|
||||||
|
function bnpSubTo(a,r) {
|
||||||
|
var i = 0, c = 0, m = Math.min(a.t,this.t);
|
||||||
|
while(i < m) {
|
||||||
|
c += this[i]-a[i];
|
||||||
|
r[i++] = c&this.DM;
|
||||||
|
c >>= this.DB;
|
||||||
|
}
|
||||||
|
if(a.t < this.t) {
|
||||||
|
c -= a.s;
|
||||||
|
while(i < this.t) {
|
||||||
|
c += this[i];
|
||||||
|
r[i++] = c&this.DM;
|
||||||
|
c >>= this.DB;
|
||||||
|
}
|
||||||
|
c += this.s;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
c += this.s;
|
||||||
|
while(i < a.t) {
|
||||||
|
c -= a[i];
|
||||||
|
r[i++] = c&this.DM;
|
||||||
|
c >>= this.DB;
|
||||||
|
}
|
||||||
|
c -= a.s;
|
||||||
|
}
|
||||||
|
r.s = (c<0)?-1:0;
|
||||||
|
if(c < -1) r[i++] = this.DV+c;
|
||||||
|
else if(c > 0) r[i++] = c;
|
||||||
|
r.t = i;
|
||||||
|
r.clamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this * a, r != this,a (HAC 14.12)
|
||||||
|
// "this" should be the larger one if appropriate.
|
||||||
|
function bnpMultiplyTo(a,r) {
|
||||||
|
var x = this.abs(), y = a.abs();
|
||||||
|
var i = x.t;
|
||||||
|
r.t = i+y.t;
|
||||||
|
while(--i >= 0) r[i] = 0;
|
||||||
|
for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t);
|
||||||
|
r.s = 0;
|
||||||
|
r.clamp();
|
||||||
|
if(this.s != a.s) BigInteger.ZERO.subTo(r,r);
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) r = this^2, r != this (HAC 14.16)
|
||||||
|
function bnpSquareTo(r) {
|
||||||
|
var x = this.abs();
|
||||||
|
var i = r.t = 2*x.t;
|
||||||
|
while(--i >= 0) r[i] = 0;
|
||||||
|
for(i = 0; i < x.t-1; ++i) {
|
||||||
|
var c = x.am(i,x[i],r,2*i,0,1);
|
||||||
|
if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) {
|
||||||
|
r[i+x.t] -= x.DV;
|
||||||
|
r[i+x.t+1] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1);
|
||||||
|
r.s = 0;
|
||||||
|
r.clamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
|
||||||
|
// r != q, this != m. q or r may be null.
|
||||||
|
function bnpDivRemTo(m,q,r) {
|
||||||
|
var pm = m.abs();
|
||||||
|
if(pm.t <= 0) return;
|
||||||
|
var pt = this.abs();
|
||||||
|
if(pt.t < pm.t) {
|
||||||
|
if(q != null) q.fromInt(0);
|
||||||
|
if(r != null) this.copyTo(r);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(r == null) r = nbi();
|
||||||
|
var y = nbi(), ts = this.s, ms = m.s;
|
||||||
|
var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus
|
||||||
|
if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); }
|
||||||
|
else { pm.copyTo(y); pt.copyTo(r); }
|
||||||
|
var ys = y.t;
|
||||||
|
var y0 = y[ys-1];
|
||||||
|
if(y0 == 0) return;
|
||||||
|
var yt = y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0);
|
||||||
|
var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2;
|
||||||
|
var i = r.t, j = i-ys, t = (q==null)?nbi():q;
|
||||||
|
y.dlShiftTo(j,t);
|
||||||
|
if(r.compareTo(t) >= 0) {
|
||||||
|
r[r.t++] = 1;
|
||||||
|
r.subTo(t,r);
|
||||||
|
}
|
||||||
|
BigInteger.ONE.dlShiftTo(ys,t);
|
||||||
|
t.subTo(y,y); // "negative" y so we can replace sub with am later
|
||||||
|
while(y.t < ys) y[y.t++] = 0;
|
||||||
|
while(--j >= 0) {
|
||||||
|
// Estimate quotient digit
|
||||||
|
var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);
|
||||||
|
if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out
|
||||||
|
y.dlShiftTo(j,t);
|
||||||
|
r.subTo(t,r);
|
||||||
|
while(r[i] < --qd) r.subTo(t,r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(q != null) {
|
||||||
|
r.drShiftTo(ys,q);
|
||||||
|
if(ts != ms) BigInteger.ZERO.subTo(q,q);
|
||||||
|
}
|
||||||
|
r.t = ys;
|
||||||
|
r.clamp();
|
||||||
|
if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder
|
||||||
|
if(ts < 0) BigInteger.ZERO.subTo(r,r);
|
||||||
|
}
|
||||||
|
|
||||||
|
// (public) this mod a
|
||||||
|
function bnMod(a) {
|
||||||
|
var r = nbi();
|
||||||
|
this.abs().divRemTo(a,null,r);
|
||||||
|
if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modular reduction using "classic" algorithm
|
||||||
|
function Classic(m) { this.m = m; }
|
||||||
|
function cConvert(x) {
|
||||||
|
if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
|
||||||
|
else return x;
|
||||||
|
}
|
||||||
|
function cRevert(x) { return x; }
|
||||||
|
function cReduce(x) { x.divRemTo(this.m,null,x); }
|
||||||
|
function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||||||
|
function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||||||
|
|
||||||
|
Classic.prototype.convert = cConvert;
|
||||||
|
Classic.prototype.revert = cRevert;
|
||||||
|
Classic.prototype.reduce = cReduce;
|
||||||
|
Classic.prototype.mulTo = cMulTo;
|
||||||
|
Classic.prototype.sqrTo = cSqrTo;
|
||||||
|
|
||||||
|
// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
|
||||||
|
// justification:
|
||||||
|
// xy == 1 (mod m)
|
||||||
|
// xy = 1+km
|
||||||
|
// xy(2-xy) = (1+km)(1-km)
|
||||||
|
// x[y(2-xy)] = 1-k^2m^2
|
||||||
|
// x[y(2-xy)] == 1 (mod m^2)
|
||||||
|
// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
|
||||||
|
// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
|
||||||
|
// JS multiply "overflows" differently from C/C++, so care is needed here.
|
||||||
|
function bnpInvDigit() {
|
||||||
|
if(this.t < 1) return 0;
|
||||||
|
var x = this[0];
|
||||||
|
if((x&1) == 0) return 0;
|
||||||
|
var y = x&3; // y == 1/x mod 2^2
|
||||||
|
y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4
|
||||||
|
y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8
|
||||||
|
y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16
|
||||||
|
// last step - calculate inverse mod DV directly;
|
||||||
|
// assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
|
||||||
|
y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits
|
||||||
|
// we really want the negative inverse, and -DV < y < DV
|
||||||
|
return (y>0)?this.DV-y:-y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Montgomery reduction
|
||||||
|
function Montgomery(m) {
|
||||||
|
this.m = m;
|
||||||
|
this.mp = m.invDigit();
|
||||||
|
this.mpl = this.mp&0x7fff;
|
||||||
|
this.mph = this.mp>>15;
|
||||||
|
this.um = (1<<(m.DB-15))-1;
|
||||||
|
this.mt2 = 2*m.t;
|
||||||
|
}
|
||||||
|
|
||||||
|
// xR mod m
|
||||||
|
function montConvert(x) {
|
||||||
|
var r = nbi();
|
||||||
|
x.abs().dlShiftTo(this.m.t,r);
|
||||||
|
r.divRemTo(this.m,null,r);
|
||||||
|
if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// x/R mod m
|
||||||
|
function montRevert(x) {
|
||||||
|
var r = nbi();
|
||||||
|
x.copyTo(r);
|
||||||
|
this.reduce(r);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// x = x/R mod m (HAC 14.32)
|
||||||
|
function montReduce(x) {
|
||||||
|
while(x.t <= this.mt2) // pad x so am has enough room later
|
||||||
|
x[x.t++] = 0;
|
||||||
|
for(var i = 0; i < this.m.t; ++i) {
|
||||||
|
// faster way of calculating u0 = x[i]*mp mod DV
|
||||||
|
var j = x[i]&0x7fff;
|
||||||
|
var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM;
|
||||||
|
// use am to combine the multiply-shift-add into one call
|
||||||
|
j = i+this.m.t;
|
||||||
|
x[j] += this.m.am(0,u0,x,i,0,this.m.t);
|
||||||
|
// propagate carry
|
||||||
|
while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; }
|
||||||
|
}
|
||||||
|
x.clamp();
|
||||||
|
x.drShiftTo(this.m.t,x);
|
||||||
|
if(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// r = "x^2/R mod m"; x != r
|
||||||
|
function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
|
||||||
|
|
||||||
|
// r = "xy/R mod m"; x,y != r
|
||||||
|
function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
|
||||||
|
|
||||||
|
Montgomery.prototype.convert = montConvert;
|
||||||
|
Montgomery.prototype.revert = montRevert;
|
||||||
|
Montgomery.prototype.reduce = montReduce;
|
||||||
|
Montgomery.prototype.mulTo = montMulTo;
|
||||||
|
Montgomery.prototype.sqrTo = montSqrTo;
|
||||||
|
|
||||||
|
// (protected) true iff this is even
|
||||||
|
function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }
|
||||||
|
|
||||||
|
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
||||||
|
function bnpExp(e,z) {
|
||||||
|
if(e > 0xffffffff || e < 1) return BigInteger.ONE;
|
||||||
|
var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
|
||||||
|
g.copyTo(r);
|
||||||
|
while(--i >= 0) {
|
||||||
|
z.sqrTo(r,r2);
|
||||||
|
if((e&(1<<i)) > 0) z.mulTo(r2,g,r);
|
||||||
|
else { var t = r; r = r2; r2 = t; }
|
||||||
|
}
|
||||||
|
return z.revert(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
// (public) this^e % m, 0 <= e < 2^32
|
||||||
|
function bnModPowInt(e,m) {
|
||||||
|
var z;
|
||||||
|
if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
|
||||||
|
return this.exp(e,z);
|
||||||
|
}
|
||||||
|
|
||||||
|
// protected
|
||||||
|
BigInteger.prototype.copyTo = bnpCopyTo;
|
||||||
|
BigInteger.prototype.fromInt = bnpFromInt;
|
||||||
|
BigInteger.prototype.fromString = bnpFromString;
|
||||||
|
BigInteger.prototype.clamp = bnpClamp;
|
||||||
|
BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
|
||||||
|
BigInteger.prototype.drShiftTo = bnpDRShiftTo;
|
||||||
|
BigInteger.prototype.lShiftTo = bnpLShiftTo;
|
||||||
|
BigInteger.prototype.rShiftTo = bnpRShiftTo;
|
||||||
|
BigInteger.prototype.subTo = bnpSubTo;
|
||||||
|
BigInteger.prototype.multiplyTo = bnpMultiplyTo;
|
||||||
|
BigInteger.prototype.squareTo = bnpSquareTo;
|
||||||
|
BigInteger.prototype.divRemTo = bnpDivRemTo;
|
||||||
|
BigInteger.prototype.invDigit = bnpInvDigit;
|
||||||
|
BigInteger.prototype.isEven = bnpIsEven;
|
||||||
|
BigInteger.prototype.exp = bnpExp;
|
||||||
|
|
||||||
|
// public
|
||||||
|
BigInteger.prototype.toString = bnToString;
|
||||||
|
BigInteger.prototype.negate = bnNegate;
|
||||||
|
BigInteger.prototype.abs = bnAbs;
|
||||||
|
BigInteger.prototype.compareTo = bnCompareTo;
|
||||||
|
BigInteger.prototype.bitLength = bnBitLength;
|
||||||
|
BigInteger.prototype.mod = bnMod;
|
||||||
|
BigInteger.prototype.modPowInt = bnModPowInt;
|
||||||
|
|
||||||
|
// "constants"
|
||||||
|
BigInteger.ZERO = nbv(0);
|
||||||
|
BigInteger.ONE = nbv(1);
|
79
static/js/spice-html5/thirdparty/prng4.js
vendored
Normal file
79
static/js/spice-html5/thirdparty/prng4.js
vendored
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
// Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2003-2005 Tom Wu
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||||
|
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||||
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||||
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||||
|
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||||
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* In addition, the following condition applies:
|
||||||
|
*
|
||||||
|
* All redistributions must retain an intact copy of this copyright notice
|
||||||
|
* and disclaimer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// prng4.js - uses Arcfour as a PRNG
|
||||||
|
|
||||||
|
function Arcfour() {
|
||||||
|
this.i = 0;
|
||||||
|
this.j = 0;
|
||||||
|
this.S = new Array();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize arcfour context from key, an array of ints, each from [0..255]
|
||||||
|
function ARC4init(key) {
|
||||||
|
var i, j, t;
|
||||||
|
for(i = 0; i < 256; ++i)
|
||||||
|
this.S[i] = i;
|
||||||
|
j = 0;
|
||||||
|
for(i = 0; i < 256; ++i) {
|
||||||
|
j = (j + this.S[i] + key[i % key.length]) & 255;
|
||||||
|
t = this.S[i];
|
||||||
|
this.S[i] = this.S[j];
|
||||||
|
this.S[j] = t;
|
||||||
|
}
|
||||||
|
this.i = 0;
|
||||||
|
this.j = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ARC4next() {
|
||||||
|
var t;
|
||||||
|
this.i = (this.i + 1) & 255;
|
||||||
|
this.j = (this.j + this.S[this.i]) & 255;
|
||||||
|
t = this.S[this.i];
|
||||||
|
this.S[this.i] = this.S[this.j];
|
||||||
|
this.S[this.j] = t;
|
||||||
|
return this.S[(t + this.S[this.i]) & 255];
|
||||||
|
}
|
||||||
|
|
||||||
|
Arcfour.prototype.init = ARC4init;
|
||||||
|
Arcfour.prototype.next = ARC4next;
|
||||||
|
|
||||||
|
// Plug in your RNG constructor here
|
||||||
|
function prng_newstate() {
|
||||||
|
return new Arcfour();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pool size must be a multiple of 4 and greater than 32.
|
||||||
|
// An array of bytes the size of the pool will be passed to init()
|
||||||
|
var rng_psize = 256;
|
102
static/js/spice-html5/thirdparty/rng.js
vendored
Normal file
102
static/js/spice-html5/thirdparty/rng.js
vendored
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
// Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2003-2005 Tom Wu
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||||
|
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||||
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||||
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||||
|
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||||
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* In addition, the following condition applies:
|
||||||
|
*
|
||||||
|
* All redistributions must retain an intact copy of this copyright notice
|
||||||
|
* and disclaimer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// Random number generator - requires a PRNG backend, e.g. prng4.js
|
||||||
|
|
||||||
|
// For best results, put code like
|
||||||
|
// <body onClick='rng_seed_time();' onKeyPress='rng_seed_time();'>
|
||||||
|
// in your main HTML document.
|
||||||
|
|
||||||
|
var rng_state;
|
||||||
|
var rng_pool;
|
||||||
|
var rng_pptr;
|
||||||
|
|
||||||
|
// Mix in a 32-bit integer into the pool
|
||||||
|
function rng_seed_int(x) {
|
||||||
|
rng_pool[rng_pptr++] ^= x & 255;
|
||||||
|
rng_pool[rng_pptr++] ^= (x >> 8) & 255;
|
||||||
|
rng_pool[rng_pptr++] ^= (x >> 16) & 255;
|
||||||
|
rng_pool[rng_pptr++] ^= (x >> 24) & 255;
|
||||||
|
if(rng_pptr >= rng_psize) rng_pptr -= rng_psize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mix in the current time (w/milliseconds) into the pool
|
||||||
|
function rng_seed_time() {
|
||||||
|
rng_seed_int(new Date().getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the pool with junk if needed.
|
||||||
|
if(rng_pool == null) {
|
||||||
|
rng_pool = new Array();
|
||||||
|
rng_pptr = 0;
|
||||||
|
var t;
|
||||||
|
if(navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto) {
|
||||||
|
// Extract entropy (256 bits) from NS4 RNG if available
|
||||||
|
var z = window.crypto.random(32);
|
||||||
|
for(t = 0; t < z.length; ++t)
|
||||||
|
rng_pool[rng_pptr++] = z.charCodeAt(t) & 255;
|
||||||
|
}
|
||||||
|
while(rng_pptr < rng_psize) { // extract some randomness from Math.random()
|
||||||
|
t = Math.floor(65536 * Math.random());
|
||||||
|
rng_pool[rng_pptr++] = t >>> 8;
|
||||||
|
rng_pool[rng_pptr++] = t & 255;
|
||||||
|
}
|
||||||
|
rng_pptr = 0;
|
||||||
|
rng_seed_time();
|
||||||
|
//rng_seed_int(window.screenX);
|
||||||
|
//rng_seed_int(window.screenY);
|
||||||
|
}
|
||||||
|
|
||||||
|
function rng_get_byte() {
|
||||||
|
if(rng_state == null) {
|
||||||
|
rng_seed_time();
|
||||||
|
rng_state = prng_newstate();
|
||||||
|
rng_state.init(rng_pool);
|
||||||
|
for(rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)
|
||||||
|
rng_pool[rng_pptr] = 0;
|
||||||
|
rng_pptr = 0;
|
||||||
|
//rng_pool = null;
|
||||||
|
}
|
||||||
|
// TODO: allow reseeding after first request
|
||||||
|
return rng_state.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
function rng_get_bytes(ba) {
|
||||||
|
var i;
|
||||||
|
for(i = 0; i < ba.length; ++i) ba[i] = rng_get_byte();
|
||||||
|
}
|
||||||
|
|
||||||
|
function SecureRandom() {}
|
||||||
|
|
||||||
|
SecureRandom.prototype.nextBytes = rng_get_bytes;
|
146
static/js/spice-html5/thirdparty/rsa.js
vendored
Normal file
146
static/js/spice-html5/thirdparty/rsa.js
vendored
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
// Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2003-2005 Tom Wu
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
||||||
|
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
|
||||||
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
|
||||||
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
|
||||||
|
* THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
|
||||||
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* In addition, the following condition applies:
|
||||||
|
*
|
||||||
|
* All redistributions must retain an intact copy of this copyright notice
|
||||||
|
* and disclaimer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
// Depends on jsbn.js and rng.js
|
||||||
|
|
||||||
|
// Version 1.1: support utf-8 encoding in pkcs1pad2
|
||||||
|
|
||||||
|
// convert a (hex) string to a bignum object
|
||||||
|
function parseBigInt(str,r) {
|
||||||
|
return new BigInteger(str,r);
|
||||||
|
}
|
||||||
|
|
||||||
|
function linebrk(s,n) {
|
||||||
|
var ret = "";
|
||||||
|
var i = 0;
|
||||||
|
while(i + n < s.length) {
|
||||||
|
ret += s.substring(i,i+n) + "\n";
|
||||||
|
i += n;
|
||||||
|
}
|
||||||
|
return ret + s.substring(i,s.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
function byte2Hex(b) {
|
||||||
|
if(b < 0x10)
|
||||||
|
return "0" + b.toString(16);
|
||||||
|
else
|
||||||
|
return b.toString(16);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigint
|
||||||
|
function pkcs1pad2(s,n) {
|
||||||
|
if(n < s.length + 11) { // TODO: fix for utf-8
|
||||||
|
alert("Message too long for RSA");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var ba = new Array();
|
||||||
|
var i = s.length - 1;
|
||||||
|
while(i >= 0 && n > 0) {
|
||||||
|
var c = s.charCodeAt(i--);
|
||||||
|
if(c < 128) { // encode using utf-8
|
||||||
|
ba[--n] = c;
|
||||||
|
}
|
||||||
|
else if((c > 127) && (c < 2048)) {
|
||||||
|
ba[--n] = (c & 63) | 128;
|
||||||
|
ba[--n] = (c >> 6) | 192;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ba[--n] = (c & 63) | 128;
|
||||||
|
ba[--n] = ((c >> 6) & 63) | 128;
|
||||||
|
ba[--n] = (c >> 12) | 224;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ba[--n] = 0;
|
||||||
|
var rng = new SecureRandom();
|
||||||
|
var x = new Array();
|
||||||
|
while(n > 2) { // random non-zero pad
|
||||||
|
x[0] = 0;
|
||||||
|
while(x[0] == 0) rng.nextBytes(x);
|
||||||
|
ba[--n] = x[0];
|
||||||
|
}
|
||||||
|
ba[--n] = 2;
|
||||||
|
ba[--n] = 0;
|
||||||
|
return new BigInteger(ba);
|
||||||
|
}
|
||||||
|
|
||||||
|
// "empty" RSA key constructor
|
||||||
|
function RSAKey() {
|
||||||
|
this.n = null;
|
||||||
|
this.e = 0;
|
||||||
|
this.d = null;
|
||||||
|
this.p = null;
|
||||||
|
this.q = null;
|
||||||
|
this.dmp1 = null;
|
||||||
|
this.dmq1 = null;
|
||||||
|
this.coeff = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the public key fields N and e from hex strings
|
||||||
|
function RSASetPublic(N,E) {
|
||||||
|
if(N != null && E != null && N.length > 0 && E.length > 0) {
|
||||||
|
this.n = parseBigInt(N,16);
|
||||||
|
this.e = parseInt(E,16);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
alert("Invalid RSA public key");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform raw public operation on "x": return x^e (mod n)
|
||||||
|
function RSADoPublic(x) {
|
||||||
|
return x.modPowInt(this.e, this.n);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the PKCS#1 RSA encryption of "text" as an even-length hex string
|
||||||
|
function RSAEncrypt(text) {
|
||||||
|
var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3);
|
||||||
|
if(m == null) return null;
|
||||||
|
var c = this.doPublic(m);
|
||||||
|
if(c == null) return null;
|
||||||
|
var h = c.toString(16);
|
||||||
|
if((h.length & 1) == 0) return h; else return "0" + h;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the PKCS#1 RSA encryption of "text" as a Base64-encoded string
|
||||||
|
//function RSAEncryptB64(text) {
|
||||||
|
// var h = this.encrypt(text);
|
||||||
|
// if(h) return hex2b64(h); else return null;
|
||||||
|
//}
|
||||||
|
|
||||||
|
// protected
|
||||||
|
RSAKey.prototype.doPublic = RSADoPublic;
|
||||||
|
|
||||||
|
// public
|
||||||
|
RSAKey.prototype.setPublic = RSASetPublic;
|
||||||
|
RSAKey.prototype.encrypt = RSAEncrypt;
|
||||||
|
//RSAKey.prototype.encrypt_b64 = RSAEncryptB64;
|
346
static/js/spice-html5/thirdparty/sha1.js
vendored
Normal file
346
static/js/spice-html5/thirdparty/sha1.js
vendored
Normal file
|
@ -0,0 +1,346 @@
|
||||||
|
/*
|
||||||
|
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
|
||||||
|
* in FIPS 180-1
|
||||||
|
* Version 2.2 Copyright Paul Johnston 2000 - 2009.
|
||||||
|
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||||
|
* Distributed under the BSD License
|
||||||
|
* See http://pajhome.org.uk/crypt/md5 for details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Downloaded 6/1/2012 from the above address by Jeremy White.
|
||||||
|
License reproduce here for completeness:
|
||||||
|
|
||||||
|
Copyright (c) 1998 - 2009, Paul Johnston & Contributors
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Configurable variables. You may need to tweak these to be compatible with
|
||||||
|
* the server-side, but the defaults work in most cases.
|
||||||
|
*/
|
||||||
|
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
|
||||||
|
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These are the functions you'll usually want to call
|
||||||
|
* They take string arguments and return either hex or base-64 encoded strings
|
||||||
|
*/
|
||||||
|
function hex_sha1(s) { return rstr2hex(rstr_sha1(str2rstr_utf8(s))); }
|
||||||
|
function b64_sha1(s) { return rstr2b64(rstr_sha1(str2rstr_utf8(s))); }
|
||||||
|
function any_sha1(s, e) { return rstr2any(rstr_sha1(str2rstr_utf8(s)), e); }
|
||||||
|
function hex_hmac_sha1(k, d)
|
||||||
|
{ return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }
|
||||||
|
function b64_hmac_sha1(k, d)
|
||||||
|
{ return rstr2b64(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }
|
||||||
|
function any_hmac_sha1(k, d, e)
|
||||||
|
{ return rstr2any(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)), e); }
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perform a simple self-test to see if the VM is working
|
||||||
|
*/
|
||||||
|
function sha1_vm_test()
|
||||||
|
{
|
||||||
|
return hex_sha1("abc").toLowerCase() == "a9993e364706816aba3e25717850c26c9cd0d89d";
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate the SHA1 of a raw string
|
||||||
|
*/
|
||||||
|
function rstr_sha1(s)
|
||||||
|
{
|
||||||
|
return binb2rstr(binb_sha1(rstr2binb(s), s.length * 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate the HMAC-SHA1 of a key and some data (raw strings)
|
||||||
|
*/
|
||||||
|
function rstr_hmac_sha1(key, data)
|
||||||
|
{
|
||||||
|
var bkey = rstr2binb(key);
|
||||||
|
if(bkey.length > 16) bkey = binb_sha1(bkey, key.length * 8);
|
||||||
|
|
||||||
|
var ipad = Array(16), opad = Array(16);
|
||||||
|
for(var i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
ipad[i] = bkey[i] ^ 0x36363636;
|
||||||
|
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||||
|
}
|
||||||
|
|
||||||
|
var hash = binb_sha1(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
|
||||||
|
return binb2rstr(binb_sha1(opad.concat(hash), 512 + 160));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a raw string to a hex string
|
||||||
|
*/
|
||||||
|
function rstr2hex(input)
|
||||||
|
{
|
||||||
|
try { hexcase } catch(e) { hexcase=0; }
|
||||||
|
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||||
|
var output = "";
|
||||||
|
var x;
|
||||||
|
for(var i = 0; i < input.length; i++)
|
||||||
|
{
|
||||||
|
x = input.charCodeAt(i);
|
||||||
|
output += hex_tab.charAt((x >>> 4) & 0x0F)
|
||||||
|
+ hex_tab.charAt( x & 0x0F);
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a raw string to a base-64 string
|
||||||
|
*/
|
||||||
|
function rstr2b64(input)
|
||||||
|
{
|
||||||
|
try { b64pad } catch(e) { b64pad=''; }
|
||||||
|
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
var output = "";
|
||||||
|
var len = input.length;
|
||||||
|
for(var i = 0; i < len; i += 3)
|
||||||
|
{
|
||||||
|
var triplet = (input.charCodeAt(i) << 16)
|
||||||
|
| (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
|
||||||
|
| (i + 2 < len ? input.charCodeAt(i+2) : 0);
|
||||||
|
for(var j = 0; j < 4; j++)
|
||||||
|
{
|
||||||
|
if(i * 8 + j * 6 > input.length * 8) output += b64pad;
|
||||||
|
else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a raw string to an arbitrary string encoding
|
||||||
|
*/
|
||||||
|
function rstr2any(input, encoding)
|
||||||
|
{
|
||||||
|
var divisor = encoding.length;
|
||||||
|
var remainders = Array();
|
||||||
|
var i, q, x, quotient;
|
||||||
|
|
||||||
|
/* Convert to an array of 16-bit big-endian values, forming the dividend */
|
||||||
|
var dividend = Array(Math.ceil(input.length / 2));
|
||||||
|
for(i = 0; i < dividend.length; i++)
|
||||||
|
{
|
||||||
|
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Repeatedly perform a long division. The binary array forms the dividend,
|
||||||
|
* the length of the encoding is the divisor. Once computed, the quotient
|
||||||
|
* forms the dividend for the next step. We stop when the dividend is zero.
|
||||||
|
* All remainders are stored for later use.
|
||||||
|
*/
|
||||||
|
while(dividend.length > 0)
|
||||||
|
{
|
||||||
|
quotient = Array();
|
||||||
|
x = 0;
|
||||||
|
for(i = 0; i < dividend.length; i++)
|
||||||
|
{
|
||||||
|
x = (x << 16) + dividend[i];
|
||||||
|
q = Math.floor(x / divisor);
|
||||||
|
x -= q * divisor;
|
||||||
|
if(quotient.length > 0 || q > 0)
|
||||||
|
quotient[quotient.length] = q;
|
||||||
|
}
|
||||||
|
remainders[remainders.length] = x;
|
||||||
|
dividend = quotient;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert the remainders to the output string */
|
||||||
|
var output = "";
|
||||||
|
for(i = remainders.length - 1; i >= 0; i--)
|
||||||
|
output += encoding.charAt(remainders[i]);
|
||||||
|
|
||||||
|
/* Append leading zero equivalents */
|
||||||
|
var full_length = Math.ceil(input.length * 8 /
|
||||||
|
(Math.log(encoding.length) / Math.log(2)))
|
||||||
|
for(i = output.length; i < full_length; i++)
|
||||||
|
output = encoding[0] + output;
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Encode a string as utf-8.
|
||||||
|
* For efficiency, this assumes the input is valid utf-16.
|
||||||
|
*/
|
||||||
|
function str2rstr_utf8(input)
|
||||||
|
{
|
||||||
|
var output = "";
|
||||||
|
var i = -1;
|
||||||
|
var x, y;
|
||||||
|
|
||||||
|
while(++i < input.length)
|
||||||
|
{
|
||||||
|
/* Decode utf-16 surrogate pairs */
|
||||||
|
x = input.charCodeAt(i);
|
||||||
|
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
|
||||||
|
if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
|
||||||
|
{
|
||||||
|
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Encode output as utf-8 */
|
||||||
|
if(x <= 0x7F)
|
||||||
|
output += String.fromCharCode(x);
|
||||||
|
else if(x <= 0x7FF)
|
||||||
|
output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
|
||||||
|
0x80 | ( x & 0x3F));
|
||||||
|
else if(x <= 0xFFFF)
|
||||||
|
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
|
||||||
|
0x80 | ((x >>> 6 ) & 0x3F),
|
||||||
|
0x80 | ( x & 0x3F));
|
||||||
|
else if(x <= 0x1FFFFF)
|
||||||
|
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
|
||||||
|
0x80 | ((x >>> 12) & 0x3F),
|
||||||
|
0x80 | ((x >>> 6 ) & 0x3F),
|
||||||
|
0x80 | ( x & 0x3F));
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Encode a string as utf-16
|
||||||
|
*/
|
||||||
|
function str2rstr_utf16le(input)
|
||||||
|
{
|
||||||
|
var output = "";
|
||||||
|
for(var i = 0; i < input.length; i++)
|
||||||
|
output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
|
||||||
|
(input.charCodeAt(i) >>> 8) & 0xFF);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function str2rstr_utf16be(input)
|
||||||
|
{
|
||||||
|
var output = "";
|
||||||
|
for(var i = 0; i < input.length; i++)
|
||||||
|
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
|
||||||
|
input.charCodeAt(i) & 0xFF);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a raw string to an array of big-endian words
|
||||||
|
* Characters >255 have their high-byte silently ignored.
|
||||||
|
*/
|
||||||
|
function rstr2binb(input)
|
||||||
|
{
|
||||||
|
var output = Array(input.length >> 2);
|
||||||
|
for(var i = 0; i < output.length; i++)
|
||||||
|
output[i] = 0;
|
||||||
|
for(var i = 0; i < input.length * 8; i += 8)
|
||||||
|
output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert an array of big-endian words to a string
|
||||||
|
*/
|
||||||
|
function binb2rstr(input)
|
||||||
|
{
|
||||||
|
var output = "";
|
||||||
|
for(var i = 0; i < input.length * 32; i += 8)
|
||||||
|
output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Calculate the SHA-1 of an array of big-endian words, and a bit length
|
||||||
|
*/
|
||||||
|
function binb_sha1(x, len)
|
||||||
|
{
|
||||||
|
/* append padding */
|
||||||
|
x[len >> 5] |= 0x80 << (24 - len % 32);
|
||||||
|
x[((len + 64 >> 9) << 4) + 15] = len;
|
||||||
|
|
||||||
|
var w = Array(80);
|
||||||
|
var a = 1732584193;
|
||||||
|
var b = -271733879;
|
||||||
|
var c = -1732584194;
|
||||||
|
var d = 271733878;
|
||||||
|
var e = -1009589776;
|
||||||
|
|
||||||
|
for(var i = 0; i < x.length; i += 16)
|
||||||
|
{
|
||||||
|
var olda = a;
|
||||||
|
var oldb = b;
|
||||||
|
var oldc = c;
|
||||||
|
var oldd = d;
|
||||||
|
var olde = e;
|
||||||
|
|
||||||
|
for(var j = 0; j < 80; j++)
|
||||||
|
{
|
||||||
|
if(j < 16) w[j] = x[i + j];
|
||||||
|
else w[j] = bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
|
||||||
|
var t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),
|
||||||
|
safe_add(safe_add(e, w[j]), sha1_kt(j)));
|
||||||
|
e = d;
|
||||||
|
d = c;
|
||||||
|
c = bit_rol(b, 30);
|
||||||
|
b = a;
|
||||||
|
a = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
a = safe_add(a, olda);
|
||||||
|
b = safe_add(b, oldb);
|
||||||
|
c = safe_add(c, oldc);
|
||||||
|
d = safe_add(d, oldd);
|
||||||
|
e = safe_add(e, olde);
|
||||||
|
}
|
||||||
|
return Array(a, b, c, d, e);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perform the appropriate triplet combination function for the current
|
||||||
|
* iteration
|
||||||
|
*/
|
||||||
|
function sha1_ft(t, b, c, d)
|
||||||
|
{
|
||||||
|
if(t < 20) return (b & c) | ((~b) & d);
|
||||||
|
if(t < 40) return b ^ c ^ d;
|
||||||
|
if(t < 60) return (b & c) | (b & d) | (c & d);
|
||||||
|
return b ^ c ^ d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Determine the appropriate additive constant for the current iteration
|
||||||
|
*/
|
||||||
|
function sha1_kt(t)
|
||||||
|
{
|
||||||
|
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
|
||||||
|
(t < 60) ? -1894007588 : -899497514;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
||||||
|
* to work around bugs in some JS interpreters.
|
||||||
|
*/
|
||||||
|
function safe_add(x, y)
|
||||||
|
{
|
||||||
|
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
|
||||||
|
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
||||||
|
return (msw << 16) | (lsw & 0xFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bitwise rotate a 32-bit number to the left.
|
||||||
|
*/
|
||||||
|
function bit_rol(num, cnt)
|
||||||
|
{
|
||||||
|
return (num << cnt) | (num >>> (32 - cnt));
|
||||||
|
}
|
250
static/js/spice-html5/ticket.js
Normal file
250
static/js/spice-html5/ticket.js
Normal file
|
@ -0,0 +1,250 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var SHA_DIGEST_LENGTH = 20;
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** General ticket RSA encryption functions - just good enough to
|
||||||
|
** support what we need to send back an encrypted ticket.
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** OAEP padding functions. Inspired by the OpenSSL implementation.
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function MGF1(mask, seed)
|
||||||
|
{
|
||||||
|
var i, j, outlen;
|
||||||
|
for (i = 0, outlen = 0; outlen < mask.length; i++)
|
||||||
|
{
|
||||||
|
var combo_buf = new String;
|
||||||
|
|
||||||
|
for (j = 0; j < seed.length; j++)
|
||||||
|
combo_buf += String.fromCharCode(seed[j]);
|
||||||
|
combo_buf += String.fromCharCode((i >> 24) & 255);
|
||||||
|
combo_buf += String.fromCharCode((i >> 16) & 255);
|
||||||
|
combo_buf += String.fromCharCode((i >> 8) & 255);
|
||||||
|
combo_buf += String.fromCharCode((i) & 255);
|
||||||
|
|
||||||
|
var combo_hash = rstr_sha1(combo_buf);
|
||||||
|
for (j = 0; j < combo_hash.length && outlen < mask.length; j++, outlen++)
|
||||||
|
{
|
||||||
|
mask[outlen] = combo_hash.charCodeAt(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function RSA_padding_add_PKCS1_OAEP(tolen, from, param)
|
||||||
|
{
|
||||||
|
var seed = new Array(SHA_DIGEST_LENGTH);
|
||||||
|
var rand = new SecureRandom();
|
||||||
|
rand.nextBytes(seed);
|
||||||
|
|
||||||
|
var dblen = tolen - 1 - seed.length;
|
||||||
|
var db = new Array(dblen);
|
||||||
|
var padlen = dblen - from.length - 1;
|
||||||
|
var i;
|
||||||
|
|
||||||
|
if (param === undefined)
|
||||||
|
param = "";
|
||||||
|
|
||||||
|
if (padlen < SHA_DIGEST_LENGTH)
|
||||||
|
{
|
||||||
|
console.log("Error - data too large for key size.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < padlen; i++)
|
||||||
|
db[i] = 0;
|
||||||
|
|
||||||
|
var param_hash = rstr_sha1(param);
|
||||||
|
for (i = 0; i < param_hash.length; i++)
|
||||||
|
db[i] = param_hash.charCodeAt(i);
|
||||||
|
|
||||||
|
db[padlen] = 1;
|
||||||
|
for (i = 0; i < from.length; i++)
|
||||||
|
db[i + padlen + 1] = from.charCodeAt(i);
|
||||||
|
|
||||||
|
var dbmask = new Array(dblen);
|
||||||
|
if (MGF1(dbmask, seed) < 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
for (i = 0; i < dbmask.length; i++)
|
||||||
|
db[i] ^= dbmask[i];
|
||||||
|
|
||||||
|
|
||||||
|
var seedmask = Array(SHA_DIGEST_LENGTH);
|
||||||
|
if (MGF1(seedmask, db) < 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
for (i = 0; i < seedmask.length; i++)
|
||||||
|
seed[i] ^= seedmask[i];
|
||||||
|
|
||||||
|
var ret = new String;
|
||||||
|
ret += String.fromCharCode(0);
|
||||||
|
for (i = 0; i < seed.length; i++)
|
||||||
|
ret += String.fromCharCode(seed[i]);
|
||||||
|
for (i = 0; i < db.length; i++)
|
||||||
|
ret += String.fromCharCode(db[i]);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function asn_get_length(u8, at)
|
||||||
|
{
|
||||||
|
var len = u8[at++];
|
||||||
|
if (len > 0x80)
|
||||||
|
{
|
||||||
|
if (len != 0x81)
|
||||||
|
{
|
||||||
|
console.log("Error: we lazily don't support keys bigger than 255 bytes. It'd be easy to fix.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
len = u8[at++];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [ at, len];
|
||||||
|
}
|
||||||
|
|
||||||
|
function find_sequence(u8, at)
|
||||||
|
{
|
||||||
|
var lenblock;
|
||||||
|
at = at || 0;
|
||||||
|
if (u8[at++] != 0x30)
|
||||||
|
{
|
||||||
|
console.log("Error: public key should start with a sequence flag.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
lenblock = asn_get_length(u8, at);
|
||||||
|
if (! lenblock)
|
||||||
|
return null;
|
||||||
|
return lenblock;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** Extract an RSA key from a memory buffer
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function create_rsa_from_mb(mb, at)
|
||||||
|
{
|
||||||
|
var u8 = new Uint8Array(mb);
|
||||||
|
var lenblock;
|
||||||
|
var seq;
|
||||||
|
var ba;
|
||||||
|
var i;
|
||||||
|
var ret;
|
||||||
|
|
||||||
|
/* We have a sequence which contains a sequence followed by a bit string */
|
||||||
|
seq = find_sequence(u8, at);
|
||||||
|
if (! seq)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
at = seq[0];
|
||||||
|
seq = find_sequence(u8, at);
|
||||||
|
if (! seq)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
/* Skip over the contained sequence */
|
||||||
|
at = seq[0] + seq[1];
|
||||||
|
if (u8[at++] != 0x3)
|
||||||
|
{
|
||||||
|
console.log("Error: expecting bit string next.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the bit string, which is *itself* a sequence. Having fun yet? */
|
||||||
|
lenblock = asn_get_length(u8, at);
|
||||||
|
if (! lenblock)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
at = lenblock[0];
|
||||||
|
if (u8[at] != 0 && u8[at + 1] != 0x30)
|
||||||
|
{
|
||||||
|
console.log("Error: unexpected values in bit string.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Okay, now we have a sequence of two binary values, we hope. */
|
||||||
|
seq = find_sequence(u8, at + 1);
|
||||||
|
if (! seq)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
at = seq[0];
|
||||||
|
if (u8[at++] != 0x02)
|
||||||
|
{
|
||||||
|
console.log("Error: expecting integer n next.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
lenblock = asn_get_length(u8, at);
|
||||||
|
if (! lenblock)
|
||||||
|
return null;
|
||||||
|
at = lenblock[0];
|
||||||
|
|
||||||
|
ba = new Array(lenblock[1]);
|
||||||
|
for (i = 0; i < lenblock[1]; i++)
|
||||||
|
ba[i] = u8[at + i];
|
||||||
|
|
||||||
|
ret = new RSAKey();
|
||||||
|
ret.n = new BigInteger(ba);
|
||||||
|
|
||||||
|
at += lenblock[1];
|
||||||
|
|
||||||
|
if (u8[at++] != 0x02)
|
||||||
|
{
|
||||||
|
console.log("Error: expecting integer e next.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
lenblock = asn_get_length(u8, at);
|
||||||
|
if (! lenblock)
|
||||||
|
return null;
|
||||||
|
at = lenblock[0];
|
||||||
|
|
||||||
|
ret.e = u8[at++];
|
||||||
|
for (i = 1; i < lenblock[1]; i++)
|
||||||
|
{
|
||||||
|
ret.e <<= 8;
|
||||||
|
ret.e |= u8[at++];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
function rsa_encrypt(rsa, str)
|
||||||
|
{
|
||||||
|
var i;
|
||||||
|
var ret = [];
|
||||||
|
var oaep = RSA_padding_add_PKCS1_OAEP((rsa.n.bitLength()+7)>>3, str);
|
||||||
|
if (! oaep)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var ba = new Array(oaep.length);
|
||||||
|
|
||||||
|
for (i = 0; i < oaep.length; i++)
|
||||||
|
ba[i] = oaep.charCodeAt(i);
|
||||||
|
var bigint = new BigInteger(ba);
|
||||||
|
var enc = rsa.doPublic(bigint);
|
||||||
|
var h = enc.toString(16);
|
||||||
|
if ((h.length & 1) != 0)
|
||||||
|
h = "0" + h;
|
||||||
|
for (i = 0; i < h.length; i += 2)
|
||||||
|
ret[i / 2] = parseInt(h.substring(i, i + 2), 16);
|
||||||
|
return ret;
|
||||||
|
}
|
265
static/js/spice-html5/utils.js
Normal file
265
static/js/spice-html5/utils.js
Normal file
|
@ -0,0 +1,265 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** Utility settings and functions for Spice
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
var DEBUG = 0;
|
||||||
|
var DUMP_DRAWS = false;
|
||||||
|
var DUMP_CANVASES = false;
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** combine_array_buffers
|
||||||
|
** Combine two array buffers.
|
||||||
|
** FIXME - this can't be optimal. See wire.js about eliminating the need.
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function combine_array_buffers(a1, a2)
|
||||||
|
{
|
||||||
|
var in1 = new Uint8Array(a1);
|
||||||
|
var in2 = new Uint8Array(a2);
|
||||||
|
var ret = new ArrayBuffer(a1.byteLength + a2.byteLength);
|
||||||
|
var out = new Uint8Array(ret);
|
||||||
|
var o = 0;
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < in1.length; i++)
|
||||||
|
out[o++] = in1[i];
|
||||||
|
for (i = 0; i < in2.length; i++)
|
||||||
|
out[o++] = in2[i];
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** hexdump_buffer
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function hexdump_buffer(a)
|
||||||
|
{
|
||||||
|
var mg = new Uint8Array(a);
|
||||||
|
var hex = "";
|
||||||
|
var str = "";
|
||||||
|
var last_zeros = 0;
|
||||||
|
for (var i = 0; i < mg.length; i++)
|
||||||
|
{
|
||||||
|
var h = Number(mg[i]).toString(16);
|
||||||
|
if (h.length == 1)
|
||||||
|
hex += "0";
|
||||||
|
hex += h + " ";
|
||||||
|
|
||||||
|
if (mg[i] == 10 || mg[i] == 13 || mg[i] == 8)
|
||||||
|
str += ".";
|
||||||
|
else
|
||||||
|
str += String.fromCharCode(mg[i]);
|
||||||
|
|
||||||
|
if ((i % 16 == 15) || (i == (mg.length - 1)))
|
||||||
|
{
|
||||||
|
while (i % 16 != 15)
|
||||||
|
{
|
||||||
|
hex += " ";
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (last_zeros == 0)
|
||||||
|
console.log(hex + " | " + str);
|
||||||
|
|
||||||
|
if (hex == "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ")
|
||||||
|
{
|
||||||
|
if (last_zeros == 1)
|
||||||
|
{
|
||||||
|
console.log(".");
|
||||||
|
last_zeros++;
|
||||||
|
}
|
||||||
|
else if (last_zeros == 0)
|
||||||
|
last_zeros++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
last_zeros = 0;
|
||||||
|
|
||||||
|
hex = str = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** Converting keycodes to AT scancodes is very hard.
|
||||||
|
** luckly there are some resources on the web and in the Xorg driver that help
|
||||||
|
** us figure out what browser depenend keycodes match to what scancodes.
|
||||||
|
**
|
||||||
|
** This will most likely not work for non US keyboard and browsers other than
|
||||||
|
** modern Chrome and FireFox.
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
var common_scanmap = [];
|
||||||
|
common_scanmap['Q'.charCodeAt(0)] = KEY_Q;
|
||||||
|
common_scanmap['W'.charCodeAt(0)] = KEY_W;
|
||||||
|
common_scanmap['E'.charCodeAt(0)] = KEY_E;
|
||||||
|
common_scanmap['R'.charCodeAt(0)] = KEY_R;
|
||||||
|
common_scanmap['T'.charCodeAt(0)] = KEY_T;
|
||||||
|
common_scanmap['Y'.charCodeAt(0)] = KEY_Y;
|
||||||
|
common_scanmap['U'.charCodeAt(0)] = KEY_U;
|
||||||
|
common_scanmap['I'.charCodeAt(0)] = KEY_I;
|
||||||
|
common_scanmap['O'.charCodeAt(0)] = KEY_O;
|
||||||
|
common_scanmap['P'.charCodeAt(0)] = KEY_P;
|
||||||
|
common_scanmap['A'.charCodeAt(0)] = KEY_A;
|
||||||
|
common_scanmap['S'.charCodeAt(0)] = KEY_S;
|
||||||
|
common_scanmap['D'.charCodeAt(0)] = KEY_D;
|
||||||
|
common_scanmap['F'.charCodeAt(0)] = KEY_F;
|
||||||
|
common_scanmap['G'.charCodeAt(0)] = KEY_G;
|
||||||
|
common_scanmap['H'.charCodeAt(0)] = KEY_H;
|
||||||
|
common_scanmap['J'.charCodeAt(0)] = KEY_J;
|
||||||
|
common_scanmap['K'.charCodeAt(0)] = KEY_K;
|
||||||
|
common_scanmap['L'.charCodeAt(0)] = KEY_L;
|
||||||
|
common_scanmap['Z'.charCodeAt(0)] = KEY_Z;
|
||||||
|
common_scanmap['X'.charCodeAt(0)] = KEY_X;
|
||||||
|
common_scanmap['C'.charCodeAt(0)] = KEY_C;
|
||||||
|
common_scanmap['V'.charCodeAt(0)] = KEY_V;
|
||||||
|
common_scanmap['B'.charCodeAt(0)] = KEY_B;
|
||||||
|
common_scanmap['N'.charCodeAt(0)] = KEY_N;
|
||||||
|
common_scanmap['M'.charCodeAt(0)] = KEY_M;
|
||||||
|
common_scanmap[' '.charCodeAt(0)] = KEY_Space;
|
||||||
|
common_scanmap[13] = KEY_Enter;
|
||||||
|
common_scanmap[27] = KEY_Escape;
|
||||||
|
common_scanmap[8] = KEY_BackSpace;
|
||||||
|
common_scanmap[9] = KEY_Tab;
|
||||||
|
common_scanmap[16] = KEY_ShiftL;
|
||||||
|
common_scanmap[17] = KEY_LCtrl;
|
||||||
|
common_scanmap[18] = KEY_Alt;
|
||||||
|
common_scanmap[20] = KEY_CapsLock;
|
||||||
|
common_scanmap[144] = KEY_NumLock;
|
||||||
|
common_scanmap[112] = KEY_F1;
|
||||||
|
common_scanmap[113] = KEY_F2;
|
||||||
|
common_scanmap[114] = KEY_F3;
|
||||||
|
common_scanmap[115] = KEY_F4;
|
||||||
|
common_scanmap[116] = KEY_F5;
|
||||||
|
common_scanmap[117] = KEY_F6;
|
||||||
|
common_scanmap[118] = KEY_F7;
|
||||||
|
common_scanmap[119] = KEY_F8;
|
||||||
|
common_scanmap[120] = KEY_F9;
|
||||||
|
common_scanmap[121] = KEY_F10;
|
||||||
|
common_scanmap[122] = KEY_F11;
|
||||||
|
common_scanmap[123] = KEY_F12;
|
||||||
|
|
||||||
|
/* These externded scancodes do not line up with values from atKeynames */
|
||||||
|
common_scanmap[42] = 99;
|
||||||
|
common_scanmap[19] = 101; // Break
|
||||||
|
common_scanmap[111] = 0xE035; // KP_Divide
|
||||||
|
common_scanmap[106] = 0xE037; // KP_Multiply
|
||||||
|
common_scanmap[36] = 0xE047; // Home
|
||||||
|
common_scanmap[38] = 0xE048; // Up
|
||||||
|
common_scanmap[33] = 0xE049; // PgUp
|
||||||
|
common_scanmap[37] = 0xE04B; // Left
|
||||||
|
common_scanmap[39] = 0xE04D; // Right
|
||||||
|
common_scanmap[35] = 0xE04F; // End
|
||||||
|
common_scanmap[40] = 0xE050; // Down
|
||||||
|
common_scanmap[34] = 0xE051; // PgDown
|
||||||
|
common_scanmap[45] = 0xE052; // Insert
|
||||||
|
common_scanmap[46] = 0xE053; // Delete
|
||||||
|
common_scanmap[44] = 0x2A37; // Print
|
||||||
|
|
||||||
|
/* These are not common between ALL browsers but are between Firefox and DOM3 */
|
||||||
|
common_scanmap['1'.charCodeAt(0)] = KEY_1;
|
||||||
|
common_scanmap['2'.charCodeAt(0)] = KEY_2;
|
||||||
|
common_scanmap['3'.charCodeAt(0)] = KEY_3;
|
||||||
|
common_scanmap['4'.charCodeAt(0)] = KEY_4;
|
||||||
|
common_scanmap['5'.charCodeAt(0)] = KEY_5;
|
||||||
|
common_scanmap['6'.charCodeAt(0)] = KEY_6;
|
||||||
|
common_scanmap['7'.charCodeAt(0)] = KEY_7;
|
||||||
|
common_scanmap['8'.charCodeAt(0)] = KEY_8;
|
||||||
|
common_scanmap['9'.charCodeAt(0)] = KEY_9;
|
||||||
|
common_scanmap['0'.charCodeAt(0)] = KEY_0;
|
||||||
|
common_scanmap[145] = KEY_ScrollLock;
|
||||||
|
common_scanmap[103] = KEY_KP_7;
|
||||||
|
common_scanmap[104] = KEY_KP_8;
|
||||||
|
common_scanmap[105] = KEY_KP_9;
|
||||||
|
common_scanmap[100] = KEY_KP_4;
|
||||||
|
common_scanmap[101] = KEY_KP_5;
|
||||||
|
common_scanmap[102] = KEY_KP_6;
|
||||||
|
common_scanmap[107] = KEY_KP_Plus;
|
||||||
|
common_scanmap[97] = KEY_KP_1;
|
||||||
|
common_scanmap[98] = KEY_KP_2;
|
||||||
|
common_scanmap[99] = KEY_KP_3;
|
||||||
|
common_scanmap[96] = KEY_KP_0;
|
||||||
|
common_scanmap[110] = KEY_KP_Decimal;
|
||||||
|
common_scanmap[191] = KEY_Slash;
|
||||||
|
common_scanmap[190] = KEY_Period;
|
||||||
|
common_scanmap[188] = KEY_Comma;
|
||||||
|
common_scanmap[220] = KEY_BSlash;
|
||||||
|
common_scanmap[192] = KEY_Tilde;
|
||||||
|
common_scanmap[222] = KEY_Quote;
|
||||||
|
common_scanmap[219] = KEY_LBrace;
|
||||||
|
common_scanmap[221] = KEY_RBrace;
|
||||||
|
|
||||||
|
common_scanmap[91] = 0xE05B; //KEY_LMeta
|
||||||
|
common_scanmap[92] = 0xE05C; //KEY_RMeta
|
||||||
|
common_scanmap[93] = 0xE05D; //KEY_Menu
|
||||||
|
|
||||||
|
/* Firefox/Mozilla codes */
|
||||||
|
var firefox_scanmap = [];
|
||||||
|
firefox_scanmap[173] = KEY_Minus;
|
||||||
|
firefox_scanmap[109] = KEY_Minus;
|
||||||
|
firefox_scanmap[61] = KEY_Equal;
|
||||||
|
firefox_scanmap[59] = KEY_SemiColon;
|
||||||
|
|
||||||
|
/* DOM3 codes */
|
||||||
|
var DOM_scanmap = [];
|
||||||
|
DOM_scanmap[189] = KEY_Minus;
|
||||||
|
DOM_scanmap[187] = KEY_Equal;
|
||||||
|
DOM_scanmap[186] = KEY_SemiColon;
|
||||||
|
|
||||||
|
function get_scancode(code)
|
||||||
|
{
|
||||||
|
if (common_scanmap[code] === undefined)
|
||||||
|
{
|
||||||
|
if (navigator.userAgent.indexOf("Firefox") != -1)
|
||||||
|
return firefox_scanmap[code];
|
||||||
|
else
|
||||||
|
return DOM_scanmap[code];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return common_scanmap[code];
|
||||||
|
}
|
||||||
|
|
||||||
|
function keycode_to_start_scan(code)
|
||||||
|
{
|
||||||
|
var scancode = get_scancode(code);
|
||||||
|
if (scancode === undefined)
|
||||||
|
{
|
||||||
|
alert('no map for ' + code);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scancode < 0x100) {
|
||||||
|
return scancode;
|
||||||
|
} else {
|
||||||
|
return 0xe0 | ((scancode - 0x100) << 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function keycode_to_end_scan(code)
|
||||||
|
{
|
||||||
|
var scancode = get_scancode(code);
|
||||||
|
if (scancode === undefined)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (scancode < 0x100) {
|
||||||
|
return scancode | 0x80;
|
||||||
|
} else {
|
||||||
|
return 0x80e0 | ((scancode - 0x100) << 8);
|
||||||
|
}
|
||||||
|
}
|
553
static/js/spice-html5/webm.js
Normal file
553
static/js/spice-html5/webm.js
Normal file
|
@ -0,0 +1,553 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2014 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** EBML identifiers
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
var EBML_HEADER = [ 0x1a, 0x45, 0xdf, 0xa3 ];
|
||||||
|
var EBML_HEADER_VERSION = [ 0x42, 0x86 ];
|
||||||
|
var EBML_HEADER_READ_VERSION = [ 0x42, 0xf7 ];
|
||||||
|
var EBML_HEADER_MAX_ID_LENGTH = [ 0x42, 0xf2 ];
|
||||||
|
var EBML_HEADER_MAX_SIZE_LENGTH = [ 0x42, 0xf3 ];
|
||||||
|
var EBML_HEADER_DOC_TYPE = [ 0x42, 0x82 ];
|
||||||
|
var EBML_HEADER_DOC_TYPE_VERSION = [ 0x42, 0x87 ];
|
||||||
|
var EBML_HEADER_DOC_TYPE_READ_VERSION = [ 0x42, 0x85 ];
|
||||||
|
|
||||||
|
var WEBM_SEGMENT_HEADER = [ 0x18, 0x53, 0x80, 0x67 ];
|
||||||
|
var WEBM_SEGMENT_INFORMATION = [ 0x15, 0x49, 0xA9, 0x66 ];
|
||||||
|
|
||||||
|
var WEBM_TIMECODE_SCALE = [ 0x2A, 0xD7, 0xB1 ];
|
||||||
|
var WEBM_MUXING_APP = [ 0x4D, 0x80 ];
|
||||||
|
var WEBM_WRITING_APP = [ 0x57, 0x41 ];
|
||||||
|
|
||||||
|
var WEBM_SEEK_HEAD = [ 0x11, 0x4D, 0x9B, 0x74 ];
|
||||||
|
var WEBM_SEEK = [ 0x4D, 0xBB ];
|
||||||
|
var WEBM_SEEK_ID = [ 0x53, 0xAB ];
|
||||||
|
var WEBM_SEEK_POSITION = [ 0x53, 0xAC ];
|
||||||
|
|
||||||
|
var WEBM_TRACKS = [ 0x16, 0x54, 0xAE, 0x6B ];
|
||||||
|
var WEBM_TRACK_ENTRY = [ 0xAE ];
|
||||||
|
var WEBM_TRACK_NUMBER = [ 0xD7 ];
|
||||||
|
var WEBM_TRACK_UID = [ 0x73, 0xC5 ];
|
||||||
|
var WEBM_TRACK_TYPE = [ 0x83 ];
|
||||||
|
var WEBM_FLAG_ENABLED = [ 0xB9 ];
|
||||||
|
var WEBM_FLAG_DEFAULT = [ 0x88 ];
|
||||||
|
var WEBM_FLAG_FORCED = [ 0x55, 0xAA ];
|
||||||
|
var WEBM_FLAG_LACING = [ 0x9C ];
|
||||||
|
var WEBM_MIN_CACHE = [ 0x6D, 0xE7 ];
|
||||||
|
|
||||||
|
var WEBM_MAX_BLOCK_ADDITION_ID = [ 0x55, 0xEE ];
|
||||||
|
var WEBM_CODEC_DECODE_ALL = [ 0xAA ];
|
||||||
|
var WEBM_SEEK_PRE_ROLL = [ 0x56, 0xBB ];
|
||||||
|
var WEBM_CODEC_DELAY = [ 0x56, 0xAA ];
|
||||||
|
var WEBM_CODEC_PRIVATE = [ 0x63, 0xA2 ];
|
||||||
|
var WEBM_CODEC_ID = [ 0x86 ];
|
||||||
|
|
||||||
|
var WEBM_AUDIO = [ 0xE1 ] ;
|
||||||
|
var WEBM_SAMPLING_FREQUENCY = [ 0xB5 ] ;
|
||||||
|
var WEBM_CHANNELS = [ 0x9F ] ;
|
||||||
|
|
||||||
|
var WEBM_CLUSTER = [ 0x1F, 0x43, 0xB6, 0x75 ];
|
||||||
|
var WEBM_TIME_CODE = [ 0xE7 ] ;
|
||||||
|
var WEBM_SIMPLE_BLOCK = [ 0xA3 ] ;
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** Various OPUS / Webm constants
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
var CLUSTER_SIMPLEBLOCK_FLAG_KEYFRAME = 1 << 7;
|
||||||
|
|
||||||
|
var OPUS_FREQUENCY = 48000;
|
||||||
|
var OPUS_CHANNELS = 2;
|
||||||
|
|
||||||
|
var SPICE_PLAYBACK_CODEC = 'audio/webm; codecs="opus"';
|
||||||
|
var MAX_CLUSTER_TIME = 1000;
|
||||||
|
|
||||||
|
var GAP_DETECTION_THRESHOLD = 50;
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** EBML utility functions
|
||||||
|
** These classes can create the binary representation of a webm file
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function EBML_write_u1_data_len(len, dv, at)
|
||||||
|
{
|
||||||
|
var b = 0x80 | len;
|
||||||
|
dv.setUint8(at, b);
|
||||||
|
return at + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function EBML_write_u8_value(id, val, dv, at)
|
||||||
|
{
|
||||||
|
at = EBML_write_array(id, dv, at);
|
||||||
|
at = EBML_write_u1_data_len(1, dv, at);
|
||||||
|
dv.setUint8(at, val);
|
||||||
|
return at + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function EBML_write_u32_value(id, val, dv, at)
|
||||||
|
{
|
||||||
|
at = EBML_write_array(id, dv, at);
|
||||||
|
at = EBML_write_u1_data_len(4, dv, at);
|
||||||
|
dv.setUint32(at, val);
|
||||||
|
return at + 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
function EBML_write_u16_value(id, val, dv, at)
|
||||||
|
{
|
||||||
|
at = EBML_write_array(id, dv, at);
|
||||||
|
at = EBML_write_u1_data_len(2, dv, at);
|
||||||
|
dv.setUint16(at, val);
|
||||||
|
return at + 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function EBML_write_float_value(id, val, dv, at)
|
||||||
|
{
|
||||||
|
at = EBML_write_array(id, dv, at);
|
||||||
|
at = EBML_write_u1_data_len(4, dv, at);
|
||||||
|
dv.setFloat32(at, val);
|
||||||
|
return at + 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function EBML_write_u64_data_len(len, dv, at)
|
||||||
|
{
|
||||||
|
/* Javascript doesn't do 64 bit ints, so this cheats and
|
||||||
|
just has a max of 32 bits. Fine for our purposes */
|
||||||
|
dv.setUint8(at++, 0x01);
|
||||||
|
dv.setUint8(at++, 0x00);
|
||||||
|
dv.setUint8(at++, 0x00);
|
||||||
|
dv.setUint8(at++, 0x00);
|
||||||
|
var val = len & 0xFFFFFFFF;
|
||||||
|
for (var shift = 24; shift >= 0; shift -= 8)
|
||||||
|
dv.setUint8(at++, val >> shift);
|
||||||
|
return at;
|
||||||
|
}
|
||||||
|
|
||||||
|
function EBML_write_array(arr, dv, at)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < arr.length; i++)
|
||||||
|
dv.setUint8(at + i, arr[i]);
|
||||||
|
return at + arr.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function EBML_write_string(str, dv, at)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < str.length; i++)
|
||||||
|
dv.setUint8(at + i, str.charCodeAt(i));
|
||||||
|
return at + str.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
function EBML_write_data(id, data, dv, at)
|
||||||
|
{
|
||||||
|
at = EBML_write_array(id, dv, at);
|
||||||
|
if (data.length < 127)
|
||||||
|
at = EBML_write_u1_data_len(data.length, dv, at);
|
||||||
|
else
|
||||||
|
at = EBML_write_u64_data_len(data.length, dv, at);
|
||||||
|
if ((typeof data) == "string")
|
||||||
|
at = EBML_write_string(data, dv, at);
|
||||||
|
else
|
||||||
|
at = EBML_write_array(data, dv, at);
|
||||||
|
return at;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------
|
||||||
|
** Webm objects
|
||||||
|
** These classes can create the binary representation of a webm file
|
||||||
|
**--------------------------------------------------------------------------*/
|
||||||
|
function EBMLHeader()
|
||||||
|
{
|
||||||
|
this.id = EBML_HEADER;
|
||||||
|
this.Version = 1;
|
||||||
|
this.ReadVersion = 1;
|
||||||
|
this.MaxIDLength = 4;
|
||||||
|
this.MaxSizeLength = 8;
|
||||||
|
this.DocType = "webm";
|
||||||
|
this.DocTypeVersion = 2; /* Not well specified by the WebM guys, but functionally required for Firefox */
|
||||||
|
this.DocTypeReadVersion = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
EBMLHeader.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var dv = new DataView(a);
|
||||||
|
|
||||||
|
at = EBML_write_array(this.id, dv, at);
|
||||||
|
at = EBML_write_u64_data_len(0x1f, dv, at);
|
||||||
|
at = EBML_write_u8_value(EBML_HEADER_VERSION, this.Version, dv, at);
|
||||||
|
at = EBML_write_u8_value(EBML_HEADER_READ_VERSION, this.ReadVersion, dv, at);
|
||||||
|
at = EBML_write_u8_value(EBML_HEADER_MAX_ID_LENGTH, this.MaxIDLength, dv, at);
|
||||||
|
at = EBML_write_u8_value(EBML_HEADER_MAX_SIZE_LENGTH, this.MaxSizeLength, dv, at);
|
||||||
|
at = EBML_write_data(EBML_HEADER_DOC_TYPE, this.DocType, dv, at);
|
||||||
|
at = EBML_write_u8_value(EBML_HEADER_DOC_TYPE_VERSION, this.DocTypeVersion, dv, at);
|
||||||
|
at = EBML_write_u8_value(EBML_HEADER_DOC_TYPE_READ_VERSION, this.DocTypeReadVersion, dv, at);
|
||||||
|
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return 0x1f + 8 + this.id.length;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function webm_Segment()
|
||||||
|
{
|
||||||
|
this.id = WEBM_SEGMENT_HEADER;
|
||||||
|
}
|
||||||
|
|
||||||
|
webm_Segment.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var dv = new DataView(a);
|
||||||
|
|
||||||
|
at = EBML_write_array(this.id, dv, at);
|
||||||
|
dv.setUint8(at++, 0xff);
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return this.id.length + 1;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function webm_SegmentInformation()
|
||||||
|
{
|
||||||
|
this.id = WEBM_SEGMENT_INFORMATION;
|
||||||
|
this.timecode_scale = 1000000; /* 1 ms */
|
||||||
|
this.muxing_app = "spice";
|
||||||
|
this.writing_app = "spice-html5";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
webm_SegmentInformation.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var dv = new DataView(a);
|
||||||
|
|
||||||
|
at = EBML_write_array(this.id, dv, at);
|
||||||
|
at = EBML_write_u64_data_len(this.buffer_size() - 8 - this.id.length, dv, at);
|
||||||
|
at = EBML_write_u32_value(WEBM_TIMECODE_SCALE, this.timecode_scale, dv, at);
|
||||||
|
at = EBML_write_data(WEBM_MUXING_APP, this.muxing_app, dv, at);
|
||||||
|
at = EBML_write_data(WEBM_WRITING_APP, this.writing_app, dv, at);
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return this.id.length + 8 +
|
||||||
|
WEBM_TIMECODE_SCALE.length + 1 + 4 +
|
||||||
|
WEBM_MUXING_APP.length + 1 + this.muxing_app.length +
|
||||||
|
WEBM_WRITING_APP.length + 1 + this.writing_app.length;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function webm_Audio(frequency)
|
||||||
|
{
|
||||||
|
this.id = WEBM_AUDIO;
|
||||||
|
this.sampling_frequency = frequency;
|
||||||
|
this.channels = OPUS_CHANNELS;
|
||||||
|
}
|
||||||
|
|
||||||
|
webm_Audio.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var dv = new DataView(a);
|
||||||
|
at = EBML_write_array(this.id, dv, at);
|
||||||
|
at = EBML_write_u64_data_len(this.buffer_size() - 8 - this.id.length, dv, at);
|
||||||
|
at = EBML_write_u8_value(WEBM_CHANNELS, this.channels, dv, at);
|
||||||
|
at = EBML_write_float_value(WEBM_SAMPLING_FREQUENCY, this.sampling_frequency, dv, at);
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return this.id.length + 8 +
|
||||||
|
WEBM_SAMPLING_FREQUENCY.length + 1 + 4 +
|
||||||
|
WEBM_CHANNELS.length + 1 + 1;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ---------------------------
|
||||||
|
SeekHead not currently used. Hopefully not needed.
|
||||||
|
*/
|
||||||
|
function webm_Seek(seekid, pos)
|
||||||
|
{
|
||||||
|
this.id = WEBM_SEEK;
|
||||||
|
this.pos = pos;
|
||||||
|
this.seekid = seekid;
|
||||||
|
}
|
||||||
|
|
||||||
|
webm_Seek.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var dv = new DataView(a);
|
||||||
|
at = EBML_write_array(this.id, dv, at);
|
||||||
|
at = EBML_write_u1_data_len(this.buffer_size() - 1 - this.id.length, dv, at);
|
||||||
|
|
||||||
|
at = EBML_write_data(WEBM_SEEK_ID, this.seekid, dv, at)
|
||||||
|
at = EBML_write_u16_value(WEBM_SEEK_POSITION, this.pos, dv, at)
|
||||||
|
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return this.id.length + 1 +
|
||||||
|
WEBM_SEEK_ID.length + 1 + this.seekid.length +
|
||||||
|
WEBM_SEEK_POSITION.length + 1 + 2;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
function webm_SeekHead(info_pos, track_pos)
|
||||||
|
{
|
||||||
|
this.id = WEBM_SEEK_HEAD;
|
||||||
|
this.info = new webm_Seek(WEBM_SEGMENT_INFORMATION, info_pos);
|
||||||
|
this.track = new webm_Seek(WEBM_TRACKS, track_pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
webm_SeekHead.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var dv = new DataView(a);
|
||||||
|
at = EBML_write_array(this.id, dv, at);
|
||||||
|
at = EBML_write_u64_data_len(this.buffer_size() - 8 - this.id.length, dv, at);
|
||||||
|
|
||||||
|
at = this.info.to_buffer(a, at);
|
||||||
|
at = this.track.to_buffer(a, at);
|
||||||
|
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return this.id.length + 8 +
|
||||||
|
this.info.buffer_size() +
|
||||||
|
this.track.buffer_size();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------
|
||||||
|
End of Seek Head
|
||||||
|
*/
|
||||||
|
|
||||||
|
function webm_TrackEntry()
|
||||||
|
{
|
||||||
|
this.id = WEBM_TRACK_ENTRY;
|
||||||
|
this.number = 1;
|
||||||
|
this.uid = 1;
|
||||||
|
this.type = 2; // Audio
|
||||||
|
this.flag_enabled = 1;
|
||||||
|
this.flag_default = 1;
|
||||||
|
this.flag_forced = 1;
|
||||||
|
this.flag_lacing = 0;
|
||||||
|
this.min_cache = 0; // fixme - check
|
||||||
|
this.max_block_addition_id = 0;
|
||||||
|
this.codec_decode_all = 0; // fixme - check
|
||||||
|
this.seek_pre_roll = 0; // 80000000; // fixme - check
|
||||||
|
this.codec_delay = 80000000; // Must match codec_private.preskip
|
||||||
|
this.codec_id = "A_OPUS";
|
||||||
|
this.audio = new webm_Audio(OPUS_FREQUENCY);
|
||||||
|
|
||||||
|
// See: http://tools.ietf.org/html/draft-terriberry-oggopus-01
|
||||||
|
this.codec_private = [ 0x4f, 0x70, 0x75, 0x73, 0x48, 0x65, 0x61, 0x64, // OpusHead
|
||||||
|
0x01, // Version
|
||||||
|
OPUS_CHANNELS,
|
||||||
|
0x00, 0x0F, // Preskip - 3840 samples - should be 8ms at 48kHz
|
||||||
|
0x80, 0xbb, 0x00, 0x00, // 48000
|
||||||
|
0x00, 0x00, // Output gain
|
||||||
|
0x00 // Channel mapping family
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
webm_TrackEntry.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var dv = new DataView(a);
|
||||||
|
at = EBML_write_array(this.id, dv, at);
|
||||||
|
at = EBML_write_u64_data_len(this.buffer_size() - 8 - this.id.length, dv, at);
|
||||||
|
at = EBML_write_u8_value(WEBM_TRACK_NUMBER, this.number, dv, at);
|
||||||
|
at = EBML_write_u8_value(WEBM_TRACK_UID, this.uid, dv, at);
|
||||||
|
at = EBML_write_u8_value(WEBM_FLAG_ENABLED, this.flag_enabled, dv, at);
|
||||||
|
at = EBML_write_u8_value(WEBM_FLAG_DEFAULT, this.flag_default, dv, at);
|
||||||
|
at = EBML_write_u8_value(WEBM_FLAG_FORCED, this.flag_forced, dv, at);
|
||||||
|
at = EBML_write_u8_value(WEBM_FLAG_LACING, this.flag_lacing, dv, at);
|
||||||
|
at = EBML_write_data(WEBM_CODEC_ID, this.codec_id, dv, at);
|
||||||
|
at = EBML_write_u8_value(WEBM_MIN_CACHE, this.min_cache, dv, at);
|
||||||
|
at = EBML_write_u8_value(WEBM_MAX_BLOCK_ADDITION_ID, this.max_block_addition_id, dv, at);
|
||||||
|
at = EBML_write_u8_value(WEBM_CODEC_DECODE_ALL, this.codec_decode_all, dv, at);
|
||||||
|
at = EBML_write_u32_value(WEBM_CODEC_DELAY, this.codec_delay, dv, at);
|
||||||
|
at = EBML_write_u32_value(WEBM_SEEK_PRE_ROLL, this.seek_pre_roll, dv, at);
|
||||||
|
at = EBML_write_u8_value(WEBM_TRACK_TYPE, this.type, dv, at);
|
||||||
|
at = EBML_write_data(WEBM_CODEC_PRIVATE, this.codec_private, dv, at);
|
||||||
|
|
||||||
|
at = this.audio.to_buffer(a, at);
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return this.id.length + 8 +
|
||||||
|
WEBM_TRACK_NUMBER.length + 1 + 1 +
|
||||||
|
WEBM_TRACK_UID.length + 1 + 1 +
|
||||||
|
WEBM_TRACK_TYPE.length + 1 + 1 +
|
||||||
|
WEBM_FLAG_ENABLED.length + 1 + 1 +
|
||||||
|
WEBM_FLAG_DEFAULT.length + 1 + 1 +
|
||||||
|
WEBM_FLAG_FORCED.length + 1 + 1 +
|
||||||
|
WEBM_FLAG_LACING.length + 1 + 1 +
|
||||||
|
WEBM_MIN_CACHE.length + 1 + 1 +
|
||||||
|
WEBM_MAX_BLOCK_ADDITION_ID.length + 1 + 1 +
|
||||||
|
WEBM_CODEC_DECODE_ALL.length + 1 + 1 +
|
||||||
|
WEBM_SEEK_PRE_ROLL.length + 1 + 4 +
|
||||||
|
WEBM_CODEC_DELAY.length + 1 + 4 +
|
||||||
|
WEBM_CODEC_ID.length + this.codec_id.length + 1 +
|
||||||
|
WEBM_CODEC_PRIVATE.length + 1 + this.codec_private.length +
|
||||||
|
this.audio.buffer_size();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
function webm_Tracks(entry)
|
||||||
|
{
|
||||||
|
this.id = WEBM_TRACKS;
|
||||||
|
this.track_entry = entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
webm_Tracks.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var dv = new DataView(a);
|
||||||
|
at = EBML_write_array(this.id, dv, at);
|
||||||
|
at = EBML_write_u64_data_len(this.buffer_size() - 8 - this.id.length, dv, at);
|
||||||
|
at = this.track_entry.to_buffer(a, at);
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return this.id.length + 8 +
|
||||||
|
this.track_entry.buffer_size();
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function webm_Cluster(timecode, data)
|
||||||
|
{
|
||||||
|
this.id = WEBM_CLUSTER;
|
||||||
|
this.timecode = timecode;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
webm_Cluster.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var dv = new DataView(a);
|
||||||
|
at = EBML_write_array(this.id, dv, at);
|
||||||
|
dv.setUint8(at++, 0xff);
|
||||||
|
at = EBML_write_u32_value(WEBM_TIME_CODE, this.timecode, dv, at);
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return this.id.length + 1 +
|
||||||
|
WEBM_TIME_CODE.length + 1 + 4;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function webm_SimpleBlock(timecode, data, keyframe)
|
||||||
|
{
|
||||||
|
this.id = WEBM_SIMPLE_BLOCK;
|
||||||
|
this.timecode = timecode;
|
||||||
|
this.data = data;
|
||||||
|
this.keyframe = keyframe;
|
||||||
|
}
|
||||||
|
|
||||||
|
webm_SimpleBlock.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
var dv = new DataView(a);
|
||||||
|
at = EBML_write_array(this.id, dv, at);
|
||||||
|
at = EBML_write_u64_data_len(this.data.byteLength + 4, dv, at);
|
||||||
|
at = EBML_write_u1_data_len(1, dv, at); // Track #
|
||||||
|
dv.setUint16(at, this.timecode); at += 2; // timecode - relative to cluster
|
||||||
|
dv.setUint8(at, this.keyframe ? CLUSTER_SIMPLEBLOCK_FLAG_KEYFRAME : 0); at += 1; // flags
|
||||||
|
|
||||||
|
// FIXME - There should be a better way to copy
|
||||||
|
var u8 = new Uint8Array(this.data);
|
||||||
|
for (var i = 0; i < this.data.byteLength; i++)
|
||||||
|
dv.setUint8(at++, u8[i]);
|
||||||
|
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return this.id.length + 8 +
|
||||||
|
1 + 2 + 1 +
|
||||||
|
this.data.byteLength;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function webm_Header()
|
||||||
|
{
|
||||||
|
this.ebml = new EBMLHeader;
|
||||||
|
this.segment = new webm_Segment;
|
||||||
|
this.seek_head = new webm_SeekHead(0, 0);
|
||||||
|
|
||||||
|
this.seek_head.info.pos = this.segment.buffer_size() + this.seek_head.buffer_size();
|
||||||
|
|
||||||
|
this.info = new webm_SegmentInformation;
|
||||||
|
|
||||||
|
this.seek_head.track.pos = this.seek_head.info.pos + this.info.buffer_size();
|
||||||
|
|
||||||
|
this.track_entry = new webm_TrackEntry;
|
||||||
|
this.tracks = new webm_Tracks(this.track_entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
webm_Header.prototype =
|
||||||
|
{
|
||||||
|
to_buffer: function(a, at)
|
||||||
|
{
|
||||||
|
at = at || 0;
|
||||||
|
at = this.ebml.to_buffer(a, at);
|
||||||
|
at = this.segment.to_buffer(a, at);
|
||||||
|
at = this.info.to_buffer(a, at);
|
||||||
|
at = this.tracks.to_buffer(a, at);
|
||||||
|
|
||||||
|
return at;
|
||||||
|
},
|
||||||
|
buffer_size: function()
|
||||||
|
{
|
||||||
|
return this.ebml.buffer_size() +
|
||||||
|
this.segment.buffer_size() +
|
||||||
|
this.info.buffer_size() +
|
||||||
|
this.tracks.buffer_size();
|
||||||
|
},
|
||||||
|
}
|
123
static/js/spice-html5/wire.js
Normal file
123
static/js/spice-html5/wire.js
Normal file
|
@ -0,0 +1,123 @@
|
||||||
|
"use strict";
|
||||||
|
/*
|
||||||
|
Copyright (C) 2012 by Jeremy P. White <jwhite@codeweavers.com>
|
||||||
|
|
||||||
|
This file is part of spice-html5.
|
||||||
|
|
||||||
|
spice-html5 is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
spice-html5 is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------
|
||||||
|
** SpiceWireReader
|
||||||
|
** This class will receive messages from a WebSocket and relay it to a given
|
||||||
|
** callback. It will optionally save and pass along a header, useful in processing
|
||||||
|
** the mini message format.
|
||||||
|
**--------------------------------------------------------------------------------------*/
|
||||||
|
function SpiceWireReader(sc, callback)
|
||||||
|
{
|
||||||
|
this.sc = sc;
|
||||||
|
this.callback = callback;
|
||||||
|
this.needed = 0;
|
||||||
|
|
||||||
|
this.buffers = [];
|
||||||
|
|
||||||
|
this.sc.ws.wire_reader = this;
|
||||||
|
this.sc.ws.binaryType = "arraybuffer";
|
||||||
|
this.sc.ws.addEventListener('message', wire_blob_catcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
SpiceWireReader.prototype =
|
||||||
|
{
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------
|
||||||
|
** Process messages coming in from our WebSocket
|
||||||
|
**----------------------------------------------------------------------*/
|
||||||
|
inbound: function (mb)
|
||||||
|
{
|
||||||
|
var at;
|
||||||
|
|
||||||
|
/* Just buffer if we don't need anything yet */
|
||||||
|
if (this.needed == 0)
|
||||||
|
{
|
||||||
|
this.buffers.push(mb);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Optimization - if we have just one inbound block, and it's
|
||||||
|
suitable for our needs, just use it. */
|
||||||
|
if (this.buffers.length == 0 && mb.byteLength >= this.needed)
|
||||||
|
{
|
||||||
|
if (mb.byteLength > this.needed)
|
||||||
|
{
|
||||||
|
this.buffers.push(mb.slice(this.needed));
|
||||||
|
mb = mb.slice(0, this.needed);
|
||||||
|
}
|
||||||
|
this.callback.call(this.sc, mb,
|
||||||
|
this.saved_msg_header || undefined);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.buffers.push(mb);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* If we have fragments that add up to what we need, combine them */
|
||||||
|
/* FIXME - it would be faster to revise the processing code to handle
|
||||||
|
** multiple fragments directly. Essentially, we should be
|
||||||
|
** able to do this without any slice() or combine_array_buffers() calls */
|
||||||
|
while (this.buffers.length > 1 && this.buffers[0].byteLength < this.needed)
|
||||||
|
{
|
||||||
|
var mb1 = this.buffers.shift();
|
||||||
|
var mb2 = this.buffers.shift();
|
||||||
|
|
||||||
|
this.buffers.unshift(combine_array_buffers(mb1, mb2));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
while (this.buffers.length > 0 && this.buffers[0].byteLength >= this.needed)
|
||||||
|
{
|
||||||
|
mb = this.buffers.shift();
|
||||||
|
if (mb.byteLength > this.needed)
|
||||||
|
{
|
||||||
|
this.buffers.unshift(mb.slice(this.needed));
|
||||||
|
mb = mb.slice(0, this.needed);
|
||||||
|
}
|
||||||
|
this.callback.call(this.sc, mb,
|
||||||
|
this.saved_msg_header || undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
request: function(n)
|
||||||
|
{
|
||||||
|
this.needed = n;
|
||||||
|
},
|
||||||
|
|
||||||
|
save_header: function(h)
|
||||||
|
{
|
||||||
|
this.saved_msg_header = h;
|
||||||
|
},
|
||||||
|
|
||||||
|
clear_header: function()
|
||||||
|
{
|
||||||
|
this.saved_msg_header = undefined;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function wire_blob_catcher(e)
|
||||||
|
{
|
||||||
|
DEBUG > 1 && console.log(">> WebSockets.onmessage");
|
||||||
|
DEBUG > 1 && console.log("id " + this.wire_reader.sc.connection_id +"; type " + this.wire_reader.sc.type);
|
||||||
|
SpiceWireReader.prototype.inbound.call(this.wire_reader, e.data);
|
||||||
|
}
|
Loading…
Reference in a new issue