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