CEFWebInterfaceBrowserDialog.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Engine/Source/Runtime/WebBrowser/Private/CEF/CEFWebBrowserDialog.h
  2. #pragma once
  3. #include "CoreMinimal.h"
  4. #include "Misc/AssertionMacros.h"
  5. #include "Internationalization/Text.h"
  6. #if WITH_CEF3
  7. #if PLATFORM_WINDOWS
  8. # include "Windows/AllowWindowsPlatformTypes.h"
  9. #endif
  10. #pragma push_macro("OVERRIDE")
  11. # undef OVERRIDE // cef headers provide their own OVERRIDE macro
  12. #if PLATFORM_APPLE
  13. PRAGMA_DISABLE_DEPRECATION_WARNINGS
  14. #endif
  15. # include "include/cef_jsdialog_handler.h"
  16. #if PLATFORM_APPLE
  17. PRAGMA_ENABLE_DEPRECATION_WARNINGS
  18. #endif
  19. #pragma pop_macro("OVERRIDE")
  20. #if PLATFORM_WINDOWS
  21. # include "Windows/HideWindowsPlatformTypes.h"
  22. #endif
  23. #include "IWebInterfaceBrowserDialog.h"
  24. class FCEFWebInterfaceBrowserDialog
  25. : public IWebInterfaceBrowserDialog
  26. {
  27. public:
  28. virtual ~FCEFWebInterfaceBrowserDialog()
  29. {}
  30. // IWebBrowserDialog interface:
  31. virtual EWebInterfaceBrowserDialogType GetType() override
  32. {
  33. return Type;
  34. }
  35. virtual const FText& GetMessageText() override
  36. {
  37. return MessageText;
  38. }
  39. virtual const FText& GetDefaultPrompt() override
  40. {
  41. return DefaultPrompt;
  42. }
  43. virtual bool IsReload() override
  44. {
  45. check(Type == EWebInterfaceBrowserDialogType::Unload);
  46. return bIsReload;
  47. }
  48. virtual void Continue(bool Success = true, const FText& UserResponse = FText::GetEmpty()) override
  49. {
  50. check(Type == EWebInterfaceBrowserDialogType::Prompt || UserResponse.IsEmpty());
  51. Callback->Continue(Success, TCHAR_TO_WCHAR(*UserResponse.ToString()));
  52. }
  53. private:
  54. EWebInterfaceBrowserDialogType Type;
  55. FText MessageText;
  56. FText DefaultPrompt;
  57. bool bIsReload;
  58. CefRefPtr<CefJSDialogCallback> Callback;
  59. // Create a dialog from OnJSDialog arguments
  60. FCEFWebInterfaceBrowserDialog(CefJSDialogHandler::JSDialogType InDialogType, const CefString& InMessageText, const CefString& InDefaultPrompt, CefRefPtr<CefJSDialogCallback> InCallback)
  61. : Type((EWebInterfaceBrowserDialogType)InDialogType)
  62. , MessageText(FText::FromString(WCHAR_TO_TCHAR(InMessageText.ToWString().c_str())))
  63. , DefaultPrompt(FText::FromString(WCHAR_TO_TCHAR(InDefaultPrompt.ToWString().c_str())))
  64. , bIsReload(false)
  65. , Callback(InCallback)
  66. {}
  67. // Create a dialog from OnBeforeUnloadDialog arguments
  68. FCEFWebInterfaceBrowserDialog(const CefString& InMessageText, bool InIsReload, CefRefPtr<CefJSDialogCallback> InCallback)
  69. : Type(EWebInterfaceBrowserDialogType::Unload)
  70. , MessageText(FText::FromString(WCHAR_TO_TCHAR(InMessageText.ToWString().c_str())))
  71. , DefaultPrompt(FText::GetEmpty())
  72. , bIsReload(InIsReload)
  73. , Callback(InCallback)
  74. {};
  75. friend class FCEFWebInterfaceBrowserWindow;
  76. };
  77. typedef FCEFWebInterfaceBrowserDialog FWebInterfaceBrowserDialog;
  78. #endif