| 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/ui/views/certificate_selector.h" | 5 #include "chrome/browser/ui/views/certificate_selector.h" |
| 6 | 6 |
| 7 #include <stddef.h> // For size_t. | 7 #include <stddef.h> // For size_t. |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/certificate_viewer.h" | 13 #include "chrome/browser/certificate_viewer.h" |
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "components/constrained_window/constrained_window_views.h" | 15 #include "components/constrained_window/constrained_window_views.h" |
| 16 #include "components/guest_view/browser/guest_view_base.h" |
| 17 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 16 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/models/table_model.h" | 20 #include "ui/base/models/table_model.h" |
| 19 #include "ui/base/models/table_model_observer.h" | 21 #include "ui/base/models/table_model_observer.h" |
| 20 #include "ui/views/controls/button/label_button.h" | 22 #include "ui/views/controls/button/label_button.h" |
| 21 #include "ui/views/controls/table/table_view.h" | 23 #include "ui/views/controls/table/table_view.h" |
| 22 #include "ui/views/layout/grid_layout.h" | 24 #include "ui/views/layout/grid_layout.h" |
| 23 #include "ui/views/layout/layout_constants.h" | 25 #include "ui/views/layout/layout_constants.h" |
| 24 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 25 #include "ui/views/window/dialog_client_view.h" | 27 #include "ui/views/window/dialog_client_view.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 web_contents_(web_contents), | 82 web_contents_(web_contents), |
| 81 table_(nullptr), | 83 table_(nullptr), |
| 82 view_cert_button_(nullptr) { | 84 view_cert_button_(nullptr) { |
| 83 CHECK(web_contents_); | 85 CHECK(web_contents_); |
| 84 } | 86 } |
| 85 | 87 |
| 86 CertificateSelector::~CertificateSelector() { | 88 CertificateSelector::~CertificateSelector() { |
| 87 table_->SetModel(nullptr); | 89 table_->SetModel(nullptr); |
| 88 } | 90 } |
| 89 | 91 |
| 92 // static |
| 93 bool CertificateSelector::CanShow(content::WebContents* web_contents) { |
| 94 // GetTopLevelWebContents returns |web_contents| if it is not a guest. |
| 95 content::WebContents* top_level_web_contents = |
| 96 guest_view::GuestViewBase::GetTopLevelWebContents(web_contents); |
| 97 return web_modal::WebContentsModalDialogManager::FromWebContents( |
| 98 top_level_web_contents) != nullptr; |
| 99 } |
| 100 |
| 90 void CertificateSelector::Show() { | 101 void CertificateSelector::Show() { |
| 91 constrained_window::ShowWebModalDialogViews(this, web_contents_); | 102 constrained_window::ShowWebModalDialogViews(this, web_contents_); |
| 92 | 103 |
| 93 // Select the first row automatically. This must be done after the dialog has | 104 // Select the first row automatically. This must be done after the dialog has |
| 94 // been created. | 105 // been created. |
| 95 table_->Select(0); | 106 table_->Select(0); |
| 96 } | 107 } |
| 97 | 108 |
| 98 void CertificateSelector::InitWithText(scoped_ptr<views::View> text_label) { | 109 void CertificateSelector::InitWithText(scoped_ptr<views::View> text_label) { |
| 99 views::GridLayout* const layout = views::GridLayout::CreatePanel(this); | 110 views::GridLayout* const layout = views::GridLayout::CreatePanel(this); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 void CertificateSelector::OnSelectionChanged() { | 184 void CertificateSelector::OnSelectionChanged() { |
| 174 GetDialogClientView()->ok_button()->SetEnabled(GetSelectedCert() != nullptr); | 185 GetDialogClientView()->ok_button()->SetEnabled(GetSelectedCert() != nullptr); |
| 175 } | 186 } |
| 176 | 187 |
| 177 void CertificateSelector::OnDoubleClick() { | 188 void CertificateSelector::OnDoubleClick() { |
| 178 if (GetSelectedCert()) | 189 if (GetSelectedCert()) |
| 179 GetDialogClientView()->AcceptWindow(); | 190 GetDialogClientView()->AcceptWindow(); |
| 180 } | 191 } |
| 181 | 192 |
| 182 } // namespace chrome | 193 } // namespace chrome |
| OLD | NEW |