OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "chrome_frame/test/win_event_receiver.h" | 5 #include "chrome_frame/test/win_event_receiver.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/win/object_watcher.h" | 9 #include "base/win/object_watcher.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 i = (observer == i->observer) ? observers_.erase(i) : ++i; | 162 i = (observer == i->observer) ? observers_.erase(i) : ++i; |
163 } | 163 } |
164 | 164 |
165 if (observers_.empty()) | 165 if (observers_.empty()) |
166 win_event_receiver_.StopReceivingEvents(); | 166 win_event_receiver_.StopReceivingEvents(); |
167 } | 167 } |
168 | 168 |
169 std::string WindowWatchdog::GetWindowCaption(HWND hwnd) { | 169 std::string WindowWatchdog::GetWindowCaption(HWND hwnd) { |
170 std::string caption; | 170 std::string caption; |
171 int len = ::GetWindowTextLength(hwnd) + 1; | 171 int len = ::GetWindowTextLength(hwnd) + 1; |
172 ::GetWindowTextA(hwnd, WriteInto(&caption, len), len); | 172 if (len > 1) |
173 | 173 ::GetWindowTextA(hwnd, WriteInto(&caption, len), len); |
174 return caption; | 174 return caption; |
175 } | 175 } |
176 | 176 |
177 bool WindowWatchdog::MatchingWindow(const ObserverEntry& entry, | 177 bool WindowWatchdog::MatchingWindow(const ObserverEntry& entry, |
178 const std::string& caption, | 178 const std::string& caption, |
179 const std::string& class_name) { | 179 const std::string& class_name) { |
180 bool should_match_caption = !entry.caption_pattern.empty(); | 180 bool should_match_caption = !entry.caption_pattern.empty(); |
181 bool should_match_class = !entry.class_name_pattern.empty(); | 181 bool should_match_class = !entry.class_name_pattern.empty(); |
182 | 182 |
183 if (should_match_caption && | 183 if (should_match_caption && |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 HandleOnOpen(hwnd); | 266 HandleOnOpen(hwnd); |
267 } else { | 267 } else { |
268 DCHECK(event == EVENT_OBJECT_DESTROY || event == EVENT_OBJECT_HIDE); | 268 DCHECK(event == EVENT_OBJECT_DESTROY || event == EVENT_OBJECT_HIDE); |
269 HandleOnClose(hwnd); | 269 HandleOnClose(hwnd); |
270 } | 270 } |
271 } | 271 } |
272 | 272 |
273 void WindowWatchdog::OnHwndProcessExited(HWND hwnd) { | 273 void WindowWatchdog::OnHwndProcessExited(HWND hwnd) { |
274 HandleOnClose(hwnd); | 274 HandleOnClose(hwnd); |
275 } | 275 } |
OLD | NEW |