Android Chromoting: Remove exit-fullscreen button.
[chromium-blink-merge.git] / components / browser_watcher / endsession_watcher_window_win.cc
blobce46076bf8b04bb1573dbb6628850dcba62d91e7
1 // Copyright (c) 2015 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 "components/browser_watcher/endsession_watcher_window_win.h"
7 #include "base/logging.h"
8 #include "base/profiler/scoped_tracker.h"
9 #include "base/win/wrapped_window_proc.h"
11 namespace browser_watcher {
13 namespace {
15 const wchar_t kWindowClassName[] = L"Chrome_BrowserWatcherWindow";
17 } // namespace
19 EndSessionWatcherWindow::EndSessionWatcherWindow(
20 const EndSessionMessageCallback& on_end_session_message) :
21 on_end_session_message_(on_end_session_message) {
22 WNDCLASSEX window_class = {0};
23 base::win::InitializeWindowClass(
24 kWindowClassName,
25 &base::win::WrappedWindowProc<EndSessionWatcherWindow::WndProcThunk>,
26 0, 0, 0, NULL, NULL, NULL, NULL, NULL,
27 &window_class);
28 instance_ = window_class.hInstance;
29 ATOM clazz = ::RegisterClassEx(&window_class);
30 DCHECK(clazz);
32 // TODO(siggi): will a message window do here?
33 window_ = ::CreateWindow(kWindowClassName,
34 0, 0, 0, 0, 0, 0, 0, 0, instance_, 0);
35 ::SetWindowLongPtr(window_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
36 DCHECK_EQ(::GetWindowLongPtr(window_, GWLP_USERDATA),
37 reinterpret_cast<LONG_PTR>(this));
40 EndSessionWatcherWindow::~EndSessionWatcherWindow() {
41 if (window_) {
42 ::DestroyWindow(window_);
43 ::UnregisterClass(kWindowClassName, instance_);
47 LRESULT EndSessionWatcherWindow::OnEndSessionMessage(UINT message,
48 WPARAM wparam,
49 LPARAM lparam) {
50 on_end_session_message_.Run(message, lparam);
51 return 0;
54 LRESULT CALLBACK EndSessionWatcherWindow::WndProcThunk(HWND hwnd,
55 UINT message,
56 WPARAM wparam,
57 LPARAM lparam) {
58 // TODO(vadimt): Remove ScopedTracker below once crbug.com/440919 is fixed.
59 tracked_objects::ScopedTracker tracking_profile(
60 FROM_HERE_WITH_EXPLICIT_FUNCTION(
61 "440919 EndSessionWatcherWindow::WndProcThunk"));
63 EndSessionWatcherWindow* msg_wnd =
64 reinterpret_cast<EndSessionWatcherWindow*>(
65 ::GetWindowLongPtr(hwnd, GWLP_USERDATA));
66 if (msg_wnd)
67 return msg_wnd->WndProc(hwnd, message, wparam, lparam);
69 return ::DefWindowProc(hwnd, message, wparam, lparam);
72 LRESULT EndSessionWatcherWindow::WndProc(HWND hwnd,
73 UINT message,
74 WPARAM wparam,
75 LPARAM lparam) {
76 switch (message) {
77 case WM_ENDSESSION:
78 case WM_QUERYENDSESSION:
79 return OnEndSessionMessage(message, wparam, lparam);
80 default:
81 break;
84 return ::DefWindowProc(hwnd, message, wparam, lparam);
87 } // namespace browser_watcher