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

Update projects to use latest WebView2 SDK 1.0.2357-prerelease #234

Merged
merged 2 commits into from
Jan 30, 2024
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
16 changes: 14 additions & 2 deletions SampleApps/WebView2APISample/AppWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "ScenarioExtensionsManagement.h"
#include "ScenarioIFrameDevicePermission.h"
#include "ScenarioNavigateWithWebResourceRequest.h"
#include "ScenarioNonClientRegionSupport.h"
#include "ScenarioAcceleratorKeyPressed.h"
#include "ScenarioNotificationReceived.h"
#include "ScenarioPermissionManagement.h"
#include "ScenarioSharedBuffer.h"
Expand Down Expand Up @@ -182,9 +184,9 @@ AppWindow::AppWindow(
UINT creationModeId, const WebViewCreateOption& opt, const std::wstring& initialUri,
const std::wstring& userDataFolderParam, bool isMainWindow,
std::function<void()> webviewCreatedCallback, bool customWindowRect, RECT windowRect,
bool shouldHaveToolbar)
bool shouldHaveToolbar, bool isPopup)
: m_creationModeId(creationModeId), m_webviewOption(opt), m_initialUri(initialUri),
m_onWebViewFirstInitialized(webviewCreatedCallback)
m_onWebViewFirstInitialized(webviewCreatedCallback), m_isPopupWindow(isPopup)
{
// Initialize COM as STA.
CHECK_FAILURE(OleInitialize(NULL));
Expand Down Expand Up @@ -651,6 +653,16 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
{
return PrintToPdfStream();
}
case IDM_SCENARIO_NON_CLIENT_REGION_SUPPORT:
{
NewComponent<ScenarioNonClientRegionSupport>(this);
return true;
}
case IDM_SCENARIO_ACCELERATOR_KEY_PRESSED:
{
NewComponent<ScenarioAcceleratorKeyPressed>(this);
return true;
}
}
return false;
}
Expand Down
15 changes: 6 additions & 9 deletions SampleApps/WebView2APISample/AppWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,11 @@ class AppWindow
{
public:
AppWindow(
UINT creationModeId,
const WebViewCreateOption& opt,
const std::wstring& initialUri = L"",
const std::wstring& userDataFolderParam = L"",
bool isMainWindow = false,
std::function<void()> webviewCreatedCallback = nullptr,
bool customWindowRect = false,
RECT windowRect = { 0 },
bool shouldHaveToolbar = true);
UINT creationModeId, const WebViewCreateOption& opt,
const std::wstring& initialUri = L"", const std::wstring& userDataFolderParam = L"",
bool isMainWindow = false, std::function<void()> webviewCreatedCallback = nullptr,
bool customWindowRect = false, RECT windowRect = {0}, bool shouldHaveToolbar = true,
bool isPopup = false);

~AppWindow();

Expand Down Expand Up @@ -293,6 +289,7 @@ class AppWindow
RECT m_appBackgroundImageRect;
};

