The Webview Univeral Flutter package for Appeto SDK.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

145 lignes
5.5 KiB

  1. // Copyright (C) Microsoft Corporation. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef __core_webview2_environment_options_h__
  5. #define __core_webview2_environment_options_h__
  6. #include <objbase.h>
  7. #include <wrl/implements.h>
  8. #include "webview2.h"
  9. #define CORE_WEBVIEW_TARGET_PRODUCT_VERSION L"94.0.992.28"
  10. #define COREWEBVIEW2ENVIRONMENTOPTIONS_STRING_PROPERTY(p) \
  11. public: \
  12. HRESULT STDMETHODCALLTYPE get_##p(LPWSTR* value) override { \
  13. if (!value) \
  14. return E_POINTER; \
  15. *value = m_##p.Copy(); \
  16. if ((*value == nullptr) && (m_##p.Get() != nullptr)) \
  17. return HRESULT_FROM_WIN32(GetLastError()); \
  18. return S_OK; \
  19. } \
  20. HRESULT STDMETHODCALLTYPE put_##p(LPCWSTR value) override { \
  21. LPCWSTR result = m_##p.Set(value); \
  22. if ((result == nullptr) && (value != nullptr)) \
  23. return HRESULT_FROM_WIN32(GetLastError()); \
  24. return S_OK; \
  25. } \
  26. \
  27. protected: \
  28. AutoCoMemString m_##p;
  29. #define COREWEBVIEW2ENVIRONMENTOPTIONS_BOOL_PROPERTY(p) \
  30. public: \
  31. HRESULT STDMETHODCALLTYPE get_##p(BOOL* value) override { \
  32. if (!value) \
  33. return E_POINTER; \
  34. *value = m_##p; \
  35. return S_OK; \
  36. } \
  37. HRESULT STDMETHODCALLTYPE put_##p(BOOL value) override { \
  38. m_##p = value; \
  39. return S_OK; \
  40. } \
  41. \
  42. protected: \
  43. BOOL m_##p = FALSE;
  44. // This is a base COM class that implements ICoreWebView2EnvironmentOptions.
  45. template <typename allocate_fn_t,
  46. allocate_fn_t allocate_fn,
  47. typename deallocate_fn_t,
  48. deallocate_fn_t deallocate_fn>
  49. class CoreWebView2EnvironmentOptionsBase
  50. : public Microsoft::WRL::Implements<
  51. Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
  52. ICoreWebView2EnvironmentOptions> {
  53. public:
  54. CoreWebView2EnvironmentOptionsBase() {
  55. // Initialize the target compatible browser version value to the version of
  56. // the browser binaries corresponding to this version of the SDK.
  57. m_TargetCompatibleBrowserVersion.Set(CORE_WEBVIEW_TARGET_PRODUCT_VERSION);
  58. }
  59. protected:
  60. ~CoreWebView2EnvironmentOptionsBase(){};
  61. class AutoCoMemString {
  62. public:
  63. AutoCoMemString() {}
  64. ~AutoCoMemString() { Release(); }
  65. void Release() {
  66. if (m_string) {
  67. deallocate_fn(m_string);
  68. m_string = nullptr;
  69. }
  70. }
  71. LPCWSTR Set(LPCWSTR str) {
  72. Release();
  73. if (str) {
  74. m_string = MakeCoMemString(str);
  75. }
  76. return m_string;
  77. }
  78. LPCWSTR Get() { return m_string; }
  79. LPWSTR Copy() {
  80. if (m_string)
  81. return MakeCoMemString(m_string);
  82. return nullptr;
  83. }
  84. protected:
  85. LPWSTR MakeCoMemString(LPCWSTR source) {
  86. const size_t length = wcslen(source);
  87. const size_t bytes = (length + 1) * sizeof(*source);
  88. // Ensure we didn't overflow during our size calculation.
  89. if (bytes <= length) {
  90. return nullptr;
  91. }
  92. wchar_t* result = reinterpret_cast<wchar_t*>(allocate_fn(bytes));
  93. if (result)
  94. memcpy(result, source, bytes);
  95. return result;
  96. }
  97. LPWSTR m_string = nullptr;
  98. };
  99. COREWEBVIEW2ENVIRONMENTOPTIONS_STRING_PROPERTY(AdditionalBrowserArguments)
  100. COREWEBVIEW2ENVIRONMENTOPTIONS_STRING_PROPERTY(Language)
  101. COREWEBVIEW2ENVIRONMENTOPTIONS_STRING_PROPERTY(TargetCompatibleBrowserVersion)
  102. COREWEBVIEW2ENVIRONMENTOPTIONS_BOOL_PROPERTY(
  103. AllowSingleSignOnUsingOSPrimaryAccount)
  104. };
  105. template <typename allocate_fn_t,
  106. allocate_fn_t allocate_fn,
  107. typename deallocate_fn_t,
  108. deallocate_fn_t deallocate_fn>
  109. class CoreWebView2EnvironmentOptionsBaseClass
  110. : public Microsoft::WRL::RuntimeClass<
  111. Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
  112. CoreWebView2EnvironmentOptionsBase<allocate_fn_t,
  113. allocate_fn,
  114. deallocate_fn_t,
  115. deallocate_fn>> {
  116. public:
  117. CoreWebView2EnvironmentOptionsBaseClass() {}
  118. protected:
  119. ~CoreWebView2EnvironmentOptionsBaseClass() override{};
  120. };
  121. typedef CoreWebView2EnvironmentOptionsBaseClass<decltype(&::CoTaskMemAlloc),
  122. ::CoTaskMemAlloc,
  123. decltype(&::CoTaskMemFree),
  124. ::CoTaskMemFree>
  125. CoreWebView2EnvironmentOptions;
  126. #endif // __core_webview2_environment_options_h__