| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/crypto_module_password_dialog.h" | 5 #include "chrome/browser/ui/crypto_module_password_dialog.h" |
| 6 | 6 |
| 7 #include <pk11pub.h> | 7 #include <pk11pub.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 return (PK11_NeedLogin(module->os_module_handle()) && | 25 return (PK11_NeedLogin(module->os_module_handle()) && |
| 26 !PK11_IsLoggedIn(module->os_module_handle(), NULL /* wincx */)); | 26 !PK11_IsLoggedIn(module->os_module_handle(), NULL /* wincx */)); |
| 27 } | 27 } |
| 28 | 28 |
| 29 // Basically an asynchronous implementation of NSS's PK11_DoPassword. | 29 // Basically an asynchronous implementation of NSS's PK11_DoPassword. |
| 30 // Note: This currently handles only the simple case. See the TODOs in | 30 // Note: This currently handles only the simple case. See the TODOs in |
| 31 // GotPassword for what is yet unimplemented. | 31 // GotPassword for what is yet unimplemented. |
| 32 class SlotUnlocker { | 32 class SlotUnlocker { |
| 33 public: | 33 public: |
| 34 SlotUnlocker(const net::CryptoModuleList& modules, | 34 SlotUnlocker(const net::CryptoModuleList& modules, |
| 35 browser::CryptoModulePasswordReason reason, | 35 chrome::CryptoModulePasswordReason reason, |
| 36 const std::string& host, | 36 const std::string& host, |
| 37 const base::Closure& callback); | 37 const base::Closure& callback); |
| 38 | 38 |
| 39 void Start(); | 39 void Start(); |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 void GotPassword(const char* password); | 42 void GotPassword(const char* password); |
| 43 void Done(); | 43 void Done(); |
| 44 | 44 |
| 45 size_t current_; | 45 size_t current_; |
| 46 net::CryptoModuleList modules_; | 46 net::CryptoModuleList modules_; |
| 47 browser::CryptoModulePasswordReason reason_; | 47 chrome::CryptoModulePasswordReason reason_; |
| 48 std::string host_; | 48 std::string host_; |
| 49 base::Closure callback_; | 49 base::Closure callback_; |
| 50 PRBool retry_; | 50 PRBool retry_; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 SlotUnlocker::SlotUnlocker(const net::CryptoModuleList& modules, | 53 SlotUnlocker::SlotUnlocker(const net::CryptoModuleList& modules, |
| 54 browser::CryptoModulePasswordReason reason, | 54 chrome::CryptoModulePasswordReason reason, |
| 55 const std::string& host, | 55 const std::string& host, |
| 56 const base::Closure& callback) | 56 const base::Closure& callback) |
| 57 : current_(0), | 57 : current_(0), |
| 58 modules_(modules), | 58 modules_(modules), |
| 59 reason_(reason), | 59 reason_(reason), |
| 60 host_(host), | 60 host_(host), |
| 61 callback_(callback), | 61 callback_(callback), |
| 62 retry_(PR_FALSE) { | 62 retry_(PR_FALSE) { |
| 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 64 } | 64 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 | 127 |
| 128 void SlotUnlocker::Done() { | 128 void SlotUnlocker::Done() { |
| 129 DCHECK_EQ(current_, modules_.size()); | 129 DCHECK_EQ(current_, modules_.size()); |
| 130 callback_.Run(); | 130 callback_.Run(); |
| 131 delete this; | 131 delete this; |
| 132 } | 132 } |
| 133 | 133 |
| 134 } // namespace | 134 } // namespace |
| 135 | 135 |
| 136 namespace browser { | 136 namespace chrome { |
| 137 | 137 |
| 138 void UnlockSlotsIfNecessary(const net::CryptoModuleList& modules, | 138 void UnlockSlotsIfNecessary(const net::CryptoModuleList& modules, |
| 139 browser::CryptoModulePasswordReason reason, | 139 chrome::CryptoModulePasswordReason reason, |
| 140 const std::string& host, | 140 const std::string& host, |
| 141 const base::Closure& callback) { | 141 const base::Closure& callback) { |
| 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 143 for (size_t i = 0; i < modules.size(); ++i) { | 143 for (size_t i = 0; i < modules.size(); ++i) { |
| 144 if (ShouldShowDialog(modules[i].get())) { | 144 if (ShouldShowDialog(modules[i].get())) { |
| 145 (new SlotUnlocker(modules, reason, host, callback))->Start(); | 145 (new SlotUnlocker(modules, reason, host, callback))->Start(); |
| 146 return; | 146 return; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 callback.Run(); | 149 callback.Run(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void UnlockCertSlotIfNecessary(net::X509Certificate* cert, | 152 void UnlockCertSlotIfNecessary(net::X509Certificate* cert, |
| 153 browser::CryptoModulePasswordReason reason, | 153 chrome::CryptoModulePasswordReason reason, |
| 154 const std::string& host, | 154 const std::string& host, |
| 155 const base::Closure& callback) { | 155 const base::Closure& callback) { |
| 156 net::CryptoModuleList modules; | 156 net::CryptoModuleList modules; |
| 157 modules.push_back(net::CryptoModule::CreateFromHandle( | 157 modules.push_back(net::CryptoModule::CreateFromHandle( |
| 158 cert->os_cert_handle()->slot)); | 158 cert->os_cert_handle()->slot)); |
| 159 UnlockSlotsIfNecessary(modules, reason, host, callback); | 159 UnlockSlotsIfNecessary(modules, reason, host, callback); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace browser | 162 } // namespace chrome |
| OLD | NEW |