// Creates and registers a component on this `AppWindow`.
template <class ComponentType, class... Args> void AppWindow::NewComponent(Args&&... args)
{
m_components.emplace_back(new ComponentType(std::forward<Args>(args)...));
Expand Down
10 changes: 10 additions & 0 deletions SampleApps/WebView2APISample/CheckFailure.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ void FeatureNotAvailable();

// Returns nothing, which is different from CHECK_FEATURE_RETURN
#define CHECK_FEATURE_RETURN_EMPTY(feature) { if (!feature) { FeatureNotAvailable(); return; } }

// Returns S_OK, which is different from CHECK_FEATURE_RETURN
#define CHECK_FEATURE_RETURN_HRESULT(feature) \
{ \
if (!feature) \
{ \
FeatureNotAvailable(); \
return S_OK; \
} \
}
12 changes: 12 additions & 0 deletions SampleApps/WebView2APISample/ComponentBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@

#include "stdafx.h"

// A component is meant to encapsulate all details required for a specific
// capability of the AppWindow, typically demonstrating usage of a WebView2 API.
//
// Component instances are owned by an AppWindow, which will give each of its
// components a chance to handle any messages it gets. AppWindow deletes all its
// components when WebView is closed.
//
// Components are meant to be created and registered by AppWindow itself,
// through `AppWindow::NewComponent<TComponent>(...)`. For example, the
// AppWindow might create a new component upon selection of a menu item by the
// user. Components typically take and keep a pointer to their owning AppWindow
// so they can control the WebView.
class ComponentBase
{
public:
Expand Down
23 changes: 23 additions & 0 deletions SampleApps/WebView2APISample/DiscardsComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.

#include "stdafx.h"

#include "DiscardsComponent.h"

DiscardsComponent::DiscardsComponent(AppWindow* appWindow) : m_appWindow(appWindow)
{
m_appWindowDiscardsView = new AppWindow(
IDM_CREATION_MODE_WINDOWED, appWindow->GetWebViewOption(), L"edge://discards/graph",
appWindow->GetUserDataFolder(), false /* isMainWindow */,
nullptr /* webviewCreatedCallback */, true /* customWindowRect */, {100, 100, 900, 900},
false /* shouldHaveToolbar */);

m_appWindowDiscardsView->SetOnAppWindowClosing([&] { m_appWindow->DeleteComponent(this); });
}

DiscardsComponent::~DiscardsComponent()
{
m_appWindowDiscardsView->SetOnAppWindowClosing(nullptr);
}
23 changes: 23 additions & 0 deletions SampleApps/WebView2APISample/DiscardsComponent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.

#pragma once

#include "stdafx.h"

#include "AppWindow.h"
#include "ComponentBase.h"

class DiscardsComponent : public ComponentBase
{
public:
DiscardsComponent(AppWindow* appWindow);
~DiscardsComponent() override;

private:
AppWindow* m_appWindow = nullptr;

// The AppWindow showing discards.
AppWindow* m_appWindowDiscardsView;
};
48 changes: 23 additions & 25 deletions SampleApps/WebView2APISample/ProcessComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,26 +244,26 @@ void ProcessComponent::AppendFrameInfo(
CHECK_FAILURE(frameInfo->get_Source(&sourceRaw));
std::wstring source = sourceRaw.get()[0] ? sourceRaw.get() : L"none";

wil::com_ptr<ICoreWebView2ExperimentalFrameInfo> frameInfoExperimental;
CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
frameInfoExperimental->get_FrameId(&frameId);
frameInfoExperimental->get_FrameKind(&frameKind);
wil::com_ptr<ICoreWebView2FrameInfo2> frameInfo2;
CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
frameInfo2->get_FrameId(&frameId);
frameInfo2->get_FrameKind(&frameKind);

wil::com_ptr<ICoreWebView2FrameInfo> parentFrameInfo;
CHECK_FAILURE(frameInfoExperimental->get_ParentFrameInfo(&parentFrameInfo));
CHECK_FAILURE(frameInfo2->get_ParentFrameInfo(&parentFrameInfo));
if (parentFrameInfo)
{
CHECK_FAILURE(parentFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
CHECK_FAILURE(frameInfoExperimental->get_FrameId(&parentFrameId));
CHECK_FAILURE(parentFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
CHECK_FAILURE(frameInfo2->get_FrameId(&parentFrameId));
}

wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo = GetAncestorMainFrameInfo(frameInfo);
if (mainFrameInfo == frameInfo)
{
type = L"main frame";
}
CHECK_FAILURE(mainFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
CHECK_FAILURE(frameInfoExperimental->get_FrameId(&mainFrameId));
CHECK_FAILURE(mainFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
CHECK_FAILURE(frameInfo2->get_FrameId(&mainFrameId));

wil::com_ptr<ICoreWebView2FrameInfo> childFrameInfo =
GetAncestorMainFrameDirectChildFrameInfo(frameInfo);
Expand All @@ -273,8 +273,8 @@ void ProcessComponent::AppendFrameInfo(
}
if (childFrameInfo)
{
CHECK_FAILURE(childFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
CHECK_FAILURE(frameInfoExperimental->get_FrameId(&childFrameId));
CHECK_FAILURE(childFrameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
CHECK_FAILURE(frameInfo2->get_FrameId(&childFrameId));
}

result << L"{frame name:" << name << L" | frame Id:" << frameId << L" | parent frame Id:"
Expand All @@ -293,12 +293,12 @@ wil::com_ptr<ICoreWebView2FrameInfo> ProcessComponent::GetAncestorMainFrameInfo(
wil::com_ptr<ICoreWebView2FrameInfo> frameInfo)
{
wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo;
wil::com_ptr<ICoreWebView2ExperimentalFrameInfo> frameInfoExperimental;
wil::com_ptr<ICoreWebView2FrameInfo2> frameInfo2;
while (frameInfo)
{
mainFrameInfo = frameInfo;
CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
CHECK_FAILURE(frameInfoExperimental->get_ParentFrameInfo(&frameInfo));
CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
CHECK_FAILURE(frameInfo2->get_ParentFrameInfo(&frameInfo));
}
return mainFrameInfo;
}
Expand All @@ -320,30 +320,28 @@ wil::com_ptr<ICoreWebView2FrameInfo> ProcessComponent::GetAncestorMainFrameDirec
{
wil::com_ptr<ICoreWebView2FrameInfo> mainFrameInfo;
wil::com_ptr<ICoreWebView2FrameInfo> childFrameInfo;
wil::com_ptr<ICoreWebView2ExperimentalFrameInfo> frameInfoExperimental;
wil::com_ptr<ICoreWebView2FrameInfo2> frameInfo2;
while (frameInfo)
{
childFrameInfo = mainFrameInfo;
mainFrameInfo = frameInfo;
CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfoExperimental)));
CHECK_FAILURE(frameInfoExperimental->get_ParentFrameInfo(&frameInfo));
CHECK_FAILURE(frameInfo->QueryInterface(IID_PPV_ARGS(&frameInfo2)));
CHECK_FAILURE(frameInfo2->get_ParentFrameInfo(&frameInfo));
}
return childFrameInfo;
}

void ProcessComponent::ShowProcessExtendedInfo()
{
auto environmentExperimental13 =
m_webViewEnvironment.try_query<ICoreWebView2ExperimentalEnvironment13>();
if (environmentExperimental13)
auto environment13 = m_webViewEnvironment.try_query<ICoreWebView2Environment13>();
if (environment13)
{
//! [GetProcessExtendedInfos]
CHECK_FAILURE(environmentExperimental13->GetProcessExtendedInfos(
Callback<ICoreWebView2ExperimentalGetProcessExtendedInfosCompletedHandler>(
CHECK_FAILURE(environment13->GetProcessExtendedInfos(
Callback<ICoreWebView2GetProcessExtendedInfosCompletedHandler>(
[this](
HRESULT error,
ICoreWebView2ExperimentalProcessExtendedInfoCollection* processCollection)
-> HRESULT
ICoreWebView2ProcessExtendedInfoCollection* processCollection) -> HRESULT
{
UINT32 processCount = 0;
UINT32 rendererProcessCount = 0;
Expand All @@ -352,7 +350,7 @@ void ProcessComponent::ShowProcessExtendedInfo()
std::wstringstream rendererProcessInfos;
for (UINT32 i = 0; i < processCount; i++)
{
Microsoft::WRL::ComPtr<ICoreWebView2ExperimentalProcessExtendedInfo>
Microsoft::WRL::ComPtr<ICoreWebView2ProcessExtendedInfo>
processExtendedInfo;
CHECK_FAILURE(
processCollection->GetValueAtIndex(i, &processExtendedInfo));
Expand Down
Loading
Loading