Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / ssl_client_certificate_selector.cc
index d6805e5..08eefd9 100644 (file)
@@ -9,13 +9,11 @@
 #include "base/logging.h"
 #include "base/strings/utf_string_conversions.h"
 #include "chrome/browser/certificate_viewer.h"
-#include "chrome/browser/ui/views/constrained_window_views.h"
 #include "components/web_modal/web_contents_modal_dialog_host.h"
 #include "components/web_modal/web_contents_modal_dialog_manager.h"
 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_view.h"
 #include "grit/generated_resources.h"
 #include "net/cert/x509_certificate.h"
 #include "net/ssl/ssl_cert_request_info.h"
 #include "ui/views/widget/widget.h"
 #include "ui/views/window/dialog_client_view.h"
 
+#if defined(USE_NSS)
+#include "chrome/browser/ui/crypto_module_password_dialog_nss.h"
+#endif
+
 using content::BrowserThread;
 using content::WebContents;
 using web_modal::WebContentsModalDialogManager;
@@ -54,11 +56,11 @@ class CertificateSelectorTableModel : public ui::TableModel {
 
   // ui::TableModel implementation:
   virtual int RowCount() OVERRIDE;
-  virtual string16 GetText(int index, int column_id) OVERRIDE;
+  virtual base::string16 GetText(int index, int column_id) OVERRIDE;
   virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
 
  private:
-  std::vector<string16> items_;
+  std::vector<base::string16> items_;
 
   DISALLOW_COPY_AND_ASSIGN(CertificateSelectorTableModel);
 };
@@ -67,10 +69,10 @@ CertificateSelectorTableModel::CertificateSelectorTableModel(
     net::SSLCertRequestInfo* cert_request_info) {
   for (size_t i = 0; i < cert_request_info->client_certs.size(); ++i) {
     net::X509Certificate* cert = cert_request_info->client_certs[i].get();
-    string16 text = l10n_util::GetStringFUTF16(
+    base::string16 text = l10n_util::GetStringFUTF16(
         IDS_CERT_SELECTOR_TABLE_CERT_FORMAT,
-        UTF8ToUTF16(cert->subject().GetDisplayName()),
-        UTF8ToUTF16(cert->issuer().GetDisplayName()));
+        base::UTF8ToUTF16(cert->subject().GetDisplayName()),
+        base::UTF8ToUTF16(cert->issuer().GetDisplayName()));
     items_.push_back(text);
   }
 }
@@ -79,7 +81,8 @@ int CertificateSelectorTableModel::RowCount() {
   return items_.size();
 }
 
-string16 CertificateSelectorTableModel::GetText(int index, int column_id) {
+base::string16 CertificateSelectorTableModel::GetText(int index,
+                                                      int column_id) {
   DCHECK_EQ(column_id, 0);
   DCHECK_GE(index, 0);
   DCHECK_LT(index, static_cast<int>(items_.size()));
@@ -123,9 +126,9 @@ void SSLClientCertificateSelector::Init() {
       1, views::GridLayout::USE_PREF, 0, 0);
 
   layout->StartRow(0, column_set_id);
-  string16 text = l10n_util::GetStringFUTF16(
+  base::string16 text = l10n_util::GetStringFUTF16(
       IDS_CLIENT_CERT_DIALOG_TEXT,
-      ASCIIToUTF16(cert_request_info()->host_and_port));
+      base::ASCIIToUTF16(cert_request_info()->host_and_port.ToString()));
   views::Label* label = new views::Label(text);
   label->SetMultiLine(true);
   label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
@@ -150,10 +153,9 @@ void SSLClientCertificateSelector::Init() {
       web_contents_modal_dialog_manager->delegate();
   DCHECK(modal_delegate);
   window_ = views::Widget::CreateWindowAsFramelessChild(
-      this,
-      web_contents_->GetView()->GetNativeView(),
-      modal_delegate->GetWebContentsModalDialogHost()->GetHostView());
-  web_contents_modal_dialog_manager->ShowDialog(window_->GetNativeView());
+      this, modal_delegate->GetWebContentsModalDialogHost()->GetHostView());
+  web_contents_modal_dialog_manager->ShowModalDialog(
+      window_->GetNativeView());
 
   // Select the first row automatically.  This must be done after the dialog has
   // been created.
@@ -185,7 +187,7 @@ bool SSLClientCertificateSelector::CanResize() const {
   return true;
 }
 
-string16 SSLClientCertificateSelector::GetWindowTitle() const {
+base::string16 SSLClientCertificateSelector::GetWindowTitle() const {
   return l10n_util::GetStringUTF16(IDS_CLIENT_CERT_DIALOG_TITLE);
 }
 
@@ -211,26 +213,30 @@ bool SSLClientCertificateSelector::Cancel() {
 
 bool SSLClientCertificateSelector::Accept() {
   DVLOG(1) << __FUNCTION__;
-  net::X509Certificate* cert = GetSelectedCert();
+  scoped_refptr<net::X509Certificate> cert = GetSelectedCert();
   if (cert) {
+    // Remove the observer before we try unlocking, otherwise we might act on a
+    // notification while waiting for the unlock dialog, causing us to delete
+    // ourself before the Unlocked callback gets called.
     StopObserving();
-    CertificateSelected(cert);
-    return true;
+#if defined(USE_NSS)
+    chrome::UnlockCertSlotIfNecessary(
+        cert,
+        chrome::kCryptoModulePasswordClientAuth,
+        cert_request_info()->host_and_port,
+        window_->GetNativeView(),
+        base::Bind(&SSLClientCertificateSelector::Unlocked,
+                   base::Unretained(this),
+                   cert));
+#else
+    Unlocked(cert);
+#endif
+    return false;  // Unlocked() will close the dialog.
   }
 
   return false;
 }
 
-// TODO(wittman): Remove this override once we move to the new style frame view
-// on all dialogs.
-views::NonClientFrameView*
-    SSLClientCertificateSelector::CreateNonClientFrameView(
-        views::Widget* widget) {
-  return CreateConstrainedStyleNonClientFrameView(
-      widget,
-      web_contents_->GetBrowserContext());
-}
-
 views::View* SSLClientCertificateSelector::GetInitiallyFocusedView() {
   return table_;
 }
@@ -239,7 +245,7 @@ views::View* SSLClientCertificateSelector::CreateExtraView() {
   DCHECK(!view_cert_button_);
   view_cert_button_ = new views::LabelButton(this,
       l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON));
-  view_cert_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
+  view_cert_button_->SetStyle(views::Button::STYLE_BUTTON);
   return view_cert_button_;
 }
 
@@ -260,7 +266,7 @@ void SSLClientCertificateSelector::ButtonPressed(
     net::X509Certificate* cert = GetSelectedCert();
     if (cert)
       ShowCertificateViewer(web_contents_,
-                            web_contents_->GetView()->GetTopLevelNativeWindow(),
+                            web_contents_->GetTopLevelNativeWindow(),
                             cert);
   }
 }
@@ -289,6 +295,12 @@ void SSLClientCertificateSelector::CreateCertTable() {
   table_->SetObserver(this);
 }
 
+void SSLClientCertificateSelector::Unlocked(net::X509Certificate* cert) {
+  DVLOG(1) << __FUNCTION__;
+  CertificateSelected(cert);
+  window_->Close();
+}
+
 namespace chrome {
 
 void ShowSSLClientCertificateSelector(
@@ -297,7 +309,7 @@ void ShowSSLClientCertificateSelector(
     net::SSLCertRequestInfo* cert_request_info,
     const chrome::SelectCertificateCallback& callback) {
   DVLOG(1) << __FUNCTION__ << " " << contents;
-  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+  DCHECK_CURRENTLY_ON(BrowserThread::UI);
   (new SSLClientCertificateSelector(
        contents, network_session, cert_request_info, callback))->Init();
 }