OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "chrome/browser/ui/cocoa/page_info/page_info_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/page_info/page_info_bubble_controller.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include <cmath> | 9 #include <cmath> |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "skia/ext/skia_utils_mac.h" | 38 #include "skia/ext/skia_utils_mac.h" |
39 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" | 39 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw
eaker.h" |
40 #import "ui/base/cocoa/a11y_util.h" | 40 #import "ui/base/cocoa/a11y_util.h" |
41 #include "ui/base/cocoa/cocoa_base_utils.h" | 41 #include "ui/base/cocoa/cocoa_base_utils.h" |
42 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 42 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
43 #import "ui/base/cocoa/flipped_view.h" | 43 #import "ui/base/cocoa/flipped_view.h" |
44 #import "ui/base/cocoa/hover_image_button.h" | 44 #import "ui/base/cocoa/hover_image_button.h" |
45 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
46 #include "ui/base/material_design/material_design_controller.h" | 46 #include "ui/base/material_design/material_design_controller.h" |
47 #include "ui/base/resource/resource_bundle.h" | 47 #include "ui/base/resource/resource_bundle.h" |
| 48 #include "ui/gfx/image/image_skia_util_mac.h" |
48 #import "ui/gfx/mac/coordinate_conversion.h" | 49 #import "ui/gfx/mac/coordinate_conversion.h" |
49 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 50 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
50 #include "ui/resources/grit/ui_resources.h" | 51 #include "ui/resources/grit/ui_resources.h" |
51 | 52 |
52 using ChosenObjectInfoPtr = std::unique_ptr<PageInfoUI::ChosenObjectInfo>; | 53 using ChosenObjectInfoPtr = std::unique_ptr<PageInfoUI::ChosenObjectInfo>; |
53 using ChosenObjectDeleteCallback = | 54 using ChosenObjectDeleteCallback = |
54 base::Callback<void(const PageInfoUI::ChosenObjectInfo&)>; | 55 base::Callback<void(const PageInfoUI::ChosenObjectInfo&)>; |
55 | 56 |
56 namespace { | 57 namespace { |
57 | 58 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 if (location_bar) { | 134 if (location_bar) { |
134 NSPoint bubble_point = location_bar->GetPageInfoBubblePoint(); | 135 NSPoint bubble_point = location_bar->GetPageInfoBubblePoint(); |
135 origin = ui::ConvertPointFromWindowToScreen(parent, bubble_point); | 136 origin = ui::ConvertPointFromWindowToScreen(parent, bubble_point); |
136 } | 137 } |
137 } | 138 } |
138 return origin; | 139 return origin; |
139 } | 140 } |
140 | 141 |
141 } // namespace | 142 } // namespace |
142 | 143 |
| 144 // The |InspectLinkView| objects are used to show the Cookie and Certificate |
| 145 // status and a link to inspect the underlying data. |
| 146 @interface InspectLinkView : FlippedView |
| 147 @end |
| 148 |
| 149 @implementation InspectLinkView { |
| 150 NSButton* actionLink_; |
| 151 } |
| 152 |
| 153 - (id)initWithFrame:(NSRect)frame { |
| 154 if (self = [super initWithFrame:frame]) { |
| 155 [self setAutoresizingMask:NSViewWidthSizable]; |
| 156 } |
| 157 return self; |
| 158 } |
| 159 |
| 160 - (void)setActionLink:(NSButton*)actionLink { |
| 161 actionLink_ = actionLink; |
| 162 } |
| 163 |
| 164 - (void)setLinkText:(NSString*)linkText { |
| 165 [actionLink_ setTitle:linkText]; |
| 166 [GTMUILocalizerAndLayoutTweaker sizeToFitView:actionLink_]; |
| 167 } |
| 168 |
| 169 - (void)setLinkToolTip:(NSString*)linkToolTip { |
| 170 [actionLink_ setToolTip:linkToolTip]; |
| 171 } |
| 172 |
| 173 - (void)setLinkTarget:(NSObject*)target withAction:(SEL)action { |
| 174 [actionLink_ setTarget:target]; |
| 175 [actionLink_ setAction:action]; |
| 176 } |
| 177 @end |
| 178 |
143 @interface ChosenObjectDeleteButton : HoverImageButton { | 179 @interface ChosenObjectDeleteButton : HoverImageButton { |
144 @private | 180 @private |
145 ChosenObjectInfoPtr objectInfo_; | 181 ChosenObjectInfoPtr objectInfo_; |
146 ChosenObjectDeleteCallback callback_; | 182 ChosenObjectDeleteCallback callback_; |
147 } | 183 } |
148 | 184 |
149 // Designated initializer. Takes ownership of |objectInfo|. | 185 // Designated initializer. Takes ownership of |objectInfo|. |
150 - (instancetype)initWithChosenObject:(ChosenObjectInfoPtr)objectInfo | 186 - (instancetype)initWithChosenObject:(ChosenObjectInfoPtr)objectInfo |
151 atPoint:(NSPoint)point | 187 atPoint:(NSPoint)point |
152 withCallback:(ChosenObjectDeleteCallback)callback; | 188 withCallback:(ChosenObjectDeleteCallback)callback; |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 | 418 |
383 // Create and return a subview for the site settings and add it to the given | 419 // Create and return a subview for the site settings and add it to the given |
384 // |superview|. |superview| retains the new view. | 420 // |superview|. |superview| retains the new view. |
385 - (NSView*)addSiteSettingsSectionToView:(NSView*)superview { | 421 - (NSView*)addSiteSettingsSectionToView:(NSView*)superview { |
386 base::scoped_nsobject<NSView> siteSettingsSectionView( | 422 base::scoped_nsobject<NSView> siteSettingsSectionView( |
387 [[FlippedView alloc] initWithFrame:[superview frame]]); | 423 [[FlippedView alloc] initWithFrame:[superview frame]]); |
388 [superview addSubview:siteSettingsSectionView]; | 424 [superview addSubview:siteSettingsSectionView]; |
389 | 425 |
390 // Initialize the two containers that hold the controls. The initial frames | 426 // Initialize the two containers that hold the controls. The initial frames |
391 // are arbitrary, and will be adjusted after the controls are laid out. | 427 // are arbitrary, and will be adjusted after the controls are laid out. |
392 cookiesView_ = | 428 PageInfoUI::PermissionInfo info; |
393 [[[FlippedView alloc] initWithFrame:[superview frame]] autorelease]; | 429 info.type = CONTENT_SETTINGS_TYPE_COOKIES; |
394 [cookiesView_ setAutoresizingMask:NSViewWidthSizable]; | 430 info.setting = CONTENT_SETTING_ALLOW; |
395 [siteSettingsSectionView addSubview:cookiesView_]; | 431 cookiesView_ = [self |
| 432 addInspectLinkToView:siteSettingsSectionView |
| 433 sectionIcon:PageInfoUI::GetPermissionIcon(info).ToNSImage() |
| 434 sectionTitle:l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES) |
| 435 linkText:l10n_util::GetPluralNSStringF( |
| 436 IDS_PAGE_INFO_NUM_COOKIES, 0)]; |
| 437 [cookiesView_ setLinkTarget:self |
| 438 withAction:@selector(showCookiesAndSiteData:)]; |
396 | 439 |
397 permissionsView_ = | 440 permissionsView_ = |
398 [[[FlippedView alloc] initWithFrame:[superview frame]] autorelease]; | 441 [[[FlippedView alloc] initWithFrame:[superview frame]] autorelease]; |
399 [siteSettingsSectionView addSubview:permissionsView_]; | 442 [siteSettingsSectionView addSubview:permissionsView_]; |
400 | 443 |
| 444 // The certificate section is created on demand. |
| 445 certificateView_ = nil; |
| 446 |
401 // Create the link button to view site settings. Its position will be set in | 447 // Create the link button to view site settings. Its position will be set in |
402 // performLayout. | 448 // performLayout. |
403 NSString* siteSettingsButtonText = | 449 NSString* siteSettingsButtonText = |
404 l10n_util::GetNSString(IDS_PAGE_INFO_SITE_SETTINGS_LINK); | 450 l10n_util::GetNSString(IDS_PAGE_INFO_SITE_SETTINGS_LINK); |
405 siteSettingsButton_ = [self addButtonWithText:siteSettingsButtonText | 451 siteSettingsButton_ = [self addButtonWithText:siteSettingsButtonText |
406 toView:siteSettingsSectionView]; | 452 toView:siteSettingsSectionView]; |
407 [GTMUILocalizerAndLayoutTweaker sizeToFitView:siteSettingsButton_]; | 453 [GTMUILocalizerAndLayoutTweaker sizeToFitView:siteSettingsButton_]; |
408 | 454 |
409 [siteSettingsButton_ setTarget:self]; | 455 [siteSettingsButton_ setTarget:self]; |
410 [siteSettingsButton_ setAction:@selector(showSiteSettingsData:)]; | 456 [siteSettingsButton_ setAction:@selector(showSiteSettingsData:)]; |
411 | 457 |
412 return siteSettingsSectionView.get(); | 458 return siteSettingsSectionView.get(); |
413 } | 459 } |
414 | 460 |
| 461 - (InspectLinkView*)addInspectLinkToView:(NSView*)superview |
| 462 sectionIcon:(NSImage*)imageIcon |
| 463 sectionTitle:(const base::string16&)titleText |
| 464 linkText:(NSString*)linkText { |
| 465 // Create the subview. |
| 466 base::scoped_nsobject<InspectLinkView> newView( |
| 467 [[InspectLinkView alloc] initWithFrame:[superview frame]]); |
| 468 [superview addSubview:newView]; |
| 469 |
| 470 bool isRTL = base::i18n::IsRTL(); |
| 471 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); |
| 472 |
| 473 CGFloat viewWidth = NSWidth([newView frame]); |
| 474 |
| 475 // Reset X for the icon. |
| 476 if (isRTL) { |
| 477 controlOrigin.x = |
| 478 viewWidth - kPermissionImageSize - kSectionHorizontalPadding; |
| 479 } |
| 480 |
| 481 NSImageView* imageView = [self addImageWithSize:[imageIcon size] |
| 482 toView:newView |
| 483 atPoint:controlOrigin]; |
| 484 [imageView setImage:imageIcon]; |
| 485 |
| 486 NSButton* actionLink = [self addLinkButtonWithText:linkText toView:newView]; |
| 487 [newView setActionLink:actionLink]; |
| 488 |
| 489 if (isRTL) { |
| 490 controlOrigin.x -= kPermissionImageSpacing; |
| 491 NSTextField* sectionTitle = [self addText:titleText |
| 492 withSize:[NSFont systemFontSize] |
| 493 bold:NO |
| 494 toView:newView |
| 495 atPoint:controlOrigin]; |
| 496 [sectionTitle sizeToFit]; |
| 497 |
| 498 NSPoint sectionTitleOrigin = [sectionTitle frame].origin; |
| 499 sectionTitleOrigin.x -= NSWidth([sectionTitle frame]); |
| 500 [sectionTitle setFrameOrigin:sectionTitleOrigin]; |
| 501 |
| 502 // Align the icon with the text. |
| 503 [self alignPermissionIcon:imageView withTextField:sectionTitle]; |
| 504 |
| 505 controlOrigin.y += |
| 506 NSHeight([sectionTitle frame]) + kPermissionLabelBottomPadding; |
| 507 controlOrigin.x -= NSWidth([actionLink frame]) - kLinkButtonXAdjustment; |
| 508 [actionLink setFrameOrigin:controlOrigin]; |
| 509 } else { |
| 510 controlOrigin.x += kPermissionImageSize + kPermissionImageSpacing; |
| 511 NSTextField* sectionTitle = [self addText:titleText |
| 512 withSize:[NSFont systemFontSize] |
| 513 bold:NO |
| 514 toView:newView |
| 515 atPoint:controlOrigin]; |
| 516 [sectionTitle sizeToFit]; |
| 517 |
| 518 // Align the icon with the text. |
| 519 [self alignPermissionIcon:imageView withTextField:sectionTitle]; |
| 520 |
| 521 controlOrigin.y += |
| 522 NSHeight([sectionTitle frame]) + kPermissionLabelBottomPadding; |
| 523 controlOrigin.x -= kLinkButtonXAdjustment; |
| 524 [actionLink setFrameOrigin:controlOrigin]; |
| 525 } |
| 526 |
| 527 controlOrigin.y += NSHeight([actionLink frame]); |
| 528 [newView setFrameSize:NSMakeSize(NSWidth([newView frame]), controlOrigin.y)]; |
| 529 |
| 530 return newView.get(); |
| 531 } |
| 532 |
415 // Handler for the link button below the list of cookies. | 533 // Handler for the link button below the list of cookies. |
416 - (void)showCookiesAndSiteData:(id)sender { | 534 - (void)showCookiesAndSiteData:(id)sender { |
417 DCHECK(webContents_); | 535 DCHECK(webContents_); |
418 DCHECK(presenter_); | 536 DCHECK(presenter_); |
419 presenter_->RecordPageInfoAction(PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED); | 537 presenter_->RecordPageInfoAction(PageInfo::PAGE_INFO_COOKIES_DIALOG_OPENED); |
420 TabDialogs::FromWebContents(webContents_)->ShowCollectedCookies(); | 538 TabDialogs::FromWebContents(webContents_)->ShowCollectedCookies(); |
421 } | 539 } |
422 | 540 |
423 // Handler for the site settings button below the list of permissions. | 541 // Handler for the site settings button below the list of permissions. |
424 - (void)showSiteSettingsData:(id)sender { | 542 - (void)showSiteSettingsData:(id)sender { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 yPos)]; | 665 yPos)]; |
548 yPos = NSMaxY([resetDecisionsButton_ frame]); | 666 yPos = NSMaxY([resetDecisionsButton_ frame]); |
549 } | 667 } |
550 | 668 |
551 // Resize the height based on contents. | 669 // Resize the height based on contents. |
552 [self setHeightOfView:securitySectionView_ to:yPos + kSectionVerticalPadding]; | 670 [self setHeightOfView:securitySectionView_ to:yPos + kSectionVerticalPadding]; |
553 } | 671 } |
554 | 672 |
555 - (void)layoutSiteSettingsSection { | 673 - (void)layoutSiteSettingsSection { |
556 // Start the layout with the first element. Margins are handled by the caller. | 674 // Start the layout with the first element. Margins are handled by the caller. |
557 CGFloat yPos = 0; | 675 CGFloat yPos = kSectionVerticalPadding; |
558 | 676 |
559 yPos = | 677 if (certificateView_) { |
560 [self setYPositionOfView:cookiesView_ to:yPos + kSectionVerticalPadding]; | 678 yPos = [self setYPositionOfView:certificateView_ to:yPos] + |
| 679 kPermissionsVerticalSpacing; |
| 680 } |
| 681 |
| 682 yPos = [self setYPositionOfView:cookiesView_ to:yPos]; |
561 | 683 |
562 if (permissionsPresent_) { | 684 if (permissionsPresent_) { |
563 // Put the permission info just below the link button. | 685 // Put the permission info just below the link button. |
564 yPos = [self setYPositionOfView:permissionsView_ to:yPos]; | 686 yPos = [self setYPositionOfView:permissionsView_ to:yPos]; |
565 } | 687 } |
566 | 688 |
567 yPos = [self layoutViewAtRTLStart:siteSettingsButton_ withYPosition:yPos]; | 689 yPos = [self layoutViewAtRTLStart:siteSettingsButton_ withYPosition:yPos]; |
568 | 690 |
569 // Resize the height based on contents. | 691 // Resize the height based on contents. |
570 [self setHeightOfView:siteSettingsSectionView_ | 692 [self setHeightOfView:siteSettingsSectionView_ |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 buttonFrame.size.width = maxTitleWidth; | 825 buttonFrame.size.width = maxTitleWidth; |
704 | 826 |
705 [button setFrame:buttonFrame]; | 827 [button setFrame:buttonFrame]; |
706 [button setButtonType:NSMomentaryPushInButton]; | 828 [button setButtonType:NSMomentaryPushInButton]; |
707 [button setBezelStyle:NSRegularSquareBezelStyle]; | 829 [button setBezelStyle:NSRegularSquareBezelStyle]; |
708 [view addSubview:button.get()]; | 830 [view addSubview:button.get()]; |
709 | 831 |
710 return button.get(); | 832 return button.get(); |
711 } | 833 } |
712 | 834 |
713 // Set the content of the identity and identity status fields. | 835 // Set the content of the identity and identity status fields, and add the |
| 836 // Certificate view if applicable. |
714 - (void)setIdentityInfo:(const PageInfoUI::IdentityInfo&)identityInfo { | 837 - (void)setIdentityInfo:(const PageInfoUI::IdentityInfo&)identityInfo { |
715 std::unique_ptr<PageInfoUI::SecurityDescription> security_description = | 838 std::unique_ptr<PageInfoUI::SecurityDescription> security_description = |
716 identityInfo.GetSecurityDescription(); | 839 identityInfo.GetSecurityDescription(); |
717 [securitySummaryField_ | 840 [securitySummaryField_ |
718 setStringValue:base::SysUTF16ToNSString(security_description->summary)]; | 841 setStringValue:SysUTF16ToNSString(security_description->summary)]; |
719 | 842 |
720 [securityDetailsField_ | 843 [securityDetailsField_ |
721 setStringValue:SysUTF16ToNSString(security_description->details)]; | 844 setStringValue:SysUTF16ToNSString(security_description->details)]; |
722 | 845 |
723 certificate_ = identityInfo.certificate; | 846 certificate_ = identityInfo.certificate; |
724 | 847 |
725 if (certificate_ && identityInfo.show_ssl_decision_revoke_button) { | 848 if (certificate_) { |
726 resetDecisionsField_ = | 849 if (identityInfo.show_ssl_decision_revoke_button) { |
727 [self addText:base::string16() | 850 resetDecisionsField_ = |
728 withSize:[NSFont smallSystemFontSize] | 851 [self addText:base::string16() |
729 bold:NO | 852 withSize:[NSFont smallSystemFontSize] |
730 toView:securitySectionView_ | 853 bold:NO |
731 atPoint:NSMakePoint(kSectionHorizontalPadding, 0)]; | 854 toView:securitySectionView_ |
732 [resetDecisionsField_ | 855 atPoint:NSMakePoint(kSectionHorizontalPadding, 0)]; |
733 setStringValue:l10n_util::GetNSString( | 856 [resetDecisionsField_ |
734 IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION)]; | 857 setStringValue:l10n_util::GetNSString( |
735 [self sizeTextFieldHeightToFit:resetDecisionsField_]; | 858 IDS_PAGEINFO_INVALID_CERTIFICATE_DESCRIPTION)]; |
| 859 [self sizeTextFieldHeightToFit:resetDecisionsField_]; |
736 | 860 |
737 resetDecisionsButton_ = | 861 resetDecisionsButton_ = |
738 [self addLinkButtonWithText: | 862 [self addLinkButtonWithText: |
739 l10n_util::GetNSString( | 863 l10n_util::GetNSString( |
740 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON) | 864 IDS_PAGEINFO_RESET_INVALID_CERTIFICATE_DECISIONS_BUTTON) |
741 toView:securitySectionView_]; | 865 toView:securitySectionView_]; |
742 [resetDecisionsButton_ setTarget:self]; | 866 [resetDecisionsButton_ setTarget:self]; |
743 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)]; | 867 [resetDecisionsButton_ setAction:@selector(resetCertificateDecisions:)]; |
| 868 } |
| 869 |
| 870 if (PageInfoUI::ShouldShowCertificateLink()) { |
| 871 bool isValid = (identityInfo.identity_status != |
| 872 PageInfo::SITE_IDENTITY_STATUS_ERROR); |
| 873 NSString* linkText = l10n_util::GetNSString( |
| 874 isValid ? IDS_PAGE_INFO_CERTIFICATE_VALID_LINK |
| 875 : IDS_PAGE_INFO_CERTIFICATE_INVALID_LINK); |
| 876 |
| 877 certificateView_ = |
| 878 [self addInspectLinkToView:siteSettingsSectionView_ |
| 879 sectionIcon:NSImageFromImageSkia( |
| 880 PageInfoUI::GetCertificateIcon()) |
| 881 sectionTitle:l10n_util::GetStringUTF16( |
| 882 IDS_PAGE_INFO_CERTIFICATE) |
| 883 linkText:linkText]; |
| 884 if (isValid) { |
| 885 [certificateView_ |
| 886 setLinkToolTip:l10n_util::GetNSStringF( |
| 887 IDS_PAGE_INFO_CERTIFICATE_VALID_LINK_TOOLTIP, |
| 888 base::UTF8ToUTF16( |
| 889 certificate_->issuer().GetDisplayName()))]; |
| 890 } |
| 891 |
| 892 [certificateView_ setLinkTarget:self |
| 893 withAction:@selector(showCertificateInfo:)]; |
| 894 } |
744 } | 895 } |
745 | 896 |
746 [self performLayout]; | 897 [self performLayout]; |
747 } | 898 } |
748 | 899 |
749 // Add a pop-up button for |permissionInfo| to the given view. | 900 // Add a pop-up button for |permissionInfo| to the given view. |
750 - (NSPopUpButton*)addPopUpButtonForPermission: | 901 - (NSPopUpButton*)addPopUpButtonForPermission: |
751 (const PageInfoUI::PermissionInfo&)permissionInfo | 902 (const PageInfoUI::PermissionInfo&)permissionInfo |
752 toView:(NSView*)view | 903 toView:(NSView*)view |
753 atPoint:(NSPoint)point { | 904 atPoint:(NSPoint)point { |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 // Align an image with a text field by vertically centering the image on | 1181 // Align an image with a text field by vertically centering the image on |
1031 // the cap height of the first line of text. | 1182 // the cap height of the first line of text. |
1032 - (void)alignPermissionIcon:(NSImageView*)imageView | 1183 - (void)alignPermissionIcon:(NSImageView*)imageView |
1033 withTextField:(NSTextField*)textField { | 1184 withTextField:(NSTextField*)textField { |
1034 NSRect frame = [imageView frame]; | 1185 NSRect frame = [imageView frame]; |
1035 frame.origin.y += kPermissionIconYAdjustment; | 1186 frame.origin.y += kPermissionIconYAdjustment; |
1036 [imageView setFrame:frame]; | 1187 [imageView setFrame:frame]; |
1037 } | 1188 } |
1038 | 1189 |
1039 - (void)setCookieInfo:(const CookieInfoList&)cookieInfoList { | 1190 - (void)setCookieInfo:(const CookieInfoList&)cookieInfoList { |
1040 // A result of re-ordering of the permissions (crbug.com/444244) is | |
1041 // that sometimes permissions may not be displayed at all, so it's | |
1042 // incorrect to check they are set before the cookie info. | |
1043 | |
1044 // |cookieInfoList| should only ever have 2 items: first- and third-party | 1191 // |cookieInfoList| should only ever have 2 items: first- and third-party |
1045 // cookies. | 1192 // cookies. |
1046 DCHECK_EQ(cookieInfoList.size(), 2u); | 1193 DCHECK_EQ(cookieInfoList.size(), 2u); |
1047 | 1194 |
1048 int totalAllowed = 0; | 1195 int totalAllowed = 0; |
1049 for (const auto& i : cookieInfoList) { | 1196 for (const auto& i : cookieInfoList) { |
1050 totalAllowed += i.allowed; | 1197 totalAllowed += i.allowed; |
1051 } | 1198 } |
1052 base::string16 label_text = | |
1053 l10n_util::GetPluralStringFUTF16(IDS_PAGE_INFO_NUM_COOKIES, totalAllowed); | |
1054 | 1199 |
1055 base::string16 sectionTitle = | 1200 [cookiesView_ setLinkText:l10n_util::GetPluralNSStringF( |
1056 l10n_util::GetStringUTF16(IDS_PAGE_INFO_TITLE_SITE_DATA); | 1201 IDS_PAGE_INFO_NUM_COOKIES, totalAllowed)]; |
1057 bool isRTL = base::i18n::IsRTL(); | |
1058 | |
1059 [cookiesView_ setSubviews:[NSArray array]]; | |
1060 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); | |
1061 | |
1062 CGFloat viewWidth = NSWidth([cookiesView_ frame]); | |
1063 | |
1064 // Reset X for the cookie image. | |
1065 if (isRTL) { | |
1066 controlOrigin.x = viewWidth - kPermissionImageSize - | |
1067 kPermissionImageSpacing - kSectionHorizontalPadding; | |
1068 } | |
1069 | |
1070 PageInfoUI::PermissionInfo info; | |
1071 info.type = CONTENT_SETTINGS_TYPE_COOKIES; | |
1072 info.setting = CONTENT_SETTING_ALLOW; | |
1073 // info.default_setting, info.source, and info.is_incognito have not been set, | |
1074 // but GetPermissionIcon doesn't use any of those. | |
1075 NSImage* image = PageInfoUI::GetPermissionIcon(info).ToNSImage(); | |
1076 NSImageView* imageView = [self addImageWithSize:[image size] | |
1077 toView:cookiesView_ | |
1078 atPoint:controlOrigin]; | |
1079 [imageView setImage:image]; | |
1080 | |
1081 NSButton* cookiesButton = | |
1082 [self addLinkButtonWithText:base::SysUTF16ToNSString(label_text) | |
1083 toView:cookiesView_]; | |
1084 [cookiesButton setTarget:self]; | |
1085 [cookiesButton setAction:@selector(showCookiesAndSiteData:)]; | |
1086 | |
1087 if (isRTL) { | |
1088 controlOrigin.x -= kPermissionImageSpacing; | |
1089 NSTextField* cookiesLabel = | |
1090 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES) | |
1091 withSize:[NSFont systemFontSize] | |
1092 bold:NO | |
1093 toView:cookiesView_ | |
1094 atPoint:controlOrigin]; | |
1095 [cookiesLabel sizeToFit]; | |
1096 | |
1097 NSPoint cookiesLabelOrigin = [cookiesLabel frame].origin; | |
1098 cookiesLabelOrigin.x -= NSWidth([cookiesLabel frame]); | |
1099 [cookiesLabel setFrameOrigin:cookiesLabelOrigin]; | |
1100 | |
1101 // Align the icon with the text. | |
1102 [self alignPermissionIcon:imageView withTextField:cookiesLabel]; | |
1103 | |
1104 controlOrigin.y += | |
1105 NSHeight([cookiesLabel frame]) + kPermissionLabelBottomPadding; | |
1106 controlOrigin.x -= NSWidth([cookiesButton frame]) - kLinkButtonXAdjustment; | |
1107 [cookiesButton setFrameOrigin:controlOrigin]; | |
1108 } else { | |
1109 controlOrigin.x += kPermissionImageSize + kPermissionImageSpacing; | |
1110 NSTextField* cookiesLabel = | |
1111 [self addText:l10n_util::GetStringUTF16(IDS_PAGE_INFO_COOKIES) | |
1112 withSize:[NSFont systemFontSize] | |
1113 bold:NO | |
1114 toView:cookiesView_ | |
1115 atPoint:controlOrigin]; | |
1116 [cookiesLabel sizeToFit]; | |
1117 | |
1118 controlOrigin.y += | |
1119 NSHeight([cookiesLabel frame]) + kPermissionLabelBottomPadding; | |
1120 controlOrigin.x -= kLinkButtonXAdjustment; | |
1121 [cookiesButton setFrameOrigin:controlOrigin]; | |
1122 | |
1123 // Align the icon with the text. | |
1124 [self alignPermissionIcon:imageView withTextField:cookiesLabel]; | |
1125 } | |
1126 | |
1127 controlOrigin.y += NSHeight([cookiesButton frame]); | |
1128 [cookiesView_ | |
1129 setFrameSize:NSMakeSize(NSWidth([cookiesView_ frame]), controlOrigin.y)]; | |
1130 | |
1131 [self performLayout]; | 1202 [self performLayout]; |
1132 } | 1203 } |
1133 | 1204 |
1134 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList | 1205 - (void)setPermissionInfo:(const PermissionInfoList&)permissionInfoList |
1135 andChosenObjects:(ChosenObjectInfoList)chosenObjectInfoList { | 1206 andChosenObjects:(ChosenObjectInfoList)chosenObjectInfoList { |
1136 [permissionsView_ setSubviews:[NSArray array]]; | 1207 [permissionsView_ setSubviews:[NSArray array]]; |
1137 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); | 1208 NSPoint controlOrigin = NSMakePoint(kSectionHorizontalPadding, 0); |
1138 | 1209 |
1139 permissionsPresent_ = YES; | 1210 permissionsPresent_ = YES; |
1140 | 1211 |
1141 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) { | 1212 if (permissionInfoList.size() > 0 || chosenObjectInfoList.size() > 0) { |
1142 base::string16 sectionTitle = | |
1143 l10n_util::GetStringUTF16(IDS_PAGE_INFO_TITLE_SITE_PERMISSIONS); | |
1144 | |
1145 for (const auto& permission : permissionInfoList) { | 1213 for (const auto& permission : permissionInfoList) { |
1146 controlOrigin.y += kPermissionsVerticalSpacing; | 1214 controlOrigin.y += kPermissionsVerticalSpacing; |
1147 NSPoint rowBottomRight = [self addPermission:permission | 1215 NSPoint rowBottomRight = [self addPermission:permission |
1148 toView:permissionsView_ | 1216 toView:permissionsView_ |
1149 atPoint:controlOrigin]; | 1217 atPoint:controlOrigin]; |
1150 controlOrigin.y = rowBottomRight.y; | 1218 controlOrigin.y = rowBottomRight.y; |
1151 } | 1219 } |
1152 | 1220 |
1153 for (auto& object : chosenObjectInfoList) { | 1221 for (auto& object : chosenObjectInfoList) { |
1154 controlOrigin.y += kPermissionsVerticalSpacing; | 1222 controlOrigin.y += kPermissionsVerticalSpacing; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1243 void PageInfoUIBridge::SetCookieInfo(const CookieInfoList& cookie_info_list) { | 1311 void PageInfoUIBridge::SetCookieInfo(const CookieInfoList& cookie_info_list) { |
1244 [bubble_controller_ setCookieInfo:cookie_info_list]; | 1312 [bubble_controller_ setCookieInfo:cookie_info_list]; |
1245 } | 1313 } |
1246 | 1314 |
1247 void PageInfoUIBridge::SetPermissionInfo( | 1315 void PageInfoUIBridge::SetPermissionInfo( |
1248 const PermissionInfoList& permission_info_list, | 1316 const PermissionInfoList& permission_info_list, |
1249 ChosenObjectInfoList chosen_object_info_list) { | 1317 ChosenObjectInfoList chosen_object_info_list) { |
1250 [bubble_controller_ setPermissionInfo:permission_info_list | 1318 [bubble_controller_ setPermissionInfo:permission_info_list |
1251 andChosenObjects:std::move(chosen_object_info_list)]; | 1319 andChosenObjects:std::move(chosen_object_info_list)]; |
1252 } | 1320 } |
OLD | NEW |