15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/views/signed_certificate_timestamps_views.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/strings/string_number_conversions.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/strings/stringprintf.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chrome_notification_types.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/views/constrained_window_views.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/views/signed_certificate_timestamp_info_view.h" 136e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/grit/generated_resources.h" 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/notification_source.h" 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/browser/signed_certificate_timestamp_store.h" 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "content/public/common/signed_certificate_timestamp_id_and_status.h" 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h" 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/base/models/combobox_model.h" 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/controls/combobox/combobox.h" 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/layout/grid_layout.h" 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/layout/layout_constants.h" 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/widget/widget.h" 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace { 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SignedCertificateTimestampIDsToList( 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const content::SignedCertificateTimestampIDStatusList& sct_ids_list, 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) net::SignedCertificateTimestampAndStatusList* sct_list) { 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (content::SignedCertificateTimestampIDStatusList::const_iterator it = 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sct_ids_list.begin(); 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) it != sct_ids_list.end(); 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ++it) { 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_refptr<net::ct::SignedCertificateTimestamp> sct; 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::SignedCertificateTimestampStore::GetInstance()->Retrieve(it->id, 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) &sct); 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sct_list->push_back( 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) net::SignedCertificateTimestampAndStatus(sct, it->status)); 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace chrome { 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ShowSignedCertificateTimestampsViewer( 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::WebContents* web_contents, 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const content::SignedCertificateTimestampIDStatusList& sct_ids_list) { 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) net::SignedCertificateTimestampAndStatusList sct_list; 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SignedCertificateTimestampIDsToList(sct_ids_list, &sct_list); 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new SignedCertificateTimestampsViews(web_contents, sct_list); 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace chrome 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class SCTListModel : public ui::ComboboxModel { 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) explicit SCTListModel( 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const net::SignedCertificateTimestampAndStatusList& sct_list); 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ~SCTListModel(); 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Overridden from ui::ComboboxModel: 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual int GetItemCount() const OVERRIDE; 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual base::string16 GetItemAt(int index) OVERRIDE; 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) net::SignedCertificateTimestampAndStatusList sct_list_; 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(SCTListModel); 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SCTListModel::SCTListModel( 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const net::SignedCertificateTimestampAndStatusList& sct_list) 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : sct_list_(sct_list) {} 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SCTListModel::~SCTListModel() {} 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int SCTListModel::GetItemCount() const { return sct_list_.size(); } 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::string16 SCTListModel::GetItemAt(int index) { 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK_LT(static_cast<size_t>(index), sct_list_.size()); 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string origin = l10n_util::GetStringUTF8( 821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci chrome::ct::SCTOriginToResourceID(*(sct_list_[index].sct.get()))); 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string status = l10n_util::GetStringUTF8( 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) chrome::ct::StatusToResourceID(sct_list_[index].status)); 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 87a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // This formatting string may be internationalized for RTL, etc. 88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) return l10n_util::GetStringFUTF16(IDS_SCT_CHOOSER_FORMAT, 89a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::IntToString16(index + 1), 90a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::UTF8ToUTF16(origin), 91a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::UTF8ToUTF16(status)); 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SignedCertificateTimestampsViews::SignedCertificateTimestampsViews( 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::WebContents* web_contents, 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const net::SignedCertificateTimestampAndStatusList& sct_list) 970529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch : sct_info_view_(NULL), 980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch sct_list_(sct_list) { 9946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) ShowWebModalDialogViews(this, web_contents); 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)SignedCertificateTimestampsViews::~SignedCertificateTimestampsViews() {} 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)base::string16 SignedCertificateTimestampsViews::GetWindowTitle() const { 1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return l10n_util::GetStringUTF16(IDS_SCT_VIEWER_TITLE); 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)int SignedCertificateTimestampsViews::GetDialogButtons() const { 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return ui::DIALOG_BUTTON_CANCEL; 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)ui::ModalType SignedCertificateTimestampsViews::GetModalType() const { 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return ui::MODAL_TYPE_CHILD; 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SignedCertificateTimestampsViews::OnPerformAction( 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) views::Combobox* combobox) { 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK_EQ(combobox, sct_selector_box_.get()); 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK_LT(combobox->selected_index(), sct_list_model_->GetItemCount()); 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ShowSCTInfo(combobox->selected_index()); 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SignedCertificateTimestampsViews::ViewHierarchyChanged( 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const ViewHierarchyChangedDetails& details) { 1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (details.is_add && details.child == this) 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Init(); 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SignedCertificateTimestampsViews::Init() { 13046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) views::GridLayout* layout = views::GridLayout::CreatePanel(this); 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetLayoutManager(layout); 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const int kSelectorBoxLayoutId = 0; 1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) views::ColumnSet* column_set = layout->AddColumnSet(kSelectorBoxLayoutId); 13546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 13646d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) views::GridLayout::USE_PREF, 0, 0); 1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->StartRow(0, kSelectorBoxLayoutId); 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Add SCT selector drop-down list. 1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->StartRow(0, kSelectorBoxLayoutId); 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sct_list_model_.reset(new SCTListModel(sct_list_)); 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sct_selector_box_.reset(new views::Combobox(sct_list_model_.get())); 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sct_selector_box_->set_listener(this); 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sct_selector_box_->set_owned_by_client(); 1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->AddView(sct_selector_box_.get()); 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Add the SCT info view, displaying information about a specific SCT. 1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->StartRow(0, kSelectorBoxLayoutId); 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sct_info_view_ = new SignedCertificateTimestampInfoView(); 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) layout->AddView(sct_info_view_); 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci sct_info_view_->SetSignedCertificateTimestamp(*(sct_list_[0].sct.get()), 1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) sct_list_[0].status); 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SignedCertificateTimestampsViews::ShowSCTInfo(int sct_index) { 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if ((sct_index < 0) || (static_cast<size_t>(sct_index) > sct_list_.size())) 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci sct_info_view_->SetSignedCertificateTimestamp( 1641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci *(sct_list_[sct_index].sct.get()), sct_list_[sct_index].status); 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SignedCertificateTimestampsViews::Observe( 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int type, 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const content::NotificationSource& source, 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const content::NotificationDetails& details) { 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetWidget()->Close(); 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 173