1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/certificate_viewer.h"
12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_dialogs.h"
16 #include "chrome/browser/ui/views/collected_cookies_views.h"
17 #include "chrome/browser/ui/views/website_settings/permission_selector_view.h"
18 #include "chrome/browser/ui/website_settings/website_settings.h"
19 #include "chrome/browser/ui/website_settings/website_settings_utils.h"
20 #include "chrome/common/url_constants.h"
21 #include "chrome/grit/chromium_strings.h"
22 #include "chrome/grit/generated_resources.h"
23 #include "components/content_settings/core/common/content_settings_types.h"
24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/cert_store.h"
26 #include "content/public/browser/user_metrics.h"
27 #include "grit/theme_resources.h"
28 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/models/simple_menu_model.h"
30 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/gfx/canvas.h"
32 #include "ui/gfx/font_list.h"
33 #include "ui/gfx/geometry/insets.h"
34 #include "ui/gfx/image/image.h"
35 #include "ui/resources/grit/ui_resources.h"
36 #include "ui/views/controls/button/image_button.h"
37 #include "ui/views/controls/button/menu_button.h"
38 #include "ui/views/controls/button/menu_button_listener.h"
39 #include "ui/views/controls/image_view.h"
40 #include "ui/views/controls/label.h"
41 #include "ui/views/controls/link.h"
42 #include "ui/views/controls/menu/menu_model_adapter.h"
43 #include "ui/views/controls/menu/menu_runner.h"
44 #include "ui/views/controls/separator.h"
45 #include "ui/views/controls/tabbed_pane/tabbed_pane.h"
46 #include "ui/views/layout/box_layout.h"
47 #include "ui/views/layout/grid_layout.h"
48 #include "ui/views/layout/layout_manager.h"
49 #include "ui/views/view.h"
50 #include "ui/views/widget/widget.h"
55 // NOTE(jdonnelly): This use of this process-wide variable assumes that there's
56 // never more than one website settings popup shown and that it's associated
57 // with the current window. If this assumption fails in the future, we'll need
58 // to return a weak pointer from ShowPopup so callers can associate it with the
59 // current window (or other context) and check if the popup they care about is
61 bool is_popup_showing
= false;
63 // Padding values for sections on the connection tab.
64 const int kConnectionSectionPaddingBottom
= 16;
65 const int kConnectionSectionPaddingLeft
= 18;
66 const int kConnectionSectionPaddingTop
= 16;
67 const int kConnectionSectionPaddingRight
= 18;
69 // The text color that is used for the site identity status text, if the site's
70 // identity was sucessfully verified.
71 const SkColor kIdentityVerifiedTextColor
= 0xFF298a27;
74 const int kIconMarginLeft
= 6;
76 // Margin and padding values for the |PopupHeaderView|.
77 const int kHeaderMarginBottom
= 10;
78 const int kHeaderPaddingBottom
= 12;
79 const int kHeaderPaddingLeft
= 18;
80 const int kHeaderPaddingRight
= 8;
81 const int kHeaderPaddingTop
= 12;
83 // Spacing between the site identity label and the site identity status text in
85 const int kHeaderRowSpacing
= 4;
87 // To make the bubble's arrow point directly at the location icon rather than at
88 // the Omnibox's edge, inset the bubble's anchor rect by this amount of pixels.
89 const int kLocationIconVerticalMargin
= 5;
91 // The max possible width of the popup.
92 const int kMaxPopupWidth
= 500;
94 // The margins between the popup border and the popup content.
95 const int kPopupMarginTop
= 4;
96 const int kPopupMarginLeft
= 0;
97 const int kPopupMarginBottom
= 10;
98 const int kPopupMarginRight
= 0;
100 // Padding values for sections on the permissions tab.
101 const int kPermissionsSectionContentMinWidth
= 300;
102 const int kPermissionsSectionPaddingBottom
= 6;
103 const int kPermissionsSectionPaddingLeft
= 18;
104 const int kPermissionsSectionPaddingTop
= 16;
106 // Space between the headline and the content of a section on the permissions
108 const int kPermissionsSectionHeadlineMarginBottom
= 10;
109 // The content of the "Permissions" section and the "Cookies and Site Data"
110 // section is structured in individual rows. |kPermissionsSectionRowSpacing|
111 // is the space between these rows.
112 const int kPermissionsSectionRowSpacing
= 2;
114 const int kSiteDataIconColumnWidth
= 20;
115 const int kSiteDataSectionRowSpacing
= 11;
119 // |PopupHeaderView| is the UI element (view) that represents the header of the
120 // |WebsiteSettingsPopupView|. The header shows the status of the site's
121 // identity check and the name of the site's identity.
122 class PopupHeaderView
: public views::View
{
124 explicit PopupHeaderView(views::ButtonListener
* close_button_listener
);
125 ~PopupHeaderView() override
;
127 // Sets the name of the site's identity.
128 void SetIdentityName(const base::string16
& name
);
130 // Sets the |status_text| for the identity check of this site and the
132 void SetIdentityStatus(const base::string16
& status_text
, SkColor text_color
);
135 // The label that displays the name of the site's identity.
137 // The label that displays the status of the identity check for this site.
138 views::Label
* status_
;
140 DISALLOW_COPY_AND_ASSIGN(PopupHeaderView
);
143 // Website Settings are not supported for internal Chrome pages. Instead of the
144 // |WebsiteSettingsPopupView|, the |InternalPageInfoPopupView| is
146 class InternalPageInfoPopupView
: public views::BubbleDelegateView
{
148 explicit InternalPageInfoPopupView(views::View
* anchor_view
);
149 ~InternalPageInfoPopupView() override
;
151 // views::BubbleDelegateView:
152 void OnWidgetDestroying(views::Widget
* widget
) override
;
155 DISALLOW_COPY_AND_ASSIGN(InternalPageInfoPopupView
);
158 ////////////////////////////////////////////////////////////////////////////////
160 ////////////////////////////////////////////////////////////////////////////////
162 PopupHeaderView::PopupHeaderView(views::ButtonListener
* close_button_listener
)
163 : name_(nullptr), status_(nullptr) {
164 views::GridLayout
* layout
= new views::GridLayout(this);
165 SetLayoutManager(layout
);
167 const int label_column
= 0;
168 views::ColumnSet
* column_set
= layout
->AddColumnSet(label_column
);
169 column_set
->AddPaddingColumn(0, kHeaderPaddingLeft
);
170 column_set
->AddColumn(views::GridLayout::FILL
,
171 views::GridLayout::FILL
,
173 views::GridLayout::USE_PREF
,
176 column_set
->AddPaddingColumn(1, 0);
177 column_set
->AddColumn(views::GridLayout::FILL
,
178 views::GridLayout::FILL
,
180 views::GridLayout::USE_PREF
,
183 column_set
->AddPaddingColumn(0, kHeaderPaddingRight
);
185 layout
->AddPaddingRow(0, kHeaderPaddingTop
);
187 layout
->StartRow(0, label_column
);
188 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
189 name_
= new views::Label(
190 base::string16(), rb
.GetFontList(ui::ResourceBundle::BoldFont
));
191 layout
->AddView(name_
, 1, 1, views::GridLayout::LEADING
,
192 views::GridLayout::TRAILING
);
193 views::ImageButton
* close_button
=
194 new views::ImageButton(close_button_listener
);
195 close_button
->SetImage(views::CustomButton::STATE_NORMAL
,
196 rb
.GetImageNamed(IDR_CLOSE_2
).ToImageSkia());
197 close_button
->SetImage(views::CustomButton::STATE_HOVERED
,
198 rb
.GetImageNamed(IDR_CLOSE_2_H
).ToImageSkia());
199 close_button
->SetImage(views::CustomButton::STATE_PRESSED
,
200 rb
.GetImageNamed(IDR_CLOSE_2_P
).ToImageSkia());
201 layout
->AddView(close_button
, 1, 1, views::GridLayout::TRAILING
,
202 views::GridLayout::LEADING
);
204 layout
->AddPaddingRow(0, kHeaderRowSpacing
);
206 layout
->StartRow(1, label_column
);
207 status_
= new views::Label(base::string16());
208 status_
->SetMultiLine(true);
209 status_
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
210 layout
->AddView(status_
,
213 views::GridLayout::LEADING
,
214 views::GridLayout::LEADING
);
216 layout
->AddPaddingRow(1, kHeaderPaddingBottom
);
219 PopupHeaderView::~PopupHeaderView() {
222 void PopupHeaderView::SetIdentityName(const base::string16
& name
) {
223 name_
->SetText(name
);
226 void PopupHeaderView::SetIdentityStatus(const base::string16
& status
,
227 SkColor text_color
) {
228 status_
->SetText(status
);
229 status_
->SetEnabledColor(text_color
);
232 ////////////////////////////////////////////////////////////////////////////////
233 // InternalPageInfoPopupView
234 ////////////////////////////////////////////////////////////////////////////////
236 InternalPageInfoPopupView::InternalPageInfoPopupView(views::View
* anchor_view
)
237 : BubbleDelegateView(anchor_view
, views::BubbleBorder::TOP_LEFT
) {
238 // Compensate for built-in vertical padding in the anchor view's image.
239 set_anchor_view_insets(gfx::Insets(kLocationIconVerticalMargin
, 0,
240 kLocationIconVerticalMargin
, 0));
242 const int kSpacing
= 4;
243 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal
, kSpacing
,
244 kSpacing
, kSpacing
));
245 views::ImageView
* icon_view
= new views::ImageView();
246 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
247 icon_view
->SetImage(rb
.GetImageSkiaNamed(IDR_PRODUCT_LOGO_26
));
248 AddChildView(icon_view
);
250 views::Label
* label
=
251 new views::Label(l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE
));
252 label
->SetMultiLine(true);
253 label
->SetAllowCharacterBreak(true);
254 label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
257 views::BubbleDelegateView::CreateBubble(this)->Show();
261 InternalPageInfoPopupView::~InternalPageInfoPopupView() {
264 void InternalPageInfoPopupView::OnWidgetDestroying(views::Widget
* widget
) {
265 is_popup_showing
= false;
268 ////////////////////////////////////////////////////////////////////////////////
269 // WebsiteSettingsPopupView
270 ////////////////////////////////////////////////////////////////////////////////
272 WebsiteSettingsPopupView::~WebsiteSettingsPopupView() {
276 void WebsiteSettingsPopupView::ShowPopup(views::View
* anchor_view
,
278 content::WebContents
* web_contents
,
280 const content::SSLStatus
& ssl
,
282 is_popup_showing
= true;
283 if (InternalChromePage(url
)) {
284 new InternalPageInfoPopupView(anchor_view
);
286 new WebsiteSettingsPopupView(anchor_view
, profile
, web_contents
, url
, ssl
,
292 bool WebsiteSettingsPopupView::IsPopupShowing() {
293 return is_popup_showing
;
296 WebsiteSettingsPopupView::WebsiteSettingsPopupView(
297 views::View
* anchor_view
,
299 content::WebContents
* web_contents
,
301 const content::SSLStatus
& ssl
,
303 : BubbleDelegateView(anchor_view
, views::BubbleBorder::TOP_LEFT
),
304 web_contents_(web_contents
),
307 tabbed_pane_(nullptr),
308 permissions_tab_(nullptr),
309 site_data_content_(nullptr),
310 cookie_dialog_link_(nullptr),
311 permissions_content_(nullptr),
312 connection_tab_(nullptr),
313 identity_info_content_(nullptr),
314 certificate_dialog_link_(nullptr),
315 reset_decisions_button_(nullptr),
317 help_center_link_(nullptr),
318 connection_info_content_(nullptr),
319 weak_factory_(this) {
320 // Compensate for built-in vertical padding in the anchor view's image.
321 set_anchor_view_insets(gfx::Insets(kLocationIconVerticalMargin
, 0,
322 kLocationIconVerticalMargin
, 0));
324 views::GridLayout
* layout
= new views::GridLayout(this);
325 SetLayoutManager(layout
);
326 const int content_column
= 0;
327 views::ColumnSet
* column_set
= layout
->AddColumnSet(content_column
);
328 column_set
->AddColumn(views::GridLayout::FILL
,
329 views::GridLayout::FILL
,
331 views::GridLayout::USE_PREF
,
335 header_
= new PopupHeaderView(this);
336 layout
->StartRow(1, content_column
);
337 layout
->AddView(header_
);
339 layout
->AddPaddingRow(1, kHeaderMarginBottom
);
340 tabbed_pane_
= new views::TabbedPane();
341 layout
->StartRow(1, content_column
);
342 layout
->AddView(tabbed_pane_
);
344 // Tabs must be added after the tabbed_pane_ was added to the views hierarchy.
345 // Adding the |tabbed_pane_| to the views hierarchy triggers the
346 // initialization of the native tab UI element. If the native tab UI element
347 // is not initalized, adding a tab will result in a NULL pointer exception.
348 permissions_tab_
= CreatePermissionsTab();
349 tabbed_pane_
->AddTabAtIndex(
351 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TAB_LABEL_PERMISSIONS
),
353 connection_tab_
= CreateConnectionTab();
354 tabbed_pane_
->AddTabAtIndex(
356 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TAB_LABEL_CONNECTION
),
358 DCHECK_EQ(tabbed_pane_
->GetTabCount(), NUM_TAB_IDS
);
359 tabbed_pane_
->set_listener(this);
361 set_margins(gfx::Insets(kPopupMarginTop
, kPopupMarginLeft
,
362 kPopupMarginBottom
, kPopupMarginRight
));
364 views::BubbleDelegateView::CreateBubble(this)->Show();
367 presenter_
.reset(new WebsiteSettings(
369 TabSpecificContentSettings::FromWebContents(web_contents
),
370 InfoBarService::FromWebContents(web_contents
), url
, ssl
,
371 content::CertStore::GetInstance()));
374 void WebsiteSettingsPopupView::OnPermissionChanged(
375 const WebsiteSettingsUI::PermissionInfo
& permission
) {
376 presenter_
->OnSitePermissionChanged(permission
.type
, permission
.setting
);
379 void WebsiteSettingsPopupView::OnWidgetDestroying(views::Widget
* widget
) {
380 is_popup_showing
= false;
381 presenter_
->OnUIClosing();
384 void WebsiteSettingsPopupView::ButtonPressed(views::Button
* button
,
385 const ui::Event
& event
) {
386 if (button
== reset_decisions_button_
)
387 presenter_
->OnRevokeSSLErrorBypassButtonPressed();
388 GetWidget()->Close();
391 void WebsiteSettingsPopupView::LinkClicked(views::Link
* source
,
393 // The popup closes automatically when the collected cookies dialog or the
394 // certificate viewer opens. So delay handling of the link clicked to avoid
395 // a crash in the base class which needs to complete the mouse event handling.
396 content::BrowserThread::PostTask(
397 content::BrowserThread::UI
, FROM_HERE
,
398 base::Bind(&WebsiteSettingsPopupView::HandleLinkClickedAsync
,
399 weak_factory_
.GetWeakPtr(), source
));
402 void WebsiteSettingsPopupView::TabSelectedAt(int index
) {
404 case TAB_ID_PERMISSIONS
:
405 presenter_
->RecordWebsiteSettingsAction(
406 WebsiteSettings::WEBSITE_SETTINGS_PERMISSIONS_TAB_SELECTED
);
408 case TAB_ID_CONNECTION
:
409 // If the Connection tab is selected first, we're still inside the
410 // construction of presenter_. In that case, the action is already logged
411 // by WEBSITE_SETTINGS_CONNECTION_TAB_SHOWN_IMMEDIATELY.
413 presenter_
->RecordWebsiteSettingsAction(
414 WebsiteSettings::WEBSITE_SETTINGS_CONNECTION_TAB_SELECTED
);
420 tabbed_pane_
->GetSelectedTab()->Layout();
424 gfx::Size
WebsiteSettingsPopupView::GetPreferredSize() const {
425 if (header_
== nullptr && tabbed_pane_
== nullptr)
426 return views::View::GetPreferredSize();
430 height
+= header_
->GetPreferredSize().height();
432 height
+= tabbed_pane_
->GetPreferredSize().height();
434 int width
= kPermissionsSectionContentMinWidth
;
435 if (site_data_content_
)
436 width
= std::max(width
, site_data_content_
->GetPreferredSize().width());
437 if (permissions_content_
)
438 width
= std::max(width
, permissions_content_
->GetPreferredSize().width());
439 width
+= kPermissionsSectionPaddingLeft
;
440 width
= std::min(width
, kMaxPopupWidth
);
442 return gfx::Size(width
, height
);
445 void WebsiteSettingsPopupView::SetCookieInfo(
446 const CookieInfoList
& cookie_info_list
) {
447 site_data_content_
->RemoveAllChildViews(true);
449 views::GridLayout
* layout
= new views::GridLayout(site_data_content_
);
450 site_data_content_
->SetLayoutManager(layout
);
452 const int site_data_content_column
= 0;
453 views::ColumnSet
* column_set
=
454 layout
->AddColumnSet(site_data_content_column
);
455 column_set
->AddColumn(views::GridLayout::FILL
,
456 views::GridLayout::FILL
,
458 views::GridLayout::FIXED
,
459 kSiteDataIconColumnWidth
,
461 column_set
->AddPaddingColumn(0, kIconMarginLeft
);
462 column_set
->AddColumn(views::GridLayout::FILL
,
463 views::GridLayout::FILL
,
465 views::GridLayout::USE_PREF
,
469 layout
->AddPaddingRow(1, 5);
470 for (CookieInfoList::const_iterator
i(cookie_info_list
.begin());
471 i
!= cookie_info_list
.end();
473 base::string16 label_text
= l10n_util::GetStringFUTF16(
474 IDS_WEBSITE_SETTINGS_SITE_DATA_STATS_LINE
,
475 base::UTF8ToUTF16(i
->cookie_source
),
476 base::IntToString16(i
->allowed
),
477 base::IntToString16(i
->blocked
));
478 if (i
!= cookie_info_list
.begin())
479 layout
->AddPaddingRow(1, kSiteDataSectionRowSpacing
);
480 layout
->StartRow(1, site_data_content_column
);
481 WebsiteSettingsUI::PermissionInfo info
;
482 info
.type
= CONTENT_SETTINGS_TYPE_COOKIES
;
483 info
.setting
= CONTENT_SETTING_ALLOW
;
484 views::ImageView
* icon
= new views::ImageView();
485 const gfx::Image
& image
= WebsiteSettingsUI::GetPermissionIcon(info
);
486 icon
->SetImage(image
.ToImageSkia());
487 layout
->AddView(icon
, 1, 1, views::GridLayout::CENTER
,
488 views::GridLayout::CENTER
);
489 layout
->AddView(new views::Label(label_text
), 1, 1,
490 views::GridLayout::LEADING
, views::GridLayout::CENTER
);
492 layout
->AddPaddingRow(1, 6);
494 layout
->Layout(site_data_content_
);
498 void WebsiteSettingsPopupView::SetPermissionInfo(
499 const PermissionInfoList
& permission_info_list
) {
500 permissions_content_
= new views::View();
501 views::GridLayout
* layout
= new views::GridLayout(permissions_content_
);
502 permissions_content_
->SetLayoutManager(layout
);
504 base::string16 headline
=
505 permission_info_list
.empty()
507 : l10n_util::GetStringUTF16(
508 IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS
);
509 views::View
* permissions_section
=
510 CreateSection(headline
, permissions_content_
, nullptr);
511 permissions_tab_
->AddChildView(permissions_section
);
513 const int content_column
= 0;
514 views::ColumnSet
* column_set
= layout
->AddColumnSet(content_column
);
515 column_set
->AddColumn(views::GridLayout::FILL
,
516 views::GridLayout::FILL
,
518 views::GridLayout::USE_PREF
,
521 for (PermissionInfoList::const_iterator permission
=
522 permission_info_list
.begin();
523 permission
!= permission_info_list
.end();
525 layout
->StartRow(1, content_column
);
526 PermissionSelectorView
* selector
= new PermissionSelectorView(
527 web_contents_
? web_contents_
->GetURL() : GURL::EmptyGURL(),
529 selector
->AddObserver(this);
530 layout
->AddView(selector
,
533 views::GridLayout::LEADING
,
534 views::GridLayout::CENTER
);
535 layout
->AddPaddingRow(1, kPermissionsSectionRowSpacing
);
538 layout
->Layout(permissions_content_
);
540 // Add site settings link.
541 site_settings_link_
= new views::Link(
542 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_SETTINGS_LINK
));
543 site_settings_link_
->set_listener(this);
544 views::View
* link_section
= new views::View();
545 const int kLinkMarginTop
= 4;
546 link_section
->SetLayoutManager(
547 new views::BoxLayout(views::BoxLayout::kHorizontal
,
548 kConnectionSectionPaddingLeft
, kLinkMarginTop
, 0));
549 link_section
->AddChildView(site_settings_link_
);
550 permissions_tab_
->AddChildView(link_section
);
555 void WebsiteSettingsPopupView::SetIdentityInfo(
556 const IdentityInfo
& identity_info
) {
557 base::string16 identity_status_text
= identity_info
.GetIdentityStatusText();
558 SkColor text_color
= SK_ColorBLACK
;
559 if (identity_info
.identity_status
==
560 WebsiteSettings::SITE_IDENTITY_STATUS_CERT
||
561 identity_info
.identity_status
==
562 WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT
) {
563 text_color
= kIdentityVerifiedTextColor
;
565 header_
->SetIdentityName(base::UTF8ToUTF16(identity_info
.site_identity
));
566 header_
->SetIdentityStatus(identity_status_text
, text_color
);
568 // The headline and the certificate dialog link of the site's identity
569 // section is only displayed if the site's identity was verified. If the
570 // site's identity was verified, then the headline contains the organization
571 // name from the provided certificate. If the organization name is not
572 // available than the hostname of the site is used instead.
573 base::string16 headline
;
574 if (identity_info
.cert_id
) {
575 cert_id_
= identity_info
.cert_id
;
577 certificate_dialog_link_
= new views::Link(
578 l10n_util::GetStringUTF16(IDS_PAGEINFO_CERT_INFO_BUTTON
));
579 certificate_dialog_link_
->set_listener(this);
581 if (identity_info
.show_ssl_decision_revoke_button
) {
582 reset_decisions_button_
= new views::LabelButton(
584 l10n_util::GetStringUTF16(
585 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON
));
586 reset_decisions_button_
->SetStyle(views::Button::STYLE_BUTTON
);
589 headline
= base::UTF8ToUTF16(identity_info
.site_identity
);
591 ResetConnectionSection(
592 identity_info_content_
,
593 WebsiteSettingsUI::GetIdentityIcon(identity_info
.identity_status
),
594 base::string16(), // The identity section has no headline.
595 base::UTF8ToUTF16(identity_info
.identity_status_description
),
596 certificate_dialog_link_
,
597 reset_decisions_button_
);
599 ResetConnectionSection(
600 connection_info_content_
,
601 WebsiteSettingsUI::GetConnectionIcon(identity_info
.connection_status
),
602 base::string16(), // The connection section has no headline.
603 base::UTF8ToUTF16(identity_info
.connection_status_description
),
607 connection_tab_
->InvalidateLayout();
612 void WebsiteSettingsPopupView::SetSelectedTab(TabId tab_id
) {
613 tabbed_pane_
->SelectTabAt(tab_id
);
616 views::View
* WebsiteSettingsPopupView::CreatePermissionsTab() {
617 views::View
* pane
= new views::View();
618 pane
->SetLayoutManager(
619 new views::BoxLayout(views::BoxLayout::kVertical
, 0, 0, 1));
621 // Add cookies and site data section.
622 cookie_dialog_link_
= new views::Link(
623 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_SHOW_SITE_DATA
));
624 cookie_dialog_link_
->set_listener(this);
625 site_data_content_
= new views::View();
626 views::View
* site_data_section
=
627 CreateSection(l10n_util::GetStringUTF16(
628 IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA
),
630 cookie_dialog_link_
);
631 pane
->AddChildView(site_data_section
);
636 views::View
* WebsiteSettingsPopupView::CreateConnectionTab() {
637 views::View
* pane
= new views::View();
638 pane
->SetLayoutManager(
639 new views::BoxLayout(views::BoxLayout::kVertical
, 0, 0, 1));
640 // Add site identity section.
641 identity_info_content_
= new views::View();
642 pane
->AddChildView(identity_info_content_
);
644 // Add connection section.
645 pane
->AddChildView(new views::Separator(views::Separator::HORIZONTAL
));
646 connection_info_content_
= new views::View();
647 pane
->AddChildView(connection_info_content_
);
649 pane
->AddChildView(new views::Separator(views::Separator::HORIZONTAL
));
651 // Add help center link.
652 help_center_link_
= new views::Link(
653 l10n_util::GetStringUTF16(IDS_PAGE_INFO_HELP_CENTER_LINK
));
654 help_center_link_
->set_listener(this);
655 views::View
* link_section
= new views::View();
656 const int kLinkMarginTop
= 4;
657 link_section
->SetLayoutManager(
658 new views::BoxLayout(views::BoxLayout::kHorizontal
,
659 kConnectionSectionPaddingLeft
,
662 link_section
->AddChildView(help_center_link_
);
663 pane
->AddChildView(link_section
);
667 views::View
* WebsiteSettingsPopupView::CreateSection(
668 const base::string16
& headline_text
,
669 views::View
* content
,
671 views::View
* container
= new views::View();
672 views::GridLayout
* layout
= new views::GridLayout(container
);
673 container
->SetLayoutManager(layout
);
674 const int content_column
= 0;
675 views::ColumnSet
* column_set
= layout
->AddColumnSet(content_column
);
676 column_set
->AddPaddingColumn(0, kPermissionsSectionPaddingLeft
);
677 column_set
->AddColumn(views::GridLayout::FILL
,
678 views::GridLayout::FILL
,
680 views::GridLayout::USE_PREF
,
684 if (headline_text
.length() > 0) {
685 layout
->AddPaddingRow(1, kPermissionsSectionPaddingTop
);
686 layout
->StartRow(1, content_column
);
687 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
688 views::Label
* headline
= new views::Label(
689 headline_text
, rb
.GetFontList(ui::ResourceBundle::BoldFont
));
690 layout
->AddView(headline
, 1, 1, views::GridLayout::LEADING
,
691 views::GridLayout::CENTER
);
694 layout
->AddPaddingRow(1, kPermissionsSectionHeadlineMarginBottom
);
695 layout
->StartRow(1, content_column
);
696 layout
->AddView(content
, 1, 1, views::GridLayout::LEADING
,
697 views::GridLayout::CENTER
);
700 layout
->AddPaddingRow(1, 4);
701 layout
->StartRow(1, content_column
);
702 layout
->AddView(link
, 1, 1, views::GridLayout::LEADING
,
703 views::GridLayout::CENTER
);
706 layout
->AddPaddingRow(1, kPermissionsSectionPaddingBottom
);
710 void WebsiteSettingsPopupView::ResetConnectionSection(
711 views::View
* section_container
,
712 const gfx::Image
& icon
,
713 const base::string16
& headline
,
714 const base::string16
& text
,
716 views::LabelButton
* reset_decisions_button
) {
717 section_container
->RemoveAllChildViews(true);
719 views::GridLayout
* layout
= new views::GridLayout(section_container
);
720 section_container
->SetLayoutManager(layout
);
721 views::ColumnSet
* column_set
= layout
->AddColumnSet(0);
722 column_set
->AddPaddingColumn(0, kConnectionSectionPaddingLeft
);
723 column_set
->AddColumn(views::GridLayout::LEADING
,
724 views::GridLayout::LEADING
,
726 views::GridLayout::USE_PREF
,
729 column_set
->AddPaddingColumn(0, kIconMarginLeft
);
730 column_set
->AddColumn(views::GridLayout::FILL
,
731 views::GridLayout::FILL
,
733 views::GridLayout::USE_PREF
,
736 column_set
->AddPaddingColumn(0, kConnectionSectionPaddingRight
);
739 layout
->AddPaddingRow(0, kConnectionSectionPaddingTop
);
740 layout
->StartRow(1, 0);
743 views::ImageView
* icon_view
= new views::ImageView();
744 icon_view
->SetImage(*icon
.ToImageSkia());
745 layout
->AddView(icon_view
, 1, 1, views::GridLayout::LEADING
,
746 views::GridLayout::LEADING
);
748 // Add section content.
749 views::View
* content_pane
= new views::View();
750 views::GridLayout
* content_layout
= new views::GridLayout(content_pane
);
751 content_pane
->SetLayoutManager(content_layout
);
752 views::ColumnSet
* content_column_set
= content_layout
->AddColumnSet(0);
753 content_column_set
->AddColumn(views::GridLayout::LEADING
,
754 views::GridLayout::LEADING
,
756 views::GridLayout::USE_PREF
,
759 if (!headline
.empty()) {
760 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
761 views::Label
* headline_label
= new views::Label(
762 headline
, rb
.GetFontList(ui::ResourceBundle::BoldFont
));
763 headline_label
->SetMultiLine(true);
764 headline_label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
765 // Allow linebreaking in the middle of words if necessary, so that extremely
766 // long hostnames (longer than one line) will still be completely shown.
767 headline_label
->SetAllowCharacterBreak(true);
768 content_layout
->StartRow(1, 0);
769 content_layout
->AddView(headline_label
);
772 views::Label
* description_label
= new views::Label(text
);
773 description_label
->SetMultiLine(true);
774 description_label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
775 description_label
->SetAllowCharacterBreak(true);
776 content_layout
->StartRow(1, 0);
777 content_layout
->AddView(description_label
);
780 content_layout
->StartRow(1, 0);
781 content_layout
->AddView(link
);
784 if (reset_decisions_button
) {
785 content_layout
->StartRow(1, 0);
786 content_layout
->AddView(reset_decisions_button
);
789 layout
->AddView(content_pane
, 1, 1, views::GridLayout::LEADING
,
790 views::GridLayout::LEADING
);
791 layout
->AddPaddingRow(0, kConnectionSectionPaddingBottom
);
794 void WebsiteSettingsPopupView::HandleLinkClickedAsync(views::Link
* source
) {
795 if (source
== cookie_dialog_link_
) {
796 // Count how often the Collected Cookies dialog is opened.
797 presenter_
->RecordWebsiteSettingsAction(
798 WebsiteSettings::WEBSITE_SETTINGS_COOKIES_DIALOG_OPENED
);
800 if (web_contents_
!= NULL
)
801 new CollectedCookiesViews(web_contents_
);
802 } else if (source
== certificate_dialog_link_
) {
803 gfx::NativeWindow parent
= GetAnchorView() ?
804 GetAnchorView()->GetWidget()->GetNativeWindow() : nullptr;
805 presenter_
->RecordWebsiteSettingsAction(
806 WebsiteSettings::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED
);
807 ShowCertificateViewerByID(web_contents_
, parent
, cert_id_
);
808 } else if (source
== help_center_link_
) {
810 content::OpenURLParams(GURL(chrome::kPageInfoHelpCenterURL
),
813 ui::PAGE_TRANSITION_LINK
,
815 presenter_
->RecordWebsiteSettingsAction(
816 WebsiteSettings::WEBSITE_SETTINGS_CONNECTION_HELP_OPENED
);
817 } else if (source
== site_settings_link_
) {
818 // TODO(palmer): This opens the general Content Settings pane, which is OK
819 // for now. But on Android, it opens a page specific to a given origin that
820 // shows all of the settings for that origin. If/when that's available on
821 // desktop we should link to that here, too.
822 browser_
->OpenURL(content::OpenURLParams(
823 GURL(chrome::kChromeUIContentSettingsURL
), content::Referrer(),
824 NEW_FOREGROUND_TAB
, ui::PAGE_TRANSITION_LINK
, false));
825 presenter_
->RecordWebsiteSettingsAction(
826 WebsiteSettings::WEBSITE_SETTINGS_SITE_SETTINGS_OPENED
);