36
36
#include < WebKit/WKContext.h>
37
37
#include < WebKit/WKWebsiteDataStoreConfigurationRef.h>
38
38
#include < WebKit/WKWebsiteDataStoreRef.h>
39
+ #include < WebKit/WKWebsiteDataStoreRefCurl.h>
39
40
#include < wtf/win/SoftLinking.h>
40
41
#include " WebKitBrowserWindow.h"
41
42
#include < wtf/MainThread.h>
44
45
SOFT_LINK_LIBRARY (user32);
45
46
SOFT_LINK_OPTIONAL (user32, SetProcessDpiAwarenessContext, BOOL, STDAPICALLTYPE, (DPI_AWARENESS_CONTEXT));
46
47
47
- WKRetainPtr<WKStringRef> toWK (const std::string& string)
48
+ CommandLineOptions g_options;
49
+
50
+ static WKRetainPtr<WKStringRef> toWK (const std::string& string)
48
51
{
49
52
return adoptWK (WKStringCreateWithUTF8CString (string.c_str ()));
50
53
}
51
54
52
- std::string toUTF8String (const wchar_t * src, size_t srcLength)
55
+ static std::string toUTF8String (const wchar_t * src, size_t srcLength)
53
56
{
54
57
int length = WideCharToMultiByte (CP_UTF8, 0 , src, srcLength, 0 , 0 , nullptr , nullptr );
55
58
std::vector<char > buffer (length);
56
59
size_t actualLength = WideCharToMultiByte (CP_UTF8, 0 , src, srcLength, buffer.data (), length, nullptr , nullptr );
57
60
return { buffer.data (), actualLength };
58
61
}
59
62
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
+
60
71
int WINAPI wWinMain (_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpstrCmdLine, _In_ int nCmdShow)
61
72
{
62
73
#ifdef _CRTDBG_MAP_ALLOC
@@ -73,14 +84,15 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
73
84
InitCtrlEx.dwICC = 0x00004000 ; // ICC_STANDARD_CLASSES;
74
85
InitCommonControlsEx (&InitCtrlEx);
75
86
76
- auto options = parseCommandLine ();
77
- if (options .inspectorPipe ) {
87
+ g_options = parseCommandLine ();
88
+ if (g_options .inspectorPipe ) {
78
89
WKInspectorInitializeRemoteInspectorPipe (
90
+ configureDataStore,
79
91
WebKitBrowserWindow::createPageCallback,
80
92
[]() { PostQuitMessage (0 ); });
81
93
}
82
94
83
- if (options .useFullDesktop )
95
+ if (g_options .useFullDesktop )
84
96
computeFullDesktopFrame ();
85
97
86
98
// Init COM
@@ -89,12 +101,12 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
89
101
if (SetProcessDpiAwarenessContextPtr ())
90
102
SetProcessDpiAwarenessContextPtr ()(DPI_AWARENESS_CONTEXT_UNAWARE);
91
103
92
- MainWindow::configure (options .headless , options .noStartupWindow );
104
+ MainWindow::configure (g_options .headless , g_options .noStartupWindow );
93
105
94
- if (!options .noStartupWindow ) {
106
+ if (!g_options .noStartupWindow ) {
95
107
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 ());
98
110
WKWebsiteDataStoreConfigurationSetApplicationCacheDirectory (configuration.get (), toWK (profileFolder + " \\ ApplicationCache" ).get ());
99
111
WKWebsiteDataStoreConfigurationSetNetworkCacheDirectory (configuration.get (), toWK (profileFolder + " \\ Cache" ).get ());
100
112
WKWebsiteDataStoreConfigurationSetCacheStorageDirectory (configuration.get (), toWK (profileFolder + " \\ CacheStorage" ).get ());
@@ -108,6 +120,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
108
120
auto context = adoptWK (WKContextCreateWithConfiguration (nullptr ));
109
121
auto dataStore = adoptWK (WKWebsiteDataStoreCreateWithConfiguration (configuration.get ()));
110
122
WKContextSetPrimaryDataStore (context.get (), dataStore.get ());
123
+ configureDataStore (dataStore.get ());
111
124
112
125
auto * mainWindow = new MainWindow ();
113
126
auto conf = adoptWK (WKPageConfigurationCreate ());
@@ -117,8 +130,8 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance,
117
130
if (FAILED (hr))
118
131
goto exit;
119
132
120
- if (options .requestedURL .length ())
121
- mainWindow->loadURL (options .requestedURL .GetBSTR ());
133
+ if (g_options .requestedURL .length ())
134
+ mainWindow->loadURL (g_options .requestedURL .GetBSTR ());
122
135
else
123
136
mainWindow->loadURL (L" about:blank" );
124
137
}
0 commit comments