WebBrowser.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /******************************************************************************
  19. *
  20. * NAME
  21. * $Archive: /Commando/Code/Commando/WebBrowser.h $
  22. *
  23. * DESCRIPTION
  24. * Web Browser
  25. *
  26. * PROGRAMMER
  27. * Denzil E. Long, Jr.
  28. * $Author: Denzil_l $
  29. *
  30. * VERSION INFO
  31. * $Revision: 7 $
  32. * $Modtime: 1/15/02 3:06p $
  33. *
  34. ******************************************************************************/
  35. #ifndef __WEBBROWSER_H__
  36. #define __WEBBROWSER_H__
  37. #include "WOLBrowser\WOLBrowser.h"
  38. #include <WWLib\Notify.h>
  39. #include <atlbase.h>
  40. #include <windows.h>
  41. class WebBrowser;
  42. class WebEvent :
  43. public TypedEventPtr<WebEvent, WebBrowser>
  44. {
  45. public:
  46. typedef enum
  47. {
  48. None = 0, // NULL event
  49. Quit, // User initiated quit
  50. CertificationFailed, // Requested page failed certification.
  51. } EventID;
  52. //! Retrieve event
  53. inline EventID Event(void) const
  54. {return mEvent;}
  55. WebEvent(EventID event, WebBrowser* object) :
  56. TypedEventPtr<WebEvent, WebBrowser>(object),
  57. mEvent(event)
  58. {}
  59. protected:
  60. // Prevent copy and assignment
  61. WebEvent(const WebEvent&);
  62. const WebEvent& operator=(const WebEvent&);
  63. private:
  64. EventID mEvent;
  65. };
  66. class WebBrowser :
  67. public IWOLBrowserEvent,
  68. public Notifier<WebEvent>
  69. {
  70. public:
  71. // Initialize browser prerequisites.
  72. // NOTE: This is for development purpose only; The game installer should handle
  73. // these tasks.
  74. #ifdef _DEBUG
  75. static bool InstallPrerequisites(void);
  76. #endif
  77. //! Test if a web page is currently displayed
  78. static bool IsWebPageDisplayed(void);
  79. //! Create an instance of the embedded browser for Dune Emperor.
  80. static WebBrowser* CreateInstance(HWND window);
  81. //! Check if browser is embedded or external (True if embedded)
  82. bool UsingEmbeddedBrowser(void) const
  83. {return (mWOLBrowser != NULL);}
  84. //! Test if the external browser is running
  85. bool IsExternalBrowserRunning(void) const;
  86. //! Display the specified web content.
  87. bool ShowWebPage(char* page);
  88. //! Launch the external browser
  89. bool LaunchExternal(const char* url);
  90. //! Show the browser
  91. void Show(void);
  92. //! Hide the browser
  93. void Hide(void);
  94. //! Test if the browser is visible
  95. bool IsVisible(void) const
  96. {return mVisible;}
  97. protected:
  98. // Protected to prevent direct construction via new, use CreateInstance() instead.
  99. WebBrowser();
  100. virtual ~WebBrowser();
  101. // Protected to prevent copy and assignment
  102. WebBrowser(const WebBrowser&);
  103. const WebBrowser& operator=(const WebBrowser&);
  104. bool FinalizeCreate(HWND window);
  105. bool RetrievePageURL(const char* page, char* url, int size);
  106. bool RetrieveHTMLPath(char* path, int size);
  107. DECLARE_NOTIFIER(WebEvent)
  108. private:
  109. static WebBrowser* _mInstance;
  110. ULONG mRefCount;
  111. CComPtr<IWOLBrowser> mWOLBrowser;
  112. wchar_t mPendingURL[512];
  113. bool mVisible;
  114. PROCESS_INFORMATION mProcessInfo;
  115. bool mSwitchedMode;
  116. int mRestoreWidth;
  117. int mRestoreHeight;
  118. int mRestoreBits;
  119. //---------------------------------------------------------------------------
  120. // IUnknown methods
  121. //---------------------------------------------------------------------------
  122. public:
  123. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject);
  124. ULONG STDMETHODCALLTYPE AddRef(void);
  125. ULONG STDMETHODCALLTYPE Release(void);
  126. //---------------------------------------------------------------------------
  127. // IWOLBrowserEvent methods
  128. //---------------------------------------------------------------------------
  129. private:
  130. STDMETHOD(OnScriptQuit)(void);
  131. STDMETHOD(OnBeforeNavigate)(const wchar_t* url, const wchar_t* targetFrame);
  132. STDMETHOD(OnDocumentComplete)(const wchar_t* url, BOOL topFrame);
  133. STDMETHOD(OnDownloadBegin)(void);
  134. STDMETHOD(OnProgressChange)(LONG progress, LONG progressMax);
  135. STDMETHOD(OnDownloadComplete)(void);
  136. STDMETHOD(OnNavigateComplete)(const wchar_t* url);
  137. STDMETHOD(OnStatusTextChange)(const wchar_t* statusText);
  138. STDMETHOD(OnTitleChange)(const wchar_t* title);
  139. STDMETHOD(OnNewWindow)(void);
  140. STDMETHOD(OnShowMessage)(const wchar_t* text, const wchar_t* caption, ULONG type, LONG* result);
  141. STDMETHOD(OnFailedPageCertification)(void);
  142. STDMETHOD(OnErrorMsg)(const wchar_t* error);
  143. STDMETHOD(OnRegisterLogin)(const wchar_t* nick, const wchar_t* pass);
  144. };
  145. #endif // __WEBBROWSER_H__