Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smoketest/1.0.1905 testing #196

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions SampleApps/WebView2APISample/AppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ PCWSTR AppWindow::GetWindowClass()
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_WEBVIEW2APISAMPLE);
wcex.lpszClassName = windowClass;
wcex.hIconSm = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_SMALL));
wcex.hIconSm = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_WEBVIEW2APISAMPLE));

RegisterClassExW(&wcex);
return windowClass;
Expand Down Expand Up @@ -1465,26 +1465,13 @@ HRESULT AppWindow::CreateControllerWithOptions()

void AppWindow::SetAppIcon(bool inPrivate)
{
HICON newSmallIcon = nullptr;
HICON newBigIcon = nullptr;
if (inPrivate)
{
static HICON smallInPrivateIcon = reinterpret_cast<HICON>(LoadImage(
g_hInstance, MAKEINTRESOURCEW(IDI_WEBVIEW2APISAMPLE_INPRIVATE), IMAGE_ICON, 16, 16,
LR_DEFAULTCOLOR));
static HICON bigInPrivateIcon = reinterpret_cast<HICON>(LoadImage(
g_hInstance, MAKEINTRESOURCEW(IDI_WEBVIEW2APISAMPLE_INPRIVATE), IMAGE_ICON, 32, 32,
LR_DEFAULTCOLOR));
newSmallIcon = smallInPrivateIcon;
newBigIcon = bigInPrivateIcon;
}
else
{
static HICON smallIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_WEBVIEW2APISAMPLE));
static HICON bigIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_SMALL));
newSmallIcon = smallIcon;
newBigIcon = bigIcon;
}
int iconID = inPrivate ? IDI_WEBVIEW2APISAMPLE_INPRIVATE : IDI_WEBVIEW2APISAMPLE;

HICON newSmallIcon = reinterpret_cast<HICON>(
LoadImage(g_hInstance, MAKEINTRESOURCEW(iconID), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR));
HICON newBigIcon = reinterpret_cast<HICON>(
LoadImage(g_hInstance, MAKEINTRESOURCEW(iconID), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR));

reinterpret_cast<HICON>(SendMessage(
m_mainWindow, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(newSmallIcon)));
reinterpret_cast<HICON>(
Expand Down Expand Up @@ -1804,10 +1791,10 @@ void AppWindow::RegisterEventHandlers()
[this]
{
std::wstring message =
L"A new version of the Microsoft Edge WebView2 Runtime is available on this machine. ";
L"We detected there is a new version for the browser.";
if (m_webView)
{
message += L"Do you want to restart the WebView2APISample app? \n\n";
message += L"Do you want to restart the app? \n\n";
message +=
L"Click No if you only want to re-create the webviews. \n";
message += L"Click Cancel for no action. \n";
Expand Down
4 changes: 2 additions & 2 deletions SampleApps/WebView2APISample/ProcessComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ bool ProcessComponent::HandleWindowMessage(
}
return false;
}

// Show the WebView's PID to the user.
void ProcessComponent::ShowBrowserProcessInfo() {
void ProcessComponent::ShowBrowserProcessInfo()
{
UINT32 processId;
m_webView->get_BrowserProcessId(&processId);

Expand Down
2 changes: 0 additions & 2 deletions SampleApps/WebView2APISample/ProcessComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ProcessComponent : public ComponentBase
void CrashBrowserProcess();
void CrashRenderProcess();
void PerformanceInfo();

~ProcessComponent() override;

// Wait for process to exit for timeoutMs, then force quit it if it hasn't.
Expand All @@ -50,7 +49,6 @@ class ProcessComponent : public ComponentBase

UINT m_browserProcessId = 0;
wil::com_ptr<ICoreWebView2ProcessInfoCollection> m_processCollection;

EventRegistrationToken m_processFailedToken = {};
EventRegistrationToken m_processInfosChangedToken = {};
};
351 changes: 337 additions & 14 deletions SampleApps/WebView2APISample/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using namespace Microsoft::WRL;
using namespace std;

static constexpr wchar_t c_samplePath[] = L"ScenarioWebViewEventMonitor.html";

std::wstring WebResourceSourceToString(COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS source)
{
switch (source)
Expand Down
1 change: 1 addition & 0 deletions SampleApps/WebView2APISample/ScriptComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ void ScriptComponent::HandleIFrames()
})
.Get(),
NULL));

