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/options2/certificate_manager_handler2.h" | 5 #include "chrome/browser/ui/webui/options2/certificate_manager_handler2.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 #include <map> |
| 9 |
7 #include "base/bind.h" | 10 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
9 #include "base/file_util.h" // for FileAccessProvider | 12 #include "base/file_util.h" // for FileAccessProvider |
| 13 #include "base/id_map.h" |
10 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
11 #include "base/safe_strerror_posix.h" | 15 #include "base/safe_strerror_posix.h" |
12 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
13 #include "base/values.h" | 17 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/certificate_viewer.h" | 19 #include "chrome/browser/certificate_viewer.h" |
16 #include "chrome/browser/ui/certificate_dialogs.h" | 20 #include "chrome/browser/ui/certificate_dialogs.h" |
17 #include "chrome/browser/ui/crypto_module_password_dialog.h" | 21 #include "chrome/browser/ui/crypto_module_password_dialog.h" |
18 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
(...skipping 25 matching lines...) Expand all Loading... |
45 | 49 |
46 // Enumeration of different callers of SelectFile. (Start counting at 1 so | 50 // Enumeration of different callers of SelectFile. (Start counting at 1 so |
47 // if SelectFile is accidentally called with params=NULL it won't match any.) | 51 // if SelectFile is accidentally called with params=NULL it won't match any.) |
48 enum { | 52 enum { |
49 EXPORT_PERSONAL_FILE_SELECTED = 1, | 53 EXPORT_PERSONAL_FILE_SELECTED = 1, |
50 IMPORT_PERSONAL_FILE_SELECTED, | 54 IMPORT_PERSONAL_FILE_SELECTED, |
51 IMPORT_SERVER_FILE_SELECTED, | 55 IMPORT_SERVER_FILE_SELECTED, |
52 IMPORT_CA_FILE_SELECTED, | 56 IMPORT_CA_FILE_SELECTED, |
53 }; | 57 }; |
54 | 58 |
55 // TODO(mattm): These are duplicated from cookies_view_handler.cc | |
56 // Encodes a pointer value into a hex string. | |
57 std::string PointerToHexString(const void* pointer) { | |
58 return base::HexEncode(&pointer, sizeof(pointer)); | |
59 } | |
60 | |
61 // Decodes a pointer from a hex string. | |
62 void* HexStringToPointer(const std::string& str) { | |
63 std::vector<uint8> buffer; | |
64 if (!base::HexStringToBytes(str, &buffer) || | |
65 buffer.size() != sizeof(void*)) { | |
66 return NULL; | |
67 } | |
68 | |
69 return *reinterpret_cast<void**>(&buffer[0]); | |
70 } | |
71 | |
72 std::string OrgNameToId(const std::string& org) { | 59 std::string OrgNameToId(const std::string& org) { |
73 return "org-" + org; | 60 return "org-" + org; |
74 } | 61 } |
75 | 62 |
76 std::string CertToId(const net::X509Certificate& cert) { | |
77 return "cert-" + PointerToHexString(&cert); | |
78 } | |
79 | |
80 net::X509Certificate* IdToCert(const std::string& id) { | |
81 if (!StartsWithASCII(id, "cert-", true)) | |
82 return NULL; | |
83 return reinterpret_cast<net::X509Certificate*>( | |
84 HexStringToPointer(id.substr(5))); | |
85 } | |
86 | |
87 net::X509Certificate* CallbackArgsToCert(const ListValue* args) { | |
88 std::string node_id; | |
89 if (!args->GetString(0, &node_id)){ | |
90 return NULL; | |
91 } | |
92 net::X509Certificate* cert = IdToCert(node_id); | |
93 if (!cert) { | |
94 NOTREACHED(); | |
95 return NULL; | |
96 } | |
97 return cert; | |
98 } | |
99 | |
100 bool CallbackArgsToBool(const ListValue* args, int index, bool* result) { | 63 bool CallbackArgsToBool(const ListValue* args, int index, bool* result) { |
101 std::string string_value; | 64 std::string string_value; |
102 if (!args->GetString(index, &string_value)) | 65 if (!args->GetString(index, &string_value)) |
103 return false; | 66 return false; |
104 | 67 |
105 *result = string_value[0] == 't'; | 68 *result = string_value[0] == 't'; |
106 return true; | 69 return true; |
107 } | 70 } |
108 | 71 |
109 struct DictionaryIdComparator { | 72 struct DictionaryIdComparator { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 default: | 104 default: |
142 return l10n_util::GetStringUTF8(IDS_CERT_MANAGER_UNKNOWN_ERROR); | 105 return l10n_util::GetStringUTF8(IDS_CERT_MANAGER_UNKNOWN_ERROR); |
143 } | 106 } |
144 } | 107 } |
145 | 108 |
146 } // namespace | 109 } // namespace |
147 | 110 |
148 namespace options2 { | 111 namespace options2 { |
149 | 112 |
150 /////////////////////////////////////////////////////////////////////////////// | 113 /////////////////////////////////////////////////////////////////////////////// |
| 114 // CertIdMap |
| 115 |
| 116 class CertIdMap { |
| 117 public: |
| 118 CertIdMap() {} |
| 119 ~CertIdMap() {} |
| 120 |
| 121 std::string CertToId(net::X509Certificate* cert); |
| 122 net::X509Certificate* IdToCert(const std::string& id); |
| 123 net::X509Certificate* CallbackArgsToCert(const base::ListValue* args); |
| 124 |
| 125 private: |
| 126 typedef std::map<net::X509Certificate*, int32> CertMap; |
| 127 |
| 128 // Creates an ID for cert and looks up the cert for an ID. |
| 129 IDMap<net::X509Certificate>id_map_; |
| 130 |
| 131 // Finds the ID for a cert. |
| 132 CertMap cert_map_; |
| 133 |
| 134 DISALLOW_COPY_AND_ASSIGN(CertIdMap); |
| 135 }; |
| 136 |
| 137 std::string CertIdMap::CertToId(net::X509Certificate* cert) { |
| 138 CertMap::const_iterator iter = cert_map_.find(cert); |
| 139 if (iter != cert_map_.end()) |
| 140 return base::IntToString(iter->second); |
| 141 |
| 142 int32 new_id = id_map_.Add(cert); |
| 143 cert_map_[cert] = new_id; |
| 144 return base::IntToString(new_id); |
| 145 } |
| 146 |
| 147 net::X509Certificate* CertIdMap::IdToCert(const std::string& id) { |
| 148 int32 cert_id = 0; |
| 149 if (!base::StringToInt(id, &cert_id)) |
| 150 return NULL; |
| 151 |
| 152 return id_map_.Lookup(cert_id); |
| 153 } |
| 154 |
| 155 net::X509Certificate* CertIdMap::CallbackArgsToCert( |
| 156 const ListValue* args) { |
| 157 std::string node_id; |
| 158 if (!args->GetString(0, &node_id)) |
| 159 return NULL; |
| 160 |
| 161 net::X509Certificate* cert = IdToCert(node_id); |
| 162 if (!cert) { |
| 163 NOTREACHED(); |
| 164 return NULL; |
| 165 } |
| 166 |
| 167 return cert; |
| 168 } |
| 169 |
| 170 /////////////////////////////////////////////////////////////////////////////// |
151 // FileAccessProvider | 171 // FileAccessProvider |
152 | 172 |
153 // TODO(mattm): Move to some shared location? | 173 // TODO(mattm): Move to some shared location? |
154 class FileAccessProvider | 174 class FileAccessProvider |
155 : public base::RefCountedThreadSafe<FileAccessProvider>, | 175 : public base::RefCountedThreadSafe<FileAccessProvider>, |
156 public CancelableRequestProvider { | 176 public CancelableRequestProvider { |
157 public: | 177 public: |
158 // Reports 0 on success or errno on failure, and the data of the file upon | 178 // Reports 0 on success or errno on failure, and the data of the file upon |
159 // success. | 179 // success. |
160 // TODO(mattm): don't pass std::string by value.. could use RefCountedBytes | 180 // TODO(mattm): don't pass std::string by value.. could use RefCountedBytes |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 return; | 267 return; |
248 | 268 |
249 request->ForwardResult(saved_errno, bytes_written); | 269 request->ForwardResult(saved_errno, bytes_written); |
250 } | 270 } |
251 | 271 |
252 /////////////////////////////////////////////////////////////////////////////// | 272 /////////////////////////////////////////////////////////////////////////////// |
253 // CertificateManagerHandler | 273 // CertificateManagerHandler |
254 | 274 |
255 CertificateManagerHandler::CertificateManagerHandler() | 275 CertificateManagerHandler::CertificateManagerHandler() |
256 : file_access_provider_(new FileAccessProvider()), | 276 : file_access_provider_(new FileAccessProvider()), |
257 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 277 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 278 cert_id_map_(new CertIdMap) { |
258 certificate_manager_model_.reset(new CertificateManagerModel(this)); | 279 certificate_manager_model_.reset(new CertificateManagerModel(this)); |
259 } | 280 } |
260 | 281 |
261 CertificateManagerHandler::~CertificateManagerHandler() { | 282 CertificateManagerHandler::~CertificateManagerHandler() { |
262 } | 283 } |
263 | 284 |
264 void CertificateManagerHandler::GetLocalizedValues( | 285 void CertificateManagerHandler::GetLocalizedValues( |
265 DictionaryValue* localized_strings) { | 286 DictionaryValue* localized_strings) { |
266 DCHECK(localized_strings); | 287 DCHECK(localized_strings); |
267 | 288 |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 case IMPORT_SERVER_FILE_SELECTED: | 504 case IMPORT_SERVER_FILE_SELECTED: |
484 case IMPORT_CA_FILE_SELECTED: | 505 case IMPORT_CA_FILE_SELECTED: |
485 ImportExportCleanup(); | 506 ImportExportCleanup(); |
486 break; | 507 break; |
487 default: | 508 default: |
488 NOTREACHED(); | 509 NOTREACHED(); |
489 } | 510 } |
490 } | 511 } |
491 | 512 |
492 void CertificateManagerHandler::View(const ListValue* args) { | 513 void CertificateManagerHandler::View(const ListValue* args) { |
493 net::X509Certificate* cert = CallbackArgsToCert(args); | 514 net::X509Certificate* cert = cert_id_map_->CallbackArgsToCert(args); |
494 if (!cert) | 515 if (!cert) |
495 return; | 516 return; |
496 ShowCertificateViewer(GetParentWindow(), cert); | 517 ShowCertificateViewer(GetParentWindow(), cert); |
497 } | 518 } |
498 | 519 |
499 void CertificateManagerHandler::GetCATrust(const ListValue* args) { | 520 void CertificateManagerHandler::GetCATrust(const ListValue* args) { |
500 net::X509Certificate* cert = CallbackArgsToCert(args); | 521 net::X509Certificate* cert = cert_id_map_->CallbackArgsToCert(args); |
501 if (!cert) { | 522 if (!cert) { |
502 web_ui()->CallJavascriptFunction("CertificateEditCaTrustOverlay.dismiss"); | 523 web_ui()->CallJavascriptFunction("CertificateEditCaTrustOverlay.dismiss"); |
503 return; | 524 return; |
504 } | 525 } |
505 | 526 |
506 net::CertDatabase::TrustBits trust_bits = | 527 net::CertDatabase::TrustBits trust_bits = |
507 certificate_manager_model_->cert_db().GetCertTrust(cert, net::CA_CERT); | 528 certificate_manager_model_->cert_db().GetCertTrust(cert, net::CA_CERT); |
508 base::FundamentalValue ssl_value( | 529 base::FundamentalValue ssl_value( |
509 static_cast<bool>(trust_bits & net::CertDatabase::TRUSTED_SSL)); | 530 static_cast<bool>(trust_bits & net::CertDatabase::TRUSTED_SSL)); |
510 base::FundamentalValue email_value( | 531 base::FundamentalValue email_value( |
511 static_cast<bool>(trust_bits & net::CertDatabase::TRUSTED_EMAIL)); | 532 static_cast<bool>(trust_bits & net::CertDatabase::TRUSTED_EMAIL)); |
512 base::FundamentalValue obj_sign_value( | 533 base::FundamentalValue obj_sign_value( |
513 static_cast<bool>(trust_bits & net::CertDatabase::TRUSTED_OBJ_SIGN)); | 534 static_cast<bool>(trust_bits & net::CertDatabase::TRUSTED_OBJ_SIGN)); |
514 web_ui()->CallJavascriptFunction( | 535 web_ui()->CallJavascriptFunction( |
515 "CertificateEditCaTrustOverlay.populateTrust", | 536 "CertificateEditCaTrustOverlay.populateTrust", |
516 ssl_value, email_value, obj_sign_value); | 537 ssl_value, email_value, obj_sign_value); |
517 } | 538 } |
518 | 539 |
519 void CertificateManagerHandler::EditCATrust(const ListValue* args) { | 540 void CertificateManagerHandler::EditCATrust(const ListValue* args) { |
520 net::X509Certificate* cert = CallbackArgsToCert(args); | 541 net::X509Certificate* cert = cert_id_map_->CallbackArgsToCert(args); |
521 bool fail = !cert; | 542 bool fail = !cert; |
522 bool trust_ssl = false; | 543 bool trust_ssl = false; |
523 bool trust_email = false; | 544 bool trust_email = false; |
524 bool trust_obj_sign = false; | 545 bool trust_obj_sign = false; |
525 fail |= !CallbackArgsToBool(args, 1, &trust_ssl); | 546 fail |= !CallbackArgsToBool(args, 1, &trust_ssl); |
526 fail |= !CallbackArgsToBool(args, 2, &trust_email); | 547 fail |= !CallbackArgsToBool(args, 2, &trust_email); |
527 fail |= !CallbackArgsToBool(args, 3, &trust_obj_sign); | 548 fail |= !CallbackArgsToBool(args, 3, &trust_obj_sign); |
528 if (fail) { | 549 if (fail) { |
529 LOG(ERROR) << "EditCATrust args fail"; | 550 LOG(ERROR) << "EditCATrust args fail"; |
530 web_ui()->CallJavascriptFunction("CertificateEditCaTrustOverlay.dismiss"); | 551 web_ui()->CallJavascriptFunction("CertificateEditCaTrustOverlay.dismiss"); |
(...skipping 13 matching lines...) Expand all Loading... |
544 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_SET_TRUST_ERROR_TITLE), | 565 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_SET_TRUST_ERROR_TITLE), |
545 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_UNKNOWN_ERROR)); | 566 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_UNKNOWN_ERROR)); |
546 } | 567 } |
547 } | 568 } |
548 | 569 |
549 void CertificateManagerHandler::EditServer(const ListValue* args) { | 570 void CertificateManagerHandler::EditServer(const ListValue* args) { |
550 NOTIMPLEMENTED(); | 571 NOTIMPLEMENTED(); |
551 } | 572 } |
552 | 573 |
553 void CertificateManagerHandler::ExportPersonal(const ListValue* args) { | 574 void CertificateManagerHandler::ExportPersonal(const ListValue* args) { |
554 net::X509Certificate* cert = CallbackArgsToCert(args); | 575 net::X509Certificate* cert = cert_id_map_->CallbackArgsToCert(args); |
555 if (!cert) | 576 if (!cert) |
556 return; | 577 return; |
557 | 578 |
558 selected_cert_list_.push_back(cert); | 579 selected_cert_list_.push_back(cert); |
559 | 580 |
560 SelectFileDialog::FileTypeInfo file_type_info; | 581 SelectFileDialog::FileTypeInfo file_type_info; |
561 file_type_info.extensions.resize(1); | 582 file_type_info.extensions.resize(1); |
562 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("p12")); | 583 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("p12")); |
563 file_type_info.extension_description_overrides.push_back( | 584 file_type_info.extension_description_overrides.push_back( |
564 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_PKCS12_FILES)); | 585 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_PKCS12_FILES)); |
(...skipping 12 matching lines...) Expand all Loading... |
577 | 598 |
578 void CertificateManagerHandler::ExportPersonalFileSelected( | 599 void CertificateManagerHandler::ExportPersonalFileSelected( |
579 const FilePath& path) { | 600 const FilePath& path) { |
580 file_path_ = path; | 601 file_path_ = path; |
581 web_ui()->CallJavascriptFunction( | 602 web_ui()->CallJavascriptFunction( |
582 "CertificateManager.exportPersonalAskPassword"); | 603 "CertificateManager.exportPersonalAskPassword"); |
583 } | 604 } |
584 | 605 |
585 void CertificateManagerHandler::ExportPersonalPasswordSelected( | 606 void CertificateManagerHandler::ExportPersonalPasswordSelected( |
586 const ListValue* args) { | 607 const ListValue* args) { |
587 if (!args->GetString(0, &password_)){ | 608 if (!args->GetString(0, &password_)) { |
588 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); | 609 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); |
589 ImportExportCleanup(); | 610 ImportExportCleanup(); |
590 return; | 611 return; |
591 } | 612 } |
592 | 613 |
593 // Currently, we don't support exporting more than one at a time. If we do, | 614 // Currently, we don't support exporting more than one at a time. If we do, |
594 // this would need to either change this to use UnlockSlotsIfNecessary or | 615 // this would need to either change this to use UnlockSlotsIfNecessary or |
595 // change UnlockCertSlotIfNecessary to take a CertificateList. | 616 // change UnlockCertSlotIfNecessary to take a CertificateList. |
596 DCHECK_EQ(selected_cert_list_.size(), 1U); | 617 DCHECK_EQ(selected_cert_list_.size(), 1U); |
597 | 618 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 if (write_errno) { | 654 if (write_errno) { |
634 ShowError( | 655 ShowError( |
635 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_PKCS12_EXPORT_ERROR_TITLE), | 656 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_PKCS12_EXPORT_ERROR_TITLE), |
636 l10n_util::GetStringFUTF8(IDS_CERT_MANAGER_WRITE_ERROR_FORMAT, | 657 l10n_util::GetStringFUTF8(IDS_CERT_MANAGER_WRITE_ERROR_FORMAT, |
637 UTF8ToUTF16(safe_strerror(write_errno)))); | 658 UTF8ToUTF16(safe_strerror(write_errno)))); |
638 } | 659 } |
639 } | 660 } |
640 | 661 |
641 void CertificateManagerHandler::StartImportPersonal(const ListValue* args) { | 662 void CertificateManagerHandler::StartImportPersonal(const ListValue* args) { |
642 SelectFileDialog::FileTypeInfo file_type_info; | 663 SelectFileDialog::FileTypeInfo file_type_info; |
643 if (!args->GetBoolean(0, &use_hardware_backed_)){ | 664 if (!args->GetBoolean(0, &use_hardware_backed_)) { |
644 // Unable to retrieve the hardware backed attribute from the args, | 665 // Unable to retrieve the hardware backed attribute from the args, |
645 // so bail. | 666 // so bail. |
646 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); | 667 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); |
647 ImportExportCleanup(); | 668 ImportExportCleanup(); |
648 return; | 669 return; |
649 } | 670 } |
650 file_type_info.extensions.resize(1); | 671 file_type_info.extensions.resize(1); |
651 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("p12")); | 672 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("p12")); |
652 file_type_info.extension_description_overrides.push_back( | 673 file_type_info.extension_description_overrides.push_back( |
653 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_PKCS12_FILES)); | 674 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_PKCS12_FILES)); |
654 file_type_info.include_all_files = true; | 675 file_type_info.include_all_files = true; |
655 select_file_dialog_ = SelectFileDialog::Create(this); | 676 select_file_dialog_ = SelectFileDialog::Create(this); |
656 select_file_dialog_->SelectFile( | 677 select_file_dialog_->SelectFile( |
657 SelectFileDialog::SELECT_OPEN_FILE, string16(), | 678 SelectFileDialog::SELECT_OPEN_FILE, string16(), |
658 FilePath(), &file_type_info, 1, FILE_PATH_LITERAL("p12"), | 679 FilePath(), &file_type_info, 1, FILE_PATH_LITERAL("p12"), |
659 web_ui()->GetWebContents(), GetParentWindow(), | 680 web_ui()->GetWebContents(), GetParentWindow(), |
660 reinterpret_cast<void*>(IMPORT_PERSONAL_FILE_SELECTED)); | 681 reinterpret_cast<void*>(IMPORT_PERSONAL_FILE_SELECTED)); |
661 } | 682 } |
662 | 683 |
663 void CertificateManagerHandler::ImportPersonalFileSelected( | 684 void CertificateManagerHandler::ImportPersonalFileSelected( |
664 const FilePath& path) { | 685 const FilePath& path) { |
665 file_path_ = path; | 686 file_path_ = path; |
666 web_ui()->CallJavascriptFunction( | 687 web_ui()->CallJavascriptFunction( |
667 "CertificateManager.importPersonalAskPassword"); | 688 "CertificateManager.importPersonalAskPassword"); |
668 } | 689 } |
669 | 690 |
670 void CertificateManagerHandler::ImportPersonalPasswordSelected( | 691 void CertificateManagerHandler::ImportPersonalPasswordSelected( |
671 const ListValue* args) { | 692 const ListValue* args) { |
672 if (!args->GetString(0, &password_)){ | 693 if (!args->GetString(0, &password_)) { |
673 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); | 694 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); |
674 ImportExportCleanup(); | 695 ImportExportCleanup(); |
675 return; | 696 return; |
676 } | 697 } |
677 file_access_provider_->StartRead( | 698 file_access_provider_->StartRead( |
678 file_path_, | 699 file_path_, |
679 &consumer_, | 700 &consumer_, |
680 base::Bind(&CertificateManagerHandler::ImportPersonalFileRead, | 701 base::Bind(&CertificateManagerHandler::ImportPersonalFileRead, |
681 base::Unretained(this))); | 702 base::Unretained(this))); |
682 } | 703 } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_UNKNOWN_ERROR)); | 929 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_UNKNOWN_ERROR)); |
909 } else if (!not_imported.empty()) { | 930 } else if (!not_imported.empty()) { |
910 ShowImportErrors( | 931 ShowImportErrors( |
911 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_CA_IMPORT_ERROR_TITLE), | 932 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_CA_IMPORT_ERROR_TITLE), |
912 not_imported); | 933 not_imported); |
913 } | 934 } |
914 ImportExportCleanup(); | 935 ImportExportCleanup(); |
915 } | 936 } |
916 | 937 |
917 void CertificateManagerHandler::Export(const ListValue* args) { | 938 void CertificateManagerHandler::Export(const ListValue* args) { |
918 net::X509Certificate* cert = CallbackArgsToCert(args); | 939 net::X509Certificate* cert = cert_id_map_->CallbackArgsToCert(args); |
919 if (!cert) | 940 if (!cert) |
920 return; | 941 return; |
921 ShowCertExportDialog(web_ui()->GetWebContents(), GetParentWindow(), | 942 ShowCertExportDialog(web_ui()->GetWebContents(), GetParentWindow(), |
922 cert->os_cert_handle()); | 943 cert->os_cert_handle()); |
923 } | 944 } |
924 | 945 |
925 void CertificateManagerHandler::Delete(const ListValue* args) { | 946 void CertificateManagerHandler::Delete(const ListValue* args) { |
926 net::X509Certificate* cert = CallbackArgsToCert(args); | 947 net::X509Certificate* cert = cert_id_map_->CallbackArgsToCert(args); |
927 if (!cert) | 948 if (!cert) |
928 return; | 949 return; |
929 bool result = certificate_manager_model_->Delete(cert); | 950 bool result = certificate_manager_model_->Delete(cert); |
930 if (!result) { | 951 if (!result) { |
931 // TODO(mattm): better error messages? | 952 // TODO(mattm): better error messages? |
932 ShowError( | 953 ShowError( |
933 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_DELETE_CERT_ERROR_TITLE), | 954 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_DELETE_CERT_ERROR_TITLE), |
934 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_UNKNOWN_ERROR)); | 955 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_UNKNOWN_ERROR)); |
935 } | 956 } |
936 } | 957 } |
(...skipping 27 matching lines...) Expand all Loading... |
964 DictionaryValue* dict = new DictionaryValue; | 985 DictionaryValue* dict = new DictionaryValue; |
965 dict->SetString(kKeyId, OrgNameToId(i->first)); | 986 dict->SetString(kKeyId, OrgNameToId(i->first)); |
966 dict->SetString(kNameId, i->first); | 987 dict->SetString(kNameId, i->first); |
967 | 988 |
968 // Populate second level (certs). | 989 // Populate second level (certs). |
969 ListValue* subnodes = new ListValue; | 990 ListValue* subnodes = new ListValue; |
970 for (net::CertificateList::const_iterator org_cert_it = i->second.begin(); | 991 for (net::CertificateList::const_iterator org_cert_it = i->second.begin(); |
971 org_cert_it != i->second.end(); ++org_cert_it) { | 992 org_cert_it != i->second.end(); ++org_cert_it) { |
972 DictionaryValue* cert_dict = new DictionaryValue; | 993 DictionaryValue* cert_dict = new DictionaryValue; |
973 net::X509Certificate* cert = org_cert_it->get(); | 994 net::X509Certificate* cert = org_cert_it->get(); |
974 cert_dict->SetString(kKeyId, CertToId(*cert)); | 995 cert_dict->SetString(kKeyId, cert_id_map_->CertToId(cert)); |
975 cert_dict->SetString(kNameId, certificate_manager_model_->GetColumnText( | 996 cert_dict->SetString(kNameId, certificate_manager_model_->GetColumnText( |
976 *cert, CertificateManagerModel::COL_SUBJECT_NAME)); | 997 *cert, CertificateManagerModel::COL_SUBJECT_NAME)); |
977 cert_dict->SetBoolean( | 998 cert_dict->SetBoolean( |
978 kReadOnlyId, | 999 kReadOnlyId, |
979 certificate_manager_model_->cert_db().IsReadOnly(cert)); | 1000 certificate_manager_model_->cert_db().IsReadOnly(cert)); |
980 cert_dict->SetBoolean( | 1001 cert_dict->SetBoolean( |
981 kUntrustedId, | 1002 kUntrustedId, |
982 certificate_manager_model_->cert_db().IsUntrusted(cert)); | 1003 certificate_manager_model_->cert_db().IsUntrusted(cert)); |
983 // TODO(hshi): This should be determined by testing for PKCS #11 | 1004 // TODO(hshi): This should be determined by testing for PKCS #11 |
984 // CKA_EXTRACTABLE attribute. We may need to use the NSS function | 1005 // CKA_EXTRACTABLE attribute. We may need to use the NSS function |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 web_ui()->CallJavascriptFunction("CertificateManager.onCheckTpmTokenReady", | 1082 web_ui()->CallJavascriptFunction("CertificateManager.onCheckTpmTokenReady", |
1062 ready); | 1083 ready); |
1063 } | 1084 } |
1064 #endif | 1085 #endif |
1065 | 1086 |
1066 gfx::NativeWindow CertificateManagerHandler::GetParentWindow() const { | 1087 gfx::NativeWindow CertificateManagerHandler::GetParentWindow() const { |
1067 return web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(); | 1088 return web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(); |
1068 } | 1089 } |
1069 | 1090 |
1070 } // namespace options2 | 1091 } // namespace options2 |
OLD | NEW |