Skip to content

Commit

Permalink
Merge branch 'webview2'
Browse files Browse the repository at this point in the history
  • Loading branch information
vslavik committed Mar 27, 2023
2 parents b55db4d + ec27189 commit 8f0490a
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 109 deletions.
19 changes: 19 additions & 0 deletions 3rdparty/wx.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@
<ClCompile Include="wxWidgets\src\common\ustring.cpp" />
<ClCompile Include="wxWidgets\src\common\utilscmn.cpp" />
<ClCompile Include="wxWidgets\src\common\variant.cpp" />
<ClCompile Include="wxWidgets\src\common\webview.cpp" />
<ClCompile Include="wxWidgets\src\common\wfstream.cpp" />
<ClCompile Include="wxWidgets\src\common\wincmn.cpp" />
<ClCompile Include="wxWidgets\src\common\windowid.cpp" />
Expand Down Expand Up @@ -506,6 +507,7 @@
<ClCompile Include="wxWidgets\src\msw\nativewin.cpp" />
<ClCompile Include="wxWidgets\src\msw\nonownedwnd.cpp" />
<ClCompile Include="wxWidgets\src\msw\ole\activex.cpp" />
<ClCompile Include="wxWidgets\src\msw\ole\automtn.cpp" />
<ClCompile Include="wxWidgets\src\msw\ole\comimpl.cpp" />
<ClCompile Include="wxWidgets\src\msw\ole\dataobj.cpp" />
<ClCompile Include="wxWidgets\src\msw\ole\oleutils.cpp" />
Expand Down Expand Up @@ -534,12 +536,29 @@
<ClCompile Include="wxWidgets\src\msw\utilsgui.cpp" />
<ClCompile Include="wxWidgets\src\msw\utilswin.cpp" />
<ClCompile Include="wxWidgets\src\msw\uxtheme.cpp" />
<ClCompile Include="wxWidgets\src\msw\webview_edge.cpp" />
<ClCompile Include="wxWidgets\src\msw\webview_ie.cpp" />
<ClCompile Include="wxWidgets\src\msw\window.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="wxWidgets\include\wx\msw\webview_edge.h" />
<ClInclude Include="wxWidgets\include\wx\msw\webview_ie.h" />
<ClInclude Include="wxWidgets\include\wx\webview.h" />
<ClInclude Include="wxWidgets\include\wx\webviewarchivehandler.h" />
<ClInclude Include="wxWidgets\include\wx\webviewfshandler.h" />
<ClInclude Include="wxWidgets_setup_h\wx\setup.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.1661.34\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.1661.34\build\native\Microsoft.Web.WebView2.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.1661.34\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.1661.34\build\native\Microsoft.Web.WebView2.targets'))" />
</Target>
</Project>
30 changes: 30 additions & 0 deletions 3rdparty/wx.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@
<ClInclude Include="wxWidgets_setup_h\wx\setup.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="wxWidgets\include\wx\webview.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="wxWidgets\include\wx\webviewarchivehandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="wxWidgets\include\wx\webviewfshandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="wxWidgets\include\wx\msw\webview_edge.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="wxWidgets\include\wx\msw\webview_ie.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="wxWidgets\src\common\any.cpp">
Expand Down Expand Up @@ -550,5 +565,20 @@
<ClCompile Include="wxWidgets\src\msw\window.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="wxWidgets\src\msw\webview_edge.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="wxWidgets\src\msw\webview_ie.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="wxWidgets\src\common\webview.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="wxWidgets\src\msw\ole\automtn.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\packages.config" />
</ItemGroup>
</Project>
18 changes: 7 additions & 11 deletions 3rdparty/wxWidgets_setup_h/wx/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@
#define wxUSE_IPV6 0

// Set to 1 to enable virtual file systems (required by wxHTML)
#define wxUSE_FILESYSTEM 0
#define wxUSE_FILESYSTEM 1

// Set to 1 to enable virtual ZIP filesystem (requires wxUSE_FILESYSTEM)
#define wxUSE_FS_ZIP 0
Expand Down Expand Up @@ -792,32 +792,28 @@
// Default is 1
//
// Recommended setting: 1
#define wxUSE_WEBVIEW 0
#define wxUSE_WEBVIEW 1

