IWebInterfaceBrowserSingleton.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // Engine/Source/Runtime/WebBrowser/Public/IWebBrowserSingleton.h
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "Rendering/SlateRenderer.h"
  5. #include "IWebInterfaceBrowserResourceLoader.h"
  6. class FCEFWebInterfaceBrowserWindow;
  7. class IWebInterfaceBrowserCookieManager;
  8. class IWebInterfaceBrowserWindow;
  9. class IWebInterfaceBrowserSchemeHandlerFactory;
  10. class UMaterialInterface;
  11. struct FWebInterfaceBrowserWindowInfo;
  12. class IWebInterfaceBrowserWindowFactory
  13. {
  14. public:
  15. virtual TSharedPtr<IWebInterfaceBrowserWindow> Create(
  16. TSharedPtr<FCEFWebInterfaceBrowserWindow>& BrowserWindowParent,
  17. TSharedPtr<FWebInterfaceBrowserWindowInfo>& BrowserWindowInfo) = 0;
  18. virtual TSharedPtr<IWebInterfaceBrowserWindow> Create(
  19. void* OSWindowHandle,
  20. FString InitialURL,
  21. bool bUseTransparency,
  22. bool bThumbMouseButtonNavigation,
  23. bool InterceptLoadRequests = false,
  24. TOptional<FString> ContentsToLoad = TOptional<FString>(),
  25. bool ShowErrorMessage = true,
  26. FColor BackgroundColor = FColor(255, 255, 255, 255)) = 0;
  27. };
  28. struct WEBBROWSERUI_API FInterfaceBrowserContextSettings
  29. {
  30. FInterfaceBrowserContextSettings(const FString& InId)
  31. : Id(InId)
  32. , AcceptLanguageList()
  33. , CookieStorageLocation()
  34. , bPersistSessionCookies(false)
  35. , bIgnoreCertificateErrors(false)
  36. , bEnableNetSecurityExpiration(true)
  37. { }
  38. FString Id;
  39. FString AcceptLanguageList;
  40. FString CookieStorageLocation;
  41. bool bPersistSessionCookies;
  42. bool bIgnoreCertificateErrors;
  43. bool bEnableNetSecurityExpiration;
  44. FOnBeforeInterfaceContextResourceLoadDelegate OnBeforeContextResourceLoad;
  45. };
  46. struct WEBBROWSERUI_API FCreateInterfaceBrowserWindowSettings
  47. {
  48. FCreateInterfaceBrowserWindowSettings()
  49. : OSWindowHandle(nullptr)
  50. , InitialURL()
  51. , bAcceleratedPaint(false)
  52. , bUseTransparency(false)
  53. , bInterceptLoadRequests(false)
  54. , bUseNativeCursors(false)
  55. , bThumbMouseButtonNavigation(false)
  56. , ContentsToLoad()
  57. , bShowErrorMessage(true)
  58. , BackgroundColor(FColor(255, 255, 255, 255))
  59. , BrowserFrameRate(60)
  60. , Context()
  61. , AltRetryDomains()
  62. { }
  63. void* OSWindowHandle;
  64. FString InitialURL;
  65. bool bAcceleratedPaint;
  66. bool bUseTransparency;
  67. bool bInterceptLoadRequests;
  68. bool bUseNativeCursors;
  69. bool bThumbMouseButtonNavigation;
  70. TOptional<FString> ContentsToLoad;
  71. bool bShowErrorMessage;
  72. FColor BackgroundColor;
  73. int BrowserFrameRate;
  74. TOptional<FInterfaceBrowserContextSettings> Context;
  75. TArray<FString> AltRetryDomains;
  76. };
  77. /**
  78. * A singleton class that takes care of general web browser tasks
  79. */
  80. class WEBBROWSERUI_API IWebInterfaceBrowserSingleton
  81. {
  82. public:
  83. /**
  84. * Virtual Destructor
  85. */
  86. virtual ~IWebInterfaceBrowserSingleton() {};
  87. /** @return A factory object that can be used to construct additional WebBrowserWindows on demand. */
  88. virtual TSharedRef<IWebInterfaceBrowserWindowFactory> GetWebBrowserWindowFactory() const = 0;
  89. /**
  90. * Create a new web browser window
  91. *
  92. * @param BrowserWindowParent The parent browser window
  93. * @param BrowserWindowInfo Info for setting up the new browser window
  94. * @return New Web Browser Window Interface (may be null if not supported)
  95. */
  96. virtual TSharedPtr<IWebInterfaceBrowserWindow> CreateBrowserWindow(
  97. TSharedPtr<FCEFWebInterfaceBrowserWindow>& BrowserWindowParent,
  98. TSharedPtr<FWebInterfaceBrowserWindowInfo>& BrowserWindowInfo
  99. ) = 0;
  100. /**
  101. * Create a new web browser window
  102. *
  103. * @param Settings Struct containing browser window settings
  104. * @return New Web Browser Window Interface (may be null if not supported)
  105. */
  106. virtual TSharedPtr<IWebInterfaceBrowserWindow> CreateBrowserWindow(const FCreateInterfaceBrowserWindowSettings& Settings) = 0;
  107. #if BUILD_EMBEDDED_APP
  108. virtual TSharedPtr<IWebInterfaceBrowserWindow> CreateNativeBrowserProxy() = 0;
  109. #endif
  110. virtual TSharedPtr<class IWebInterfaceBrowserCookieManager> GetCookieManager() const = 0;
  111. virtual TSharedPtr<class IWebInterfaceBrowserCookieManager> GetCookieManager(TOptional<FString> ContextId) const = 0;
  112. virtual bool RegisterContext(const FInterfaceBrowserContextSettings& Settings) = 0;
  113. virtual bool UnregisterContext(const FString& ContextId) = 0;
  114. // @return the application cache dir where the cookies are stored
  115. virtual FString ApplicationCacheDir() const = 0;
  116. /**
  117. * Registers a custom scheme handler factory, for a given scheme and domain. The domain is ignored if the scheme is not a browser built in scheme
  118. * and all requests will go through this factory.
  119. * @param Scheme The scheme name to handle.
  120. * @param Domain The domain name to handle.
  121. * @param WebBrowserSchemeHandlerFactory The factory implementation for creating request handlers for this scheme.
  122. */
  123. virtual bool RegisterSchemeHandlerFactory(FString Scheme, FString Domain, IWebInterfaceBrowserSchemeHandlerFactory* WebBrowserSchemeHandlerFactory) = 0;
  124. /**
  125. * Unregister a custom scheme handler factory. The factory may still be used by existing open browser windows, but will no longer be provided for new ones.
  126. * @param WebBrowserSchemeHandlerFactory The factory implementation to remove.
  127. */
  128. virtual bool UnregisterSchemeHandlerFactory(IWebInterfaceBrowserSchemeHandlerFactory* WebBrowserSchemeHandlerFactory) = 0;
  129. /**
  130. * Enable or disable CTRL/CMD-SHIFT-I shortcut to show the Chromium Dev tools window.
  131. * The value defaults to true on debug builds, otherwise false.
  132. *
  133. * The relevant handlers for spawning new browser windows have to be set up correctly in addition to this flag being true before anything is shown.
  134. *
  135. * @param Value a boolean value to enable or disable the keyboard shortcut.
  136. */
  137. virtual void SetDevToolsShortcutEnabled(bool Value) = 0;
  138. /**
  139. * Returns whether the CTRL/CMD-SHIFT-I shortcut to show the Chromium Dev tools window is enabled.
  140. *
  141. * The relevant handlers for spawning new browser windows have to be set up correctly in addition to this flag being true before anything is shown.
  142. *
  143. * @return a boolean value indicating whether the keyboard shortcut is enabled or not.
  144. */
  145. virtual bool IsDevToolsShortcutEnabled() = 0;
  146. /**
  147. * Enable or disable to-lowering of JavaScript object member bindings.
  148. *
  149. * Due to how JavaScript to UObject bridges require the use of FNames for building up the JS API objects, it is possible for case-sensitivity issues
  150. * to develop if an FName has been previously created with differing case to your function or property names. To-lowering the member names allows
  151. * a guaranteed casing for the web page's JS to reference.
  152. *
  153. * Default behavior is enabled, so that all JS side objects have only lowercase members.
  154. *
  155. * @param bEnabled a boolean value to enable or disable the to-lowering.
  156. */
  157. virtual void SetJSBindingToLoweringEnabled(bool bEnabled) = 0;
  158. /**
  159. * Delete old/unused web cache paths. Some Web implementations (i.e CEF) use version specific cache folders, this
  160. * call lets you schedule a deletion of any now unused folders. Calling this may resulting in async disk I/O.
  161. *
  162. * @param CachePathRoot the base path used for saving the webcache folder
  163. * @param CachePrefix the filename prefix we use for the cache folder (i.e "webcache")
  164. */
  165. virtual void ClearOldCacheFolders(const FString &CachePathRoot, const FString &CachePrefix) = 0;
  166. /** Set a reference to UWebBrowser's default material*/
  167. virtual void SetDefaultMaterial(UMaterialInterface* InDefaultMaterial) = 0;
  168. /** Set a reference to UWebBrowser's translucent material*/
  169. virtual void SetDefaultTranslucentMaterial(UMaterialInterface* InDefaultMaterial) = 0;
  170. /** Get a reference to UWebBrowser's default material*/
  171. virtual UMaterialInterface* GetDefaultMaterial() = 0;
  172. /** Get a reference to UWebBrowser's transparent material*/
  173. virtual UMaterialInterface* GetDefaultTranslucentMaterial() = 0;
  174. };