IEWebGameCtrl.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // Torque 3D web deployment for Internet Explorer (ActiveX)
  23. #pragma once
  24. #include "resource.h" // main symbols
  25. #include <atlctl.h>
  26. #include "IEWebGamePlugin_i.h"
  27. #include "IEWebGameWindow.h"
  28. #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
  29. #error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
  30. #endif
  31. // The heavy lifting is done by our game control (which inherits from WebGameWindow)
  32. // CIEWebGameCtrl
  33. class ATL_NO_VTABLE CIEWebGameCtrl :
  34. public CComObjectRootEx<CComSingleThreadModel>,
  35. public CStockPropImpl<CIEWebGameCtrl, IIEWebGameCtrl>,
  36. public IPersistStreamInitImpl<CIEWebGameCtrl>,
  37. public IOleControlImpl<CIEWebGameCtrl>,
  38. public IOleObjectImpl<CIEWebGameCtrl>,
  39. public IOleInPlaceActiveObjectImpl<CIEWebGameCtrl>,
  40. public IViewObjectExImpl<CIEWebGameCtrl>,
  41. public IOleInPlaceObjectWindowlessImpl<CIEWebGameCtrl>,
  42. public IObjectSafetyImpl<CIEWebGameCtrl, INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
  43. public CComCoClass<CIEWebGameCtrl, &CLSID_IEWebGameCtrl>,
  44. public CComControl<CIEWebGameCtrl, WebGameWindow>
  45. {
  46. public:
  47. DECLARE_OLEMISC_STATUS(OLEMISC_RECOMPOSEONRESIZE |
  48. OLEMISC_CANTLINKINSIDE |
  49. OLEMISC_INSIDEOUT |
  50. OLEMISC_ACTIVATEWHENVISIBLE |
  51. OLEMISC_SETCLIENTSITEFIRST
  52. )
  53. DECLARE_REGISTRY_RESOURCEID(IDR_IEWEBGAMECTRL)
  54. BEGIN_COM_MAP(CIEWebGameCtrl)
  55. COM_INTERFACE_ENTRY(IIEWebGameCtrl)
  56. COM_INTERFACE_ENTRY(IDispatch)
  57. COM_INTERFACE_ENTRY(IViewObjectEx)
  58. COM_INTERFACE_ENTRY(IViewObject2)
  59. COM_INTERFACE_ENTRY(IViewObject)
  60. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  61. COM_INTERFACE_ENTRY(IOleInPlaceObject)
  62. COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
  63. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  64. COM_INTERFACE_ENTRY(IOleControl)
  65. COM_INTERFACE_ENTRY(IOleObject)
  66. COM_INTERFACE_ENTRY(IPersistStreamInit)
  67. COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
  68. COM_INTERFACE_ENTRY_IID(IID_IObjectSafety, IObjectSafety)
  69. END_COM_MAP()
  70. BEGIN_PROP_MAP(CIEWebGameCtrl)
  71. PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
  72. PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
  73. // Example entries
  74. // PROP_ENTRY_TYPE("Property Name", dispid, clsid, vtType)
  75. // PROP_PAGE(CLSID_StockColorPage)
  76. END_PROP_MAP()
  77. BEGIN_MSG_MAP(WebGameWindow)
  78. CHAIN_MSG_MAP(WebGameWindow)
  79. DEFAULT_REFLECTION_HANDLER()
  80. END_MSG_MAP()
  81. // Handler prototypes:
  82. // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  83. // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  84. // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  85. // IViewObjectEx
  86. DECLARE_VIEW_STATUS(0)
  87. // IIEWebGameCtrl
  88. public:
  89. static CIEWebGameCtrl* sInstance;
  90. CIEWebGameCtrl()
  91. {
  92. m_bWindowOnly = TRUE;
  93. sInstance = this;
  94. mInitialized = false;
  95. }
  96. DECLARE_PROTECT_FINAL_CONSTRUCT()
  97. HRESULT FinalConstruct()
  98. {
  99. return S_OK;
  100. }
  101. void FinalRelease()
  102. {
  103. }
  104. // the javascript accessible methods which can be called our on plugin object
  105. // plugin.getVariable("$MyVariable"); - get a Torque 3D console variable
  106. STDMETHOD(getVariable)(BSTR name, BSTR* value);
  107. // plugin.setVariable("$MyVariable", 42); - set a Torque 3D console variable
  108. STDMETHOD(setVariable)(BSTR name, BSTR value);
  109. // var result = plugin.callScript("mySecureFunction('one', 'two', 'three');"); - call a TorqueScript function marked as secure in webConfig.h with supplied arguments
  110. STDMETHOD(callScript)(BSTR code, BSTR* retValue);
  111. // plugin.exportFunction("MyJavascriptFunction",3); - export a Javascript function to the Torque 3D console system via its name and argument count
  112. STDMETHOD(exportFunction)(BSTR name, LONG numArguments);
  113. // plugin.startup(); - called once web page is fully loaded and plugin (including Torque 3D) is initialized
  114. STDMETHOD(startup)();
  115. // TorqueScript -> Javascript call handling
  116. const char* callFunction(const char* name, LONG numArguments, const char* argv[]);
  117. // our plugin requires no signing as it is installer based
  118. STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions);
  119. STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions);
  120. protected:
  121. // these can be added on the page before we're initialized, so we cache them at startup
  122. typedef struct JavasScriptExport
  123. {
  124. std::string jsCallback; //javascript function name
  125. UINT numArguments; //the number of arguments it takes
  126. };
  127. std::vector<JavasScriptExport> mJavaScriptExports;
  128. // actually handle the export (once Torque 3D is fully initialized)
  129. void internalExportFunction(const JavasScriptExport& jsexport);
  130. BOOL mInitialized;
  131. // checks a given domain against the allowed domains in webConfig.h
  132. bool checkDomain();
  133. };
  134. OBJECT_ENTRY_AUTO(__uuidof(IEWebGameCtrl), CIEWebGameCtrl)