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.2261 testing #226

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 12 additions & 0 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 @@ -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
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
145 changes: 145 additions & 0 deletions SampleApps/WebView2APISample/ScenarioAcceleratorKeyPressed.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// 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 "ScenarioAcceleratorKeyPressed.h"

#include "AppWindow.h"
#include "CheckFailure.h"

using namespace Microsoft::WRL;

static constexpr WCHAR c_samplePath[] = L"ScenarioAcceleratorKeyPressed.html";
ScenarioAcceleratorKeyPressed::ScenarioAcceleratorKeyPressed(AppWindow* appWindow)
: m_appWindow(appWindow), m_controller(appWindow->GetWebViewController()),
m_webView(appWindow->GetWebView())
{
m_sampleUri = m_appWindow->GetLocalUri(c_samplePath);
wil::com_ptr<ICoreWebView2Settings> settings;
CHECK_FAILURE(m_webView->get_Settings(&settings));
m_settings3 = settings.try_query<ICoreWebView2Settings3>();
// Setup the web message received event handler before navigating to
// ensure we don't miss any messages.
CHECK_FAILURE(m_webView->add_WebMessageReceived(
Microsoft::WRL::Callback<ICoreWebView2WebMessageReceivedEventHandler>(
[this](ICoreWebView2* sender, ICoreWebView2WebMessageReceivedEventArgs* args)
{
wil::unique_cotaskmem_string uri;
CHECK_FAILURE(args->get_Source(&uri));

// Always validate that the origin of the message is what you expect.
if (uri.get() != m_sampleUri)
{
return S_OK;
}
wil::unique_cotaskmem_string messageRaw;
CHECK_FAILURE(args->TryGetWebMessageAsString(&messageRaw));
std::wstring message = messageRaw.get();
std::wstring reply;

if (message.compare(0, 26, L"DisableBrowserAccelerators") == 0)
{
CHECK_FAILURE(m_settings3->put_AreBrowserAcceleratorKeysEnabled(FALSE));
MessageBox(
nullptr,
L"Browser-specific accelerator keys, for example: \n"
L"Ctrl+F and F3 for Find on Page\n"
L"Ctrl+P for Print\n"
L"Ctrl+R and F5 for Reload\n"
L"Ctrl+Plus and Ctrl+Minus for zooming\n"
L"Ctrl+Shift-C and F12 for DevTools\n"
L"Special keys for browser functions, such as Back, Forward, and "
L"Search \n"
L"will be disabled after the next navigation except for F7.",
L"Settings change", MB_OK);
}
else if (message.compare(0, 25, L"EnableBrowserAccelerators") == 0)
{
CHECK_FAILURE(m_settings3->put_AreBrowserAcceleratorKeysEnabled(TRUE));
MessageBox(
nullptr,
L"Browser-specific accelerator keys, for example: \n"
L"Ctrl+F and F3 for Find on Page\n"
L"Ctrl+R and F5 for Reload\n"
L"Ctrl+Plus and Ctrl+Minus for zooming\n"
L"Ctrl+Shift-C and F12 for DevTools\n"
L"Special keys for browser functions, such as Back, Forward, and "
L"Search \n"
L"will be enabled after the next navigation except for Ctr + P.",
L"Settings change", MB_OK);
}
return S_OK;
})
.Get(),
&m_webMessageReceivedToken));

//! [IsBrowserAcceleratorKeyEnabled]
if (m_settings3)
{
// Register a handler for the AcceleratorKeyPressed event.
CHECK_FAILURE(m_controller->add_AcceleratorKeyPressed(
Callback<ICoreWebView2AcceleratorKeyPressedEventHandler>(
[this](
ICoreWebView2Controller* sender,
ICoreWebView2AcceleratorKeyPressedEventArgs* args) -> HRESULT
{
COREWEBVIEW2_KEY_EVENT_KIND kind;
CHECK_FAILURE(args->get_KeyEventKind(&kind));
// We only care about key down events.
if (kind == COREWEBVIEW2_KEY_EVENT_KIND_KEY_DOWN ||
kind == COREWEBVIEW2_KEY_EVENT_KIND_SYSTEM_KEY_DOWN)
{
UINT key;
CHECK_FAILURE(args->get_VirtualKey(&key));

wil::com_ptr<ICoreWebView2AcceleratorKeyPressedEventArgs2> args2;

args->QueryInterface(IID_PPV_ARGS(&args2));
if (args2)
{
if (key == 'P' && (GetKeyState(VK_CONTROL) < 0))
{
// tell the browser to skip the key
CHECK_FAILURE(args2->put_IsBrowserAcceleratorKeyEnabled(FALSE));
}
if (key == VK_F7)
{
// tell the browser to process the key
CHECK_FAILURE(args2->put_IsBrowserAcceleratorKeyEnabled(TRUE));
}
}
}
return S_OK;
})
.Get(),
&m_acceleratorKeyPressedToken));
}
//! [IsBrowserAcceleratorKeyEnabled]

// Turn off this scenario if we navigate away from the sample page
CHECK_FAILURE(m_webView->add_ContentLoading(
Callback<ICoreWebView2ContentLoadingEventHandler>(
[this](ICoreWebView2* sender, ICoreWebView2ContentLoadingEventArgs* args) -> HRESULT
{
wil::unique_cotaskmem_string uri;
sender->get_Source(&uri);
if (uri.get() != m_sampleUri)
{
m_appWindow->DeleteComponent(this);
}
return S_OK;
})
.Get(),
&m_contentLoadingToken));

CHECK_FAILURE(m_webView->Navigate(m_sampleUri.c_str()));
}

ScenarioAcceleratorKeyPressed::~ScenarioAcceleratorKeyPressed()
{
m_webView->remove_WebMessageReceived(m_webMessageReceivedToken);
m_controller->remove_AcceleratorKeyPressed(m_acceleratorKeyPressedToken);
m_webView->remove_ContentLoading(m_contentLoadingToken);
}
29 changes: 29 additions & 0 deletions SampleApps/WebView2APISample/ScenarioAcceleratorKeyPressed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 <string>

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

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

private:
EventRegistrationToken m_acceleratorKeyPressedToken = {};
EventRegistrationToken m_contentLoadingToken = {};
EventRegistrationToken m_webMessageReceivedToken = {};

AppWindow* m_appWindow = nullptr;
std::wstring m_sampleUri;
wil::com_ptr<ICoreWebView2Controller> m_controller;
wil::com_ptr<ICoreWebView2> m_webView;
wil::com_ptr<ICoreWebView2Settings3> m_settings3;
};
Loading
Loading