1、前端页面调用
showProxySettings() {
chrome.send("showProxySettings")
}
2、c++ 响应代码如下 chrome\browser\ui\webui\settings\system_handler.cc
void SystemHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"showProxySettings",
base::BindRepeating(&SystemHandler::HandleShowProxySettings,
base::Unretained(this)));
}
void SystemHandler::HandleShowProxySettings(const base::Value::List& args) {
base::RecordAction(base::UserMetricsAction("Options_ShowProxySettings"));
settings_utils::ShowNetworkProxySettings(web_ui()->GetWebContents());
}
3、chrome\browser\ui\webui\settings\settings_utils_win.cc
// Connections tab selected.
void OpenConnectionDialogCallback() {
// Using rundll32 seems better than LaunchConnectionDialog which causes a
// new dialog to be made for each call. rundll32 uses the same global
// dialog and it seems to share with the shortcut in control panel.
base::FilePath rundll32;
base::PathService::Get(base::DIR_SYSTEM, &rundll32);
rundll32 = rundll32.AppendASCII("rundll32.exe");
base::FilePath shell32dll;
base::PathService::Get(base::DIR_SYSTEM, &shell32dll);
shell32dll = shell32dll.AppendASCII("shell32.dll");
base::FilePath inetcpl;
base::PathService::Get(base::DIR_SYSTEM, &inetcpl);
inetcpl = inetcpl.AppendASCII("inetcpl.cpl,,4");
std::wstring args(shell32dll.value());
args.append(L",Control_RunDLL ");
args.append(inetcpl.value());
//通过shell方式启动系统代理设置
//win10以下打开IE代理
ShellExecute(NULL, L"open", rundll32.value().c_str(), args.c_str(), NULL,
SW_SHOWNORMAL);
}
void ShowNetworkProxySettings(content::WebContents* web_contents) {
if (base::win::GetVersion() >= base::win::Version::WIN10) {
// See
启动的是SystemSettings.exe 代理
// https://docs.microsoft.com/en-us/windows/uwp/launch-resume/launch-settings-app#network--internet
platform_util::OpenExternal(
Profile::FromBrowserContext(web_contents->GetBrowserContext()),
GURL("ms-settings:network-proxy"));
} else {
base::ThreadPool::PostTask(
FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()},
base::BindOnce(&OpenConnectionDialogCallback));
}
}
win10效果:
win7系统效果: