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
Esse commit está contido em:
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
@@ -88,6 +88,7 @@ MessagePumpForUI::MessagePumpForUI() {
|
||||
|
||||
MessagePumpForUI::~MessagePumpForUI() {
|
||||
DestroyWindow(message_hwnd_);
|
||||
UnregisterClass(kWndClass, GetModuleHandle(NULL));
|
||||
}
|
||||
|
||||
void MessagePumpForUI::ScheduleWork() {
|
||||
|
||||
@@ -45,8 +45,10 @@ ProcessSingleton::ProcessSingleton(const FilePath& user_data_dir)
|
||||
}
|
||||
|
||||
ProcessSingleton::~ProcessSingleton() {
|
||||
if (window_)
|
||||
if (window_) {
|
||||
DestroyWindow(window_);
|
||||
UnregisterClass(chrome::kMessageWindowClass, GetModuleHandle(NULL));
|
||||
}
|
||||
}
|
||||
|
||||
bool ProcessSingleton::NotifyOtherProcess() {
|
||||
@@ -142,7 +144,8 @@ void ProcessSingleton::Create() {
|
||||
wc.lpfnWndProc = ProcessSingleton::WndProcStatic;
|
||||
wc.hInstance = hinst;
|
||||
wc.lpszClassName = chrome::kMessageWindowClass;
|
||||
RegisterClassEx(&wc);
|
||||
ATOM clazz = RegisterClassEx(&wc);
|
||||
DCHECK(clazz);
|
||||
|
||||
std::wstring user_data_dir;
|
||||
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
|
||||
|
||||
@@ -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,37 +59,76 @@ 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) {
|
||||
}
|
||||
|
||||
// Info used to create the class.
|
||||
ClassInfo info;
|
||||
|
||||
// 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);
|
||||
};
|
||||
|
||||
typedef std::list<RegisteredClass> RegisteredClasses;
|
||||
|
||||
// The list of registered classes.
|
||||
static RegisteredClasses* registered_classes = NULL;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário