Skip to content

Commit c02a862

Browse files
authored
browser(webkit): implement support for proxy (#2436)
1 parent a644f0a commit c02a862

File tree

6 files changed

+123
-142
lines changed

6 files changed

+123
-142
lines changed

browser_patches/webkit/BUILD_NUMBER

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1251
1+
1252

browser_patches/webkit/patches/bootstrap.diff

Lines changed: 92 additions & 37 deletions
Large diffs are not rendered by default.

browser_patches/webkit/src/Tools/Playwright/win/Common.cpp

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -122,90 +122,6 @@ void createCrashReport(EXCEPTION_POINTERS* exceptionPointers)
122122
}
123123
}
124124

125-
bool askProxySettings(HWND hwnd, ProxySettings& settings)
126-
{
127-
class ProxyDialog : public Dialog {
128-
public:
129-
ProxyDialog(ProxySettings& settings)
130-
: settings { settings }
131-
{
132-
}
133-
134-
protected:
135-
ProxySettings& settings;
136-
137-
void setup() final
138-
{
139-
auto command = commandForProxyChoice();
140-
proxyChoice().set(command);
141-
setText(IDC_PROXY_URL, settings.url);
142-
setText(IDC_PROXY_EXCLUDE, settings.excludeHosts);
143-
}
144-
145-
void ok() final
146-
{
147-
settings.url = getText(IDC_PROXY_URL);
148-
settings.excludeHosts = getText(IDC_PROXY_EXCLUDE);
149-
updateProxyChoice(proxyChoice().get());
150-
}
151-
152-
bool validate() final
153-
{
154-
bool valid = true;
155-
156-
if (proxyChoice().get() == IDC_PROXY_CUSTOM) {
157-
setEnabled(IDC_PROXY_URL, true);
158-
setEnabled(IDC_PROXY_EXCLUDE, true);
159-
160-
if (!getTextLength(IDC_PROXY_URL))
161-
valid = false;
162-
} else {
163-
setEnabled(IDC_PROXY_URL, false);
164-
setEnabled(IDC_PROXY_EXCLUDE, false);
165-
}
166-
167-
return valid;
168-
}
169-
170-
RadioGroup proxyChoice()
171-
{
172-
return radioGroup(IDC_PROXY_DEFAULT, IDC_PROXY_DISABLE);
173-
}
174-
175-
int commandForProxyChoice()
176-
{
177-
if (!settings.enable)
178-
return IDC_PROXY_DISABLE;
179-
if (settings.custom)
180-
return IDC_PROXY_CUSTOM;
181-
return IDC_PROXY_DEFAULT;
182-
}
183-
184-
void updateProxyChoice(int command)
185-
{
186-
switch (command) {
187-
case IDC_PROXY_DEFAULT:
188-
settings.enable = true;
189-
settings.custom = false;
190-
break;
191-
case IDC_PROXY_CUSTOM:
192-
settings.enable = true;
193-
settings.custom = true;
194-
break;
195-
case IDC_PROXY_DISABLE:
196-
settings.enable = false;
197-
settings.custom = false;
198-
break;
199-
default:
200-
break;
201-
}
202-
}
203-
};
204-
205-
ProxyDialog dialog { settings };
206-
return dialog.run(hInst, hwnd, IDD_PROXY);
207-
}
208-
209125
Optional<Credential> askCredential(HWND hwnd, const std::wstring& realm)
210126
{
211127
struct AuthDialog : public Dialog {
@@ -274,6 +190,10 @@ CommandLineOptions parseCommandLine()
274190
options.inspectorPipe = true;
275191
else if (!wcsncmp(argv[i], L"--user-data-dir=", 16))
276192
options.userDataDir = argv[i] + 16;
193+
else if (!wcsncmp(argv[i], L"--curl-proxy=", 13))
194+
options.curloptProxy = argv[i] + 13;
195+
else if (!wcsncmp(argv[i], L"--curl-noproxy=", 15))
196+
options.curloptNoproxy = argv[i] + 15;
277197
else if (!wcsicmp(argv[i], L"--headless"))
278198
options.headless = true;
279199
else if (!wcsicmp(argv[i], L"--no-startup-window"))

browser_patches/webkit/src/Tools/Playwright/win/Common.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ struct CommandLineOptions {
3838
bool noStartupWindow { };
3939
_bstr_t requestedURL;
4040
_bstr_t userDataDir;
41+
_bstr_t curloptProxy;
42+
_bstr_t curloptNoproxy;
4143

4244
CommandLineOptions()
4345
{
@@ -49,19 +51,11 @@ struct Credential {
4951
std::wstring password;
5052
};
5153

52-
struct ProxySettings {
53-
bool enable { true };
54-
bool custom { false };
55-
std::wstring url;
56-
std::wstring excludeHosts;
57-
};
58-
5954
void computeFullDesktopFrame();
6055
bool getAppDataFolder(_bstr_t& directory);
6156
CommandLineOptions parseCommandLine();
6257
void createCrashReport(EXCEPTION_POINTERS*);
6358
Optional<Credential> askCredential(HWND, const std::wstring& realm);
64-
bool askProxySettings(HWND, ProxySettings&);
6559

6660
bool askServerTrustEvaluation(HWND, const std::wstring& text);
6761
std::wstring replaceString(std::wstring src, const std::wstring& oldValue, const std::wstring& newValue);

browser_patches/webkit/src/Tools/Playwright/win/WebKitBrowserWindow.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class WebKitBrowserWindow {
7676
BrowserWindowClient& m_client;
7777
WKRetainPtr<WKViewRef> m_view;
7878
HWND m_hMainWnd { nullptr };
79-
ProxySettings m_proxy { };
8079
std::unordered_map<std::wstring, std::wstring> m_acceptedServerTrustCerts;
8180
WKPageRunJavaScriptAlertResultListenerRef m_alertDialog = { };
8281
WKPageRunJavaScriptConfirmResultListenerRef m_confirmDialog = { };

browser_patches/webkit/src/Tools/Playwright/win/WinMain.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <WebKit/WKContext.h>
3737
#include <WebKit/WKWebsiteDataStoreConfigurationRef.h>
3838
#include <WebKit/WKWebsiteDataStoreRef.h>
39+
#include <WebKit/WKWebsiteDataStoreRefCurl.h>
3940
#include <wtf/win/SoftLinking.h>
4041
#include "WebKitBrowserWindow.h"
4142
#include <wtf/MainThread.h>
@@ -44,19 +45,29 @@
4445
SOFT_LINK_LIBRARY(user32);
4546
SOFT_LINK_OPTIONAL(user32, SetProcessDpiAwarenessContext, BOOL, STDAPICALLTYPE, (DPI_AWARENESS_CONTEXT));
4647

47-
WKRetainPtr<WKStringRef> toWK(const std::string& string)
48+
CommandLineOptions g_options;
49+
50+
static WKRetainPtr<WKStringRef> toWK(const std::string& string)
4851
{
4952
return adoptWK(WKStringCreateWithUTF8CString(string.c_str()));
5053
}
5154

52-
std::string toUTF8String(const wchar_t* src, size_t srcLength)
55+
static std::string toUTF8String(const wchar_t* src, size_t srcLength)
5356
{
5457
int length = WideCharToMultiByte(CP_UTF8, 0, src, srcLength, 0, 0, nullptr, nullptr);
5558
std::vector<char> buffer(length);
5659
size_t actualLength = WideCharToMultiByte(CP_UTF8, 0, src, srcLength, buffer.data(), length, nullptr, nullptr);
5760
return { buffer.data(), actualLength };
5861
}
5962

63+
static void configureDataStore(WKWebsiteDataStoreRef dataStore) {
64+
if (g_options.curloptProxy.length()) {
65+
auto curloptProxy = createWKURL(g_options.curloptProxy);
66+
auto curloptNoproxy = createWKString(g_options.curloptNoproxy);
67+
WKWebsiteDataStoreEnableCustomNetworkProxySettings(dataStore, curloptProxy.get(), curloptNoproxy.get());
68+
}
69+
}
70+
6071
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpstrCmdLine, _In_ int nCmdShow)
6172
{
6273
#ifdef _CRTDBG_MAP_ALLOC
@@ -73,14 +84,15 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
7384
InitCtrlEx.dwICC = 0x00004000; // ICC_STANDARD_CLASSES;
7485
InitCommonControlsEx(&InitCtrlEx);
7586

76-
auto options = parseCommandLine();
77-
if (options.inspectorPipe) {
87+
g_options = parseCommandLine();
88+
if (g_options.inspectorPipe) {
7889
WKInspectorInitializeRemoteInspectorPipe(
90+
configureDataStore,
7991
WebKitBrowserWindow::createPageCallback,
8092
[]() { PostQuitMessage(0); });
8193
}
8294

83-
if (options.useFullDesktop)
95+
if (g_options.useFullDesktop)
8496
computeFullDesktopFrame();
8597

8698
// Init COM
@@ -89,12 +101,12 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
89101
if (SetProcessDpiAwarenessContextPtr())
90102
SetProcessDpiAwarenessContextPtr()(DPI_AWARENESS_CONTEXT_UNAWARE);
91103

92-
MainWindow::configure(options.headless, options.noStartupWindow);
104+
MainWindow::configure(g_options.headless, g_options.noStartupWindow);
93105

94-
if (!options.noStartupWindow) {
106+
if (!g_options.noStartupWindow) {
95107
auto configuration = adoptWK(WKWebsiteDataStoreConfigurationCreate());
96-
if (options.userDataDir.length()) {
97-
std::string profileFolder = toUTF8String(options.userDataDir, options.userDataDir.length());
108+
if (g_options.userDataDir.length()) {
109+
std::string profileFolder = toUTF8String(g_options.userDataDir, g_options.userDataDir.length());
98110
WKWebsiteDataStoreConfigurationSetApplicationCacheDirectory(configuration.get(), toWK(profileFolder + "\\ApplicationCache").get());
99111
WKWebsiteDataStoreConfigurationSetNetworkCacheDirectory(configuration.get(), toWK(profileFolder + "\\Cache").get());
100112
WKWebsiteDataStoreConfigurationSetCacheStorageDirectory(configuration.get(), toWK(profileFolder + "\\CacheStorage").get());
@@ -108,6 +120,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
108120
auto context = adoptWK(WKContextCreateWithConfiguration(nullptr));
109121
auto dataStore = adoptWK(WKWebsiteDataStoreCreateWithConfiguration(configuration.get()));
110122
WKContextSetPrimaryDataStore(context.get(), dataStore.get());
123+
configureDataStore(dataStore.get());
111124

112125
auto* mainWindow = new MainWindow();
113126
auto conf = adoptWK(WKPageConfigurationCreate());
@@ -117,8 +130,8 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
117130
if (FAILED(hr))
118131
goto exit;
119132

120-
if (options.requestedURL.length())
121-
mainWindow->loadURL(options.requestedURL.GetBSTR());
133+
if (g_options.requestedURL.length())
134+
mainWindow->loadURL(g_options.requestedURL.GetBSTR());
122135
else
123136
mainWindow->loadURL(L"about:blank");
124137
}

0 commit comments

Comments
 (0)