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/location.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "base/message_loop/message_loop.h" | |
13 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "base/single_thread_task_runner.h" | |
14 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
15 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
16 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "ui/shell_dialogs/base_shell_dialog_win.h" | |
18 #include "ui/views/win/hwnd_util.h" | 23 #include "ui/views/win/hwnd_util.h" |
19 | 24 |
20 using content::BrowserThread; | 25 using content::BrowserThread; |
21 using content::WebContents; | 26 using content::WebContents; |
22 | 27 |
23 namespace options { | 28 namespace options { |
24 | 29 |
30 namespace { | |
31 | |
32 // Shows a Windows certificate management dialog on the dialog thread. Deletes | |
33 // itself when the dialog is closed. | |
davidben
2015/07/23 19:49:33
I hate self-deleting classes, but the dialog is fi
| |
34 class ManageCertificatesDialog : public ui::BaseShellDialogImpl { | |
35 public: | |
36 explicit ManageCertificatesDialog(WebContents* web_contents) | |
37 : ui_task_runner_(base::MessageLoopForUI::current()->task_runner()) { | |
38 HWND parent = | |
39 views::HWNDForNativeWindow(web_contents->GetTopLevelNativeWindow()); | |
40 run_state_ = BeginRun(parent); | |
41 run_state_.dialog_thread->message_loop()->PostTask( | |
mmenke
2015/07/23 20:03:34
PostTaskAndReply? (You'll need to use task_runner
davidben
2015/07/23 20:21:55
Done.
| |
42 FROM_HERE, | |
43 base::Bind(&ManageCertificatesDialog::Show, base::Unretained(this))); | |
44 } | |
45 | |
46 private: | |
47 ~ManageCertificatesDialog() override {} | |
48 | |
49 void Show() { | |
50 CRYPTUI_CERT_MGR_STRUCT cert_mgr = {0}; | |
51 cert_mgr.dwSize = sizeof(CRYPTUI_CERT_MGR_STRUCT); | |
52 cert_mgr.hwndParent = run_state_.owner; | |
53 ::CryptUIDlgCertMgr(&cert_mgr); | |
54 DisableOwner(run_state_.owner); | |
davidben
2015/07/23 19:49:33
This seems kinda unnecessary since we're not doing
mmenke
2015/07/23 20:03:34
Doesn't BeginRun already do this?
davidben
2015/07/23 20:21:55
BeginRun disables it, but CryptUIDlgCertMgr will r
ananta
2015/07/23 20:32:57
Does CryptUIDlgCertMgr display a modal dialog?. Fr
mmenke
2015/07/23 20:34:29
Enabling an already enabled window should be fine.
davidben
2015/07/24 22:43:35
I was just going by the documentation of DisableOw
| |
55 | |
56 ui_task_runner_->PostTask( | |
57 FROM_HERE, base::Bind(&ManageCertificatesDialog::DialogClosed, | |
58 base::Unretained(this))); | |
59 } | |
60 | |
61 void DialogClosed() { | |
62 EndRun(run_state_); | |
mmenke
2015/07/23 20:03:34
Could you just do this in the destructor, and use
davidben
2015/07/23 20:21:55
Done. Made it no longer self-owning.
| |
63 delete this; | |
64 } | |
65 | |
66 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | |
67 RunState run_state_; | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(ManageCertificatesDialog); | |
70 }; | |
71 | |
72 } // namespace | |
73 | |
25 // Callback that opens the Internet Options control panel dialog with the | 74 // Callback that opens the Internet Options control panel dialog with the |
26 // Connections tab selected. | 75 // Connections tab selected. |
27 void OpenConnectionDialogCallback() { | 76 void OpenConnectionDialogCallback() { |
28 // Using rundll32 seems better than LaunchConnectionDialog which causes a | 77 // Using rundll32 seems better than LaunchConnectionDialog which causes a |
29 // new dialog to be made for each call. rundll32 uses the same global | 78 // 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. | 79 // dialog and it seems to share with the shortcut in control panel. |
31 base::FilePath rundll32; | 80 base::FilePath rundll32; |
32 PathService::Get(base::DIR_SYSTEM, &rundll32); | 81 PathService::Get(base::DIR_SYSTEM, &rundll32); |
33 rundll32 = rundll32.AppendASCII("rundll32.exe"); | 82 rundll32 = rundll32.AppendASCII("rundll32.exe"); |
34 | 83 |
(...skipping 16 matching lines...) Expand all Loading... | |
51 void AdvancedOptionsUtilities::ShowNetworkProxySettings( | 100 void AdvancedOptionsUtilities::ShowNetworkProxySettings( |
52 WebContents* web_contents) { | 101 WebContents* web_contents) { |
53 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::FILE)); | 102 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::FILE)); |
54 BrowserThread::PostTask(BrowserThread::FILE, | 103 BrowserThread::PostTask(BrowserThread::FILE, |
55 FROM_HERE, | 104 FROM_HERE, |
56 base::Bind(&OpenConnectionDialogCallback)); | 105 base::Bind(&OpenConnectionDialogCallback)); |
57 } | 106 } |
58 | 107 |
59 void AdvancedOptionsUtilities::ShowManageSSLCertificates( | 108 void AdvancedOptionsUtilities::ShowManageSSLCertificates( |
60 WebContents* web_contents) { | 109 WebContents* web_contents) { |
61 CRYPTUI_CERT_MGR_STRUCT cert_mgr = { 0 }; | 110 new ManageCertificatesDialog(web_contents); |
62 cert_mgr.dwSize = sizeof(CRYPTUI_CERT_MGR_STRUCT); | |
63 cert_mgr.hwndParent = views::HWNDForNativeWindow( | |
64 web_contents->GetTopLevelNativeWindow()); | |
65 ::CryptUIDlgCertMgr(&cert_mgr); | |
66 } | 111 } |
67 | 112 |
68 } // namespace options | 113 } // namespace options |
OLD | NEW |