summaryrefslogtreecommitdiffstats
path: root/chrome/views/widget
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-27 20:51:51 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-27 20:51:51 +0000
commitaef15bdabed270718140d5ec2eee49878bd91384 (patch)
tree2a5e395791ca9d9691987018a201c5b2ff70cf12 /chrome/views/widget
parentffeba6d07caa89ac69f1c2ef0c19aa3b1bbe4117 (diff)
downloadchromium_src-aef15bdabed270718140d5ec2eee49878bd91384.zip
chromium_src-aef15bdabed270718140d5ec2eee49878bd91384.tar.gz
chromium_src-aef15bdabed270718140d5ec2eee49878bd91384.tar.bz2
Relanding this.
The Ole unitialization was failing on one of the Vista build-bot. It is not clear when the Ole initialization is balanced when a CRichEditCtrl is created/destructed. So I now turn it off explicitly. This CL makes sure we unregister our Windows window classes when shut-down. It also balances-out an OLE initialization performed by the CRichEditCTRL. This is necessary for allowing to reload chrome.dll in a process, which is what the browser tests will do. BUG=None TEST=None Review URL: http://codereview.chromium.org/101004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14649 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views/widget')
-rw-r--r--chrome/views/widget/widget_win.cc102
1 files changed, 64 insertions, 38 deletions
diff --git a/chrome/views/widget/widget_win.cc b/chrome/views/widget/widget_win.cc
index a362f21..bdd709f 100644
--- a/chrome/views/widget/widget_win.cc
+++ b/chrome/views/widget/widget_win.cc
@@ -42,13 +42,6 @@ NativeControlWin* GetNativeControlWinForHWND(HWND hwnd) {
::GetProp(hwnd, NativeControlWin::kNativeControlWinKey));
}
-// Used to locate the WidgetWin issuing the current Create. Only valid for the
-// life of Create.
-//
-// This obviously assumes we only create WidgetWins from the same thread,
-// which is currently the case.
-static WidgetWin* instance_issuing_create = NULL;
-
///////////////////////////////////////////////////////////////////////////////
// Window class tracking.
@@ -66,36 +59,75 @@ struct ClassInfo {
background(NULL) {}
// Compares two ClassInfos. Returns true if all members match.
- bool Equals(const ClassInfo& other) {
+ bool Equals(const ClassInfo& other) const {
return (other.style == style && other.background == background);
}
};
-// Represents a registered window class.
-struct RegisteredClass {
- RegisteredClass(const ClassInfo& info,
- const std::wstring& name,
- ATOM atom)
- : info(info),
- name(name),
- atom(atom) {
+class ClassRegistrar {
+ public:
+ ~ClassRegistrar() {
+ for (RegisteredClasses::iterator i = registered_classes_.begin();
+ i != registered_classes_.end(); ++i) {
+ UnregisterClass(i->name.c_str(), NULL);
+ }
}
- // Info used to create the class.
- ClassInfo info;
+ // Puts the name for the class matching |class_info| in |class_name|, creating
+ // a new name if the class is not yet known.
+ // Returns true if this class was already known, false otherwise.
+ bool RetrieveClassName(const ClassInfo& class_info, std::wstring* name) {
+ for (RegisteredClasses::const_iterator i = registered_classes_.begin();
+ i != registered_classes_.end(); ++i) {
+ if (class_info.Equals(i->info)) {
+ name->assign(i->name);
+ return true;
+ }
+ }
- // The name given to the window.
- std::wstring name;
+ name->assign(std::wstring(WidgetWin::kBaseClassName) +
+ IntToWString(registered_count_++));
+ return false;
+ }
- // The ATOM returned from creating the window.
- ATOM atom;
-};
+ void RegisterClass(const ClassInfo& class_info,
+ const std::wstring& name,
+ ATOM atom) {
+ registered_classes_.push_back(RegisteredClass(class_info, name, atom));
+ }
+
+ private:
+ // Represents a registered window class.
+ struct RegisteredClass {
+ RegisteredClass(const ClassInfo& info,
+ const std::wstring& name,
+ ATOM atom)
+ : info(info),
+ name(name),
+ atom(atom) {
+ }
-typedef std::list<RegisteredClass> RegisteredClasses;
+ // Info used to create the class.
+ ClassInfo info;
-// The list of registered classes.
-static RegisteredClasses* registered_classes = NULL;
+ // The name given to the window.
+ std::wstring name;
+ // The ATOM returned from creating the window.
+ ATOM atom;
+ };
+
+ ClassRegistrar() : registered_count_(0) { }
+ friend struct DefaultSingletonTraits<ClassRegistrar>;
+
+ typedef std::list<RegisteredClass> RegisteredClasses;
+ RegisteredClasses registered_classes_;
+
+ // Counter of how many classes have ben registered so far.
+ int registered_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(ClassRegistrar);
+};
///////////////////////////////////////////////////////////////////////////////
// WidgetWin, public
@@ -855,19 +887,12 @@ void WidgetWin::UpdateWindowFromContents(HDC dib_dc) {
}
std::wstring WidgetWin::GetWindowClassName() {
- if (!registered_classes)
- registered_classes = new RegisteredClasses();
ClassInfo class_info(initial_class_style());
- for (RegisteredClasses::iterator i = registered_classes->begin();
- i != registered_classes->end(); ++i) {
- if (class_info.Equals(i->info))
- return i->name;
- }
+ std::wstring name;
+ if (Singleton<ClassRegistrar>()->RetrieveClassName(class_info, &name))
+ return name;
// No class found, need to register one.
- static int registered_count = 0;
- std::wstring name =
- std::wstring(kBaseClassName) + IntToWString(registered_count++);
WNDCLASSEX class_ex;
class_ex.cbSize = sizeof(WNDCLASSEX);
class_ex.style = class_info.style;
@@ -884,8 +909,9 @@ std::wstring WidgetWin::GetWindowClassName() {
class_ex.hIconSm = class_ex.hIcon;
ATOM atom = RegisterClassEx(&class_ex);
DCHECK(atom);
- RegisteredClass registered_class(class_info, name, atom);
- registered_classes->push_back(registered_class);
+
+ Singleton<ClassRegistrar>()->RegisterClass(class_info, name, atom);
+
return name;
}