| Index: sandbox/win/tests/integration_tests/hooking_win_proc.cc
|
| diff --git a/sandbox/win/tests/integration_tests/hooking_win_proc.cc b/sandbox/win/tests/integration_tests/hooking_win_proc.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..92f8e5c318b81578c523f235ac4a3d3d2c9a450f
|
| --- /dev/null
|
| +++ b/sandbox/win/tests/integration_tests/hooking_win_proc.cc
|
| @@ -0,0 +1,93 @@
|
| +// Copyright (c) 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include <windows.h>
|
| +
|
| +namespace {
|
| +
|
| +const wchar_t* class_name = L"myWindowClass";
|
| +// WinProc event name
|
| +const wchar_t* winproc_event = L"ChromeExtensionTestEvent";
|
| +
|
| +} // namespace
|
| +
|
| +LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
| + // Injected keystroke via PostThreadMessage won't be dispatched to here.
|
| + // Have to use SendMessage or SendInput to trigger the keyboard hook.
|
| + switch (msg) {
|
| + case WM_KEYDOWN:
|
| + break;
|
| + case WM_KEYUP:
|
| + break;
|
| + case WM_CLOSE:
|
| + ::DestroyWindow(hwnd);
|
| + break;
|
| + case WM_DESTROY:
|
| + ::PostQuitMessage(0);
|
| + break;
|
| + default:
|
| + return ::DefWindowProc(hwnd, msg, wParam, lParam);
|
| + }
|
| + return 0;
|
| +}
|
| +
|
| +int WINAPI WinMain(HINSTANCE hInstance,
|
| + HINSTANCE hPrevInstance,
|
| + LPSTR lpCmdLine,
|
| + int nCmdShow) {
|
| + WNDCLASSEX wc;
|
| + HWND hwnd;
|
| + MSG msg;
|
| +
|
| + // Our parent should have set up this event already.
|
| + HANDLE event = ::OpenEventW(EVENT_MODIFY_STATE, FALSE, winproc_event);
|
| + if (event == NULL || event == INVALID_HANDLE_VALUE)
|
| + return 1;
|
| +
|
| + // Step 1: Registering the Window Class.
|
| + wc.cbSize = sizeof(WNDCLASSEX);
|
| + wc.style = 0;
|
| + wc.lpfnWndProc = WndProc;
|
| + wc.cbClsExtra = 0;
|
| + wc.cbWndExtra = 0;
|
| + wc.hInstance = hInstance;
|
| + wc.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
|
| + wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
|
| + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
| + wc.lpszMenuName = NULL;
|
| + wc.lpszClassName = class_name;
|
| + wc.hIconSm = ::LoadIcon(NULL, IDI_APPLICATION);
|
| +
|
| + if (!::RegisterClassEx(&wc))
|
| + return 1;
|
| +
|
| + // Step 2: Creating the Window.
|
| + hwnd =
|
| + ::CreateWindowExW(WS_EX_CLIENTEDGE, class_name,
|
| + L"ChromeMitigationTests", WS_OVERLAPPEDWINDOW,
|
| + CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL,
|
| + hInstance, NULL);
|
| +
|
| + if (hwnd == NULL)
|
| + return 1;
|
| +
|
| + ::ShowWindow(hwnd, nCmdShow);
|
| + ::UpdateWindow(hwnd);
|
| +
|
| + // Step 3: Let 'em know we're up and running.
|
| + ::SetEvent(event);
|
| +
|
| + // Step 4: The Message Loop
|
| + // WM_QUIT results in a 0 value from GetMessageW,
|
| + // breaking the loop.
|
| + while (::GetMessageW(&msg, NULL, 0, 0) > 0) {
|
| + ::TranslateMessage(&msg);
|
| + ::DispatchMessageW(&msg);
|
| + }
|
| +
|
| + ::SetEvent(event);
|
| + ::CloseHandle(event);
|
| +
|
| + return msg.wParam;
|
| +}
|
|
|