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

Unified Diff: chrome/views/focus_manager.cc

Issue 12434: Focus manager subclassing check (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 1 month 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
« no previous file with comments | « base/win_util.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/views/focus_manager.cc
===================================================================
--- chrome/views/focus_manager.cc (revision 5976)
+++ chrome/views/focus_manager.cc (working copy)
@@ -4,6 +4,7 @@
#include <algorithm>
+#include "base/histogram.h"
#include "base/logging.h"
#include "base/win_util.h"
#include "chrome/browser/render_widget_host_view_win.h"
@@ -30,6 +31,15 @@
// - prevent tab key events from being sent to views.
static const wchar_t* const kViewKey = L"__CHROME_VIEW__";
+// A property set to 1 to indicate whether the focus manager has subclassed that
+// window. We are doing this to ensure we are not subclassing several times.
+// Subclassing twice is not a problem if no one is subclassing the HWND between
+// the 2 subclassing (the 2 subclassing is ignored since the WinProc is the same
+// as the current one). However if some other app goes and subclasses the HWND
+// between the 2 subclassing, we will end up subclassing twice.
+// This flag lets us test that whether we have or not subclassed yet.
+static const wchar_t* const kSubclassed = L"__FOCUS_SUBCLASS_INSTALLED__";
+
namespace views {
static bool IsCompatibleWithMouseWheelRedirection(HWND window) {
@@ -209,15 +219,29 @@
// static
void FocusManager::InstallFocusSubclass(HWND window, View* view) {
DCHECK(window);
- win_util::Subclass(window, &FocusWindowCallback);
+
+ bool already_subclassed = reinterpret_cast<bool>(GetProp(window,
+ kSubclassed));
+ if (already_subclassed &&
+ !win_util::IsSubclassed(window, &FocusWindowCallback)) {
+ NOTREACHED() << " FocusManager sub-classed twice";
+ // Track in UMA so we know if this case happens.
+ UMA_HISTOGRAM_COUNTS(L"FocusManager.MultipleSubclass", 1);
+ } else {
+ bool success = win_util::Subclass(window, &FocusWindowCallback);
+ DCHECK(success);
+ SetProp(window, kSubclassed, reinterpret_cast<HANDLE>(true));
+ }
if (view)
SetProp(window, kViewKey, view);
}
void FocusManager::UninstallFocusSubclass(HWND window) {
DCHECK(window);
- if (win_util::Unsubclass(window, &FocusWindowCallback))
+ if (win_util::Unsubclass(window, &FocusWindowCallback)) {
RemoveProp(window, kViewKey);
+ RemoveProp(window, kSubclassed);
+ }
}
// static
« no previous file with comments | « base/win_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698