| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // chrome_frame_helper_main.cc : The .exe that bootstraps the |
| 6 // chrome_frame_helper.dll. |
| 7 // |
| 8 // This is a small exe that loads the hook dll to set the event hooks and then |
| 9 // waits in a message loop. It is intended to be shut down by looking for a |
| 10 // window with the class and title |
| 11 // kChromeFrameHelperWindowClassName and kChromeFrameHelperWindowName and then |
| 12 // sending that window a WM_CLOSE message. |
| 13 // |
| 14 |
| 15 #include <crtdbg.h> |
| 16 #include <windows.h> |
| 17 |
| 18 // Window class and window names. |
| 19 const wchar_t kChromeFrameHelperWindowClassName[] = |
| 20 L"ChromeFrameHelperWindowClass"; |
| 21 const wchar_t kChromeFrameHelperWindowName[] = |
| 22 L"ChromeFrameHelperWindowName"; |
| 23 |
| 24 // Small helper class that assists in loading the DLL that contains code |
| 25 // to register our event hook callback. Automatically removes the hook and |
| 26 // unloads the DLL on destruction. |
| 27 class HookDllLoader { |
| 28 public: |
| 29 HookDllLoader() : dll_(NULL), start_proc_(NULL), stop_proc_(NULL) {} |
| 30 ~HookDllLoader() { |
| 31 if (dll_) { |
| 32 Unload(); |
| 33 } |
| 34 } |
| 35 |
| 36 bool Load() { |
| 37 dll_ = LoadLibrary(L"chrome_frame_helper.dll"); |
| 38 if (dll_) { |
| 39 start_proc_ = GetProcAddress(dll_, "StartUserModeBrowserInjection"); |
| 40 stop_proc_ = GetProcAddress(dll_, "StopUserModeBrowserInjection"); |
| 41 } |
| 42 |
| 43 bool result = true; |
| 44 if (!start_proc_ || !stop_proc_) { |
| 45 _ASSERTE(L"failed to load hook dll."); |
| 46 result = false; |
| 47 } else { |
| 48 if (FAILED(start_proc_())) { |
| 49 _ASSERTE(L"failed to initialize hook dll."); |
| 50 result = false; |
| 51 } |
| 52 } |
| 53 return result; |
| 54 } |
| 55 |
| 56 void Unload() { |
| 57 if (stop_proc_) { |
| 58 stop_proc_(); |
| 59 } |
| 60 if (dll_) { |
| 61 FreeLibrary(dll_); |
| 62 } |
| 63 } |
| 64 |
| 65 private: |
| 66 HMODULE dll_; |
| 67 PROC start_proc_; |
| 68 PROC stop_proc_; |
| 69 }; |
| 70 |
| 71 |
| 72 LRESULT CALLBACK ChromeFrameHelperWndProc(HWND hwnd, |
| 73 UINT message, |
| 74 WPARAM wparam, |
| 75 LPARAM lparam) { |
| 76 switch (message) { |
| 77 case WM_DESTROY: |
| 78 PostQuitMessage(0); |
| 79 break; |
| 80 default: |
| 81 return ::DefWindowProc(hwnd, message, wparam, lparam); |
| 82 } |
| 83 return 0; |
| 84 } |
| 85 |
| 86 HWND RegisterAndCreateWindow(HINSTANCE hinstance) { |
| 87 WNDCLASSEX wcex = {0}; |
| 88 wcex.cbSize = sizeof(WNDCLASSEX); |
| 89 wcex.lpfnWndProc = ChromeFrameHelperWndProc; |
| 90 wcex.hInstance = GetModuleHandle(NULL); |
| 91 wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1); |
| 92 wcex.lpszClassName = kChromeFrameHelperWindowClassName; |
| 93 RegisterClassEx(&wcex); |
| 94 |
| 95 HWND hwnd = CreateWindow(kChromeFrameHelperWindowClassName, |
| 96 kChromeFrameHelperWindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, |
| 97 CW_USEDEFAULT, 0, NULL, NULL, hinstance, NULL); |
| 98 |
| 99 return hwnd; |
| 100 } |
| 101 |
| 102 int APIENTRY wWinMain(HINSTANCE hinstance, HINSTANCE, wchar_t*, int show_cmd) { |
| 103 // TODO(robertshield): Before this actually gets used, add breakpad |
| 104 // integration. |
| 105 |
| 106 // Create a window with a known class and title just to listen for WM_CLOSE |
| 107 // messages that will shut us down. |
| 108 HWND hwnd = RegisterAndCreateWindow(hinstance); |
| 109 _ASSERTE(hwnd); |
| 110 |
| 111 // Load the hook dll, and set the event hooks. |
| 112 HookDllLoader loader; |
| 113 bool loaded = loader.Load(); |
| 114 _ASSERTE(loaded); |
| 115 |
| 116 if (loaded) { |
| 117 MSG msg; |
| 118 BOOL ret; |
| 119 // Main message loop: |
| 120 while ((ret = GetMessage(&msg, NULL, 0, 0))) { |
| 121 if (ret == -1) { |
| 122 break; |
| 123 } else { |
| 124 TranslateMessage(&msg); |
| 125 DispatchMessage(&msg); |
| 126 } |
| 127 } |
| 128 } |
| 129 |
| 130 return 0; |
| 131 } |
| OLD | NEW |