Skip to content

Commit 0b7d035

Browse files
Update projects to use latest WebView2 SDK 1.0.1724-prerelease (#177)
* Updates for Win32, WPF and WinForms sample apps from 113.0.1724.0 * Updated package version for Win32, WPF and WinForms sample apps to 1.0.1724-prerelease --------- Co-authored-by: WebView2 Github Bot <[email protected]>
1 parent 30faed2 commit 0b7d035

23 files changed

+1948
-650
lines changed

SampleApps/WebView2APISample/AppWindow.cpp

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,14 @@ bool AppWindow::ExecuteWebViewCommands(WPARAM wParam, LPARAM lParam)
546546
NewComponent<ScenarioCookieManagement>(this);
547547
return true;
548548
}
549+
case IDM_SCENARIO_COOKIE_MANAGEMENT_PROFILE:
550+
{
551+
NewComponent<ScenarioCookieManagement>(this, true);
552+
MessageBox(
553+
m_mainWindow, L"Got CookieManager from Profile instead of ICoreWebView2.",
554+
L"CookieManagement", MB_OK);
555+
return true;
556+
}
549557
case IDM_SCENARIO_CUSTOM_SCHEME:
550558
{
551559
NewComponent<ScenarioCustomScheme>(this);
@@ -769,6 +777,10 @@ bool AppWindow::ExecuteAppCommands(WPARAM wParam, LPARAM lParam)
769777
{
770778
return ClearBrowsingData(COREWEBVIEW2_BROWSING_DATA_KINDS_ALL_PROFILE);
771779
}
780+
case IDM_SCENARIO_CLEAR_CUSTOM_DATA_PARTITION:
781+
{
782+
return ClearCustomDataPartition();
783+
}
772784
}
773785
return false;
774786
}
@@ -797,6 +809,63 @@ bool AppWindow::ClearBrowsingData(COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds)
797809
return true;
798810
}
799811
//! [ClearBrowsingData]
812+
813+
//! [ClearCustomDataPartition]
814+
bool AppWindow::ClearCustomDataPartition()
815+
{
816+
auto webView2_13 = m_webView.try_query<ICoreWebView2_13>();
817+
CHECK_FEATURE_RETURN(webView2_13);
818+
wil::com_ptr<ICoreWebView2Profile> webView2Profile;
819+
CHECK_FAILURE(webView2_13->get_Profile(&webView2Profile));
820+
CHECK_FEATURE_RETURN(webView2Profile);
821+
auto webView2Profile7 = webView2Profile.try_query<ICoreWebView2ExperimentalProfile7>();
822+
CHECK_FEATURE_RETURN(webView2Profile7);
823+
std::wstring partitionToClearData;
824+
wil::com_ptr<ICoreWebView2Experimental20> webViewStaging20;
825+
webViewStaging20 = m_webView.try_query<ICoreWebView2Experimental20>();
826+
wil::unique_cotaskmem_string partitionId;
827+
CHECK_FAILURE(webViewStaging20->get_CustomDataPartitionId(&partitionId));
828+
if (!partitionId.get() || !*partitionId.get())
829+
{
830+
TextInputDialog dialog(
831+
GetMainWindow(), L"Custom Data Partition Id", L"Custom Data Partition Id:",
832+
L"Enter custom data partition id");
833+
if (dialog.confirmed)
834+
{
835+
partitionToClearData = dialog.input.c_str();
836+
}
837+
}
838+
else
839+
{
840+
// Use partition id from the WebView.
841+
partitionToClearData = partitionId.get();
842+
}
843+
if (!partitionToClearData.empty())
844+
{
845+
CHECK_FAILURE(webView2Profile7->ClearCustomDataPartition(
846+
partitionToClearData.c_str(),
847+
Callback<ICoreWebView2ExperimentalClearCustomDataPartitionCompletedHandler>(
848+
[this](HRESULT result) -> HRESULT
849+
{
850+
if (SUCCEEDED(result))
851+
{
852+
AsyncMessageBox(L"Completed", L"Clear Custom Data Partition");
853+
}
854+
else
855+
{
856+
std::wstringstream message;
857+
message << L"Failed: " << std::to_wstring(result) << L"(0x" << std::hex
858+
<< result << L")" << std::endl;
859+
AsyncMessageBox(message.str(), L"Clear Custom Data Partition");
860+
}
861+
return S_OK;
862+
})
863+
.Get()));
864+
}
865+
return true;
866+
}
867+
//! [ClearCustomDataPartition]
868+
800869
// Prompt the user for a new language string
801870
void AppWindow::ChangeLanguage()
802871
{
@@ -1184,7 +1253,10 @@ void AppWindow::InitializeWebView()
11841253
}
11851254
//! [CreateCoreWebView2EnvironmentWithOptions]
11861255

