Skip to content

Commit

Permalink
Merged PR 5677497: [Git2Git] Merged PR 5655213: Allow conhost to hand…
Browse files Browse the repository at this point in the history
…off to registered default app handler

Contains:
- Delegation Configurator that can lookup/edit/save configuration information to registry
- Conhost can lookup the CLSID of a registered default
- Conhost has the ability to handoff a starting visible-window interactive session to the registered default
- Velocity key since this is a big deal and we want to be careful
- IDL for the interface

Related work items: MSFT-16458099
Retrieved from https://microsoft.visualstudio.com os.2020 OS official/rs_wdx_dxp_windev 0ca55027d8180fbbaa145f2fe7a15005856c0f7c
  • Loading branch information
DHowett committed Feb 11, 2021
1 parent 38da2ff commit 3822d5b
Show file tree
Hide file tree
Showing 25 changed files with 557 additions and 111 deletions.
33 changes: 33 additions & 0 deletions OpenConsole.sln
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests_Remoting", "src\c
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "wpf", "wpf", "{4DAF0299-495E-4CD1-A982-9BAC16A45932}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Host.Proxy", "src\host\proxy\Host.Proxy.vcxproj", "{E437B604-3E98-4F40-A927-E173E818EA4B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
AuditMode|Any CPU = AuditMode|Any CPU
Expand Down Expand Up @@ -2558,6 +2560,36 @@ Global
{68A10CD3-AA64-465B-AF5F-ED4E9700543C}.Release|x64.Build.0 = Release|x64
{68A10CD3-AA64-465B-AF5F-ED4E9700543C}.Release|x86.ActiveCfg = Release|Win32
{68A10CD3-AA64-465B-AF5F-ED4E9700543C}.Release|x86.Build.0 = Release|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.AuditMode|Any CPU.ActiveCfg = AuditMode|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.AuditMode|ARM.ActiveCfg = AuditMode|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.AuditMode|ARM64.ActiveCfg = AuditMode|ARM64
{E437B604-3E98-4F40-A927-E173E818EA4B}.AuditMode|ARM64.Build.0 = AuditMode|ARM64
{E437B604-3E98-4F40-A927-E173E818EA4B}.AuditMode|DotNet_x64Test.ActiveCfg = AuditMode|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.AuditMode|DotNet_x86Test.ActiveCfg = AuditMode|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.AuditMode|x64.ActiveCfg = AuditMode|x64
{E437B604-3E98-4F40-A927-E173E818EA4B}.AuditMode|x64.Build.0 = AuditMode|x64
{E437B604-3E98-4F40-A927-E173E818EA4B}.AuditMode|x86.ActiveCfg = AuditMode|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.AuditMode|x86.Build.0 = AuditMode|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.Debug|Any CPU.ActiveCfg = Debug|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.Debug|ARM.ActiveCfg = Debug|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.Debug|ARM64.ActiveCfg = Debug|ARM64
{E437B604-3E98-4F40-A927-E173E818EA4B}.Debug|ARM64.Build.0 = Debug|ARM64
{E437B604-3E98-4F40-A927-E173E818EA4B}.Debug|DotNet_x64Test.ActiveCfg = Debug|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.Debug|DotNet_x86Test.ActiveCfg = Debug|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.Debug|x64.ActiveCfg = Debug|x64
{E437B604-3E98-4F40-A927-E173E818EA4B}.Debug|x64.Build.0 = Debug|x64
{E437B604-3E98-4F40-A927-E173E818EA4B}.Debug|x86.ActiveCfg = Debug|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.Debug|x86.Build.0 = Debug|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.Release|Any CPU.ActiveCfg = Release|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.Release|ARM.ActiveCfg = Release|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.Release|ARM64.ActiveCfg = Release|ARM64
{E437B604-3E98-4F40-A927-E173E818EA4B}.Release|ARM64.Build.0 = Release|ARM64
{E437B604-3E98-4F40-A927-E173E818EA4B}.Release|DotNet_x64Test.ActiveCfg = Release|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.Release|DotNet_x86Test.ActiveCfg = Release|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.Release|x64.ActiveCfg = Release|x64
{E437B604-3E98-4F40-A927-E173E818EA4B}.Release|x64.Build.0 = Release|x64
{E437B604-3E98-4F40-A927-E173E818EA4B}.Release|x86.ActiveCfg = Release|Win32
{E437B604-3E98-4F40-A927-E173E818EA4B}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2648,6 +2680,7 @@ Global
{27B5AAEB-A548-44CF-9777-F8BAA32AF7AE} = {59840756-302F-44DF-AA47-441A9D673202}
{68A10CD3-AA64-465B-AF5F-ED4E9700543C} = {BDB237B6-1D1D-400F-84CC-40A58FA59C8E}
{4DAF0299-495E-4CD1-A982-9BAC16A45932} = {59840756-302F-44DF-AA47-441A9D673202}
{E437B604-3E98-4F40-A927-E173E818EA4B} = {E8F24881-5E37-4362-B191-A3BA0ED7F4EB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3140B1B7-C8EE-43D1-A772-D82A7061A271}
Expand Down
3 changes: 2 additions & 1 deletion src/host/dirs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DIRS=exe \
DIRS=proxy \
exe \
lib \
ut_lib \
ut_host \
Expand Down
81 changes: 0 additions & 81 deletions src/host/dll/host.vcxproj

