From 4cf04bb7b4082903880aaa85d4a7d63803fa36d5 Mon Sep 17 00:00:00 2001 From: "alexeypa@chromium.org" Date: Thu, 11 Jul 2013 09:22:38 +0000 Subject: ProcessSingleton now uses base::win::MessageWindow to create a message-only window. Collateral changes: - base::win::MessageWindow registes a single window class used by all message-only windows it creates. The class is registered via base::LazyInstance. - Added base::win::MessageWindow::FindWindow() wrapper used to find other message-only windows, including the other created by a different process. - Removed chrome::kMessageWindowClass constant. - chrome_frame_test::ContextMenuTest destroys the clipboard during the test teardown. Review URL: https://chromiumcodereview.appspot.com/18348025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211049 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/process_singleton_win.cc | 97 +++++++++++---------------------- 1 file changed, 32 insertions(+), 65 deletions(-) (limited to 'chrome/browser/process_singleton_win.cc') diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc index 237004a..94647c7 100644 --- a/chrome/browser/process_singleton_win.cc +++ b/chrome/browser/process_singleton_win.cc @@ -7,6 +7,7 @@ #include #include "base/base_paths.h" +#include "base/bind.h" #include "base/command_line.h" #include "base/files/file_path.h" #include "base/path_service.h" @@ -21,7 +22,6 @@ #include "base/win/scoped_handle.h" #include "base/win/win_util.h" #include "base/win/windows_version.h" -#include "base/win/wrapped_window_proc.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process_platform_part.h" #include "chrome/browser/chrome_process_finder_win.h" @@ -93,24 +93,6 @@ BOOL CALLBACK BrowserWindowEnumeration(HWND window, LPARAM param) { return !*result; } -// This function thunks to the object's version of the windowproc, taking in -// consideration that there are several messages being dispatched before -// WM_NCCREATE which we let windows handle. -LRESULT CALLBACK ThunkWndProc(HWND hwnd, UINT message, - WPARAM wparam, LPARAM lparam) { - ProcessSingleton* singleton = - reinterpret_cast(ui::GetWindowUserData(hwnd)); - if (message == WM_NCCREATE) { - CREATESTRUCT* cs = reinterpret_cast(lparam); - singleton = reinterpret_cast(cs->lpCreateParams); - CHECK(singleton); - ui::SetWindowUserData(hwnd, singleton); - } else if (!singleton) { - return ::DefWindowProc(hwnd, message, wparam, lparam); - } - return singleton->WndProc(hwnd, message, wparam, lparam); -} - bool ParseCommandLine(const COPYDATASTRUCT* cds, CommandLine* parsed_command_line, base::FilePath* current_directory) { @@ -171,6 +153,31 @@ bool ParseCommandLine(const COPYDATASTRUCT* cds, return false; } +bool ProcessLaunchNotification( + const ProcessSingleton::NotificationCallback& notification_callback, + UINT message, + WPARAM wparam, + LPARAM lparam, + LRESULT* result) { + if (message != WM_COPYDATA) + return false; + + // Handle the WM_COPYDATA message from another process. + HWND hwnd = reinterpret_cast(wparam); + const COPYDATASTRUCT* cds = reinterpret_cast(lparam); + + CommandLine parsed_command_line(CommandLine::NO_PROGRAM); + base::FilePath current_directory; + if (!ParseCommandLine(cds, &parsed_command_line, ¤t_directory)) { + *result = TRUE; + return true; + } + + *result = notification_callback.Run(parsed_command_line, current_directory) ? + TRUE : FALSE; + return true; +} + // Returns true if Chrome needs to be relaunched into Windows 8 immersive mode. // Following conditions apply:- // 1. Windows 8 or greater. @@ -260,20 +267,12 @@ bool ProcessSingleton::EscapeVirtualization( ProcessSingleton::ProcessSingleton( const base::FilePath& user_data_dir, const NotificationCallback& notification_callback) - : window_(NULL), notification_callback_(notification_callback), + : notification_callback_(notification_callback), is_virtualized_(false), lock_file_(INVALID_HANDLE_VALUE), user_data_dir_(user_data_dir) { } ProcessSingleton::~ProcessSingleton() { - // We need to unregister the window as late as possible so that we can detect - // another instance of chrome running. Otherwise we may end up writing out - // data while a new chrome is starting up. - if (window_) { - ::DestroyWindow(window_); - ::UnregisterClass(chrome::kMessageWindowClass, - base::GetModuleFromAddress(&ThunkWndProc)); - } if (lock_file_ != INVALID_HANDLE_VALUE) ::CloseHandle(lock_file_); } @@ -439,22 +438,12 @@ bool ProcessSingleton::Create() { << "Lock file can not be created! Error code: " << error; if (lock_file_ != INVALID_HANDLE_VALUE) { - HINSTANCE hinst = base::GetModuleFromAddress(&ThunkWndProc); - - WNDCLASSEX wc = {0}; - wc.cbSize = sizeof(wc); - wc.lpfnWndProc = base::win::WrappedWindowProc; - wc.hInstance = hinst; - wc.lpszClassName = chrome::kMessageWindowClass; - ATOM clazz = ::RegisterClassEx(&wc); - DCHECK(clazz); - // Set the window's title to the path of our user data directory so // other Chrome instances can decide if they should forward to us. - window_ = ::CreateWindow(MAKEINTATOM(clazz), - user_data_dir_.value().c_str(), - 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hinst, this); - CHECK(window_); + bool result = window_.CreateNamed( + base::Bind(&ProcessLaunchNotification, notification_callback_), + user_data_dir_.value()); + CHECK(result && window_.hwnd()); } if (base::win::GetVersion() >= base::win::VERSION_WIN8) { @@ -468,30 +457,8 @@ bool ProcessSingleton::Create() { } } - return window_ != NULL; + return window_.hwnd() != NULL; } void ProcessSingleton::Cleanup() { } - -LRESULT ProcessSingleton::OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds) { - CommandLine parsed_command_line(CommandLine::NO_PROGRAM); - base::FilePath current_directory; - if (!ParseCommandLine(cds, &parsed_command_line, ¤t_directory)) - return TRUE; - return notification_callback_.Run(parsed_command_line, current_directory) ? - TRUE : FALSE; -} - -LRESULT ProcessSingleton::WndProc(HWND hwnd, UINT message, - WPARAM wparam, LPARAM lparam) { - switch (message) { - case WM_COPYDATA: - return OnCopyData(reinterpret_cast(wparam), - reinterpret_cast(lparam)); - default: - break; - } - - return ::DefWindowProc(hwnd, message, wparam, lparam); -} -- cgit v1.1