Browse Source

MeshViewer html & NaCl bulletproofisation. iframe works perfectly and Restart/error logic is plugged.

undefined
Benjamin ‘Touky’ Huet Sam Hocevar <sam@hocevar.net> 11 years ago
parent
commit
ebf93dc2a3
3 changed files with 91 additions and 70 deletions
  1. +54
    -49
      test/meshviewer_index.html
  2. +5
    -10
      test/meshviewer_nacl.html
  3. +32
    -11
      test/nacl_loading.js

+ 54
- 49
test/meshviewer_index.html View File

@@ -63,7 +63,7 @@ progress::-webkit-progress-value
{ {
position: relative; position: relative;
} }
#id_div_embed_data
#id_div_frame_embed
{ {
position: absolute; position: absolute;
top: 2px; top: 2px;
@@ -82,10 +82,12 @@ progress::-webkit-progress-value


<title>Mesh Viewer NaCl</title> <title>Mesh Viewer NaCl</title>


</head>

<script type="text/javascript"> <script type="text/javascript">
//Base data Setup //Base data Setup
g_div_embed_data_save = '';
g_div_embed_data = null; // Global application object.
g_div_frame_embed_save = '';
g_div_frame_embed = null; // Global application object.
g_embed_nacl_module = null; // Global application object. g_embed_nacl_module = null; // Global application object.
g_txtarea_code_src = null; g_txtarea_code_src = null;
g_div_helper_cmd = [null, null]; g_div_helper_cmd = [null, null];
@@ -99,15 +101,15 @@ progress::-webkit-progress-value
g_var_progress_bar = -1; g_var_progress_bar = -1;
g_frame_embed = null; g_frame_embed = null;


function GetNaClListenerDiv() { return document.getElementById('id_div_listener'); }
function GetNaClListenerDiv() { return g_frame_embed.contentDocument.getElementById('id_div_embed_data'); }
function GetNaClModuleVar() { return g_embed_nacl_module; } function GetNaClModuleVar() { return g_embed_nacl_module; }
function InitNaClModuleVar() { g_embed_nacl_module = document.getElementById('id_embed_nacl_module'); }
function InitNaClModuleVar() { g_embed_nacl_module = g_frame_embed.contentDocument.getElementById('id_embed_nacl_module'); }
function GetTextAreaCodeSrc() { return g_txtarea_code_src; } function GetTextAreaCodeSrc() { return g_txtarea_code_src; }
function GetDivProgress() { return g_div_progress; } function GetDivProgress() { return g_div_progress; }
function GetProgressBar() { return g_progress_bar; } function GetProgressBar() { return g_progress_bar; }
function GetDivProgressStatus() { return g_div_progress_status; } function GetDivProgressStatus() { return g_div_progress_status; }
function GetDivEmbedData() { return g_div_embed_data; }
function GetDivEmbedDataSave() { return g_div_embed_data_save; }
function GetDivEmbedData() { return g_div_frame_embed; }
function GetDivEmbedDataSave() { return g_div_frame_embed_save; }
function GetFrameData() { return g_frame_embed; } function GetFrameData() { return g_frame_embed; }
function IsUsingNaCl() { return true; } function IsUsingNaCl() { return true; }
</script> </script>
@@ -121,22 +123,15 @@ progress::-webkit-progress-value
<script src="./nacl_loading.js"></script> <script src="./nacl_loading.js"></script>


<script type="text/javascript"> <script type="text/javascript">
//Init should always start before the first tick
window.setTimeout("Init()", 100);
window.setTimeout("Tick()", 200);
window.setTimeout("UpdateEmbed()", 2000);

function UpdateEmbed()
{
window.setTimeout("UpdateEmbed()", 2000);
g_frame_embed.contentDocument.location.reload(true);
}

//Base init for all datas //Base init for all datas
function Init() function Init()
{ {
g_div_embed_data = document.getElementById('id_div_embed_data');
g_frame_embed = document.getElementById('id_frame_embed');
alert('INIT PROUT');
//Init frame variable first.
g_frame_embed = document.getElementById('id_frame_embed');
//This is in an iframe.
g_div_frame_embed = g_frame_embed.contentDocument.getElementById('id_div_frame_embed');
//The rest of these are in this page.
g_txtarea_code_src = document.getElementById('id_txtarea_code_src'); g_txtarea_code_src = document.getElementById('id_txtarea_code_src');
g_div_helper_cmd[0] = document.getElementById('id_div_helper_cmd_0'); g_div_helper_cmd[0] = document.getElementById('id_div_helper_cmd_0');
g_div_helper_cmd[1] = document.getElementById('id_div_helper_cmd_1'); g_div_helper_cmd[1] = document.getElementById('id_div_helper_cmd_1');
@@ -148,22 +143,32 @@ progress::-webkit-progress-value
g_div_progress_status = document.getElementById('id_div_progress_status'); g_div_progress_status = document.getElementById('id_div_progress_status');
g_progress_bar = document.getElementById('id_progress_bar'); g_progress_bar = document.getElementById('id_progress_bar');


//Pulg here any cookie update
if (!g_txtarea_code_src.value)
g_txtarea_code_src.value = "//This is a comment\nsc#f8f afcb 1 1 1 0";

//Fill the TOC //Fill the TOC
g_div_alphabet.innerHTML = '&nbsp;Table of content<br>&nbsp;[';
var new_toc = BuildTOC(true);
var pattern = new RegExp("^[a-zA-Z\.]");
while (pattern.test(new_toc))
new_toc = new_toc.replace(pattern, "<b>$&");
pattern = new RegExp("[a-zA-Z\.]$");
while (pattern.test(new_toc))
new_toc = new_toc.replace(pattern, "$&</b>");
pattern = new RegExp("([a-zA-Z])([\.])");
while (pattern.test(new_toc))
new_toc = new_toc.replace(pattern, "$1</b>$2");
pattern = new RegExp("([\.])([a-zA-Z])");
while (pattern.test(new_toc))
new_toc = new_toc.replace(pattern, "$1<b>$2");
g_div_alphabet.innerHTML += new_toc + ']&nbsp;<br>&nbsp;';
if (!g_div_alphabet.innerHTML)
{
g_div_alphabet.innerHTML = '&nbsp;Table of content<br>&nbsp;[';
var new_toc = BuildTOC(true);
var pattern = new RegExp("^[a-zA-Z\.]");
while (pattern.test(new_toc))
new_toc = new_toc.replace(pattern, "<b>$&");
pattern = new RegExp("[a-zA-Z\.]$");
while (pattern.test(new_toc))
new_toc = new_toc.replace(pattern, "$&</b>");
pattern = new RegExp("([a-zA-Z])([\.])");
while (pattern.test(new_toc))
new_toc = new_toc.replace(pattern, "$1</b>$2");
pattern = new RegExp("([\.])([a-zA-Z])");
while (pattern.test(new_toc))
new_toc = new_toc.replace(pattern, "$1<b>$2");
g_div_alphabet.innerHTML += new_toc + ']&nbsp;<br>&nbsp;';
}

//Tick has been done, start Tick
window.setTimeout("Tick()", 200);
} }


function Tick() function Tick()
@@ -176,35 +181,35 @@ progress::-webkit-progress-value
var div_vars = g_div_helper_vars; var div_vars = g_div_helper_vars;
CmdLookup(div_cmds, div_args, div_cmnt, div_vars, text_src); CmdLookup(div_cmds, div_args, div_cmnt, div_vars, text_src);
} }
</script>


