OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/webui/options/advanced_options_utils.h" | 5 #include "chrome/browser/ui/webui/options/advanced_options_utils.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <cryptuiapi.h> | 8 #include <cryptuiapi.h> |
9 #pragma comment(lib, "cryptui.lib") | 9 #pragma comment(lib, "cryptui.lib") |
10 #include <shellapi.h> | 10 #include <shellapi.h> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" |
| 14 #include "base/location.h" |
| 15 #include "base/message_loop/message_loop.h" |
13 #include "base/path_service.h" | 16 #include "base/path_service.h" |
14 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
15 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
16 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "ui/shell_dialogs/base_shell_dialog_win.h" |
18 #include "ui/views/win/hwnd_util.h" | 22 #include "ui/views/win/hwnd_util.h" |
19 | 23 |
20 using content::BrowserThread; | 24 using content::BrowserThread; |
21 using content::WebContents; | 25 using content::WebContents; |
22 | 26 |
23 namespace options { | 27 namespace options { |
24 | 28 |
| 29 namespace { |
| 30 |
| 31 // Shows a Windows certificate management dialog on the dialog thread. |
| 32 class ManageCertificatesDialog : public ui::BaseShellDialogImpl { |
| 33 public: |
| 34 ManageCertificatesDialog() {} |
| 35 |
| 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); |
| 41 return; |
| 42 } |
| 43 |
| 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)); |
| 50 } |
| 51 |
| 52 private: |
| 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); |
| 58 } |
| 59 |
| 60 void OnDialogClosed(const RunState& run_state, |
| 61 const base::Closure& callback) { |
| 62 EndRun(run_state); |
| 63 // May delete |this|. |
| 64 callback.Run(); |
| 65 } |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(ManageCertificatesDialog); |
| 68 }; |
| 69 |
| 70 } // namespace |
| 71 |
25 // Callback that opens the Internet Options control panel dialog with the | 72 // Callback that opens the Internet Options control panel dialog with the |
26 // Connections tab selected. | 73 // Connections tab selected. |
27 void OpenConnectionDialogCallback() { | 74 void OpenConnectionDialogCallback() { |
28 // Using rundll32 seems better than LaunchConnectionDialog which causes a | 75 // Using rundll32 seems better than LaunchConnectionDialog which causes a |
29 // new dialog to be made for each call. rundll32 uses the same global | 76 // new dialog to be made for each call. rundll32 uses the same global |
30 // dialog and it seems to share with the shortcut in control panel. | 77 // dialog and it seems to share with the shortcut in control panel. |
31 base::FilePath rundll32; | 78 base::FilePath rundll32; |
32 PathService::Get(base::DIR_SYSTEM, &rundll32); | 79 PathService::Get(base::DIR_SYSTEM, &rundll32); |
33 rundll32 = rundll32.AppendASCII("rundll32.exe"); | 80 rundll32 = rundll32.AppendASCII("rundll32.exe"); |
34 | 81 |
(...skipping 16 matching lines...) Expand all Loading... |
51 void AdvancedOptionsUtilities::ShowNetworkProxySettings( | 98 void AdvancedOptionsUtilities::ShowNetworkProxySettings( |
52 WebContents* web_contents) { | 99 WebContents* web_contents) { |
53 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::FILE)); | 100 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::FILE)); |
54 BrowserThread::PostTask(BrowserThread::FILE, | 101 BrowserThread::PostTask(BrowserThread::FILE, |
55 FROM_HERE, | 102 FROM_HERE, |
56 base::Bind(&OpenConnectionDialogCallback)); | 103 base::Bind(&OpenConnectionDialogCallback)); |
57 } | 104 } |
58 | 105 |
59 void AdvancedOptionsUtilities::ShowManageSSLCertificates( | 106 void AdvancedOptionsUtilities::ShowManageSSLCertificates( |
60 WebContents* web_contents) { | 107 WebContents* web_contents) { |
61 CRYPTUI_CERT_MGR_STRUCT cert_mgr = { 0 }; | 108 HWND parent = |
62 cert_mgr.dwSize = sizeof(CRYPTUI_CERT_MGR_STRUCT); | 109 views::HWNDForNativeWindow(web_contents->GetTopLevelNativeWindow()); |
63 cert_mgr.hwndParent = views::HWNDForNativeWindow( | 110 |
64 web_contents->GetTopLevelNativeWindow()); | 111 ManageCertificatesDialog* dialog = new ManageCertificatesDialog; |
65 ::CryptUIDlgCertMgr(&cert_mgr); | 112 dialog->Show( |
| 113 parent, |
| 114 base::Bind(&base::DeletePointer<ManageCertificatesDialog>, dialog)); |
66 } | 115 } |
67 | 116 |
68 } // namespace options | 117 } // namespace options |
OLD | NEW |