#55504: fix: keep ses.setProxy() config when the network service restarts
Description of Change
If an app has a proxy switch on the command line (--proxy-server or one of its siblings), a proxy set with ses.setProxy() doesn't survive a network service restart.
ConfigureNetworkContextParams() ends with a call to ApplyProxyModeFromCommandLine(). It runs again for every session whose NetworkContext is rebuilt after the restart. That call writes to the same per-session pref store as Session::SetProxy(), so each restart overwrites the app's proxy with the switch.
The call used to run once. Before #17431 it sat in URLRequestContextGetter::Handle::LazyInitialize(), behind the initialized_ check. #17431 added the same call to the end of what is now ConfigureNetworkContextParams(), which has no such check.
This PR applies the switches once per session in ElectronBrowserContext::InitPrefs() and drops the later call. BrowserProcessImpl::PostEarlyInitialization() already does the same for the process-wide store.
There is one behavior change. A proxy switch appended with app.commandLine.appendSwitch() after a session exists no longer reaches that session. Before, it reached it only the next time the session's network context was rebuilt. Apps that append their switches before ready see no difference.
The new test restarts the network service and checks that one session keeps its setProxy() proxy while another keeps the switch's.
Checklist
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
-
npm testpasses - tests are changed or added
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, past tense, and no longer than 80 characters.
Release Notes
Notes: Fixed proxy switches replacing ses.setProxy() after a network service restart.
Backports
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron