Skip to content

Commit

Permalink
browser(firefox): make pipe work on Windows (#4058)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Oct 5, 2020
1 parent a7beaf6 commit 857abcf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
4 changes: 2 additions & 2 deletions browser_patches/firefox/BUILD_NUMBER
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1180
Changed: dgozman@gmail.com Fri Oct 2 09:36:06 PDT 2020
1181
Changed: pavel.feldman@gmail.com Mon, Oct 5, 2020 5:57:35 PM
14 changes: 9 additions & 5 deletions browser_patches/firefox/juggler/pipe/nsRemoteDebuggingPipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ namespace {

StaticRefPtr<nsRemoteDebuggingPipe> gPipe;

const int readFD = 3;
const int writeFD = 4;

const size_t kWritePacketSize = 1 << 16;

#if defined(_WIN32)
HANDLE readHandle;
HANDLE writeHandle;
#else
const int readFD = 3;
const int writeFD = 4;
#endif

size_t ReadBytes(void* buffer, size_t size, bool exact_size)
Expand Down Expand Up @@ -107,8 +107,12 @@ nsresult nsRemoteDebuggingPipe::Init(nsIRemoteDebuggingPipeClient* aClient) {
MOZ_ALWAYS_SUCCEEDS(NS_NewNamedThread("Pipe Writer", getter_AddRefs(mWriterThread)));

#if defined(_WIN32)
readHandle = reinterpret_cast<HANDLE>(_get_osfhandle(readFD));
writeHandle = reinterpret_cast<HANDLE>(_get_osfhandle(writeFD));
CHAR pipeReadStr[20];
CHAR pipeWriteStr[20];
GetEnvironmentVariable("PW_PIPE_READ", pipeReadStr, 20);
GetEnvironmentVariable("PW_PIPE_WRITE", pipeWriteStr, 20);
readHandle = reinterpret_cast<HANDLE>(atoi(pipeReadStr));
writeHandle = reinterpret_cast<HANDLE>(atoi(pipeWriteStr));
#endif

MOZ_ALWAYS_SUCCEEDS(mReaderThread->Dispatch(NewRunnableMethod(
Expand Down
39 changes: 39 additions & 0 deletions browser_patches/firefox/patches/bootstrap.diff
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,45 @@ index f042cc1081850ac60e329b70b5569f8b97d4e4dc..65bcff9b41b9471ef1427e3ea330481c
/**
* Return XPCOM wrapper for the internal accessible.
*/
diff --git a/browser/app/winlauncher/LauncherProcessWin.cpp b/browser/app/winlauncher/LauncherProcessWin.cpp
index 7a8b4a621dd4056dfde1f200c62cf629415cc6a4..e600b2cb78a769a460d27104e1dcb805dbd11ed7 100644
--- a/browser/app/winlauncher/LauncherProcessWin.cpp
+++ b/browser/app/winlauncher/LauncherProcessWin.cpp
@@ -21,6 +21,7 @@
#include "mozilla/WinHeaderOnlyUtils.h"
#include "nsWindowsHelpers.h"

+#include <io.h>
#include <windows.h>
#include <processthreadsapi.h>

@@ -322,8 +323,25 @@ Maybe<int> LauncherMain(int& argc, wchar_t* argv[],
HANDLE stdHandles[] = {::GetStdHandle(STD_INPUT_HANDLE),
::GetStdHandle(STD_OUTPUT_HANDLE),
::GetStdHandle(STD_ERROR_HANDLE)};
-
attrs.AddInheritableHandles(stdHandles);
+ // Playwright pipe installation.
+ bool hasJugglerPipe =
+ mozilla::CheckArg(argc, argv, L"juggler-pipe",
+ static_cast<const wchar_t**>(nullptr),
+ mozilla::CheckArgFlag::None) == mozilla::ARG_FOUND;
+ if (hasJugglerPipe && !mozilla::EnvHasValue("PW_PIPE_READ")) {
+ intptr_t stdio3 = _get_osfhandle(3);
+ intptr_t stdio4 = _get_osfhandle(4);
+ CHAR stdio3str[20];
+ CHAR stdio4str[20];
+ itoa(stdio3, stdio3str, 10);
+ itoa(stdio4, stdio4str, 10);
+ SetEnvironmentVariable("PW_PIPE_READ", stdio3str);
+ SetEnvironmentVariable("PW_PIPE_WRITE", stdio4str);
+ HANDLE pipeHandles[] = {reinterpret_cast<HANDLE>(stdio3),
+ reinterpret_cast<HANDLE>(stdio4)};
+ attrs.AddInheritableHandles(pipeHandles);
+ }

DWORD creationFlags = CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT;

diff --git a/browser/installer/allowed-dupes.mn b/browser/installer/allowed-dupes.mn
index 1e583f9fb014129d791d25b64a727021d6848105..6a91ef0bd0796abf99d8fd54ff6aede94aeb0807 100644
--- a/browser/installer/allowed-dupes.mn
Expand Down

0 comments on commit 857abcf

Please sign in to comment.