</script>
</head>

<body onload="PageDidLoad()">
<body>


<h1>Mesh Viewer : Native Client version.</h1> <h1>Mesh Viewer : Native Client version.</h1>

<p> <p>
<div id="final_div"> <div id="final_div">
<div id="id_div_listener" align="center" style="width:770px;height:200px"> <div id="id_div_listener" align="center" style="width:770px;height:200px">
<canvas id="BGCanvas" width="772" height="202"></canvas> <canvas id="BGCanvas" width="772" height="202"></canvas>
<div id="id_div_progress"> <div id="id_div_progress">
<br>&nbsp;
<progress id="id_progress_bar" align="left"></progress>
<div id="id_div_progress_status">....</div>&nbsp;
<br>&nbsp;
<progress id="id_progress_bar" align="left"></progress>
<div id="id_div_progress_status">....</div>&nbsp;
</div> </div>
<div id="id_div_embed_data">
<iframe id="id_frame_embed" src="meshviewer_nacl.html" width=770 height=200 frameborder=0 scrolling=no></iframe>
<div id="id_div_frame_embed">
<iframe onload="Init(); PageDidLoad();" id="id_frame_embed" src="meshviewer_nacl.html" width=770 height=200 frameborder=0 scrolling=no></iframe>
</div> </div>
</div> </div>
</div> </div>
</p> </p>

