Chromium 设置页面打开系统代理源码分析c++

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系统效果:                                  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值