| Index: base/win/message_window.cc
|
| diff --git a/remoting/host/win/message_window.cc b/base/win/message_window.cc
|
| similarity index 51%
|
| rename from remoting/host/win/message_window.cc
|
| rename to base/win/message_window.cc
|
| index f0426f1c28e1ecbbca9e3af80726ab867624cd87..6b2594e21e9272e38cad8f2ac0cfc9d35673691a 100644
|
| --- a/remoting/host/win/message_window.cc
|
| +++ b/base/win/message_window.cc
|
| @@ -2,32 +2,21 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "remoting/host/win/message_window.h"
|
| +#include "base/win/message_window.h"
|
|
|
| #include "base/logging.h"
|
| #include "base/process_util.h"
|
| +#include "base/strings/string16.h"
|
| #include "base/strings/stringprintf.h"
|
| -#include "base/strings/utf_string_conversions.h"
|
| #include "base/win/wrapped_window_proc.h"
|
|
|
| -const char kClassNameFormat[] = "Chromoting_MessageWindow_%p";
|
| +const wchar_t kClassNameFormat[] = L"Chrome_MessageWindow_%p";
|
|
|
| -namespace remoting {
|
| +namespace base {
|
| namespace win {
|
|
|
| MessageWindow::MessageWindow()
|
| : atom_(0),
|
| - instance_(NULL),
|
| - window_(NULL) {
|
| - class_name_ = base::StringPrintf(kClassNameFormat, this);
|
| - instance_ = base::GetModuleFromAddress(static_cast<WNDPROC>(
|
| - &base::win::WrappedWindowProc<WindowProc>));
|
| -}
|
| -
|
| -MessageWindow::MessageWindow(const std::string& class_name, HINSTANCE instance)
|
| - : atom_(0),
|
| - class_name_(class_name),
|
| - instance_(instance),
|
| window_(NULL) {
|
| }
|
|
|
| @@ -35,30 +24,34 @@ MessageWindow::~MessageWindow() {
|
| DCHECK(CalledOnValidThread());
|
|
|
| if (window_ != NULL) {
|
| - DestroyWindow(window_);
|
| - window_ = NULL;
|
| + BOOL result = DestroyWindow(window_);
|
| + DCHECK(result);
|
| }
|
|
|
| if (atom_ != 0) {
|
| - UnregisterClass(MAKEINTATOM(atom_), instance_);
|
| - atom_ = 0;
|
| + BOOL result = UnregisterClass(
|
| + MAKEINTATOM(atom_),
|
| + base::GetModuleFromAddress(&MessageWindow::WindowProc));
|
| + DCHECK(result);
|
| }
|
| }
|
|
|
| -bool MessageWindow::Create(Delegate* delegate) {
|
| +bool MessageWindow::Create(Delegate* delegate, const wchar_t* window_name) {
|
| DCHECK(CalledOnValidThread());
|
| DCHECK(!atom_);
|
| DCHECK(!window_);
|
|
|
| // Register a separate window class for each instance of |MessageWindow|.
|
| - string16 class_name = UTF8ToUTF16(class_name_);
|
| + string16 class_name = base::StringPrintf(kClassNameFormat, this);
|
| + HINSTANCE instance = base::GetModuleFromAddress(&MessageWindow::WindowProc);
|
| +
|
| WNDCLASSEX window_class;
|
| window_class.cbSize = sizeof(window_class);
|
| window_class.style = 0;
|
| window_class.lpfnWndProc = &base::win::WrappedWindowProc<WindowProc>;
|
| window_class.cbClsExtra = 0;
|
| window_class.cbWndExtra = 0;
|
| - window_class.hInstance = instance_;
|
| + window_class.hInstance = instance;
|
| window_class.hIcon = NULL;
|
| window_class.hCursor = NULL;
|
| window_class.hbrBackground = NULL;
|
| @@ -68,12 +61,12 @@ bool MessageWindow::Create(Delegate* delegate) {
|
| atom_ = RegisterClassEx(&window_class);
|
| if (atom_ == 0) {
|
| LOG_GETLASTERROR(ERROR)
|
| - << "Failed to register the window class '" << class_name_ << "'";
|
| + << "Failed to register the window class for a message-only window";
|
| return false;
|
| }
|
|
|
| - window_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0,
|
| - instance_, delegate);
|
| + window_ = CreateWindow(MAKEINTATOM(atom_), window_name, 0, 0, 0, 0, 0,
|
| + HWND_MESSAGE, 0, instance, delegate);
|
| if (!window_) {
|
| LOG_GETLASTERROR(ERROR) << "Failed to create a message-only window";
|
| return false;
|
| @@ -87,21 +80,31 @@ LRESULT CALLBACK MessageWindow::WindowProc(HWND hwnd,
|
| UINT message,
|
| WPARAM wparam,
|
| LPARAM lparam) {
|
| - Delegate* delegate = NULL;
|
| -
|
| - // Set up the delegate before handling WM_CREATE.
|
| - if (message == WM_CREATE) {
|
| - CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(lparam);
|
| - delegate = reinterpret_cast<Delegate*>(cs->lpCreateParams);
|
| -
|
| - // Store pointer to the delegate to the window's user data.
|
| - SetLastError(ERROR_SUCCESS);
|
| - LONG_PTR result = SetWindowLongPtr(
|
| - hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(delegate));
|
| - CHECK(result != 0 || GetLastError() == ERROR_SUCCESS);
|
| - } else {
|
| - delegate = reinterpret_cast<Delegate*>(GetWindowLongPtr(hwnd,
|
| - GWLP_USERDATA));
|
| + Delegate* delegate = reinterpret_cast<Delegate*>(
|
| + GetWindowLongPtr(hwnd, GWLP_USERDATA));
|
| +
|
| + switch (message) {
|
| + // Set up the delegate before handling WM_CREATE.
|
| + case WM_CREATE: {
|
| + CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(lparam);
|
| + delegate = reinterpret_cast<Delegate*>(cs->lpCreateParams);
|
| +
|
| + // Store pointer to the delegate to the window's user data.
|
| + SetLastError(ERROR_SUCCESS);
|
| + LONG_PTR result = SetWindowLongPtr(
|
| + hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(delegate));
|
| + CHECK(result != 0 || GetLastError() == ERROR_SUCCESS);
|
| + break;
|
| + }
|
| +
|
| + // Clear the pointer to stop calling the delegate once WM_DESTROY is
|
| + // received.
|
| + case WM_DESTROY: {
|
| + SetLastError(ERROR_SUCCESS);
|
| + LONG_PTR result = SetWindowLongPtr(hwnd, GWLP_USERDATA, NULL);
|
| + CHECK(result != 0 || GetLastError() == ERROR_SUCCESS);
|
| + break;
|
| + }
|
| }
|
|
|
| // Handle the message.
|
| @@ -115,4 +118,4 @@ LRESULT CALLBACK MessageWindow::WindowProc(HWND hwnd,
|
| }
|
|
|
| } // namespace win
|
| -} // namespace remoting
|
| +} // namespace base
|
|
|