Skip to content

Commit 33a5a3e

Browse files
authored
Merge pull request #286 from MicrosoftEdge/smoketest/1.0.3650-testing
Smoketest/1.0.3650 testing
2 parents d56e43c + a3d3f76 commit 33a5a3e

14 files changed

+688
-393
lines changed

SampleApps/WebView2APISample/AppWindow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "ScenarioSaveAs.h"
5656
#include "ScenarioScreenCapture.h"
5757
#include "ScenarioSensitivityLabel.h"
58+
#include "ScenarioServiceWorkerWRR.h"
5859
#include "ScenarioSharedBuffer.h"
5960
#include "ScenarioSharedWorkerWRR.h"
6061
#include "ScenarioThrottlingControl.h"
@@ -611,6 +612,11 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
611612
NewComponent<ScenarioSharedWorkerWRR>(this);
612613
return true;
613614
}
615+
case IDM_SCENARIO_SERVICE_WORKER_WRR:
616+
{
617+
NewComponent<ScenarioServiceWorkerWRR>(this);
618+
return true;
619+
}
614620
case IDM_SCENARIO_SHARED_BUFFER:
615621
{
616622
NewComponent<ScenarioSharedBuffer>(this);

SampleApps/WebView2APISample/AppWindow.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ class AppWindow
172172
{
173173
return m_webviewOption;
174174
}
175-
176175
private:
177176
static PCWSTR GetWindowClass();
178177

@@ -291,6 +290,7 @@ class AppWindow
291290

292291
bool m_CustomCrashReportingEnabled = false;
293292
bool m_TrackingPreventionEnabled = true;
293+
private:
294294
// Fullscreen related code
295295
RECT m_previousWindowRect;
296296
HMENU m_hMenu;
@@ -299,6 +299,7 @@ class AppWindow
299299
bool m_isPopupWindow = false;
300300
void EnterFullScreen();
301301
void ExitFullScreen();
302+
302303
// Compositor creation helper methods
303304
HRESULT DCompositionCreateDevice2(IUnknown* renderingDevice, REFIID riid, void** ppv);
304305
HRESULT TryCreateDispatcherQueue();
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Copyright (C) Microsoft Corporation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "stdafx.h"
6+
7+
#include "ScenarioServiceWorkerWRR.h"
8+
9+
#include "AppWindow.h"
10+
#include "CheckFailure.h"
11+
12+
#include "shlwapi.h"
13+
14+
using namespace Microsoft::WRL;
15+
16+
static constexpr WCHAR c_samplePath[] =
17+
L"https://mdn.github.io/dom-examples/service-worker/simple-service-worker/";
18+
static constexpr WCHAR c_wrrUrlPattern[] = L"*";
19+
20+
ScenarioServiceWorkerWRR::ScenarioServiceWorkerWRR(AppWindow* appWindow)
21+
: m_appWindow(appWindow), m_webView(appWindow->GetWebView()), m_sampleUri(c_samplePath)
22+
{
23+
wil::com_ptr<ICoreWebView2_22> webView_22 = m_webView.try_query<ICoreWebView2_22>();
24+
CHECK_FEATURE_RETURN_EMPTY(webView_22);
25+
26+
webView_22->AddWebResourceRequestedFilterWithRequestSourceKinds(
27+
c_wrrUrlPattern, COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL,
28+
COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL);
29+
webView_22->add_WebResourceRequested(
30+
Callback<ICoreWebView2WebResourceRequestedEventHandler>(
31+
[this](ICoreWebView2* sender, ICoreWebView2WebResourceRequestedEventArgs* args)
32+
-> HRESULT
33+
{
34+
COREWEBVIEW2_WEB_RESOURCE_CONTEXT resourceContext;
35+
args->get_ResourceContext(&resourceContext);
36+
wil::com_ptr<ICoreWebView2WebResourceRequest> request;
37+
CHECK_FAILURE(args->get_Request(&request));
38+
wil::unique_cotaskmem_string uri;
39+
CHECK_FAILURE(request->get_Uri(&uri));
40+
if (wcscmp(uri.get(), c_samplePath) != 0)
41+
{
42+
return S_OK;
43+
}
44+
45+
wil::com_ptr<IStream> stream;
46+
// Create a stream with some text content
47+
std::string content = "<html><head><script>"
48+
"navigator.serviceWorker.register('sw.js')"
49+
"</script></head><body><h1>Response from WV2 "
50+
"interceptor!</h1></body></html>";
51+
52+
stream.attach(SHCreateMemStream(
53+
reinterpret_cast<const BYTE*>(content.c_str()),
54+
static_cast<UINT>(content.size())));
55+
56+
wil::com_ptr<ICoreWebView2WebResourceResponse> response;
57+
wil::com_ptr<ICoreWebView2Environment> environment;
58+
wil::com_ptr<ICoreWebView2_2> webview2;
59+
m_webView->QueryInterface(IID_PPV_ARGS(&webview2));
60+
webview2->get_Environment(&environment);
61+
environment->CreateWebResourceResponse(
62+
stream.get(), 200, L"OK", L"Content-Type: text/html", &response);
63+
args->put_Response(response.get());
64+
return S_OK;
65+
})
66+
.Get(),
67+
&m_webResourceRequestedToken);
68+
69+
// Turn off this scenario if we navigate away from the sample page.
70+
CHECK_FAILURE(m_webView->add_ContentLoading(
71+
Callback<ICoreWebView2ContentLoadingEventHandler>(
72+
[this](ICoreWebView2* sender, ICoreWebView2ContentLoadingEventArgs* args) -> HRESULT
73+
{
74+
wil::unique_cotaskmem_string uri;
75+
sender->get_Source(&uri);
76+
if (uri.get() != m_sampleUri)
77+
{
78+
m_appWindow->DeleteComponent(this);
79+
}
80+
return S_OK;
81+
})
82+
.Get(),
83+
&m_contentLoadingToken));
84+
85+
CHECK_FAILURE(m_webView->Navigate(m_sampleUri.c_str()));
86+
}
87+
88+
ScenarioServiceWorkerWRR::~ScenarioServiceWorkerWRR()
89+
{
90+
wil::com_ptr<ICoreWebView2_22> webView_22 = m_webView.try_query<ICoreWebView2_22>();
91+
if (webView_22)
92+
{
93+
CHECK_FAILURE(webView_22->RemoveWebResourceRequestedFilterWithRequestSourceKinds(
94+
c_wrrUrlPattern, COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL,
95+
COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL));
96+
}
97+
98+
CHECK_FAILURE(m_webView->remove_WebResourceRequested(m_webResourceRequestedToken));
99+
m_webView->remove_ContentLoading(m_contentLoadingToken);
100+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (C) Microsoft Corporation. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "stdafx.h"
6+
7+
#include <string>
8+
9+
#include "AppWindow.h"
10+
#include "ComponentBase.h"
11+
12+
// This sample demonstrates how to intercept Service Worker requests with
13+
// WebResourceRequested event.
14+
class ScenarioServiceWorkerWRR : public ComponentBase
15+
{
16+
public:
17+
ScenarioServiceWorkerWRR(AppWindow* appWindow);
18+
~ScenarioServiceWorkerWRR() override;
19+
20+
private:
21+
AppWindow* m_appWindow;
22+
wil::com_ptr<ICoreWebView2> m_webView;
23+
std::wstring m_sampleUri;
24+
EventRegistrationToken m_contentLoadingToken = {};
25+
EventRegistrationToken m_webResourceRequestedToken = {};
26+
};

SampleApps/WebView2APISample/WebView2APISample.rc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,13 @@ BEGIN
261261
MENUITEM "Install Default Extensions", IDM_SCENARIO_EXTENSIONS_MANAGEMENT_INSTALL_DEFAULT
262262
MENUITEM "Offload Default Extensions", IDM_SCENARIO_EXTENSIONS_MANAGEMENT_OFFLOAD_DEFAULT
263263
END
264-
MENUITEM "Custom scheme WebResourceRequested CORS", IDM_SCENARIO_CUSTOM_SCHEME
265-
MENUITEM "Navigate to custom scheme via WebResourceRequested", IDM_SCENARIO_CUSTOM_SCHEME_NAVIGATE
266-
MENUITEM "Shared worker WebResourceRequested", IDM_SCENARIO_SHARED_WORKER
264+
POPUP "WebResourceRequested"
265+
BEGIN
266+
MENUITEM "Custom scheme WebResourceRequested CORS", IDM_SCENARIO_CUSTOM_SCHEME
267+
MENUITEM "Navigate to custom scheme via WebResourceRequested", IDM_SCENARIO_CUSTOM_SCHEME_NAVIGATE
268+
MENUITEM "Service worker WebResourceRequested", IDM_SCENARIO_SERVICE_WORKER_WRR
269+
MENUITEM "Shared worker WebResourceRequested", IDM_SCENARIO_SHARED_WORKER
270+
END
267271
POPUP "Custom Download Experience"
268272
BEGIN
269273
MENUITEM "Use Deferred Download Dialog", IDM_SCENARIO_USE_DEFERRED_DOWNLOAD
@@ -297,7 +301,6 @@ BEGIN
297301
MENUITEM "Web Messaging", IDM_SCENARIO_POST_WEB_MESSAGE
298302
MENUITEM "WebView Event Monitor", IDM_SCENARIO_WEB_VIEW_EVENT_MONITOR
299303
MENUITEM "WebView Window Controls Overlay", IDM_SCENARIO_WINDOW_CONTROLS_OVERLAY
300-
301304
MENUITEM "Dropped file path", IDM_SCENARIO_DROPPED_FILE_PATH
302305
POPUP "Save As"
303306
BEGIN

SampleApps/WebView2APISample/WebView2APISample.vcxproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@
253253
<ClInclude Include="ScenarioSensitivityLabel.h" />
254254
<ClInclude Include="ScenarioServiceWorkerManager.h" />
255255
<ClInclude Include="ScenarioServiceWorkerPostMessage.h" />
256+
<ClInclude Include="ScenarioServiceWorkerWRR.h" />
256257
<ClInclude Include="ScenarioSharedBuffer.h" />
257258
<ClInclude Include="ScenarioSharedWorkerManager.h" />
258259
<ClInclude Include="ScenarioSharedWorkerWRR.h" />
@@ -315,6 +316,7 @@
315316
<ClCompile Include="ScenarioSensitivityLabel.cpp" />
316317
<ClCompile Include="ScenarioServiceWorkerManager.cpp" />
317318
<ClCompile Include="ScenarioServiceWorkerPostMessage.cpp" />
319+
<ClCompile Include="ScenarioServiceWorkerWRR.cpp" />
318320
<ClCompile Include="ScenarioSharedBuffer.cpp" />
319321
<ClCompile Include="ScenarioSharedWorkerManager.cpp" />
320322
<ClCompile Include="ScenarioSharedWorkerWRR.cpp" />
@@ -451,6 +453,9 @@
451453
<CopyFileToFolders Include="assets/ScenarioThrottlingControlMonitor.js">
452454
<DestinationFolders>$(OutDir)\assets</DestinationFolders>
453455
</CopyFileToFolders>
456+
<CopyFileToFolders Include="assets/ScenarioWebrtcUdpPortConfiguration.html">
457+
<DestinationFolders>$(OutDir)\assets</DestinationFolders>
458+
</CopyFileToFolders>
454459
<CopyFileToFolders Include="assets/ScenarioWindowControlsOverlay.html">
455460
<DestinationFolders>$(OutDir)\assets</DestinationFolders>
456461
</CopyFileToFolders>
@@ -525,13 +530,13 @@
525530
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
526531
<ImportGroup Label="ExtensionTargets">
527532
<Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
528-
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.3590-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.3590-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
533+
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.3650-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.3650-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
529534
</ImportGroup>
530535
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
531536
<PropertyGroup>
532537
<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>
533538
</PropertyGroup>
534539
<Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
535-
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.3590-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.3590-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
540+
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.3650-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.3650-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
536541
</Target>
537542
</Project>

SampleApps/WebView2APISample/assets/ScenarioSensitivityLabelChanged.html

Lines changed: 34 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,119 +2,69 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<title>Sensitivity Label Changed Scenario</title>
5+
<title>Sensitivity Label API Sample</title>
66
<link rel="stylesheet" href="ScenarioSensitivityLabelChanged.css">
77
</head>
88
<body>
99
<div class="container">
10-
<h1>Sensitivity Label Changed Event Scenario</h1>
10+
<h1>Sensitivity Label API Sample</h1>
1111

12+
<!-- Info box for the feature -->
1213
<div class="info-box">
13-
<h3>About This Scenario</h3>
14-
<p>This scenario demonstrates the <strong>SensitivityLabelChanged</strong> event in WebView2. This event is fired when the sensitivity label of the document changes, typically used in Microsoft Information Protection (MIP) scenarios.</p>
15-
16-
<p>The WebView2 control has registered an event handler that will show a popup dialog whenever a sensitivity label change is detected.</p>
17-
</div>
18-
19-
<div id="pirmWarningBox" class="error-box" style="display: none;">
20-
<h3>❌ PageInteractionRestrictionManager Not Available</h3>
21-
<p><strong>The navigator.pageInteractionRestrictionManager API is not available on this page.</strong></p>
22-
<p>To enable this API, you need to add this URL to the PageInteractionRestrictionManager allowlist:</p>
23-
<div class="code">
24-
<strong>URL to Add:</strong> <span id="currentUrl"></span>
25-
</div>
26-
<p><strong>How to fix:</strong></p>
27-
<ol>
28-
<li>Go to <strong>Scenario → Sensitivity Label → Set Allowlist</strong> in the menu</li>
29-
<li>Add the URL shown above to the allowlist</li>
30-
<li>Refresh this page to try again</li>
31-
</ol>
14+
<h3>About This Sample</h3>
15+
<p>This sample demonstrates how to use the <strong>PageInteractionRestrictionManager API</strong> to add and remove sensitivity labels, which triggers the <strong>SensitivityInfoChanged</strong> event in WebView2.</p>
3216
</div>
3317

34-
<div id="pirmAvailableBox" class="info-box" style="display: none;">
35-
<h3>✅ PageInteractionRestrictionManager Available</h3>
36-
<p>The navigator.pageInteractionRestrictionManager API is available and ready to use!</p>
18+
<!-- Status box for API availability -->
19+
<div id="pirmStatus" class="status-box">
20+
<h3>API Status</h3>
21+
<p id="pirmStatusText">Checking PageInteractionRestrictionManager availability...</p>
3722
</div>
3823

24+
<!-- Form for adding sensitivity labels -->
3925
<div class="form-container">
4026
<h3>Add Sensitivity Label</h3>
41-
<p>Enter the Label ID GUID and Organization ID GUID to apply a sensitivity label to this page:</p>
42-
43-
<div class="form-group">
44-
<label for="labelIdInput">Label ID GUID:</label>
45-
<input type="text" id="labelIdInput" placeholder="e.g., 12345678-1234-1234-1234-123456789abc" />
46-
</div>
47-
48-
<div class="form-group">
49-
<label for="orgIdInput">Organization ID GUID:</label>
50-
<input type="text" id="orgIdInput" placeholder="e.g., 87654321-4321-4321-4321-cba987654321" />
51-
</div>
52-
53-
<button id="addLabelBtn" onclick="applySensitivityLabel()">Add Sensitivity Label</button>
27+
<label for="labelId">Label ID GUID:</label>
28+
<input type="text" id="labelId" placeholder="12345678-1234-1234-1234-123456789abc" />
5429

55-
<div id="resultBox" class="result-box">
56-
<strong>Success:</strong> <span id="resultMessage"></span>
57-
</div>
30+
<label for="orgId">Organization ID GUID:</label>
31+
<input type="text" id="orgId" placeholder="87654321-4321-4321-4321-cba987654321" />
5832

59-
<div id="errorBox" class="error-box">
60-
<strong>Error:</strong> <span id="errorMessage"></span>
61-
</div>
33+
<button onclick="addLabel()">Add Label</button>
6234
</div>
6335

36+
<!-- Form for removing sensitivity labels -->
6437
<div class="form-container">
6538
<h3>Remove Sensitivity Label</h3>
66-
<p>Select a label ID from the list below to remove an existing sensitivity label:</p>
39+
<label for="labelSelect">Select Label to Remove:</label>
40+
<select id="labelSelect">
41+
<option value="">No labels available</option>
42+
</select>
6743

68-
<div class="form-group">
69-
<label for="removeLabelSelect">Select Label ID to Remove:</label>
70-
<select id="removeLabelSelect" disabled>
71-
<option value="">No labels available</option>
72-
</select>
73-
</div>
74-
75-
<button id="removeLabelBtn" onclick="removeSensitivityLabel()" disabled>Remove Selected Label</button>
44+
<button onclick="removeLabel()">Remove Label</button>
7645
</div>
7746

78-
<h3>Test the Event</h3>
79-
<p>The sample app scenario can be tested with the following steps:</p>
80-
<ol>
81-
<li>Enter valid Label ID GUID and Organization ID GUID in the "Add Sensitivity Label" form above</li>
82-
<li>Click the "Add Sensitivity Label" button to apply a label (you can add multiple labels with different IDs)</li>
83-
<li>Select a label ID from the dropdown in the "Remove Sensitivity Label" section</li>
84-
<li>Click the "Remove Selected Label" button to remove the chosen label</li>
85-
<li>Observe the popup dialog that appears when the SensitivityLabelChanged event fires for both add and remove operations</li>
86-
<li>Alternatively, navigate to a document or website that supports Microsoft Information Protection</li>
87-
</ol>
47+
<!-- Logs of actions -->
48+
<div>
49+
<h3>Last Operation Status</h3>
50+
<p id="output" class="output"></p>
51+
</div>
8852

89-
<div class="code">
90-
<h4>JavaScript API Calls:</h4>
53+
<!-- Code sample for API usage -->
54+
<div class="code-sample">
55+
<h3>API Usage</h3>
9156
<pre>
92-
// API call for adding a label (executed when you click "Add Sensitivity Label")
93-
let lm = await navigator.pageInteractionRestrictionManager.requestLabelManager();
94-
let label_ = await lm.addLabel('MicrosoftSensitivityLabel', {
57+
// Add a sensitivity label
58+
const labelManager = await navigator.pageInteractionRestrictionManager.requestLabelManager();
59+
const label = await labelManager.addLabel('MicrosoftSensitivityLabel', {
9560
label: 'your-label-guid',
9661
organization: 'your-org-guid'
9762
});
9863

99-
// API call for removing a label (executed when you click "Remove Sensitivity Label")
100-
// Note: remove() is called on the label object returned by addLabel
101-
let result = await label_.remove();
102-
103-
// Both operations will trigger the SensitivityLabelChanged event in the WebView2 control
64+
// Remove a sensitivity label
65+
await label.remove();
10466
</pre>
10567
</div>
106-
107-
<h3>Event Handler Details</h3>
108-
<p>The C++ event handler registered for this scenario:</p>
109-
<ul>
110-
<li>Captures the new sensitivity label value</li>
111-
<li>Shows a popup dialog with the label information</li>
112-
<li>Includes timestamp for when the event occurred</li>
113-
<li>Provides context about Microsoft Information Protection</li>
114-
</ul>
115-
116-
<p><em>Navigate to a page with Microsoft Information Protection to see the event in action!</em></p>
117-
11868
</div>
11969

12070
<script src="ScenarioSensitivityLabelChanged.js"></script>

0 commit comments

Comments
 (0)