| OLD | NEW |
| (Empty) |
| 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/bind_helpers.h" | |
| 14 #include "base/location.h" | |
| 15 #include "base/macros.h" | |
| 16 #include "base/message_loop/message_loop.h" | |
| 17 #include "base/path_service.h" | |
| 18 #include "base/threading/thread.h" | |
| 19 #include "chrome/browser/browser_process.h" | |
| 20 #include "content/public/browser/browser_thread.h" | |
| 21 #include "content/public/browser/web_contents.h" | |
| 22 #include "ui/shell_dialogs/base_shell_dialog_win.h" | |
| 23 #include "ui/views/win/hwnd_util.h" | |
| 24 | |
| 25 using content::BrowserThread; | |
| 26 using content::WebContents; | |
| 27 | |
| 28 namespace options { | |
| 29 | |
| 30 namespace { | |
| 31 | |
| 32 // Shows a Windows certificate management dialog on the dialog thread. | |
| 33 class ManageCertificatesDialog : public ui::BaseShellDialogImpl { | |
| 34 public: | |
| 35 ManageCertificatesDialog() {} | |
| 36 | |
| 37 // Shows the dialog and calls |callback| when the dialog closes. The caller | |
| 38 // must ensure the ManageCertificatesDialog remains valid until then. | |
| 39 void Show(HWND parent, const base::Closure& callback) { | |
| 40 if (IsRunningDialogForOwner(parent)) { | |
| 41 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | |
| 42 return; | |
| 43 } | |
| 44 | |
| 45 RunState run_state = BeginRun(parent); | |
| 46 run_state.dialog_thread->task_runner()->PostTaskAndReply( | |
| 47 FROM_HERE, base::Bind(&ManageCertificatesDialog::ShowOnDialogThread, | |
| 48 base::Unretained(this), run_state), | |
| 49 base::Bind(&ManageCertificatesDialog::OnDialogClosed, | |
| 50 base::Unretained(this), run_state, callback)); | |
| 51 } | |
| 52 | |
| 53 private: | |
| 54 void ShowOnDialogThread(const RunState& run_state) { | |
| 55 CRYPTUI_CERT_MGR_STRUCT cert_mgr = {0}; | |
| 56 cert_mgr.dwSize = sizeof(CRYPTUI_CERT_MGR_STRUCT); | |
| 57 cert_mgr.hwndParent = run_state.owner; | |
| 58 ::CryptUIDlgCertMgr(&cert_mgr); | |
| 59 } | |
| 60 | |
| 61 void OnDialogClosed(const RunState& run_state, | |
| 62 const base::Closure& callback) { | |
| 63 EndRun(run_state); | |
| 64 // May delete |this|. | |
| 65 callback.Run(); | |
| 66 } | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(ManageCertificatesDialog); | |
| 69 }; | |
| 70 | |
| 71 } // namespace | |
| 72 | |
| 73 // Callback that opens the Internet Options control panel dialog with the | |
| 74 // Connections tab selected. | |
| 75 void OpenConnectionDialogCallback() { | |
| 76 // Using rundll32 seems better than LaunchConnectionDialog which causes a | |
| 77 // new dialog to be made for each call. rundll32 uses the same global | |
| 78 // dialog and it seems to share with the shortcut in control panel. | |
| 79 base::FilePath rundll32; | |
| 80 PathService::Get(base::DIR_SYSTEM, &rundll32); | |
| 81 rundll32 = rundll32.AppendASCII("rundll32.exe"); | |
| 82 | |
| 83 base::FilePath shell32dll; | |
| 84 PathService::Get(base::DIR_SYSTEM, &shell32dll); | |
| 85 shell32dll = shell32dll.AppendASCII("shell32.dll"); | |
| 86 | |
| 87 base::FilePath inetcpl; | |
| 88 PathService::Get(base::DIR_SYSTEM, &inetcpl); | |
| 89 inetcpl = inetcpl.AppendASCII("inetcpl.cpl,,4"); | |
| 90 | |
| 91 std::wstring args(shell32dll.value()); | |
| 92 args.append(L",Control_RunDLL "); | |
| 93 args.append(inetcpl.value()); | |
| 94 | |
| 95 ShellExecute(NULL, L"open", rundll32.value().c_str(), args.c_str(), NULL, | |
| 96 SW_SHOWNORMAL); | |
| 97 } | |
| 98 | |
| 99 void AdvancedOptionsUtilities::ShowNetworkProxySettings( | |
| 100 WebContents* web_contents) { | |
| 101 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::FILE)); | |
| 102 BrowserThread::PostTask(BrowserThread::FILE, | |
| 103 FROM_HERE, | |
| 104 base::Bind(&OpenConnectionDialogCallback)); | |
| 105 } | |
| 106 | |
| 107 void AdvancedOptionsUtilities::ShowManageSSLCertificates( | |
| 108 WebContents* web_contents) { | |
| 109 HWND parent = | |
| 110 views::HWNDForNativeWindow(web_contents->GetTopLevelNativeWindow()); | |
| 111 | |
| 112 ManageCertificatesDialog* dialog = new ManageCertificatesDialog; | |
| 113 dialog->Show( | |
| 114 parent, | |
| 115 base::Bind(&base::DeletePointer<ManageCertificatesDialog>, dialog)); | |
| 116 } | |
| 117 | |
| 118 } // namespace options | |
| OLD | NEW |