1256+
std::wstring args;
1257+
args.append(L"--enable-features=ThirdPartyStoragePartitioning,PartitionedCookies");
11871258
auto options = Microsoft::WRL::Make<CoreWebView2EnvironmentOptions>();
1259+
options->put_AdditionalBrowserArguments(args.c_str());
11881260
CHECK_FAILURE(
11891261
options->put_AllowSingleSignOnUsingOSPrimaryAccount(m_AADSSOEnabled ? TRUE : FALSE));
11901262
CHECK_FAILURE(options->put_ExclusiveUserDataFolderAccess(
@@ -1513,6 +1585,19 @@ HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(
15131585
// Webview creation was aborted because the user closed this window.
15141586
// No need to report this as an error.
15151587
}
1588+
else if (result == HRESULT_FROM_WIN32(ERROR_DELETE_PENDING))
1589+
{
1590+
RunAsync(
1591+
[this, result]()
1592+
{
1593+
ShowFailure(
1594+
result,
1595+
L"Failed to create webview, because the profile's name has been marked as "
1596+
L"deleted, please use a different profile's name");
1597+
m_webviewOption.PopupDialog(this);
1598+
CloseAppWindow();
1599+
});
1600+
}
15161601
else
15171602
{
15181603
ShowFailure(result, L"Failed to create webview");
@@ -1750,7 +1835,44 @@ void AppWindow::RegisterEventHandlers()
17501835
.Get(),
17511836
nullptr));
17521837
//! [NewBrowserVersionAvailable]
1838+
//! [ProfileDeleted]
1839+
auto webView2_13 = m_webView.try_query<ICoreWebView2_13>();
1840+
if (webView2_13)
1841+
{
1842+
wil::com_ptr<ICoreWebView2Profile> webView2ProfileBase;
1843+
webView2_13->get_Profile(&webView2ProfileBase);
1844+
if (webView2ProfileBase)
1845+
{
1846+
auto webView2Profile =
1847+
webView2ProfileBase.try_query<ICoreWebView2ExperimentalProfile10>();
1848+
if (webView2Profile)
1849+
{
1850+
CHECK_FAILURE(webView2Profile->add_Deleted(
1851+
Microsoft::WRL::Callback<
1852+
ICoreWebView2ExperimentalProfileDeletedEventHandler>(
1853+
[this](ICoreWebView2Profile* sender, IUnknown* args)
1854+
{
1855+
RunAsync(
1856+
[this]()
1857+
{
1858+
std::wstring message =
1859+
L"The profile has been marked for deletion. Any "
1860+
L"associated webview2 objects will be closed.";
1861+
MessageBox(
1862+
m_mainWindow, message.c_str(), L"webview2 closed",
1863+
MB_OK);
1864+
CloseAppWindow();
1865+
});
1866+
return S_OK;
1867+
})
1868+
.Get(),
1869+
nullptr));
1870+
}
1871+
}
1872+
}
1873+
//! [ProfileDeleted]
17531874
}
1875+
17541876
// Updates the sizing and positioning of everything in the window.
17551877
void AppWindow::ResizeEverything()
17561878
{

SampleApps/WebView2APISample/AppWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class AppWindow
202202
void UpdateCreationModeMenu();
203203
void ToggleAADSSO();
204204
bool ClearBrowsingData(COREWEBVIEW2_BROWSING_DATA_KINDS dataKinds);
205+
bool ClearCustomDataPartition();
205206
void UpdateAppTitle();
206207
void ToggleExclusiveUserDataFolderAccess();
207208
void ToggleCustomCrashReporting();

SampleApps/WebView2APISample/ScenarioCookieManagement.cpp

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace Microsoft::WRL;
1515

1616
static constexpr WCHAR c_samplePath[] = L"ScenarioCookieManagement.html";
1717

18-
ScenarioCookieManagement::ScenarioCookieManagement(AppWindow* appWindow)
18+
ScenarioCookieManagement::ScenarioCookieManagement(AppWindow* appWindow, bool isFromProfile)
1919
: m_appWindow(appWindow), m_webView(appWindow->GetWebView())
2020
{
2121
m_sampleUri = m_appWindow->GetLocalUri(c_samplePath);
@@ -24,12 +24,27 @@ ScenarioCookieManagement::ScenarioCookieManagement(AppWindow* appWindow)
2424
CHECK_FAILURE(m_webView->get_Settings(&settings));
2525
CHECK_FAILURE(settings->put_IsWebMessageEnabled(TRUE));
2626

27-
//! [CookieManager]
28-
auto webview2_2 = m_webView.try_query<ICoreWebView2_2>();
29-
CHECK_FEATURE_RETURN_EMPTY(webview2_2);
30-
CHECK_FAILURE(webview2_2->get_CookieManager(&m_cookieManager));
31-
//! [CookieManager]
32-
27+
if (isFromProfile)
28+
{
29+
//! [CookieManagerProfile]
30+
auto webView2_13 = m_webView.try_query<ICoreWebView2_13>();
31+
CHECK_FEATURE_RETURN_EMPTY(webView2_13);
32+
wil::com_ptr<ICoreWebView2Profile> webView2Profile;
33+
CHECK_FAILURE(webView2_13->get_Profile(&webView2Profile));
34+
auto webView2ExperimentalProfile8 =
35+
webView2Profile.try_query<ICoreWebView2ExperimentalProfile8>();
36+
CHECK_FEATURE_RETURN_EMPTY(webView2ExperimentalProfile8);
37+
CHECK_FAILURE(webView2ExperimentalProfile8->get_CookieManager(&m_cookieManager));
38+
//! [CookieManagerProfile]
39+
}
40+
else
41+
{
42+
//! [CookieManager]
43+
auto webview2_2 = m_webView.try_query<ICoreWebView2_2>();
44+
CHECK_FEATURE_RETURN_EMPTY(webview2_2);
45+
CHECK_FAILURE(webview2_2->get_CookieManager(&m_cookieManager));
46+
//! [CookieManager]
47+
}
3348
SetupEventsOnWebview();
3449

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

SampleApps/WebView2APISample/ScenarioCookieManagement.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class ScenarioCookieManagement : public ComponentBase
1414
{
1515
public:
16-
ScenarioCookieManagement(AppWindow* appWindow);
16+
ScenarioCookieManagement(AppWindow* appWindow, bool isFromProfile = false);
1717
~ScenarioCookieManagement() override;
1818

1919
private:

SampleApps/WebView2APISample/ScenarioPermissionManagement.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ std::wstring PermissionKindToString(COREWEBVIEW2_PERMISSION_KIND type)
5151
return L"other sensors";
5252
case COREWEBVIEW2_PERMISSION_KIND_MIDI_SYSTEM_EXCLUSIVE_MESSAGES:
5353
return L"midi sysex";
54+
case COREWEBVIEW2_PERMISSION_KIND_WINDOW_MANAGEMENT:
55+
return L"window management";
5456
default:
5557
return L"unknown";
5658
}
@@ -73,7 +75,8 @@ std::vector<COREWEBVIEW2_PERMISSION_KIND> permissionKinds{
7375
COREWEBVIEW2_PERMISSION_KIND_MICROPHONE,
7476
COREWEBVIEW2_PERMISSION_KIND_NOTIFICATIONS,
7577
COREWEBVIEW2_PERMISSION_KIND_OTHER_SENSORS,
76-
COREWEBVIEW2_PERMISSION_KIND_MIDI_SYSTEM_EXCLUSIVE_MESSAGES};
78+
COREWEBVIEW2_PERMISSION_KIND_MIDI_SYSTEM_EXCLUSIVE_MESSAGES,
79+
COREWEBVIEW2_PERMISSION_KIND_WINDOW_MANAGEMENT};
7780

7881
ScenarioPermissionManagement::ScenarioPermissionManagement(AppWindow* appWindow)
7982
: m_appWindow(appWindow), m_webView(appWindow->GetWebView())

SampleApps/WebView2APISample/ScenarioWebViewEventMonitor.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ using namespace Microsoft::WRL;
2020
using namespace std;
2121

2222
static constexpr wchar_t c_samplePath[] = L"ScenarioWebViewEventMonitor.html";
23-
2423
std::wstring WebResourceSourceToString(COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS source)
2524
{
2625
switch (source)
@@ -958,9 +957,7 @@ void ScenarioWebViewEventMonitor::InitializeEventView(ICoreWebView2* webviewEven
958957
-> HRESULT {
959958
wil::com_ptr<ICoreWebView2Frame> webviewFrame;
960959
CHECK_FAILURE(args->get_Frame(&webviewFrame));
961-
962960
InitializeFrameEventView(webviewFrame);
963-
964961
wil::unique_cotaskmem_string name;
965962
CHECK_FAILURE(webviewFrame->get_Name(&name));
966963

SampleApps/WebView2APISample/ScriptComponent.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ void ScriptComponent::SubscribeToCdpEvent()
635635
Callback<ICoreWebView2DevToolsProtocolEventReceivedEventHandler>(
636636
[this, eventName](
637637
ICoreWebView2* sender,
638-
ICoreWebView2DevToolsProtocolEventReceivedEventArgs* args) -> HRESULT
638+
ICoreWebView2DevToolsProtocolEventReceivedEventArgs* args) -> HRESULT
639639
{
640640
wil::unique_cotaskmem_string parameterObjectAsJson;
641641
CHECK_FAILURE(args->get_ParameterObjectAsJson(&parameterObjectAsJson));
@@ -1014,7 +1014,6 @@ void ScriptComponent::HandleIFrames()
10141014
})
10151015
.Get(),
10161016
NULL));
1017-
10181017
//! [AdditionalAllowedFrameAncestors_2]
10191018
// Set up the event listeners to handle site embedding scenario. The code will take effect
10201019
// when the site embedding page is navigated to and the embedding iframe navigates to the
@@ -1024,8 +1023,8 @@ void ScriptComponent::HandleIFrames()
10241023
// embedding a site. The result is recorded in m_siteEmbeddingIFrameCount.
10251024
CHECK_FAILURE(webview2_4->add_FrameCreated(
10261025
Callback<ICoreWebView2FrameCreatedEventHandler>(
1027-
[this](ICoreWebView2* sender, ICoreWebView2FrameCreatedEventArgs* args)
1028-
-> HRESULT
1026+
[this](
1027+
ICoreWebView2* sender, ICoreWebView2FrameCreatedEventArgs* args) -> HRESULT
10291028
{
10301029
wil::com_ptr<ICoreWebView2Frame> webviewFrame;
10311030
CHECK_FAILURE(args->get_Frame(&webviewFrame));

0 commit comments

Comments
 (0)