PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/AI_Patch/src/vgui2/chromehtml/html_chrome.h

#
C++ Header | 637 lines | 509 code | 90 blank | 38 comment | 22 complexity | 1a6be413940e5ab26713af6521fad695 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef HTML_CHROME_H
  6. #define HTML_CHROME_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. #include "cef/include/cef_render_handler.h"
  11. #include "cef/include/cef_client.h"
  12. #include "cef/include/cef_app.h"
  13. #include "cef/include/cef_browser.h"
  14. #include "cef/include/cef_command_line.h"
  15. #include "cef/include/cef_frame.h"
  16. #include "cef/include/cef_runnable.h"
  17. #include "cef/include/cef_web_urlrequest.h"
  18. #include "cef/include/cef_request_handler.h"
  19. #include "cef/include/cef_load_handler.h"
  20. #include "cef/include/cef_display_handler.h"
  21. #include "cef/include/cef_life_span_handler.h"
  22. #include "cef/include/cef_render_handler.h"
  23. #include "tier0/platform.h"
  24. #include "tier0/vprof.h"
  25. #include "tier1/utlarray.h"
  26. #include "tier1/utlbuffer.h"
  27. #include "fileio.h"
  28. //#include "constants.h"
  29. #include "tier0/validator.h"
  30. #include "tier1/utlmap.h"
  31. #include "tier1/utlstring.h"
  32. #include "tier0/tslist.h"
  33. #include "html/ihtmlchrome.h"
  34. #include "html/htmlprotobuf.h"
  35. // These must be undefed so that the MacOS build will work -- their STL
  36. // fails if min and max are defined. I'm undefing them in all builds to
  37. // avoid having a Windows dependency on min/max creep in.
  38. #undef min
  39. #undef max
  40. #include "htmlmessages.pb.h"
  41. class CClientHandler;
  42. class CChromePainter;
  43. class ICookieCallback;
  44. bool ChromeSetWebCookie( const char *pchHostname, const char *pchName, const char *pchValue, const char *pchPath, RTime32 nExpires );
  45. bool ChromeGetWebCookiesForURL( CUtlString *pstrValue, const char *pchURL, const char *pchName );
  46. //-----------------------------------------------------------------------------
  47. // Purpose: track dirty rects, shuttle bits between renderer and main thread
  48. //-----------------------------------------------------------------------------
  49. class CChromeUpdateRegion
  50. {
  51. public:
  52. CChromeUpdateRegion() { MarkAllClean(); }
  53. int GetUpdateX( int clampWide ) const { return clamp( m_nUpdateX0, 0, clampWide ); }
  54. int GetUpdateY( int clampTall ) const { return clamp( m_nUpdateY0, 0, clampTall ); }
  55. int GetUpdateWide( int clampWide ) const { return clamp( m_nUpdateX1, 0, clampWide ) - GetUpdateX( clampWide ); }
  56. int GetUpdateTall( int clampTall ) const { return clamp( m_nUpdateY1, 0, clampTall ) - GetUpdateY( clampTall ); }
  57. void MarkAllClean() { m_nUpdateX0 = m_nUpdateY0 = INT_MAX; m_nUpdateX1 = m_nUpdateY1 = 0; }
  58. void MarkAllDirty() { m_nUpdateX0 = m_nUpdateY0 = 0; m_nUpdateX1 = m_nUpdateY1 = INT_MAX; }
  59. void MarkDirtyRect( int x0, int y0, int x1, int y1 )
  60. {
  61. if ( x0 >= x1 || y0 >= y1 ) return;
  62. if ( m_nUpdateX0 > x0 ) m_nUpdateX0 = x0;
  63. if ( m_nUpdateY0 > y0 ) m_nUpdateY0 = y0;
  64. if ( m_nUpdateX1 < x1 ) m_nUpdateX1 = x1;
  65. if ( m_nUpdateY1 < y1 ) m_nUpdateY1 = y1;
  66. }
  67. void MarkDirtyRect( const CChromeUpdateRegion& other )
  68. {
  69. MarkDirtyRect( other.m_nUpdateX0, other.m_nUpdateY0, other.m_nUpdateX1, other.m_nUpdateY1 );
  70. }
  71. protected:
  72. int m_nUpdateX0;
  73. int m_nUpdateY0;
  74. int m_nUpdateX1;
  75. int m_nUpdateY1;
  76. };
  77. class CChromeRenderBuffer : public CChromeUpdateRegion
  78. {
  79. public:
  80. CChromeRenderBuffer() { m_nWide = m_nTall = 0; }
  81. void SetSize( int wide, int tall )
  82. {
  83. if ( wide != m_nWide || tall != m_nTall )
  84. {
  85. m_nWide = wide;
  86. m_nTall = tall;
  87. MarkAllDirty();
  88. m_Texture.EnsureCapacity( wide * tall * 4 );
  89. }
  90. }
  91. int GetWide() const { return m_nWide; }
  92. int GetTall() const { return m_nTall; }
  93. byte *GetPixels() { return m_Texture.Base(); }
  94. bool BUpdatePixels( byte *pOther, int wide, int tall )
  95. {
  96. SetSize( wide, tall );
  97. int x0 = clamp( m_nUpdateX0, 0, wide );
  98. int y0 = clamp( m_nUpdateY0, 0, tall );
  99. int x1 = clamp( m_nUpdateX1, 0, wide );
  100. int y1 = clamp( m_nUpdateY1, 0, tall );
  101. if ( x0 >= x1 || y0 >= y1 )
  102. return false;
  103. if ( x0 == 0 && x1 == wide )
  104. {
  105. byte *pDst = GetPixels() + y0*wide*4;
  106. byte *pSrc = pOther + y0*wide*4;
  107. Q_memcpy( pDst, pSrc, wide * ( y1 - y0 ) * 4 );
  108. }
  109. else
  110. {
  111. byte *pDst = GetPixels() + y0*wide*4 + x0*4;
  112. byte *pSrc = pOther + y0*wide*4 + x0*4;
  113. int nCopyBytesPerRow = (x1 - x0)*4;
  114. for ( int rows = y1 - y0; rows > 0; --rows )
  115. {
  116. Q_memcpy( pDst, pSrc, nCopyBytesPerRow );
  117. pSrc += wide * 4;
  118. pDst += wide * 4;
  119. }
  120. }
  121. return true;
  122. }
  123. #ifdef DBGFLAG_VALIDATE
  124. virtual void Validate( CValidator &validator, const char *pchName )
  125. {
  126. VALIDATE_SCOPE();
  127. ValidateObj( m_Texture );
  128. }
  129. #endif
  130. protected:
  131. int m_nWide; // dimensions of the buffer
  132. int m_nTall;
  133. CUtlVector<byte> m_Texture; // rgba data
  134. };
  135. //-----------------------------------------------------------------------------
  136. // Purpose: interface Chrome uses to send up paint messages
  137. //-----------------------------------------------------------------------------
  138. class CChromePainter : public CefRenderHandler
  139. {
  140. public:
  141. CChromePainter( CClientHandler *pParent );
  142. ~CChromePainter();
  143. virtual bool GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) OVERRIDE { return false; }
  144. virtual bool GetScreenRect(CefRefPtr<CefBrowser> browser, CefRect& rect) OVERRIDE { return false; }
  145. virtual bool GetScreenPoint(CefRefPtr<CefBrowser> browser, int viewX, int viewY, int& screenX, int& screenY) OVERRIDE { return false; }
  146. virtual void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) OVERRIDE;
  147. virtual void OnPopupSize(CefRefPtr<CefBrowser> browser, const CefRect& rect) OVERRIDE;
  148. virtual void OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList& dirtyRects, const void* buffer) OVERRIDE;
  149. virtual void OnCursorChange(CefRefPtr<CefBrowser> browser, CefCursorHandle cursor) OVERRIDE {}
  150. virtual bool OnSetCursor( CefRefPtr<CefBrowser> browser, const CursorType type, const void *pchIconData, int iWide, int iTall, int xHotSpot, int yHotSpot ) OVERRIDE;
  151. virtual bool OnFileOpenDialog( CefRefPtr<CefBrowser> browser, bool bMultiSelect, const CefString &default_title, const CefString &default_file, CefWebFileChooserCallback *pCallback ) OVERRIDE;
  152. virtual bool OnEnterFullScreen( CefRefPtr<CefBrowser> browser ) OVERRIDE;
  153. virtual bool OnExitFullScreen( CefRefPtr<CefBrowser> browser ) OVERRIDE;
  154. bool BUpdated();
  155. void SetUpdated( bool state );
  156. int GetPopupTall() const { return m_nPopupTall; }
  157. int GetPopupWide() const { return m_nPopupWide; }
  158. int GetPopupX() const { return m_nPopupX; }
  159. int GetPopupY() const { return m_nPopupY; }
  160. const byte *PPopupTextureData()
  161. {
  162. return m_PopupTexture.Base();
  163. }
  164. uint32 FlipTexture();
  165. void SetTextureUploaded( uint32 id );
  166. bool BPaintBufferAvailable();
  167. byte *PComposedTextureData( uint32 iTexture );
  168. int GetTall() const { return m_MainTexture.GetTall(); }
  169. int GetWide() const { return m_MainTexture.GetWide(); }
  170. int GetUpdateX() const { return m_UpdateRect.GetUpdateX( GetWide() ); }
  171. int GetUpdateY() const { return m_UpdateRect.GetUpdateY( GetTall() ); }
  172. int GetUpdateWide() const { return m_UpdateRect.GetUpdateWide( GetWide() ); }
  173. int GetUpdateTall() const { return m_UpdateRect.GetUpdateTall( GetTall() ); }
  174. void ClearUpdateRect() { m_UpdateRect.MarkAllClean(); }
  175. // XXX not shuttled safely between threads, should use real buffering
  176. const byte *PPopupTextureDataCached();
  177. bool BPopupVisible() const { return m_bPopupVisible; }
  178. // WebKit will show popups before they have been given a size and painted and we may do
  179. // a drawing pass during that time, so we want to make sure to only do something
  180. // with the popup when it has an actual size and content.
  181. bool BPopupVisibleAndPainted() const
  182. {
  183. return m_bPopupVisible &&
  184. m_nPopupWide != 0 &&
  185. m_nPopupTall != 0 &&
  186. m_PopupTexture.Count() >= m_nPopupWide * m_nPopupTall * 4;
  187. }
  188. void PopupRect( int &x, int &y, int &wide, int &tall ) const { x = m_nPopupX; y = m_nPopupY; wide = m_nPopupWide; tall = m_nPopupTall; }
  189. #ifdef DBGFLAG_VALIDATE
  190. virtual void Validate( CValidator &validator, const char *pchName )
  191. {
  192. VALIDATE_SCOPE();
  193. for ( int i = 0; i < Q_ARRAYSIZE(m_Texture); i++ )
  194. ValidateObj( m_Texture[i] );
  195. ValidateObj( m_PopupTextureCache );
  196. ValidateObj( m_PopupTexture );
  197. ValidateObj( m_MainTexture );
  198. }
  199. #endif
  200. IMPLEMENT_REFCOUNTING(CChromePainter);
  201. private:
  202. uint32 m_iNextTexture;
  203. uint32 m_iTexturesInFlightBits;
  204. int m_nPopupWide;
  205. int m_nPopupTall;
  206. CChromeRenderBuffer m_MainTexture;
  207. CChromeRenderBuffer m_Texture[2]; // buffering -- XXX should use atomic swap, not push multiple buffers to command buffer
  208. CChromeUpdateRegion m_UpdateRect;
  209. CUtlVector<byte> m_PopupTextureCache;
  210. CUtlVector<byte> m_PopupTexture;
  211. bool m_bUpdated;
  212. CClientHandler *m_pParent;
  213. bool m_bPopupVisible;
  214. int m_nPopupX, m_nPopupY;
  215. };
  216. //-----------------------------------------------------------------------------
  217. // Purpose: CEF callback object
  218. //-----------------------------------------------------------------------------
  219. class CClientHandler : public CefClient,
  220. public CefLifeSpanHandler,
  221. public CefLoadHandler,
  222. public CefRequestHandler,
  223. public CefDisplayHandler,
  224. public CefJSDialogHandler,
  225. public CefFindHandler,
  226. public CefMenuHandler,
  227. public CefFocusHandler,
  228. public CefPermissionHandler
  229. {
  230. public:
  231. CClientHandler( int iBrowser, const char *pchUserAgent, uint16 nSerial );
  232. ~CClientHandler();
  233. // CefClient methods
  234. virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
  235. return this;
  236. }
  237. virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
  238. return this;
  239. }
  240. virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
  241. return this;
  242. }
  243. virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
  244. return this;
  245. }
  246. virtual CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE {
  247. return &m_Painter;
  248. }
  249. virtual CefRefPtr<CefFocusHandler> GetFocusHandler() OVERRIDE {
  250. return this;
  251. }
  252. virtual CefRefPtr<CefMenuHandler> GetMenuHandler() OVERRIDE {
  253. return this;
  254. }
  255. virtual CefRefPtr<CefPermissionHandler> GetPermissionHandler() OVERRIDE {
  256. return this;
  257. }
  258. virtual CefRefPtr<CefFindHandler> GetFindHandler() OVERRIDE {
  259. return this;
  260. }
  261. virtual CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() OVERRIDE {
  262. return this;
  263. }
  264. // CefLifeSpanHandler methods
  265. virtual bool OnBeforePopup(CefRefPtr<CefBrowser> parentBrowser, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, const CefString& url, CefRefPtr<CefClient>& client, CefBrowserSettings& settings) OVERRIDE;
  266. virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
  267. virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
  268. virtual bool DoClose(CefRefPtr<CefBrowser> browser) { return false; }
  269. virtual bool OnNewTab(CefRefPtr<CefBrowser> parentBrowser, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, const CefString& url, bool bForeground, CefRefPtr<CefClient>& client, CefBrowserSettings& settings );
  270. // CefLoadHandler methods
  271. virtual void OnLoadStart(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, bool bIsNewNavigation ) OVERRIDE;
  272. virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode, CefRefPtr<CefRequest> request ) OVERRIDE;
  273. virtual bool OnLoadError(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, ErrorCode errorCode, const CefString& failedUrl, CefString& errorText);
  274. // CefRequestHandler methods
  275. virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, NavType navType, bool isRedirect, bool isNewTabRequest );
  276. virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefRequest> request, CefString& redirectUrl, CefRefPtr<CefStreamReader>& resourceStream, CefRefPtr<CefResponse> response, int loadFlags);
  277. // CefDisplayHandler methods
  278. virtual void OnNavStateChange(CefRefPtr<CefBrowser> browser, bool canGoBack, bool canGoForward) OVERRIDE {}
  279. virtual void OnAddressChange(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& url) OVERRIDE { }
  280. virtual void OnTitleChange(CefRefPtr<CefBrowser> browser, const CefString& title) OVERRIDE;
  281. virtual bool OnTooltip(CefRefPtr<CefBrowser> browser, CefString& text);
  282. virtual void OnStatusMessage(CefRefPtr<CefBrowser> browser, const CefString& value, StatusType type);
  283. virtual bool OnConsoleMessage(CefRefPtr<CefBrowser> browser, const CefString& message, const CefString& source, int line);
  284. virtual void OnTakeFocus(CefRefPtr<CefBrowser> browser, bool next) {}
  285. virtual bool OnSetFocus(CefRefPtr<CefBrowser> browser, FocusSource source) { return true; }
  286. virtual void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefDOMNode> node);
  287. virtual bool OnBeforeMenu(CefRefPtr<CefBrowser> browser, const CefMenuInfo& menuInfo) { return true; }
  288. virtual void GetMenuLabel(CefRefPtr<CefBrowser> browser, MenuId menuId, CefString& label) {}
  289. virtual bool OnMenuAction(CefRefPtr<CefBrowser> browser, MenuId menuId) { return true; }
  290. virtual bool OnBeforeScriptExtensionLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& extensionName) { return false; }
  291. virtual void OnFindResult(CefRefPtr<CefBrowser> browser, int identifier, int count, const CefRect& selectionRect, int activeMatchOrdinal, bool finalUpdate);
  292. virtual bool OnJSAlert(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& message);
  293. virtual bool OnJSConfirm(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& message, bool& retval);
  294. virtual bool OnJSPrompt(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString& message, const CefString& defaultValue, bool& retval, CefString& result);
  295. void FileOpenDialogResult( const char *pchFileName );
  296. // paint helpers
  297. void Paint();
  298. bool BNeedsPaint();
  299. int GetTextureTall() const { return m_Painter.GetTall(); }
  300. int GetTextureWide() const { return m_Painter.GetWide(); }
  301. int GetUpdateX() const { return m_Painter.GetUpdateX(); }
  302. int GetUpdateY() const { return m_Painter.GetUpdateY(); }
  303. int GetUpdateWide() const { return m_Painter.GetUpdateWide(); }
  304. int GetUpdateTall() const { return m_Painter.GetUpdateTall(); }
  305. const byte *PPopupTextureDataCached() { return m_Painter.PPopupTextureDataCached(); }
  306. bool BPopupVisible() const { return m_Painter.BPopupVisible(); }
  307. bool BPopupVisibleAndPainted() const { return m_Painter.BPopupVisibleAndPainted(); }
  308. void PopupRect( int &x, int &y, int &wide, int &tall ) const { m_Painter.PopupRect( x, y, wide, tall ); }
  309. const byte *PComposedTextureData( uint32 iTexture );
  310. uint32 FlipTexture() { return m_Painter.FlipTexture(); }
  311. void SetTextureUploaded( uint32 iTexture ) { m_Painter.SetTextureUploaded( iTexture ); }
  312. void ClearUpdateRect() { m_Painter.ClearUpdateRect(); }
  313. bool BPaintBufferReady() { return m_Painter.BPaintBufferAvailable(); }
  314. // Helpers
  315. CefRefPtr<CefBrowser> GetBrowser();
  316. void CloseBrowser();
  317. uint32 GetPageSerial() { return m_nPageSerial; }
  318. void SetPendingPageSerial( uint32 nPageSerial )
  319. {
  320. m_nPendingPageSerial = nPageSerial;
  321. }
  322. void SetUserAgent( const char *pchAgent ) { Q_strncpy( m_szUserAgentExtras, pchAgent, sizeof(m_szUserAgentExtras) ); }
  323. const char *PchCurrentURL() { return m_strCurrentUrl.String(); }
  324. bool IsVisuallyNonEmpty();
  325. void SetErrorStrings( const char *pchTitle, const char *pchHeader, const char *pchCacheMiss, const char *pchBadURL, const char *pchConnectionProblem,
  326. const char *pchProxyProblem, const char *pchUnknown );
  327. void SetMouseLocation( int x, int y );
  328. void GetMouseLocation( int &x, int &y ) { x = m_nMouseX; y = m_nMouseY; }
  329. void SetMouseFocus( bool bFocus ) { m_bMouseFocus = bFocus; }
  330. void SetSize( int wide, int tall ) { m_nExpectedWide = wide; m_nExpectedTall = tall; }
  331. void GetExpectedSize( int &wide, int &tall ) { wide = m_nExpectedWide; tall =m_nExpectedTall; }
  332. //-----------------------------------------------------------------------------
  333. // Purpose: Adds a custom header to all requests
  334. //-----------------------------------------------------------------------------
  335. void AddHeader( const char *pchHeader, const char *pchValue )
  336. {
  337. m_vecHeaders.AddToTail( std::make_pair( CStrAutoEncode( pchHeader ).ToWString(), CStrAutoEncode( pchValue ).ToWString() ) );
  338. }
  339. void RequestScreenShot( const CHTMLProtoBufMsg<CMsgSavePageToJPEG> &cmd );
  340. void SavePageToJPEGIfNeeded( CefRefPtr<CefBrowser> browser, const byte *pRGBA, int wide, int tall );
  341. bool BPendingScreenShot()
  342. {
  343. return m_Snapshot.m_flRequestTimeout > 0.0f && m_Snapshot.m_sURLSnapshot.IsValid() && m_Snapshot.m_flRequestTimeout < Plat_FloatTime();
  344. }
  345. void SetUserAgentIdentifier( const char *pchIdent )
  346. {
  347. m_strUserAgentIdentifier = pchIdent;
  348. }
  349. uint16 NSerial() { return m_nSerial; }
  350. void RefreshCEFHoverStatesAfterScroll();
  351. #ifdef DBGFLAG_VALIDATE
  352. virtual void Validate( CValidator &validator, const char *pchName )
  353. {
  354. VALIDATE_SCOPE();
  355. ValidateObj( m_strCurrentUrl );
  356. ValidateObj( m_strPostData );
  357. ValidateObj( m_strLastRedirectURL );
  358. ValidateObj( m_vecHeaders );
  359. ValidateObj( m_strUserAgent );
  360. ValidateObj( m_Painter );
  361. ValidateObj( m_sErrorTitle );
  362. ValidateObj( m_sErrorHeader );
  363. ValidateObj( m_sErrorCacheMiss );
  364. ValidateObj( m_sErrorBadURL );
  365. ValidateObj( m_sErrorConnectionProblem );
  366. ValidateObj( m_sErrorProxyProblem );
  367. ValidateObj( m_sErrorUnknown );
  368. ValidateObj( m_strUserAgentIdentifier );
  369. // ValidateObj( m_vecHCursor );
  370. }
  371. #endif
  372. IMPLEMENT_REFCOUNTING(CClientHandler);
  373. IMPLEMENT_LOCKING(CClientHandler);
  374. private:
  375. friend class CChromePainter;
  376. friend class CCEFThread;
  377. void SetBrowserAgent( CefRefPtr<CefBrowser> browser );
  378. // The child browser window
  379. CefRefPtr<CefBrowser> m_Browser;
  380. CefRenderHandler::CefWebFileChooserCallback *m_pOpenFileCallback;
  381. uint16 m_nSerial;
  382. char m_szUserAgentExtras[ 256 ];
  383. CUtlString m_strCurrentUrl;
  384. CUtlString m_strPostData;
  385. CUtlString m_strLastRedirectURL;
  386. CUtlString m_strUserAgent;
  387. CUtlString m_strUserAgentIdentifier;
  388. CUtlString m_strToolTip;
  389. bool m_bShowingToolTip;
  390. bool m_bPendingPaint;
  391. bool m_bBrowserClosing;
  392. bool m_bMouseFocus;
  393. CChromePainter m_Painter;
  394. CUtlVector< std::pair< std::wstring, std::wstring > > m_vecHeaders;
  395. int m_iBrowser;
  396. int m_nExpectedWide;
  397. int m_nExpectedTall;
  398. uint32 m_nPageSerial;
  399. uint32 m_nPendingPageSerial;
  400. CUtlString m_sErrorTitle;
  401. CUtlString m_sErrorHeader;
  402. CUtlString m_sErrorCacheMiss;
  403. CUtlString m_sErrorBadURL;
  404. CUtlString m_sErrorConnectionProblem;
  405. CUtlString m_sErrorProxyProblem;
  406. CUtlString m_sErrorUnknown;
  407. int m_nMouseX;
  408. int m_nMouseY;
  409. int m_nMouseScrolledX;
  410. int m_nMouseScrolledY;
  411. struct SnapshotData_t
  412. {
  413. CUtlString m_sURLSnapshot;
  414. CUtlString m_sFileNameSnapshot;
  415. int m_nWide, m_nTall;
  416. float m_flRequestTimeout;
  417. };
  418. SnapshotData_t m_Snapshot;
  419. // Scroll bar state is cached and compared to CEF's current values every frame;
  420. // any changes are passed on to the client handler as serialized update messages.
  421. struct CachedScrollBarState_t
  422. {
  423. int m_nX;
  424. int m_nY;
  425. int m_nWide;
  426. int m_nTall;
  427. int m_nMax;
  428. int m_nScroll;
  429. int m_bVisible; // using 'int' to avoid padding bytes so memcmp can be used
  430. };
  431. CachedScrollBarState_t m_CachedVScroll;
  432. CachedScrollBarState_t m_CachedHScroll;
  433. };
  434. //-----------------------------------------------------------------------------
  435. // Purpose: CEF thinking thread
  436. //-----------------------------------------------------------------------------
  437. class CCEFThread : public CValidatableThread
  438. {
  439. public:
  440. CCEFThread();
  441. ~CCEFThread();
  442. void SetCEFPaths( const char *pchHTMLCacheDir, const char *pchCookiePath );
  443. void TriggerShutdown();
  444. void WakeThread();
  445. virtual int Run();
  446. bool BHasPendingMessages() { return m_tslResponseBuffers.Count() > 0; }
  447. HTMLCommandBuffer_t *GetFreeCommandBuffer( EHTMLCommands eCmd, int iBrowser );
  448. void ReleaseCommandBuffer( HTMLCommandBuffer_t *pBuf );
  449. void PushCommand( HTMLCommandBuffer_t * );
  450. void PushResponse( HTMLCommandBuffer_t * );
  451. bool GetMainThreadCommand( HTMLCommandBuffer_t ** );
  452. HTMLCommandBuffer_t *BWaitForCommand( EHTMLCommands eCmd, int iBrowser );
  453. HTMLCommandBuffer_t *BWaitForResponse( EHTMLCommands eCmd, int iBrowser );
  454. bool GetCEFThreadCommand( HTMLCommandBuffer_t **pBuf );
  455. #ifdef DBGFLAG_VALIDATE
  456. virtual void SleepForValidate() { CValidatableThread::SleepForValidate(); m_evWaitingForCommand.Set(); WakeThread(); }
  457. virtual void Validate( CValidator &validator, const tchar *pchName );
  458. #endif
  459. private:
  460. void RunCurrentCommands();
  461. const char *PchWebkitUserAgent();
  462. void AppGetSettings(CefSettings& settings, CefRefPtr<CefApp>& app);
  463. void CleanupTempFolders();
  464. void ThreadCreateBrowser( const CHTMLProtoBufMsg<CMsgBrowserCreate> &htmlCommand );
  465. void ThreadRemoveBrowser( const CHTMLProtoBufMsg<CMsgBrowserRemove> &htmlCommand );
  466. void ThreadBrowserSize( const CHTMLProtoBufMsg<CMsgBrowserSize> &htmlCommand );
  467. void ThreadBrowserPosition( const CHTMLProtoBufMsg<CMsgBrowserPosition> &htmlCommand );
  468. void ThreadBrowserPostURL( const CHTMLProtoBufMsg<CMsgPostURL> &htmlCommand );
  469. void ThreadBrowserStopLoad( const CHTMLProtoBufMsg<CMsgStopLoad> &htmlCommand );
  470. void ThreadBrowserReload( const CHTMLProtoBufMsg<CMsgReload> &htmlCommand );
  471. void ThreadBrowserGoForward( const CHTMLProtoBufMsg<CMsgGoForward> &htmlCommand );
  472. void ThreadBrowserGoBack( const CHTMLProtoBufMsg<CMsgGoBack> &htmlCommand );
  473. void ThreadBrowserCopy( const CHTMLProtoBufMsg<CMsgCopy> &htmlCommand );
  474. void ThreadBrowserPaste( const CHTMLProtoBufMsg<CMsgPaste> &htmlCommand );
  475. void ThreadBrowserExecuteJavascript( const CHTMLProtoBufMsg<CMsgExecuteJavaScript> &htmlCommand );
  476. void ThreadBrowserSetFocus( const CHTMLProtoBufMsg<CMsgSetFocus> &htmlCommand );
  477. void ThreadBrowserHorizontalScrollBarSize( const CHTMLProtoBufMsg<CMsgHorizontalScrollBarSize> &htmlCommand );
  478. void ThreadBrowserVerticalScrollBarSize( const CHTMLProtoBufMsg<CMsgVerticalScrollBarSize> &htmlCommand );
  479. void ThreadBrowserFind( const CHTMLProtoBufMsg<CMsgFind> &htmlCommand );
  480. void ThreadBrowserStopFind( const CHTMLProtoBufMsg<CMsgStopFind> &htmlCommand );
  481. void ThreadBrowserSetHorizontalScroll( const CHTMLProtoBufMsg<CMsgSetHorizontalScroll> &htmlCommand );
  482. void ThreadBrowserSetVerticalScroll( const CHTMLProtoBufMsg<CMsgSetVerticalScroll> &htmlCommand );
  483. void ThreadBrowserSetZoomLevel( const CHTMLProtoBufMsg<CMsgSetZoomLevel> &htmlCommand );
  484. void ThreadBrowserViewSource( const CHTMLProtoBufMsg<CMsgViewSource> &htmlCommand );
  485. void ThreadNeedsPaintResponse( const CHTMLProtoBufMsg<CMsgNeedsPaintResponse> &htmlCommand );
  486. void ThreadBrowserErrorStrings( const CHTMLProtoBufMsg<CMsgBrowserErrorStrings> &htmlCommand );
  487. void ThreadAddHeader( const CHTMLProtoBufMsg<CMsgAddHeader> &htmlCommand );
  488. void ThreadGetZoom( const CHTMLProtoBufMsg<CMsgGetZoom> &htmlCommand );
  489. void ThreadHidePopup( const CHTMLProtoBufMsg<CMsgHidePopup> &htmlCommand );
  490. void ThreadGetCookiesForURL( const CHTMLProtoBufMsg<CMsgGetCookiesForURL> &htmlCommand );
  491. void ThreadKeyDown( const CHTMLProtoBufMsg<CMsgKeyDown> &htmlCommand );
  492. void ThreadKeyUp( const CHTMLProtoBufMsg<CMsgKeyUp> &htmlCommand );
  493. void ThreadKeyTyped( const CHTMLProtoBufMsg<CMsgKeyChar> &htmlCommand );
  494. void ThreadMouseButtonDown( const CHTMLProtoBufMsg<CMsgMouseDown> &htmlCommand );
  495. void ThreadMouseButtonUp( const CHTMLProtoBufMsg<CMsgMouseUp> &htmlCommand );
  496. void ThreadMouseButtonDlbClick( const CHTMLProtoBufMsg<CMsgMouseDblClick> &htmlCommand );
  497. void ThreadMouseWheel( const CHTMLProtoBufMsg<CMsgMouseWheel> &htmlCommand );
  498. void ThreadMouseMove( const CHTMLProtoBufMsg<CMsgMouseMove> &htmlCommand );
  499. void ThreadMouseLeave( const CHTMLProtoBufMsg<CMsgMouseLeave> &htmlCommand );
  500. void ThreadLinkAtPosition( const CHTMLProtoBufMsg<CMsgLinkAtPosition> &htmlCommand );
  501. void ThreadZoomToElementAtPosition( const CHTMLProtoBufMsg<CMsgZoomToElementAtPosition> &htmlCommand );
  502. void ThreadZoomToFocusedElement( const CHTMLProtoBufMsg<CMsgZoomToFocusedElement> &htmlCommand );
  503. void ThreadSavePageToJPEG( const CHTMLProtoBufMsg<CMsgSavePageToJPEG> &htmlCommand );
  504. void ThreadSetCookie( const CHTMLProtoBufMsg<CMsgSetCookie> &htmlCommand );
  505. void ThreadSetTargetFrameRate( const CHTMLProtoBufMsg<CMsgSetTargetFrameRate> &htmlCommand );
  506. void ThreadFullRepaint( const CHTMLProtoBufMsg<CMsgFullRepaint> &htmlCommand );
  507. void ThreadSetPageScale( const CHTMLProtoBufMsg<CMsgScalePageToValue> &htmlCommand );
  508. void ThreadExitFullScreen( const CHTMLProtoBufMsg<CMsgExitFullScreen> &htmlCommand );
  509. void ThreadCloseFullScreenFlashIfOpen( const CHTMLProtoBufMsg<CMsgCloseFullScreenFlashIfOpen> &htmlCommand );
  510. void ThreadPauseFullScreenFlashMovieIfOpen( const CHTMLProtoBufMsg<CMsgPauseFullScreenFlashMovieIfOpen> &htmlCommand );
  511. void ThreadGetFocusedNodeText( const CHTMLProtoBufMsg<CMsgFocusedNodeText> &htmlCommand );
  512. void ThreadBrowserVerticalScrollBarSizeHelper( int iBrowser, bool bForceSendUpdate );
  513. void ThreadBrowserHorizontalScrollBarSizeHelper( int iBrowser, bool bForceSendUpdate );
  514. bool BIsValidBrowserHandle( uint32 nHandle, int &iClient );
  515. void SendSizeChangeEvents();
  516. void CheckForFullScreenFlashControl();
  517. CThreadEvent m_WakeEvent;
  518. CUtlString m_sHTMLCacheDir;
  519. CUtlString m_sCookiePath;
  520. bool m_bExit;
  521. CThreadEvent m_eventDidExit;
  522. CUtlLinkedList<CClientHandler *> m_listClientHandlers;
  523. CTSQueue<HTMLCommandBuffer_t*> m_tslCommandBuffers;
  524. CUtlVector<HTMLCommandBuffer_t*> m_vecQueueCommands;
  525. CTSQueue<HTMLCommandBuffer_t*> m_tslResponseBuffers;
  526. CUtlVector<HTMLCommandBuffer_t*> m_vecQueueResponses;
  527. CTSList<HTMLCommandBuffer_t*> m_tslUnsedBuffers;
  528. CThreadEvent m_evWaitingForCommand;
  529. CThreadEvent m_evWaitingForResponse;
  530. int m_nTargetFrameRate;
  531. uint16 m_nBrowserSerial;
  532. bool m_bFullScreenFlashVisible;
  533. #ifdef WIN32
  534. HWND m_flashfullscreenHWND;
  535. #endif
  536. bool m_bSawUserInputThisFrame;
  537. struct SizeChange_t
  538. {
  539. int iBrowser;
  540. int nBeforeWidth;
  541. int nBeforeHeight;
  542. float flNewZoom;
  543. };
  544. CUtlMap< int, SizeChange_t, int > m_mapSizeChangesPending;
  545. };
  546. CCEFThread &AccessHTMLWrapper();
  547. #endif // HTML_CHROME_H