//! [AdditionalAllowedFrameAncestors_2]
// Set up the event listeners to handle site embedding scenario. The code will take effect
// when the site embedding page is navigated to and the embedding iframe navigates to the
Expand Down
237 changes: 114 additions & 123 deletions SampleApps/WebView2APISample/SettingsComponent.cpp

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions SampleApps/WebView2APISample/SettingsComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class SettingsComponent : public ComponentBase
wil::com_ptr<ICoreWebView2_13> m_webView2_13;
wil::com_ptr<ICoreWebView2_14> m_webView2_14;
wil::com_ptr<ICoreWebView2_15> m_webView2_15;
wil::com_ptr<ICoreWebView2_18> m_webView2_18;
wil::com_ptr<ICoreWebView2Settings> m_settings;
wil::com_ptr<ICoreWebView2Settings2> m_settings2;
wil::com_ptr<ICoreWebView2Settings3> m_settings3;
Expand All @@ -67,8 +68,6 @@ class SettingsComponent : public ComponentBase
wil::com_ptr<ICoreWebView2Controller> m_controller;
wil::com_ptr<ICoreWebView2Controller3> m_controller3;
wil::com_ptr<ICoreWebView2Environment> m_webViewEnvironment;
wil::com_ptr<ICoreWebView2Experimental5> m_webViewExperimental5;
wil::com_ptr<ICoreWebView2Experimental21> m_webViewExperimental21;
wil::com_ptr<ICoreWebView2ContextMenuItem> m_displayPageUrlContextSubMenuItem;

