Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: chrome/browser/ui/views/website_settings/website_settings_popup_view.cc

Issue 2413773003: Material Page Info (Views, 3/3): Update site settings section. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/website_settings/website_settings_popup_view.h " 5 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h "
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/strings/string16.h"
15 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "chrome/browser/certificate_viewer.h" 18 #include "chrome/browser/certificate_viewer.h"
18 #include "chrome/browser/devtools/devtools_toggle_action.h" 19 #include "chrome/browser/devtools/devtools_toggle_action.h"
19 #include "chrome/browser/devtools/devtools_window.h" 20 #include "chrome/browser/devtools/devtools_window.h"
20 #include "chrome/browser/infobars/infobar_service.h" 21 #include "chrome/browser/infobars/infobar_service.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_dialogs.h" 24 #include "chrome/browser/ui/browser_dialogs.h"
24 #include "chrome/browser/ui/layout_constants.h" 25 #include "chrome/browser/ui/layout_constants.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 namespace { 66 namespace {
66 67
67 // NOTE(jdonnelly): This use of this process-wide variable assumes that there's 68 // NOTE(jdonnelly): This use of this process-wide variable assumes that there's
68 // never more than one website settings popup shown and that it's associated 69 // never more than one website settings popup shown and that it's associated
69 // with the current window. If this assumption fails in the future, we'll need 70 // with the current window. If this assumption fails in the future, we'll need
70 // to return a weak pointer from ShowPopup so callers can associate it with the 71 // to return a weak pointer from ShowPopup so callers can associate it with the
71 // current window (or other context) and check if the popup they care about is 72 // current window (or other context) and check if the popup they care about is
72 // showing. 73 // showing.
73 bool is_popup_showing = false; 74 bool is_popup_showing = false;
74 75
75 // Left icon margin. 76 // General constants -----------------------------------------------------------
76 const int kIconMarginLeft = 6; 77
78 // Popup width constraints.
79 const int kMinPopupWidth = 320;
80 const int kMaxPopupWidth = 1000;
81
82 // Margin and padding values shared by all sections.
83 const int kSectionPaddingHorizontal = 16;
84
85 // Padding for the bottom of the bubble.
86 const int kPopupMarginBottom = 16;
87
88 // Security Section (PopupHeaderView) ------------------------------------------
77 89
78 // Margin and padding values for the |PopupHeaderView|. 90 // Margin and padding values for the |PopupHeaderView|.
79 const int kHeaderMarginBottom = 10; 91 const int kHeaderMarginBottom = 10;
80 const int kHeaderPaddingBottom = 16; 92 const int kHeaderPaddingBottom = 16;
81 const int kHeaderPaddingLeft = 18;
82 const int kHeaderPaddingRightForText = kHeaderPaddingLeft;
83 const int kHeaderPaddingTop = 16; 93 const int kHeaderPaddingTop = 16;
84 const int kHeaderPaddingForCloseButton = 8; 94 const int kHeaderPaddingForCloseButton = 8;
85 95
86 // Spacing between labels in the header. 96 // Spacing between labels in the header.
87 const int kHeaderLabelSpacing = 4; 97 const int kHeaderLabelSpacing = 4;
88 98
89 // The max possible width of the popup. 99 // Site Settings Section -------------------------------------------------------
90 const int kMaxPopupWidth = 1000;
91 100
92 // The margins between the popup border and the popup content. 101 // Spacing above and below the cookies view.
93 const int kPopupMarginBottom = 14; 102 const int kCookiesViewVerticalPadding = 6;
94 103
95 // Padding values for sections on the site settings view. 104 // Spacing between a permission image and the text.
96 const int kSiteSettingsViewContentMinWidth = 300; 105 const int kPermissionImageSpacing = 6;
97 const int kSiteSettingsViewPaddingBottom = 6;
98 const int kSiteSettingsViewPaddingLeft = 18;
99 const int kSiteSettingsViewPaddingRight = 18;
100 const int kSiteSettingsViewPaddingTop = 4;
101 106
102 // Space between the headline and the content of a section. 107 // Spacing between rows in the site settings section
103 const int kSiteSettingsViewHeadlineMarginBottom = 10; 108 const int kPermissionsVerticalSpacing = 12;
104 // Spacing between rows in the "Permissions" and "Cookies and Site Data"
105 // sections.
106 const int kContentRowSpacing = 2;
107 109
108 const int kSiteDataIconColumnWidth = 20; 110 // Button IDs ------------------------------------------------------------------
109 111
110 const int BUTTON_RESET_CERTIFICATE_DECISIONS = 1337; 112 const int BUTTON_RESET_CERTIFICATE_DECISIONS = 1337;
113 const int BUTTON_SITE_SETTINGS = 1338;
111 114
112 } // namespace 115 } // namespace
113 116
114 // |PopupHeaderView| is the UI element (view) that represents the header of the 117 // |PopupHeaderView| is the UI element (view) that represents the header of the
115 // |WebsiteSettingsPopupView|. The header shows the status of the site's 118 // |WebsiteSettingsPopupView|. The header shows the status of the site's
116 // identity check and the name of the site's identity. 119 // identity check and the name of the site's identity.
117 class PopupHeaderView : public views::View { 120 class PopupHeaderView : public views::View {
118 public: 121 public:
119 explicit PopupHeaderView(views::ButtonListener* button_listener, 122 explicit PopupHeaderView(views::ButtonListener* button_listener,
120 views::StyledLabelListener* styled_label_listener); 123 views::StyledLabelListener* styled_label_listener);
121 ~PopupHeaderView() override; 124 ~PopupHeaderView() override;
122 125
123 // Sets the security summary for the current page. 126 // Sets the security summary for the current page.
124 void SetSummary(const base::string16& summary_text); 127 void SetSummary(const base::string16& summary_text);
125 128
126 // Sets the security details for the current page. 129 // Sets the security details for the current page.
127 void SetDetails(const base::string16& details_text, 130 void SetDetails(const base::string16& details_text,
128 bool include_details_link); 131 bool include_details_link);
129 132
130 int GetPreferredNameWidth() const;
131
132 void AddResetDecisionsLabel(); 133 void AddResetDecisionsLabel();
133 134
134 private: 135 private:
135 // The listener for the styled labels in this view. 136 // The listener for the styled labels in this view.
136 views::StyledLabelListener* styled_label_listener_; 137 views::StyledLabelListener* styled_label_listener_;
137 138
138 // The label that displays security summary for the current page. 139 // The label that displays security summary for the current page.
139 views::Label* summary_label_; 140 views::Label* summary_label_;
140 141
141 // The label that displays the status of the identity check for this site. 142 // The label that displays the status of the identity check for this site.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 : styled_label_listener_(styled_label_listener), 186 : styled_label_listener_(styled_label_listener),
186 summary_label_(nullptr), 187 summary_label_(nullptr),
187 details_label_(nullptr), 188 details_label_(nullptr),
188 reset_decisions_label_container_(nullptr), 189 reset_decisions_label_container_(nullptr),
189 reset_decisions_label_(nullptr) { 190 reset_decisions_label_(nullptr) {
190 views::GridLayout* layout = new views::GridLayout(this); 191 views::GridLayout* layout = new views::GridLayout(this);
191 SetLayoutManager(layout); 192 SetLayoutManager(layout);
192 193
193 const int label_column = 0; 194 const int label_column = 0;
194 views::ColumnSet* column_set = layout->AddColumnSet(label_column); 195 views::ColumnSet* column_set = layout->AddColumnSet(label_column);
195 column_set->AddPaddingColumn(0, kHeaderPaddingLeft); 196 column_set->AddPaddingColumn(0, kSectionPaddingHorizontal);
196 column_set->AddColumn(views::GridLayout::FILL, 197 column_set->AddColumn(views::GridLayout::FILL,
197 views::GridLayout::FILL, 198 views::GridLayout::FILL,
198 1, 199 1,
199 views::GridLayout::USE_PREF, 200 views::GridLayout::USE_PREF,
200 0, 201 0,
201 0); 202 0);
202 column_set->AddPaddingColumn(1, 0); 203 column_set->AddPaddingColumn(1, 0);
203 column_set->AddColumn(views::GridLayout::FILL, 204 column_set->AddColumn(views::GridLayout::FILL,
204 views::GridLayout::FILL, 205 views::GridLayout::FILL,
205 1, 206 1,
206 views::GridLayout::USE_PREF, 207 views::GridLayout::USE_PREF,
207 0, 208 0,
208 0); 209 0);
209 column_set->AddPaddingColumn(0, kHeaderPaddingForCloseButton); 210 column_set->AddPaddingColumn(0, kHeaderPaddingForCloseButton);
210 211
211 // First we add the padding needed for the close button. 212 // First we add the padding needed for the close button.
212 // In order to move down the summary, we simulate additional padding by giving 213 // In order to move down the summary, we simulate additional padding by giving
213 // it an empty border on top later on. 214 // it an empty border on top later on.
214 layout->AddPaddingRow(0, kHeaderPaddingForCloseButton); 215 layout->AddPaddingRow(0, kHeaderPaddingForCloseButton);
215 216
216 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 217 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
217 218
218 layout->StartRow(0, label_column); 219 layout->StartRow(0, label_column);
219 const gfx::FontList& font_list = rb.GetFontListWithDelta(1); 220 const gfx::FontList& font_list = rb.GetFontListWithDelta(1);
220 summary_label_ = new views::Label(base::string16(), font_list); 221 summary_label_ = new views::Label(base::string16(), font_list);
222 summary_label_->SetMultiLine(true);
221 summary_label_->SetBorder(views::Border::CreateEmptyBorder( 223 summary_label_->SetBorder(views::Border::CreateEmptyBorder(
222 kHeaderPaddingTop - kHeaderPaddingForCloseButton, 0, 0, 0)); 224 kHeaderPaddingTop - kHeaderPaddingForCloseButton, 0, 0, 0));
223 layout->AddView(summary_label_, 1, 1, views::GridLayout::LEADING, 225 layout->AddView(summary_label_, 1, 1, views::GridLayout::LEADING,
224 views::GridLayout::TRAILING); 226 views::GridLayout::TRAILING);
225 views::ImageButton* close_button = new views::ImageButton(button_listener); 227 views::ImageButton* close_button = new views::ImageButton(button_listener);
226 close_button->SetImage(views::CustomButton::STATE_NORMAL, 228 close_button->SetImage(views::CustomButton::STATE_NORMAL,
227 rb.GetImageNamed(IDR_CLOSE_2).ToImageSkia()); 229 rb.GetImageNamed(IDR_CLOSE_2).ToImageSkia());
228 close_button->SetImage(views::CustomButton::STATE_HOVERED, 230 close_button->SetImage(views::CustomButton::STATE_HOVERED,
229 rb.GetImageNamed(IDR_CLOSE_2_H).ToImageSkia()); 231 rb.GetImageNamed(IDR_CLOSE_2_H).ToImageSkia());
230 close_button->SetImage(views::CustomButton::STATE_PRESSED, 232 close_button->SetImage(views::CustomButton::STATE_PRESSED,
231 rb.GetImageNamed(IDR_CLOSE_2_P).ToImageSkia()); 233 rb.GetImageNamed(IDR_CLOSE_2_P).ToImageSkia());
232 layout->AddView(close_button, 1, 1, views::GridLayout::TRAILING, 234 layout->AddView(close_button, 1, 1, views::GridLayout::TRAILING,
233 views::GridLayout::LEADING); 235 views::GridLayout::LEADING);
234 236
235 layout->AddPaddingRow(0, kHeaderLabelSpacing); 237 layout->AddPaddingRow(0, kHeaderLabelSpacing);
236 238
237 const int label_column_status = 1; 239 const int label_column_status = 1;
238 views::ColumnSet* column_set_status = 240 views::ColumnSet* column_set_status =
239 layout->AddColumnSet(label_column_status); 241 layout->AddColumnSet(label_column_status);
240 column_set_status->AddPaddingColumn(0, kHeaderPaddingLeft); 242 column_set_status->AddPaddingColumn(0, kSectionPaddingHorizontal);
241 column_set_status->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 243 column_set_status->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
242 1, views::GridLayout::USE_PREF, 0, 0); 244 1, views::GridLayout::USE_PREF, 0, 0);
243 column_set_status->AddPaddingColumn(0, kHeaderPaddingRightForText); 245 column_set_status->AddPaddingColumn(0, kSectionPaddingHorizontal);
244 246
245 layout->AddPaddingRow(0, kHeaderLabelSpacing); 247 layout->AddPaddingRow(0, kHeaderLabelSpacing);
246 248
247 layout->StartRow(0, label_column_status); 249 layout->StartRow(0, label_column_status);
248 details_label_ = 250 details_label_ =
249 new views::StyledLabel(base::string16(), styled_label_listener); 251 new views::StyledLabel(base::string16(), styled_label_listener);
250 layout->AddView(details_label_, 1, 1, views::GridLayout::FILL, 252 layout->AddView(details_label_, 1, 1, views::GridLayout::FILL,
251 views::GridLayout::LEADING); 253 views::GridLayout::LEADING);
252 254
253 layout->StartRow(0, label_column_status); 255 layout->StartRow(0, label_column_status);
254 reset_decisions_label_container_ = new views::View(); 256 reset_decisions_label_container_ = new views::View();
255 reset_decisions_label_container_->SetLayoutManager( 257 reset_decisions_label_container_->SetLayoutManager(
256 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); 258 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
257 layout->AddView(reset_decisions_label_container_, 1, 1, 259 layout->AddView(reset_decisions_label_container_, 1, 1,
258 views::GridLayout::FILL, views::GridLayout::LEADING); 260 views::GridLayout::FILL, views::GridLayout::LEADING);
259 261
260 layout->AddPaddingRow(1, kHeaderPaddingBottom); 262 layout->AddPaddingRow(1, kHeaderPaddingBottom);
261 } 263 }
262 264
263 PopupHeaderView::~PopupHeaderView() {} 265 PopupHeaderView::~PopupHeaderView() {}
264 266
265 int PopupHeaderView::GetPreferredNameWidth() const {
266 return summary_label_->GetPreferredSize().width();
267 }
268
269 void PopupHeaderView::SetSummary(const base::string16& summary_text) { 267 void PopupHeaderView::SetSummary(const base::string16& summary_text) {
270 summary_label_->SetText(summary_text); 268 summary_label_->SetText(summary_text);
271 } 269 }
272 270
273 void PopupHeaderView::SetDetails(const base::string16& details_text, 271 void PopupHeaderView::SetDetails(const base::string16& details_text,
274 bool include_details_label_link) { 272 bool include_details_label_link) {
275 if (include_details_label_link) { 273 if (include_details_label_link) {
276 base::string16 details_link_text = 274 base::string16 details_link_text =
277 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_DETAILS_LINK); 275 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_DETAILS_LINK);
278 276
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 Profile* profile, 439 Profile* profile,
442 content::WebContents* web_contents, 440 content::WebContents* web_contents,
443 const GURL& url, 441 const GURL& url,
444 const security_state::SecurityStateModel::SecurityInfo& security_info) 442 const security_state::SecurityStateModel::SecurityInfo& security_info)
445 : content::WebContentsObserver(web_contents), 443 : content::WebContentsObserver(web_contents),
446 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), 444 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
447 profile_(profile), 445 profile_(profile),
448 header_(nullptr), 446 header_(nullptr),
449 separator_(nullptr), 447 separator_(nullptr),
450 site_settings_view_(nullptr), 448 site_settings_view_(nullptr),
451 site_data_content_(nullptr), 449 cookies_view_(nullptr),
452 cookie_dialog_link_(nullptr), 450 cookie_dialog_link_(nullptr),
453 permissions_content_(nullptr), 451 permissions_view_(nullptr),
454 site_settings_link_(nullptr),
455 weak_factory_(this) { 452 weak_factory_(this) {
456 set_parent_window(parent_window); 453 set_parent_window(parent_window);
457 454
458 is_devtools_disabled_ = 455 is_devtools_disabled_ =
459 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled); 456 profile->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled);
460 457
461 // Compensate for built-in vertical padding in the anchor view's image. 458 // Compensate for built-in vertical padding in the anchor view's image.
462 set_anchor_view_insets(gfx::Insets( 459 set_anchor_view_insets(gfx::Insets(
463 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); 460 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0));
464 461
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 GetWidget()->Close(); 500 GetWidget()->Close();
504 } 501 }
505 502
506 void WebsiteSettingsPopupView::WebContentsDestroyed() { 503 void WebsiteSettingsPopupView::WebContentsDestroyed() {
507 weak_factory_.InvalidateWeakPtrs(); 504 weak_factory_.InvalidateWeakPtrs();
508 } 505 }
509 506
510 void WebsiteSettingsPopupView::OnPermissionChanged( 507 void WebsiteSettingsPopupView::OnPermissionChanged(
511 const WebsiteSettingsUI::PermissionInfo& permission) { 508 const WebsiteSettingsUI::PermissionInfo& permission) {
512 presenter_->OnSitePermissionChanged(permission.type, permission.setting); 509 presenter_->OnSitePermissionChanged(permission.type, permission.setting);
510 // The menu buttons for the permissions might have longer strings now, so we
511 // need to size the whole bubble.
512 SizeToContents();
513 } 513 }
514 514
515 void WebsiteSettingsPopupView::OnChosenObjectDeleted( 515 void WebsiteSettingsPopupView::OnChosenObjectDeleted(
516 const WebsiteSettingsUI::ChosenObjectInfo& info) { 516 const WebsiteSettingsUI::ChosenObjectInfo& info) {
517 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object); 517 presenter_->OnSiteChosenObjectDeleted(info.ui_info, *info.object);
518 } 518 }
519 519
520 void WebsiteSettingsPopupView::OnWidgetDestroying(views::Widget* widget) { 520 void WebsiteSettingsPopupView::OnWidgetDestroying(views::Widget* widget) {
521 is_popup_showing = false; 521 is_popup_showing = false;
522 presenter_->OnUIClosing(); 522 presenter_->OnUIClosing();
523 } 523 }
524 524
525 int WebsiteSettingsPopupView::GetDialogButtons() const { 525 int WebsiteSettingsPopupView::GetDialogButtons() const {
526 return ui::DIALOG_BUTTON_NONE; 526 return ui::DIALOG_BUTTON_NONE;
527 } 527 }
528 528
529 void WebsiteSettingsPopupView::ButtonPressed(views::Button* button, 529 void WebsiteSettingsPopupView::ButtonPressed(views::Button* button,
530 const ui::Event& event) { 530 const ui::Event& event) {
531 if (button->id() == BUTTON_RESET_CERTIFICATE_DECISIONS) 531 switch (button->id()) {
532 presenter_->OnRevokeSSLErrorBypassButtonPressed(); 532 case BUTTON_RESET_CERTIFICATE_DECISIONS:
533 GetWidget()->Close(); 533 presenter_->OnRevokeSSLErrorBypassButtonPressed();
534 GetWidget()->Close();
535 break;
536 case BUTTON_SITE_SETTINGS:
537 // TODO(palmer): This opens the general Content Settings pane, which is OK
538 // for now. But on Android, it opens a page specific to a given origin
539 // that shows all of the settings for that origin. If/when that's
540 // available on desktop we should link to that here, too.
541 web_contents()->OpenURL(content::OpenURLParams(
542 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(),
543 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
544 false));
545 presenter_->RecordWebsiteSettingsAction(
546 WebsiteSettings::WEBSITE_SETTINGS_SITE_SETTINGS_OPENED);
547 break;
548 default:
549 NOTREACHED();
550 }
534 } 551 }
535 552
536 void WebsiteSettingsPopupView::LinkClicked(views::Link* source, 553 void WebsiteSettingsPopupView::LinkClicked(views::Link* source,
537 int event_flags) { 554 int event_flags) {
538 // The popup closes automatically when the collected cookies dialog or the 555 // The popup closes automatically when the collected cookies dialog or the
539 // certificate viewer opens. So delay handling of the link clicked to avoid 556 // certificate viewer opens. So delay handling of the link clicked to avoid
540 // a crash in the base class which needs to complete the mouse event handling. 557 // a crash in the base class which needs to complete the mouse event handling.
541 content::BrowserThread::PostTask( 558 content::BrowserThread::PostTask(
542 content::BrowserThread::UI, FROM_HERE, 559 content::BrowserThread::UI, FROM_HERE,
543 base::Bind(&WebsiteSettingsPopupView::HandleLinkClickedAsync, 560 base::Bind(&WebsiteSettingsPopupView::HandleLinkClickedAsync,
544 weak_factory_.GetWeakPtr(), source)); 561 weak_factory_.GetWeakPtr(), source));
545 } 562 }
546 563
547 gfx::Size WebsiteSettingsPopupView::GetPreferredSize() const { 564 gfx::Size WebsiteSettingsPopupView::GetPreferredSize() const {
548 if (header_ == nullptr && site_settings_view_ == nullptr) 565 if (header_ == nullptr && site_settings_view_ == nullptr)
549 return views::View::GetPreferredSize(); 566 return views::View::GetPreferredSize();
550 567
551 int height = 0; 568 int height = 0;
552 if (header_) 569 if (header_)
553 height += header_->GetPreferredSize().height() + kHeaderMarginBottom; 570 height += header_->GetPreferredSize().height() + kHeaderMarginBottom;
554 if (separator_) 571 if (separator_)
555 height += separator_->GetPreferredSize().height(); 572 height += separator_->GetPreferredSize().height();
556 573
557 if (site_settings_view_) 574 if (site_settings_view_)
558 height += site_settings_view_->GetPreferredSize().height(); 575 height += site_settings_view_->GetPreferredSize().height();
559 576
560 int width = kSiteSettingsViewContentMinWidth; 577 int width = kMinPopupWidth;
561 if (site_data_content_) 578 if (site_settings_view_)
562 width = std::max(width, site_data_content_->GetPreferredSize().width()); 579 width = std::max(width, site_settings_view_->GetPreferredSize().width());
563 if (permissions_content_)
564 width = std::max(width, permissions_content_->GetPreferredSize().width());
565 if (header_)
566 width = std::max(width, header_->GetPreferredNameWidth());
567 width += kSiteSettingsViewPaddingLeft + kSiteSettingsViewPaddingRight;
568 width = std::min(width, kMaxPopupWidth); 580 width = std::min(width, kMaxPopupWidth);
569 return gfx::Size(width, height); 581 return gfx::Size(width, height);
570 } 582 }
571 583
572 void WebsiteSettingsPopupView::SetCookieInfo( 584 void WebsiteSettingsPopupView::SetCookieInfo(
573 const CookieInfoList& cookie_info_list) { 585 const CookieInfoList& cookie_info_list) {
574 // |cookie_info_list| should only ever have 2 items: first- and third-party 586 // |cookie_info_list| should only ever have 2 items: first- and third-party
575 // cookies. 587 // cookies.
576 DCHECK_EQ(cookie_info_list.size(), 2u); 588 DCHECK_EQ(cookie_info_list.size(), 2u);
577 base::string16 first_party_label_text; 589 int total_allowed = 0;
578 base::string16 third_party_label_text; 590 for (const auto& i : cookie_info_list)
579 for (const auto& i : cookie_info_list) { 591 total_allowed += i.allowed;
580 if (i.is_first_party) { 592 base::string16 label_text = l10n_util::GetPluralStringFUTF16(
581 first_party_label_text = l10n_util::GetPluralStringFUTF16( 593 IDS_WEBSITE_SETTINGS_NUM_COOKIES, total_allowed);
582 IDS_WEBSITE_SETTINGS_FIRST_PARTY_SITE_DATA, i.allowed);
583 } else {
584 third_party_label_text = l10n_util::GetPluralStringFUTF16(
585 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA, i.allowed);
586 }
587 }
588 594
589 if (!cookie_dialog_link_) { 595 if (!cookie_dialog_link_) {
590 cookie_dialog_link_ = new views::Link(first_party_label_text); 596 cookie_dialog_link_ = new views::Link(label_text);
591 cookie_dialog_link_->set_listener(this); 597 cookie_dialog_link_->set_listener(this);
592 } else { 598 } else {
593 cookie_dialog_link_->SetText(first_party_label_text); 599 cookie_dialog_link_->SetText(label_text);
594 } 600 }
595 601
596 views::GridLayout* layout = 602 views::GridLayout* layout =
597 static_cast<views::GridLayout*>(site_data_content_->GetLayoutManager()); 603 static_cast<views::GridLayout*>(cookies_view_->GetLayoutManager());
598 if (!layout) { 604 if (!layout) {
599 layout = new views::GridLayout(site_data_content_); 605 layout = new views::GridLayout(cookies_view_);
600 site_data_content_->SetLayoutManager(layout); 606 cookies_view_->SetLayoutManager(layout);
601 607
602 const int site_data_content_column = 0; 608 const int cookies_view_column = 0;
603 views::ColumnSet* column_set = 609 views::ColumnSet* column_set = layout->AddColumnSet(cookies_view_column);
604 layout->AddColumnSet(site_data_content_column); 610 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
605 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 611 views::GridLayout::FIXED, kPermissionIconColumnWidth,
606 views::GridLayout::FIXED, kSiteDataIconColumnWidth,
607 0); 612 0);
608 column_set->AddPaddingColumn(0, kIconMarginLeft); 613 column_set->AddPaddingColumn(0, kPermissionImageSpacing);
609 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 614 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
610 views::GridLayout::USE_PREF, 0, 0); 615 0, views::GridLayout::USE_PREF, 0, 0);
611 // No padding. This third column is for |third_party_label_text| (see
612 // below),
613 // and the text needs to flow naturally from the |first_party_label_text|
614 // link.
615 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
616 views::GridLayout::USE_PREF, 0, 0);
617 616
618 layout->AddPaddingRow(1, 5); 617 layout->AddPaddingRow(0, kCookiesViewVerticalPadding);
619 618
620 layout->StartRow(1, site_data_content_column); 619 layout->StartRow(1, cookies_view_column);
621 WebsiteSettingsUI::PermissionInfo info; 620 WebsiteSettingsUI::PermissionInfo info;
622 info.type = CONTENT_SETTINGS_TYPE_COOKIES; 621 info.type = CONTENT_SETTINGS_TYPE_COOKIES;
623 info.setting = CONTENT_SETTING_ALLOW; 622 info.setting = CONTENT_SETTING_ALLOW;
624 info.is_incognito = 623 info.is_incognito =
625 Profile::FromBrowserContext(web_contents()->GetBrowserContext()) 624 Profile::FromBrowserContext(web_contents()->GetBrowserContext())
626 ->IsOffTheRecord(); 625 ->IsOffTheRecord();
627 views::ImageView* icon = new views::ImageView(); 626 views::ImageView* icon = new views::ImageView();
628 const gfx::Image& image = WebsiteSettingsUI::GetPermissionIcon(info); 627 const gfx::Image& image = WebsiteSettingsUI::GetPermissionIcon(info);
629 icon->SetImage(image.ToImageSkia()); 628 icon->SetImage(image.ToImageSkia());
630 layout->AddView(icon, 1, 1, views::GridLayout::CENTER, 629 layout->AddView(
631 views::GridLayout::CENTER); 630 icon, 1, 2, views::GridLayout::FILL,
632 layout->AddView(cookie_dialog_link_, 1, 1, views::GridLayout::CENTER, 631 // TODO: The vertical alignment may change to CENTER once Harmony is
633 views::GridLayout::CENTER); 632 // implemented. See https://crbug.com/512442#c48
634 base::string16 comma = base::ASCIIToUTF16(", "); 633 views::GridLayout::LEADING);
635 634
636 layout->AddView(new views::Label(comma + third_party_label_text), 1, 1, 635 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
637 views::GridLayout::LEADING, views::GridLayout::CENTER); 636 const gfx::FontList& font_list = rb.GetFontListWithDelta(1);
637 views::Label* cookies_label = new views::Label(
638 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA),
639 font_list);
640 layout->AddView(cookies_label);
641 layout->StartRow(1, cookies_view_column);
642 layout->SkipColumns(1);
638 643
639 layout->AddPaddingRow(1, 6); 644 layout->AddView(cookie_dialog_link_);
645
646 layout->AddPaddingRow(0, kCookiesViewVerticalPadding);
640 } 647 }
641 648
642 layout->Layout(site_data_content_); 649 layout->Layout(cookies_view_);
643 SizeToContents(); 650 SizeToContents();
644 } 651 }
645 652
646 void WebsiteSettingsPopupView::SetPermissionInfo( 653 void WebsiteSettingsPopupView::SetPermissionInfo(
647 const PermissionInfoList& permission_info_list, 654 const PermissionInfoList& permission_info_list,
648 const ChosenObjectInfoList& chosen_object_info_list) { 655 const ChosenObjectInfoList& chosen_object_info_list) {
649 // When a permission is changed, WebsiteSettings::OnSitePermissionChanged() 656 // When a permission is changed, WebsiteSettings::OnSitePermissionChanged()
650 // calls this method with updated permissions. However, PermissionSelectorRow 657 // calls this method with updated permissions. However, PermissionSelectorRow
651 // will have already updated its state, so it's already reflected in the UI. 658 // will have already updated its state, so it's already reflected in the UI.
652 // In addition, if a permission is set to the default setting, WebsiteSettings 659 // In addition, if a permission is set to the default setting, WebsiteSettings
653 // removes it from |permission_info_list|, but the button should remain. 660 // removes it from |permission_info_list|, but the button should remain.
654 if (permissions_content_) { 661 if (permissions_view_) {
655 base::STLDeleteContainerPointers(chosen_object_info_list.begin(), 662 base::STLDeleteContainerPointers(chosen_object_info_list.begin(),
656 chosen_object_info_list.end()); 663 chosen_object_info_list.end());
657 return; 664 return;
658 } 665 }
659 666
660 permissions_content_ = new views::View(); 667 permissions_view_ = new views::View();
661 views::GridLayout* layout = new views::GridLayout(permissions_content_); 668 views::GridLayout* layout = new views::GridLayout(permissions_view_);
662 permissions_content_->SetLayoutManager(layout); 669 permissions_view_->SetLayoutManager(layout);
663 670
664 base::string16 headline = 671 site_settings_view_->AddChildView(permissions_view_);
665 permission_info_list.empty()
666 ? base::string16()
667 : l10n_util::GetStringUTF16(
668 IDS_WEBSITE_SETTINGS_TITLE_SITE_PERMISSIONS);
669 views::View* permissions_section =
670 CreateSection(headline, permissions_content_, nullptr);
671 site_settings_view_->AddChildView(permissions_section);
672 672
673 const int content_column = 0; 673 const int content_column = 0;
674 views::ColumnSet* column_set = layout->AddColumnSet(content_column); 674 views::ColumnSet* column_set = layout->AddColumnSet(content_column);
675 column_set->AddColumn(views::GridLayout::FILL, 675 column_set->AddColumn(views::GridLayout::FILL,
676 views::GridLayout::FILL, 676 views::GridLayout::FILL,
677 1, 677 1,
678 views::GridLayout::USE_PREF, 678 views::GridLayout::USE_PREF,
679 0, 679 0,
680 0); 680 0);
681 for (const auto& permission : permission_info_list) { 681 for (const auto& permission : permission_info_list) {
682 layout->StartRow(1, content_column); 682 layout->StartRow(1, content_column);
683 PermissionSelectorRow* selector = new PermissionSelectorRow( 683 PermissionSelectorRow* selector = new PermissionSelectorRow(
684 profile_, 684 profile_,
685 web_contents() ? web_contents()->GetVisibleURL() : GURL::EmptyGURL(), 685 web_contents() ? web_contents()->GetVisibleURL() : GURL::EmptyGURL(),
686 permission); 686 permission);
687 selector->AddObserver(this); 687 selector->AddObserver(this);
688 layout->AddView(selector, 688 layout->AddView(selector, 1, 1, views::GridLayout::FILL,
689 1,
690 1,
691 views::GridLayout::LEADING,
692 views::GridLayout::CENTER); 689 views::GridLayout::CENTER);
693 layout->AddPaddingRow(1, kContentRowSpacing); 690 layout->AddPaddingRow(1, kPermissionsVerticalSpacing);
694 } 691 }
695 692
696 for (auto* object : chosen_object_info_list) { 693 for (auto* object : chosen_object_info_list) {
697 layout->StartRow(1, content_column); 694 layout->StartRow(1, content_column);
698 // The view takes ownership of the object info. 695 // The view takes ownership of the object info.
699 auto* object_view = new ChosenObjectRow(base::WrapUnique(object)); 696 auto* object_view = new ChosenObjectRow(base::WrapUnique(object));
700 object_view->AddObserver(this); 697 object_view->AddObserver(this);
701 layout->AddView(object_view, 1, 1, views::GridLayout::LEADING, 698 layout->AddView(object_view, 1, 1, views::GridLayout::LEADING,
702 views::GridLayout::CENTER); 699 views::GridLayout::CENTER);
703 layout->AddPaddingRow(1, kContentRowSpacing); 700 layout->AddPaddingRow(1, kPermissionsVerticalSpacing);
704 } 701 }
705 702
706 layout->Layout(permissions_content_); 703 layout->Layout(permissions_view_);
707 704
708 // Add site settings link. 705 // Add site settings link.
709 site_settings_link_ = new views::Link( 706 views::Link* site_settings_link = new views::Link(
710 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_SETTINGS_LINK)); 707 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_SETTINGS_LINK));
711 site_settings_link_->set_listener(this); 708 site_settings_link->set_listener(this);
712 views::View* link_section = new views::View(); 709 views::View* link_section = new views::View();
713 const int kLinkMarginTop = 4; 710 const int kLinkMarginTop = 4;
714 link_section->SetLayoutManager( 711 link_section->SetLayoutManager(new views::BoxLayout(
715 new views::BoxLayout(views::BoxLayout::kHorizontal, 712 views::BoxLayout::kHorizontal, 0, kLinkMarginTop, 0));
716 kSiteSettingsViewPaddingLeft, kLinkMarginTop, 0)); 713 link_section->AddChildView(site_settings_link);
717 link_section->AddChildView(site_settings_link_);
718 site_settings_view_->AddChildView(link_section); 714 site_settings_view_->AddChildView(link_section);
719 715
720 SizeToContents(); 716 SizeToContents();
721 } 717 }
722 718
723 void WebsiteSettingsPopupView::SetIdentityInfo( 719 void WebsiteSettingsPopupView::SetIdentityInfo(
724 const IdentityInfo& identity_info) { 720 const IdentityInfo& identity_info) {
725 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description = 721 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description =
726 identity_info.GetSecurityDescription(); 722 identity_info.GetSecurityDescription();
727 723
(...skipping 12 matching lines...) Expand all
740 736
741 Layout(); 737 Layout();
742 SizeToContents(); 738 SizeToContents();
743 } 739 }
744 740
745 void WebsiteSettingsPopupView::SetSelectedTab(TabId tab_id) { 741 void WebsiteSettingsPopupView::SetSelectedTab(TabId tab_id) {
746 // TODO(lgarron): Remove this method. (https://crbug.com/571533) 742 // TODO(lgarron): Remove this method. (https://crbug.com/571533)
747 } 743 }
748 744
749 views::View* WebsiteSettingsPopupView::CreateSiteSettingsView() { 745 views::View* WebsiteSettingsPopupView::CreateSiteSettingsView() {
750 views::View* pane = new views::View(); 746 views::View* site_settings_view = new views::View();
751 pane->SetLayoutManager( 747 views::BoxLayout* box_layout =
752 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 1)); 748 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
749 site_settings_view->SetLayoutManager(box_layout);
750 box_layout->set_cross_axis_alignment(
751 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
752 box_layout->set_inside_border_insets(
753 gfx::Insets(0, kSectionPaddingHorizontal));
753 754
754 // Add cookies and site data section. 755 // Add cookies view.
755 site_data_content_ = new views::View(); 756 cookies_view_ = new views::View();
756 views::View* site_data_section = CreateSection( 757 site_settings_view->AddChildView(cookies_view_);
757 l10n_util::GetStringUTF16(IDS_WEBSITE_SETTINGS_TITLE_SITE_DATA),
758 site_data_content_, nullptr);
759 pane->AddChildView(site_data_section);
760 758
761 return pane; 759 return site_settings_view;
762 } 760 }
763 views::View* WebsiteSettingsPopupView::CreateSection(
764 const base::string16& headline_text,
765 views::View* content,
766 views::Link* link) {
767 views::View* container = new views::View();
768 views::GridLayout* layout = new views::GridLayout(container);
769 container->SetLayoutManager(layout);
770 const int content_column = 0;
771 views::ColumnSet* column_set = layout->AddColumnSet(content_column);
772 column_set->AddPaddingColumn(0, kSiteSettingsViewPaddingLeft);
773 column_set->AddColumn(views::GridLayout::FILL,
774 views::GridLayout::FILL,
775 1,
776 views::GridLayout::USE_PREF,
777 0,
778 0);
779
780 if (headline_text.length() > 0) {
781 layout->AddPaddingRow(1, kSiteSettingsViewPaddingTop);
782 layout->StartRow(1, content_column);
783 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
784 views::Label* headline = new views::Label(
785 headline_text, rb.GetFontList(ui::ResourceBundle::BoldFont));
786 layout->AddView(headline, 1, 1, views::GridLayout::LEADING,
787 views::GridLayout::CENTER);
788 }
789
790 layout->AddPaddingRow(1, kSiteSettingsViewHeadlineMarginBottom);
791 layout->StartRow(1, content_column);
792 layout->AddView(content, 1, 1, views::GridLayout::LEADING,
793 views::GridLayout::CENTER);
794
795 if (link) {
796 layout->AddPaddingRow(1, 4);
797 layout->StartRow(1, content_column);
798 layout->AddView(link, 1, 1, views::GridLayout::LEADING,
799 views::GridLayout::CENTER);
800 }
801
802 layout->AddPaddingRow(1, kSiteSettingsViewPaddingBottom);
803 return container;
804 }
805
806 761
807 void WebsiteSettingsPopupView::HandleLinkClickedAsync(views::Link* source) { 762 void WebsiteSettingsPopupView::HandleLinkClickedAsync(views::Link* source) {
808 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed()) 763 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed())
809 return; 764 return;
810 765 DCHECK_EQ(source, cookie_dialog_link_);
811 if (source == cookie_dialog_link_) { 766 // Count how often the Collected Cookies dialog is opened.
812 // Count how often the Collected Cookies dialog is opened. 767 presenter_->RecordWebsiteSettingsAction(
813 presenter_->RecordWebsiteSettingsAction( 768 WebsiteSettings::WEBSITE_SETTINGS_COOKIES_DIALOG_OPENED);
814 WebsiteSettings::WEBSITE_SETTINGS_COOKIES_DIALOG_OPENED); 769 new CollectedCookiesViews(web_contents());
815
816 new CollectedCookiesViews(web_contents());
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 web_contents()->OpenURL(content::OpenURLParams(
823 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(),
824 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK,
825 false));
826 presenter_->RecordWebsiteSettingsAction(
827 WebsiteSettings::WEBSITE_SETTINGS_SITE_SETTINGS_OPENED);
828 } else {
829 NOTREACHED();
830 }
831 } 770 }
832 771
833 void WebsiteSettingsPopupView::StyledLabelLinkClicked(views::StyledLabel* label, 772 void WebsiteSettingsPopupView::StyledLabelLinkClicked(views::StyledLabel* label,
834 const gfx::Range& range, 773 const gfx::Range& range,
835 int event_flags) { 774 int event_flags) {
836 presenter_->RecordWebsiteSettingsAction( 775 presenter_->RecordWebsiteSettingsAction(
837 WebsiteSettings::WEBSITE_SETTINGS_SECURITY_DETAILS_OPENED); 776 WebsiteSettings::WEBSITE_SETTINGS_SECURITY_DETAILS_OPENED);
838 777
839 if (is_devtools_disabled_) { 778 if (is_devtools_disabled_) {
840 DCHECK(certificate_); 779 DCHECK(certificate_);
841 gfx::NativeWindow parent = 780 gfx::NativeWindow parent =
842 anchor_widget() ? anchor_widget()->GetNativeWindow() : nullptr; 781 anchor_widget() ? anchor_widget()->GetNativeWindow() : nullptr;
843 presenter_->RecordWebsiteSettingsAction( 782 presenter_->RecordWebsiteSettingsAction(
844 WebsiteSettings::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED); 783 WebsiteSettings::WEBSITE_SETTINGS_CERTIFICATE_DIALOG_OPENED);
845 ShowCertificateViewer(web_contents(), parent, certificate_.get()); 784 ShowCertificateViewer(web_contents(), parent, certificate_.get());
846 } else { 785 } else {
847 DevToolsWindow::OpenDevToolsWindow( 786 DevToolsWindow::OpenDevToolsWindow(
848 web_contents(), DevToolsToggleAction::ShowSecurityPanel()); 787 web_contents(), DevToolsToggleAction::ShowSecurityPanel());
849 } 788 }
850 } 789 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698