1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/gfx/win/singleton_hwnd.h"
7 #include "base/memory/singleton.h"
8 #include "base/message_loop/message_loop.h"
9 #include "ui/gfx/win/singleton_hwnd_observer.h"
14 SingletonHwnd
* SingletonHwnd::GetInstance() {
15 return Singleton
<SingletonHwnd
>::get();
18 BOOL
SingletonHwnd::ProcessWindowMessage(HWND window
,
24 FOR_EACH_OBSERVER(SingletonHwndObserver
,
26 OnWndProc(window
, message
, wparam
, lparam
));
30 SingletonHwnd::SingletonHwnd() {
31 if (!base::MessageLoopForUI::IsCurrent()) {
32 // Creating this window in (e.g.) a renderer inhibits shutdown on
33 // Windows. See http://crbug.com/230122 and http://crbug.com/236039.
34 DLOG(ERROR
) << "Cannot create windows on non-UI thread!";
37 WindowImpl::Init(NULL
, Rect());
40 SingletonHwnd::~SingletonHwnd() {
41 // WindowImpl will clean up the hwnd value on WM_NCDESTROY.
43 DestroyWindow(hwnd());
45 // Tell all of our current observers to clean themselves up.
46 FOR_EACH_OBSERVER(SingletonHwndObserver
, observer_list_
, ClearWndProc());
49 void SingletonHwnd::AddObserver(SingletonHwndObserver
* observer
) {
50 observer_list_
.AddObserver(observer
);
53 void SingletonHwnd::RemoveObserver(SingletonHwndObserver
* observer
) {
54 observer_list_
.RemoveObserver(observer
);