summaryrefslogtreecommitdiffstats
path: root/toolkit/components/remote/nsWinRemoteServer.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/remote/nsWinRemoteServer.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/remote/nsWinRemoteServer.cpp')
-rw-r--r--toolkit/components/remote/nsWinRemoteServer.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/toolkit/components/remote/nsWinRemoteServer.cpp b/toolkit/components/remote/nsWinRemoteServer.cpp
new file mode 100644
index 0000000000..0fa4f5facc
--- /dev/null
+++ b/toolkit/components/remote/nsWinRemoteServer.cpp
@@ -0,0 +1,104 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:expandtab:shiftwidth=2:tabstop=2:
+ */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "CmdLineAndEnvUtils.h"
+#include "nsWinRemoteServer.h"
+#include "RemoteUtils.h"
+#include "nsCOMPtr.h"
+#include "nsXPCOM.h"
+#include "nsPIDOMWindow.h"
+#include "nsIWindowMediator.h"
+#include "nsIBaseWindow.h"
+#include "nsIWidget.h"
+#include "nsICommandLineRunner.h"
+#include "nsICommandLine.h"
+#include "nsCommandLine.h"
+#include "nsIDocShell.h"
+#include "WinRemoteMessage.h"
+
+HWND hwndForDOMWindow(mozIDOMWindowProxy* window) {
+ if (!window) {
+ return 0;
+ }
+ nsCOMPtr<nsPIDOMWindowOuter> pidomwindow = nsPIDOMWindowOuter::From(window);
+
+ nsCOMPtr<nsIBaseWindow> ppBaseWindow =
+ do_QueryInterface(pidomwindow->GetDocShell());
+ if (!ppBaseWindow) {
+ return 0;
+ }
+
+ nsCOMPtr<nsIWidget> ppWidget;
+ ppBaseWindow->GetMainWidget(getter_AddRefs(ppWidget));
+
+ return (HWND)(ppWidget->GetNativeData(NS_NATIVE_WIDGET));
+}
+
+static nsresult GetMostRecentWindow(mozIDOMWindowProxy** aWindow) {
+ nsresult rv;
+ nsCOMPtr<nsIWindowMediator> med(
+ do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv));
+ if (NS_FAILED(rv)) return rv;
+
+ if (med) return med->GetMostRecentWindow(nullptr, aWindow);
+
+ return NS_ERROR_FAILURE;
+}
+
+LRESULT CALLBACK WindowProc(HWND msgWindow, UINT msg, WPARAM wp, LPARAM lp) {
+ if (msg == WM_COPYDATA) {
+ WinRemoteMessageReceiver receiver;
+ if (NS_SUCCEEDED(receiver.Parse(reinterpret_cast<COPYDATASTRUCT*>(lp)))) {
+ receiver.CommandLineRunner()->Run();
+ } else {
+ NS_ERROR("Error initializing command line.");
+ }
+
+ // Get current window and return its window handle.
+ nsCOMPtr<mozIDOMWindowProxy> win;
+ GetMostRecentWindow(getter_AddRefs(win));
+ return win ? (LRESULT)hwndForDOMWindow(win) : 0;
+ }
+ return DefWindowProcW(msgWindow, msg, wp, lp);
+}
+
+nsresult nsWinRemoteServer::Startup(const char* aAppName,
+ const char* aProfileName) {
+ nsString className;
+ BuildClassName(aAppName, aProfileName, className);
+
+ WNDCLASSW classStruct = {0, // style
+ &WindowProc, // lpfnWndProc
+ 0, // cbClsExtra
+ 0, // cbWndExtra
+ 0, // hInstance
+ 0, // hIcon
+ 0, // hCursor
+ 0, // hbrBackground
+ 0, // lpszMenuName
+ className.get()}; // lpszClassName
+
+ // Register the window class.
+ NS_ENSURE_TRUE(::RegisterClassW(&classStruct), NS_ERROR_FAILURE);
+
+ // Create the window.
+ mHandle = ::CreateWindowW(className.get(),
+ 0, // title
+ WS_CAPTION, // style
+ 0, 0, 0, 0, // x, y, cx, cy
+ 0, // parent
+ 0, // menu
+ 0, // instance
+ 0); // create struct
+
+ return mHandle ? NS_OK : NS_ERROR_FAILURE;
+}
+
+void nsWinRemoteServer::Shutdown() {
+ DestroyWindow(mHandle);
+ mHandle = nullptr;
+}