|
14 | 14 | #include <vector> |
15 | 15 |
|
16 | 16 | #include "AppWindow.h" |
| 17 | +#include "CheckFailure.h" |
17 | 18 | #include "DpiUtil.h" |
| 19 | +#include "ScenarioClusterEnvironment.h" |
18 | 20 |
|
19 | 21 | HINSTANCE g_hInstance; |
20 | 22 | int g_nCmdShow; |
@@ -44,6 +46,12 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmd |
44 | 46 | DWORD creationModeId = IDM_CREATION_MODE_WINDOWED; |
45 | 47 | WebViewCreateOption opt; |
46 | 48 |
|
| 49 | + // When launched with --clustername=..., this instance is a secondary host |
| 50 | + // process that should join an existing shared cluster environment instead |
| 51 | + // of creating a normal (private) environment. |
| 52 | + bool joinCluster = false; |
| 53 | + ClusterEnvironmentSpec clusterSpec; |
| 54 | + |
47 | 55 | if (lpCmdLine && lpCmdLine[0]) |
48 | 56 | { |
49 | 57 | int paramCount = 0; |
@@ -94,6 +102,64 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmd |
94 | 102 | { |
95 | 103 | userDataFolder = nextParam.substr(nextParam.find(L'=') + 1); |
96 | 104 | } |
| 105 | + else if (NEXT_PARAM_CONTAINS(L"clustername=")) |
| 106 | + { |
| 107 | + joinCluster = true; |
| 108 | + clusterSpec.clusterName = nextParam.substr(nextParam.find(L'=') + 1); |
| 109 | + } |
| 110 | + else if (NEXT_PARAM_CONTAINS(L"clusterlang=")) |
| 111 | + { |
| 112 | + clusterSpec.language = nextParam.substr(nextParam.find(L'=') + 1); |
| 113 | + } |
| 114 | + else if (NEXT_PARAM_CONTAINS(L"clusterargs=")) |
| 115 | + { |
| 116 | + clusterSpec.additionalBrowserArguments = |
| 117 | + nextParam.substr(nextParam.find(L'=') + 1); |
| 118 | + } |
| 119 | + else if (NEXT_PARAM_CONTAINS(L"clustersso=")) |
| 120 | + { |
| 121 | + clusterSpec.allowSingleSignOn = |
| 122 | + nextParam.substr(nextParam.find(L'=') + 1) == L"1"; |
| 123 | + } |
| 124 | + else if (NEXT_PARAM_CONTAINS(L"clustertracking=")) |
| 125 | + { |
| 126 | + clusterSpec.enableTrackingPrevention = |
| 127 | + nextParam.substr(nextParam.find(L'=') + 1) == L"1"; |
| 128 | + } |
| 129 | + else if (NEXT_PARAM_CONTAINS(L"clusterextensions=")) |
| 130 | + { |
| 131 | + clusterSpec.areBrowserExtensionsEnabled = |
| 132 | + nextParam.substr(nextParam.find(L'=') + 1) == L"1"; |
| 133 | + } |
| 134 | + else if (NEXT_PARAM_CONTAINS(L"clusterisolation=")) |
| 135 | + { |
| 136 | + clusterSpec.perHostProfileIsolation = |
| 137 | + nextParam.substr(nextParam.find(L'=') + 1) == L"1"; |
| 138 | + } |
| 139 | + else if (NEXT_PARAM_CONTAINS(L"clusterchannels=")) |
| 140 | + { |
| 141 | + // wcstol rather than stoi: a malformed value should fall back to |
| 142 | + // 0 (NONE) rather than throw out of command-line parsing. Masked |
| 143 | + // because the value is cast to a flags enum, and a negative or |
| 144 | + // oversized number would otherwise set every reserved bit. |
| 145 | + const long channels = |
| 146 | + wcstol(nextParam.substr(nextParam.find(L'=') + 1).c_str(), nullptr, 10); |
| 147 | + clusterSpec.releaseChannels = |
| 148 | + static_cast<COREWEBVIEW2_RELEASE_CHANNELS>(channels & kAllReleaseChannels); |
| 149 | + } |
| 150 | + else if (NEXT_PARAM_CONTAINS(L"clustersearchkind=")) |
| 151 | + { |
| 152 | + // Parsed the same way the parent writes it, rather than by |
| 153 | + // testing for L"1", so a value added to the enum later does not |
| 154 | + // silently arrive as MOST_STABLE. Clamped for the same reason |
| 155 | + // the channels are masked: this is cast to an enum. |
| 156 | + const long searchKind = |
| 157 | + wcstol(nextParam.substr(nextParam.find(L'=') + 1).c_str(), nullptr, 10); |
| 158 | + clusterSpec.channelSearchKind = |
| 159 | + searchKind == COREWEBVIEW2_CHANNEL_SEARCH_KIND_LEAST_STABLE |
| 160 | + ? COREWEBVIEW2_CHANNEL_SEARCH_KIND_LEAST_STABLE |
| 161 | + : COREWEBVIEW2_CHANNEL_SEARCH_KIND_MOST_STABLE; |
| 162 | + } |
97 | 163 | else if (NEXT_PARAM_CONTAINS(L"creationmode=")) |
98 | 164 | { |
99 | 165 | nextParam = nextParam.substr(nextParam.find(L'=') + 1); |
@@ -125,7 +191,18 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR lpCmdLine, int nCmd |
125 | 191 |
|
126 | 192 | DpiUtil::SetProcessDpiAwarenessContext(dpiAwarenessContext); |
127 | 193 |
|
128 | | - new AppWindow(creationModeId, opt, initialUri, userDataFolder, true); |
| 194 | + if (joinCluster) |
| 195 | + { |
| 196 | + // COM is required before calling into the loader; AppWindow (created in |
| 197 | + // the completion handler) will also initialize COM on this thread. |
| 198 | + CHECK_FAILURE(OleInitialize(nullptr)); |
| 199 | + CreateOrJoinClusterAndOpenWindow( |
| 200 | + clusterSpec, /*isMainWindow=*/true, /*parent=*/nullptr); |
| 201 | + } |
| 202 | + else |
| 203 | + { |
| 204 | + new AppWindow(creationModeId, opt, initialUri, userDataFolder, true); |
| 205 | + } |
129 | 206 |
|
130 | 207 | int retVal = RunMessagePump(); |
131 | 208 |
|
|
0 commit comments