| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/certificate_provider/certificate_provider_serv
ice.h" | 5 #include "chrome/browser/chromeos/certificate_provider/certificate_provider_serv
ice.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "ash/shell.h" |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 13 #include "base/callback.h" | 14 #include "base/callback.h" |
| 14 #include "base/location.h" | 15 #include "base/location.h" |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 19 #include "base/strings/string_piece.h" | 20 #include "base/strings/string_piece.h" |
| 21 #include "base/strings/utf_string_conversions.h" |
| 20 #include "base/task_runner.h" | 22 #include "base/task_runner.h" |
| 21 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h" | 24 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h" |
| 25 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/ui/browser_finder.h" |
| 28 #include "chrome/browser/ui/browser_window.h" |
| 23 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
| 24 #include "net/ssl/client_key_store.h" | 30 #include "net/ssl/client_key_store.h" |
| 31 #include "ui/views/widget/widget.h" |
| 32 #include "ui/views/window/dialog_client_view.h" |
| 25 | 33 |
| 26 namespace chromeos { | 34 namespace chromeos { |
| 27 | 35 |
| 28 namespace { | 36 namespace { |
| 29 | 37 |
| 30 void PostSignResultToTaskRunner( | 38 void PostSignResultToTaskRunner( |
| 31 const scoped_refptr<base::TaskRunner>& target_task_runner, | 39 const scoped_refptr<base::TaskRunner>& target_task_runner, |
| 32 const net::SSLPrivateKey::SignCallback& callback, | 40 const net::SSLPrivateKey::SignCallback& callback, |
| 33 net::Error error, | 41 net::Error error, |
| 34 const std::vector<uint8_t>& signature) { | 42 const std::vector<uint8_t>& signature) { |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 base::Callback<void(const net::CertificateList&)> callback; | 401 base::Callback<void(const net::CertificateList&)> callback; |
| 394 certificate_requests_.RemoveRequest(cert_request_id, &certificates, | 402 certificate_requests_.RemoveRequest(cert_request_id, &certificates, |
| 395 &callback); | 403 &callback); |
| 396 UpdateCertificatesAndRun(certificates, callback); | 404 UpdateCertificatesAndRun(certificates, callback); |
| 397 } | 405 } |
| 398 | 406 |
| 399 certificate_map_.RemoveExtension(extension_id); | 407 certificate_map_.RemoveExtension(extension_id); |
| 400 | 408 |
| 401 for (auto callback : sign_requests_.RemoveAllRequests(extension_id)) | 409 for (auto callback : sign_requests_.RemoveAllRequests(extension_id)) |
| 402 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); | 410 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); |
| 411 |
| 412 last_rejected_[extension_id] = false; |
| 403 } | 413 } |
| 404 | 414 |
| 405 void CertificateProviderService::GetCertificatesFromExtensions( | 415 void CertificateProviderService::GetCertificatesFromExtensions( |
| 406 const base::Callback<void(const net::CertificateList&)>& callback) { | 416 const base::Callback<void(const net::CertificateList&)>& callback) { |
| 407 DCHECK(thread_checker_.CalledOnValidThread()); | 417 DCHECK(thread_checker_.CalledOnValidThread()); |
| 408 | 418 |
| 409 const std::vector<std::string> provider_extensions( | 419 const std::vector<std::string> provider_extensions( |
| 410 delegate_->CertificateProviderExtensions()); | 420 delegate_->CertificateProviderExtensions()); |
| 411 | 421 |
| 412 if (provider_extensions.empty()) { | 422 if (provider_extensions.empty()) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 479 |
| 470 const int sign_request_id = sign_requests_.AddRequest(extension_id, callback); | 480 const int sign_request_id = sign_requests_.AddRequest(extension_id, callback); |
| 471 if (!delegate_->DispatchSignRequestToExtension(extension_id, sign_request_id, | 481 if (!delegate_->DispatchSignRequestToExtension(extension_id, sign_request_id, |
| 472 hash, certificate, digest)) { | 482 hash, certificate, digest)) { |
| 473 sign_requests_.RemoveRequest(extension_id, sign_request_id, | 483 sign_requests_.RemoveRequest(extension_id, sign_request_id, |
| 474 nullptr /* callback */); | 484 nullptr /* callback */); |
| 475 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); | 485 callback.Run(net::ERR_FAILED, std::vector<uint8_t>()); |
| 476 } | 486 } |
| 477 } | 487 } |
| 478 | 488 |
| 489 void CertificateProviderService::OnPinDialogInput( |
| 490 const std::string& extension_id, |
| 491 const bool closed) { |
| 492 last_rejected_[extension_id] = closed; |
| 493 if (closed) { |
| 494 active_pin_dialog_ = nullptr; |
| 495 } else { |
| 496 // Set the temporary callback to be called if user closes the dialog while |
| 497 // request is processing by the extension. |
| 498 active_pin_dialog_->SetCallback( |
| 499 base::Bind(&CertificateProviderService::OnFlowInterrupted, |
| 500 base::Unretained(this))); |
| 501 } |
| 502 } |
| 503 |
| 504 void CertificateProviderService::OnFlowInterrupted( |
| 505 const base::string16& value) { |
| 506 DCHECK(value.empty()); |
| 507 OnPinDialogInput(active_dialog_extension_id_, true); |
| 508 } |
| 509 |
| 510 bool CertificateProviderService::LastPinDialogClosed( |
| 511 const std::string& extension_id) { |
| 512 return last_rejected_[extension_id]; |
| 513 } |
| 514 |
| 515 bool CertificateProviderService::ShowPinDialog( |
| 516 const std::string& extension_id, |
| 517 const std::string& extension_name, |
| 518 const std::string& dialog_type, |
| 519 const base::string16& error_message, |
| 520 const bool accept_input, |
| 521 const RequestPinView::UserInputCallback& callback) { |
| 522 // Don't allow the extension to create anything if an active dialog already |
| 523 // exists |
| 524 if (active_pin_dialog_ != nullptr) { |
| 525 if (!active_dialog_extension_id_.empty() && |
| 526 extension_id == active_dialog_extension_id_) { |
| 527 // Set the new callback to be used by the view. |
| 528 active_pin_dialog_->SetCallback(callback); |
| 529 active_pin_dialog_->SetErrorMessage(error_message); |
| 530 active_pin_dialog_->SetDialogType(dialog_type); |
| 531 active_pin_dialog_->SetAcceptInput(accept_input); |
| 532 active_pin_dialog_->GetDialogClientView()->UpdateDialogButtons(); |
| 533 return true; |
| 534 } |
| 535 |
| 536 return false; |
| 537 } |
| 538 |
| 539 active_dialog_extension_id_ = extension_id; |
| 540 active_pin_dialog_ = new chromeos::RequestPinView( |
| 541 extension_name, dialog_type, error_message, accept_input, callback); |
| 542 gfx::NativeWindow context = ash::Shell::GetPrimaryRootWindow(); |
| 543 if (chromeos::LoginDisplayHost::default_host()) { |
| 544 active_window_ = views::DialogDelegate::CreateDialogWidget( |
| 545 active_pin_dialog_, context, |
| 546 chromeos::LoginDisplayHost::default_host()->GetNativeWindow()); |
| 547 active_window_->SetAlwaysOnTop(true); |
| 548 active_window_->Show(); |
| 549 } else { |
| 550 Browser* browser = chrome::FindTabbedBrowser( |
| 551 ProfileManager::GetPrimaryUserProfile(), true); |
| 552 if (browser) { |
| 553 gfx::NativeWindow native_window = browser->window()->GetNativeWindow(); |
| 554 active_window_ = views::DialogDelegate::CreateDialogWidget( |
| 555 active_pin_dialog_, context, native_window); |
| 556 active_window_->SetAlwaysOnTop(true); |
| 557 active_window_->Show(); |
| 558 } |
| 559 } |
| 560 |
| 561 return true; |
| 562 } |
| 563 |
| 564 bool CertificateProviderService::CloseDialog(const std::string& extension_id) { |
| 565 if (extension_id != active_dialog_extension_id_ || |
| 566 active_pin_dialog_ == nullptr) { |
| 567 LOG(ERROR) << "CloseDialog called by wrong extension"; |
| 568 return false; |
| 569 } |
| 570 |
| 571 // |active_pin_dialog_| gets deleted inside Close(). |
| 572 active_window_->Close(); |
| 573 active_pin_dialog_ = nullptr; |
| 574 |
| 575 return true; |
| 576 } |
| 577 |
| 479 } // namespace chromeos | 578 } // namespace chromeos |
| OLD | NEW |