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.
5 #include "chrome/browser/ui/webui/options/advanced_options_utils.h"
8 #include <cryptuiapi.h>
9 #pragma comment(lib, "cryptui.lib")
12 #include "base/bind.h"
13 #include "base/bind_helpers.h"
14 #include "base/location.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/path_service.h"
17 #include "base/threading/thread.h"
18 #include "chrome/browser/browser_process.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/web_contents.h"
21 #include "ui/shell_dialogs/base_shell_dialog_win.h"
22 #include "ui/views/win/hwnd_util.h"
24 using content::BrowserThread
;
25 using content::WebContents
;
31 // Shows a Windows certificate management dialog on the dialog thread.
32 class ManageCertificatesDialog
: public ui::BaseShellDialogImpl
{
34 ManageCertificatesDialog() {}
36 // Shows the dialog and calls |callback| when the dialog closes. The caller
37 // must ensure the ManageCertificatesDialog remains valid until then.
38 void Show(HWND parent
, const base::Closure
& callback
) {
39 if (IsRunningDialogForOwner(parent
)) {
40 base::MessageLoop::current()->PostTask(FROM_HERE
, callback
);
44 RunState run_state
= BeginRun(parent
);
45 run_state
.dialog_thread
->task_runner()->PostTaskAndReply(
46 FROM_HERE
, base::Bind(&ManageCertificatesDialog::ShowOnDialogThread
,
47 base::Unretained(this), run_state
),
48 base::Bind(&ManageCertificatesDialog::OnDialogClosed
,
49 base::Unretained(this), run_state
, callback
));
53 void ShowOnDialogThread(const RunState
& run_state
) {
54 CRYPTUI_CERT_MGR_STRUCT cert_mgr
= {0};
55 cert_mgr
.dwSize
= sizeof(CRYPTUI_CERT_MGR_STRUCT
);
56 cert_mgr
.hwndParent
= run_state
.owner
;
57 ::CryptUIDlgCertMgr(&cert_mgr
);
60 void OnDialogClosed(const RunState
& run_state
,
61 const base::Closure
& callback
) {
67 DISALLOW_COPY_AND_ASSIGN(ManageCertificatesDialog
);
72 // Callback that opens the Internet Options control panel dialog with the
73 // Connections tab selected.
74 void OpenConnectionDialogCallback() {
75 // Using rundll32 seems better than LaunchConnectionDialog which causes a
76 // new dialog to be made for each call. rundll32 uses the same global
77 // dialog and it seems to share with the shortcut in control panel.
78 base::FilePath rundll32
;
79 PathService::Get(base::DIR_SYSTEM
, &rundll32
);
80 rundll32
= rundll32
.AppendASCII("rundll32.exe");
82 base::FilePath shell32dll
;
83 PathService::Get(base::DIR_SYSTEM
, &shell32dll
);
84 shell32dll
= shell32dll
.AppendASCII("shell32.dll");
86 base::FilePath inetcpl
;
87 PathService::Get(base::DIR_SYSTEM
, &inetcpl
);
88 inetcpl
= inetcpl
.AppendASCII("inetcpl.cpl,,4");
90 std::wstring
args(shell32dll
.value());
91 args
.append(L
",Control_RunDLL ");
92 args
.append(inetcpl
.value());
94 ShellExecute(NULL
, L
"open", rundll32
.value().c_str(), args
.c_str(), NULL
,
98 void AdvancedOptionsUtilities::ShowNetworkProxySettings(
99 WebContents
* web_contents
) {
100 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::FILE));
101 BrowserThread::PostTask(BrowserThread::FILE,
103 base::Bind(&OpenConnectionDialogCallback
));
106 void AdvancedOptionsUtilities::ShowManageSSLCertificates(
107 WebContents
* web_contents
) {
109 views::HWNDForNativeWindow(web_contents
->GetTopLevelNativeWindow());
111 ManageCertificatesDialog
* dialog
= new ManageCertificatesDialog
;
114 base::Bind(&base::DeletePointer
<ManageCertificatesDialog
>, dialog
));
117 } // namespace options