OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/win/message_window.h" | 5 #include "base/win/message_window.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/process_util.h" | 8 #include "base/process_util.h" |
9 #include "base/string16.h" | |
9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
10 #include "base/strings/utf_string_conversions.h" | |
11 #include "base/win/wrapped_window_proc.h" | 11 #include "base/win/wrapped_window_proc.h" |
12 | 12 |
13 const char kClassNameFormat[] = "Chromoting_MessageWindow_%p"; | 13 const wchar_t kClassNameFormat[] = L"Chrome_MessageWindow_%p"; |
cpu_(ooo_6.6-7.5)
2013/06/14 22:49:32
const string16
Sergey Ulanov
2013/06/14 22:53:06
Wouldn't that introduce static intializer/finializ
alexeypa (please no reviews)
2013/06/17 18:09:25
Global constants are required to be POD types.
cpu_(ooo_6.6-7.5)
2013/06/18 23:59:58
yeah my bad.
| |
14 | 14 |
15 namespace remoting { | 15 namespace base { |
16 namespace win { | 16 namespace win { |
17 | 17 |
18 MessageWindow::MessageWindow() | 18 MessageWindow::MessageWindow() |
19 : atom_(0), | 19 : atom_(0), |
20 instance_(NULL), | |
21 window_(NULL) { | |
22 class_name_ = base::StringPrintf(kClassNameFormat, this); | |
23 instance_ = base::GetModuleFromAddress(static_cast<WNDPROC>( | |
24 &base::win::WrappedWindowProc<WindowProc>)); | |
25 } | |
26 | |
27 MessageWindow::MessageWindow(const std::string& class_name, HINSTANCE instance) | |
28 : atom_(0), | |
29 class_name_(class_name), | |
30 instance_(instance), | |
31 window_(NULL) { | 20 window_(NULL) { |
32 } | 21 } |
33 | 22 |
34 MessageWindow::~MessageWindow() { | 23 MessageWindow::~MessageWindow() { |
35 DCHECK(CalledOnValidThread()); | 24 DCHECK(CalledOnValidThread()); |
36 | 25 |
37 if (window_ != NULL) { | 26 if (window_ != NULL) |
38 DestroyWindow(window_); | 27 DestroyWindow(window_); |
39 window_ = NULL; | |
40 } | |
41 | 28 |
42 if (atom_ != 0) { | 29 if (atom_ != 0) { |
43 UnregisterClass(MAKEINTATOM(atom_), instance_); | 30 UnregisterClass(MAKEINTATOM(atom_), |
cpu_(ooo_6.6-7.5)
2013/06/14 22:49:32
in many files we use :: for windows calls, so here
alexeypa (please no reviews)
2013/06/17 18:09:25
I prefer to avoid using explicit scope.
This poin
cpu_(ooo_6.6-7.5)
2013/06/18 23:59:58
It was all based on personal taste. I think that l
| |
44 atom_ = 0; | 31 base::GetModuleFromAddress(&MessageWindow::WindowProc)); |
45 } | 32 } |
46 } | 33 } |
47 | 34 |
48 bool MessageWindow::Create(Delegate* delegate) { | 35 bool MessageWindow::Create(Delegate* delegate) { |
49 DCHECK(CalledOnValidThread()); | 36 DCHECK(CalledOnValidThread()); |
50 DCHECK(!atom_); | 37 DCHECK(!atom_); |
51 DCHECK(!window_); | 38 DCHECK(!window_); |
52 | 39 |
53 // Register a separate window class for each instance of |MessageWindow|. | 40 // Register a separate window class for each instance of |MessageWindow|. |
54 string16 class_name = UTF8ToUTF16(class_name_); | 41 string16 class_name = base::StringPrintf(kClassNameFormat, this); |
cpu_(ooo_6.6-7.5)
2013/06/14 22:49:32
so one of the main uses is for example in our proc
alexeypa (please no reviews)
2013/06/17 18:09:25
I was going to update MessageWindow at some point
cpu_(ooo_6.6-7.5)
2013/06/18 23:59:58
I don't see how lazy class registration solves the
alexeypa (please no reviews)
2013/06/19 00:04:57
With lazy initialization there will be a single wi
| |
42 HINSTANCE instance = base::GetModuleFromAddress(&MessageWindow::WindowProc); | |
43 | |
55 WNDCLASSEX window_class; | 44 WNDCLASSEX window_class; |
56 window_class.cbSize = sizeof(window_class); | 45 window_class.cbSize = sizeof(window_class); |
57 window_class.style = 0; | 46 window_class.style = 0; |
58 window_class.lpfnWndProc = &base::win::WrappedWindowProc<WindowProc>; | 47 window_class.lpfnWndProc = &base::win::WrappedWindowProc<WindowProc>; |
59 window_class.cbClsExtra = 0; | 48 window_class.cbClsExtra = 0; |
60 window_class.cbWndExtra = 0; | 49 window_class.cbWndExtra = 0; |
61 window_class.hInstance = instance_; | 50 window_class.hInstance = instance; |
62 window_class.hIcon = NULL; | 51 window_class.hIcon = NULL; |
63 window_class.hCursor = NULL; | 52 window_class.hCursor = NULL; |
64 window_class.hbrBackground = NULL; | 53 window_class.hbrBackground = NULL; |
65 window_class.lpszMenuName = NULL; | 54 window_class.lpszMenuName = NULL; |
66 window_class.lpszClassName = class_name.c_str(); | 55 window_class.lpszClassName = class_name.c_str(); |
67 window_class.hIconSm = NULL; | 56 window_class.hIconSm = NULL; |
68 atom_ = RegisterClassEx(&window_class); | 57 atom_ = RegisterClassEx(&window_class); |
69 if (atom_ == 0) { | 58 if (atom_ == 0) { |
70 LOG_GETLASTERROR(ERROR) | 59 LOG_GETLASTERROR(ERROR) |
71 << "Failed to register the window class '" << class_name_ << "'"; | 60 << "Failed to register the window class for a message-only window"; |
72 return false; | 61 return false; |
73 } | 62 } |
74 | 63 |
75 window_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, | 64 window_ = CreateWindow(MAKEINTATOM(atom_), 0, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, |
76 instance_, delegate); | 65 instance, delegate); |
77 if (!window_) { | 66 if (!window_) { |
78 LOG_GETLASTERROR(ERROR) << "Failed to create a message-only window"; | 67 LOG_GETLASTERROR(ERROR) << "Failed to create a message-only window"; |
79 return false; | 68 return false; |
80 } | 69 } |
81 | 70 |
82 return true; | 71 return true; |
83 } | 72 } |
84 | 73 |
85 // static | 74 // static |
86 LRESULT CALLBACK MessageWindow::WindowProc(HWND hwnd, | 75 LRESULT CALLBACK MessageWindow::WindowProc(HWND hwnd, |
(...skipping 15 matching lines...) Expand all Loading... | |
102 } else { | 91 } else { |
103 delegate = reinterpret_cast<Delegate*>(GetWindowLongPtr(hwnd, | 92 delegate = reinterpret_cast<Delegate*>(GetWindowLongPtr(hwnd, |
104 GWLP_USERDATA)); | 93 GWLP_USERDATA)); |
105 } | 94 } |
106 | 95 |
107 // Handle the message. | 96 // Handle the message. |
108 if (delegate) { | 97 if (delegate) { |
109 LRESULT message_result; | 98 LRESULT message_result; |
110 if (delegate->HandleMessage(hwnd, message, wparam, lparam, &message_result)) | 99 if (delegate->HandleMessage(hwnd, message, wparam, lparam, &message_result)) |
111 return message_result; | 100 return message_result; |
112 } | 101 } |
cpu_(ooo_6.6-7.5)
2013/06/14 22:49:32
An improvement here is to stop calling the delegat
alexeypa (please no reviews)
2013/06/17 18:09:25
Done.
| |
113 | 102 |
114 return DefWindowProc(hwnd, message, wparam, lparam); | 103 return DefWindowProc(hwnd, message, wparam, lparam); |
115 } | 104 } |
116 | 105 |
117 } // namespace win | 106 } // namespace win |
118 } // namespace remoting | 107 } // namespace base |
OLD | NEW |