Backed out changeset b06f19b95b94 (bug 1784438) for causing build bustages CLOSED...
[gecko.git] / toolkit / components / remote / nsWinRemoteClient.cpp
blobbbd170dc951a786d17c5c8481fd20da8491dac03
1 /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=4:tabstop=4:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "nsWinRemoteClient.h"
9 #include <windows.h>
10 #include "RemoteUtils.h"
11 #include "WinRemoteMessage.h"
13 using namespace mozilla;
15 nsresult nsWinRemoteClient::Init() { return NS_OK; }
17 nsresult nsWinRemoteClient::SendCommandLine(const char* aProgram,
18 const char* aProfile, int32_t argc,
19 const char** argv, bool aRaise) {
20 nsString className;
21 BuildClassName(aProgram, aProfile, className);
23 HWND handle = ::FindWindowW(className.get(), 0);
25 if (!handle) {
26 return NS_ERROR_NOT_AVAILABLE;
29 WCHAR cwd[MAX_PATH];
30 _wgetcwd(cwd, MAX_PATH);
31 WinRemoteMessageSender sender(argc, argv, nsDependentString(cwd));
33 if (aRaise) {
34 // Because we are the running process we have permission to raise the target
35 // instance to the foreground. We can do so for the hidden message window as
36 // we have its handle here. The target instance is then able to raise any
37 // window it chooses to as part of handling the command line.
38 ::SetForegroundWindow(handle);
40 ::SendMessageW(handle, WM_COPYDATA, 0,
41 reinterpret_cast<LPARAM>(sender.CopyData()));
43 return NS_OK;