Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ui / gfx / win / singleton_hwnd.cc
blob9a9d183af6e007dfb912774bc6b8b782c49dbbcd
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"
11 namespace gfx {
13 // static
14 SingletonHwnd* SingletonHwnd::GetInstance() {
15 return Singleton<SingletonHwnd>::get();
18 BOOL SingletonHwnd::ProcessWindowMessage(HWND window,
19 UINT message,
20 WPARAM wparam,
21 LPARAM lparam,
22 LRESULT& result,
23 DWORD msg_map_id) {
24 FOR_EACH_OBSERVER(SingletonHwndObserver,
25 observer_list_,
26 OnWndProc(window, message, wparam, lparam));
27 return false;
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!";
35 return;
37 WindowImpl::Init(NULL, Rect());
40 SingletonHwnd::~SingletonHwnd() {
41 // WindowImpl will clean up the hwnd value on WM_NCDESTROY.
42 if (hwnd())
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);
57 } // namespace gfx