<div><button onclick="SendMessageToModule()">Send Mesh Command !</button></div> <div><button onclick="SendMessageToModule()">Send Mesh Command !</button></div>

<table border="0" cellpadding="0" cellspacing="0"> <table border="0" cellpadding="0" cellspacing="0">
<tr> <tr>
<td> <td>
<div id="bouton"> <div id="bouton">
<textarea autofocus id="id_txtarea_code_src" rows="6" cols="94" style="font: 14px Consolas; resize: none;">//This is a comment
sc#f8f afcb 1 1 1 0</textarea>
<textarea autofocus id="id_txtarea_code_src" rows="6" cols="94" style="font: 14px Consolas; resize: none;"></textarea>
</div> </div>
</td> </td>
<td valign="top" rowspan="3">&nbsp;</td> <td valign="top" rowspan="3">&nbsp;</td>
@@ -214,9 +219,9 @@ sc#f8f afcb 1 1 1 0</textarea>
</td> </td>
</tr> </tr>
<tr> <tr>
<td>
<div id="id_div_alphabet"></div>
</td>
<td>
<div id="id_div_alphabet"></div>
</td>
</tr> </tr>
<tr> <tr>
<td valign="top"> <td valign="top">


+ 5
- 10
test/meshviewer_nacl.html View File

@@ -1,13 +1,8 @@
<DOCTYPE html> <DOCTYPE html>
<html> <html>
<body onload="PageDidLoad()">
<div id="id_div_embed_data">
<param name="wmode" value="opaque"/>
<embed name="name_embed_nacl_module"
id="id_embed_nacl_module"
width=770 height=200
src="meshviewer_nacl.nmf"
type="application/x-nacl" />
</div>
</body>
<body>
<div id="id_div_embed_data" style="left:0px;top:0px;position:absolute;">
<embed name="name_embed_nacl_module" id="id_embed_nacl_module" width=770 height=200 src="meshviewer_nacl.nmf" type="application/x-nacl" />
</div>
</body>
</html> </html>

+ 32
- 11
test/nacl_loading.js View File

@@ -2,7 +2,7 @@ g_status_text = [null];
g_status_timer = [-1.0]; g_status_timer = [-1.0];
g_var_progress_bar = -1; g_var_progress_bar = -1;


window.setTimeout("RegisterListener()", 200);
//window.setTimeout("RegisterListener()", 200);


function RegisterListener() function RegisterListener()
{ {
@@ -16,7 +16,7 @@ function RegisterListener()
div_listener.addEventListener('progress', ModuleLoadUpdate, true); div_listener.addEventListener('progress', ModuleLoadUpdate, true);
div_listener.addEventListener('message', ModuleSentMessage, true); div_listener.addEventListener('message', ModuleSentMessage, true);
div_listener.addEventListener('crash', ModuleCrash, true); div_listener.addEventListener('crash', ModuleCrash, true);
window.setTimeout("UpdateTextStatus()", 100);
window.setTimeout("UpdateTextStatus(0.1)", 100);
} }
else if (IsUsingNaCl()) else if (IsUsingNaCl())
window.setTimeout("RegisterListener()", 200); window.setTimeout("RegisterListener()", 200);
@@ -29,8 +29,9 @@ function RegisterListener()
function PageDidLoad() function PageDidLoad()
{ {
//Page did load before NaCl module //Page did load before NaCl module
if (GetNaClModuleVar() == null)
if (!GetNaClModuleVar())
AddTextStatus('Please wait for module loading'); AddTextStatus('Please wait for module loading');
RegisterListener();
} }


//Module starts load //Module starts load
@@ -68,12 +69,16 @@ function ModuleLoadUpdate(event)
//Indicate module load success. //Indicate module load success.
function ModuleDidLoad() function ModuleDidLoad()
{ {
if (GetNaClModuleVar() == null)
if (!GetNaClModuleVar())
InitNaClModuleVar(); InitNaClModuleVar();


//Hide the progress div //Hide the progress div
AddTextStatus('Module is live, thank you for your patience.'); AddTextStatus('Module is live, thank you for your patience.');
window.setTimeout('HideProgressStatus(true)', 4000);
var hide_timer = 0.1;
for (var i = 0; i < g_status_timer.length; i++)
if (g_status_timer[i])
hide_timer = Math.max(g_status_timer[i], hide_timer);
window.setTimeout('HideProgressStatus(true)', hide_timer * 1000);
} }


