summaryrefslogtreecommitdiffstats
path: root/browser/app/pbproxy
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /browser/app/pbproxy
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/app/pbproxy')
-rw-r--r--browser/app/pbproxy/Makefile.in2
-rw-r--r--browser/app/pbproxy/docs/index.rst15
-rw-r--r--browser/app/pbproxy/module.ver8
-rw-r--r--browser/app/pbproxy/moz.build29
-rw-r--r--browser/app/pbproxy/pbproxy.cpp94
-rw-r--r--browser/app/pbproxy/pbproxy.rc9
6 files changed, 157 insertions, 0 deletions
diff --git a/browser/app/pbproxy/Makefile.in b/browser/app/pbproxy/Makefile.in
new file mode 100644
index 0000000000..f58f09bec1
--- /dev/null
+++ b/browser/app/pbproxy/Makefile.in
@@ -0,0 +1,2 @@
+# To make sure this process doesn't show a taskbar icon
+MOZ_WINCONSOLE = 0
diff --git a/browser/app/pbproxy/docs/index.rst b/browser/app/pbproxy/docs/index.rst
new file mode 100644
index 0000000000..b7d0b60467
--- /dev/null
+++ b/browser/app/pbproxy/docs/index.rst
@@ -0,0 +1,15 @@
+======================
+Private Browsing Proxy
+======================
+
+On Windows, Firefox ships with a small binary that always launches
+``firefox.exe`` in Private Browsing mode (``private_browsing.exe``). Its sole
+purpose for existing is to allow Private Browsing shortcuts to have their own
+Visual Elements. This is most notably seen when pinning a Private Browsing
+shortcut to the Start Menu -- Visual Elements are used for the icon there
+rather than the shortcut's icon.
+
+In addition to always passing ``-private-window``, ``private_browsing.exe``
+will forward any other command line arguments given to it to ``firefox.exe``.
+It will also forward shortcut information from the Windows ``STARTUPINFOW``
+structure to ensure that Firefox knows how it was started.
diff --git a/browser/app/pbproxy/module.ver b/browser/app/pbproxy/module.ver
new file mode 100644
index 0000000000..5ef8d2a02a
--- /dev/null
+++ b/browser/app/pbproxy/module.ver
@@ -0,0 +1,8 @@
+WIN32_MODULE_COMPANYNAME=Mozilla Corporation
+WIN32_MODULE_COPYRIGHT=©Firefox and Mozilla Developers; available under the MPL 2 license.
+WIN32_MODULE_PRODUCTVERSION=@MOZ_APP_WINVERSION@
+WIN32_MODULE_PRODUCTVERSION_STRING=@MOZ_APP_VERSION@
+WIN32_MODULE_TRADEMARKS=Firefox is a Trademark of The Mozilla Foundation.
+WIN32_MODULE_DESCRIPTION=@MOZ_APP_DISPLAYNAME@
+WIN32_MODULE_PRODUCTNAME=@MOZ_APP_DISPLAYNAME@
+WIN32_MODULE_NAME=@MOZ_APP_DISPLAYNAME@
diff --git a/browser/app/pbproxy/moz.build b/browser/app/pbproxy/moz.build
new file mode 100644
index 0000000000..bf9e0125e0
--- /dev/null
+++ b/browser/app/pbproxy/moz.build
@@ -0,0 +1,29 @@
+SPHINX_TREES["private-browsing-proxy"] = "docs"
+
+SOURCES += ["pbproxy.cpp"]
+
+# For nsNativeAppSupportWin.h icon definitions
+LOCAL_INCLUDES += ["/toolkit/xre"]
+
+if CONFIG["OS_TARGET"] == "WINNT" and CONFIG["CC_TYPE"] in ("gcc", "clang"):
+ # This allows us to use wmain as the entry point on mingw
+ LDFLAGS += [
+ "-municode",
+ ]
+
+RCINCLUDE = "pbproxy.rc"
+DEFINES["UNICODE"] = 1
+DEFINES["MOZ_APP_NAME"] = 'L"{}"'.format(CONFIG["MOZ_APP_NAME"])
+Program("private_browsing")
+
+OS_LIBS += ["shlwapi", "user32"]
+
+DEFINES["PBMODE_ICO"] = '"{}/{}/pbmode.ico"'.format(
+ TOPSRCDIR,
+ CONFIG["MOZ_BRANDING_DIRECTORY"],
+)
+
+DisableStlWrapping()
+
+with Files("**"):
+ BUG_COMPONENT = ("Firefox", "Shell Integration")
diff --git a/browser/app/pbproxy/pbproxy.cpp b/browser/app/pbproxy/pbproxy.cpp
new file mode 100644
index 0000000000..841cd654a1
--- /dev/null
+++ b/browser/app/pbproxy/pbproxy.cpp
@@ -0,0 +1,94 @@
+/* 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 <windows.h>
+#include <processthreadsapi.h>
+#include <winbase.h>
+#include <winuser.h>
+#include <shlwapi.h>
+#include <string>
+
+// Max command line length, per CreateProcessW docs
+#define MAX_CMD_LENGTH 32767
+#define EXTRA_ERR_MSG_LENGTH 39
+#define ERR_GET_OUR_PATH L"844fa30e-0860-11ed-898b-373276936058"
+#define ERR_GET_APP_DIR L"811237de-0904-11ed-8745-c7c269742323"
+#define ERR_GET_APP_EXE L"8964fd30-0860-11ed-8374-576505ba4488"
+#define ERR_LAUNCHING_APP L"89d2ca2c-0860-11ed-883c-bf345b8391bc"
+
+void raiseError(DWORD err, std::wstring uuid) {
+ LPWSTR winerr;
+ if (err && ::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ nullptr, err, 0, (LPWSTR)&winerr, 0, nullptr)) {
+ std::wstring errmsg(winerr);
+ errmsg += L"\n\n" + uuid;
+ ::MessageBoxW(nullptr, errmsg.c_str(), MOZ_APP_NAME " private_browsing.exe",
+ MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
+ } else {
+ ::MessageBoxW(nullptr, uuid.c_str(), MOZ_APP_NAME " private_browsing.exe",
+ MB_OK | MB_ICONERROR | MB_SETFOREGROUND);
+ }
+}
+
+/*
+ * A very simple wrapper that always launches Firefox in Private Browsing
+ * mode. Any arguments given to this program will be forwarded to Firefox,
+ * as well the information provided by GetStartupInfoW() (the latter is mainly
+ * done to ensure that Firefox's `launch_method` Telemetry works, which
+ * depends on shortcut information).
+ *
+ * Any errors that happen during this process will pop up a MessageBox
+ * with a Windows error (if present) and a unique UUID for debugability --
+ * but these are very unlikely to be seen in practice.
+ */
+int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR aCmdLine, int) {
+ wchar_t app[MAX_PATH];
+ DWORD ret = GetModuleFileNameW(nullptr, app, MAX_PATH);
+ if (!ret ||
+ (ret == MAX_PATH && ::GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
+ ret = ::GetLastError();
+ raiseError(ret, ERR_GET_OUR_PATH);
+ return ret;
+ }
+ if (!PathRemoveFileSpecW(app)) {
+ raiseError(0, ERR_GET_APP_DIR);
+ return 1;
+ }
+ if (!PathAppendW(app, MOZ_APP_NAME L".exe")) {
+ raiseError(0, ERR_GET_APP_EXE);
+ return 1;
+ }
+
+ std::wstring cmdLine(L"\"");
+ cmdLine += app;
+ cmdLine += L"\" -private-window";
+ if (wcslen(aCmdLine) > 0) {
+ cmdLine += L" ";
+ cmdLine += aCmdLine;
+ }
+ DWORD creationFlags = CREATE_UNICODE_ENVIRONMENT;
+ // Mainly used to pass along shortcut information to ensure
+ // launch_method Telemetry will be accurate.
+ STARTUPINFOW startupInfo = {0};
+ startupInfo.cb = sizeof(STARTUPINFOW);
+ GetStartupInfoW(&startupInfo);
+ PROCESS_INFORMATION pi;
+
+ bool rv =
+ ::CreateProcessW(app, cmdLine.data(), nullptr, nullptr, FALSE,
+ creationFlags, nullptr, nullptr, &startupInfo, &pi);
+
+ if (!rv) {
+ ret = ::GetLastError();
+ raiseError(ret, ERR_LAUNCHING_APP);
+ return ret;
+ }
+
+ ::CloseHandle(pi.hProcess);
+ ::CloseHandle(pi.hThread);
+
+ return 0;
+}
diff --git a/browser/app/pbproxy/pbproxy.rc b/browser/app/pbproxy/pbproxy.rc
new file mode 100644
index 0000000000..bb7489d03c
--- /dev/null
+++ b/browser/app/pbproxy/pbproxy.rc
@@ -0,0 +1,9 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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 <windows.h>
+#include "nsNativeAppSupportWin.h"
+
+IDI_APPICON ICON PBMODE_ICO