forked from MicrosoftEdge/WebView2Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScenarioVirtualHostMappingForSW.cpp
41 lines (34 loc) · 1.38 KB
/
ScenarioVirtualHostMappingForSW.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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 "ScenarioVirtualHostMappingForSW.h"
#include "AppWindow.h"
#include "CheckFailure.h"
using namespace Microsoft::WRL;
static constexpr WCHAR c_samplePath[] = L"sw_scope/index.html";
ScenarioVirtualHostMappingForSW::ScenarioVirtualHostMappingForSW(AppWindow* appWindow)
: m_appWindow(appWindow), m_webView(appWindow->GetWebView())
{
m_sampleUri = m_appWindow->GetLocalUri(c_samplePath);
// 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()));
}
ScenarioVirtualHostMappingForSW::~ScenarioVirtualHostMappingForSW()
{
m_webView->remove_ContentLoading(m_contentLoadingToken);
}