//Module did crash //Module did crash
@@ -93,6 +98,13 @@ function ModuleError(event)
//Used to restart module on crash/error/load fail .... //Used to restart module on crash/error/load fail ....
function RestartModule() function RestartModule()
{ {
var id_frame_embed = GetFrameData();
if (id_frame_embed)
{
HideProgressStatus(false);
window.setTimeout('GetFrameData().contentDocument.location.reload(true)', 1000);
}
/*
var div_embed_data = GetDivEmbedData(); var div_embed_data = GetDivEmbedData();
var div_embed_data_save = GetDivEmbedDataSave(); var div_embed_data_save = GetDivEmbedDataSave();


@@ -102,12 +114,14 @@ function RestartModule()


div_embed_data_save = div_embed_data.innerHTML; div_embed_data_save = div_embed_data.innerHTML;
div_embed_data.innerHTML = ''; div_embed_data.innerHTML = '';
window.setTimeout('RestartModuleRestoreEmbed()', 1000);
} }
*/
} }


//Called after the Restart to effectively do it
function RestartModuleRestoreEmbed() function RestartModuleRestoreEmbed()
{ {
/*
var div_embed_data = GetDivEmbedData(); var div_embed_data = GetDivEmbedData();
var div_embed_data_save = GetDivEmbedDataSave(); var div_embed_data_save = GetDivEmbedDataSave();


@@ -117,6 +131,7 @@ function RestartModuleRestoreEmbed()
div_embed_data_save = ''; div_embed_data_save = '';
HideProgressStatus(false); HideProgressStatus(false);
} }
*/
} }


//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -160,27 +175,33 @@ function UpdateTextStatus(seconds)
{ {
g_status_timer[i] -= seconds; g_status_timer[i] -= seconds;
div_progress_status.innerHTML += g_status_text[i]; div_progress_status.innerHTML += g_status_text[i];
//div_progress_status.innerHTML += '[' + g_status_timer[i].toFixed(2) + ']';
if (i < g_status_text.length - 1) if (i < g_status_text.length - 1)
div_progress_status.innerHTML += '<br>'; div_progress_status.innerHTML += '<br>';
} }
} }
window.setTimeout("UpdateTextStatus()", 100);
window.setTimeout("UpdateTextStatus(0.1)", 100);
} }
} }


//Add text status to the stack //Add text status to the stack
function AddTextStatus(message, message_id) function AddTextStatus(message, message_id)
{ {
var msg_timer = 2.0;
if (message_id == undefined || message_id < 0) if (message_id == undefined || message_id < 0)
{ {
for (var i = g_status_timer.length - 1; i >= 0; i--)
if (g_status_timer[i])
msg_timer = Math.max(msg_timer, g_status_timer[i] + 0.5);

g_status_text[g_status_text.length] = message; g_status_text[g_status_text.length] = message;
g_status_timer[g_status_timer.length] = 5.0;
g_status_timer[g_status_timer.length] = msg_timer;
return g_status_timer.length - 1; return g_status_timer.length - 1;
} }
else else
{ {
g_status_text[message_id] = message; g_status_text[message_id] = message;
g_status_timer[message_id] = 5.0;
g_status_timer[message_id] = msg_timer;
return message_id; return message_id;
} }
} }
@@ -198,14 +219,14 @@ function HideProgressStatus(should_hide)
g_status_text.splice(0, g_status_text.length); g_status_text.splice(0, g_status_text.length);
g_status_timer.splice(0, g_status_timer.length); g_status_timer.splice(0, g_status_timer.length);
progress_bar.value = -1; progress_bar.value = -1;
UpdateTextStatus(0.1);
UpdateTextStatus(1.0);
} }
else else
{ {
div_progress.style.visibility = "visible"; div_progress.style.visibility = "visible";
progress_bar.value = -1; progress_bar.value = -1;
AddTextStatus('Please wait for module loading'); AddTextStatus('Please wait for module loading');
UpdateTextStatus(0.1);
UpdateTextStatus(1.0);
} }
} }
} }

Loading…
Cancel
Save