// Use the IE wxWebView backend
//
// Default is 1 on MSW
//
// Recommended setting: 1
#ifdef __WXMSW__
#define wxUSE_WEBVIEW_IE 0
#else
#define wxUSE_WEBVIEW_IE 0
#endif
#define wxUSE_WEBVIEW_IE 1

// Use the Edge (Chromium) wxWebView backend (Requires WebView2 SDK)
//
// Default is 0 because WebView2 is not always available, set it to 1 if you do have it.
//
// Recommended setting: 1 when building for Windows with WebView2 SDK
#define wxUSE_WEBVIEW_EDGE 0
// Recommended setting: 1 when building for Windows with W ebView2 SDK
#define wxUSE_WEBVIEW_EDGE 1

// Use the Edge (Chromium) wxWebView backend without loader DLL
//
// Default is 0, set it to 1 if you don't want to depend on WebView2Loader.dll.
//
// Recommended setting: 0
#define wxUSE_WEBVIEW_EDGE_STATIC 0
#define wxUSE_WEBVIEW_EDGE_STATIC 1

// Use the WebKit wxWebView backend
//
Expand Down Expand Up @@ -1691,7 +1687,7 @@
//
// Recommended setting: 1 if you need to control other applications via OLE
// Automation, can be safely set to 0 otherwise
#define wxUSE_OLE_AUTOMATION 0
#define wxUSE_OLE_AUTOMATION 1

// Set this to 1 to enable wxActiveXContainer class allowing to embed OLE
// controls in wx.
Expand Down
7 changes: 7 additions & 0 deletions WinSparkle.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -450,5 +450,12 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="WinSparkle.targets" />
<Import Project="packages\Microsoft.Web.WebView2.1.0.1661.34\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('packages\Microsoft.Web.WebView2.1.0.1661.34\build\native\Microsoft.Web.WebView2.targets')" />
</ImportGroup>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\Microsoft.Web.WebView2.1.0.1661.34\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Web.WebView2.1.0.1661.34\build\native\Microsoft.Web.WebView2.targets'))" />
</Target>
</Project>
3 changes: 2 additions & 1 deletion packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Gettext.Tools" version="0.20.2" targetFramework="native" />
<package id="Microsoft.Web.WebView2" version="1.0.1661.34" targetFramework="native" />
</packages>
126 changes: 29 additions & 97 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@
#include <wx/stattext.h>
#include <wx/timer.h>
#include <wx/settings.h>
#include <wx/msw/ole/activex.h>
#include <wx/msgdlg.h>
#include <wx/webview.h>
#include <wx/msw/webview_ie.h>

#include <exdisp.h>
#include <mshtml.h>
Expand Down Expand Up @@ -465,8 +466,7 @@ class UpdateDialog : public WinSparkleDialog
wxSizer *m_updateButtonsSizer;
wxSizer *m_releaseNotesSizer;
wxPanel *m_browserParent;

wxAutoOleInterface<IWebBrowser2> m_webBrowser;
wxWebView *m_webBrowser;

// current appcast data (only valid after StateUpdateAvailable())
Appcast m_appcast;
Expand Down Expand Up @@ -518,6 +518,8 @@ UpdateDialog::UpdateDialog()
wxDefaultPosition,
wxSize(PX(RELNOTES_WIDTH), PX(RELNOTES_HEIGHT)));
m_browserParent->SetBackgroundColour(*wxWHITE);
m_webBrowser = NULL;

