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