Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #25 from Microsoft/addEnableEdgeForDebug
Browse files Browse the repository at this point in the history
Calling enable/disable debug on the Edge package. This will prevent the Edge content processes from being stopped by the OS when at a breakpoint.
  • Loading branch information
andysterland committed Apr 26, 2016
2 parents e6e7db3 + 25409db commit c6673c2
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 10 deletions.
39 changes: 39 additions & 0 deletions Common/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <ExDisp.h>
#include <webapplication.h>
#include <sstream>
#include <Appmodel.h>

#define IDM_STARTDIAGNOSTICSMODE 3802
#define CP_AUTO 50001
Expand Down Expand Up @@ -434,4 +435,42 @@ namespace Helpers

return S_OK;
}

HRESULT GetEdgePackageFamilyName(_Out_ CString& packageFullName)
{
LONG result = ERROR_SUCCESS;
CString edgeFamilyName = L"Microsoft.MicrosoftEdge_8wekyb3d8bbwe";

UINT32 packageCount = 0;
UINT32 packageNamesBufferLength = 0;
result = FindPackagesByPackageFamily(edgeFamilyName, PACKAGE_FILTER_HEAD | PACKAGE_INFORMATION_BASIC, &packageCount, nullptr, &packageNamesBufferLength, nullptr, nullptr);

if (result != ERROR_SUCCESS)
{
return E_FAIL;
}

if (packageCount <= 0)
{
return E_FAIL;
}

//unique_ptr<PWSTR[]> packageNames(new PWSTR[packageCount]);
vector<PWSTR> packageNames;
packageNames.resize(packageCount);
//unique_ptr<wchar_t[]> buffer(new wchar_t[packageNamesBufferLength]);
CString buffer;

result = FindPackagesByPackageFamily(edgeFamilyName, PACKAGE_FILTER_HEAD | PACKAGE_INFORMATION_BASIC, &packageCount, packageNames.data(), &packageNamesBufferLength, buffer.GetBufferSetLength(packageNamesBufferLength), nullptr);
buffer.ReleaseBufferSetLength(packageNamesBufferLength);

if (result != ERROR_SUCCESS)
{
return E_FAIL;
}

packageFullName = packageNames[0];

return S_OK;
}
}
3 changes: 3 additions & 0 deletions Common/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ namespace Helpers

HRESULT OpenUrlInMicrosoftEdge(_In_ PCWSTR url);
HRESULT KillAllProcessByExe(const wchar_t *filename);

HRESULT GetEdgePackageFamilyName(_Out_ CString& packageFullName);
HRESULT SetEdgeForDebugging(bool enable);
}
1 change: 0 additions & 1 deletion EdgeDiagnosticsAdapter/WebSocketHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ WebSocketHandler::WebSocketHandler(_In_ LPCWSTR rootPath, _In_ HWND adapterhWnd,
this->IsServerListening = false;
std::wcout << L"Error: Starting websocket handler: " << e.what();
}

}

// WebSocket Callbacks
Expand Down
61 changes: 52 additions & 9 deletions EdgeDiagnosticsAdapter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@
CHandle hChromeProcess;
namespace po = boost::program_options;

BOOL WINAPI OnClose(DWORD reason)
{
if (hChromeProcess.m_h)
{
::TerminateProcess(hChromeProcess.m_h, 0);
}
return TRUE;
}

CString getPathToCurrentExeContainer()
{
// Get the current path that we are running from
Expand Down Expand Up @@ -99,6 +90,54 @@ void setSecurityACLs()
}
}

HRESULT setEdgeForDebugging(bool enable)
{
HRESULT hrResult = E_FAIL;

CString edgePackageFamilyName;
hrResult = Helpers::GetEdgePackageFamilyName(edgePackageFamilyName);

if (!SUCCEEDED(hrResult))
{
std::cerr << "Failed to get the full package name of Edge." << std::endl;
std::cerr << "HR Code: " << hrResult << std::endl;
return hrResult;
}

CComPtr<IPackageDebugSettings> spPackageDebugSettings;
hrResult = CoCreateInstance(CLSID_PackageDebugSettings, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&spPackageDebugSettings));

if (!SUCCEEDED(hrResult))
{
std::cerr << "Failed to CoCreateInstance of CLSID_PackageDebugSettings." << std::endl;
std::cerr << "HR Code: " << hrResult << std::endl;
return hrResult;
}

if (enable)
{
hrResult = spPackageDebugSettings->EnableDebugging(edgePackageFamilyName, NULL, NULL);
}
else
{
hrResult = spPackageDebugSettings->DisableDebugging(edgePackageFamilyName);
}

return hrResult;
}

BOOL WINAPI OnClose(DWORD reason)
{
if (hChromeProcess.m_h)
{
::TerminateProcess(hChromeProcess.m_h, 0);
}

setEdgeForDebugging(false);

return TRUE;
}

int wmain(int argc, wchar_t* argv[])
{
//::MessageBox(NULL, L"Stop here", L"STOP!", MB_ICONWARNING | MB_CANCELTRYCONTINUE | MB_DEFBUTTON3);
Expand Down Expand Up @@ -244,8 +283,12 @@ int wmain(int argc, wchar_t* argv[])
port = vm["port"].as<string>();
}

// We don't care if this fails as the developer can set it manually.
setSecurityACLs();

// We don't care if this fails or not as maybe the developer wants to do something that won't hit the PLM. In case errors went to the console.
setEdgeForDebugging(true);

// Load the proxy server
EdgeDiagnosticsAdapter proxy(getPathToCurrentExeContainer(), port);

Expand Down

0 comments on commit c6673c2

Please sign in to comment.