From 7cd6d109d420d2ac6ffd896c8949903a5b8b2460 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Sat, 12 Jun 2021 07:32:03 +1000 Subject: [PATCH] [windows] Add missing files --- .../windows/WebView2EnvironmentOptions.h | 144 ++++++++++++++++++ .../ffenestri/windows/scripts/version.txt | 1 + 2 files changed, 145 insertions(+) create mode 100644 v2/internal/ffenestri/windows/WebView2EnvironmentOptions.h create mode 100644 v2/internal/ffenestri/windows/scripts/version.txt diff --git a/v2/internal/ffenestri/windows/WebView2EnvironmentOptions.h b/v2/internal/ffenestri/windows/WebView2EnvironmentOptions.h new file mode 100644 index 00000000..6475ce58 --- /dev/null +++ b/v2/internal/ffenestri/windows/WebView2EnvironmentOptions.h @@ -0,0 +1,144 @@ +// Copyright (C) Microsoft Corporation. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef __core_webview2_environment_options_h__ +#define __core_webview2_environment_options_h__ + +#include +#include + +#include "webview2.h" +#define CORE_WEBVIEW_TARGET_PRODUCT_VERSION L"91.0.864.35" + +#define COREWEBVIEW2ENVIRONMENTOPTIONS_STRING_PROPERTY(p) \ + public: \ + HRESULT STDMETHODCALLTYPE get_##p(LPWSTR* value) override { \ + if (!value) \ + return E_POINTER; \ + *value = m_##p.Copy(); \ + if ((*value == nullptr) && (m_##p.Get() != nullptr)) \ + return HRESULT_FROM_WIN32(GetLastError()); \ + return S_OK; \ + } \ + HRESULT STDMETHODCALLTYPE put_##p(LPCWSTR value) override { \ + LPCWSTR result = m_##p.Set(value); \ + if ((result == nullptr) && (value != nullptr)) \ + return HRESULT_FROM_WIN32(GetLastError()); \ + return S_OK; \ + } \ + \ + protected: \ + AutoCoMemString m_##p; + +#define COREWEBVIEW2ENVIRONMENTOPTIONS_BOOL_PROPERTY(p) \ + public: \ + HRESULT STDMETHODCALLTYPE get_##p(BOOL* value) override { \ + if (!value) \ + return E_POINTER; \ + *value = m_##p; \ + return S_OK; \ + } \ + HRESULT STDMETHODCALLTYPE put_##p(BOOL value) override { \ + m_##p = value; \ + return S_OK; \ + } \ + \ + protected: \ + BOOL m_##p = FALSE; + +// This is a base COM class that implements ICoreWebView2EnvironmentOptions. +template +class CoreWebView2EnvironmentOptionsBase + : public Microsoft::WRL::Implements< + Microsoft::WRL::RuntimeClassFlags, + ICoreWebView2EnvironmentOptions> { + public: + CoreWebView2EnvironmentOptionsBase() { + // Initialize the target compatible browser version value to the version of + // the browser binaries corresponding to this version of the SDK. + m_TargetCompatibleBrowserVersion.Set(CORE_WEBVIEW_TARGET_PRODUCT_VERSION); + } + + protected: + ~CoreWebView2EnvironmentOptionsBase(){}; + + class AutoCoMemString { + public: + AutoCoMemString() {} + ~AutoCoMemString() { Release(); } + void Release() { + if (m_string) { + deallocate_fn(m_string); + m_string = nullptr; + } + } + + LPCWSTR Set(LPCWSTR str) { + Release(); + if (str) { + m_string = MakeCoMemString(str); + } + return m_string; + } + LPCWSTR Get() { return m_string; } + LPWSTR Copy() { + if (m_string) + return MakeCoMemString(m_string); + return nullptr; + } + + protected: + LPWSTR MakeCoMemString(LPCWSTR source) { + const size_t length = wcslen(source); + const size_t bytes = (length + 1) * sizeof(*source); + // Ensure we didn't overflow during our size calculation. + if (bytes <= length) { + return nullptr; + } + + wchar_t* result = reinterpret_cast(allocate_fn(bytes)); + if (result) + memcpy(result, source, bytes); + + return result; + } + + LPWSTR m_string = nullptr; + }; + + COREWEBVIEW2ENVIRONMENTOPTIONS_STRING_PROPERTY(AdditionalBrowserArguments) + COREWEBVIEW2ENVIRONMENTOPTIONS_STRING_PROPERTY(Language) + COREWEBVIEW2ENVIRONMENTOPTIONS_STRING_PROPERTY(TargetCompatibleBrowserVersion) + COREWEBVIEW2ENVIRONMENTOPTIONS_BOOL_PROPERTY( + AllowSingleSignOnUsingOSPrimaryAccount) +}; + +template +class CoreWebView2EnvironmentOptionsBaseClass + : public Microsoft::WRL::RuntimeClass< + Microsoft::WRL::RuntimeClassFlags, + CoreWebView2EnvironmentOptionsBase> { + public: + CoreWebView2EnvironmentOptionsBaseClass() {} + + protected: + ~CoreWebView2EnvironmentOptionsBaseClass() override{}; +}; + +typedef CoreWebView2EnvironmentOptionsBaseClass + CoreWebView2EnvironmentOptions; + +#endif // __core_webview2_environment_options_h__ diff --git a/v2/internal/ffenestri/windows/scripts/version.txt b/v2/internal/ffenestri/windows/scripts/version.txt new file mode 100644 index 00000000..123b71ef --- /dev/null +++ b/v2/internal/ffenestri/windows/scripts/version.txt @@ -0,0 +1 @@ +The version of WebView2 used: 1.0.864.35