This file was deleted.

4 changes: 4 additions & 0 deletions src/host/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class Globals

ApiRoutines api;

bool handoffTarget = false;

std::optional<CLSID> handoffConsoleClsid;

#ifdef UNIT_TESTING
void EnableConptyModeForTests(std::unique_ptr<Microsoft::Console::Render::VtEngine> vtRenderEngine);
#endif
Expand Down
37 changes: 37 additions & 0 deletions src/host/proxy/Host.Proxy.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{E437B604-3E98-4F40-A927-E173E818EA4B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>openconsoleproxy</RootNamespace>
<ProjectName>OpenConsoleProxy</ProjectName>
<TargetName>OpenConsoleProxy</TargetName>
<ConfigurationType>Utility</ConfigurationType>
</PropertyGroup>
<Import Project="$(SolutionDir)src\common.build.pre.props" />
<ItemGroup>
<ClInclude Include="$(IntDir)\IConsoleHandoff.h" />
</ItemGroup>
<ItemGroup>
<Midl Include="IConsoleHandoff.idl">
<!--
In Razzle, IDL files generate %FileName%.h
In Visual Studio, IDL files generate %FileName%_h.h
Visual Studio is easier to override than Razzle.
This has to be built in both the OS and outside, so we
override the easier-to-override side to a uniform name.
-->
<HeaderFileName>IConsoleHandoff.h</HeaderFileName>
<MinimumTargetSystem>NT100</MinimumTargetSystem>
<OutputDirectory>$(IntDir)</OutputDirectory>
</Midl>
</ItemGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>
<!-- Careful reordering these. Some default props (contained in these files) are order sensitive. -->
<Import Project="$(SolutionDir)src\common.build.post.props" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,16 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\precomp.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<Natvis Include="$(SolutionDir)tools\ConsoleTypes.natvis" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\precomp.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource.h">
<ClInclude Include="IConsoleHandoff_h.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ConhostV2.def">
<Midl Include="IConsoleHandoff.idl">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Host.DLL.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</Midl>
</ItemGroup>
</Project>
</Project>
26 changes: 26 additions & 0 deletions src/host/proxy/IConsoleHandoff.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import "oaidl.idl";
import "ocidl.idl";

typedef struct _CONSOLE_PORTABLE_ATTACH_MSG
{
DWORD IdLowPart;
LONG IdHighPart;
ULONG64 Process;
ULONG64 Object;
ULONG Function;
ULONG InputSize;
ULONG OutputSize;
} CONSOLE_PORTABLE_ATTACH_MSG;

typedef CONSOLE_PORTABLE_ATTACH_MSG* PCONSOLE_PORTABLE_ATTACH_MSG;
typedef const CONSOLE_PORTABLE_ATTACH_MSG* PCCONSOLE_PORTABLE_ATTACH_MSG;

[
object,
uuid(2B607BC1-43EB-40C3-95AE-2856ADDB7F23)
] interface IConsoleHandoff : IUnknown
{
HRESULT EstablishHandoff([in, system_handle(sh_file)] HANDLE server,
[in, system_handle(sh_event)] HANDLE inputEvent,
[in, ref] PCCONSOLE_PORTABLE_ATTACH_MSG msg);
};
31 changes: 31 additions & 0 deletions src/host/proxy/sources
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -------------------------------------
# Windows Console
# - Console Host COM Proxy
# -------------------------------------

# This program provides the COM call and proxy
# information for handing off one console session to another
# capable console host application.

# -------------------------------------
# Program Information
# -------------------------------------

TARGETNAME =
TARGETTYPE = NOTARGET

# -------------------------------------
# Build System Settings
# -------------------------------------

MIDL_FLAGS = $(MIDL_FLAGS)

# -------------------------------------
# Sources, Headers, and Libraries
# -------------------------------------

SOURCES = \
IConsoleHandoff.idl \

INCLUDES = \
$(INCLUDES); \
6 changes: 6 additions & 0 deletions src/host/proxy/sources.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PUBLIC_PASS0_CONSUMES= \
minkernel\published\base|PASS0 \
onecore\com\published\idlole\publish|PASS0 \
onecore\enduser\sql\xml\msxml3\publish|PASS0 \
onecore\inetcore\published\sdk\inc|PASS0 \

31 changes: 22 additions & 9 deletions src/host/srvinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "renderData.hpp"
#include "../renderer/base/renderer.hpp"

#include "../inc/conint.h"
#include "../propslib/DelegationConfig.hpp"

#pragma hdrstop

using namespace Microsoft::Console::Interactivity;
Expand All @@ -32,27 +35,37 @@ const UINT CONSOLE_EVENT_FAILURE_ID = 21790;
const UINT CONSOLE_LPC_PORT_FAILURE_ID = 21791;

[[nodiscard]] HRESULT ConsoleServerInitialization(_In_ HANDLE Server, const ConsoleArguments* const args)
try
{
Globals& Globals = ServiceLocator::LocateGlobals();

try
{
Globals.pDeviceComm = new ConDrvDeviceComm(Server);
Globals.pDeviceComm = new ConDrvDeviceComm(Server);

Globals.launchArgs = *args;

Globals.launchArgs = *args;
Globals.uiOEMCP = GetOEMCP();
Globals.uiWindowsCP = GetACP();

Globals.uiOEMCP = GetOEMCP();
Globals.uiWindowsCP = GetACP();
Globals.pFontDefaultList = new RenderFontDefaults();

Globals.pFontDefaultList = new RenderFontDefaults();
FontInfoBase::s_SetFontDefaultList(Globals.pFontDefaultList);

FontInfoBase::s_SetFontDefaultList(Globals.pFontDefaultList);
// Check if this conhost is allowed to delegate its activities to another.
// If so, look up the registered default console handler.
bool isEnabled = false;
if (SUCCEEDED(Microsoft::Console::Internal::DefaultApp::CheckDefaultAppPolicy(isEnabled) && isEnabled))
{
IID delegationClsid;
if (SUCCEEDED(DelegationConfig::s_GetConsole(delegationClsid)))
{
Globals.handoffConsoleClsid = delegationClsid;
}
}
CATCH_RETURN();

// Removed allocation of scroll buffer here.
return S_OK;
}
CATCH_RETURN()

static bool s_IsOnDesktop()
{
Expand Down
2 changes: 2 additions & 0 deletions src/host/srvinit.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ PWSTR TranslateConsoleTitle(_In_ PCWSTR pwszConsoleTitle, const BOOL fUnexpand,
[[nodiscard]] NTSTATUS ConsoleAllocateConsole(PCONSOLE_API_CONNECTINFO p);
[[nodiscard]] NTSTATUS RemoveConsole(_In_ ConsoleProcessHandle* ProcessData);

[[nodiscard]] bool ConsoleConnectionDeservesVisibleWindow(PCONSOLE_API_CONNECTINFO p);

void ConsoleCheckDebug();
5 changes: 5 additions & 0 deletions src/inc/conint.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ namespace Microsoft::Console::Internal
{
[[nodiscard]] HRESULT TrySetDarkMode(HWND hwnd) noexcept;
}

namespace DefaultApp
{
[[nodiscard]] HRESULT CheckDefaultAppPolicy(bool& isEnabled) noexcept;
}
}
7 changes: 7 additions & 0 deletions src/internal/stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ void EdpPolicy::AuditClipboard(const std::wstring_view /*destinationName*/) noex
{
return S_FALSE;
}

[[nodiscard]]
HRESULT DefaultApp::CheckDefaultAppPolicy(bool& isEnabled) noexcept
{
isEnabled = false;
return S_OK;
}
Loading

0 comments on commit 3822d5b

Please sign in to comment.