| Index: chrome/browser/chromeos/certificate_provider/certificate_provider_service.cc
|
| diff --git a/chrome/browser/chromeos/certificate_provider/certificate_provider_service.cc b/chrome/browser/chromeos/certificate_provider/certificate_provider_service.cc
|
| index 88bd84133790e9cb7c15e4e77ee93b2361155316..8db9a582202304cf696ef694976109dd0a1a9ba9 100644
|
| --- a/chrome/browser/chromeos/certificate_provider/certificate_provider_service.cc
|
| +++ b/chrome/browser/chromeos/certificate_provider/certificate_provider_service.cc
|
| @@ -8,6 +8,7 @@
|
|
|
| #include <utility>
|
|
|
| +#include "ash/shell.h"
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| #include "base/callback.h"
|
| @@ -17,11 +18,18 @@
|
| #include "base/memory/ptr_util.h"
|
| #include "base/stl_util.h"
|
| #include "base/strings/string_piece.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| #include "base/task_runner.h"
|
| #include "base/threading/thread_task_runner_handle.h"
|
| #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h"
|
| +#include "chrome/browser/chromeos/login/ui/login_display_host.h"
|
| +#include "chrome/browser/profiles/profile_manager.h"
|
| +#include "chrome/browser/ui/browser_finder.h"
|
| +#include "chrome/browser/ui/browser_window.h"
|
| #include "net/base/net_errors.h"
|
| #include "net/ssl/client_key_store.h"
|
| +#include "ui/views/widget/widget.h"
|
| +#include "ui/views/window/dialog_client_view.h"
|
|
|
| namespace chromeos {
|
|
|
| @@ -400,6 +408,8 @@ void CertificateProviderService::OnExtensionUnloaded(
|
|
|
| for (auto callback : sign_requests_.RemoveAllRequests(extension_id))
|
| callback.Run(net::ERR_FAILED, std::vector<uint8_t>());
|
| +
|
| + last_rejected_[extension_id] = false;
|
| }
|
|
|
| void CertificateProviderService::GetCertificatesFromExtensions(
|
| @@ -476,4 +486,93 @@ void CertificateProviderService::RequestSignatureFromExtension(
|
| }
|
| }
|
|
|
| +void CertificateProviderService::OnPinDialogInput(
|
| + const std::string& extension_id,
|
| + const bool closed) {
|
| + last_rejected_[extension_id] = closed;
|
| + if (closed) {
|
| + active_pin_dialog_ = nullptr;
|
| + } else {
|
| + // Set the temporary callback to be called if user closes the dialog while
|
| + // request is processing by the extension.
|
| + active_pin_dialog_->SetCallback(
|
| + base::Bind(&CertificateProviderService::OnFlowInterrupted,
|
| + base::Unretained(this)));
|
| + }
|
| +}
|
| +
|
| +void CertificateProviderService::OnFlowInterrupted(
|
| + const base::string16& value) {
|
| + DCHECK(value.empty());
|
| + OnPinDialogInput(active_dialog_extension_id_, true);
|
| +}
|
| +
|
| +bool CertificateProviderService::LastPinDialogClosed(
|
| + const std::string& extension_id) {
|
| + return last_rejected_[extension_id];
|
| +}
|
| +
|
| +bool CertificateProviderService::ShowPinDialog(
|
| + const std::string& extension_id,
|
| + const std::string& extension_name,
|
| + const std::string& dialog_type,
|
| + const base::string16& error_message,
|
| + const bool accept_input,
|
| + const RequestPinView::UserInputCallback& callback) {
|
| + // Don't allow the extension to create anything if an active dialog already
|
| + // exists
|
| + if (active_pin_dialog_ != nullptr) {
|
| + if (!active_dialog_extension_id_.empty() &&
|
| + extension_id == active_dialog_extension_id_) {
|
| + // Set the new callback to be used by the view.
|
| + active_pin_dialog_->SetCallback(callback);
|
| + active_pin_dialog_->SetErrorMessage(error_message);
|
| + active_pin_dialog_->SetDialogType(dialog_type);
|
| + active_pin_dialog_->SetAcceptInput(accept_input);
|
| + active_pin_dialog_->GetDialogClientView()->UpdateDialogButtons();
|
| + return true;
|
| + }
|
| +
|
| + return false;
|
| + }
|
| +
|
| + active_dialog_extension_id_ = extension_id;
|
| + active_pin_dialog_ = new chromeos::RequestPinView(
|
| + extension_name, dialog_type, error_message, accept_input, callback);
|
| + gfx::NativeWindow context = ash::Shell::GetPrimaryRootWindow();
|
| + if (chromeos::LoginDisplayHost::default_host()) {
|
| + active_window_ = views::DialogDelegate::CreateDialogWidget(
|
| + active_pin_dialog_, context,
|
| + chromeos::LoginDisplayHost::default_host()->GetNativeWindow());
|
| + active_window_->SetAlwaysOnTop(true);
|
| + active_window_->Show();
|
| + } else {
|
| + Browser* browser = chrome::FindTabbedBrowser(
|
| + ProfileManager::GetPrimaryUserProfile(), true);
|
| + if (browser) {
|
| + gfx::NativeWindow native_window = browser->window()->GetNativeWindow();
|
| + active_window_ = views::DialogDelegate::CreateDialogWidget(
|
| + active_pin_dialog_, context, native_window);
|
| + active_window_->SetAlwaysOnTop(true);
|
| + active_window_->Show();
|
| + }
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +bool CertificateProviderService::CloseDialog(const std::string& extension_id) {
|
| + if (extension_id != active_dialog_extension_id_ ||
|
| + active_pin_dialog_ == nullptr) {
|
| + LOG(ERROR) << "CloseDialog called by wrong extension";
|
| + return false;
|
| + }
|
| +
|
| + // |active_pin_dialog_| gets deleted inside Close().
|
| + active_window_->Close();
|
| + active_pin_dialog_ = nullptr;
|
| +
|
| + return true;
|
| +}
|
| +
|
| } // namespace chromeos
|
|
|