1
0

scriptbrowser.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #include "precomp.h"
  2. #include "scriptbrowser.h"
  3. #include "main.h"
  4. #include "script/script.h"
  5. #include "script/scriptmgr.h"
  6. #include "script/vcpu.h"
  7. #include "mbmgr.h"
  8. BrowserScriptController _browserController;
  9. BrowserScriptController *browserController = &_browserController;
  10. // -- Functions table -------------------------------------
  11. function_descriptor_struct BrowserScriptController::exportedFunction[] = {
  12. {"gotoUrl", 1, (void*)ScriptBrowserWnd::script_vcpu_gotoUrl },
  13. {"back", 0, (void*)ScriptBrowserWnd::script_vcpu_back },
  14. {"forward", 0, (void*)ScriptBrowserWnd::script_vcpu_forward },
  15. {"home", 0, (void*)ScriptBrowserWnd::script_vcpu_home},
  16. {"refresh", 0, (void*)ScriptBrowserWnd::script_vcpu_refresh},
  17. {"setTargetName", 1, (void*)ScriptBrowserWnd::script_vcpu_setTargetName},
  18. {"onBeforeNavigate", 3, (void*)ScriptBrowserWnd::script_vcpu_onBeforeNavigate},
  19. {"onDocumentComplete", 1, (void*)ScriptBrowserWnd::script_vcpu_onDocumentComplete},
  20. };
  21. // --------------------------------------------------------
  22. const wchar_t *BrowserScriptController::getClassName() {
  23. return L"Browser";
  24. }
  25. const wchar_t *BrowserScriptController::getAncestorClassName() {
  26. return L"GuiObject";
  27. }
  28. ScriptObject *BrowserScriptController::instantiate() {
  29. ScriptBrowserWnd *sb = new ScriptBrowserWnd;
  30. ASSERT(sb != NULL);
  31. return sb->getScriptObject();
  32. }
  33. void BrowserScriptController::destroy(ScriptObject *o) {
  34. ScriptBrowserWnd *sb = static_cast<ScriptBrowserWnd *>(o->vcpu_getInterface(browserGuid));
  35. ASSERT(sb != NULL);
  36. delete sb;
  37. }
  38. void *BrowserScriptController::encapsulate(ScriptObject *o) {
  39. return NULL; // no encapsulation for browsers yet
  40. }
  41. void BrowserScriptController::deencapsulate(void *o) {
  42. }
  43. int BrowserScriptController::getNumFunctions() {
  44. return sizeof(exportedFunction) / sizeof(function_descriptor_struct);
  45. }
  46. const function_descriptor_struct *BrowserScriptController::getExportedFunctions() {
  47. return exportedFunction;
  48. }
  49. GUID BrowserScriptController::getClassGuid() {
  50. return browserGuid;
  51. }
  52. ScriptBrowserWnd::ScriptBrowserWnd() {
  53. getScriptObject()->vcpu_setInterface(browserGuid, (void *)static_cast<ScriptBrowserWnd *>(this));
  54. getScriptObject()->vcpu_setClassName("Browser");
  55. getScriptObject()->vcpu_setController(browserController);
  56. }
  57. ScriptBrowserWnd::~ScriptBrowserWnd() {
  58. }
  59. int ScriptBrowserWnd::setXmlParam(const char *name, const char *value) {
  60. if (SCRIPTBROWSERWND_PARENT::setParam(name, value)) return 1;
  61. else if (STRCASEEQL(name,"url")) defurl = value;
  62. else if (STRCASEEQL(name,"mainmb")) setMainMB(WTOI(value));
  63. else if (STRCASEEQL(name,"targetname")) setTargetName(value);
  64. else return 0;
  65. return 1;
  66. }
  67. int ScriptBrowserWnd::onInit() {
  68. SCRIPTBROWSERWND_PARENT::onInit();
  69. if (!defurl.isempty()) navigateUrl(defurl);
  70. return 1;
  71. }
  72. void ScriptBrowserWnd::setMainMB(int m) {
  73. if (m)
  74. MBManager::setMainMB(this);
  75. else
  76. if (MBManager::getMainMB() == this)
  77. MBManager::setMainMB(NULL);
  78. }
  79. int ScriptBrowserWnd::onBeforeNavigate(const char *url, int flags, const char *frame) {
  80. if (SCRIPTBROWSERWND_PARENT::onBeforeNavigate(url, flags, frame)) return 1;
  81. scriptVar v = script_vcpu_onBeforeNavigate(SCRIPT_CALL, getScriptObject(), MAKE_SCRIPT_STRING(url), MAKE_SCRIPT_INT(flags), MAKE_SCRIPT_STRING(frame));
  82. if (SOM::isNumeric(&v)) return GET_SCRIPT_BOOLEAN(v);
  83. return 0;
  84. }
  85. void ScriptBrowserWnd::onDocumentComplete(const char *url) {
  86. SCRIPTBROWSERWND_PARENT::onDocumentComplete(url);
  87. script_vcpu_onDocumentComplete(SCRIPT_CALL, getScriptObject(), MAKE_SCRIPT_STRING(url));
  88. }
  89. // VCPU
  90. scriptVar ScriptBrowserWnd::script_vcpu_gotoUrl(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar url) {
  91. SCRIPT_FUNCTION_INIT
  92. ASSERT(url.type == SCRIPT_STRING);
  93. ScriptBrowserWnd *sb = static_cast<ScriptBrowserWnd*>(o->vcpu_getInterface(browserGuid));
  94. if (sb) sb->navigateUrl(url.data.sdata);
  95. RETURN_SCRIPT_VOID;
  96. }
  97. scriptVar ScriptBrowserWnd::script_vcpu_back(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  98. SCRIPT_FUNCTION_INIT
  99. ScriptBrowserWnd *sb = static_cast<ScriptBrowserWnd*>(o->vcpu_getInterface(browserGuid));
  100. if (sb) sb->back();
  101. RETURN_SCRIPT_VOID;
  102. }
  103. scriptVar ScriptBrowserWnd::script_vcpu_forward(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  104. SCRIPT_FUNCTION_INIT
  105. ScriptBrowserWnd *sb = static_cast<ScriptBrowserWnd*>(o->vcpu_getInterface(browserGuid));
  106. if (sb) sb->forward();
  107. RETURN_SCRIPT_VOID;
  108. }
  109. scriptVar ScriptBrowserWnd::script_vcpu_home(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  110. SCRIPT_FUNCTION_INIT
  111. ScriptBrowserWnd *sb = static_cast<ScriptBrowserWnd*>(o->vcpu_getInterface(browserGuid));
  112. if (sb) sb->home();
  113. RETURN_SCRIPT_VOID;
  114. }
  115. scriptVar ScriptBrowserWnd::script_vcpu_refresh(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  116. SCRIPT_FUNCTION_INIT
  117. ScriptBrowserWnd *sb = static_cast<ScriptBrowserWnd*>(o->vcpu_getInterface(browserGuid));
  118. if (sb) sb->refresh();
  119. RETURN_SCRIPT_VOID;
  120. }
  121. scriptVar ScriptBrowserWnd::script_vcpu_stop(SCRIPT_FUNCTION_PARAMS, ScriptObject *o) {
  122. SCRIPT_FUNCTION_INIT
  123. ScriptBrowserWnd *sb = static_cast<ScriptBrowserWnd*>(o->vcpu_getInterface(browserGuid));
  124. if (sb) sb->stop();
  125. RETURN_SCRIPT_VOID;
  126. }
  127. scriptVar ScriptBrowserWnd::script_vcpu_setTargetName(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar name) {
  128. SCRIPT_FUNCTION_INIT
  129. ScriptBrowserWnd *sb = static_cast<ScriptBrowserWnd*>(o->vcpu_getInterface(browserGuid));
  130. if (sb) sb->setTargetName(GET_SCRIPT_STRING(name));
  131. RETURN_SCRIPT_VOID;
  132. }
  133. scriptVar ScriptBrowserWnd::script_vcpu_onBeforeNavigate(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar url, scriptVar flags, scriptVar framename) {
  134. SCRIPT_FUNCTION_INIT
  135. PROCESS_HOOKS3(o, browserController, url, flags, framename);
  136. SCRIPT_FUNCTION_CHECKABORTEVENT;
  137. SCRIPT_EXEC_EVENT3(o, url, flags, framename);
  138. }
  139. scriptVar ScriptBrowserWnd::script_vcpu_onDocumentComplete(SCRIPT_FUNCTION_PARAMS, ScriptObject *o, scriptVar url) {
  140. SCRIPT_FUNCTION_INIT
  141. PROCESS_HOOKS1(o, browserController, url);
  142. SCRIPT_FUNCTION_CHECKABORTEVENT;
  143. SCRIPT_EXEC_EVENT1(o, url);
  144. }