Backed out 7 changesets (bug 1942424) for causing frequent crashes. a=backout
[gecko.git] / toolkit / components / remote / WinRemoteMessage.h
blobb06cca987cf1e39375da846f6468f2aee8ff523b
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef __WinRemoteMessage_h__
7 #define __WinRemoteMessage_h__
9 #include <windows.h>
11 #include "nsICommandLineRunner.h"
12 #include "nsCOMPtr.h"
13 #include "nsString.h"
15 // This version number, stored in COPYDATASTRUCT::dwData, defines the format of
16 // COPYDATASTRUCT::lpData in a WM_COPYDATA message.
18 // Previous versions are documented here, but are no longer produced or
19 // accepted.
20 // * Despite being documented as "UTF-8", older versions could not properly
21 // handle non-ASCII characters (bug 1650637).
22 // * Backwards-compatibly supporting v0 led to other issues: some ill-behaved
23 // applications may broadcast WM_COPYDATA messages to all and sundry, and a
24 // version-0 message whose payload happened to start with a NUL byte was
25 // treated as valid (bug 1847458).
27 // Whenever possible, we should retain backwards compatibility for currently-
28 // supported ESR versions. Any future versions should contain a magic cookie of
29 // some sort, as v3 does, to reduce the chances of variants of bug 1847458.
30 enum class WinRemoteMessageVersion : uint32_t {
31 // "<CommandLine>\0" in utf8
32 /* CommandLineOnly = 0, */
34 // "<CommandLine>\0<WorkingDir>\0" in utf8
35 /* CommandLineAndWorkingDir = 1, */
37 // L"<CommandLine>\0<WorkingDir>\0" in utf16, used by ESR 128
38 CommandLineAndWorkingDirInUtf16 = 2,
40 // L"🔥🦊\0<WorkingDir>\0<Arg0>\0<Arg1>\0..." in utf8
41 NullSeparatedArguments = 3,
44 class WinRemoteMessageSender final {
45 COPYDATASTRUCT mData;
47 public:
48 WinRemoteMessageSender(int32_t aArgc, const char** aArgv,
49 const nsAString& aWorkingDir);
51 WinRemoteMessageSender(const WinRemoteMessageSender&) = delete;
52 WinRemoteMessageSender(WinRemoteMessageSender&&) = delete;
53 WinRemoteMessageSender& operator=(const WinRemoteMessageSender&) = delete;
54 WinRemoteMessageSender& operator=(WinRemoteMessageSender&&) = delete;
56 COPYDATASTRUCT* CopyData();
58 private:
59 nsCString mCmdLineBuffer;
62 class WinRemoteMessageReceiver final {
63 nsCOMPtr<nsICommandLineRunner> mCommandLine;
65 nsresult ParseV2(const nsAString& aBuffer);
66 nsresult ParseV3(const nsACString& aBuffer);
68 public:
69 WinRemoteMessageReceiver() = default;
70 WinRemoteMessageReceiver(const WinRemoteMessageReceiver&) = delete;
71 WinRemoteMessageReceiver(WinRemoteMessageReceiver&&) = delete;
72 WinRemoteMessageReceiver& operator=(const WinRemoteMessageReceiver&) = delete;
73 WinRemoteMessageReceiver& operator=(WinRemoteMessageReceiver&&) = delete;
75 nsresult Parse(const COPYDATASTRUCT* aMessageData);
76 nsICommandLineRunner* CommandLineRunner();
79 #endif // __WinRemoteMessage_h__