OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/platform_keys/platform_keys_service.h" | 5 #include "chrome/browser/chromeos/platform_keys/platform_keys_service.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 // This task determines all known client certs matching |request|. If | 420 // This task determines all known client certs matching |request|. If |
421 // |interactive| is true, calls |service->select_delegate_->Select()| to | 421 // |interactive| is true, calls |service->select_delegate_->Select()| to |
422 // select a cert from all matches. The extension with |extension_id| will be | 422 // select a cert from all matches. The extension with |extension_id| will be |
423 // granted unlimited sign permission for the selected cert. | 423 // granted unlimited sign permission for the selected cert. |
424 // Finally, either the selection or, if |interactive| is false, matching certs | 424 // Finally, either the selection or, if |interactive| is false, matching certs |
425 // that the extension has permission for are passed to |callback|. | 425 // that the extension has permission for are passed to |callback|. |
426 SelectTask(const platform_keys::ClientCertificateRequest& request, | 426 SelectTask(const platform_keys::ClientCertificateRequest& request, |
427 bool interactive, | 427 bool interactive, |
428 const std::string& extension_id, | 428 const std::string& extension_id, |
429 const SelectCertificatesCallback& callback, | 429 const SelectCertificatesCallback& callback, |
| 430 content::WebContents* web_contents, |
430 PlatformKeysService* service) | 431 PlatformKeysService* service) |
431 : request_(request), | 432 : request_(request), |
432 interactive_(interactive), | 433 interactive_(interactive), |
433 extension_id_(extension_id), | 434 extension_id_(extension_id), |
434 callback_(callback), | 435 callback_(callback), |
| 436 web_contents_(web_contents), |
435 service_(service), | 437 service_(service), |
436 weak_factory_(this) {} | 438 weak_factory_(this) {} |
437 ~SelectTask() override {} | 439 ~SelectTask() override {} |
438 | 440 |
439 void Start() override { | 441 void Start() override { |
440 CHECK(next_step_ == Step::GET_MATCHING_CERTS); | 442 CHECK(next_step_ == Step::GET_MATCHING_CERTS); |
441 DoStep(); | 443 DoStep(); |
442 } | 444 } |
443 bool IsDone() override { return next_step_ == Step::DONE; } | 445 bool IsDone() override { return next_step_ == Step::DONE; } |
444 | 446 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 // Will call back to |GotSelection()|. | 507 // Will call back to |GotSelection()|. |
506 void SelectCerts() { | 508 void SelectCerts() { |
507 CHECK(interactive_); | 509 CHECK(interactive_); |
508 if (matches_.empty()) { | 510 if (matches_.empty()) { |
509 // Don't show a select dialog if no certificate is matching. | 511 // Don't show a select dialog if no certificate is matching. |
510 DoStep(); | 512 DoStep(); |
511 return; | 513 return; |
512 } | 514 } |
513 service_->select_delegate_->Select( | 515 service_->select_delegate_->Select( |
514 extension_id_, matches_, | 516 extension_id_, matches_, |
515 base::Bind(&SelectTask::GotSelection, base::Unretained(this))); | 517 base::Bind(&SelectTask::GotSelection, base::Unretained(this)), |
| 518 web_contents_, service_->browser_context_); |
516 } | 519 } |
517 | 520 |
518 // Will be called by |SelectCerts()| with the selected cert or null if no cert | 521 // Will be called by |SelectCerts()| with the selected cert or null if no cert |
519 // was selected. | 522 // was selected. |
520 void GotSelection(scoped_refptr<net::X509Certificate> selected_cert) { | 523 void GotSelection(const scoped_refptr<net::X509Certificate>& selected_cert) { |
521 selected_cert_ = selected_cert; | 524 selected_cert_ = selected_cert; |
522 DoStep(); | 525 DoStep(); |
523 } | 526 } |
524 | 527 |
525 // Updates the extension's state store about unlimited sign permission for the | 528 // Updates the extension's state store about unlimited sign permission for the |
526 // selected cert. Does nothing if no cert was selected. | 529 // selected cert. Does nothing if no cert was selected. |
527 // Will call back to |DidUpdatePermission()|. | 530 // Will call back to |DidUpdatePermission()|. |
528 void UpdatePermission() { | 531 void UpdatePermission() { |
529 CHECK(interactive_); | 532 CHECK(interactive_); |
530 if (!selected_cert_) { | 533 if (!selected_cert_) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 Step next_step_ = Step::GET_MATCHING_CERTS; | 597 Step next_step_ = Step::GET_MATCHING_CERTS; |
595 scoped_ptr<KeyEntries> platform_keys_; | 598 scoped_ptr<KeyEntries> platform_keys_; |
596 scoped_ptr<PermissionUpdateTask> permission_update_; | 599 scoped_ptr<PermissionUpdateTask> permission_update_; |
597 | 600 |
598 net::CertificateList matches_; | 601 net::CertificateList matches_; |
599 scoped_refptr<net::X509Certificate> selected_cert_; | 602 scoped_refptr<net::X509Certificate> selected_cert_; |
600 platform_keys::ClientCertificateRequest request_; | 603 platform_keys::ClientCertificateRequest request_; |
601 const bool interactive_; | 604 const bool interactive_; |
602 const std::string extension_id_; | 605 const std::string extension_id_; |
603 const SelectCertificatesCallback callback_; | 606 const SelectCertificatesCallback callback_; |
| 607 content::WebContents* const web_contents_; |
604 PlatformKeysService* const service_; | 608 PlatformKeysService* const service_; |
605 base::WeakPtrFactory<SelectTask> weak_factory_; | 609 base::WeakPtrFactory<SelectTask> weak_factory_; |
606 | 610 |
607 DISALLOW_COPY_AND_ASSIGN(SelectTask); | 611 DISALLOW_COPY_AND_ASSIGN(SelectTask); |
608 }; | 612 }; |
609 | 613 |
610 PlatformKeysService::SelectDelegate::SelectDelegate() { | 614 PlatformKeysService::SelectDelegate::SelectDelegate() { |
611 } | 615 } |
612 | 616 |
613 PlatformKeysService::SelectDelegate::~SelectDelegate() { | 617 PlatformKeysService::SelectDelegate::~SelectDelegate() { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 681 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
678 StartOrQueueTask(make_scoped_ptr(new SignTask( | 682 StartOrQueueTask(make_scoped_ptr(new SignTask( |
679 token_id, data, public_key, true /* sign directly without hashing */, | 683 token_id, data, public_key, true /* sign directly without hashing */, |
680 platform_keys::HASH_ALGORITHM_NONE, extension_id, callback, this))); | 684 platform_keys::HASH_ALGORITHM_NONE, extension_id, callback, this))); |
681 } | 685 } |
682 | 686 |
683 void PlatformKeysService::SelectClientCertificates( | 687 void PlatformKeysService::SelectClientCertificates( |
684 const platform_keys::ClientCertificateRequest& request, | 688 const platform_keys::ClientCertificateRequest& request, |
685 bool interactive, | 689 bool interactive, |
686 const std::string& extension_id, | 690 const std::string& extension_id, |
687 const SelectCertificatesCallback& callback) { | 691 const SelectCertificatesCallback& callback, |
| 692 content::WebContents* web_contents) { |
688 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 693 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
689 StartOrQueueTask(make_scoped_ptr( | 694 StartOrQueueTask(make_scoped_ptr(new SelectTask( |
690 new SelectTask(request, interactive, extension_id, callback, this))); | 695 request, interactive, extension_id, callback, web_contents, this))); |
691 } | 696 } |
692 | 697 |
693 void PlatformKeysService::StartOrQueueTask(scoped_ptr<Task> task) { | 698 void PlatformKeysService::StartOrQueueTask(scoped_ptr<Task> task) { |
694 tasks_.push(make_linked_ptr(task.release())); | 699 tasks_.push(make_linked_ptr(task.release())); |
695 if (tasks_.size() == 1) | 700 if (tasks_.size() == 1) |
696 tasks_.front()->Start(); | 701 tasks_.front()->Start(); |
697 } | 702 } |
698 | 703 |
699 void PlatformKeysService::TaskFinished(Task* task) { | 704 void PlatformKeysService::TaskFinished(Task* task) { |
700 DCHECK(!tasks_.empty()); | 705 DCHECK(!tasks_.empty()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 const GetPlatformKeysCallback& callback, | 761 const GetPlatformKeysCallback& callback, |
757 scoped_ptr<base::Value> value) { | 762 scoped_ptr<base::Value> value) { |
758 scoped_ptr<KeyEntries> key_entries(new KeyEntries); | 763 scoped_ptr<KeyEntries> key_entries(new KeyEntries); |
759 if (value) | 764 if (value) |
760 key_entries = KeyEntriesFromState(*value); | 765 key_entries = KeyEntriesFromState(*value); |
761 | 766 |
762 callback.Run(key_entries.Pass()); | 767 callback.Run(key_entries.Pass()); |
763 } | 768 } |
764 | 769 |
765 } // namespace chromeos | 770 } // namespace chromeos |
OLD | NEW |