您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

106 行
3.1 KiB

  1. //-------------------------------------------------------------------------
  2. // MODULE INIT FUNCTIONS
  3. //-------------------------------------------------------------------------
  4. function RegisterListener()
  5. {
  6. //Register all the correct functions to the listener
  7. var div_listener = GetiFrameDivEmbed();
  8. if (div_listener)
  9. {
  10. div_listener.addEventListener('loadstart', NaClModuleStartedLoad, true);
  11. div_listener.addEventListener('load', NaClModuleDidLoad, true);
  12. div_listener.addEventListener('error', NaClModuleError, true);
  13. div_listener.addEventListener('progress', NaClModuleLoadUpdate, true);
  14. div_listener.addEventListener('message', NaClModuleSentMessage, true);
  15. div_listener.addEventListener('crash', NaClModuleCrash, true);
  16. window.setTimeout("UpdateTextStatus(0.1)", 100);
  17. }
  18. else if (IsUsingNaCl())
  19. window.setTimeout("RegisterListener()", 200);
  20. }
  21. function NaClInitModuleVar()
  22. {
  23. InitModuleVar();
  24. if (g_embed_module)
  25. g_embed_module['SendMessage'] = function(message) { g_embed_module.postMessage(message); }
  26. }
  27. //-------------------------------------------------------------------------
  28. // MODULE LOADING FUNCTIONS
  29. //-------------------------------------------------------------------------
  30. //Indicate page has been loaded.
  31. function NaClLoadingInit()
  32. {
  33. HideProgressStatus(false);
  34. //Page did load before NaCl module
  35. if (!g_embed_module)
  36. AddTextStatus('Please wait for module loading');
  37. RegisterListener();
  38. }
  39. //Module starts load
  40. function NaClModuleStartedLoad()
  41. {
  42. AddTextStatus('Module Started Loading');
  43. NaClInitModuleVar();
  44. }
  45. //Module progress event
  46. function NaClModuleLoadUpdate(event)
  47. {
  48. if (event.lengthComputable)
  49. UpdateProgressBarValue('Please wait, loading', event.loaded, event.total);
  50. else
  51. UpdateProgressBarValue('Please wait, calculating load balance ...');
  52. }
  53. //Indicate module load success.
  54. function NaClModuleDidLoad()
  55. {
  56. if (!g_embed_module)
  57. NaClInitModuleVar();
  58. //Hide the progress div
  59. AddTextStatus('Module is live, thank you for your patience.');
  60. window.setTimeout('HideProgressStatus(true)', GetMaxStatusTime(0.5) * 1000);
  61. ModuleIsLive();
  62. }
  63. //Module did crash
  64. function NaClModuleCrash(event)
  65. {
  66. NaClRestartModule();
  67. AddTextStatus("Module has crashed ! Restarting ...");
  68. }
  69. //Module had an error
  70. function NaClModuleError(event)
  71. {
  72. NaClRestartModule();
  73. AddTextStatus("Module Load/start Error ! Restarting ...");
  74. }
  75. //Used to restart module on crash/error/load fail ....
  76. function NaClRestartModule()
  77. {
  78. var id_frame_embed = GetFrameData();
  79. if (id_frame_embed)
  80. {
  81. HideProgressStatus(false);
  82. window.setTimeout('GetFrameData().contentDocument.location.reload(true)', 1000);
  83. }
  84. }
  85. //-------------------------------------------------------------------------
  86. // MODULE COMMUNICATION FUNCTIONS
  87. //-------------------------------------------------------------------------
  88. //Handle message from the NaCl module
  89. function NaClModuleSentMessage(message)
  90. {
  91. ModuleSentMessage(message);
  92. }