summaryrefslogtreecommitdiffstats
path: root/ui/base/win
diff options
context:
space:
mode:
authorbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-28 14:45:46 +0000
committerbauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-28 14:45:46 +0000
commit3a3505cdafe4e8bbcf82b11049f9ac66c52eef0d (patch)
tree352c4220d757c4f8fe45d039bb16520318223a9a /ui/base/win
parent77dddc3366d6e662c7d046dc46cbeaaff4e10563 (diff)
downloadchromium_src-3a3505cdafe4e8bbcf82b11049f9ac66c52eef0d.zip
chromium_src-3a3505cdafe4e8bbcf82b11049f9ac66c52eef0d.tar.gz
chromium_src-3a3505cdafe4e8bbcf82b11049f9ac66c52eef0d.tar.bz2
Reland r167487: Get full WebPluginInfo for the PDF plug-in before enabling it for print preview.
Previous review: http://codereview.chromium.org/11364202/ TBR=thestig@chromium.org BUG=159902,113008 Review URL: https://chromiumcodereview.appspot.com/11417003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169938 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base/win')
-rw-r--r--ui/base/win/window_impl.cc151
-rw-r--r--ui/base/win/window_impl.h4
2 files changed, 68 insertions, 87 deletions
diff --git a/ui/base/win/window_impl.cc b/ui/base/win/window_impl.cc
index dce0f2f..d494efa 100644
--- a/ui/base/win/window_impl.cc
+++ b/ui/base/win/window_impl.cc
@@ -44,72 +44,27 @@ struct ClassInfo {
class ClassRegistrar {
public:
- static ClassRegistrar* GetInstance() {
- return Singleton<ClassRegistrar>::get();
- }
+ ~ClassRegistrar();
- ~ClassRegistrar() {
- for (RegisteredClasses::iterator i = registered_classes_.begin();
- i != registered_classes_.end(); ++i) {
- if (!UnregisterClass(MAKEINTATOM(i->atom), i->instance)) {
- LOG(ERROR) << "Failed to unregister class " << i->name.c_str()
- << ". Error = " << GetLastError();
- }
- }
- }
+ static ClassRegistrar* GetInstance();
- // 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;
- }
- }
-
- name->assign(string16(WindowImpl::kBaseClassName) +
- base::IntToString16(registered_count_++));
- return false;
- }
-
- void RegisterClass(const ClassInfo& class_info,
- const std::wstring& name,
- ATOM atom,
- HMODULE instance) {
- registered_classes_.push_back(
- RegisteredClass(class_info, name, atom, instance));
- }
+ // Returns the atom identifying the class matching |class_info|,
+ // creating and registering a new class if the class is not yet known.
+ ATOM RetrieveClassAtom(const ClassInfo& class_info);
private:
// Represents a registered window class.
struct RegisteredClass {
- RegisteredClass(const ClassInfo& info,
- const std::wstring& name,
- ATOM atom,
- HMODULE instance)
- : info(info),
- name(name),
- atom(atom),
- instance(instance) {
- }
+ RegisteredClass(const ClassInfo& info, ATOM atom);
// Info used to create the class.
ClassInfo info;
- // The name given to the window class.
- std::wstring name;
-
- // The ATOM returned from registering the window class.
+ // The atom identifying the window class.
ATOM atom;
-
- // The handle of the module containing the window procedure.
- HMODULE instance;
};
- ClassRegistrar() : registered_count_(0) { }
+ ClassRegistrar();
friend struct DefaultSingletonTraits<ClassRegistrar>;
typedef std::list<RegisteredClass> RegisteredClasses;
@@ -121,6 +76,56 @@ class ClassRegistrar {
DISALLOW_COPY_AND_ASSIGN(ClassRegistrar);
};
+ClassRegistrar::~ClassRegistrar() {}
+
+// static
+ClassRegistrar* ClassRegistrar::GetInstance() {
+ return Singleton<ClassRegistrar,
+ LeakySingletonTraits<ClassRegistrar> >::get();
+}
+
+ATOM ClassRegistrar::RetrieveClassAtom(const ClassInfo& class_info) {
+ for (RegisteredClasses::const_iterator i = registered_classes_.begin();
+ i != registered_classes_.end(); ++i) {
+ if (class_info.Equals(i->info))
+ return i->atom;
+ }
+
+ // No class found, need to register one.
+ string16 name = string16(WindowImpl::kBaseClassName) +
+ base::IntToString16(registered_count_++);
+
+ HBRUSH background = NULL;
+ WNDCLASSEX window_class;
+ base::win::InitializeWindowClass(
+ name.c_str(),
+ &base::win::WrappedWindowProc<WindowImpl::WndProc>,
+ class_info.style,
+ 0,
+ 0,
+ NULL,
+ reinterpret_cast<HBRUSH>(background + 1),
+ NULL,
+ class_info.icon,
+ class_info.icon,
+ &window_class);
+ HMODULE instance = window_class.hInstance;
+ ATOM atom = RegisterClassEx(&window_class);
+ CHECK(atom) << GetLastError();
+
+ registered_classes_.push_back(RegisteredClass(class_info, atom));
+
+ return atom;
+}
+
+ClassRegistrar::RegisteredClass::RegisteredClass(const ClassInfo& info,
+ ATOM atom)
+ : info(info),
+ atom(atom) {}
+
+ClassRegistrar::ClassRegistrar() : registered_count_(0) { }
+
+
///////////////////////////////////////////////////////////////////////////////
// WindowImpl, public
@@ -165,10 +170,11 @@ void WindowImpl::Init(HWND parent, const gfx::Rect& bounds) {
height = bounds.height();
}
- std::wstring name(GetWindowClassName());
+ ATOM atom = GetWindowClassAtom();
bool destroyed = false;
destroyed_ = &destroyed;
- HWND hwnd = CreateWindowEx(window_ex_style_, name.c_str(), NULL,
+ HWND hwnd = CreateWindowEx(window_ex_style_,
+ reinterpret_cast<wchar_t*>(atom), NULL,
window_style_, x, y, width, height,
parent, NULL, NULL, this);
if (!hwnd_ && GetLastError() == 0) {
@@ -181,8 +187,9 @@ void WindowImpl::Init(HWND parent, const gfx::Rect& bounds) {
WNDCLASSEX class_info;
memset(&class_info, 0, sizeof(WNDCLASSEX));
class_info.cbSize = sizeof(WNDCLASSEX);
- BOOL got_class = GetClassInfoEx(
- GetModuleHandle(NULL), name.c_str(), &class_info);
+ BOOL got_class = GetClassInfoEx(GetModuleHandle(NULL),
+ reinterpret_cast<wchar_t*>(atom),
+ &class_info);
base::debug::Alias(&got_class);
bool procs_match = got_class && class_info.lpfnWndProc ==
base::win::WrappedWindowProc<&WindowImpl::WndProc>;
@@ -243,36 +250,10 @@ LRESULT CALLBACK WindowImpl::WndProc(HWND hwnd,
return window->OnWndProc(message, w_param, l_param);
}
-std::wstring WindowImpl::GetWindowClassName() {
+ATOM WindowImpl::GetWindowClassAtom() {
HICON icon = GetDefaultWindowIcon();
ClassInfo class_info(initial_class_style(), icon);
- std::wstring name;
- if (ClassRegistrar::GetInstance()->RetrieveClassName(class_info, &name))
- return name;
-
- // No class found, need to register one.
- HBRUSH background = NULL;
- WNDCLASSEX window_class;
- base::win::InitializeWindowClass(
- name.c_str(),
- &base::win::WrappedWindowProc<WindowImpl::WndProc>,
- class_info.style,
- 0,
- 0,
- NULL,
- reinterpret_cast<HBRUSH>(background + 1),
- NULL,
- icon,
- icon,
- &window_class);
- HMODULE instance = window_class.hInstance;
- ATOM atom = RegisterClassEx(&window_class);
- CHECK(atom) << GetLastError();
-
- ClassRegistrar::GetInstance()->RegisterClass(
- class_info, name, atom, instance);
-
- return name;
+ return ClassRegistrar::GetInstance()->RetrieveClassAtom(class_info);
}
} // namespace ui
diff --git a/ui/base/win/window_impl.h b/ui/base/win/window_impl.h
index 2200393..1f3b5d3 100644
--- a/ui/base/win/window_impl.h
+++ b/ui/base/win/window_impl.h
@@ -90,9 +90,9 @@ class UI_EXPORT WindowImpl : public MessageMapInterface {
WPARAM w_param,
LPARAM l_param);
- // Gets the window class name to use when creating the corresponding HWND.
+ // Gets the window class atom to use when creating the corresponding HWND.
// If necessary, this registers the window class.
- std::wstring GetWindowClassName();
+ ATOM GetWindowClassAtom();
// All classes registered by WindowImpl start with this name.
static const wchar_t* const kBaseClassName;