From d0b683b69c926467468b4ca0b93d670317f7a2dc Mon Sep 17 00:00:00 2001 From: "jcivelli@chromium.org" Date: Wed, 19 May 2010 16:07:03 +0000 Subject: A crasher would sometimes happen when opening a selet file dialog (such as when loading an unpacled extension). This is because we would reinterpret cast the user data of the HWND to a WidgetWin, and in that case the Windows dialog has a user-data that we did not set. This CL checks that the HWND is at least a WindowImpl before attempting to retrieve the WidgetWin, ensuring we won't mess with windows we did not create directly. BUG=44312 TEST=Open the extension page. Move the focus by pressing TAB to the "Load unpacked extension..." button. Press ENTER many times quickly so it opens/closes the "Select dir" dialog. It should not crash. Review URL: http://codereview.chromium.org/2124009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47672 0039d316-1c4b-4281-b951-d872f2087c98 --- app/win/window_impl.cc | 10 ++++++++++ app/win/window_impl.h | 3 +++ 2 files changed, 13 insertions(+) (limited to 'app') diff --git a/app/win/window_impl.cc b/app/win/window_impl.cc index 9668f82..5488434 100644 --- a/app/win/window_impl.cc +++ b/app/win/window_impl.cc @@ -152,6 +152,16 @@ HICON WindowImpl::GetDefaultWindowIcon() const { return NULL; } +// static +bool WindowImpl::IsWindowImpl(HWND hwnd) { + wchar_t tmp[128]; + if (!::GetClassName(hwnd, tmp, 128)) + return false; + + std::wstring class_name(tmp); + return class_name.find(kBaseClassName) == 0; +} + LRESULT WindowImpl::OnWndProc(UINT message, WPARAM w_param, LPARAM l_param) { LRESULT result = 0; diff --git a/app/win/window_impl.h b/app/win/window_impl.h index ad1fc87..67f3bf7 100644 --- a/app/win/window_impl.h +++ b/app/win/window_impl.h @@ -70,6 +70,9 @@ class WindowImpl : public MessageMapInterface { } UINT initial_class_style() const { return class_style_; } + // Returns true if the specified |hwnd| is a WindowImpl. + static bool IsWindowImpl(HWND hwnd); + protected: // Handles the WndProc callback for this object. virtual LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param); -- cgit v1.1