// 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 "ScenarioVirtualHostMappingForPopUpWindow.h" #include "AppWindow.h" #include "CheckFailure.h" using namespace Microsoft::WRL; static constexpr WCHAR c_samplePath[] = L"ScenarioVirtualHostMappingForPopUpWindow.html"; ScenarioVirtualHostMappingForPopUpWindow::ScenarioVirtualHostMappingForPopUpWindow( AppWindow* appWindow) : m_appWindow(appWindow), m_webView(appWindow->GetWebView()) { m_sampleUri = m_appWindow->GetLocalUri(c_samplePath); m_appWindow->EnableHandlingNewWindowRequest(false); // Turn off this scenario if we navigate away from the sample page CHECK_FAILURE(m_webView->add_ContentLoading( Callback( [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())); } ScenarioVirtualHostMappingForPopUpWindow::~ScenarioVirtualHostMappingForPopUpWindow() { m_appWindow->EnableHandlingNewWindowRequest(true); m_webView->remove_ContentLoading(m_contentLoadingToken); }