Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Unified Diff: remoting/host/win/message_window.cc

Issue 13142002: Moved code implementing message-only windows to a dedicated class (Windows only). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/win/message_window.cc
diff --git a/remoting/host/win/message_window.cc b/remoting/host/win/message_window.cc
new file mode 100644
index 0000000000000000000000000000000000000000..657f8b58654192a36dba96219a2dddf0ba2e91a6
--- /dev/null
+++ b/remoting/host/win/message_window.cc
@@ -0,0 +1,112 @@
+// Copyright 2013 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 "remoting/host/win/message_window.h"
+
+#include "base/logging.h"
+#include "base/process_util.h"
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "base/win/wrapped_window_proc.h"
+
+const char kClassNameFormat[] = "Chromoting_MessageWindow_%p";
+
+namespace remoting {
+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) {
+}
+
+MessageWindow::~MessageWindow() {
+ DCHECK(CalledOnValidThread());
+
+ if (window_ != NULL) {
+ DestroyWindow(window_);
+ window_ = NULL;
+ }
+
+ if (atom_ != 0) {
+ UnregisterClass(MAKEINTATOM(atom_), instance_);
+ atom_ = 0;
+ }
+}
+
+bool MessageWindow::Create(Delegate* delegate) {
+ DCHECK(CalledOnValidThread());
+ DCHECK(!atom_);
+ DCHECK(!window_);
+
+ // Register a separate window class for each instance of |MessageWindow|.
+ string16 class_name = UTF8ToUTF16(class_name_);
+ 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.hIcon = NULL;
+ window_class.hCursor = NULL;
+ window_class.hbrBackground = NULL;
+ window_class.lpszMenuName = NULL;
+ window_class.lpszClassName = class_name.c_str();
+ window_class.hIconSm = NULL;
+ atom_ = RegisterClassEx(&window_class);
+ if (atom_ == 0) {
+ LOG_GETLASTERROR(ERROR)
+ << "Failed to register the window class '" << class_name_ << "'";
+ return false;
+ }
+
+ window_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0,
+ instance_, delegate);
+ if (window_ == NULL) {
+ LOG_GETLASTERROR(ERROR) << "Failed to create a message-only window";
+ return false;
+ }
+
+ return true;
+}
+
+// static
+LRESULT CALLBACK MessageWindow::WindowProc(HWND hwnd,
+ UINT message,
+ WPARAM wparam,
+ LPARAM lparam) {
+ // Store |this| to the window's user data.
dcaiafa 2013/03/28 23:25:35 You're actually storing delegate here, not |this|.
alexeypa (please no reviews) 2013/03/29 16:57:01 Done.
+ if (message == WM_CREATE) {
+ CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(lparam);
+ SetLastError(ERROR_SUCCESS);
+ LONG_PTR result = SetWindowLongPtr(
+ hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(cs->lpCreateParams));
+ CHECK(result != 0 || GetLastError() == ERROR_SUCCESS);
+ }
+
+ // Handle the message.
+ Delegate* delegate = reinterpret_cast<Delegate*>(
+ GetWindowLongPtr(hwnd, GWLP_USERDATA));
+ if (delegate) {
+ LRESULT result;
+ if (delegate->HandleMessage(message, wparam, lparam, &result))
+ return result;
+ }
+
+ return DefWindowProc(hwnd, message, wparam, lparam);
+}
+
+} // namespace win
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698