bool m_blockImages = false;
Expand Down
22 changes: 5 additions & 17 deletions SampleApps/WebView2APISample/ViewComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,7 @@ void ViewComponent::Suspend()
{
wil::com_ptr<ICoreWebView2_3> webView;
webView = m_webView.try_query<ICoreWebView2_3>();
if (!webView)
{
ShowFailure(E_NOINTERFACE, L"TrySuspend API not available");
return;
}
CHECK_FEATURE_RETURN_EMPTY(webView);
HRESULT hr = webView->TrySuspend(
Callback<ICoreWebView2TrySuspendCompletedHandler>(
[this](HRESULT errorCode, BOOL isSuccessful) -> HRESULT {
Expand All @@ -449,13 +445,9 @@ void ViewComponent::Suspend()
//! [MemoryUsageTargetLevel]
void ViewComponent::ToggleMemoryUsageTargetLevel()
{
wil::com_ptr<ICoreWebView2Experimental5> webView;
webView = m_webView.try_query<ICoreWebView2Experimental5>();
if (!webView)
{
ShowFailure(E_NOINTERFACE, L"MemoryUsageTargetLevel API not available");
return;
}
wil::com_ptr<ICoreWebView2_19> webView;
webView = m_webView.try_query<ICoreWebView2_19>();
CHECK_FEATURE_RETURN_EMPTY(webView);
COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL memory_target_level =
COREWEBVIEW2_MEMORY_USAGE_TARGET_LEVEL_NORMAL;
CHECK_FAILURE(webView->get_MemoryUsageTargetLevel(&memory_target_level));
Expand All @@ -477,11 +469,7 @@ void ViewComponent::Resume()
{
wil::com_ptr<ICoreWebView2_3> webView;
webView = m_webView.try_query<ICoreWebView2_3>();
if (!webView)
{
ShowFailure(E_NOINTERFACE, L"Resume API not available");
return;
}
CHECK_FEATURE_RETURN_EMPTY(webView);
webView->Resume();
}
//! [Resume]
Expand Down
Binary file modified SampleApps/WebView2APISample/WebView2APISample.ico
Binary file not shown.
1 change: 0 additions & 1 deletion SampleApps/WebView2APISample/WebView2APISample.rc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
// remains consistent on all systems.
IDI_WEBVIEW2APISAMPLE ICON "WebView2APISample.ico"
IDI_WEBVIEW2APISAMPLE_INPRIVATE ICON "WebView2APISample_Inprivate.ico"
IDI_SMALL ICON "small.ico"

IDI_WEBVIEW2_BACKGROUND BITMAP "AppBackground.bmp"

Expand Down
4 changes: 2 additions & 2 deletions SampleApps/WebView2APISample/WebView2APISample.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,13 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.1829-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.1829-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.1905-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.1905-prerelease\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.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.191107.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.1829-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.1829-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.1905-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.1905-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
</Target>
</Project>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion SampleApps/WebView2APISample/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Web.WebView2" version="1.0.1829-prerelease" targetFramework="native" />
<package id="Microsoft.Web.WebView2" version="1.0.1905-prerelease" targetFramework="native" />
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.191107.2" targetFramework="native" />
</packages>
2 changes: 1 addition & 1 deletion SampleApps/WebView2APISample/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDI_WEBVIEW2APISAMPLE 107
#define IDI_SMALL 108
//#define IDI_SMALL 108 - UNUSED
#define IDC_WEBVIEW2APISAMPLE 109
#define IDC_WEBVIEW2APISAMPLEHOST 110
#define IDM_ZOOM_05 111
Expand Down
Binary file removed SampleApps/WebView2APISample/small.ico
Binary file not shown.
14 changes: 14 additions & 0 deletions SampleApps/WebView2WindowsFormsBrowser/BridgeAddRemoteObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,19 @@ public async Task<string> GetObjectTypeAsync(object obj)
}
private Dictionary<int, string> m_dictionary = new Dictionary<int, string>();

public void InvokeEvent()
{
TestEvent0?.Invoke();
TestEvent1?.Invoke("param1");
TestEvent2?.Invoke("param1", DateTime.UtcNow);
}
#pragma warning disable CS0067
public delegate void TestEvent0Delegate();
public event TestEvent0Delegate TestEvent0;
public delegate void TestEvent1Delegate(String param1);
public event TestEvent1Delegate TestEvent1;
public delegate void TestEvent2Delegate(String param1, DateTime param2);
public event TestEvent2Delegate TestEvent2;
#pragma warning restore CS0067
}
}
42 changes: 35 additions & 7 deletions SampleApps/WebView2WindowsFormsBrowser/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
description: "Demonstrates the features and usage patterns of WebView2 in Windows Forms apps."
description: "Demonstrate the features and usage patterns of WebView2 in Windows Forms."
extendedZipContent:
-
path: SharedContent
Expand All @@ -14,13 +14,41 @@ products:
- microsoft-edge
urlFragment: WebView2WindowsFormsBrowser
---
# WinForms sample app
# WebView2 Windows Forms Browser

<!-- only enough info to differentiate this sample vs the others; what is different about this sample compared to the sibling samples? -->
This sample, **WebView2WindowsFormsBrowser**, embeds a WebView within a Windows Forms application.
This is a hybrid application built with the [Microsoft Edge WebView2](https://aka.ms/webview2) control.

This sample is built as a Windows Forms Visual Studio project. It uses C# and HTML/CSS/JavaScript in the WebView2 environment.
![Sample App Snapshot](https://raw.githubusercontent.com/MicrosoftEdge/WebView2Samples/master/SampleApps/WebView2WindowsFormsBrowser/screenshots/winforms-browser-screenshot.png)

For more information, see [WinForms sample app](https://learn.microsoft.com/microsoft-edge/webview2/samples/webview2windowsformsbrowser).
The WebView2WindowsFormsBrowser is an example of an application that embeds a WebView within a Windows Forms application. It is built as a Windows Forms [Visual Studio 2019](https://visualstudio.microsoft.com/vs/) project and makes use of both C# and HTML/CSS/JavaScript in the WebView2 environment.

![The WinForms sample app running](screenshots/winforms-browser-screenshot.png)
The API Sample showcases a selection of WebView2's event handlers and API methods that allow a Windows Forms application to directly interact with a WebView and vice versa.

If this is your first time using WebView, we recommend first following the [Getting Started](https://learn.microsoft.com/microsoft-edge/webview2/gettingstarted/winforms) guide, which goes over how to create a WebView2 and walks through some basic WebView2 functionality.

To learn more specifics about events and API Handlers in WebView2, you can refer to the [WebView2 Reference Documentation](https://learn.microsoft.com/microsoft-edge/webview2/webview2-api-reference).

## Prerequisites

- [Microsoft Edge (Chromium)](https://www.microsoftedgeinsider.com/download/) installed on a supported OS. Currently we recommend the latest version of the Edge Canary channel.
- [Visual Studio](https://visualstudio.microsoft.com/vs/) with .NET support installed.
- Latest pre-release version of our [WebView2 SDK](https://aka.ms/webviewnuget), which is included in this project.

## Build the WebView2 Windows Forms Browser

Clone the repository and open the solution in Visual Studio. WebView2 is already included as a NuGet package* in this project.

- Clone this repository
- Open the solution in Visual Studio 2019**
- Set the target you want to build (Debug/Release, AnyCPU)
- Build the project file: _WebView2WindowsFormsBrowser.csproj_

That's it! Everything should be ready to just launch the app.

*You can get the WebView2 NugetPackage through the Visual Studio NuGet Package Manager.

**You can also use Visual Studio 2017 by changing the project's Platform Toolset in Project Properties/Configuration properties/General/Platform Toolset. You might also need to change the Windows SDK to the latest version available to you.

## Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact opencode@microsoft.com with any additional questions or comments.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1829-prerelease" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1905-prerelease" />
</ItemGroup>
<ItemGroup>
<Folder Include="assets\" />
Expand Down
14 changes: 14 additions & 0 deletions SampleApps/WebView2WpfBrowser/BridgeAddRemoteObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,19 @@ public async Task<string> GetObjectTypeAsync(object obj)
}
private Dictionary<int, string> m_dictionary = new Dictionary<int, string>();

public void InvokeEvent()
{
TestEvent0?.Invoke();
TestEvent1?.Invoke("param1");
TestEvent2?.Invoke("param1", DateTime.UtcNow);
}
#pragma warning disable CS0067
public delegate void TestEvent0Delegate();
public event TestEvent0Delegate TestEvent0;
public delegate void TestEvent1Delegate(String param1);
public event TestEvent1Delegate TestEvent1;
public delegate void TestEvent2Delegate(String param1, DateTime param2);
public event TestEvent2Delegate TestEvent2;
#pragma warning restore CS0067
}
}
Loading
Loading