Chromium Code Reviews| 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> |
| 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/string16.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/sys_string_conversions.h" | |
|
msw
2017/02/24 18:42:49
Is this used?
lgarron
2017/02/28 03:21:01
No, certainly not in the current patch anymore. Re
| |
| 17 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 18 #include "chrome/browser/certificate_viewer.h" | 19 #include "chrome/browser/certificate_viewer.h" |
| 19 #include "chrome/browser/infobars/infobar_service.h" | 20 #include "chrome/browser/infobars/infobar_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_dialogs.h" | 23 #include "chrome/browser/ui/browser_dialogs.h" |
| 23 #include "chrome/browser/ui/layout_constants.h" | 24 #include "chrome/browser/ui/layout_constants.h" |
| 24 #include "chrome/browser/ui/views/collected_cookies_views.h" | 25 #include "chrome/browser/ui/views/collected_cookies_views.h" |
| 25 #include "chrome/browser/ui/views/website_settings/chosen_object_row.h" | 26 #include "chrome/browser/ui/views/website_settings/chosen_object_row.h" |
| 26 #include "chrome/browser/ui/views/website_settings/non_accessible_image_view.h" | 27 #include "chrome/browser/ui/views/website_settings/non_accessible_image_view.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 | 98 |
| 98 // Spacing between rows in the site settings section | 99 // Spacing between rows in the site settings section |
| 99 const int kPermissionsVerticalSpacing = 12; | 100 const int kPermissionsVerticalSpacing = 12; |
| 100 | 101 |
| 101 // Button/styled label/link IDs ------------------------------------------------ | 102 // Button/styled label/link IDs ------------------------------------------------ |
| 102 const int BUTTON_CLOSE = 1337; | 103 const int BUTTON_CLOSE = 1337; |
| 103 const int STYLED_LABEL_SECURITY_DETAILS = 1338; | 104 const int STYLED_LABEL_SECURITY_DETAILS = 1338; |
| 104 const int STYLED_LABEL_RESET_CERTIFICATE_DECISIONS = 1339; | 105 const int STYLED_LABEL_RESET_CERTIFICATE_DECISIONS = 1339; |
| 105 const int LINK_COOKIE_DIALOG = 1340; | 106 const int LINK_COOKIE_DIALOG = 1340; |
| 106 const int LINK_SITE_SETTINGS = 1341; | 107 const int LINK_SITE_SETTINGS = 1341; |
| 108 const int LINK_SHOW_ALL_PERMISSIONS = 1342; | |
|
msw
2017/02/24 18:42:49
optional nit: constexpr here and for others above
lgarron
2017/02/28 03:21:01
I would prefer to avoid growing it in this CL, but
| |
| 107 | 109 |
| 108 // The default, ui::kTitleFontSizeDelta, is too large for the website settings | 110 // The default, ui::kTitleFontSizeDelta, is too large for the website settings |
| 109 // bubble (e.g. +3). Use +1 to obtain a smaller font. | 111 // bubble (e.g. +3). Use +1 to obtain a smaller font. |
| 110 constexpr int kSummaryFontSizeDelta = 1; | 112 constexpr int kSummaryFontSizeDelta = 1; |
| 111 | 113 |
| 112 // Adds a ColumnSet on |layout| with a single View column and padding columns | 114 // Adds a ColumnSet on |layout| with a single View column and padding columns |
| 113 // on either side of it with |margin| width. | 115 // on either side of it with |margin| width. |
| 114 void AddColumnWithSideMargin(views::GridLayout* layout, int margin, int id) { | 116 void AddColumnWithSideMargin(views::GridLayout* layout, int margin, int id) { |
| 115 views::ColumnSet* column_set = layout->AddColumnSet(id); | 117 views::ColumnSet* column_set = layout->AddColumnSet(id); |
| 116 column_set->AddPaddingColumn(0, margin); | 118 column_set->AddPaddingColumn(0, margin); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 const security_state::SecurityInfo& security_info) | 397 const security_state::SecurityInfo& security_info) |
| 396 : content::WebContentsObserver(web_contents), | 398 : content::WebContentsObserver(web_contents), |
| 397 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), | 399 BubbleDialogDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), |
| 398 profile_(profile), | 400 profile_(profile), |
| 399 header_(nullptr), | 401 header_(nullptr), |
| 400 separator_(nullptr), | 402 separator_(nullptr), |
| 401 site_settings_view_(nullptr), | 403 site_settings_view_(nullptr), |
| 402 cookies_view_(nullptr), | 404 cookies_view_(nullptr), |
| 403 cookie_dialog_link_(nullptr), | 405 cookie_dialog_link_(nullptr), |
| 404 permissions_view_(nullptr), | 406 permissions_view_(nullptr), |
| 407 permission_link_(nullptr), | |
| 405 weak_factory_(this) { | 408 weak_factory_(this) { |
| 406 g_shown_popup_type = POPUP_WEBSITE_SETTINGS; | 409 g_shown_popup_type = POPUP_WEBSITE_SETTINGS; |
| 407 set_parent_window(parent_window); | 410 set_parent_window(parent_window); |
| 408 | 411 |
| 409 // Compensate for built-in vertical padding in the anchor view's image. | 412 // Compensate for built-in vertical padding in the anchor view's image. |
| 410 set_anchor_view_insets(gfx::Insets( | 413 set_anchor_view_insets(gfx::Insets( |
| 411 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); | 414 GetLayoutConstant(LOCATION_BAR_BUBBLE_ANCHOR_VERTICAL_INSET), 0)); |
| 412 | 415 |
| 413 // Capture the default bubble margin, and move it to the Layout classes. This | 416 // Capture the default bubble margin, and move it to the Layout classes. This |
| 414 // is necessary so that the views::Separator can extend the full width of the | 417 // is necessary so that the views::Separator can extend the full width of the |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 layout->AddPaddingRow(0, kCookiesViewVerticalPadding); | 612 layout->AddPaddingRow(0, kCookiesViewVerticalPadding); |
| 610 } | 613 } |
| 611 | 614 |
| 612 layout->Layout(cookies_view_); | 615 layout->Layout(cookies_view_); |
| 613 SizeToContents(); | 616 SizeToContents(); |
| 614 } | 617 } |
| 615 | 618 |
| 616 void WebsiteSettingsPopupView::SetPermissionInfo( | 619 void WebsiteSettingsPopupView::SetPermissionInfo( |
| 617 const PermissionInfoList& permission_info_list, | 620 const PermissionInfoList& permission_info_list, |
| 618 ChosenObjectInfoList chosen_object_info_list) { | 621 ChosenObjectInfoList chosen_object_info_list) { |
| 619 // When a permission is changed, WebsiteSettings::OnSitePermissionChanged() | 622 // Clear all children, since it's not straightforward to intersperse new ones |
|
msw
2017/02/24 18:42:49
nit: simplify (or remove) this comment: "Recreate
lgarron
2017/02/28 03:21:01
Sure. I've taken your comment.
| |
| 620 // calls this method with updated permissions. However, PermissionSelectorRow | 623 // between existing ones. |
| 621 // will have already updated its state, so it's already reflected in the UI. | 624 permissions_view_->RemoveAllChildViews(true); |
|
msw
2017/02/24 18:42:49
Does this cause any flickering when permissions ch
lgarron
2017/02/28 03:21:01
No. At least not on Mac, and also not the one time
| |
| 622 // In addition, if a permission is set to the default setting, WebsiteSettings | |
| 623 // removes it from |permission_info_list|, but the button should remain. | |
| 624 if (permissions_view_) | |
| 625 return; | |
| 626 | 625 |
| 627 permissions_view_ = new views::View(); | |
| 628 views::GridLayout* layout = new views::GridLayout(permissions_view_); | 626 views::GridLayout* layout = new views::GridLayout(permissions_view_); |
| 629 permissions_view_->SetLayoutManager(layout); | 627 permissions_view_->SetLayoutManager(layout); |
| 630 | 628 |
| 631 site_settings_view_->AddChildView(permissions_view_); | |
| 632 | |
| 633 const int content_column = 0; | 629 const int content_column = 0; |
| 634 views::ColumnSet* column_set = layout->AddColumnSet(content_column); | 630 views::ColumnSet* column_set = layout->AddColumnSet(content_column); |
| 635 column_set->AddColumn(views::GridLayout::FILL, | 631 column_set->AddColumn(views::GridLayout::FILL, |
| 636 views::GridLayout::FILL, | 632 views::GridLayout::FILL, |
| 637 1, | 633 1, |
| 638 views::GridLayout::USE_PREF, | 634 views::GridLayout::USE_PREF, |
| 639 0, | 635 0, |
| 640 0); | 636 0); |
| 641 for (const auto& permission : permission_info_list) { | 637 for (const auto& permission : permission_info_list) { |
| 642 layout->StartRow(1, content_column); | 638 layout->StartRow(1, content_column); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 654 layout->StartRow(1, content_column); | 650 layout->StartRow(1, content_column); |
| 655 // The view takes ownership of the object info. | 651 // The view takes ownership of the object info. |
| 656 auto* object_view = new ChosenObjectRow(std::move(object)); | 652 auto* object_view = new ChosenObjectRow(std::move(object)); |
| 657 object_view->AddObserver(this); | 653 object_view->AddObserver(this); |
| 658 layout->AddView(object_view, 1, 1, views::GridLayout::LEADING, | 654 layout->AddView(object_view, 1, 1, views::GridLayout::LEADING, |
| 659 views::GridLayout::CENTER); | 655 views::GridLayout::CENTER); |
| 660 layout->AddPaddingRow(1, kPermissionsVerticalSpacing); | 656 layout->AddPaddingRow(1, kPermissionsVerticalSpacing); |
| 661 } | 657 } |
| 662 | 658 |
| 663 layout->Layout(permissions_view_); | 659 layout->Layout(permissions_view_); |
| 664 | |
| 665 // Add site settings link. | |
| 666 views::Link* site_settings_link = new views::Link( | |
| 667 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SITE_SETTINGS_LINK)); | |
| 668 site_settings_link->set_id(LINK_SITE_SETTINGS); | |
| 669 site_settings_link->set_listener(this); | |
| 670 views::View* link_section = new views::View(); | |
| 671 const int kLinkMarginTop = 4; | |
| 672 link_section->SetLayoutManager(new views::BoxLayout( | |
| 673 views::BoxLayout::kHorizontal, 0, kLinkMarginTop, 0)); | |
| 674 link_section->AddChildView(site_settings_link); | |
| 675 site_settings_view_->AddChildView(link_section); | |
| 676 | |
| 677 SizeToContents(); | 660 SizeToContents(); |
| 678 } | 661 } |
| 679 | 662 |
| 680 void WebsiteSettingsPopupView::UpdatePermissionButton( | 663 void WebsiteSettingsPopupView::UpdatePermissionButton( |
| 681 WebsiteSettingsUI::VisiblePermissions visible_permissions) { | 664 WebsiteSettingsUI::VisiblePermissions visible_permissions) { |
| 682 // TODO(crbug.com/657267) | 665 permission_link_->SetText(GetPermissionButtonString(visible_permissions)); |
| 666 if (visible_permissions == WebsiteSettingsUI::VISIBLE_PERMISSIONS_ALL) { | |
|
msw
2017/02/24 18:42:49
nit: curlies not needed (or use a ternary)
| |
| 667 permission_link_->set_id(LINK_SITE_SETTINGS); | |
| 668 } else { | |
| 669 permission_link_->set_id(LINK_SHOW_ALL_PERMISSIONS); | |
| 670 } | |
| 671 SizeToContents(); | |
| 683 } | 672 } |
| 684 | 673 |
| 685 void WebsiteSettingsPopupView::SetIdentityInfo( | 674 void WebsiteSettingsPopupView::SetIdentityInfo( |
| 686 const IdentityInfo& identity_info) { | 675 const IdentityInfo& identity_info) { |
| 687 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description = | 676 std::unique_ptr<WebsiteSettingsUI::SecurityDescription> security_description = |
| 688 identity_info.GetSecurityDescription(); | 677 identity_info.GetSecurityDescription(); |
| 689 | 678 |
| 690 summary_text_ = security_description->summary; | 679 summary_text_ = security_description->summary; |
| 691 GetWidget()->UpdateWindowTitle(); | 680 GetWidget()->UpdateWindowTitle(); |
| 692 | 681 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 708 views::BoxLayout* box_layout = | 697 views::BoxLayout* box_layout = |
| 709 new views::BoxLayout(views::BoxLayout::kVertical, side_margin, 0, 0); | 698 new views::BoxLayout(views::BoxLayout::kVertical, side_margin, 0, 0); |
| 710 site_settings_view->SetLayoutManager(box_layout); | 699 site_settings_view->SetLayoutManager(box_layout); |
| 711 box_layout->set_cross_axis_alignment( | 700 box_layout->set_cross_axis_alignment( |
| 712 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); | 701 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); |
| 713 | 702 |
| 714 // Add cookies view. | 703 // Add cookies view. |
| 715 cookies_view_ = new views::View(); | 704 cookies_view_ = new views::View(); |
| 716 site_settings_view->AddChildView(cookies_view_); | 705 site_settings_view->AddChildView(cookies_view_); |
| 717 | 706 |
| 707 permissions_view_ = new views::View(); | |
| 708 site_settings_view->AddChildView(permissions_view_); | |
| 709 | |
| 710 // Create permission link with wrapper, and keep a member reference to the | |
| 711 // link itself so we can change the title/behaviour later. | |
| 712 permission_link_ = new views::Link(base::string16()); | |
|
msw
2017/02/24 18:42:49
It would be nice if this class initialized the lin
lgarron
2017/02/28 03:21:01
Sure.
I've set and initial ID of LINK_SITE_SETTIN
| |
| 713 permission_link_->set_listener(this); | |
| 714 const int kLinkMarginTop = 4; | |
| 715 views::View* permission_link_wrapper = new views::View(); | |
| 716 permission_link_wrapper->SetLayoutManager(new views::BoxLayout( | |
| 717 views::BoxLayout::kHorizontal, 0, kLinkMarginTop, 0)); | |
| 718 permission_link_wrapper->AddChildView(permission_link_); | |
| 719 site_settings_view->AddChildView(permission_link_wrapper); | |
| 720 | |
| 718 return site_settings_view; | 721 return site_settings_view; |
| 719 } | 722 } |
| 720 | 723 |
| 721 void WebsiteSettingsPopupView::HandleLinkClickedAsync(views::Link* source) { | 724 void WebsiteSettingsPopupView::HandleLinkClickedAsync(views::Link* source) { |
| 722 // Both switch cases require accessing web_contents(), so we check it here. | 725 // Both switch cases require accessing web_contents(), so we check it here. |
| 723 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed()) | 726 if (web_contents() == nullptr || web_contents()->IsBeingDestroyed()) |
| 724 return; | 727 return; |
| 725 switch (source->id()) { | 728 switch (source->id()) { |
| 729 case LINK_SHOW_ALL_PERMISSIONS: | |
| 730 // TODO(crbug.com/695670): Place this code in a cross-platform location. | |
| 731 DCHECK(presenter_); | |
| 732 presenter_->OnPresentAllSitePermissions(); | |
|
msw
2017/02/24 18:42:48
nit: maybe just "PresentAllSitePermissions", it's
lgarron
2017/02/28 03:21:01
Oh, I see. Yeah, I definitely prefer PresentAllSit
| |
| 733 presenter_->RecordWebsiteSettingsAction( | |
| 734 WebsiteSettings::WEBSITE_SETTINGS_SHOW_ALL_PERMISSIONS_PRESSED); | |
| 735 break; | |
| 726 case LINK_SITE_SETTINGS: | 736 case LINK_SITE_SETTINGS: |
| 727 // TODO(crbug.com/655876): This opens the general Content Settings pane, | 737 // TODO(crbug.com/655876): This opens the general Content Settings pane, |
| 728 // which is OK for now. But on Android, it opens a page specific to a | 738 // which is OK for now. But on Android, it opens a page specific to a |
| 729 // given origin that shows all of the settings for that origin. If/when | 739 // given origin that shows all of the settings for that origin. If/when |
| 730 // that's available on desktop we should link to that here, too. | 740 // that's available on desktop we should link to that here, too. |
| 731 web_contents()->OpenURL(content::OpenURLParams( | 741 web_contents()->OpenURL(content::OpenURLParams( |
| 732 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(), | 742 GURL(chrome::kChromeUIContentSettingsURL), content::Referrer(), |
| 733 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, | 743 WindowOpenDisposition::NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, |
| 734 false)); | 744 false)); |
| 735 presenter_->RecordWebsiteSettingsAction( | 745 presenter_->RecordWebsiteSettingsAction( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 759 WebsiteSettings::WEBSITE_SETTINGS_CONNECTION_HELP_OPENED); | 769 WebsiteSettings::WEBSITE_SETTINGS_CONNECTION_HELP_OPENED); |
| 760 break; | 770 break; |
| 761 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS: | 771 case STYLED_LABEL_RESET_CERTIFICATE_DECISIONS: |
| 762 presenter_->OnRevokeSSLErrorBypassButtonPressed(); | 772 presenter_->OnRevokeSSLErrorBypassButtonPressed(); |
| 763 GetWidget()->Close(); | 773 GetWidget()->Close(); |
| 764 break; | 774 break; |
| 765 default: | 775 default: |
| 766 NOTREACHED(); | 776 NOTREACHED(); |
| 767 } | 777 } |
| 768 } | 778 } |
| OLD | NEW |