m_releaseNotesSizer->Add
(
m_browserParent,
Expand Down Expand Up @@ -997,110 +999,40 @@ void UpdateDialog::StateUpdateDownloaded(const std::wstring& updateFile, const s

void UpdateDialog::ShowReleaseNotes(const Appcast& info)
{
if ( !m_webBrowser.IsOk() )
if ( !m_webBrowser )
{
// Load MSIE control

wxBusyCursor busy;

IWebBrowser2 *browser;
HRESULT hr = CoCreateInstance
(
CLSID_WebBrowser,
NULL,
CLSCTX_INPROC_SERVER,
IID_IWebBrowser2,
(void**)&browser
);

if ( FAILED(hr) )
{
// hide the notes again, we cannot show them
LayoutChangesGuard guard(this);
HIDE(m_releaseNotesSizer);
MakeResizable(false);
LogError("Failed to create WebBrowser ActiveX control.");
return;
}

m_webBrowser = browser;

new wxActiveXContainer(m_browserParent, IID_IWebBrowser2, browser);

// Poke the browser to initialize it. This is needed when using
// info.Description and does no harm with ReleaseNotesURL. To
// complicate things, it must be done exactly once, which is why it's
// here and not below.
// See https://github.com/vslavik/winsparkle/issues/155
m_webBrowser->Navigate
(
wxBasicString("about:blank"),
NULL, // Flags
NULL, // TargetFrameName
NULL, // PostData
NULL // Headers
);
if (!wxWebView::IsBackendAvailable(wxWebViewBackendEdge))
wxWebViewIE::MSWSetEmulationLevel(wxWEBVIEWIE_EMU_IE11);
// Note that about:blank is used so that subsequent SetPage() call doesn't fail with
// MSIE. See https://github.com/vslavik/winsparkle/issues/155 and
// https://github.com/wxWidgets/wxWidgets/issues/14768
m_webBrowser = wxWebView::New(m_browserParent, wxID_ANY, "about:blank",
wxDefaultPosition, wxSize(PX(RELNOTES_WIDTH), PX(RELNOTES_HEIGHT)));
auto sizer = new wxBoxSizer(wxVERTICAL);
sizer->Add(m_webBrowser, wxSizerFlags(1).Expand());
m_browserParent->SetSizer(sizer);

// Open all links in the default browser:
m_webBrowser->Bind(wxEVT_WEBVIEW_NAVIGATING, [info](wxWebViewEvent& evt)
{
auto url = evt.GetURL();
if (url.starts_with("http") && url != info.ReleaseNotesURL)
{
wxLaunchDefaultBrowser(url);
evt.Veto();
}
});
}

if( !info.ReleaseNotesURL.empty() )
{
m_webBrowser->Navigate
(
wxBasicString(info.ReleaseNotesURL),
NULL, // Flags
NULL, // TargetFrameName
NULL, // PostData
NULL // Headers
);
m_webBrowser->LoadURL(info.ReleaseNotesURL);
}
else if ( !info.Description.empty() )
{
HRESULT hr = E_FAIL;
IHTMLDocument2 *doc;
hr = m_webBrowser->get_Document((IDispatch **)&doc);
if ( FAILED(hr) || !doc )
{
LogError("Failed to get HTML document");
return;
}

// If the code below looks crazy, that's because it is. Apparently,
// the document may be in some uninitialized state first time around,
// so we need to write an empty string into it first and only then the
// real content. (At least that's what wxWebView does...)
//
// See https://github.com/vslavik/winsparkle/issues/29
SAFEARRAY *psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1);
if ( psaStrings != NULL )
{
VARIANT *param;
SafeArrayAccessData(psaStrings, (LPVOID*)&param);
param->vt = VT_BSTR;
param->bstrVal = SysAllocString(OLESTR(""));
SafeArrayUnaccessData(psaStrings);

doc->write(psaStrings);
doc->close();

SafeArrayDestroy(psaStrings);

psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1);
if (psaStrings != NULL)
{
VARIANT *param;
SafeArrayAccessData(psaStrings, (LPVOID*) &param);
param->vt = VT_BSTR;
param->bstrVal = wxBasicString(wxString::FromUTF8(info.Description.c_str())).Detach();
SafeArrayUnaccessData(psaStrings);

doc->write(psaStrings);
doc->close();

SafeArrayDestroy(psaStrings);
}

doc->Release();
}
m_webBrowser->SetPage(wxString::FromUTF8(info.Description), "");
}

SetWindowStyleFlag(GetWindowStyleFlag() | wxRESIZE_BORDER);
Expand Down

0 comments on commit 8f0490a

Please sign in to comment.