advanced_options_utils_win.cc revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/webui/options/advanced_options_utils.h"
6
7#include <windows.h>
8#include <cryptuiapi.h>
9#pragma comment(lib, "cryptui.lib")
10#include <shellapi.h>
11
12#include "base/bind.h"
13#include "base/path_service.h"
14#include "base/threading/thread.h"
15#include "chrome/browser/browser_process.h"
16#include "content/public/browser/browser_thread.h"
17#include "content/public/browser/web_contents.h"
18#include "content/public/browser/web_contents_view.h"
19#include "ui/views/win/hwnd_util.h"
20
21using content::BrowserThread;
22using content::WebContents;
23
24namespace options {
25
26// Callback that opens the Internet Options control panel dialog with the
27// Connections tab selected.
28void OpenConnectionDialogCallback() {
29  // Using rundll32 seems better than LaunchConnectionDialog which causes a
30  // new dialog to be made for each call.  rundll32 uses the same global
31  // dialog and it seems to share with the shortcut in control panel.
32  base::FilePath rundll32;
33  PathService::Get(base::DIR_SYSTEM, &rundll32);
34  rundll32 = rundll32.AppendASCII("rundll32.exe");
35
36  base::FilePath shell32dll;
37  PathService::Get(base::DIR_SYSTEM, &shell32dll);
38  shell32dll = shell32dll.AppendASCII("shell32.dll");
39
40  base::FilePath inetcpl;
41  PathService::Get(base::DIR_SYSTEM, &inetcpl);
42  inetcpl = inetcpl.AppendASCII("inetcpl.cpl,,4");
43
44  std::wstring args(shell32dll.value());
45  args.append(L",Control_RunDLL ");
46  args.append(inetcpl.value());
47
48  ShellExecute(NULL, L"open", rundll32.value().c_str(), args.c_str(), NULL,
49               SW_SHOWNORMAL);
50}
51
52void AdvancedOptionsUtilities::ShowNetworkProxySettings(
53      WebContents* web_contents) {
54  DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::FILE));
55  BrowserThread::PostTask(BrowserThread::FILE,
56                          FROM_HERE,
57                          base::Bind(&OpenConnectionDialogCallback));
58}
59
60void AdvancedOptionsUtilities::ShowManageSSLCertificates(
61      WebContents* web_contents) {
62  CRYPTUI_CERT_MGR_STRUCT cert_mgr = { 0 };
63  cert_mgr.dwSize = sizeof(CRYPTUI_CERT_MGR_STRUCT);
64  cert_mgr.hwndParent = views::HWNDForNativeWindow(
65      web_contents->GetView()->GetTopLevelNativeWindow());
66  ::CryptUIDlgCertMgr(&cert_mgr);
67}
68
69}  // namespace options
70